Arch: explicitly import modules in the initialization
Also other small fixes: cleanup for getting the icon of the workbench; translation of some strings; cleanup of comments, printing functions, and PEP8 style.
This commit is contained in:
@@ -1,70 +1,100 @@
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2011 Yorik van Havre <yorik@uncreated.net> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
"""Initialization of the Arch workbench (graphical interface)."""
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2011 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
import os
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
|
||||
|
||||
class ArchWorkbench(FreeCADGui.Workbench):
|
||||
"""The Arch workbench definition."""
|
||||
|
||||
class ArchWorkbench(Workbench):
|
||||
"Arch workbench object"
|
||||
def __init__(self):
|
||||
self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Arch/Resources/icons/ArchWorkbench.svg"
|
||||
self.__class__.MenuText = "Arch"
|
||||
self.__class__.ToolTip = "Architecture workbench"
|
||||
def QT_TRANSLATE_NOOP(context, text):
|
||||
return text
|
||||
|
||||
__dirname__ = os.path.join(FreeCAD.getResourceDir(), "Mod", "Arch")
|
||||
_tooltip = ("The Arch workbench is used to model "
|
||||
"architectural components, and entire buildings")
|
||||
self.__class__.Icon = os.path.join(__dirname__,
|
||||
"Resources", "icons",
|
||||
"ArchWorkbench.svg")
|
||||
self.__class__.MenuText = QT_TRANSLATE_NOOP("Arch", "Arch")
|
||||
self.__class__.ToolTip = QT_TRANSLATE_NOOP("Arch", _tooltip)
|
||||
|
||||
def Initialize(self):
|
||||
import DraftTools,DraftGui,Arch_rc,Arch,Draft_rc
|
||||
from DraftTools import translate
|
||||
"""When the workbench is first loaded."""
|
||||
|
||||
# arch tools
|
||||
self.archtools = ["Arch_Wall","Arch_Structure","Arch_Rebar","Arch_BuildingPart",
|
||||
"Arch_Project", "Arch_Site", "Arch_Building", "Arch_Floor", "Arch_Reference",
|
||||
"Arch_Window","Arch_Roof","Arch_AxisTools",
|
||||
"Arch_SectionPlane","Arch_Space","Arch_Stairs",
|
||||
"Arch_PanelTools","Arch_Equipment",
|
||||
"Arch_Frame", "Arch_Fence", "Arch_MaterialTools","Arch_Schedule","Arch_PipeTools",
|
||||
"Arch_CutPlane", "Arch_CutLine",
|
||||
"Arch_Add","Arch_Remove","Arch_Survey"]
|
||||
self.utilities = ["Arch_Component","Arch_CloneComponent","Arch_SplitMesh","Arch_MeshToShape",
|
||||
"Arch_SelectNonSolidMeshes","Arch_RemoveShape",
|
||||
"Arch_CloseHoles","Arch_MergeWalls","Arch_Check",
|
||||
"Arch_ToggleIfcBrepFlag","Arch_3Views",
|
||||
"Arch_IfcSpreadsheet","Arch_ToggleSubs"]
|
||||
def QT_TRANSLATE_NOOP(context, text):
|
||||
return text
|
||||
|
||||
# try to locate the Rebar addon
|
||||
import Draft_rc
|
||||
import DraftTools
|
||||
import DraftGui
|
||||
from draftguitools import gui_circulararray
|
||||
from draftguitools import gui_polararray
|
||||
import Arch_rc
|
||||
import Arch
|
||||
|
||||
# Set up command lists
|
||||
self.archtools = ["Arch_Wall", "Arch_Structure", "Arch_Rebar",
|
||||
"Arch_BuildingPart",
|
||||
"Arch_Project", "Arch_Site", "Arch_Building",
|
||||
"Arch_Floor", "Arch_Reference",
|
||||
"Arch_Window", "Arch_Roof", "Arch_AxisTools",
|
||||
"Arch_SectionPlane", "Arch_Space", "Arch_Stairs",
|
||||
"Arch_PanelTools", "Arch_Equipment",
|
||||
"Arch_Frame", "Arch_Fence", "Arch_MaterialTools",
|
||||
"Arch_Schedule", "Arch_PipeTools",
|
||||
"Arch_CutPlane", "Arch_CutLine",
|
||||
"Arch_Add", "Arch_Remove", "Arch_Survey"]
|
||||
self.utilities = ["Arch_Component", "Arch_CloneComponent",
|
||||
"Arch_SplitMesh", "Arch_MeshToShape",
|
||||
"Arch_SelectNonSolidMeshes", "Arch_RemoveShape",
|
||||
"Arch_CloseHoles", "Arch_MergeWalls", "Arch_Check",
|
||||
"Arch_ToggleIfcBrepFlag", "Arch_3Views",
|
||||
"Arch_IfcSpreadsheet", "Arch_ToggleSubs"]
|
||||
|
||||
# Add the rebar tools from the Reinforcement addon, if available
|
||||
try:
|
||||
import RebarTools
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
class RebarGroupCommand:
|
||||
def GetCommands(self):
|
||||
return tuple(RebarTools.RebarCommands+["Arch_Rebar"])
|
||||
return tuple(RebarTools.RebarCommands + ["Arch_Rebar"])
|
||||
|
||||
def GetResources(self):
|
||||
return { 'MenuText': 'Rebar tools',
|
||||
'ToolTip': 'Rebar tools'
|
||||
}
|
||||
_tooltip = ("Create various types of rebars, "
|
||||
"including U-shaped, L-shaped, and stirrup")
|
||||
return {'MenuText': QT_TRANSLATE_NOOP("Arch", 'Rebar tools'),
|
||||
'ToolTip': QT_TRANSLATE_NOOP("Arch", _tooltip)}
|
||||
|
||||
def IsActive(self):
|
||||
return not FreeCAD.ActiveDocument is None
|
||||
FreeCADGui.addCommand('Arch_RebarTools', RebarGroupCommand())
|
||||
self.archtools[2] = "Arch_RebarTools"
|
||||
|
||||
|
||||
# draft tools
|
||||
# Set up Draft command lists
|
||||
self.drafttools = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc","Draft_Ellipse",
|
||||
"Draft_Polygon","Draft_Rectangle", "Draft_Text",
|
||||
"Draft_Dimension", "Draft_BSpline","Draft_Point",
|
||||
@@ -88,55 +118,69 @@ class ArchWorkbench(Workbench):
|
||||
'Draft_Snap_Extension','Draft_Snap_Near','Draft_Snap_Ortho','Draft_Snap_Special',
|
||||
'Draft_Snap_Dimensions','Draft_Snap_WorkingPlane']
|
||||
|
||||
def QT_TRANSLATE_NOOP(scope, text): return text
|
||||
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Arch tools"),self.archtools)
|
||||
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft tools"),self.drafttools)
|
||||
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft mod tools"),self.draftmodtools)
|
||||
self.appendMenu([QT_TRANSLATE_NOOP("arch","&Arch"),QT_TRANSLATE_NOOP("arch","Utilities")],self.utilities)
|
||||
self.appendMenu(QT_TRANSLATE_NOOP("arch","&Arch"),self.archtools)
|
||||
self.appendMenu(QT_TRANSLATE_NOOP("arch","&Draft"),self.drafttools+self.draftmodtools+self.draftextratools)
|
||||
self.appendMenu([QT_TRANSLATE_NOOP("arch","&Draft"),QT_TRANSLATE_NOOP("arch","Utilities")],self.draftutils+self.draftcontexttools)
|
||||
self.appendMenu([QT_TRANSLATE_NOOP("arch","&Draft"),QT_TRANSLATE_NOOP("arch","Snapping")],self.snapList)
|
||||
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "Arch tools"), self.archtools)
|
||||
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "Draft tools"), self.drafttools)
|
||||
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "Draft mod tools"), self.draftmodtools)
|
||||
|
||||
self.appendMenu([QT_TRANSLATE_NOOP("arch", "&Arch"),
|
||||
QT_TRANSLATE_NOOP("arch", "Utilities")],
|
||||
self.utilities)
|
||||
self.appendMenu(QT_TRANSLATE_NOOP("arch", "&Arch"), self.archtools)
|
||||
self.appendMenu(QT_TRANSLATE_NOOP("arch", "&Draft"),
|
||||
self.drafttools + self.draftmodtools + self.draftextratools)
|
||||
self.appendMenu([QT_TRANSLATE_NOOP("arch", "&Draft"),
|
||||
QT_TRANSLATE_NOOP("arch", "Utilities")],
|
||||
self.draftutils + self.draftcontexttools)
|
||||
self.appendMenu([QT_TRANSLATE_NOOP("arch", "&Draft"),
|
||||
QT_TRANSLATE_NOOP("arch", "Snapping")], self.snapList)
|
||||
FreeCADGui.addIconPath(":/icons")
|
||||
FreeCADGui.addLanguagePath(":/translations")
|
||||
if hasattr(FreeCADGui,"draftToolBar"):
|
||||
if not hasattr(FreeCADGui.draftToolBar,"loadedArchPreferences"):
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-arch.ui","Arch")
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-archdefaults.ui","Arch")
|
||||
|
||||
if hasattr(FreeCADGui, "draftToolBar"):
|
||||
if not hasattr(FreeCADGui.draftToolBar, "loadedArchPreferences"):
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-arch.ui", QT_TRANSLATE_NOOP("Arch", "Arch"))
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-archdefaults.ui", QT_TRANSLATE_NOOP("Arch", "Arch"))
|
||||
FreeCADGui.draftToolBar.loadedArchPreferences = True
|
||||
if not hasattr(FreeCADGui.draftToolBar,"loadedPreferences"):
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-draft.ui","Draft")
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-draftsnap.ui","Draft")
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-draftvisual.ui","Draft")
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-drafttexts.ui","Draft")
|
||||
if not hasattr(FreeCADGui.draftToolBar, "loadedPreferences"):
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-draft.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-draftsnap.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-draftvisual.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-drafttexts.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
|
||||
FreeCADGui.draftToolBar.loadedPreferences = True
|
||||
Log ('Loading Arch module... done\n')
|
||||
FreeCAD.Console.PrintLog('Loading Arch module, done\n')
|
||||
|
||||
def Activated(self):
|
||||
if hasattr(FreeCADGui,"draftToolBar"):
|
||||
"""When entering the workbench."""
|
||||
if hasattr(FreeCADGui, "draftToolBar"):
|
||||
FreeCADGui.draftToolBar.Activated()
|
||||
if hasattr(FreeCADGui,"Snapper"):
|
||||
if hasattr(FreeCADGui, "Snapper"):
|
||||
FreeCADGui.Snapper.show()
|
||||
Log("Arch workbench activated\n")
|
||||
|
||||
FreeCAD.Console.PrintLog("Arch workbench activated.\n")
|
||||
|
||||
def Deactivated(self):
|
||||
if hasattr(FreeCADGui,"draftToolBar"):
|
||||
"""When leaving the workbench."""
|
||||
if hasattr(FreeCADGui, "draftToolBar"):
|
||||
FreeCADGui.draftToolBar.Deactivated()
|
||||
if hasattr(FreeCADGui,"Snapper"):
|
||||
if hasattr(FreeCADGui, "Snapper"):
|
||||
FreeCADGui.Snapper.hide()
|
||||
Log("Arch workbench deactivated\n")
|
||||
FreeCAD.Console.PrintLog("Arch workbench deactivated.\n")
|
||||
|
||||
def ContextMenu(self, recipient):
|
||||
self.appendContextMenu("Utilities",self.draftcontexttools)
|
||||
"""Define an optional custom context menu."""
|
||||
self.appendContextMenu("Utilities", self.draftcontexttools)
|
||||
|
||||
def GetClassName(self):
|
||||
def GetClassName(self):
|
||||
"""Type of workbench."""
|
||||
return "Gui::PythonWorkbench"
|
||||
|
||||
|
||||
FreeCADGui.addWorkbench(ArchWorkbench)
|
||||
|
||||
# File format pref pages are independent and can be loaded at startup
|
||||
# Preference pages for importing and exporting various file formats
|
||||
# are independent of the loading of the workbench and can be loaded at startup
|
||||
import Arch_rc
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-ifc.ui","Import-Export")
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-dae.ui","Import-Export")
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-ifc.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export"))
|
||||
FreeCADGui.addPreferencePage(":/ui/preferences-dae.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export"))
|
||||
|
||||
FreeCAD.__unit_test__ += [ "TestArch" ]
|
||||
FreeCAD.__unit_test__ += ["TestArch"]
|
||||
|
||||
Reference in New Issue
Block a user