| Stateflow | ![]() |
www.kxcad.net Home > CAE Software Index > MATLAB Index >
| On this page… |
|---|
About Creating and Destroying API Objects |
You create (construct), parent (contain), and delete (destroy) objects in Stateflow through constructor methods in the Stateflow API. For all but the Editor and Clipboard objects, creating objects establishes a handle to them that you can use for accessing their properties and methods to make modifications to Stateflow diagrams.
Stateflow objects are contained (parented) by other objects as defined in the Stateflow hierarchy of objects (see Stateflow API Object Hierarchy). You control containment of nongraphical objects in the Stateflow Explorer.
You create a Stateflow object as the child of a parent object through API constructor methods. Each Stateflow object type has its own constructor method. See Constructor Methods for a list of the valid constructor methods.
Use the following process to create Stateflow objects with the Stateflow API:
Access the parent object to obtain a handle to it.
When you first begin populating a model or chart, this means that you must get a handle to the Stateflow Model object or a particular Chart object. See Access the Model Object and Access the Chart Object.
See also Accessing Existing Stateflow Objects for a more general means of accessing (getting an object handle to) an existing Stateflow object.
Call the appropriate constructor method for the creation of the object using the parent (containing) object as an argument.
For example, the following command creates and returns a handle s to a new state object in the chart object with the handle ch:
s = Stateflow.State(ch)
By default, the newly created state from the preceding command appears in the upper-left corner of the Stateflow chart (at x-y coordinates 0,0).

The constructor returns a handle to an API object for the newly created Stateflow object. Use this handle to display or change the object through its properties and methods.
Use the object handle returned by the constructor to make changes to the object in Stateflow.
For example, you can now use the handle s to set its name (Name property) and position (Position property). You can also connect it to other states or junctions by creating a Transition object and setting its Source or Destination property to s. See Create New Objects in the Chart for examples.
Use the preceding process to create all Stateflow objects in your chart. Create New Objects in the Chart gives examples for creating states and transitions. Objects of other types are created just as easily. For example, the following command creates and returns a handle (d1) for a new Data object belonging to the state A (handle sA):
d1 = Stateflow.Data(sA)
Note Currently, there is no constructor for a Stateflow chart. To create a chart with the Stateflow API you must use the sfnew function. |
As discussed in the previous section, Creating Stateflow Objects, the Stateflow API constructor establishes the parent for a newly created object by taking a handle for the parent object as an argument to the constructor.
When graphical objects (states, boxes, notes, functions, transitions, junctions) are created, they appear completely inside their containing parent object. In the diagram editor, graphical containment is a necessary and sufficient condition for establishing the containing parent.
Repositioning a graphical object through its Position property can change an object's parent or cause an undefined parent error condition. Parsing a chart in which the edges of one object overlap with another produces an undefined parent error condition that cannot be resolved by the Stateflow parser. You can check for this condition by examining the value of the BadIntersection property of a Chart object, which equals 1 if the edges of a graphical object overlap with other objects. You need to set the size and position of objects so that they are clearly positioned and separate from other objects.
When nongraphical objects (data, events, and targets) are created, they appear in the Stateflow Explorer at the hierarchical level of their owning object. Containment for nongraphical objects is established through the Stateflow Explorer only. See the section Using the Model Explorer with Stateflow Objects in the Stateflow and Stateflow Coder User's Guide documentation.
Each Stateflow object of type State, Box, Function, Note, Transition, Junction, Event, Data, or Target has a destructor method named delete. In the following example, a State object, s, is deleted:
s.delete
The preceding command is equivalent to performing a mouse select and keyboard delete operation in the Stateflow diagram editor. Upon deletion, graphical Stateflow objects are sent to the clipboard; nongraphical objects, such as data and events, are completely deleted. The workspace variable s still exists but is no longer a handle to the deleted state.
| Displaying Properties and Methods | Accessing Existing Stateflow Objects | ![]() |
© 1984-2007 The MathWorks, Inc. Terms of Use Patents Trademarks Acknowledgments