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:
|
for obj in objs:
|
||||||
FreeCADGui.Selection.addSelection(obj)
|
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):
|
def makeCircle(radius, placement=None, face=True, startangle=None, endangle=None, support=None):
|
||||||
'''makeCircle(radius,[placement,face,startangle,endangle])
|
'''makeCircle(radius,[placement,face,startangle,endangle])
|
||||||
or makeCircle(edge,[face]):
|
or makeCircle(edge,[face]):
|
||||||
|
@ -1375,21 +1416,22 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
# TODO add Radius constraits
|
# TODO add Radius constraits
|
||||||
ok = True
|
ok = True
|
||||||
elif tp == "Rectangle":
|
elif tp == "Rectangle":
|
||||||
for edge in obj.Shape.Edges:
|
if obj.FilletRadius == 0:
|
||||||
nobj.addGeometry(edge.Curve)
|
for edge in obj.Shape.Edges:
|
||||||
if autoconstraints:
|
nobj.addGeometry(edge.Curve)
|
||||||
last = nobj.GeometryCount - 1
|
if autoconstraints:
|
||||||
segs = [last-3,last-2,last-1,last]
|
last = nobj.GeometryCount - 1
|
||||||
if obj.Placement.Rotation.Q == (0,0,0,1):
|
segs = [last-3,last-2,last-1,last]
|
||||||
nobj.addConstraint(Constraint("Coincident",last-3,EndPoint,last-2,StartPoint))
|
if obj.Placement.Rotation.Q == (0,0,0,1):
|
||||||
nobj.addConstraint(Constraint("Coincident",last-2,EndPoint,last-1,StartPoint))
|
nobj.addConstraint(Constraint("Coincident",last-3,EndPoint,last-2,StartPoint))
|
||||||
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,last,StartPoint))
|
nobj.addConstraint(Constraint("Coincident",last-2,EndPoint,last-1,StartPoint))
|
||||||
nobj.addConstraint(Constraint("Coincident",last,EndPoint,last-3,StartPoint))
|
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,last,StartPoint))
|
||||||
nobj.addConstraint(Constraint("Horizontal",last-3))
|
nobj.addConstraint(Constraint("Coincident",last,EndPoint,last-3,StartPoint))
|
||||||
nobj.addConstraint(Constraint("Vertical",last-2))
|
nobj.addConstraint(Constraint("Horizontal",last-3))
|
||||||
nobj.addConstraint(Constraint("Horizontal",last-1))
|
nobj.addConstraint(Constraint("Vertical",last-2))
|
||||||
nobj.addConstraint(Constraint("Vertical",last))
|
nobj.addConstraint(Constraint("Horizontal",last-1))
|
||||||
ok = True
|
nobj.addConstraint(Constraint("Vertical",last))
|
||||||
|
ok = True
|
||||||
elif tp in ["Wire","Polygon"]:
|
elif tp in ["Wire","Polygon"]:
|
||||||
closed = False
|
closed = False
|
||||||
if tp == "Polygon":
|
if tp == "Polygon":
|
||||||
|
@ -1410,7 +1452,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
if closed:
|
if closed:
|
||||||
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
|
nobj.addConstraint(Constraint("Coincident",last-1,EndPoint,segs[0],StartPoint))
|
||||||
ok = True
|
ok = True
|
||||||
elif obj.isDerivedFrom("Part::Feature"):
|
if (not ok) and obj.isDerivedFrom("Part::Feature"):
|
||||||
if fcgeo.hasOnlyWires(obj.Shape):
|
if fcgeo.hasOnlyWires(obj.Shape):
|
||||||
for w in obj.Shape.Wires:
|
for w in obj.Shape.Wires:
|
||||||
for edge in fcgeo.sortEdges(w.Edges):
|
for edge in fcgeo.sortEdges(w.Edges):
|
||||||
|
@ -1543,8 +1585,6 @@ class _ViewProviderDraft:
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
obj.Proxy = self
|
obj.Proxy = self
|
||||||
obj.addProperty("App::PropertyEnumeration","DrawStyle","Base",
|
|
||||||
"The line style of this object")
|
|
||||||
self.Object = obj.Object
|
self.Object = obj.Object
|
||||||
|
|
||||||
def attach(self, obj):
|
def attach(self, obj):
|
||||||
|
@ -2148,9 +2188,11 @@ class _ViewProviderRectangle(_ViewProviderDraft):
|
||||||
if prop == "TextureImage":
|
if prop == "TextureImage":
|
||||||
r = vp.RootNode
|
r = vp.RootNode
|
||||||
if os.path.exists(vp.TextureImage):
|
if os.path.exists(vp.TextureImage):
|
||||||
self.texture = coin.SoTexture2()
|
im = loadTexture(vp.TextureImage)
|
||||||
self.texture.filename = str(vp.TextureImage)
|
if im:
|
||||||
r.insertChild(self.texture,1)
|
self.texture = coin.SoTexture2()
|
||||||
|
self.texture.image = im
|
||||||
|
r.insertChild(self.texture,1)
|
||||||
else:
|
else:
|
||||||
if self.texture:
|
if self.texture:
|
||||||
r.removeChild(self.texture)
|
r.removeChild(self.texture)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user