How can I design a link in EMF - eclipse-emf

I have an EMF model like the next one:
HardwareVerification -1-*-> Driver
HardwareVerification -0-*-> Environment
Environment -1-1-> Driver
Every time I create a instance of the EMF model I have to create a Driver in the environment and, another in the HardwareVerification, but what I need is to have the same Driver in both places.
For example:
h1 -> driver 1
h1 -> env1
env1 -> driver1
My question is: How should I model this?
* I read that to manage links in EMF you can use another EClass with the source and target attribute.

EReferences can be modeled as containment or non containment references. If you use non containment references, then you can refer to the same object that is contained in the model somewhere else.
Assuming that the Environment "owns" the driver, then that would be the containment reference.
And the HardwareVerification would only "use" the driver, then that would be the non containment reference. a textual "UML" diagram could look like this (the < x > denotes the containment and the <> the non containment reference.
env1 <x>-----> driver1
^
|
h1 <>--------------

I believe the link you are talking about is the EReference.
When you adding an EReference to an EClass in ecore file, you can specify the cardinality by using the Lower Bound and Upper Bound property of the EReference.
In your case, you can set LowerBound = 1, UpperBound = -1 (infinite) to represent -1-*->

Related

EMF error : the attribute "XYZ.Attribute_name" is not transient o it must have a data type that is serializable

I am creating an ECore model. I created an EClass and inside it I want to create a data member that is a list. So I created an EAttribute of type EEList.
However when I try to create the genmodel file I get an error saying
the attribute "XYZ.Attribute_name" is not transient o it must have a data type that is serializable.
It also gives a warning saying
The generic type associated with the 'EEList' classifier should have 1 type atrgument(s) to match the number of type parameter(s) of the classifier.
Can anyone tell me what I'm doing wrong? I could not figure out how to set the E in EEList<E>.
First error
The first error probably disappears after you've fix the second error. I write an explanation here, but you probably don't have to deal with it to solve you problem.
It is because, to be saved to disk, the EDataTypes of attributes must be convertible to a text format.
There are two ways to ensure this:
Implement conversion to and from strings for the used EDataType. Standard EMF EDataTypes already do this, but if you have created your own EDataType you have to do it manually.
Use a Java type for the EDataType that is serializable. It must thus implement the Serializable interface and provide serializating operations. Many standard Java classes, such as String and Integer already do that.
Another solution is to set the Transient property of the attribute to true. The the attribute will not be saved and its EDataType does not need to be serialized.
Second error
The normal way to create a list attribute is to set the Upper Bound property of the attribute to a value different from 1. To create a list attribute which can contain any number of elements, set Upper Bound to -1, which means Unbounded.
The EAttribute Type should be set to the element type, not to a list type.
The generated Java code will contain a property with the type EList<ElementType>.

Group custom attributes to nodes in Maya

I am writing a Maya plugin in c++, and have a custom MPxLocatorNode.I have added numerous custom attributes to this node with:
MFnNumericAttribute nAttr;
Attrib1 = nAttr.create( "Attribute1", "att1", MFnNumericData::kInt,1.0 );
nAttr.setKeyable(false);
nAttr.setStorable(true);
nAttr.setReadable(true);
nAttr.setWritable(true);
nAttr.setHidden(false);
addAttribute( unitId );
Attrib2 = nAttr.create( "Attribute2", "att2", MFnNumericData::kInt,1.0 );
nAttr.setKeyable(false);
...
However I need to add plenty of these attributes and would therefore like to group them when displayed in the attribute editor. Is there a way to dynamically create groups or separators ?
I am a bit confused by the word grouping, but I'll answer the 2 grouping options.
The first one is to group attributes as a compound. A good example of a compound is a point compound. In short you got a point attribute which owns 3 double attributes. So the x, y, z coordinates are grouped under the Point attribute. If now you go in the Channel Editor, you'll see the grouping effect. In the Attribute Editor and for known / predefined types, controls will be assigned automatically, doing some grouping as well.
Now, and because you mentioned the Attribute Panel, I think you are more interested on how you teach the Attribute Editor to have a different layout than the default one. If you create an AE<my custom node name>Template.mel file, with a function of the same name in it, then you can take control on how the layout is done and group, show, hide, change controls of each individual attributes.
For example I got a custom node which you can download from here. Since it is Python and MEL, you can get the full source code from there.
The node name is adskMathNode.
So I created a AEadskMathNodeTemplate.mel file.
This file contains a function declare like this:
global proc AEasdkMathNodeTemplate (string $nodeName) {
editorTemplate -beginScrollLayout ;
...
}
This is where you describe the new layout.
You'll get plenty of bigger example in the Maya folder at
/scripts/AETemplates

Even with copy.deepcopy(django.model), _meta options are shared

I have several tables with exactly the same structure (columns) but different elements (rows). These tables are spatial grids and each table defines a zooming level, therefore it's not necessary to write a model for each one (at least that's what I thought). My approach was to change the attribute ._meta.db_table to the table I need to do my stuff.
The problem is that if I instantiate an object M, say for level 1 (i.e. M._meta.db_table == "table-level-1"), and then instantiate another object N, say for level 2 (i.e. N._meta.db_table == "table-level-2") that same attribute in object M will change as well. Even if I use a deep copy of it!
Do you have any idea how to fix this?
I'm not sure I understand exactly what you've done, but here's how I would implement multiple models with the same structure.
class MyBase(models.Model):
foo = models.Integer()
# and so on
class Meta:
abstract = True
class MySubOne(MyBase):
pass
class MySubTwo(MyBase):
pass
By setting abstract=True on the base model, Django won't create a table for that model. But it will create a table for each of the models that inherits from it. More info: https://docs.djangoproject.com/en/1.7/topics/db/models/#abstract-base-classes

How to hide the symbol number on PowerDesigner?

In Sybase PowerDesigner, when designing an UML diagram that takes 2 copies/instances of the same XXXX object (ie. objects), the application adds a number identifier like "XXXX : 2" to that symbol.
Is it possible to remove it?
Thanks in advance!
It does not seem to be directly doable.
However, (somewhat tested with 16.0), you can add an Extension to your model, define a computed attribute (type String) on your object type, returning the object name:
%Get% = obj.name
and use Tools > Display Preferences > xxx > Advanced to modify the symbol contents, and use your computed attribute instead of Name...
V 16.5
You can do that:
Select the Relationship
Right Click - Format...
Click on the Content tab
Go to the Center Section
Uncheck Name, keep Stereotype checked

What is a good design pattern to implement a dynamic data importer tool?

We are planning to build a dynamic data import tool. Basically taking information on one end in a specified format (access, excel, csv) and upload it into an web service.
The situation is that we do not know the export field names, so the application will need to be able to see the wsdl definition and map to the valid entries in the other end.
In the import section we can define most of the fields, but usually they have a few that are custom. Which I see no problem with that.
I just wonder if there is a design pattern that will fit this type of application or help with the development of it.
I am not sure where the complexity is in your application, so I will just give an example of how I have used patterns for importing data of different formats. I created a factory which takes file format as argument and returns a parser for particular file format. Then I use the builder pattern. The parser is provided with a builder which the parser calls as it is parsing the file to construct desired data objects in application.
// In this example file format describes a house (complex data object)
AbstractReader reader = factory.createReader("name of file format");
AbstractBuilder builder = new HouseBuilder(list_of_houses);
reader.import(text_stream, builder);
// now the list_of_houses should contain an extra house
// as defined in the text_stream
I would say the Adaptor Pattern, as you are "adapting" the data from a file to an object, like the SqlDataDataAdapter does it from a Sql table to a DataTable
have a different Adaptor for each file type/format? example SqlDataAdptor, MySqlDataAdapter, they handle the same commands but different datasources, to achive the same output DataTable
Adaptor pattern
HTH
Bones
Probably Bridge could fit, since you have to deal with different file formats.
And Façade to simplify the usage. Handle my reply with care, I'm just learning design patterns :)
You will probably also need Abstract Factory and Command patterns.
If the data doesn't match the input format you will probably need to transform it somehow.
That's where the command pattern come in. Because the formats are dynamic, you will need to base the commands you generate off of the input. That's where Abstract factory is useful.
Our situation is that we need to import parametric shapes from competitors files. The layout of their screen and data fields are similar but different enough so that there is a conversion process. In addition we have over a half dozen competitor and maintenance would be a nightmare if done through code only. Since most of them use tables to store their parameters for their shapes we wrote a general purpose collection of objects to convert X into Y.
In my CAD/CAM application the file import is a Command. However the conversion magic is done by a Ruleset via the following steps.
Import the data into a table. The field names are pulled in as well depending on the format.
We pass the table to a RuleSet. I will explain the structure the ruleset in a minute.
The Ruleset transform the data into a new set of objects (or tables) which we retrieve
We pass the result to the rest of the software.
A RuleSet is comprise of set of Rules. A Rule can contain another Rule. A rule has a CONDITION that it tests, and a MAP TABLE.
The MAP TABLE maps the incoming field with a field (or property) in the result. There are can be one mapping or a multitude. The mapping doesn't have to involve just poking the input value into a output field. We have a syntax for calculation and string concatenation as well.
This syntax is also used in the Condition and can incorporate multiple files like ([INFIELD1] & "-" & [INFIELD2])="A-B" or [DIM1] + [DIM2] > 10. Anything between the brackets is substituted with a incoming field.
Rules can contain other Rules. The way this works is that in order for a sub Rule mapping to apply both it's condition and those of it's parent (or parents) have to be true. If a subRule has a mapping that conflicts with a parent's mapping then the subRule Mapping applies.
If two Rules on the same level have condition that are true and have conflicting mapping then the rule with the higher index (or lower on the list if you are looking at tree view) will have it's mapping apply.
Nested Rules is equivalent to ANDs while rules on the same level are equivalent of ORs.
The result is a mapping table that is applied to the incoming data to transform it to the needed output.
It is amicable to be being displayed in a UI. Namely a Treeview showing the rules hierarchy and a side panel showing the mapping table and conditions of the rule. Just as importantly you can create wizards that automate common rule structures.