STAMP/STPA
Get facet model
All STAMP/STPA models and presentations exist in the STAMP/STPA facet Model which can be accessed by calling getFacet(String symbolicName)of ProjectAccessor.
public IFacet getSTAMPFacet(ProjectAccessor projectAccessor) throws ProjectNotFoundException {
return projectAccessor.getFacet(IStampFacet.FACET_SYMBOLIC_NAME);
}
Get Models and Presentations
Get Models
Control Action
Let’s get control actions from Component1 in the sample control structure diagram below.
This is how Astah API works in this case.
Control Actions cannot be got from Component1 directly. Control Links with Control Actions connected to Component1 must be got at first.
This is the instance diagram. As you can see, you can get Control Link from StpaAnalysis (IStpaAnalysis#getLinks().
Control Actions can be get from Control Link IControlLink#getActions().
public List<IControlAction> getControlActions(IComponent component) throws ClassNotFoundException {
List<IControlAction> controlActions = new ArrayList<>();
= AstahAPI.getAstahAPI().getProjectAccessor().getFacet(IStampFacet.FACET_SYMBOLIC_NAME);
IFacet facet = facet.getRootElement(IStpaAnalysis.class);
IStpaAnalysis analysis List<ILink> links = analysis.getLinks();
for (ILink link : links) {
if (link instanceof IControlLink && (((IControlLink) link).getSource() == component
|| ((IControlLink) link).getTarget() == component)) {
.addAll(((IControlLink) link).getActions());
controlActions}
}
return controlActions;
}
ProvidingCondition of ControlAction of UCA
Use IUnsafeControlAction.getControlAction to get ControlAction of UCA.
Use ISignal.getProvidingCondition to get ProvidingCondition because IControlAction generalizes ISignal.
public String getProvidingCondition(IUnsafeControlAction uca) {
return uca.getControlAction().getProvidingCondition();
}
Get Diagrams and Presentations
Get Control Structure Diagram
public List<IControlStructureDiagram> getControlStructureDiagrams(IFacet facet) {
= facet.getRootElement(IStpaAnalysis.class);
IStpaAnalysis analysis List<IControlStructureDiagram> controlStructureDiagrams = new ArrayList<>();
for (IDiagram diagram : analysis.getDiagrams()) {
if (diagram instanceof IControlStructureDiagram) {
.add((IControlStructureDiagram) diagram);
controlStructureDiagrams}
}
return controlStructureDiagrams;
}
Get UCA Table of Control Structure Diagram
Use StampDiagramEditor to get UCA Table of Control Structure Diagram. UCA Table can be created if there is no identified one of Control Structure Diagram.
public IUCATable createOrGetUCATable(IControlStructureDiagram controlStructureDiagram, String ucaTableName)
throws ClassNotFoundException, InvalidUsingException, InvalidEditingException {
= AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory();
IDiagramEditorFactory diagramEditorFactory = diagramEditorFactory.getDiagramEditor(StampDiagramEditor.class);
StampDiagramEditor stampDiagramEditor return stampDiagramEditor.createOrGetUCATable(controlStructureDiagram, ucaTableName);
}
Get all nested component presentations in selected component presentation
Let’s get all nested component presentations from parent component in the sample control structure diagram below.
You can get nested component presentatons from parent component presentation with INodePresentation.getChildren.
public INodePresentation[] getChildrenComponentPresentation(
) throws InvalidUsingException {
IControlStructureDiagram controlStructureDiagramfor (IPresentation presentation : controlStructureDiagram.getPresentations()) {
= presentation.getModel();
IElement model if (presentation instanceof INodePresentation && model instanceof IComponent
&& "parent component".equals(((IComponent) model).getName())) {
return ((INodePresentation) presentation).getChildren();
}
}
return new INodePresentation[0];
}
Edit Models and Presentations
In order to edit models or presentations using API, you need the transaction process. Also an exception will happen if:
- The project is not registered in the project accessor or
- The edition for the API is not correct or
- target models/presentations you are trying to edit are non-editable
Edit model
Model Editor
The StampModelEditor is to used when you edit STAMP/STPA model with API.
For example, A Control Action can be created from StampModelEditor.
If you edit a model that can have multiple presentations, you can create/edit from each Model Editor.
Model Editors | Model elements you can create in the Model Editor |
---|---|
StampModelEditor | Component,Control Action,Control Link,Feedback,Feedback Link,Process Model,Process Variable,Process Value,Precondition,Accident,Hazard,Safety Constraint,UCA,Non UCA,HazardCausalFactor,Hazard Scenario |
Create Hazard with SafetyConstraint for Accident
// Transaction processing is required
public IHazard createHazard(IAccident accident, String hazardDescription) throws InvalidEditingException {
= projectAccessor.getModelEditorFactory();
IModelEditorFactory modelEditorFactory = modelEditorFactory.getModelEditor(StampModelEditor.class);
StampModelEditor stampModelEditor = projectAccessor.getFacet(IStampFacet.FACET_SYMBOLIC_NAME);
IFacet facet = facet.getRootElement(IStpaAnalysis.class);
IStpaAnalysis analysis
= stampModelEditor.createHazard(analysis,
IHazard hazard Collections.singletonList(accident), hazardDescription);
= stampModelEditor.createSafetyConstraint(analysis,
ISafetyConstraint safetyConstraint1 Collections.singletonList(hazard), "safetyConstraint1");
= stampModelEditor.createSafetyConstraint(analysis,
ISafetyConstraint safetyConstraint2 Collections.singletonList(hazard), "safetyConstraint2");
return hazard;
}
Create UCA for Control Action
Let’s create UCA1 for Control Action and Not Providing GuideWord cell in the sample UCA Table below.
This is the instance diagram.
// Transaction processing is required
public IUnsafeControlAction createUCA(IStpaAnalysis analysis) throws ClassNotFoundException, InvalidEditingException {
final ITransactionManager transactionManager = projectAccessor.getTransactionManager();
= null;
IUnsafeControlAction uca try {
.beginTransaction();
transactionManager= AstahAPI.getAstahAPI().getProjectAccessor().getModelEditorFactory();
IModelEditorFactory modelEditorFactory = modelEditorFactory.getModelEditor(StampDiagramEditor.class);
StampDiagramEditor stampDiagramEditor = stampDiagramEditor.createControlStructureDiagram(analysis, "controlStructureDiagram");
IControlStructureDiagram controlStructureDiagram
= modelEditorFactory.getModelEditor(StampModelEditor.class);
StampModelEditor stampModelEditor = stampModelEditor.createComponent(analysis, "component1");
IComponent component1 = stampModelEditor.createComponent(analysis, "component2");
IComponent component2 = stampModelEditor.createControlLink(component1, component2);
IControlLink controlLink = stampModelEditor.createControlAction(controlLink, "controlAction");
IControlAction controlAction = stampDiagramEditor.createNodePresentation(component1, createPoint2D(100.0, 100.0));
INodePresentation component1Presentation = stampDiagramEditor.createNodePresentation(component2, createPoint2D(250.0, 250.0));
INodePresentation component2Presentation = stampDiagramEditor.createLinkPresentation(controlLink, component1Presentation, component2Presentation);
ILinkPresentation controlLinkPresentation
= stampDiagramEditor.createOrGetUCATable(controlStructureDiagram, "ucaTable");
IUCATable ucaTable = analysis.getUCAGuideWords().get(0);
INamedElement guideword0 = stampModelEditor.createUnsafeControlAction(controlAction, guideword0, "UCA1");
uca .setIdentifier("UCA1-N-1");
uca.endTransaction();
transactionManager
.beginTransaction();
transactionManager.setCell(controlAction, guideword0, Collections.singletonList(uca));
ucaTable.endTransaction();
transactionManager} catch (BadTransactionException e) {
.abortTransaction();
transactionManager}
return uca;
}
private Point2D createPoint2D(double x, double y) {
Point2D location = new Point2D.Double();
.setLocation(x, y);
locationreturn location;
}
Edit Diagrams and Presentations
Get StampDiagramEditor
You will use StampDiagramEditor to create, edit and delete diagram, table and presentations.
= AstahAPI.getAstahAPI().getProjectAccessor();
ProjectAccessor projectAccessor = projectAccessor.getDiagramEditorFactory();
IDiagramEditorFactory diagramEditorFactory = diagramEditorFactory.getDiagramEditor(StampDiagramEditor.class); StampDiagramEditor diagramEditor
Create Control Loop Diagram
// Transaction processing is required
public IControlLoopDiagram createControlLoopDiagram(ILinkPresentation controlLinkPresentation)
throws ClassNotFoundException, InvalidUsingException, InvalidEditingException {
= AstahAPI.getAstahAPI().getProjectAccessor();
ProjectAccessor projectAccessor = projectAccessor.getDiagramEditorFactory();
IDiagramEditorFactory diagramEditorFactory = diagramEditorFactory.getDiagramEditor(StampDiagramEditor.class);
StampDiagramEditor diagramEditor = diagramEditor.createControlLoopDiagram(controlLinkPresentation, "test");
IControlLoopDiagram diagram return diagram;
}
Create nested component presentation
// Transaction processing is required
public INodePresentation createNestedNodePresentation(StampDiagramEditor editor, IComponent parent, IComponent child,
Point2D location) throws InvalidEditingException {
= createNodePresentation(editor, parent, location);
INodePresentation parentNodePresentation return editor.createNodePresentation(child, parentNodePresentation, location);
}
// Transaction processing is required
public INodePresentation createNodePresentation(StampDiagramEditor editor, IComponent model,
Point2D location) throws InvalidEditingException {
return editor.createNodePresentation(model, location);
}
Create Loss Scenario Table
// Transaction processing is required
public ILossScenarioTable createLossScenarioTable(IUnsafeControlAction uca)
throws ClassNotFoundException, InvalidUsingException, InvalidEditingException {
= AstahAPI.getAstahAPI().getProjectAccessor();
ProjectAccessor projectAccessor = projectAccessor.getDiagramEditorFactory();
IDiagramEditorFactory diagramEditorFactory = diagramEditorFactory.getDiagramEditor(StampDiagramEditor.class);
StampDiagramEditor diagramEditor = diagramEditor.createOrGetLossScenarioTable(uca, "lossScenarioTable");
ILossScenarioTable table return table;
}
Delete Tables
// Transaction processing is required
public void deleteUCATable(IUnsafeControlAction uca, IControlStructureDiagram controlStructureDiagram)
throws ClassNotFoundException, InvalidUsingException, InvalidEditingException {
= AstahAPI.getAstahAPI().getProjectAccessor();
ProjectAccessor projectAccessor = projectAccessor.getDiagramEditorFactory();
IDiagramEditorFactory diagramEditorFactory = diagramEditorFactory.getDiagramEditor(StampDiagramEditor.class);
StampDiagramEditor diagramEditor = diagramEditor.createOrGetUCATable(controlStructureDiagram, "ucaTable0");
IUCATable ucatable if (ucatable != null) {
.delete(ucatable);
diagramEditor}
}
Supported model / Presentation list
See Astah STAMP/STPA API Structure details: STAMP/STPA Overview in Javadoc
Supported Models in Each Diagram
Summary of supported models of each STAMP/STPA diagram. See model details:StampModelEditor.
See diagram details:StampDiagramEditor.
Diagram | Class | Related Model Structure | Get models | Create models |
---|---|---|---|---|
Control Loop Diagram | IControlLoopDiagram | Control Loop Diagram | ✓ | ✓ |
Control Structure Diagram | IControlStructureDiagram | Control Structure Diagram | ✓ | ✓ |
PreconditionTable | IPreconditionTable | PreconditionTable | ✓ | ✓ |
AccidentHazardSafetyConstraintTable | IAccidentHazardSafetyConstraintTable | AccidentHazardSafetyConstraintTable | ✓ | ✓ |
UCATable | IUCATable | UCATable | ✓ | ✓ |
LossScenarioTable | ILossScenarioTable | LossScenarioTable | ✓ | ✓ |
CountermeasureTable | ICountermeasureTable | CountermeasureTable | ✓ | ✓ |
Supported Presentations in Each Diagram
This is a list of Presentation in Astah. To find out which presentation is editable or not, please refer to the StampDiagramEditor.
Diagram | Class | DiagramEditor | INodePresentation | ILinkPresentation |
---|---|---|---|---|
Control Loop Diagram | IControlLoopDiagram | StampDiagramEditor | ✓ | ✓ |
Control Structure Diagram | IControlStructureDiagram | StampDiagramEditor | ✓ | ✓ |