Exemplo n.º 1
0
    def getPort(self, sel):
        obj = sel.Object
        sub = sel.SubObjects[-1]
        ports = Port.extractAdvancedPorts(obj)

        closest_port = Port.getNearestPort(obj.Placement, ports,
                                           sub.CenterOfMass)
        return closest_port
Exemplo n.º 2
0
    def moveTo(part, porti: int, to_part, to_porti: int):
        """Move a part to another part, such that their ports coinside.

        Move a part to antother part. Both parts must be Dodo parts with
        advancedPorts.

        :param part: Part to be moved.
        :param porti: Port index of the moved part, which will connect to another part.
        :param to_part: Part to which another part will be moved.
          This part does not channge its position.
        :param to_porti: Port index where another part will be moved to.
        """
        # Now adjust part to
        # print(obj_of_part.Placement)
        ports = Port.extractAdvancedPorts(part)
        to_ports = Port.extractAdvancedPorts(to_part)
        if (0 <= porti < len(ports)) and (0 <= to_porti < len(to_ports)):
            # FreeCAD.Console.PrintMessage("Move port {} to port {}.\n".format(porti + 1, to_porti + 1))
            port = ports[porti]
            to_port = to_ports[to_porti]
            part.Placement = port.getPartPlacement(to_part.Placement, to_port)
Exemplo n.º 3
0
    def showDestinationPorts(self, part, port_i):
        if part is not None and Port.supportsAdvancedPort(part):
            nports = len(part.Ports)
        else:
            nports = 0

        for i in range(0, nports):
            self.radioDestinationPorts[i].setEnabled(True)
        for i in range(nports, len(self.radioPorts)):
            self.radioDestinationPorts[i].setEnabled(False)

        if port_i >= 0:
            self.radioDestinationPorts[port_i].setChecked(True)
Exemplo n.º 4
0
    def isSelectedPartSupported(part):
        """Check if the selected part is supported for movment.

        If the part is not supported print a warning.
        """
        if part is None:
            FreeCAD.Console.PrintWarning("No part selected. Do nothing.\n")
            return False

        if not Port.supportsAdvancedPort(part):
            FreeCAD.Console.PrintWarning("This part is not supported.\n")
            return False

        return True
Exemplo n.º 5
0
    def getPortIndexOfSelection(selection):
        """Estimate port index of a selected part."""

        if (len(selection.SubObjects) > 0):
            # Only a pipe has ports on creation. The other fitting can be accessed only through their objects.
            part = selection.Object
            sub = selection.SubObjects[-1]
            ports = MoveAroundPanel.getPorts(part)
            if len(ports) > 0:
                i = Port.getNearestPortIndex(part.Placement, ports,
                                             sub.CenterOfMass)
                FreeCAD.Console.PrintMessage("Select Port {}\n".format(i + 1))
                return i
        return -1
def all_selected_parts_have_ports():
    for sel in FreeCADGui.Selection.getSelectionEx():
        if not Port.supportsAdvancedPort(sel.Object):
            return False
    return True
Exemplo n.º 7
0
    def moveFlamingoPartToSelection(document, part):
        # Place the part with Dodo. If Dodo not found, use Flamingo instead.
        try:
            import pCmd as dfCmd
        except ModuleNotFoundError:
            import pipeCmd as dfCmd

        # Check if something is selected:
        if (len(FreeCADGui.Selection.getSelectionEx()) > 0
                and len(FreeCADGui.Selection.getSelectionEx()[-1].SubObjects) > 0):
            # Only a pipe has ports on creation. The other fitting can be accessed only through their objects.
            obj_of_part = document.getObject(part.Name)
            # Get last selection
            target = FreeCADGui.Selection.getSelectionEx()[-1].Object
            sub = FreeCADGui.Selection.getSelectionEx()[-1].SubObjects[-1]
            # Check if the part has ports.
            if obj_of_part.Ports == []:
                FreeCAD.Console.PrintMessage(
                    "The new part has an empty port list. Cannot move the part.\n")
                return
            try:
                # Check if the new part support advancedPorts
                # sel = FreeCADGui.Selection.getSelectionEx()
                # rpdb2.start_embedded_debugger("test")

                if Port.supportsAdvancedPort(obj_of_part) and Port.supportsAdvancedPort(target):
                    # Use new placement methos.
                    # Ports of the moved objects.

                    moved_ports = Port.extractAdvancedPorts(obj_of_part)
                    # Ports of the object to whom the object will be moved.
                    fix_ports = Port.extractAdvancedPorts(target)

                    # Find the closest port to a selected surface or edge.
                    closest_port = Port.getNearestPort(
                        target.Placement, fix_ports, sub.CenterOfMass)

                    # Now adjust new part to closet port
                    # print(obj_of_part.Placement)
                    obj_of_part.Placement = moved_ports[0].getPartPlacement(
                        target.Placement, closest_port)
                    # print(obj_of_part.Placement)
                else:
                    FreeCAD.Console.PrintWarning(
                        "Not all parts are OSE Fittings. I will try to use Dodo/Flamingo for positioning.\n")
                    nearest_ports = dfCmd.nearestPort(
                        target, sub.CenterOfMass)
                    if nearest_ports != []:
                        FreeCAD.Console.PrintMessage("Move new part to port {0}.\n".format(
                            nearest_ports[0]))
                        dfCmd.placeThePype(
                            obj_of_part, 0, target, nearest_ports[0])
                    else:
                        FreeCAD.Console.PrintMessage(
                            "No nearest ports found.\n")
            except Exception as e:
                FreeCAD.Console.PrintMessage(
                    "Positioning of Flamingo parts failed: {}\n".format(e))
        else:
            FreeCAD.Console.PrintMessage(
                "No flamngo parts selected. Insert to the standard position,\n")
Exemplo n.º 8
0
 def getPorts(part):
     if Port.supportsAdvancedPort(part):
         return Port.extractAdvancedPorts(part)
     else:
         return []