0001151: Draft loads Part module at start

+ Fixed loading of Part module at startup
+ Minor cleaning around
This commit is contained in:
Yorik van Havre 2013-06-15 15:39:29 -03:00
parent 6a9594d4c0
commit 31fbfd33ef
6 changed files with 50 additions and 37 deletions

View File

@ -66,6 +66,7 @@ class ArchWorkbench(Workbench):
def Initialize(self): def Initialize(self):
import DraftTools,DraftGui,Arch_rc,Arch,Draft_rc import DraftTools,DraftGui,Arch_rc,Arch,Draft_rc
from DraftTools import translate
# arch tools # arch tools
self.archtools = ["Arch_Wall","Arch_Structure", self.archtools = ["Arch_Wall","Arch_Structure",
@ -91,17 +92,18 @@ class ArchWorkbench(Workbench):
"Draft_ShowSnapBar","Draft_ToggleGrid","Draft_UndoLine", "Draft_ShowSnapBar","Draft_ToggleGrid","Draft_UndoLine",
"Draft_FinishLine","Draft_CloseLine"] "Draft_FinishLine","Draft_CloseLine"]
self.appendToolbar(str(DraftTools.translate("arch","Arch tools")),self.archtools) self.appendToolbar(str(translate("arch","Arch tools")),self.archtools)
self.appendToolbar(str(DraftTools.translate("arch","Draft tools")),self.drafttools) self.appendToolbar(str(translate("arch","Draft tools")),self.drafttools)
self.appendToolbar(str(DraftTools.translate("arch","Draft mod tools")),self.draftmodtools) self.appendToolbar(str(translate("arch","Draft mod tools")),self.draftmodtools)
self.appendMenu([str(DraftTools.translate("arch","&Architecture")),str(DraftTools.translate("arch","Conversion Tools"))],self.meshtools) self.appendMenu([str(translate("arch","&Architecture")),str(translate("arch","Conversion Tools"))],self.meshtools)
self.appendMenu([str(DraftTools.translate("arch","&Architecture")),str(DraftTools.translate("arch","Calculation Tools"))],self.calctools) self.appendMenu([str(translate("arch","&Architecture")),str(translate("arch","Calculation Tools"))],self.calctools)
self.appendMenu(str(DraftTools.translate("arch","&Architecture")),self.archtools) self.appendMenu(str(translate("arch","&Architecture")),self.archtools)
self.appendMenu(str(DraftTools.translate("arch","&Draft")),self.drafttools+self.draftmodtools) self.appendMenu(str(translate("arch","&Draft")),self.drafttools+self.draftmodtools)
self.appendMenu([str(DraftTools.translate("arch","&Draft")),str(DraftTools.translate("arch","Context Tools"))],self.draftcontexttools) self.appendMenu([str(translate("arch","&Draft")),str(translate("arch","Context Tools"))],self.draftcontexttools)
FreeCADGui.addIconPath(":/icons") FreeCADGui.addIconPath(":/icons")
FreeCADGui.addLanguagePath(":/translations") FreeCADGui.addLanguagePath(":/translations")
FreeCADGui.addPreferencePage(":/ui/archprefs-base.ui","Arch") FreeCADGui.addPreferencePage(":/ui/archprefs-base.ui","Arch")
if hasattr(FreeCADGui,"draftToolBar"):
if not hasattr(FreeCADGui.draftToolBar,"loadedPreferences"): if not hasattr(FreeCADGui.draftToolBar,"loadedPreferences"):
FreeCADGui.addPreferencePage(":/ui/userprefs-base.ui","Draft") FreeCADGui.addPreferencePage(":/ui/userprefs-base.ui","Draft")
FreeCADGui.addPreferencePage(":/ui/userprefs-import.ui","Draft") FreeCADGui.addPreferencePage(":/ui/userprefs-import.ui","Draft")
@ -129,9 +131,12 @@ class ArchWorkbench(Workbench):
return "Gui::PythonWorkbench" return "Gui::PythonWorkbench"
FreeCADGui.addWorkbench(ArchWorkbench) FreeCADGui.addWorkbench(ArchWorkbench)
# add import/export types
FreeCAD.addImportType("Industry Foundation Classes (*.ifc)","importIFC") FreeCAD.addImportType("Industry Foundation Classes (*.ifc)","importIFC")
FreeCAD.addExportType("Wavefront OBJ - Arch module (*.obj)","importOBJ") FreeCAD.addExportType("Wavefront OBJ - Arch module (*.obj)","importOBJ")
FreeCAD.addExportType("WebGL file (*.html)","importWebGL") FreeCAD.addExportType("WebGL file (*.html)","importWebGL")
# check for pycollada # check for pycollada
try: try:
import collada import collada

View File

@ -27,7 +27,6 @@ __url__ = "http://free-cad.sourceforge.net"
import FreeCAD, FreeCADGui, math, Draft, DraftGui, DraftTrackers, DraftVecUtils import FreeCAD, FreeCADGui, math, Draft, DraftGui, DraftTrackers, DraftVecUtils
from DraftGui import todo,getMainWindow
from FreeCAD import Vector from FreeCAD import Vector
from pivy import coin from pivy import coin
from PyQt4 import QtCore,QtGui from PyQt4 import QtCore,QtGui
@ -118,7 +117,7 @@ class Snapper:
if not hasattr(self,"toolbar"): if not hasattr(self,"toolbar"):
self.makeSnapToolBar() self.makeSnapToolBar()
mw = getMainWindow() mw = DraftGui.getMainWindow()
bt = mw.findChild(QtGui.QToolBar,"Draft Snap") bt = mw.findChild(QtGui.QToolBar,"Draft Snap")
if not bt: if not bt:
mw.addToolBar(self.toolbar) mw.addToolBar(self.toolbar)
@ -929,7 +928,7 @@ class Snapper:
"shows the toolbar and the grid" "shows the toolbar and the grid"
if not hasattr(self,"toolbar"): if not hasattr(self,"toolbar"):
self.makeSnapToolBar() self.makeSnapToolBar()
mw = getMainWindow() mw = DraftGui.getMainWindow()
bt = mw.findChild(QtGui.QToolBar,"Draft Snap") bt = mw.findChild(QtGui.QToolBar,"Draft Snap")
if not bt: if not bt:
mw.addToolBar(self.toolbar) mw.addToolBar(self.toolbar)

View File

@ -28,7 +28,6 @@ __url__ = "http://free-cad.sourceforge.net"
import FreeCAD,FreeCADGui,math,Draft, DraftVecUtils import FreeCAD,FreeCADGui,math,Draft, DraftVecUtils
from FreeCAD import Vector from FreeCAD import Vector
from pivy import coin from pivy import coin
from DraftGui import todo
class Tracker: class Tracker:
"A generic Draft Tracker, to be used by other specific trackers" "A generic Draft Tracker, to be used by other specific trackers"
@ -52,9 +51,11 @@ class Tracker:
self.switch.addChild(node) self.switch.addChild(node)
self.switch.whichChild = -1 self.switch.whichChild = -1
self.Visible = False self.Visible = False
from DraftGui import todo
todo.delay(self._insertSwitch, self.switch) todo.delay(self._insertSwitch, self.switch)
def finalize(self): def finalize(self):
from DraftGui import todo
todo.delay(self._removeSwitch, self.switch) todo.delay(self._removeSwitch, self.switch)
self.switch = None self.switch = None

View File

@ -93,18 +93,17 @@ class DraftWorkbench (Workbench):
if not depsOK: if not depsOK:
return return
# import Draft tools, icons and macros menu
try: try:
import os,macros,DraftTools,DraftGui,Draft_rc import os,macros,Draft_rc,DraftTools, DraftGui
from DraftTools import translate
FreeCADGui.addLanguagePath(":/translations") FreeCADGui.addLanguagePath(":/translations")
FreeCADGui.addIconPath(":/icons") FreeCADGui.addIconPath(":/icons")
if not hasattr(FreeCADGui.draftToolBar,"loadedPreferences"): self.appendMenu(["&Macro",str(translate("draft","Installed Macros"))],macros.macrosList)
FreeCADGui.addPreferencePage(":/ui/userprefs-base.ui","Draft")
FreeCADGui.addPreferencePage(":/ui/userprefs-import.ui","Draft")
FreeCADGui.draftToolBar.loadedPreferences = True
self.appendMenu(["&Macro",str(DraftTools.translate("draft","Installed Macros"))],macros.macrosList)
Log ('Loading Draft module...done\n')
except: except:
pass pass
# setup menus
self.cmdList = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc","Draft_Ellipse", self.cmdList = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc","Draft_Ellipse",
"Draft_Polygon","Draft_Rectangle", "Draft_Text", "Draft_Polygon","Draft_Rectangle", "Draft_Text",
"Draft_Dimension", "Draft_BSpline","Draft_Point", "Draft_Dimension", "Draft_BSpline","Draft_Point",
@ -120,9 +119,15 @@ class DraftWorkbench (Workbench):
self.lineList = ["Draft_UndoLine","Draft_FinishLine","Draft_CloseLine"] self.lineList = ["Draft_UndoLine","Draft_FinishLine","Draft_CloseLine"]
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft creation tools"),self.cmdList) self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft creation tools"),self.cmdList)
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft modification tools"),self.modList) self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft modification tools"),self.modList)
self.appendMenu(str(DraftTools.translate("draft","&Draft")),self.cmdList+self.modList) self.appendMenu(str(translate("draft","&Draft")),self.cmdList+self.modList)
self.appendMenu([str(DraftTools.translate("draft","&Draft")),str(DraftTools.translate("draft","Context tools"))],self.treecmdList) self.appendMenu([str(translate("draft","&Draft")),str(translate("draft","Context tools"))],self.treecmdList)
self.appendMenu([str(DraftTools.translate("draft","&Draft")),str(DraftTools.translate("draft","Wire tools"))],self.lineList) self.appendMenu([str(translate("draft","&Draft")),str(translate("draft","Wire tools"))],self.lineList)
if hasattr(FreeCADGui,"draftToolBar"):
if not hasattr(FreeCADGui.draftToolBar,"loadedPreferences"):
FreeCADGui.addPreferencePage(":/ui/userprefs-base.ui","Draft")
FreeCADGui.addPreferencePage(":/ui/userprefs-import.ui","Draft")
FreeCADGui.draftToolBar.loadedPreferences = True
Log ('Loading Draft module...done\n')
def Activated(self): def Activated(self):
if hasattr(FreeCADGui,"draftToolBar"): if hasattr(FreeCADGui,"draftToolBar"):
@ -159,6 +164,8 @@ class DraftWorkbench (Workbench):
# ability to turn off the Draft workbench (since it is also all included in Arch) # ability to turn off the Draft workbench (since it is also all included in Arch)
if not FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("hideDraftWorkbench"): if not FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("hideDraftWorkbench"):
FreeCADGui.addWorkbench(DraftWorkbench) FreeCADGui.addWorkbench(DraftWorkbench)
# add Import/Export types
App.addImportType("Autodesk DXF (*.dxf)","importDXF") App.addImportType("Autodesk DXF (*.dxf)","importDXF")
App.addImportType("SVG as geometry (*.svg)","importSVG") App.addImportType("SVG as geometry (*.svg)","importSVG")
App.addImportType("Open CAD Format (*.oca *.gcad)","importOCA") App.addImportType("Open CAD Format (*.oca *.gcad)","importOCA")
@ -167,7 +174,7 @@ App.addExportType("Autodesk DXF (*.dxf)","importDXF")
App.addExportType("Flattened SVG (*.svg)","importSVG") App.addExportType("Flattened SVG (*.svg)","importSVG")
App.addExportType("Open CAD Format (*.oca)","importOCA") App.addExportType("Open CAD Format (*.oca)","importOCA")
# DWG support # add DWG support
import importDWG import importDWG
if importDWG.getTeighaConverter(): if importDWG.getTeighaConverter():
App.addImportType("Autodesk DWG (*.dwg)","importDWG") App.addImportType("Autodesk DWG (*.dwg)","importDWG")

View File

@ -38,7 +38,7 @@ currently unsupported: use, image
# implement inherting fill style from group # implement inherting fill style from group
# handle relative units # handle relative units
import xml.sax, string, FreeCAD, os, math, re, Draft, DraftVecUtils, DraftGeomUtils import xml.sax, string, FreeCAD, os, math, re, Draft, DraftVecUtils
from FreeCAD import Vector from FreeCAD import Vector
try: import FreeCADGui try: import FreeCADGui
@ -283,6 +283,7 @@ def makewire(path,checkclosed=False,donttry=False):
#ToDo Do not catch all exceptions #ToDo Do not catch all exceptions
if not donttry: if not donttry:
try: try:
import DraftGeomUtils
sh = Part.Wire(DraftGeomUtils.sortEdges(path)) sh = Part.Wire(DraftGeomUtils.sortEdges(path))
#sh = Part.Wire(path) #sh = Part.Wire(path)
isok = (not checkclosed) or sh.isClosed() isok = (not checkclosed) or sh.isClosed()