Browse Source

Modify informations for 'Axes' and 'Clous' entities

Jean-Charles BRAUN 2 months ago
parent
commit
78db1ac92c
2 changed files with 252 additions and 30 deletions
  1. 163 27
      csv2scr.py
  2. 89 3
      csv2scr_ds.py

+ 163 - 27
csv2scr.py

@@ -17,6 +17,7 @@ import tkinter.filedialog
 import tkinter.messagebox
 import os
 import csv
+import math
 
 # Définition des variables
 filetext = 'Choix du fichier CSV'
@@ -92,6 +93,20 @@ def goconvert():
         fichier_scr.write('ST ' + num_ue + '\n')
         fichier_scr.write('X\n')
 
+    def InsNumAxes(startpoint, endpoint, info):
+        x1 = float(startpoint.split(',')[0])
+        x2 = float(endpoint.split(',')[0])
+        y1 = float(startpoint.split(',')[1])
+        y2 = float(endpoint.split(',')[1])
+        z1 = float(startpoint.split(',')[2])
+        z2 = float(endpoint.split(',')[2])
+        midpoint_x = format((x1 + x2) / 2, '.3f')
+        midpoint_y = format((y1 + y2) / 2, '.3f')
+        midpoint_z = format((z1 + z2) / 2, '.3f')
+        arctan = math.atan((y2 - y1) / (x2 - x1))
+        angle = format(math.degrees(arctan), '.3f')
+        fichier_scr.write('-TEXTE ' + midpoint_x + ',' + midpoint_y + ',' + midpoint_z + ' 0.05 ' + angle + ' ' + info + '\n')
+
     # Déclaration des noms des fichiers
     filename = filebut['text']
     dirname = dirbut['text']
@@ -314,9 +329,9 @@ def goconvert():
     list_ENZ40 = []
     list_ENZ50 = []
     list_ENZ60 = []
-    s40 = []
-    s50 = []
-    s60 = []
+    list_info40 = []
+    list_info50 = []
+    list_info60 = []
     fichier_csv.seek(0)
     fichier_scr.write('-CALQUE\n')
     fichier_scr.write('CH\n')
@@ -332,63 +347,71 @@ def goconvert():
         # Axes simples
         if code == '40':
             list_ENZ40.append(coord_E + ',' + coord_N + ',' + coord_Z)
-            if info != '':
-                s40.append(info)
+            list_info40.append(info)
         if code == '41':
             list_ENZ40.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info40.append(info)
             fichier_scr.write('POLY3D ' + ' '.join(list_ENZ40) + '\n\n')
-            if info != '':
-                s40.append(info)
             # Insertion des XDATA
             if XD_set == 1:
-                info = '-'.join(s40)
+                info = list_info40[-1]
                 X_DATA('Axe', info)
             list_ENZ40 = []
-            s40 = []
+            list_info40 = []
 
         # Axes de plans
         if code == '50':
             list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
-            if info != '':
-                s50.append(info)
+            list_info50.append(info)
         if code == '51':
             list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info50.append(info)
             fichier_scr.write('-COULEUR\n')
             fichier_scr.write('rouge\n')
             fichier_scr.write('POLY3D ' + ' '.join(list_ENZ50) + '\n\n')
             fichier_scr.write('-COULEUR\n')
             fichier_scr.write('ByLayer\n')
-            if info != '':
-                s50.append(info)
             # Insertion des XDATA
             if XD_set == 1:
-                info = '-'.join(s50)
-                X_DATA('Axe_Plan', info)
+                if set(list_info50[:-1]) == {''} and list_info50[-1] != '':
+                    info = list_info50[-1]
+                    X_DATA('Axe_Plan', info)
+                else:
+                    info = ''
+                    X_DATA('Axe_Plan', info)
             list_ENZ50 = []
-            s50 = []
+            list_info50 = []
 
         # Axes de coupes
         if code == '60':
             list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
-            if info != '':
-                s60.append(info)
+            list_info60.append(info)
         if code == '61':
             list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info60.append(info)
             fichier_scr.write('-COULEUR\n')
             fichier_scr.write('30\n')
             fichier_scr.write('POLY3D ' + ' '.join(list_ENZ60) + '\n\n')
             fichier_scr.write('-COULEUR\n')
             fichier_scr.write('ByLayer\n')
-            if info != '':
-                s60.append(info)
             # Insertion des XDATA
             if XD_set == 1:
-                info = '-'.join(s60)
-                X_DATA('Axe_Coupe', info)
+                if set(list_info60[:-1]) == {''} and list_info60[-1] != '':
+                    info = list_info60[-1]
+                    X_DATA('Axe_Coupe', info)
+                else:
+                    info = ''
+                    X_DATA('Axe_Coupe', info)
             list_ENZ60 = []
-            s60 = []
+            list_info60 = []
 
     # Insertion des numéros d'axes
+    list_ENZ40 = []
+    list_ENZ50 = []
+    list_ENZ60 = []
+    list_info40 = []
+    list_info50 = []
+    list_info60 = []
     fichier_csv.seek(0)
     fichier_scr.write('-CALQUE\n')
     fichier_scr.write('CH\n')
@@ -400,10 +423,51 @@ def goconvert():
         coord_Z = row[3]
         code = row[4]
         info = row[5]
-        if info != '' and (code == '40' or code == '41'):
-            fichier_scr.write('-TEXTE ' + coord_E + ',' + coord_N + ',' + coord_Z + ' 0.1 0 ' + info + '\n')
+
+        # Numéros d'axes simples
+        if code == '40':
+            list_ENZ40.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info40.append(info)
+        if code == '41':
+            list_ENZ40.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info40.append(info)
+            if info != '':
+                for num in range(len(list_ENZ40))[:-1]:
+                    InsNumAxes(list_ENZ40[num], list_ENZ40[num + 1], list_info40[-1])
+            list_ENZ40 = []
+            list_info40 = []
+
+        # Numéros d'axes de plans
+        if code == '50':
+            list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info50.append(info)
+        if code == '51':
+            list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info50.append(info)
+            if set(list_info50[:-1]) == {''} and list_info50[-1] != '':
+                for num in range(len(list_ENZ50))[:-1]:
+                    InsNumAxes(list_ENZ50[num], list_ENZ50[num + 1], list_info50[-1])
+            list_ENZ50 = []
+            list_info50 = []
+
+        # Numéros d'axes de coupes
+        if code == '60':
+            list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info60.append(info)
+        if code == '61':
+            list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info60.append(info)
+            if set(list_info60[:-1]) == {''} and list_info60[-1] != '':
+                for num in range(len(list_ENZ60))[:-1]:
+                    InsNumAxes(list_ENZ60[num], list_ENZ60[num + 1], list_info60[-1])
+            list_ENZ60 = []
+            list_info60 = []
 
     # Insertion des clous
+    list_ENZ50 = []
+    list_ENZ60 = []
+    list_info50 = []
+    list_info60 = []
     fichier_csv.seek(0)
     fichier_scr.write('-CALQUE\n')
     fichier_scr.write('CH\n')
@@ -415,13 +479,61 @@ def goconvert():
         coord_Z = row[3]
         code = row[4]
         info = row[5]
-        if code == '11' or code == '50' or code == '51' or code == '60' or code == '61':
+        if code == '11':
             fichier_scr.write('-INSERER 11-clou.dxf ' + coord_E + ',' + coord_N + ',' + coord_Z + ' 1 1 0\n')
             # Insertion des XDATA
             if XD_set == 1:
                 X_DATA('Clou', info)
+        if code == '50':
+            list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info50.append(info)
+        if code == '51':
+            list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info50.append(info)
+            if len(set(list_info50)) == len(list_info50) and '' not in list_info50:
+                for num, coord_ENZ in enumerate(list_ENZ50):
+                    fichier_scr.write('-INSERER 11-clou.dxf ' + coord_ENZ + ' 1 1 0\n')
+                    # Insertion des XDATA
+                    if XD_set == 1:
+                        info = list_info50[num]
+                        X_DATA('Clou', info)
+            else:
+                for coord_ENZ in list_ENZ50:
+                    fichier_scr.write('-INSERER 11-clou.dxf ' + coord_ENZ + ' 1 1 0\n')
+                    # Insertion des XDATA
+                    if XD_set == 1:
+                        info = ''
+                        X_DATA('Clou', info)
+            list_ENZ50 = []
+            list_info50 = []
+        if code == '60':
+            list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info60.append(info)
+        if code == '61':
+            list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info60.append(info)
+            if len(set(list_info60)) == len(list_info60) and '' not in list_info60:
+                for num, coord_ENZ in enumerate(list_ENZ60):
+                    fichier_scr.write('-INSERER 11-clou.dxf ' + coord_ENZ + ' 1 1 0\n')
+                    # Insertion des XDATA
+                    if XD_set == 1:
+                        info = list_info60[num]
+                        X_DATA('Clou', info)
+            else:
+                for coord_ENZ in list_ENZ60:
+                    fichier_scr.write('-INSERER 11-clou.dxf ' + coord_ENZ + ' 1 1 0\n')
+                    # Insertion des XDATA
+                    if XD_set == 1:
+                        info = ''
+                        X_DATA('Clou', info)
+            list_ENZ60 = []
+            list_info60 = []
 
     # Insertion des numéros de clous
+    list_ENZ50 = []
+    list_ENZ60 = []
+    list_info50 = []
+    list_info60 = []
     fichier_csv.seek(0)
     fichier_scr.write('-CALQUE\n')
     fichier_scr.write('CH\n')
@@ -433,8 +545,32 @@ def goconvert():
         coord_Z = row[3]
         code = row[4]
         info = row[5]
-        if info != '' and (code == '11' or code == '50' or code == '51' or code == '60' or code == '61'):
+        if code == '11' and info != '':
             fichier_scr.write('-TEXTE ' + coord_E + ',' + coord_N + ',' + coord_Z + ' 0.1 0 ' + info + '\n')
+        if code == '50':
+            list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info50.append(info)
+        if code == '51':
+            list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info50.append(info)
+            if len(set(list_info50)) == len(list_info50) and '' not in list_info50:
+                for num, coord_ENZ in enumerate(list_ENZ50):
+                    info = list_info50[num]
+                    fichier_scr.write('-TEXTE ' + coord_ENZ + ' 0.1 0 ' + info + '\n')
+            list_ENZ50 = []
+            list_info50 = []
+        if code == '60':
+            list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info60.append(info)
+        if code == '61':
+            list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+            list_info60.append(info)
+            if len(set(list_info60)) == len(list_info60) and '' not in list_info60:
+                for num, coord_ENZ in enumerate(list_ENZ60):
+                    info = list_info60[num]
+                    fichier_scr.write('-TEXTE ' + coord_ENZ + ' 0.1 0 ' + info + '\n')
+            list_ENZ60 = []
+            list_info60 = []
 
     # Insertion des clous de redressement
     fichier_csv.seek(0)

+ 89 - 3
csv2scr_ds.py

@@ -16,6 +16,7 @@ import tkinter.constants
 import tkinter.filedialog
 import os
 import csv
+import math
 
 # Définition des variables
 filetext = 'Choix du fichier CSV'
@@ -41,6 +42,20 @@ def openDirectory():
     board.update()
     board.create_image(board.winfo_width() / 2, board.winfo_height() / 2, anchor=CENTER, image=logo)
 
+def InsNumAxes(startpoint, endpoint, info):
+    x1 = float(startpoint.split(',')[0])
+    x2 = float(endpoint.split(',')[0])
+    y1 = float(startpoint.split(',')[1])
+    y2 = float(endpoint.split(',')[1])
+    z1 = float(startpoint.split(',')[2])
+    z2 = float(endpoint.split(',')[2])
+    midpoint_x = format((x1 + x2) / 2, '.3f')
+    midpoint_y = format((y1 + y2) / 2, '.3f')
+    midpoint_z = format((z1 + z2) / 2, '.3f')
+    arctan = math.atan((y2 - y1) / (x2 - x1))
+    angle = format(math.degrees(arctan), '.3f')
+    fichier_scr.write('-NOTESIMPLE ' + midpoint_x + ',' + midpoint_y + ',' + midpoint_z + ' 0.05 ' + angle + ' ' + info + '\n')
+
 # Construction de la fenêtre principale
 root = Tk()
 root.title('csv2scr_ds.py')
@@ -322,6 +337,12 @@ for row in reader:
         list_ENZ60 = []
 
 # Insertion des numéros d'axes
+list_ENZ40 = []
+list_ENZ50 = []
+list_ENZ60 = []
+list_info40 = []
+list_info50 = []
+list_info60 = []
 fichier_csv.seek(0)
 fichier_scr.write('-CALQUE\n')
 fichier_scr.write('ET\n')
@@ -333,8 +354,45 @@ for row in reader:
     coord_Z = row[3]
     code = row[4]
     info = row[5]
-    if info != '' and (code == '40' or code == '41'):
-        fichier_scr.write('-NOTESIMPLE ' + coord_E + ',' + coord_N + ',' + coord_Z + ' 0.1 0 ' + info + '\n')
+
+    # Numéros d'axes simples
+    if code == '40':
+        list_ENZ40.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info40.append(info)
+    if code == '41':
+        list_ENZ40.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info40.append(info)
+        if info != '':
+            for num in range(len(list_ENZ40))[:-1]:
+                InsNumAxes(list_ENZ40[num], list_ENZ40[num + 1], list_info40[-1])
+        list_ENZ40 = []
+        list_info40 = []
+
+    # Numéros d'axes de plans
+    if code == '50':
+        list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info50.append(info)
+    if code == '51':
+        list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info50.append(info)
+        if set(list_info50[:-1]) == {''} and list_info50[-1] != '':
+            for num in range(len(list_ENZ50))[:-1]:
+                InsNumAxes(list_ENZ50[num], list_ENZ50[num + 1], list_info50[-1])
+        list_ENZ50 = []
+        list_info50 = []
+
+    # Numéros d'axes de coupes
+    if code == '60':
+        list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info60.append(info)
+    if code == '61':
+        list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info60.append(info)
+        if set(list_info60[:-1]) == {''} and list_info60[-1] != '':
+            for num in range(len(list_ENZ60))[:-1]:
+                InsNumAxes(list_ENZ60[num], list_ENZ60[num + 1], list_info60[-1])
+        list_ENZ60 = []
+        list_info60 = []
 
 # Insertion des clous
 fichier_csv.seek(0)
@@ -352,6 +410,10 @@ for row in reader:
         fichier_scr.write('-INSERBLOC 11-clou.dxf ' + coord_E + ',' + coord_N + ',' + coord_Z + ' 1 1 0\n')
 
 # Insertion des numéros de clous
+list_ENZ50 = []
+list_ENZ60 = []
+list_info50 = []
+list_info60 = []
 fichier_csv.seek(0)
 fichier_scr.write('-CALQUE\n')
 fichier_scr.write('ET\n')
@@ -363,8 +425,32 @@ for row in reader:
     coord_Z = row[3]
     code = row[4]
     info = row[5]
-    if info != '' and (code == '11' or code == '50' or code == '51' or code == '60' or code == '61'):
+    if code == '11' and info != '':
         fichier_scr.write('-NOTESIMPLE ' + coord_E + ',' + coord_N + ',' + coord_Z + ' 0.1 0 ' + info + '\n')
+    if code == '50':
+        list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info50.append(info)
+    if code == '51':
+        list_ENZ50.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info50.append(info)
+        if len(set(list_info50)) == len(list_info50) and '' not in list_info50:
+            for num, coord_ENZ in enumerate(list_ENZ50):
+                info = list_info50[num]
+                fichier_scr.write('-NOTESIMPLE ' + coord_ENZ + ' 0.1 0 ' + info + '\n')
+        list_ENZ50 = []
+        list_info50 = []
+    if code == '60':
+        list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info60.append(info)
+    if code == '61':
+        list_ENZ60.append(coord_E + ',' + coord_N + ',' + coord_Z)
+        list_info60.append(info)
+        if len(set(list_info60)) == len(list_info60) and '' not in list_info60:
+            for num, coord_ENZ in enumerate(list_ENZ60):
+                info = list_info60[num]
+                fichier_scr.write('-NOTESIMPLE ' + coord_ENZ + ' 0.1 0 ' + info + '\n')
+        list_ENZ60 = []
+        list_info60 = []
 
 # Insertion des clous de redressement
 fichier_csv.seek(0)