Solvespace

Форк
0
/
VbDemo.vb 
1251 строка · 48.6 Кб
1
'-----------------------------------------------------------------------------
2
' Some sample code for slvs.dll. We draw some geometric entities, provide
3
' initial guesses for their positions, and then constrain them. The solver
4
' calculates their new positions, in order to satisfy the constraints.
5
'
6
' The library is distributed as a DLL, but the functions are designed to
7
' be usable from .net languages through a P/Invoke. This file contains an
8
' example of that process, and a wrapper class around those P/Invoke'd
9
' functions that you may wish to use a starting point in your own
10
' application.
11
'
12
' Copyright 2008-2013 Jonathan Westhues.
13
'-----------------------------------------------------------------------------
14

15
Imports System.Runtime.InteropServices
16

17
Module VbDemo
18

19
    ' Call our example functions, which set up some kind of sketch, solve
20
    ' it, and then print the result. 
21
    Sub Main()
22
        Console.WriteLine("EXAMPLE IN 3d (by objects):")
23
        Example3dWithObjects()
24
        Console.WriteLine("")
25

26
        Console.WriteLine("EXAMPLE IN 2d (by objects):")
27
        Example2dWithObjects()
28
        Console.WriteLine("")
29

30
        Console.WriteLine("EXAMPLE IN 3d (by handles):")
31
        Example3dWithHandles()
32
        Console.WriteLine("")
33

34
        Console.WriteLine("EXAMPLE IN 2d (by handles):")
35
        Example2dWithHandles()
36
        Console.WriteLine("")
37
    End Sub
38

39

40
    '''''''''''''''''''''''''''''''
41
    ' This is the simplest way to use the library. A set of wrapper
42
    ' classes allow us to represent entities (e.g., lines and points)
43
    ' as .net objects. So we create an Slvs object, which will contain
44
    ' the entire sketch, with all the entities and constraints.
45
    ' 
46
    ' We then create entity objects (for example, points and lines)
47
    ' associated with that sketch, indicating the initial positions of
48
    ' those entities and any hierarchical relationships among them (e.g.,
49
    ' defining a line entity in terms of endpoint entities). We also add
50
    ' constraints associated with those entities.
51
    ' 
52
    ' Finally, we solve, and print the new positions of the entities. If the
53
    ' solution succeeded, then the entities will satisfy the constraints. If
54
    ' not, then the solver will suggest problematic constraints that, if
55
    ' removed, would render the sketch solvable.
56

57
    Sub Example3dWithObjects()
58
        Dim g As UInteger
59
        Dim slv As New Slvs
60

61
        ' This will contain a single group, which will arbitrarily number 1.
62
        g = 1
63

64
        Dim p1, p2 As Slvs.Point3d
65
        ' A point, initially at (x y z) = (10 10 10)
66
        p1 = slv.NewPoint3d(g, 10.0, 10.0, 10.0)
67
        ' and a second point at (20 20 20)
68
        p2 = slv.NewPoint3d(g, 20.0, 20.0, 20.0)
69

70
        Dim ln As Slvs.LineSegment
71
        ' and a line segment connecting them.
72
        ln = slv.NewLineSegment(g, slv.FreeIn3d(), p1, p2)
73

74
        ' The distance between the points should be 30.0 units.
75
        slv.AddConstraint(1, g, Slvs.SLVS_C_PT_PT_DISTANCE, _
76
                              slv.FreeIn3d(), 30.0, p1, p2, Nothing, Nothing)
77

78
        ' Let's tell the solver to keep the second point as close to constant
79
        ' as possible, instead moving the first point.
80
        slv.Solve(g, p2, True)
81

82
        If (slv.GetResult() = Slvs.SLVS_RESULT_OKAY) Then
83
            ' We call the GetX(), GetY(), and GetZ() functions to see
84
            ' where the solver moved our points to.
85
            Console.WriteLine(String.Format( _
86
                "okay; now at ({0:F3}, {1:F3}, {2:F3})", _
87
                p1.GetX(), p1.GetY(), p1.GetZ()))
88
            Console.WriteLine(String.Format( _
89
                "             ({0:F3}, {1:F3}, {2:F3})", _
90
                p2.GetX(), p2.GetY(), p2.GetZ()))
91
            Console.WriteLine(slv.GetDof().ToString() + " DOF")
92
        Else
93
            Console.WriteLine("solve failed")
94
        End If
95
    End Sub
96

97
    Sub Example2dWithObjects()
98
        Dim g As UInteger
99
        Dim slv As New Slvs
100

101
        g = 1
102

103
        ' First, we create our workplane. Its origin corresponds to the origin
104
        ' of our base frame (x y z) = (0 0 0)
105
        Dim origin As Slvs.Point3d
106
        origin = slv.NewPoint3d(g, 0.0, 0.0, 0.0)
107
        ' and it is parallel to the xy plane, so it has basis vectors (1 0 0)
108
        ' and (0 1 0).
109
        Dim normal As Slvs.Normal3d
110
        normal = slv.NewNormal3d(g, 1.0, 0.0, 0.0, _
111
                                    0.0, 1.0, 0.0)
112

113
        Dim wrkpl As Slvs.Workplane
114
        wrkpl = slv.NewWorkplane(g, origin, normal)
115

116
        ' Now create a second group. We'll solve group 2, while leaving group 1
117
        ' constant; so the workplane that we've created will be locked down,
118
        ' and the solver can't move it.
119
        g = 2
120
        ' These points are represented by their coordinates (u v) within the
121
        ' workplane, so they need only two parameters each.
122
        Dim pl1, pl2 As Slvs.Point2d
123
        pl1 = slv.NewPoint2d(g, wrkpl, 10.0, 20.0)
124
        pl2 = slv.NewPoint2d(g, wrkpl, 20.0, 10.0)
125

126
        ' And we create a line segment with those endpoints.
127
        Dim ln As Slvs.LineSegment
128
        ln = slv.NewLineSegment(g, wrkpl, pl1, pl2)
129

130
        ' Now three more points.
131
        Dim pc, ps, pf As Slvs.Point2d
132
        pc = slv.NewPoint2d(g, wrkpl, 100.0, 120.0)
133
        ps = slv.NewPoint2d(g, wrkpl, 120.0, 110.0)
134
        pf = slv.NewPoint2d(g, wrkpl, 115.0, 115.0)
135

136
        ' And arc, centered at point pc, starting at point ps, ending at
137
        ' point pf.
138
        Dim arc As Slvs.ArcOfCircle
139
        arc = slv.NewArcOfCircle(g, wrkpl, normal, pc, ps, pf)
140

141
        ' Now one more point, and a distance
142
        Dim pcc As Slvs.Point2d
143
        pcc = slv.NewPoint2d(g, wrkpl, 200.0, 200.0)
144
        Dim r As Slvs.Distance
145
        r = slv.NewDistance(g, wrkpl, 30.0)
146

147
        ' And a complete circle, centered at point pcc with radius equal to
148
        ' distance r. The normal is the same as for our workplane.
149
        Dim circle As Slvs.Circle
150
        circle = slv.NewCircle(g, wrkpl, pcc, normal, r)
151

152
        ' The length of our line segment is 30.0 units.
153
        slv.AddConstraint(1, g, Slvs.SLVS_C_PT_PT_DISTANCE, _
154
            wrkpl, 30.0, pl1, pl2, Nothing, Nothing)
155

156
        ' And the distance from our line segment to the origin is 10.0 units.
157
        slv.AddConstraint(2, g, Slvs.SLVS_C_PT_LINE_DISTANCE, _
158
            wrkpl, 10.0, origin, Nothing, ln, Nothing)
159

160
        ' And the line segment is vertical.
161
        slv.AddConstraint(3, g, Slvs.SLVS_C_VERTICAL, _
162
            wrkpl, 0.0, Nothing, Nothing, ln, Nothing)
163

164
        ' And the distance from one endpoint to the origin is 15.0 units.
165
        slv.AddConstraint(4, g, Slvs.SLVS_C_PT_PT_DISTANCE, _
166
            wrkpl, 15.0, pl1, origin, Nothing, Nothing)
167

168
        ' And same for the other endpoint; so if you add this constraint then
169
        ' the sketch is overconstrained and will signal an error.
170
        'slv.AddConstraint(5, g, Slvs.SLVS_C_PT_PT_DISTANCE, _
171
        '    wrkpl, 18.0, pl2, origin, Nothing, Nothing)
172

173
        ' The arc and the circle have equal radius.
174
        slv.AddConstraint(6, g, Slvs.SLVS_C_EQUAL_RADIUS, _
175
            wrkpl, 0.0, Nothing, Nothing, arc, circle)
176

177
        ' The arc has radius 17.0 units.
178
        slv.AddConstraint(7, g, Slvs.SLVS_C_DIAMETER, _
179
            wrkpl, 2 * 17.0, Nothing, Nothing, arc, Nothing)
180

181
        ' If the solver fails, then ask it to report which constraints caused
182
        ' the problem.
183
        slv.Solve(g, True)
184

185
        If (slv.GetResult() = Slvs.SLVS_RESULT_OKAY) Then
186
            Console.WriteLine("solved okay")
187
            ' We call the GetU(), GetV(), and GetDistance() functions to
188
            ' see where the solver moved our points and distances to.
189
            Console.WriteLine(String.Format( _
190
                "line from ({0:F3} {1:F3}) to ({2:F3} {3:F3})", _
191
                pl1.GetU(), pl1.GetV(), _
192
                pl2.GetU(), pl2.GetV()))
193
            Console.WriteLine(String.Format( _
194
                "arc center ({0:F3} {1:F3}) start ({2:F3} {3:F3}) " + _
195
                    "finish ({4:F3} {5:F3})", _
196
                pc.GetU(), pc.GetV(), _
197
                ps.GetU(), ps.GetV(), _
198
                pf.GetU(), pf.GetV()))
199
            Console.WriteLine(String.Format( _
200
                "circle center ({0:F3} {1:F3}) radius {2:F3}", _
201
                pcc.GetU(), pcc.GetV(), _
202
                r.GetDistance()))
203

204
            Console.WriteLine(slv.GetDof().ToString() + " DOF")
205
        Else
206
            Console.Write("solve failed; problematic constraints are:")
207
            Dim t As UInteger
208
            For Each t In slv.GetFaileds()
209
                Console.Write(" " + t.ToString())
210
            Next
211
            Console.WriteLine("")
212
            If (slv.GetResult() = Slvs.SLVS_RESULT_INCONSISTENT) Then
213
                Console.WriteLine("system inconsistent")
214
            Else
215
                Console.WriteLine("system nonconvergent")
216
            End If
217
        End If
218

219
    End Sub
220

221

222
    '''''''''''''''''''''''''''''''
223
    ' This is a lower-level way to use the library. Internally, the library
224
    ' represents parameters, entities, and constraints by integer handles.
225
    ' Here, those handles are assigned manually, and not by the wrapper
226
    ' classes.
227

228
    Sub Example3dWithHandles()
229
        Dim g As UInteger
230
        Dim slv As New Slvs
231

232
        ' This will contain a single group, which will arbitrarily number 1.
233
        g = 1
234

235
        ' A point, initially at (x y z) = (10 10 10)
236
        slv.AddParam(1, g, 10.0)
237
        slv.AddParam(2, g, 10.0)
238
        slv.AddParam(3, g, 10.0)
239
        slv.AddPoint3d(101, g, 1, 2, 3)
240

241
        ' and a second point at (20 20 20)
242
        slv.AddParam(4, g, 20.0)
243
        slv.AddParam(5, g, 20.0)
244
        slv.AddParam(6, g, 20.0)
245
        slv.AddPoint3d(102, g, 4, 5, 6)
246

247
        ' and a line segment connecting them.
248
        slv.AddLineSegment(200, g, Slvs.SLVS_FREE_IN_3D, 101, 102)
249

250
        ' The distance between the points should be 30.0 units.
251
        slv.AddConstraint(1, g, Slvs.SLVS_C_PT_PT_DISTANCE, _
252
            Slvs.SLVS_FREE_IN_3D, 30.0, 101, 102, 0, 0)
253

254
        ' Let's tell the solver to keep the second point as close to constant
255
        ' as possible, instead moving the first point. That's parameters
256
        ' 4, 5, and 6.
257
        slv.Solve(g, 4, 5, 6, 0, True)
258

259
        If (slv.GetResult() = Slvs.SLVS_RESULT_OKAY) Then
260
            ' Note that we are referring to the parameters by their handles,
261
            ' and not by their index in the list. This is a difference from
262
            ' the C example.
263
            Console.WriteLine(String.Format( _
264
                "okay; now at ({0:F3}, {1:F3}, {2:F3})", _
265
                slv.GetParamByHandle(1), slv.GetParamByHandle(2), _
266
                slv.GetParamByHandle(3)))
267
            Console.WriteLine(String.Format( _
268
                "             ({0:F3}, {1:F3}, {2:F3})", _
269
                slv.GetParamByHandle(4), slv.GetParamByHandle(5), _
270
                slv.GetParamByHandle(6)))
271
            Console.WriteLine(slv.GetDof().ToString() + " DOF")
272
        Else
273
            Console.WriteLine("solve failed")
274
        End If
275
    End Sub
276

277

278
    Sub Example2dWithHandles()
279
        Dim g As UInteger
280
        Dim qw, qx, qy, qz As Double
281

282
        Dim slv As New Slvs
283

284
        g = 1
285

286
        ' First, we create our workplane. Its origin corresponds to the origin
287
        ' of our base frame (x y z) = (0 0 0)
288
        slv.AddParam(1, g, 0.0)
289
        slv.AddParam(2, g, 0.0)
290
        slv.AddParam(3, g, 0.0)
291
        slv.AddPoint3d(101, g, 1, 2, 3)
292
        ' and it is parallel to the xy plane, so it has basis vectors (1 0 0)
293
        ' and (0 1 0).
294
        slv.MakeQuaternion(1, 0, 0, _
295
                           0, 1, 0, qw, qx, qy, qz)
296
        slv.AddParam(4, g, qw)
297
        slv.AddParam(5, g, qx)
298
        slv.AddParam(6, g, qy)
299
        slv.AddParam(7, g, qz)
300
        slv.AddNormal3d(102, g, 4, 5, 6, 7)
301

302
        slv.AddWorkplane(200, g, 101, 102)
303

304
        ' Now create a second group. We'll solve group 2, while leaving group 1
305
        ' constant; so the workplane that we've created will be locked down,
306
        ' and the solver can't move it.
307
        g = 2
308
        ' These points are represented by their coordinates (u v) within the
309
        ' workplane, so they need only two parameters each.
310
        slv.AddParam(11, g, 10.0)
311
        slv.AddParam(12, g, 20.0)
312
        slv.AddPoint2d(301, g, 200, 11, 12)
313

314
        slv.AddParam(13, g, 20.0)
315
        slv.AddParam(14, g, 10.0)
316
        slv.AddPoint2d(302, g, 200, 13, 14)
317

318
        ' And we create a line segment with those endpoints.
319
        slv.AddLineSegment(400, g, 200, 301, 302)
320

321
        ' Now three more points.
322
        slv.AddParam(15, g, 100.0)
323
        slv.AddParam(16, g, 120.0)
324
        slv.AddPoint2d(303, g, 200, 15, 16)
325

326
        slv.AddParam(17, g, 120.0)
327
        slv.AddParam(18, g, 110.0)
328
        slv.AddPoint2d(304, g, 200, 17, 18)
329

330
        slv.AddParam(19, g, 115.0)
331
        slv.AddParam(20, g, 115.0)
332
        slv.AddPoint2d(305, g, 200, 19, 20)
333

334
        ' And arc, centered at point 303, starting at point 304, ending at
335
        ' point 305.
336
        slv.AddArcOfCircle(401, g, 200, 102, 303, 304, 305)
337

338
        ' Now one more point, and a distance
339
        slv.AddParam(21, g, 200.0)
340
        slv.AddParam(22, g, 200.0)
341
        slv.AddPoint2d(306, g, 200, 21, 22)
342

343
        slv.AddParam(23, g, 30.0)
344
        slv.AddDistance(307, g, 200, 23)
345

346
        ' And a complete circle, centered at point 306 with radius equal to
347
        ' distance 307. The normal is 102, the same as our workplane.
348
        slv.AddCircle(402, g, 200, 306, 102, 307)
349

350
        ' The length of our line segment is 30.0 units.
351
        slv.AddConstraint(1, g, Slvs.SLVS_C_PT_PT_DISTANCE, _
352
            200, 30.0, 301, 302, 0, 0)
353

354
        ' And the distance from our line segment to the origin is 10.0 units.
355
        slv.AddConstraint(2, g, Slvs.SLVS_C_PT_LINE_DISTANCE, _
356
            200, 10.0, 101, 0, 400, 0)
357

358
        ' And the line segment is vertical.
359
        slv.AddConstraint(3, g, Slvs.SLVS_C_VERTICAL, _
360
            200, 0.0, 0, 0, 400, 0)
361

362
        ' And the distance from one endpoint to the origin is 15.0 units.
363
        slv.AddConstraint(4, g, Slvs.SLVS_C_PT_PT_DISTANCE, _
364
            200, 15.0, 301, 101, 0, 0)
365

366
        ' And same for the other endpoint; so if you add this constraint then
367
        ' the sketch is overconstrained and will signal an error.
368
        'slv.AddConstraint(5, g, Slvs.SLVS_C_PT_PT_DISTANCE, _
369
        '    200, 18.0, 302, 101, 0, 0)
370

371
        ' The arc and the circle have equal radius.
372
        slv.AddConstraint(6, g, Slvs.SLVS_C_EQUAL_RADIUS, _
373
            200, 0.0, 0, 0, 401, 402)
374

375
        ' The arc has radius 17.0 units.
376
        slv.AddConstraint(7, g, Slvs.SLVS_C_DIAMETER, _
377
            200, 2 * 17.0, 0, 0, 401, 0)
378

379
        ' If the solver fails, then ask it to report which constraints caused
380
        ' the problem.
381
        slv.Solve(g, 0, 0, 0, 0, True)
382

383
        If (slv.GetResult() = Slvs.SLVS_RESULT_OKAY) Then
384
            Console.WriteLine("solved okay")
385
            ' Note that we are referring to the parameters by their handles,
386
            ' and not by their index in the list. This is a difference from
387
            ' the C example.
388
            Console.WriteLine(String.Format( _
389
                "line from ({0:F3} {1:F3}) to ({2:F3} {3:F3})", _
390
                slv.GetParamByHandle(11), slv.GetParamByHandle(12), _
391
                slv.GetParamByHandle(13), slv.GetParamByHandle(14)))
392
            Console.WriteLine(String.Format( _
393
                "arc center ({0:F3} {1:F3}) start ({2:F3} {3:F3}) " + _
394
                    "finish ({4:F3} {5:F3})", _
395
                slv.GetParamByHandle(15), slv.GetParamByHandle(16), _
396
                slv.GetParamByHandle(17), slv.GetParamByHandle(18), _
397
                slv.GetParamByHandle(19), slv.GetParamByHandle(20)))
398
            Console.WriteLine(String.Format( _
399
                "circle center ({0:F3} {1:F3}) radius {2:F3}", _
400
                slv.GetParamByHandle(21), slv.GetParamByHandle(22), _
401
                slv.GetParamByHandle(23)))
402

403
            Console.WriteLine(slv.GetDof().ToString() + " DOF")
404
        Else
405
            Console.Write("solve failed; problematic constraints are:")
406
            Dim t As UInteger
407
            For Each t In slv.GetFaileds()
408
                Console.Write(" " + t.ToString())
409
            Next
410
            Console.WriteLine("")
411
            If (slv.GetResult() = Slvs.SLVS_RESULT_INCONSISTENT) Then
412
                Console.WriteLine("system inconsistent")
413
            Else
414
                Console.WriteLine("system nonconvergent")
415
            End If
416
        End If
417

418
    End Sub
419

420

421
    '''''''''''''''''''''''''''''''
422
    ' The interface to the library, and the wrapper functions around
423
    ' that interface, follow.
424

425
    ' These are the core functions imported from the DLL
426
    <DllImport("slvs.dll", CallingConvention:=CallingConvention.Cdecl)> _
427
    Public Sub Slvs_Solve(ByVal sys As IntPtr, ByVal hg As UInteger)
428
    End Sub
429

430
    <DllImport("slvs.dll", CallingConvention:=CallingConvention.Cdecl)> _
431
    Public Sub Slvs_MakeQuaternion(
432
        ByVal ux As Double, ByVal uy As Double, ByVal uz As Double,
433
        ByVal vx As Double, ByVal vy As Double, ByVal vz As Double,
434
        ByRef qw As Double, ByRef qx As Double, ByRef qy As Double,
435
            ByRef qz As Double)
436
    End Sub
437

438
    ' And this is a thin wrapper around those functions, which provides
439
    ' convenience functions similar to those provided in slvs.h for the C API.
440
    Public Class Slvs
441

442
        <StructLayout(LayoutKind.Sequential)> Public Structure Slvs_Param
443
            Public h As UInteger
444
            Public group As UInteger
445
            Public val As Double
446
        End Structure
447

448
        Public Const SLVS_FREE_IN_3D As Integer = 0
449

450
        Public Const SLVS_E_POINT_IN_3D As Integer = 50000
451
        Public Const SLVS_E_POINT_IN_2D As Integer = 50001
452
        Public Const SLVS_E_NORMAL_IN_3D As Integer = 60000
453
        Public Const SLVS_E_NORMAL_IN_2D As Integer = 60001
454
        Public Const SLVS_E_DISTANCE As Integer = 70000
455
        Public Const SLVS_E_WORKPLANE As Integer = 80000
456
        Public Const SLVS_E_LINE_SEGMENT As Integer = 80001
457
        Public Const SLVS_E_CUBIC As Integer = 80002
458
        Public Const SLVS_E_CIRCLE As Integer = 80003
459
        Public Const SLVS_E_ARC_OF_CIRCLE As Integer = 80004
460

461
        <StructLayout(LayoutKind.Sequential)> Public Structure Slvs_Entity
462
            Public h As UInteger
463
            Public group As UInteger
464

465
            Public type As Integer
466

467
            Public wrkpl As UInteger
468
            Public point0 As UInteger
469
            Public point1 As UInteger
470
            Public point2 As UInteger
471
            Public point3 As UInteger
472
            Public normal As UInteger
473
            Public distance As UInteger
474

475
            Public param0 As UInteger
476
            Public param1 As UInteger
477
            Public param2 As UInteger
478
            Public param3 As UInteger
479
        End Structure
480

481
        Public Const SLVS_C_POINTS_COINCIDENT As Integer = 100000
482
        Public Const SLVS_C_PT_PT_DISTANCE As Integer = 100001
483
        Public Const SLVS_C_PT_PLANE_DISTANCE As Integer = 100002
484
        Public Const SLVS_C_PT_LINE_DISTANCE As Integer = 100003
485
        Public Const SLVS_C_PT_FACE_DISTANCE As Integer = 100004
486
        Public Const SLVS_C_PT_IN_PLANE As Integer = 100005
487
        Public Const SLVS_C_PT_ON_LINE As Integer = 100006
488
        Public Const SLVS_C_PT_ON_FACE As Integer = 100007
489
        Public Const SLVS_C_EQUAL_LENGTH_LINES As Integer = 100008
490
        Public Const SLVS_C_LENGTH_RATIO As Integer = 100009
491
        Public Const SLVS_C_EQ_LEN_PT_LINE_D As Integer = 100010
492
        Public Const SLVS_C_EQ_PT_LN_DISTANCES As Integer = 100011
493
        Public Const SLVS_C_EQUAL_ANGLE As Integer = 100012
494
        Public Const SLVS_C_EQUAL_LINE_ARC_LEN As Integer = 100013
495
        Public Const SLVS_C_SYMMETRIC As Integer = 100014
496
        Public Const SLVS_C_SYMMETRIC_HORIZ As Integer = 100015
497
        Public Const SLVS_C_SYMMETRIC_VERT As Integer = 100016
498
        Public Const SLVS_C_SYMMETRIC_LINE As Integer = 100017
499
        Public Const SLVS_C_AT_MIDPOINT As Integer = 100018
500
        Public Const SLVS_C_HORIZONTAL As Integer = 100019
501
        Public Const SLVS_C_VERTICAL As Integer = 100020
502
        Public Const SLVS_C_DIAMETER As Integer = 100021
503
        Public Const SLVS_C_PT_ON_CIRCLE As Integer = 100022
504
        Public Const SLVS_C_SAME_ORIENTATION As Integer = 100023
505
        Public Const SLVS_C_ANGLE As Integer = 100024
506
        Public Const SLVS_C_PARALLEL As Integer = 100025
507
        Public Const SLVS_C_PERPENDICULAR As Integer = 100026
508
        Public Const SLVS_C_ARC_LINE_TANGENT As Integer = 100027
509
        Public Const SLVS_C_CUBIC_LINE_TANGENT As Integer = 100028
510
        Public Const SLVS_C_EQUAL_RADIUS As Integer = 100029
511
        Public Const SLVS_C_PROJ_PT_DISTANCE As Integer = 100030
512
        Public Const SLVS_C_WHERE_DRAGGED As Integer = 100031
513
        Public Const SLVS_C_CURVE_CURVE_TANGENT As Integer = 100032
514
        Public Const SLVS_C_LENGTH_DIFFERENCE As Integer = 100033
515

516
        <StructLayout(LayoutKind.Sequential)> Public Structure Slvs_Constraint
517
            Public h As UInteger
518
            Public group As UInteger
519

520
            Public type As Integer
521

522
            Public wrkpl As UInteger
523

524
            Public valA As Double
525
            Public ptA As UInteger
526
            Public ptB As UInteger
527
            Public entityA As UInteger
528
            Public entityB As UInteger
529
            Public entityC As UInteger
530
            Public entityD As UInteger
531

532
            Public other As Integer
533
            Public other2 As Integer
534
        End Structure
535

536
        Public Const SLVS_RESULT_OKAY As Integer = 0
537
        Public Const SLVS_RESULT_INCONSISTENT As Integer = 1
538
        Public Const SLVS_RESULT_DIDNT_CONVERGE As Integer = 2
539
        Public Const SLVS_RESULT_TOO_MANY_UNKNOWNS As Integer = 3
540

541
        <StructLayout(LayoutKind.Sequential)> Public Structure Slvs_System
542
            Public param As IntPtr
543
            Public params As Integer
544
            Public entity As IntPtr
545
            Public entities As Integer
546
            Public constraint As IntPtr
547
            Public constraints As Integer
548

549
            Public dragged0 As UInteger
550
            Public dragged1 As UInteger
551
            Public dragged2 As UInteger
552
            Public dragged3 As UInteger
553

554
            Public calculatedFaileds As Integer
555

556
            Public failed As IntPtr
557
            Public faileds As Integer
558

559
            Public dof As Integer
560

561
            Public result As Integer
562
        End Structure
563

564
        Dim Params As New List(Of Slvs_Param)
565
        Dim Entities As New List(Of Slvs_Entity)
566
        Dim Constraints As New List(Of Slvs_Constraint)
567

568
        Dim Faileds As New List(Of UInteger)
569

570
        Dim Result As Integer
571
        Dim Dof As Integer
572

573
        ' Return the value of a parameter, by its handle. This function
574
        ' may be used, for example, to obtain the new values of the
575
        ' parameters after a call to Solve().
576
        Public Function GetParamByHandle(ByVal h As UInteger) As Double
577
            Dim t As Slvs_Param
578
            For Each t In Params
579
                If (t.h = h) Then
580
                    Return t.val
581
                End If
582
            Next
583
            Throw New Exception("Invalid parameter handle.")
584
        End Function
585

586
        ' Return the value of a parameter, by its index in the list (where
587
        ' that index is determined by the order in which the parameters
588
        ' were inserted with AddParam(), not by its handle).
589
        Public Function GetParamByIndex(ByVal i As Integer) As Double
590
            Return Params(i).val
591
        End Function
592

593
        ' Get the result after a call to Solve(). This may be
594
        '   SLVS_RESULT_OKAY              - it worked
595
        '   SLVS_RESULT_INCONSISTENT      - failed, inconsistent
596
        '   SLVS_RESULT_DIDNT_CONVERGE    - consistent, but still failed
597
        '   SLVS_RESULT_TOO_MANY_UNKNOWNS - too many parameters in one group
598
        Public Function GetResult() As Integer
599
            Return Result
600
        End Function
601

602
        ' After a call to Solve(), this returns the number of unconstrained 
603
        ' degrees of freedom for the sketch.
604
        Public Function GetDof() As Integer
605
            Return Dof
606
        End Function
607

608
        ' After a failing call to Solve(), this returns the list of
609
        ' constraints, identified by their handle, that would fix the
610
        ' system if they were deleted. This list will be populated only
611
        ' if calculateFaileds is True in the Solve() call.
612
        Public Function GetFaileds() As List(Of UInteger)
613
            Return Faileds
614
        End Function
615

616
        ' Clear our lists of entities, constraints, and parameters.
617
        Public Sub ResetAll()
618
            Params.Clear()
619
            Entities.Clear()
620
            Constraints.Clear()
621
        End Sub
622

623

624
        '''''''''''''''''''''''''''''''
625
        ' These functions are broadly similar to the Slvs_Make...
626
        ' functions in slvs.h. See the file DOC.txt accompanying the
627
        ' library for details.
628

629
        Public Sub AddParam(ByVal h As UInteger, ByVal group As UInteger,
630
                            ByVal val As Double)
631
            Dim p As Slvs_Param
632
            p.h = h
633
            p.group = group
634
            p.val = val
635
            Params.Add(p)
636
        End Sub
637

638
        Public Sub AddPoint2d(ByVal h As UInteger, ByVal group As UInteger,
639
                              ByVal wrkpl As UInteger,
640
                              ByVal u As UInteger, ByVal v As UInteger)
641
            Dim e As Slvs_Entity
642
            e.h = h
643
            e.group = group
644
            e.type = SLVS_E_POINT_IN_2D
645
            e.wrkpl = wrkpl
646
            e.param0 = u
647
            e.param1 = v
648
            Entities.Add(e)
649
        End Sub
650

651
        Public Sub AddPoint3d(ByVal h As UInteger, ByVal group As UInteger,
652
                 ByVal x As UInteger, ByVal y As UInteger, ByVal z As UInteger)
653
            Dim e As Slvs_Entity
654
            e.h = h
655
            e.group = group
656
            e.type = SLVS_E_POINT_IN_3D
657
            e.wrkpl = SLVS_FREE_IN_3D
658
            e.param0 = x
659
            e.param1 = y
660
            e.param2 = z
661
            Entities.Add(e)
662
        End Sub
663

664
        Public Sub AddNormal3d(ByVal h As UInteger, ByVal group As UInteger,
665
                                    ByVal qw As UInteger, ByVal qx As UInteger,
666
                                    ByVal qy As UInteger, ByVal qz As UInteger)
667
            Dim e As Slvs_Entity
668
            e.h = h
669
            e.group = group
670
            e.type = SLVS_E_NORMAL_IN_3D
671
            e.wrkpl = SLVS_FREE_IN_3D
672
            e.param0 = qw
673
            e.param1 = qx
674
            e.param2 = qy
675
            e.param3 = qz
676
            Entities.Add(e)
677
        End Sub
678

679
        Public Sub AddNormal2d(ByVal h As UInteger, ByVal group As UInteger,
680
                               ByVal wrkpl As UInteger)
681
            Dim e As Slvs_Entity
682
            e.h = h
683
            e.group = group
684
            e.type = SLVS_E_NORMAL_IN_2D
685
            e.wrkpl = wrkpl
686
            Entities.Add(e)
687
        End Sub
688

689
        Public Sub AddDistance(ByVal h As UInteger, ByVal group As UInteger,
690
                               ByVal wrkpl As UInteger, ByVal d As UInteger)
691
            Dim e As Slvs_Entity
692
            e.h = h
693
            e.group = group
694
            e.type = SLVS_E_DISTANCE
695
            e.wrkpl = wrkpl
696
            e.param0 = d
697
            Entities.Add(e)
698
        End Sub
699

700
        Public Sub AddLineSegment(ByVal h As UInteger, ByVal group As UInteger,
701
                                  ByVal wrkpl As UInteger,
702
                                  ByVal ptA As UInteger, ByVal ptB As UInteger)
703
            Dim e As Slvs_Entity
704
            e.h = h
705
            e.group = group
706
            e.type = SLVS_E_LINE_SEGMENT
707
            e.wrkpl = wrkpl
708
            e.point0 = ptA
709
            e.point1 = ptB
710
            Entities.Add(e)
711
        End Sub
712

713
        Public Sub AddCubic(ByVal h As UInteger, ByVal group As UInteger,
714
                            ByVal wrkpl As UInteger,
715
                            ByVal pt0 As UInteger, ByVal pt1 As UInteger,
716
                            ByVal pt2 As UInteger, ByVal pt3 As UInteger)
717
            Dim e As Slvs_Entity
718
            e.h = h
719
            e.group = group
720
            e.type = SLVS_E_CUBIC
721
            e.wrkpl = wrkpl
722
            e.point0 = pt0
723
            e.point1 = pt1
724
            e.point2 = pt2
725
            e.point3 = pt3
726
            Entities.Add(e)
727
        End Sub
728

729
        Public Sub AddArcOfCircle(ByVal h As UInteger, ByVal group As UInteger,
730
                                  ByVal wrkpl As UInteger,
731
                                  ByVal normal As UInteger,
732
                                  ByVal center As UInteger,
733
                                  ByVal pstart As UInteger,
734
                                  ByVal pend As UInteger)
735
            Dim e As Slvs_Entity
736
            e.h = h
737
            e.group = group
738
            e.type = SLVS_E_ARC_OF_CIRCLE
739
            e.wrkpl = wrkpl
740
            e.normal = normal
741
            e.point0 = center
742
            e.point1 = pstart
743
            e.point2 = pend
744
            Entities.Add(e)
745
        End Sub
746

747
        Public Sub AddCircle(ByVal h As UInteger, ByVal group As UInteger,
748
                             ByVal wrkpl As UInteger,
749
                             ByVal center As UInteger, ByVal normal As UInteger,
750
                             ByVal radius As UInteger)
751
            Dim e As Slvs_Entity
752
            e.h = h
753
            e.group = group
754
            e.type = SLVS_E_CIRCLE
755
            e.wrkpl = wrkpl
756
            e.point0 = center
757
            e.normal = normal
758
            e.distance = radius
759
            Entities.Add(e)
760
        End Sub
761

762
        Public Sub AddWorkplane(ByVal h As UInteger, ByVal group As UInteger,
763
                                ByVal origin As UInteger,
764
                                ByVal normal As UInteger)
765
            Dim e As Slvs_Entity
766
            e.h = h
767
            e.group = group
768
            e.type = SLVS_E_WORKPLANE
769
            e.wrkpl = SLVS_FREE_IN_3D
770
            e.point0 = origin
771
            e.normal = normal
772
            Entities.Add(e)
773
        End Sub
774

775
        Public Sub AddConstraint(ByVal h As UInteger,
776
                                 ByVal group As UInteger,
777
                                 ByVal type As Integer,
778
                                 ByVal wrkpl As UInteger,
779
                                 ByVal valA As Double,
780
                                 ByVal ptA As UInteger,
781
                                 ByVal ptB As UInteger,
782
                                 ByVal entityA As UInteger,
783
                                 ByVal entityB As UInteger)
784
            Dim c As Slvs_Constraint
785
            c.h = h
786
            c.group = group
787
            c.type = type
788
            c.wrkpl = wrkpl
789
            c.valA = valA
790
            c.ptA = ptA
791
            c.ptB = ptB
792
            c.entityA = entityA
793
            c.entityB = entityB
794
            Constraints.Add(c)
795
        End Sub
796

797
        ' Solve the system. The geometry of the system must already have
798
        ' been specified through the Add...() calls. The result of the
799
        ' solution process may be obtained by calling GetResult(),
800
        ' GetFaileds(), GetDof(), and GetParamByXXX().
801
        '
802
        ' The parameters draggedx (indicated by their handles) will be held
803
        ' as close as possible to their original positions, even if this
804
        ' results in large moves for other parameters. This feature may be
805
        ' useful if, for example, the user is dragging the point whose
806
        ' location is defined by those parameters. Unused draggedx
807
        ' parameters may be specified as zero.
808
        Public Sub Solve(ByVal group As UInteger,
809
                         ByVal dragged0 As UInteger, ByVal dragged1 As UInteger,
810
                         ByVal dragged2 As UInteger, ByVal dragged3 As UInteger,
811
                         ByVal calculateFaileds As Boolean)
812
            Dim i As Integer
813

814
            Dim pp, p(Params.Count()) As Slvs_Param
815
            i = 0
816
            For Each pp In Params
817
                p(i) = pp
818
                i += 1
819
            Next
820

821
            Dim ee, e(Entities.Count()) As Slvs_Entity
822
            i = 0
823
            For Each ee In Entities
824
                e(i) = ee
825
                i += 1
826
            Next
827

828
            Dim cc, c(Constraints.Count()) As Slvs_Constraint
829
            i = 0
830
            For Each cc In Constraints
831
                c(i) = cc
832
                i += 1
833
            Next
834
            Dim f(Constraints.Count()) As UInteger
835

836
            Dim sys As Slvs_System
837

838
            Dim pgc, egc, cgc As GCHandle
839
            pgc = GCHandle.Alloc(p, GCHandleType.Pinned)
840
            sys.param = pgc.AddrOfPinnedObject()
841
            sys.params = Params.Count()
842
            egc = GCHandle.Alloc(e, GCHandleType.Pinned)
843
            sys.entity = egc.AddrOfPinnedObject()
844
            sys.entities = Entities.Count()
845
            cgc = GCHandle.Alloc(c, GCHandleType.Pinned)
846
            sys.constraint = cgc.AddrOfPinnedObject()
847
            sys.constraints = Constraints.Count()
848

849
            sys.dragged0 = dragged0
850
            sys.dragged1 = dragged1
851
            sys.dragged2 = dragged2
852
            sys.dragged3 = dragged3
853

854
            Dim fgc As GCHandle
855
            fgc = GCHandle.Alloc(f, GCHandleType.Pinned)
856
            If calculateFaileds Then
857
                sys.calculatedFaileds = 1
858
            Else
859
                sys.calculatedFaileds = 0
860
            End If
861
            sys.faileds = Constraints.Count()
862
            sys.failed = fgc.AddrOfPinnedObject()
863

864
            Dim sysgc As GCHandle
865
            sysgc = GCHandle.Alloc(sys, GCHandleType.Pinned)
866

867
            Slvs_Solve(sysgc.AddrOfPinnedObject(), group)
868

869
            sys = sysgc.Target
870

871
            For i = 0 To Params.Count() - 1
872
                Params(i) = p(i)
873
            Next
874

875
            Faileds.Clear()
876
            For i = 0 To sys.faileds - 1
877
                Faileds.Add(f(i))
878
            Next
879

880
            sysgc.Free()
881
            fgc.Free()
882
            pgc.Free()
883
            egc.Free()
884
            cgc.Free()
885

886
            Result = sys.result
887
            Dof = sys.dof
888
        End Sub
889
        ' A simpler version of the function, if the parameters being dragged
890
        ' correspond to a single point.
891
        Public Sub Solve(ByVal group As UInteger, ByVal dragged As Point,
892
                         ByVal calculatedFaileds As Boolean)
893
            If TypeOf dragged Is Point2d Then
894
                Dim p As Point2d
895
                p = dragged
896
                Solve(group, p.up.H, p.vp.H, 0, 0, calculatedFaileds)
897
            ElseIf TypeOf dragged Is Point3d Then
898
                Dim p As Point3d
899
                p = dragged
900
                Solve(group, p.xp.H, p.yp.H, p.zp.H, 0, calculatedFaileds)
901
            Else
902
                Throw New Exception("Can't get dragged params for point.")
903
            End If
904
        End Sub
905
        ' or if it's a single distance (e.g., the radius of a circle)
906
        Public Sub Solve(ByVal group As UInteger, ByVal dragged As Distance,
907
                         ByVal calculatedFaileds As Boolean)
908
            Solve(group, dragged.dp.H, 0, 0, 0, calculatedFaileds)
909
        End Sub
910
        ' or if it's nothing.
911
        Public Sub Solve(ByVal group As UInteger,
912
                         ByVal calculateFaileds As Boolean)
913
            Solve(group, 0, 0, 0, 0, calculateFaileds)
914
        End Sub
915

916
        ' Return the quaternion in (qw, qx, qy, qz) that represents a
917
        ' rotation from the base frame to a coordinate system with the
918
        ' specified basis vectors u and v. For example, u = (0, 1, 0)
919
        ' and v = (0, 0, 1) specifies the yz plane, such that a point with
920
        ' (u, v) = (7, 12) has (x, y, z) = (0, 7, 12).
921
        Public Sub MakeQuaternion(
922
            ByVal ux As Double, ByVal uy As Double, ByVal uz As Double,
923
            ByVal vx As Double, ByVal vy As Double, ByVal vz As Double,
924
            ByRef qw As Double, ByRef qx As Double, ByRef qy As Double,
925
                ByRef qz As Double)
926
            Slvs_MakeQuaternion(ux, uy, uz, _
927
                                vx, vy, vz, _
928
                                qw, qx, qy, qz)
929
        End Sub
930

931
        Public Function FreeIn3d()
932
            Return New Workplane(Me)
933
        End Function
934

935

936
        '''''''''''''''''''''''''''''''
937
        ' Functions to create the object-oriented wrappers defined below.
938

939
        Public Function NewParam(ByVal group As UInteger, ByVal val As Double)
940
            Return New Param(Me, group, val)
941
        End Function
942
        Public Function NewPoint2d(ByVal group As UInteger,
943
                                   ByVal wrkpl As Workplane,
944
                                   ByVal u As Double, ByVal v As Double)
945
            Return New Point2d(Me, group, wrkpl, u, v)
946
        End Function
947
        Public Function NewPoint2d(ByVal group As UInteger,
948
                                   ByVal wrkpl As Workplane,
949
                                   ByVal u As Param, ByVal v As Param)
950
            Return New Point2d(Me, group, wrkpl, u, v)
951
        End Function
952
        Public Function NewPoint3d(ByVal group As UInteger,
953
                                   ByVal x As Double,
954
                                   ByVal y As Double,
955
                                   ByVal z As Double)
956
            Return New Point3d(Me, group, x, y, z)
957
        End Function
958
        Public Function NewPoint3d(ByVal group As UInteger,
959
                                   ByVal x As Param,
960
                                   ByVal y As Param,
961
                                   ByVal z As Param)
962
            Return New Point3d(Me, group, x, y, z)
963
        End Function
964
        Public Function NewNormal3d(ByVal group As UInteger,
965
                    ByVal ux As Double, ByVal uy As Double, ByVal uz As Double,
966
                    ByVal vx As Double, ByVal vy As Double, ByVal vz As Double)
967
            Return New Normal3d(Me, group, ux, uy, uz, vx, vy, vz)
968
        End Function
969
        Public Function NewNormal3d(ByVal group As UInteger,
970
                                    ByVal qw As Param, ByVal qx As Param,
971
                                    ByVal qy As Param, ByVal qz As Param)
972
            Return New Normal3d(Me, group, qw, qx, qy, qz)
973
        End Function
974
        Public Function NewNormal2d(ByVal group As UInteger,
975
                                    ByVal wrkpl As Workplane)
976
            Return New Normal2d(Me, group, wrkpl)
977
        End Function
978
        Public Function NewDistance(ByVal group As UInteger,
979
                                    ByVal wrkpl As Workplane, ByVal d As Double)
980
            Return New Distance(Me, group, wrkpl, d)
981
        End Function
982
        Public Function NewDistance(ByVal group As UInteger,
983
                                    ByVal wrkpl As Workplane, ByVal d As Param)
984
            Return New Distance(Me, group, wrkpl, d)
985
        End Function
986
        Public Function NewLineSegment(ByVal group As UInteger,
987
                                       ByVal wrkpl As Workplane,
988
                                       ByVal ptA As Point, ByVal ptB As Point)
989
            Return New LineSegment(Me, group, wrkpl, ptA, ptB)
990
        End Function
991
        Public Function NewArcOfCircle(ByVal group As UInteger,
992
                                       ByVal wrkpl As Workplane,
993
                                       ByVal normal As Normal,
994
                                       ByVal center As Point,
995
                                       ByVal pstart As Point,
996
                                       ByVal pend As Point)
997
            Return New ArcOfCircle(Me, group, wrkpl, normal, _
998
                                   center, pstart, pend)
999
        End Function
1000
        Public Function NewCircle(ByVal group As UInteger,
1001
                                  ByVal wrkpl As Workplane,
1002
                                  ByVal center As Point,
1003
                                  ByVal normal As Normal,
1004
                                  ByVal radius As Distance)
1005
            Return New Circle(Me, group, wrkpl, center, normal, radius)
1006
        End Function
1007
        Public Function NewWorkplane(ByVal group As UInteger,
1008
                                     ByVal origin As Point,
1009
                                     ByVal normal As Normal)
1010
            Return New Workplane(Me, group, origin, normal)
1011
        End Function
1012

1013
        Public Sub AddConstraint(ByVal H As UInteger, ByVal group As UInteger,
1014
                                 ByVal type As Integer,
1015
                                 ByVal wrkpl As Workplane,
1016
                                 ByVal valA As Double,
1017
                                 ByVal ptA As Point, ByVal ptB As Point,
1018
                                 ByVal entityA As Entity,
1019
                                 ByVal entityB As Entity)
1020
            AddConstraint(H, group, type, _
1021
                              If(IsNothing(wrkpl), 0, wrkpl.H), _
1022
                              valA, _
1023
                              If(IsNothing(ptA), 0, ptA.H), _
1024
                              If(IsNothing(ptB), 0, ptB.H), _
1025
                              If(IsNothing(entityA), 0, entityA.H), _
1026
                              If(IsNothing(entityB), 0, entityB.H))
1027
        End Sub
1028

1029

1030
        '''''''''''''''''''''''''''''''
1031
        ' The object-oriented wrapper classes themselves, to allow the
1032
        ' representation of entities and constraints as .net objects, not
1033
        ' integer handles. These don't do any work themselves, beyond
1034
        ' allocating and storing a unique integer handle.
1035
        '
1036
        ' These functions will assign parameters and entities with
1037
        ' consecutive handles starting from 1. If they are intermixed
1038
        ' with parameters and entities with user-specified handles, then
1039
        ' those handles must be chosen not to conflict, e.g. starting
1040
        ' from 100 000 or another large number.
1041

1042
        Public Class Param
1043
            Public Slv As Slvs
1044
            Public H As UInteger
1045

1046
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1047
                           ByVal val As Double)
1048
                Slv = s
1049
                H = Slv.Params.Count() + 1
1050
                Slv.AddParam(H, group, val)
1051
            End Sub
1052
        End Class
1053

1054
        Public MustInherit Class Entity
1055
            Public Slv As Slvs
1056
            Public H As UInteger
1057

1058
            Public Sub New(ByVal s As Slvs)
1059
                Slv = s
1060
                H = Slv.Entities.Count() + 1
1061
            End Sub
1062
        End Class
1063

1064
        Public MustInherit Class Point
1065
            Inherits Entity
1066
            Public Sub New(ByVal s As Slvs)
1067
                MyBase.New(s)
1068
            End Sub
1069
        End Class
1070

1071
        Public MustInherit Class Normal
1072
            Inherits Entity
1073
            Public Sub New(ByVal s As Slvs)
1074
                MyBase.New(s)
1075
            End Sub
1076
        End Class
1077

1078
        Public Class Point2d
1079
            Inherits Point
1080
            Public up, vp As Param
1081
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1082
                           ByVal wrkpl As Workplane,
1083
                           ByVal u As Double, ByVal v As Double)
1084
                MyBase.New(s)
1085
                up = New Param(Slv, group, u)
1086
                vp = New Param(Slv, group, v)
1087
                Slv.AddPoint2d(H, group, wrkpl.H, up.H, vp.H)
1088
            End Sub
1089
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1090
                           ByVal wrkpl As Workplane,
1091
                           ByVal u As Param, ByVal v As Param)
1092
                MyBase.New(s)
1093
                Slv.AddPoint2d(H, group, wrkpl.H, u.H, v.H)
1094
                up = u
1095
                vp = v
1096
            End Sub
1097
            Function GetU()
1098
                Return Slv.GetParamByHandle(up.H)
1099
            End Function
1100
            Function GetV()
1101
                Return Slv.GetParamByHandle(vp.H)
1102
            End Function
1103
        End Class
1104

1105
        Public Class Point3d
1106
            Inherits Point
1107
            Public xp, yp, zp As Param
1108
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1109
                           ByVal x As Double, ByVal y As Double,
1110
                           ByVal z As Double)
1111
                MyBase.New(s)
1112
                xp = New Param(Slv, group, x)
1113
                yp = New Param(Slv, group, y)
1114
                zp = New Param(Slv, group, z)
1115
                Slv.AddPoint3d(H, group, xp.H, yp.H, zp.H)
1116
            End Sub
1117
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1118
                           ByVal x As Param, ByVal y As Param, ByVal z As Param)
1119
                MyBase.New(s)
1120
                Slv.AddPoint3d(H, group, x.H, y.H, z.H)
1121
                xp = x
1122
                yp = y
1123
                zp = z
1124
            End Sub
1125
            Function GetX()
1126
                Return Slv.GetParamByHandle(xp.H)
1127
            End Function
1128
            Function GetY()
1129
                Return Slv.GetParamByHandle(yp.H)
1130
            End Function
1131
            Function GetZ()
1132
                Return Slv.GetParamByHandle(zp.H)
1133
            End Function
1134
        End Class
1135

1136
        Public Class Normal3d
1137
            Inherits Normal
1138
            Dim qwp, qxp, qyp, qzp As Param
1139
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1140
                   ByVal ux As Double, ByVal uy As Double, ByVal uz As Double,
1141
                   ByVal vx As Double, ByVal vy As Double, ByVal vz As Double)
1142
                MyBase.New(s)
1143
                Dim qw, qx, qy, qz As Double
1144
                Slv.MakeQuaternion(ux, uy, uz, vx, vy, vz, qw, qx, qy, qz)
1145
                qwp = New Param(Slv, group, qw)
1146
                qxp = New Param(Slv, group, qx)
1147
                qyp = New Param(Slv, group, qy)
1148
                qzp = New Param(Slv, group, qz)
1149
                Slv.AddNormal3d(H, group, qwp.H, qxp.H, qyp.H, qzp.H)
1150
            End Sub
1151
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1152
                           ByVal qw As Param, ByVal qx As Param,
1153
                           ByVal qy As Param, ByVal qz As Param)
1154
                MyBase.New(s)
1155
                Slv.AddNormal3d(H, group, qw.H, qx.H, qy.H, qz.H)
1156
                qwp = qw
1157
                qxp = qx
1158
                qyp = qy
1159
                qzp = qz
1160
            End Sub
1161
        End Class
1162

1163
        Public Class Normal2d
1164
            Inherits Normal
1165
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1166
                           ByVal wrkpl As Workplane)
1167
                MyBase.New(s)
1168
                Slv.AddNormal2d(H, group, wrkpl.H)
1169
            End Sub
1170
        End Class
1171

1172
        Public Class Distance
1173
            Inherits Entity
1174
            Public dp As Param
1175

1176
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1177
                           ByVal wrkpl As Workplane, ByVal d As Double)
1178
                MyBase.New(s)
1179
                dp = New Param(Slv, group, d)
1180
                Slv.AddDistance(H, group, wrkpl.H, dp.H)
1181
            End Sub
1182
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1183
                           ByVal wrkpl As Workplane, ByVal d As Param)
1184
                MyBase.New(s)
1185
                Slv.AddDistance(H, group, wrkpl.H, d.H)
1186
                dp = d
1187
            End Sub
1188
            Function GetDistance() As Double
1189
                Return Slv.GetParamByHandle(dp.H)
1190
            End Function
1191
        End Class
1192

1193
        Public Class LineSegment
1194
            Inherits Entity
1195
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1196
                           ByVal wrkpl As Workplane,
1197
                           ByVal ptA As Point, ByVal ptB As Point)
1198
                MyBase.New(s)
1199
                Slv.AddLineSegment(H, group, wrkpl.H, ptA.H, ptB.H)
1200
            End Sub
1201
        End Class
1202

1203
        Public Class Cubic
1204
            Inherits Entity
1205
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1206
                           ByVal wrkpl As Workplane,
1207
                           ByVal pt0 As Point, ByVal pt1 As Point,
1208
                           ByVal pt2 As Point, ByVal pt3 As Point)
1209
                MyBase.New(s)
1210
                Slv.AddCubic(H, group, wrkpl.H, pt0.H, pt1.H, pt2.H, pt3.H)
1211
            End Sub
1212
        End Class
1213

1214
        Public Class ArcOfCircle
1215
            Inherits Entity
1216
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1217
                           ByVal wrkpl As Workplane, ByVal normal As Normal,
1218
                           ByVal center As Point, ByVal pstart As Point,
1219
                           ByVal pend As Point)
1220
                MyBase.New(s)
1221
                Slv.AddArcOfCircle(H, group, wrkpl.H, normal.H, _
1222
                                   center.H, pstart.H, pend.H)
1223
            End Sub
1224
        End Class
1225

1226
        Public Class Circle
1227
            Inherits Entity
1228
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1229
                           ByVal wrkpl As Workplane, ByVal center As Point,
1230
                           ByVal normal As Normal, ByVal radius As Distance)
1231
                MyBase.New(s)
1232
                Slv.AddCircle(H, group, wrkpl.H, center.H, normal.H, radius.H)
1233
            End Sub
1234
        End Class
1235

1236
        Public Class Workplane
1237
            Inherits Entity
1238
            Public Sub New(ByVal s As Slvs)
1239
                MyBase.New(s)
1240
                H = SLVS_FREE_IN_3D
1241
            End Sub
1242
            Public Sub New(ByVal s As Slvs, ByVal group As UInteger,
1243
                           ByVal origin As Point, ByVal normal As Normal)
1244
                MyBase.New(s)
1245
                Slv.AddWorkplane(H, group, origin.H, normal.H)
1246
            End Sub
1247
        End Class
1248

1249
    End Class
1250

1251
End Module
1252

1253

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.