Skip to content

Commit

Permalink
Arch: Finished base implementation of Reference object
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Sep 29, 2018
1 parent 1fec4d0 commit 496df34
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 20 deletions.
27 changes: 19 additions & 8 deletions src/Mod/Arch/ArchBuildingPart.py
Expand Up @@ -211,19 +211,19 @@ def makeBuildingPart(objectslist=None,baseobj=None,name="BuildingPart"):


def makeFloor(objectslist=None,baseobj=None,name="Floor"):

"""overwrites ArchFloor.makeFloor"""

obj = makeBuildingPart(objectslist)
obj.Label = name
obj.IfcRole = "Building Storey"
return obj


def makeBuilding(objectslist=None,baseobj=None,name="Building"):

"""overwrites ArchBuilding.makeBuilding"""

obj = makeBuildingPart(objectslist)
obj.Label = name
obj.IfcRole = "Building"
Expand Down Expand Up @@ -396,17 +396,28 @@ def onChanged(self,obj,prop):
def execute(self,obj):

# gather all the child shapes into a compound
shapes = []
for o in obj.Group:
if o.isDerivedFrom("Part::Feature") and o.Shape and (not o.Shape.isNull()):
shapes.append(o.Shape)
shapes = self.getShapes(obj)
if shapes:
import Part
obj.Shape = Part.makeCompound(shapes)

def getShapes(self,obj):

"recursively get the shapes of objects inside this BuildingPart"

shapes = []
if hasattr(obj,"Group"):
for child in obj.Group:
if child.isDerivedFrom("Part::Feature") and child.Shape and (not child.Shape.isNull()):
shapes.append(child.Shape)
elif hasattr(child,"Group"):
shapes.extend(self.getShapes(child))
return shapes

def getSpaces(self,obj):

"gets the list of Spaces that have this object as their Zone property"

g = []
for o in obj.OutList:
if hasattr(o,"Zone"):
Expand Down
112 changes: 102 additions & 10 deletions src/Mod/Arch/ArchReference.py
Expand Up @@ -82,14 +82,15 @@ def __init__(self,obj):
obj.Proxy = self
ArchReference.setProperties(self,obj)
self.Type = "Reference"
self.reload = True

def setProperties(self,obj):

pl = obj.PropertiesList
if not "File" in pl:
obj.addProperty("App::PropertyFile","File","Component",QT_TRANSLATE_NOOP("App::Property","The base file this component is built upon"))
obj.addProperty("App::PropertyFile","File","Reference",QT_TRANSLATE_NOOP("App::Property","The base file this component is built upon"))
if not "Part" in pl:
obj.addProperty("App::PropertyString","Part","Component",QT_TRANSLATE_NOOP("App::Property","The part to use from the base file"))
obj.addProperty("App::PropertyString","Part","Reference",QT_TRANSLATE_NOOP("App::Property","The part to use from the base file"))
self.Type = "Reference"

def onDocumentRestored(self,obj):
Expand All @@ -104,9 +105,14 @@ def __setstate__(self,state):

return None

def onChanged(self,obj,prop):

if prop in ["File","Part"]:
self.reload = True

def execute(self,obj):

if obj.File and obj.Part:
if obj.File and obj.Part and self.reload:
self.parts = self.getPartsList(obj)
if self.parts:
zdoc = zipfile.ZipFile(obj.File)
Expand All @@ -122,7 +128,7 @@ def execute(self,obj):
obj.Shape = shape
else:
print("Part not found in file")
return True
self.reload = False

def getPartsList(self,obj,filename=None):

Expand Down Expand Up @@ -171,6 +177,14 @@ class ViewProviderArchReference:
def __init__(self,vobj):

vobj.Proxy = self
self.setProperties(vobj)

def setProperties(self,vobj):

pl = vobj.PropertiesList
if not "TimeStamp" in pl:
vobj.addProperty("App::PropertyFloat","TimeStamp","Reference",QT_TRANSLATE_NOOP("App::Property","The latest time stamp of the linked file"))
vobj.setEditorMode("TimeStamp",2)

def getIcon(self):

Expand All @@ -188,6 +202,15 @@ def unsetEdit(self,vobj,mode):
FreeCADGui.Control.closeDialog()
return

def attach(self,vobj):

self.Object = vobj.Object
# Check for file change every minute
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.checkChanges)
s = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetInt("ReferenceCheckInterval",60)
self.timer.start(1000*s)

def doubleClicked(self,vobj):

self.setEdit(vobj)
Expand All @@ -200,6 +223,57 @@ def __setstate__(self,state):

return None

def checkChanges(self):

"checks if the linked file has changed"

if hasattr(self,"Object") and self.Object:
try:
f = self.Object.File
except ReferenceError:
f = None
if hasattr(self,"timer"):
self.timer.stop()
del self.timer
if f:
st_mtime = os.stat(self.Object.File).st_mtime
if hasattr(self.Object.ViewObject,"TimeStamp"):
if self.Object.ViewObject.TimeStamp:
if self.Object.ViewObject.TimeStamp != st_mtime:
self.Object.Proxy.reload = True
self.Object.touch()
self.Object.ViewObject.TimeStamp = st_mtime

def onDelete(self):

self.timer.stop()
del self.timer

def setupContextMenu(self,vobj,menu):

action1 = QtGui.QAction(QtGui.QIcon(":/icons/view-refresh.svg"),"Reload reference",menu)
QtCore.QObject.connect(action1,QtCore.SIGNAL("triggered()"),self.onReload)
menu.addAction(action1)
action2 = QtGui.QAction(QtGui.QIcon(":/icons/document-open.svg"),"Open reference",menu)
QtCore.QObject.connect(action2,QtCore.SIGNAL("triggered()"),self.onOpen)
menu.addAction(action2)

def onReload(self):

"reloads the reference object"

if hasattr(self,"Object") and self.Object:
self.Object.Proxy.reload = True
self.Object.touch()
FreeCAD.ActiveDocument.recompute()

def onOpen(self):

"opens the reference file"

if hasattr(self,"Object") and self.Object:
if self.Object.File:
FreeCAD.openDocument(self.Object.File)


class ArchReferenceTaskPanel:
Expand All @@ -217,7 +291,14 @@ def __init__(self,obj):
label1 = QtGui.QLabel("External file:")
layout.addWidget(label1)
self.fileButton = QtGui.QPushButton(self.form)
layout.addWidget(self.fileButton)
self.openButton = QtGui.QPushButton(self.form)
self.openButton.setText("Open")
if not self.obj.File:
self.openButton.setEnabled(False)
l2 = QtGui.QHBoxLayout(self.form)
layout.addLayout(l2)
l2.addWidget(self.fileButton)
l2.addWidget(self.openButton)
label2 = QtGui.QLabel("Part to use:")
layout.addWidget(label2)
if self.obj.File:
Expand All @@ -230,12 +311,13 @@ def __init__(self,obj):
parts = self.obj.Proxy.parts
else:
parts = self.obj.Proxy.getPartsList(self.obj)
keys = parts.keys()
keys = parts.keys()
self.partCombo.addItems(keys)
if self.obj.Part:
if self.obj.Part in keys:
self.partCombo.setCurrentIndex(keys.index(self.obj.Part))
QtCore.QObject.connect(self.fileButton, QtCore.SIGNAL("clicked()"), self.chooseFile)
QtCore.QObject.connect(self.openButton, QtCore.SIGNAL("clicked()"), self.openFile)

def chooseFile(self):

Expand All @@ -255,12 +337,21 @@ def chooseFile(self):
if self.obj.Part in keys:
self.partCombo.setCurrentIndex(keys.index(self.obj.Part))

def openFile(self):
if self.obj.File:
FreeCAD.openDocument(self.obj.File)
FreeCADGui.Control.closeDialog()

def accept(self):

if self.filename and self.partCombo.currentText():
self.obj.File = self.filename
self.obj.Part = self.partCombo.currentText()
FreeCAD.ActiveDocument.recompute()
if self.filename:
if self.filename != self.obj.File:
self.obj.File = self.filename
FreeCAD.ActiveDocument.recompute()
if self.partCombo.currentText():
if self.partCombo.currentText() != self.obj.Part:
self.obj.Part = self.partCombo.currentText()
FreeCAD.ActiveDocument.recompute()
return True


Expand All @@ -274,6 +365,7 @@ def GetResources(self):

return {'Pixmap' : 'Arch_Reference',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_Reference","External reference"),
'Accel': "E, X",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Reference","Creates an external reference object")}

def IsActive(self):
Expand Down
56 changes: 54 additions & 2 deletions src/Mod/Arch/Resources/ui/preferences-arch.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>428</width>
<height>703</height>
<width>446</width>
<height>792</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -113,6 +113,9 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
Expand Down Expand Up @@ -146,6 +149,55 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Interval between file checks for references</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefSpinBox" name="spinBox_2">
<property name="suffix">
<string> seconds</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>60</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>ReferenceCheckInterval</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 496df34

Please sign in to comment.