ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magicsld/PoGCode.vb
Revision: 47
Committed: Wed Aug 22 20:50:41 2007 UTC (17 years, 8 months ago) by lacroix
File size: 124611 byte(s)
Log Message:
Mise a jour: méthode préé-optimisation automatique et manuelle

File Contents

# Content
1 Imports System
2 Imports System.IO
3 Module PoGCode
4 Private TabPoints(,) As Double
5 Private tabpointsface() As SldWorks.Face2
6 Private tabpointsedge() As SldWorks.Edge
7 Private tabpointsVertex() As SldWorks.Vertex
8 Private Tabface() As SldWorks.Face2
9 Private TabVertex(,) As Double
10 Private TabVertexDouble(,) As Double
11 Private TabFaceDouble(,) As Double
12 Private TabEdgeDouble(,) As Double
13 Private TabEdge() As SldWorks.Edge
14 Private cptVertex As Long
15 Private cpt As Long
16 Private vBodies As Object
17 Private swbody As SldWorks.Body2
18 Private Class retrait_mat
19 Public face As SldWorks.Face2
20 Public diametre As Double
21 Public Sub New(ByRef fac As SldWorks.Face2, ByVal diam As Double)
22 face = fac
23 diametre = diam
24 End Sub
25 End Class
26 Private Tabretrait_mat() As retrait_mat
27
28
29 'le programme fonction de la manière suivante :
30 ' - on va tout d'abord initialiser toutes les entités du modèle comme
31 ' ayant un coefficient de raffinement de maillage = 1
32 ' - Ensuite on va utiliser les algorithmes de detections des caractéristiques de forme
33 ' le coefficient de raffinement de maillage de chaque entité repérée est changé
34 ' - on créée ensuite les points d'échantillonnage en commencant par les sommets repérés
35 ' puis les arêtes puis les faces.
36 ' - La grille vérifie que qu'on ne place pas trop de points d'échantillonnage et
37 ' elle est initialisée sur la boite englobante du modèle
38 ' - Si l'utilisateur la préciser on génère des points d'échantillonnage dans le volume
39 ' la fonction functionvolume permet de rajouter ou de modifier la fonctionnelle de répartition
40 ' - Tous les points d'échantillonnage créés se retrouvent dans "tabpoint"
41 ' on écrit le fichier des points d'échantillonnage à partir de se tableau
42
43 Public Function DebutManuel(ByVal Eng As Double, ByVal NbCouches As Integer, ByVal ArrondiBool As Boolean, ByVal Arrondis As Double, ByVal rentrantBool As Boolean, ByVal rentrant As Double, ByVal matiereBool As Boolean, ByVal matiere As Double, ByVal entitésbool As Boolean, ByVal entités As SldWorks.PropertyManagerPageSelectionbox, ByVal Entities As Double, ByVal RaffInd As Boolean) As String
44 Dim frequence As Integer
45 Dim vbody As Object
46 Dim grill As New grille
47 Dim Bbox() As Double
48 Dim path As String
49
50
51 Dim CMDialogl As New Windows.Forms.SaveFileDialog
52 CMDialogl.DefaultExt = ".txt"
53 CMDialogl.Filter = "Fichiers PoG (*.txt)|*.txt|Tout fichiers(*.*)|*.*"
54
55 CMDialogl.OverwritePrompt = True
56 CMDialogl.Title = "Sélectionnez le fichier pour enregistrer les points"
57 CMDialogl.ShowDialog()
58 path = CMDialogl.FileName
59 path = Txtpath(path)
60 If path Is Nothing Or path = "" Then MsgBox("Aucun fichier sélectionné, sortie du programme!", MsgBoxStyle.Critical, "Erreur!") : Return ""
61
62 'MsgBox("Début de la routine de pré-optimisation" & vbCr & vbCr & "l'écart nodal global est de : " & Eng & vbCr & "La zone de transition : " & NbCouches & vbCr & "Les arrondis sont à : " & Arrondis & vbCr & "Arretes rentrantes: " & rentrant & vbCr & "Les retraits matière: " & matiere & vbCr & vbCr & "Arrondi = " & ArrondiBool & vbCr & "Rentrant = " & rentrantBool & vbCr & "Matiere = " & matiereBool)
63 vBodies = swPart.GetBodies2(SwConst.swBodyType_e.swAllBodies, True)
64 For Each vbody In vBodies
65 cpt = 0
66 Erase TabPoints
67 Erase Tabface
68 Erase TabFaceDouble
69 Erase TabEdge
70 Erase TabEdgeDouble
71
72 swbody = vbody
73 BoiteEnglobante()
74 initialisation()
75
76 'initialistation de la grille
77 Dim Coeffmin As Double = Math.Min(Math.Min(Arrondis, matiere), Math.Min(rentrant, Entities))
78 Dim taillecase As Double = Eng * (1 - Coeffmin)
79 Bbox = swbody.GetBodyBox
80 ' on initialise la grille 0.5 pourcent supérieur à la bounding box
81 grill.initialiser(Bbox(0) - (Bbox(3) - Bbox(0)) * 0.005, Bbox(1) - (Bbox(4) - Bbox(1)) * 0.005, Bbox(2) - (Bbox(5) - Bbox(2)) * 0.005, Bbox(3) + (Bbox(3) - Bbox(0)) * 0.005, Bbox(4) + (Bbox(4) - Bbox(1)) * 0.005, Bbox(5) + (Bbox(5) - Bbox(2)) * 0.005, Int((Bbox(3) - Bbox(0) + 2 * (Bbox(3) - Bbox(0)) * 0.005) / taillecase), Int((Bbox(4) - Bbox(1) + 2 * (Bbox(4) - Bbox(1)) * 0.005) / taillecase), Int((Bbox(5) - Bbox(2) + 2 * (Bbox(5) - Bbox(2)) * 0.005) / taillecase))
82
83 ' si la case arrondis est cochée
84 If ArrondiBool = True Then
85 testArrondis(Arrondis) 'i * 0.1)
86 End If
87 ' Si la case retrait matiere est cochée
88 If matiereBool = True Then
89 testretraitMatiere(matiere)
90 End If
91 ' si la case rentrant est cochée
92 If rentrantBool = True Then
93 testAngleMatiere(rentrant)
94 End If
95 ' si la case entités est cochée
96 If entitésbool = True Then
97 If Enregistrement.selectionpog.GetSelectionFocus = True Then
98 entitéselection(Entities, RaffInd)
99 End If
100 End If
101 ' on crée les points d'échantillonnage sur les sommets
102 CreerPointsVertex(Eng, grill)
103 ' on crée les points d'échantillonnage sur les arêtes
104 CreerPointsEdge(Eng, grill)
105 ' on crée les points d'échantillonnage sur les faces
106 CreerPointsFace(Eng, grill)
107
108 If NbCouches <> 0 Then
109 CreerPointsVolume(Eng, NbCouches, grill)
110 End If
111 ' on crée les points d'échantillonnage dans le volume
112
113 'Remarque, selon l'ordre, on obtient pas le même fichier d'échantillonage
114 ' on peut changé l'ordre selon la convenence de l'utilisateur
115
116 ' on créée le fichier d'échantillonnage
117 fichiertxt(Eng, path)
118 swModel.ClearSelection2(True)
119 testPog(False, False, False, True, False)
120 Return path
121 Next vbody
122
123 End Function
124
125 ''' <summary>
126 ''' Function POur traiter la préoptimisation de façon automatique
127 ''' </summary>
128 ''' <param name="Erx">Premier paramètre</param>
129 ''' <param name="LimPT">youjhou</param>
130 ''' <returns></returns>
131 ''' <remarks></remarks>
132 Public Function DebutAutomatique(ByVal Erx As Double, ByVal LimPT As Double) As String
133
134 Dim vbody As Object
135 Dim grill As New grille
136 Dim Bbox() As Double
137 Dim path As String
138 Dim Eng As Double
139 Dim coef_min As Double
140 Erx = (100 - Erx) / 100 ' valeur d'erreur d'analyse exacte a priori
141
142
143 Dim CMDialogl As New Windows.Forms.SaveFileDialog
144 CMDialogl.DefaultExt = ".txt"
145 CMDialogl.Filter = "Fichiers PoG (*.txt)|*.txt|Tout fichiers(*.*)|*.*"
146
147 CMDialogl.OverwritePrompt = True
148 CMDialogl.Title = "Sélectionnez le fichier pour enregistrer les points"
149 CMDialogl.ShowDialog()
150 path = CMDialogl.FileName
151 path = Txtpath(path)
152 If path Is Nothing Or path = "" Then MsgBox("Aucun fichier sélectionné, sortie du programme!", MsgBoxStyle.Critical, "Erreur!") : Return ""
153
154 vBodies = swPart.GetBodies2(SwConst.swBodyType_e.swAllBodies, True)
155 For Each vbody In vBodies
156 cpt = 0
157 Erase TabPoints
158 Erase Tabface
159 Erase TabFaceDouble
160 Erase TabEdge
161 Erase TabEdgeDouble
162
163 swbody = vbody
164 BoiteEnglobante()
165 initialisation()
166
167 'Calul de Eng
168 Eng = determination_ecart_nodal_global_retraits_mat(Erx, coef_min)
169
170
171 'initialistation de la grille
172
173 Dim taillecase As Double = Eng * (1 - coef_min)
174 Bbox = swbody.GetBodyBox
175 ' on initialise la grille 0.5 pourcent supérieur à la bounding box
176 grill.initialiser(Bbox(0) - (Bbox(3) - Bbox(0)) * 0.005, Bbox(1) - (Bbox(4) - Bbox(1)) * 0.005, Bbox(2) - (Bbox(5) - Bbox(2)) * 0.005, Bbox(3) + (Bbox(3) - Bbox(0)) * 0.005, Bbox(4) + (Bbox(4) - Bbox(1)) * 0.005, Bbox(5) + (Bbox(5) - Bbox(2)) * 0.005, Int((Bbox(3) - Bbox(0) + 2 * (Bbox(3) - Bbox(0)) * 0.005) / taillecase), Int((Bbox(4) - Bbox(1) + 2 * (Bbox(4) - Bbox(1)) * 0.005) / taillecase), Int((Bbox(5) - Bbox(2) + 2 * (Bbox(5) - Bbox(2)) * 0.005) / taillecase))
177
178
179 raffinement_retrait_matiere(Eng, Erx, LimPT)
180
181
182 ' on crée les points d'échantillonnage sur les sommets
183 CreerPointsVertex(Eng, grill)
184 ' on crée les points d'échantillonnage sur les arêtes
185 CreerPointsEdge(Eng, grill)
186 ' on crée les points d'échantillonnage sur les faces
187 CreerPointsFace(Eng, grill)
188
189
190 ' on créée le fichier d'échantillonnage
191 fichiertxt(Eng, path)
192 swModel.ClearSelection2(True)
193 testPog(False, False, False, True, False)
194 Return path
195 Next vbody
196 End Function
197
198 Sub entitéselection(ByRef coeff As Double, ByRef Ind As Boolean)
199 Dim swSelMgr As SldWorks.SelectionMgr
200 Dim i As Integer
201 Dim swent As SldWorks.Entity
202 Dim swvertex As SldWorks.Vertex
203 Dim point() As Double
204 Dim type As String
205 Dim tabface() As SldWorks.Face2
206 Dim SelfaceBool As Boolean = False
207 Dim cptface As Integer = 0
208 Dim selAreteBool As Boolean = False
209 Dim tabArete() As SldWorks.Edge
210 Dim cptarete As Integer = 0
211 Dim selSommetBool As Boolean = False
212 Dim tabSommet() As SldWorks.Vertex
213 Dim cptsommet As Integer = 0
214
215
216 swSelMgr = swModel.SelectionManager
217 For i = 1 To swSelMgr.GetSelectedObjectCount
218 swent = swSelMgr.GetSelectedObject5(i)
219 type = swent.GetType
220 Select Case type
221 Case "2"
222 ReDim Preserve tabface(cptface)
223 tabface(cptface) = swent
224 cptface = cptface + 1
225 SelfaceBool = True
226 Case "1"
227 ReDim Preserve tabArete(cptarete)
228 tabArete(cptarete) = swent
229 cptarete = cptarete + 1
230 selAreteBool = True
231 Case "3"
232 ReDim Preserve tabSommet(cptsommet)
233 tabSommet(cptsommet) = swent
234 cptsommet = cptsommet + 1
235 selSommetBool = True
236 End Select
237 Next i
238 swModel.ClearSelection2(True)
239
240 If selSommetBool = True Then
241 For i = 0 To UBound(tabSommet)
242 swent = tabSommet(i)
243 If Ind = True Then
244 coeff = InputBox("coefficient de raffinement : ", "coefficient de raffinement", 0.1)
245 While coeff < 0 Or coeff > 1
246 coeff = InputBox("le coefficient doit être compris entre 0 et 1 excluent" & "coefficient de raffinement : ", "coefficient de raffinement", 0.1)
247 End While
248 End If
249 swvertex = swent
250 point = swvertex.GetPoint()
251 ReDim Preserve TabVertex(2, cptVertex)
252 ReDim Preserve TabVertexDouble(2, cptVertex)
253 TabVertex(0, cptVertex) = point(0)
254 TabVertex(1, cptVertex) = point(1)
255 TabVertex(2, cptVertex) = point(2)
256 TabVertexDouble(0, cptVertex) = coeff
257 cptVertex = cptVertex + 1
258 Next
259 End If
260
261 If selAreteBool = True Then
262 For i = 0 To UBound(tabArete)
263 swent = tabArete(i)
264 swent.Select(False)
265 If Ind = True Then
266 coeff = InputBox("coefficient de raffinement : ", "coefficient de raffinement", 0.1)
267 While coeff < 0 Or coeff > 1
268 coeff = InputBox("le coefficient doit être compris entre 0 et 1 excluent" & "coefficient de raffinement : ", "coefficient de raffinement", 0.1)
269 End While
270 End If
271 ChangeTabEdge(swent, coeff)
272 Next
273 End If
274
275 If SelfaceBool = True Then
276 For i = 0 To UBound(tabface)
277 swent = tabface(i)
278 swent.Select(False)
279 If Ind = True Then
280 coeff = InputBox("coefficient de raffinement : ", "coefficient de raffinement", 0.1)
281 While coeff < 0 Or coeff > 1
282 coeff = InputBox("le coefficient doit être compris entre 0 et 1 excluent" & "coefficient de raffinement : ", "coefficient de raffinement", 0.1)
283 End While
284 End If
285 ChangeTabFace(swent, coeff)
286 Next
287 End If
288
289
290 End Sub
291 Sub test()
292 Dim Actform As New pogtest
293 Actform.Show()
294 End Sub
295 Public Sub testPog(ByRef a As Boolean, ByRef b As Boolean, ByRef c As Boolean, ByRef d As Boolean, ByRef e As Boolean)
296 Dim vBodies As Object
297 Dim vbody As Object
298 Dim swbody As SldWorks.Body2
299 Dim vBoundingBox() As Double
300 Dim xmin, XMax, ymin, YMax, zmin, ZMax As Double
301 Dim facecount As Integer
302 Dim edgecount As Integer
303 Dim vertexcount As Integer
304 Dim cpt1 As Long
305 Dim Cpt2 As Long
306 Dim swent As SldWorks.Entity
307 Dim swSelMgr As SldWorks.SelectionMgr
308 Dim swSelData As SldWorks.SelectData
309
310 If cpt = 0 Then
311 If a = True Or b = True Or d = True Then
312 MsgBox("pas de points d'échantillonnage")
313 End If
314 End If
315
316 vBodies = swPart.GetBodies2(SwConst.swBodyType_e.swAllBodies, True)
317 For Each vbody In vBodies
318 swbody = vbody
319
320 If a = True Then
321 swSelMgr = swModel.SelectionManager
322 swSelData = swSelMgr.CreateSelectData
323 swModel.ClearSelection2(True)
324 If cpt <> 0 Then
325 For cpt1 = 0 To UBound(Tabface)
326 If TabFaceDouble(0, cpt1) <> 1 Then
327 facecount = facecount + 1
328 swent = Tabface(cpt1)
329 swent.Select4(True, swSelData)
330 End If
331 Next cpt1
332 For cpt1 = 0 To UBound(TabEdge)
333 If TabEdgeDouble(0, cpt1) <> 1 Then
334 edgecount = edgecount + 1
335 swent = TabEdge(cpt1)
336 swent.Select4(True, swSelData)
337 End If
338 Next cpt1
339 For cpt1 = 0 To UBound(TabVertexDouble, 2)
340 If TabVertexDouble(0, cpt1) <> 1 Then
341 vertexcount = vertexcount + 1
342 End If
343 Next cpt1
344 End If
345 End If
346
347 If b = True Then
348 If cpt <> 0 Then
349 montrerpoints()
350 End If
351 End If
352
353 If d = True Then
354 If cpt <> 0 Then
355 For cpt1 = 0 To UBound(Tabface)
356 If TabFaceDouble(0, cpt1) <> 1 Then
357 facecount = facecount + 1
358 End If
359 Next cpt1
360 For cpt1 = 0 To UBound(TabEdge)
361 If TabEdgeDouble(0, cpt1) <> 1 Then
362 edgecount = edgecount + 1
363 End If
364 Next cpt1
365 For cpt1 = 0 To UBound(TabVertexDouble, 2)
366 If TabVertexDouble(0, cpt1) <> 1 Then
367 vertexcount = vertexcount + 1
368 End If
369 Next cpt1
370 Dim cptpointssommet As Long
371 Dim cptpointsarete As Long = 0
372 Dim cptpointsface As Long = 0
373 Dim cptpointsvolume As Long = 0
374 For Cpt2 = 1 To cpt
375 If TabPoints(4, Cpt2) = 0 Then cptpointssommet = cptpointssommet + 1
376 If TabPoints(4, Cpt2) = 1 Then cptpointsarete = cptpointsarete + 1
377 If TabPoints(4, Cpt2) = 2 Then cptpointsface = cptpointsface + 1
378 If TabPoints(4, Cpt2) = 3 Then cptpointsvolume = cptpointsvolume + 1
379 Next
380 'MsgBox(cpt & " Points créés sur : " & Chr(10) & facecount & " faces" & " -> " & cptpointsface & " points" & Chr(10) & edgecount & " aretes" & " -> " & cptpointsarete & " points" & Chr(10) & vertexcount & " sommets" & " -> " & cptpointssommet & " points" & Chr(10) & cptpointsvolume & " points dans le volume")
381 End If
382 End If
383
384 If c = True Then
385 vBoundingBox = swbody.GetBodyBox
386 xmin = vBoundingBox(0)
387 XMax = vBoundingBox(3)
388 ymin = vBoundingBox(1)
389 YMax = vBoundingBox(4)
390 zmin = vBoundingBox(2)
391 ZMax = vBoundingBox(5)
392 'MsgBox("Xmin : " & Format(xmin, "0.0000") & Chr(9) & "Xmax : " & Format(XMax, "0.0000") & Chr(9) & "deltaX : " & Format((XMax - xmin), "0.0000") & Chr(10) & "Ymin : " & Format(ymin, "0.0000") & Chr(9) & "Ymax : " & Format(YMax, "0.0000") & Chr(9) & "deltaY : " & Format((YMax - ymin), "0.0000") & Chr(10) & "Zmin : " & Format(zmin, "0.0000") & Chr(9) & "Zmax : " & Format(ZMax, "0.0000") & Chr(9) & "deltaZ : " & Format((ZMax - zmin), "0.0000"))
393 End If
394 'Format(TabPoints(0, cpt1), "0.0000000e+00")
395 Next vbody
396
397 If e = True Then
398 Dim path As String
399 Dim CMDialogl As New Windows.Forms.OpenFileDialog
400 CMDialogl.ShowDialog()
401 path = CMDialogl.FileName
402 'MsgBox("Ne fonctionne pas encore")
403 If File.Exists(path) Then
404 lire_fichier_ech(path)
405 Else
406 MsgBox("fichier inexistant")
407 End If
408 End If
409
410 End Sub
411 Sub testArrondis(ByRef coeff As Double)
412
413 Dim swface As SldWorks.Face2
414 Dim swfeat As SldWorks.Feature
415 Dim FeatType As String
416 Dim cpt1 As Integer
417 Dim lmbd_arr As Integer
418 Dim courb_arr As Double
419 lmbd_arr = 5
420 courb_arr = 1
421
422 swface = swbody.GetFirstFace
423 ' on parcours les faces si la feature est un congé on execute la sous routine arrondi
424 For cpt1 = 0 To swbody.GetFaceCount - 1
425 swfeat = swface.GetFeature
426 FeatType = swfeat.GetTypeName
427 If FeatType = "Fillet" Or FeatType = "VarFillet" Then
428 Select Case Arrondi(swface)
429 Case 1
430 ' on creer les points sur la face si c est un arrondi
431 ChangeTabFace(swface, coeff, lmbd_arr, courb_arr)
432 ' si les congé ne sont pas des arrondis on verifie qu'il ne soit pas leur prolongement avec arrondi voisin
433 Case 2
434 If arrondivoisin(swface) = True Then
435 ChangeTabFace(swface, coeff, lmbd_arr, courb_arr)
436 End If
437 Case Else
438 End Select
439 End If
440 swface = swface.GetNextFace
441 Next cpt1
442
443 End Sub
444 Sub testretraitMatiere(ByRef coeff As Double)
445
446 Dim swface As SldWorks.Face2
447 Dim swsurface As SldWorks.Surface
448 Dim swfaceref As SldWorks.Face2
449 Dim swfeat As SldWorks.Feature
450 Dim swloop As SldWorks.Loop2
451 Dim cpt1 As Integer
452 Dim cpt2 As Integer
453 Dim swedge As SldWorks.Edge
454 Dim vedge As Object
455 Dim vface As Object
456 Dim cpt3 As Integer
457 Dim i As Integer
458 Dim swent As SldWorks.Entity
459 Dim bRet As Boolean
460 Dim lmbd_rm As Double = 4
461 Dim courb_rm As Double = 0
462
463 swfaceref = swbody.GetFirstFace
464
465 For cpt1 = 0 To swbody.GetFaceCount - 1
466 swfeat = swfaceref.GetFeature
467 swsurface = swfaceref.GetSurface
468 swloop = swfaceref.GetFirstLoop
469 For cpt2 = 0 To swfaceref.GetLoopCount - 1
470 If swloop.IsOuter = False Then
471 vedge = swloop.GetEdges
472 For cpt3 = 0 To swloop.GetEdgeCount - 1
473 swedge = vedge(cpt3)
474 vface = swedge.GetTwoAdjacentFaces
475 For i = 0 To 1
476 swface = vface(i)
477 If swface.IsSame(swfaceref) = False Then
478 If GetAngle(swedge, swfaceref, swface) < 179 Then
479 ChangeTabFace(swface, coeff)
480 End If
481 End If
482 Next i
483 Next cpt3
484 Else
485 If swfeat.GetTypeName = "HoleWzd" Then
486 ChangeTabFace(swfaceref, coeff)
487 Else
488 If swfeat.GetFaceCount = 1 And swfeat.GetTypeName = "Cut" Then
489 If swsurface.Identity = 4002 Or swsurface.Identity = 4003 Or swsurface.Identity = 4005 Then
490 ChangeTabFace(swfaceref, coeff)
491 End If
492 End If
493 End If
494 End If
495 swloop = swloop.GetNext
496 Next cpt2
497 swfaceref = swfaceref.GetNextFace
498 Next cpt1
499
500 End Sub
501 Sub testAngleMatiere(ByRef coeff As Double)
502
503 Dim vface As Object
504 Dim vedge As Object
505 Dim swedge As SldWorks.Edge
506 Dim swface As SldWorks.Face2
507 Dim swface1 As SldWorks.Face2
508 Dim swface2 As SldWorks.Face2
509 Dim cpt1 As Integer
510 Dim Phi As Double
511 Dim swcurve As SldWorks.Curve
512 Dim lmbd_am As Double = 4
513 Dim courb_am As Double = 0
514
515
516 vedge = swbody.GetEdges
517 ' on test les arete et on prend celles qui sont des lignes
518 For cpt1 = 0 To swbody.GetEdgeCount - 1
519 swedge = vedge(cpt1)
520 swcurve = swedge.GetCurve
521 'If swcurve.IsLine Then
522 vface = swedge.GetTwoAdjacentFaces2
523 If Not vface(1) Is Nothing Then
524 swface1 = vface(0)
525 swface2 = vface(1)
526 'on test l'angle entre les deux face
527 Phi = GetAngle(swedge, swface1, swface2)
528 If Phi > 181 Then
529 ChangeTabEdge(swedge, coeff, lmbd_am, courb_am)
530 End If
531 End If
532 Next cpt1
533
534 End Sub
535 Function GetAngle(ByRef swedge As SldWorks.Edge, ByRef swface1 As SldWorks.Face2, ByRef swface2 As SldWorks.Face2) As Double
536 'cette fonction donne l'angle matière au centre de l'arête commune à deux faces
537 Dim N1() As Double
538 Dim N2() As Double
539 Dim T1() As Double
540 Dim T2() As Double
541 Dim V1() As Double
542 Dim V2() As Double
543 Dim V1scalV2 As Double
544 Dim N1scalV2 As Double
545 Dim Phi As Double
546 Dim a As Double
547 Dim vEdgeparam As Object
548 Dim swcurve As SldWorks.Curve
549 Dim xyz As Object
550
551 vEdgeparam = swedge.GetCurveParams2
552 swcurve = swedge.GetCurve
553
554 xyz = swcurve.Evaluate((vEdgeparam(7) - vEdgeparam(6)) / 2)
555
556 N1 = getNormatAtPoint(xyz, swface1)
557 N2 = getNormatAtPoint(xyz, swface2)
558
559 T1 = GetTangent(swedge, swface1)
560 T2 = GetTangent(swedge, swface2)
561
562 T1 = Vecteur_Unitaire(T1)
563 T2 = Vecteur_Unitaire(T2)
564
565 V1 = Produitvectoriel(N1, T1)
566 V2 = Produitvectoriel(N2, T2)
567
568 V1scalV2 = V1(0) * V2(0) + V1(1) * V2(1) + V1(2) * V2(2)
569 N1scalV2 = N1(0) * V2(0) + N1(1) * V2(1) + N1(2) * V2(2)
570
571 a = 0.0000001
572 If N1scalV2 < 0 + a Then
573 Phi = Math.Acos(V1scalV2) 'convexe
574 Else
575 Phi = 2 * 3.14159265 - Math.Acos(V1scalV2) 'concave
576 End If
577
578 GetAngle = Math.Abs(Phi * 360 / (2 * 3.14159265))
579
580 End Function
581 Function GetAngle(ByRef swedge As SldWorks.Edge, ByRef swface1 As SldWorks.Face2, ByRef swface2 As SldWorks.Face2, ByVal tc As Double) As Double
582 'cette fonction donne l'angle matière au centre de l'arête commune à deux faces
583 Dim N1() As Double
584 Dim N2() As Double
585 Dim T1() As Double
586 Dim T2() As Double
587 Dim V1() As Double
588 Dim V2() As Double
589 Dim V1scalV2 As Double
590 Dim N1scalV2 As Double
591 Dim Phi As Double
592 Dim a As Double
593 Dim vEdgeparam As Object
594 Dim swcurve As SldWorks.Curve
595 Dim xyz As Object
596
597 vEdgeparam = swedge.GetCurveParams2
598 swcurve = swedge.GetCurve
599 tc = Math.Min(Math.Max(tc, vEdgeparam(6)), vEdgeparam(7))
600
601 xyz = swcurve.Evaluate(tc)
602
603 N1 = getNormatAtPoint(xyz, swface1)
604 N2 = getNormatAtPoint(xyz, swface2)
605
606 T1 = GetTangent(swedge, swface1, tc)
607 T2 = GetTangent(swedge, swface2, tc)
608
609 T1 = Vecteur_Unitaire(T1)
610 T2 = Vecteur_Unitaire(T2)
611
612 V1 = Produitvectoriel(N1, T1)
613 V2 = Produitvectoriel(N2, T2)
614
615 V1scalV2 = V1(0) * V2(0) + V1(1) * V2(1) + V1(2) * V2(2)
616 N1scalV2 = N1(0) * V2(0) + N1(1) * V2(1) + N1(2) * V2(2)
617
618 a = 0.0000001
619 If N1scalV2 < 0 + a Then
620 Phi = Math.Acos(V1scalV2) 'convexe
621 Else
622 Phi = 2 * 3.14159265 - Math.Acos(V1scalV2) 'concave
623 End If
624
625 GetAngle = Math.Abs(Phi * 360 / (2 * 3.14159265))
626 End Function
627 Function Get_vect_into_mat(ByRef swedge As SldWorks.Edge, ByRef swface1 As SldWorks.Face2, ByVal tc As Double) As Double()
628
629 Dim N1() As Double
630 Dim T1() As Double
631 Dim V1() As Double
632 Dim vEdgeparam As Object
633 Dim swcurve As SldWorks.Curve
634 Dim xyz As Object
635
636 vEdgeparam = swedge.GetCurveParams2
637 swcurve = swedge.GetCurve
638 tc = Math.Min(Math.Max(tc, vEdgeparam(6)), vEdgeparam(7))
639
640 xyz = swcurve.Evaluate(tc)
641
642 N1 = getNormatAtPoint(xyz, swface1)
643 T1 = GetTangent(swedge, swface1, tc)
644 V1 = Produitvectoriel(N1, T1)
645 V1 = Vecteur_Unitaire(V1)
646
647 Get_vect_into_mat = V1
648
649 End Function
650 Function GetTangent(ByRef swedge As SldWorks.Edge, ByRef swface As SldWorks.Face2) As Double()
651 'cette fonction donne la direction de la tangente au centre de l'arete spécifiée
652 'La face donne la direction de la tangente
653 Dim swcurve As SldWorks.Curve
654 Dim vMParam() As Double
655 Dim vCurveParam() As Double
656 Dim Edgesens As Boolean
657 Dim Tangente(2) As Double
658 Dim t1 As Double
659 Dim t2 As Double
660
661 swcurve = swedge.GetCurve
662 vCurveParam = swedge.GetCurveParams2
663 vMParam = swcurve.Evaluate((vCurveParam(7) - vCurveParam(6)) / 2)
664
665 Edgesens = swedge.EdgeInFaceSense(swface)
666
667 If Edgesens Then
668 Tangente(0) = vMParam(3)
669 Tangente(1) = vMParam(4)
670 Tangente(2) = vMParam(5)
671 Else
672 Tangente(0) = -vMParam(3)
673 Tangente(1) = -vMParam(4)
674 Tangente(2) = -vMParam(5)
675 End If
676
677 GetTangent = Tangente
678
679 End Function
680 Function GetTangent(ByRef swedge As SldWorks.Edge, ByRef swface As SldWorks.Face2, ByVal tc As Double) As Double()
681 'cette fonction donne la direction de la tangente en un point de l'arête de l'arete spécifiée
682 'La face donne la direction de la tangente
683 Dim swcurve As SldWorks.Curve
684 Dim vMParam() As Double
685 Dim vCurveParam() As Double
686 Dim Edgesens As Boolean
687 Dim Tangente(2) As Double
688 Dim t1 As Double
689 Dim t2 As Double
690
691 swcurve = swedge.GetCurve
692 vCurveParam = swedge.GetCurveParams2
693
694 tc = Math.Min(Math.Max(tc, vCurveParam(6)), vCurveParam(7))
695 vMParam = swcurve.Evaluate(tc)
696
697 Edgesens = swedge.EdgeInFaceSense(swface)
698
699 If Edgesens Then
700 Tangente(0) = vMParam(3)
701 Tangente(1) = vMParam(4)
702 Tangente(2) = vMParam(5)
703 Else
704 Tangente(0) = -vMParam(3)
705 Tangente(1) = -vMParam(4)
706 Tangente(2) = -vMParam(5)
707 End If
708
709 GetTangent = Tangente
710
711 End Function
712 Function Arrondi(ByRef swface As SldWorks.Face2) As Integer
713 Dim swsurface As SldWorks.Surface
714 Dim vFaceUV() As Double
715 Dim vParam() As Double
716 Dim facesens As Boolean
717 Dim dUU(2) As Double
718 Dim dVV(2) As Double
719 Dim Normal(2) As Double 'normale
720 Dim NormU As Double
721 Dim NormV As Double
722 Dim xyz() As Double
723 Dim vbbox() As Double
724
725 vbbox = swface.GetBox
726 swsurface = swface.GetSurface
727 vFaceUV = swface.GetUVBounds
728 vParam = swsurface.Evaluate((vFaceUV(1) - vFaceUV(0)) / 2, (vFaceUV(3) - vFaceUV(2)) / 2, 2, 2)
729 If PointIsInFace(swface, vParam) = False Then
730 xyz = swface.GetClosestPointOn(vParam(0), vParam(1), vParam(2))
731 vFaceUV = swsurface.ReverseEvaluate(xyz(0), xyz(1), xyz(2))
732 vParam = swsurface.Evaluate(vFaceUV(0), vFaceUV(1), 2, 2)
733 End If
734
735 facesens = swface.FaceInSurfaceSense
736
737 If facesens Then
738 Normal(0) = -vParam(27) : Normal(1) = -vParam(28) : Normal(2) = -vParam(29)
739 Else
740 Normal(0) = vParam(27) : Normal(1) = vParam(28) : Normal(2) = vParam(29)
741 End If
742 dUU(0) = vParam(6) : dUU(1) = vParam(7) : dUU(2) = vParam(8)
743 dVV(0) = vParam(18) : dVV(1) = vParam(19) : dVV(2) = vParam(20)
744
745 NormU = getNorme(dUU)
746 NormV = getNorme(dVV)
747
748 If NormU < 0.0000000000001 Then
749 NormU = 0
750 End If
751 If NormV < 0.0000000000001 Then
752 NormV = 0
753 End If
754
755 If NormU <> 0 And NormV <> 0 Then
756 If NormU < NormV Then
757 If Produit_scalaire(Normal, dUU) > 0 Then
758 Arrondi = 1
759 Else
760 Arrondi = 2
761 End If
762 Else
763 If Produit_scalaire(Normal, dVV) > 0 Then
764 Arrondi = 1
765 Else
766 Arrondi = 2
767 End If
768 End If
769 Else
770 If NormU <> 0 Then
771 If Produit_scalaire(Normal, dUU) > 0 Then
772 Arrondi = 1
773 Else
774 Arrondi = 3
775 End If
776 Else
777 If NormV <> 0 Then
778 If Produit_scalaire(Normal, dVV) > 0 Then
779 Arrondi = 1
780 Else
781 Arrondi = 3
782 End If
783 End If
784 End If
785 End If
786 End Function
787 Function getNorme(ByRef u() As Double) As Double
788 'cette fonction norme le vecteur u
789 Dim norm As Double
790 norm = (u(0) * u(0) + u(1) * u(1) + u(2) * u(2)) ^ 0.5
791 Return norm
792 End Function
793 Function Produit_scalaire(ByRef u() As Double, ByRef v() As Double) As Double
794 'Cette fonction donne le produit scalaire de deux vecteurs de dimension 3
795 Produit_scalaire = u(0) * v(0) + u(1) * v(1) + u(2) * v(2)
796 End Function
797 Function arrondivoisin(ByRef swface As SldWorks.Face2) As Boolean
798 ' cette fonction teste si la face donné a des faces "arrondis" comme voisines
799 Dim vedge As Object
800 Dim swEdge As SldWorks.Edge
801 Dim vface As Object
802 Dim swfaceadja As SldWorks.Face2
803 Dim swfeat As SldWorks.Feature
804 Dim FeatType As String
805 Dim cpt1 As Integer
806 Dim i As Integer
807 Dim swEndVert As SldWorks.Vertex
808 Dim swStartVert As SldWorks.Vertex
809
810 vedge = swface.GetEdges
811 For cpt1 = 0 To swface.GetEdgeCount - 1
812 swEdge = vedge(cpt1)
813 vface = swEdge.GetTwoAdjacentFaces
814 For i = 0 To 1
815 swfaceadja = vface(i)
816 If swfaceadja.IsSame(swface) = False Then
817 swfeat = swfaceadja.GetFeature
818 FeatType = swfeat.GetTypeName
819 If FeatType = "Fillet" Or FeatType = "VarFillet" Then
820 If Arrondi(swfaceadja) = 1 Then
821 swEndVert = swEdge.GetStartVertex
822 swStartVert = swEdge.GetEndVertex
823 If testcontinuite(swEdge, swface, swfaceadja, swEndVert) = True Then
824 Return True 'arrondivoisin = True
825 Else
826 If testcontinuite(swEdge, swface, swfaceadja, swStartVert) = True Then
827 Return True 'arrondivoisin = True
828 End If
829 End If
830 End If
831 End If
832 End If
833 Next i
834 Next cpt1
835 End Function
836 Function testcontinuite(ByRef swedge As SldWorks.Edge, ByRef swface As SldWorks.Face2, ByRef swfaceAdj As SldWorks.Face2, ByRef swVert As SldWorks.Vertex) As Boolean
837 'cette fonction test si l'arete appartenant à la face est continue avec une des aretes contenant le meme point de la face adjacente
838 Dim vedge As Object
839 Dim swEdgeAdj As SldWorks.Edge
840 Dim vface As Object
841 Dim swface1 As SldWorks.Face2
842 Dim swface2 As SldWorks.Face2
843 Dim i As Integer
844
845 vedge = swVert.GetEdges
846 For i = 0 To UBound(vedge)
847 swEdgeAdj = vedge(i)
848 vface = swEdgeAdj.GetTwoAdjacentFaces2
849 swface1 = vface(0)
850 swface2 = vface(1)
851 If swface1.IsSame(swface) = False And swface2.IsSame(swface) = False Then
852 If swface1.IsSame(swfaceAdj) = True Or swface2.IsSame(swfaceAdj) = True Then
853 If testedgeIsSame(swEdgeAdj, swface, swfaceAdj) = True Then
854 Return True 'testcontinuite = True
855 End If
856 End If
857 End If
858 Next i
859 End Function
860 Function testedgeIsSame(ByRef swedge As SldWorks.Edge, ByRef swface As SldWorks.Face2, ByRef swfaceAdj As SldWorks.Face2) As Boolean
861
862 Dim vedgetan As Object
863 Dim swedgetan As SldWorks.Edge
864 Dim vface As Object
865 Dim swface1 As SldWorks.Face2
866 Dim swface2 As SldWorks.Face2
867 Dim i As Integer
868
869 vedgetan = swedge.GetTangentEdges
870 For i = 0 To swedge.GetTangentEdgesCount - 1
871 swedgetan = vedgetan(i)
872 vface = swedgetan.GetTwoAdjacentFaces2
873 swface1 = vface(0)
874 swface2 = vface(1)
875 If swface1.IsSame(swface) = True Or swface2.IsSame(swface) = True Then
876 Return True
877 End If
878 Next i
879
880 End Function
881 Function Vecteur_Unitaire(ByRef varVec1() As Double) As Double()
882 ' cette fonction donne le vecteur unitaire du vecteur
883 Dim dblMag As Double
884 Dim dblUnit1(2) As Double
885
886 dblMag = (varVec1(0) * varVec1(0) + varVec1(1) * varVec1(1) + varVec1(2) * varVec1(2)) ^ 0.5
887 dblUnit1(0) = varVec1(0) / dblMag : dblUnit1(1) = varVec1(1) / dblMag : dblUnit1(2) = varVec1(2) / dblMag
888
889 Vecteur_Unitaire = dblUnit1
890
891 End Function
892 Function Produitvectoriel(ByRef varVec1() As Double, ByRef varVec2() As Double) As Double()
893 'Cette fonction donne le produit vectoriel de deux vecteurs de dimension 3
894 Dim dblCross(2) As Double
895
896 dblCross(0) = varVec1(1) * varVec2(2) - varVec1(2) * varVec2(1)
897 dblCross(1) = varVec1(2) * varVec2(0) - varVec1(0) * varVec2(2)
898 dblCross(2) = varVec1(0) * varVec2(1) - varVec1(1) * varVec2(0)
899 Produitvectoriel = dblCross
900 End Function
901 Function PointIsInFace(ByRef swface As SldWorks.Face2, ByRef xyz() As Double) As Boolean
902 ' cette fonction test si le point appartient à la face
903 Dim x1y1z1() As Double
904 Dim a As Double = 0.000000001
905 Dim vedge As Object
906 Dim swedge As SldWorks.Edge
907 Dim cpt1 As Integer
908
909 vedge = swface.GetEdges
910 x1y1z1 = swface.GetClosestPointOn(xyz(0), xyz(1), xyz(2))
911
912 If x1y1z1(0) < xyz(0) + a And x1y1z1(0) > xyz(0) - a And _
913 x1y1z1(1) < xyz(1) + a And x1y1z1(1) > xyz(1) - a And _
914 x1y1z1(2) < xyz(2) + a And x1y1z1(2) > xyz(2) - a Then
915 For cpt1 = 0 To swface.GetEdgeCount - 1
916 swedge = vedge(cpt1)
917 x1y1z1 = swedge.GetClosestPointOn(xyz(0), xyz(1), xyz(2))
918 If x1y1z1(0) < xyz(0) + a And x1y1z1(0) > xyz(0) - a And _
919 x1y1z1(1) < xyz(1) + a And x1y1z1(1) > xyz(1) - a And _
920 x1y1z1(2) < xyz(2) + a And x1y1z1(2) > xyz(2) - a Then
921 Else
922 Return True
923 cpt1 = swface.GetEdgeCount - 1
924 End If
925 Next cpt1
926 Else
927 Return False
928 End If
929 End Function
930 Function VertexExist(ByRef xyz() As Double) As Boolean
931 'cette fonction test si le sommet existe dans le tableau des sommets
932 Dim i As Integer
933 Dim a As Double
934
935 a = 0.0000000000001
936 If cptVertex <> 0 Then
937 For i = 0 To cptVertex - 1
938 If xyz(0) < TabVertex(0, i) + a And xyz(0) > TabVertex(0, i) - a And _
939 xyz(1) < TabVertex(1, i) + a And xyz(1) > TabVertex(1, i) - a And _
940 xyz(2) < TabVertex(2, i) + a And xyz(2) > TabVertex(2, i) - a Then
941 Return False
942 Else
943 VertexExist = True
944 End If
945 Next i
946 Else
947 VertexExist = True
948 End If
949
950 End Function
951 Function Facecirculaire(ByRef swface As SldWorks.Face2) As Integer
952 'cette fonction teste si la face est cylindrique spherique ou autre
953 Dim swsurface As SldWorks.Surface
954 Dim vUVbound() As Double
955 Dim vUVXYZdebut() As Double
956 Dim UVXYZdebut(2) As Double
957 Dim vUXYZfin() As Double
958 Dim UXYZfin(2) As Double
959 Dim vVXYZfin() As Double
960 Dim VXYZfin(2) As Double
961
962 swsurface = swface.GetSurface
963 vUVbound = swface.GetUVBounds
964 vUVXYZdebut = swsurface.Evaluate(vUVbound(0), vUVbound(2), 0, 0)
965 vUXYZfin = swsurface.Evaluate(vUVbound(1), vUVbound(2), 0, 0)
966 vVXYZfin = swsurface.Evaluate(vUVbound(0), vUVbound(3), 0, 0)
967 UVXYZdebut(0) = vUVXYZdebut(0) : UVXYZdebut(1) = vUVXYZdebut(1) : UVXYZdebut(2) = vUVXYZdebut(2)
968 UXYZfin(0) = vUXYZfin(0) : UXYZfin(1) = vUXYZfin(1) : UXYZfin(2) = vUXYZfin(2)
969 VXYZfin(0) = vVXYZfin(0) : VXYZfin(1) = vVXYZfin(1) : VXYZfin(2) = vVXYZfin(2)
970
971 If PointIsInFace(swface, UVXYZdebut) = False Then
972 Facecirculaire = 4
973 Else
974 If PointEgale(UVXYZdebut, UXYZfin) Then
975 If PointEgale(UVXYZdebut, VXYZfin) Then
976 Facecirculaire = 1
977 Else
978 Facecirculaire = 2
979 End If
980 Else
981 If PointEgale(UVXYZdebut, VXYZfin) Then
982 Facecirculaire = 3
983 Else
984 Facecirculaire = 4
985 End If
986 End If
987 End If
988 End Function
989 Function Edgecirculaire(ByRef swedge As SldWorks.Edge) As Integer
990 'cette fonction test si l'arete est cylindrique ou autre
991 Dim edgeparam() As Double
992 Dim pointdebut(2) As Double
993 Dim pointfin(2) As Double
994
995 edgeparam = swedge.GetCurveParams2
996 pointdebut(0) = edgeparam(0) : pointdebut(1) = edgeparam(1) : pointdebut(2) = edgeparam(2)
997 pointfin(0) = edgeparam(3) : pointfin(1) = edgeparam(4) : pointfin(2) = edgeparam(5)
998 If PointEgale(pointdebut, pointfin) = True Then
999 Edgecirculaire = 2
1000 Else
1001 Edgecirculaire = 1
1002 End If
1003
1004 End Function
1005 Function PointEgale(ByRef xyz1() As Double, ByRef xyz2() As Double) As Boolean
1006 'cette fonction test si les deux points sont égaux
1007 Dim a As Double
1008 a = 0.0000000000001
1009 If xyz1(0) < xyz2(0) + a And xyz1(0) > xyz2(0) - a And _
1010 xyz1(1) < xyz2(1) + a And xyz1(1) > xyz2(1) - a And _
1011 xyz1(2) < xyz2(2) + a And xyz1(2) > xyz2(2) - a Then
1012 PointEgale = True
1013 Else
1014 PointEgale = False
1015 End If
1016 End Function
1017 Function getNormatAtPoint(ByRef P() As Double, ByRef swface As SldWorks.Face2) As Double()
1018 'cette fonction donne la normale à la face au point P
1019 Dim swsurface As SldWorks.Surface
1020 Dim xyzP(2) As Double
1021 Dim UVP() As Double
1022 Dim vSurfparam() As Double
1023 Dim facesens As Boolean
1024 Dim Nxyz(2) As Double
1025
1026 swsurface = swface.GetSurface
1027 UVP = swsurface.ReverseEvaluate(P(0), P(1), P(2))
1028 If UVP Is Nothing Then
1029 xyzP = swsurface.GetClosestPointOn(P(0), P(1), P(2))
1030 UVP = swsurface.ReverseEvaluate(xyzP(0), xyzP(1), xyzP(2))
1031 End If
1032
1033 vSurfparam = swsurface.Evaluate(UVP(0), UVP(1), 0, 0)
1034
1035 facesens = swface.FaceInSurfaceSense
1036 If facesens Then
1037 Nxyz(0) = -vSurfparam(3) : Nxyz(1) = -vSurfparam(4) : Nxyz(2) = -vSurfparam(5)
1038 Else
1039 Nxyz(0) = vSurfparam(3) : Nxyz(1) = vSurfparam(4) : Nxyz(2) = vSurfparam(5)
1040 End If
1041
1042 getNormatAtPoint = Nxyz
1043
1044 End Function
1045 Function faceIsAlreadyRepear(ByRef swface As SldWorks.Face2) As Boolean
1046 'Cette fonction test si la face a déja été repérée dans le tableau de face
1047 Dim cpt1 As Integer
1048 Dim swfacetab As SldWorks.Face2
1049
1050 For cpt1 = 0 To UBound(Tabface)
1051 swfacetab = Tabface(cpt1)
1052 If swface.IsSame(swfacetab) Then
1053 If TabFaceDouble(0, cpt1) <> 1 Then
1054 Return True
1055 Else
1056 Return False
1057 End If
1058 End If
1059 Next cpt1
1060
1061
1062 End Function
1063 Function IsInBodyBox(ByRef P() As Double) As Boolean
1064 'cette fonction test si le point P est dans la boite englobante
1065 Dim BodyBox() As Double
1066 BodyBox = swbody.GetBodyBox
1067 If P(0) < BodyBox(0) Or P(1) < BodyBox(1) Or P(2) < BodyBox(2) _
1068 Or P(0) > BodyBox(3) Or P(1) > BodyBox(4) Or P(2) > BodyBox(5) Then
1069 IsInBodyBox = False
1070 Else
1071 IsInBodyBox = True
1072 End If
1073 End Function
1074 Function GetUVLong(ByRef swFace As SldWorks.Face2) As Object
1075 'Cette fonction donne la plus grande isoparametrique des 2 direction u et v avec u = umin ou umax ou v = vmin ou vmax
1076 Dim LUvmin As Double = 0
1077 Dim LVumin As Double = 0
1078 Dim LUvmax As Double = 0
1079 Dim LVumax As Double = 0
1080 Dim UVL(1) As Double
1081 Dim vUV() As Double
1082 Dim IncrU As Double
1083 Dim IncrV As Double
1084 Dim Pincr() As Double
1085 Dim nbIncr As Integer = 25
1086 Dim PP(2, 99) As Double
1087 Dim swsurface As SldWorks.Surface
1088 Dim i As Integer
1089 Dim u As Integer
1090
1091 swsurface = swFace.GetSurface
1092 vUV = swFace.GetUVBounds
1093
1094 IncrU = (vUV(1) - vUV(0)) / nbIncr
1095 IncrV = (vUV(3) - vUV(2)) / nbIncr
1096
1097 For i = 0 To nbIncr
1098 Pincr = swsurface.Evaluate(vUV(0) + i * IncrU, vUV(2), 0, 0)
1099 PP(0, i) = Pincr(0) : PP(1, i) = Pincr(1) : PP(2, i) = Pincr(2)
1100 Next i
1101 For u = 0 To nbIncr - 1
1102 LUvmin = LUvmin + Dist(PP(0, u), PP(1, u), PP(2, u), PP(0, u + 1), PP(1, u + 1), PP(2, u + 1))
1103 Next u
1104
1105 For i = 0 To nbIncr
1106 Pincr = swsurface.Evaluate(vUV(0) + i * IncrU, vUV(3), 0, 0)
1107 PP(0, i) = Pincr(0) : PP(1, i) = Pincr(1) : PP(2, i) = Pincr(2)
1108 Next i
1109 For u = 0 To nbIncr - 1
1110 LUvmax = LUvmax + Dist(PP(0, u), PP(1, u), PP(2, u), PP(0, u + 1), PP(1, u + 1), PP(2, u + 1))
1111 Next u
1112
1113 For i = 0 To nbIncr
1114 Pincr = swsurface.Evaluate(vUV(0), vUV(2) + i * IncrV, 0, 0)
1115 PP(0, i) = Pincr(0) : PP(1, i) = Pincr(1) : PP(2, i) = Pincr(2)
1116 Next i
1117 For u = 0 To nbIncr - 1
1118 LVumin = LVumin + Dist(PP(0, u), PP(1, u), PP(2, u), PP(0, u + 1), PP(1, u + 1), PP(2, u + 1))
1119 Next u
1120
1121 For i = 0 To nbIncr
1122 Pincr = swsurface.Evaluate(vUV(1), vUV(2) + i * IncrV, 0, 0)
1123 PP(0, i) = Pincr(0) : PP(1, i) = Pincr(1) : PP(2, i) = Pincr(2)
1124 Next i
1125 For u = 0 To nbIncr - 1
1126 LVumax = LVumax + Dist(PP(0, u), PP(1, u), PP(2, u), PP(0, u + 1), PP(1, u + 1), PP(2, u + 1))
1127 Next u
1128
1129 UVL(0) = Math.Max(LUvmin, LUvmax) : UVL(1) = Math.Max(LVumin, LVumax)
1130
1131 GetUVLong = UVL
1132 End Function
1133 Function GetEdgeLenght(ByRef swedge As SldWorks.Edge) As Double
1134 'cette fonction donne la longueur de l'arete
1135 Dim swcurve As SldWorks.Curve
1136 Dim lenght As Double
1137 Dim vParam() As Double
1138 vParam = swedge.GetCurveParams2
1139 swcurve = swedge.GetCurve
1140 lenght = swcurve.GetLength2(vParam(6), vParam(7))
1141 'lenght = get_edge_lenght(swedge, vParam(6), vParam(7))
1142 GetEdgeLenght = lenght
1143 End Function
1144 Function Dist(ByRef x1 As Double, ByRef y1 As Double, ByRef z1 As Double, ByRef x2 As Double, ByRef y2 As Double, ByRef z2 As Double) As Double
1145 'cette fonction donne la distance entre les deux points
1146 Dist = ((x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 2) ^ (1 / 2)
1147 End Function
1148 Function FonctionVolume(ByRef x As Double, ByRef a As Double, ByVal F As Integer) As Double()
1149 ' cette fonction définit la fonction de variation de l'écart nodal dans le volume
1150 Dim u As Double
1151 Dim fx As Double
1152 Dim fprim As Double
1153 Dim intvl As Double
1154 Dim Pasest As Double
1155 Dim Funct(2) As Double
1156 Dim Param As Double
1157 Select Case F
1158
1159 Case 1
1160 intvl = 10
1161 u = intvl * x
1162 fx = (u + a) / (u + 1)
1163 fprim = intvl * (1 - a) / ((u + 1) * (u + 1))
1164
1165 Case 2
1166 fx = (x ^ 5 + a) / (x + 1)
1167 fprim = (4 * x ^ 5 + 5 * x ^ 4 - a) / ((x + 1) * (x + 1))
1168 intvl = 1
1169 Pasest = intvl / 10
1170
1171 Case 3
1172 fx = 0.3 * x
1173 fprim = 0.3
1174
1175 Case 4
1176 fx = (x ^ 3 + a) / (x + 1)
1177 fprim = (2 * x ^ 3 + 3 * x ^ 2 - a) / ((x + 1) * (x + 1))
1178
1179 Case 5
1180 fx = a + (1 - 2 * a) * Math.Sin(3.14 * x)
1181 fprim = (1 - 2 * a) * Math.Cos(3.14 * x) * 3.14
1182
1183 End Select
1184
1185 Funct(0) = fx
1186 Funct(1) = fprim
1187 Funct(2) = Math.Abs(fprim - 1 + a)
1188
1189 FonctionVolume = Funct
1190 End Function
1191 Function FonctionVolume2(ByRef x As Double, ByRef eng As Double, ByRef eni As Double, ByRef delta As Double, ByRef F As Integer) As Double
1192
1193 Dim fx As Double
1194 Dim b As Double = 0.1
1195
1196 Select Case F
1197
1198 Case 1
1199 fx = eni + (eng - eni) * (x / delta)
1200 Case 2
1201 fx = -(b * eni * (x - delta) - (b + 1) * x * eng) / (x + b * delta)
1202 Case 3
1203 fx = ((b + 1) * eni * (x - delta) - b * x * eng) / (x - (b + 1) * delta)
1204 End Select
1205
1206
1207 FonctionVolume2 = fx
1208
1209 End Function
1210 Function GetFirstIntersectFace(ByRef Dir() As Double, ByRef Pt() As Double) As SldWorks.Face2
1211 'Donne la premiere face intersecté dans une direction à partir d'1 point
1212 'rayintersection fonctionne pas avec vb.net : a voir avec la version SW 2006
1213 Dim swface As SldWorks.Face2
1214 Dim VInterParam(6) As Double
1215 Dim status As Boolean
1216
1217 VInterParam(0) = Pt(0) + 0.00001 * Dir(0) : VInterParam(1) = Pt(1) + 0.00001 * Dir(1) : VInterParam(2) = Pt(2) + 0.00001 * Dir(2)
1218 VInterParam(3) = Dir(0) : VInterParam(4) = Dir(1) : VInterParam(5) = Dir(2)
1219 VInterParam(6) = 0
1220 swModel.ClearSelection2(True)
1221 status = swModel.SelectByRay(VInterParam, 2)
1222 If status = True Then
1223 Dim swSelMgr As SldWorks.SelectionMgr = swModel.SelectionManager
1224 swface = swSelMgr.GetSelectedObject5(1)
1225 Return swface
1226 Else
1227 Return Nothing
1228 End If
1229
1230 End Function
1231 Function GetPointFirstIntersectFace(ByRef Dir() As Double, ByRef Pt() As Double, ByRef Swface As SldWorks.Face2) As Double()
1232 ' Donne le point appartenant a la premiere face intersecté dans une direction à partir d'un point
1233 Dim modeler As SldWorks.Modeler
1234 Dim swcurve As SldWorks.Curve
1235 Dim retval As Object
1236 Dim vCurveParam As Object
1237 Dim startp(2) As Double
1238 Dim endp(2) As Double
1239 Dim vStart As Object
1240 Dim vEnd As Object
1241 Dim swsurf As SldWorks.Surface
1242 Dim vCurvebounds(5) As Double
1243 Dim i As Integer
1244 Dim knots(3) As Double
1245 Dim ctrlPoints(5) As Double
1246 Dim props As Object
1247 Dim dProps(1) As Double
1248 Dim vKnots As Object, vCtrlPoints As Object
1249 Dim bRet As Boolean
1250 Dim vPointArray As Object, vTArray As Object, vUVArray As Object
1251
1252 If Not Swface Is Nothing Then
1253 swsurf = Swface.GetSurface
1254 modeler = swApp.GetModeler
1255 swcurve = modeler.CreateLine(Pt, Dir)
1256
1257 'Dim closestpoint() As Double
1258 'closestpoint = Swface.GetClosestPointOn(Pt(0), Pt(1), Pt(2))
1259
1260 startp(0) = Pt(0) : startp(1) = Pt(1) : startp(2) = Pt(2)
1261 'startp(0) = closestpoint(0) : startp(1) = closestpoint(1) : startp(2) = closestpoint(2)
1262 vStart = startp
1263
1264 endp(0) = Pt(0) + 0.01 * Dir(0) : endp(1) = Pt(1) + 0.01 * Dir(1) : endp(2) = Pt(2) + 0.01 * Dir(2)
1265 While IsInBodyBox(endp) = True
1266 endp(0) = endp(0) + 0.01 * Dir(0)
1267 endp(1) = endp(1) + 0.01 * Dir(1)
1268 endp(2) = endp(2) + 0.01 * Dir(2)
1269 End While
1270 vEnd = endp
1271
1272 For i = 0 To 2
1273 vCurvebounds(i) = startp(i)
1274 vCurvebounds(3 + i) = endp(i)
1275 Next
1276
1277 retval = swcurve.ConvertLineToBcurve(vStart, vEnd)
1278 ' on suppose que la droite est toujours transformée en spline non-rationelle de dimension 3 et d'ordre 2
1279
1280 knots(0) = retval(2) : knots(1) = retval(3) : knots(2) = retval(4) : knots(3) = retval(5)
1281 ctrlPoints(0) = retval(6) : ctrlPoints(1) = retval(7) : ctrlPoints(2) = retval(8) : ctrlPoints(3) = retval(9) : ctrlPoints(4) = retval(10) : ctrlPoints(5) = retval(11)
1282
1283 dProps(0) = retval(0)
1284 dProps(1) = retval(1)
1285 props = dProps
1286 vKnots = knots
1287 vCtrlPoints = ctrlPoints
1288
1289 swcurve = modeler.CreateBsplineCurve(props, vKnots, vCtrlPoints)
1290
1291 bRet = swsurf.IntersectCurve(swcurve, vCurvebounds, vPointArray, vTArray, vUVArray)
1292 Return vPointArray
1293 Else
1294 Return Nothing
1295 End If
1296 End Function
1297 Function DistPointFace(ByRef Pt() As Double, ByRef Dir() As Double, ByRef Swface As SldWorks.Face2) As Double
1298 'donne la distance entre un point et la face
1299 'A cause que rAYintersection marche pas avec Vbnet
1300 Dim distance As Double
1301 Dim vPointArray() As Double
1302
1303 vPointArray = GetPointFirstIntersectFace(Dir, Pt, Swface)
1304 If vPointArray.Length > 1 Then
1305 If IsInSurfSens(Pt, vPointArray, Swface) = True Then
1306 If PointIsInFace(Swface, vPointArray) Then
1307 distance = Dist(Pt(0), Pt(1), Pt(2), vPointArray(0), vPointArray(1), vPointArray(2))
1308 End If
1309 End If
1310
1311 If UBound(vPointArray) > 2 Then
1312 Dim i As Integer
1313 Dim di As Double
1314 Dim xyz(2) As Double
1315 For i = 3 To UBound(vPointArray) - 1 Step 3
1316 xyz(0) = vPointArray(0 + i) : xyz(1) = vPointArray(1 + i) : xyz(2) = vPointArray(2 + i)
1317 di = Dist(Pt(0), Pt(1), Pt(2), xyz(0), xyz(1), xyz(2))
1318 If IsInSurfSens(Pt, xyz, Swface) = True Then
1319 If PointIsInFace(Swface, xyz) Then
1320 distance = Math.Min(di, distance)
1321 End If
1322 End If
1323 Next
1324 End If
1325 Return distance
1326 Else
1327 Return 0
1328 End If
1329
1330 End Function
1331 Function IsInSurfSens(ByRef Porigin() As Double, ByRef Pface() As Double, ByRef swface As SldWorks.Face2) As Boolean
1332 'fonction spécifique
1333 Dim Vect(2) As Double
1334 Dim Normale() As Double
1335 Dim VscalN As Double
1336
1337 Vect(0) = Pface(0) - Porigin(0)
1338 Vect(1) = Pface(1) - Porigin(1)
1339 Vect(2) = Pface(2) - Porigin(2)
1340 Vect = Vecteur_Unitaire(Vect)
1341 Normale = getNormatAtPoint(Pface, swface)
1342 Normale = Vecteur_Unitaire(Normale)
1343 VscalN = Produit_scalaire(Vect, Normale)
1344
1345 If VscalN > 0 Then Return True Else : Return False
1346
1347 End Function
1348 Function EdgeIsRepair(ByRef swedge As SldWorks.Edge) As Boolean
1349 ' cette fonction permet de tester si une arête à déja été repérée
1350 Dim Cprm1() As Double
1351 Dim Cprm2() As Double
1352 Dim Strpt1(2) As Double
1353 Dim Endpt1(2) As Double
1354 Dim Strpt2(2) As Double
1355 Dim Endpt2(2) As Double
1356 Dim swedge2 As SldWorks.Edge
1357 Dim i As Integer
1358
1359 Cprm1 = swedge.GetCurveParams2
1360 Strpt1(0) = Cprm1(0) : Strpt1(1) = Cprm1(1) : Strpt1(2) = Cprm1(2)
1361 Endpt1(0) = Cprm1(3) : Endpt1(1) = Cprm1(4) : Endpt1(2) = Cprm1(5)
1362
1363 For i = 0 To UBound(TabEdge)
1364 If TabEdgeDouble(0, i) <> 1 Then
1365 swedge2 = TabEdge(i)
1366 Cprm2 = swedge2.GetCurveParams2
1367 Strpt2(0) = Cprm2(0) : Strpt2(1) = Cprm2(1) : Strpt2(2) = Cprm2(2)
1368 If PointEgale(Strpt1, Strpt2) = True Or PointEgale(Endpt1, Strpt2) Then
1369 Endpt2(0) = Cprm2(3) : Endpt2(1) = Cprm2(4) : Endpt2(2) = Cprm2(5)
1370 If PointEgale(Endpt1, Endpt2) = True Or PointEgale(Strpt1, Endpt2) Then
1371 Return True
1372 End If
1373 End If
1374 End If
1375 Next
1376 Return False
1377 End Function
1378 Function Txtpath(ByVal path As String) As String
1379 Dim Carray() As String
1380 Carray = path.Split(".")
1381 If Not Carray(UBound(Carray)) = "txt" Then
1382 path = path & ".txt"
1383 End If
1384 Return path
1385 End Function
1386 Sub BoiteEnglobante()
1387 ' Ecrit la boite englobante dans le tableau de points
1388 Dim BodyBox() As Double
1389 Dim cpt1 As Integer
1390
1391 BodyBox = swbody.GetBodyBox
1392 ReDim Preserve TabPoints(8, cpt)
1393
1394 For cpt1 = 0 To 5
1395 TabPoints(cpt1, 0) = BodyBox(cpt1)
1396 Next cpt1
1397
1398 End Sub
1399 Sub initialisation()
1400 'initialise les entité comme n'étant pas raffiné i.e. avec un coeff de raffinement de maillage = 1
1401 Dim swface As SldWorks.Face2
1402 Dim cptface As Integer
1403 Dim cptedge As Integer
1404 Dim vEdge As Object
1405 Dim swEdge As SldWorks.Edge
1406 Dim vEdgeParam() As Double
1407 Dim point(2) As Double
1408 Dim cpt1 As Integer
1409
1410 swface = swbody.GetFirstFace
1411
1412 ReDim Preserve Tabface(swbody.GetFaceCount - 1)
1413 ReDim Preserve TabFaceDouble(2, swbody.GetFaceCount - 1)
1414 ReDim Preserve TabEdge(swbody.GetEdgeCount - 1)
1415 ReDim Preserve TabEdgeDouble(2, swbody.GetEdgeCount - 1)
1416
1417 For cptface = 0 To swbody.GetFaceCount - 1
1418 Tabface(cptface) = swface
1419 TabFaceDouble(0, cptface) = 1
1420 TabFaceDouble(1, cptface) = 4
1421 TabFaceDouble(2, cptface) = 0
1422 swface = swface.GetNextFace
1423 Next cptface
1424 vEdge = swbody.GetEdges
1425 For cptedge = 0 To swbody.GetEdgeCount - 1
1426 TabEdge(cptedge) = vEdge(cptedge)
1427 TabEdgeDouble(0, cptedge) = 1
1428 TabEdgeDouble(1, cptedge) = 4
1429 TabEdgeDouble(2, cptedge) = 0
1430 Next cptedge
1431
1432 cptVertex = 0
1433
1434 For cpt1 = 0 To swbody.GetEdgeCount - 1
1435 swEdge = vEdge(cpt1)
1436 vEdgeParam = swEdge.GetCurveParams2
1437 point(0) = vEdgeParam(0)
1438 point(1) = vEdgeParam(1)
1439 point(2) = vEdgeParam(2)
1440 If VertexExist(point) = True Then
1441 ReDim Preserve TabVertex(2, cptVertex)
1442 ReDim Preserve TabVertexDouble(2, cptVertex)
1443 TabVertex(0, cptVertex) = point(0)
1444 TabVertex(1, cptVertex) = point(1)
1445 TabVertex(2, cptVertex) = point(2)
1446 TabVertexDouble(0, cptVertex) = 1
1447 TabVertexDouble(1, cptVertex) = 4
1448 TabVertexDouble(2, cptVertex) = 0
1449 cptVertex = cptVertex + 1
1450 End If
1451 point(0) = vEdgeParam(3)
1452 point(1) = vEdgeParam(4)
1453 point(2) = vEdgeParam(5)
1454 If VertexExist(point) = True Then
1455 ReDim Preserve TabVertex(2, cptVertex)
1456 ReDim Preserve TabVertexDouble(2, cptVertex)
1457 TabVertex(0, cptVertex) = point(0)
1458 TabVertex(1, cptVertex) = point(1)
1459 TabVertex(2, cptVertex) = point(2)
1460 TabVertexDouble(0, cptVertex) = 1
1461 TabVertexDouble(1, cptVertex) = 4
1462 TabVertexDouble(2, cptVertex) = 0
1463 cptVertex = cptVertex + 1
1464 End If
1465 Next cpt1
1466
1467 End Sub
1468 Sub ChangeTabFace(ByRef swface As SldWorks.Face2, ByRef coeff As Double, Optional ByRef lambda As Double = 4, Optional ByRef courbure As Double = 0)
1469 'Change la valeur du coeff de raff de maill et lambda et courbure du tableau des faces du modele
1470 Dim swfacetab As SldWorks.Face2
1471 Dim cpt1 As Integer
1472 Dim vedge As Object
1473 Dim swedge As SldWorks.Edge
1474 Dim cpt2 As Integer
1475
1476 For cpt1 = 0 To UBound(Tabface)
1477 swfacetab = Tabface(cpt1)
1478 If swface.IsSame(swfacetab) Then
1479 If TabFaceDouble(0, cpt1) > coeff Then
1480 TabFaceDouble(0, cpt1) = coeff
1481 TabFaceDouble(1, cpt1) = lambda
1482 TabFaceDouble(2, cpt1) = courbure
1483
1484 vedge = swface.GetEdges
1485 For cpt2 = 0 To swface.GetEdgeCount - 1
1486 swedge = vedge(cpt2)
1487 ChangeTabEdge(swedge, coeff, lambda, courbure)
1488 Next cpt2
1489 End If
1490 End If
1491 Next cpt1
1492 End Sub
1493 Sub ChangeTabEdge(ByRef swedge As SldWorks.Edge, ByRef coeff As Double, Optional ByRef lambda As Double = 4, Optional ByRef courbure As Double = 0)
1494 ' comme changetabface mais pour les aretes
1495 Dim swedgetab As SldWorks.Edge
1496 Dim ParamEdgeTab() As Double
1497 Dim ParamEdge() As Double
1498 Dim cpt1 As Integer
1499 For cpt1 = 0 To UBound(TabEdge)
1500 swedgetab = TabEdge(cpt1)
1501 ParamEdgeTab = swedgetab.GetCurveParams2
1502 ParamEdge = swedge.GetCurveParams2
1503 If ParamEdgeTab(0) = ParamEdge(0) And _
1504 ParamEdgeTab(1) = ParamEdge(1) And _
1505 ParamEdgeTab(2) = ParamEdge(2) And _
1506 ParamEdgeTab(3) = ParamEdge(3) And _
1507 ParamEdgeTab(4) = ParamEdge(4) And _
1508 ParamEdgeTab(5) = ParamEdge(5) And _
1509 ParamEdgeTab(6) = ParamEdge(6) And _
1510 ParamEdgeTab(7) = ParamEdge(7) Then
1511 If TabEdgeDouble(0, cpt1) > coeff Then
1512 TabEdgeDouble(0, cpt1) = coeff
1513 TabEdgeDouble(1, cpt1) = lambda
1514 TabEdgeDouble(2, cpt1) = courbure
1515 Changetabvertex(swedge, coeff, lambda, courbure)
1516 End If
1517 End If
1518 Next cpt1
1519 End Sub
1520 Sub Changetabvertex(ByRef swedge As SldWorks.Edge, ByRef coeff As Double, Optional ByRef lambda As Double = 4, Optional ByRef courbure As Double = 0)
1521 'et pour les sommet
1522 Dim vParamEdge() As Double
1523 Dim i As Integer
1524 Dim a As Double
1525 Dim b As Integer
1526
1527 vParamEdge = swedge.GetCurveParams2
1528 b = Edgecirculaire(swedge)
1529 If b = 1 Then
1530 a = 0.0000000000001
1531 For i = 0 To cptVertex - 1
1532 If vParamEdge(0) < TabVertex(0, i) + a And vParamEdge(0) > TabVertex(0, i) - a And _
1533 vParamEdge(1) < TabVertex(1, i) + a And vParamEdge(1) > TabVertex(1, i) - a And _
1534 vParamEdge(2) < TabVertex(2, i) + a And vParamEdge(2) > TabVertex(2, i) - a Then
1535 If coeff < TabVertexDouble(0, i) Then
1536 TabVertexDouble(0, i) = coeff
1537 TabVertexDouble(1, i) = lambda
1538 TabVertexDouble(2, i) = courbure
1539 End If
1540 End If
1541 Next i
1542 For i = 0 To cptVertex - 1
1543 If vParamEdge(3) < TabVertex(0, i) + a And vParamEdge(3) > TabVertex(0, i) - a And _
1544 vParamEdge(4) < TabVertex(1, i) + a And vParamEdge(4) > TabVertex(1, i) - a And _
1545 vParamEdge(5) < TabVertex(2, i) + a And vParamEdge(5) > TabVertex(2, i) - a Then
1546 If coeff < TabVertexDouble(0, i) Then
1547 TabVertexDouble(0, i) = coeff
1548 TabVertexDouble(1, i) = lambda
1549 TabVertexDouble(2, i) = courbure
1550 End If
1551 End If
1552 Next i
1553 End If
1554 End Sub
1555 Sub CreerPointsVertex(ByRef Eng As Double, ByRef grill As grille)
1556 'créee les points sur les sommets
1557 Dim i As Integer
1558 Dim swvertex As SldWorks.Vertex
1559 Dim pt1 As point_grille
1560 Dim inserer As Boolean
1561
1562 For i = 0 To cptVertex - 1
1563 If TabVertexDouble(0, i) <> 1 Then
1564 Dim listpts As New Collection
1565 grill.rechercher(TabVertex(0, i), TabVertex(1, i), TabVertex(2, i), 0.5 * Eng * (1 - TabVertexDouble(0, i)), listpts)
1566 inserer = False
1567 If listpts.Count = 0 Then
1568 inserer = True
1569 Else
1570 Dim cmin As Double = 1
1571 Dim c_courant As Double
1572 Dim delta_courant As Double
1573 Dim delta_max As Double = 0
1574 Dim n As Integer
1575 For n = 1 To listpts.Count
1576 c_courant = TabPoints(3, listpts(n).get_id)
1577 delta_courant = TabPoints(7, listpts(n).get_id) * Eng * (1 - c_courant)
1578 If c_courant < cmin Then cmin = c_courant
1579 If delta_courant > delta_max Then delta_max = delta_courant
1580 Next
1581 c_courant = TabVertexDouble(0, i)
1582 delta_courant = TabVertexDouble(1, i) * Eng * (1 - c_courant)
1583 If c_courant < cmin Or delta_courant > delta_max Then inserer = True
1584 End If
1585 If inserer Then
1586 cpt = cpt + 1
1587 pt1 = New point_grille(TabVertex(0, i), TabVertex(1, i), TabVertex(2, i), cpt)
1588 grill.inserer(pt1)
1589
1590
1591
1592 ReDim Preserve TabPoints(8, cpt)
1593 ReDim Preserve tabpointsface(cpt)
1594 ReDim Preserve tabpointsedge(cpt)
1595
1596 TabPoints(0, cpt) = TabVertex(0, i)
1597 TabPoints(1, cpt) = TabVertex(1, i)
1598 TabPoints(2, cpt) = TabVertex(2, i)
1599 TabPoints(3, cpt) = TabVertexDouble(0, i)
1600 TabPoints(4, cpt) = 0
1601 TabPoints(7, cpt) = TabVertexDouble(1, i)
1602 TabPoints(8, cpt) = TabVertexDouble(2, i)
1603 tabpointsedge(cpt) = Nothing
1604 tabpointsface(cpt) = Nothing
1605 End If
1606 End If
1607 Next i
1608 End Sub
1609 Sub CreerPointsEdge(ByRef Eng As Double, ByRef grill As grille)
1610 'creer les point sur les aretes
1611 Dim cpt1 As Integer
1612 Dim cpt2 As Integer
1613 Dim vEdgeU() As Double
1614 Dim pas As Double
1615 Dim nbpas As Integer
1616 Dim points() As Double
1617 Dim swedge As SldWorks.Edge
1618 Dim longueur As Double
1619 Dim pasmax As Double
1620 Dim vfaceadj As Object
1621 Dim pt1 As point_grille
1622 Dim inserer As Boolean
1623
1624
1625 For cpt2 = 0 To UBound(TabEdgeDouble, 2)
1626 If TabEdgeDouble(0, cpt2) < 1 Then
1627 swedge = TabEdge(cpt2)
1628 vEdgeU = swedge.GetCurveParams2
1629 longueur = GetEdgeLenght(swedge)
1630 pasmax = distance_entre_points(Eng, TabEdgeDouble(0, cpt2), TabEdgeDouble(1, cpt2), TabEdgeDouble(2, cpt2), 0.5)
1631
1632 nbpas = 3 * Math.Max(2, Math.Floor(longueur / pasmax - 0.0001) + 1)
1633 pas = (vEdgeU(7) - vEdgeU(6)) / nbpas
1634
1635
1636 For cpt1 = 0 To nbpas
1637 points = swedge.Evaluate(vEdgeU(6) + pas * cpt1)
1638 Dim listpts As New Collection
1639 grill.rechercher(points(0), points(1), points(2), 0.5 * pasmax, listpts)
1640 inserer = False
1641 If listpts.Count = 0 Then
1642 inserer = True
1643 Else
1644 Dim cmin As Double = 1
1645 Dim c_courant As Double
1646 Dim delta_courant As Double
1647 Dim delta_max As Double = 0
1648 Dim i As Integer
1649 For i = 1 To listpts.Count
1650 c_courant = TabPoints(3, listpts(i).get_id)
1651 delta_courant = TabPoints(7, listpts(i).get_id) * Eng * (1 - c_courant)
1652 If c_courant < cmin Then cmin = c_courant
1653 If delta_courant > delta_max Then delta_max = delta_courant
1654 Next
1655 c_courant = TabEdgeDouble(0, cpt2)
1656 delta_courant = TabEdgeDouble(1, cpt2) * Eng * (1 - c_courant)
1657 If c_courant < cmin Or delta_courant > delta_max Then inserer = True
1658 End If
1659 If inserer Then
1660 cpt = cpt + 1
1661 pt1 = New point_grille(points(0), points(1), points(2), cpt)
1662 grill.inserer(pt1)
1663
1664
1665 ReDim Preserve TabPoints(8, cpt)
1666 ReDim Preserve tabpointsface(cpt)
1667 ReDim Preserve tabpointsedge(cpt)
1668
1669 TabPoints(0, cpt) = points(0)
1670 TabPoints(1, cpt) = points(1)
1671 TabPoints(2, cpt) = points(2)
1672 TabPoints(3, cpt) = TabEdgeDouble(0, cpt2)
1673 TabPoints(4, cpt) = 1
1674 TabPoints(5, cpt) = vEdgeU(6) + pas * cpt1
1675 TabPoints(7, cpt) = TabEdgeDouble(1, cpt2)
1676 TabPoints(8, cpt) = TabEdgeDouble(2, cpt2)
1677 tabpointsedge(cpt) = swedge
1678 tabpointsface(cpt) = Nothing
1679 End If
1680 Next cpt1
1681 End If
1682 Next cpt2
1683 End Sub
1684 Sub CreerPointsFace(ByRef Eng As Double, ByRef grill As grille)
1685 'creer les points sur les faces
1686 Dim cpt1 As Integer
1687 Dim cpt2 As Integer
1688 Dim cpt3 As Integer
1689 Dim swsurf As SldWorks.Surface
1690 Dim vFaceUV() As Double
1691 Dim vSurfParam() As Double
1692 Dim nbpasU As Integer
1693 Dim nbpasV As Integer
1694 Dim pasU As Double
1695 Dim PasV As Double
1696 Dim pasmax As Double
1697 Dim points() As Double
1698 Dim swface As SldWorks.Face2
1699 Dim vUVlong() As Double
1700 Dim vbbox() As Double
1701 Dim j As Integer
1702 Dim inserer As Boolean
1703
1704 For cpt3 = 0 To UBound(TabFaceDouble, 2)
1705 If TabFaceDouble(0, cpt3) < 1 Then
1706
1707 swface = Tabface(cpt3)
1708 swsurf = swface.GetSurface
1709
1710 Dim pt1 As point_grille
1711
1712 vFaceUV = swface.GetUVBounds
1713 vSurfParam = swsurf.Parameterization
1714
1715 vUVlong = GetUVLong(swface)
1716 pasmax = distance_entre_points(Eng, TabFaceDouble(0, cpt3), TabFaceDouble(1, cpt3), TabFaceDouble(2, cpt3), 0.5)
1717
1718 nbpasU = 3 * Math.Max(2, Math.Floor(vUVlong(0) / pasmax - 0.0001) + 1)
1719 nbpasV = 3 * Math.Max(2, Math.Floor(vUVlong(1) / pasmax - 0.0001) + 1)
1720
1721
1722 pasU = (vFaceUV(1) - vFaceUV(0)) / nbpasU
1723 PasV = (vFaceUV(3) - vFaceUV(2)) / nbpasV
1724
1725
1726 For cpt1 = 0 To nbpasU
1727 For cpt2 = 0 To nbpasV
1728 points = swsurf.Evaluate((vFaceUV(0) + pasU * cpt1), (vFaceUV(2) + PasV * cpt2), 0, 0)
1729 If PointIsInFace(swface, points) = True Then
1730 Dim listpts As New Collection
1731 grill.rechercher(points(0), points(1), points(2), 0.5 * pasmax, listpts)
1732 inserer = False
1733 If listpts.Count = 0 Then
1734 inserer = True
1735 Else
1736 Dim cmin As Double = 1
1737 Dim c_courant As Double
1738 Dim delta_courant As Double
1739 Dim delta_max As Double = 0
1740 Dim i As Integer
1741 For i = 1 To listpts.Count
1742 c_courant = TabPoints(3, listpts(i).get_id)
1743 delta_courant = TabPoints(7, listpts(i).get_id) * Eng * (1 - c_courant)
1744 If c_courant < cmin Then cmin = c_courant
1745 If delta_courant > delta_max Then delta_max = delta_courant
1746 Next
1747 c_courant = TabFaceDouble(0, cpt3)
1748 delta_courant = TabFaceDouble(1, cpt3) * Eng * (1 - c_courant)
1749 If c_courant < cmin Or delta_courant > delta_max Then inserer = True
1750 End If
1751 If inserer Then
1752 cpt = cpt + 1
1753 pt1 = New point_grille(points(0), points(1), points(2), cpt)
1754 grill.inserer(pt1)
1755
1756
1757 ReDim Preserve TabPoints(8, cpt)
1758 ReDim Preserve tabpointsface(cpt)
1759 ReDim Preserve tabpointsedge(cpt)
1760
1761 TabPoints(0, cpt) = points(0)
1762 TabPoints(1, cpt) = points(1)
1763 TabPoints(2, cpt) = points(2)
1764 TabPoints(3, cpt) = TabFaceDouble(0, cpt3)
1765 TabPoints(4, cpt) = 2
1766 TabPoints(5, cpt) = (vFaceUV(0) + pasU * cpt1)
1767 TabPoints(6, cpt) = (vFaceUV(2) + PasV * cpt2)
1768 TabPoints(7, cpt) = TabFaceDouble(1, cpt3)
1769 TabPoints(8, cpt) = TabFaceDouble(2, cpt3)
1770 tabpointsface(cpt) = swface
1771 tabpointsedge(cpt) = Nothing
1772 End If
1773 End If
1774 Next cpt2
1775 Next cpt1
1776 End If
1777 Next cpt3
1778 End Sub
1779 Sub CreerPointsVolume(ByRef Eng As Double, ByRef nbcouches As Integer, ByRef grill As grille)
1780 'creer les points dans le volume
1781 Dim cpt1 As Integer
1782 Dim Cpt2 As Integer = cpt
1783
1784 For cpt1 = 1 To Cpt2
1785 Select Case TabPoints(4, cpt1)
1786 Case 0
1787 PointVolumeVertex(TabPoints(0, cpt1), TabPoints(1, cpt1), TabPoints(2, cpt1), Eng, TabPoints(3, cpt1), nbcouches, grill)
1788 Case 1
1789 PointVolumeEdge(TabPoints(0, cpt1), TabPoints(1, cpt1), TabPoints(2, cpt1), tabpointsedge(cpt1), Eng, TabPoints(3, cpt1), nbcouches, grill)
1790 Case 2
1791 PointVolumeFace(TabPoints(0, cpt1), TabPoints(1, cpt1), TabPoints(2, cpt1), tabpointsface(cpt1), Eng, TabPoints(3, cpt1), nbcouches, grill)
1792 End Select
1793 Next
1794 End Sub
1795 Sub fichiertxt(ByRef Eng As Double, ByVal path As String)
1796 'ecriture du fichier texte
1797 Dim cpt1 As Long
1798 'Dim path As String
1799 Dim dg As Double
1800 'path = swModel.GetPathName()
1801 'path = Left(path, Len(path) - 12)
1802 Dim ligne_txt As String
1803
1804 Dim fichier As StreamWriter = File.CreateText(path)
1805 'MsgBox(path)
1806 ligne_txt = CStr(TabPoints(0, 0)) & " " & CStr(TabPoints(1, 0)) & " " & CStr(TabPoints(2, 0)) & " " & CStr(TabPoints(3, 0)) & " " & CStr(TabPoints(4, 0)) & " " & CStr(TabPoints(5, 0))
1807 fichier.WriteLine(Replace(ligne_txt, ",", "."))
1808 ligne_txt = Str(Eng)
1809 fichier.WriteLine(Replace(ligne_txt, ",", "."))
1810 For cpt1 = 1 To cpt
1811 ligne_txt = CStr(TabPoints(0, cpt1)) & " " & CStr(TabPoints(1, cpt1)) & " " & CStr(TabPoints(2, cpt1)) & " " & CStr(TabPoints(3, cpt1)) & " " & CStr(TabPoints(7, cpt1)) & " " & CStr(TabPoints(8, cpt1))
1812 fichier.WriteLine(Replace(ligne_txt, ",", "."))
1813 Next cpt1
1814 fichier.Close()
1815 End Sub
1816 Sub montrerpoints()
1817 'montre les points d'echantillonnage
1818 Dim cpt1 As Long
1819 Dim points As SldWorks.SketchPoint
1820
1821 swModel.SetAddToDB(True)
1822 swModel.Insert3DSketch2(False)
1823
1824 For cpt1 = 1 To cpt
1825 points = swModel.CreatePoint2(TabPoints(0, cpt1), TabPoints(1, cpt1), TabPoints(2, cpt1))
1826 Next cpt1
1827
1828 swModel.SetAddToDB(False)
1829 swModel.Insert3DSketch2(True)
1830 'MsgBox("points créés")
1831 swModel.EditRebuild3()
1832 End Sub
1833 Sub PointVolumeFace(ByRef x As Double, ByRef y As Double, ByRef z As Double, ByRef swface As SldWorks.Face2, ByRef Eng As Double, ByRef coeff As Double, ByRef nbcouches As Integer, ByVal grill As grille)
1834 'direction des points dans le volume pour les faces
1835 Dim i As Integer
1836 Dim j As Integer
1837 Dim N1(2) As Double
1838 Dim minusN1(2) As Double
1839 Dim P(2) As Double
1840 Dim Pi(2) As Double
1841 Dim Ci As Double
1842 Dim di As Double = 0
1843 Dim rdi As Double
1844 Dim lst As New Collection
1845 Dim pt1 As point_grille
1846 Dim vardi As Double
1847 Dim ParamFonction() As Double
1848 Dim F As Integer = 1
1849 Dim intvl As Integer
1850
1851 P(0) = x : P(1) = y : P(2) = z
1852 N1 = getNormatAtPoint(P, swface)
1853 N1 = Vecteur_Unitaire(N1)
1854 minusN1(0) = -N1(0) : minusN1(1) = -N1(1) : minusN1(2) = -N1(2)
1855 Pointsvolume(coeff, Eng, nbcouches, P, minusN1, grill)
1856
1857 End Sub
1858 Sub PointVolumeEdge(ByRef x As Double, ByRef y As Double, ByRef z As Double, ByRef swedge As SldWorks.Edge, ByRef Eng As Double, ByRef coeff As Double, ByRef nbcouches As Integer, ByVal grill As grille)
1859 'direction des points dans le volume pour les aretes
1860 Dim i As Integer
1861 Dim j As Integer
1862 Dim P(2) As Double
1863 Dim vfaceadj As Object
1864 Dim swface1 As SldWorks.Face2
1865 Dim swface2 As SldWorks.Face2
1866 Dim N1(2) As Double
1867 Dim N2(2) As Double
1868 Dim Phi As Double
1869 Dim nbline As Integer
1870 Dim gama As Double
1871 Dim Vi(2) As Double
1872 Dim Face1bool As Boolean
1873 Dim Face2bool As Boolean
1874
1875 P(0) = x : P(1) = y : P(2) = z
1876 vfaceadj = swedge.GetTwoAdjacentFaces2
1877 swface1 = vfaceadj(0)
1878 swface2 = vfaceadj(1)
1879
1880 Face1bool = faceIsAlreadyRepear(swface1)
1881 Face2bool = faceIsAlreadyRepear(swface2)
1882
1883 N1 = getNormatAtPoint(P, swface1) : N1 = Vecteur_Unitaire(N1)
1884 N2 = getNormatAtPoint(P, swface2) : N2 = Vecteur_Unitaire(N2)
1885
1886 N1(0) = -N1(0) : N1(1) = -N1(1) : N1(2) = -N1(2)
1887 N2(0) = -N2(0) : N2(1) = -N2(1) : N2(2) = -N2(2)
1888
1889 Phi = GetAngle(swedge, swface1, swface2)
1890
1891 Dim V() As Double = Produitvectoriel(N1, N2) : V = Vecteur_Unitaire(V)
1892 Dim S1() As Double = Produitvectoriel(V, N1) : S1 = Vecteur_Unitaire(S1)
1893 Dim S2() As Double = Produitvectoriel(N2, V) : S2 = Vecteur_Unitaire(S2)
1894
1895 If Phi > 180 Then
1896 S1(0) = -S1(0) : S1(1) = -S1(1) : S1(2) = -S1(2)
1897 S2(0) = -S2(0) : S2(1) = -S2(1) : S2(2) = -S2(2)
1898 End If
1899
1900 If Face1bool = False And Face2bool = False Then
1901 nbline = Int(Phi / 45)
1902 If nbline > 0 Then
1903 gama = Phi / (nbline + 1)
1904 Dim detA As Double = S1(0) * (N1(1) * V(2) - V(1) * N1(2)) - N1(0) * (S1(1) * V(2) - V(1) * S1(2)) + V(0) * (S1(1) * N1(2) - N1(1) * S1(2))
1905 For i = 1 To nbline
1906 Vi(0) = Math.Cos(i * gama * 3.14 / 180) * (N1(1) * V(2) - V(1) * N1(2)) - Math.Sin(i * gama * 3.14 / 180) * (S1(1) * V(2) - V(1) * S1(2)) : Vi(0) = Vi(0) / detA
1907 Vi(1) = -Math.Cos(i * gama * 3.14 / 180) * (N1(0) * V(2) - V(0) * N1(2)) + Math.Sin(i * gama * 3.14 / 180) * (S1(0) * V(2) - V(0) * S1(2)) : Vi(1) = Vi(1) / detA
1908 Vi(2) = Math.Cos(i * gama * 3.14 / 180) * (N1(0) * V(1) - V(0) * N1(1)) - Math.Sin(i * gama * 3.14 / 180) * (S1(0) * V(1) - V(0) * S1(1)) : Vi(2) = Vi(2) / detA
1909 Pointsvolume(coeff, Eng, nbcouches, P, Vi, grill)
1910 Next
1911 End If
1912 Pointsvolumeface(coeff, Eng, nbcouches, P, S2, grill, swface2)
1913 Pointsvolumeface(coeff, Eng, nbcouches, P, S1, grill, swface1)
1914 Else
1915 If Face1bool = True Then
1916 Pointsvolume(coeff, Eng, nbcouches, P, N1, grill)
1917 End If
1918 If Face2bool = True Then
1919 Pointsvolume(coeff, Eng, nbcouches, P, N2, grill)
1920 End If
1921 End If
1922
1923 End Sub
1924 Sub PointVolumeVertex(ByRef x As Double, ByRef y As Double, ByRef z As Double, ByRef Eng As Double, ByRef coeff As Double, ByRef nbcouches As Integer, ByVal grill As grille)
1925 'direction des points dans le volume pour les sommets
1926 Dim vedge As Object
1927 Dim xyz(2) As Double
1928 Dim swedge As SldWorks.Edge
1929 Dim Cprm() As Double
1930 Dim i As Integer
1931 Dim Strpt(2) As Double
1932 Dim Endpt(2) As Double
1933
1934 vedge = swbody.GetEdges
1935 xyz(0) = x : xyz(1) = y : xyz(2) = z
1936 For i = 0 To swbody.GetEdgeCount - 1
1937 swedge = vedge(i)
1938 Cprm = swedge.GetCurveParams2
1939 Strpt(0) = Cprm(0) : Strpt(1) = Cprm(1) : Strpt(2) = Cprm(2)
1940 Endpt(0) = Cprm(3) : Endpt(1) = Cprm(4) : Endpt(2) = Cprm(5)
1941 If PointEgale(xyz, Strpt) Or PointEgale(xyz, Endpt) Then
1942 If EdgeIsRepair(swedge) = True Then
1943 PointVolumeEdge(x, y, z, swedge, Eng, coeff, nbcouches, grill)
1944 End If
1945 End If
1946 Next i
1947 End Sub
1948 Sub Pointsvolume(ByRef coeff As Double, ByRef Eng As Double, ByRef nbcouches As Integer, ByRef P() As Double, ByRef dir() As Double, ByVal grill As grille)
1949 'creer les points dans le volume dans la direction donnée
1950 'objectif: pas de points dans le volume pour une fonction linéaire de Eni à Eng sur la taile de la zone d'influence du point de surface
1951 Dim ci As Double
1952 Dim di As Double
1953 Dim Vardi As Double
1954 Dim rdi As Double
1955 Dim rd As Double
1956 Dim j As Integer
1957 Dim Pi(2) As Double
1958 Dim lst As New Collection
1959 Dim pt1 As point_grille
1960 Dim Paramfonction() As Double
1961 Dim param As Double
1962 Dim F As Integer = 1
1963 Dim intvl As Integer
1964 Dim lambda As Double
1965 Dim Dface As Double
1966 Dim Dmax As Double
1967 Dim swface As SldWorks.Face2
1968
1969
1970 swface = GetFirstIntersectFace(dir, P)
1971 If Not swface Is Nothing Then
1972 Dface = DistPointFace(P, dir, swface)
1973 Else
1974 Dface = 0
1975 End If
1976
1977 If Dface <> 0 Then
1978 Dmax = Math.Min(nbcouches * Eng * (1 - coeff), Dface)
1979
1980 'départ au point di=0,
1981 For j = 0 To 2
1982 Pi(j) = P(j)
1983 Next j
1984
1985
1986 Paramfonction = FonctionVolume(0, coeff, F)
1987 Vardi = (nbcouches * Eng * (1 - coeff)) * 0.01
1988
1989 While di < Dmax And ci < 0.95
1990
1991 ci = Paramfonction(0)
1992 lambda = Math.Min(10, Math.Max(0.1, Math.Abs(Paramfonction(1)))) '+-lambda=pente locale de la courbe, limite inférieur--> pas de zones d'influences infinies, limte sup--» pas de zones microsopiques(discontinuitées)
1993 rd = di / (nbcouches * Eng * (1 - coeff))
1994
1995 For j = 0 To 2
1996 Pi(j) = P(j) + di * dir(j)
1997 Next j
1998
1999 If IsInBodyBox(Pi) = True Then
2000 If grill.chercher(Pi(0), Pi(1), Pi(2), Vardi / 2) = False Then
2001 cpt = cpt + 1
2002 pt1 = New point_grille(Pi(0), Pi(1), Pi(2), cpt)
2003 grill.inserer(pt1)
2004
2005 ReDim Preserve TabPoints(8, cpt)
2006 TabPoints(0, cpt) = Pi(0)
2007 TabPoints(1, cpt) = Pi(1)
2008 TabPoints(2, cpt) = Pi(2)
2009 TabPoints(3, cpt) = ci
2010 TabPoints(4, cpt) = 3
2011 TabPoints(5, cpt) = 1 / lambda
2012 End If
2013 End If
2014
2015 param = 0
2016
2017 While param < 0.1 And di < Dmax 'Compare la courbe théorique avec la droite issue du dernier pt, de courbe lambda, et avance jusqu'a un écart abs de 0.1
2018
2019 di = di + Vardi
2020 rdi = di / (nbcouches * Eng * (1 - coeff))
2021 Paramfonction = FonctionVolume(rdi, coeff, F)
2022 param = Math.Abs(Paramfonction(0) - ci - lambda * (rdi - rd))
2023
2024 End While
2025
2026 End While
2027 End If
2028 End Sub
2029 Sub Pointsvolumeface(ByRef coeff As Double, ByRef Eng As Double, ByRef nbcouches As Integer, ByRef P() As Double, ByRef dir() As Double, ByVal grill As grille, ByRef swface As SldWorks.Face2)
2030 'Cette sous routine génére des points dans le volume qui se retrouvent en fait sur une face
2031 Dim ci As Double
2032 Dim di As Double
2033 Dim Vardi As Double
2034 Dim rdi As Double
2035 Dim j As Integer
2036 Dim Pi(2) As Double
2037 Dim lst As New Collection
2038 Dim pt1 As point_grille
2039 Dim Paramfonction() As Double
2040 Dim param As Double
2041 Dim F As Integer = 1
2042 Dim intvl As Integer
2043 Dim Dmax As Double
2044 Dim lambda As Double
2045 Dim rd As Double
2046 Dmax = nbcouches * Eng * (1 - coeff)
2047
2048 For j = 0 To 2
2049 Pi(j) = P(j)
2050 Next j
2051
2052 Paramfonction = FonctionVolume(0, coeff, F)
2053 Vardi = (nbcouches * Eng * (1 - coeff)) * 0.01
2054
2055 While di < Dmax And ci < 0.95
2056
2057 'Mémorise pt placé:
2058
2059 ci = Paramfonction(0)
2060 lambda = Math.Min(10, Math.Max(0.1, Math.Abs(Paramfonction(1)))) '+-lambda=pente locale de la courbe, limite inférieur--> pas de zones d'influences infinies, limte sup--» pas de zones microsopiques(discontinuitées)
2061 rd = di / (nbcouches * Eng * (1 - coeff))
2062
2063 For j = 0 To 2
2064 Pi(j) = P(j) + di * dir(j)
2065 Next j
2066
2067 If IsInBodyBox(Pi) = True Then
2068 If grill.chercher(Pi(0), Pi(1), Pi(2), Vardi / 2) = False Then
2069 If PointIsInFace(swface, Pi) = True Then
2070 cpt = cpt + 1
2071 pt1 = New point_grille(Pi(0), Pi(1), Pi(2), cpt)
2072 grill.inserer(pt1)
2073
2074 ReDim Preserve TabPoints(8, cpt)
2075 TabPoints(0, cpt) = Pi(0)
2076 TabPoints(1, cpt) = Pi(1)
2077 TabPoints(2, cpt) = Pi(2)
2078 TabPoints(3, cpt) = ci
2079 TabPoints(4, cpt) = 3 'on pourrait mettre 4 mais en vérité ils se trouvent sur une face--Je mets 3 car points qui servent à suivre une fonctionnelle
2080 TabPoints(5, cpt) = 1 / lambda 'lambda=pente locale de la courbe
2081 End If
2082 End If
2083 End If
2084
2085 Paramfonction(2) = 0
2086
2087 param = 0
2088
2089 While param < 0.1 And di < Dmax 'Compare la courbe théorique avec la droite issue du dernier pt, de courbe lambda, et avance jusqu'a un écart de 0.1
2090
2091 di = di + Vardi
2092 rdi = di / (nbcouches * Eng * (1 - coeff))
2093 Paramfonction = FonctionVolume(rdi, coeff, F)
2094 param = Math.Abs(Paramfonction(0) - ci - lambda * (rdi - rd))
2095
2096 End While
2097
2098 End While
2099 End Sub
2100 Sub lire_fichier_ech(ByRef path As String)
2101 Dim fichier As StreamReader = New StreamReader(path)
2102 Dim line As String
2103 Dim Carray() As String
2104 Dim xyz(,) As Double
2105 Dim cptpoints As Long = 0
2106
2107 'les deux première ligne du fichier ne contienne pas de points d'échantillonnage
2108 line = fichier.ReadLine
2109 line = fichier.ReadLine
2110 line = fichier.ReadLine
2111
2112 Do
2113 ReDim Preserve xyz(2, cptpoints)
2114 Carray = line.Split(Chr(32))
2115 xyz(0, cptpoints) = CDbl(Carray(0))
2116 xyz(1, cptpoints) = CDbl(Carray(1))
2117 xyz(2, cptpoints) = CDbl(Carray(2))
2118 cptpoints = cptpoints + 1
2119 line = fichier.ReadLine()
2120 Loop Until line Is Nothing
2121
2122 fichier.Close()
2123
2124 Dim cpt1 As Long
2125 Dim points As SldWorks.SketchPoint
2126
2127 swModel.SetAddToDB(True)
2128 swModel.Insert3DSketch2(False)
2129
2130 For cpt1 = 0 To cptpoints - 1
2131 points = swModel.CreatePoint2(xyz(0, cpt1), xyz(1, cpt1), xyz(2, cpt1))
2132 Next cpt1
2133
2134 swModel.SetAddToDB(False)
2135 swModel.Insert3DSketch2(True)
2136 swModel.EditRebuild3()
2137
2138
2139 End Sub
2140 Function distance_entre_points(ByVal eng As Double, ByVal coef As Double, ByVal lmbd As Double, ByVal courbure As Double, ByVal erreur As Double) As Double
2141 Dim rmax As Double
2142 Dim nor As Double = 0.5
2143 Dim eni As Double = eng * coef
2144 Dim enmax As Double = eng * coef * (1 + erreur)
2145
2146
2147 If (courbure > 0.0001) Then rmax = 0.05 * (Math.Sqrt((nor * (eng - enmax) - eni + enmax) * (nor * (eng - enmax) - eni + enmax) - 40 * courbure * nor * (eni - enmax) * (eng - enmax)) - nor * (eng - enmax) + eni - enmax) / (courbure * nor * (eng - enmax))
2148 If (courbure <= 0.0001) Then rmax = (enmax - eni) / (nor * (eng - enmax) - eni + enmax)
2149
2150
2151 Return 2 * rmax * lmbd * eng * (1 - coef)
2152
2153 End Function
2154
2155 Function get_edge_lenght(ByRef swedge As SldWorks.Edge, ByVal t1 As Double, ByVal t2 As Double) As Double
2156 Dim curve As SldWorks.Curve
2157 Dim curveparam() As Double
2158 Dim cpt As Integer
2159 Dim cpt1 As Integer
2160 Dim i As Integer
2161 Dim swent As SldWorks.Entity
2162 Dim bRet As Boolean
2163 Dim lmbd_rm, courb_rm As Double
2164 Dim longueur As Double
2165 Dim Nb_pas As Integer
2166 Dim pas As Double
2167 Dim ti As Double
2168 Dim tip1 As Double
2169 Dim parametre_au_point() As Double
2170 Dim tgauss1 As Double
2171 Dim tgauss2 As Double
2172 Dim cprim1 As Double
2173 Dim cprim2 As Double
2174
2175 Nb_pas = 10
2176 longueur = 0
2177
2178 curveparam = swedge.GetCurveParams2()
2179 curve = swedge.GetCurve()
2180
2181 If (t1 <= curveparam(6)) Then t1 = curveparam(6)
2182 If (t2 >= curveparam(7)) Then t2 = curveparam(7)
2183
2184 pas = (t2 - t1) / Nb_pas
2185 ti = t1
2186
2187 For cpt1 = 0 To Nb_pas - 1
2188
2189 tip1 = ti + pas
2190 tgauss1 = ((1 / Math.Sqrt(3) + 1) * ti + (-1 / Math.Sqrt(3) + 1) * tip1) / 2
2191 tgauss2 = ((-1 / Math.Sqrt(3) + 1) * ti + (1 / Math.Sqrt(3) + 1) * tip1) / 2
2192
2193 parametre_au_point = curve.Evaluate(tgauss1)
2194 cprim1 = Math.Sqrt(parametre_au_point(3) * parametre_au_point(3) + parametre_au_point(4) * parametre_au_point(4) + parametre_au_point(5) * parametre_au_point(5))
2195
2196 parametre_au_point = curve.Evaluate(tgauss2)
2197 cprim2 = Math.Sqrt(parametre_au_point(3) * parametre_au_point(3) + parametre_au_point(4) * parametre_au_point(4) + parametre_au_point(5) * parametre_au_point(5))
2198
2199 longueur = longueur + (tip1 - ti) / 2 * (cprim1 + cprim2)
2200
2201 ti = ti + pas
2202 Next
2203
2204 Return longueur
2205
2206 End Function
2207
2208 Function get_edge_plane_lenght(ByRef swedge As SldWorks.Edge, ByRef n() As Double) As Double
2209 ' donne la longueur d'une arête, projettée selon le plan normal à un vecteur donné
2210 Dim curve As SldWorks.Curve
2211 Dim curveparam() As Double
2212 Dim cpt As Integer
2213 Dim cpt1 As Integer
2214 Dim i As Integer
2215 Dim swent As SldWorks.Entity
2216 Dim bRet As Boolean
2217 Dim lmbd_rm, courb_rm As Double
2218 Dim longueur As Double
2219 Dim Nb_pas As Integer
2220 Dim pas As Double
2221 Dim ti As Double
2222 Dim tip1 As Double
2223 Dim parametre_au_point() As Double
2224 Dim tgauss1 As Double
2225 Dim tgauss2 As Double
2226 Dim cprim1 As Double
2227 Dim cprim2 As Double
2228 Dim u(2) As Double
2229 Dim v(2) As Double
2230 Dim b As Double
2231 Dim c As Double
2232 Dim delta As Double
2233 Dim t1 As Double
2234 Dim t2 As Double
2235
2236 Nb_pas = 15
2237 longueur = 0
2238
2239 curveparam = swedge.GetCurveParams2()
2240 curve = swedge.GetCurve()
2241
2242 t1 = curveparam(6)
2243 t2 = curveparam(7)
2244
2245 pas = (t2 - t1) / Nb_pas
2246 ti = t1
2247
2248 For cpt1 = 0 To Nb_pas - 1
2249 ti = t1 + cpt1 * pas
2250 tip1 = ti + pas
2251 tgauss1 = ((1 / Math.Sqrt(3) + 1) * ti + (-1 / Math.Sqrt(3) + 1) * tip1) / 2
2252 tgauss2 = ((-1 / Math.Sqrt(3) + 1) * ti + (1 / Math.Sqrt(3) + 1) * tip1) / 2
2253
2254 parametre_au_point = curve.Evaluate(tgauss1)
2255 u(0) = parametre_au_point(3)
2256 u(1) = parametre_au_point(4)
2257 u(2) = parametre_au_point(5)
2258 cprim1 = Produit_scalaire(Vecteur_Unitaire(Produitvectoriel(Produitvectoriel(n, u), n)), u)
2259
2260
2261 parametre_au_point = curve.Evaluate(tgauss2)
2262 u(0) = parametre_au_point(3)
2263 u(1) = parametre_au_point(4)
2264 u(2) = parametre_au_point(5)
2265 cprim2 = Produit_scalaire(Vecteur_Unitaire(Produitvectoriel(Produitvectoriel(n, u), n)), u)
2266
2267 longueur = longueur + pas / 2 * (cprim1 + cprim2)
2268 Next
2269
2270 Return longueur
2271
2272 End Function
2273 Function get_edge_plane_lenght(ByRef swedge As SldWorks.Edge, ByRef n() As Double, ByVal t1 As Double, ByVal t2 As Double) As Double
2274 ' donne la longueur d'une arête, projettée selon le plan normal à un vecteur donné
2275 Dim curve As SldWorks.Curve
2276 Dim curveparam() As Double
2277 Dim cpt As Integer
2278 Dim cpt1 As Integer
2279 Dim i As Integer
2280 Dim swent As SldWorks.Entity
2281 Dim bRet As Boolean
2282 Dim lmbd_rm, courb_rm As Double
2283 Dim longueur As Double
2284 Dim Nb_pas As Integer
2285 Dim pas As Double
2286 Dim ti As Double
2287 Dim tip1 As Double
2288 Dim parametre_au_point() As Double
2289 Dim tgauss1 As Double
2290 Dim tgauss2 As Double
2291 Dim cprim1 As Double
2292 Dim cprim2 As Double
2293 Dim u(2) As Double
2294 Dim v(2) As Double
2295 Dim b As Double
2296 Dim c As Double
2297 Dim delta As Double
2298
2299
2300 Nb_pas = 15
2301 longueur = 0
2302
2303
2304 curveparam = swedge.GetCurveParams2()
2305 curve = swedge.GetCurve()
2306
2307 If (t1 <= curveparam(6)) Then t1 = curveparam(6)
2308 If (t2 >= curveparam(7)) Then t2 = curveparam(7)
2309
2310 pas = (t2 - t1) / Nb_pas
2311 ti = t1
2312
2313 For cpt1 = 0 To Nb_pas - 1
2314 ti = t1 + cpt1 * pas
2315 tip1 = ti + pas
2316 tgauss1 = ((1 / Math.Sqrt(3) + 1) * ti + (-1 / Math.Sqrt(3) + 1) * tip1) / 2
2317 tgauss2 = ((-1 / Math.Sqrt(3) + 1) * ti + (1 / Math.Sqrt(3) + 1) * tip1) / 2
2318
2319 parametre_au_point = curve.Evaluate(tgauss1)
2320 u(0) = parametre_au_point(3)
2321 u(1) = parametre_au_point(4)
2322 u(2) = parametre_au_point(5)
2323 cprim1 = Produit_scalaire(Vecteur_Unitaire(Produitvectoriel(Produitvectoriel(n, u), n)), u)
2324
2325
2326 parametre_au_point = curve.Evaluate(tgauss2)
2327 u(0) = parametre_au_point(3)
2328 u(1) = parametre_au_point(4)
2329 u(2) = parametre_au_point(5)
2330 cprim2 = Produit_scalaire(Vecteur_Unitaire(Produitvectoriel(Produitvectoriel(n, u), n)), u)
2331
2332 longueur = longueur + pas / 2 * (cprim1 + cprim2)
2333 Next
2334
2335 Return longueur
2336
2337 End Function
2338
2339 Function get_loop_plane_area(ByRef swloop As SldWorks.Loop2, ByRef ns() As Double) As Double
2340 ' donne l'aire délimité par une boucle donnée, projettée selon le plan normal à un vecteur donné
2341 Dim swedge As SldWorks.Edge
2342 Dim ledge As Object
2343 Dim curve As SldWorks.Curve
2344 Dim curveparam() As Double
2345 Dim cpt As Integer
2346 Dim cpt1 As Integer
2347 Dim div As Double
2348 Dim swent As SldWorks.Entity
2349 Dim bRet As Boolean
2350 Dim lmbd_rm, courb_rm As Double
2351 Dim surface As Double
2352 Dim Nb_pas As Integer = 20
2353 Dim pas As Double = 0
2354 Dim t1 As Double
2355 Dim t2 As Double
2356 Dim ti As Double
2357 Dim tip1 As Double
2358 Dim v(2) As Double
2359 Dim n1(2) As Double
2360 Dim n2(2) As Double
2361 Dim phi1(2) As Double
2362 Dim phi2(2) As Double
2363 Dim xyz() As Double
2364 Dim lgi As Double
2365 Dim tgauss1 As Double
2366 Dim tgauss2 As Double
2367 Dim phi(2) As Double
2368 Dim t(2) As Double
2369 Dim i As Integer
2370 Dim nb_edge As Integer
2371 Dim pt(2) As Double
2372 Dim curvparmip1
2373 Dim dpt As Double
2374 Dim sens As Integer ' sens de parcous de la première arête
2375 Dim sensi As Integer
2376 Dim f1 As Double
2377 Dim f2 As Double
2378 Dim dl As Double
2379
2380 ledge = swloop.GetEdges
2381 swedge = ledge(0)
2382 curveparam = swedge.GetCurveParams2()
2383 v = swedge.Evaluate(curveparam(6))
2384 t(0) = v(3) : t(1) = v(4) : t(2) = v(5)
2385 phi = Produitvectoriel(ns, t)
2386
2387 phi = Vecteur_Unitaire(phi)
2388
2389 nb_edge = swloop.GetEdgeCount
2390 For cpt = 0 To nb_edge - 1
2391 sens = 1
2392 If cpt <> 0 Then pt = swedge.Evaluate(t2)
2393 swedge = ledge(cpt)
2394 curveparam = swedge.GetCurveParams2()
2395 curve = swedge.GetCurve()
2396 t1 = curveparam(6)
2397 t2 = curveparam(7)
2398 If cpt = 0 Then
2399 If nb_edge > 1 Then
2400 swedge = ledge(cpt + 1)
2401 curvparmip1 = swedge.GetCurveParams2()
2402 dpt = Math.Sqrt((curveparam(0) - curvparmip1(0)) ^ 2 + (curveparam(1) - curvparmip1(1)) ^ 2 + (curveparam(2) - curvparmip1(2)) ^ 2)
2403 If dpt > 0.01 * GetEdgeLenght(swedge) Then
2404 sens = -1
2405 t1 = curveparam(7)
2406 t2 = curveparam(6)
2407 End If
2408 swedge = ledge(cpt)
2409 End If
2410 Else
2411 dpt = Math.Sqrt((curveparam(0) - pt(0)) ^ 2 + (curveparam(1) - pt(1)) ^ 2 + (curveparam(2) - pt(2)) ^ 2)
2412 If dpt > 0.01 * GetEdgeLenght(swedge) Then
2413 sens = -1
2414 t1 = curveparam(7)
2415 t2 = curveparam(6)
2416 End If
2417 End If
2418 pas = (t2 - t1) / Nb_pas
2419 ti = t1
2420
2421 For cpt1 = 0 To Nb_pas - 1
2422 ti = t1 + cpt1 * pas
2423 tip1 = ti + pas
2424 tgauss1 = ((1 / Math.Sqrt(3) + 1) * ti + (-1 / Math.Sqrt(3) + 1) * tip1) / 2
2425 tgauss2 = ((-1 / Math.Sqrt(3) + 1) * ti + (1 / Math.Sqrt(3) + 1) * tip1) / 2
2426
2427 v = swedge.Evaluate(tgauss1)
2428 t(0) = -sens * v(3) : t(1) = -sens * v(4) : t(2) = -sens * v(5)
2429 n1 = Produitvectoriel(ns, t)
2430 ' n1 = Vecteur_Unitaire(n1)
2431
2432 phi1(0) = phi(0) * Produit_scalaire(v, phi)
2433 phi1(1) = phi(1) * Produit_scalaire(v, phi)
2434 phi1(2) = phi(2) * Produit_scalaire(v, phi)
2435
2436 v = swedge.Evaluate(tgauss2)
2437 t(0) = -sens * v(3) : t(1) = -sens * v(4) : t(2) = -sens * v(5)
2438 n2 = Produitvectoriel(ns, t)
2439 ' n2 = Vecteur_Unitaire(n2)
2440
2441 phi2(0) = phi(0) * Produit_scalaire(v, phi)
2442 phi2(1) = phi(1) * Produit_scalaire(v, phi)
2443 phi2(2) = phi(2) * Produit_scalaire(v, phi)
2444
2445 f1 = Produit_scalaire(phi1, n1)
2446 f2 = Produit_scalaire(phi2, n2)
2447
2448 ' dl = get_edge_plane_lenght(swedge, ns, ti, tip1)
2449
2450 surface = surface + (f1 + f2) * pas / 2
2451 Next cpt1
2452 Next cpt
2453 Return Math.Abs(surface)
2454
2455 End Function
2456
2457 Function GetAnglem(ByRef swedge As SldWorks.Edge, ByRef swface1 As SldWorks.Face2, ByRef swface2 As SldWorks.Face2, ByVal opt As String, ByRef tm As Double) As Double
2458 'donne l'angle matiere maximum ou minimum sur une arête, ainsi que le parametre de position du point du maximum (ou minimum)
2459
2460 Dim vEdgeparam As Object
2461 Dim swcurve As SldWorks.Curve
2462 Dim xyz As Object
2463 Dim tmin As Double
2464 Dim tmax As Double
2465 Dim t1 As Double
2466 Dim t2 As Double
2467 Dim angle As Double
2468 Dim dangle As Double
2469 Dim t As Double
2470 Dim dt As Double
2471 Dim pas As Double
2472 Dim cpt As Integer
2473 Dim Nb_pas As Integer = 15
2474 Dim anglemin As Double = 360
2475 Dim anglemax As Double = 0
2476 Dim data(Nb_pas, 1) As Double
2477 Dim a1 As Double
2478 Dim a2 As Double
2479 Dim danglemin1 As Double = 1000
2480 Dim danglemin2 As Double = 1000
2481 Dim i As Integer = 0
2482
2483
2484 vEdgeparam = swedge.GetCurveParams2
2485 swcurve = swedge.GetCurve
2486 t1 = vEdgeparam(6)
2487 t2 = vEdgeparam(7)
2488
2489 pas = (t2 - t1) / (Nb_pas - 1)
2490 For cpt = 0 To Nb_pas
2491 t = t1 + (cpt - 1) * pas
2492 a1 = GetAngle(swedge, swface1, swface2, pararam_cycliques(t, t1, t2))
2493 a2 = GetAngle(swedge, swface1, swface2, pararam_cycliques(t + pas, t1, t2))
2494 dangle = (a2 - a1) / pas
2495 angle = (a2 + a1) / 2
2496 data(cpt, 0) = dangle
2497 data(cpt, 1) = pararam_cycliques(t + pas / 2, t1, t2)
2498 If angle <= anglemin + 0.001 Then anglemin = angle : tmin = t
2499 If angle >= anglemax - 0.001 Then anglemax = angle : tmax = t
2500 Next
2501 While Math.Abs(danglemin1) > 0.1 And Math.Abs(danglemin2) > 0.1 And i < 20
2502 For cpt = 0 To Nb_pas - 1
2503 If data(cpt, 0) * data(cpt + 1, 0) <= 0.0001 Then
2504 If (data(cpt + 1, 0) - data(cpt, 0) <> 0) Then
2505 If (Math.Abs(data(cpt + 1, 1) - data(cpt, 1)) > pas) Then
2506 t = -data(cpt, 0) / (data(cpt + 1, 0) - data(cpt, 0)) * (data(cpt + 1, 1) - data(cpt, 1) + t2 - t1) + data(cpt, 1)
2507 Else
2508 t = -data(cpt, 0) / (data(cpt + 1, 0) - data(cpt, 0)) * (data(cpt + 1, 1) - data(cpt, 1)) + data(cpt, 1)
2509 End If
2510 t = pararam_cycliques(t, t1, t2)
2511 dangle = (GetAngle(swedge, swface1, swface2, t + Math.Min(t2 - t, pas / 10)) - GetAngle(swedge, swface1, swface2, t - Math.Min(t - t1, pas / 10))) / (Math.Min(t2 - t, pas / 10) + Math.Min(t - t1, pas / 10))
2512 data(cpt, 0) = dangle
2513 data(cpt, 1) = t
2514 Else
2515 t = data(cpt, 1)
2516 End If
2517
2518 angle = GetAngle(swedge, swface1, swface2, t)
2519 If angle <= anglemin + 0.001 Then anglemin = angle : tmin = t : If Math.Abs(data(cpt, 0)) < Math.Abs(danglemin1) Then danglemin1 = data(cpt, 0)
2520 If angle >= anglemax - 0.001 Then anglemax = angle : tmax = t : If Math.Abs(data(cpt, 0)) < Math.Abs(danglemin2) Then danglemin2 = data(cpt, 0)
2521 End If
2522 Next cpt
2523 i = i + 1
2524 End While
2525 If opt = "min" Then tm = tmin : GetAnglem = anglemin
2526 If opt = "max" Then tm = tmax : GetAnglem = anglemax
2527
2528 End Function
2529 Function pararam_cycliques(ByVal u As Double, ByRef u1 As Double, ByRef u2 As Double) As Double
2530 If (u < u1) Then
2531 pararam_cycliques = u2 - u1 + u
2532 Else
2533 If (u > u2) Then
2534 pararam_cycliques = u1 + u - u2
2535 Else
2536 pararam_cycliques = u
2537 End If
2538 End If
2539 End Function
2540 Function anglemin_face_arete(ByRef swface As SldWorks.Face2, ByRef swedge As SldWorks.Edge, ByRef vertex As SldWorks.Vertex) As Double
2541 'Donne l'angle entre une face et une arete, au point commun face-arete, angle orienté de telle facon qu'il soit minimum
2542 Dim n(2) As Double
2543 Dim u() As Double
2544 Dim angle As Double
2545 Dim pt() As Double
2546 Dim t As Double
2547 Dim phi As Double
2548 Dim v(2) As Double
2549
2550 pt = vertex.GetPoint
2551 n = getNormatAtPoint(pt, swface)
2552 n = Vecteur_Unitaire(n)
2553 t = swedge.GetParameter(pt(0), pt(1), pt(2))
2554 u = swedge.Evaluate(t)
2555 v(0) = u(3) : v(1) = u(4) : v(2) = u(5)
2556
2557 v = Vecteur_Unitaire(v)
2558 If (Produit_scalaire(n, v) < 0) Then v(0) = -v(0) : v(1) = -v(1) : v(2) = -v(2)
2559 n = Produitvectoriel(n, v)
2560 phi = 180 / Math.PI * Math.Asin(Math.Sqrt(n(0) ^ 2 + n(1) ^ 2 + n(2) ^ 2))
2561 v(0) = -v(0) : v(1) = -v(1) : v(2) = -v(2)
2562 anglemin_face_arete = phi
2563 End Function
2564 Function anglemin_face_arete(ByRef swface As SldWorks.Face2, ByRef swedge As SldWorks.Edge, ByRef pt() As Double, ByRef v() As Double) As Double
2565 'Donne l'angle entre une face et une arete, au point commun face-arete, angle orienté de telle facon qu'il soit minimum, et le vecteur porté par l'arete rentrant dans la matière
2566 Dim n(2) As Double
2567 Dim u() As Double
2568 Dim angle As Double
2569 Dim t() As Double
2570 Dim phi As Double
2571
2572 n = getNormatAtPoint(pt, swface)
2573 n = Vecteur_Unitaire(n)
2574 t = swedge.GetParameter(pt(0), pt(1), pt(2))
2575 If t(1) Then
2576 u = swedge.Evaluate(t(0))
2577 Else
2578 MsgBox("erreur ! fonction anglemin_face_arete")
2579 End If
2580
2581 v(0) = u(3) : v(1) = u(4) : v(2) = u(5)
2582
2583 v = Vecteur_Unitaire(v)
2584 If (Produit_scalaire(n, v) < 0) Then v(0) = -v(0) : v(1) = -v(1) : v(2) = -v(2)
2585 n = Produitvectoriel(n, v)
2586 phi = 180 / Math.PI * Math.Asin(Math.Sqrt(n(0) ^ 2 + n(1) ^ 2 + n(2) ^ 2))
2587 v(0) = -v(0) : v(1) = -v(1) : v(2) = -v(2)
2588 anglemin_face_arete = phi
2589 End Function
2590
2591 Function direction_retrait_matiere(ByRef swloop As SldWorks.Loop2, ByRef swfaceref As SldWorks.Face2) As Double()
2592 'donne le vecteur de direction d'un retrait de matière à partir d'une boucle interne à une face, surlaquelle on a détecté un retrait de matière
2593 Dim swface As SldWorks.Face2
2594 Dim swfacetmp As SldWorks.Face2
2595 Dim swfacetmp2 As SldWorks.Face2
2596 Dim swsurface As SldWorks.Surface
2597 Dim cpt1 As Integer
2598 Dim cpt2 As Integer
2599 Dim swedge As SldWorks.Edge
2600 Dim swedgetmp As SldWorks.Edge
2601 Dim swedgetmp1 As SldWorks.Edge
2602 Dim swedgetmp2 As SldWorks.Edge
2603 Dim vedge As Object
2604 Dim vedgetmp1 As Object
2605 Dim vedgetmp2 As Object
2606 Dim vface As Object
2607 Dim vfacetmp As Object
2608 Dim i As Integer
2609 Dim lg As Double
2610 Dim n(2) As Double
2611 Dim nmin(2) As Double
2612 Dim nmax(2) As Double
2613 Dim area As Double
2614 Dim angle_min As Double
2615 Dim angle_max As Double
2616 Dim angle As Double
2617 Dim angletmp As Double
2618 Dim t As Double
2619 Dim curvparm1() As Double
2620 Dim curvparm2() As Double
2621 Dim pt(2) As Double
2622 Dim multiface As Boolean = False
2623
2624
2625 angle_min = 180 : angle_max = 0
2626 nmin(0) = 0 : nmin(1) = 0 : nmin(2) = 0 : nmax(0) = 0 : nmax(1) = 0 : nmax(2) = 0
2627
2628 vedge = swloop.GetEdges
2629
2630 For cpt1 = 0 To swloop.GetEdgeCount - 1
2631 swedgetmp = vedge(cpt1)
2632 vfacetmp = swedgetmp.GetTwoAdjacentFaces
2633 swfacetmp = vfacetmp(0)
2634 If swfacetmp.IsSame(swfaceref) = True Then
2635 swfacetmp = vfacetmp(1)
2636 Else
2637 If vfacetmp(1).IsSame(swfaceref) = False Then
2638 multiface = True
2639 Continue For
2640 End If
2641 End If
2642
2643 angle = GetAnglem(swedgetmp, swfaceref, swfacetmp, "min", t)
2644 If angle < angle_min Then angle_min = angle : nmin = Get_vect_into_mat(swedgetmp, swfacetmp, t)
2645 angle = GetAnglem(swedgetmp, swfaceref, swfacetmp, "max", t)
2646 If angle > angle_max Then angle_max = angle : nmax = Get_vect_into_mat(swedgetmp, swfacetmp, t)
2647
2648 If cpt1 > 0 Then
2649 curvparm1 = swedgetmp.GetCurveParams2
2650 curvparm2 = swedgetmp2.GetCurveParams2
2651 lg = Math.Min(GetEdgeLenght(swedgetmp), GetEdgeLenght(swedgetmp2))
2652 pt(0) = curvparm1(0) : pt(1) = curvparm1(1) : pt(2) = curvparm1(2)
2653 If (Math.Sqrt((pt(0) - curvparm2(0)) ^ 2 + (pt(1) - curvparm2(1)) ^ 2 + (pt(2) - curvparm2(2)) ^ 2) > 0.1 * lg And Math.Sqrt((pt(0) - curvparm2(3)) ^ 2 + (pt(1) - curvparm2(4)) ^ 2 + (pt(2) - curvparm2(5)) ^ 2) > 0.1 * lg) Then pt(0) = curvparm1(3) : pt(1) = curvparm1(4) : pt(2) = curvparm1(5)
2654 If (Math.Sqrt((pt(0) - curvparm2(0)) ^ 2 + (pt(1) - curvparm2(1)) ^ 2 + (pt(2) - curvparm2(2)) ^ 2) > 0.1 * lg And Math.Sqrt((pt(0) - curvparm2(3)) ^ 2 + (pt(1) - curvparm2(4)) ^ 2 + (pt(2) - curvparm2(5)) ^ 2) > 0.1 * lg) Then MsgBox("erreur")
2655
2656 vedgetmp1 = swfacetmp.GetEdges
2657 For cpt2 = 0 To UBound(vedgetmp1)
2658 swedgetmp1 = vedgetmp1(cpt2)
2659 curvparm1 = swedgetmp1.GetCurveParams2
2660 lg = GetEdgeLenght(swedgetmp1)
2661 If (Math.Sqrt((pt(0) - curvparm1(0)) ^ 2 + (pt(1) - curvparm1(1)) ^ 2 + (pt(2) - curvparm1(2)) ^ 2) < 0.1 * lg Or Math.Sqrt((pt(0) - curvparm1(3)) ^ 2 + (pt(1) - curvparm1(4)) ^ 2 + (pt(2) - curvparm1(5)) ^ 2) < 0.1 * lg) Then
2662 If (swedgetmp1.GetCurve.Equals(swedgetmp.GetCurve) = False) Then
2663 angle = anglemin_face_arete(swfaceref, swedgetmp1, pt, n)
2664 If 90 + angle > angle_max Then angle_max = 90 + angle : nmax(0) = n(0) : nmax(1) = n(1) : nmax(2) = n(2)
2665 If 90 - angle < angle_min Then angle_min = 90 - angle : nmin(0) = n(0) : nmin(1) = n(1) : nmin(2) = n(2)
2666 End If
2667 End If
2668 Next cpt2
2669 End If
2670
2671 swfacetmp2 = swfacetmp
2672 swedgetmp2 = swedgetmp
2673 Next cpt1
2674
2675 If (multiface) Then
2676 If (90 - angle_min > angle_max - 90) Then
2677 n(0) = nmin(0)
2678 n(1) = nmin(1)
2679 n(2) = nmin(2)
2680 Else
2681 n(0) = nmax(0)
2682 n(1) = nmax(1)
2683 n(2) = nmax(2)
2684 End If
2685 Else
2686 n(0) = nmin(0) + nmax(0)
2687 n(1) = nmin(1) + nmax(1)
2688 n(2) = nmin(2) + nmax(2)
2689 If (n(2) + n(2) + n(2) = 0) Then MsgBox("erreur, vecteur de norme nulle")
2690 n = Vecteur_Unitaire(n)
2691 End If
2692 direction_retrait_matiere = n
2693 End Function
2694 Function raffinn_auto_retrait_mat(ByVal Erx_ref As Double, ByRef coef As Double, ByRef lmbd As Double, ByRef courb As Double, ByVal Dng As Double, ByVal rayon As Double, ByVal pentelimite As Double, ByRef params() As Double) As Boolean
2695 Dim delta_ref_theo As Double
2696 Dim delta_ref_ptlimite As Double
2697 Dim Eng_ref As Double
2698 Dim delta As Double
2699 Dim Eni_ref As Double
2700 Dim Eni As Double
2701 Dim A As Double = 0.12
2702 Dim B As Double = 0.68
2703 Dim param_rm() As Double
2704
2705 Dim x As Double
2706 Dim pente As Double
2707
2708
2709 Eng_ref = Dng / rayon
2710 If Eng_ref > 0.00001 Then
2711
2712 Eni_ref = Erx_ref / (A * Math.Pow(contrainte_vm_rm_ref(0, 2, param_rm), B)) ' estimateur
2713
2714 delta_ref_theo = (Math.Log(Math.Pow(Erx_ref / (A * Eng_ref), 1 / B) / (param_rm(2) * param_rm(2))) - param_rm(1)) / param_rm(2) - 1
2715 delta_ref_ptlimite = delta_ref_theo
2716
2717 For x = 0 To 0.9 * delta_ref_theo Step delta_ref_theo / 10
2718 pente = (Erx_ref / (A * Math.Pow(contrainte_vm_rm_ref(x + delta_ref_theo / 10, 2, param_rm), B)) - Erx_ref / (A * Math.Pow(contrainte_vm_rm_ref(x, 2, param_rm), B))) / (delta_ref_theo / 10)
2719 If pente > pentelimite Then
2720 delta_ref_ptlimite = (Eng_ref - Erx_ref / (A * Math.Pow(contrainte_vm_rm_ref(x, 2, param_rm), B))) / pentelimite + x
2721 Exit For
2722 End If
2723 Next
2724
2725
2726 delta = Math.Max(delta_ref_theo, delta_ref_ptlimite) * rayon
2727 courb = Math.Min(-0.5 * (1 - 0.25 * (delta_ref_ptlimite - delta_ref_theo) / delta_ref_theo), 0)
2728 Eni = Eni_ref * rayon
2729 coef = Eni / Dng
2730 lmbd = delta / (Dng - Eni)
2731 raffinn_auto_retrait_mat = True
2732 Else
2733 raffinn_auto_retrait_mat = False
2734 End If
2735 ReDim params(1)
2736 params(0) = A : params(1) = B
2737 End Function
2738 Function contrainte_vm_rm_ref(ByVal x As Double, ByVal degre As Integer, ByRef param As Double()) As Double
2739 Dim A As Double = 1.06446
2740 Dim B As Double = 4.1287
2741 Dim C As Double = -3.46124
2742 Dim D As Double = -0.00946
2743
2744 ' contrainte vm du retrait de matiere de reference et ses dérivées en fct de la position / a la surface su retrait matiere
2745 x = x + 1
2746 If degre = 0 Then
2747 contrainte_vm_rm_ref = A + Math.Exp(B + C * x) + D * x
2748 Else
2749 If degre = 1 Then
2750 contrainte_vm_rm_ref = C * Math.Exp(B + C * x) + D
2751 Else
2752 If degre = 2 Then
2753 contrainte_vm_rm_ref = C * C * Math.Exp(B + C * x)
2754 Else
2755 contrainte_vm_rm_ref = 0
2756 End If
2757 End If
2758 End If
2759 ReDim param(4)
2760 param(0) = A : param(1) = B : param(2) = C : param(3) = D
2761 End Function
2762 Function determination_ecart_nodal_global_retraits_mat(ByRef Erx_m As Double, ByRef coeffmin As Double) As Double
2763
2764 Dim swface As SldWorks.Face2
2765 Dim swsurface As SldWorks.Surface
2766 Dim swfaceref As SldWorks.Face2
2767 Dim swfeat As SldWorks.Feature
2768 Dim swloop As SldWorks.Loop2
2769 Dim cpt1 As Integer
2770 Dim cpt2 As Integer
2771 Dim swedge As SldWorks.Edge
2772 Dim swedgetmp As SldWorks.Edge
2773 Dim vedge As Object
2774 Dim vface As Object
2775 Dim cpt3 As Integer
2776 Dim cpt4 As Integer
2777 Dim lg As Double
2778 Dim lgi As Double
2779 Dim angle As Double
2780 Dim n(2) As Double
2781 Dim area As Double
2782 Dim select_loop As Integer
2783 Dim diametre As Double = 0
2784 Dim nb_retrait_mat As Integer = 0
2785 Dim param(1) As Double
2786 Dim Eng_moy As Double = 0
2787 Dim tmp() As Double
2788 Dim Eni As Double
2789
2790 ReDim Preserve Tabretrait_mat(0)
2791 Tabretrait_mat(0) = New retrait_mat(Nothing, 0)
2792
2793 swfaceref = swbody.GetFirstFace
2794 For cpt1 = 0 To swbody.GetFaceCount - 1
2795 diametre = 0
2796 swfeat = swfaceref.GetFeature
2797 swsurface = swfaceref.GetSurface
2798 swloop = swfaceref.GetFirstLoop
2799 For cpt2 = 0 To swfaceref.GetLoopCount - 1
2800 select_loop = 0
2801 If swloop.IsOuter = False Then
2802 vedge = swloop.GetEdges
2803 For cpt3 = 0 To swloop.GetEdgeCount - 1
2804 swedge = vedge(cpt3)
2805 vface = swedge.GetTwoAdjacentFaces
2806 swface = vface(0)
2807 If swface.IsSame(swfaceref) = True Then swface = vface(1)
2808 angle = GetAngle(swedge, swfaceref, swface)
2809 If angle < 179 Then
2810 If (select_loop = 0) Then
2811
2812 n = direction_retrait_matiere(swloop, swfaceref)
2813 lg = 0
2814 For cpt4 = 0 To swloop.GetEdgeCount - 1
2815 swedgetmp = vedge(cpt4)
2816 lgi = get_edge_plane_lenght(swedgetmp, n)
2817 lg = lg + lgi
2818 Next cpt4
2819 area = get_loop_plane_area(swloop, n)
2820 diametre = 4 * area / lg
2821 select_loop = 1
2822 End If
2823 If diametre > 0.000001 Then
2824 nb_retrait_mat = nb_retrait_mat + 1
2825 ReDim Preserve Tabretrait_mat(nb_retrait_mat - 1)
2826 Tabretrait_mat(nb_retrait_mat - 1) = New retrait_mat(swface, diametre)
2827 raffinn_auto_retrait_mat(0, 0, 0, 0, 0, 0, 0, param)
2828 Eng_moy = Eng_moy + diametre / 2 * Erx_m / (param(0) * Math.Pow(contrainte_vm_rm_ref(1, 2, tmp), param(1))) ' Calcul de En_reference à une distance de 1 fois le rayon de reference (fin de zone à gradients de contraintes perturbés) puis multiplication par le rayon de la caractéristique (extrapolation)
2829 If Eni = 0 Then Eni = Eng_moy
2830 Eni = Math.Min(Eni, diametre / 2 * Erx_m / (param(0) * Math.Pow(contrainte_vm_rm_ref(0, 2, tmp), param(1)))) ' calcul du Eni minimal sur le domaine
2831 End If
2832 End If
2833 Next cpt3
2834 Else
2835 If swfeat.GetTypeName = "HoleWzd" Then
2836 diametre = 0
2837 Dim hole As SldWorks.WizardHoleFeatureData2
2838 hole = swfeat.GetDefinition
2839 Select Case hole.Type
2840 Case 0, 2 To 5, 7 To 9
2841 diametre = hole.Diameter
2842 Case 1, 6
2843 diametre = (hole.MajorDiameter - hole.MinorDiameter) / 2
2844 Case 10 To 13, 22 To 24, 43
2845 diametre = hole.HoleDiameter
2846 Case 14 To 21, 25 To 30, 44, 45
2847 diametre = hole.ThruHoleDiameter
2848 Case 31, 32, 37, 38, 46, 47
2849 diametre = hole.TapDrillDiameter
2850 Case 33 To 36, 39 To 42, 48 To 55
2851 diametre = hole.ThruTapDrillDiameter
2852 Case Else
2853 MsgBox("Type de trou non reconnu")
2854 End Select
2855 If diametre > 0.000001 Then
2856 nb_retrait_mat = nb_retrait_mat + 1
2857 ReDim Preserve Tabretrait_mat(nb_retrait_mat - 1)
2858 Tabretrait_mat(nb_retrait_mat - 1) = New retrait_mat(swfaceref, diametre)
2859 raffinn_auto_retrait_mat(0, 0, 0, 0, 0, 0, 0, param)
2860 Eng_moy = Eng_moy + diametre / 2 * Erx_m / (param(0) * Math.Pow(contrainte_vm_rm_ref(1, 2, tmp), param(1))) ' Calcul de En_reference à une distance de 1 fois le rayon de reference (fin de zone à gradients de contraintes perturbés) puis multiplication par le rayon de la caractéristique (extrapolation)
2861 If Eni = 0 Then Eni = Eng_moy
2862 Eni = Math.Min(Eni, diametre / 2 * Erx_m / (param(0) * Math.Pow(contrainte_vm_rm_ref(0, 2, tmp), param(1)))) ' calcul du Eni minimal sur le domaine
2863 End If
2864 Else
2865 If swfeat.GetFaceCount = 1 And (swfeat.GetTypeName = "Cut" Or swfeat.GetTypeName = "RevCut") Then
2866 diametre = 0
2867 Dim params() As Double
2868 If swsurface.Identity = 4002 Then
2869 params = swsurface.CylinderParams
2870 diametre = params(6) * 2
2871 End If
2872 If swsurface.Identity = 4003 Then
2873 params = swsurface.ConeParams
2874 diametre = params(6) * 2
2875 End If
2876 If swsurface.Identity = 4005 Then
2877 params = swsurface.TorusParams
2878 diametre = params(7) * 2
2879 End If
2880 If diametre > 0.000001 Then
2881 nb_retrait_mat = nb_retrait_mat + 1
2882 ReDim Preserve Tabretrait_mat(nb_retrait_mat - 1)
2883 Tabretrait_mat(nb_retrait_mat - 1) = New retrait_mat(swfaceref, diametre)
2884 raffinn_auto_retrait_mat(0, 0, 0, 0, 0, 0, 0, param)
2885 Eng_moy = Eng_moy + diametre / 2 * Erx_m / (param(0) * Math.Pow(contrainte_vm_rm_ref(1, 2, tmp), param(1))) ' Calcul de En_reference à une distance de 1 fois le rayon de reference (fin de zone à gradients de contraintes perturbés) puis multiplication par le rayon de la caractéristique (extrapolation)
2886 If Eni = 0 Then Eni = Eng_moy
2887 Eni = Math.Min(Eni, diametre / 2 * Erx_m / (param(0) * Math.Pow(contrainte_vm_rm_ref(0, 2, tmp), param(1)))) ' calcul du Eni minimal sur le domaine
2888 End If
2889 End If
2890 End If
2891 End If
2892 swloop = swloop.GetNext
2893 Next cpt2
2894 swfaceref = swfaceref.GetNextFace
2895 Next cpt1
2896
2897 If nb_retrait_mat > 0 Or Tabretrait_mat(0).diametre > 0 Then
2898 Eng_moy = Eng_moy / nb_retrait_mat
2899 raffinn_auto_retrait_mat(0, 0, 0, 0, 0, 0, 0, param)
2900 determination_ecart_nodal_global_retraits_mat = Eng_moy
2901 coeffmin = Eni / Eng_moy
2902 'MsgBox("Pré-optimisation de maillage des caractéristiques Retraits de matière avec une écart nodal global de " & 1000 * Eng_moy & "mm")
2903 Else
2904 determination_ecart_nodal_global_retraits_mat = 0
2905 End If
2906 End Function
2907
2908 Sub raffinement_retrait_matiere(ByRef Eng As Double, ByRef Erx As Double, Optional ByRef limitepente As Double = 0.25)
2909 Dim cpt As Integer
2910 Dim coeff As Double
2911 Dim lmbd As Double
2912 Dim courb As Double
2913 Dim tmp() As Double
2914
2915 For cpt = 0 To UBound(Tabretrait_mat)
2916 If raffinn_auto_retrait_mat(Erx, coeff, lmbd, courb, Eng, Tabretrait_mat(cpt).diametre / 2, limitepente, tmp) Then ChangeTabFace(Tabretrait_mat(cpt).face, coeff, lmbd, courb)
2917 Next
2918
2919 End Sub
2920
2921 End Module
2922
2923
2924
2925
2926
2927 REM
2928 ' on a les listes suivantes si on provient de l'icone sauvegarder pour MAGiC
2929 ' lst_AreteVolume ' liste de SlyAreteVol: courbes appartenant au volume
2930 ' lst_AreteCoque ' liste de SlyAreteCoque: courbes appartenant aux coques
2931 ' lst_AretePoutre ' liste de SlyAretePoutre: courbe libres (poutres)
2932 ' lst_FaceVolume ' liste de SlyFaceVol: faces appartenant au volume
2933 ' lst_FaceCoque ' liste de SlyFaceCoque: face libres (coques)
2934 ' lst_SommetVolume ' liste de SlySommetVolume: Sommets du volume
2935 ' lst_SommetCoque ' liste de SlySommetCoque: sommets des coques
2936 ' lst_sommetPoutre ' liste de SlySommetPoutre: sommets des poutres