Example #1
0
    def Initialize(self):
        def QT_TRANSLATE_NOOP(scope, text):
            return text

        #import GDMLCommands, GDMLResources
        commands=['CycleCommand','ExpandCommand', \
              'PolyHedraCommand', 'BoxCommand','ConeCommand','ElTubeCommand', \
              'EllipsoidCommand','SphereCommand', \
              'TrapCommand','TubeCommand','AddCompound', \
              'TessellateCommand', 'Mesh2TessCommand']
        toolbarcommands=['CycleCommand','ExpandCommand',
              'PolyHedraCommand', 'BoxCommand','ConeCommand', \
                  'ElTubeCommand', 'EllipsoidCommand','SphereCommand', \
                  'TrapCommand','TubeCommand','AddCompound', \
                  'TessellateCommand', 'Mesh2TessCommand']

        parttoolbarcommands = ['Part_Cut', 'Part_Fuse', 'Part_Common']
        meshtoolbarcommands = ['Mesh_FromPartShape']

        self.appendToolbar(QT_TRANSLATE_NOOP('Workbench', 'GDMLTools'),
                           toolbarcommands)
        self.appendMenu('GDML', commands)
        self.appendToolbar(QT_TRANSLATE_NOOP('Workbech', 'GDML Part tools'),
                           parttoolbarcommands)
        FreeCADGui.addIconPath(joinDir("Resources/icons"))
        FreeCADGui.addLanguagePath(joinDir("Resources/translations"))
        FreeCADGui.addPreferencePage(joinDir("Resources/ui/GDML-base.ui"),
                                     "GDML")
Example #2
0
    def Initialize(self):
        # run self-tests
        depsOK = 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, DDA workbench will be disabled.\n")
        except:
            FreeCAD.Console.PrintWarning("Error: Unknown error while trying to load Pivy\n")
        else:
            try:
                import PyQt4
            except ImportError:
                FreeCAD.Console.PrintWarning("Error: PyQt4 not found, DDA workbench will be disabled.\n")
            else:
                depsOK = True

#        import FreeCAD , FreeCADGui

        import DDA_rc
        import FreeCADGui

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


#            try:
        import DDAShapes
#            except:
#                FreeCAD.Console.PrintWarning("'DDAShapes' moudle import failed.")

        import DGPlayer , DFCalculation , DDAPanel
#            try:
        import drawGui 
#            except:
#                FreeCAD.Console.PrintWarning("'drawGui' moudle import failed.")
        import DDAToolbars

        import interfaceTools
        import storeScene
        import loadDataTools
        import DDAStdCommands
        import AnalysisDDAResult
#        FreeCADGui.addPreferencePage(":/DDA-preferences.ui","DDA")
#        FreeCADGui.addPreferencePage(":/userprefs-base.ui","DDA")
#        FreeCAD.Console.PrintMessage('Loading DDA GUI...\n')
        
        import DDAGui
        list = ['DDA_NewDoc' , 'DDA_Undo' , 'DDA_Redo',  'Std_ViewFitAll' , 'DDA_ChooseProjectPath' , 'DDA_Examples', 'DDA_DL' , 'DDA_DC','DFCalculation','PlayDF', 'DDA_DGAnalysiser' ]
#        list = ['DDA_NewDoc' , 'DDA_Undo' , 'DDA_Redo', 'DDA_ChooseProjectPath' , 'DDA_SetPanelSize' , 'DDA_DL' , 'DDA_DC','DFCalculation','PlayDF']
        self.appendToolbar('DDACmds' , list)
Example #3
0
def setup_translation():
    import FreeCADGui as Gui
    global tr_encoding, tr_initialized
    try:
        log('Loading Translations...')
        Gui.addLanguagePath(str(get_resource_path('translations')))
        Gui.updateLocale()
        tr_initialized = 1
        try:
            tr_encoding = QtGui.QApplication.UnicodeUTF8
        except:
            tr_encoding = None
    except Exception as ex:
        log('Translation loading error: ', str(ex))
        tr_initialized = -1
Example #4
0
    def Initialize(self):
        #"This function is executed when FreeCAD starts"
        import EB_Commands, MeasureEdges  # import here all the needed files that create your FreeCAD commands
        self.listTests = ([
            "Clear_Console", "EnableConnectionToEB", "DisableConnectionToEB",
            "ShowTestsConsole"
        ])
        self.appendToolbar("EB Tests", self.listTests)

        self.list = ([
            "Get_EB_Shape", "Get_EB_Shape_Step", "Add_EB_Shape_With_Shift",
            "Add_EB_Shape_With_Shift_Step", "Add_EB_Step_Assembly",
            "Select_EB_Shape"
        ])  # A list of command names created in the line above
        self.appendToolbar(
            "EB Commands",
            self.list)  # creates a new toolbar with your commands
        self.appendMenu("Engineering Base", self.list)  # creates a new menu
        self.listAux = ([
            "Get_DIN_Rail_TS35", "Get_Terminal_Block", "Get_GuiTab"
        ])
        self.appendToolbar("EB Aux", self.listAux)
        # import Draft tools, icons
        try:
            import os, Draft_rc, DraftTools, DraftGui, Draft
            from DraftTools import translate
            FreeCADGui.addLanguagePath(":/translations")
            FreeCADGui.addIconPath(":/icons")
        except Exception as inst:
            print(inst)
            FreeCAD.Console.PrintError(
                "Error: Initializing one or more of the Draft modules failed, Draft will not work as expected.\n"
            )
        self.createList = [
            "Draft_Line", "Draft_Wire", "Draft_Circle", "Draft_Ellipse",
            "Draft_Polygon", "Draft_Rectangle", "Draft_Point"
        ]
        self.appendToolbar("Create", self.createList)
        self.moveList = [
            "Mover_For_Object", "Draft_Move", "Draft_Rotate",
            "Move_Piont_To_Point", "Rotate_Sel_Object_15"
        ]
        self.appendToolbar("EB Move", self.moveList)
        self.visibilityList = [
            "Set_Transparancy", "Set_Display_Mode_Wire_Frame",
            "Set_Display_Mode_Flat_Lines", "Set_Visibility_True"
        ]
        self.appendToolbar("EB Visibility", self.visibilityList)
Example #5
0
    def Initialize(self):
        def QT_TRANSLATE_NOOP(scope, text):
            return text
        
        #import GDMLCommands, GDMLResources
        commands=['CycleCommand','ColourMapCommand','ExpandCommand', \
              'ExpandMaxCommand','SetMaterialCommand', \
              'BoxCommand','ConeCommand','ElTubeCommand', \
              'EllipsoidCommand','SphereCommand', \
              'TorusCommand','TrapCommand','TubeCommand', \
              'Sketcher_NewSketch','Part_Extrude', \
              'BooleanCutCommand','BooleanIntersectionCommand', \
              'BooleanUnionCommand', \
              'TessellateCommand','TessellateGmshCommand', \
              'DecimateCommand', \
              'Mesh_FromPartShape','Mesh_Evaluation', \
              'Mesh2TessCommand','Tess2MeshCommand', 'TetrahedronCommand', \
              'AddCompound']

        toolbarcommands=['CycleCommand','ColourMapCommand','ExpandCommand',
              'ExpandMaxCommand', 'SetMaterialCommand', \
              'Separator','Std_Part','BoxCommand','ConeCommand', \
              'ElTubeCommand', 'EllipsoidCommand','SphereCommand', \
              'TorusCommand','TrapCommand','TubeCommand', \
              'Sketcher_NewSketch','Part_Extrude', \
              'Separator', 'BooleanCutCommand','BooleanIntersectionCommand', \
              'BooleanUnionCommand','Separator', \
              'TessellateCommand','TessellateGmshCommand', \
              'DecimateCommand', \
              'Mesh_FromPartShape','Mesh_Evaluation', \
              'Mesh2TessCommand','Tess2MeshCommand','TetrahedronCommand', \
              'AddCompound']

        #parttoolbarcommands = ['Part_Cut','Part_Fuse','Part_Common']
        #meshtoolbarcommands = ['Mesh_FromPartShape','Mesh_Evaluation']

        self.appendToolbar(QT_TRANSLATE_NOOP('Workbench','GDMLTools'),toolbarcommands)
        self.appendMenu('GDML',commands)
        #self.appendToolbar(QT_TRANSLATE_NOOP('Workbech','GDML Part tools'),parttoolbarcommands)
        #self.appendToolbar(QT_TRANSLATE_NOOP('Workbech','GDML Mesh Tools'),meshtoolbarcommands)
        FreeCADGui.addIconPath(joinDir("Resources/icons"))
        FreeCADGui.addLanguagePath(joinDir("Resources/translations"))
        FreeCADGui.addPreferencePage(joinDir("Resources/ui/GDML-base.ui"),"GDML")
Example #6
0
    def Initialize(self):
        def QT_TRANSLATE_NOOP(scope, text):
            return text

        #import 2SCommands
        commands=['toSPlaneCommand','toSketchCommand','toMacroCommand', \
                  'toCurveFitCommand', \
                  'toScaleCommand','toResetOriginCommand']

        toolbarcommands=['toSPlaneCommand','toSketchCommand','toMacroCommand', \
                  'toCurveFitCommand', \
                  'toScaleCommand','toResetOriginCommand']

        import PartGui
        parttoolbarcommands = ['Part_Loft']
        self.appendToolbar(QT_TRANSLATE_NOOP('Workbench', \
                           'toSketch_Tools'),toolbarcommands)
        self.appendToolbar(QT_TRANSLATE_NOOP('Workbench', \
                           'toSketch_Tools Part Tools'),parttoolbarcommands)
        self.appendMenu('toSketch', commands)
        FreeCADGui.addIconPath(joinDir("Resources/icons"))
        FreeCADGui.addLanguagePath(joinDir("Resources/translations"))
Example #7
0
    def Initialize(self):
        """This function is executed when FreeCAD starts"""
        import RebarTools

        from BillOfMaterial.BOMPreferences import BOMPreferences
        from pathlib import Path

        self.rebar_commands = RebarTools.ReinforcementCommands
        self.appendToolbar("RebarCommands", self.rebar_commands)

        BOMPreferences()
        FreeCADGui.addPreferencePage(
            str(
                Path(RebarTools.__file__).parent.absolute() /
                "BillOfMaterial" / "BOMPreferences.ui"),
            "Reinforcement",
        )
        FreeCADGui.addIconPath(
            str(
                Path(RebarTools.__file__).parent.absolute() / "icons" /
                "preferences"))
        FreeCADGui.addLanguagePath(
            str(Path(RebarTools.__file__).parent.absolute() / "translations"))
Example #8
0
    def Initialize(self):
        # run self-tests
        depsOK = 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, DDA workbench will be disabled.\n")
        except:
            FreeCAD.Console.PrintWarning(
                "Error: Unknown error while trying to load Pivy\n")
        else:
            try:
                import PyQt4
            except ImportError:
                FreeCAD.Console.PrintWarning(
                    "Error: PyQt4 not found, DDA workbench will be disabled.\n"
                )
            else:
                depsOK = True

#        import FreeCAD , FreeCADGui

        import DDA_rc
        import FreeCADGui

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

        #            try:
        import DDAShapes
        #            except:
        #                FreeCAD.Console.PrintWarning("'DDAShapes' moudle import failed.")

        import DGPlayer, DFCalculation, DDAPanel
        #            try:
        import drawGui
        #            except:
        #                FreeCAD.Console.PrintWarning("'drawGui' moudle import failed.")
        import DDAToolbars

        import interfaceTools
        import storeScene
        import loadDataTools
        import DDAStdCommands
        import AnalysisDDAResult
        #        FreeCADGui.addPreferencePage(":/DDA-preferences.ui","DDA")
        #        FreeCADGui.addPreferencePage(":/userprefs-base.ui","DDA")
        #        FreeCAD.Console.PrintMessage('Loading DDA GUI...\n')

        import DDAGui
        list = [
            'DDA_NewDoc', 'DDA_Undo', 'DDA_Redo', 'Std_ViewFitAll',
            'DDA_ChooseProjectPath', 'DDA_DL', 'DDA_DC', 'DFCalculation',
            'PlayDF', 'DDA_DGAnalysiser', 'DDA_Examples'
        ]
        #        list = ['DDA_NewDoc' , 'DDA_Undo' , 'DDA_Redo', 'DDA_ChooseProjectPath' , 'DDA_SetPanelSize' , 'DDA_DL' , 'DDA_DC','DFCalculation','PlayDF']
        self.appendToolbar('DDACmds', list)
Example #9
0
from collections import OrderedDict
import os
import FreeCAD, FreeCADGui
from pivy import coin
from PySide import QtCore, QtGui
try:
    from six import with_metaclass
except ImportError:
    from .deps import with_metaclass
from .utils import getElementPos, objName, addIconToFCAD, guilogger as logger
from .proxy import ProxyType
from .FCADLogger import FCADLogger

FreeCADGui.addLanguagePath(
    os.path.join(os.path.dirname(__file__), "translations"))

from FreeCAD import Qt

translate = Qt.translate
QT_TRANSLATE_NOOP = Qt.QT_TRANSLATE_NOOP


def _isCommandActive(cmd):
    try:
        return FreeCADGui.Command.isActive(FreeCADGui.Command.get(cmd))
    except Exception:
        pass
    try:
        return FreeCADGui.isCommandActive(cmd)
    except Exception:
        return True
Example #10
0
#*   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                                                                   *
#*                                                                         *
#***************************************************************************


# This is the start page template. It builds a HTML global variable that contains
# the html code of the start page. It is built only once per FreeCAD session for now...

import sys,os,FreeCAD,FreeCADGui,tempfile,time,zipfile,urllib,re
from . import TranslationTexts
from PySide import QtCore,QtGui

FreeCADGui.addLanguagePath(":/translations")
FreeCADGui.updateLocale()

iconprovider = QtGui.QFileIconProvider()
iconbank = {} # to store already created icons so we don't overpollute the temp dir
tempfolder = None # store icons inside a subfolder in temp dir
defaulticon = None # store a default icon for problematic file types


def encode(text):

    "make sure we are always working with unicode in python2"

    if sys.version_info.major < 3:
        if not isinstance(text,unicode):
            return text.decode("utf8")
def updateLocale():
    FreeCADGui.addLanguagePath(
        os.path.join(os.path.dirname(__file__), "translations"))
    FreeCADGui.updateLocale()
Example #12
0
    def Initialize(self):
        from a2p_translateUtils import QT_TRANSLATE_NOOP
        from a2p_translateUtils import translate
        from a2p_translateUtils import tr_
        
        import sys
        PyVersion = sys.version_info[0]
        if PyVersion == 2:
            import a2p_Resources2
        else:
            import a2p_Resources3
        import a2plib
        
        # add translations path
        FreeCADGui.addLanguagePath(a2plib.getLanguagePath())
        print("languagePath of A2plus Workbench is: {}".format(a2plib.getLanguagePath()))
        
        import a2p_importpart
        import a2p_recursiveUpdatePlanner
        import a2p_convertPart
        import a2p_solversystem
        import a2p_MuxAssembly
        import a2p_partinformation
        import a2p_constraintDialog
        import a2p_constraintcommands
        import a2p_bom # bom == bill of materials == partslist
        import a2p_constraintServices
        import a2p_searchConstraintConflicts

        if a2plib.getRecursiveUpdateEnabled():
            partCommands = [
                'a2p_ImportPart',
                'a2p_ImportShapeReferenceCommand',
                'a2p_updateImportedParts',
                'a2p_recursiveUpdateImportedPartsCommand',
                'a2p_movePart',
                'a2p_MovePartUnderConstraints',
                'a2p_duplicatePart',
                'a2p_ConvertPart',
                'a2p_editImportedPart',
                'a2p_SaveAndExit_Command',
                ]
        else:
            partCommands = [
                'a2p_ImportPart',
                'a2p_ImportShapeReferenceCommand',
                'a2p_updateImportedParts',
                'a2p_movePart',
                'a2p_MovePartUnderConstraints',
                'a2p_duplicatePart',
                'a2p_ConvertPart',
                'a2p_editImportedPart',
                'a2p_SaveAndExit_Command',
                ]
        
        if a2plib.SHOW_CONSTRAINTS_ON_TOOLBAR:
            constraintCommands = [
                'a2p_ConstraintDialogCommand',
                'a2p_EditConstraintCommand',
                'a2p_reAdjustConstraintDirectionsCommand',
                'a2p_DeleteConnectionsCommand',
                'a2p_PointIdentityConstraintCommand',
                'a2p_PointOnLineConstraintCommand',
                'a2p_PointOnPlaneConstraintCommand',
                'a2p_SphericalSurfaceConstraintCommand',
                'a2p_CircularEdgeConnection',
                'a2p_AxialConstraintCommand',
                'a2p_AxisParallelConstraintCommand',
                'a2p_AxisPlaneParallelCommand',
                'a2p_AxisPlaneNormalCommand',
                'a2p_AxisPlaneAngleCommand',
                'a2p_PlanesParallelConstraintCommand',
                'a2p_PlaneCoincidentConstraintCommand',
                'a2p_AngledPlanesConstraintCommand',
                'a2p_CenterOfMassConstraintCommand',
                ]
        else:
            constraintCommands = [
                'a2p_ConstraintDialogCommand',
                'a2p_EditConstraintCommand',
                'a2p_reAdjustConstraintDirectionsCommand',
                'a2p_DeleteConnectionsCommand',
                ]
        
        if a2plib.GRAPHICALDEBUG:
            solverCommands = [
                'a2p_SolverCommand',
                'a2p_ToggleAutoSolveCommand',
                'a2p_FlipConstraintDirectionCommand',
                'a2p_Show_Hierarchy_Command',
                'a2p_SearchConstraintConflictsCommand',
                'a2p_cleanUpDebug3dCommand'
                ]
        else:
            solverCommands = [
                'a2p_SolverCommand',
                'a2p_ToggleAutoSolveCommand',
                'a2p_FlipConstraintDirectionCommand',
                'a2p_Show_Hierarchy_Command',
                'a2p_SearchConstraintConflictsCommand'
                ]
        viewCommands = [
            'a2p_isolateCommand',
            'a2p_ViewConnectionsCommand',
            'a2p_Restore_Transparency',
            'a2p_ToggleTransparencyCommand',            
            'a2p_Show_PartLabels_Command',
            'a2p_Show_DOF_info_Command',
            ]
        miscCommands = [
            'a2p_SimpleAssemblyShapeCommand',
            'a2p_repairTreeViewCommand',
            'a2p_CreatePartInformationSheet_Command',
            'a2p_CreatePartlist',
            ]

        self.appendToolbar(
               'A2p_Part',
               partCommands
               )
        self.appendToolbar(
               'A2p_Constraint',
               constraintCommands
               )
        self.appendToolbar(
               'A2p_Solver',
               solverCommands
               )
        self.appendToolbar(
               'A2p_View',
               viewCommands
               )
        self.appendToolbar(
               'A2p_Misc',
               miscCommands
               )

        self.appendMenu(
            'A2plus',
            partCommands
            )
        self.appendMenu(
            ['A2plus', 'Constraint'],
            constraintCommands
            )
        self.appendMenu(
            ['A2plus', 'Solver'],
            solverCommands
            )
        self.appendMenu(
            ['A2plus', 'View'],
            viewCommands
            )
        self.appendMenu(
            ['A2plus', 'Misc'],
            miscCommands
            )            
            
        menuEntries = [
            'a2p_absPath_to_relPath_Command',
            'a2p_MigrateProxiesCommand'
            ]
        self.appendMenu(
            ['A2plus', 'Misc'],
            menuEntries
            )
        FreeCADGui.addIconPath(':/icons')
        
        FreeCADGui.addPreferencePage(
            a2plib.pathOfModule() +
            '/GuiA2p/Resources/ui/a2p_prefs.ui','A2plus'
            )
Example #13
0
    def __init__(self):

        # this is to be able to cancel running progress
        self.running = True

        # locate and load available translations
        FreeCADGui.addLanguagePath(os.path.join(os.path.dirname(__file__),"translations"))

        # load the ui file. Widgets re automatically named from the ui file
        self.form = FreeCADGui.PySideUic.loadUi(os.path.join(os.path.dirname(__file__),"bimbots.ui"))

        # set the logo and icon
        self.form.setWindowIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","BIM-Bots-validationchecker.png")))
        logo = QtGui.QPixmap(os.path.join(os.path.dirname(__file__),"icons","BIM-Bots-header.png"))
        w = self.form.servicesList.width()
        h = int(w*0.2578)
        self.form.labelLogo.setText("")
        self.form.labelLogo.setPixmap(logo.scaled(w,h))
        # hide the logo for now TODO : Do something better here...
        self.form.labelLogo.hide()

        # hide the collapsible parts
        self.form.groupProgress.hide()
        self.form.groupRescan.hide()
        self.form.groupAddService.hide()
        self.form.groupAuthenticate.hide()
        self.form.groupResults.hide()

        # restore default settings
        self.get_defaults()

        # connect buttons
        self.form.buttonRescan.clicked.connect(self.form.groupRescan.show)
        self.form.buttonDoRescan.clicked.connect(self.form.groupRescan.hide)
        self.form.buttonDoRescan.clicked.connect(self.on_scan)
        self.form.buttonCancelRescan.clicked.connect(self.form.groupRescan.hide)
        self.form.buttonAddService.clicked.connect(self.form.groupAddService.show)
        self.form.buttonRemoveService.clicked.connect(self.on_remove_service)
        self.form.buttonSaveService.clicked.connect(self.on_add_service)
        self.form.buttonCancelService.clicked.connect(self.form.groupAddService.hide)
        self.form.buttonAuthenticate.clicked.connect(self.form.groupAuthenticate.show)
        self.form.buttonAuthenticate.clicked.connect(self.on_authenticate)
        self.form.buttonSaveAuthenticate.clicked.connect(self.on_save_authenticate)
        self.form.buttonCancelAuthenticate.clicked.connect(self.form.groupAuthenticate.hide)
        self.form.buttonRun.clicked.connect(self.on_run)
        self.form.buttonCancelProgress.clicked.connect(self.on_cancel)
        self.form.buttonCloseResults.clicked.connect(self.form.groupServices.show)
        self.form.buttonCloseResults.clicked.connect(self.form.groupRun.show)
        self.form.buttonCloseResults.clicked.connect(self.form.groupResults.hide)

        # fields validation
        self.form.lineEditServiceName.textChanged.connect(self.validate_fields)
        self.form.lineEditServiceUrl.textChanged.connect(self.validate_fields)
        self.form.lineEditAuthenticateUrl.textChanged.connect(self.validate_fields)
        self.form.lineEditAuthenticateToken.textChanged.connect(self.validate_fields)

        # connect services list
        self.form.servicesList.currentItemChanged.connect(self.on_list_click)
        self.form.scopeList.currentItemChanged.connect(self.on_list_click)

        # connect widgets that should remember their setting
        self.form.checkAutoDiscover.stateChanged.connect(self.save_defaults)
        self.form.checkShowUnreachable.stateChanged.connect(self.save_defaults)

        # connect clickable links
        self.form.treeResults.itemDoubleClicked.connect(self.on_click_results)
        self.form.labelHelp.linkActivated.connect(self.on_click_help)

        # perform initial scan after the UI has been fully drawn
        QtCore.QTimer.singleShot(0,self.on_scan)

        # remove test items if needed
        if not DEBUG:
            self.form.scopeList.takeItem(5) # Test output only
            self.form.scopeList.takeItem(4) # Test payload
            self.form.scopeList.takeItem(3) # External IFC file
def updateLocale():
    FreeCADGui.addLanguagePath(str(Path(__file__).parent / "translations"))
    FreeCADGui.updateLocale()
Example #15
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
            from draftguitools import gui_circulararray
            from draftguitools import gui_polararray
            from draftguitools import gui_orthoarray
            from draftguitools import gui_arrays
            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.context_commands = it.get_draft_context_commands()
        self.line_commands = it.get_draft_line_commands()
        self.utility_commands = it.get_draft_utility_commands()

        # Set up toolbars
        self.appendToolbar(QT_TRANSLATE_NOOP("Draft", "Draft creation tools"),
                           self.drawing_commands)
        self.appendToolbar(
            QT_TRANSLATE_NOOP("Draft", "Draft annotation tools"),
            self.annotation_commands)
        self.appendToolbar(
            QT_TRANSLATE_NOOP("Draft", "Draft modification tools"),
            self.modification_commands)

        # Set up menus
        self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Drafting"),
                        self.drawing_commands)
        self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Annotation"),
                        self.annotation_commands)
        self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Modification"),
                        self.modification_commands)
        self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Utilities"),
                        self.utility_commands + self.context_commands)

        # 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-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')
Example #16
0
#*   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                                                                   *
#*                                                                         *
#***************************************************************************

from PyQt4 import QtCore, QtGui
import FreeCAD, FreeCADGui, os

# Load resources
import Plot_rc
FreeCADGui.addLanguagePath(":/Plot/translations")
FreeCADGui.addIconPath(":/Plot/icons")

"""
# Setup tranlations
from plotUtils import Paths
path = Paths.translationsPath()
FreeCADGui.addLanguagePath(path)
import os
import FreeCAD
translator = QtCore.QTranslator()
dirList=os.listdir(path)
for fname in dirList:
	valid = translator.load(os.path.join(path, fname))
	if valid:
		QtGui.QApplication.installTranslator(translator)
#*   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 PySide
from PySide import QtCore, QtGui
import FreeCAD
import FreeCADGui
import os

import Ship_rc


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


class LoadExample:
    def Activated(self):
        import shipLoadExample
        shipLoadExample.load()

    def GetResources(self):
        MenuText = QtCore.QT_TRANSLATE_NOOP(
            'Ship_LoadExample',
            'Load an example ship geometry')
        ToolTip = QtCore.QT_TRANSLATE_NOOP(
            'Ship_LoadExample',
            'Load an example ship hull geometry.')
Example #18
0
def get_freecad_home_path():
    """Returns platform independent freecad install path"""
    return __freecad_home_path__


def get_freecad_resource_path():
    """Returns platform independent freecad resource path"""
    return __freecad_resource_path__


# +---------------------------------------------------------------------------+
# | Translations setup                                                        |
# +---------------------------------------------------------------------------+

try:
    Gui.addLanguagePath(get_resource_path('translations'))
    Gui.updateLocale()
except Exception as ex:
    log('Translation loading error')

try:
    _encoding = QtGui.QApplication.UnicodeUTF8

    @functools.lru_cache()
    def tr(text):
        """Translate text"""
        u = QtGui.QApplication.translate('extman', text, None, _encoding)
        return u.replace(chr(39), "&rsquo;")

except Exception as ex:
Example #19
0
    def Initialize(self):
        "This function is executed when FreeCAD starts"
        import BOPTools  # as bop
        import Design456_Extrude  # import all	 needed files
        import Design456_Extract
        import Design456_ExtrudeFace
        import Design456_SplitObject
        import Design456_loftOnDirection
        import Design456_Part as designPart
        import Design456_Part_Tools as pTools
        import Design456_Part_Utils as pUtils
        import Design456_2Ddrawing as TwoDDraw
        import Design456_SelectionGate as SelGate
        import Design456_Alignment as align
        # from Part import CommandShapes	 #Tube	not working
        Gui.runCommand('Std_PerspectiveCamera', 1)

        self.appendToolbar("Design456_Part", designPart.Design456_Part.list)
        self.appendToolbar("Design456_Tools", pTools.Design456_Part_Tools.list)
        self.appendToolbar("Design456_2DTools",
                           pUtils.Design456_Part_Utils.list)
        self.appendToolbar("Design456_2Ddrawing",
                           TwoDDraw.Design456_2Ddrawing.list)
        self.appendToolbar("Selection Mode",
                           SelGate.Design456_SelectionGate.list)
        self.appendToolbar("Design456_Alignments",
                           align.Design456_Alignment.list)

        self.appendMenu("Design456_Part", designPart.Design456_Part.list)
        self.appendMenu("Design456_Tools", pTools.Design456_Part_Tools.list)
        self.appendMenu("Design456_2Ddrawing",
                        TwoDDraw.Design456_2Ddrawing.list)
        self.appendMenu("Design456_2DTools", pUtils.Design456_Part_Utils.list)
        self.appendMenu("Design456_Alignments", align.Design456_Alignment.list)

        # 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
            if Gui.getSoDBVersion() != coin.SoDB.getVersion():
                raise AssertionError("FreeCAD and Pivy use different versions "
                                     "of Coin. "
                                     "This will lead to unexpected behavior.")
        except AssertionError:
            App.Console.PrintWarning("Error: FreeCAD and Pivy "
                                     "use different versions of Coin. "
                                     "This will lead to unexpected "
                                     "behavior.\n")
        except Exception:
            App.Console.PrintWarning("Error: Pivy not found, "
                                     "Draft Workbench will be disabled.\n")
        except Exception:
            App.Console.PrintWarning("Error: Unknown error "
                                     "while trying to load Pivy.\n")
        else:
            dependencies_OK = True

        if not dependencies_OK:
            return
        # END DRAFT

        # Import Draft tools, icons
        try:
            import Draft_rc
            import DraftTools
            import DraftGui
            import DraftFillet
            Gui.addLanguagePath(":/translations")
            Gui.addIconPath(":/icons")
        except Exception as exc:
            App.Console.PrintError(exc)
            App.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.context_commands = it.get_draft_context_commands()
            self.line_commands = it.get_draft_line_commands()
            self.utility_commands = it.get_draft_utility_commands()
            self.utility_small = it.get_draft_small_commands()

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

            # Set up menus
            self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Drafting"),
                            self.drawing_commands)
            self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Annotation"),
                            self.annotation_commands)
            self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Modification"),
                            self.modification_commands)
            self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Utilities"),
                            self.utility_commands + self.context_commands)

            # Set up preferences pages
            if hasattr(FreeCADGui, "draftToolBar"):
                if not hasattr(Gui.draftToolBar, "loadedPreferences"):
                    Gui.addPreferencePage(":/ui/preferences-draft.ui",
                                          QT_TRANSLATE_NOOP("Draft", "Draft"))
                    Gui.addPreferencePage(":/ui/preferences-draftinterface.ui",
                                          QT_TRANSLATE_NOOP("Draft", "Draft"))
                    Gui.addPreferencePage(":/ui/preferences-draftsnap.ui",
                                          QT_TRANSLATE_NOOP("Draft", "Draft"))
                    Gui.addPreferencePage(":/ui/preferences-draftvisual.ui",
                                          QT_TRANSLATE_NOOP("Draft", "Draft"))
                    Gui.addPreferencePage(":/ui/preferences-drafttexts.ui",
                                          QT_TRANSLATE_NOOP("Draft", "Draft"))
                    Gui.draftToolBar.loadedPreferences = True
                # END DRAFT
        except Exception as exc:
            App.Console.PrintError(exc)
            App.Console.PrintError("Error: Initializing one or more "
                                   "of the Draft modules failed, "
                                   "Draft will not work as expected.\n")
Example #20
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
        from draftguitools import gui_circulararray
        from draftguitools import gui_polararray
        from draftguitools import gui_orthoarray
        from draftguitools import gui_arrays
        import Arch_rc
        import Arch

        # Set up command lists
        self.archtools = ["Arch_Wall", "Arch_StructureTools", "Arch_Rebar",
                          "Arch_CurtainWall","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_Truss",
                          "Arch_Profile","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 Exception:
            pass
        else:
            class RebarGroupCommand:
                def GetCommands(self):
                    return tuple(RebarTools.RebarCommands + ["Arch_Rebar"])

                def GetResources(self):
                    _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"

        # 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_context_commands = it.get_draft_context_commands()
        self.draft_line_commands = it.get_draft_line_commands()
        self.draft_utility_commands = it.get_draft_utility_commands()

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

        # Set up menus
        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"),
                         QT_TRANSLATE_NOOP("arch", "Creation")],
                        self.draft_drawing_commands)
        self.appendMenu([QT_TRANSLATE_NOOP("arch", "&Draft"),
                         QT_TRANSLATE_NOOP("arch", "Annotation")],
                        self.draft_annotation_commands)
        self.appendMenu([QT_TRANSLATE_NOOP("arch", "&Draft"),
                         QT_TRANSLATE_NOOP("arch", "Modification")],
                        self.draft_modification_commands)
        self.appendMenu([QT_TRANSLATE_NOOP("arch", "&Draft"),
                         QT_TRANSLATE_NOOP("arch", "Utilities")],
                        self.draft_utility_commands
                        + self.draft_context_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')
Example #21
0
    def Initialize(self):
        """This function is executed when FreeCAD starts"""
        '''
        disabling numpad shortcuts
        to use for positioning and quick launch
        '''

        preset = [
            ("Std_ViewAxo", "CTRL+0"),
            ("Std_ViewFront", "CTRL+1"),
            ("Std_ViewTop", "CTRL+2"),
            ("Std_ViewRight", "CTRL+3"),
            ("Std_ViewRear", "CTRL+4"),
            ("Std_ViewBottom", "CTRL+5"),
            ("Std_ViewLeft", "CTRL+6"),
            ("Std_BoxSelection", "b"),
        ]

        for (cmd, shortcut) in preset:
            FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Shortcut").SetString(
                    cmd, shortcut)

        def QT_TRANSLATE_NOOP(scope, text):
            return text

        try:
            import os, Draft_rc, DraftTools, DraftGui, Arch, Arch_rc, WFrame
            from DraftTools import translate
            FreeCADGui.addLanguagePath(":/translations")
            FreeCADGui.addIconPath(":/icons")
        except Exception as inst:
            print(inst)
            FreeCAD.Console.PrintError(
                "Error: Initializing one or more of the Draft modules failed, Draft will not work as expected.\n"
            )

        self.wframe = [
            "Draft_Layer", "WF_Beam", "WF_Panel", "Arch_CutPlane",
            "Arch_CutLine", "WF_Copy", "WF_Stretch", "WF_List",
            "WF_EditAttributes", "WF_SelectByAttributes", "WF_AlignViewWPlane"
        ]
        self.wframeExport = ["WF_AddContainer", "WF_AddView", "WF_Export"]

        self.appendToolbar("Wood Frame", self.wframe)
        self.appendToolbar("Wood Frame Export", self.wframeExport)
        self.appendMenu("Wood Frame", self.wframe)  # creates a new menu

        # self.appendMenu(["An existing Menu","My submenu"],self.list) # appends a submenu to an existing menu

        #add draft toolbar
        self.drafttools = [
            "Draft_Line", "Draft_Wire", "Draft_Circle", "Draft_Arc",
            "Draft_Arc_3Points", "Draft_Ellipse", "Draft_Polygon",
            "Draft_Rectangle", "Draft_Text", "Draft_Dimension",
            "Draft_BSpline", "Draft_Point", "Draft_ShapeString",
            "Draft_Facebinder", "Draft_BezierTools", "Draft_Label"
        ]
        self.draftmodtools = [
            "Draft_Move", "Draft_Rotate", "Draft_Offset", "Draft_Trimex",
            "Draft_Join", "Draft_Split", "Draft_Upgrade", "Draft_Downgrade",
            "Draft_Scale", "Draft_Edit", "Draft_WireToBSpline",
            "Draft_AddPoint", "Draft_DelPoint", "Draft_Shape2DView",
            "Draft_Draft2Sketch", "Draft_Array", "Draft_PathArray",
            "Draft_PointArray", "Draft_Clone", "Draft_Drawing", "Draft_Mirror",
            "Draft_Stretch"
        ]
        self.draftextratools = [
            "Draft_WireToBSpline", "Draft_AddPoint", "Draft_DelPoint",
            "Draft_ShapeString", "Draft_PathArray", "Draft_Mirror",
            "Draft_Stretch"
        ]
        self.draftcontexttools = [
            "Draft_ApplyStyle", "Draft_ToggleDisplayMode", "Draft_AddToGroup",
            "Draft_AutoGroup", "Draft_SelectGroup", "Draft_SelectPlane",
            "Draft_ShowSnapBar", "Draft_ToggleGrid", "Draft_UndoLine",
            "Draft_FinishLine", "Draft_CloseLine"
        ]
        self.utils = [
            "Draft_Heal", "Draft_FlipDimension",
            "Draft_ToggleConstructionMode", "Draft_ToggleContinueMode",
            "Draft_Edit", "Draft_Slope", "Draft_SetWorkingPlaneProxy",
            "Draft_AddConstruction"
        ]
        self.snapList = [
            '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.appendToolbar(
            QT_TRANSLATE_NOOP("Workbench", "Draft creation tools"),
            self.drafttools)
        self.appendToolbar(
            QT_TRANSLATE_NOOP("Workbench", "Draft modification tools"),
            self.draftmodtools)
        # self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft mod tools"),self.draftextratools)
        self.appendMenu(QT_TRANSLATE_NOOP("draft", "&Draft"),
                        self.drafttools + self.draftmodtools)
        self.appendMenu([
            QT_TRANSLATE_NOOP("draft", "&Draft"),
            QT_TRANSLATE_NOOP("Workbench", "Utilities")
        ], self.utils + self.draftcontexttools)
        self.appendMenu([
            QT_TRANSLATE_NOOP("draft", "&Draft"),
            QT_TRANSLATE_NOOP("Workbench", "Snapping")
        ], self.snapList)

        if hasattr(FreeCADGui, "draftToolBar"):
            if not hasattr(FreeCADGui.draftToolBar, "loadedArchPreferences"):
                FreeCADGui.addPreferencePage(":/ui/preferences-arch.ui",
                                             "Arch")
                FreeCADGui.addPreferencePage(
                    ":/ui/preferences-archdefaults.ui", "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")
                FreeCADGui.draftToolBar.loadedPreferences = True
        Log('Loading Draft module...done\n')
Example #22
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")
Example #23
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')
Example #24
0
#!/usr/bin/env python3
# coding: utf-8
#
# LGPL
#
# Asm4_Translate.py

import os
import FreeCADGui as Gui
import FreeCAD as App

Gui.addLanguagePath(
    os.path.join(os.path.dirname(__file__), "Resources/translations"))


def _atr(context: str, text: str) -> str:
    """Wrap strings which should be translated in in this function."""
    return App.Qt.translate(context, text)


def QT_TRANSLATE_NOOP(context: str, text: str) -> str:
    """NOP Marker Macro Alias for strings for which FreeCAD/Qt handles translations."""
    return text