Пример #1
0
def minMaxVectorsLimits(vertexes):
    """ Return the min and max limits along the 3 Axis for all selected Vectors.
    """
    xmax = xmin = ymax = ymin = zmax = zmin = 0
    m_vertx = vertexes
    m_num = len(m_vertx)

    if vertexes is None:
        print_msg("ERROR : vertexes == None, leaving minMaxVectorsLimits()")
        return xmax, xmin, ymax, ymin, zmax, zmin

    if m_num < 1:
        print_msg("ERROR : len(vertexes) < 1 , leaving minMaxVectorsLimits()")
        return xmax, xmin, ymax, ymin, zmax, zmin

    min_val, max_val = init_min_max()
    xmin = ymin = zmin = max_val
    xmax = ymax = zmax = min_val

    for m_vert in m_vertx:
        xmax = max(xmax, m_vert.x)
        xmin = min(xmin, m_vert.x)
        ymax = max(ymax, m_vert.y)
        ymin = min(ymin, m_vert.y)
        zmax = max(zmax, m_vert.z)
        zmin = min(zmin, m_vert.z)

    return xmax, xmin, ymax, ymin, zmax, zmin
Пример #2
0
    def execute_2018(self, selfobj):
        """ Doing a old recomputation.
        """
        if M_DEBUG:
            print("Recompute Python CenterLinePoint feature (old manner)\n")

        if 'Edge' not in selfobj.PropertiesList:
            return
        if 'IndexPart' not in selfobj.PropertiesList:
            return
        if 'NumberLinePart' not in selfobj.PropertiesList:
            return

#         n = eval(selfobj.Edge[1][0].lstrip('Edge'))
        m_int = re.sub('[^0-9]', '', selfobj.Edge[1][0])
        n = int(m_int)
        if WF.verbose():
            print_msg("n = " + str(n))

        try:
            vector_point = alongLinePoint(selfobj.Edge[0].Shape.Edges[n - 1],
                                          selfobj.IndexPart,
                                          selfobj.NumberLinePart)

            point = Part.Point(vector_point)
            selfobj.Shape = point.toShape()
            propertiesPoint(selfobj.Label)
            selfobj.X = float(vector_point.x)
            selfobj.Y = float(vector_point.y)
            selfobj.Z = float(vector_point.z)
        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)
Пример #3
0
def meanVectorsPoint(vertexes):
    """ Return the mean point of all selected Vectors.
    """
    Vector_mean = App.Vector(0.0, 0.0, 0.0)
    m_vertx = vertexes
    m_num = len(m_vertx)

    if vertexes is None:
        print_msg("ERROR : vertexes == None, leaving meanVectorsPoint()")
        return Vector_mean
    if m_num < 1:
        print_msg("ERROR : len(vertexes) < 1 , meanVectorsPoint()")
        return Vector_mean
    m_list = []
    for m_vert in m_vertx:
        m_list.append(m_vert.x)
        m_list.append(m_vert.y)
        m_list.append(m_vert.z)

    import numpy
    V = numpy.array(m_list)
    Vre = V.reshape(m_num, 3)
    C = sum(Vre, 0) / m_num

    Vector_mean = App.Vector(C[0], C[1], C[2])

    return Vector_mean
Пример #4
0
    def execute_2018(self, selfobj):
        if WF.verbose():
            m_msg = "Recompute Python CenterLinePoint feature (old manner)\n"
            App.Console.PrintMessage(m_msg)

        if 'Edge' not in selfobj.PropertiesList:
            return
        if 'IndexPart' not in selfobj.PropertiesList:
            return
        if 'NumberLinePart' not in selfobj.PropertiesList:
            return

        n = eval(selfobj.Edge[1][0].lstrip('Edge'))
        if WF.verbose():
            print_msg("n = " + str(n))

        try:
            Vector_point = alongLinePoint(selfobj.Edge[0].Shape.Edges[n - 1],
                                          selfobj.IndexPart,
                                          selfobj.NumberLinePart)

            point = Part.Point(Vector_point)
            selfobj.Shape = point.toShape()
            propertiesPoint(selfobj.Label)
            selfobj.X = float(Vector_point.x)
            selfobj.Y = float(Vector_point.y)
            selfobj.Z = float(Vector_point.z)
        except Exception as err:
            printError_msg(err.args[0], title=m_macro)
Пример #5
0
 def Activated(self):
     m_actDoc = App.activeDocument()
     if m_actDoc is not None:
         m_selEx = Gui.Selection.getSelectionEx(m_actDoc.Name)
         if len(m_selEx) != 0 and WF.verbose():
             print_msg(str(m_selEx))
         run_showhide('Not')
Пример #6
0
def rmObjectFromGrp(obj, grp, info=0):
    """ Removes an object 'obj' from the group 'grp'
    """
    grp.removeObject(obj)
    if info != 0:
        m_msg = "Object " + str(obj.Label)
        m_msg += " removed from Group : " + str(grp.Label)
        print_msg(m_msg)
Пример #7
0
def selection_debug(m_parent, m_name, m_i, m_type):
    m_shape = m_parent.Shape
    if WF.verbose():
        print_msg("   m_obj.Object = " + str(m_parent))
        print_msg("   m_obj.SubElementNames = " + str(m_name))
        print_msg("   m_obj.Object.Shape = " + str(m_shape))
        print_msg("   type(m_obj.Object.Shape) = " + str(m_type))
        print_msg("   m_i = " + str(m_i))
Пример #8
0
def addObjectToGrp(obj, grp, info=0):
    """ Adds an object 'obj' to the group 'grp'
    """
    grp.addObject(obj)
    if info != 0:
        m_msg = "Object " + str(obj.Label)
        m_msg += " added to Group : " + str(grp.Label)
        print_msg(m_msg)
Пример #9
0
def getSel(verbose=0):
    """ Create and return A Selection Object
    and the active FreeCAD document.

    Return:
    -------
    (sel, doc) when success
    (None, message) when error

    Parameters
    -------
    *verbose*   : (Integer , Optional, default=0)
                if == 1 force the verbose mode.

    Examples
    -------
    >>> import WF_selection as sel
    >>> # Open a document in FreeCAD
    >>> m_in_file_name = u"/home/.../01.FCStd"
    >>> m_doc = App.open(m_in_file_name)
    >>> # Clear selection
    >>> Gui.Selection.clearSelection()
    >>> # You can use this to add your element to FreeCAD's selection :
    >>> Gui.Selection.addSelection(m_doc.Line001)
    >>> # Recover the selection Object m_sel
    >>> m_sel, m_act_doc = sel.getSel(verbose=0)
    """
    global M_DEBUG

    M_DEBUG = False
    if verbose:
        M_DEBUG = True

    m_doc = App.activeDocument()
    if m_doc is None:
        message = "No Active document selected !"
        return (None, message)
    if not m_doc.Name:
        message = "No Active document.name selected !"
        return (None, message)

    if M_DEBUG:
        print("Document      = " + str(m_doc))
        print("Document.Name = " + str(m_doc.Name))
        printObjectStructure()

    m_selEx = Gui.Selection.getSelectionEx(m_doc.Name)
    m_sel = Selection(m_selEx)

    if m_sel is None:
        message = "Unable to create a Selection Object !"
        print_msg(message)
        return (None, message)

    if M_DEBUG:
        print(str(m_sel))

    return m_sel, m_doc
Пример #10
0
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        if m_debug:
            print("running NPointsPoint.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 NPointsPoint feature\n"
            App.Console.PrintMessage(m_msg)

        if m_debug:
            print("selfobj.PropertiesList = " + str(selfobj.PropertiesList))

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

        try:
            Vector_point = None
            if m_debug:
                print("selfobj.Points = " + str(selfobj.Points))
            if selfobj.Points is not None:
                m_points = []
                for p in linkSubList_convertToOldStyle(selfobj.Points):
                    n = eval(p[1].lstrip('Vertex'))
                    if m_debug:
                        print("p " + str(p))
                        print_msg("n = " + str(n))
                    m_points.append(p[0].Shape.Vertexes[n - 1].Point)

            Vector_point = meanVectorsPoint(m_points)

            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.args[0], title=m_macro)
Пример #11
0
def buildFromPoints(macro, group, vertexes):
    """ Build a NPointsPoint feature object using a list of points.
    """
    if WF.verbose():
        print_msg("vertexes = " + str(vertexes))
    App.ActiveDocument.openTransaction(macro)
    selfobj, m_inst = makeNPointsPointFeature(group)
    m_inst.addSubobjects(selfobj, vertexes)
    selfobj.Proxy.execute(selfobj)
    WF.touch(selfobj)
Пример #12
0
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        m_properties_list = [
            'Edge',
            'At',
        ]
        for m_property in m_properties_list:
            if m_property not in selfobj.PropertiesList:
                return

        if M_DEBUG:
            print("running ExtremaLinePoint.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

        try:
            vector_point = None
            m_n = re.sub('[^0-9]', '', selfobj.Edge[1][0])
            m_n = int(m_n)
            if M_DEBUG:
                print_msg(str(selfobj.Edge))
                print_msg("m_n = " + str(m_n))

            if not selfobj.Edge[0].Shape.Edges:
                return

            if selfobj.At == "Begin":
                vector_point = selfobj.Edge[0].Shape.Edges[m_n -
                                                           1].Vertexes[0].Point
            else:
                vector_point = selfobj.Edge[0].Shape.Edges[
                    m_n - 1].Vertexes[-1].Point

            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 AttributeError as err:
            print("AttributeError" + str(err))
        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)
Пример #13
0
def coordVectorPoint(vertex):
    """ Return the coordinates (x,y,z) of selected Vector.
    """
    m_coord = (0.0, 0.0, 0.0)
    m_vert = vertex

    if vertex is None:
        print_msg("ERROR : vertex == None, leaving coordVectorPoint()")
        return m_coord

    return (m_vert.x, m_vert.y, m_vert.z)
Пример #14
0
def addObjectToGrp(obj, grp, info=0):
    """ Add an object to the group
    """
    m_obj = obj
    m_grp = grp
    # adds object to the group
    m_grp.addObject(m_obj)
    if info != 0:
        m_msg = "Object " + str(m_obj.Label)
        m_msg += " added to Group : " + str(m_grp.Label)
        print_msg(m_msg)
Пример #15
0
def printPoint(point, msg=""):
    """ Print x,y and z of a point:vector.
    """
    if point.__class__.__name__ != "Vector":
        print_msg("Not a Vector to print !")
        return

    print_msg(str(msg) + " " +
              "x =" + str(point.x) + ", "
              "y =" + str(point.y) + ", "
              "z =" + str(point.z))
    return
Пример #16
0
def run_showhide(parametric='Dynamic'):
    for obj in App.ActiveDocument.Objects:
        # print str(obj.Name)
        # print obj.PropertiesList
        if "Parametric" in obj.PropertiesList:
            if WF.verbose():
                print(str(obj.Name))
                print(str(obj.Parametric))
            if str(obj.Parametric) == parametric:
                obj.ViewObject.Visibility = not obj.ViewObject.Visibility

    if WF.verbose():
        print_msg("Show/Hide done !")
Пример #17
0
    def accept(self):
        global m_extension
        m_extension = float(self.form.UI_Plane_extension.text())

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

        Gui.Control.closeDialog()
        m_actDoc = App.activeDocument()
        if m_actDoc is not None:
            if len(Gui.Selection.getSelectionEx(m_actDoc.Name)) != 0:
                run()
        return True
Пример #18
0
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        m_properties_list = ['Points',
                             ]
        for m_property in m_properties_list:
            if m_property not in selfobj.PropertiesList:
                return

        if M_DEBUG:
            print("running NPointsPoint.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

        try:
            vector_point = None
            if selfobj.Points is not None:
                m_points = []
                for p in linkSubList_convertToOldStyle(selfobj.Points):
                    # n = eval(p[1].lstrip('Vertex'))
                    m_n = re.sub('[^0-9]', '', p[1])
                    m_n = int(m_n)
                    if M_DEBUG:
                        print("p " + str(p))
                        print_msg("m_n = " + str(m_n))

                    m_points.append(p[0].Shape.Vertexes[m_n - 1].Point)

            vector_point = meanVectorsPoint(m_points)

            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 AttributeError as err:
            print("AttributeError" + str(err))
        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)
Пример #19
0
    def accept(self):
        global m_distanceLinePoint

        m_distanceLinePoint = float(self.form.UI_Distance.text())

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

        Gui.Control.closeDialog()
        m_actDoc = App.activeDocument()
        if m_actDoc is not None:
            if len(Gui.Selection.getSelectionEx(m_actDoc.Name)) != 0:
                run()
        return True
Пример #20
0
def propertiesPoint(Point_User_Name,
                    color=(1.00, 0.67, 0.00)):
    """ Define the properties of a Work feature Point.
    PointColor
    PointSize
    Transparency
    """
    try:
        if isinstance(color, tuple):
            Gui.ActiveDocument.getObject(Point_User_Name).PointColor = color
    except Exception as err:
        printError_msg(err.message, title="propertiesPoint")
        print_msg("Not able to set PointColor !")
        print_msg("Color : " + str(color) + " !")
    try:
        Gui.ActiveDocument.getObject(
            Point_User_Name).PointSize = WF.pointSize()

    except Exception as err:
        printError_msg(err.message, title="propertiesPoint")
        print_msg("Not able to set PointSize !")
    try:
        Gui.ActiveDocument.getObject(Point_User_Name).Transparency = 0
    except Exception as err:
        printError_msg(err.message, title="propertiesPoint")
        print_msg("Not able to set Transparency !")

    return
Пример #21
0
def propertiesPlane(Plane_User_Name,
                    color=(1.00, 0.67, 0.00),
                    s_color=(0.00, 0.33, 1.00)):
    """ Define the properties of a Work feature Plane.
    PointColor
    LineColor
    ShapeColor
    Transparency
    """
    try:
        if isinstance(color, tuple):
            Gui.ActiveDocument.getObject(Plane_User_Name).PointColor = color
    except Exception as err:
        printError_msg(err.message, title="propertiesPlane")
        print_msg("Not able to set PointColor !")
    try:
        if isinstance(color, tuple):
            Gui.ActiveDocument.getObject(Plane_User_Name).LineColor = color
    except Exception as err:
        printError_msg(err.message, title="propertiesPlane")
        print_msg("Not able to set LineColor !")
    try:
        if isinstance(s_color, tuple):
            Gui.ActiveDocument.getObject(Plane_User_Name).ShapeColor = s_color
    except Exception as err:
        printError_msg(err.message, title="propertiesPlane")
        print_msg("Not able to set ShapeColor !")
    try:
        Gui.ActiveDocument.getObject(Plane_User_Name).Transparency = 75
    except Exception as err:
        printError_msg(err.message, title="propertiesPlane")
        print_msg("Not able to set Transparency !")

    return
Пример #22
0
def run_refresh():
    for obj in App.ActiveDocument.Objects:
        # print str(obj.Name)
        # print obj.PropertiesList
        if "Parametric" in obj.PropertiesList:
            if WF.verbose():
                print(str(obj.Name))
                print(str(obj.Parametric))
            if str(obj.Parametric) == 'Interactive':
                obj.Parametric = 'Dynamic'
                obj.touch()
                obj.Parametric = 'Interactive'

    if WF.verbose():
        print_msg("Update done !")
Пример #23
0
def buildFromEdgeAndPoint(macro, group, edge, point, distance):
    """ Build a AlongLinePoint feature object using an edge.
    and a point.
    """
    if WF.verbose():
        print_msg("edge = " + str(edge))
        print_msg("point = " + str(point))

    App.ActiveDocument.openTransaction(macro)
    selfobj = makeAlongLinePointFeature(group)
    selfobj.AlongEdge = edge
    selfobj.Point = point
    selfobj.Edge = None
    selfobj.Distance = distance
    selfobj.Proxy.execute(selfobj)
Пример #24
0
def buildFromEdge(macro, group, edge, number_line_part, index_part):
    """ Build a CenterLinePoint feature object using an edge.
    """
    if WF.verbose():
        print_msg("edge = " + str(edge))
    App.ActiveDocument.openTransaction(macro)
    selfobj = makeCenterLinePointFeature(group)
    selfobj.Edge = edge
    selfobj.Point1 = None
    selfobj.Point2 = None
    selfobj.NumberLinePart = number_line_part
    selfobj.IndexPart = index_part
    selfobj.Proxy.execute(selfobj)

    WF.touch(selfobj)
Пример #25
0
    def accept(self):
        """ Run when click on OK button.
        """
        global M_PLANE_EXT
        M_PLANE_EXT = float(self.form.UI_Plane_extension.text())

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

        Gui.Control.closeDialog()
        m_act_doc = App.activeDocument()
        if m_act_doc is not None:
            if Gui.Selection.getSelectionEx(m_act_doc.Name):
                line_point_plane_command()
        return True
Пример #26
0
def buildFromPointAndLine(macro, group, vertex, edge, extension):
    """ Build a LinePointPlane feature object using one point
    and one line.
    """
    if WF.verbose():
        print_msg("edge = " + str(edge))
        print_msg("vertex = " + str(vertex))

    App.ActiveDocument.openTransaction(macro)
    selfobj = makeLinePointPlaneFeature(group)
    selfobj.Edge = edge
    selfobj.Point = vertex
    selfobj.Extension = extension
    selfobj.Proxy.execute(selfobj)
    WF.touch(selfobj)
Пример #27
0
    def accept(self):
        """ Run when click on OK button.
        """
        global M_LOCATION
        M_LOCATION = self.form.UI_ExtremaLinePoint_comboBox.currentText()

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

        Gui.Control.closeDialog()
        m_act_doc = App.activeDocument()
        if m_act_doc is not None:
            if Gui.Selection.getSelectionEx(m_act_doc.Name):
                extrema_line_point_command()
        return True
Пример #28
0
def buildFromPoints(macro, group, vertex1, vertex2, line_ext):
    """ Build a TwoPointsLine feature object using two points.
    """

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

    App.ActiveDocument.openTransaction(macro)
    selfobj = makeTwoPointsLineFeature(group)
    selfobj.Point1 = vertex1
    selfobj.Point2 = vertex2
    selfobj.Extension = line_ext
    selfobj.Proxy.execute(selfobj)
    WF.touch(selfobj)
Пример #29
0
    def accept(self):
        global m_sel_plane
        global m_proj_line
        m_sel_plane = self.form.UI_ProjectePoint_comboBox.currentText()
        m_proj_line = self.form.UI_ProjectePoint_checkBox.isChecked()

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

        Gui.Control.closeDialog()
        m_actDoc = App.activeDocument()
        if m_actDoc is not None:
            if len(Gui.Selection.getSelectionEx(m_actDoc.Name)) != 0:
                run()
        return True
Пример #30
0
    def accept(self):
        """ Run when click on OK button.
        """
        global M_DISTANCELINEPOINT

        M_DISTANCELINEPOINT = float(self.form.UI_Distance.text())

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

        Gui.Control.closeDialog()
        m_act_doc = App.activeDocument()
        if m_act_doc is not None:
            if Gui.Selection.getSelectionEx(m_act_doc.Name):
                along_line_point_command()
        return True