This page shows how you to edit models and diagram presentations by using Astah SysML API.
To learn a difference between models and presentations, please read this page.

section divider

Edit models

Transaction processing is required before you edit models.

Sample: Edit block name and its definition

  try {
      TransactionManager.beginTransaction();
      SysmlModelEditor bme = ModelEditorFactory.getSysmlModelEditor();
      // Create a block
      IBlock block0 = bme.createBlock(project, "block0");
      // Set name
      block0.setName("new block0 name");
      // Set definition
      block0.setDefinition("Definition of the block0");
      TransactionManager.endTransaction();
  } catch (InvalidEditingException e) {
      TransactionManager.abortTransaction();
  }
section divider

Edit diagram presentations

This page shows you how to edit diagram presentations by using Astah SysML API.
To learn a difference between models and presentations, please read this page.

section divider

Transaction Process

The transaction processsing is required before you start editing presentations.

Presentation API

IPresentation is a base interface of presentation. INodePresentation and ILinkPresentation are derived from IPresentation.

Name of presentation interface

Description

Presentations

INodePresentationInterface for Rectangular presentationPackage, Frame, Note, Block, Part, UseCase, State, Partition, Action, Lifeline, ConstraintProperty, Port, Requirement, TestCase, Topic, Boundary and etc.
ILinkPresentationInterface for Line presentationNest, NoteAnchor, Association, Generalization, Realization, Usage, Dependency, Connector, Extend, Include, Binding Connector, Message, Anchor, DeriveReqt, Copy, Satisfy, Verify, Refine, Trace and etc.
section divider

Edit INodePresentations

We’ll give you some sample codes for editing INodePresentations such as setting location, width, and height, adding a label and background color.

Set the location

    public void setLocation(INodePresentation ps, Point2D location) {
        try {
            TransactionManager.beginTransaction();
            ps.setLocation(location);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
    }

Set width

    public void setWidth(INodePresentation ps, double width) {
        try {
            TransactionManager.beginTransaction();
            ps.setWidth(width);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
    }

Set hight

    public void setHeight(INodePresentation ps, double height) {
        try {
            TransactionManager.beginTransaction();
            ps.setHeight(height);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
    }

Set Label

    public void setLabel(INodePresentation ps, String label) {
        try {
            TransactionManager.beginTransaction();
            ps.setLabel(label);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
    }

Set background-color

    //(EX)red:color="#FF0000" green:color="#00FF00" blue:color="#0000FF" 
    public void setColor(INodePresentation ps, String color) {
        try {
            TransactionManager.beginTransaction();
            ps.setProperty("fill.color", color);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
    }
section divider

Modify ILinkPresentations

This is an example code to modify ILinkPresentations such as Association, Dependency, Generalization, Realization, Include, Extension, Binding Connector and etc.

Set start and endpoints

    public void setPoints(ILinkPresentation ps, Point2D[] points) {
        try {
            TransactionManager.beginTransaction();
            ps.setPoints(points);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
    }