« Back

Simplified Modelling - Object Creation

Combination View Flat View Tree View
Threads [ Previous | Next ]
Simplified Modelling - Object Creation
external coupling scenario documentation modeltype graphrep visualisation adoscript
Answer
3/27/14 9:01 AM
This package provides an implementation of a mechanism which creates new objects in the actual model. The new object's position on the drawing area depends on the number of already existing objects in the model.


Clicking the plus-button 23 times results in:





Downloads

The files below contain an example library (Graph re-writing.abl) and an example model (Graph re-writing demo model.adl). A step-by-step configuration guide is presented in the Hands-On section below. It completely describes how to build this example library and contains the code of the mechanism.

Graph re-writing.abl
Graph re-writing demo model.adl


Description of the Mechanism



Functionality provided by ADOxx



ADOxx Realisation Approach


  1. Pressing the Add-Button (c.f. buttons on the drawing area) triggers the mechanism
  2. Get all object IDs of already existing objects in the model.
  3. Create new object
  4. Re-positioning of new object depending on the number of existing objects according 2.

Used Modeling Language for Demonstration of the Mechanism
  • modeltype: Graph re-writing Sample
  • classes: __ModelTypeMetaData__, A
  • attributes: Add Object Button GraphRep (Longstring), _AddObject_ (Programcall).

Hands-On


1) Preparations

Definition of before mentioned classes & attributes for the sake of a minimal working example. This step can be skipped – import Graph re-writing.abl instead.

a) Define new classes A, __ModelTypeMetaData__


  • Go to the Library management, select a dynamic library and click Class hierarchy.
  • Click View and select Metamodel.
  • Select __D-construct__ (Metamodel)
  • Click New --> New class; name it A
  • Click New --> New class; name it  __ModelTypeMetaData__
b) Configure GraphRep for class A


  • Go to class A
  • Double click GraphRep (Metamodel)
  • Click the Dialog button
  • Enter the following code:
1GRAPHREP
2SHADOW off
3FILL color:blue
4ELLIPSE x:0.00cm y:0cm rx:1cm ry:1cm
5ATTR "Name" x:0.00cm y:1.0cm w:c

c) Add new attributes to class __ModelTypeMetaData__


  • Select class __ModelTypeMetaData__
  • Click New --> New attribute...
  • Name new attributes and select type according figure above: (1) name: Add Object Button Graphrep, type: Longstring (2) name: _AddObject_, type: Programcall.
d) Configure Add Object Button GraphRep attribute


  • Double click Add Object Button GraphRep attribute, set Standard value to:
1GRAPHREP layer:-3
2IF (_outdevtype = "drawingarea") {
3SET addIcon:"db:\\btn_add.png"
4BITMAPINFO (addIcon)
5BITMAP (addIcon) x:1cm y:0.5cm w:1.5cm h:1.5cm
6HOTSPOT "_AddObject_" text:"Add Object" x:1cm y:0.5cm w:1.5cm h:1.5cm
7}
  • Make sure that the file btn_add.png is contained in the database (close the Library management and go to Extras à File management…).
e) Configure _AddObject_ attribute (Programcall)


  • Select class __ModelTypeMetaData__
  • Double click _AddObject_ attribute
  • Set standard value to: Add Object
  • Click Facets and set EnumerationDomain to:
1ITEM "Add Object"
2EXECUTE file: ("db:\\add_object.asc")

f) Definine Modeltypes



  • Go back to the Library management and select your current Dynamic Library.
  • Click Library attributes… -->  Add-ons and define the following model type according the figure above:
1MODELTYPE "Graph re-writing Sample" from:none plural:"Graph re-writing Samples" pos:0 not-simulateable bitmap:"db:\\sample.bmp" graphrep: "Add Object Button GraphRep"
2INCL "A"

2) Implementation of Mechanism with AdoScript


 1# get ID of actual model:
 2CC "Modeling" GET_ACT_MODEL
 3SET id_modelID: ( modelid )
 4SET s_ClassName: "A"
 5# get classID for class A:
 6CC "Core" GET_CLASS_ID classname: (s_ClassName) bp-library
 7SET id_ClassID: ( classid )
 8# get all objects of class A in actual model:
 9CC "Core" GET_ALL_OBJS_OF_CLASSNAME modelid: (id_modelID) classname: (s_ClassName)
10SET s_listOfAllObjects: ( objids )
11# define coordinates for new object:
12SET n_existingObjects: (tokcnt ( s_listOfAllObjects , " ") )
13SET n_existingLinesOfObjects: ( floor (n_existingObjects/5))
14SET n_existingColumnsOfObjects: ( n_existingObjects -  n_existingLinesOfObjects*5)
15SET cm_xpos: ( 3.0cm + n_existingColumnsOfObjects*3.5cm)
16SET cm_ypos: (4.0cm + n_existingLinesOfObjects*3.5cm)
17# define name of new object:
18SET s_newObjectName: (s_ClassName + "_" + ( STR (n_existingObjects + 1)))
19# create new object:
20CC "Core" CREATE_OBJ modelid: (id_modelID) classid: ( id_ClassID ) objname: (s_newObjectName)
21SET createdObject: ( objid )
22# draw new object using coordinates from above:
23CC "Modeling" SET_OBJ_POS objid: ( createdObject ) x: (cm_xpos) y: (cm_ypos)
24# save changes in actual model:
25CC "Modeling" SAVE modelid: (id_modelID)