Draft: small fixes
+ added svg scaling capability to Draft.loadTexture() + late-loading of svg patterns + fixed warnings in Draft Drawing tool
This commit is contained in:
parent
0883e885b3
commit
321938c1f5
|
@ -158,6 +158,8 @@ def getRealName(name):
|
|||
def getType(obj):
|
||||
"getType(object): returns the Draft type of the given object"
|
||||
import Part
|
||||
if not obj:
|
||||
return None
|
||||
if isinstance(obj,Part.Shape):
|
||||
return "Shape"
|
||||
if "Proxy" in obj.PropertiesList:
|
||||
|
@ -404,13 +406,38 @@ def select(objs=None):
|
|||
for obj in objs:
|
||||
FreeCADGui.Selection.addSelection(obj)
|
||||
|
||||
def loadTexture(filename):
|
||||
"loadTexture(filename): returns a SoSFImage from a file"
|
||||
def loadSvgPatterns():
|
||||
"loads the default Draft SVG patterns and custom patters if available"
|
||||
import importSVG
|
||||
FreeCAD.svgpatterns = importSVG.getContents(Draft_rc.qt_resource_data,'pattern',True)
|
||||
altpat = getParam("patternFile")
|
||||
if os.path.isdir(altpat):
|
||||
for f in os.listdir(altpat):
|
||||
if f[-4:].upper() == ".SVG":
|
||||
p = importSVG.getContents(altpat+os.sep+f,'pattern')
|
||||
if p:
|
||||
FreeCAD.svgpatterns.update(p)
|
||||
|
||||
def loadTexture(filename,size=None):
|
||||
"""loadTexture(filename,[size]): returns a SoSFImage from a file. If size
|
||||
is defined (an int or a tuple), and provided the input image is a png file,
|
||||
it will be scaled to match the given size."""
|
||||
if gui:
|
||||
from pivy import coin
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4 import QtGui,QtSvg
|
||||
try:
|
||||
p = QtGui.QImage(filename)
|
||||
if size and (".svg" in filename.lower()):
|
||||
# we need to resize
|
||||
if isinstance(size,int):
|
||||
size = (size,size)
|
||||
svgr = QtSvg.QSvgRenderer(filename)
|
||||
p = QtGui.QImage(size[0],size[1],QtGui.QImage.Format_ARGB32_Premultiplied)
|
||||
pa = QtGui.QPainter()
|
||||
pa.begin(p)
|
||||
svgr.render(pa)
|
||||
pa.end()
|
||||
else:
|
||||
p = QtGui.QImage(filename)
|
||||
size = coin.SbVec2s(p.width(), p.height())
|
||||
buffersize = p.numBytes()
|
||||
numcomponents = int (buffersize / ( size[0] * size[1] ))
|
||||
|
@ -442,6 +469,7 @@ def loadTexture(filename):
|
|||
|
||||
img.setValue(size, numcomponents, bytes)
|
||||
except:
|
||||
print "Draft: unable to load texture"
|
||||
return None
|
||||
else:
|
||||
return img
|
||||
|
@ -1330,6 +1358,8 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
return Vector(lx,ly,0)
|
||||
|
||||
def getPattern(pat):
|
||||
if not hasattr(FreeCAD,"svgpatterns"):
|
||||
loadSvgPatterns()
|
||||
if pat in FreeCAD.svgpatterns:
|
||||
return FreeCAD.svgpatterns[pat]
|
||||
return ''
|
||||
|
@ -1383,8 +1413,11 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
svg += ';fill:' + fill + '"'
|
||||
svg += '/>\n'
|
||||
return svg
|
||||
|
||||
if not obj:
|
||||
pass
|
||||
|
||||
if getType(obj) == "Dimension":
|
||||
elif getType(obj) == "Dimension":
|
||||
p1,p2,p3,p4,tbase,norm,rot = obj.ViewObject.Proxy.calcGeom(obj)
|
||||
dimText = getParam("dimPrecision")
|
||||
dimText = "%."+str(dimText)+"f"
|
||||
|
@ -3322,6 +3355,8 @@ class _DrawingView(_DraftObject):
|
|||
obj.addProperty("App::PropertyLink","Source","Base","The linked object")
|
||||
obj.addProperty("App::PropertyEnumeration","FillStyle","Drawing View","Shape Fill Style")
|
||||
fills = ['shape color']
|
||||
if not hasattr(FreeCAD,"svgpatterns"):
|
||||
loadSvgPatterns()
|
||||
for f in FreeCAD.svgpatterns.keys():
|
||||
fills.append(f)
|
||||
obj.FillStyle = fills
|
||||
|
|
|
@ -563,7 +563,6 @@ class DraftToolBar:
|
|||
|
||||
def redraw(self):
|
||||
"utility function that is performed after each clicked point"
|
||||
print "redrawing"
|
||||
self.checkLocal()
|
||||
|
||||
def selectPlaneUi(self):
|
||||
|
|
|
@ -29,7 +29,7 @@ __url__ = "http://free-cad.sourceforge.net"
|
|||
# Generic stuff
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
import os, FreeCAD, FreeCADGui, WorkingPlane, math, re, importSVG, Draft, Draft_rc, DraftVecUtils
|
||||
import os, FreeCAD, FreeCADGui, WorkingPlane, math, re, Draft, Draft_rc, DraftVecUtils
|
||||
from FreeCAD import Vector
|
||||
from DraftGui import todo,QtCore,QtGui
|
||||
from DraftSnap import *
|
||||
|
@ -43,16 +43,6 @@ from pivy import coin
|
|||
# update the translation engine
|
||||
FreeCADGui.updateLocale()
|
||||
|
||||
# loads the fill patterns
|
||||
FreeCAD.svgpatterns = importSVG.getContents(Draft_rc.qt_resource_data,'pattern',True)
|
||||
altpat = Draft.getParam("patternFile")
|
||||
if os.path.isdir(altpat):
|
||||
for f in os.listdir(altpat):
|
||||
if f[-4:].upper() == ".SVG":
|
||||
p = importSVG.getContents(altpat+os.sep+f,'pattern')
|
||||
if p:
|
||||
FreeCAD.svgpatterns.update(p)
|
||||
|
||||
# sets the default working plane
|
||||
plane = WorkingPlane.plane()
|
||||
FreeCAD.DraftWorkingPlane = plane
|
||||
|
|
Loading…
Reference in New Issue
Block a user