From b8bcb43b66006fb789941a6737f500ad7b83283b Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Sat, 31 Dec 2011 17:16:51 -0200 Subject: [PATCH] fixed bug #556 - Premature loading of modules The Draft and Arch modules now load heavy modules such as Part or Sketch only when they use them, not anymore at Init time. --- src/Mod/Arch/ArchAxis.py | 6 ++++-- src/Mod/Arch/ArchBuilding.py | 2 +- src/Mod/Arch/ArchCell.py | 5 +++-- src/Mod/Arch/ArchCommands.py | 7 +++++-- src/Mod/Arch/ArchFloor.py | 2 +- src/Mod/Arch/ArchSectionPlane.py | 7 +++++-- src/Mod/Arch/ArchSite.py | 2 +- src/Mod/Arch/ArchStructure.py | 6 ++++-- src/Mod/Arch/ArchWall.py | 7 +++++-- src/Mod/Arch/ArchWindow.py | 6 ++++-- src/Mod/Draft/Draft.py | 33 +++++++++++++++++++++++++++++--- src/Mod/Draft/DraftSnap.py | 10 +++++++--- src/Mod/Draft/DraftTools.py | 10 ++++++++-- src/Mod/Draft/DraftTrackers.py | 8 ++++++-- src/Mod/Draft/WorkingPlane.py | 2 +- src/Mod/Draft/importSVG.py | 6 ++++-- 16 files changed, 89 insertions(+), 30 deletions(-) diff --git a/src/Mod/Arch/ArchAxis.py b/src/Mod/Arch/ArchAxis.py index 94b8f9ea6..689c54172 100644 --- a/src/Mod/Arch/ArchAxis.py +++ b/src/Mod/Arch/ArchAxis.py @@ -21,8 +21,8 @@ #* * #*************************************************************************** -import FreeCAD,FreeCADGui,Part,Draft,ArchComponent,math -from draftlibs import fcgeo,fcvec +import FreeCAD,FreeCADGui,Draft,ArchComponent,math +from draftlibs import fcvec from FreeCAD import Vector from PyQt4 import QtCore from pivy import coin @@ -81,6 +81,7 @@ class _Axis(ArchComponent.Component): self.createGeometry(obj) def createGeometry(self,obj): + import Part pl = obj.Placement geoms = [] dist = 0 @@ -121,6 +122,7 @@ class _ViewProviderAxis(ArchComponent.ViewProviderComponent): self.bubbles = None def makeBubbles(self): + import Part rn = self.ViewObject.RootNode.getChild(2).getChild(0).getChild(0) if self.bubbles: rn.removeChild(self.bubbles) diff --git a/src/Mod/Arch/ArchBuilding.py b/src/Mod/Arch/ArchBuilding.py index 4a7afbd9e..8bb703021 100644 --- a/src/Mod/Arch/ArchBuilding.py +++ b/src/Mod/Arch/ArchBuilding.py @@ -56,7 +56,7 @@ class _CommandBuilding: if Draft.getType(sel[0]) in ["Cell","Site","Floor"]: FreeCAD.ActiveDocument.openTransaction("Type conversion") nobj = makeBuilding() - Commands.copyProperties(sel[0],nobj) + ArchCommands.copyProperties(sel[0],nobj) FreeCAD.ActiveDocument.removeObject(sel[0].Name) FreeCAD.ActiveDocument.commitTransaction() ok = True diff --git a/src/Mod/Arch/ArchCell.py b/src/Mod/Arch/ArchCell.py index a3fe1819c..8e006a6db 100644 --- a/src/Mod/Arch/ArchCell.py +++ b/src/Mod/Arch/ArchCell.py @@ -21,7 +21,7 @@ #* * #*************************************************************************** -import FreeCAD,FreeCADGui,Part,Draft,ArchComponent,ArchCommands +import FreeCAD,FreeCADGui,Draft,ArchComponent,ArchCommands from FreeCAD import Vector from PyQt4 import QtCore @@ -58,7 +58,7 @@ class _CommandCell: if Draft.getType(sel[0]) in ["Floor","Site","Building"]: FreeCAD.ActiveDocument.openTransaction("Type conversion") nobj = makeCell() - Commands.copyProperties(sel[0],nobj) + ArchCommands.copyProperties(sel[0],nobj) FreeCAD.ActiveDocument.removeObject(sel[0].Name) FreeCAD.ActiveDocument.commitTransaction() ok = True @@ -86,6 +86,7 @@ class _Cell(ArchComponent.Component): self.createGeometry(obj) def createGeometry(self,obj): + import Part pl = obj.Placement if obj.Components: if obj.JoinMode: diff --git a/src/Mod/Arch/ArchCommands.py b/src/Mod/Arch/ArchCommands.py index bde08e6a6..8a0a54640 100644 --- a/src/Mod/Arch/ArchCommands.py +++ b/src/Mod/Arch/ArchCommands.py @@ -21,8 +21,8 @@ #* * #*************************************************************************** -import FreeCAD,FreeCADGui,Part,Draft,MeshPart,ArchComponent -from draftlibs import fcgeo,fcvec +import FreeCAD,FreeCADGui,Draft,ArchComponent +from draftlibs import fcvec from FreeCAD import Vector from PyQt4 import QtCore @@ -138,6 +138,8 @@ def splitMesh(obj,mark=True): def meshToShape(obj,mark=True): '''meshToShape(object,[mark]): turns a mesh into a shape, joining coplanar facets. If mark is True (default), non-solid objects will be marked in red''' + import Part,MeshPart + from draftlibs import fcgeo if "Mesh" in obj.PropertiesList: faces = [] mesh = obj.Mesh @@ -195,6 +197,7 @@ def meshToShape(obj,mark=True): def removeShape(objs,mark=True): '''takes an arch object (wall or structure) built on a cubic shape, and removes the inner shape, keeping its length, width and height as parameters.''' + from draftlibs import fcgeo if not isinstance(objs,list): objs = [objs] for obj in objs: diff --git a/src/Mod/Arch/ArchFloor.py b/src/Mod/Arch/ArchFloor.py index f3fda4ebe..864fb2bc0 100644 --- a/src/Mod/Arch/ArchFloor.py +++ b/src/Mod/Arch/ArchFloor.py @@ -57,7 +57,7 @@ class _CommandFloor: if Draft.getType(sel[0]) in ["Cell","Site","Building"]: FreeCAD.ActiveDocument.openTransaction("Type conversion") nobj = makeFloor() - Commands.copyProperties(sel[0],nobj) + ArchCommands.copyProperties(sel[0],nobj) FreeCAD.ActiveDocument.removeObject(sel[0].Name) FreeCAD.ActiveDocument.commitTransaction() ok = True diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index aeb5e384d..b67803a39 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -1,8 +1,8 @@ -import FreeCAD,FreeCADGui,Part,ArchComponent,WorkingPlane,Drawing,math +import FreeCAD,FreeCADGui,ArchComponent,WorkingPlane,Drawing,math from FreeCAD import Vector from PyQt4 import QtCore from pivy import coin -from draftlibs import fcvec,fcgeo +from draftlibs import fcvec class _CommandSectionPlane: @@ -46,6 +46,7 @@ class _SectionPlane: self.Type = "SectionPlane" def execute(self,obj): + import Part pl = obj.Placement l = obj.ViewObject.DisplaySize p = Part.makePlane(l,l,Vector(l/2,-l/2,0),Vector(0,0,-1)) @@ -183,6 +184,8 @@ class _ArchDrawingView: return Vector(lx,ly,0) def getPath(self,face,plane): + import Part + from draftlibs import fcgeo "returns a svg path from a face" svg ='