diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py
index 1579033455..c3b18c3799 100644
--- a/src/Mod/Draft/DraftGui.py
+++ b/src/Mod/Draft/DraftGui.py
@@ -40,6 +40,7 @@ Report to Draft.py for info
'''
import FreeCAD, FreeCADGui, os, Draft, sys, DraftVecUtils, math
+import DraftTools
try:
from PySide import QtCore, QtGui, QtSvg
@@ -2460,42 +2461,87 @@ class ShapeStringTaskPanel:
self.task.leString.setText(self.stringText)
self.task.fcFontFile.setFileName(Draft.getParam("FontFile",""))
self.fileSpec = Draft.getParam("FontFile","")
+ self.point = FreeCAD.Vector(0.0,0.0,0.0)
+ self.pointPicked = False
QtCore.QObject.connect(self.task.fcFontFile,QtCore.SIGNAL("fileNameSelected(const QString&)"),self.fileSelect)
+ QtCore.QObject.connect(self.task.pbReset,QtCore.SIGNAL("clicked()"),self.resetPoint)
+ self.point = None
+ self.view = Draft.get3DView()
+ self.call = self.view.addEventCallback("SoEvent",self.action)
+ DraftTools.msg(translate("draft", "Pick ShapeString location point:")+"\n")
+
def fileSelect(self, fn):
self.fileSpec = fn
- def accept(self):
- FreeCAD.ActiveDocument.openTransaction("ShapeString")
- qr,sup,points,fil = self.sourceCmd.getStrings()
- height = FreeCAD.Units.Quantity(self.task.sbHeight.text()).Value
- ss = Draft.makeShapeString(str(self.task.leString.text()), ##needs to be bytes for Py3!
- str(self.fileSpec),
- height,
- 0.0)
+ def resetPoint(self):
+ self.pointPicked = False
+ origin = FreeCAD.Vector(0.0,0.0,0.0)
+ self.setPoint(origin)
+ def action(self,arg):
+ "scene event handler"
+ if arg["Type"] == "SoKeyboardEvent":
+ if arg["Key"] == "ESCAPE":
+ self.reject()
+ elif arg["Type"] == "SoLocation2Event": #mouse movement detection
+ self.point,ctrlPoint,info = DraftTools.getPoint(self.sourceCmd,arg,noTracker=True)
+ if not self.pointPicked:
+ self.setPoint(self.point)
+ elif arg["Type"] == "SoMouseButtonEvent":
+ if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
+ self.setPoint(self.point)
+ self.pointPicked = True
+
+ def setPoint(self, point):
+ self.task.sbX.setProperty('rawValue',point.x)
+ self.task.sbY.setProperty('rawValue',point.y)
+ self.task.sbZ.setProperty('rawValue',point.z)
+
+ def createObject(self):
+ "creates object in the current doc"
+ dquote = '"'
+ if sys.version_info.major < 3: # Python3: no more unicode
+ String = 'u' + dquote + str(self.task.leString.text().encode('unicode_escape')) + dquote
+ else:
+ String = dquote + self.task.leString.text() + dquote
+ FFile = dquote + str(self.fileSpec) + dquote
+
+ Size = str(FreeCAD.Units.Quantity(self.task.sbHeight.text()).Value)
+ Tracking = str(0.0)
x = FreeCAD.Units.Quantity(self.task.sbX.text()).Value
y = FreeCAD.Units.Quantity(self.task.sbY.text()).Value
z = FreeCAD.Units.Quantity(self.task.sbZ.text()).Value
ssBase = FreeCAD.Vector(x,y,z)
- plm=FreeCAD.Placement()
- plm.Base = ssBase
- elements = qr[1:-1].split(",") #string to tuple
- mytuple = tuple(elements) #to prevent
- plm.Rotation.Q = mytuple #PyCXX: Error creating object of type N2Py5TupleE from '(0.0,-0.0,-0.0,1.0)'
- ss.Placement=plm
- if sup:
- ss.Support = FreeCAD.ActiveDocument.getObject(sup)
- Draft.autogroup(ss)
- FreeCAD.ActiveDocument.commitTransaction()
+ # this try block is almost identical to the one in DraftTools
+ try:
+ qr,sup,points,fil = self.sourceCmd.getStrings()
+ FreeCADGui.addModule("Draft")
+ self.sourceCmd.commit(translate("draft","Create ShapeString"),
+ ['ss=Draft.makeShapeString(String='+String+',FontFile='+FFile+',Size='+Size+',Tracking='+Tracking+')',
+ 'plm=FreeCAD.Placement()',
+ 'plm.Base='+DraftVecUtils.toString(ssBase),
+ 'plm.Rotation.Q='+qr,
+ 'ss.Placement=plm',
+ 'ss.Support='+sup,
+ 'Draft.autogroup(ss)'])
+ except Exception as e:
+ DraftTools.msg("Draft_ShapeString: error delaying commit", "error")
- FreeCAD.ActiveDocument.recompute()
+ def accept(self):
+ self.createObject();
+ if self.call: self.view.removeEventCallback("SoEvent",self.call)
FreeCADGui.ActiveDocument.resetEdit()
+ FreeCADGui.Snapper.off()
+ self.sourceCmd.creator.finish(self.sourceCmd)
return True
def reject(self):
+ if self.call: self.view.removeEventCallback("SoEvent",self.call)
FreeCADGui.ActiveDocument.resetEdit()
+ FreeCADGui.Snapper.off()
+ self.sourceCmd.creator.finish(self.sourceCmd)
return True
if not hasattr(FreeCADGui,"draftToolBar"):
diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py
index c017bc330f..6557850e05 100644
--- a/src/Mod/Draft/DraftTools.py
+++ b/src/Mod/Draft/DraftTools.py
@@ -2227,10 +2227,15 @@ class ShapeString(Creator):
def Activated(self):
name = translate("draft","ShapeString")
Creator.Activated(self,name)
+ self.creator = Creator
if self.ui:
self.ui.sourceCmd = self
self.taskmode = Draft.getParam("UiMode",1)
if self.taskmode:
+ try:
+ del self.task
+ except AttributeError:
+ pass
self.task = DraftGui.ShapeStringTaskPanel()
self.task.sourceCmd = self
DraftGui.todo.delay(FreeCADGui.Control.showDialog,self.task)
diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc
index cceddee6ef..4994d7c726 100644
--- a/src/Mod/Draft/Resources/Draft.qrc
+++ b/src/Mod/Draft/Resources/Draft.qrc
@@ -134,4 +134,4 @@
ui/preferences-oca.ui
ui/TaskShapeString.ui
-
+
diff --git a/src/Mod/Draft/Resources/ui/TaskShapeString.ui b/src/Mod/Draft/Resources/ui/TaskShapeString.ui
index 9c132d72f1..cc16b4d75c 100644
--- a/src/Mod/Draft/Resources/ui/TaskShapeString.ui
+++ b/src/Mod/Draft/Resources/ui/TaskShapeString.ui
@@ -38,7 +38,76 @@
- -
+
-
+
+
-
+
+
+ Enter coordinates or select point with mouse.
+
+
+
+
+
+
+ -
+
+
+ Enter coordinates or select point with mouse.
+
+
+
+
+
+
+ -
+
+
+ X
+
+
+
+ -
+
+
+ Enter coordinates or select point with mouse.
+
+
+
+
+
+
+ -
+
+
+ Y
+
+
+
+ -
+
+
+ Z
+
+
+
+
+
+ -
+
+
-
+
+
+ Font file
+
+
+
+ -
+
+
+
+
+ -
-
@@ -56,7 +125,7 @@
- -
+
-
-
@@ -83,7 +152,7 @@
- -
+
-
Qt::Vertical
@@ -96,64 +165,34 @@
- -
-
-
-
-
-
-
+
-
+
+
-
+
+
+ Qt::Horizontal
-
-
- -
-
-
-
+
+
+ 40
+ 20
+
-
+
- -
-
+
-
+
+
+ Reset 3d point selection
+
+
+
+
- X
+ Reset Point
- -
-
-
-
-
-
-
- -
-
-
- Y
-
-
-
- -
-
-
- Z
-
-
-
-
-
- -
-
-
-
-
-
- Font file
-
-
-
- -
-
-