This service is archived, please use www.eclipse.org/forums


Home » Capella » Capella Studio » How to change components appearance from viewpoint (I'm trying to programatically change the background color of existing Capella elements)
How to change components appearance from viewpoint [message #3503] Tue, 03 September 2019 05:29 Go to next message
MehdiBelatrous is currently offline  MehdiBelatrous
Messages: 8
Registered: July 2019
Location: Erlangen
Junior Member
Hello everyone,

I'm currently trying to create a viewpoint that will change some existing components background color based on some conditions and I'm not sure what would be the best approach. As far as possible, I would like this operation to be a kind of "background" task permanently running, so it seems to be that some sort of listener would fit the need, maybe a ResourceSetListener as suggested in this post https://polarsys.org/forums/index.php/t/584/

First I went through basic viewpoints code (price, mass, perf) but I dont want to add an extension to existing elements, just read their PVMT values and change background color according to value. Moreover, from what I pulled from Git I did not get any services.vptext file, though the whole viewpoints logic is in their, so I was not able to debug as much as I would have like.

Second approach, I added my logic in a service rule, so that I can run it on demand. However I did not succeed to modify the appearence of components and the more I dig in Capella and EMF code the more I get confused. Below is what I've tried to so far :


EObject eObject = (EObject) selection[0];
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(eObject);
Session session = SessionManager.INSTANCE.getSession(eObject);
for (DRepresentationDescriptor descriptor : DialectManager.INSTANCE.getAllRepresentationDescriptors(session)){
	DDiagram diagram = (DDiagram) descriptor.getRepresentation();
	for(final DDiagramElement element : diagram.getDiagramElements()){
		EObject elemTarget =  element.getTarget();
		if(elemTarget instanceof LogicalComponentImpl){
                     final SquareSpec sSpec = (SquareSpec) element.getStyle();
                     final RGBValues color = RGBValues.create(255,0, 0);
                     ExecutionManager manager = TransactionHelper.getExecutionManager(element);
                     manager.execute(new AbstractReadWriteCommand(){
		         @Override
		         public void run() {
				sSpec.setColor(color);
		        }
	         });
 
                }
	    }
	}
}


But the components are never updated. This code is inspired from : https://polarsys.org/forums/index.php/m/2521/
It seems to me that I'm definetly not editing the good element.
In addition I've also tried to use
 domain.getCommandStack().execute(new RecordingCommand(domain) ... ) 
and was also wondering what was the "good" approach. So, what would be the correct approach to edit component background color and where I can find relevant documentation ? (Sirus, Kitalpha, EMF, Capella ?)

Thanks in advance for any help !

[Updated on: Tue, 03 September 2019 05:33]

Report message to a moderator

Re: How to change components appearance from viewpoint [message #3508 is a reply to message #3503] Wed, 04 September 2019 09:12 Go to previous messageGo to next message
MehdiBelatrous is currently offline  MehdiBelatrous
Messages: 8
Registered: July 2019
Location: Erlangen
Junior Member
I finally succeeded to do what I wanted. Below is the code I used if it can be of any help. I did not notice any behavior difference between
 domain.commandStack 
and
 manager.execute(new AbstractReadWriteCommand)
so I don't know what should be prefered.

EObject eObject = (EObject) selection[0];
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(eObject);
Session session = SessionManager.INSTANCE.getSession(eObject);
for (DRepresentationDescriptor descriptor : DialectManager.INSTANCE.getAllRepresentationDescriptors(session)){
	DDiagram diagram = (DDiagram) descriptor.getRepresentation();
	for(final DDiagramElement element : diagram.getDiagramElements()){
		EObject elemTarget =  element.getTarget();
		if (elemTarget instanceof PartImpl){
						final FlatContainerStyle fcStyle = (FlatContainerStyle) style ;
						final RGBValues bgColor = RGBValues.create(255, 0, 0);
						ExecutionManager manager = TransactionHelper.getExecutionManager(element);
						manager.execute(new AbstractReadWriteCommand(){
							@Override
							public void run() {
								fcStyle.setBackgroundColor(bgColor);
								fcStyle.setForegroundColor(bgColor);
							}
						}
					);
	    }
	}
}
Re: How to change components appearance from viewpoint [message #3667 is a reply to message #3508] Wed, 13 November 2019 13:00 Go to previous messageGo to next message
marc.saguer.fr.thalesgrou is currently offline  marc.saguer.fr.thalesgrou
Messages: 4
Registered: November 2019
Junior Member
Hi Mehdi,

Did you already hear about PVMT(Property Value Management Tool) and DiagramStyler? The first one is used to define a PV metamodel and apply it on elements depending on scopes. The second one change the element style in sirius diagram depending on PV values.
You can have a look to help you: https://gitlab.thalesdigital.io/capella-addons.

Best regards,

Marc
Re: How to change components appearance from viewpoint [message #3672 is a reply to message #3667] Thu, 14 November 2019 09:28 Go to previous message
MehdiBelatrous is currently offline  MehdiBelatrous
Messages: 8
Registered: July 2019
Location: Erlangen
Junior Member
Hello Marc,

I'm well aware of PVMT but style customizations features are not wide enough for my needs. I ended up using a custom .odesign for this project.

Best regards.
Previous Topic: adding external jars in VP
Next Topic: Proxy Settings
Goto Forum:
  


Current Time: Mon Mar 30 16:39:14 EST 2020

Total time taken to generate the page: 0.01678 seconds