From 7d2498d65e77fbae2edf76f406d1f45fd3b6771f Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 13 May 2019 14:55:58 -0300 Subject: [PATCH] Draft: Fixed Part primitives mode of Draft tools --- src/Mod/Draft/DraftGui.py | 14 +++++++++++++- src/Mod/Draft/DraftTools.py | 22 +++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py index 52d2f0dfc9..6c164d8b1c 100644 --- a/src/Mod/Draft/DraftGui.py +++ b/src/Mod/Draft/DraftGui.py @@ -812,7 +812,7 @@ class DraftToolBar: self.isRelative.setText(translate("draft", "Relative")+" ("+inCommandShortcuts["Relative"][0]+")") self.isRelative.setToolTip(translate("draft", "Coordinates relative to last point or absolute")) self.hasFill.setText(translate("draft", "Filled")+" ("+inCommandShortcuts["Fill"][0]+")") - self.hasFill.setToolTip(translate("draft", "Check this if the object should appear as filled, otherwise it will appear as wireframe")) + self.hasFill.setToolTip(translate("draft", "Check this if the object should appear as filled, otherwise it will appear as wireframe. Not available if Draft preference option 'Use Part Primitives' is enabled")) self.finishButton.setText(translate("draft", "Finish")+" ("+inCommandShortcuts["Exit"][0]+")") self.finishButton.setToolTip(translate("draft", "Finishes the current drawing or editing operation")) self.continueCmd.setToolTip(translate("draft", "If checked, command will not finish until you press the command button again")) @@ -1021,6 +1021,10 @@ class DraftToolBar: self.xValue.setEnabled(True) self.yValue.setEnabled(True) self.isRelative.show() + if Draft.getParam("UsePartPrimitives",False): + self.hasFill.setEnabled(False) + else: + self.hasFill.setEnabled(True) self.hasFill.show() self.finishButton.show() self.closeButton.show() @@ -1033,6 +1037,10 @@ class DraftToolBar: self.pointUi(translate("draft", "Circle"),icon="Draft_Circle") self.continueCmd.show() self.labelx.setText(translate("draft", "Center X")) + if Draft.getParam("UsePartPrimitives",False): + self.hasFill.setEnabled(False) + else: + self.hasFill.setEnabled(True) self.hasFill.show() def arcUi(self): @@ -1275,6 +1283,10 @@ class DraftToolBar: self.arc3PtButton.setChecked(False) def extUi(self): + if Draft.getParam("UsePartPrimitives",False): + self.hasFill.setEnabled(False) + else: + self.hasFill.setEnabled(True) self.hasFill.show() self.continueCmd.show() diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index db309d8740..26d73b8611 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -594,6 +594,7 @@ class Line(Creator): FreeCADGui.Snapper.restack() self.oldWP = None if (len(self.node) > 1): + FreeCADGui.addModule("Draft") if (len(self.node) == 2) and Draft.getParam("UsePartPrimitives",False): # use Part primitive p1 = self.node[0] @@ -611,7 +612,6 @@ class Line(Creator): else: # building command string rot,sup,pts,fil = self.getStrings() - FreeCADGui.addModule("Draft") self.commit(translate("draft","Create Wire"), ['pl = FreeCAD.Placement()', 'pl.Rotation.Q = '+rot, @@ -1241,6 +1241,9 @@ class Rectangle(Creator): self.refpoint = None self.ui.pointUi(name) self.ui.extUi() + if Draft.getParam("UsePartPrimitives",False): + self.fillstate = self.ui.hasFill.isChecked() + self.ui.hasFill.setChecked(True) self.call = self.view.addEventCallback("SoEvent",self.action) self.rect = rectangleTracker() msg(translate("draft", "Pick first point:")+"\n") @@ -1249,9 +1252,11 @@ class Rectangle(Creator): "terminates the operation and closes the poly if asked" Creator.finish(self) if self.ui: + if hasattr(self,"fillstate"): + self.ui.hasFill.setChecked(self.fillstate) + del self.fillstate self.rect.off() self.rect.finalize() - if self.ui: if self.ui.continueMode: self.Activated() @@ -1276,6 +1281,7 @@ class Rectangle(Creator): if height < 0: height = -height base = base.add((p1.sub(p2)).negative()) + FreeCADGui.addModule("Draft") if Draft.getParam("UsePartPrimitives",False): # Use Part Primitive self.commit(translate("draft","Create Plane"), @@ -1289,7 +1295,6 @@ class Rectangle(Creator): 'Draft.autogroup(plane)', 'FreeCAD.ActiveDocument.recompute()']) else: - FreeCADGui.addModule("Draft") self.commit(translate("draft","Create Rectangle"), ['pl = FreeCAD.Placement()', 'pl.Rotation.Q = '+rot, @@ -1809,21 +1814,21 @@ class Polygon(Creator): def drawPolygon(self): "actually draws the FreeCAD object" rot,sup,pts,fil = self.getStrings() + FreeCADGui.addModule("Draft") if Draft.getParam("UsePartPrimitives",False): + FreeCADGui.addModule("Part") self.commit(translate("draft","Create Polygon"), - ['import Part', - 'pl=FreeCAD.Placement()', + ['pl=FreeCAD.Placement()', 'pl.Rotation.Q=' + rot, 'pl.Base=' + DraftVecUtils.toString(self.center), 'pol = FreeCAD.ActiveDocument.addObject("Part::RegularPolygon","RegularPolygon")', 'pol.Polygon = ' + str(self.ui.numFaces.value()), 'pol.Circumradius = ' + str(self.rad), 'pol.Placement = pl', - 'Draft.autogroup(pol)' + 'Draft.autogroup(pol)', 'FreeCAD.ActiveDocument.recompute()']) else: # building command string - FreeCADGui.addModule("Draft") self.commit(translate("draft","Create Polygon"), ['pl=FreeCAD.Placement()', 'pl.Rotation.Q = ' + rot, @@ -1831,7 +1836,6 @@ class Polygon(Creator): 'pol = Draft.makePolygon(' + str(self.ui.numFaces.value()) + ',radius=' + str(self.rad) + ',inscribed=True,placement=pl,face=' + fil + ',support=' + sup + ')', 'Draft.autogroup(pol)', 'FreeCAD.ActiveDocument.recompute()']) - FreeCAD.ActiveDocument.recompute() self.finish(cont=True) def numericInput(self,numx,numy,numz): @@ -1916,6 +1920,7 @@ class Ellipse(Creator): rot2 = FreeCAD.Placement(m) rot2 = rot2.Rotation rot = str((rot1.multiply(rot2)).Q) + FreeCADGui.addModule("Draft") if Draft.getParam("UsePartPrimitives",False): # Use Part Primitive self.commit(translate("draft","Create Ellipse"), @@ -1930,7 +1935,6 @@ class Ellipse(Creator): 'Draft.autogroup(ellipse)', 'FreeCAD.ActiveDocument.recompute()']) else: - FreeCADGui.addModule("Draft") self.commit(translate("draft","Create Ellipse"), ['pl = FreeCAD.Placement()', 'pl.Rotation.Q = '+rot,