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
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
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]
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]
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)
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]
def draw_bbox(n): """Draw the bbox of an object.""" return drawBbox(named(n))
def draw_free_edges(n): """Draw the feature edges of an object.""" return drawFreeEdges(named(n), color='black')
def draw_node_numbers(n): """Draw the numbers of an object's nodes.""" return drawNumbers(named(n).coords, color='red')
def draw_nodes(n): """Draw the nodes of an object.""" return draw(named(n).coords, nolight=True, wait=False)
def draw_elem_numbers(n): """Draw the numbers of an object's elements.""" return drawNumbers(named(n), color='blue')
def draw_object_name(n): """Draw the name of an object at its center.""" return drawText3D(n, named(n).center())