Skip to content
Permalink
Browse files

Fix ShapeString attachment to Face

  • Loading branch information...
WandererFan authored and yorikvanhavre committed Feb 18, 2019
1 parent 99b289e commit dace2f39cfb09d094e61563570671cf97c37cb17
@@ -40,6 +40,7 @@
'''

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

try:
from PySide import QtCore, QtGui, QtSvg
@@ -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"):
@@ -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)
@@ -134,4 +134,4 @@
<file>ui/preferences-oca.ui</file>
<file>ui/TaskShapeString.ui</file>
</qresource>
</RCC>
</RCC>
@@ -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">
@@ -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">
@@ -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>
@@ -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>

0 comments on commit dace2f3

Please sign in to comment.
You can’t perform that action at this time.