ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magicsld/PoGCode.vb
Revision: 46
Committed: Wed Aug 22 18:28:53 2007 UTC (17 years, 8 months ago) by bournival
File size: 124119 byte(s)
Log Message:
Ajout de la page de pré-optimisation automatique et des modification que j'ai apportées.

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