Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Create diagram programmatically(How to Create diagram programmatically ?)
Create diagram programmatically [message #1815626] Mon, 07 October 2019 12:43 Go to next message
Jean Pierre Clavery is currently offline Jean Pierre ClaveryFriend
Messages: 2
Registered: June 2019
Junior Member
Hi,

I am very new to Sirius.

I would like to know if is it possible to create a diagram programmatically and put in elements?

Thanks
Re: Create diagram programmatically [message #1815630 is a reply to message #1815626] Mon, 07 October 2019 13:34 Go to previous messageGo to next message
Emmanuel Chebbi is currently offline Emmanuel ChebbiFriend
Messages: 69
Registered: February 2018
Member
Hi,

This is possible. As far as I know the API is not documented but you can start with taking a look at the following threads:

Regards,
Emmanuel
Re: Create diagram programmatically [message #1816011 is a reply to message #1815630] Thu, 17 October 2019 08:32 Go to previous messageGo to next message
Jean Pierre Clavery is currently offline Jean Pierre ClaveryFriend
Messages: 2
Registered: June 2019
Junior Member
Thank you very much, it help me.

Now I want to insert element from my model into the diagram. I can i do this ?
Re: Create diagram programmatically [message #1819658 is a reply to message #1816011] Mon, 20 January 2020 14:21 Go to previous messageGo to next message
Emmanuel Chebbi is currently offline Emmanuel ChebbiFriend
Messages: 69
Registered: February 2018
Member
Sorry, I'm a bit late and hope you found the solution. In case someone stumble upon this thread I just posted a code snippet that shows how I managed to programmatically create a diagram for a given model here:
Re: Create diagram programmatically [message #1821021 is a reply to message #1815626] Tue, 04 February 2020 15:19 Go to previous message
Viet Dinh is currently offline Viet DinhFriend
Messages: 2
Registered: December 2019
Junior Member
Hi,
thank you for the answer and the hint to the other posts. I managed to create a session and a diagram.
However, I am stuck with one remaining thing. I want to create more than 1 representation for different objects.


What I get is that:
index.php/fa/37332/0/



My code should create a representation for "Global Context Diagram", but it does not. Why?
 


	// Add the initial model object to the contents.
	//
	EObject rootObject = createInitialModel();
					
	if (rootObject != null) {
							resource.getContents().add(rootObject);
	}

	// Save the contents of the resource to the file system.
	//
	Map<Object, Object> options = new HashMap<Object, Object>();
	options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
	resource.save(options);
						
	// create aird representation which is a session
	URI sessionResourceURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString()+".aird", true);
	Session session = SessionManager.INSTANCE.getSession(sessionResourceURI, progressMonitor);
	session.open(progressMonitor);

	// add semantic resource
	session.getTransactionalEditingDomain().getCommandStack()
				           .execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
				               @Override
				               protected void doExecute() {
				            	   SubMonitor subMonitor = SubMonitor.convert(progressMonitor);
				            	   subMonitor.setTaskName("Adding resource");
				                   SubMonitor commandMonitor = SubMonitor.convert(subMonitor);
				                   session.addSemanticResource(fileURI, commandMonitor);
				               }
				           });
						
						
						
         //select the correct Viewpoint and instantiate a representation
	UserSession userSession = UserSession.from(session);
	userSession.selectViewpoint("probframes");

for (RepresentationDescription rd: DialectManager.INSTANCE.
				getAvailableRepresentationDescriptions(ViewpointRegistry.getInstance().getViewpoints(), rootObject)) {
							DialectManager.INSTANCE.createRepresentation("GlobalCD", rootObject, rd, session, progressMonitor);
							break;
						}
						
						


update:
Strange thing here is, that dialectmanager seems not to create a representation. Everything else works . Any hints are welcome again! Thx
  • Attachment: curr.PNG
    (Size: 5.61KB, Downloaded 17 times)

[Updated on: Tue, 11 February 2020 09:42]

Report message to a moderator

Previous Topic:Selection Wizard
Next Topic:how to locate at the element in table through navigation tool from diagram
Goto Forum:
  


Current Time: Wed Feb 26 17:03:23 GMT 2020

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

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

Back to the top