diff --git a/src/Mod/Arch/Arch.py b/src/Mod/Arch/Arch.py index d0b419ddef..fa0c509852 100644 --- a/src/Mod/Arch/Arch.py +++ b/src/Mod/Arch/Arch.py @@ -63,3 +63,4 @@ from ArchSchedule import * from ArchPrecast import * from ArchPipe import * from ArchBuildingPart import * +from ArchReference import * diff --git a/src/Mod/Arch/ArchReference.py b/src/Mod/Arch/ArchReference.py new file mode 100644 index 0000000000..e82c4bdbdc --- /dev/null +++ b/src/Mod/Arch/ArchReference.py @@ -0,0 +1,295 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2018 Yorik van Havre * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU Lesser General Public License (LGPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* GNU Library General Public License for more details. * +#* * +#* You should have received a copy of the GNU Library General Public * +#* License along with this program; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#* * +#*************************************************************************** + +__title__="FreeCAD Arch External Reference" +__author__ = "Yorik van Havre" +__url__ = "http://www.freecadweb.org" + + +import FreeCAD,os,zipfile,re +if FreeCAD.GuiUp: + import FreeCADGui + from PySide import QtCore, QtGui + from DraftTools import translate + from PySide.QtCore import QT_TRANSLATE_NOOP +else: + # \cond + def translate(ctxt,txt, utf8_decode=False): + return txt + def QT_TRANSLATE_NOOP(ctxt,txt): + return txt + # \endcond + +## @package ArchReference +# \ingroup ARCH +# \brief The Reference object and tools +# +# This module provides tools to build Reference objects. +# References can take a shape from a Part-based object in +# another file. + + + +def makeReference(filepath=None,partname=None,name="External Reference"): + + + "makeReference([filepath,partname]): Creates an Arch Reference object" + + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return + obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ArchReference") + obj.Label = name + ArchReference(obj) + if FreeCAD.GuiUp: + ViewProviderArchReference(obj.ViewObject) + if filepath: + obj.File = filepath + if partname: + obj.Part = partname + import Draft + Draft.select(obj) + return obj + + + +class ArchReference: + + + "The Arch Reference object" + + def __init__(self,obj): + + obj.Proxy = self + ArchReference.setProperties(self,obj) + self.Type = "Reference" + + 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")) + if not "Part" in pl: + obj.addProperty("App::PropertyString","Part","Component",QT_TRANSLATE_NOOP("App::Property","The part to use from the base file")) + self.Type = "Reference" + + def onDocumentRestored(self,obj): + + ArchReference.setProperties(self,obj) + + def __getstate__(self): + + return None + + def __setstate__(self,state): + + return None + + def execute(self,obj): + + if obj.File and obj.Part: + self.parts = self.getPartsList(obj) + if self.parts: + zdoc = zipfile.ZipFile(obj.File) + if zdoc: + if obj.Part in self.parts: + if self.parts[obj.Part] in zdoc.namelist(): + f = zdoc.open(self.parts[obj.Part]) + shapedata = f.read() + f.close() + import Part + shape = Part.Shape() + shape.importBrepFromString(shapedata) + obj.Shape = shape + else: + print("Part not found in file") + return True + + def getPartsList(self,obj,filename=None): + + parts = {} + if not filename: + filename = obj.File + if not filename: + return parts + if not filename.lower().endswith(".fcstd"): + return parts + if not os.path.exists(filename): + return parts + zdoc = zipfile.ZipFile(filename) + with zdoc.open("Document.xml") as docf: + label = None + part = None + writemode = False + for line in docf: + if "icons/Arch_BuildingPart.svg icons/Arch_BuildingPart_Tree.svg icons/Arch_Profile.svg + icons/Arch_Reference.svg ui/ParametersWindowDouble.svg ui/ParametersWindowSimple.svg ui/ParametersWindowFixed.svg diff --git a/src/Mod/Arch/Resources/icons/Arch_Reference.svg b/src/Mod/Arch/Resources/icons/Arch_Reference.svg new file mode 100644 index 0000000000..3407b4f123 --- /dev/null +++ b/src/Mod/Arch/Resources/icons/Arch_Reference.svg @@ -0,0 +1,558 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + [wmayer] + + + Arch_Floor + 2011-10-10 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/Arch/Resources/icons/Arch_ + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + [agryson] Alexander Gryson + + + + + + + + + + + + + +