Attribute VB_Name = "Module2"
Option Explicit

Public Function extraction_champ(chaine As String, type_objet As String)
    
    Dim i As Integer
    
    'découpe la chaine en fonction des espaces " "
    'le résultat de la fonction Split est stocké dans un tableau
    Tableau = Split(chaine, " ")
    
    'boucle sur le tableau pour visualiser le résultat
    'For i = 0 To UBound(Tableau)
    'Le résultat s'affiche dans la fenêtre d'execution de l'éditeur de macros
    'Debug.Print Tableau(i)
    'Next i
    
    Num = CDbl(Tableau(0))
    Pos_X = CDbl(Tableau(1))
    Pos_Y = CDbl(Tableau(2))
    
    If (type_objet = "PAD") Then
        Type_Instance = Tableau(3)
        Orientation = LCase(Tableau(4))
    End If
    
End Function

Public Function toto(ByVal nombre_liens)

Form1.MSFlexGrid_Template.Cols = 27
Form1.MSFlexGrid_Template.Rows = nombre_liens

'
Form1.MSFlexGrid_Template.Col = 0
Form1.MSFlexGrid_Template.Row = 0
Form1.MSFlexGrid_Template.ColAlignment(0) = flexAlignCenterTop
Form1.MSFlexGrid_Template.ColWidth(0) = 1500
Form1.MSFlexGrid_Template.Text = "PAD"
'
Form1.MSFlexGrid_Template.Col = 1
Form1.MSFlexGrid_Template.Row = 0
Form1.MSFlexGrid_Template.ColAlignment(1) = flexAlignCenterTop
Form1.MSFlexGrid_Template.ColWidth(1) = 1500
Form1.MSFlexGrid_Template.Text = "X"
'
Form1.MSFlexGrid_Template.Col = 2
Form1.MSFlexGrid_Template.Row = 0
Form1.MSFlexGrid_Template.ColAlignment(2) = flexAlignCenterTop
Form1.MSFlexGrid_Template.ColWidth(2) = 1500
Form1.MSFlexGrid_Template.Text = "Y"
'
'Form1.MSFlexGrid_Template.Col = 3
'Form1.MSFlexGrid_Template.Row = 0
'Form1.MSFlexGrid_Template.Text = "Animateur"

'Les propriétés Cols et Rows permettent de définir le nombre de colonne et de ligne

'Form1.MSFlexGrid_Template.ColWidth = 150


Form1.MSFlexGrid_Template.Row = 2
Form1.MSFlexGrid_Template.Col = 4
Form1.MSFlexGrid_Template.Text = "PAD"

'Form1.MSFlexGrid_Template.CellFontBold = True    'Texte en gras
'Grid.CellForeColor = Color.Red 'Couleur du texte

'Grid.Text = Texte

Form1.MSFlexGrid_Template.TextMatrix(2, 5) = "Texte"

End Function


Public Function TrouveLien(ByVal x As Double, ByVal y As Double, ByRef PorteNum As Long, ByRef Pinnum As Long)
' trouve un lien en fonction de coordonnées

Dim PosX As Double, PosY As Double
Dim PinPos() As Double
Dim SortiePosX As Double, SortiePosY As Double

PorteNum = -1

' on prend un peu de marge, un lien etant tres fin, il est dur a cliquer
For i = 0 To NB_PAD - 1
If GatesStatus(i) = 1 Then
    tmp = Gates(i).GetPosition(, , PinPos)
    NbEntree = Gates(i).GetNbEntree()
    ' teste les entrees
   For j = 0 To NbEntree - 1
        Parent = Gates(i).GetParent(j)
        If Parent <> -1 Then
            tmp = Gates(Parent).GetPosition(, , , SortiePosX, SortiePosY)
            ' calcule l'equation affine du lien y = ax + b
            A = (PinPos(1, j) - SortiePosY) / (PinPos(0, j) - SortiePosX)
            B = SortiePosY - A * SortiePosX
            ' si le point est sur cette droite, on tient le lien
            If y < (A * x + B) + 50 And y > (A * x + B) - 50 Then
                ' si le point est bien entre les 2 pins, et non dans la prolongation
                If (((x < SortiePosX + 50) And (x > PinPos(0, j) - 50)) Or ((x < PinPos(0, j) + 50) And (x > SortiePosX - 50))) And (((y < SortiePosY + 50) And (y > PinPos(1, j) - 50)) Or ((y < PinPos(1, j) + 50) And (y > SortiePosY - 50))) Then
                    PorteNum = i
                    Pinnum = j
                End If
            End If
        End If
    Next j
End If
Next i

End Function

