Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » How to change Papyrs-rt model color programmatically?
How to change Papyrs-rt model color programmatically? [message #1714074] Mon, 09 November 2015 17:38 Go to next message
Da Mist is currently offline Da MistFriend
Messages: 9
Registered: November 2015
Junior Member
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 10:29 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 887
Registered: February 2011
Senior Member
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


Camille Letavernier
Re: How to change Papyrs-rt model color programmatically? [message #1714820 is a reply to message #1714387] Tue, 17 November 2015 00:49 Go to previous message
Da Mist is currently offline Da MistFriend
Messages: 9
Registered: November 2015
Junior Member
Hi Camille,

Thank you for your reply!
I am wondering if you could tell me how can I get the active editor or the state programmatically?

Thanks!
Previous Topic:Papyrus for Real Time v 0.7.1 is now available!
Next Topic:Combining Papyrus RT with normal Code
Goto Forum:
  


Current Time: Wed Nov 14 12:07:36 GMT 2018

Powered by FUDForum. Page generated in 0.02226 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top