Arch: Lightweight mode for Arch References
This commit is contained in:
@@ -22,7 +22,14 @@
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import FreeCAD,Draft,ArchCommands,DraftVecUtils,sys,ArchIFC
|
||||
import FreeCAD
|
||||
import Draft
|
||||
import ArchCommands
|
||||
import DraftVecUtils
|
||||
import sys
|
||||
import ArchIFC
|
||||
import tempfile
|
||||
import os
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
from PySide import QtCore, QtGui
|
||||
@@ -35,7 +42,6 @@ else:
|
||||
def QT_TRANSLATE_NOOP(ctxt,txt):
|
||||
return txt
|
||||
# \endcond
|
||||
import sys
|
||||
if sys.version_info.major >= 3:
|
||||
unicode = str
|
||||
|
||||
@@ -335,6 +341,9 @@ class BuildingPart:
|
||||
obj.addProperty("App::PropertyString","Tag","Component",QT_TRANSLATE_NOOP("App::Property","An optional tag for this component"))
|
||||
if not "Shape" in pl:
|
||||
obj.addProperty("Part::PropertyPartShape","Shape","BuildingPart",QT_TRANSLATE_NOOP("App::Property","The shape of this object"))
|
||||
if not "SavedInventor" in pl:
|
||||
obj.addProperty("App::PropertyFileIncluded","SavedInventor","BuildingPart",QT_TRANSLATE_NOOP("App::Property","This property stores an inventor representation for this object"))
|
||||
obj.setEditorMode("SavedInventor",2)
|
||||
|
||||
self.Type = "BuildingPart"
|
||||
|
||||
@@ -368,7 +377,7 @@ class BuildingPart:
|
||||
|
||||
elif prop == "Placement":
|
||||
if hasattr(self,"oldPlacement"):
|
||||
if self.oldPlacement:
|
||||
if self.oldPlacement and (self.oldPlacement != obj.Placement):
|
||||
deltap = obj.Placement.Base.sub(self.oldPlacement.Base)
|
||||
if deltap.Length == 0:
|
||||
deltap = None
|
||||
@@ -399,8 +408,14 @@ class BuildingPart:
|
||||
# gather all the child shapes into a compound
|
||||
shapes = self.getShapes(obj)
|
||||
if shapes:
|
||||
f = []
|
||||
for s in shapes:
|
||||
f.extend(s.Faces)
|
||||
#print("faces before compound:",len(f))
|
||||
import Part
|
||||
obj.Shape = Part.makeCompound(shapes)
|
||||
obj.Shape = Part.makeCompound(f)
|
||||
#print("faces after compound:",len(obj.Shape.Faces))
|
||||
#print("recomputing ",obj.Label)
|
||||
obj.Area = self.getArea(obj)
|
||||
|
||||
def getArea(self,obj):
|
||||
@@ -421,18 +436,9 @@ class BuildingPart:
|
||||
"recursively get the shapes of objects inside this BuildingPart"
|
||||
|
||||
shapes = []
|
||||
if obj.isDerivedFrom("Part::Feature") and obj.Shape and (not obj.Shape.isNull()):
|
||||
shapes.append(obj.Shape)
|
||||
if hasattr(obj,"Group"):
|
||||
for child in obj.Group:
|
||||
shapes.extend(self.getShapes(child))
|
||||
for i in obj.InList:
|
||||
if hasattr(i,"Hosts"):
|
||||
if obj in i.Hosts:
|
||||
shapes.extend(self.getShapes(i))
|
||||
elif hasattr(i,"Host"):
|
||||
if obj == i.Host:
|
||||
shapes.extend(self.getShapes(i))
|
||||
for child in Draft.getGroupContents(obj):
|
||||
if child.isDerivedFrom("Part::Feature"):
|
||||
shapes.extend(child.Shape.Faces)
|
||||
return shapes
|
||||
|
||||
def getSpaces(self,obj):
|
||||
@@ -514,7 +520,6 @@ class ViewProviderBuildingPart:
|
||||
vobj.ChildrenLineColor = (float((c>>24)&0xFF)/255.0,float((c>>16)&0xFF)/255.0,float((c>>8)&0xFF)/255.0,0.0)
|
||||
if not "ChildrenTransparency" in pl:
|
||||
vobj.addProperty("App::PropertyPercent","ChildrenTransparency","Children",QT_TRANSLATE_NOOP("App::Property","The transparency of child objects"))
|
||||
|
||||
if not "CutView" in pl:
|
||||
vobj.addProperty("App::PropertyBool","CutView","Clip",QT_TRANSLATE_NOOP("App::Property","Cut the view above this level"))
|
||||
if not "CutMargin" in pl:
|
||||
@@ -522,6 +527,8 @@ class ViewProviderBuildingPart:
|
||||
vobj.CutMargin = 1600
|
||||
if not "AutoCutView" in pl:
|
||||
vobj.addProperty("App::PropertyBool","AutoCutView","Clip",QT_TRANSLATE_NOOP("App::Property","Turn cutting on when activating this level"))
|
||||
if not "SaveInventor" in pl:
|
||||
vobj.addProperty("App::PropertyBool","SaveInventor","BuildingPart",QT_TRANSLATE_NOOP("App::Property","If this is enabled, the inventor representation of this object will be saved in the FreeCAD file, allowing to reference it in other file sin lightweight mode."))
|
||||
|
||||
def onDocumentRestored(self,vobj):
|
||||
|
||||
@@ -591,6 +598,9 @@ class ViewProviderBuildingPart:
|
||||
if len(colors) == len(obj.Shape.Faces):
|
||||
if colors != obj.ViewObject.DiffuseColor:
|
||||
obj.ViewObject.DiffuseColor = colors
|
||||
self.writeInventor(obj)
|
||||
#else:
|
||||
#print("color mismatch:",len(colors),"colors,",len(obj.Shape.Faces),"faces")
|
||||
elif prop == "Group":
|
||||
self.onChanged(obj.ViewObject,"ChildrenOverride")
|
||||
elif prop == "Label":
|
||||
@@ -601,23 +611,14 @@ class ViewProviderBuildingPart:
|
||||
"recursively get the colors of objects inside this BuildingPart"
|
||||
|
||||
colors = []
|
||||
if obj.isDerivedFrom("Part::Feature") and obj.Shape and (not obj.Shape.isNull()):
|
||||
if hasattr(obj.ViewObject,"DiffuseColor") and (len(obj.ViewObject.DiffuseColor) == len(obj.Shape.Faces)):
|
||||
colors.extend(obj.ViewObject.DiffuseColor)
|
||||
elif hasattr(obj.ViewObject,"ShapeColor"):
|
||||
c = obj.ViewObject.ShapeColor[:3]+(obj.ViewObject.Transparency/100.0,)
|
||||
for i in range(len(obj.Shape.Faces)):
|
||||
colors.append(c)
|
||||
if hasattr(obj,"Group"):
|
||||
for child in obj.Group:
|
||||
colors.extend(self.getColors(child))
|
||||
for i in obj.InList:
|
||||
if hasattr(i,"Hosts"):
|
||||
if obj in i.Hosts:
|
||||
colors.extend(self.getColors(i))
|
||||
elif hasattr(i,"Host"):
|
||||
if obj == i.Host:
|
||||
colors.extend(self.getColors(i))
|
||||
for child in Draft.getGroupContents(obj):
|
||||
if child.isDerivedFrom("Part::Feature"):
|
||||
if len(child.ViewObject.DiffuseColor) == len(child.Shape.Faces):
|
||||
colors.extend(child.ViewObject.DiffuseColor)
|
||||
else:
|
||||
c = child.ViewObject.ShapeColor[:3]+(child.ViewObject.Transparency/100.0,)
|
||||
for i in range(len(child.Shape.Faces)):
|
||||
colors.append(c)
|
||||
return colors
|
||||
|
||||
def onChanged(self,vobj,prop):
|
||||
@@ -728,6 +729,8 @@ class ViewProviderBuildingPart:
|
||||
# turn clipping off when turning the object off
|
||||
if hasattr(vobj,"Visibility") and not(vobj.Visibility) and hasattr(vobj,"CutView"):
|
||||
vobj.CutView = False
|
||||
elif prop == "SaveInventor":
|
||||
self.writeInventor(vobj.Object)
|
||||
|
||||
def onDelete(self,vobj,subelements):
|
||||
|
||||
@@ -737,6 +740,7 @@ class ViewProviderBuildingPart:
|
||||
for o in Draft.getGroupContents(vobj.Object.Group,walls=True):
|
||||
if hasattr(o.ViewObject,"Lighting"):
|
||||
o.ViewObject.Lighting = "Two side"
|
||||
return True
|
||||
|
||||
def doubleClicked(self,vobj):
|
||||
|
||||
@@ -865,5 +869,36 @@ class ViewProviderBuildingPart:
|
||||
def __setstate__(self,state):
|
||||
return None
|
||||
|
||||
def writeInventor(self,obj):
|
||||
|
||||
def callback(match):
|
||||
return next(callback.v)
|
||||
|
||||
if hasattr(obj.ViewObject,"SaveInventor") and obj.ViewObject.SaveInventor:
|
||||
if obj.Shape and obj.Shape.Faces and hasattr(obj,"SavedInventor"):
|
||||
colors = obj.ViewObject.DiffuseColor
|
||||
if len(colors) != len(obj.Shape.Faces):
|
||||
print("Debug: Colors mismatch in",obj.Label)
|
||||
colors = None
|
||||
iv = self.Object.Shape.writeInventor()
|
||||
import re
|
||||
if colors:
|
||||
if len(re.findall("IndexedFaceSet",iv)) == len(obj.Shape.Faces):
|
||||
# convert colors to iv representations
|
||||
colors = ["Material { diffuseColor "+str(color[0])+" "+str(color[1])+" "+str(color[2])+"}\n IndexedFaceSet" for color in colors]
|
||||
# replace
|
||||
callback.v=iter(colors)
|
||||
iv = re.sub("IndexedFaceSet",callback,iv)
|
||||
else:
|
||||
print("Debug: IndexedFaceSet mismatch in",obj.Label)
|
||||
# save embedded file
|
||||
tf = tempfile.mkstemp(prefix=obj.Name,suffix=".iv")[1]
|
||||
f = open(tf,"w")
|
||||
f.write(iv)
|
||||
f.close()
|
||||
obj.SavedInventor = tf
|
||||
os.remove(tf)
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('Arch_BuildingPart',CommandBuildingPart())
|
||||
|
||||
Reference in New Issue
Block a user