How to change Papyrs-rt model color programmatically? [message #1714074] |
Mon, 09 November 2015 12:38  |
Eclipse User |
|
|
|
Hi,
I am new here. I started using papyrus rt and the development environment for papyrus RT in eclipse mars. So when I run papyrus rt development environment , it creates an instance where I can view papyrus rt model. But now I want to change the model (states) color or shape in the instance level programmatically. Right now I am trying to write a plug in which will have a button, and in the instance when user will click the button it should change the color of the model. I know the exact name of the state (i,e capsule name _ state name). So using this name I want to change the color in the model. Till now I couldn't find any appropriate way to do this. I'll be grateful if anyone can help me in this regard. Thanks!
|
|
|
Re: How to change Papyrs-rt model color programmatically? [message #1714387 is a reply to message #1714074] |
Thu, 12 November 2015 05:29   |
Eclipse User |
|
|
|
Hi,
There are basically two options for modifying the appearance of nodes in Papyrus (Not specific to Papyrus-RT):
1) Change the Notation model directly
2) Use a CSS Stylesheet and apply it to your project, model or diagram
For the first option, you need to:
- Find the Notation View associated to your UML Element. Usually, it is the first view (Shape, or Connector...) with a reference to your element (e.g. <Shape element="model.uml#yourElementID" ... />)
- Use the View#setFillColor(int) method to change the color
The pseudo-code looks like:
State myState = ...;
Shape stateRepresenation = findView(myState);
stateRepresentation.setFillColor(123456); //The color is a 24-bits integer representing the RGB code
Note that you need to start a transaction before being able to modify a Papyrus model; otherwise the change will be rejected. This can be achieved by executing a Command on the model's CommandStack
For the second option, you need to:
- Create a *.css text file which will contain the rules to change the colors
- Generate some rules matching the following pattern inside this *.css file:
State[name="MyState"]{
fillColor: red;
}
State[name="MyOtherState"]{
fillColor: rgb(125, 255, 32);
}
Then apply this stylesheet to your project, model or diagram
Please feel free to ask if you need additional information for these steps
HTH,
Camille
|
|
|
|
Powered by
FUDForum. Page generated in 0.02706 seconds