Arch: Enable materials hierarchy

This commit is contained in:
Yorik van Havre
2018-07-20 17:59:39 -03:00
parent 9066154407
commit 7abbcf529a
2 changed files with 85 additions and 29 deletions

View File

@@ -366,13 +366,19 @@ class _ViewProviderArchMaterial:
return ":/icons/Arch_Material.svg"
def attach(self, vobj):
self.Object = vobj.Object
return
def updateData(self, obj, prop):
return
def onChanged(self, vobj, prop):
return
if prop == "Material":
if "Father" in vobj.Object.Material:
for o in FreeCAD.ActiveDocument.Objects:
if o.isDerivedFrom("App::MaterialObject"):
if o.Label == vobj.Object.Material["Father"]:
o.touch()
def setEdit(self,vobj,mode):
taskd = _ArchMaterialTaskPanel(vobj.Object)
@@ -390,6 +396,17 @@ class _ViewProviderArchMaterial:
def __setstate__(self,state):
return None
def claimChildren(self):
ch = []
if hasattr(self,"Object"):
for o in FreeCAD.ActiveDocument.Objects:
if o.isDerivedFrom("App::MaterialObject"):
if o.Material:
if "Father" in o.Material:
if o.Material["Father"] == self.Object.Label:
ch.append(o)
return ch
class _ArchMaterialTaskPanel:
@@ -406,12 +423,21 @@ class _ArchMaterialTaskPanel:
self.form.ButtonColor.setIcon(QtGui.QIcon(colorPix))
QtCore.QObject.connect(self.form.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(QString)"), self.chooseMat)
QtCore.QObject.connect(self.form.comboBox_FromExisting, QtCore.SIGNAL("currentIndexChanged(int)"), self.fromExisting)
QtCore.QObject.connect(self.form.comboFather, QtCore.SIGNAL("currentIndexChanged(QString)"), self.setFather)
QtCore.QObject.connect(self.form.comboFather, QtCore.SIGNAL("currentTextChanged(QString)"), self.setFather)
QtCore.QObject.connect(self.form.ButtonColor,QtCore.SIGNAL("pressed()"),self.getColor)
QtCore.QObject.connect(self.form.ButtonUrl,QtCore.SIGNAL("pressed()"),self.openUrl)
QtCore.QObject.connect(self.form.ButtonEditor,QtCore.SIGNAL("pressed()"),self.openEditor)
QtCore.QObject.connect(self.form.ButtonCode,QtCore.SIGNAL("pressed()"),self.getCode)
self.fillMaterialCombo()
self.fillExistingCombo()
try:
import BimClassification
except:
self.form.ButtonCode.hide()
else:
import os
self.form.ButtonCode.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(BimClassification.__file__),"icons","BIM_Classification.svg")))
if self.obj:
if hasattr(self.obj,"Material"):
self.material = self.obj.Material
@@ -446,6 +472,22 @@ class _ArchMaterialTaskPanel:
self.form.FieldUrl.setText(self.material['ProductURL'])
if 'Transparency' in self.material:
self.form.SpinBox_Transparency.setValue(int(self.material["Transparency"]))
if "Father" in self.material:
father = self.material["Father"]
else:
father = None
found = False
for o in FreeCAD.ActiveDocument.Objects:
if o.isDerivedFrom("App::MaterialObject"):
if o != self.obj:
self.form.comboFather.addItem(o.Label)
if o.Label == father:
self.form.comboFather.setCurrentIndex(self.form.comboFather.count()-1)
found = True
if father and not found:
self.form.comboFather.addItem(father)
self.form.comboFather.setCurrentIndex(self.form.comboFather.count()-1)
def getFields(self):
"sets self.material from the contents of the task box"
@@ -484,6 +526,11 @@ class _ArchMaterialTaskPanel:
self.material = m.Material
self.setFields()
def setFather(self,text):
"sets the father"
if text:
self.material["Father"] = text
def getColor(self):
"opens a color picker dialog"
self.color = QtGui.QColorDialog.getColor()
@@ -535,8 +582,7 @@ class _ArchMaterialTaskPanel:
QtGui.QDesktopServices.openUrl(self.material['ProductURL'])
def getCode(self):
baseurl = "http://bsdd.buildingsmart.org/#concept/browse"
QtGui.QDesktopServices.openUrl(baseurl)
FreeCADGui.runCommand("BIM_Classification")
class _ArchMultiMaterial:

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>216</width>
<height>295</height>
<height>327</height>
</rect>
</property>
<property name="windowTitle">
@@ -15,36 +15,28 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<widget class="QComboBox" name="comboBox_MaterialsInDir">
<property name="toolTip">
<string>Choose a preset card</string>
</property>
<item>
<widget class="QComboBox" name="comboBox_MaterialsInDir">
<property name="toolTip">
<string>Choose a preset card</string>
</property>
<item>
<property name="text">
<string>Choose preset...</string>
</property>
</item>
</widget>
<property name="text">
<string>Choose preset...</string>
</property>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<widget class="QComboBox" name="comboBox_FromExisting">
<property name="toolTip">
<string>Copy values from an existing material in the document</string>
</property>
<item>
<widget class="QComboBox" name="comboBox_FromExisting">
<property name="toolTip">
<string>Copy values from an existing material in the document</string>
</property>
<item>
<property name="text">
<string>Copy existing...</string>
</property>
</item>
</widget>
<property name="text">
<string>Copy existing...</string>
</property>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
@@ -173,7 +165,7 @@
</size>
</property>
<property name="toolTip">
<string>Opens the OmniClass website to pick a category</string>
<string>Opens a browser dialog to choose a class from a BIM standard</string>
</property>
<property name="text">
<string/>
@@ -232,6 +224,24 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Father</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboFather">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>