Skip to content

Commit

Permalink
DXF and IFC pref pages can now be set to show on each import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Feb 2, 2016
1 parent 5ef5a8e commit 79a615f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 50 deletions.
15 changes: 14 additions & 1 deletion src/Mod/Arch/Resources/ui/preferences-ifc.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>456</width>
<height>486</height>
<height>542</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -20,6 +20,19 @@
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_7">
<property name="text">
<string>Show this dialog when importing and exporting</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ifcShowDialog</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
Expand Down
62 changes: 38 additions & 24 deletions src/Mod/Arch/importIFC.py
Expand Up @@ -96,6 +96,7 @@
END-ISO-10303-21;
"""


def decode(filename,utf=False):
if isinstance(filename,unicode):
# workaround since ifcopenshell currently can't handle unicode filenames
Expand All @@ -107,6 +108,7 @@ def decode(filename,utf=False):
filename = filename.encode(encoding)
return filename


def doubleClickTree(item,column):
txt = item.text(column)
if "Entity #" in txt:
Expand All @@ -116,13 +118,41 @@ def doubleClickTree(item,column):
tree.scrollToItem(addr[0])
addr[0].setSelected(True)


def getPreferences():
"""retrieves IFC preferences"""
global DEBUG, PREFIX_NUMBERS, SKIP, SEPARATE_OPENINGS,
ROOT_ELEMENT, GET_EXTRUSIONS, MERGE_MATERIALS,
MERGE_MODE_ARCH, MERGE_MODE_STRUCT, CREATE_CLONES,
FORCE_BREP
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
if FreeCAD.GuiUp and p.GetBool("ifcShowDialog",False):
import FreeCADGui
FreeCADGui.showPreferences("Import-Export",0)
DEBUG = p.GetBool("ifcDebug",False)
PREFIX_NUMBERS = p.GetBool("ifcPrefixNumbers",False)
SKIP = p.GetString("ifcSkip","").split(",")
SEPARATE_OPENINGS = p.GetBool("ifcSeparateOpenings",False)
ROOT_ELEMENT = p.GetString("ifcRootElement","IfcProduct")
GET_EXTRUSIONS = p.GetBool("ifcGetExtrusions",False)
MERGE_MATERIALS = p.GetBool("ifcMergeMaterials",False)
MERGE_MODE_ARCH = p.GetInt("ifcImportModeArch",0)
MERGE_MODE_STRUCT = p.GetInt("ifcImportModeStruct",1)
if MERGE_MODE_ARCH > 0:
SEPARATE_OPENINGS = False
GET_EXTRUSIONS = False
if not SEPARATE_OPENINGS:
SKIP.append("IfcOpeningElement")
CREATE_CLONES = p.GetBool("ifcCreateClones",True)
FORCEBREP = p.GetBool("ifcExportAsBrep",False)


def explore(filename=None):
"""explore([filename]): opens a dialog showing
the contents of an IFC file. If no filename is given, a dialog will
pop up to choose a file."""

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
DEBUG = p.GetBool("ifcDebug",False)

getPreferences()

try:
import ifcopenshell
Expand Down Expand Up @@ -287,24 +317,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
certain object ids (will also get their children) and root can be used to
import only the derivates of a certain element type (default = ifcProduct)."""

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
DEBUG = p.GetBool("ifcDebug",False)
PREFIX_NUMBERS = p.GetBool("ifcPrefixNumbers",False)
SKIP = p.GetString("ifcSkip","").split(",")
SEPARATE_OPENINGS = p.GetBool("ifcSeparateOpenings",False)
ROOT_ELEMENT = p.GetString("ifcRootElement","IfcProduct")
GET_EXTRUSIONS = p.GetBool("ifcGetExtrusions",False)
MERGE_MATERIALS = p.GetBool("ifcMergeMaterials",False)
if root:
ROOT_ELEMENT = root
MERGE_MODE_ARCH = p.GetInt("ifcImportModeArch",0)
MERGE_MODE_STRUCT = p.GetInt("ifcImportModeStruct",1)
if MERGE_MODE_ARCH > 0:
SEPARATE_OPENINGS = False
GET_EXTRUSIONS = False
if not SEPARATE_OPENINGS:
SKIP.append("IfcOpeningElement")
CREATE_CLONES = p.GetBool("ifcCreateClones",True)
getPreferences()

try:
import ifcopenshell
Expand All @@ -320,6 +333,9 @@ def insert(filename,docname,skip=[],only=[],root=None):
FreeCAD.ActiveDocument = doc

if DEBUG: print "done."

if root:
ROOT_ELEMENT = root

#global ifcfile # keeping global for debugging purposes
filename = decode(filename,utf=True)
Expand Down Expand Up @@ -789,9 +805,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
def export(exportList,filename):
"exports FreeCAD contents to an IFC file"

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
FORCEBREP = p.GetBool("ifcExportAsBrep",False)
DEBUG = p.GetBool("ifcDebug",False)
getPreferences()

try:
global ifcopenshell
Expand Down
59 changes: 34 additions & 25 deletions src/Mod/Draft/Resources/ui/preferences-dxf.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>506</width>
<height>564</height>
<height>611</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -20,10 +20,42 @@
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_6">
<property name="text">
<string>Show this dialog when importing and exporting</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>dxfShowDialog</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_4">
<property name="toolTip">
<string>If this is checked, the old python importer is used, otherwise the new C++ one (faster, but not as many features yet)</string>
</property>
<property name="text">
<string>Use legacy python importer</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>dxfUseLegacyImporter</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Automatic update</string>
<string>Automatic update (legacy importer only)</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
Expand Down Expand Up @@ -61,29 +93,6 @@
<property name="margin">
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_4">
<property name="toolTip">
<string>If this is checked, the old python importer is used, otherwise the new C++ one (faster, but not as many features yet)</string>
</property>
<property name="text">
<string>Use legacy python importer</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>dxfUseLegacyImporter</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Draft/importDXF.py
Expand Up @@ -2010,6 +2010,9 @@ def exportPageLegacy(page,filename):
def readPreferences():
# reading parameters
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
if FreeCAD.GuiUp and p.GetBool("dxfShowDialog",False):
import FreeCADGui
FreeCADGui.showPreferences("Import-Export",2)
global dxfCreatePart, dxfCreateDraft, dxfCreateSketch, dxfDiscretizeCurves, dxfStarBlocks
global dxfMakeBlocks, dxfJoin, dxfRenderPolylineWidth, dxfImportTexts, dxfImportLayouts
global dxfImportPoints, dxfImportHatches, dxfUseStandardSize, dxfGetColors, dxfUseDraftVisGroups
Expand Down

0 comments on commit 79a615f

Please sign in to comment.