Skip to content

Commit dace2f3

Browse files
WandererFanyorikvanhavre
authored andcommitted
Fix ShapeString attachment to Face
1 parent 99b289e commit dace2f3

File tree

4 files changed

+162
-72
lines changed

4 files changed

+162
-72
lines changed

src/Mod/Draft/DraftGui.py

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'''
4141

4242
import FreeCAD, FreeCADGui, os, Draft, sys, DraftVecUtils, math
43+
import DraftTools
4344

4445
try:
4546
from PySide import QtCore, QtGui, QtSvg
@@ -2460,42 +2461,87 @@ def __init__(self):
24602461
self.task.leString.setText(self.stringText)
24612462
self.task.fcFontFile.setFileName(Draft.getParam("FontFile",""))
24622463
self.fileSpec = Draft.getParam("FontFile","")
2464+
self.point = FreeCAD.Vector(0.0,0.0,0.0)
2465+
self.pointPicked = False
24632466

24642467
QtCore.QObject.connect(self.task.fcFontFile,QtCore.SIGNAL("fileNameSelected(const QString&)"),self.fileSelect)
2468+
QtCore.QObject.connect(self.task.pbReset,QtCore.SIGNAL("clicked()"),self.resetPoint)
2469+
self.point = None
2470+
self.view = Draft.get3DView()
2471+
self.call = self.view.addEventCallback("SoEvent",self.action)
2472+
DraftTools.msg(translate("draft", "Pick ShapeString location point:")+"\n")
2473+
24652474

24662475
def fileSelect(self, fn):
24672476
self.fileSpec = fn
24682477

2469-
def accept(self):
2470-
FreeCAD.ActiveDocument.openTransaction("ShapeString")
2471-
qr,sup,points,fil = self.sourceCmd.getStrings()
2472-
height = FreeCAD.Units.Quantity(self.task.sbHeight.text()).Value
2473-
ss = Draft.makeShapeString(str(self.task.leString.text()), ##needs to be bytes for Py3!
2474-
str(self.fileSpec),
2475-
height,
2476-
0.0)
2478+
def resetPoint(self):
2479+
self.pointPicked = False
2480+
origin = FreeCAD.Vector(0.0,0.0,0.0)
2481+
self.setPoint(origin)
2482+
2483+
def action(self,arg):
2484+
"scene event handler"
2485+
if arg["Type"] == "SoKeyboardEvent":
2486+
if arg["Key"] == "ESCAPE":
2487+
self.reject()
2488+
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
2489+
self.point,ctrlPoint,info = DraftTools.getPoint(self.sourceCmd,arg,noTracker=True)
2490+
if not self.pointPicked:
2491+
self.setPoint(self.point)
2492+
elif arg["Type"] == "SoMouseButtonEvent":
2493+
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
2494+
self.setPoint(self.point)
2495+
self.pointPicked = True
2496+
2497+
def setPoint(self, point):
2498+
self.task.sbX.setProperty('rawValue',point.x)
2499+
self.task.sbY.setProperty('rawValue',point.y)
2500+
self.task.sbZ.setProperty('rawValue',point.z)
2501+
2502+
def createObject(self):
2503+
"creates object in the current doc"
2504+
dquote = '"'
2505+
if sys.version_info.major < 3: # Python3: no more unicode
2506+
String = 'u' + dquote + str(self.task.leString.text().encode('unicode_escape')) + dquote
2507+
else:
2508+
String = dquote + self.task.leString.text() + dquote
2509+
FFile = dquote + str(self.fileSpec) + dquote
24772510

2511+
Size = str(FreeCAD.Units.Quantity(self.task.sbHeight.text()).Value)
2512+
Tracking = str(0.0)
24782513
x = FreeCAD.Units.Quantity(self.task.sbX.text()).Value
24792514
y = FreeCAD.Units.Quantity(self.task.sbY.text()).Value
24802515
z = FreeCAD.Units.Quantity(self.task.sbZ.text()).Value
24812516
ssBase = FreeCAD.Vector(x,y,z)
2482-
plm=FreeCAD.Placement()
2483-
plm.Base = ssBase
2484-
elements = qr[1:-1].split(",") #string to tuple
2485-
mytuple = tuple(elements) #to prevent
2486-
plm.Rotation.Q = mytuple #PyCXX: Error creating object of type N2Py5TupleE from '(0.0,-0.0,-0.0,1.0)'
2487-
ss.Placement=plm
2488-
if sup:
2489-
ss.Support = FreeCAD.ActiveDocument.getObject(sup)
2490-
Draft.autogroup(ss)
2491-
FreeCAD.ActiveDocument.commitTransaction()
2517+
# this try block is almost identical to the one in DraftTools
2518+
try:
2519+
qr,sup,points,fil = self.sourceCmd.getStrings()
2520+
FreeCADGui.addModule("Draft")
2521+
self.sourceCmd.commit(translate("draft","Create ShapeString"),
2522+
['ss=Draft.makeShapeString(String='+String+',FontFile='+FFile+',Size='+Size+',Tracking='+Tracking+')',
2523+
'plm=FreeCAD.Placement()',
2524+
'plm.Base='+DraftVecUtils.toString(ssBase),
2525+
'plm.Rotation.Q='+qr,
2526+
'ss.Placement=plm',
2527+
'ss.Support='+sup,
2528+
'Draft.autogroup(ss)'])
2529+
except Exception as e:
2530+
DraftTools.msg("Draft_ShapeString: error delaying commit", "error")
24922531

2493-
FreeCAD.ActiveDocument.recompute()
2532+
def accept(self):
2533+
self.createObject();
2534+
if self.call: self.view.removeEventCallback("SoEvent",self.call)
24942535
FreeCADGui.ActiveDocument.resetEdit()
2536+
FreeCADGui.Snapper.off()
2537+
self.sourceCmd.creator.finish(self.sourceCmd)
24952538
return True
24962539

24972540
def reject(self):
2541+
if self.call: self.view.removeEventCallback("SoEvent",self.call)
24982542
FreeCADGui.ActiveDocument.resetEdit()
2543+
FreeCADGui.Snapper.off()
2544+
self.sourceCmd.creator.finish(self.sourceCmd)
24992545
return True
25002546

25012547
if not hasattr(FreeCADGui,"draftToolBar"):

src/Mod/Draft/DraftTools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,10 +2227,15 @@ def GetResources(self):
22272227
def Activated(self):
22282228
name = translate("draft","ShapeString")
22292229
Creator.Activated(self,name)
2230+
self.creator = Creator
22302231
if self.ui:
22312232
self.ui.sourceCmd = self
22322233
self.taskmode = Draft.getParam("UiMode",1)
22332234
if self.taskmode:
2235+
try:
2236+
del self.task
2237+
except AttributeError:
2238+
pass
22342239
self.task = DraftGui.ShapeStringTaskPanel()
22352240
self.task.sourceCmd = self
22362241
DraftGui.todo.delay(FreeCADGui.Control.showDialog,self.task)

src/Mod/Draft/Resources/Draft.qrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,4 @@
134134
<file>ui/preferences-oca.ui</file>
135135
<file>ui/TaskShapeString.ui</file>
136136
</qresource>
137-
</RCC>
137+
</RCC>

src/Mod/Draft/Resources/ui/TaskShapeString.ui

Lines changed: 91 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,76 @@
3838
<string/>
3939
</property>
4040
<layout class="QGridLayout" name="gridLayout_4">
41-
<item row="1" column="0">
41+
<item row="0" column="0">
42+
<layout class="QGridLayout" name="gridLayout_7">
43+
<item row="0" column="1">
44+
<widget class="Gui::QuantitySpinBox" name="sbX">
45+
<property name="toolTip">
46+
<string>Enter coordinates or select point with mouse.</string>
47+
</property>
48+
<property name="unit" stdset="0">
49+
<string notr="true"/>
50+
</property>
51+
</widget>
52+
</item>
53+
<item row="1" column="1">
54+
<widget class="Gui::QuantitySpinBox" name="sbY">
55+
<property name="toolTip">
56+
<string>Enter coordinates or select point with mouse.</string>
57+
</property>
58+
<property name="unit" stdset="0">
59+
<string notr="true"/>
60+
</property>
61+
</widget>
62+
</item>
63+
<item row="0" column="0">
64+
<widget class="QLabel" name="labelX">
65+
<property name="text">
66+
<string>X</string>
67+
</property>
68+
</widget>
69+
</item>
70+
<item row="2" column="1">
71+
<widget class="Gui::QuantitySpinBox" name="sbZ">
72+
<property name="toolTip">
73+
<string>Enter coordinates or select point with mouse.</string>
74+
</property>
75+
<property name="unit" stdset="0">
76+
<string notr="true"/>
77+
</property>
78+
</widget>
79+
</item>
80+
<item row="1" column="0">
81+
<widget class="QLabel" name="labelY">
82+
<property name="text">
83+
<string>Y</string>
84+
</property>
85+
</widget>
86+
</item>
87+
<item row="2" column="0">
88+
<widget class="QLabel" name="labelZ">
89+
<property name="text">
90+
<string>Z</string>
91+
</property>
92+
</widget>
93+
</item>
94+
</layout>
95+
</item>
96+
<item row="9" column="0">
97+
<layout class="QGridLayout" name="gridLayout_3">
98+
<item row="1" column="0">
99+
<widget class="QLabel" name="labelFontFile">
100+
<property name="text">
101+
<string>Font file</string>
102+
</property>
103+
</widget>
104+
</item>
105+
<item row="1" column="1">
106+
<widget class="Gui::FileChooser" name="fcFontFile"/>
107+
</item>
108+
</layout>
109+
</item>
110+
<item row="2" column="0">
42111
<layout class="QGridLayout" name="gridLayout_6">
43112
<item row="0" column="1">
44113
<widget class="QLineEdit" name="leString">
@@ -56,7 +125,7 @@
56125
</item>
57126
</layout>
58127
</item>
59-
<item row="7" column="0">
128+
<item row="8" column="0">
60129
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,1">
61130
<item row="0" column="0">
62131
<widget class="QLabel" name="labelHeight">
@@ -83,7 +152,7 @@
83152
</item>
84153
</layout>
85154
</item>
86-
<item row="9" column="0">
155+
<item row="10" column="0">
87156
<spacer name="verticalSpacer_2">
88157
<property name="orientation">
89158
<enum>Qt::Vertical</enum>
@@ -96,64 +165,34 @@
96165
</property>
97166
</spacer>
98167
</item>
99-
<item row="0" column="0">
100-
<layout class="QGridLayout" name="gridLayout_7">
101-
<item row="0" column="1">
102-
<widget class="Gui::QuantitySpinBox" name="sbX">
103-
<property name="unit" stdset="0">
104-
<string notr="true"/>
105-
</property>
106-
</widget>
107-
</item>
108-
<item row="1" column="1">
109-
<widget class="Gui::QuantitySpinBox" name="sbY">
110-
<property name="unit" stdset="0">
111-
<string notr="true"/>
112-
</property>
113-
</widget>
114-
</item>
115-
<item row="0" column="0">
116-
<widget class="QLabel" name="labelX">
117-
<property name="text">
118-
<string>X</string>
168+
<item row="1" column="0">
169+
<layout class="QHBoxLayout" name="horizontalLayout">
170+
<item>
171+
<spacer name="horizontalSpacer">
172+
<property name="orientation">
173+
<enum>Qt::Horizontal</enum>
119174
</property>
120-
</widget>
121-
</item>
122-
<item row="2" column="1">
123-
<widget class="Gui::QuantitySpinBox" name="sbZ">
124-
<property name="unit" stdset="0">
125-
<string notr="true"/>
175+
<property name="sizeHint" stdset="0">
176+
<size>
177+
<width>40</width>
178+
<height>20</height>
179+
</size>
126180
</property>
127-
</widget>
181+
</spacer>
128182
</item>
129-
<item row="1" column="0">
130-
<widget class="QLabel" name="labelY">
131-
<property name="text">
132-
<string>Y</string>
183+
<item>
184+
<widget class="QPushButton" name="pbReset">
185+
<property name="toolTip">
186+
<string>Reset 3d point selection</string>
133187
</property>
134-
</widget>
135-
</item>
136-
<item row="2" column="0">
137-
<widget class="QLabel" name="labelZ">
138-
<property name="text">
139-
<string>Z</string>
188+
<property name="statusTip">
189+
<string/>
140190
</property>
141-
</widget>
142-
</item>
143-
</layout>
144-
</item>
145-
<item row="8" column="0">
146-
<layout class="QGridLayout" name="gridLayout_3">
147-
<item row="1" column="0">
148-
<widget class="QLabel" name="labelFontFile">
149191
<property name="text">
150-
<string>Font file</string>
192+
<string>Reset Point</string>
151193
</property>
152194
</widget>
153195
</item>
154-
<item row="1" column="1">
155-
<widget class="Gui::FileChooser" name="fcFontFile"/>
156-
</item>
157196
</layout>
158197
</item>
159198
</layout>

0 commit comments

Comments
 (0)