ui update

This commit is contained in:
Thomas-Alexandre Moreau 2025-04-08 14:50:37 +02:00
parent 989ccb7c25
commit 8dfec0d603
2 changed files with 57 additions and 25 deletions

View file

@ -9,9 +9,11 @@ import Mesh
class WindowDialog(): class WindowDialog():
def __init__(self): def __init__(self):
self.outputRacine = self._createFolder()
self.ui_file = os.path.join(FreeCAD.getUserMacroDir(True), 'MultiExport/MultiExport.ui') self.ui_file = os.path.join(FreeCAD.getUserMacroDir(True), 'MultiExport/MultiExport.ui')
self.form = FreeCADGui.PySideUic.loadUi(self.ui_file) self.form = FreeCADGui.PySideUic.loadUi(self.ui_file)
self._connect_widgets() self._connect_widgets()
self._populate_selector_list()
self.form.show() self.form.show()
def _connect_widgets(self): def _connect_widgets(self):
@ -19,11 +21,37 @@ class WindowDialog():
self.form.pushButtonCalepinage.pressed.connect(lambda: self.exportSVG(True)) self.form.pushButtonCalepinage.pressed.connect(lambda: self.exportSVG(True))
self.form.pushButtonSTLSingle.pressed.connect(lambda: self.exportSTL(True)) self.form.pushButtonSTLSingle.pressed.connect(lambda: self.exportSTL(True))
self.form.pushButtonSTLMulti.pressed.connect(lambda: self.exportSTL(False)) self.form.pushButtonSTLMulti.pressed.connect(lambda: self.exportSTL(False))
self.form.listWidgetSelector.itemSelectionChanged.connect(self._on_selector_item_changed)
def _populate_selector_list(self):
self.form.listWidgetSelector.clear() # Clear the list first
for obj in FreeCAD.ActiveDocument.Objects:
if obj.Label.startswith("EXP-"):
self.form.listWidgetSelector.addItem(obj.Label)
def _on_selector_item_changed(self):
selected_items = self.form.listWidgetSelector.selectedItems()
selected_labels = [item.text() for item in selected_items]
FreeCADGui.Selection.clearSelection() # Clear previous selection
# Select objects in FreeCAD based on labels selected in the list
for obj in FreeCAD.ActiveDocument.Objects:
if obj.Label in selected_labels:
FreeCADGui.Selection.addSelection(obj)
def _createFolder(self):
folderPath = f"{FreeCAD.activeDocument().getFileName().rpartition('.')[0]}-Exports/"
if not os.path.exists(folderPath):
os.makedirs(folderPath)
return folderPath
# -------- MODIFICATION DE LA MACRO "exportSketchEnMasse-SVG" de Gauthier Brière -------- # # -------- MODIFICATION DE LA MACRO "exportSketchEnMasse-SVG" de Gauthier Brière -------- #
def _exportSketchBasic(self, sketchList): def _exportSketchBasic(self, sketchList):
outputRacine = App.activeDocument().getFileName().rpartition('.')[0]
for __O__ in sketchList: for __O__ in sketchList:
__obj__ = [] __obj__ = []
__obj__.append(__O__) __obj__.append(__O__)
@ -31,16 +59,15 @@ class WindowDialog():
print('Export SVG de : ' + __obj__[0].Label) print('Export SVG de : ' + __obj__[0].Label)
oldPlace = __obj__[0].Placement oldPlace = __obj__[0].Placement
__obj__[0].Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(1,0,0),0), App.Vector(0,0,0)) __obj__[0].Placement=FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(FreeCAD.Vector(1,0,0),0), FreeCAD.Vector(0,0,0))
fichierSVG = u"" + outputRacine + '--' + __obj__[0].Label + '.svg' fichierSVG = u"" + self.outputRacine + '--' + __obj__[0].Label + '.svg'
importSVG.export(__obj__, fichierSVG) importSVG.export(__obj__, fichierSVG)
__obj__[0].Placement = oldPlace __obj__[0].Placement = oldPlace
App.ActiveDocument.removeObject(__O__.Label) FreeCAD.ActiveDocument.removeObject(__O__.Label)
App.activeDocument().recompute() FreeCAD.activeDocument().recompute()
def _exportSketchCalepinage(self, sketchList, plateLength, plateWidth, spacing, laserSize): def _exportSketchCalepinage(self, sketchList, plateLength, plateWidth, spacing, laserSize):
outputRacine = App.activeDocument().getFileName().rpartition('.')[0]
copy_sketchList = sketchList[:] copy_sketchList = sketchList[:]
__obj__ = [] __obj__ = []
currentX = 0.0 currentX = 0.0
@ -61,8 +88,8 @@ class WindowDialog():
copy_sketchList.pop(index) copy_sketchList.pop(index)
listSize = len(copy_sketchList) listSize = len(copy_sketchList)
errorCount += 1 errorCount += 1
App.ActiveDocument.removeObject(__O__.Label) FreeCAD.ActiveDocument.removeObject(__O__.Label)
App.activeDocument().recompute() FreeCAD.activeDocument().recompute()
continue continue
if boundingBox.XLength + currentX > plateLength: if boundingBox.XLength + currentX > plateLength:
if boundingBox.YLength + currentY > plateWidth: if boundingBox.YLength + currentY > plateWidth:
@ -81,7 +108,7 @@ class WindowDialog():
continue continue
__obj__.insert(0, __O__) __obj__.insert(0, __O__)
maxY = boundingBox.YLength if boundingBox.YLength > maxY else maxY maxY = boundingBox.YLength if boundingBox.YLength > maxY else maxY
__obj__[0].Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(1,0,0),0), App.Vector(0,0,0)) __obj__[0].Placement=FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(FreeCAD.Vector(1,0,0),0), FreeCAD.Vector(0,0,0))
if currentX == 0.0: if currentX == 0.0:
__obj__[0].Placement.Base = FreeCAD.Vector(-boundingBox.XMin + currentX, -boundingBox.YMin + currentY, 0.0) __obj__[0].Placement.Base = FreeCAD.Vector(-boundingBox.XMin + currentX, -boundingBox.YMin + currentY, 0.0)
@ -92,7 +119,7 @@ class WindowDialog():
copy_sketchList.pop(index) copy_sketchList.pop(index)
listSize = len(copy_sketchList) listSize = len(copy_sketchList)
App.activeDocument().recompute() FreeCAD.activeDocument().recompute()
index = 0 index = 0
YBlockCounter = 0 YBlockCounter = 0
@ -101,16 +128,16 @@ class WindowDialog():
maxY = 0.0 maxY = 0.0
index = 0 index = 0
listSize = len(copy_sketchList) listSize = len(copy_sketchList)
App.activeDocument().recompute() FreeCAD.activeDocument().recompute()
if listSize <= 0 or isSVGFull: if listSize <= 0 or isSVGFull:
fichierSVG = u"" + outputRacine + '--CALEPINAGE-' + str(SVGNameCounter) + '.svg' fichierSVG = u"" + self.outputRacine + '--CALEPINAGE-' + str(SVGNameCounter) + '.svg'
print('Export SVG de : ' + u"" + str(os.path.basename(outputRacine)) + '--CALEPINAGE-' + str(SVGNameCounter) + '.svg') print('Export SVG de : ' + u"" + str(os.path.basename(self.outputRacine)) + '--CALEPINAGE-' + str(SVGNameCounter) + '.svg')
importSVG.export(__obj__, fichierSVG) importSVG.export(__obj__, fichierSVG)
for __i__ in __obj__: for __i__ in __obj__:
App.ActiveDocument.removeObject(__i__.Label) FreeCAD.ActiveDocument.removeObject(__i__.Label)
App.activeDocument().recompute() FreeCAD.activeDocument().recompute()
__obj__.clear() __obj__.clear()
maxY = 0.0 maxY = 0.0
index = 0 index = 0
@ -149,7 +176,7 @@ class WindowDialog():
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
sketchList.append(sk) sketchList.append(sk)
if hasattr(sv0, 'Name'): if hasattr(sv0, 'Name'):
App.ActiveDocument.removeObject(sv0.Name) FreeCAD.ActiveDocument.removeObject(sv0.Name)
if isCalepinage: if isCalepinage:
self._exportSketchCalepinage(sketchList, plateLength, plateWidth, spacing, laserSize) self._exportSketchCalepinage(sketchList, plateLength, plateWidth, spacing, laserSize)
@ -157,30 +184,29 @@ class WindowDialog():
self._exportSketchBasic(sketchList) self._exportSketchBasic(sketchList)
def exportSTL(self, singleMode): def exportSTL(self, singleMode):
outputRacine = App.activeDocument().getFileName().rpartition('.')[0]
__obj__ = [] __obj__ = []
for selectedObject in FreeCADGui.Selection.getSelectionEx(): for selectedObject in FreeCADGui.Selection.getSelectionEx():
__obj__.append(selectedObject.Object) __obj__.append(selectedObject.Object)
if not singleMode: if not singleMode:
filename = u"" + outputRacine + '--' + __obj__[0].Label + '.stl' filename = u"" + self.outputRacine + '--' + __obj__[0].Label + '.stl'
if hasattr(Mesh, "exportOptions"): if hasattr(Mesh, "exportOptions"):
options = Mesh.exportOptions(outputRacine) options = Mesh.exportOptions(self.outputRacine)
Mesh.export(__obj__, filename, options) Mesh.export(__obj__, filename, options)
else: else:
Mesh.export(__obj__, filename) Mesh.export(__obj__, filename)
print(f'Export STL de : {__obj__[0].Label}.stl') print(f'Export STL de : {__obj__[0].Label}.stl')
__obj__.clear() __obj__.clear()
if singleMode: if singleMode:
filename = u"" + outputRacine + '--' + __obj__[0].Label + '.stl' if len(__obj__) == 1 else u"" + outputRacine + '.stl' filename = u"" + self.outputRacine + '--' + __obj__[0].Label + '.stl' if len(__obj__) == 1 else u"" + self.outputRacine + '.stl'
if hasattr(Mesh, "exportOptions"): if hasattr(Mesh, "exportOptions"):
options = Mesh.exportOptions(outputRacine) options = Mesh.exportOptions(self.outputRacine)
Mesh.export(__obj__, filename, options) Mesh.export(__obj__, filename, options)
else: else:
Mesh.export(__obj__, filename) Mesh.export(__obj__, filename)
if len(__obj__) == 1: if len(__obj__) == 1:
print(f'Export STL de : {__obj__[0].Label}.stl') print(f'Export STL de : {__obj__[0].Label}.stl')
else: else:
print(f'Export STL de {os.path.basename(outputRacine)}.stl') print(f'Export STL de {os.path.basename(self.outputRacine)}.stl')
del __obj__ del __obj__

View file

@ -9,15 +9,21 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>300</width> <width>600</width>
<height>250</height> <height>500</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string notr="true">Multi Exporting</string> <string notr="true">Multi Exporting</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="10" column="0" colspan="3">
<widget class="QListWidget" name="listWidgetSelector">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</item>
<item row="16" column="0" colspan="3"> <item row="16" column="0" colspan="3">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">