ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magicsld/Intersections.vb
Revision: 205
Committed: Thu Jul 23 20:53:57 2009 UTC (15 years, 9 months ago) by bournival
File size: 111956 byte(s)
Log Message:
Commit de MAGiC_SLD pendant que j'y pense.  Les modifications ne devraient pas concerner personne d'autre que moi.   -- Sylvain

File Contents

# User Rev Content
1 bournival 48 Imports SolidWorks.Interop
2     Imports SolidWorks.Interop.swconst
3     Imports SolidWorks.Interop.swpublished
4    
5 bournival 40 Module Intersections
6     Public DefAttrInterALAL As SldWorks.AttributeDef
7     Public DefAttrConditionLimite As SldWorks.AttributeDef
8     Public DefAttrRCP1 As SldWorks.AttributeDef
9     Public DefAttrRCCoque As SldWorks.AttributeDef
10     Public DefAttrFaceInterne As SldWorks.AttributeDef
11     Public DefAttrDoublon As SldWorks.AttributeDef
12 bournival 205 Public DefAttrIgnorer As sldworks.AttributeDef
13 bournival 40
14     Public nbMinipoutre As Long
15    
16 bournival 130 Public lst_InterCoqueCoque As New Collections.Generic.List(Of InterCoqueCoque)
17 bournival 40
18 bournival 130 Public MettreMiniPoutresSurFaceInternes As Boolean
19     Public MultiDecoupageCoques As Boolean = False
20 bournival 205 Public SectionSimpleSurPoutre As Boolean
21 bournival 40
22     #Region "Enums"
23     Public Enum typeInterPoutreVolume
24     Centre = 0
25     Sur_arete = 1
26     Sur_sommet = 2
27     Courbe = 3
28     End Enum
29    
30     #End Region
31    
32    
33     Public Sub Debuter(Optional ByRef nom2 As String = "C:\Documents and Settings\Sylvain Bournival\Bureau\testMAGiC.sldprt", Optional ByVal nomFichier As String = "", Optional ByRef original As Boolean = True, Optional ByRef modifie As Boolean = True)
34    
35     ' *******
36     ' quelques options de performance
37     ' *******
38 bournival 48 swApp.SetUserPreferenceIntegerValue(swconst.swUserPreferenceIntegerValue_e.swAutoSaveInterval, 0)
39 bournival 40 swModel.SetAddToDB(True)
40     swModel.SetDisplayWhenAdded(False)
41 bournival 130 swModel.SetInferenceMode(False)
42 bournival 40 ' ******
43     ' fin des options de performance
44     ' ******
45    
46 bournival 205
47    
48 bournival 40 Memoriser3iemePoint() ' mémorise le coord system car si on découpe, sa coordonnée est perdue.
49 bournival 130
50 bournival 40 CouperPoutres()
51     Commun.GenererListes() ' va ignorer les poutres à ignorer... et ajouter les poutres coupées dans la liste.
52    
53 bournival 205 lst_InterCoqueCoque.Clear()
54     DetectionCoqueCoque()
55     DetectionPoutresVolumes() ' doit être avant interpoutreCoque au cas où on aurait une poutre de section
56     DetectionPoutresCoques()
57     DetectionCoqueVolume()
58 bournival 40
59    
60 bournival 205
61    
62    
63    
64 bournival 40 ' Traitement des intersection poutres-Volumes
65     DecouperPoutreVolume()
66     swModel.EditRebuild3()
67    
68     ' Traitement des intersection entre poutre et coques
69     DecouperPoutreCoque()
70 bournival 205 swModel.EditRebuild3()
71 bournival 40
72     ' traitement des coques-volumes
73     DécouperCoqueVolume()
74 bournival 205 swModel.EditRebuild3()
75 bournival 40
76     ' traitement des coques-coques
77 bournival 46 DecouperCoqueCoque()
78 bournival 205 swModel.EditRebuild3()
79 bournival 40
80    
81    
82 bournival 205
83 bournival 40 ' *******
84     ' quelques options de performance, remettre à la position initiale
85     ' *******
86 bournival 48 swApp.SetUserPreferenceIntegerValue(swconst.swUserPreferenceIntegerValue_e.swAutoSaveInterval, 15)
87 bournival 40 swModel.SetAddToDB(False)
88     swModel.SetDisplayWhenAdded(True)
89     swModel.GraphicsRedraw2()
90 bournival 130 swModel.SetInferenceMode(True)
91 bournival 40 ' ******
92     ' fin des options de performance
93     ' ******
94     ReplacerFolder()
95    
96    
97     End Sub
98    
99    
100     ''' <summary>
101 bournival 46 ''' Sub qui découpe les coques en fonction des informations placées dans le InterCoqueCoque
102     ''' </summary>
103     ''' <remarks></remarks>
104     Private Sub DecouperCoqueCoque()
105     Dim rayon As Double
106    
107 bournival 130 For Each interCC As InterCoqueCoque In lst_InterCoqueCoque
108     'rayon = IIf(Coque Is interCC.sFaceCoque1, interCC.sFaceCoque2.GetEpaisseur, interCC.sFaceCoque1.GetEpaisseur)
109 bournival 205 'MsgBox("Traitement de l'intersection de coque - coque # " & interCC.Numero)
110 bournival 46
111 bournival 205 Try
112     If interCC.DoitCouperCoque1 Then
113     rayon = interCC.sFaceCoque2.GetEpaisseur / 2
114     Dim sweep As sldworks.Body2 = interCC.GénérerSweep(interCC.sketch, rayon)
115     interCC.DecouperCoque(interCC.sFaceCoque1, sweep)
116     If Intersections.MettreMiniPoutresSurFaceInternes Then interCC.MarquerFacesInternes(interCC.sFaceCoque2, interCC.sFaceCoque1)
117     End If
118 bournival 46
119 bournival 205 If interCC.DoitCouperCoque2 Then
120     rayon = interCC.sFaceCoque1.GetEpaisseur / 2
121     Dim sweep As sldworks.Body2 = interCC.GénérerSweep(interCC.sketch, rayon)
122     interCC.DecouperCoque(interCC.sFaceCoque2, sweep)
123     If Intersections.MettreMiniPoutresSurFaceInternes Then interCC.MarquerFacesInternes(interCC.sFaceCoque1, interCC.sFaceCoque2)
124     End If
125     Catch
126     If interCC.DoitCouperCoque2 Then
127     rayon = interCC.sFaceCoque1.GetEpaisseur / 2
128     Dim sweep As sldworks.Body2 = interCC.GénérerSweep(interCC.sketch, rayon)
129     interCC.DecouperCoque(interCC.sFaceCoque2, sweep)
130     If Intersections.MettreMiniPoutresSurFaceInternes Then interCC.MarquerFacesInternes(interCC.sFaceCoque1, interCC.sFaceCoque2)
131     End If
132 bournival 130
133 bournival 205 If interCC.DoitCouperCoque1 Then
134     rayon = interCC.sFaceCoque2.GetEpaisseur / 2
135     Dim sweep As sldworks.Body2 = interCC.GénérerSweep(interCC.sketch, rayon)
136     interCC.DecouperCoque(interCC.sFaceCoque1, sweep)
137     If Intersections.MettreMiniPoutresSurFaceInternes Then interCC.MarquerFacesInternes(interCC.sFaceCoque2, interCC.sFaceCoque1)
138     End If
139    
140    
141     End Try
142    
143    
144    
145    
146    
147 bournival 130 If interCC.FaceAPlat Then
148     interCC.CoupeAPlat()
149     End If
150    
151     ' reste à retrouver les faces internes.
152     'interCC.MarquerFacesInternes(IIf(Coque Is interCC.sFaceCoque1, interCC.sFaceCoque2, interCC.sFaceCoque1), IIf(Coque Is interCC.sFaceCoque1, interCC.sFaceCoque1, interCC.sFaceCoque2))
153 bournival 46 Next
154    
155    
156     End Sub
157    
158 bournival 130 'Private Sub DecouperCoqueCoque()
159     ' Dim rayon As Double
160    
161    
162     ' For Each Coque As SlyFaceCoque In Commun.lst_FaceCoque
163     ' For Each interCC As InterCoqueCoque In Coque.lst_InterCoqueCoque
164     ' rayon = IIf(Coque Is interCC.sFaceCoque1, interCC.sFaceCoque2.GetEpaisseur, interCC.sFaceCoque1.GetEpaisseur)
165     ' Dim sweep As SldWorks.Body2 = interCC.GénérerSweep(interCC.sketch, rayon)
166     ' interCC.DecouperCoque(Coque, sweep)
167    
168     ' ' reste à retrouver les faces internes.
169     ' interCC.MarquerFacesInternes(IIf(Coque Is interCC.sFaceCoque1, interCC.sFaceCoque2, interCC.sFaceCoque1), IIf(Coque Is interCC.sFaceCoque1, interCC.sFaceCoque1, interCC.sFaceCoque2))
170     ' Next
171     ' Next
172    
173    
174     'End Sub
175    
176    
177    
178 bournival 46 ''' <summary>
179 bournival 40 ''' sub qui créé une instance de la classe interCoqueCoque s'il y a une intersection de ce type
180     ''' </summary>
181     ''' <remarks></remarks>
182     Private Sub DetectionCoqueCoque()
183    
184     Dim sketch As SldWorks.Sketch = Nothing
185     Dim interCC As InterCoqueCoque = Nothing
186 bournival 46 Dim Coque1 As SlyFaceCoque, Coque2 As SlyFaceCoque
187 bournival 40
188 bournival 46 For i As Integer = 0 To Commun.lst_FaceCoque.Count - 2 'For Each Coque1 As SlyFaceCoque In Commun.lst_FaceCoque
189     Coque1 = Commun.lst_FaceCoque.Item(i)
190     For j As Integer = i + 1 To Commun.lst_FaceCoque.Count - 1 ' For Each coque2 As SlyFaceCoque In lst_FaceCoque
191     Coque2 = Commun.lst_FaceCoque.Item(j)
192     If DetectFaceFace(Coque2.SwFace, Coque1.SwFace, True, sketch) Then
193 bournival 40 ' création de l'instance de interFace-face entre coque et coque
194    
195 bournival 130 interCC = New InterCoqueCoque(Coque1, Coque2)
196 bournival 40 interCC.FaceDeSection = False
197     interCC.sketch = sketch
198 bournival 130 interCC.determineType()
199     lst_InterCoqueCoque.Add(interCC)
200 bournival 40
201 bournival 205
202 bournival 130 'Coque1.lst_InterCoqueCoque.Add(interCC)
203     'Coque2.lst_InterCoqueCoque.Add(interCC)
204 bournival 40 End If
205    
206 bournival 46 Next j
207     Next i
208 bournival 40
209     End Sub
210    
211    
212     Private Sub ReplacerFolder()
213     ' on doit mettre les folders à la fin pour que ça marche dans MAGiC
214     'Si on ne met pas les attributs à la fin on est baisé...
215    
216     Dim swFeat As SldWorks.Feature = Nothing
217     Dim nomdernier As String
218     Dim dansFolder As Boolean = False
219     Dim i As Integer = 0
220     Dim ok As Boolean = False
221     Dim SelMgr As SldWorks.SelectionMgr
222    
223     'trouver le premier feature qui n'est pas un folder...
224     Do Until ok
225     swFeat = swModel.FeatureByPositionReverse(i)
226     nomdernier = swFeat.GetTypeName
227    
228     If (nomdernier = "FtrFolder") Then
229     dansFolder = Not dansFolder
230     Else
231     If Not dansFolder Then ok = True
232     End If
233     i += 1
234     Loop
235    
236     nomdernier = swFeat.Name
237    
238     SelMgr = swModel.SelectionManager
239     If swModel.Extension.SelectByID2("Poutres", "FTRFOLDER", 0, 0, 0, False, 0, Nothing, 0) Then swModel.ReorderFeature("Poutres", nomdernier)
240     If swModel.Extension.SelectByID2("Coques", "FTRFOLDER", 0, 0, 0, False, 0, Nothing, 0) Then swModel.ReorderFeature("Coques", nomdernier)
241     If swModel.Extension.SelectByID2("Conditions Aux Limites", "FTRFOLDER", 0, 0, 0, False, 0, Nothing, 0) Then swModel.ReorderFeature("Conditions Aux Limites", nomdernier)
242     If swModel.Extension.SelectByID2("FaceInternes", "FTRFOLDER", 0, 0, 0, False, 0, Nothing, 0) Then swModel.ReorderFeature("FaceInternes", nomdernier)
243    
244     End Sub
245    
246    
247     Public Sub RegisterAttribut()
248     Static nouveau As Boolean
249     'propriétés des intersections entre 2 poutres (Arete-libre Arête-libre)
250    
251     If nouveau Then Exit Sub
252     Dim nom As String
253     Dim retval As Boolean
254    
255     nom = "InterALAL"
256     DefAttrInterALAL = swApp.DefineAttribute(nom)
257 bournival 48 DefAttrInterALAL.AddParameter("X", swconst.swParamType_e.swParamTypeDouble, 0, 0)
258     DefAttrInterALAL.AddParameter("Y", swconst.swParamType_e.swParamTypeDouble, 0, 0)
259     DefAttrInterALAL.AddParameter("Z", swconst.swParamType_e.swParamTypeDouble, 0, 0)
260     DefAttrInterALAL.AddParameter("T", swconst.swParamType_e.swParamTypeDouble, -1, 0)
261 bournival 40 retval = DefAttrInterALAL.Register()
262     If retval = False Then MsgBox("Enregistrement raté pour le InterALAL")
263    
264    
265     nom = "ConditionLimite"
266     DefAttrConditionLimite = swApp.DefineAttribute(nom)
267 bournival 48 DefAttrConditionLimite.AddParameter("CL", swconst.swParamType_e.swParamTypeString, 0, 0)
268 bournival 40 retval = DefAttrConditionLimite.Register()
269     If retval = False Then MsgBox("Enregistrement raté pour le COndition Limite")
270    
271    
272     DefAttrRCP1 = swApp.DefineAttribute("Poutre1")
273     DefAttrRCP1.AddParameter("M", 1, 0, 0) ' 0 = double, 1 = string, 2 = integer
274     DefAttrRCP1.AddParameter("S", 1, 0, 0)
275     DefAttrRCP1.AddParameter("As", 0, 0, 0)
276     DefAttrRCP1.AddParameter("I1", 0, 0, 0)
277     DefAttrRCP1.AddParameter("I2", 0, 0, 0)
278     DefAttrRCP1.AddParameter("N3", 1, 0, 0) ' le nom du troisième point
279     DefAttrRCP1.AddParameter("X3", 0, 0, 0) ' le x du troisième point
280     DefAttrRCP1.AddParameter("Y3", 0, 0, 0) ' le y du troisième point
281     DefAttrRCP1.AddParameter("Z3", 0, 0, 0) ' le z du troisième point
282     DefAttrRCP1.AddParameter("D1", 0, 0, 0)
283     DefAttrRCP1.AddParameter("D2", 0, 0, 0)
284     DefAttrRCP1.AddParameter("D3", 0, 0, 0)
285     DefAttrRCP1.AddParameter("D4", 0, 0, 0)
286     DefAttrRCP1.AddParameter("D5", 0, 0, 0)
287     DefAttrRCP1.AddParameter("D6", 0, 0, 0)
288     DefAttrRCP1.AddParameter("Flag", 0, 0, 0)
289     retval = DefAttrRCP1.Register()
290     If retval = False Then MsgBox("Enregistrement raté pour le RCPoutre")
291    
292     DefAttrRCCoque = swApp.DefineAttribute("Coque")
293     DefAttrRCCoque.AddParameter("M", 1, 0, 0) 'le matériau' 0 = double, 1 = string, 2 = integer
294     DefAttrRCCoque.AddParameter("Ep", 0, 0, 0) ' épaisseur
295     DefAttrRCCoque.AddParameter("Flag", 0, 0, 0) ' un flag pour les coques...
296     retval = DefAttrRCCoque.Register()
297     If retval = False Then MsgBox("Enregistrement raté pour le RCCoque")
298    
299     DefAttrFaceInterne = swApp.DefineAttribute("FaceInterne")
300 bournival 130 DefAttrFaceInterne.AddParameter("FI", 0, 0, 0) ' la taille des éléments
301     DefAttrFaceInterne.AddParameter("Po", 0, 0, 0) ' =0 si poutre, =1 si coque
302 bournival 40 retval = DefAttrFaceInterne.Register()
303     If retval = False Then MsgBox("Enregistrement raté pour le FaceInterne")
304    
305     DefAttrDoublon = swApp.DefineAttribute("Doublon")
306     DefAttrDoublon.AddParameter("Maitre", 1, 0, 0) ' le nom du maitre...
307     DefAttrDoublon.AddParameter("Sens", 0, 0, 0) ' -1 si dans le sens oposé
308     retval = DefAttrDoublon.Register()
309     If retval = False Then MsgBox("Enregistrement raté pour le Doublon")
310    
311     nom = "Ignorer"
312     DefAttrIgnorer = swApp.DefineAttribute(nom)
313     DefAttrIgnorer.AddParameter("Rien", 0, 0, 0)
314     retval = DefAttrIgnorer.Register()
315     If retval = False Then MsgBox("Enregistrement raté pour le Ignorer")
316    
317 bournival 205
318 bournival 40 nouveau = True
319    
320     End Sub
321    
322     Private Sub TraiteAPAP()
323     ' procédure plus utilisée.
324     ' procédure qui trouve les intersections entre les poutres et qui créé un attribut contenant les informations
325    
326     ' en premier on efface les features attributs, pour ne pas avoir de doubles
327     Dim feat As SldWorks.Feature
328     feat = swPart.FirstFeature
329     Dim nextfeat As SldWorks.Feature
330    
331     Do While Not feat Is Nothing
332     If Left(feat.Name, 9) = "InterAPAP" Then
333     nextfeat = feat.GetNextFeature
334     swModel.Extension.SelectByID2(feat.Name, "ATTRIBUTE", 0, 0, 0, False, 0, Nothing, 0)
335     swPart.EditDelete()
336     feat = nextfeat
337     Else
338     feat = feat.GetNextFeature
339     End If
340     Loop
341     ' faut aussi détruire les liste de points dans les poutres
342     ' ce qui suit n'est pas optimisé en temps d'exécution, mais en temps de programmation ;-)
343     ' j'aurais besoin d'un trouver qui retourne le sly... en fonction d'un feature(edge)
344     Dim p As SlyAretePoutre
345     For Each p In lst_AretePoutre
346     p.EffacerIntersection()
347     Next
348    
349    
350     ' ' fin de l'effacement des attributs
351     Dim swArete1 As SldWorks.Edge
352     Dim swArete2 As SldWorks.Edge
353     Dim SlyArete1 As SlyAretePoutre
354     Dim SlyArete2 As SlyAretePoutre
355    
356     Dim xyz() As Double = Nothing
357     Dim pt As New InterPoutrePoutre
358     'Dim lst_pts As New Collection
359     Dim i As Long
360    
361     Dim a1 As Integer
362     Dim a2 As Integer
363    
364    
365     For a1 = 0 To lst_AretePoutre.Count - 2
366     SlyArete1 = lst_AretePoutre.Item(a1)
367     swArete1 = SlyArete1.swArete
368    
369     For a2 = a1 + 1 To lst_AretePoutre.Count - 1
370     SlyArete2 = lst_AretePoutre.Item(a2)
371     swArete2 = SlyArete2.swArete
372    
373     If DetectAreteArete(swArete1, swArete2, xyz) Then ' intersection courbe-courbe
374     For i = 0 To CInt((UBound(xyz) + 1) / 4) Step 4 ' si y'a plus d'une intersection entre les 2 courbes...
375    
376     Select Case isIntersect_milieu(swArete1, swArete2, xyz(i), xyz(i + 1), xyz(i + 2))
377     Case 1 ' la première courbe est coupée
378     pt = New InterPoutrePoutre
379     pt.Arete = swArete1
380     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
381     SlyArete1.AjouterPointAPAP(pt)
382     pt = Nothing
383     Case 2 ' la seconde courbe est coupée
384     pt = New InterPoutrePoutre
385     pt.Arete = swArete2
386     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
387     SlyArete2.AjouterPointAPAP(pt)
388     pt = Nothing
389     Case 3 ' les doux courbes sont coupées
390     pt = New InterPoutrePoutre
391     pt.Arete = swArete1
392     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
393     SlyArete1.AjouterPointAPAP(pt)
394     pt = Nothing
395     pt = New InterPoutrePoutre
396     pt.Arete = swArete2
397     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
398     SlyArete2.AjouterPointAPAP(pt)
399     pt = Nothing
400     End Select
401     Next i
402     End If
403    
404     Next a2
405     Next a1
406     pt = Nothing
407     End Sub
408    
409    
410     Public Function DetectAreteArete(ByRef swArete1 As SldWorks.Edge, ByRef swArete2 As SldWorks.Edge, ByRef xyz() As Double) As Boolean
411     ' function qui détermine si 2 arêtes se touchent, si oui alors la fonction retourne vrai et le tableau XYZ contient le point d'intersection
412     xyz = Nothing
413     If swArete2 Is Nothing Then Exit Function
414     If swArete1 Is Nothing Then Exit Function
415    
416     Dim swSommet As SldWorks.Vertex
417     Dim point1 As Object ' point début courbe 1
418     Dim point2 As Object ' point fin, courbe 1
419     Dim point3 As Object ' point début courbe 2
420     Dim point4 As Object ' point fin, courbe 2
421     Dim swCourbe1 As SldWorks.Curve
422     Dim swCourbe2 As SldWorks.Curve
423     Dim vIntersectPts As Object
424    
425     swSommet = swArete1.GetStartVertex
426     If swSommet Is Nothing Then ' cercle fermé
427     point1 = swArete1.Evaluate(0)
428     point2 = point1
429     Else
430     point1 = swSommet.GetPoint
431     swSommet = swArete1.GetEndVertex
432     point2 = swSommet.GetPoint
433     End If
434    
435     swSommet = swArete2.GetStartVertex
436     If swSommet Is Nothing Then
437     point3 = swArete2.Evaluate(0)
438     point4 = point3
439     Else
440     point3 = swSommet.GetPoint
441    
442     swSommet = swArete2.GetEndVertex
443     point4 = swSommet.GetPoint
444     End If
445     swCourbe1 = swArete1.GetCurve
446     swCourbe2 = swArete2.GetCurve
447    
448    
449     vIntersectPts = swCourbe1.IntersectCurve(swCourbe2, point1, point2, point3, point4)
450    
451     Try ' je déteste cette façon de procéder, mais il ne détecte pas que le vintersectpts est nothing, il le croit system.dbnull. Et je ne peut comparer avec ça.
452     xyz = vIntersectPts
453    
454     If Not xyz Is Nothing Then
455     DetectAreteArete = True
456     Dim i As Integer
457     For i = 0 To ((UBound(xyz) + 1) / 4) - 1
458     Debug.Write("x" & i & " = " & xyz(i * 4) * 1000 & " mm")
459     Debug.Write("y" & i & " = " & xyz(i * 4) * 1000 & " mm")
460     Debug.Write("z" & i & " = " & xyz(i * 4) * 1000 & " mm")
461     Next i
462     Else
463     Return False
464     End If
465     Catch ex As Exception
466     DetectAreteArete = False
467     End Try
468    
469     End Function
470    
471     Public Function DetectAreteArete(ByRef swArete1 As SldWorks.Edge, ByRef swCourbe2 As SldWorks.Curve, ByRef xyz() As Double) As Boolean
472     ' function qui détermine si 2 arêtes se touchent, si oui alors la fonction retourne vrai et le tableau XYZ contient le point d'intersection
473     xyz = Nothing
474     If swArete1 Is Nothing Then Exit Function
475     Dim swSommet As SldWorks.Vertex
476     Dim point1 As Object ' point début courbe 1
477     Dim point2 As Object ' point fin, courbe 1
478     Dim point3 As Object ' point début courbe 2
479     Dim point4 As Object ' point fin, courbe 2
480     Dim swCourbe1 As SldWorks.Curve
481    
482     Dim vIntersectPts As Object
483    
484     swSommet = swArete1.GetStartVertex
485     If swSommet Is Nothing Then ' cercle fermé
486     point1 = swArete1.Evaluate(0)
487     point2 = point1
488     Else
489     point1 = swSommet.GetPoint
490     swSommet = swArete1.GetEndVertex
491     point2 = swSommet.GetPoint
492     End If
493    
494    
495    
496     If Not swCourbe2.IsTrimmedCurve Then
497     Dim vP1 As Object, vP2 As Object
498     vP1 = swCourbe2.Evaluate(-9000)
499     vP2 = swCourbe2.Evaluate(9000)
500     swCourbe2 = swCourbe2.CreateTrimmedCurve2(vP1(0), vP1(1), vP1(2), vP2(0), vP2(1), vP2(2))
501     End If
502    
503     If Not swCourbe2.IsTrimmedCurve Then
504     MsgBox("Ça plante, le trimmage n'a pas fonctionné...")
505     End If
506    
507     Dim dpoint3 As Double, dpoint4 As Double, isClosed As Boolean, isPeriodic As Boolean
508     swCourbe2.GetEndParams(dpoint3, dpoint4, isClosed, isPeriodic)
509    
510     point3 = swCourbe2.Evaluate(dpoint3)
511     point4 = swCourbe2.Evaluate(dpoint4)
512    
513     swCourbe1 = swArete1.GetCurve
514    
515     vIntersectPts = swCourbe1.IntersectCurve(swCourbe2, point1, point2, point3, point4)
516    
517     Try ' je déteste cette façon de procéder, mais il ne détecte pas que le vintersectpts est nothing, il le croit system.dbnull. Et je ne peut comparer avec ça.
518     xyz = vIntersectPts
519    
520     If Not xyz Is Nothing Then
521     DetectAreteArete = True
522     Dim i As Integer
523     For i = 0 To ((UBound(xyz) + 1) / 4) - 1
524     Debug.Write("x" & i & " = " & xyz(i * 4) * 1000 & " mm")
525     Debug.Write("y" & i & " = " & xyz(i * 4) * 1000 & " mm")
526     Debug.Write("z" & i & " = " & xyz(i * 4) * 1000 & " mm")
527     Next i
528     Else
529     Return False
530     End If
531     Catch ex As Exception
532     DetectAreteArete = False
533     End Try
534    
535     End Function
536    
537     Private Function isIntersect_milieu(ByRef Arete1 As SldWorks.Edge, ByRef Arete2 As SldWorks.Edge, ByRef x As Double, ByRef y As Double, ByRef z As Double) As Byte
538     'procédure qui dit si les courbes s'intersectent au milieu ou à leurs point d'extrémité.
539     ' 0 si les deux intersections sont sur des points
540     ' 1 si la première courbe est coupée
541     ' 2 si la deuxième est coupée
542     ' 3 si les deux courbes sont coupées
543    
544    
545     Dim retv As Object ' mettre les valeurs de T dans la classe
546    
547     retv = Arete1.GetCurveParams2() ' retv 0,1,2 point de départ, 3,4,5 point final
548     If (Math.Abs(retv(0) - x) < Epsilon) And (Math.Abs(retv(1) - y) < Epsilon) And (Math.Abs(retv(2) - z) < Epsilon) Or (Math.Abs(retv(3) - x) < Epsilon) And (Math.Abs(retv(4) - y) < Epsilon) And (Math.Abs(retv(5) - z) < Epsilon) Then isIntersect_milieu = 0 Else isIntersect_milieu = 1
549    
550     retv = Arete2.GetCurveParams2() ' retv 0,1,2 point de départ, 3,4,5 point final
551     If (Math.Abs(retv(0) - x) < Epsilon) And (Math.Abs(retv(1) - y) < Epsilon) And (Math.Abs(retv(2) - z) < Epsilon) Or (Math.Abs(retv(3) - x) < Epsilon) And (Math.Abs(retv(4) - y) < Epsilon) And (Math.Abs(retv(5) - z) < Epsilon) Then isIntersect_milieu += 0 Else isIntersect_milieu += 2
552    
553     End Function
554    
555    
556     ''' <summary>
557     ''' Sub qui traite les intersections entre les Poutres et les coques
558     ''' </summary>
559     ''' <remarks></remarks>
560     Private Sub DetectionPoutresCoques()
561     '#1 on détecte les intersections, on en a 4 types,
562     ' #1a) intersection au milieu de la coque
563     ' #1b) intersection sur une arête
564     ' #1c) intersection sur un sommet
565     ' #1d) intersection sur une certaine longueur
566     ' faut également faire attention, il peut y avoir plus d'une poutre qui se rejoint à la même intersection.
567     ' hypothèses: 1- les zones d'influence des poutres ne se croisent pas.
568     ' 2- une arête ne fait qu'une seule intersection, à un pount ou sur une ligne, mais pas à plusieurs endroits.
569     ' 3- une arête dont l'intersection est une courbe n'a pas d'autres intersections (pout l'instant)
570     ' lorsqu'une intersection est détectée on créé une instance de la classe InterPoutreCoque
571    
572     Dim sPoutre As SlyAretePoutre
573     Dim sCoque As SlyFaceCoque
574     Dim inter As InterPoutreCoque
575     Dim xyz() As Double = Nothing
576     Dim tipe As Byte
577     Dim i As Integer
578     Dim premier2 As Boolean
579    
580    
581     For Each sCoque In lst_FaceCoque
582     For Each sPoutre In lst_AretePoutre
583     ' on cherche entre la coque et la poutre
584    
585     If DetectFaceArete(sPoutre.swArete, sCoque.SwFace, xyz) Then
586     For i = 0 To UBound(xyz) - 1 Step 3
587     ' trouver le tipe d'intersection...
588    
589     Dim u() As Double
590     Dim v() As Double
591    
592     u = sPoutre.GetOrientation(xyz(i + 0), xyz(i + 1), xyz(i + 2))
593     v = sCoque.GetNormale(xyz(i + 0), xyz(i + 1), xyz(i + 2))
594    
595     If Math.Abs((Math.Abs(Math.Acos(Outils_Math.cosdir(u, v))) - Pi / 2)) < Epsilon Then
596     ' on est dans le même plan que la coque, on doit déterminer si on sort ou entre dans la coque.
597     Dim T As Double, T1 As Double, T2 As Double
598     Dim PointTest(2) As Double
599     T = sPoutre.GetT(xyz(i + 0), xyz(i + 1), xyz(i + 2))
600    
601     ' on fait T + ou - 15 * epsilon. si une valeur est dans la coque alors on considère que l'on a le type 2
602     ' on prend 15 fois epsilon car à 10, la fonction de solidworks considère que l'on est tellement près que l'on est sur la face
603     T1 = T + 15 * Epsilon
604     T2 = T - 15 * Epsilon
605    
606     Dim effacer As Double
607    
608     If sPoutre.Evaluer(T1, PointTest) Then
609     ' la valeur de T appartient à la poutre, maintenant on vérifie s'il appartient aussi à la coque
610 bournival 130 If Distance(sCoque.lst_Faces.Item(0), PointTest(0), PointTest(1), PointTest(2)) < Epsilon Then
611 bournival 40 ' on est dans la coque.
612     If Not premier2 Then tipe = 2 : premier2 = True Else tipe = 22
613     End If
614     End If
615    
616     If sPoutre.Evaluer(T2, PointTest) Then
617 bournival 205 effacer = Distance(sCoque.lst_Faces.Item(0), PointTest(0), PointTest(1), PointTest(2))
618     If Distance(sCoque.lst_Faces.Item(0), PointTest(0), PointTest(1), PointTest(2)) < Epsilon Then
619 bournival 40 If Not premier2 Then tipe = 2 : premier2 = True Else tipe = 22
620     End If
621     End If
622    
623    
624     ' si tipe n'est pas à 2 alors on est par défaut à 3
625     If tipe = 0 Then tipe = 3
626    
627     Else
628     tipe = 1 ' on va devoir couper en X
629     End If
630    
631     inter = sCoque.AjouterInterPoutre(sPoutre, xyz, tipe)
632     sPoutre.lst_InterCoque.Add(inter)
633     tipe = 0 ' reset
634    
635     Next i ' autre point d'intersection
636    
637     End If
638     premier2 = False ' reset
639     Next sPoutre
640     Next sCoque
641     End Sub
642    
643    
644    
645     ''' <summary>
646     ''' Sub qui procède au découpage des coques en fonction des poutres
647     ''' </summary>
648     ''' <remarks></remarks>
649     Private Sub DecouperPoutreCoque()
650     ' #2 on procède au découpage de la face
651     Dim sCoque As SlyFaceCoque
652     For Each sCoque In lst_FaceCoque
653     If sCoque.lst_InterPoutre.Count > 0 Then
654     'sVol.chercherAttributs()
655     sCoque.decouper()
656    
657     ' on met-a-jour l'attribut des conditions aux limites
658     Dim attr As SldWorks.Attribute
659     Dim swent As SldWorks.Entity
660     Dim nom3 As String = Nothing
661     Dim p As SldWorks.Parameter
662     If Not sCoque.AttributCL Is Nothing Then
663     nom3 = "CL_" & sCoque.nom
664     swent = sCoque.lst_Faces.Item(1)
665     attr = swent.FindAttribute(Intersections.DefAttrConditionLimite, 0) ' si l'attribut existe déjà on pointe dessus.
666    
667     If attr Is Nothing Then attr = Intersections.DefAttrConditionLimite.CreateInstance5(swModel, sCoque.lst_Faces.Item(1), nom3, 0, 0)
668     p = attr.GetParameter("CL")
669     p.SetStringValue(sCoque.condition)
670    
671     End If
672     GererDossiers("Conditions Aux Limites", nom3)
673     End If
674    
675     Next
676     End Sub
677    
678    
679     ''' <summary>
680     ''' Sub qui détecte les intersections entre les faces du volume et les poutres
681     ''' </summary>
682     ''' <remarks></remarks>
683     Private Sub DetectionPoutresVolumes()
684     Dim sPoutre As SlyAretePoutre
685    
686     For Each sPoutre In lst_AretePoutre
687     If Not sPoutre.IsFaceDeSection Then
688     Call Intersections.GestionPoutreNormaleAvecVolume(sPoutre)
689     Else
690     ' la poutre est flaggée pour prendre la face de section
691     Call Intersections.GestionFace_De_section(sPoutre)
692     End If
693     Next sPoutre
694     End Sub
695    
696     ''' <summary>
697     ''' Sub qui prend les intersections entre les faces et les volumes et qui coupe les volumes
698     ''' </summary>
699     ''' <remarks></remarks>
700     Private Sub DecouperPoutreVolume()
701     ' #2 on procède au découpage de la face
702 bournival 205 Dim sFaceVol As SlyFaceVolume
703 bournival 40
704 bournival 205 For Each sFaceVol In lst_FaceVolume
705     If sFaceVol.lst_InterPoutre.Count > 0 Then
706     sFaceVol.decouper()
707 bournival 40
708     ' on met-a-jour l'attribut des conditions aux limites
709 bournival 205 Dim attr As sldworks.Attribute
710     Dim swent As sldworks.Entity
711 bournival 40 Dim nom3 As String = Nothing
712 bournival 205 Dim p As sldworks.Parameter
713     If Not sFaceVol.AttributCL Is Nothing Then
714     nom3 = "CL_" & sFaceVol.nom
715     swent = sFaceVol.SwFace
716 bournival 40 attr = swent.FindAttribute(Intersections.DefAttrConditionLimite, 0) ' si l'attribut existe déjà on pointe dessus.
717    
718 bournival 205 If attr Is Nothing Then attr = Intersections.DefAttrConditionLimite.CreateInstance5(swModel, sFaceVol.SwFace, nom3, 0, 0)
719 bournival 40 p = attr.GetParameter("CL")
720 bournival 205 p.SetStringValue(sFaceVol.condition)
721 bournival 40
722     End If
723     GererDossiers("Conditions Aux Limites", nom3)
724     End If
725    
726     Next
727     End Sub
728    
729    
730    
731    
732    
733     ''' <summary>
734     ''' Sub qui gère la poutre qui a été flaggée comme ayant une face de section. Met à jour les attributs avec les bonnes inerties et autre
735     ''' </summary>
736     ''' <param name="sPoutre">La poutre avec laquelle il faut travailler</param>
737     ''' <remarks></remarks>
738     Private Sub GestionFace_De_section(ByRef sPoutre As SlyAretePoutre)
739    
740     Dim sVol As SlyFaceVolume
741     Dim swExt As SldWorks.ModelDocExtension
742     Dim xyz() As Double = Nothing, xyz2() As Double = Nothing
743     Dim section As Object
744     Dim Face1 As SlyFaceVolume = Nothing, prop1() As Double = Nothing
745     Dim Face2 As SlyFaceVolume = Nothing, prop2() As Double = Nothing
746     Dim proprietes() As Double
747     Dim i As Integer
748     swExt = swModel.Extension
749    
750     ' 1 - Spotter la ou les faces en question
751     xyz = sPoutre.GetStartPoint
752     xyz2 = sPoutre.GetEndPoint
753 bournival 130
754 bournival 40 For Each sVol In Commun.lst_FaceVolume
755     If Intersections.DetectSurfaceArete(sPoutre.swArete, sVol.SwFace, Nothing) Then
756     swModel.ClearSelection2(True)
757     sVol.Selectionner()
758     section = swExt.GetSectionProperties2(sVol.SwFace) : proprietes = section
759     swModel.ClearSelection2(True)
760 bournival 130 ' la fonction getsectionproperties renvoie des valeurs dont la précision est très douteuse...
761 bournival 40 ' on met alors une beaucoup plus grosse tolérance...
762 bournival 130 If Math.Abs(xyz(0) - proprietes(2)) < 0.0001 And Math.Abs(xyz(1) - proprietes(3)) < 0.0001 And Math.Abs(xyz(2) - proprietes(4)) < 0.0001 Then
763     Face1 = sVol : prop1 = proprietes
764     ElseIf Math.Abs(xyz2(0) - proprietes(2)) < 0.0001 And Math.Abs(xyz2(1) - proprietes(3)) < 0.0001 And Math.Abs(xyz2(2) - proprietes(4)) < 0.0001 Then
765     Face2 = sVol : prop2 = proprietes
766     Else
767     ' on a une intersection où la poutre touche à une face «guide» et une autre partie touche à une face normale
768     ' la face est automatiquement une face de volume. Si c'est une coque, elle est traitée ailleurs.
769    
770     'Dim interNormale As InterPoutreVolume
771     'Dim point1 As Object = Nothing
772     'swModel.ClosestDistance(sPoutre.swArete, sVol.SwFace, point1, Nothing)
773     'Dim xyzNormale() As Double = point1
774     'interNormale = sVol.AjouterInterPoutre(sPoutre, xyzNormale, 6) ' y'a des cas où ça pourrait ne pas être 1...
775     'sPoutre.lst_InterCoque.Add(interNormale)
776    
777     End If
778    
779 bournival 40 End If
780     Next
781    
782     ' si les 2 faces sont nothing, c'est que l'on a un sérieux problème...
783     If Face1 Is Nothing AndAlso Face2 Is Nothing Then
784     MsgBox("La poutre " & sPoutre.nom & " doit avoir au moins une face pour évaluer sa section. Cette face n'a pas été trouvée." & vbCr & vbCr & " Vérifiez que: " & vbCr & " - Un sommet de la poutre repose sur le centre de gravité d'une face" & vbCr & " - Que l'arète de la poutre est perpendiculaire à la face" & vbCr & " - Que la face est plane " & vbCr & " - Je crois avoir tout couvert..." & vbCr & vbCr & " La poutre a problème a été colorée en rouge.", MsgBoxStyle.Critical, "Impossible de trouver la face représentant la section")
785     Dim e As New SuperArete(sPoutre.swArete, True)
786     e.Colorer(3, 1, 0, 0)
787     sPoutre.Selectionner()
788 bournival 130 Err.Raise(520, "Gestion_Face_De_Section", "Une poutre ne peut être traitée car elle n'a pas été correctement définie.")
789 bournival 40 Exit Sub
790     End If
791    
792    
793    
794     ' 2 - s'assurer que:
795     ' 2.1 les 2 faces sont identiques (si 2 faces)
796     If Face1 IsNot Nothing And Face2 IsNot Nothing Then
797     If Not Math.Abs(prop1(1) - prop2(1)) < 0.0000001 Then
798     Dim chaine As String
799     chaine = "Les 2 faces ne sont pas identiques... "
800     For i = 0 To 14
801     chaine = chaine & vbCr & i & " - " & Format(prop1(i), "0.000E+00") & " " & Format(prop2(i), "0.000E+00")
802     Next i
803     MsgBox(chaine)
804     End If
805     End If
806     ' 2.2 le centroide est au point d'intersection
807     ' déjà fait
808     ' 2.3 la face est plane
809 bournival 130 Dim prop() As Double = Nothing
810    
811 bournival 40 If Face1 IsNot Nothing Then
812 bournival 130 prop = prop1
813 bournival 40 If Not (Face1.estPlan Xor Face1.estFauxPlan(prop1(2), prop1(3), prop1(4))) Then
814     MsgBox("La face 1 n'est pas plane!")
815     Err.Raise(513, , "Ne peut pas prendre une face non plane comme source de la section de la poutre")
816     End If
817     End If
818     If Face2 IsNot Nothing Then
819 bournival 130 prop = prop2
820     If Not (Face2.estPlan Xor Face2.estFauxPlan(prop2(2), prop2(3), prop2(4))) Then
821 bournival 40 MsgBox("La face 2 n'est pas plane!")
822     Err.Raise(513, , "Ne peut pas prendre une face non plane comme source de la section de la poutre")
823     End If
824     End If
825    
826    
827     ' 2.4 les face sont perpendiculaire aux point d'intersection
828     Dim u() As Double
829     Dim v() As Double
830     Dim angle As Double
831     If Face1 IsNot Nothing Then
832     u = Face1.GetNormaleSurface(prop1(2), prop1(3), prop1(4))
833     v = sPoutre.GetOrientation(prop1(2), prop1(3), prop1(4))
834     angle = Outils_Math.Angle2Vecteurs(u, v)
835     If Not (Math.Abs(angle - Pi) < (100 * Epsilon)) And Not (angle < 0.005) Then
836     MsgBox("La poutre n'est pas perpendiculaire à la face1")
837     Err.Raise(514, "GestionFace_de_section - Dans intersection.vb", "Ne peut pas traiter une poutre dont la face de base n'est pas perpendiculaire")
838     End If
839     End If
840    
841     If Face2 IsNot Nothing Then
842     u = Face2.GetNormaleSurface(prop2(2), prop2(3), prop2(4))
843     v = sPoutre.GetOrientation(prop2(2), prop2(3), prop2(4))
844     angle = Outils_Math.Angle2Vecteurs(u, v)
845     If Not (Math.Abs(angle - Pi) < (100 * Epsilon)) And Not (angle < Epsilon) Then
846     MsgBox("La poutre n'est pas perpendiculaire à la face2")
847     Err.Raise(514, "GestionFace_de_section - Dans intersection.vb", "Ne peut pas traiter une poutre dont la face de base n'est pas perpendiculaire")
848     End If
849     End If
850    
851     ' 3 - trouver l'inertie et l'aire, placer le point 3 de façon cohérente, updater l'attribut.
852     Dim Nom3 As String
853    
854 bournival 130 Commun.MettreUnPoint(prop(2) + prop(18) / 1000, prop(3) + prop(19) / 1000, prop(4) + prop(20) / 1000, True)
855     Dim selmgr As sldworks.SelectionMgr = swModel.SelectionManager
856     Nom3 = RealConstant.RCCode.Creation3iemePoint(selmgr.GetSelectedObject(1))
857     sPoutre.SetAttributsDePoutre(False, Nom3, , , prop(13), prop(14), prop(1), , , , , , , 1)
858 bournival 40
859     ' 4 créer une nouvelle instance de la classe interFacePoutre de tipe 5
860     Dim inter As New InterPoutreVolume
861     Dim inter2 As New InterPoutreVolume
862     If Face1 IsNot Nothing Then
863     xyz(0) = prop1(2) : xyz(1) = prop1(3) : xyz(2) = prop1(4)
864     inter = Face1.AjouterInterPoutre(sPoutre, xyz, 5)
865     sPoutre.lst_InterCoque.Add(inter)
866     End If
867    
868     If Face2 IsNot Nothing Then
869     xyz(0) = prop2(2) : xyz(1) = prop2(3) : xyz(2) = prop2(4)
870     inter2 = Face2.AjouterInterPoutre(sPoutre, xyz, 5)
871     sPoutre.lst_InterCoque.Add(inter2)
872     End If
873    
874     End Sub
875    
876    
877     ''' <summary>
878     ''' Sub qui trouve les intersections entre les poutres et les faces de volumes et qui créé une instance de la classe d'intersection
879     ''' </summary>
880     ''' <param name="sPoutre">La poutre avec laquelle il faut trouver les intersections</param>
881     ''' <remarks></remarks>
882     Private Sub GestionPoutreNormaleAvecVolume(ByRef sPoutre As SlyAretePoutre)
883     Dim inter As InterPoutreVolume
884     Dim xyz() As Double = Nothing
885     Dim tipe As Byte
886     Dim i As Integer
887     Dim premier2 As Boolean
888     Dim sVol As SlyFaceVolume
889 bournival 130 Dim SurSurface As Boolean = False
890 bournival 40
891     For Each sVol In lst_FaceVolume
892    
893     ' on cherche entre la coque et la poutre
894 bournival 130 SurSurface = False
895     If DetectFaceArete(sPoutre.swArete, sVol, xyz, SurSurface) Then
896 bournival 40 For i = 0 To UBound(xyz) - 1 Step 3
897     ' trouver le tipe d'intersection...
898    
899     Dim u() As Double
900     Dim v() As Double
901    
902     u = sPoutre.GetOrientation(xyz(i + 0), xyz(i + 1), xyz(i + 2))
903     v = sVol.GetNormale(xyz(i + 0), xyz(i + 1), xyz(i + 2))
904    
905     ' ***** ici, différencier entre coque et volume ****
906     If Math.Abs((Math.Abs(Math.Acos(Outils_Math.cosdir(u, v))) - Pi / 2)) < Epsilon Then
907     ' on est dans le même plan que la coque, on doit déterminer si on sort ou entre dans la coque.
908     Dim T As Double, T1 As Double, T2 As Double
909     Dim PointTest(2) As Double
910     T = sPoutre.GetT(xyz(i + 0), xyz(i + 1), xyz(i + 2))
911    
912     ' on fait T + ou - 15 * epsilon. si une valeur est dans la coque alors on considère que l'on a le type 2
913     ' on prend 15 fois epxilon car à 10, la fonction de solidworks considère que l'on est tellement près que l'on est sur la face
914     T1 = T + 15 * Epsilon
915     T2 = T - 15 * Epsilon
916    
917    
918     If sPoutre.Evaluer(T1, PointTest) Then
919     ' la valeur de T appartient à la poutre, maintenant on vérifie s'il appartient aussi à la coque
920     If Distance(sVol.SwFace, PointTest(0), PointTest(1), PointTest(2)) < Epsilon Then
921     ' on est dans la coque.
922     If Not premier2 Then tipe = 2 : premier2 = True Else tipe = 22
923     End If
924     End If
925    
926     If sPoutre.Evaluer(T2, PointTest) Then
927 bournival 130
928 bournival 40 If Distance(sVol.SwFace, PointTest(0), PointTest(1), PointTest(2)) < Epsilon Then
929     If Not premier2 Then tipe = 2 : premier2 = True Else tipe = 22
930     End If
931     End If
932    
933     ' si tipe n'est pas à 2 alors on est par défaut à 3
934     If tipe = 0 Then tipe = 3
935    
936     Else
937     tipe = 1 ' on va devoir couper en X
938     End If
939    
940     inter = sVol.AjouterInterPoutre(sPoutre, xyz, tipe)
941     sPoutre.lst_InterCoque.Add(inter)
942     tipe = 0 ' reset
943    
944     Next i ' autre point d'intersection
945    
946 bournival 130 ElseIf SurSurface = True Then
947     ' Si les 2 points de la courbe touchent à la surface alors coupe-long
948     If Commun.Distance(sVol.SwFace, sPoutre.GetStartPoint()) < Epsilon AndAlso Commun.Distance(sVol.SwFace, sPoutre.GetEndPoint()) < Epsilon Then
949     inter = sVol.AjouterInterPoutre(sPoutre, xyz, 2)
950     sPoutre.lst_InterCoque.Add(inter)
951     End If
952 bournival 40 End If
953     premier2 = False ' reset
954    
955     Next sVol
956     End Sub
957    
958    
959    
960    
961     'Private Function DetectFaceArete(ByRef swCurve As SldWorks.Curve, ByRef swFace As SldWorks.Face2, ByRef xyz() As Double) As Boolean
962     ' ' function qui détecte si une arête coupe une face, si c'est le cas la function retourne true et remplie le tableau xyz avec le point d'intersection
963     ' Dim vCurveParam As Object
964     ' Dim swSurf As SldWorks.Surface
965     ' Dim vCurveBounds As Object, vPointArray As Object, vTArray As Object, vUVArray As Object
966     ' Dim nCurveBounds(5) As Double
967     ' Dim bRet As Boolean
968     ' Dim i As Integer
969    
970     ' swSurf = swFace.GetSurface
971    
972     ' ' 2- on va chercher les paramètres de la spline avec Curve::ConvertLineToBcurve
973     ' If swCurve.IsLine Then
974     ' Dim startp(2) As Double
975     ' Dim endp(2) As Double
976     ' Dim vStart As Object
977     ' Dim vEnd As Object
978    
979     ' vCurveParam = swCurve.LineParams()
980     ' startp(0) = vCurveParam(0)
981     ' startp(1) = vCurveParam(1)
982     ' startp(2) = vCurveParam(2)
983     ' vStart = startp
984    
985     ' endp(0) = vCurveParam(3)
986     ' endp(1) = vCurveParam(4)
987     ' endp(2) = vCurveParam(5)
988     ' vEnd = endp
989    
990     ' Dim retval As Object
991     ' Dim valeur As Double
992     ' Dim dimension As Integer
993     ' Dim ordre As Integer
994     ' Dim nbpoints As Integer
995     ' Dim periodique As Integer
996    
997     ' retval = swCurve.ConvertLineToBcurve(vStart, vEnd)
998    
999     ' ' on suppose que la droite est toujours transformée en spline non-rationelle de dimension 3 et d'ordre 2
1000     ' Dim knots(3) As Double
1001     ' Dim ctrlPoints(5) As Double
1002    
1003     ' knots(0) = retval(2)
1004     ' knots(1) = retval(3)
1005     ' knots(2) = retval(4)
1006     ' knots(3) = retval(5)
1007    
1008     ' ctrlPoints(0) = retval(6)
1009     ' ctrlPoints(1) = retval(7)
1010     ' ctrlPoints(2) = retval(8)
1011     ' ctrlPoints(3) = retval(9)
1012     ' ctrlPoints(4) = retval(10)
1013     ' ctrlPoints(5) = retval(11)
1014    
1015     ' '3 - on créé une spline dans le modeleur
1016    
1017    
1018     ' Dim modeler As SldWorks.Modeler
1019     ' modeler = swApp.GetModeler
1020     ' Dim props As Object
1021     ' Dim dProps(1) As Double
1022     ' Dim vKnots As Object, vCtrlPoints As Object
1023    
1024     ' dProps(0) = retval(0)
1025     ' dProps(1) = retval(1)
1026     ' props = dProps
1027     ' vKnots = knots
1028     ' vCtrlPoints = ctrlPoints
1029    
1030     ' swCurve = modeler.CreateBsplineCurve(props, vKnots, vCtrlPoints)
1031     ' ' 4 - on a une spline, on peut utiliser la fonction IntersectCurve
1032     ' End If
1033    
1034    
1035     ' For i = 0 To 5
1036     ' nCurveBounds(i) = vCurveParam(i)
1037     ' Next i
1038    
1039     ' vCurveBounds = nCurveBounds
1040     ' bRet = swSurf.IntersectCurve(swCurve, vCurveBounds, vPointArray, vTArray, vUVArray)
1041    
1042     ' Dim Pts() As Double
1043     ' Dim PointsTemp() As Double
1044     ' Dim j As Integer
1045    
1046     ' Pts = vPointArray
1047    
1048     ' If UBound(Pts) < 1 Then Return False
1049     ' ' ATTENTION, le point n'est pas nécessairement dans la face
1050     ' For i = 0 To UBound(Pts) - 1 Step 3
1051     ' If Commun.Distance(swFace, Pts(i + 0), Pts(i + 1), Pts(i + 2)) < Epsilon Then
1052     ' ReDim Preserve PointsTemp(j + 2)
1053     ' PointsTemp(j) = Pts(i + 0)
1054     ' PointsTemp(j + 1) = Pts(i + 1)
1055     ' PointsTemp(j + 2) = Pts(i + 2)
1056     ' j += 3
1057     ' End If
1058     ' Next
1059    
1060     ' xyz = PointsTemp
1061     ' If xyz Is Nothing Then Return False
1062     ' If UBound(xyz) > 0 Then Return True
1063    
1064    
1065     'End Function
1066    
1067     Private Function DetectFaceArete(ByRef swArete As SldWorks.Edge, ByRef swFace As SldWorks.Face2, ByRef xyz() As Double) As Boolean
1068     ' function qui détecte si une arête coupe une face, si c'est le cas la function retourne true et remplie le tableau xyz avec le point d'intersection
1069    
1070     Dim P1 As Object = Nothing, p2 As Object = Nothing
1071 bournival 48 If swModel.ClosestDistance(swArete, swFace, P1, p2) > Epsilon Then Return False
1072 bournival 40
1073     Dim swCurve As SldWorks.Curve
1074     Dim swSurf As SldWorks.Surface
1075     Dim vCurveParam As Object
1076    
1077     Dim vCurveBounds As Object, vPointArray As Object = Nothing, vTArray As Object = Nothing, vUVArray As Object = Nothing
1078     Dim nCurveBounds(5) As Double
1079     Dim bRet As Boolean
1080     Dim i As Integer
1081    
1082     '1 - on va chercher la courbe et la surface
1083     swCurve = swArete.GetCurve
1084     swSurf = swFace.GetSurface
1085    
1086    
1087     ' 2- on va chercher les paramètres de la spline avec Curve::ConvertLineToBcurve
1088     vCurveParam = swArete.GetCurveParams2
1089     If swCurve.IsLine Then
1090     Dim startp(2) As Double
1091     Dim endp(2) As Double
1092     Dim vStart As Object
1093     Dim vEnd As Object
1094    
1095    
1096     startp(0) = vCurveParam(0)
1097     startp(1) = vCurveParam(1)
1098     startp(2) = vCurveParam(2)
1099     vStart = startp
1100    
1101     endp(0) = vCurveParam(3)
1102     endp(1) = vCurveParam(4)
1103     endp(2) = vCurveParam(5)
1104     vEnd = endp
1105    
1106     Dim retval As Object
1107    
1108     retval = swCurve.ConvertLineToBcurve(vStart, vEnd)
1109    
1110     ' on suppose que la droite est toujours transformée en spline non-rationelle de dimension 3 et d'ordre 2
1111     Dim knots(3) As Double
1112     Dim ctrlPoints(5) As Double
1113    
1114     knots(0) = retval(2)
1115     knots(1) = retval(3)
1116     knots(2) = retval(4)
1117     knots(3) = retval(5)
1118    
1119     ctrlPoints(0) = retval(6)
1120     ctrlPoints(1) = retval(7)
1121     ctrlPoints(2) = retval(8)
1122     ctrlPoints(3) = retval(9)
1123     ctrlPoints(4) = retval(10)
1124     ctrlPoints(5) = retval(11)
1125    
1126     '3 - on créé une spline dans le modeleur
1127    
1128    
1129     Dim modeler As SldWorks.Modeler
1130     modeler = swApp.GetModeler
1131     Dim props As Object
1132     Dim dProps(1) As Double
1133     Dim vKnots As Object, vCtrlPoints As Object
1134    
1135     dProps(0) = retval(0)
1136     dProps(1) = retval(1)
1137     props = dProps
1138     vKnots = knots
1139     vCtrlPoints = ctrlPoints
1140    
1141     swCurve = modeler.CreateBsplineCurve(props, vKnots, vCtrlPoints)
1142     ' 4 - on a une spline, on peut utiliser la fonction IntersectCurve
1143     End If
1144    
1145    
1146     For i = 0 To 5
1147     nCurveBounds(i) = vCurveParam(i)
1148     Next i
1149    
1150     vCurveBounds = nCurveBounds
1151     bRet = swSurf.IntersectCurve(swCurve, vCurveBounds, vPointArray, vTArray, vUVArray)
1152    
1153     Dim Pts() As Double
1154     Dim PointsTemp() As Double = Nothing
1155     Dim j As Integer
1156    
1157     Pts = vPointArray
1158    
1159     If UBound(Pts) < 1 Then Return False
1160     ' ATTENTION, le point n'est pas nécessairement dans la face
1161     For i = 0 To UBound(Pts) - 1 Step 3
1162     If Commun.Distance(swFace, Pts(i + 0), Pts(i + 1), Pts(i + 2)) < Epsilon Then
1163     ReDim Preserve PointsTemp(j + 2)
1164     PointsTemp(j) = Pts(i + 0)
1165     PointsTemp(j + 1) = Pts(i + 1)
1166     PointsTemp(j + 2) = Pts(i + 2)
1167     j += 3
1168     End If
1169     Next
1170    
1171     xyz = PointsTemp
1172     If xyz Is Nothing Then Return False
1173     If UBound(xyz) > 0 Then Return True
1174    
1175     End Function
1176    
1177    
1178    
1179 bournival 130 Private Function DetectFaceArete(ByRef swArete As sldworks.Edge, ByRef Slyface As SlyFaceVolume, ByRef xyz() As Double, Optional ByRef SurSurface As Boolean = False) As Boolean
1180     Dim swface As sldworks.Face2
1181    
1182 bournival 40 For Each swface In Slyface.lst_Faces
1183     If DetectFaceArete(swArete, swface, xyz) Then
1184     Dim vEdges As Object
1185 bournival 130 Dim Arete As sldworks.Edge
1186 bournival 40 Dim inu() As Double = Nothing
1187    
1188     vEdges = swface.GetEdges
1189    
1190     For Each Arete In vEdges
1191     If DetectAreteArete(Arete, swArete, inu) Then
1192     ' on a un type d'intersection entre une face et une arète...
1193 bournival 130 Dim swSurf As sldworks.Surface
1194 bournival 40 Dim retval As Object
1195     Dim v(2) As Double
1196     Dim u(2) As Double
1197     Dim angle As Double
1198     swSurf = swface.GetSurface
1199     retval = swSurf.EvaluateAtPoint(xyz(0), xyz(1), xyz(2))
1200     ' les 3 premiers de retval sont la normale...
1201     v(0) = retval(0) : v(1) = retval(1) : v(2) = retval(2)
1202    
1203     retval = swArete.GetParameter(inu(0), inu(1), inu(2))
1204     retval = swArete.Evaluate(retval(0))
1205     u(0) = retval(3) : u(1) = retval(4) : u(2) = retval(5)
1206     angle = Outils_Math.Angle2Vecteurs(u, v)
1207 bournival 130 'MsgBox(angle * 180 / Pi & "<-- angle sens --> " & swface.FaceInSurfaceSense & vbCr & "Aire = " & Slyface.Aire)
1208 bournival 40
1209 bournival 130
1210     'Si l'angle entre la normale de la face et la normale de la courbe est de 0
1211     ' ou de pi/2 alors on a une SurSurface
1212     If Math.Abs(angle - Pi / 2) < 100 * Epsilon Or Math.Abs(angle) < 100 * Epsilon Then
1213     SurSurface = True
1214     Else
1215 bournival 40 Return True
1216     End If
1217 bournival 130
1218     'If ((angle < (Pi / 2)) Xor swface.FaceInSurfaceSense()) Then
1219     ' Return True
1220     'Else
1221     ' SurSurface = True
1222     'End If
1223 bournival 40 End If
1224     Next
1225    
1226    
1227 bournival 130 If Not SurSurface Then Return True Else Return False
1228 bournival 40 End If
1229     Next
1230     End Function
1231    
1232    
1233    
1234    
1235     Private Function DetectSurfaceArete(ByRef swArete As SldWorks.Edge, ByRef swFace As SldWorks.Face2, ByRef xyz() As Double) As Boolean
1236     ' function qui détecte si une arête coupe une face, si c'est le cas la function retourne true et remplie le tableau xyz avec le point d'intersection
1237     Dim swCurve As SldWorks.Curve
1238     Dim swSurf As SldWorks.Surface
1239     Dim vCurveParam As Object
1240    
1241     Dim vCurveBounds As Object, vPointArray As Object = Nothing, vTArray As Object = Nothing, vUVArray As Object = Nothing
1242     Dim nCurveBounds(5) As Double
1243     Dim bRet As Boolean
1244     Dim i As Integer
1245    
1246     '1 - on va chercher la courbe et la surface
1247     swCurve = swArete.GetCurve
1248     swSurf = swFace.GetSurface
1249    
1250    
1251     ' 2- on va chercher les paramètres de la spline avec Curve::ConvertLineToBcurve
1252     vCurveParam = swArete.GetCurveParams2
1253     If swCurve.IsLine Then
1254     Dim startp(2) As Double
1255     Dim endp(2) As Double
1256     Dim vStart As Object
1257     Dim vEnd As Object
1258    
1259    
1260     startp(0) = vCurveParam(0)
1261     startp(1) = vCurveParam(1)
1262     startp(2) = vCurveParam(2)
1263     vStart = startp
1264    
1265     endp(0) = vCurveParam(3)
1266     endp(1) = vCurveParam(4)
1267     endp(2) = vCurveParam(5)
1268     vEnd = endp
1269    
1270     Dim retval As Object
1271    
1272     retval = swCurve.ConvertLineToBcurve(vStart, vEnd)
1273    
1274     ' on suppose que la droite est toujours transformée en spline non-rationelle de dimension 3 et d'ordre 2
1275     Dim knots(3) As Double
1276     Dim ctrlPoints(5) As Double
1277    
1278     knots(0) = retval(2)
1279     knots(1) = retval(3)
1280     knots(2) = retval(4)
1281     knots(3) = retval(5)
1282    
1283     ctrlPoints(0) = retval(6)
1284     ctrlPoints(1) = retval(7)
1285     ctrlPoints(2) = retval(8)
1286     ctrlPoints(3) = retval(9)
1287     ctrlPoints(4) = retval(10)
1288     ctrlPoints(5) = retval(11)
1289    
1290     '3 - on créé une spline dans le modeleur
1291    
1292    
1293     Dim modeler As SldWorks.Modeler
1294     modeler = swApp.GetModeler
1295     Dim props As Object
1296     Dim dProps(1) As Double
1297     Dim vKnots As Object, vCtrlPoints As Object
1298    
1299     dProps(0) = retval(0)
1300     dProps(1) = retval(1)
1301     props = dProps
1302     vKnots = knots
1303     vCtrlPoints = ctrlPoints
1304    
1305     swCurve = modeler.CreateBsplineCurve(props, vKnots, vCtrlPoints)
1306     ' 4 - on a une spline, on peut utiliser la fonction IntersectCurve
1307     End If
1308    
1309    
1310     For i = 0 To 5
1311     nCurveBounds(i) = vCurveParam(i)
1312     Next i
1313    
1314     vCurveBounds = nCurveBounds
1315     bRet = swSurf.IntersectCurve(swCurve, vCurveBounds, vPointArray, vTArray, vUVArray)
1316    
1317     Dim Pts() As Double
1318     Dim PointsTemp() As Double = Nothing
1319     Dim j As Integer
1320    
1321     Pts = vPointArray
1322    
1323     If UBound(Pts) < 1 Then Return False
1324    
1325     For i = 0 To UBound(Pts) - 1 Step 3
1326     ReDim Preserve PointsTemp(j + 2)
1327     PointsTemp(j) = Pts(i + 0)
1328     PointsTemp(j + 1) = Pts(i + 1)
1329     PointsTemp(j + 2) = Pts(i + 2)
1330     j += 3
1331     Next i
1332    
1333     xyz = PointsTemp
1334     If xyz Is Nothing Then Return False
1335     If UBound(xyz) > 0 Then Return True
1336    
1337    
1338     End Function
1339    
1340    
1341    
1342     Private Function DetectSommetArete(ByRef swsommet As SldWorks.Vertex, ByRef swArete As SldWorks.Edge, ByRef xyz() As Double) As Boolean
1343     Dim x As Double, y As Double, z As Double
1344     Dim vPoint As Object
1345     Dim vPoint2 As Object
1346     vPoint = swsommet.GetPoint
1347    
1348     x = vPoint(0)
1349     y = vPoint(1)
1350     z = vPoint(2)
1351    
1352     vPoint2 = swArete.GetClosestPointOn(x, y, z)
1353     If Math.Abs(vPoint2(0) - x) < Epsilon And Math.Abs(vPoint2(1) - y) < Epsilon And Math.Abs(vPoint2(2) - z) < Epsilon Then
1354     ReDim xyz(2)
1355     xyz(0) = x
1356     xyz(1) = y
1357     xyz(2) = z
1358     DetectSommetArete = True
1359     End If
1360    
1361     End Function
1362    
1363    
1364     Private Function DetectSommetArete(ByRef x As Double, ByRef y As Double, ByRef z As Double, ByRef swArete As SldWorks.Edge) As Byte
1365     Dim vPoint As Object
1366     Dim vPoint2 As Object
1367    
1368     vPoint2 = swArete.GetClosestPointOn(x, y, z)
1369     If Math.Abs(vPoint2(0) - x) < Epsilon And Math.Abs(vPoint2(1) - y) < Epsilon And Math.Abs(vPoint2(2) - z) < Epsilon Then
1370     DetectSommetArete = 1
1371    
1372     ' maintenant on cherche à savoir si ca touche au premier sommet de l'arrête.
1373     vPoint = swArete.GetCurveParams2()
1374    
1375     If Math.Abs(vPoint(0) - x) < Epsilon And Math.Abs(vPoint(1) - y) < Epsilon And Math.Abs(vPoint(2) - z) < Epsilon Then DetectSommetArete = 2
1376     If Math.Abs(vPoint(3) - x) < Epsilon And Math.Abs(vPoint(4) - y) < Epsilon And Math.Abs(vPoint(5) - z) < Epsilon Then DetectSommetArete = 2
1377    
1378     End If
1379    
1380     End Function
1381    
1382     Private Function DetectSommetArete(ByRef swArete2som As SldWorks.Edge, ByRef swArete As SldWorks.Edge, ByRef xyz() As Double, Optional ByRef ret As Byte = 0) As Boolean
1383     ' ret: 1 = sur premier sommet, 2 = sur dernier sommet
1384     Dim x As Double, y As Double, z As Double
1385     Dim vPoint As Object
1386     Dim vPoint2 As Object
1387     Dim swSommet As SldWorks.Vertex
1388    
1389     swSommet = swArete2som.GetStartVertex
1390     If IsNothing(swSommet) Then Exit Function ' on a un cercle...
1391    
1392    
1393     vPoint = swSommet.GetPoint
1394    
1395     x = vPoint(0)
1396     y = vPoint(1)
1397     z = vPoint(2)
1398    
1399     vPoint2 = swArete.GetClosestPointOn(x, y, z)
1400     If Math.Abs(vPoint2(0) - x) < Epsilon And Math.Abs(vPoint2(1) - y) < Epsilon And Math.Abs(vPoint2(2) - z) < Epsilon Then
1401     ReDim xyz(2)
1402     xyz(0) = x
1403     xyz(1) = y
1404     xyz(2) = z
1405     DetectSommetArete = True
1406     ret += 1
1407     End If
1408    
1409     swSommet = swArete2som.GetEndVertex
1410     vPoint = swSommet.GetPoint
1411    
1412     x = vPoint(0)
1413     y = vPoint(1)
1414     z = vPoint(2)
1415    
1416     vPoint2 = swArete.GetClosestPointOn(x, y, z)
1417     If Math.Abs(vPoint2(0) - x) < Epsilon And Math.Abs(vPoint2(1) - y) < Epsilon And Math.Abs(vPoint2(2) - z) < Epsilon Then
1418     ReDim xyz(2)
1419     xyz(0) = x
1420     xyz(1) = y
1421     xyz(2) = z
1422     DetectSommetArete = True
1423     ret += 2
1424     End If
1425    
1426    
1427     End Function
1428    
1429     Private Sub Memoriser3iemePoint()
1430     Dim poutre As SlyAretePoutre
1431     Dim attr As SldWorks.Attribute
1432     Dim p As SldWorks.Parameter
1433     Dim swEnt As SldWorks.Entity
1434    
1435    
1436    
1437     For Each poutre In Commun.lst_AretePoutre
1438     Dim xyz() As Double
1439     Dim nom As String = Nothing
1440    
1441     If Not poutre.IsFaceDeSection Then
1442     xyz = poutre.GetPoint3(nom)
1443    
1444     poutre.X3 = xyz(0)
1445     poutre.Y3 = xyz(1)
1446     poutre.Z3 = xyz(2)
1447    
1448     swEnt = poutre.swArete
1449    
1450     attr = swEnt.FindAttribute(Intersections.DefAttrRCP1, 0)
1451     p = attr.GetParameter("N3")
1452    
1453     p = attr.GetParameter("X3")
1454     p.SetDoubleValue2(poutre.X3, 2, "")
1455    
1456     p = attr.GetParameter("Y3")
1457     p.SetDoubleValue2(poutre.Y3, 2, "")
1458    
1459     p = attr.GetParameter("Z3")
1460     p.SetDoubleValue2(poutre.Z3, 2, "")
1461     End If
1462     Next poutre
1463    
1464     End Sub
1465    
1466    
1467    
1468     Private Sub CouperPoutres()
1469    
1470     ' procédure qui trouve les intersections entre les poutres et qui les coupe.
1471     ' à la fin on a plus d'intersections entre les poutres (ailleur qu'un sommet)
1472    
1473     Dim swArete1 As SldWorks.Edge
1474     Dim swArete2 As SldWorks.Edge
1475     Dim SlyArete1 As SlyAretePoutre
1476     Dim SlyArete2 As SlyAretePoutre
1477    
1478     Dim xyz() As Double = Nothing
1479     Dim pt As New InterPoutrePoutre
1480     'Dim lst_pts As New Collection
1481     Dim i As Long
1482    
1483     Dim a1 As Integer
1484     Dim a2 As Integer
1485    
1486 bournival 130 Try
1487     For a1 = 0 To lst_AretePoutre.Count - 1
1488     SlyArete1 = lst_AretePoutre.Item(a1)
1489     swArete1 = SlyArete1.swArete
1490 bournival 40
1491 bournival 130 If Not a1 = lst_AretePoutre.Count - 1 Then
1492     For a2 = a1 + 1 To lst_AretePoutre.Count - 1
1493     SlyArete2 = lst_AretePoutre.Item(a2)
1494     swArete2 = SlyArete2.swArete
1495 bournival 40
1496 bournival 130 If DetectAreteArete(swArete1, swArete2, xyz) Then ' intersection courbe-courbe
1497     For i = 0 To CInt((UBound(xyz) + 1) / 4) Step 4 ' si y'a plus d'une intersection entre les 2 courbes...
1498 bournival 40
1499 bournival 130 Select Case isIntersect_milieu(swArete1, swArete2, xyz(i), xyz(i + 1), xyz(i + 2))
1500     Case 1 ' la première courbe est coupée
1501     pt = New InterPoutrePoutre
1502     pt.Arete = swArete1
1503     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
1504     SlyArete1.AjouterPointAPAP(pt)
1505     pt = Nothing
1506     Case 2 ' la seconde courbe est coupée
1507     pt = New InterPoutrePoutre
1508     pt.Arete = swArete2
1509     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
1510     SlyArete2.AjouterPointAPAP(pt)
1511     pt = Nothing
1512     Case 3 ' les doux poutres sont coupées
1513     pt = New InterPoutrePoutre
1514     pt.Arete = swArete1
1515     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
1516     SlyArete1.AjouterPointAPAP(pt)
1517     pt = Nothing
1518     pt = New InterPoutrePoutre
1519     pt.Arete = swArete2
1520     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
1521     SlyArete2.AjouterPointAPAP(pt)
1522     pt = Nothing
1523     End Select
1524     Next i
1525     End If
1526 bournival 40
1527 bournival 130 Next a2
1528 bournival 40 End If
1529    
1530 bournival 130 Dim SlyArete3 As SlyAreteCoque
1531     For a2 = 0 To lst_AreteCoque.Count - 1
1532     SlyArete3 = lst_AreteCoque.Item(a2)
1533     swArete2 = SlyArete3.swArete
1534 bournival 40
1535 bournival 130 If DetectAreteArete(swArete1, swArete2, xyz) Then ' intersection courbe-courbe
1536     For i = 0 To CInt((UBound(xyz) + 1) / 4) Step 4 ' si y'a plus d'une intersection entre les 2 courbes...
1537 bournival 40
1538 bournival 130 Select Case isIntersect_milieu(swArete1, swArete2, xyz(i), xyz(i + 1), xyz(i + 2))
1539     Case 1 ' la première courbe est coupée
1540     pt = New InterPoutrePoutre
1541     pt.Arete = swArete1
1542     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
1543     SlyArete1.AjouterPointAPAP(pt)
1544     pt = Nothing
1545     ' seul la coque est coupée, elle sera découpée anyway.
1546     Case 3 ' les doux poutres sont coupées, mais on note juste la deuxième
1547     pt = New InterPoutrePoutre
1548     pt.Arete = swArete1
1549     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
1550     SlyArete1.AjouterPointAPAP(pt)
1551     pt = Nothing
1552     End Select
1553     Next i
1554     End If
1555     Next a2
1556 bournival 40
1557 bournival 130 Dim slyarete4 As SlyAreteVol
1558     For a2 = 0 To lst_AreteVolume.Count - 1
1559     slyarete4 = lst_AreteVolume.Item(a2)
1560     swArete2 = slyarete4.swArete
1561 bournival 40
1562 bournival 130 If DetectAreteArete(swArete1, swArete2, xyz) Then ' intersection courbe-courbe
1563     For i = 0 To CInt((UBound(xyz) + 1) / 4) Step 4 ' si y'a plus d'une intersection entre les 2 courbes...
1564 bournival 40
1565 bournival 130 Select Case isIntersect_milieu(swArete1, swArete2, xyz(i), xyz(i + 1), xyz(i + 2))
1566     Case 1 ' la première courbe est coupée
1567     pt = New InterPoutrePoutre
1568     pt.Arete = swArete1
1569     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
1570     SlyArete1.AjouterPointAPAP(pt)
1571     pt = Nothing
1572     Case 3 ' les doux poutres sont coupées, mais on note juste la deuxième
1573     pt = New InterPoutrePoutre
1574     pt.Arete = swArete1
1575     pt.x = xyz(i) : pt.y = xyz(i + 1) : pt.z = xyz(i + 2)
1576     SlyArete1.AjouterPointAPAP(pt)
1577     pt = Nothing
1578     End Select
1579     Next i
1580     End If
1581     Next a2
1582 bournival 40
1583    
1584    
1585 bournival 130 Next a1
1586     pt = Nothing
1587 bournival 40
1588 bournival 130 Catch
1589     MsgBox(" La première boucle n'a pas marchée")
1590     End Try
1591 bournival 40
1592    
1593 bournival 130 Dim count As Long = 0, count2 As Long = 0
1594     Try
1595 bournival 40
1596 bournival 130 'toutes les poutres ont des points où elles doivent être coupées
1597     ' il suffit de couper.
1598     ' en réalité on suppress et on créé 2 ou plus courbes par dessus.
1599     Dim attr As sldworks.Attribute
1600     Dim swEnt As sldworks.Entity
1601 bournival 40
1602 bournival 130 For Each SlyArete1 In lst_AretePoutre
1603     If SlyArete1.lst_PtsInterAPAP.Count > 0 Then ' on coupe
1604     '1 - ordonner les points, de Tmin à Tmax et inclure les 2 extrémités de la poutre
1605 bournival 40
1606 bournival 130 count += 1
1607     ' si c'est une droite
1608     If SlyArete1.IsLine Then
1609     Dim Pts(,) As Double
1610     Dim swSketch As sldworks.Sketch
1611     ReDim Pts(3, SlyArete1.lst_PtsInterAPAP.Count + 1)
1612 bournival 40
1613 bournival 130 SlyArete1.GetStartPoint(Pts(0, 0), Pts(1, 0), Pts(2, 0)) ' le premier point
1614     Pts(3, 0) = SlyArete1.GetT(Pts(0, 0), Pts(1, 0), Pts(2, 0))
1615 bournival 40
1616 bournival 130 For i = 1 To SlyArete1.lst_PtsInterAPAP.Count
1617     Pts(0, i) = SlyArete1.lst_PtsInterAPAP.Item(i).x
1618     Pts(1, i) = SlyArete1.lst_PtsInterAPAP.Item(i).y
1619     Pts(2, i) = SlyArete1.lst_PtsInterAPAP.Item(i).z
1620     Pts(3, i) = SlyArete1.GetT(Pts(0, i), Pts(1, i), Pts(2, i))
1621     Next i
1622 bournival 40
1623 bournival 130 Dim max As Integer = SlyArete1.lst_PtsInterAPAP.Count + 1
1624     SlyArete1.GetEndPoint(Pts(0, max), Pts(1, max), Pts(2, max)) ' le dernier point
1625     Pts(3, max) = SlyArete1.GetT(Pts(0, max), Pts(1, max), Pts(2, max))
1626 bournival 40
1627 bournival 130 ' faut ordonner les points selon T...
1628     Dim j As Integer
1629     Dim T1 As Double, T2 As Double, T3 As Double, T0 As Double
1630     For i = 0 To max - 2
1631     For j = 0 To max - i - 1
1632     If Pts(3, j) > Pts(3, j + 1) Then
1633     T0 = Pts(0, j) : T1 = Pts(1, j) : T2 = Pts(2, j) : T3 = Pts(3, j)
1634     Pts(0, j) = Pts(0, j + 1) : Pts(1, j) = Pts(1, j + 1) : Pts(2, j) = Pts(2, j + 1) : Pts(3, j) = Pts(3, j + 1)
1635     Pts(0, j + 1) = T0 : Pts(1, j + 1) = T1 : Pts(2, j + 1) = T2 : Pts(3, j + 1) = T3
1636     End If
1637     Next j
1638     Next i
1639 bournival 40
1640    
1641 bournival 130 For i = 0 To UBound(Pts, 2) - 1
1642     swModel.Insert3DSketch2(False)
1643     swModel.CreateLine2(Pts(0, i), Pts(1, i), Pts(2, i), Pts(0, i + 1), Pts(1, i + 1), Pts(2, i + 1)) ' et pour chaque segment
1644     swSketch = swModel.GetActiveSketch2
1645     swModel.Insert3DSketch2(False)
1646 bournival 40
1647 bournival 130 swEnt = swSketch : swEnt.Select2(False, 1) ' doit avoir un mark de 1
1648     swModel.InsertCompositeCurve()
1649     Try
1650     count2 += 1
1651     UpdateAttributs(SlyArete1, i) 'ajouter les attributs de la vieille poutre sur la nouvelle
1652     Catch
1653     MsgBox("UpdateAttribut n'a pas marché au compte # " & count2)
1654     End Try
1655     Next i
1656 bournival 40
1657    
1658 bournival 130 Else ' If SlyArete1.IsCircle Then ' si c'est un cercle
1659 bournival 40
1660 bournival 130 Dim Pts(,) As Double
1661     Dim swSketch As sldworks.Sketch
1662     ReDim Pts(3, SlyArete1.lst_PtsInterAPAP.Count + 1)
1663 bournival 40
1664 bournival 130 SlyArete1.GetStartPoint(Pts(0, 0), Pts(1, 0), Pts(2, 0)) ' le premier point
1665     Pts(3, 0) = SlyArete1.GetT(Pts(0, 0), Pts(1, 0), Pts(2, 0))
1666 bournival 40
1667 bournival 130 For i = 1 To SlyArete1.lst_PtsInterAPAP.Count
1668     Pts(0, i) = SlyArete1.lst_PtsInterAPAP.Item(i).x
1669     Pts(1, i) = SlyArete1.lst_PtsInterAPAP.Item(i).y
1670     Pts(2, i) = SlyArete1.lst_PtsInterAPAP.Item(i).z
1671     Pts(3, i) = SlyArete1.GetT(Pts(0, i), Pts(1, i), Pts(2, i))
1672     Next i
1673 bournival 40
1674 bournival 130 Dim max As Integer = SlyArete1.lst_PtsInterAPAP.Count + 1
1675     SlyArete1.GetEndPoint(Pts(0, max), Pts(1, max), Pts(2, max)) ' le dernier point
1676     Pts(3, max) = SlyArete1.GetT(Pts(0, max), Pts(1, max), Pts(2, max))
1677 bournival 40
1678 bournival 130 ' faut ordonner les points selon T...
1679     Dim j As Integer
1680     Dim T1 As Double, T2 As Double, T3 As Double, T0 As Double
1681     For i = 0 To max - 2
1682     For j = 0 To max - i - 1
1683     If Pts(3, j) > Pts(3, j + 1) Then
1684     T0 = Pts(0, j) : T1 = Pts(1, j) : T2 = Pts(2, j) : T3 = Pts(3, j)
1685     Pts(0, j) = Pts(0, j + 1) : Pts(1, j) = Pts(1, j + 1) : Pts(2, j) = Pts(2, j + 1) : Pts(3, j) = Pts(3, j + 1)
1686     Pts(0, j + 1) = T0 : Pts(1, j + 1) = T1 : Pts(2, j + 1) = T2 : Pts(3, j + 1) = T3
1687     End If
1688     Next j
1689     Next i
1690 bournival 40
1691 bournival 130 Dim skSeg As sldworks.SketchSegment
1692     Dim x As Double, y As Double, z As Double
1693     Dim vretval As Object
1694     Dim useEdge As sldworks.SketchSegment
1695     Dim m As Integer
1696 bournival 40
1697    
1698 bournival 130 For i = 0 To UBound(Pts, 2) - 1
1699     swModel.Insert3DSketch2(False)
1700     ' sélectionner la edge originale
1701     swEnt = SlyArete1.swArete
1702     swEnt.Select4(False, Nothing)
1703     swModel.SketchUseEdge2(False)
1704     swSketch = swModel.GetActiveSketch2()
1705 bournival 40
1706 bournival 130 ' on créé 2 lignes de construction et on pick de chaque coté... mais on ne le fait pas si on est au premier ou au dernier segment. là on fait juste un pick.
1707     If i <> 0 Then ' premier pick, élimine ce qui est avant.
1708     skSeg = swModel.CreateLine2(Pts(0, i), Pts(1, i), Pts(2, i), 0.01, 0.01, 0.01) 'pts(0, i - 1) + 10000000 * Epsilon, pts(1, i - 1) + 100000 * Epsilon, pts(2, i - 1) + 100000 * Epsilon)
1709     skSeg.ConstructionGeometry = True ' ligne de construction
1710     swModel.ClearSelection2(True)
1711     ' x et y doit être sélectionné sur un point avec un T inférieur au point d'intersection
1712     SlyArete1.Evaluer((Pts(3, i - 1) + Pts(3, i)) / 2, x, y, z)
1713     vretval = swSketch.GetSketchSegments
1714     useEdge = vretval(0) : m = 0
1715     Do Until useEdge.ConstructionGeometry = False
1716     m += 1
1717     useEdge = vretval(m)
1718     Loop
1719     useEdge.Select4(False, Nothing)
1720     swModel.SketchTrim(1, 0, x, y) ' option = 1 pour trim, selEnd est pas utilisé ?, puis un point x et Y pour sélectionner. et y'a pas de Z????? c'est un sketch3D!!!!!
1721     skSeg = swModel.CreateLine2(0, 0, 0, x, y, 0)
1722     skSeg.ConstructionGeometry = True
1723     End If
1724 bournival 40
1725 bournival 130 If i <> UBound(Pts, 2) - 1 Then 'Second(pick)
1726     skSeg = swModel.CreateLine2(Pts(0, i + 1), Pts(1, i + 1), Pts(2, i + 1), 0.05, 0, 0.01) 'pts(0, i + 1) + 10000000 * Epsilon, pts(1, i + 1) + 1000000 * Epsilon, pts(2, i + 1) + 100000 * Epsilon)
1727     skSeg.ConstructionGeometry = True ' ligne de construction
1728     swModel.ClearSelection2(True)
1729 bournival 40
1730 bournival 130 ' x et y doit être sélectionné sur un point avec un T inférieur au point d'intersection
1731     SlyArete1.Evaluer((Pts(3, i + 1) + Pts(3, i + 2)) / 2, x, y, z)
1732     vretval = swSketch.GetSketchSegments
1733     useEdge = vretval(0) : m = 0
1734     Do Until useEdge.ConstructionGeometry = False
1735     m += 1
1736     useEdge = vretval(m)
1737     Loop
1738 bournival 40
1739 bournival 130 useEdge.Select4(False, Nothing)
1740     swModel.SketchTrim(1, 0, x, y) ' option = 1 pour trim, selEnd est pas utilisé ?, puis un point x et Y pour sélectionner. et y'a pas de Z????? c'est un sketch3D!!!!!
1741     skSeg = swModel.CreateLine2(0, 0.02, 0, x, y, 0)
1742     skSeg.ConstructionGeometry = True
1743     End If
1744 bournival 40
1745 bournival 130 swModel.Insert3DSketch2(False)
1746     swEnt = swSketch : swEnt.Select2(False, 1) ' doit avoir un mark de 1
1747     swModel.InsertCompositeCurve()
1748     UpdateAttributs(SlyArete1, i)
1749     Next i
1750 bournival 40
1751 bournival 130 End If
1752 bournival 40
1753    
1754 bournival 205 ' on met un attribut pour ignorer l'arète. Les sommets devraient donc aussi être ignorés.
1755 bournival 40
1756 bournival 205 SlyArete1.MettreAttributIgnorer()
1757 bournival 40
1758 bournival 205 'Dim nom As String
1759     'Dim no As Integer
1760     'Dim arete As sldworks.Edge
1761     'arete = SlyArete1.swArete
1762     'swEnt = arete
1763     'nom = "Ignorer" & SlyArete1.nom & "_" & CStr(no)
1764     'attr = swEnt.FindAttribute(Intersections.DefAttrRCP1, 0)
1765     ''attr = DefAttrRCP1.CreateInstance5(swModel, arete, nom, 0, 2) ' une deuxième instance du RCPoutre...
1766     'If attr Is Nothing Then
1767     ' Commun.ColorerAretes()
1768     ' swEnt = SlyArete1.swArete
1769     ' attr = swEnt.FindAttribute(Intersections.DefAttrRCP1, 0)
1770     'End If
1771 bournival 40
1772 bournival 205 'Dim p As sldworks.Parameter
1773     'p = attr.GetParameter("D1")
1774     'p.SetDoubleValue(-9)
1775     'p = attr.GetParameter("D2")
1776     'p.SetDoubleValue(-9)
1777     'p = attr.GetParameter("D3")
1778     'p.SetDoubleValue(-9)
1779     'p = attr.GetParameter("D4")
1780     'p.SetDoubleValue(-9)
1781 bournival 40
1782 bournival 205 'If attr Is Nothing Then MsgBox("Pas marché")
1783    
1784    
1785 bournival 130 End If
1786     Next SlyArete1
1787     Catch
1788     MsgBox("La seconde boucle n'a pas marchée Compte: " & count)
1789     End Try
1790 bournival 40
1791     End Sub
1792    
1793    
1794 bournival 130 Private Sub UpdateAttributs(ByRef slyarete1 As SlyAretePoutre, ByVal i As Integer)
1795     Dim newArete As sldworks.Edge
1796     Dim refcurve As sldworks.ReferenceCurve
1797     Dim attr As sldworks.Attribute = Nothing
1798     Dim swfeat As sldworks.Feature
1799     swModel.EditRebuild3()
1800 bournival 40 swfeat = swModel.FeatureByPositionReverse(0)
1801    
1802 bournival 130 Debug.Print(swfeat.Name & "<-- Nom Typename--> " & swfeat.GetTypeName)
1803    
1804 bournival 40 refcurve = swfeat.GetSpecificFeature2()
1805     newArete = refcurve.GetFirstSegment()
1806    
1807 bournival 130 Dim ParamM As sldworks.Parameter
1808     Dim ParamS As sldworks.Parameter
1809     Dim ParamI1 As sldworks.Parameter
1810     Dim ParamI2 As sldworks.Parameter
1811     Dim ParamD1 As sldworks.Parameter
1812     Dim ParamD2 As sldworks.Parameter
1813     Dim ParamD3 As sldworks.Parameter
1814     Dim ParamD4 As sldworks.Parameter
1815     Dim ParamD5 As sldworks.Parameter
1816     Dim ParamD6 As sldworks.Parameter
1817     Dim ParamAs As sldworks.Parameter
1818     Dim ParamN3 As sldworks.Parameter
1819 bournival 40
1820 bournival 130 Do While attr Is Nothing
1821     attr = Intersections.DefAttrRCP1.CreateInstance5(swModel, newArete, "Nouveau" & i & slyarete1.nom, 0, 2)
1822     i += 1
1823     Loop
1824 bournival 40
1825     ParamM = attr.GetParameter("M")
1826     ParamS = attr.GetParameter("S")
1827     ParamI1 = attr.GetParameter("I1")
1828     ParamI2 = attr.GetParameter("I2")
1829     ParamD1 = attr.GetParameter("D1")
1830     ParamD2 = attr.GetParameter("D2")
1831     ParamD3 = attr.GetParameter("D3")
1832     ParamD4 = attr.GetParameter("D4")
1833     ParamD5 = attr.GetParameter("D5")
1834     ParamD6 = attr.GetParameter("D6")
1835     ParamAs = attr.GetParameter("As")
1836    
1837     ParamM.SetStringValue2(slyarete1.GetM, 2, "") ' swAllConfiguration = 2
1838     ParamS.SetStringValue2(slyarete1.GetSection, 2, "")
1839     ParamI1.SetDoubleValue2(slyarete1.GetInertieXX, 2, "")
1840     ParamI2.SetDoubleValue2(slyarete1.GetInertieYY, 2, "")
1841     ParamD1.SetDoubleValue2(slyarete1.GetD1, 2, "")
1842     ParamD2.SetDoubleValue2(slyarete1.GetD2, 2, "")
1843     ParamD3.SetDoubleValue2(slyarete1.GetD3, 2, "")
1844     ParamD4.SetDoubleValue2(slyarete1.GetD4, 2, "")
1845     ParamD5.SetDoubleValue2(slyarete1.GetD5, 2, "")
1846     ParamD6.SetDoubleValue2(slyarete1.GetD6, 2, "")
1847     ParamAs.SetDoubleValue2(slyarete1.GetAireSection, 2, "")
1848    
1849 bournival 130 Dim p As sldworks.Parameter
1850 bournival 40 p = attr.GetParameter("N3")
1851     p.SetStringValue(slyarete1.GetN3)
1852     p = attr.GetParameter("X3")
1853     p.SetDoubleValue2(slyarete1.X3, 2, "")
1854     p = attr.GetParameter("Y3")
1855     p.SetDoubleValue2(slyarete1.Y3, 2, "")
1856     p = attr.GetParameter("Z3")
1857     p.SetDoubleValue2(slyarete1.Z3, 2, "")
1858    
1859 bournival 130 ' Commun.GererDossiers("Poutres", "Nouveau" & i & slyarete1.nom)
1860 bournival 40
1861     End Sub
1862    
1863    
1864    
1865    
1866     ''' <summary>
1867     ''' sub qui gère la détection des intersections entre les coques et les volumes.
1868     ''' </summary>
1869     ''' <remarks></remarks>
1870     Private Sub DetectionCoqueVolume()
1871    
1872     ' détection de coque-coque
1873     Dim Face1 As SlyFaceVolume
1874     Dim coque2 As SlyFaceCoque
1875     Dim sketch As SldWorks.Sketch = Nothing
1876     Dim interFF As InterCoqueVolume
1877    
1878     For Each Face1 In Commun.lst_FaceVolume
1879     For Each coque2 In lst_FaceCoque
1880    
1881     If DetectFaceFace(coque2, Face1, True, sketch) Then
1882 bournival 130 ' création de l'instance de interFace-face entre coque et volume
1883 bournival 40
1884 bournival 130 Dim vSeg As Object = sketch.GetSketchSegments()
1885     If vSeg Is Nothing Then
1886     DetectFaceFace(coque2, Face1, True, sketch)
1887     vSeg = sketch.GetSketchSegments()
1888     If vSeg Is Nothing Then MsgBox("Problème") : Err.Raise(555)
1889     End If
1890 bournival 40
1891 bournival 130
1892    
1893 bournival 40 interFF = New InterCoqueVolume
1894     interFF.sFaceVolume = Face1
1895     interFF.sFaceCoque = coque2
1896     If coque2.PossedeFaceDeSection = True Then
1897     interFF.FaceDeSection = True
1898     Verifier_Coque_Section(interFF)
1899     Else
1900     interFF.FaceDeSection = False
1901     End If
1902     interFF.sketch = sketch
1903     coque2.lst_InterCoqueVolume.Add(interFF)
1904     End If
1905    
1906 bournival 130 Next coque2
1907     Next Face1
1908 bournival 40
1909    
1910    
1911    
1912     End Sub
1913    
1914     ''' <summary>
1915     ''' Sub qui fait les 6 vérifications pour le type d'intersection où la coque est partiellement dessinée en 3D.
1916     ''' En profite également pour remettre à jour la proriété de l'épaisseur de la coque
1917     ''' </summary>
1918     ''' <param name="interFF">L'intersection</param>
1919     ''' <remarks>On fait au total 6 vérifications</remarks>
1920     Private Sub Verifier_Coque_Section(ByRef interFF As InterCoqueVolume)
1921     Dim sFaceCoque As SlyFaceCoque
1922     Dim sFaceVol As SlyFaceVolume
1923     Dim swFace1 As SldWorks.Face2
1924     Dim swent As SldWorks.Entity
1925    
1926     sFaceCoque = interFF.sFaceCoque
1927     sFaceVol = interFF.sFaceVolume
1928    
1929     ' 1 - vérifier que la face du volume est plane
1930     If Not sFaceVol.estPlan Then
1931     Err.Raise(513, "Verifier_Coque_Section", "La face représentant la section de la coque n'est pas plane...")
1932     End If
1933    
1934     ' 1.5 - La face du volume a 4 courbes, 2 petites de même longueur et 2 longues
1935     ' 1.6 ou qu'elle est une courbe fermée avec 2 loop d'une seule arète chaque.
1936     Dim vEdges As Object
1937     Dim Aretes() As SldWorks.Edge
1938     Dim longueur(3) As Double
1939     Dim i As Integer
1940     Dim a As SldWorks.Edge
1941     ReDim Aretes(0)
1942    
1943     swFace1 = sFaceVol.SwFace
1944    
1945     vEdges = swFace1.GetEdges()
1946     For Each a In vEdges
1947     ReDim Preserve Aretes(i)
1948     Aretes(i) = a
1949     i += 1
1950     Next
1951    
1952     If UBound(Aretes) = 3 Then
1953     For i = 0 To 3
1954     longueur(i) = Commun.GetLongueurArete(Aretes(i))
1955     Next i
1956     longueur = Ordonner(longueur, Aretes)
1957     If Not Math.Abs(longueur(0) - longueur(1)) < Epsilon Then
1958     swent = swFace1 : swent.Select2(False, 0)
1959     Err.Raise(514, "Verifier_Coque_Section", "La face du volume représentant la coque n'a pas 2 petites arètes de la même longueur, ce n'est pas normal. La face a problème a été sélectionée")
1960     End If
1961    
1962     ElseIf UBound(Aretes) = 1 Then ' la coque représente un cylindre (ou un autre truc fermé)
1963     If Not swFace1.GetLoopCount = 2 Then
1964     swent = swFace1 : swent.Select2(False, 0)
1965     Err.Raise(514, "Verifier_Coque_Section", "La face du volume représentant la coque n'a pas 2 ou 4 arêtes ou n'est pas correcte... La face a problème a été sélectionée")
1966     End If
1967     Else
1968     swent = swFace1 : swent.Select2(False, 0)
1969     Err.Raise(514, "Verifier_Coque_Section", "La face du volume représentant la coque n'a pas 2 ou 4 arêtes. La face a problème a été sélectionée")
1970     End If
1971    
1972     ' 2 - Vérifier que la ligne est plane, mais ça je ne sais pas comment
1973    
1974     ' 3 - Perpendiculaire
1975     ' ok, on va chercher le midpoint de la ligne et on demande la normale à cette position des 2 faces. Puis on demande(l) 'angle entre les 2 normales...
1976    
1977     Dim swArete As SldWorks.Edge
1978     Dim vmid As Object
1979     Dim mid() As Double = Nothing
1980     Dim T As Double
1981     Dim u() As Double, v() As Double
1982     Dim angle As Double
1983    
1984 bournival 130 If interFF.AreteCoque Is Nothing Then interFF.QuelleAreteCoqueToucheVolume() : Dim effacer As New SuperArete(interFF.AreteCoque, True) ': effacer.Colorer(2, 0.7, 0, 0.7)
1985 bournival 40 swArete = interFF.AreteCoque
1986     T = Commun.GetTMilieu(swArete)
1987     vmid = swArete.Evaluate(T)
1988     mid = vmid
1989    
1990     u = sFaceVol.GetNormale(mid(0), mid(1), mid(2))
1991     v = sFaceCoque.GetNormale(mid(0), mid(1), mid(2))
1992    
1993     angle = Outils_Math.Angle2Vecteurs(u, v)
1994    
1995     If Not Math.Abs(angle - Pi / 2) < (Epsilon * 10) Then
1996     sFaceVol.Selectionner(, False)
1997     sFaceCoque.Selectionner(, True)
1998     Err.Raise(515, "Verifier_Coque_Section", "La face de la coque n'est pas perpendiculaire à la face représentant sa section. Les faces fautives ont été sélectionées.")
1999     End If
2000    
2001     ' 4 - vérifier que les 2 petites arètes sont coupées au milieu
2002    
2003    
2004     ' maintenant on update l'attribut de la coque, par chance, j'ai les coordonnées du point milieu...
2005     Dim epaisseur As Double
2006     Dim distance1 As Double, distance2 As Double
2007     Dim point1(2) As Double, point2(2) As Double
2008     Dim p As Object = Nothing, p2 As Object = Nothing
2009    
2010     If UBound(Aretes) = 3 Then
2011     p = Aretes(2).GetClosestPointOn(mid(0), mid(1), mid(2))
2012     point1(0) = p(0) : point1(1) = p(1) : point1(2) = p(2)
2013     distance1 = Math.Sqrt((point1(0) - mid(0)) ^ 2 + (point1(1) - mid(1)) ^ 2 + (point1(2) - mid(2)) ^ 2)
2014    
2015     p = Aretes(3).GetClosestPointOn(mid(0), mid(1), mid(2))
2016     point2(0) = p(0) : point2(1) = p(1) : point2(2) = p(2)
2017     distance2 = Math.Sqrt((point2(0) - mid(0)) ^ 2 + (point2(1) - mid(1)) ^ 2 + (point2(2) - mid(2)) ^ 2)
2018    
2019     If Not Math.Abs(distance1 - distance2) < Epsilon Then
2020     Err.Raise(516, "Verifier_Coque_Section", "La distance n'est pas la même de chaque coté de la coque")
2021     Else
2022     epaisseur = distance1 * 2
2023     End If
2024    
2025     ElseIf UBound(Aretes) = 1 Then ' on a des cercles
2026     epaisseur = swModel.ClosestDistance(Aretes(0), Aretes(1), p, p2)
2027     If epaisseur <= 0 Then MsgBox("Il y a un problème ici...")
2028     Else
2029     MsgBox("On ne doit jamias passer ici en principe")
2030     End If
2031    
2032     sFaceCoque.SetAttributDeCoque(epaisseur)
2033    
2034     End Sub
2035    
2036     ''' <summary>
2037     ''' sub qui découpe une face en fonction des paramètres qu'on lui passe.
2038     ''' </summary>
2039     ''' <remarks></remarks>
2040     Private Sub DécouperCoqueVolume()
2041 bournival 205 Static vc As Integer
2042 bournival 130 ' Algo:
2043     ' Pour chaque coque
2044     ' Si on doit couper la coque, alors on la coupe
2045     ' On découpe la face du volume
2046     ' ON identifie les faces internes
2047    
2048    
2049 bournival 40 Dim coque1 As SlyFaceCoque
2050     Dim interFF As InterCoqueVolume
2051    
2052     ' 1 - Pour toutes les coques
2053 bournival 130 Dim lst_face As New Collections.Generic.List(Of SlyFaceVolume)
2054 bournival 40
2055     For Each coque1 In Commun.lst_FaceCoque
2056 bournival 130
2057 bournival 40 For Each interFF In coque1.lst_InterCoqueVolume
2058 bournival 130
2059     'If interFF.Face_A_Plat Then
2060     ' If Not lst_face.Contains(interFF.sFaceVolume) Then
2061     ' lst_face.Add(interFF.sFaceVolume)
2062     ' interFF.DécouperFace_A_Plat()
2063     ' End If
2064    
2065    
2066 bournival 40 If interFF.FaceDeSection Then
2067     CoupeCoque1(interFF)
2068 bournival 130 If Not Intersections.MultiDecoupageCoques Then interFF.MarquerFacesInternes()
2069 bournival 40 Else
2070 bournival 205 interFF.DécouperVolume()
2071     ' s'il y a plus d'une arête sur la coque qui touche au volume alors on doit découper la coque aussi
2072     ' on sélectionne les 2 entités, puis on fait le sketch d'intersection et on évalue le nombre de courbes.
2073     Dim swBod1 As sldworks.Body2 = interFF.sFaceVolume.SwFace.GetBody() : swBod1.Select2(False, Nothing)
2074     Dim swBod2 As sldworks.Body2 = interFF.sFaceCoque.SwFace.GetBody() : swBod2.Select2(True, Nothing)
2075 bournival 130
2076 bournival 205 swModel.Sketch3DIntersections()
2077     Dim sketch As sldworks.Sketch = swModel.GetActiveSketch2
2078     swModel.InsertSketch2(True)
2079     Dim swfeatS As sldworks.Feature = swModel.FeatureByPositionReverse(0)
2080     swfeatS.Name = "Vérif_decoupage_coque#" & vc : vc += 1
2081    
2082     If UBound(sketch.GetSketchSegments) > 1 Then
2083 bournival 40 interFF.DecouperCoque()
2084 bournival 130 interFF.QuelleAreteCoqueToucheVolume()
2085 bournival 40 End If
2086 bournival 205
2087 bournival 130 If Not Intersections.MultiDecoupageCoques Then interFF.MarquerFacesInternes() ' étape 6
2088 bournival 40
2089     End If
2090 bournival 130 Next interFF
2091 bournival 40 Next coque1
2092    
2093    
2094     End Sub
2095    
2096    
2097    
2098     ''' <summary>
2099     ''' Lorsque la coque est modélisée en partie par un morceau de volume. Dessine et coupe.
2100     ''' </summary>
2101     ''' <param name="int">L'interFaceFace</param>
2102     ''' <remarks></remarks>
2103     Private Sub CoupeCoque1(ByRef int As InterCoqueVolume)
2104     Dim sVol As SlyFaceVolume
2105     Dim swFace As SldWorks.Face2
2106     Dim swent As SldWorks.Entity
2107     Dim sketch As SldWorks.Sketch
2108     Dim vEdges As Object
2109     Dim swArete As SldWorks.Edge
2110     Dim aretes() As SldWorks.Edge = Nothing
2111     Dim i As Integer
2112    
2113     ' a - prendre la face du volume
2114     sVol = int.sFaceVolume
2115     swFace = sVol.SwFace
2116     sVol.Selectionner(0, False)
2117    
2118 bournival 130 '' b - lui mettre une esquisse
2119     'swModel.InsertSketch2(True)
2120 bournival 40
2121 bournival 130 '' c - convertir l'esquisse déjà créée
2122     'sketch = int.sketch
2123     'swent = sketch
2124     'swent.Select2(False, 0)
2125 bournival 40
2126 bournival 130 'swModel.SketchUseEdge2(False)
2127 bournival 40
2128 bournival 130 '' si la face est carrée
2129 bournival 40
2130 bournival 130 'If swFace.GetEdgeCount = 4 Then
2131     ' ' d - ajouter des lignes pour compléter l'esquisse
2132     ' Dim longueur(3) As Double
2133 bournival 40
2134    
2135 bournival 130 ' Dim vLine As Object
2136     ' Dim line1 As SldWorks.SketchLine, line2 As SldWorks.SketchLine
2137     ' Dim P1 As SldWorks.SketchPoint, P2 As SldWorks.SketchPoint, P3 As SldWorks.SketchPoint, P4 As SldWorks.SketchPoint
2138     ' Dim skSeg As SldWorks.SketchSegment
2139     ' vEdges = swFace.GetEdges()
2140     ' For Each swArete In vEdges
2141     ' ReDim Preserve aretes(i)
2142     ' aretes(i) = swArete
2143     ' i += 1
2144     ' Next
2145     ' For i = 0 To 3
2146     ' longueur(i) = Commun.GetLongueurArete(vEdges(i))
2147     ' Next i
2148     ' longueur = Ordonner(longueur, aretes)
2149 bournival 40
2150 bournival 130 ' swent = aretes(3) : swent.Select2(False, 0) ' on prend la plus grande arète
2151     ' swModel.SketchUseEdge2(False)
2152     ' sketch = swModel.GetActiveSketch()
2153     ' vLine = sketch.GetSketchSegments()
2154     ' skSeg = vLine(0) : line1 = skSeg
2155     ' skSeg = vLine(1) : line2 = skSeg
2156 bournival 40
2157 bournival 130 ' P1 = line1.GetStartPoint2()
2158     ' P2 = line1.GetEndPoint2()
2159     ' P3 = line2.GetStartPoint2()
2160     ' P4 = line2.GetEndPoint2()
2161 bournival 40
2162 bournival 130 ' If Distance(P1.X, P1.Y, P1.Z, P3.X, P3.Y, P3.Z) < Distance(P1.X, P1.Y, P1.Z, P4.X, P4.Y, P4.Z) Then ' ligne entre 1 et 3
2163     ' swModel.CreateLine2(P1.X, P1.Y, P1.Z, P3.X, P3.Y, P3.Z)
2164     ' swModel.CreateLine2(P2.X, P2.Y, P2.Z, P4.X, P4.Y, P4.Z)
2165     ' Else ' ligne entre 1 et 4 & 2 et 3
2166     ' swModel.CreateLine2(P1.X, P1.Y, P1.Z, P4.X, P4.Y, P4.Z)
2167     ' swModel.CreateLine2(P2.X, P2.Y, P2.Z, P3.X, P3.Y, P3.Z)
2168     ' End If
2169     'Else
2170     ' sketch = swModel.GetActiveSketch()
2171     'End If
2172     'swModel.InsertSketch2(True)
2173 bournival 40
2174    
2175 bournival 130 '' e - splitter
2176     'swent = swFace : swent.Select2(False, 1)
2177     'swent = sketch : swent.Select2(True, 4)
2178     'swModel.InsertSplitLineProject(False, False)
2179 bournival 40
2180    
2181 bournival 130 sVol.Selectionner(32, False) 'swPart.Extension.SelectByID2("", "FACE", 0.05746341258515, 0.007456177698316, 0.04437034503314, False, 16, Nothing, 0)
2182     int.sFaceCoque.Selectionner(16, True) 'swPart.Extension.SelectByID2("", "FACE", 0.03921396269902, -0.007016448377556, 0, True, 32, Nothing, 0)
2183     swPart.FeatureManager.InsertSplitLineIntersect(7)
2184    
2185 bournival 40 ' f - mettre un FaceInterne sur les 2 faces résultantes.
2186     Dim swFeat As SldWorks.Feature
2187     Dim vFace As Object
2188     Dim swFace1 As SldWorks.Face2, swFace2 As SldWorks.Face2
2189     Dim attr As SldWorks.Attribute
2190     Dim nom As String
2191     Dim no As Long
2192     swFeat = swModel.FeatureByPositionReverse(0)
2193     vFace = swFeat.GetFaces
2194    
2195     swFace1 = vFace(0)
2196     swFace2 = vFace(1)
2197    
2198 bournival 130 sVol.AjouterFace(swFace1)
2199     sVol.AjouterFace(swFace2)
2200 bournival 40
2201 bournival 130 'Dim eFace As New SlyFaceVolume(swFace1, True)
2202     'eFace.MettreAttributFaceInterne(swFace1, , False)
2203 bournival 40
2204 bournival 130 'swent = swFace1
2205     'attr = swent.FindAttribute(Intersections.DefAttrFaceInterne, 0) ' si l'attribut existe déjà on pointe dessus.
2206     'nom = "FaceInterneCoque1"
2207     'If attr Is Nothing Then attr = Intersections.DefAttrFaceInterne.CreateInstance5(swModel, swFace1, nom, 0, 2) ' 0 = swThisconfig
2208 bournival 40
2209 bournival 130 'While attr Is Nothing
2210     ' no += 1
2211     ' nom = "FaceInterneCoque" & CStr(no)
2212     ' attr = Intersections.DefAttrFaceInterne.CreateInstance5(swModel, swFace1, nom, 0, 2)
2213     'End While
2214     'GererDossiers("FaceInternes", nom)
2215 bournival 40
2216 bournival 130 'swent = swFace2
2217     'attr = swent.FindAttribute(Intersections.DefAttrFaceInterne, 0) ' si l'attribut existe déjà on pointe dessus.
2218     'nom = "FaceInterneCoque1"
2219     'If attr Is Nothing Then attr = Intersections.DefAttrFaceInterne.CreateInstance5(swModel, swFace2, nom, 0, 2) ' 0 = swThisconfig
2220 bournival 40
2221 bournival 130 'While attr Is Nothing
2222     ' no += 1
2223     ' nom = "FaceInterneCoque" & CStr(no)
2224     ' attr = Intersections.DefAttrFaceInterne.CreateInstance5(swModel, swFace2, nom, 0, 2)
2225     'End While
2226     'GererDossiers("FaceInternes", nom)
2227    
2228    
2229 bournival 40 End Sub
2230    
2231    
2232     ''' <summary>
2233     ''' Détecte s'il y a une intersection entre une coque et une face d'un volume
2234     ''' </summary>
2235     ''' <param name="sFaceCoque"></param>
2236     ''' <param name="sFaceVolume"></param>
2237     ''' <param name="dessiner">Si oui, alors on dessine une ligne à l'intersection</param>
2238     ''' <param name="sketch">Si dessiner est vrai, alors ce sketch contient la ligne d'intersection</param>
2239     ''' <returns>Vrai s'il y a une intersection</returns>
2240     ''' <remarks></remarks>
2241     Private Function DetectFaceFace(ByRef sFaceCoque As SlyFaceCoque, ByRef sFaceVolume As SlyFaceVolume, Optional ByRef dessiner As Boolean = False, Optional ByRef sketch As SldWorks.Sketch = Nothing) As Boolean
2242     For Each swfc As SldWorks.Face2 In sFaceCoque.lst_Faces
2243     For Each swFV As SldWorks.Face2 In sFaceVolume.lst_Faces
2244     If DetectFaceFace(swfc, swFV, dessiner, sketch) Then Return True
2245     Next
2246     Next
2247     End Function
2248    
2249    
2250     ''' <summary>
2251     ''' Function qui retourne vrai ou faux si 2 FACES (pas surfaces) se touchent. La routine finit par appeler la sub dessinecourbe pour dessiner la courbe.
2252     ''' </summary>
2253     ''' <param name="face1">Première face</param>
2254     ''' <param name="face2">Seconde face</param>
2255     ''' <param name="dessiner">Si l'on veut dessiner une esquisse contenant la courbe</param>
2256 bournival 130 ''' <param name="Sketch">Si la précédente option est vrai, ce paramètre redonne l'esquisse qui contient la courbe (peut contenir plusieurs segments) d'intersection</param>
2257 bournival 40 ''' <returns>Vrai si les faces se touchent</returns>
2258     ''' <remarks>Si les 2 faces se touchent en un seul point alors ça retourne faux.</remarks>
2259     Private Function DetectFaceFace(ByRef face1 As SldWorks.Face2, ByRef face2 As SldWorks.Face2, Optional ByRef dessiner As Boolean = False, Optional ByRef Sketch As SldWorks.Sketch = Nothing) As Boolean
2260 bournival 130 'sub qui détecte si 2 faces se touchent et retourne vrai si c'est le cas.
2261     Dim Surface1 As sldworks.Surface
2262     Dim Surface2 As sldworks.Surface
2263 bournival 40 Dim curveArray As Object = Nothing
2264 bournival 130 Dim curve As sldworks.Curve
2265 bournival 40 Dim ret As Boolean
2266     Dim boundsArray As Object = Nothing
2267     Dim bounds() As Double
2268     Dim Point1(2) As Double
2269     Dim Point2(2) As Double
2270     Dim P1 As Object = Nothing, P2 As Object = Nothing
2271     Dim ClosestDist As Double
2272    
2273     Surface1 = face1.GetSurface
2274     Surface2 = face2.GetSurface
2275    
2276     ClosestDist = swModel.ClosestDistance(face1, face2, P1, P2)
2277     If ClosestDist > (Epsilon * 10) Then Return False
2278    
2279     ' curvearray est un tableau de curves, boundsarray est un tableau de T des limites de la courbe
2280     ret = Surface1.IntersectSurface(Surface2, curveArray, boundsArray) ' si c'est une ligne, retourne une ligne infinie...
2281     ' il faut alors renvoyer vers le detectFaceArete()
2282     If Not ret Then Return False
2283     bounds = boundsArray
2284    
2285     Try
2286     curve = curveArray(0)
2287     Catch
2288 bournival 205 Return False 'GoTo Fairesketch 'ne va pas toujours marcher, mais je n'ai rien de mieu pour l'instant...
2289 bournival 130 'MsgBox("On a une intersection où 2 faces sont sur la même surface...") ' en théorie...
2290 bournival 205 ' ouch... pas certain.
2291 bournival 40 End Try
2292    
2293    
2294     If Not curve.IsLine Then ' si c'est une ligne, alors le principe de longueur ne fonctionnera pas...
2295     Dim longueur As Double = curve.GetLength2(bounds(0), bounds(1))
2296     If longueur < Epsilon Then Return False ' on a juste un point d'intersection
2297     Else
2298     Dim vParam As Object
2299     vParam = curve.GetClosestPointOn(P1(0), P1(1), P1(2)) ' vparam(3) est le U
2300    
2301 bournival 130 P1 = curve.Evaluate(vParam(3) + 100000 * Epsilon) : Point1(0) = P1(0) : Point1(1) = P1(1) : Point1(2) = P1(2)
2302     P2 = curve.Evaluate(vParam(3) - 100000 * Epsilon) : Point2(0) = P2(0) : Point2(1) = P2(1) : Point2(2) = P2(2)
2303 bournival 40
2304 bournival 130 ' si p1 et p2 sont identiques alors on a un point D'intersection, ce que l'on ne veut pas
2305     If Distance(Point1, Point2) < 1000 * Epsilon Then Return False
2306    
2307     If ((Distance(face1, Point1(0), Point1(1), Point1(2)) < (1000 * Epsilon)) AndAlso (Distance(face2, Point1(0), Point1(1), Point1(2)) < (1000 * Epsilon))) OrElse ((Distance(face1, Point2(0), Point2(1), Point2(2)) < (Epsilon * 1000)) AndAlso (Distance(face2, Point2(0), Point2(1), Point2(2)) < (1000 * Epsilon))) Then
2308     ' return true
2309 bournival 40 Else
2310 bournival 205
2311 bournival 130 Dim swent2 As sldworks.Entity
2312     Dim feat2 As sldworks.Feature
2313     swModel.Insert3DSketch2(False)
2314     swModel.ClearSelection2(True)
2315 bournival 205 'swent2 = face1 : swent2.Select2(False, 0)
2316     'swent2 = face2 : swent2.Select2(True, 0)
2317     Dim swBod1 As sldworks.Body2 = face1.GetBody : swBod1.Select2(False, Nothing)
2318     Dim swBod2 As sldworks.Body2 = face2.GetBody : swBod2.Select2(True, Nothing)
2319    
2320 bournival 130 swModel.Sketch3DIntersections()
2321    
2322     swModel.Insert3DSketch2(False)
2323     swModel.EditRebuild3()
2324     feat2 = swModel.FeatureByPositionReverse(0)
2325    
2326 bournival 205 Debug.Print(feat2.Name)
2327    
2328 bournival 130 Sketch = feat2.GetSpecificFeature2
2329     feat2.Name = "TouchePas" & CStr(Rnd())
2330 bournival 205 'MsgBox(face1.GetArea)
2331 bournival 130 Dim vSeg2 As Object = Sketch.GetSketchSegments()
2332     If vSeg2 Is Nothing Then
2333     swent2 = feat2
2334     swent2.Select(False)
2335     swModel.EditDelete()
2336     Return False
2337     Else
2338 bournival 205 If Math.Abs(bounds(0)) > 490 Then Return False ' se touchent à l'infini...
2339 bournival 130 Return True
2340     End If
2341 bournival 205
2342 bournival 40 End If
2343     End If
2344    
2345 bournival 205 Fairesketch:
2346 bournival 130 Dim swent As sldworks.Entity
2347     Dim feat As sldworks.Feature
2348     swModel.Insert3DSketch2(False)
2349     swModel.ClearSelection2(True)
2350 bournival 205 'swent = face1 : swent.Select2(False, 0)
2351     'swent = face2 : swent.Select2(True, 0)
2352     Dim swBod1a As sldworks.Body2 = face1.GetBody : swBod1a.Select2(False, Nothing)
2353     Dim swBod2a As sldworks.Body2 = face2.GetBody : swBod2a.Select2(True, Nothing)
2354    
2355 bournival 130 swModel.Sketch3DIntersections()
2356 bournival 40
2357 bournival 130 swModel.Insert3DSketch2(False)
2358     swModel.EditRebuild3()
2359     feat = swModel.FeatureByPositionReverse(0)
2360 bournival 205 Debug.Print(feat.Name)
2361 bournival 130 Sketch = feat.GetSpecificFeature2
2362     Dim vSeg As Object = Sketch.GetSketchSegments()
2363     If vSeg Is Nothing Then
2364     swent = feat
2365     swent.Select(False)
2366     swModel.EditDelete()
2367     Return False
2368     Else
2369     Return True
2370 bournival 40 End If
2371    
2372     Return True
2373    
2374     End Function
2375    
2376    
2377     Public Function trier(ByRef lst() As Double) As Double()
2378     ' sub qui retourne les T min et T max en fonction de la collection.
2379     ' normalement on enlève les 2 points max et min et il devrait nous rester un nombre pair de valeurs.
2380     Dim i As Integer, j As Integer
2381     Dim lst2() As Double
2382    
2383     Dim temp As Double
2384    
2385     If UBound(lst) < 1 Then Return Nothing
2386    
2387     For j = 0 To UBound(lst) - 1
2388     For i = 0 To UBound(lst) - j - 1
2389     If lst(i) > lst(i + 1) Then
2390     temp = lst(i)
2391     lst(i) = lst(i + 1)
2392     lst(i + 1) = temp
2393     End If
2394     Next i
2395     Next j
2396    
2397     ReDim lst2(UBound(lst) - 2)
2398     For i = 1 To UBound(lst) - 1
2399     lst2(i - 1) = lst(i)
2400     Next
2401     Return lst2
2402    
2403    
2404    
2405     End Function
2406    
2407     ''' <summary>
2408     ''' Function qui remet en ordre croissant les valeurs d'un tableau
2409     ''' </summary>
2410     ''' <param name="lst">Le tableau de valeurs à ordonner</param>
2411     ''' <param name="liste2">un second tableau que l'on peut ordonner</param>
2412     ''' <returns></returns>
2413     ''' <remarks></remarks>
2414     Public Function Ordonner(ByRef lst() As Double, Optional ByRef liste2() As SldWorks.Edge = Nothing) As Double()
2415    
2416     Dim i As Integer, j As Integer
2417     Dim temp2 As Object
2418    
2419     Dim temp As Double
2420    
2421     If UBound(lst) < 1 Then Return Nothing
2422    
2423     For j = 0 To UBound(lst) - 1
2424     For i = 0 To UBound(lst) - j - 1
2425     If lst(i) > lst(i + 1) Then
2426     temp = lst(i)
2427     lst(i) = lst(i + 1)
2428     lst(i + 1) = temp
2429     If Not liste2 Is Nothing Then
2430     temp2 = liste2(i)
2431     liste2(i) = liste2(i + 1)
2432     liste2(i + 1) = temp2
2433     End If
2434    
2435     End If
2436     Next i
2437     Next j
2438    
2439     Return lst
2440    
2441    
2442    
2443     End Function
2444    
2445    
2446 bournival 130 ''' <summary>
2447     ''' Sub qui fait comme le tavail de Antoine et Rémi et qui créé un fichier pour la carte de taille. Si l'option de pré-optimisation est enclenchée, la sub ne fait qu'ajouter des éléments au fichier .txt
2448     ''' </summary>
2449     ''' <remarks></remarks>
2450     Public Sub FairePreCarte()
2451 bournival 40
2452 bournival 130 Dim ligne_txt As String
2453     Dim fichier As System.IO.StreamWriter
2454     Dim EcartNodal As Double = Commun.ÉcartNodal
2455 bournival 40
2456 bournival 130 ' si le fichier pog n'est pas encore créé, on doit le faire...
2457     If Commun.NomFichierPog = Nothing Then
2458     ' la première ligne donne la boite englobante, la seconde la taille ENG
2459    
2460     Dim path As String = Nothing
2461     Dim CMDialogl As New Windows.Forms.SaveFileDialog
2462     CMDialogl.DefaultExt = ".txt"
2463     CMDialogl.Filter = "Fichiers PoG (*.txt)|*.txt|Tout fichiers(*.*)|*.*"
2464    
2465     CMDialogl.OverwritePrompt = True
2466     CMDialogl.Title = "Sélectionnez le fichier pour enregistrer les points"
2467     CMDialogl.ShowDialog()
2468     path = CMDialogl.FileName
2469     path = Txtpath(path) : Commun.NomFichierPog = path
2470     If path Is Nothing Or path = "" Then MsgBox("Aucun fichier sélectionné, sortie du programme!", MsgBoxStyle.Critical, "Erreur!")
2471    
2472     fichier = System.IO.File.CreateText(path)
2473    
2474     Dim vBox As Object = swPart.GetPartBox(True)
2475     Dim box() As Double = vBox
2476    
2477     Dim centre(2) As Double ' le centre de la boite englobante
2478     Dim longueurs(2) As Double
2479    
2480     centre(0) = (box(3) + box(0)) / 2
2481     centre(1) = (box(4) + box(1)) / 2
2482     centre(2) = (box(5) + box(2)) / 2
2483    
2484     longueurs(0) = (box(3) - box(0)) * 1.25
2485     longueurs(1) = (box(4) - box(1)) * 1.25
2486     longueurs(2) = (box(5) - box(2)) * 1.25
2487    
2488    
2489     ligne_txt = CStr(centre(0) - longueurs(0) / 2) & " " & CStr(centre(1) - longueurs(1) / 2) & " " & CStr(centre(2) - longueurs(2) / 2) & " " & CStr(centre(0) + longueurs(0) / 2) & " " & CStr(centre(1) + longueurs(1) / 2) & " " & CStr(centre(2) + longueurs(2) / 2)
2490     fichier.WriteLine(Replace(ligne_txt, ",", "."))
2491    
2492     fichier.WriteLine(Replace(CStr(EcartNodal), ",", "."))
2493     Else
2494     ' Le fichier pog existe déjà...
2495     fichier = System.IO.File.AppendText(Commun.NomFichierPog)
2496     'fichier.WriteLine(Replace(CStr(EcartNodal), ",", "."))
2497     End If
2498    
2499    
2500     ' *** C'est ici que le fun se passe.
2501    
2502    
2503     ' 1 - On parcourt toutes les faces, les listes sont déjà RE-crées, donc pas de multifaces
2504     For Each sFace As SlyFaceVolume In Commun.lst_FaceVolume
2505     sFace.MettrePointSurPOG(fichier)
2506     Next
2507    
2508 bournival 205 For Each sFace As SlyFaceCoque In Commun.lst_FaceCoque
2509     sFace.MettrePointSurPOG(fichier)
2510     Next
2511 bournival 130
2512     ' *** Fin
2513     fichier.Close()
2514     End Sub
2515    
2516     ''' <summary>
2517     ''' Fonction qui compare 2 surfaces
2518     ''' </summary>
2519     ''' <param name="swSurf1">La première surface</param>
2520     ''' <param name="swSurf2">La seconde</param>
2521     ''' <returns>Vrai si les 2 surfaces sont identiques, faux sinon</returns>
2522     ''' <remarks></remarks>
2523     Public Function ComparerSurfaces(ByRef swSurf1 As sldworks.Surface, ByRef swSurf2 As sldworks.Surface) As Boolean
2524     'swSurf1.GetBSurfParams2(True,False,
2525    
2526    
2527     If swSurf1.IsPlane And swSurf2.IsPlane Then
2528     Dim obj1 As Object = swSurf1.PlaneParams
2529     Dim obj2 As Object = swSurf2.PlaneParams
2530     For i As Integer = 0 To 2
2531     If Not Math.Abs(obj1(i) - obj2(i)) < Epsilon Then Return False
2532     Next
2533     Return True
2534     ElseIf swSurf1.IsBlending And swSurf2.IsBlending Then
2535     ' pas de blendingParams
2536    
2537     ElseIf swSurf1.IsCone And swSurf2.IsCone Then
2538     Dim obj1 As Object = swSurf1.ConeParams
2539     Dim obj2 As Object = swSurf2.ConeParams
2540     For i As Integer = 0 To 7
2541     If Not Math.Abs(obj1(i) - obj2(i)) < Epsilon Then Return False
2542     Next
2543     Return True
2544    
2545     ElseIf swSurf1.IsCylinder And swSurf2.IsCylinder Then
2546     Dim obj1 As Object = swSurf1.CylinderParams
2547     Dim obj2 As Object = swSurf2.CylinderParams
2548     For i As Integer = 0 To 6
2549     If Not Math.Abs(obj1(i) - obj2(i)) < Epsilon Then Return False
2550     Next
2551     Return True
2552     ElseIf swSurf1.IsForeign And swSurf2.IsForeign Then
2553     ' ???
2554     ElseIf swSurf1.IsOffset And swSurf2.IsOffset Then
2555     ' Pas de offsetParam
2556    
2557     ElseIf swSurf1.IsParametric And swSurf2.IsParametric Then
2558     ' pas de ParametricParams
2559    
2560     ElseIf swSurf1.IsRevolved And swSurf2.IsRevolved Then
2561     ' pas de revolvedparams
2562    
2563     ElseIf swSurf1.IsSphere And swSurf2.IsSphere Then
2564     Dim obj1 As Object = swSurf1.SphereParams
2565     Dim obj2 As Object = swSurf2.SphereParams
2566    
2567     For i As Integer = 0 To 3
2568     If Not Math.Abs(obj1(i) - obj2(i)) < Epsilon Then Return False
2569     Next
2570     Return True
2571     ElseIf swSurf1.IsSwept And swSurf2.IsSwept Then
2572     ' merde, il n'y a pas de Sweptparams
2573    
2574     ElseIf swSurf1.IsTorus And swSurf2.IsTorus Then
2575     Dim obj1 As Object = swSurf1.TorusParams
2576     Dim obj2 As Object = swSurf2.TorusParams
2577    
2578     For i As Integer = 0 To 7
2579     If Not Math.Abs(obj1(i) - obj2(i)) < Epsilon Then Return False
2580     Next
2581     Return True
2582     Else
2583     ' faut quand même évaluer si on a la bonne chose...
2584 bournival 205 Try
2585     Dim pt As Object = swSurf1.Evaluate(0.5, 0.5, 0, 0)
2586     Dim obj As Object = swSurf1.GetClosestPointOn(pt(0), pt(1), pt(2)) ' x, y , z, U, V
2587     Dim obj1 As Object = swSurf1.EvaluateAtPoint(obj(0), obj(1), obj(2))
2588 bournival 130
2589 bournival 205 Dim objb As Object = swSurf2.GetClosestPointOn(pt(0), pt(1), pt(2)) ' x, y , z, U, V
2590     Dim obj2 As Object = swSurf2.EvaluateAtPoint(objb(0), objb(1), objb(2))
2591 bournival 130
2592 bournival 205 If Math.Abs(obj1(9) - obj2(9)) < Epsilon And Math.Abs(obj1(10) - obj2(10)) < Epsilon Then
2593     ' c'est cheap.... mais
2594     Return True
2595     End If
2596     Return False
2597     Catch
2598     Return False
2599     End Try
2600 bournival 130
2601     End If
2602    
2603     Return False
2604    
2605    
2606    
2607     End Function
2608    
2609    
2610 bournival 205
2611 bournival 40 End Module