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

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 Public Class SuperArete
6     Inherits SuperEntite
7     Public swArete As SldWorks.Edge
8     Private Shared compteur As Long
9     Private Shared no As Long
10    
11     Protected swCourbe As SldWorks.Curve
12    
13    
14     ''' <summary>
15     ''' Le new pour un encapsulateur de l'arète
16     ''' </summary>
17     ''' <param name="swArete"></param>
18     ''' <param name="encapsulateur"></param>
19     ''' <remarks></remarks>
20     Public Sub New(ByRef swArete As SldWorks.Edge, ByRef encapsulateur As Boolean)
21     Me.swArete = swArete
22     Me.swCourbe = swArete.GetCurve
23 bournival 130
24    
25 bournival 40 End Sub
26    
27 bournival 130
28    
29 bournival 48 Public Sub New(ByRef arete As SldWorks.Edge, Optional ByVal tip As Integer = 0)
30 bournival 40 Me.swArete = arete
31     Me.swCourbe = swArete.GetCurve
32     Select Case tip
33     Case Commun.tipe_e.Volume
34     nom = "Arete" & compteur
35     Case Commun.tipe_e.coque
36     nom = "AreteCoque" & compteur
37     Case Commun.tipe_e.poutre
38     nom = "AretePoutre" & compteur
39     Case Commun.tipe_e.MiniPoutre
40     nom = "Mini-Poutre" & compteur
41     End Select
42     nomOrig = nom
43     compteur = compteur + 1
44     End Sub
45    
46    
47     Public Overrides Sub SaveNom()
48     ' procédure qui enregistre le nom et qui , pour l'instant ne tient pas compte des conditions aux limites
49     Dim ent As SldWorks.Entity
50     ent = swArete
51     Dim retval As Boolean
52    
53     Try
54     retval = swPart.SetEntityName(ent, nom)
55     Catch
56 bournival 130
57    
58     Dim i As Integer
59     If retval = False Then
60     Do Until retval = True
61     i += 1
62     retval = swPart.SetEntityName(ent, nom & Chr(96 + i))
63     Loop
64     Me.nom = nom & Chr(96 + i)
65     'MsgBox("Impossibilité d'écrire le nom de l'entité... il y a déjà un nom." & Chr(13) & nom) ' MsgBox("Impossibilité d'écrire le nom de l'entité... il y a déjà un nom." & Chr(13) & nom, MsgBoxStyle.Critical, "Problème dans le setID de l'arrète")
66     End If
67     MsgBox("Le prog ne veut pas mettre le nom sur une entité.." & vbCr & "Le nom devrait être: " & nom) ' MsgBox("Le prog ne veut pas mettre le nom sur une entité.." & vbCr & "Le nom devrait être: " & nom)
68 bournival 40 End Try
69     End Sub
70    
71     Shared Sub reinitialiser()
72     compteur = 0
73     End Sub
74    
75     Public Function GetOrientation(ByRef T As Double) As Double()
76     'retval = Edge.Evaluate ( Parameter) retval est un tableau, 4,5 et 6 sont les tangentes au point...
77    
78     Dim temp(2) As Double
79     Dim retval As Object
80    
81     retval = Me.swArete.Evaluate(T)
82    
83     temp(0) = retval(3)
84     temp(1) = retval(4)
85     temp(2) = retval(5)
86    
87     Return temp
88    
89     End Function
90    
91     Public Function GetOrientation(ByRef x As Double, ByRef y As Double, ByRef z As Double) As Double()
92     Dim retval As Object
93     retval = Me.swArete.GetClosestPointOn(x, y, z)
94     Return GetOrientation(retval(3))
95     End Function
96    
97    
98    
99     Public Sub MettreAttributPourConditionLimite()
100     Dim swent As SldWorks.Entity
101     Dim nom As String
102     Dim cond As String
103    
104     cond = Me.condition
105     If cond = "" Then Exit Sub
106    
107     swent = Me.swArete
108    
109     nom = "CL" & CStr(no) & "_" & cond
110     Dim Attr As SldWorks.Attribute = Nothing
111    
112     Try
113     Attr = swent.FindAttribute(Intersections.DefAttrConditionLimite, 0) ' si l'attribut existe déjà on pointe dessus.
114     Catch ex As Exception
115     MsgBox("N'arrive pas à se lier à l'attribut, erreur: " & ex.Message, MsgBoxStyle.Critical)
116     End Try
117    
118     ' si nothing c'est que l'attribut n'existe pas
119     If Attr Is Nothing Then Attr = Intersections.DefAttrConditionLimite.CreateInstance5(swModel, Me.swArete, nom, 0, 2) ' 0 = swThisconfig, 2 = allconfig
120    
121     While Attr Is Nothing
122     no += 1
123     nom = "CL" & CStr(no) & "_" & cond
124     Attr = Intersections.DefAttrConditionLimite.CreateInstance5(swModel, Me.swArete, nom, 0, 2)
125     End While
126    
127     Dim ParamCL As SldWorks.Parameter
128     ParamCL = Attr.GetParameter("CL")
129    
130     ParamCL.SetStringValue2(cond, 2, "") ' swAllConfiguration = 2
131    
132     GererDossiers("Conditions Aux Limites", nom)
133     no = no + 1
134    
135     End Sub
136    
137    
138     ' une fonction qui transforme un attribut en condition aux limites
139     Public Sub AttributVersConditionLimite()
140     Dim p As SldWorks.Parameter
141     Dim ent As SldWorks.Entity
142     Dim attr As SldWorks.Attribute
143    
144     ent = Me.swArete
145     attr = ent.FindAttribute(Intersections.DefAttrConditionLimite, 0)
146     If Not attr Is Nothing Then
147     p = attr.GetParameter("CL")
148     nom = nomOrig & "@" & p.GetStringValue
149     End If
150    
151     End Sub
152    
153    
154     Public Function GetSwSommets() As SldWorks.Vertex()
155     Dim swsommet(1) As SldWorks.Vertex
156     swsommet(0) = Me.swArete.GetStartVertex()
157     If swsommet(0) Is Nothing Then Return Nothing
158     swsommet(1) = Me.swArete.GetEndVertex
159     Return swsommet
160     End Function
161    
162     Public Overrides Sub Selectionner(Optional ByVal Mark As Integer = 0, Optional ByRef Append As Boolean = True)
163     Dim swent As SldWorks.Entity
164     swent = swArete
165     swent.Select2(Append, Mark)
166     End Sub
167    
168    
169    
170     ''' <summary>
171     ''' Renvoie les coordonnées du point milieu
172     ''' </summary>
173     ''' <returns></returns>
174 bournival 130 ''' <remarks>Attention: Ce sont les coordonnées du point à T milieu, ce qui n'est pas nécessairement le milieu de l'arète dans le cas de b-spline </remarks>
175     Public Function GetPointMilieu(Optional ByVal Reverse As Boolean = False) As Double()
176 bournival 40 Dim T As Double
177     Dim xyz(2) As Double
178 bournival 130 T = Me.GetTMilieu(Reverse)
179 bournival 40 Me.Evaluer(T, xyz)
180     Return xyz
181     End Function
182    
183     ''' <summary>
184     ''' Renvoie les coordonnées du point milieu
185     ''' </summary>
186 bournival 130 ''' <returns>Faux si le sommet n'existe pas</returns>
187 bournival 40 ''' <remarks></remarks>
188 bournival 130 Public Function GetPointMilieu(ByRef x As Double, ByRef y As Double, ByRef z As Double, Optional ByVal Reverse As Boolean = False) As Boolean
189 bournival 40 Dim T As Double
190 bournival 130 T = Me.GetTMilieu(Reverse)
191 bournival 40 Me.Evaluer(T, x, y, z)
192     Return True
193     End Function
194    
195    
196    
197    
198     ''' <summary>
199     ''' Détermine si une courbe est une ligne
200     ''' </summary>
201     ''' <returns>Vrai si la courbe est une ligne</returns>
202     ''' <remarks></remarks>
203     Public Function IsLine() As Boolean
204 bournival 130
205     Dim ev As Object = Me.swArete.Evaluate(0.2)
206     Dim cr As sldworks.Curve = Me.swArete.GetCurve
207    
208 bournival 40 Try
209 bournival 130 Dim swCourbe As sldworks.Curve = Me.swArete.GetCurve
210     Select Case swCourbe.Identity()
211    
212     Case swconst.swCurveTypes_e.LINE_TYPE
213     Return True
214    
215     Case Else
216     Return False
217     End Select
218    
219 bournival 40 Catch
220 bournival 130 ' on a un drole de type de courbe... on ne peut dire si c'est une ligne ou autre...
221     Try
222     Dim swCourbe2 As sldworks.Curve = swCourbe.GetBaseCurve
223     Select Case swCourbe2.Identity()
224    
225     Case swconst.swCurveTypes_e.LINE_TYPE
226     Return True
227    
228     Case Else
229     Return False
230     End Select
231     Catch ex As Exception
232    
233     End Try
234    
235    
236     Return False
237 bournival 40 End Try
238    
239     End Function
240    
241 bournival 130
242 bournival 40 ''' <summary>
243 bournival 130 ''' Retourne vrai si la courbe est fermée
244     ''' </summary>
245     ''' <value></value>
246     ''' <returns></returns>
247     ''' <remarks></remarks>
248     Public ReadOnly Property IsClosed() As Boolean
249     Get
250     If Me.swArete.GetStartVertex Is Nothing Then Return False Else Return True
251     End Get
252     End Property
253    
254     ''' <summary>
255 bournival 40 ''' Détermine si la courbe est un cercle
256     ''' </summary>
257     ''' <returns>Vrai si la courbe est un cercle</returns>
258     ''' <remarks></remarks>
259     Public Function IsCircle() As Boolean
260 bournival 130
261 bournival 40 Try
262    
263 bournival 130 If Me.swCourbe.IsLine Then Return False
264 bournival 40 Return Me.swCourbe.IsCircle
265     Catch ex As Exception
266 bournival 130 Dim fault As sldworks.FaultEntity = Me.swArete.Check
267 bournival 40 Debug.WriteLine("N'arrive pas à déterminer si la courbe est un cercle" & vbCr & "FaultEntity.Count = " & IIf(fault Is Nothing, "0", fault.Count) & vbCr & Me.nom)
268 bournival 130
269     Try
270     If swCourbe.Identity() = swconst.swCurveTypes_e.CIRCLE_TYPE Then Return True Else Return False
271    
272     Catch
273     Debug.Print("Même merde que pour la ligne, le lien entre la courbe et le pointeur se perd par magie!")
274     End Try
275    
276 bournival 40 Return False
277     End Try
278    
279     End Function
280    
281     ''' <summary>
282     ''' Détermine si la courbe est une B-Spline
283     ''' </summary>
284     ''' <returns></returns>
285     ''' <remarks>Vrai si la courbe est une b-spline</remarks>
286     Public Function IsBcurve() As Boolean
287     Try
288     Dim swCourbe As SldWorks.Curve = Me.swArete.GetCurve
289     If swCourbe.IsLine Then Return False
290     If swCourbe.IsCircle Then Return False ' le manuel dit de vérifier ça avant de demander pour une Spline...
291     Return swCourbe.IsBcurve()
292     Catch
293     Dim fault As SldWorks.FaultEntity = Me.swArete.Check
294     Debug.WriteLine("N'arrive pas à déterminer si la courbe est une spline" & vbCr & "FaultEntity.Count = " & IIf(fault Is Nothing, "0", fault.Count) & vbCr & Me.nom)
295     Return False
296     End Try
297     End Function
298    
299     ''' <summary>
300     ''' Détermine si la courbe est une ellipse
301     ''' </summary>
302     ''' <returns></returns>
303     ''' <remarks>Vrai si ellipse</remarks>
304     Public Function IsEllipse() As Boolean
305     Try
306     Dim swCourbe As SldWorks.Curve = Me.swArete.GetCurve
307     If swCourbe.IsLine Then Return False
308     Return swCourbe.IsEllipse
309     Catch
310     Dim fault As SldWorks.FaultEntity = Me.swArete.Check
311     Debug.WriteLine("N'arrive pas à déterminer si la courbe est une ellipse" & vbCr & "FaultEntity.Count = " & IIf(fault Is Nothing, "0", fault.Count) & vbCr & Me.nom)
312     End Try
313    
314     End Function
315    
316    
317     ''' <summary>
318     ''' Sub pour sélectionner l'arète dans la fenètre de solidworks
319     ''' </summary>
320     ''' <param name="Append"></param>
321     ''' <remarks></remarks>
322     Public Sub sélectionner(Optional ByVal Append As Boolean = False)
323     Dim swent As SldWorks.Entity
324     swent = Me.SwArete
325     swent.Select2(Append, 0)
326     End Sub
327    
328     ''' <summary>
329     ''' Sub qui colore une arète
330     ''' </summary>
331     ''' <param name="Largeur">La largeur de la ligne</param>
332     ''' <param name="Rouge">Le ton de rouge, entre 0 et 1</param>
333     ''' <param name="Vert">Le ton de vert, entre 0 et 1</param>
334     ''' <param name="Bleu">Le ton de bleu, entre 0 et 1</param>
335     ''' <remarks></remarks>
336     Public Sub Colorer(Optional ByVal Largeur As Integer = 2, Optional ByRef Rouge As Double = 1, Optional ByRef Vert As Double = 0, Optional ByRef Bleu As Double = 0)
337 bournival 48 swArete.Display(Largeur, Rouge, Vert, Bleu, True)
338 bournival 40 End Sub
339    
340    
341     ''' <summary>
342 bournival 130 ''' Sub qui met ou Update les paramètres des doublons des arètes. Une entité avec un attribut de doublon est ignoré par MAGiC
343 bournival 40 ''' </summary>
344     ''' <param name="Numero">Le numéro que l'on veut attribuer</param>
345     ''' <param name="Maitre">Si ce,st un maitre on met true</param>
346     ''' <param name="NomMaitre">Le nom du maitre si on le connait.</param>
347     ''' <remarks>Il faut toujours effacer l'attribut du maitreé... ou s'assurer que dans MAGiC on ignore "Inconnu"... De plus, si l'attribut existe déjà, le numéro devient innutile.</remarks>
348     Public Sub MettreAttributDoublon(Optional ByRef Numero As Integer = 0, Optional ByRef Maitre As Boolean = False, Optional ByRef NomMaitre As String = Nothing)
349     Dim attr As SldWorks.Attribute
350     Dim swent As SldWorks.Entity
351     Dim nom As String
352     Dim ParamMaitre As SldWorks.Parameter
353     Dim paramSens As SldWorks.Parameter
354     Dim sens As Double = -5
355    
356     'mettre un attribut et l'updater...
357     swent = Me.SwArete
358    
359     nom = "DoublonA_" & Format(Numero, "000")
360     If Maitre Then nom &= "Maitre" Else nom &= "Esclave"
361    
362     attr = swent.FindAttribute(Intersections.DefAttrDoublon, 0)
363    
364     Do While attr Is Nothing
365     nom = "DoublonA_" & Format(Numero, "000")
366     If Maitre Then nom &= "Maitre" Else nom &= "Esclave"
367 bournival 48 attr = Intersections.DefAttrDoublon.CreateInstance5(swModel, swArete, nom, 0, 2) ' 0 = swThisconfig
368 bournival 40 If attr Is Nothing Then Numero += 1
369     Loop
370    
371     ParamMaitre = attr.GetParameter("Maitre")
372 bournival 48 paramSens = attr.GetParameter("Sens")
373 bournival 40 If NomMaitre = Nothing Then
374     NomMaitre = "Inconnu"
375    
376     Else ' il faut mettre les attribut de doublons sur les sommets.
377     Dim swSommet1 As SldWorks.Vertex
378     Dim swSommet2 As SldWorks.Vertex
379    
380     swSommet1 = Me.SwArete.GetStartVertex()
381     If swSommet1 IsNot Nothing Then
382     swSommet2 = Me.SwArete.GetEndVertex
383     Dim esom1 As New SuperSommet(swSommet1, True)
384     Dim esom2 As New SuperSommet(swSommet2, True)
385     Dim premier As Boolean = False
386     Dim second As Boolean = False
387    
388     Dim SlySommetTest As SlySommetVolume
389    
390     For Each SlySommetTest In Commun.lst_SommetVolume
391 bournival 130 If Not premier AndAlso Distance(esom1.GetSommet, SlySommetTest.swSommet) < (10000 * Epsilon) Then ' on vient de trouver le sommet du volume
392 bournival 40 esom1.MettreAttributDoublonSommet(SlySommetTest.nom, SlySommetTest.swSommet)
393     premier = True
394 bournival 130 ElseIf Distance(esom2.GetSommet, SlySommetTest.swSommet) < (10000 * Epsilon) Then
395 bournival 40 esom2.MettreAttributDoublonSommet(SlySommetTest.nom, SlySommetTest.swSommet)
396     second = True
397     End If
398     If premier AndAlso second Then Exit For
399     Next
400    
401     End If
402    
403     ' trouver si le sens est le même, mettre 1 si oui, et -1 si non.
404     ' on met 1 si les 2 startvertex sont au même endroit, -1 si ce n'est pas le cas
405    
406 bournival 130 Dim a As SuperArete = Nothing
407     Dim trouve As Boolean = False
408 bournival 40 Dim som1 As SldWorks.Vertex, som2 As SldWorks.Vertex
409     For Each a In Commun.lst_AreteVolume
410 bournival 130 If a.nom = NomMaitre Then trouve = True : Exit For
411 bournival 40 Next
412 bournival 130
413     If Not trouve Then
414     For Each a In Commun.lst_AreteCoque
415     If a.nom = NomMaitre Then Exit For
416     Next
417     End If
418    
419    
420     som1 = Me.swArete.GetStartVertex
421 bournival 40 If som1 IsNot Nothing Then
422     som2 = a.swArete.GetStartVertex
423 bournival 130 If som2 Is Nothing Then a.Colorer(4, 0.5, 0, 0.5) : Me.Colorer(4, 1, 0, 1) : MsgBox(a.nom & " " & Me.nom & "Comparer = " & Me.comparer(a.swArete))
424 bournival 40 If Distance(som1, som2) < Epsilon Then sens = 1 Else sens = -1
425     Else ' wouch!, si on a une courbe fermée, comment on trouve le sens de l'arête maitre comparé à l'arète esclave.
426     ' si les 2 arètes sont une par-dessus l'autre, alors je prend le point à t=0 et le T du point équivalent sur l'arète esclave
427     ' si T+ deltaT = le même point sur l'arète esclave alors Bingo, même sens
428    
429     ' a est la Slyarete du maitre, Me est l'arète esclave
430     Dim x, y, z, T2, T3 As Double
431     Dim ret As Boolean = Me.Evaluer(0, x, y, z)
432     T2 = a.GetT(x, y, z)
433     Me.Evaluer(0.1, x, y, z)
434     T3 = a.GetT(x, y, z)
435     If T3 = (T2 + 0.1) Then sens = 1 Else sens = -1
436     End If
437    
438     End If
439    
440     paramSens.SetDoubleValue2(sens, 2, "")
441     ParamMaitre.SetStringValue2(NomMaitre, 2, "") ' swAllConfiguration = 2
442 bournival 130 'GererDossiers("Doublons", nom)
443 bournival 40
444 bournival 130 ' Me.Colorer(2, 1, 1, 0)
445 bournival 40
446     End Sub
447    
448    
449     ''' <summary>
450     ''' sub qui efface l'attribut du doublon sur l'arète maitre.
451     ''' </summary>
452     ''' <remarks></remarks>
453     Public Sub EffacerAttributDoublon()
454     Dim attr As SldWorks.Attribute
455     Dim swent As SldWorks.Entity
456     swent = Me.SwArete
457     attr = swent.FindAttribute(Intersections.DefAttrDoublon, 0)
458     attr.Delete(True)
459     End Sub
460    
461     ''' <summary>
462     ''' Function qui retourne le nom qui est sur une arète
463     ''' </summary>
464     ''' <returns></returns>
465     ''' <remarks></remarks>
466     Public Function getNom() As String
467     Dim swEnt As SldWorks.Entity
468     swEnt = swArete
469     getNom = swPart.GetEntityName(swEnt)
470     End Function
471    
472    
473     ''' <summary>
474     ''' Calcule et retourne le T au milieu de l'arète
475     ''' </summary>
476 bournival 130 ''' <param name="Reverse">Si oui, alors oon retourne le milieu de la courbe inversée. Le «milieu» n'est pas le même si on a une spline...</param>
477 bournival 40 ''' <returns>Le T du milieu</returns>
478     ''' <remarks></remarks>
479 bournival 130 Public Function GetTMilieu(Optional ByVal Reverse As Boolean = False) As Double
480     Dim swCourbe As sldworks.Curve
481 bournival 40 Dim temp As Object
482     Dim T1 As Double, T2 As Double
483 bournival 130 Dim sommet As sldworks.Vertex
484 bournival 40 Dim point As Object
485    
486    
487 bournival 130 swCourbe = Me.swArete.GetCurve
488     If Reverse Then swCourbe = swCourbe.ReverseCurve()
489 bournival 40
490 bournival 130 sommet = Me.swArete.GetStartVertex()
491    
492 bournival 40 If sommet IsNot Nothing Then
493 bournival 48 point = sommet.GetPoint() : temp = swArete.GetParameter(point(0), point(1), point(2)) : T1 = temp(0)
494     sommet = swArete.GetEndVertex() : point = sommet.GetPoint() : temp = swArete.GetParameter(point(0), point(1), point(2)) : T2 = temp(0)
495 bournival 40 Return (T1 + T2) / 2
496    
497     Else
498     'l'arète est fermée.
499     Return 0.5 ' c'est un cercle... tous les points sont au milieu!
500     MsgBox("On demande la longueur d'une courbe fermée qui n'est pas un cercle... ce n'est pas encore programmé car ça ne devrait pas arriver.")
501     End If
502    
503     End Function
504    
505    
506     ''' <summary>
507     ''' Calcule et retourne la valeur de T à un certain endroit
508     ''' </summary>
509     ''' <param name="x"></param>
510     ''' <param name="y"></param>
511     ''' <param name="z"></param>
512     ''' <returns></returns>
513     ''' <remarks></remarks>
514     Public Function GetT(ByRef x As Double, ByRef y As Double, ByRef z As Double) As Double
515     Dim retval As Object
516     Dim retour(1) As Double
517     retval = Me.SwArete.GetParameter(x, y, z)
518     retour = retval
519 bournival 130 If Not retour(1) Then
520     Me.Colorer(2, 1, 0.5, 0) ' : Commun.MettreUnPoint(x, y, z)
521     Dim ret As Object = Me.swArete.GetClosestPointOn(x, y, z)
522    
523     Dim obj As Object = Me.swArete.GetClosestPointOn(x, y, z)
524     Dim ob() As Double = obj
525     retval = Me.swArete.GetParameter(ob(0), ob(1), ob(2))
526    
527     End If
528 bournival 40 Return retour(0)
529     End Function
530    
531     ''' <summary>
532     ''' Fonction qui retourne le Tmin de l'arète
533     ''' </summary>
534     ''' <returns>Tmax</returns>
535     ''' <remarks></remarks>
536     Public Function GetTMin() As Double
537     Dim vp As Object
538 bournival 48 swArete.GetCurve()
539     vp = swArete.GetCurveParams2()
540 bournival 40 Return vp(6)
541     End Function
542    
543    
544     ''' <summary>
545     ''' Fonction qui retourne le Tmax de l'arète
546     ''' </summary>
547     ''' <returns>Tmax</returns>
548     ''' <remarks></remarks>
549     Public Function GetTMax() As Double
550     Dim vp As Object
551 bournival 48 swArete.GetCurve()
552     vp = swArete.GetCurveParams2()
553 bournival 40 Return vp(7)
554     End Function
555    
556    
557     ''' <summary>
558     ''' Détermine si la valeur de T est sur la courbe, si oui ça retourne les coordonnées XYZ
559     ''' </summary>
560     ''' <param name="T"></param>
561     ''' <param name="xyz"></param>
562     ''' <returns></returns>
563     ''' <remarks></remarks>
564     Public Function Evaluer(ByRef T As Double, Optional ByRef xyz() As Double = Nothing) As Boolean
565    
566     Dim temp(2) As Double
567     Dim retval As Object
568     Dim retour() As Double
569     Dim T1 As Double
570     Dim T2 As Double
571    
572     retval = Me.SwArete.GetCurveParams2()
573     retour = retval
574     T1 = retour(6)
575     T2 = retour(7)
576    
577     If Not ((T >= T1) And (T <= T2)) Then Return False
578    
579     retval = Me.SwArete.Evaluate(T)
580    
581     temp(0) = retval(0)
582     temp(1) = retval(1)
583     temp(2) = retval(2)
584    
585     xyz = temp
586    
587     Return True
588    
589     End Function
590    
591    
592     ''' <summary>
593     ''' Détermine si la valeur de T est sur la courbe, si oui ça retourne les coordonnées XYZ
594     ''' </summary>
595     ''' <param name="T"></param>
596     ''' <param name="x"></param>
597     ''' <param name="y"></param>
598     ''' <param name="z"></param>
599     ''' <returns></returns>
600     ''' <remarks></remarks>
601     Public Function Evaluer(ByRef T As Double, ByRef x As Double, ByRef y As Double, ByRef z As Double) As Boolean
602     'si XYZ est omis alors on veut juste savoir si le paramètre est sur la courbe
603    
604     Dim temp(2) As Double
605     Dim retval As Object
606     Dim retour() As Double
607     Dim T1 As Double
608     Dim T2 As Double
609    
610     retval = Me.SwArete.GetCurveParams2()
611     retour = retval
612     T1 = retour(6)
613     T2 = retour(7)
614    
615     If Not ((T >= T1) And (T <= T2)) Then Return False
616    
617     retval = Me.SwArete.Evaluate(T)
618    
619     x = retval(0)
620     y = retval(1)
621     z = retval(2)
622    
623     Return True
624     End Function
625    
626     ''' <summary>
627     ''' Fonction qui compare la superarete avec une autre arète de solidworks
628     ''' </summary>
629     ''' <param name="swArete"></param>
630     ''' <returns></returns>
631     ''' <remarks></remarks>
632     Public Function comparer(ByRef swArete As SldWorks.Edge) As Boolean
633     Dim e As New SuperArete(swArete, True)
634     Return comparer(e)
635     End Function
636    
637    
638    
639    
640     ''' <summary>
641     ''' Fonction qui compare 2 superaretes. Retourne vrai si les 2 arêtes sont identiques
642     ''' </summary>
643     ''' <param name="sAreteTest">L'arète avec laquelle comparer</param>
644     ''' <returns>Vrais si les 2 arêtes peuvent être fusionnées. Faux sinon</returns>
645     ''' <remarks></remarks>
646     Public Function Comparer(ByRef sAreteTest As SuperArete) As Boolean
647     'on a 2 arètes, et on ne peut comparer directement les pointeurs...
648    
649     If swArete Is sAreteTest Then Return True
650    
651    
652    
653     ' 2 - les 2 points d'extrémités sont identiques.
654     Dim debut1() As Double = Me.GetStartPoint
655     Dim debut2() As Double = sAreteTest.GetStartPoint
656     Dim fin1() As Double = Me.GetEndPoint
657     Dim fin2() As Double = sAreteTest.GetEndPoint
658    
659     If debut1 Is Nothing Xor debut2 Is Nothing Then Return False
660     If debut1 Is Nothing And debut2 Is Nothing Then ' peut-être un cercle
661     If Not swModel.ClosestDistance(sAreteTest.swArete, Me.swArete, Nothing, Nothing) < Epsilon Then Return False
662     ' bon, on a 2 cercles (ou courbe fermées) qui se touchent à au moins un point...
663 bournival 130 Dim courbe1 As sldworks.Curve = Me.swArete.GetCurve
664     Dim courbe2 As sldworks.Curve = sAreteTest.swCourbe
665 bournival 40
666 bournival 130 If Me.IsCircle AndAlso sAreteTest.IsCircle Then
667 bournival 40 Dim vparam1 As Object = courbe1.CircleParams()
668     Dim vparam2 As Object = courbe2.CircleParams()
669 bournival 130 If Math.Abs(vparam1(0) - vparam2(0)) < 1000 * Epsilon AndAlso Math.Abs(vparam1(1) - vparam2(1)) < 1000 * Epsilon AndAlso Math.Abs(vparam1(2) - vparam2(2)) < 1000 * Epsilon AndAlso Math.Abs(vparam1(6) - vparam2(6)) < 1000 * Epsilon Then
670     Dim tmilieuC As Double = Me.GetTMilieu
671     Dim xyzC() As Double = Nothing
672     If Not Me.Evaluer(tmilieuC, xyzC) Then MsgBox("Marche pas ici...") ' alors prendre ce qu'il y a en commentaire plus haut....
673     Dim vPointC As Object = sAreteTest.swArete.GetClosestPointOn(xyzC(0), xyzC(1), xyzC(2))
674     If Distance(xyzC(0), xyzC(1), xyzC(2), vPointC(0), vPointC(1), vPointC(2)) < 0.000001 Then Return True Else Return False
675     Else
676     Return False
677     End If
678    
679     ElseIf Me.IsEllipse AndAlso sAreteTest.IsEllipse Then
680 bournival 40 Dim vparam1 As Object = courbe1.GetEllipseParams()
681     Dim vparam2 As Object = courbe2.GetEllipseParams()
682     For i As Integer = 0 To 10
683 bournival 130 If Math.Abs(vparam1(i) - vparam2(i)) > 1000 * Epsilon Then Return False
684 bournival 40 Next
685     Return True
686 bournival 130 Else ' peut-être des splines fermées...
687     ' on fait un test sur ... ? 20 points ? ... sur une des 2 courbes, et si le point appartient à l'autre courbe aussi on retourne true
688     ' la courbe Originale est me.swArete
689     Dim g As Integer = 0
690     Dim pointTest(2) As Double
691     Dim Tmin As Double = Me.GetTMin
692     Dim Tmax As Double = Me.GetTMax
693     Dim incrT As Double = (Tmax - Tmin) / 20
694    
695    
696     While g < 20
697     Me.Evaluer(Tmin + g * incrT, pointTest)
698     If Commun.Distance(sAreteTest.swArete, pointTest) > 0.000001 Then Return False ' merde, je déteste cette façon de procéder!
699     g += 1
700     End While
701    
702    
703     Return True
704 bournival 40 End If
705 bournival 130 End If
706 bournival 40
707 bournival 130 If Distance(debut1, debut2) > 1000 * Epsilon AndAlso Distance(debut1, fin2) > 1000 * Epsilon Then Return False
708     If Distance(fin1, debut2) > 1000 * Epsilon AndAlso Distance(fin1, fin2) > 1000 * Epsilon Then Return False
709 bournival 40
710 bournival 130 ' update, le point milieu ne marche pas toujours.., mais si on a une ligne, innutile de tester plus loin
711     If Me.IsLine And sAreteTest.IsLine Then Return True
712 bournival 40
713 bournival 130
714    
715     'Dim D1() As Double = Me.GetTangenceDepart()
716     'Dim A1() As Double = Me.GetTangenceArivee()
717    
718     'Dim D2() As Double = sAreteTest.GetTangenceDepart
719     'Dim A2() As Double = sAreteTest.GetTangenceArivee
720    
721    
722     'If Distance(debut1, debut2) < 1000 * Epsilon Then ' courbes dans même sens
723    
724     ' If Outils_Math.ComparerVecteurs3D(D1, D2) AndAlso Outils_Math.ComparerVecteurs3D(A1, A2) Then Return True Else Return False
725     'Else ' courbes dans sens différent
726     ' Dim P1(2) As Double
727     ' Dim P2(2) As Double
728     ' If Outils_Math.ComparerVecteurs3D(D1, A2) = 1 AndAlso Outils_Math.ComparerVecteurs3D(A1, D2) = 1 Then Return True Else Return False
729     'End If
730    
731    
732     ' une autre stratégie
733     Dim tmilieu As Double = Me.GetTMilieu
734     Dim xyz() As Double = Nothing
735     If Not Me.Evaluer(tmilieu, xyz) Then MsgBox("Marche pas ici...") ' alors prendre ce qu'il y a en commentaire plus haut....
736     Dim vPoint As Object = sAreteTest.swArete.GetClosestPointOn(xyz(0), xyz(1), xyz(2))
737     If Distance(xyz(0), xyz(1), xyz(2), vPoint(0), vPoint(1), vPoint(2)) < 0.000001 Then Return True Else Return False
738    
739    
740    
741 bournival 40 End Function
742    
743 bournival 130
744 bournival 40 ''' <summary>
745 bournival 130 ''' DOnne la longueur d'une arète
746 bournival 40 ''' </summary>
747 bournival 130 ''' <value></value>
748     ''' <returns>La longueur de l'arète</returns>
749 bournival 40 ''' <remarks></remarks>
750 bournival 130 Public ReadOnly Property Longueur() As Double
751     Get
752     Dim temp As Object
753     Dim T1 As Double, T2 As Double
754     Dim sommet As sldworks.Vertex
755     Dim point As Object
756 bournival 40
757 bournival 130 sommet = swArete.GetStartVertex()
758 bournival 40
759 bournival 130 If sommet IsNot Nothing Then
760     point = sommet.GetPoint() : temp = swArete.GetParameter(point(0), point(1), point(2)) : T1 = temp(0)
761     sommet = swArete.GetEndVertex() : point = sommet.GetPoint() : temp = swArete.GetParameter(point(0), point(1), point(2)) : T2 = temp(0)
762     Return swCourbe.GetLength2(T1, T2)
763 bournival 40
764 bournival 130 Else
765     'l'arète est fermée.
766     Dim params() As Double
767     If swCourbe.IsCircle Then
768     params = swCourbe.CircleParams
769     Return params(6) * Pi * 2
770     End If
771     MsgBox("On demande la longueur d'une courbe fermée qui n'est pas un cercle... ce n'est pas encore programmé car ça ne devrait pas arriver." & vbCr & " On pourrait prendre la tessellation, mais là on aurait une approximation!")
772 bournival 40 End If
773 bournival 130 End Get
774     End Property
775 bournival 40
776     ''' <summary>
777 bournival 130 ''' Si la courbe est un cercle, retourne le rayon.
778     ''' </summary>
779     ''' <value></value>
780     ''' <returns></returns>
781     ''' <remarks></remarks>
782     Public ReadOnly Property Rayon() As Double
783     Get
784     'MsgBox("Mettre du code ici")
785     Dim swCurve As sldworks.Curve = Me.swArete.GetCurve
786    
787    
788     If Me.IsCircle Then
789     Dim obj As Object = swCurve.CircleParams()
790     Return obj(6)
791     Else : Return (Nothing)
792     End If
793    
794     End Get
795     End Property
796    
797    
798     ''' <summary>
799 bournival 40 ''' Renvoie les coordonnées du point de départ
800     ''' </summary>
801     ''' <returns></returns>
802     ''' <remarks></remarks>
803     Public Function GetStartPoint() As Double()
804 bournival 130 Dim swSommet As sldworks.Vertex
805 bournival 40 Dim retval As Object
806     Dim xyz(2) As Double
807 bournival 130 swSommet = Me.swArete.GetStartVertex()
808 bournival 40 If swSommet Is Nothing Then Return Nothing
809     retval = swSommet.GetPoint()
810     xyz = retval
811     Return xyz
812     End Function
813    
814     ''' <summary>
815     ''' Renvoie les coordonnées du point de départ
816     ''' </summary>
817     ''' <returns>Faux si le sommet n'esiste pas</returns>
818     ''' <remarks></remarks>
819     Public Function GetStartPoint(ByRef x As Double, ByRef y As Double, ByRef z As Double) As Boolean
820 bournival 130 Dim swSommet As sldworks.Vertex
821 bournival 40 Dim retval As Object
822     Dim xyz(2) As Double
823 bournival 130 swSommet = Me.swArete.GetStartVertex()
824 bournival 40 If swSommet Is Nothing Then Return False
825     retval = swSommet.GetPoint()
826     x = retval(0)
827     y = retval(1)
828     z = retval(2)
829     Return True
830     End Function
831    
832     Public Function GetEndPoint() As Double()
833 bournival 130 Dim swSommet As sldworks.Vertex
834 bournival 40 Dim retval As Object
835     Dim xyz(2) As Double
836 bournival 130 swSommet = Me.swArete.GetEndVertex()
837 bournival 40 If swSommet Is Nothing Then Return Nothing
838     retval = swSommet.GetPoint()
839     xyz = retval
840     Return xyz
841     End Function
842    
843     ''' <summary>
844     ''' Renvoie les coordonnées du point de fin
845     ''' </summary>
846     ''' <returns>Faux si le sommet n'esiste pas</returns>
847     ''' <remarks></remarks>
848     Public Function GetEndPoint(ByRef x As Double, ByRef y As Double, ByRef z As Double) As Boolean
849 bournival 130 Dim swSommet As sldworks.Vertex
850 bournival 40 Dim retval As Object
851     Dim xyz(2) As Double
852 bournival 130 swSommet = Me.swArete.GetEndVertex()
853 bournival 40 If swSommet Is Nothing Then Return False
854     retval = swSommet.GetPoint()
855     x = retval(0)
856     y = retval(1)
857     z = retval(2)
858     Return True
859     End Function
860    
861    
862    
863    
864 bournival 130 ''' <summary>
865     ''' Retourne un tableau de 3 doubles représentant le vecteur de tangence au point de départ de la courbe
866     ''' </summary>
867     ''' <returns>La tangence de la courbe</returns>
868     ''' <remarks></remarks>
869     Public Function GetTangenceDepart() As Double()
870     Dim s1 As sldworks.Vertex = Me.SommetDebut
871     Dim es1 As New SuperSommet(s1, True)
872     Dim T As Double = Me.GetTMin
873 bournival 40
874 bournival 130 Dim tan(2) As Double
875     Me.Evaluer(T + 100 * Epsilon, tan)
876     tan(0) = es1.X - tan(0)
877     tan(1) = es1.Y - tan(1)
878     tan(2) = es1.Z - tan(2)
879 bournival 40
880 bournival 130 Return Outils_Math.unitaire(tan)
881 bournival 40
882 bournival 130 'Dim swCourbe As sldworks.Curve = Me.swArete.GetCurve
883     'Dim vTangent As Object = swCourbe.Evaluate(Me.GetTMin)
884     ''[ PointX, PointY, PointZ, TangentX, TangentY, TangentZ, Success ]
885     'Dim dTangent(2) As Double
886     'dTangent(0) = vTangent(3) : dTangent(1) = vTangent(4) : dTangent(2) = vTangent(5)
887     'Return dTangent
888     End Function
889 bournival 40
890 bournival 130 ''' <summary>
891     ''' Retourne un tableau de 3 doubles représentant le vecteur de tangence au point de fin de la courbe
892     ''' </summary>
893     ''' <returns>La tangence de la courbe</returns>
894     ''' <remarks></remarks>
895     Public Function GetTangenceArivee() As Double()
896     Dim s1 As sldworks.Vertex = Me.SommetFinal
897     Dim es1 As New SuperSommet(s1, True)
898     Dim T As Double = Me.GetTMax
899 bournival 40
900 bournival 130 Dim tan(2) As Double
901     Me.Evaluer(T - 100 * Epsilon, tan)
902     tan(0) = es1.X - tan(0)
903     tan(1) = es1.Y - tan(1)
904     tan(2) = es1.Z - tan(2)
905 bournival 40
906 bournival 130 Return Outils_Math.unitaire(tan)
907 bournival 40
908 bournival 130 End Function
909 bournival 40
910 bournival 130 ''' <summary>
911     ''' Retourne un tableau de 3 doubles représentant le vecteur de tangence au point de fin de la courbe
912     ''' </summary>
913     ''' <param name="T">La valuer de T à laquelle on cherche la tangence</param>
914     ''' <returns>La tangence de la courbe</returns>
915     ''' <remarks></remarks>
916     Public Function GetTangence(ByVal T As Double) As Double()
917     Dim s1 As sldworks.Vertex = Me.SommetFinal
918     Dim es1 As New SuperSommet(s1, True)
919 bournival 40
920 bournival 130 Dim tan(2) As Double
921     Me.Evaluer(T, tan)
922     tan(0) = es1.X - tan(0)
923     tan(1) = es1.Y - tan(1)
924     tan(2) = es1.Z - tan(2)
925    
926     Return Outils_Math.unitaire(tan)
927    
928     End Function
929    
930    
931     ''' <summary>
932     ''' Retourne le premier sommet de la courbe
933     ''' </summary>
934     ''' <value></value>
935     ''' <returns></returns>
936     ''' <remarks></remarks>
937     Public ReadOnly Property SommetDebut() As sldworks.Vertex
938     Get
939     Return Me.swArete.GetStartVertex
940     End Get
941     End Property
942    
943     ''' <summary>
944     ''' Retourne le dernier sommet de la courbe
945     ''' </summary>
946     ''' <value></value>
947     ''' <returns></returns>
948     ''' <remarks></remarks>
949     Public ReadOnly Property SommetFinal() As sldworks.Vertex
950     Get
951     Return Me.swArete.GetEndVertex
952     End Get
953     End Property
954    
955    
956     ''' <summary>
957     ''' Sub utilisée pour le débuggage qui met 100 points sur la courbe
958     ''' </summary>
959     ''' <remarks>POur évaluer la tolérance</remarks>
960     Public Sub RemplirDePoints()
961     Dim T As Double, Tmin As Double, Tmax As Double, Tinc As Double
962     Dim P(2) As Double
963     swModel.Insert3DSketch2(False)
964    
965     Tmin = Me.GetTMin
966     Tmax = Me.GetTMax
967     Tinc = (Tmax - Tmin) / 100
968     T = Tmin
969    
970     For i As Integer = 0 To 100
971     T += Tinc
972     Me.Evaluer(T, P)
973     swModel.CreatePoint2(P(0), P(1), P(2))
974     Next i
975    
976     swModel.Insert3DSketch2(False)
977     End Sub
978    
979    
980     ''' <summary>
981     ''' Sélectionne l'arète, mais s'assure de ne pas la désélectionner si elle est déjà sélectionnée
982     ''' </summary>
983     ''' <remarks>Pas très rapide...</remarks>
984     Public Sub SelectionnerSafe()
985     Dim swEnt As sldworks.Entity = Me.swArete
986     Dim selMgr As sldworks.SelectionMgr = swModel.SelectionManager
987    
988     For i As Integer = 1 To selMgr.GetSelectedObjectCount2(-1)
989     If selMgr.GetSelectedObject6(i, -1) Is swEnt Then
990     Exit Sub
991     End If
992     Next
993    
994     swEnt.Select4(True, Nothing)
995     End Sub
996    
997    
998     Public Sub PasserLes2FacesAdjascentes(ByRef swFace1 As sldworks.Face2, ByRef swFace2 As sldworks.Face2)
999     Dim obj As Object = Me.swArete.GetTwoAdjacentFaces2()
1000     swFace1 = obj(0)
1001     swFace2 = obj(1)
1002     End Sub
1003    
1004 bournival 40 End Class