Skip to content

Commit

Permalink
Fix ShapeString attachment to Face
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and yorikvanhavre committed Feb 19, 2019
1 parent 99b289e commit dace2f3
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 72 deletions.
84 changes: 65 additions & 19 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -40,6 +40,7 @@
'''

import FreeCAD, FreeCADGui, os, Draft, sys, DraftVecUtils, math
import DraftTools

try:
from PySide import QtCore, QtGui, QtSvg
Expand Down Expand Up @@ -2460,42 +2461,87 @@ def __init__(self):
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"):
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -2227,10 +2227,15 @@ def GetResources(self):
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)
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Draft/Resources/Draft.qrc
Expand Up @@ -134,4 +134,4 @@
<file>ui/preferences-oca.ui</file>
<file>ui/TaskShapeString.ui</file>
</qresource>
</RCC>
</RCC>
143 changes: 91 additions & 52 deletions src/Mod/Draft/Resources/ui/TaskShapeString.ui
Expand Up @@ -38,7 +38,76 @@
<string/>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="1">
<widget class="Gui::QuantitySpinBox" name="sbX">
<property name="toolTip">
<string>Enter coordinates or select point with mouse.</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::QuantitySpinBox" name="sbY">
<property name="toolTip">
<string>Enter coordinates or select point with mouse.</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelX">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::QuantitySpinBox" name="sbZ">
<property name="toolTip">
<string>Enter coordinates or select point with mouse.</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelY">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelZ">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="9" column="0">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="labelFontFile">
<property name="text">
<string>Font file</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::FileChooser" name="fcFontFile"/>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="1">
<widget class="QLineEdit" name="leString">
Expand All @@ -56,7 +125,7 @@
</item>
</layout>
</item>
<item row="7" column="0">
<item row="8" column="0">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,1">
<item row="0" column="0">
<widget class="QLabel" name="labelHeight">
Expand All @@ -83,7 +152,7 @@
</item>
</layout>
</item>
<item row="9" column="0">
<item row="10" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -96,64 +165,34 @@
</property>
</spacer>
</item>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="1">
<widget class="Gui::QuantitySpinBox" name="sbX">
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::QuantitySpinBox" name="sbY">
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelX">
<property name="text">
<string>X</string>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::QuantitySpinBox" name="sbZ">
<property name="unit" stdset="0">
<string notr="true"/>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelY">
<property name="text">
<string>Y</string>
<item>
<widget class="QPushButton" name="pbReset">
<property name="toolTip">
<string>Reset 3d point selection</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelZ">
<property name="text">
<string>Z</string>
<property name="statusTip">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="0">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="labelFontFile">
<property name="text">
<string>Font file</string>
<string>Reset Point</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::FileChooser" name="fcFontFile"/>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit dace2f3

Please sign in to comment.