84. plugins.objects — Selection of objects from the global dictionary.

This is a support module for other pyFormex plugins.

84.1. Classes defined in module plugins.objects

class plugins.objects.Objects(clas=None, like=None, filter=None, namelist=[])[source]

A selection of objects from the pyFormex Globals().

The class provides facilities to filter the global objects by their type and select one or more objects by their name(s). The values of these objects can be changed and the changes can be undone.

Examples

>>> from pyformex.core import Mesh, TriSurface
>>> pf.PF.clear()
>>> M = Mesh()
>>> M1 = Mesh(eltype='tri3')
>>> S = M1.toSurface()
>>> F = S.toFormex()
>>> gs.export({'a':2, 'M':M, 'S':S, 'F':F, 'M1':M1})
>>> Objects(clas=Mesh).listAll()
['M', 'S', 'M1']
>>> Objects(clas=Mesh,
...     filter=lambda o: isinstance(pf.PF[o], TriSurface)).listAll()
['S']
property object_type

Return the type of objects in this selection.

set(names)[source]

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.

append(name, value=None)[source]

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.

clear()[source]

Clear the selection.

narrow(allowed=())[source]

Narrow the current selection to objects of the specified classes

Parameters:

allowed (type | tuple of type) – The allowed instance types. All objects in the current selection that are not instances of any of the allowed types, are removed. The default (empty tuple) clears the selection. A value None leaves the selection untouched.

listAll(allowed=None)[source]

Return a list with all selectable objects.

This lists all the global names in pyformex.PF that match the class and/or filter (if specified).

remember(copy=False)[source]

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.

changeValues(newvalues)[source]

Replace the current values of selection by new ones.

The old values are stored locally, to enable undo operations.

This is only needed to change the values of objects that can not be changed inplace!

undoChanges()[source]

Undo the last changes of the values.

check(*, allowed=None, single=False, warn=True)[source]

Check and return the current selection.

Checks that a current selection exists and conforms to the provided requirements.

Parameters:
  • allowed (type or tuple of type, optional) – One or more object types. If provided, the current selection will be narrowed down to objects of this type.

  • single (bool, optional) – If True, only a single object should be selected. The default allows a multiple objects selection.

  • warn (bool, optional) – If True (default), a warning is displayed if the selection is empty or there is more than one selected object when single=True was specified. Setting to False suppresses the warning, which may be useful in batch processing.

Returns:

object | list of objects | None – With single=True, a single selected object, else a list of objects. These objects constitute the current selection. If there is no current selection, or more than one in case of single=True, None is returned.

checkOrAsk(*, allowed=None, single=False, warn=True)[source]

Check, ask and return the current selection.

This is like check(), but if the selection does not conform, lets the user change it.

keys()[source]

Return the names of the currently selected objects.

values()[source]

Return the values of the currently selected objects.

odict()[source]

Return the currently selected items as a dictionary.

Returns a dict with the currently selected objects in the order of the selection.names.

ask(single=False, allowed=None)[source]

Show the names of known objects and let the user select one or more.

Parameters:

single (bool) – If True, only one item can be selected.

Returns:

list | None – A list with the selected name(s), possibly empty (if nothing was selected by the user), or None if there is nothing to choose from.

Notes

This also sets the current selection to the selected names, unless the return value is None, in which case the selection remains unchanged.

ask1()[source]

Select a single object from the list.

This is like ask() with the single=True parameter, but returns the object instead of its name.

forget()[source]

Remove the selection from the globals.

keep()[source]

Remove everything except the selection from the globals.

writeToFile(filename)[source]

Write objects to a geometry file.

readFromFile(filename)[source]

Read objects from a geometry file.

class plugins.objects.DrawableObjects(**kargs)[source]

A selection of drawable objects from the globals().

This is a subclass of Objects. The constructor has the same arguments as the Objects class. THe difference is that when a selection is made in the DrawableObjects class, the selection is drawn automatically. This is therefore well suited to do interactive modeling. Furthermore it has provisions to add annotations to the rendering, like node and element numbers, or surface normals.

ask(**kargs)[source]

Interactively sets the current selection.

drawChanges()[source]

Draws old and new version of a Formex with different colors.

old and new can be a either Formex instances or names or lists thereof. old are drawn in yellow, new in the current color.

undoChanges()[source]

Undo the last changes of the values.

registerAnnotation(**kargs)[source]

Register annotation function.

An annotation function is a function that takes the name of an object as parameter and draws something related to that object. The annotations drawn by these functions can be toggled on and off. Annotion functions should silently ignore objects for which they can not draw the annptation The Geometry menu has many examples of annotation functions.

Parameters:

kargs – A dict where each key ia an annotation name and the value is an annotation function.

hasAnnotation(f)[source]

Return the status of annotation f

toggleAnnotation(f, onoff=None)[source]

Toggle the display of an annotation On or Off.

If given, onoff is True or False. If no onoff is given, this works as a toggle.

drawAnnotation(f)[source]

Draw some annotation for the current selection.

removeAnnotation(f)[source]

Remove the annotation f.

editAnnotations(ontop=None)[source]

Edit the annotation properties

Currently only changes the ontop attribute for all drawn annotations. Values: True, False or ‘’ (toggle). Other values have no effect.

setProp(prop=None)[source]

Set the property of the current selection.

prop should be a single integer value or None. If None is given, a value will be asked from the user. If a negative value is given, the property is removed. If a selected object does not have a setProp method, it is ignored.

delProp()[source]

Delete the property of the current selection.

Resets the prop attribute of all selected objects to None.