Remove dependency on ifcopenshell at runtime and introduce new IfcVersion config

This commit is contained in:
Dion Moult
2019-01-29 21:14:35 +11:00
parent 471eb4cad3
commit c9d08b7311
4 changed files with 100 additions and 19 deletions

View File

@@ -25,9 +25,8 @@ __title__="FreeCAD Arch Component"
__author__ = "Yorik van Havre"
__url__ = "http://www.freecadweb.org"
import FreeCAD,Draft,ArchCommands,math,sys,json,os,ifcopenshell,ArchIFC
import FreeCAD,Draft,ArchCommands,math,sys,json,os,ArchIFC,ArchIFCSchema
from FreeCAD import Vector
from ArchIFC import ifcProducts, ifcTypes
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtGui,QtCore
@@ -48,8 +47,7 @@ else:
# This module provides the base Arch component class, that
# is shared by all of the Arch BIM objects
# Possible roles for FreeCAD BIM objects
IfcRoles = ['Undefined']+[''.join(map(lambda x: x if x.islower() else " "+x, t[3:]))[1:] for t in ifcProducts.keys()]
IfcRoles = ['Undefined']+[''.join(map(lambda x: x if x.islower() else " "+x, t[3:]))[1:] for t in ArchIFCSchema.IfcProducts.keys()]
def convertOldComponents(objs=[]):
@@ -1183,10 +1181,10 @@ class ComponentTaskPanel:
return
if not isinstance(self.obj.IfcProperties,dict):
return
import Arch_rc,csv,os
import Arch_rc, csv, os, ArchIFCSchema
# get presets
self.ptypes = ifcTypes.keys()
self.ptypes = ArchIFCSchema.IfcTypes.keys()
self.plabels = [''.join(map(lambda x: x if x.islower() else " "+x, t[3:]))[1:] for t in self.ptypes]
self.psetdefs = {}
psetspath = os.path.join(FreeCAD.getResourceDir(),"Mod","Arch","Presets","pset_definitions.csv")

View File

@@ -1,15 +1,8 @@
import FreeCAD, os, ifcopenshell, json
import FreeCAD, os, json
if FreeCAD.GuiUp:
from PySide.QtCore import QT_TRANSLATE_NOOP
with open(os.path.join(FreeCAD.getResourceDir(), "Mod", "Arch", "Presets",
"ifc_products_" + ifcopenshell.schema_identifier + ".json")) as f:
ifcProducts = json.load(f)
with open(os.path.join(FreeCAD.getResourceDir(), "Mod", "Arch", "Presets",
"ifc_types_" + ifcopenshell.schema_identifier + ".json")) as f:
ifcTypes = json.load(f)
def setProperties(obj):
if not "IfcData" in obj.PropertiesList:
obj.addProperty("App::PropertyMap","IfcData","Component",QT_TRANSLATE_NOOP("App::Property","IFC data"))
@@ -22,9 +15,10 @@ def onChanged(obj, prop):
setObjIfcAttributeValue(obj, prop, obj.getPropertyByName(prop))
def getIfcProduct(IfcRole):
import ArchIFCSchema
name = "Ifc" + IfcRole.replace(" ", "")
if name in ifcProducts:
return ifcProducts[name]
if name in ArchIFCSchema.IfcProducts:
return ArchIFCSchema.IfcProducts[name]
def getIfcProductAttribute(ifcProduct, name):
for attribute in ifcProduct["attributes"]:
@@ -60,7 +54,7 @@ def addIfcProductAttribute(obj, attribute):
obj.addProperty("App::PropertyEnumeration", attribute["name"], "IFC Attributes", QT_TRANSLATE_NOOP("App::Property", "Description of IFC attributes are not yet implemented"))
setattr(obj, attribute["name"], attribute["enum_values"])
else:
propertyType = "App::" + ifcTypes[attribute["type"]]["property"]
propertyType = "App::" + ArchIFCSchema.IfcTypes[attribute["type"]]["property"]
obj.addProperty(propertyType, attribute["name"], "IFC Attributes", QT_TRANSLATE_NOOP("App::Property", "Description of IFC attributes are not yet implemented"))
def addIfcAttributeValueExpressions(obj, attribute):

View File

@@ -0,0 +1,12 @@
import FreeCAD, os, json
ifcVersions = ["IFC4", "IFC2X3"]
IfcVersion = ifcVersions[FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetInt("IfcVersion",0)]
with open(os.path.join(FreeCAD.getResourceDir(), "Mod", "Arch", "Presets",
"ifc_products_" + IfcVersion + ".json")) as f:
IfcProducts = json.load(f)
with open(os.path.join(FreeCAD.getResourceDir(), "Mod", "Arch", "Presets",
"ifc_types_" + IfcVersion + ".json")) as f:
IfcTypes = json.load(f)

View File

@@ -17,7 +17,16 @@
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
@@ -198,6 +207,69 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<spacer name="horizontalSpacer_11">
<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_10">
<property name="text">
<string>IFC version</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Gui::PrefComboBox" name="comboBox">
<property name="toolTip">
<string>The IFC version will change which attributes and products are supported</string>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>IfcVersion</cstring>
</property>
<item>
<property name="text">
<string>IFC4</string>
</property>
</item>
<item>
<property name="text">
<string>IFC2X3</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@@ -690,6 +762,11 @@
<extends>QDoubleSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefComboBox</class>
<extends>QComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>