コード例 #1
0
ファイル: draw.py プロジェクト: gitGNU/gnu_pyformex
def flatten(objects,recurse=True):
    """Flatten a list of geometric objects.

    Each item in the list should be either:

    - a drawable object,
    - a string with the name of such an object,
    - a list of any of these three.

    This function will flatten the lists and replace the string items with
    the object they point to. The result is a single list of drawable
    objects. This function does not enforce the objects to be drawable.
    That should be done by the caller.
    """
    r = []
    for i in objects:
        if isinstance(i, str):
            i = named(i)
        if isinstance(i, list):
            if recurse:
                r.extend(flatten(i, True))
            else:
                r.extend(i)
        else:
            r.append(i)
    return r
コード例 #2
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
    def ask1(self):
        """Select a single object from the list.

        Returns the object, not its name!
        """
        if self.ask('single'):
            return named(self.names[0])
        else:
            return None
コード例 #3
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
    def remember(self,copy=False):
        """Remember the current values of the variables in selection.

        If copy==True, the values are copied, so that the variables' current
        values can be changed inplace without affecting the remembered values.
        """
        self.values = [named(n) for n in self.names]
        if copy:
            self.values = [deepcopy(n) for n in self.values]
コード例 #4
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
    def set(self, names):
        """Set the selection to a list of names.

        namelist can be a single object name or a list of names.
        This will also store the current values of the variables.
        """
        if isinstance(names, str):
            names = [ names ]
        self.names = [ s for s in names if isinstance(s, str) ]
        self.values = [named(s) for s in self.names]
コード例 #5
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
    def append(self,name,value=None):
        """Add a name,value to a selection.

        If no value is given, its current value is used.
        If a value is given, it is exported.
        """
        self.names.append(name)
        if value is None:
            value = named(name)
        else:
            export({name:value})
        self.values.append(value)
コード例 #6
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
    def check(self,single=False,warn=True):
        """Check that we have a current selection.

        Returns the list of Objects corresponding to the current selection.
        If single==True, the selection should hold exactly one Object name and
        a single Object instance is returned.
        If there is no selection, or more than one in case of single==True,
        an error message is displayed and None is returned
        """
        self.names = [ n for n in self.names if n in pf.PF ]
        if len(self.names) == 0:
            if warn:
                warning("No %sobjects were selected" % self.object_type())
            return None
        if single and len(self.names) > 1:
            if warn:
                warning("You should select exactly one %sobject" %  self.object_type())
            return None
        if single:
            return named(self.names[0])
        else:
            return [named(n) for n in self.names]
コード例 #7
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
def draw_bbox(n):
    """Draw the bbox of an object."""
    return drawBbox(named(n))
コード例 #8
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
def draw_free_edges(n):
    """Draw the feature edges of an object."""
    return drawFreeEdges(named(n), color='black')
コード例 #9
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
def draw_node_numbers(n):
    """Draw the numbers of an object's nodes."""
    return drawNumbers(named(n).coords, color='red')
コード例 #10
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
def draw_nodes(n):
    """Draw the nodes of an object."""
    return draw(named(n).coords, nolight=True, wait=False)
コード例 #11
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
def draw_elem_numbers(n):
    """Draw the numbers of an object's elements."""
    return drawNumbers(named(n), color='blue')
コード例 #12
0
ファイル: objects.py プロジェクト: gitGNU/gnu_pyformex
def draw_object_name(n):
    """Draw the name of an object at its center."""
    return drawText3D(n, named(n).center())