« Back to AAU Project

Having default elements after creating a new model

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Hi, is it possible to create a new model (adding a new model from our model groups) which contains  default elements? because  we get usually empty models.

RE: Having default elements after creating a new model
Answer
7/31/15 10:33 AM as a reply to Fadi Al Machot.
Hi, Fadi.

You can achieve the desired behavior using the event "CreateModel", described here.
All you have to do is define an event handler for the event "CreateModel" in the library attribute "External coupling" of your library.
The event handler should look like this:
 1ON_EVENT "CreateModel"
 2{
 3    SETL nModelID: ( modelid )   
 4    CC "Core" GET_MODEL_INFO modelid: ( nModelID)
 5
 6    IF ( modeltype = "MyModelType_01") {
 7        #add standard objects
 8        CC "Core" GET_CLASS_ID classname: "MyClass_011"
 9        SETL nClass01ID: ( classid )   
10        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID )  objname: ("MyObject_011_1")
11        CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:5cm index:1"
12          
13        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID )  objname: ("MyObject_011_2")
14        CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:8cm index:1"
15      
16        # repeat for more objects of this class and/or for more classes
17
18        CC "Core" SAVE_MODEL modelid: (nModelID)
19    }
20
21    ELSIF ( modeltype = "MyModelType_02") {
22        #add standard objects
23        CC "Core" GET_CLASS_ID classname: "MyClass_21"
24        SETL nClass01ID: ( classid )   
25        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID )  objname: ("MyObject_021_1")
26        CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:5cm index:1"
27          
28        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID )  objname: ("MyObject_021_2")
29        CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:8cm index:1"
30      
31        # repeat for more objects of this class and/or for more classes
32
33        CC "Core" SAVE_MODEL modelid: (nModelID)
34    }
35    # repeat for all needed model types
36}

Of course, this piece of code may be very complex if you have many model types and many standard objects, so you could create a global procedure (called for exampe CREATE_PREDEFINED_OBJECTS), store it in a file in the application library and call it from the event handler

In this case, the event handler would look like this:
1ON_EVENT "CreateModel"
2{
3  EXECUTE file: "db:\\scripts_predefined_objects.asc"
4  CREATE_PREDEFINED_OBJECTS nModelID: ( modelid )
5}

and the definition of the procedure would be:
 1PROCEDURE global CREATE_PREDEFINED_OBJECTS nModelID: integer
 2{
 3
 4    CC "Core" GET_MODEL_INFO modelid: ( nModelID)
 5
 6    IF ( modeltype = "MyModelType_01") {
 7        #add standard objects
 8        CC "Core" GET_CLASS_ID classname: "MyClass_011"
 9        SETL nClass01ID: ( classid )   
10        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID )  objname: ("MyObject_011_1")
11        CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:5cm index:1"
12          
13        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID )  objname: ("MyObject_011_2")
14        CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:8cm index:1"
15      
16        # repeat for more objects of this class and/or for more classes
17
18        CC "Core" SAVE_MODEL modelid: (nModelID)
19    }
20
21    ELSIF ( modeltype = "MyModelType_02") {
22        #add standard objects
23        CC "Core" GET_CLASS_ID classname: "MyClass_21"
24        SETL nClass01ID: ( classid )   
25        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID )  objname: ("MyObject_021_1")
26        CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:5cm index:1"
27          
28        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID )  objname: ("MyObject_021_2")
29        CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:8cm index:1"
30      
31        # repeat for more objects of this class and/or for more classes
32
33        CC "Core" SAVE_MODEL modelid: (nModelID)
34    }
35    # repeat for all needed model types
36
37}

This second option would also enable you to read a predefined configuration for each model type from an XML-file stored in the application library or externally, at a preconfigured location, and based on each particular configuration, call a procedure that creates each object.

The parameters of the command calls CREATE_OBJECT and SET_ATTR_VAL are described in the AdoScript Documentation as well.
Hope this helps.

RE: Having default elements after creating a new model
Answer
7/31/15 10:56 AM as a reply to Sabin Popescu.
Hi Fadi, Sabin,

potentially this threads could help you as well. It relates to default models and event handling specifically using variants and views.

http://www.adoxx.org/live/faq/-/message_boards/message/110883

http://www.adoxx.org/live/faq/-/message_boards/message/110765 (incl. Variant Management Examples)

RE: Having default elements after creating a new model
Answer
8/3/15 9:50 AM as a reply to Wilfrid Utz.
Dear Wilfrid & Sabin,
thank you very much,
is it possible to change the size of the default object?
If yes would you please post an example

RE: Having default elements after creating a new model
Answer
8/3/15 11:18 AM as a reply to Fadi Al Machot.
Dear Fadi,

Could you specify what you mean by being able to change the size of the default object ?

Do you mean by that, the following scenario for example:
When a new model is created of type "Model A", an instance of class A is created as a default object. This default created one, for example, is a circle with radius 2cm. If one creates another instance of A in the model after that though the circle is smaller with only a radius 1cm.

Or is your question more generic, about how to make an object resizable or how to write Graphical Representation code defining an object's size ?

If you can clear up what you wish by maybe describing a scenario we can try and post an example.

Kind regards,

David

RE: Having default elements after creating a new model
Answer
8/3/15 2:46 PM as a reply to David Burke.
I mean when a new model is created of type "Model A", an instance of class A is created as a default object. This default created one, for example, is a circle with radius 4cm, although in graphrep, the radius could be only 2cm !

RE: Having default elements after creating a new model
Answer
8/4/15 6:42 AM as a reply to Fadi Al Machot.
Dear Fadi,

Below is a link to a library which implements both the functionality of creating default objects when a new model is created and which makes the
default object larger. In this library, there are two model types named "Modeltype AB" and "Modeltype CD". Modeltype AB contains two objects
named "A" and "B" which are circles (red and blue respectively). Modeltype CD contains two objects "C" and "D" which are squares (red and blue
respectively. When a new model is created for either of these model types, a default instance of the classes is created. Furthermore, the default
objects that are created are larger (2cm). Any instance of the classes created after that have a size of only 1cm.



This is done by using the script from Sabin's reply above and by using an attribute "Default object" which is an enumeration of either "Yes" or
"No". The full AdoScript for the creation of the default objects is

 1PROCEDURE global CREATE_PREDEFINED_OBJECTS nModelID: integer
 2{
 3
 4    CC "Core" GET_MODEL_INFO modelid: (nModelID)
 5
 6    IF ( modeltype = "Modeltype AB") {
 7        #add standard objects
 8        CC "Core" GET_CLASS_ID classname: "A"
 9        SETL nClassA: (classid)   
10        CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassA)  objname: ("A")
11        CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:5cm index:1"
12        CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"
13
14        CC "Core" GET_CLASS_ID classname: "B"
15        SETL nClassB: (classid)   
16       
17        CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassB ) objname: ("B")
18        CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:10cm index:1"
19        CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"
20      
21        # repeat for more objects of this class and/or for more classes
22
23        CC "Core" SAVE_MODEL modelid: (nModelID)
24    }
25
26    ELSIF (modeltype = "Modeltype CD") {
27        #add standard objects
28        CC "Core" GET_CLASS_ID classname: "C"
29        SETL nClassC: (classid)   
30        CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassC)  objname: ("C")
31        CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:5cm index:1"
32        CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"
33
34        CC "Core" GET_CLASS_ID classname: "D"
35        SETL nClassD: (classid)          
36
37        CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClassD )  objname: ("D")
38        CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val: "NODE x:3cm y:10cm index:1"
39        CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"
40      
41        # repeat for more objects of this class and/or for more classes
42
43        CC "Core" SAVE_MODEL modelid: (nModelID)
44    }
45    # repeat for all needed model types
46
47}


As you can see, in lines 12, 19, 32 and 39, the attribute for the created instance is set to "Yes" whereas by default it would have been set to "No". The GraphRep for the
objects then reads this attribute and if it is set to "Yes" makes it larger, and if set to "No" does not. The GraphRep, for example, for the class A is shown here and the GraphReps for B, C and D are analogous.

 1GRAPHREP
 2
 3AVAL sDef:"Default object"
 4
 5IF (sDef = "Yes")
 6SET cmRadius: (2cm)
 7ELSE
 8SET cmRadius: (1cm)
 9ENDIF
10
11FILL color:red
12ELLIPSE x: (0cm) y: (0cm) rx: (cmRadius) ry: (cmRadius)


As mentioned in the previous post, but for completeness, the calling of the script to create the default instance happens using an event "CreateModel". The code that calls the script is placed in the "External coupling" part of the library (click on "Library attributes", then go to the tab "Add-ons") and is as follows

1ON_EVENT "CreateModel"
2{
3EXECUTE file: "db:\\scripts_predefined_objects.asc"
4CREATE_PREDEFINED_OBJECTS nModelID: (modelid)
5}

 
The library itself can be downloaded here:

Create Default Elements after Model Create Library.abl

RE: Having default elements after creating a new model
Answer
8/4/15 7:18 AM as a reply to Fadi Al Machot.
Following David's comment, please keep in mind that the size of the object created relates on the characteristics defined in the GRAPHREP, more specifically on the sizing options.
In case the object is not resizeable (or does not implement the behaviour of David above), the size will always be the same. In case resizeable, using the respective sizing option (e.g sizing:asymmetrical), you can set the size of the object when created using the "Position" attribute. The "Position" attribute is a LEO string (can be parsed with the LEO commannd) and contains the x, y, w, h and index value. You can construct the Postion value and define your own sizing (in h and w) and the object would then appear accordingly.

RE: Having default elements after creating a new model
Answer
8/4/15 8:33 AM as a reply to Wilfrid Utz.
Dear Fadi,

To implement the suggestion by Wilfrid, there are two modifications that one would make to the library. This would probably be the better option, since it would take into account that the GraphRep will probably be much more complicated than a simple circle or square.

1) Firstly, to make the objects resizable the command "sizing:" is used in the GraphRep. There are three options here "symmetrical", "asymmetrical" and "keep-aspect-ratio". Hence, instead of the GraphRep code written in a previous post for A, one could simply put

1GRAPHREP
2sizing:asymmetrical
3
4SET cmRadius: (2cm)
5FILL color:red
6ELLIPSE x: (0cm) y: (0cm) rx: (cmRadius) ry: (cmRadius)


and similarly for B, C and D. The part "sizing:asymmetrical"  written in line 2 makes the GraphRep for the object resizable.

2) When we created the objects in the AdoScript written in the previous post, we wrote a string to the "Position" attibute in lines 11, 18, 31 and 38. In this case, all we would need to do is modify these lines so that they also sets the size of the object. So, for example, for line 11 it would read

1CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:5cm w:4cm h:4cm index:1"


The extra part "w:4cm h:4cmdefines the width and height of the object respectively.

As a final point, one does not need the attribute "Default object" anymore either, so this attribute can safely be removed. With these modifications, the same effect is achieved, but the method is more generic.