Exemplo n.º 1
0
    def Initialize(self):
        """When the workbench is first loaded."""

        def QT_TRANSLATE_NOOP(context, text):
            return text

        # Run self-tests
        dependencies_OK = False
        try:
            from pivy import coin
            if FreeCADGui.getSoDBVersion() != coin.SoDB.getVersion():
                raise AssertionError("FreeCAD and Pivy use different versions "
                                     "of Coin. "
                                     "This will lead to unexpected behaviour.")
        except AssertionError:
            FreeCAD.Console.PrintWarning("Error: FreeCAD and Pivy "
                                         "use different versions of Coin. "
                                         "This will lead to unexpected "
                                         "behaviour.\n")
        except ImportError:
            FreeCAD.Console.PrintWarning("Error: Pivy not found, "
                                         "Draft Workbench will be disabled.\n")
        except Exception:
            FreeCAD.Console.PrintWarning("Error: Unknown error "
                                         "while trying to load Pivy.\n")
        else:
            dependencies_OK = True

        if not dependencies_OK:
            return

        # Import Draft tools, icons
        try:
            import Draft_rc
            import DraftTools
            import DraftGui
            import DraftFillet
            FreeCADGui.addLanguagePath(":/translations")
            FreeCADGui.addIconPath(":/icons")
        except Exception as exc:
            FreeCAD.Console.PrintError(exc)
            FreeCAD.Console.PrintError("Error: Initializing one or more "
                                       "of the Draft modules failed, "
                                       "Draft will not work as expected.\n")

        # Set up command lists
        import draftutils.init_tools as it
        self.drawing_commands = it.get_draft_drawing_commands()
        self.annotation_commands = it.get_draft_annotation_commands()
        self.modification_commands = it.get_draft_modification_commands()
        self.utility_commands_menu = it.get_draft_utility_commands_menu()
        self.utility_commands_toolbar = it.get_draft_utility_commands_toolbar()
        self.context_commands = it.get_draft_context_commands()

        # Set up toolbars
        it.init_toolbar(self,
                        QT_TRANSLATE_NOOP("Workbench", "Draft creation tools"),
                        self.drawing_commands)
        it.init_toolbar(self,
                        QT_TRANSLATE_NOOP("Workbench", "Draft annotation tools"),
                        self.annotation_commands)
        it.init_toolbar(self,
                        QT_TRANSLATE_NOOP("Workbench", "Draft modification tools"),
                        self.modification_commands)
        it.init_toolbar(self,
                        QT_TRANSLATE_NOOP("Workbench", "Draft utility tools"),
                        self.utility_commands_toolbar)

        # Set up menus
        it.init_menu(self,
                     [QT_TRANSLATE_NOOP("Workbench", "&Drafting")],
                     self.drawing_commands)
        it.init_menu(self,
                     [QT_TRANSLATE_NOOP("Workbench", "&Annotation")],
                     self.annotation_commands)
        it.init_menu(self,
                     [QT_TRANSLATE_NOOP("Workbench", "&Modification")],
                     self.modification_commands)
        it.init_menu(self,
                     [QT_TRANSLATE_NOOP("Workbench", "&Utilities")],
                     self.utility_commands_menu)

        # Set up preferences pages
        if hasattr(FreeCADGui, "draftToolBar"):
            if not hasattr(FreeCADGui.draftToolBar, "loadedPreferences"):
                FreeCADGui.addPreferencePage(":/ui/preferences-draft.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
                FreeCADGui.addPreferencePage(":/ui/preferences-draftinterface.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

        FreeCADGui.getMainWindow().mainWindowClosed.connect(self.Deactivated)

        FreeCAD.Console.PrintLog('Loading Draft workbench, done.\n')
Exemplo n.º 2
0
    def Initialize(self):
        """When the workbench is first loaded."""
        def QT_TRANSLATE_NOOP(context, text):
            return text

        import Draft_rc
        import DraftTools
        import DraftGui
        import Arch_rc
        import Arch

        from ArchStructure import _ArchStructureGroupCommand
        from ArchAxis import _ArchAxisGroupCommand
        from ArchPanel import CommandPanelGroup
        from ArchMaterial import _ArchMaterialToolsCommand
        from ArchPipe import _ArchPipeGroupCommand

        stru_group = _ArchStructureGroupCommand
        axis_group = _ArchAxisGroupCommand
        pan_group = CommandPanelGroup
        mat_group = _ArchMaterialToolsCommand
        pipe_group = _ArchPipeGroupCommand

        # Set up command lists
        self.archtools = [
            "Arch_Wall",
            ([QT_TRANSLATE_NOOP("Workbench", "Structure tools")],
             list(stru_group.GetCommands(stru_group))),  # tuple len=2: submenu
            ("Arch_StructureTools", ),  # tuple len=1: toolbar flyout
            "Arch_Rebar_Submenu",  # will be replaced or removed
            "Arch_Rebar",  # may be replaced
            "Arch_CurtainWall",
            "Arch_BuildingPart",
            "Arch_Project",
            "Arch_Site",
            "Arch_Building",
            "Arch_Floor",
            "Arch_Reference",
            "Arch_Window",
            "Arch_Roof",
            ([QT_TRANSLATE_NOOP("Workbench", "Axis tools")],
             list(axis_group.GetCommands(axis_group))),
            ("Arch_AxisTools", ),
            "Arch_SectionPlane",
            "Arch_Space",
            "Arch_Stairs",
            ([QT_TRANSLATE_NOOP("Workbench", "Panel tools")],
             list(pan_group.GetCommands(pan_group))),
            ("Arch_PanelTools", ),
            "Arch_Equipment",
            "Arch_Frame",
            "Arch_Fence",
            "Arch_Truss",
            "Arch_Profile",
            ([QT_TRANSLATE_NOOP("Workbench", "Material tools")],
             list(mat_group.GetCommands(mat_group))),
            ("Arch_MaterialTools", ),
            "Arch_Schedule",
            ([QT_TRANSLATE_NOOP("Workbench", "Pipe tools")],
             list(pipe_group.GetCommands(pipe_group))),
            ("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 Exception:
            del self.archtools[3]  # remove "Arch_Rebar_Submenu"
        else:

            class RebarGroupCommand:
                def GetCommands(self):
                    return tuple(RebarTools.RebarCommands + ["Arch_Rebar"])

                def GetResources(self):
                    return {
                        'MenuText':
                        QT_TRANSLATE_NOOP("Arch_RebarTools", "Rebar tools"),
                        'ToolTip':
                        QT_TRANSLATE_NOOP(
                            "Arch_RebarTools",
                            "Create various types of rebars, "
                            "including U-shaped, L-shaped, and stirrup")
                    }

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

            FreeCADGui.addCommand('Arch_RebarTools', RebarGroupCommand())
            self.archtools[3] = ([
                QT_TRANSLATE_NOOP("Workbench", "Rebar tools")
            ], RebarTools.RebarCommands + ["Arch_Rebar"])
            self.archtools[4] = ("Arch_RebarTools", )

        # Set up Draft command lists
        import draftutils.init_tools as it
        self.draft_drawing_commands = it.get_draft_drawing_commands()
        self.draft_annotation_commands = it.get_draft_annotation_commands()
        self.draft_modification_commands = it.get_draft_modification_commands()
        self.draft_utility_commands = it.get_draft_utility_commands_menu()
        self.draft_context_commands = it.get_draft_context_commands()

        # Set up toolbars
        it.init_toolbar(self, QT_TRANSLATE_NOOP("Workbench", "Arch tools"),
                        self.archtools)
        it.init_toolbar(self,
                        QT_TRANSLATE_NOOP("Workbench", "Draft creation tools"),
                        self.draft_drawing_commands)
        it.init_toolbar(
            self, QT_TRANSLATE_NOOP("Workbench", "Draft annotation tools"),
            self.draft_annotation_commands)
        it.init_toolbar(
            self, QT_TRANSLATE_NOOP("Workbench", "Draft modification tools"),
            self.draft_modification_commands)

        # Set up menus
        it.init_menu(self, [
            QT_TRANSLATE_NOOP("Workbench", "&Arch"),
            QT_TRANSLATE_NOOP("Workbench", "Utilities")
        ], self.utilities)
        it.init_menu(self, [QT_TRANSLATE_NOOP("Workbench", "&Arch")],
                     self.archtools)
        it.init_menu(self, [
            QT_TRANSLATE_NOOP("Workbench", "&Draft"),
            QT_TRANSLATE_NOOP("Workbench", "Creation")
        ], self.draft_drawing_commands)
        it.init_menu(self, [
            QT_TRANSLATE_NOOP("Workbench", "&Draft"),
            QT_TRANSLATE_NOOP("Workbench", "Annotation")
        ], self.draft_annotation_commands)
        it.init_menu(self, [
            QT_TRANSLATE_NOOP("Workbench", "&Draft"),
            QT_TRANSLATE_NOOP("Workbench", "Modification")
        ], self.draft_modification_commands)
        it.init_menu(self, [
            QT_TRANSLATE_NOOP("Workbench", "&Draft"),
            QT_TRANSLATE_NOOP("Workbench", "Utilities")
        ], self.draft_utility_commands)

        FreeCADGui.addIconPath(":/icons")
        FreeCADGui.addLanguagePath(":/translations")

        # Set up preferences pages
        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",
                    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

        FreeCAD.Console.PrintLog('Loading Arch workbench, done.\n')
Exemplo n.º 3
0
    def Initialize(self):
        "This function is executed when FreeCAD starts"
        import BOPTools  # as bop
        import Design456_Part as designPart
        import Design456_2Ddrawing as TwoDDraw
        import Design456_Part_Tools as _tools
        import Design456_Alignment as _alignment
        import Design456_SelectionGate as SelGate
        import DirectModeling.directModelingCommands as dModeling
        import DefeaturingWB.DefeaturingTools
        import DefeaturingWB.DefeaturingCMD
        import DefeaturingWB.FuzzyTools
        import Design456Init
        from Design456Pref import Design456Preferences
        import Design456_Segmented as _segmented

        # from Part import CommandShapes     #Tube  not working
        Gui.runCommand('Std_PerspectiveCamera', 1)

        self.appendToolbar("Design456_Part", designPart.Design456_Part.list)
        self.appendToolbar("Design456 2Ddrawing",
                           TwoDDraw.Design456_2Ddrawing.list)
        self.appendToolbar("Design456_Segmented",
                           _segmented.Design456_Segmented.list)

        self.appendToolbar("Design456 Tools", _tools.Design456_Part_Tools.list)
        self.appendToolbar("Design456 Alignment",
                           _alignment.Design456_Alignment_Tools.list)
        self.appendToolbar("Selection Mode",
                           SelGate.Design456_SelectionGate.list)
        self.appendToolbar("Direct Modeling",
                           dModeling.Design456_DirectModeling.list)

        self.appendMenu("Design456_Part", designPart.Design456_Part.list)
        self.appendMenu("Design456_2Ddrawing",
                        TwoDDraw.Design456_2Ddrawing.list)
        self.appendMenu("Design456 Tools", _tools.Design456_Part_Tools.list)
        self.appendMenu("Design456 Alignment",
                        _alignment.Design456_Alignment_Tools.list)

        # Defeaturing WB  added to Design456
        self.appendToolbar("Defeaturing Tools", [
            "DefeaturingTools", "DF_SelectLoop", "refineFeatureTool",
            "DefeatShapeFeature"
        ])
        #self.appendMenu("ksu Tools", ["ksuTools","ksuToolsEdit"])
        self.appendMenu(
            "Defeaturing Tools",
            ["refineFeatureTool", "DefeaturingTools", "DF_SelectLoop"])
        self.appendToolbar("Fuzzy Tools",
                           ["FuzzyCut", "FuzzyUnion", "FuzzyCommon"])
        self.appendMenu("Fuzzy Tools",
                        ["FuzzyCut", "FuzzyUnion", "FuzzyCommon"])
        Gui.addIconPath(Design456Init.ICON_PATH)

        # Design456_Part
        # self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Drafting"), self.drawing_commands)

        # Design456_Part
        # DRAFT
        def QT_TRANSLATE_NOOP(context, text):
            return text

        # Run self-tests
        dependencies_OK = False
        try:
            from pivy import coin
            import FreeCAD
            import FreeCADGui
            if FreeCADGui.getSoDBVersion() != coin.SoDB.getVersion():
                raise AssertionError("FreeCAD and Pivy use different versions "
                                     "of Coin. "
                                     "This will lead to unexpected behaviour.")
        except AssertionError:
            FreeCAD.Console.PrintWarning("Error: FreeCAD and Pivy "
                                         "use different versions of Coin. "
                                         "This will lead to unexpected "
                                         "behaviour.\n")
        except ImportError:
            FreeCAD.Console.PrintWarning("Error: Pivy not found, "
                                         "Draft Workbench will be disabled.\n")
        except Exception:
            FreeCAD.Console.PrintWarning("Error: Unknown error "
                                         "while trying to load Pivy.\n")
        else:
            dependencies_OK = True

        if not dependencies_OK:
            return

        # Import Draft tools, icons
        try:
            import Draft_rc
            import DraftTools
            import DraftGui
            import DraftFillet
            import FreeCAD
            import FreeCADGui

            FreeCADGui.addLanguagePath(":/translations")
            FreeCADGui.addIconPath(":/icons")
        except Exception as exc:
            FreeCAD.Console.PrintError(exc)
            FreeCAD.Console.PrintError("Error: Initializing one or more "
                                       "of the Draft modules failed, "
                                       "Draft will not work as expected.\n")
        try:
            # Set up command lists
            import draftutils.init_tools as it
            self.drawing_commands = it.get_draft_drawing_commands()
            self.annotation_commands = it.get_draft_annotation_commands()
            self.modification_commands = it.get_draft_modification_commands()
            self.utility_commands_menu = it.get_draft_utility_commands_menu()
            self.utility_commands_toolbar = it.get_draft_utility_commands_toolbar(
            )
            self.context_commands = it.get_draft_context_commands()

            # Set up toolbars
            it.init_toolbar(self,
                            QT_TRANSLATE_NOOP("Draft", "Draft creation tools"),
                            self.drawing_commands)
            it.init_toolbar(
                self, QT_TRANSLATE_NOOP("Draft", "Draft annotation tools"),
                self.annotation_commands)
            it.init_toolbar(
                self, QT_TRANSLATE_NOOP("Draft", "Draft modification tools"),
                self.modification_commands)
            it.init_toolbar(self,
                            QT_TRANSLATE_NOOP("Draft", "Draft utility tools"),
                            self.utility_commands_toolbar)

            # Set up menus
            it.init_menu(self, [QT_TRANSLATE_NOOP("Draft", "&Drafting")],
                         self.drawing_commands)
            it.init_menu(self, [QT_TRANSLATE_NOOP("Draft", "&Annotation")],
                         self.annotation_commands)
            it.init_menu(self, [QT_TRANSLATE_NOOP("Draft", "&Modification")],
                         self.modification_commands)
            it.init_menu(self, [QT_TRANSLATE_NOOP("Draft", "&Utilities")],
                         self.utility_commands_menu)

            # Set up preferences pages
            if hasattr(FreeCADGui, "draftToolBar"):
                if not hasattr(FreeCADGui.draftToolBar, "loadedPreferences"):
                    FreeCADGui.addPreferencePage(
                        ":/ui/preferences-draft.ui",
                        QT_TRANSLATE_NOOP("Draft", "Draft"))
                    FreeCADGui.addPreferencePage(
                        ":/ui/preferences-draftinterface.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

            FreeCAD.Console.PrintLog('Loading Draft workbench, done.\n')

            # END DRAFT
        except Exception as exc:
            App.Console.PrintError(exc)
            App.Console.PrintError("Error: Initializing one or more "
                                   "of the Draft modules failed, "
                                   "Design456 will not work as expected.\n")