Merge pull request #5384 from Roy-043/Draft-fix-task-panel-related-issues

Draft: fix task panel related issues
This commit is contained in:
Yorik van Havre
2022-01-24 16:16:16 +01:00
committed by GitHub
9 changed files with 95 additions and 59 deletions

View File

@@ -615,7 +615,10 @@ class DraftToolBar:
QtCore.QObject.connect(self.undoButton,QtCore.SIGNAL("pressed()"),self.undoSegment)
QtCore.QObject.connect(self.selectButton,QtCore.SIGNAL("pressed()"),self.selectEdge)
QtCore.QObject.connect(self.continueCmd,QtCore.SIGNAL("stateChanged(int)"),self.setContinue)
QtCore.QObject.connect(self.isCopy,QtCore.SIGNAL("stateChanged(int)"),self.setCopymode)
QtCore.QObject.connect(self.isSubelementMode, QtCore.SIGNAL("stateChanged(int)"), self.setSubelementMode)
QtCore.QObject.connect(self.isRelative,QtCore.SIGNAL("stateChanged(int)"),self.setRelative)
QtCore.QObject.connect(self.isGlobal,QtCore.SIGNAL("stateChanged(int)"),self.setGlobal)
QtCore.QObject.connect(self.hasFill,QtCore.SIGNAL("stateChanged(int)"),self.setFill)
@@ -981,7 +984,8 @@ class DraftToolBar:
def rotateSetCenterUi(self):
self.pointUi(translate("draft", "Rotate"),icon="Draft_Rotate")
self.continueCmd.show()
self.modUi()
self.isRelative.hide()
def pointUi(self, title=translate("draft","Point"), cancel=None, extra=None,
getcoords=None, rel=False, icon="Draft_Draft"):
@@ -1306,6 +1310,9 @@ class DraftToolBar:
if self.sourceCmd.featureName == "Offset":
p.SetBool("OffsetCopyMode",bool(val))
def setSubelementMode(self):
self.sourceCmd.set_ghosts()
def relocate(self):
"""relocates the right-aligned buttons depending on the toolbar size"""
if self.baseWidget.geometry().width() < 400:

View File

@@ -39,9 +39,9 @@ import draftmake.make_line as make_line
def scale(objectslist, scale=App.Vector(1,1,1),
center=App.Vector(0,0,0), copy=False):
"""scale(objects, scale, [center], copy)
Scales the objects contained in objects (that can be a list of objects or
an object) of the given around given center.
Scales the objects contained in objects (that can be a list of objects or
an object) of the given around given center.
Parameters
----------
@@ -55,7 +55,7 @@ def scale(objectslist, scale=App.Vector(1,1,1),
copy : bool
If copy is True, the actual objects are not scaled, but copies
are created instead.
are created instead.
Return
----------
@@ -124,8 +124,8 @@ def scale(objectslist, scale=App.Vector(1,1,1),
obj.YSize = obj.YSize * scale.y
if obj.ViewObject and hasattr(obj.ViewObject,"FontSize"):
obj.ViewObject.FontSize = obj.ViewObject.FontSize * scale.y
if copy:
gui_utils.format_object(newobj,obj)
newobjlist.append(newobj)
@@ -148,7 +148,7 @@ def scale_vertex(obj, vertex_index, scale, center):
"""
points = obj.Points
points[vertex_index] = obj.Placement.inverse().multVec(
scaleVectorFromCenter(
scale_vector_from_center(
obj.Placement.multVec(points[vertex_index]),
scale, center))
obj.Points = points
@@ -173,11 +173,11 @@ def scale_edge(obj, edge_index, scale, center):
Needed for SubObjects modifiers.
Implemented by Dion Moult during 0.19 dev cycle (works only with Draft Wire).
"""
scaleVertex(obj, edge_index, scale, center)
if utils.isClosedEdge(edge_index, obj):
scaleVertex(obj, 0, scale, center)
scale_vertex(obj, edge_index, scale, center)
if utils.is_closed_edge(edge_index, obj):
scale_vertex(obj, 0, scale, center)
else:
scaleVertex(obj, edge_index+1, scale, center)
scale_vertex(obj, edge_index+1, scale, center)
scaleEdge = scale_edge
@@ -188,15 +188,15 @@ def copy_scaled_edge(obj, edge_index, scale, center):
Needed for SubObjects modifiers.
Implemented by Dion Moult during 0.19 dev cycle (works only with Draft Wire).
"""
vertex1 = scaleVectorFromCenter(
vertex1 = scale_vector_from_center(
obj.Placement.multVec(obj.Points[edge_index]),
scale, center)
if utils.isClosedEdge(edge_index, obj):
vertex2 = scaleVectorFromCenter(
if utils.is_closed_edge(edge_index, obj):
vertex2 = scale_vector_from_center(
obj.Placement.multVec(obj.Points[0]),
scale, center)
else:
vertex2 = scaleVectorFromCenter(
vertex2 = scale_vector_from_center(
obj.Placement.multVec(obj.Points[edge_index+1]),
scale, center)
return make_line.make_line(vertex1, vertex2)
@@ -212,7 +212,7 @@ def copy_scaled_edges(arguments):
"""
copied_edges = []
for argument in arguments:
copied_edges.append(copyScaledEdge(argument[0], argument[1],
copied_edges.append(copy_scaled_edge(argument[0], argument[1],
argument[2], argument[3]))
join.join_wires(copied_edges)

View File

@@ -84,7 +84,6 @@ class Mirror(gui_base_original.Modifier):
self.sel = Gui.Selection.getSelection()
self.ui.pointUi(title=translate("draft", self.featureName), icon="Draft_Mirror")
self.ui.modUi()
self.ui.xValue.setFocus()
self.ui.xValue.selectAll()
# self.ghost = trackers.ghostTracker(self.sel)

View File

@@ -174,19 +174,23 @@ class Move(gui_base_original.Modifier):
def set_ghosts(self):
"""Set the ghost to display."""
for ghost in self.ghosts:
ghost.remove()
if self.ui.isSubelementMode.isChecked():
return self.set_subelement_ghosts()
self.ghosts = [trackers.ghostTracker(self.selected_objects)]
self.ghosts = self.get_subelement_ghosts()
else:
self.ghosts = [trackers.ghostTracker(self.selected_objects)]
def set_subelement_ghosts(self):
"""Set ghost for the subelements."""
def get_subelement_ghosts(self):
"""Get ghost for the subelements (vertices, edges)."""
import Part
ghosts = []
for object in self.selected_subelements:
for subelement in object.SubObjects:
if (isinstance(subelement, Part.Vertex)
or isinstance(subelement, Part.Edge)):
self.ghosts.append(trackers.ghostTracker(subelement))
if isinstance(subelement, (Part.Vertex, Part.Edge)):
ghosts.append(trackers.ghostTracker(subelement))
return ghosts
def move(self, is_copy=False):
"""Perform the move of the subelements or the entire object."""

View File

@@ -94,7 +94,6 @@ class Rotate(gui_base_original.Modifier):
self.step = 0
self.center = None
self.ui.rotateSetCenterUi()
self.ui.modUi()
self.arctrack = trackers.arcTracker()
self.call = self.view.addEventCallback("SoEvent", self.action)
_msg(translate("draft", "Pick rotation center"))
@@ -235,19 +234,26 @@ class Rotate(gui_base_original.Modifier):
def set_ghosts(self):
"""Set the ghost to display."""
for ghost in self.ghosts:
ghost.remove()
if self.ui.isSubelementMode.isChecked():
return self.set_subelement_ghosts()
self.ghosts = [trackers.ghostTracker(self.selected_objects)]
self.ghosts = self.get_subelement_ghosts()
else:
self.ghosts = [trackers.ghostTracker(self.selected_objects)]
if self.center:
for ghost in self.ghosts:
ghost.center(self.center)
def set_subelement_ghosts(self):
"""Set ghost for the subelements (vertices, edges)."""
def get_subelement_ghosts(self):
"""Get ghost for the subelements (vertices, edges)."""
import Part
for obj in self.selected_subelements:
for subelement in obj.SubObjects:
if (isinstance(subelement, Part.Vertex)
or isinstance(subelement, Part.Edge)):
self.ghosts.append(trackers.ghostTracker(subelement))
ghosts = []
for object in self.selected_subelements:
for subelement in object.SubObjects:
if isinstance(subelement, (Part.Vertex, Part.Edge)):
ghosts.append(trackers.ghostTracker(subelement))
return ghosts
def finish(self, closed=False, cont=False):
"""Finish the rotate operation."""

View File

@@ -99,7 +99,7 @@ class Scale(gui_base_original.Modifier):
self.selected_subelements = Gui.Selection.getSelectionEx()
self.refs = []
self.ui.pointUi(title=translate("draft",self.featureName), icon="Draft_Scale")
self.ui.modUi()
self.ui.isRelative.hide()
self.ui.xValue.setFocus()
self.ui.xValue.selectAll()
self.pickmode = False
@@ -108,19 +108,24 @@ class Scale(gui_base_original.Modifier):
_msg(translate("draft", "Pick base point"))
def set_ghosts(self):
"""Set the previews of the objects to scale."""
if self.ui.isSubelementMode.isChecked():
return self.set_subelement_ghosts()
self.ghosts = [trackers.ghostTracker(self.selected_objects)]
"""Set the ghost to display."""
for ghost in self.ghosts:
ghost.remove()
if self.task and self.task.isSubelementMode.isChecked():
self.ghosts = self.get_subelement_ghosts()
else:
self.ghosts = [trackers.ghostTracker(self.selected_objects)]
def set_subelement_ghosts(self):
"""Set the previews of the subelements from an object to scale."""
def get_subelement_ghosts(self):
"""Get ghost for the subelements (vertices, edges)."""
import Part
ghosts = []
for object in self.selected_subelements:
for subelement in object.SubObjects:
if isinstance(subelement, (Part.Vertex, Part.Edge)):
self.ghosts.append(trackers.ghostTracker(subelement))
ghosts.append(trackers.ghostTracker(subelement))
return ghosts
def pickRef(self):
"""Pick a point of reference."""

View File

@@ -118,7 +118,6 @@ class Stretch(gui_base_original.Modifier):
self.step = 1
self.refpoint = None
self.ui.pointUi(title=translate("draft", self.featureName), icon="Draft_Stretch")
self.ui.extUi()
self.call = self.view.addEventCallback("SoEvent", self.action)
self.rectracker = trackers.rectangleTracker(dotted=True,
scolor=(0.0, 0.0, 1.0),

View File

@@ -81,7 +81,9 @@ class Tracker:
ToDo.delay(self._insertSwitch, self.switch)
def finalize(self):
"""Finish the command by removing the switch."""
"""Finish the command by removing the switch.
Also called by ghostTracker.remove.
"""
ToDo.delay(self._removeSwitch, self.switch)
self.switch = None
@@ -694,14 +696,10 @@ class ghostTracker(Tracker):
super().__init__(dotted, scolor, swidth,
children=self.children, name="ghostTracker")
def update(self, obj):
"""Recreate the ghost from a new object."""
obj.ViewObject.show()
self.finalize()
sep = self.getNode(obj)
super().__init__(children=[sep])
self.on()
obj.ViewObject.hide()
def remove(self):
"""Remove the ghost when switching to and from subelement mode."""
if self.switch:
self.finalize()
def move(self, delta):
"""Move the ghost to a given position.
@@ -1151,7 +1149,7 @@ class gridTracker(Tracker):
loc = FreeCAD.Vector(-bound+self.space/2,-bound+self.space/2,0)
hpts = BimProject.getHuman(loc)
pts.extend([tuple(p) for p in hpts])
pidx.append(len(hpts))
pidx.append(len(hpts))
except Exception:
# BIM not installed
return

View File

@@ -46,28 +46,30 @@ class ScaleTaskPanel:
"""The task panel for the Draft Scale tool."""
def __init__(self):
decimals = App.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals", 2)
self.sourceCmd = None
self.form = QtGui.QWidget()
self.form.setWindowIcon(QtGui.QIcon(":/icons/Draft_Scale.svg"))
layout = QtGui.QGridLayout(self.form)
self.xLabel = QtGui.QLabel()
layout.addWidget(self.xLabel, 0, 0, 1, 1)
self.xValue = QtGui.QDoubleSpinBox()
self.xValue.setRange(0.0000001, 1000000.0)
self.xValue.setDecimals(Draft.precision())
self.xValue.setDecimals(decimals)
self.xValue.setValue(1)
layout.addWidget(self.xValue,0,1,1,1)
self.yLabel = QtGui.QLabel()
layout.addWidget(self.yLabel,1,0,1,1)
self.yValue = QtGui.QDoubleSpinBox()
self.yValue.setRange(.0000001,1000000.0)
self.yValue.setDecimals(Draft.precision())
self.yValue.setRange(0.0000001, 1000000.0)
self.yValue.setDecimals(decimals)
self.yValue.setValue(1)
layout.addWidget(self.yValue,1,1,1,1)
self.zLabel = QtGui.QLabel()
layout.addWidget(self.zLabel,2,0,1,1)
self.zValue = QtGui.QDoubleSpinBox()
self.zValue.setRange(.0000001,1000000.0)
self.zValue.setDecimals(Draft.precision())
self.zValue.setRange(0.0000001, 1000000.0)
self.zValue.setDecimals(decimals)
self.zValue.setValue(1)
layout.addWidget(self.zValue,2,1,1,1)
self.lock = QtGui.QCheckBox()
@@ -93,16 +95,23 @@ class ScaleTaskPanel:
QtCore.QObject.connect(self.lock,QtCore.SIGNAL("toggled(bool)"),self.setLock)
QtCore.QObject.connect(self.relative,QtCore.SIGNAL("toggled(bool)"),self.setRelative)
QtCore.QObject.connect(self.isCopy,QtCore.SIGNAL("toggled(bool)"),self.setCopy)
QtCore.QObject.connect(self.isSubelementMode,QtCore.SIGNAL("toggled(bool)"),self.setSubelementMode)
QtCore.QObject.connect(self.isClone,QtCore.SIGNAL("toggled(bool)"),self.setClone)
self.retranslateUi()
def setLock(self, state):
"""Set the uniform scaling."""
App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleUniform", state)
if state:
val = self.xValue.value()
self.yValue.setValue(val)
self.zValue.setValue(val)
def setRelative(self, state):
"""Set the relative scaling."""
App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleRelative", state)
if self.sourceCmd:
self.sourceCmd.scaleGhost(self.xValue.value(),self.yValue.value(),self.zValue.value(),self.relative.isChecked())
def setCopy(self, state):
"""Set the scale and copy option."""
@@ -110,11 +119,20 @@ class ScaleTaskPanel:
if state and self.isClone.isChecked():
self.isClone.setChecked(False)
def setSubelementMode(self, state):
if state and self.isClone.isChecked():
self.isClone.setChecked(False)
if self.sourceCmd:
self.sourceCmd.set_ghosts()
self.sourceCmd.scaleGhost(self.xValue.value(),self.yValue.value(),self.zValue.value(),self.relative.isChecked())
def setClone(self, state):
"""Set the clone and scale option."""
App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleClone", state)
if state and self.isCopy.isChecked():
self.isCopy.setChecked(False)
if state and self.isSubelementMode.isChecked():
self.isSubelementMode.setChecked(False)
def setValue(self, val=None):
"""Set the value of the points."""