Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Graphiti diagram animation
Graphiti diagram animation [message #1354736] Wed, 14 May 2014 11:52 Go to next message
Hassan BAZOUN is currently offline Hassan BAZOUNFriend
Messages: 54
Registered: April 2012
Member
Hello,

I'm working on the implementation of an animation feature for my graphiti editor.
what i need is the following:


  • Click on the animation menu item from the menu
  • The editor should change the color of a pictogram element, wait for one second and then change the color of another element until all the elements in a list changes their color.


what i had implemented until now is the following:


  • click on the animation menu item
  • The command handler responsible for the command is executed.
  • The handler will get the list of pictogram elements to be animated
  • The handler will call the function animatePictorgamElement() of the ToolbehaviorProvider
  • The handler will animate one pictogram element
  • clicking the animation menu item another time will animate the second pictogram from the list


So what is happening in this scenario is that it is animating the diagram step by step or element by element. What i needed was to animate the whole elements with one second waiting.

In order to fullfill my requirements i insered a while loop in the execute function of the handler which will run until all elements are animated. The inside the while loop and after calling the animate function of the ToolBehaviorProvider, i added a wait(1000) command.

The result was quite different than expected, the animation done by the tool behavior is applied only after the end of the while loop.

In the Handler:
@Override
	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		editor = HandlerUtil.getActiveEditor(arg0);
		service = editor.getAppService();
		List<EObject> contents = editor.getResource().getContents();
		List<Element> elements = service.animateDiagram(contents.get(1), contents.get(0));
                while(counter<elements.size()){
		  counter = Service.getCounter();
		  Service.setCounter(++counter);
		  if (counter == elements.size())
			Service.setCounter(0);
		  ((ToolBehaviorProvider) editor.getDiagramTypeProvider().getFeatureProvider().getDiagramTypeProvider().getAvailableToolBehaviorProviders()[0]).animateElement(elements, counter);
		  
                  try{
                      synchronized(this){
                       this.wait(1000);
                      }
                     }
                  catch(Exception ex){
                     
                     }
                }
		return null;
	}


In the TOOLBehavior provider, in the animateElement method the code to animate the element is in a recording command.

	TransactionalEditingDomain domain = this.getDiagramTypeProvider()
			.getDiagramEditor().getEditingDomain();
	domain.getCommandStack().execute(new RecordingCommand(domain) {

		@Override
		protected void doExecute() {
                 //code here
                }
        });


So first why it is always waiting the execute method of the handler to finish before any pictogram element's modifications are visible on the diagram?
Second question is there a way to make it work? that is to do the full animation without being obliged to do it step by step or element by element?

Thanks in advance.
HB
Re: Graphiti diagram animation [message #1354761 is a reply to message #1354736] Wed, 14 May 2014 12:09 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
First of all, I dont think, that you need to put your animation code on the command stack, but I think if you put your animation code in another Thread, it should work as expected.

[Updated on: Wed, 14 May 2014 12:09]

Report message to a moderator

Re: Graphiti diagram animation [message #1354803 is a reply to message #1354761] Wed, 14 May 2014 12:34 Go to previous messageGo to next message
Hassan BAZOUN is currently offline Hassan BAZOUNFriend
Messages: 54
Registered: April 2012
Member
Well i need to put my code in the command stack otherwise i can not change the color of the picotgram element since it will be an illegal write transaction.

HB
Re: Graphiti diagram animation [message #1354856 is a reply to message #1354803] Wed, 14 May 2014 13:05 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
hmmm, I thinkn thats only necessary, if you make changes to your model itself... the PE's shouldn't be affected.
Re: Graphiti diagram animation [message #1354891 is a reply to message #1354856] Wed, 14 May 2014 13:22 Go to previous messageGo to next message
Hassan BAZOUN is currently offline Hassan BAZOUNFriend
Messages: 54
Registered: April 2012
Member
this is the error i got if not using the command stack

Quote:

Caused by: java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.graphiti.mm.algorithms.impl.GraphicsAlgorithmImpl.setStyle(GraphicsAlgorithmImpl.java:874)


the error is fired when trying to set the style of the pictogram element

HB
Re: Graphiti diagram animation [message #1354910 is a reply to message #1354891] Wed, 14 May 2014 13:30 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi,

first, Graphiti is not good for writing animations, because this is simply
not in the main focus.

Second, every change to the EMF model - be it a change to the domain model
or the graphical representation model - must be wrapped into an EMF
transaction otherwise you will see this exception.

You might try to trigger an explicit editor refresh after each of your
animation steps. Probably you will have to do one animation step in one
transaction then call DiagramEditor.refresh. Not sure if that finally works,
but I'd guess it is the only way you might achive this.

Michael
Re: Graphiti diagram animation [message #1354939 is a reply to message #1354910] Wed, 14 May 2014 13:49 Go to previous messageGo to next message
Hassan BAZOUN is currently offline Hassan BAZOUNFriend
Messages: 54
Registered: April 2012
Member
Hi Michael,

The refresh is not working i still have the same issue.
Thank you for your comment.

HB
Re: Graphiti diagram animation [message #1355098 is a reply to message #1354939] Wed, 14 May 2014 15:19 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
I just realised, that you have a
                  try{
                      synchronized(this){
                       this.wait(1000);
                      }
                     }
                  catch(Exception ex){
                     
                     }


in your code, if I remember correctly, you delay the Thread you are actually working on and thats not what you want. Thats the Thread for your Editor and that is the reason why its displayed at the and of your loop.
Have you ever tested it with a Thread and then sth. like Thread.sleep?

thread_ = new Thread() {
   @Override
   public void run() {
      Loop {
          Thread.sleep(1000);
      }
   }
}.start();

[Updated on: Wed, 14 May 2014 15:22]

Report message to a moderator

Re: Graphiti diagram animation [message #1355136 is a reply to message #1355098] Wed, 14 May 2014 15:40 Go to previous messageGo to next message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 181
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
That kind of "animation" should not normally be done in the EMF space; that's for structural changes to the diagram/model, that you want to be persisted when you save the editor.
For ephemeral run-time only changes, Graphiti has decorators (image, colours and borders). It's possible to change dynamically the foreground/background colours of shapes (and soon of foreground colours of connections) by providing Color decorators in the ToolBehaviourProvider.

(See an example of here, third video).

[Updated on: Wed, 14 May 2014 15:46]

Report message to a moderator

Re: Graphiti diagram animation [message #1355175 is a reply to message #1355136] Wed, 14 May 2014 15:56 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
Do you have a small code example? Because I think my simulation is very similiar to Hassan's and my next thought was to delete it from the undo-stack. I've never read something like what you are talking about.
Re: Graphiti diagram animation [message #1355184 is a reply to message #1355136] Wed, 14 May 2014 16:03 Go to previous messageGo to next message
Hassan BAZOUN is currently offline Hassan BAZOUNFriend
Messages: 54
Registered: April 2012
Member
@Soeren i had tried using the thread before but it didn't work
@Hemran can you elaborate more on your idea?

Thanks
HB
Re: Graphiti diagram animation [message #1355291 is a reply to message #1355184] Wed, 14 May 2014 17:05 Go to previous messageGo to next message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 181
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
Should be as simple as

 // in your xToolBehaviorProvider
 public IDecorator[] getDecorators(PictogramElement pe) {
  List<IDecorator> decorators = new ArrayList<IDecorator>();
  EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
 ... (deduce color of object, from some state/properties ; not stored inside the PE or the BO, but somewhere else)
  if(shouldColorObject) {
     // set change background color (color should not be hardcoded here)
     decorators.add(new ColorDecorator(null, new ColorConstant(250, 250, 120))); 
  }
  return decorators.isEmpty() ? super.getDecorators(pe) : decorators.toArray(new IDecorator[decorators.size()]);
 }


.. in your handler code:

   ... (update the "state" of your objects)
   getEDitor().getDiagramBehavior().refresh();
Re: Graphiti diagram animation [message #1358066 is a reply to message #1355291] Thu, 15 May 2014 20:30 Go to previous message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
Tyvm, the funny part, I am working with PLCs as well Very Happy
Previous Topic:Default Context Menu Choices not working
Next Topic:CompositeShape Area Selection
Goto Forum:
  


Current Time: Sat Dec 20 23:03:24 GMT 2014

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

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