Draft: Fixed regressions in Scale tool + reimplemented Clone mode
This commit is contained in:
@@ -1858,13 +1858,14 @@ def scale(objectslist,scale=Vector(1,1,1),center=Vector(0,0,0),copy=False):
|
||||
m = FreeCAD.Matrix()
|
||||
m.move(obj.Placement.Base.negative())
|
||||
m.move(center.negative())
|
||||
m.multiply(scale)
|
||||
m.scale(scale.x,scale.y,scale.z)
|
||||
m.move(center)
|
||||
m.move(obj.Placement.Base)
|
||||
scaled_shape = scaled_shape.transformGeometry(m)
|
||||
if getType(obj) == "Rectangled":
|
||||
if getType(obj) == "Rectangle":
|
||||
p = []
|
||||
for v in scaled_shape.Vertexes: p.append(v.Point)
|
||||
for v in scaled_shape.Vertexes:
|
||||
p.append(v.Point)
|
||||
pl = obj.Placement.copy()
|
||||
pl.Base = p[0]
|
||||
diag = p[2].sub(p[0])
|
||||
|
||||
@@ -1958,14 +1958,15 @@ class DraftToolBar:
|
||||
g = float(self.color.green()/255.0)
|
||||
b = float(self.color.blue()/255.0)
|
||||
elif type == "face":
|
||||
r = float(self.facecolor.red()/255.0)
|
||||
g = float(self.facecolor.green()/255.0)
|
||||
b = float(self.facecolor.blue()/255.0)
|
||||
color = facecolor = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)
|
||||
r = ((color>>24)&0xFF)/255
|
||||
g = ((color>>16)&0xFF)/255
|
||||
b = ((color>>8)&0xFF)/255
|
||||
elif type == "constr":
|
||||
color = QtGui.QColor(Draft.getParam("constructioncolor",746455039)>>8)
|
||||
r = color.red()/255.0
|
||||
g = color.green()/255.0
|
||||
b = color.blue()/255.0
|
||||
color = Draft.getParam("constructioncolor",746455039)
|
||||
r = ((color>>24)&0xFF)/255
|
||||
g = ((color>>16)&0xFF)/255
|
||||
b = ((color>>8)&0xFF)/255
|
||||
else:
|
||||
print("draft: error: couldn't get a color for ",type," type.")
|
||||
if rgb:
|
||||
@@ -2420,40 +2421,66 @@ class ScaleTaskPanel:
|
||||
self.xLabel = QtGui.QLabel()
|
||||
layout.addWidget(self.xLabel,0,0,1,1)
|
||||
self.xValue = QtGui.QDoubleSpinBox()
|
||||
self.xValue.setDecimals(Draft.getParam("precision"))
|
||||
self.xValue.setRange(.0000001,1000000.0)
|
||||
self.xValue.setDecimals(Draft.getParam("precision"))
|
||||
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.setDecimals(Draft.getParam("precision"))
|
||||
self.yValue.setRange(.0000001,1000000.0)
|
||||
self.yValue.setDecimals(Draft.getParam("precision"))
|
||||
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.setDecimals(Draft.getParam("precision"))
|
||||
self.zValue.setRange(.0000001,1000000.0)
|
||||
self.zValue.setDecimals(Draft.getParam("precision"))
|
||||
self.zValue.setValue(1)
|
||||
layout.addWidget(self.zValue,2,1,1,1)
|
||||
self.lock = QtGui.QCheckBox()
|
||||
self.lock.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleUniform",False))
|
||||
layout.addWidget(self.lock,3,0,1,2)
|
||||
self.relative = QtGui.QCheckBox()
|
||||
self.relative.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleRelative",False))
|
||||
layout.addWidget(self.relative,4,0,1,2)
|
||||
self.isCopy = QtGui.QCheckBox()
|
||||
self.isCopy.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleCopy",False))
|
||||
layout.addWidget(self.isCopy,5,0,1,2)
|
||||
self.isSubelementMode = QtGui.QCheckBox()
|
||||
layout.addWidget(self.isSubelementMode,6,0,1,2)
|
||||
self.isClone = QtGui.QCheckBox()
|
||||
layout.addWidget(self.isClone,7,0,1,2)
|
||||
self.isClone.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleClone",False))
|
||||
self.pickrefButton = QtGui.QPushButton()
|
||||
layout.addWidget(self.pickrefButton,7,0,1,2)
|
||||
layout.addWidget(self.pickrefButton,8,0,1,2)
|
||||
QtCore.QObject.connect(self.xValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue)
|
||||
QtCore.QObject.connect(self.yValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue)
|
||||
QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue)
|
||||
QtCore.QObject.connect(self.pickrefButton,QtCore.SIGNAL("clicked()"),self.pickRef)
|
||||
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.isClone,QtCore.SIGNAL("toggled(bool)"),self.setClone)
|
||||
self.retranslateUi()
|
||||
|
||||
def setLock(self,state):
|
||||
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleUniform",state)
|
||||
|
||||
def setRelative(self,state):
|
||||
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleRelative",state)
|
||||
|
||||
def setCopy(self,state):
|
||||
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleCopy",state)
|
||||
if state and self.isClone.isChecked():
|
||||
self.isClone.setChecked(False)
|
||||
|
||||
def setClone(self,state):
|
||||
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleClone",state)
|
||||
if state and self.isCopy.isChecked():
|
||||
self.isCopy.setChecked(False)
|
||||
|
||||
def setValue(self,val=None):
|
||||
if self.lock.isChecked():
|
||||
self.xValue.setValue(val)
|
||||
@@ -2472,6 +2499,7 @@ class ScaleTaskPanel:
|
||||
self.isCopy.setText(QtGui.QApplication.translate("draft", "Copy"))
|
||||
self.isSubelementMode.setText(QtGui.QApplication.translate("draft", "Modify subelements"))
|
||||
self.pickrefButton.setText(QtGui.QApplication.translate("Draft", "Pick from/to points", None))
|
||||
self.isClone.setText(QtGui.QApplication.translate("Draft", "Create a clone", None))
|
||||
|
||||
def pickRef(self):
|
||||
if self.sourceCmd:
|
||||
|
||||
@@ -4185,6 +4185,8 @@ class Scale(Modifier):
|
||||
self.center = self.node[0]
|
||||
if self.task.isSubelementMode.isChecked():
|
||||
self.scale_subelements()
|
||||
elif self.task.isClone.isChecked():
|
||||
self.scale_with_clone()
|
||||
else:
|
||||
self.scale_object()
|
||||
self.finish()
|
||||
@@ -4198,6 +4200,16 @@ class Scale(Modifier):
|
||||
except:
|
||||
FreeCAD.Console.PrintError(translate("draft", "Some subelements could not be scaled."))
|
||||
|
||||
def scale_with_clone(self):
|
||||
if self.task.relative.isChecked():
|
||||
self.delta = FreeCAD.DraftWorkingPlane.getGlobalCoords(self.delta)
|
||||
objects = '[' + ','.join(['FreeCAD.ActiveDocument.' + object.Name for object in self.selected_objects]) + ']'
|
||||
FreeCADGui.addModule("Draft")
|
||||
self.commit(translate("draft","Copy") if self.task.isCopy.isChecked() else translate("draft","Scale"),
|
||||
['clone = Draft.clone('+objects+',forcedraft=True)',
|
||||
'clone.Scale = '+DraftVecUtils.toString(self.delta),
|
||||
'FreeCAD.ActiveDocument.recompute()'])
|
||||
|
||||
def build_copy_subelements_command(self):
|
||||
import Part
|
||||
command = []
|
||||
|
||||
Reference in New Issue
Block a user