ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magicsld/PoGCode.vb
Revision: 130
Committed: Wed Jul 30 21:26:03 2008 UTC (16 years, 9 months ago) by bournival
File size: 126059 byte(s)
Log Message:
Une mise à jour, car on aura peut-être besoin de mon code.

File Contents

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