Ejemplo n.º 1
0
    def Deactivated(self):

        if hasattr(self,"BimSelectObserver"):
            FreeCADGui.removeDocumentObserver(self.BimSelectObserver)
            del self.BimSelectObserver

        if hasattr(FreeCADGui,"draftToolBar"):
            FreeCADGui.draftToolBar.Deactivated()
        if hasattr(FreeCADGui,"Snapper"):
            FreeCADGui.Snapper.hide()

        from DraftGui import todo
        import BimStatusBar
        import BimViews

        #print("Deactivating status icon")

        todo.delay(BimStatusBar.setStatusIcons,False)

        FreeCADGui.Control.clearTaskWatcher()

        # store views widget state and vertical size

        w = BimViews.findWidget()
        FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").SetBool("RestoreBimViews",bool(w))
        if w:
            FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").SetInt("BimViewsSize",w.height())
            w.hide()

        Log("BIM workbench deactivated\n")
Ejemplo n.º 2
0
    def Activated(self):

        import FreeCADGui
        done = False
        try:
            import BimViews
        except ImportError:
            pass
        else:
            v = BimViews.findWidget()
            if v:
                i = v.tree.currentItem()
                if i:
                    # Aligning on current widget item
                    BimViews.show(i)
                    done = True
                elif hasattr(v, "lastSelected"):
                    BimViews.show(v.lastSelected)
                    # Aligning on stored widget item
                    done = True
            elif hasattr(FreeCAD, "DraftWorkingPlane"):
                if hasattr(FreeCAD.DraftWorkingPlane, "lastBuildingPart"):
                    BimViews.show(FreeCAD.DraftWorkingPlane.lastBuildingPart)
                    done = True
        if not done:
            # Aligning on current working plane
            c = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
            r = FreeCAD.DraftWorkingPlane.getRotation().Rotation.Q
            c.orientation.setValue(r)
Ejemplo n.º 3
0
    def Activated(self):

        if hasattr(FreeCADGui, "draftToolBar"):
            FreeCADGui.draftToolBar.Activated()
        if hasattr(FreeCADGui, "Snapper"):
            FreeCADGui.Snapper.show()

        from DraftGui import todo
        import BimStatusBar

        if FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/BIM").GetBool(
                    "FirstTime",
                    True) and (not hasattr(FreeCAD, "TestEnvironment")):
            todo.delay(FreeCADGui.runCommand, "BIM_Welcome")
        todo.delay(BimStatusBar.setStatusIcons, True)

        FreeCADGui.Control.clearTaskWatcher()

        class BimWatcher:
            def __init__(self, cmds, name, invert=False):

                self.commands = cmds
                self.title = name
                self.invert = invert

            def shouldShow(self):

                if self.invert:
                    return (FreeCAD.ActiveDocument != None) and (
                        FreeCADGui.Selection.getSelection() != [])
                else:
                    return (FreeCAD.ActiveDocument !=
                            None) and (not FreeCADGui.Selection.getSelection())

        FreeCADGui.Control.addTaskWatcher([
            BimWatcher(self.draftingtools + self.annotationtools,
                       "2D geometry"),
            BimWatcher(self.bimtools, "3D/BIM geometry"),
            BimWatcher(self.modify, "Modify", invert=True)
        ])

        # restore views widget if needed

        if FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/BIM").GetBool(
                    "RestoreBimViews", True):
            import BimViews
            w = BimViews.findWidget()
            if not w:
                FreeCADGui.runCommand("BIM_Views")
            else:
                w.show()

        self.setupMultipleObjectSelection()

        Log("BIM workbench activated\n")
Ejemplo n.º 4
0
    def Initialize(self):

        # QT macro
        
        def QT_TRANSLATE_NOOP(scope, text):
            return text

        import DraftTools
        import Arch

        import BimCommands
        import BimWelcome
        import BimSetup
        import BimProject
        import BimWindows
        import BimIfcElements
        import BimViews
        import BimClassification
        import BimBox
        import BimTutorial
        import BimLibrary
        import BimMaterial
        import BimIfcQuantities
        import BimIfcProperties
        import BimNudge
        import BimPreflight
        import BimReextrude
        import BimDiff
        import BimIfcExplorer
        import BimLayers
        import BimTogglePanels
        import BimTrash
        import BimClone
        import BimStructure
        import BimStatusBar
        import BimWorkingPlaneTools
        import BimPartTools

        # add translations path
        FreeCADGui.addLanguagePath(BimStatusBar.getLanguagePath())

        # create BIM commands
        # maybe this should go back in each module...

        # these should be move out of BimCommands
        FreeCADGui.addCommand('BIM_Help',BimCommands.BIM_Help())
        FreeCADGui.addCommand('BIM_Glue',BimCommands.BIM_Glue())
        FreeCADGui.addCommand('BIM_Sketch',BimCommands.BIM_Sketch())
        FreeCADGui.addCommand('BIM_WPView',BimCommands.BIM_WPView())
        FreeCADGui.addCommand('BIM_Convert',BimCommands.BIM_Convert())
        FreeCADGui.addCommand('BIM_Ungroup',BimCommands.BIM_Ungroup())
        FreeCADGui.addCommand('BIM_Rewire',BimCommands.BIM_Rewire())
        FreeCADGui.addCommand('BIM_Door',BimCommands.BIM_Door())

        FreeCADGui.addCommand('BIM_SetWPTop',BimWorkingPlaneTools.BIM_SetWPTop())
        FreeCADGui.addCommand('BIM_SetWPFront',BimWorkingPlaneTools.BIM_SetWPFront())
        FreeCADGui.addCommand('BIM_SetWPSide',BimWorkingPlaneTools.BIM_SetWPSide())
        FreeCADGui.addCommand('BIM_TogglePanels',BimTogglePanels.BIM_TogglePanels())
        FreeCADGui.addCommand('BIM_Trash',BimTrash.BIM_Trash())
        FreeCADGui.addCommand('BIM_EmptyTrash',BimTrash.BIM_EmptyTrash())
        FreeCADGui.addCommand('BIM_Copy',BimClone.BIM_Copy())
        FreeCADGui.addCommand('BIM_Clone',BimClone.BIM_Clone())
        FreeCADGui.addCommand('BIM_Column',BimStructure.BIM_Column())
        FreeCADGui.addCommand('BIM_Beam',BimStructure.BIM_Beam())
        FreeCADGui.addCommand('BIM_Slab',BimStructure.BIM_Slab())
        FreeCADGui.addCommand('BIM_ResetCloneColors',BimClone.BIM_ResetCloneColors())
        FreeCADGui.addCommand('BIM_Welcome',BimWelcome.BIM_Welcome())
        FreeCADGui.addCommand('BIM_Setup',BimSetup.BIM_Setup())
        FreeCADGui.addCommand('BIM_Project',BimProject.BIM_Project())
        FreeCADGui.addCommand('BIM_Windows',BimWindows.BIM_Windows())
        FreeCADGui.addCommand('BIM_IfcElements',BimIfcElements.BIM_IfcElements())
        FreeCADGui.addCommand('BIM_Views',BimViews.BIM_Views())
        FreeCADGui.addCommand('BIM_Classification',BimClassification.BIM_Classification())
        FreeCADGui.addCommand('BIM_Box',BimBox.BIM_Box())
        FreeCADGui.addCommand('BIM_Tutorial',BimTutorial.BIM_Tutorial())
        FreeCADGui.addCommand('BIM_Library',BimLibrary.BIM_Library())
        FreeCADGui.addCommand('BIM_Material',BimMaterial.BIM_Material())
        FreeCADGui.addCommand('BIM_IfcQuantities',BimIfcQuantities.BIM_IfcQuantities())
        FreeCADGui.addCommand('BIM_IfcProperties',BimIfcProperties.BIM_IfcProperties())
        FreeCADGui.addCommand('BIM_Nudge_Switch',BimNudge.BIM_Nudge_Switch())
        FreeCADGui.addCommand('BIM_Nudge_Up',BimNudge.BIM_Nudge_Up())
        FreeCADGui.addCommand('BIM_Nudge_Down',BimNudge.BIM_Nudge_Down())
        FreeCADGui.addCommand('BIM_Nudge_Left',BimNudge.BIM_Nudge_Left())
        FreeCADGui.addCommand('BIM_Nudge_Right',BimNudge.BIM_Nudge_Right())
        FreeCADGui.addCommand('BIM_Nudge_Extend',BimNudge.BIM_Nudge_Extend())
        FreeCADGui.addCommand('BIM_Nudge_Shrink',BimNudge.BIM_Nudge_Shrink())
        FreeCADGui.addCommand('BIM_Nudge_RotateLeft',BimNudge.BIM_Nudge_RotateLeft())
        FreeCADGui.addCommand('BIM_Nudge_RotateRight',BimNudge.BIM_Nudge_RotateRight())
        FreeCADGui.addCommand('BIM_Unclone',BimClone.BIM_Unclone())
        FreeCADGui.addCommand('BIM_Preflight',BimPreflight.BIM_Preflight())
        FreeCADGui.addCommand('BIM_Diff',BimDiff.BIM_Diff())
        FreeCADGui.addCommand('BIM_IfcExplorer',BimIfcExplorer.BIM_IfcExplorer())
        FreeCADGui.addCommand('BIM_Layers',BimLayers.BIM_Layers())
        FreeCADGui.addCommand('BIM_Reextrude',BimReextrude.BIM_Reextrude())
        
        # wrapped Part tools
        FreeCADGui.addCommand('BIM_Builder',BimPartTools.BIM_Builder())
        FreeCADGui.addCommand('BIM_Offset2D',BimPartTools.BIM_Offset2D())
        FreeCADGui.addCommand('BIM_Extrude',BimPartTools.BIM_Extrude())
        FreeCADGui.addCommand('BIM_Cut',BimPartTools.BIM_Cut())
        FreeCADGui.addCommand('BIM_Fuse',BimPartTools.BIM_Fuse())
        FreeCADGui.addCommand('BIM_Common',BimPartTools.BIM_Common())
        FreeCADGui.addCommand('BIM_Compound',BimPartTools.BIM_Compound())
        FreeCADGui.addCommand('BIM_SimpleCopy',BimPartTools.BIM_SimpleCopy())

        self.draftingtools = ["BIM_Sketch","Draft_Line","Draft_Wire","Draft_Circle",
                              "Draft_Arc","Draft_Arc_3Points","Draft_Ellipse",
                              "Draft_Polygon","Draft_Rectangle", "Draft_BSpline", "Draft_BezCurve",
                              "Draft_Point"]

        self.annotationtools = ["Draft_Text", "Draft_ShapeString", "Draft_Dimension",
                                "Draft_Label","Arch_Axis","Arch_AxisSystem","Arch_Grid",
                                "Arch_SectionPlane"]

        self.bimtools = ["Arch_Site","Arch_Building","Arch_Floor","Arch_Space","Separator",
                         "Arch_Wall","BIM_Column","BIM_Beam","BIM_Slab","Arch_Rebar","BIM_Door","Arch_Window","Arch_Pipe",
                         "Arch_PipeConnector","Arch_Stairs","Arch_Roof","Arch_Panel","Arch_Frame",
                         "Separator","BIM_Box","BIM_Builder","Draft_Facebinder","BIM_Library","Arch_Component"]

        self.modify = ["Draft_Move","BIM_Copy","Draft_Rotate","BIM_Clone","BIM_Unclone","Draft_Offset",
                       "BIM_Offset2D", "Draft_Trimex","Draft_Join","Draft_Split","Draft_Scale","Draft_Stretch",
                       "BIM_Rewire","BIM_Glue","Draft_Upgrade", "Draft_Downgrade",
                       "Draft_Draft2Sketch","Arch_CutPlane","Arch_Add","Arch_Remove","BIM_Reextrude",
                       "Draft_Array","Draft_PathArray","Draft_PointArray",
                       "Draft_Mirror","BIM_Extrude","BIM_Cut","BIM_Fuse","BIM_Common","BIM_Compound",
                       "BIM_SimpleCopy","Draft_Shape2DView"]

        self.snap = ['Draft_ToggleGrid','Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular',
                     'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel',
                     'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center',
                     'Draft_Snap_Extension','Draft_Snap_Near','Draft_Snap_Ortho',
                     'Draft_Snap_Special','Draft_Snap_Dimensions','Draft_Snap_WorkingPlane',
                     'BIM_SetWPTop','BIM_SetWPFront','BIM_SetWPSide']

        self.manage = ["BIM_Setup","BIM_Project","BIM_Views","BIM_Windows","BIM_IfcElements",
                       "BIM_IfcQuantities","BIM_IfcProperties","BIM_Classification",
                       "BIM_Material","Arch_Schedule","BIM_Preflight"]

        # experimental arch tools (for 0.19 only)
        try:
            from ArchIFC import IfcProduct
        except:
            # this is 0.18
            self.experimentaltools = None
        else:
            from archguitools import gui_wall
            from archguitools import gui_openings
            from archguitools import gui_joinwalls
            from archguitools import gui_archview
            self.experimentaltools = ["Arch_Wall2","Arch_JoinWalls", "Arch_ExtendWall", "Separator",
                                      "Arch_Opening", "Arch_Door2", "Arch_Window2", "Separator",
                                      "Arch_View"]

        # fixed command names
        if "Draft_WorkingPlaneProxy" in Gui.listCommands():
            _tool = "Draft_WorkingPlaneProxy"
        else:
            _tool = "Draft_SetWorkingPlaneProxy"

        self.utils = ["BIM_TogglePanels","BIM_Trash","BIM_WPView",
                      "Draft_Slope", _tool, "Draft_AddConstruction",
                      "Arch_SplitMesh","Arch_MeshToShape",
                      "Arch_SelectNonSolidMeshes","Arch_RemoveShape",
                      "Arch_CloseHoles","Arch_MergeWalls","Arch_Check",
                      "Arch_ToggleIfcBrepFlag",
                      "Arch_ToggleSubs","Arch_Survey","BIM_Diff","BIM_IfcExplorer"]

        nudge = ["BIM_Nudge_Switch","BIM_Nudge_Up","BIM_Nudge_Down","BIM_Nudge_Left","BIM_Nudge_Right",
                 "BIM_Nudge_RotateLeft","BIM_Nudge_RotateRight","BIM_Nudge_Extend","BIM_Nudge_Shrink"]


        # post-0.18 tools

        if "Draft_Layer" in Gui.listCommands():
            self.manage.insert(8,"BIM_Layers")
        if "Arch_Project" in Gui.listCommands():
            self.bimtools.insert(0,"Arch_Project")
        if "Arch_Reference" in Gui.listCommands():
            self.bimtools.insert(-5,"Arch_Reference")
        if "Arch_Fence" in Gui.listCommands():
            self.bimtools.insert(-7,"Arch_Fence")
        if "Draft_Arc_3Points" in Gui.listCommands():
            self.draftingtools.insert(5,"Draft_Arc_3Points")
        if 'Draft_CubicBezCurve' in Gui.listCommands():
            self.draftingtools.insert(len(self.draftingtools)-2,'Draft_CubicBezCurve')
        if "Draft_AnnotationStyleEditor" in Gui.listCommands():
            self.manage.insert(4,"Draft_AnnotationStyleEditor")
        if "Arch_Truss" in Gui.listCommands():
            self.bimtools.insert(self.bimtools.index("Arch_Frame")+1,"Arch_Truss")
        if "Arch_CurtainWall" in Gui.listCommands():
            self.bimtools.insert(self.bimtools.index("Arch_Wall")+1,"Arch_CurtainWall")
        if "Arch_Profile" in Gui.listCommands():
            self.bimtools.insert(self.bimtools.index("BIM_Box"),"Arch_Profile")

        # load rebar tools (Reinforcement addon)

        try:
            import RebarTools
        except ImportError:
            self.rebar = None
        else:
            # create popup group for Rebar tools
            class RebarGroupCommand:
                def GetCommands(self):
                    return tuple(["Arch_Rebar"]+RebarTools.RebarCommands)
                def GetResources(self):
                    return {
                        'MenuText': QT_TRANSLATE_NOOP('Arch_RebarTools','Reinforcement tools'),
                        'ToolTip': QT_TRANSLATE_NOOP('Arch_RebarTools','Reinforcement tools')}
                def IsActive(self):
                    return not FreeCAD.ActiveDocument is None
            FreeCADGui.addCommand('Arch_RebarTools', RebarGroupCommand())
            self.bimtools[self.bimtools.index("Arch_Rebar")] = "Arch_RebarTools"
            Log("Load Reinforcement Module...done\n")
            if hasattr(RebarTools,"updateLocale"):
                RebarTools.updateLocale()
            # self.appendMenu(QT_TRANSLATE_NOOP("Arch_RebarTools","Reinforcement tools"),RebarTools.RebarCommands + ["Arch_Rebar"])
            self.rebar = RebarTools.RebarCommands + ["Arch_Rebar"]

        # try to load bimbots

        try:
            import bimbots
        except ImportError:
            pass
        else:
            class BIMBots:
                def GetResources(self):
                    return bimbots.get_plugin_info()
                def Activated(self):
                    bimbots.launch_ui()
            FreeCADGui.addCommand('BIMBots', BIMBots())
            self.utils.append("BIMBots")

        # load Reporting

        try:
            import report
        except ImportError:
            pass
        else:
            if "Report_Create" in Gui.listCommands():
                self.manage[self.manage.index("Arch_Schedule")] = "Report_Create"

        # load webtools

        try:
            import BIMServer, Git, Sketchfab
        except ImportError:
            pass
        else:
            self.utils.extend(["WebTools_Git","WebTools_BimServer","WebTools_Sketchfab"])

        # load flamingo

        try:
            import CommandsPolar,CommandsFrame,CommandsPipe
        except ImportError:
            flamingo = None
        else:
            flamingo = ["frameIt","fillFrame","insertPath","insertSection","FrameLineManager","spinSect",
                        "reverseBeam","shiftBeam","pivotBeam","levelBeam","alignEdge","rotJoin","alignFlange",
                        "stretchBeam","extend","adjustFrameAngle","insertPipe","insertElbow","insertReduct",
                        "insertCap","insertFlange","insertUbolt","insertPypeLine","breakPipe","mateEdges",
                        "extend2intersection","extend1intersection","laydown","raiseup"]

        # load fasteners

        try:
            import FastenerBase,FastenersCmd
        except ImportError:
            fasteners = None
        else:
            fasteners = [c for c in FastenerBase.FSGetCommands("screws") if not isinstance(c,tuple)]


        # create toolbars

        self.appendToolbar(QT_TRANSLATE_NOOP("BIM","Drafting tools"),self.draftingtools)
        self.appendToolbar(QT_TRANSLATE_NOOP("BIM","3D/BIM tools"),self.bimtools)
        self.appendToolbar(QT_TRANSLATE_NOOP("BIM","Annotation tools"),self.annotationtools)
        self.appendToolbar(QT_TRANSLATE_NOOP("BIM","Modification tools"),self.modify)
        self.appendToolbar(QT_TRANSLATE_NOOP("BIM","Manage tools"),self.manage)
        if self.experimentaltools:
            self.appendToolbar(QT_TRANSLATE_NOOP("BIM","Experimental tools"),self.experimentaltools)
        #if flamingo:
        #    self.appendToolbar("Flamingo tools",flamingo)

        # create menus

        # ugly!
        # build a new list of bimtools only for menu
        # and put rebar menu with sub menus into it
        self.bimtools_menu = list(self.bimtools)
        if "Arch_RebarTools" in self.bimtools_menu:
            self.bimtools_menu.remove("Arch_RebarTools")

        self.appendMenu(QT_TRANSLATE_NOOP("BIM","&2D Drafting"),self.draftingtools)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM","&3D/BIM"),self.bimtools_menu)
        if self.rebar:
            self.appendMenu([QT_TRANSLATE_NOOP("BIM","&3D/BIM"),QT_TRANSLATE_NOOP("Arch_RebarTools","Reinforcement tools")],self.rebar)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM","&Annotation"),self.annotationtools)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM","&Snapping"),self.snap)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM","&Modify"),self.modify)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM","&Manage"),self.manage)
        if flamingo:
            self.appendMenu(QT_TRANSLATE_NOOP("BIM","&Flamingo"),flamingo)
        if fasteners:
            self.appendMenu(QT_TRANSLATE_NOOP("BIM","&Fasteners"),fasteners)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM","&Utils"),self.utils)
        self.appendMenu([QT_TRANSLATE_NOOP("BIM","&Utils"),QT_TRANSLATE_NOOP("BIM","Nudge")],nudge)
        self.appendMenu("&Help",["BIM_Welcome","BIM_Help","BIM_Tutorial"])


        # load Arch & Draft preference pages

        if hasattr(FreeCADGui,"draftToolBar"):
            if not hasattr(FreeCADGui.draftToolBar,"loadedArchPreferences"):
                import Arch_rc
                FreeCADGui.addPreferencePage(":/ui/preferences-arch.ui","Arch")
                FreeCADGui.addPreferencePage(":/ui/preferences-archdefaults.ui","Arch")
                FreeCADGui.draftToolBar.loadedArchPreferences = True
            if not hasattr(FreeCADGui.draftToolBar,"loadedPreferences"):
                import Draft_rc
                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")
                FreeCADGui.draftToolBar.loadedPreferences = True

        Log ('Loading BIM module... done\n')
        FreeCADGui.updateLocale()
Ejemplo n.º 5
0
def setStatusIcons(show=True):

    "shows or hides the BIM icons in the status bar"

    from PySide import QtCore, QtGui

    unitsList = [
        translate("BIM", "Millimeters"),
        translate("BIM", "Centimeters"),
        translate("BIM", "Meters"),
        translate("BIM", "Inches"),
        translate("BIM", "Feet"),
        translate("BIM", "Architectural"),
    ]

    nudgeLabelsM = [
        translate("BIM", "Custom..."), "1/16\"", "1/8\"", "1/4\"", "1\"",
        "6\"", "1\'",
        translate("BIM", "Auto")
    ]
    nudgeLabelsI = [
        translate("BIM", "Custom..."), "1 mm", "5 mm", "1 cm", "5 cm", "10 cm",
        "50 cm",
        translate("BIM", "Auto")
    ]

    def toggle(state):

        FreeCADGui.runCommand("BIM_TogglePanels")

    def toggleBimViews(state):

        FreeCADGui.runCommand("BIM_Views")

    def addonMgr():

        mw = FreeCADGui.getMainWindow()
        if mw:
            st = mw.statusBar()
            statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
            if statuswidget:
                updatebutton = statuswidget.findChild(QtGui.QPushButton,
                                                      "UpdateButton")
                if updatebutton:
                    statuswidget.actions()[-1].setVisible(False)
        FreeCADGui.runCommand("Std_AddonMgr")

    def setUnit(action):

        # set the label of the unit button
        utext = action.text().replace("&", "")
        unit = [0, 4, 1, 3, 7, 5][unitsList.index(utext)]
        FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt(
            "UserSchema", unit)
        if hasattr(FreeCAD.Units, "setSchema"):
            FreeCAD.Units.setSchema(unit)
        action.parent().parent().parent().setText(utext)

        # change the unit of the nudge button
        nudge = action.parent().parent().parent().parent().nudge
        nudgeactions = nudge.menu().actions()
        if unit in [2, 3, 5, 7]:
            nudgelabels = nudgeLabelsI
        else:
            nudgelabels = nudgeLabelsM
        for i in range(len(nudgelabels)):
            nudgeactions[i].setText(nudgelabels[i])
        if not "auto" in nudge.text().replace("&", "").lower():
            nudge.setText(
                FreeCAD.Units.Quantity(nudge.text().replace("&",
                                                            "")).UserString)

    def setNudge(action):

        utext = action.text().replace("&", "")
        if utext == nudgeLabelsM[0]:
            # load dialog
            form = FreeCADGui.PySideUic.loadUi(
                os.path.join(os.path.dirname(__file__), "dialogNudgeValue.ui"))
            # center the dialog over FreeCAD window
            mw = FreeCADGui.getMainWindow()
            form.move(mw.frameGeometry().topLeft() + mw.rect().center() -
                      form.rect().center())
            result = form.exec_()
            if not result:
                return
            utext = form.inputField.text()
        action.parent().parent().parent().setText(utext)

    class CheckWorker(QtCore.QThread):

        updateAvailable = QtCore.Signal(bool)

        def __init__(self):

            QtCore.QThread.__init__(self)

        def run(self):

            try:
                import git
            except:
                return
            FreeCAD.Console.PrintLog(
                "Checking for available updates of the BIM workbench\n")
            bimdir = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", "BIM")
            if os.path.exists(bimdir):
                if os.path.exists(bimdir + os.sep + '.git'):
                    gitrepo = git.Git(bimdir)
                    try:
                        gitrepo.fetch()
                        if "git pull" in gitrepo.status():
                            self.updateAvailable.emit(True)
                            return
                    except:
                        # can fail for any number of reasons, ex. not being online
                        pass
            self.updateAvailable.emit(False)

    def checkUpdates():

        FreeCAD.bim_update_checker = CheckWorker()
        FreeCAD.bim_update_checker.updateAvailable.connect(showUpdateButton)
        FreeCAD.bim_update_checker.start()

    def showUpdateButton(avail):

        if avail:
            mw = FreeCADGui.getMainWindow()
            if mw:
                st = mw.statusBar()
                statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
                if statuswidget:
                    updatebutton = statuswidget.findChild(
                        QtGui.QPushButton, "UpdateButton")
                    if updatebutton:
                        #updatebutton.show() # doesn't work for some reason
                        statuswidget.actions()[-1].setVisible(True)
        if hasattr(FreeCAD, "bim_update_checker"):
            del FreeCAD.bim_update_checker

    def toggleContextMenu(point):

        FreeCADGui.BimToggleMenu = QtGui.QMenu()
        for t in [
                "Report view", "Python console", "Selection view", "Combo View"
        ]:
            a = QtGui.QAction(t)
            #a.setCheckable(True)
            #a.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("toggle"+t.replace(" ",""),True))
            FreeCADGui.BimToggleMenu.addAction(a)
        pos = FreeCADGui.getMainWindow().cursor().pos()
        FreeCADGui.BimToggleMenu.triggered.connect(toggleSaveSettings)
        #QtCore.QObject.connect(FreeCADGui.BimToggleMenu,QtCore.SIGNAL("triggered(QAction *)"),toggleSaveSettings)
        FreeCADGui.BimToggleMenu.popup(pos)

    def toggleSaveSettings(action):

        t = action.text()
        FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").SetBool(
            "toggle" + t.replace(" ", ""), action.isChecked())
        if hasattr(FreeCADGui, "BimToggleMenu"):
            del FreeCADGui.BimToggleMenu

    # main code

    mw = FreeCADGui.getMainWindow()
    if mw:
        st = mw.statusBar()
        statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
        if show:
            if statuswidget:
                statuswidget.show()
            else:
                statuswidget = QtGui.QToolBar()
                statuswidget.setObjectName("BIMStatusWidget")

                # nudge button
                nudge = QtGui.QPushButton(nudgeLabelsM[-1])
                nudge.setIcon(
                    QtGui.QIcon(
                        os.path.join(os.path.dirname(__file__), "icons",
                                     "BIM_Nudge.svg")))
                nudge.setFlat(True)
                nudge.setToolTip(
                    translate(
                        "BIM",
                        "The value of the nudge movement (rotation is always 45°).\n\nCTRL+arrows to move\nCTRL+, to rotate left\nCTRL+. to rotate right\nCTRL+PgUp to extend extrusion\nCTRL+PgDown to shrink extrusion\nCTRL+/ to switch between auto and manual mode"
                    ))
                statuswidget.addWidget(nudge)
                statuswidget.nudge = nudge
                menu = QtGui.QMenu(nudge)
                gnudge = QtGui.QActionGroup(menu)
                for u in nudgeLabelsM:
                    a = QtGui.QAction(gnudge)
                    a.setText(u)
                    menu.addAction(a)
                nudge.setMenu(menu)
                gnudge.triggered.connect(setNudge)
                statuswidget.nudgeLabelsI = nudgeLabelsI
                statuswidget.nudgeLabelsM = nudgeLabelsM

                # units chooser
                statuswidget.unitsList = unitsList
                unitLabel = QtGui.QPushButton("Unit")
                unitLabel.setObjectName("UnitLabel")
                unitLabel.setFlat(True)
                unit = FreeCAD.ParamGet(
                    "User parameter:BaseApp/Preferences/Units").GetInt(
                        "UserSchema", 0)
                menu = QtGui.QMenu(unitLabel)
                gUnits = QtGui.QActionGroup(menu)
                for u in unitsList:
                    a = QtGui.QAction(gUnits)
                    a.setText(u)
                    menu.addAction(a)
                unitLabel.setMenu(menu)
                gUnits.triggered.connect(setUnit)
                unitLabel.setText([
                    unitsList[0], unitsList[2], unitsList[3], unitsList[3],
                    unitsList[1], unitsList[5], unitsList[0], unitsList[4]
                ][unit])
                unitLabel.setToolTip(
                    translate(
                        "BIM",
                        "The preferred unit you are currently working with. You can still use any other unit anywhere in FreeCAD"
                    ))
                statuswidget.addWidget(unitLabel)
                statuswidget.unitLabel = unitLabel
                st.addPermanentWidget(statuswidget)

                # report panels toggle button
                togglebutton = QtGui.QPushButton()
                bwidth = togglebutton.fontMetrics().boundingRect(
                    "AAAA").width()
                togglebutton.setMaximumWidth(bwidth)
                togglebutton.setIcon(
                    QtGui.QIcon(
                        os.path.join(os.path.dirname(__file__), "icons",
                                     "BIM_TogglePanels.svg")))
                togglebutton.setText("")
                togglebutton.setToolTip(
                    translate("BIM", "Toggle report panels on/off (Ctrl+0)"))
                togglebutton.setFlat(True)
                togglebutton.setCheckable(True)
                togglebutton.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
                togglebutton.customContextMenuRequested.connect(
                    toggleContextMenu)
                rv = mw.findChild(QtGui.QWidget, "Python console")
                if rv and rv.isVisible():
                    togglebutton.setChecked(True)
                statuswidget.togglebutton = togglebutton
                QtCore.QObject.connect(togglebutton,
                                       QtCore.SIGNAL("clicked(bool)"), toggle)
                statuswidget.addWidget(togglebutton)

                # bim views widget toggle button
                bimviewsbutton = QtGui.QPushButton()
                bwidth = bimviewsbutton.fontMetrics().boundingRect(
                    "AAAA").width()
                bimviewsbutton.setMaximumWidth(bwidth)
                bimviewsbutton.setIcon(
                    QtGui.QIcon(
                        os.path.join(os.path.dirname(__file__), "icons",
                                     "BIM_Views.svg")))
                bimviewsbutton.setText("")
                bimviewsbutton.setToolTip(
                    translate("BIM", "Toggle BIM views panel on/off (Ctrl+9)"))
                bimviewsbutton.setFlat(True)
                bimviewsbutton.setCheckable(True)
                if BimViews.findWidget():
                    bimviewsbutton.setChecked(True)
                statuswidget.bimviewsbutton = bimviewsbutton
                QtCore.QObject.connect(bimviewsbutton,
                                       QtCore.SIGNAL("clicked(bool)"),
                                       toggleBimViews)
                statuswidget.addWidget(bimviewsbutton)

                # update notifier button (starts hidden)
                updatebutton = QtGui.QPushButton()
                updatebutton.setObjectName("UpdateButton")
                updatebutton.setMaximumWidth(bwidth)
                updatebutton.setIcon(QtGui.QIcon(":/icons/view-refresh.svg"))
                updatebutton.setText("")
                updatebutton.setToolTip(
                    translate(
                        "BIM",
                        "An update to the BIM workbench is available. Click here to open the addons manager."
                    ))
                updatebutton.setFlat(True)
                QtCore.QObject.connect(updatebutton,
                                       QtCore.SIGNAL("pressed()"), addonMgr)
                updatebutton.hide()
                statuswidget.addWidget(updatebutton)
                QtCore.QTimer.singleShot(
                    2500,
                    checkUpdates)  # delay a bit the check for BIM WB update...
        else:
            if statuswidget:
                statuswidget.hide()
            else:
                # when switching workbenches, the toolbar sometimes "jumps"
                # out of the status bar to any other dock area...
                statuswidget = mw.findChild(QtGui.QToolBar, "BIMStatusWidget")
                if statuswidget:
                    statuswidget.hide()
Ejemplo n.º 6
0
    def slotChangedObject(self,obj,prop):

        BimViews.update()
        BimTutorial.update()
Ejemplo n.º 7
0
    def Initialize(self):

        # All BIM commands are specified either in BimCommands.py, or
        # in separate files (BimSetup.py, BimProject.py...) that are imported in BimCommands.
        # So importing BimCommands is all that is needed to get all the commands.

        import DraftTools
        import Arch
        import PartGui
        import SketcherGui

        import BimCommands
        import BimWelcome
        import BimSetup
        import BimProject
        import BimWindows
        import BimIfcElements
        import BimViews
        import BimClassification
        import BimBox
        import BimTutorial
        import BimLibrary
        import BimMaterial
        import BimIfcQuantities
        import BimIfcProperties
        import BimNudge
        import BimUnclone
        import BimPreflight
        import BimReextrude
        import BimDiff
        import BimIfcExplorer
        import BimLayers

        FreeCADGui.addCommand('BIM_TogglePanels',
                              BimCommands.BIM_TogglePanels())
        FreeCADGui.addCommand('BIM_Trash', BimCommands.BIM_Trash())
        FreeCADGui.addCommand('BIM_EmptyTrash', BimCommands.BIM_EmptyTrash())
        FreeCADGui.addCommand('BIM_Copy', BimCommands.BIM_Copy())
        FreeCADGui.addCommand('BIM_Clone', BimCommands.BIM_Clone())
        FreeCADGui.addCommand('BIM_Help', BimCommands.BIM_Help())
        FreeCADGui.addCommand('BIM_Glue', BimCommands.BIM_Glue())
        FreeCADGui.addCommand('BIM_Sketch', BimCommands.BIM_Sketch())
        FreeCADGui.addCommand('BIM_WPView', BimCommands.BIM_WPView())
        FreeCADGui.addCommand('BIM_Convert', BimCommands.BIM_Convert())
        FreeCADGui.addCommand('BIM_Ungroup', BimCommands.BIM_Ungroup())
        FreeCADGui.addCommand('BIM_Column', BimCommands.BIM_Column())
        FreeCADGui.addCommand('BIM_Beam', BimCommands.BIM_Beam())
        FreeCADGui.addCommand('BIM_Slab', BimCommands.BIM_Slab())
        FreeCADGui.addCommand('BIM_Door', BimCommands.BIM_Door())
        FreeCADGui.addCommand('BIM_ResetCloneColors',
                              BimCommands.BIM_ResetCloneColors())
        FreeCADGui.addCommand('BIM_Rewire', BimCommands.BIM_Rewire())
        FreeCADGui.addCommand('BIM_Welcome', BimWelcome.BIM_Welcome())
        FreeCADGui.addCommand('BIM_Setup', BimSetup.BIM_Setup())
        FreeCADGui.addCommand('BIM_Project', BimProject.BIM_Project())
        FreeCADGui.addCommand('BIM_Windows', BimWindows.BIM_Windows())
        FreeCADGui.addCommand('BIM_IfcElements',
                              BimIfcElements.BIM_IfcElements())
        FreeCADGui.addCommand('BIM_Views', BimViews.BIM_Views())
        FreeCADGui.addCommand('BIM_Classification',
                              BimClassification.BIM_Classification())
        FreeCADGui.addCommand('BIM_Box', BimBox.BIM_Box())
        FreeCADGui.addCommand('BIM_Tutorial', BimTutorial.BIM_Tutorial())
        FreeCADGui.addCommand('BIM_Library', BimLibrary.BIM_Library())
        FreeCADGui.addCommand('BIM_Material', BimMaterial.BIM_Material())
        FreeCADGui.addCommand('BIM_IfcQuantities',
                              BimIfcQuantities.BIM_IfcQuantities())
        FreeCADGui.addCommand('BIM_IfcProperties',
                              BimIfcProperties.BIM_IfcProperties())
        FreeCADGui.addCommand('BIM_Nudge_Switch', BimNudge.BIM_Nudge_Switch())
        FreeCADGui.addCommand('BIM_Nudge_Up', BimNudge.BIM_Nudge_Up())
        FreeCADGui.addCommand('BIM_Nudge_Down', BimNudge.BIM_Nudge_Down())
        FreeCADGui.addCommand('BIM_Nudge_Left', BimNudge.BIM_Nudge_Left())
        FreeCADGui.addCommand('BIM_Nudge_Right', BimNudge.BIM_Nudge_Right())
        FreeCADGui.addCommand('BIM_Nudge_Extend', BimNudge.BIM_Nudge_Extend())
        FreeCADGui.addCommand('BIM_Nudge_Shrink', BimNudge.BIM_Nudge_Shrink())
        FreeCADGui.addCommand('BIM_Nudge_RotateLeft',
                              BimNudge.BIM_Nudge_RotateLeft())
        FreeCADGui.addCommand('BIM_Nudge_RotateRight',
                              BimNudge.BIM_Nudge_RotateRight())
        FreeCADGui.addCommand('BIM_Unclone', BimUnclone.BIM_Unclone())
        FreeCADGui.addCommand('BIM_Preflight', BimPreflight.BIM_Preflight())
        FreeCADGui.addCommand('BIM_Diff', BimDiff.BIM_Diff())
        FreeCADGui.addCommand('BIM_IfcExplorer',
                              BimIfcExplorer.BIM_IfcExplorer())
        FreeCADGui.addCommand('BIM_Layers', BimLayers.BIM_Layers())

        self.draftingtools = [
            "BIM_Sketch", "Draft_Line", "Draft_Wire", "Draft_Circle",
            "Draft_Arc", "Draft_Ellipse", "Draft_Polygon", "Draft_Rectangle",
            "Draft_BSpline", "Draft_BezCurve", "Draft_Point"
        ]

        self.annotationtools = [
            "Draft_Text", "Draft_ShapeString", "Draft_Dimension",
            "Draft_Label", "Arch_Axis", "Arch_AxisSystem", "Arch_Grid",
            "Arch_SectionPlane"
        ]

        self.bimtools = [
            "Arch_Floor", "Arch_Building", "Arch_Site", "Arch_Space",
            "Separator", "Arch_Wall", "BIM_Column", "BIM_Beam", "BIM_Slab",
            "Arch_Rebar", "BIM_Door", "Arch_Window", "Arch_Pipe",
            "Arch_PipeConnector", "Arch_Stairs", "Arch_Roof", "Arch_Panel",
            "Arch_Frame", "Separator", "BIM_Box", "Part_Builder",
            "Draft_Facebinder", "BIM_Library"
        ]

        self.modify = [
            "Draft_Move", "BIM_Copy", "Draft_Rotate", "BIM_Clone",
            "BIM_Unclone", "Draft_Offset", "Part_Offset2D", "Draft_Trimex",
            "Draft_Join", "Draft_Split", "Draft_Scale", "Draft_Stretch",
            "BIM_Rewire", "BIM_Glue", "Draft_Upgrade", "Draft_Downgrade",
            "Draft_Draft2Sketch", "Arch_CutPlane", "Arch_Add", "Arch_Remove",
            "BIM_Reextrude", "Draft_Array", "Draft_PathArray",
            "Draft_PointArray", "Draft_Mirror", "Part_Extrude", "Part_Cut",
            "Part_Fuse", "Part_Common", "Part_Compound", "Part_SimpleCopy",
            "Draft_Shape2DView"
        ]

        # Support post-v0.18 tools

        if "Arch_Reference" in Gui.listCommands():
            self.bimtools.insert(-4, "Arch_Reference")
        if "Arch_Fence" in Gui.listCommands():
            self.bimtools.insert(-6, "Arch_Fence")
        if "Draft_Arc_3Points" in Gui.listCommands():
            self.draftingtools.insert(5, "Draft_Arc_3Points")
        if 'Draft_CubicBezCurve' in Gui.listCommands():
            self.draftingtools.insert(
                len(self.draftingtools) - 2, 'Draft_CubicBezCurve')

        # load rebar tools (Reinforcement addon)
        try:
            import RebarTools
        except:
            pass
        else:
            # create popup group for Rebar tools
            class RebarGroupCommand:
                def GetCommands(self):
                    return tuple(["Arch_Rebar"] + RebarTools.RebarCommands)

                def GetResources(self):
                    return {
                        'MenuText': 'Reinforcement tools',
                        'ToolTip': 'Reinforcement tools'
                    }

                def IsActive(self):
                    return not FreeCAD.ActiveDocument is None

            FreeCADGui.addCommand('Arch_RebarTools', RebarGroupCommand())
            self.bimtools[self.bimtools.index(
                "Arch_Rebar")] = "Arch_RebarTools"

        self.snap = [
            'Draft_ToggleGrid', 'Draft_Snap_Lock', 'Draft_Snap_Midpoint',
            'Draft_Snap_Perpendicular', 'Draft_Snap_Grid',
            'Draft_Snap_Intersection', 'Draft_Snap_Parallel',
            'Draft_Snap_Endpoint', 'Draft_Snap_Angle', 'Draft_Snap_Center',
            'Draft_Snap_Extension', 'Draft_Snap_Near', 'Draft_Snap_Ortho',
            'Draft_Snap_Special', 'Draft_Snap_Dimensions',
            'Draft_Snap_WorkingPlane'
        ]

        self.manage = [
            "BIM_Setup", "BIM_Project", "BIM_Views", "BIM_Windows",
            "BIM_IfcElements", "BIM_IfcQuantities", "BIM_IfcProperties",
            "BIM_Classification", "BIM_Material", "Arch_Schedule",
            "BIM_Preflight"
        ]

        self.utils = [
            "BIM_TogglePanels", "BIM_Trash", "BIM_WPView", "Draft_Slope",
            "Draft_SetWorkingPlaneProxy", "Draft_AddConstruction",
            "Arch_SplitMesh", "Arch_MeshToShape", "Arch_SelectNonSolidMeshes",
            "Arch_RemoveShape", "Arch_CloseHoles", "Arch_MergeWalls",
            "Arch_Check", "Arch_ToggleIfcBrepFlag", "Arch_ToggleSubs",
            "Arch_Survey", "BIM_Diff", "BIM_IfcExplorer"
        ]

        nudge = [
            "BIM_Nudge_Switch", "BIM_Nudge_Up", "BIM_Nudge_Down",
            "BIM_Nudge_Left", "BIM_Nudge_Right", "BIM_Nudge_RotateLeft",
            "BIM_Nudge_RotateRight", "BIM_Nudge_Extend", "BIM_Nudge_Shrink"
        ]

        # post-0.18 tools

        if "Draft_Layer" in Gui.listCommands():
            self.manage.insert(8, "BIM_Layers")

        # try to load bimbots

        try:
            import bimbots
        except:
            pass
        else:

            class BIMBots:
                def GetResources(self):
                    return bimbots.get_plugin_info()

                def Activated(self):
                    bimbots.launch_ui()

            FreeCADGui.addCommand('BIMBots', BIMBots())
            self.utils.append("BIMBots")

        # load Reporting

        try:
            import report
        except:
            pass
        else:
            if "Report_Create" in Gui.listCommands():
                self.manage[self.manage.index(
                    "Arch_Schedule")] = "Report_Create"

        # load webtools

        try:
            import BIMServer, Git, Sketchfab
        except:
            pass
        else:
            self.utils.extend(
                ["WebTools_Git", "WebTools_BimServer", "WebTools_Sketchfab"])

        # load flamingo

        try:
            import CommandsPolar, CommandsFrame, CommandsPipe
        except:
            flamingo = None
        else:
            flamingo = [
                "frameIt", "fillFrame", "insertPath", "insertSection",
                "FrameLineManager", "spinSect", "reverseBeam", "shiftBeam",
                "pivotBeam", "levelBeam", "alignEdge", "rotJoin",
                "alignFlange", "stretchBeam", "extend", "adjustFrameAngle",
                "insertPipe", "insertElbow", "insertReduct", "insertCap",
                "insertFlange", "insertUbolt", "insertPypeLine", "breakPipe",
                "mateEdges", "extend2intersection", "extend1intersection",
                "laydown", "raiseup"
            ]

        # load fasteners

        try:
            import FastenerBase, FastenersCmd
        except:
            fasteners = None
        else:
            fasteners = [
                c for c in FastenerBase.FSGetCommands("screws")
                if not isinstance(c, tuple)
            ]

        # create toolbars

        self.appendToolbar("Drafting tools", self.draftingtools)
        self.appendToolbar("3D/BIM tools", self.bimtools)
        self.appendToolbar("Annotation tools", self.annotationtools)
        self.appendToolbar("Modification tools", self.modify)
        self.appendToolbar("Manage tools", self.manage)

        #if flamingo:
        #    self.appendToolbar("Flamingo tools",flamingo)

        # create menus

        def QT_TRANSLATE_NOOP(scope, text):
            return text  # dummy function for the QT translator

        self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&2D Drafting"),
                        self.draftingtools)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&3D/BIM"), self.bimtools)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&Annotation"),
                        self.annotationtools)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&Snapping"), self.snap)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&Modify"), self.modify)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&Manage"), self.manage)
        if flamingo:
            self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&Flamingo"), flamingo)
        if fasteners:
            self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&Fasteners"), fasteners)
        self.appendMenu(QT_TRANSLATE_NOOP("BIM", "&Utils"), self.utils)
        self.appendMenu([QT_TRANSLATE_NOOP("BIM", "&Utils"), "Nudge"], nudge)
        self.appendMenu("&Help", ["BIM_Welcome", "BIM_Help", "BIM_Tutorial"])

        # load Arch & Draft preference pages

        if hasattr(FreeCADGui, "draftToolBar"):
            if not hasattr(FreeCADGui.draftToolBar, "loadedArchPreferences"):
                import Arch_rc
                FreeCADGui.addPreferencePage(":/ui/preferences-arch.ui",
                                             "Arch")
                FreeCADGui.addPreferencePage(
                    ":/ui/preferences-archdefaults.ui", "Arch")
                FreeCADGui.draftToolBar.loadedArchPreferences = True
            if not hasattr(FreeCADGui.draftToolBar, "loadedPreferences"):
                import Draft_rc
                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")
                FreeCADGui.draftToolBar.loadedPreferences = True

        # add translations path

        FreeCADGui.addLanguagePath(BimCommands.getLanguagePath())

        Log('Loading BIM module... done\n')
Ejemplo n.º 8
0
def setStatusIcons(show=True):

    "shows or hides the BIM icons in the status bar"

    from PySide import QtCore, QtGui

    def toggle(state):
        FreeCADGui.runCommand("BIM_TogglePanels")

    def toggleBimViews(state):
        FreeCADGui.runCommand("BIM_Views")

    def addonMgr():
        mw = FreeCADGui.getMainWindow()
        if mw:
            st = mw.statusBar()
            statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
            if statuswidget:
                updatebutton = statuswidget.findChild(QtGui.QPushButton,
                                                      "UpdateButton")
                if updatebutton:
                    statuswidget.actions()[-1].setVisible(False)
        FreeCADGui.runCommand("Std_AddonMgr")

    def setUnit(action):
        utext = action.text().replace("&", "")
        unit = [0, 4, 1, 3, 7, 5][[
            "Millimeters", "Centimeters", "Meters", "Inches", "Feet",
            "Architectural"
        ].index(utext)]
        FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt(
            "UserSchema", unit)
        if hasattr(FreeCAD.Units, "setSchema"):
            FreeCAD.Units.setSchema(unit)
        action.parent().parent().parent().setText(utext)

    class CheckWorker(QtCore.QThread):
        updateAvailable = QtCore.Signal(bool)

        def __init__(self):
            QtCore.QThread.__init__(self)

        def run(self):
            try:
                import git
            except:
                return
            FreeCAD.Console.PrintLog(
                "Checking for available updates of the BIM workbench\n")
            bimdir = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", "BIM")
            if os.path.exists(bimdir):
                if os.path.exists(bimdir + os.sep + '.git'):
                    gitrepo = git.Git(bimdir)
                    gitrepo.fetch()
                    if "git pull" in gitrepo.status():
                        self.updateAvailable.emit(True)
                        return
            self.updateAvailable.emit(False)

    def checkUpdates():
        FreeCAD.bim_update_checker = CheckWorker()
        FreeCAD.bim_update_checker.updateAvailable.connect(showUpdateButton)
        FreeCAD.bim_update_checker.start()

    def showUpdateButton(avail):
        if avail:
            mw = FreeCADGui.getMainWindow()
            if mw:
                st = mw.statusBar()
                statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
                if statuswidget:
                    updatebutton = statuswidget.findChild(
                        QtGui.QPushButton, "UpdateButton")
                    if updatebutton:
                        #updatebutton.show() # doesn't work for some reason
                        statuswidget.actions()[-1].setVisible(True)
        if hasattr(FreeCAD, "bim_update_checker"):
            del FreeCAD.bim_update_checker

    mw = FreeCADGui.getMainWindow()
    if mw:
        st = mw.statusBar()
        statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
        if show:
            if statuswidget:
                statuswidget.show()
            else:
                statuswidget = QtGui.QToolBar()
                statuswidget.setObjectName("BIMStatusWidget")

                # units chooser
                unitLabel = QtGui.QPushButton("Unit")
                unitLabel.setObjectName("UnitLabel")
                unitLabel.setFlat(True)
                unit = FreeCAD.ParamGet(
                    "User parameter:BaseApp/Preferences/Units").GetInt(
                        "UserSchema", 0)
                menu = QtGui.QMenu(unitLabel)
                gUnits = QtGui.QActionGroup(menu)
                for u in [
                        "Millimeters", "Centimeters", "Meters", "Inches",
                        "Feet", "Architectural"
                ]:
                    a = QtGui.QAction(gUnits)
                    a.setText(u)
                    menu.addAction(a)
                unitLabel.setMenu(menu)
                gUnits.triggered.connect(setUnit)
                unitLabel.setText([
                    "Millimeters", "Meters", "Inches", "Inches", "Centimeters",
                    "Architectural", "Millimeters", "Feet"
                ][unit])
                statuswidget.addWidget(unitLabel)
                st.addPermanentWidget(statuswidget)

                # report panels toggle button
                togglebutton = QtGui.QPushButton()
                bwidth = togglebutton.fontMetrics().boundingRect(
                    "AAAA").width()
                togglebutton.setMaximumWidth(bwidth)
                togglebutton.setIcon(
                    QtGui.QIcon(
                        os.path.join(os.path.dirname(__file__), "icons",
                                     "BIM_TogglePanels.svg")))
                togglebutton.setText("")
                togglebutton.setToolTip("Toggle report panels on/off")
                togglebutton.setFlat(True)
                togglebutton.setCheckable(True)
                rv = mw.findChild(QtGui.QWidget, "Python console")
                if rv and rv.isVisible():
                    togglebutton.setChecked(True)
                statuswidget.togglebutton = togglebutton
                QtCore.QObject.connect(togglebutton,
                                       QtCore.SIGNAL("clicked(bool)"), toggle)
                statuswidget.addWidget(togglebutton)

                # bim views widget toggle button
                bimviewsbutton = QtGui.QPushButton()
                bwidth = bimviewsbutton.fontMetrics().boundingRect(
                    "AAAA").width()
                bimviewsbutton.setMaximumWidth(bwidth)
                bimviewsbutton.setIcon(
                    QtGui.QIcon(
                        os.path.join(os.path.dirname(__file__), "icons",
                                     "BIM_Views.svg")))
                bimviewsbutton.setText("")
                bimviewsbutton.setToolTip("Toggle BIM views panel on/off")
                bimviewsbutton.setFlat(True)
                bimviewsbutton.setCheckable(True)
                if BimViews.findWidget():
                    bimviewsbutton.setChecked(True)
                statuswidget.bimviewsbutton = bimviewsbutton
                QtCore.QObject.connect(bimviewsbutton,
                                       QtCore.SIGNAL("clicked(bool)"),
                                       toggleBimViews)
                statuswidget.addWidget(bimviewsbutton)

                # update notifier button (starts hidden)
                updatebutton = QtGui.QPushButton()
                updatebutton.setObjectName("UpdateButton")
                updatebutton.setMaximumWidth(bwidth)
                updatebutton.setIcon(QtGui.QIcon(":/icons/view-refresh.svg"))
                updatebutton.setText("")
                updatebutton.setToolTip(
                    "An update to the BIM workbench is available. Click here to open the addons manager."
                )
                updatebutton.setFlat(True)
                QtCore.QObject.connect(updatebutton,
                                       QtCore.SIGNAL("pressed()"), addonMgr)
                updatebutton.hide()
                statuswidget.addWidget(updatebutton)
                QtCore.QTimer.singleShot(
                    2500,
                    checkUpdates)  # delay a bit the check for BIM WB update...
        else:
            if statuswidget:
                statuswidget.hide()
            else:
                # when switching workbenches, the toolbar sometimes "jumps"
                # out of the status bar to any other dock area...
                statuswidget = mw.findChild(QtGui.QToolBar, "BIMStatusWidget")
                if statuswidget:
                    statuswidget.hide()