Added RFE 583 - remove coin3d image loading from Draft
This commit is contained in:
parent
07d7526777
commit
65f484d7f1
|
@ -278,6 +278,47 @@ def select(objs=None):
|
|||
for obj in objs:
|
||||
FreeCADGui.Selection.addSelection(obj)
|
||||
|
||||
def loadTexture(filename):
|
||||
"loadTexture(filename): returns a SoSFImage from a file"
|
||||
from pivy import coin
|
||||
from PyQt4 import QtGui
|
||||
try:
|
||||
p = QtGui.QImage(filename)
|
||||
size = coin.SbVec2s(p.width(), p.height())
|
||||
buffersize = p.numBytes()
|
||||
numcomponents = int (buffersize / ( size[0] * size[1] ))
|
||||
|
||||
img = coin.SoSFImage()
|
||||
width = size[0]
|
||||
height = size[1]
|
||||
bytes = ""
|
||||
|
||||
for y in range(height):
|
||||
#line = width*numcomponents*(height-(y));
|
||||
for x in range(width):
|
||||
rgb = p.pixel(x,y)
|
||||
if numcomponents == 1:
|
||||
bytes = bytes + chr(QtGui.qGray( rgb ))
|
||||
elif numcomponents == 2:
|
||||
bytes = bytes + chr(QtGui.qGray( rgb ))
|
||||
bytes = bytes + chr(QtGui.qAlpha( rgb ))
|
||||
elif numcomponents == 3:
|
||||
bytes = bytes + chr(QtGui.qRed( rgb ))
|
||||
bytes = bytes + chr(QtGui.qGreen( rgb ))
|
||||
bytes = bytes + chr(QtGui.qBlue( rgb ))
|
||||
elif numcomponents == 4:
|
||||
bytes = bytes + chr(QtGui.qRed( rgb ))
|
||||
bytes = bytes + chr(QtGui.qGreen( rgb ))
|
||||
bytes = bytes + chr(QtGui.qBlue( rgb ))
|
||||
bytes = bytes + chr(QtGui.qAlpha( rgb ))
|
||||
#line += numcomponents
|
||||
|
||||
img.setValue(size, numcomponents, bytes)
|
||||
except:
|
||||
return None
|
||||
else:
|
||||
return img
|
||||
|
||||
def makeCircle(radius, placement=None, face=True, startangle=None, endangle=None, support=None):
|
||||
'''makeCircle(radius,[placement,face,startangle,endangle])
|
||||
or makeCircle(edge,[face]):
|
||||
|
@ -1375,21 +1416,22 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
|||
# TODO add Radius constraits
|
||||
ok = True
|
||||
elif tp == "Rectangle":
|
||||
for edge in obj.Shape.Edges:
|
||||
nobj.addGeometry(edge.Curve)
|
||||
if autoconstraints:
|
||||
last = nobj.GeometryCount - 1
|
||||
segs = [last-3,last-2,last-1,last]
|
||||
if obj.Placement.Rotation.Q == (0,0,0,1):
|
||||
nobj.addConstraint(Constraint("Coincident",last-3,EndPoint,last-2,StartPoint))
|
||||
nobj.addConstraint(Constraint("Coincident",last-2,EndPoint,last-1,StartPoint))
|
||||
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,last,StartPoint))
|
||||
nobj.addConstraint(Constraint("Coincident",last,EndPoint,last-3,StartPoint))
|
||||
nobj.addConstraint(Constraint("Horizontal",last-3))
|
||||
nobj.addConstraint(Constraint("Vertical",last-2))
|
||||
nobj.addConstraint(Constraint("Horizontal",last-1))
|
||||
nobj.addConstraint(Constraint("Vertical",last))
|
||||
ok = True
|
||||
if obj.FilletRadius == 0:
|
||||
for edge in obj.Shape.Edges:
|
||||
nobj.addGeometry(edge.Curve)
|
||||
if autoconstraints:
|
||||
last = nobj.GeometryCount - 1
|
||||
segs = [last-3,last-2,last-1,last]
|
||||
if obj.Placement.Rotation.Q == (0,0,0,1):
|
||||
nobj.addConstraint(Constraint("Coincident",last-3,EndPoint,last-2,StartPoint))
|
||||
nobj.addConstraint(Constraint("Coincident",last-2,EndPoint,last-1,StartPoint))
|
||||
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,last,StartPoint))
|
||||
nobj.addConstraint(Constraint("Coincident",last,EndPoint,last-3,StartPoint))
|
||||
nobj.addConstraint(Constraint("Horizontal",last-3))
|
||||
nobj.addConstraint(Constraint("Vertical",last-2))
|
||||
nobj.addConstraint(Constraint("Horizontal",last-1))
|
||||
nobj.addConstraint(Constraint("Vertical",last))
|
||||
ok = True
|
||||
elif tp in ["Wire","Polygon"]:
|
||||
closed = False
|
||||
if tp == "Polygon":
|
||||
|
@ -1410,7 +1452,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
|||
if closed:
|
||||
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
|
||||
ok = True
|
||||
elif obj.isDerivedFrom("Part::Feature"):
|
||||
if (not ok) and obj.isDerivedFrom("Part::Feature"):
|
||||
if fcgeo.hasOnlyWires(obj.Shape):
|
||||
for w in obj.Shape.Wires:
|
||||
for edge in fcgeo.sortEdges(w.Edges):
|
||||
|
@ -1543,8 +1585,6 @@ class _ViewProviderDraft:
|
|||
|
||||
def __init__(self, obj):
|
||||
obj.Proxy = self
|
||||
obj.addProperty("App::PropertyEnumeration","DrawStyle","Base",
|
||||
"The line style of this object")
|
||||
self.Object = obj.Object
|
||||
|
||||
def attach(self, obj):
|
||||
|
@ -2148,9 +2188,11 @@ class _ViewProviderRectangle(_ViewProviderDraft):
|
|||
if prop == "TextureImage":
|
||||
r = vp.RootNode
|
||||
if os.path.exists(vp.TextureImage):
|
||||
self.texture = coin.SoTexture2()
|
||||
self.texture.filename = str(vp.TextureImage)
|
||||
r.insertChild(self.texture,1)
|
||||
im = loadTexture(vp.TextureImage)
|
||||
if im:
|
||||
self.texture = coin.SoTexture2()
|
||||
self.texture.image = im
|
||||
r.insertChild(self.texture,1)
|
||||
else:
|
||||
if self.texture:
|
||||
r.removeChild(self.texture)
|
||||
|
|
Loading…
Reference in New Issue
Block a user