Create SysML Internal Block Diagram using Open API

The SysML internal block diagram use to model the decomposition of a block or its internal structure. In internal block diagram a block can be decompose into parts or subsystems. This article will show you how to create internal block diagram using Open API.

This is the internal block diagram we are going to create.

Create Blank Internal Block Diagram

The internal block diagram is for model the internal structure of a block element. Before create this diagram we first have to create a block element.

// Create parent block for the diagram
ISysMLBlock blkPowerSubsystem = IModelElementFactory.instance().createSysMLBlock();
blkPowerSubsystem.setName("PowerSubsystem");

After that we can create an internal block diagram using the DiagramManager.createDiagram() operation to create a blank diagram, and associate it as the sub-diagram of the block element.

// Create internal block diagram and make it as child (sub-diagram) of the PowerSubsystem block
DiagramManager diagramManager = ApplicationManager.instance().getDiagramManager();
IInternalBlockDiagramUIModel diagram = (IInternalBlockDiagramUIModel) diagramManager.createDiagram(IDiagramTypeConstants.DIAGRAM_TYPE_INTERNAL_BLOCK_DIAGRAM);
diagram.setName("Fuel Distribution Details");		
blkPowerSubsystem.addSubDiagram(diagram);

Create Block Elements

Now we can start creating the details of the diagram. First we create the other block elements which will used as the types for the Part Property.

// Create blocks FuelTankAssy, Fuel, FuelPump, InternalCombustionEngine, 
// FuelInjector, FuelRail and FuelFegulator
ISysMLBlock blkFuelTankAssy = IModelElementFactory.instance().createSysMLBlock();
blkFuelTankAssy.setName("FuelTankAssy");

Create Part Properties

Next we create the part property. The undelying model type for part property is IAttribute. We can use the createAttribute() operation from the parent block element to create attribute.

// Create part property for FuelTankAssy under PowerSubsystem
IAttribute attrFuelTankAssy = blkPowerSubsystem.createAttribute();
attrFuelTankAssy.setName("ft");
attrFuelTankAssy.setType(blkFuelTankAssy);

Once the attribute model is created we can then create its shape. When present attribute as part property in diagram we have to use the DiagramManager.createDiagramElement(%diagram%,%ShapeType%) operation, and then manually specify its model element later on using the setModelElement operation.

// Create diagram element for FuelTankAssy
ISysMLPropertyUIModel partFuelTankAssy = (ISysMLPropertyUIModel) diagramManager.createDiagramElement(diagram, IShapeTypeConstants.SHAPE_TYPE_SYS_ML_PROPERTY);
partFuelTankAssy.setModelElement(attrFuelTankAssy);
partFuelTankAssy.setBounds(100, 400, 350, 130);
partFuelTankAssy.setRequestResetCaption(true);

Create Port for Part Properties

Once the part property is done we can then create their ports. We can create the port model by calling IAttribute.createSysMLFlowPort operation. One the port is created we can specify its name, type and direction (in/out/inout).

// Create two out port on FuelTankAssy
ISysMLFlowPort fuelTankAssyOutPortModel1 = attrFuelTankAssy.createSysMLFlowPort();
fuelTankAssyOutPortModel1.setName("p1");
fuelTankAssyOutPortModel1.setType(blkFuel);
fuelTankAssyOutPortModel1.setDirection(ISysMLFlowPort.DIRECTION_OUT);

After that we can visualize it on diagram by create the ISysMLFlowPortUIModel.

// Create diagram element for the two outgoing port on FuelTankAssy
ISysMLFlowPortUIModel fuelTankAssyOutPortShape1 = (ISysMLFlowPortUIModel) diagramManager.createDiagramElement(diagram, fuelTankAssyOutPortModel1);
partFuelTankAssy.addChild(fuelTankAssyOutPortShape1);
fuelTankAssyOutPortShape1.setBounds(445, 465, 15, 15);
fuelTankAssyOutPortShape1.setRequestResetCaption(true);

Create Connector between Ports

When the part property and ports are ready we can then create connectors between them. We use the IModelElementFactory.createConnector operation to create the connector model, and then specify its from/to model element. After that we use the diagramManager.createConnector operation to visualize it on diagram.

// Create connector between outgoing port of FuelPump and FuelTankAssy
IConnector connectorFuelPumpFuelTankAssy = IModelElementFactory.instance().createConnector();
connectorFuelPumpFuelTankAssy.setFrom(fuelPumpOutPortModel);
connectorFuelPumpFuelTankAssy.setTo(fuelTankAssyOutPortModel1);		
diagramManager.createConnector(diagram, connectorFuelPumpFuelTankAssy, fuelPumpOutPortShape, 
                fuelTankAssyOutPortShape1, new Point[] {new Point(380,472), new Point(445,472)} );

Create Item Flow

Finally we create the item flow on the connector. Before create the item flow we first have to create an attribute to the block element at from end of the connector. i.e. for the connector between port P1 and fuelFitting, we have to create the attribute on the parent block of port P1, which is FuelTankAssy. Again, we use the create attribute operation to create new attribute on FuelTankAssy block.

// Create attribute on FuelTankAssy for Item Flow
IAttribute attrFuelSupply = blkFuelTankAssy.createAttribute();
attrFuelSupply.setName("fuelSupply");
attrFuelSupply.setType(blkFuel);

Next we create the item flow model element from connector using IConnector.createSysMLItemFlow operation. Once the item flow is created we can specify the attribute we just created its ItemProperty and specify its direction using setRevere to true/false.

// Create Item Flow from FuelTankAssy Port 1 to Inout port of Engine		
ISysMLItemFlow itemFlow = connectorFuelTankAssyPort1Engine.createSysMLItemFlow();
itemFlow.setItemProperty(attrFuelSupply);

When the item flow model is ready we then visualize it on diagram. Please note that since the item flow is attached to connector, we have to set it as child element of the connector, and we need to set it with a bigger bound in order to visualize it correctly on diagram.

ISysMLItemFlowUIModel itemFlowShape = (ISysMLItemFlowUIModel) diagramManager.createDiagramElement(diagram, itemFlow);
connectorFuelTankAssyPort1EngineShape.addChild(itemFlowShape);
itemFlowShape.setBounds(510, 447, 50, 50);
itemFlowShape.setRequestResetCaption(true);

Now it’s your turn to create other blocks, part property, ports, connectors and item flows.

Show Up the Diagram

When everything is ready we can show up the diagram.

diagramManager.openDiagram(diagram);

Sample Plugin

The sample plugin attached in this article demonstrate how to create internal block diagram using Open API. After you deploy the plugin into Visual Paradigm you can then click the plugin button in the application toolbar to trigger it.

Trigger sample plugin

Download Sample Plugin

You can click this link to download the sample plugin.

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply