def __init__(self):

        self.node = coin.SoSeparator()
        self.coordinate = coin.SoCoordinate3()
        self.crosshair_coord = coin.SoCoordinate3()
        self.transform = coin.SoTransform()

        _selection_node = \
            coin.SoType.fromName("SoFCSelection").createInstance()

        _selection_node.documentName.setValue('Document')
        _selection_node.objectName.setValue('Test Tracker')
        _selection_node.subElementName.setValue('NODE-0')

        self.node.addChild(_selection_node)
        self.node.addChild(self.transform)
        self.node.addChild(self.coordinate)
        self.node.addChild(coin.SoMarkerSet())

        self.coordinate.point.setValue((0.0, 0.0, 0.0))

        self.view = Gui.ActiveDocument.ActiveView
        self.view.addEventCallback('SoLocation2Event', self.mouse_event)

        _fn = lambda _x: self.view.getSceneGraph().insertChild(_x, 0)

        self.crosshair = self.create_crosshair()

        todo.delay(_fn, self.node)
        todo.delay(_fn, self.crosshair)
Beispiel #2
0
 def __init__(self,
              dotted=False,
              scolor=None,
              swidth=None,
              children=[],
              ontop=False,
              name=None):
     global Part, DraftGeomUtils
     import Part, DraftGeomUtils
     self.ontop = ontop
     color = coin.SoBaseColor()
     color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("ui")
     drawstyle = coin.SoDrawStyle()
     if swidth:
         drawstyle.lineWidth = swidth
     if dotted:
         drawstyle.style = coin.SoDrawStyle.LINES
         drawstyle.lineWeight = 3
         drawstyle.linePattern = 0x0f0f  #0xaa
     node = coin.SoSeparator()
     for c in [drawstyle, color] + children:
         node.addChild(c)
     self.switch = coin.SoSwitch()  # this is the on/off switch
     if name:
         self.switch.setName(name)
     self.switch.addChild(node)
     self.switch.whichChild = -1
     self.Visible = False
     from DraftGui import todo
     todo.delay(self._insertSwitch, self.switch)
Beispiel #3
0
def convertFloors(floor=None):
    """convert the given Floor (or all Arch Floors from the active document if none is given) into BuildingParts"""

    todel = []
    if floor:
        objset = [floor]
    else:
        objset = FreeCAD.ActiveDocument.Objects
    for obj in objset:
        if Draft.getType(obj) == "Floor":
            nobj = makeBuildingPart(obj.Group)
            nobj.Role = "Storey"
            label = obj.Label
            for parent in obj.InList:
                if hasattr(parent, "Group"):
                    if obj in parent.Group:
                        parent.addObject(nobj)
                        #g = parent.Group
                        #g.append(nobj)
                        #parent.Group = g
                else:
                    print("Warning: couldn't add new object '" + label +
                          "' to parent object '" + parent.Label + "'")
            todel.append(obj.Name)
            if obj.ViewObject:
                obj.ViewObject.Proxy.Object = None  # some bug makes this trigger even efter the object has been deleted...
            obj.Label = obj.Label + " to delete"  # in case FreeCAD doesn't allow 2 objs with same label
            nobj.Label = label
    for n in todel:
        from DraftGui import todo
        todo.delay(FreeCAD.ActiveDocument.removeObject, n)
Beispiel #4
0
def remove_child(node, parent):
    """
    Convenience wrapper for _remove_node
    """

    if parent.findChild(node) >= 0:
        todo.delay(parent.removeChild, node)
Beispiel #5
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")
Beispiel #6
0
    def Activated(self):

        # find existing tutorial
        m = FreeCADGui.getMainWindow()
        self.dock = m.findChild(QtGui.QDockWidget,"BIMTutorial")

        if not self.dock:

            # set the tutorial dialog up
            self.form = FreeCADGui.PySideUic.loadUi(os.path.join(os.path.dirname(__file__),"dialogTutorial.ui"))
            self.form.setObjectName("BIMTutorial")
            self.form.progressBar.setValue(0)
            self.form.labelGoal1.setText("")
            self.form.labelGoal2.setText("")
            self.form.labelIcon1.setText("")
            self.form.labelIcon2.setText("")
            self.form.buttonPrevious.setEnabled(False)
            self.form.buttonNext.setEnabled(False)
            self.form.buttonPrevious.clicked.connect(self.previous)
            self.form.buttonNext.clicked.connect(self.next)
            self.form.labelTasks.hide()
            self.form.textEdit.setOpenExternalLinks(True)

            self.dock = QtGui.QDockWidget()
            self.dock.setWidget(self.form)

            m.addDockWidget(QtCore.Qt.RightDockWidgetArea,self.dock)

            # fire the loading after displaying the widget
            from DraftGui import todo
            #self.load()
            todo.delay(self.load,None)
Beispiel #7
0
    def Activated(self):
        # if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OSAFE").GetBool("FirstTime", True):
        #     from DraftGui import todo
        #     todo.delay(Gui.runCommand, "Civil_welcome")

        from DraftGui import todo
        import osafe_statusbar
        todo.delay(osafe_statusbar.setStatusIcons, True)
Beispiel #8
0
    def action(self, arg):

        if arg["Type"] == "SoKeyboardEvent" and arg["Key"] == "ESCAPE":
            self.finish()
        if arg["Type"] == "SoMouseButtonEvent":
            if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
                # coin detection happens before the selection got a chance of being updated, so we must delay
                todo.delay(self.checkSelection, None)
Beispiel #9
0
	def cleanUp(self):
		self.view.removeEventCallbackPivy(SoEvent.getClassTypeId(),self.call) #remove event callback
		#remove the temporary geormety by sending the removal function throught to a delay function (of the Draft Module)
		#This must be done as the callback traversal is still occuring and will crash if the scene grapth objects are removed underneith it
		nodeRef = self.sceneGraph.findChild(self.tempNode) #First we get the index ofour temp geometry node under the scene graph node
		#(I don't like this, can we use a use a name instead that can't be confused with another node?)
		f = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().removeChild #this is the function that removes a node node from the scene grapth
		todo.delay(f, nodeRef) #pass the index and the function onto the delay method
		functions.edgeSelection(True) #turn back on selection of existing edge objects
Beispiel #10
0
 def updateData(self,obj,prop):
     
     if (prop == "Shape") and hasattr(obj.ViewObject,"UpdateColors") and obj.ViewObject.UpdateColors:
         if obj.Shape and not obj.Shape.isNull():
             colors = obj.Proxy.getColors(obj)
             if colors:
                 obj.ViewObject.DiffuseColor = colors
             from DraftGui import todo
             todo.delay(self.recolorize,obj.ViewObject)
Beispiel #11
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")
Beispiel #12
0
 def insert(self, index=None):
     import FreeCADGui
     if not index:
         index = self.form.tree.selectedIndexes()
         if not index:
             return
         index = index[0]
     if self.modelmode == 1:
         path = self.dirmodel.filePath(index)
     else:
         path = self.filemodel.itemFromIndex(index).toolTip()
     if path.startswith(":github"):
         path = self.download(
             LIBRARYURL.replace("/tree", "/raw") + "/" + path[7:])
     before = FreeCAD.ActiveDocument.Objects
     self.name = os.path.splitext(os.path.basename(path))[0]
     if path.lower().endswith(".stp") or path.lower().endswith(
             ".step") or path.lower().endswith(
                 ".brp") or path.lower().endswith(".brep"):
         self.place(path)
     elif path.lower().endswith(".fcstd"):
         FreeCADGui.ActiveDocument.mergeProject(path)
         from DraftGui import todo
         todo.delay(self.reject, None)
     elif path.lower().endswith(".ifc"):
         import importIFC
         importIFC.ZOOMOUT = False
         importIFC.insert(path, FreeCAD.ActiveDocument.Name)
         from DraftGui import todo
         todo.delay(self.reject, None)
     elif path.lower().endswith(".sat") or path.lower().endswith(".sab"):
         try:
             # InventorLoader addon
             import importerIL
         except ImportError:
             try:
                 # CADExchanger addon
                 import CadExchangerIO
             except ImportError:
                 FreeCAD.Console.PrintError(
                     translate(
                         "BIM",
                         "Error: Unable to import SAT files - CadExchanger addon must be installed"
                     ))
             else:
                 path = CadExchangerIO.insert(path,
                                              FreeCAD.ActiveDocument.Name,
                                              returnpath=True)
                 self.place(path)
         else:
             path = importerIL.insert(path, FreeCAD.ActiveDocument.Name)
     FreeCADGui.Selection.clearSelection()
     for o in FreeCAD.ActiveDocument.Objects:
         if not o in before:
             FreeCADGui.Selection.addSelection(o)
     FreeCADGui.SendMsgToActiveView("ViewSelection")
Beispiel #13
0
    def remove_node(self, node, parent=None):
        """
        Convenience wrapper for _remove_node
        """

        if not parent:
            parent = ViewState().sg_root

        if parent.findChild(node) >= 0:
            todo.delay(parent.removeChild, node)
Beispiel #14
0
    def convertToBuildingPart(self):
        """Converts the floor into an Arch Building Part.

        TODO: May be depreciated?
        """

        if hasattr(self, "Object"):
            import ArchBuildingPart
            from DraftGui import todo
            todo.delay(ArchBuildingPart.convertFloors, self.Object)
Beispiel #15
0
    def remove_node(self, node, parent=None):
        """
        Convenience wrapper for _remove_node
        """

        if not parent:
            parent = Draft.get3DView().getSceneGraph()

        if parent.findChild(node) >= 0:
            todo.delay(parent.removeChild, node)
Beispiel #16
0
    def insert(self):
        """
        Custom function to manage drag state insertion and provide
        flag when scenegraph has been updated
        """

        self.sg_ok = False

        self._sg_root = ViewState().sg_root
        todo.delay(DragState()._insert, DragState())
Beispiel #17
0
    def insert_into_scenegraph(self, verbose=False):
        """
        Insert the base node into the scene graph and trigger notifications
        """

        _fn = lambda _x: Base.view_state.sg_root.insertChild(_x, 0)

        if verbose:
            self.base.dump()

        todo.delay(self._do_insert, None)
    def testAll(self):

        "runs all tests"

        from DraftGui import todo
        for test in tests:
            if test != "testAll":
                QtGui.QApplication.processEvents()
                self.reset(test)
                if hasattr(self, test):
                    todo.delay(getattr(self, test), None)
Beispiel #19
0
    def updateData(self, obj, prop):

        if (prop == "Shape") and hasattr(
                obj.ViewObject,
                "UpdateColors") and obj.ViewObject.UpdateColors:
            if obj.Shape and not obj.Shape.isNull():
                colors = obj.Proxy.getColors(obj)
                if colors:
                    obj.ViewObject.DiffuseColor = colors
                from DraftGui import todo
                todo.delay(self.recolorize, obj.ViewObject)
Beispiel #20
0
def insert_child(node, parent, index=-1):
    """
    Insert a node as a child of the passed node
    """

    _fn = parent.addChild

    if index >= 0:
        _fn = lambda _x: parent.insertChild(_x, index)

    todo.delay(_fn, node)
Beispiel #21
0
    def finish(self):
        """
        Return the transformation matrix for the provided node
        """

        #node was never added, but drag state members may have changed
        if not self._sg_root:
            self.reset()
            return

        self.sg_ok = False

        todo.delay(DragState()._remove, DragState())
Beispiel #22
0
    def insert_node(self, node, parent=None, on_top=False):
        """
        Insert a node as a child of the passed node
        """

        if not parent:
            parent = Draft.get3DView().getSceneGraph()

        _fn = parent.addChild

        if on_top:
            _fn = parent.insertChild

        todo.delay(_fn, node)
Beispiel #23
0
    def onAccept(self, item=None):

        if self.dlg:
            item = self.dlg.matList.currentItem()
            if item:
                mat = FreeCAD.ActiveDocument.getObject(item.toolTip())
                if mat:
                    for obj in self.dlg.objects:
                        obj.Material = mat
            p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM")
            p.SetInt("BimMaterialDialogWidth", self.dlg.width())
            p.SetInt("BimMaterialDialogHeight", self.dlg.height())
            from DraftGui import todo
            todo.delay(self.dlg.hide, None)
Beispiel #24
0
    def accept(self, idx=None):

        i = self.form.currentItem()
        if i:
            import Arch
            FreeCAD.ActiveDocument.openTransaction("Convert to BIM")
            for o in self.objs:
                getattr(Arch, "make" + i.toolTip())(o)
            FreeCAD.ActiveDocument.commitTransaction()
            FreeCAD.ActiveDocument.recompute()
        if idx:
            from DraftGui import todo
            todo.delay(FreeCADGui.Control.closeDialog, None)
        return True
Beispiel #25
0
    def testAll(self):

        "runs all tests"

        from DraftGui import todo
        for test in tests:
            if test != "testAll":
                QtGui.QApplication.processEvents()
                self.reset(test)
                if hasattr(self, test):
                    todo.delay(getattr(self, test), None)
        for customTest in self.customTests.keys():
            todo.delay(self.testCustom, customTest)

        FreeCADGui.BIMPreflightDone = True
Beispiel #26
0
    def Deactivated(self):

        if hasattr(FreeCADGui, "draftToolBar"):
            FreeCADGui.draftToolBar.Deactivated()
        if hasattr(FreeCADGui, "Snapper"):
            FreeCADGui.Snapper.hide()
        from DraftGui import todo
        import BimCommands
        #print("Deactivating status icon")
        todo.delay(BimCommands.setStatusIcons, False)
        if hasattr(FreeCAD, "BimDocumentObserver"):
            FreeCAD.removeDocumentObserver(FreeCAD.BimDocumentObserver)
            del FreeCAD.BimDocumentObserver
            Log("Removing FreeCAD.BimDocumentObserver\n")

        Log("BIM workbench deactivated\n")
Beispiel #27
0
    def Deactivated(self):

        from DraftGui import todo
        import CivilToolsStatusBar
        from freecad_py import civiltools_views

        todo.delay(CivilToolsStatusBar.setStatusIcons, False)

        # store views widget state and vertical size

        w = civiltools_views.findWidget()
        FreeCAD.ParamGet(
            "User parameter:BaseApp/Preferences/Mod/civilTools").SetBool(
                "RestoreCivilToolsViews", bool(w))
        if w:
            FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/civilTools").SetInt(
                    "civilToolsViewsSize", w.height())
            w.hide()
Beispiel #28
0
    def Activated(self):

        if hasattr(FreeCADGui, "draftToolBar"):
            FreeCADGui.draftToolBar.Activated()
        if hasattr(FreeCADGui, "Snapper"):
            FreeCADGui.Snapper.show()
        from DraftGui import todo
        import BimCommands
        if FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/BIM").GetBool(
                    "FirstTime", True):
            todo.delay(FreeCADGui.runCommand, "BIM_Welcome")
        todo.delay(BimCommands.setStatusIcons, True)
        if not hasattr(FreeCAD, "BimDocumentObserver"):
            FreeCAD.BimDocumentObserver = BimCommands.BimDocumentObserver()
            FreeCAD.addDocumentObserver(FreeCAD.BimDocumentObserver)
            Log("Adding FreeCAD.BimDocumentObserver\n")

        Log("BIM workbench activated\n")
Beispiel #29
0
 def __init__(self,dotted=False,scolor=None,swidth=None,children=[],ontop=False):
     global Part, DraftGeomUtils
     import Part, DraftGeomUtils
     self.ontop = ontop
     color = coin.SoBaseColor()
     color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("ui")
     drawstyle = coin.SoDrawStyle()
     if swidth:
         drawstyle.lineWidth = swidth
     if dotted:
         drawstyle.style = coin.SoDrawStyle.LINES
         drawstyle.lineWeight = 3
         drawstyle.linePattern = 0x0f0f #0xaa
     node = coin.SoSeparator()
     for c in [drawstyle, color] + children:
         node.addChild(c)
     self.switch = coin.SoSwitch() # this is the on/off switch
     self.switch.addChild(node)
     self.switch.whichChild = -1
     self.Visible = False
     todo.delay(self._insertSwitch, self.switch)
Beispiel #30
0
    def insert_node(self, node, parent=None, index=None):
        """
        Insert a node as a child of the passed node
        """

        _idx = index
        _fn = None

        if not parent:
            if _idx is None:
                _idx = 0

            _fn = lambda _x: ViewState().sg_root.insertChild(_x, _idx)

        elif _idx is not None:
            _fn = lambda _x: parent.insertChild(_x, _idx)

        else:
            _fn = parent.addChild

        todo.delay(_fn, node)
Beispiel #31
0
    def Activated(self):

        from DraftGui import todo
        import CivilToolsStatusBar

        todo.delay(CivilToolsStatusBar.setStatusIcons, True)
        if FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/civilTools").GetBool(
                    "FirstTime", True):
            from DraftGui import todo
            todo.delay(Gui.runCommand, "civiltools_settings")

        # restore views widget if needed

        if FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/civilTools").GetBool(
                    "RestoreCivilToolsViews", True):
            from freecad_py import civiltools_views
            w = civiltools_views.findWidget()
            if not w:
                FreeCADGui.runCommand("civiltools_views")
            else:
                w.show()
def convertFloors(floor=None):

    """convert the given Floor or Building (or all Arch Floors from the active document if none is given) into BuildingParts"""

    todel = []
    if floor:
        objset = [floor]
    else:
        objset = FreeCAD.ActiveDocument.Objects
    for obj in objset:
        if Draft.getType(obj) in ["Floor","Building"]:
            nobj = makeBuildingPart(obj.Group)
            if Draft.getType(obj) == "Floor":
                nobj.IfcRole = "Building Storey"
            else:
                nobj.IfcRole = "Building"
                nobj.addProperty("App::PropertyEnumeration","BuildingType","Building",QT_TRANSLATE_NOOP("App::Property","The type of this building"))
                nobj.BuildingType = BuildingTypes
            label = obj.Label
            for parent in obj.InList:
                if hasattr(parent,"Group"):
                    if obj in parent.Group:
                        parent.addObject(nobj)
                        #g = parent.Group
                        #g.append(nobj)
                        #parent.Group = g
                else:
                    print("Warning: couldn't add new object '"+label+"' to parent object '"+parent.Label+"'")
            todel.append(obj.Name)
            if obj.ViewObject:
                obj.ViewObject.Proxy.Object = None # some bug makes this trigger even efter the object has been deleted...
            obj.Label = obj.Label+" to delete" # in case FreeCAD doesn't allow 2 objs with same label
            nobj.Label = label
    for n in todel:
        from DraftGui import todo
        todo.delay(FreeCAD.ActiveDocument.removeObject,n)
Beispiel #33
0
 def addNewTagAt(self, point, what):
     if what == self.obj:
         print("%s '%s'" %( point, what.Name))
         tags = self.tags
         tags.append((point.x, point.y, True))
         self.obj.Proxy.setXyEnabled(tags)
     panel = TaskPanel(self.obj, self.jvoVisible)
     todo.delay(FreeCADGui.Control.closeDialog, None)
     todo.delay(FreeCADGui.Control.showDialog, panel)
     todo.delay(panel.setupUi, None)
Beispiel #34
0
    def __init__(self):

        #generate coordinates
        _coords = self.generate_coordinates()

        #build node structure
        self.node = coin.SoSeparator()
        self.trackers = []

        self.active_node = -1
        self.size = 1.0

        self.tracker_node = coin.SoSeparator()
        self.crosshair_transform = coin.SoTransform()

        for _i, _v in enumerate(_coords):

            _t = NodeTracker(_i, _v)
            self.trackers.append(_t)
            self.tracker_node.addChild(_t.node)

        #build wire node structure
        _wire_coord = coin.SoCoordinate3()
        _wire_coord.point.setValues(_coords)

        _wire_node = coin.SoSeparator()
        _wire_node.addChild(_wire_coord)
        _wire_node.addChild(coin.SoLineSet())

        #add wire and node trackers to main node
        self.node.addChild(self.tracker_node)
        self.node.addChild(_wire_node)

        #set up event callbacks
        self.view = Gui.ActiveDocument.ActiveView
        self.view.addEventCallback(
            'SoLocation2Event', self.mouse_event)

        #add nodes and crosshair
        _fn = lambda _x: self.view.getSceneGraph().insertChild(_x, 0)

        self.crosshair = self.create_crosshair()

        todo.delay(_fn, self.node)
        todo.delay(_fn, self.crosshair)

        todo.delay(Gui.SendMsgToActiveView, "ViewFit")
 def finalize(self):
     from DraftGui import todo
     todo.delay(self._removeSwitch, self.switch)
     self.switch = None
Beispiel #36
0
 def finalize(self):
     todo.delay(self._removeSwitch, self.switch)
     self.switch = None
Beispiel #37
0
 def convertToBuildingPart(self):
     if hasattr(self,"Object"):
         import ArchBuildingPart
         from DraftGui import todo
         todo.delay(ArchBuildingPart.convertFloors,self.Object)
Beispiel #38
0
    def unsetEdit(self,vobj,mode):

        FreeCADGui.Control.closeDialog()
        from DraftGui import todo
        todo.delay(vobj.Proxy.recolorize,vobj)
        return