Draft: support for non-ascii characters in Draft texts and dimensions
This commit is contained in:
parent
a4ce94f196
commit
a39397cf89
|
@ -1,3 +1,5 @@
|
|||
# -*- coding: utf8 -*-
|
||||
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2009, 2010 *
|
||||
|
@ -610,10 +612,10 @@ def makeDimension(p1,p2,p3=None,p4=None):
|
|||
obj.Base = p1
|
||||
if p3 == "radius":
|
||||
obj.LinkedVertices = [p2,1,1]
|
||||
obj.ViewObject.Override = "Rdim"
|
||||
obj.ViewObject.Override = "R$dim"
|
||||
elif p3 == "diameter":
|
||||
obj.LinkedVertices = [p2,2,1]
|
||||
obj.ViewObject.Override = "Ddim"
|
||||
obj.ViewObject.Override = "Ø$dim"
|
||||
p3 = p4
|
||||
if not p3:
|
||||
p3 = obj.Base.Shape.Edges[0].Curve.Center.add(Vector(1,0,0))
|
||||
|
@ -747,7 +749,7 @@ def makeText(stringslist,point=Vector(0,0,0),screen=False):
|
|||
typecheck([(point,Vector)], "makeText")
|
||||
if not isinstance(stringslist,list): stringslist = [stringslist]
|
||||
textbuffer = []
|
||||
for l in stringslist: textbuffer.append(unicode(l).encode('utf-8'))
|
||||
for l in stringslist: textbuffer.append(l.decode("utf8").encode('latin1'))
|
||||
obj=FreeCAD.ActiveDocument.addObject("App::Annotation","Text")
|
||||
obj.LabelText=textbuffer
|
||||
obj.Position=point
|
||||
|
@ -2725,7 +2727,7 @@ class _ViewProviderDimension(_ViewProviderDraft):
|
|||
self.onChanged(obj,"FontName")
|
||||
|
||||
def updateData(self, obj, prop):
|
||||
if not prop in ["Start","End","Dimline","DisplayMode","ExtLines","FontSize"]:
|
||||
if not prop in ["Start","End","Dimline","DisplayMode","ExtLines","FontSize","Override"]:
|
||||
return
|
||||
from pivy import coin
|
||||
try:
|
||||
|
@ -2754,7 +2756,7 @@ class _ViewProviderDimension(_ViewProviderDraft):
|
|||
p1,p2,p3,p4,tbase,norm,rot = self.calcGeom(obj)
|
||||
# print p1,p2,p3,p4,tbase,norm,rot
|
||||
if 'Override' in obj.ViewObject.PropertiesList:
|
||||
text = str(obj.ViewObject.Override)
|
||||
text = unicode(obj.ViewObject.Override).encode("latin1")
|
||||
dtext = getParam("dimPrecision")
|
||||
dtext = "%."+str(dtext)+"f"
|
||||
dtext = (dtext % p3.sub(p2).Length)
|
||||
|
@ -3026,7 +3028,7 @@ class _ViewProviderAngularDimension(_ViewProviderDraft):
|
|||
self.arc = arc
|
||||
self.selnode.addChild(self.arc)
|
||||
if 'Override' in obj.ViewObject.PropertiesList:
|
||||
text = str(obj.ViewObject.Override)
|
||||
text = unicode(obj.ViewObject.Override).encode("latin1")
|
||||
dtext = getParam("dimPrecision")
|
||||
dtext = "%."+str(dtext)+"f"
|
||||
if obj.LastAngle > obj.FirstAngle:
|
||||
|
|
|
@ -1447,6 +1447,7 @@ class Text(Creator):
|
|||
self.ui.sourceCmd = self
|
||||
self.ui.pointUi(name)
|
||||
self.call = self.view.addEventCallback("SoEvent",self.action)
|
||||
self.active = True
|
||||
self.ui.xValue.setFocus()
|
||||
self.ui.xValue.selectAll()
|
||||
msg(translate("draft", "Pick location point:\n"))
|
||||
|
@ -1466,7 +1467,7 @@ class Text(Creator):
|
|||
for l in self.text:
|
||||
if len(tx) > 1:
|
||||
tx += ','
|
||||
tx += '"'+str(l)+'"'
|
||||
tx += '"'+str(unicode(l).encode("utf8"))+'"'
|
||||
tx += ']'
|
||||
self.commit(translate("draft","Create Text"),
|
||||
['import Draft',
|
||||
|
@ -1480,10 +1481,13 @@ class Text(Creator):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
|
||||
self.point,ctrlPoint,info = getPoint(self,arg)
|
||||
if self.active:
|
||||
self.point,ctrlPoint,info = getPoint(self,arg)
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
if self.point:
|
||||
self.active = False
|
||||
FreeCADGui.Snapper.off()
|
||||
self.node.append(self.point)
|
||||
self.ui.textUi()
|
||||
self.ui.textValue.setFocus()
|
||||
|
@ -1800,6 +1804,7 @@ class ShapeString(Creator):
|
|||
self.text = ''
|
||||
self.ui.sourceCmd = self
|
||||
self.ui.pointUi(name)
|
||||
self.active = True
|
||||
self.call = self.view.addEventCallback("SoEvent",self.action)
|
||||
self.ui.xValue.setFocus()
|
||||
self.ui.xValue.selectAll()
|
||||
|
@ -1847,11 +1852,14 @@ class ShapeString(Creator):
|
|||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
|
||||
self.point,ctrlPoint,info = getPoint(self,arg)
|
||||
if self.active:
|
||||
self.point,ctrlPoint,info = getPoint(self,arg)
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
if self.point:
|
||||
self.node.append(self.point)
|
||||
self.active = False
|
||||
FreeCADGui.Snapper.off()
|
||||
self.ui.SSUi()
|
||||
|
||||
def numericInput(self,numx,numy,numz):
|
||||
|
|
|
@ -86,34 +86,36 @@ def deformat(text):
|
|||
"removes weird formats in texts and wipes UTF characters"
|
||||
# remove ACAD string formatation
|
||||
#t = re.sub('{([^!}]([^}]|\n)*)}', '', text)
|
||||
print "input text: ",text
|
||||
t = text.strip("{}")
|
||||
t = re.sub("\\\.*?;","",t)
|
||||
# replace UTF codes
|
||||
t = re.sub("\\\\U\+00e9","e",t)
|
||||
t = re.sub("\\\\U\+00e1","a",t)
|
||||
t = re.sub("\\\\U\+00e7","c",t)
|
||||
t = re.sub("\\\\U\+00e3","a",t)
|
||||
t = re.sub("\\\\U\+00e0","a",t)
|
||||
t = re.sub("\\\\U\+00c1","A",t)
|
||||
t = re.sub("\\\\U\+00ea","e",t)
|
||||
#t = re.sub("\\\\U\+00e9","e",t)
|
||||
#t = re.sub("\\\\U\+00e1","a",t)
|
||||
#t = re.sub("\\\\U\+00e7","c",t)
|
||||
#t = re.sub("\\\\U\+00e3","a",t)
|
||||
#t = re.sub("\\\\U\+00e0","a",t)
|
||||
#t = re.sub("\\\\U\+00c1","A",t)
|
||||
#t = re.sub("\\\\U\+00ea","e",t)
|
||||
# replace non-UTF chars
|
||||
t = re.sub("ã","a",t)
|
||||
t = re.sub("ç","c",t)
|
||||
t = re.sub("õ","o",t)
|
||||
t = re.sub("à","a",t)
|
||||
t = re.sub("á","a",t)
|
||||
t = re.sub("â","a",t)
|
||||
t = re.sub("é","e",t)
|
||||
t = re.sub("è","e",t)
|
||||
t = re.sub("ê","e",t)
|
||||
t = re.sub("í","i",t)
|
||||
t = re.sub("Á","A",t)
|
||||
t = re.sub("À","A",t)
|
||||
t = re.sub("É","E",t)
|
||||
t = re.sub("È","E",t)
|
||||
#t = re.sub("ã","a",t)
|
||||
#t = re.sub("ç","c",t)
|
||||
#t = re.sub("õ","o",t)
|
||||
#t = re.sub("à","a",t)
|
||||
#t = re.sub("á","a",t)
|
||||
#t = re.sub("â","a",t)
|
||||
#t = re.sub("é","e",t)
|
||||
#t = re.sub("è","e",t)
|
||||
#t = re.sub("ê","e",t)
|
||||
#t = re.sub("í","i",t)
|
||||
#t = re.sub("Á","A",t)
|
||||
#t = re.sub("À","A",t)
|
||||
#t = re.sub("É","E",t)
|
||||
#t = re.sub("È","E",t)
|
||||
# replace degrees, diameters chars
|
||||
t = re.sub('%%d','°',t)
|
||||
t = re.sub('%%c','Ø',t)
|
||||
print "output text: ",t
|
||||
return t
|
||||
|
||||
def locateLayer(wantedLayer):
|
||||
|
|
Loading…
Reference in New Issue
Block a user