ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magicsld/PoGCode.vb
Revision: 40
Committed: Mon Aug 20 21:30:28 2007 UTC (17 years, 8 months ago) by bournival
File size: 123644 byte(s)
Log Message:
Projet de these de Sylvain Bournival. Attention projet VB.

File Contents

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