示例#1
0
    def add_child(self, *args, **kwargs):
        """ This methods modifies the mtg by adding a child to this vertex.
        The view will be updated through the graph's notifications.
        """
        gm = self.graph()
        x, y = self.get_view_data("position")
        edge_type =  kwargs.get("edge_type", "<")
        if edge_type in ["+","<"]:
            y -= 40
        elif edge_type in ["\\","/"]:
            pass #y==y

        if edge_type == "<":
            n = len(algo.sons(self.mtg, self.vertex().vid, EdgeType="<"))
            if n > 0: #there can only be one successor
                return
        elif edge_type == "+":
            children = algo.sons(self.mtg, self.vertex().vid, EdgeType="+")
            n = len(children)
            n = n if n < 60/30 else n+1
            angle = -60 + n*30
            x += sin(radians(angle))*80
        elif edge_type == "/":
            x += 200
        elif edge_type == "\\":
            x -= 200

        gm.new_vertex(parent=self.vertex(), position=[x,y], edge_type=edge_type )
示例#2
0
文件: aml.py 项目: BeGIMATH/mtg
def Sons(v,
         RestrictedTo='NoRestriction',
         EdgeType='*',
         Scale=-1,
         ContainedIn=None):
    """
    Set of vertices born or preceded by a vertex

    The set of sons of a given vertex is returned as an array of vertices.
    The order of the vertices in the array is not significant.
    The array can be empty if there are no son vertices.

    :Usage:

    .. code-block:: python

        from openalea.mtg.aml import Sons
        Sons(v)
        Sons(v, EdgeType= '+')
        Sons(v, Scale= 3)

    :Parameters:

        - v (int) : vertex of the active MTG

    :Optional Parameters:

        - RestrictedTo (str) : cf. `Father`
        - ContainedIn (int) : cf. `Father`
        - EdgeType (str) : filter on the type of sons.
        - Scale (int) : set the scale at which sons are considered.

    :Returns:

        list(vid)

    :Details:

        When the option EdgeType is applied, the function returns the set of sons
        that are connected to the argument with the specified type of relation.
        
    .. note:: `Sons(v, EdgeType= '<')` is not equivalent to `Successor(v)`.
        The first function returns an array of vertices while the second function
        returns a vertex.

        The returned vertices have the same scale as the argument.
        However, coarser or finer vertices can be obtained by specifying
        the optional argument `Scale` at which the sons are considered.


    :Examples:

    .. code-block:: python

        >>> Sons(v)
        [3,45,47,78,102]
        >>>  Sons(v, EdgeType= '+') # set of vertices borne by v
        [3,45,47,102]
        >>>  Sons(v, EdgeType= '<') # set of successors of v on the same axis
        [78]

    .. seealso:: :func:`MTG`, :func:`Father`, :func:`Successor`, :func:`Descendants`.
    """
    global _g
    return algo.sons(_g,
                     v,
                     EdgeType=EdgeType,
                     RestrictedTo=RestrictedTo,
                     Scale=Scale,
                     ContainedIn=ContainedIn)
示例#3
0
文件: aml.py 项目: imane-aanna/mtg-1
def Sons(v, RestrictedTo='NoRestriction', EdgeType='*', Scale=-1, ContainedIn= None):
    """
    Set of vertices born or preceded by a vertex

    The set of sons of a given vertex is returned as an array of vertices.
    The order of the vertices in the array is not significant.
    The array can be empty if there are no son vertices.

    :Usage:

    .. code-block:: python

        from openalea.mtg.aml import Sons
        Sons(v)
        Sons(v, EdgeType= '+')
        Sons(v, Scale= 3)

    :Parameters:

        - v (int) : vertex of the active MTG

    :Optional Parameters:

        - RestrictedTo (str) : cf. `Father`
        - ContainedIn (int) : cf. `Father`
        - EdgeType (str) : filter on the type of sons.
        - Scale (int) : set the scale at which sons are considered.

    :Returns:

        list(vid)

    :Details:

        When the option EdgeType is applied, the function returns the set of sons
        that are connected to the argument with the specified type of relation.
        
    .. note:: `Sons(v, EdgeType= '<')` is not equivalent to `Successor(v)`.
        The first function returns an array of vertices while the second function
        returns a vertex.

        The returned vertices have the same scale as the argument.
        However, coarser or finer vertices can be obtained by specifying
        the optional argument `Scale` at which the sons are considered.


    :Examples:

    .. code-block:: python

        >>> Sons(v)
        [3,45,47,78,102]
        >>>  Sons(v, EdgeType= '+') # set of vertices borne by v
        [3,45,47,102]
        >>>  Sons(v, EdgeType= '<') # set of successors of v on the same axis
        [78]

    .. seealso:: :func:`MTG`, :func:`Father`, :func:`Successor`, :func:`Descendants`.
    """
    global _g
    return algo.sons(_g, v, EdgeType=EdgeType, RestrictedTo=RestrictedTo, Scale=Scale, ContainedIn=ContainedIn)