Merge branch 'main' of ssh://git.cohabit.fr:22222/thomalex.moreau/MultiExport-FreeCAD
This commit is contained in:
commit
63e4c08990
|
|
@ -14,7 +14,7 @@ class ObjectListItem(QWidget):
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.label = QLabel(obj.Label)
|
self.label = QLabel(obj.Label)
|
||||||
self.spinbox = QSpinBox()
|
self.spinbox = QSpinBox()
|
||||||
self.spinbox.setRange(0, 9999)
|
self.spinbox.setRange(1, 9999)
|
||||||
self.spinbox.setValue(1)
|
self.spinbox.setValue(1)
|
||||||
|
|
||||||
layout = QHBoxLayout()
|
layout = QHBoxLayout()
|
||||||
|
|
@ -33,20 +33,20 @@ class WindowDialog():
|
||||||
self.outputRacine = ""
|
self.outputRacine = ""
|
||||||
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.populate_selector_list()
|
||||||
|
|
||||||
# Connect the selection change signal to keep the list in sync
|
FreeCADGui.Selection.addObserver(self.on_selection_changed)
|
||||||
FreeCADGui.Selection.addObserver(self._on_selection_changed)
|
|
||||||
|
|
||||||
self.form.show()
|
self.form.show()
|
||||||
|
|
||||||
|
|
||||||
def _connect_widgets(self):
|
def connect_widgets(self):
|
||||||
self.form.pushButtonExport.pressed.connect(self.export)
|
self.form.pushButtonExport.pressed.connect(self.export)
|
||||||
self.form.listWidgetSelector.itemClicked.connect(self._on_list_item_clicked)
|
self.form.pushButtonSave.pressed.connect(self.saveVarSet)
|
||||||
|
|
||||||
def _populate_selector_list(self):
|
|
||||||
|
def populate_selector_list(self):
|
||||||
self.form.listWidgetSelector.clear()
|
self.form.listWidgetSelector.clear()
|
||||||
FreeCADGui.Selection.clearSelection()
|
FreeCADGui.Selection.clearSelection()
|
||||||
|
|
||||||
|
|
@ -59,38 +59,25 @@ class WindowDialog():
|
||||||
self.form.listWidgetSelector.addItem(item)
|
self.form.listWidgetSelector.addItem(item)
|
||||||
self.form.listWidgetSelector.setItemWidget(item, widget)
|
self.form.listWidgetSelector.setItemWidget(item, widget)
|
||||||
|
|
||||||
# Sync selection: add the object to the selection and select the item in the list
|
|
||||||
item.setSelected(True)
|
item.setSelected(True)
|
||||||
FreeCADGui.Selection.addSelection(obj)
|
|
||||||
|
|
||||||
|
|
||||||
|
def on_selection_changed(self, doc, objects):
|
||||||
def _on_list_item_clicked(self, item):
|
|
||||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
|
||||||
obj = widget.obj
|
|
||||||
if obj in FreeCADGui.Selection.getSelection():
|
|
||||||
FreeCADGui.Selection.removeSelection(obj)
|
|
||||||
else:
|
|
||||||
FreeCADGui.Selection.addSelection(obj)
|
|
||||||
|
|
||||||
def _on_selection_changed(self, doc, objects):
|
|
||||||
# Clear current selection in the list
|
|
||||||
for index in range(self.form.listWidgetSelector.count()):
|
for index in range(self.form.listWidgetSelector.count()):
|
||||||
item = self.form.listWidgetSelector.item(index)
|
item = self.form.listWidgetSelector.item(index)
|
||||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||||
item.setSelected(False) # Deselect in the list
|
item.setSelected(False)
|
||||||
|
|
||||||
# Sync the list selection with FreeCAD's current selection
|
|
||||||
for obj in FreeCADGui.Selection.getSelection():
|
for obj in FreeCADGui.Selection.getSelection():
|
||||||
for index in range(self.form.listWidgetSelector.count()):
|
for index in range(self.form.listWidgetSelector.count()):
|
||||||
item = self.form.listWidgetSelector.item(index)
|
item = self.form.listWidgetSelector.item(index)
|
||||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||||
if widget.obj == obj:
|
if widget.obj == obj:
|
||||||
item.setSelected(True) # Select the corresponding item in the list
|
item.setSelected(True)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def _createFolder(self):
|
def createFolder(self):
|
||||||
date = datetime.today().strftime('%Y-%m-%d')
|
date = datetime.today().strftime('%Y-%m-%d')
|
||||||
time = datetime.today().strftime('%H:%M:%S')
|
time = datetime.today().strftime('%H:%M:%S')
|
||||||
|
|
||||||
|
|
@ -109,7 +96,7 @@ class WindowDialog():
|
||||||
|
|
||||||
# -------- 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):
|
||||||
for __O__ in sketchList:
|
for __O__ in sketchList:
|
||||||
__obj__ = []
|
__obj__ = []
|
||||||
__obj__.append(__O__)
|
__obj__.append(__O__)
|
||||||
|
|
@ -122,7 +109,7 @@ class WindowDialog():
|
||||||
|
|
||||||
FreeCAD.activeDocument().recompute()
|
FreeCAD.activeDocument().recompute()
|
||||||
|
|
||||||
def _exportSketchCalepinage(self, sketchList, plateLength, plateWidth, spacing):
|
def exportSketchCalepinage(self, sketchList, plateLength, plateWidth, spacing):
|
||||||
copy_sketchList = sketchList[:]
|
copy_sketchList = sketchList[:]
|
||||||
__obj__ = []
|
__obj__ = []
|
||||||
currentX = 0.0
|
currentX = 0.0
|
||||||
|
|
@ -186,8 +173,8 @@ class WindowDialog():
|
||||||
FreeCAD.activeDocument().recompute()
|
FreeCAD.activeDocument().recompute()
|
||||||
|
|
||||||
if listSize <= 0 or isSVGFull:
|
if listSize <= 0 or isSVGFull:
|
||||||
fichierSVG = u"" + self.outputRacine + 'CALEPINAGE-' + str(SVGNameCounter) + '-' + '.svg'
|
fichierSVG = u"" + self.outputRacine + 'CALEPINAGE-(' + str(SVGNameCounter) + ')' + '.svg'
|
||||||
print('Export SVG de : ' + u"" + str(os.path.basename(self.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__:
|
||||||
FreeCAD.ActiveDocument.removeObject(__i__.Label)
|
FreeCAD.ActiveDocument.removeObject(__i__.Label)
|
||||||
|
|
@ -224,64 +211,26 @@ class WindowDialog():
|
||||||
largestFace = face
|
largestFace = face
|
||||||
|
|
||||||
if largestFace:
|
if largestFace:
|
||||||
# Get normal at center of face (parametric center)
|
|
||||||
u, v = largestFace.Surface.parameter(largestFace.CenterOfMass)
|
u, v = largestFace.Surface.parameter(largestFace.CenterOfMass)
|
||||||
normal = largestFace.normalAt(u, v)
|
normal = largestFace.normalAt(u, v)
|
||||||
return normal.normalize()
|
return normal.normalize()
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# def searchDir(self, obj, xres, yres, zres):
|
|
||||||
# x, y, z = xres, yres, zres
|
def exportSVG(self, isCalepinage, svgList):
|
||||||
|
|
||||||
# if hasattr(obj, "Dir"):
|
|
||||||
# if obj.Dir.x != 0.0:
|
|
||||||
# x = obj.Dir.x
|
|
||||||
# if obj.Dir.y != 0.0:
|
|
||||||
# y = obj.Dir.y
|
|
||||||
# if obj.Dir.z != 0.0:
|
|
||||||
# z = obj.Dir.z
|
|
||||||
|
|
||||||
# if not hasattr(obj, "Objects"):
|
|
||||||
# return FreeCAD.Vector(x, y, z)
|
|
||||||
# else:
|
|
||||||
# res = FreeCAD.Vector(x, y, z)
|
|
||||||
# for i in obj.Objects:
|
|
||||||
# res = self.searchDir(i, x, y, z)
|
|
||||||
# return res
|
|
||||||
|
|
||||||
# elif hasattr(obj, "Objects"):
|
|
||||||
# res = FreeCAD.Vector(x, y, z)
|
|
||||||
# for i in obj.Objects:
|
|
||||||
# res = self.searchDir(i, x, y, z)
|
|
||||||
# return res
|
|
||||||
|
|
||||||
def exportSVG(self, isCalepinage):
|
|
||||||
plateLength = self.form.doubleSpinBoxLength.value()
|
plateLength = self.form.doubleSpinBoxLength.value()
|
||||||
plateWidth = self.form.doubleSpinBoxWidth.value()
|
plateWidth = self.form.doubleSpinBoxWidth.value()
|
||||||
spacing = self.form.doubleSpinBoxSpacing.value()
|
spacing = self.form.doubleSpinBoxSpacing.value()
|
||||||
sketchList = []
|
sketchList = []
|
||||||
|
|
||||||
for obj in FreeCADGui.Selection.getSelection():
|
for _, obj, objCount in svgList:
|
||||||
if not obj.Label.endswith("-SVG"):
|
for _ in range(objCount):
|
||||||
continue
|
|
||||||
|
|
||||||
count = 1 # default if not using spinboxes (or fetch from list if desired)
|
|
||||||
# Optional: match count from list
|
|
||||||
for index in range(self.form.listWidgetSelector.count()):
|
|
||||||
item = self.form.listWidgetSelector.item(index)
|
|
||||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
|
||||||
if widget.obj == obj:
|
|
||||||
count = widget.get_value()
|
|
||||||
break
|
|
||||||
|
|
||||||
for _ in range(count):
|
|
||||||
if hasattr(obj, "Dir"):
|
if hasattr(obj, "Dir"):
|
||||||
vector = FreeCAD.Vector(obj.Dir.x, obj.Dir.y, obj.Dir.z)
|
vector = FreeCAD.Vector(obj.Dir.x, obj.Dir.y, obj.Dir.z)
|
||||||
else:
|
else:
|
||||||
vector = self.getLargestFaceDir(obj)
|
vector = self.getLargestFaceDir(obj)
|
||||||
|
|
||||||
# vector = self.searchDir(obj, 0, 0, 0)
|
|
||||||
sv0 = Draft.make_shape2dview(obj, vector)
|
sv0 = Draft.make_shape2dview(obj, vector)
|
||||||
|
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
|
|
@ -294,32 +243,19 @@ class WindowDialog():
|
||||||
FreeCAD.ActiveDocument.removeObject(sv0.Name)
|
FreeCAD.ActiveDocument.removeObject(sv0.Name)
|
||||||
|
|
||||||
if isCalepinage:
|
if isCalepinage:
|
||||||
self._exportSketchCalepinage(sketchList, plateLength, plateWidth, spacing)
|
self.exportSketchCalepinage(sketchList, plateLength, plateWidth, spacing)
|
||||||
else:
|
else:
|
||||||
self._exportSketchBasic(sketchList)
|
self.exportSketchBasic(sketchList)
|
||||||
|
|
||||||
self._populate_selector_list()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def exportSTL(self, singleMode):
|
def exportSTL(self, singleMode, stlList):
|
||||||
objects_to_export = []
|
objects_to_export = []
|
||||||
|
|
||||||
for obj in FreeCADGui.Selection.getSelection():
|
for objLabel, obj, objCount in stlList:
|
||||||
if not obj.Label.endswith("-STL"):
|
for i in range(objCount):
|
||||||
continue
|
|
||||||
|
|
||||||
count = 1
|
|
||||||
for index in range(self.form.listWidgetSelector.count()):
|
|
||||||
item = self.form.listWidgetSelector.item(index)
|
|
||||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
|
||||||
if widget.obj == obj:
|
|
||||||
count = widget.get_value()
|
|
||||||
break
|
|
||||||
|
|
||||||
for i in range(count):
|
|
||||||
clone = Draft.clone(obj)
|
clone = Draft.clone(obj)
|
||||||
objects_to_export.append((clone, obj.Label, i + 1))
|
objects_to_export.append((clone, objLabel, i + 1))
|
||||||
|
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
|
|
||||||
|
|
@ -340,17 +276,62 @@ class WindowDialog():
|
||||||
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
||||||
|
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
self._populate_selector_list()
|
|
||||||
|
|
||||||
|
|
||||||
def export(self):
|
def export(self):
|
||||||
isCalepinage = self.form.checkBoxCalepinage.isChecked()
|
isCalepinage = self.form.checkBoxCalepinage.isChecked()
|
||||||
isCombine = self.form.checkBoxCombine.isChecked()
|
isCombine = self.form.checkBoxCombine.isChecked()
|
||||||
|
|
||||||
self.outputRacine = self._createFolder()
|
svgList = []
|
||||||
|
stlList = []
|
||||||
|
|
||||||
self.exportSVG(isCalepinage)
|
for obj in FreeCAD.ActiveDocument.Objects:
|
||||||
self.exportSTL(isCombine)
|
count = 1
|
||||||
|
|
||||||
|
for index in range(self.form.listWidgetSelector.count()):
|
||||||
|
item = self.form.listWidgetSelector.item(index)
|
||||||
|
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||||
|
|
||||||
|
if not item.isSelected():
|
||||||
|
continue
|
||||||
|
|
||||||
|
if widget.obj == obj:
|
||||||
|
count = widget.get_value()
|
||||||
|
if obj.Label.endswith("-SVG"):
|
||||||
|
svgList.append((obj.Label, obj, count))
|
||||||
|
elif obj.Label.endswith("-STL"):
|
||||||
|
stlList.append((obj.Label, obj, count))
|
||||||
|
break
|
||||||
|
|
||||||
|
if not svgList == [] or not stlList == []:
|
||||||
|
self.outputRacine = self.createFolder()
|
||||||
|
|
||||||
|
self.exportSVG(isCalepinage, svgList)
|
||||||
|
self.exportSTL(isCombine, stlList)
|
||||||
|
|
||||||
|
|
||||||
|
def saveVarSet(self, varSetName = "TestVarSet"):
|
||||||
|
varSet = FreeCAD.ActiveDocument.addObject("App::VarSet", varSetName)
|
||||||
|
|
||||||
|
for obj in FreeCADGui.Selection.getSelection():
|
||||||
|
count = 1
|
||||||
|
for index in range(self.form.listWidgetSelector.count()):
|
||||||
|
item = self.form.listWidgetSelector.item(index)
|
||||||
|
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||||
|
if widget.obj == obj:
|
||||||
|
count = widget.get_value()
|
||||||
|
break
|
||||||
|
|
||||||
|
varSet.addProperty("App::PropertyStringList", obj.Name)
|
||||||
|
if obj.Label.endswith("-SVG"):
|
||||||
|
setattr(varSet, obj.Name, ("SVG", str(count)))
|
||||||
|
else:
|
||||||
|
setattr(varSet, obj.Name, ("STL", str(count)))
|
||||||
|
|
||||||
|
FreeCAD.ActiveDocument.recompute()
|
||||||
|
|
||||||
|
|
||||||
|
# def loadVarSet(self, varSetName = "TestVarSet", count = 1):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<string notr="true">Multi Export</string>
|
<string notr="true">Multi Export</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="labelHelp">
|
<widget class="QLabel" name="labelHelp">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>❓</string>
|
<string>❓</string>
|
||||||
|
|
@ -187,6 +187,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="7" column="2" colspan="2">
|
||||||
|
<widget class="QPushButton" name="pushButtonSave">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">Save</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue