added refresh button (temp fix)
This commit is contained in:
parent
7323d8ae5c
commit
d1e0f260fc
|
|
@ -36,14 +36,28 @@ class WindowDialog():
|
||||||
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 refresh(self):
|
||||||
|
for index in range(self.form.listWidgetSelector.count()):
|
||||||
|
item = self.form.listWidgetSelector.item(index)
|
||||||
|
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||||
|
item.setSelected(False)
|
||||||
|
|
||||||
|
for obj in FreeCADGui.Selection.getSelection():
|
||||||
|
for index in range(self.form.listWidgetSelector.count()):
|
||||||
|
item = self.form.listWidgetSelector.item(index)
|
||||||
|
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||||
|
if widget.obj == obj:
|
||||||
|
item.setSelected(True)
|
||||||
|
break
|
||||||
|
|
||||||
def _connect_widgets(self):
|
def _connect_widgets(self):
|
||||||
self.form.pushButtonExport.pressed.connect(self.export)
|
self.form.pushButtonExport.pressed.connect(self.export)
|
||||||
|
self.form.pushButtonSave.pressed.connect(self.saveVarSet)
|
||||||
|
self.form.pushButtonRefresh.pressed.connect(self.refresh)
|
||||||
self.form.listWidgetSelector.itemClicked.connect(self._on_list_item_clicked)
|
self.form.listWidgetSelector.itemClicked.connect(self._on_list_item_clicked)
|
||||||
|
|
||||||
def _populate_selector_list(self):
|
def _populate_selector_list(self):
|
||||||
|
|
@ -59,7 +73,6 @@ 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)
|
FreeCADGui.Selection.addSelection(obj)
|
||||||
|
|
||||||
|
|
@ -74,19 +87,17 @@ class WindowDialog():
|
||||||
FreeCADGui.Selection.addSelection(obj)
|
FreeCADGui.Selection.addSelection(obj)
|
||||||
|
|
||||||
def _on_selection_changed(self, doc, objects):
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -224,37 +235,12 @@ 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
|
|
||||||
|
|
||||||
# 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):
|
def exportSVG(self, isCalepinage):
|
||||||
plateLength = self.form.doubleSpinBoxLength.value()
|
plateLength = self.form.doubleSpinBoxLength.value()
|
||||||
|
|
@ -266,8 +252,7 @@ class WindowDialog():
|
||||||
if not obj.Label.endswith("-SVG"):
|
if not obj.Label.endswith("-SVG"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
count = 1 # default if not using spinboxes (or fetch from list if desired)
|
count = 1
|
||||||
# Optional: match count from 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)
|
||||||
|
|
@ -281,7 +266,6 @@ class WindowDialog():
|
||||||
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()
|
||||||
|
|
@ -298,7 +282,9 @@ class WindowDialog():
|
||||||
else:
|
else:
|
||||||
self._exportSketchBasic(sketchList)
|
self._exportSketchBasic(sketchList)
|
||||||
|
|
||||||
self._populate_selector_list()
|
for obj in FreeCAD.ActiveDocument.Objects:
|
||||||
|
if obj.Label.endswith("-SVG") or obj.Label.endswith("-STL"):
|
||||||
|
FreeCADGui.Selection.addSelection(obj)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -340,7 +326,9 @@ class WindowDialog():
|
||||||
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
||||||
|
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
self._populate_selector_list()
|
for obj in FreeCAD.ActiveDocument.Objects:
|
||||||
|
if obj.Label.endswith("-SVG") or obj.Label.endswith("-STL"):
|
||||||
|
FreeCADGui.Selection.addSelection(obj)
|
||||||
|
|
||||||
|
|
||||||
def export(self):
|
def export(self):
|
||||||
|
|
@ -353,6 +341,27 @@ class WindowDialog():
|
||||||
self.exportSTL(isCombine)
|
self.exportSTL(isCombine)
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
mainWindow = WindowDialog()
|
mainWindow = WindowDialog()
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
@ -45,6 +45,21 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="2" colspan="3">
|
||||||
|
<widget class="QPushButton" name="pushButtonRefresh">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">🔄</string>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Refresh</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="1" column="0" colspan="3">
|
<item row="1" column="0" colspan="3">
|
||||||
<widget class="QListWidget" name="listWidgetSelector">
|
<widget class="QListWidget" name="listWidgetSelector">
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
|
|
@ -187,6 +202,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