Skip to content

Commit

Permalink
Draft: Fixed regressions in Scale tool + reimplemented Clone mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Jun 3, 2019
1 parent 18e83c1 commit e2f65ef
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/Mod/Draft/Draft.py
Expand Up @@ -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])
Expand Down
50 changes: 39 additions & 11 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -1958,14 +1958,15 @@ def getDefaultColor(self,type,rgb=False):
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:
Expand Down Expand Up @@ -2420,40 +2421,66 @@ def __init__(self):
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)
Expand All @@ -2472,6 +2499,7 @@ def retranslateUi(self,widget=None):
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:
Expand Down
12 changes: 12 additions & 0 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -4185,6 +4185,8 @@ def scale(self):
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()
Expand All @@ -4198,6 +4200,16 @@ def scale_subelements(self):
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 = []
Expand Down

0 comments on commit e2f65ef

Please sign in to comment.