ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magicsld/PoGCode.vb
Revision: 51
Committed: Fri Aug 24 21:33:21 2007 UTC (17 years, 8 months ago) by lacroix
File size: 124240 byte(s)
Log Message:
Commit fin de projet

File Contents

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