예제 #1
0
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        if m_debug:
            print("running LinePointPlane.execute !")

        # To be compatible with previous version > 2019
        if 'Parametric' in selfobj.PropertiesList:
            # Create the object the first time regardless
            # the parametric behavior
            if selfobj.Parametric == 'Not' and self.created:
                return
            if selfobj.Parametric == 'Interactive' and self.created:
                return

        if WF.verbose():
            m_msg = "Recompute Python LinePointPlane feature\n"
            App.Console.PrintMessage(m_msg)

        m_PropertiesList = ['Edge',
                            'Point',
                            'Extension'
                            ]
        for m_Property in m_PropertiesList:
            if m_Property not in selfobj.PropertiesList:
                return

        try:
            Plane = None
            if selfobj.Edge is not None and selfobj.Point is not None:
                n1 = eval(selfobj.Point[1][0].lstrip('Vertex'))
                n2 = eval(selfobj.Edge[1][0].lstrip('Edge'))
                if m_debug:
                    print_msg(str(selfobj.Point))
                    print_msg(str(selfobj.Edge))
                    print_msg("n1 = " + str(n1))
                    print_msg("n2 = " + str(n2))

                points = []
                point_A = selfobj.Edge[0].Shape.Edges[n2 - 1].Vertexes[0].Point
                point_B = selfobj.Edge[0].Shape.Edges[n2 - 1].Vertexes[-1].Point
                point_C = selfobj.Point[0].Shape.Vertexes[n1 - 1].Point

                if isEqualVectors(point_A, point_B):
                    m_msg = """Unable to create Plane from 2 equals Points :
                    Points 1 and 2 are equals !
                    """
                    printError_msg(m_msg, title=m_macro)
                    return

                if isEqualVectors(point_A, point_C):
                    m_msg = """Unable to create Plane from 2 equals Points :
                    Points 1 an 3 are equals !
                    """
                    printError_msg(m_msg, title=m_macro)
                    return

                if isEqualVectors(point_B, point_C):
                    m_msg = """Unable to create Plane from 2 equals Points :
                    Points 2 an 3 are equals !
                    """
                    printError_msg(m_msg, title=m_macro)
                    return

                if isColinearVectors(point_A, point_B, point_C, tolerance=1e-12):
                    printError_msg(m_exception_msg, title=m_macro)
                    return
                points.append(point_A)
                points.append(point_B)
                points.append(point_C)

                Vector_Center = meanVectorsPoint(points)
                xmax, xmin, ymax, ymin, zmax, zmin = minMaxVectorsLimits(points)

                Vector21 = point_B - point_A
                Vector31 = point_C - point_A
                Plane_Point = Vector_Center
                Plane_Normal = Vector21.cross(Vector31)

                Edge_Length = selfobj.Extension
                Plane = Part.makePlane(Edge_Length,
                                       Edge_Length,
                                       Plane_Point,
                                       Plane_Normal)
                Plane_Center = Plane.CenterOfMass
                Plane_Translate = Plane_Point - Plane_Center
                Plane.translate(Plane_Translate)

            if Plane is not None:
                selfobj.Shape = Plane
                propertiesPlane(selfobj.Label, self.color)
                selfobj.Point1_X = float(point_A.x)
                selfobj.Point1_Y = float(point_A.y)
                selfobj.Point1_Z = float(point_A.z)
                selfobj.Point2_X = float(point_B.x)
                selfobj.Point2_Y = float(point_B.y)
                selfobj.Point2_Z = float(point_B.z)
                selfobj.Point3_X = float(point_C.x)
                selfobj.Point3_Y = float(point_C.y)
                selfobj.Point3_Z = float(point_C.z)
                # To be compatible with previous version 2018
                if 'Parametric' in selfobj.PropertiesList:
                    self.created = True
        except Exception as err:
            printError_msg(err.args[0], title=m_macro)
예제 #2
0
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        if m_debug:
            print("running AlongLinePoint.execute !")

        # To be compatible with previous version > 2019
        if 'Parametric' in selfobj.PropertiesList:
            # Create the object the first time regardless
            # the parametric behavior
            if selfobj.Parametric == 'Not' and self.created:
                return
            if selfobj.Parametric == 'Interactive' and self.created:
                return

        if WF.verbose():
            m_msg = "Recompute Python AlongLinePoint feature\n"
            App.Console.PrintMessage(m_msg)

        m_PropertiesList = ["Distance",
                            'AlongEdge',
                            'Edge',
                            'Point'
                            ]
        for m_Property in m_PropertiesList:
            if m_Property not in selfobj.PropertiesList:
                return

        if selfobj.AlongEdge is None:
            return

        if selfobj.Edge is None and selfobj.Point is None:
            return

        if m_debug:
            print("selfobj.AlongEdge = " + str(selfobj.AlongEdge))
            print("selfobj.Edge = " + str(selfobj.Edge))
            print("selfobj.Point = " + str(selfobj.Point))

        try:
            Vector_point = None

            n1 = eval(selfobj.AlongEdge[1][0].lstrip('Edge'))

            if selfobj.Edge is not None:
                n2 = eval(selfobj.Edge[1][0].lstrip('Edge'))
            else:
                if selfobj.Point != selfobj.AlongEdge:
                    n3 = eval(selfobj.Point[1][0].lstrip('Vertex'))
                else:
                    print(selfobj.Point[1][0].name())
                    n3 = eval(selfobj.Point[1][0].lstrip('Edge'))

            m_distanceLinePoint = selfobj.Distance

            if m_debug:
                print_msg("n1 = " + str(n1))
                if selfobj.Edge is not None:
                    print_msg("n2 = " + str(n2))
                else:
                    print_msg("n3 = " + str(n3))
                print_msg("m_distanceLinePoint = " + str(m_distanceLinePoint))

            m_alongedge = selfobj.AlongEdge[0].Shape.Edges[n1 - 1]
            if selfobj.Edge is not None:
                m_edge = selfobj.Edge[0].Shape.Edges[n2 - 1]
            else:
                m_point = selfobj.Point[0].Shape.Vertexes[n3 - 1].Point

            if m_debug:
                print_msg("m_alongedge = " + str(m_alongedge))
                if selfobj.Edge is not None:
                    print_msg("m_edge = " + str(m_edge))
                else:
                    print_msg("m_point = " + str(m_point))

            Vector_A = m_alongedge.valueAt(0.0)
            Vector_B = m_alongedge.valueAt(m_alongedge.Length)
            if m_debug:
                print_msg("Vector_A = " + str(Vector_A))
                print_msg("Vector_B = " + str(Vector_B))

            if isEqualVectors(Vector_A, Vector_B):
                return

            if selfobj.Edge is not None:
                m_dist = m_alongedge.distToShape(m_edge)
                Vector_C = m_dist[1][0][0]
            else:
                Vector_C = m_point

            if m_debug:
                print_msg("Vector_C = " + str(Vector_C))

            # Calculate intersection Point
            Vector_T, _, _ = intersectPerpendicularLine(Vector_A,
                                                        Vector_B,
                                                        Vector_C,)
            if m_debug:
                print_msg("Vector_T = " + str(Vector_T))

            Vector_Translate = (Vector_B - Vector_A)
            if m_distanceLinePoint != 0.0:
                Vector_Translate = Vector_Translate.normalize() * m_distanceLinePoint
                Vector_point = Vector_T + Vector_Translate
            else:
                Vector_point = Vector_T

            if Vector_point is not None:
                point = Part.Point(Vector_point)
                selfobj.Shape = point.toShape()
                propertiesPoint(selfobj.Label, self.color)
                selfobj.X = float(Vector_point.x)
                selfobj.Y = float(Vector_point.y)
                selfobj.Z = float(Vector_point.z)
                # To be compatible with previous version 2018
                if 'Parametric' in selfobj.PropertiesList:
                    self.created = True

        except Exception as err:
            printError_msg(err.message, title=m_macro)
예제 #3
0
def run():
    m_sel, m_actDoc = getSel(WF.verbose())

    if WF.verbose():
        print_msg("m_sel = " + str(m_sel))

    def createSubGroup(main_dir,
                       sub_dir,
                       error_msg):
        try:
            m_ob_dir = App.ActiveDocument.getObject(main_dir)
            m_ob = m_ob_dir.newObject("App::DocumentObjectGroup",
                                      str(sub_dir))
            m_group = m_actDoc.getObject(str(m_ob.Label))
        except Exception as err:
            printError_msg(err.message, title=m_macro)
            printError_msg(error_msg)
        return m_group

    try:
        Number_of_Edges, Edge_List = m_sel.get_segmentsNames(
            getfrom=["Segments", "Curves"])
        if WF.verbose():
            print_msg("Number_of_Edges = " + str(Number_of_Edges))
            print_msg("Edge_List = " + str(Edge_List))

        Number_of_Vertexes, Vertex_List = m_sel.get_pointsNames(
            getfrom=["Points", "Segments", "Curves", "Objects"])
        if WF.verbose():
            print_msg("Number_of_Vertexes = " + str(Number_of_Vertexes))
            print_msg("Vertex_List = " + str(Vertex_List))

        if Number_of_Edges == 0:
            raise Exception(m_exception_msg)
        else:
            if Number_of_Edges == 1 and Number_of_Vertexes == 0:
                raise Exception(m_exception_msg)

        m_main_dir = "WorkPoints_P"
        m_sub_dir = "Set"
        m_group = createFolders(str(m_main_dir))
        m_error_msg = "Could not Create '"
        m_error_msg += str(m_sub_dir) + "' Objects Group!"

        # Selection of : One Edge and One or several Point(s)
        if Number_of_Edges == 1 and Number_of_Vertexes > 0:
            try:
                # Create a sub group if needed
                if Number_of_Vertexes > 1:
                    m_group = createSubGroup(m_main_dir,
                                             m_sub_dir,
                                             m_error_msg)

                if WF.verbose():
                    print_msg("Group = " + str(m_group.Label))

                edge = Edge_List[0]
                if WF.verbose():
                    print_msg("edge = " + str(edge))

                for j in range(Number_of_Vertexes):
                    point = Vertex_List[j]
                    if WF.verbose():
                        print_msg("point = " + str(point))

                    App.ActiveDocument.openTransaction(m_macro)
                    selfobj = makeAlongLinePointFeature(m_group)
                    selfobj.AlongEdge = edge
                    selfobj.Point = point
                    selfobj.Edge = None
                    selfobj.Distance = m_distanceLinePoint
                    selfobj.Proxy.execute(selfobj)

            except Exception as err:
                printError_msg(err.message, title=m_macro)

            App.ActiveDocument.commitTransaction()

        # Selection of : One Edge and One or several Edge(s)
        elif Number_of_Edges > 1 and Number_of_Vertexes == 0:
            try:
                # Create a sub group if needed
                if Number_of_Edges > 2:
                    m_group = createSubGroup(m_main_dir,
                                             m_sub_dir,
                                             m_error_msg)

                if WF.verbose():
                    print_msg("Group = " + str(m_group.Label))

                edge = Edge_List[0]
                if WF.verbose():
                    print_msg("edge = " + str(edge))

                for other_edge in Edge_List[1:]:
                    if WF.verbose():
                        print_msg("other_edge = " + str(other_edge))

                    App.ActiveDocument.openTransaction(m_macro)
                    selfobj = makeAlongLinePointFeature(m_group)
                    selfobj.AlongEdge = edge
                    selfobj.Point = None
                    selfobj.Edge = other_edge
                    selfobj.Distance = m_distanceLinePoint
                    selfobj.Proxy.execute(selfobj)

            except Exception as err:
                printError_msg(err.message, title=m_macro)

            App.ActiveDocument.commitTransaction()

        # Selection of : several Edges and Points with
        # same number of Edges and Points
        elif Number_of_Edges > 1 and Number_of_Vertexes == Number_of_Edges:
            try:
                # Create a sub group if needed
                m_group = createSubGroup(m_main_dir,
                                         m_sub_dir,
                                         m_error_msg)

                if WF.verbose():
                    print_msg("Group = " + str(m_group.Label))

                for edge, point in zip(Edge_List, Vertex_List):
                    if WF.verbose():
                        print_msg("edge = " + str(edge))
                        print_msg("point = " + str(point))

                    App.ActiveDocument.openTransaction(m_macro)
                    selfobj = makeAlongLinePointFeature(m_group)
                    selfobj.AlongEdge = edge
                    selfobj.Point = point
                    selfobj.Edge = None
                    selfobj.Distance = m_distanceLinePoint
                    selfobj.Proxy.execute(selfobj)

            except Exception as err:
                printError_msg(err.message, title=m_macro)

            App.ActiveDocument.commitTransaction()
        else:
            printError_msg("Bad selection !", title=m_macro)
    except Exception as err:
        printError_msg(err.message, title=m_macro)
예제 #4
0
def projected_point_command():
    global M_GROUP
    m_sel, m_act_doc = getSel(WF.verbose())

    def touch(selfobj):
        if str(selfobj.Parametric) == 'Interactive':
            selfobj.Parametric = 'Dynamic'
            selfobj.touch()
            selfobj.Parametric = 'Interactive'
        if str(selfobj.Parametric) == 'Not':
            selfobj.Parametric = 'Dynamic'
            selfobj.touch()
            selfobj.Parametric = 'Not'

    try:
        number_of_vertexes, vertex_list = m_sel.get_pointsNames(
            getfrom=["Points", "Segments", "Curves", "Planes", "Objects"])
        if WF.verbose():
            print_msg("number_of_vertexes = " + str(number_of_vertexes))
            print_msg("vertex_list = " + str(vertex_list))

        if number_of_vertexes < 1:
            raise Exception(M_EXCEPTION_MSG)

        try:
            m_main_dir = "WorkPoints_P"
            m_sub_dir = "Set001"
            M_GROUP = createFolders(str(m_main_dir))
            m_error_msg = "Could not Create '"
            m_error_msg += str(m_sub_dir) + "' Objects Group!"

            # Create a sub group if needed
            if number_of_vertexes > 1 or M_SEL_PLANE in M_SEL_MULTI or M_PROJ_LINE:
                try:
                    m_ob = App.ActiveDocument.getObject(
                        str(m_main_dir)).newObject("App::DocumentObjectGroup",
                                                   str(m_sub_dir))
                    M_GROUP = m_act_doc.getObject(str(m_ob.Label))
                except Exception as err:
                    printError_msg(err.args[0], title=M_MACRO)
                    printError_msg(m_error_msg)

            if WF.verbose():
                print_msg("Group = " + str(M_GROUP.Label))

            for point in vertex_list:
                if WF.verbose():
                    print_msg("Selected plane" + str(M_SEL_PLANE))

                # Possible selections
                # "XY plane",
                # "YZ plane",
                # "XZ plane",
                # "XY, YZ planes",
                # "XY, XZ planes",
                # "YZ, XZ planes",
                # "XY, YZ, XZ planes"
                # "Already Selected planes",

                if M_SEL_PLANE in [
                        "XY plane", "XY, YZ planes", "XY, XZ planes",
                        "XY, YZ, XZ planes"
                ]:
                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj = makeProjectedPointFeature(M_GROUP)
                    selfobj.Point = point
                    selfobj.At = "XY plane"
                    selfobj.Proxy.execute(selfobj)
                    WF.touch(selfobj)

                if M_SEL_PLANE in [
                        "YZ plane", "XY, YZ planes", "YZ, XZ planes",
                        "XY, YZ, XZ planes"
                ]:
                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj = makeProjectedPointFeature(M_GROUP)
                    selfobj.Point = point
                    selfobj.At = "YZ plane"
                    selfobj.Proxy.execute(selfobj)
                    WF.touch(selfobj)
                if M_SEL_PLANE in [
                        "XZ plane", "XY, XZ planes", "YZ, XZ planes",
                        "XY, YZ, XZ planes"
                ]:
                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj = makeProjectedPointFeature(M_GROUP)
                    selfobj.Point = point
                    selfobj.At = "XZ plane"
                    selfobj.Proxy.execute(selfobj)
                    WF.touch(selfobj)
        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)

        App.ActiveDocument.commitTransaction()

    except Exception as err:
        printError_msg(err.args[0], title=M_MACRO)