Attribute VB_Name = "Module3"

Public Function calculer_angle(ByVal X1 As Double, ByVal Y1 As Double, ByVal X2 As Double, ByVal Y2 As Double)
 
    Dim angle As Double
    Dim conversion_degre As Double
    Dim delta_x As Double
    Dim delta_y As Double
    
    Const PI = 3.14159265358979
 
    delta_x = X2 - X1
    delta_x = Y2 - Y1
   
    If (delta_x = 0) Then
      If (Y2 > Y1) Then
        angle = 90
      Else
        angle = 270
      End If
    End If
     If (delta_y = 0) Then
      If (X2 > X1) Then
        angle = 0
      Else
        angle = 180
     End If
    End If
    ' Angle entre 2 points quelconques
    conversion_degre = 180 / 3.141592
    angle = Int(Atn((Y1 - Y2) / (X1 - X2)) * conversion_degre * 1000) / 1000
  
    If ((delta_x < 0) And (delta_y > 0)) Then
    angle = 180 + angle
    End If
    
    If ((delta_x < 0) And (delta_y < 0)) Then
    angle = 180 + angle
    End If
    
    If ((delta_x > 0) And (delta_y < 0)) Then
    angle = 360 + angle
    End If
    
    calculer_angle = angle
 
 End Function
 
 Public Function calculer_distance(ByVal X1 As Double, ByVal Y1 As Double, ByVal X2 As Double, ByVal Y2 As Double)
 
 calculer_distance = Sqr((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2)
 
 End Function

Public Function traitement_bonding()

Dim i As Long
Dim pad_lien As Long
Dim broche_lien As Long
Dim chemin As String
Dim chaine As String
Dim Table(100) As String
Dim spacing As String

spacing = "   "

'chemin = "c:\import_limit.txt"
'Open chemin For Output As 1

With Form_principale
        .CmDlg.CancelError = False
        .CmDlg.DialogTitle = "Définir le nom du fichier de sauvegarde"
        .CmDlg.Filter = filtre_champ
        .CmDlg.FilterIndex = 1
        .CmDlg.ShowSave
   End With

Fichier_Nom = Form_principale.CmDlg.FileName

If Fichier_Nom = "" Then
   Exit Function
   End If

Open Fichier_Nom For Output As 1

'
Form1.Show

Form1.MSFlexGrid_Template.Cols = 5
Form1.MSFlexGrid_Template.Rows = 128 'nombre_liens
'
Form1.MSFlexGrid_Template.Col = 0
Form1.MSFlexGrid_Template.Row = 0
Form1.MSFlexGrid_Template.ColAlignment(0) = flexAlignCenterTop
Form1.MSFlexGrid_Template.ColWidth(0) = 500
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 = "BROCHE"
'
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 = "Angle en degrés"

Form1.MSFlexGrid_Template.Col = 3
Form1.MSFlexGrid_Template.Row = 0
Form1.MSFlexGrid_Template.ColAlignment(3) = flexAlignCenterTop
Form1.MSFlexGrid_Template.ColWidth(3) = 3000
Form1.MSFlexGrid_Template.Text = "Distance"

    If (NB_LIEN <> 0) Then
        For i = 0 To 125
            flag_retour = Objet_PAD(i).GetPosition_PAD()
            Ax = Pos_X
            Ay = Pos_Y
            flag_retour = Objet_BROCHE(i).GetPosition_BROCHE()
            Bx = Pos_X
            By = Pos_Y
            '
            angle = calculer_angle(Ax, Ay, Bx, By)
            '
            distance = calculer_distance(Ax, Ay, Bx, By)
            ' sauvegarde = écriture dans un fichier
            Table(0) = i + 1
            Table(1) = pad_lien
            Table(2) = broche_lien
            Table(3) = Ax
            Table(4) = Ay
            Table(5) = Bx
            Table(6) = By
            Table(7) = angle
            Table(8) = distance
            chaine = Table(0) & spacing & Table(1) & spacing & Table(2) & spacing & Table(3) & spacing & Table(4) & spacing & Table(5) & spacing & Table(6) & spacing & Table(7) & spacing & Table(8)
            'resultat = Join(Table, " ")
            Print #1, chaine
        
            Form1.MSFlexGrid_Template.Col = 0
            Form1.MSFlexGrid_Template.Row = i + 1
            Form1.MSFlexGrid_Template.Text = Table(1)
        
            Form1.MSFlexGrid_Template.Col = 1
            Form1.MSFlexGrid_Template.Row = i + 1
            Form1.MSFlexGrid_Template.Text = Table(2)
        
            Form1.MSFlexGrid_Template.Col = 2
            Form1.MSFlexGrid_Template.Row = i + 1
            Form1.MSFlexGrid_Template.Text = Table(7)
        
            Form1.MSFlexGrid_Template.Col = 3
            Form1.MSFlexGrid_Template.Row = i + 1
            Form1.MSFlexGrid_Template.Text = Table(8)
           
        Next i
 
    Close
 
    End If

End Function

Public Function titi(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        'Coordonnées de la cellule
'Form1.MSFlexGrid_Template.Col = 3
'Form1.MSFlexGrid_Template.CellFontBold = True    'Texte en gras
'Grid.CellForeColor = Color.Red 'Couleur du texte

'Grid.Text = Texte

'Grid.TextMatrix(2, 5) = Texte

End Function



' padring_top
' padring_left
' padring_right
' padring_bottom
'
'
'
'
'
'
