Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Blocks with defined inputs and ouptuts
Blocks with defined inputs and ouptuts [message #549624] Tue, 27 July 2010 11:59 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

I've already asked a similar question on the EuGENia forum but what I'm looking for is unfortunately impossible to do with EuGENia. For more info, here is my original post: http://www.eclipse.org/forums/index.php?t=msg&th=172439& amp;start=0&

Let me re-explain what I'm trying to achieve. I would like to be able to create blocks on my diagram. These blocks have a certain number of input and output ports (very similar as an electronic logic diagram, like memory blocks/CPU, ...). I have several different block types which all inherit from the same EClass block.
Each of these blocks have a predefined number of input and output (and those also have a specific name), still very similar as a logic diagram.

I am currently able to create blocks with no input/output and then create inputs/outputs inside the block later, but what I would like is that the block already contains all inputs and outputs when it is created (which are impossible to delete from the block).

As a reference, here is the code of my model, which is only showing one specific block (written with Emfatic):
@namespace(uri="http://www.fmtc.be/savarch/PLCOpenEditor", prefix="PLCOpenEditor")
package PLCOpenEditor;

class Model {
   val PLCOpenBlock[*] blocks;
   val Connector[*] connectors;
}

abstract class PLCOpenBlock {
   attr String name;
   val InputPort[*] inputs;
   val OutputPort[*] outputs;
}

class EquivalentBlock extends PLCOpenBlock {
   
}

abstract class Port {
   attr String name;
}

class InputPort extends Port {
   
}

class OutputPort extends Port {
   
}

class Connector {
   val OutputPort source;
   val InputPort destination;
}


I am not sure how I can solve this problem. I guess I have to modify the generated code of the EquivalentBlockEditPart so that the correct number of ports are created automatically but I don't know exactly how this can be done. I will also probably need to remove some edit policies that allow ports to be deleted but again, it is not clear what I have to do exactly.
Thanks for the help.
Re: Blocks with defined inputs and ouptuts [message #549640 is a reply to message #549624] Tue, 27 July 2010 12:49 Go to previous messageGo to next message
SonglinPiao  is currently offline SonglinPiao Friend
Messages: 11
Registered: December 2009
Junior Member
Hello I think there are two different ways to solve your problem.
First, you define your block as external xml file inside your project folder, and then when you create your block, you create model using this xml file.
So you have to define all your blocks inside this xml file.

Second, you can add your port inside the construct method. For example, in the case of Block class, there is a contruct method inside this class. You just add several lines which could add input and output ports to this class. But this method , you may encounter a problem that when you create node it seems like normal, but when you want to restore the saved file from the desk , the number of input port and output port would become double as original size. It is because the constructor method is called twice then XMLImplement class restores the file.

So both case you need to write down your own xml parser. You had better inherit XMLImplement class. Good luck!
Re: Blocks with defined inputs and ouptuts [message #549936 is a reply to message #549624] Wed, 28 July 2010 13:54 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
SonglinPiao, thanks for your answer but I have to say that I didn't get anything that you were saying in your reply. Why are you talking about XML ? Confused

Anyway, I think I found a beginning of an answer by looking at the example code from the Logic example from GMF, by trials and errors and by debugging the example (which is extremly time consuming).
As far as I understood from the example (but I didn't understand a lot), when the edit part for an OR gate (for instance) is created, an EditPartHelper is providing a specific ConfigureCommand that creates the terminals in the OR gate from the model. Then, the semantic edit policy "automatically" synchronizes the diagram.

So, what I inspired myself from the example and I created a "ConfigureBlockCommand" (very similar but a bit simpler than the "ConfigureLogicElementCommand" from the GMF logic example). Then in the "EquivalentBlockEditHelper", I override the "getConfigure" method, once again, very similar as the "getConfigure" method from "GateEditHelper".

This was not working as expected then after debugging I saw that I had to comment two methods from the "PLCOpenEditorBaseEditHelper" (base class from "PLCOpenEditorBaseEditHelper"): the "getInsteadCommand" and the "getCreateCommand":
	/**
	 * @generated
	 */
	protected ICommand getInsteadCommand(IEditCommandRequest req) {
	
		ICommand epCommand = (ICommand) req.getParameter(EDIT_POLICY_COMMAND);
		req.setParameter(EDIT_POLICY_COMMAND, null);
		ICommand ehCommand = super.getInsteadCommand(req);
		if (epCommand == null) {
			return ehCommand;
		}
		if (ehCommand == null) {
			return epCommand;
		}
		CompositeCommand command = new CompositeCommand(null);
		command.add(epCommand);
		command.add(ehCommand);
		return command;
	}

	/**
	 * @generated
	 */
	protected ICommand getCreateCommand(CreateElementRequest req) {
		return null;
	}


My question is: is it ok to do that ? Will it cause problems for other parts of the code ? I don't really understand the consequences of doing that.

Furthermore, I still need to implement a couple of additional features:
- These ports can't be delete by the user anymore (as said in my first messages each type of block has a very specific number of input and output ports).
- The user can't create additional ports in the blocks. I can of course remove the port creation tool in the palette but there is still a popup that appears when hovering over a block, this should be removed.
- The ports should be positionned at a specific location when created.
- The user is not able to move the ports.

In fact, all these features are already present in the GMF logic example, but it is extremely time consuming to find where they are "implemented'. Furthermore, the example was apparently created before the generation tools existed (gmfmap, gmfgen, ...), so it even more complicated to find the information because the structure is different.

I would really appreciate some pointers here. What would already help me a lot is an indication of were I can look for these features in the logic example.

Thanks for the help.
Re: Blocks with defined inputs and ouptuts [message #550381 is a reply to message #549936] Fri, 30 July 2010 08:05 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
I was able to find a solution to some of the features I was looking for: "forbid" the user to delete or move the ports.

For those interested, it is really easy to do: you simply have to make the ports unselectable (this way, there's no way the user will be able to delete or move them). For that, simply override the isSelectable method in the port edit part:
	/**
	 * @generated NOT
	 */
	public boolean isSelectable() {
		return false;
	}


I am still looking for a way to prevent the user to add new ports in an element. This could also be easily fixed by removing the port creation tool frrom the palette (just don't put them in the palette) and by disabling the pop-up bars. For that part, it's still not clear how to do it (I made a separate discussion with that question).
Re: Blocks with defined inputs and ouptuts [message #550475 is a reply to message #550381] Fri, 30 July 2010 13:46 Go to previous messageGo to next message
Toñi  Reina is currently offline Toñi ReinaFriend
Messages: 209
Registered: July 2009
Senior Member
Hi C,

I have a similar

El 30/07/2010 10:05, C escribió:
> I was able to find a solution to some of the features I was looking for:
> "forbid" the user to delete or move the ports.
>
> For those interested, it is really easy to do: you simply have to make
> the ports unselectable (this way, there's no way the user will be able
> to delete or move them). For that, simply override the isSelectable
> method in the port edit part:
> /**
> * @generated NOT
> */
> public boolean isSelectable() {
> return false;
> }
>
> I am still looking for a way to prevent the user to add new ports in an
> element. This could also be easily fixed by removing the port creation
> tool frrom the palette (just don't put them in the palette) and by
> disabling the pop-up bars. For that part, it's still not clear how to do
> it (I made a separate discussion with that question).
Re: Blocks with defined inputs and ouptuts [message #550476 is a reply to message #550475] Fri, 30 July 2010 13:48 Go to previous messageGo to next message
Toñi  Reina is currently offline Toñi ReinaFriend
Messages: 209
Registered: July 2009
Senior Member
Hi C,

I have a similar problem to yours. And I find ver

El 30/07/2010 15:46, Toñi Reina Quintero escribió:
> Hi C,
>
> I have a similar
>
> El 30/07/2010 10:05, C escribió:
>> I was able to find a solution to some of the features I was looking for:
>> "forbid" the user to delete or move the ports.
>>
>> For those interested, it is really easy to do: you simply have to make
>> the ports unselectable (this way, there's no way the user will be able
>> to delete or move them). For that, simply override the isSelectable
>> method in the port edit part:
>> /**
>> * @generated NOT
>> */
>> public boolean isSelectable() {
>> return false;
>> }
>>
>> I am still looking for a way to prevent the user to add new ports in an
>> element. This could also be easily fixed by removing the port creation
>> tool frrom the palette (just don't put them in the palette) and by
>> disabling the pop-up bars. For that part, it's still not clear how to do
>> it (I made a separate discussion with that question).
>
Re: Blocks with defined inputs and ouptuts [message #550490 is a reply to message #550476] Fri, 30 July 2010 13:54 Go to previous messageGo to next message
Toñi  Reina is currently offline Toñi ReinaFriend
Messages: 209
Registered: July 2009
Senior Member
Hi C,
Sorry for the two previous unfinished messages.

I have a similar problem to yours. And I find very interesting your
research, can you post the url of the tutorial you have used to create
your blocks with the ports?

Thx,




El 30/07/2010 15:48, Toñi Reina Quintero escribió:
> Hi C,
>
> I have a similar problem to yours. And I find ver
>
> El 30/07/2010 15:46, Toñi Reina Quintero escribió:
>> Hi C,
>>
>> I have a similar
>>
>> El 30/07/2010 10:05, C escribió:
>>> I was able to find a solution to some of the features I was looking for:
>>> "forbid" the user to delete or move the ports.
>>>
>>> For those interested, it is really easy to do: you simply have to make
>>> the ports unselectable (this way, there's no way the user will be able
>>> to delete or move them). For that, simply override the isSelectable
>>> method in the port edit part:
>>> /**
>>> * @generated NOT
>>> */
>>> public boolean isSelectable() {
>>> return false;
>>> }
>>>
>>> I am still looking for a way to prevent the user to add new ports in an
>>> element. This could also be easily fixed by removing the port creation
>>> tool frrom the palette (just don't put them in the palette) and by
>>> disabling the pop-up bars. For that part, it's still not clear how to do
>>> it (I made a separate discussion with that question).
>>
>
Re: Blocks with defined inputs and ouptuts [message #550669 is a reply to message #549624] Wed, 04 August 2010 06:31 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

Well, that's the point, there's no tutorial for that. I searched in the code that is provided in the GMF logic example.
This example should be provided with your Eclipse installation ("File" -> "New" -> "Example" and in the list, search for "Logic" under "GMF (...) Plug-ins".
Re: Blocks with defined inputs and ouptuts [message #551124 is a reply to message #550669] Thu, 05 August 2010 10:42 Go to previous message
Toñi  Reina is currently offline Toñi ReinaFriend
Messages: 209
Registered: July 2009
Senior Member
Thanks,

I'll take a look

El 04/08/2010 8:31, Cedric escribió:
> Hello,
>
> Well, that's the point, there's no tutorial for that. I searched in the
> code that is provided in the GMF logic example. This example should be
> provided with your Eclipse installation ("File" -> "New" -> "Example"
> and in the list, search for "Logic" under "GMF (...) Plug-ins".
Previous Topic:New GMF Project
Next Topic:Adding Native Drag Support to Editor
Goto Forum:
  


Current Time: Tue Jun 18 05:48:39 GMT 2024

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

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

Back to the top