Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Create dynamically anchors on a shape
Create dynamically anchors on a shape [message #903145] Wed, 22 August 2012 08:16 Go to next message
Thomas Zöchbauer is currently offline Thomas ZöchbauerFriend
Messages: 10
Registered: August 2012
Junior Member
hi, i think there are some similar problems but i couldn't get smart of them.

This is the problem:

I have a Rectangle on my Diagram


@Override
	public PictogramElement add(IAddContext context) {
		Shape ladder = createLadderGraphic(context);

		getDiagram().eResource().getContents()
				.add((EObject) context.getNewObject());
		link(ladder, context.getNewObject());
		return ladder;
	}

	private Shape createLadderGraphic(IAddContext context) {

		Diagram targetDiagram = (Diagram) context.getTargetContainer();
		IGaService gaService = Graphiti.getGaService();
		IPeCreateService peCreateService = Graphiti.getPeCreateService();
		Ladder bo = (Ladder) context.getNewObject();
		// 1 containershape
		ContainerShape containerShape = peCreateService.createContainerShape(
				targetDiagram, true);

		Rectangle rectangle = gaService.createRectangle(containerShape);
		rectangle.setBackground(manageColor(StyleUtil.COLOR_BLACK));
		rectangle.setFilled(true);
		gaService.setLocationAndSize(rectangle, context.getX(), context.getY(),
				context.getWidth(), context.getHeight());

		return containerShape;
	}


Works Smile

Now this what i am trying....

Creating a Connection from the location i clicked in the shape to the target.

I hooked into attach

@Override
	public void attachedToSource(final ICreateConnectionContext context) {
		final Object bo = getBusinessObjectForPictogramElement(context
				.getSourcePictogramElement());

		// create fix anchor for connection on ladder
		if (bo instanceof StartLadder) {
			TransactionalEditingDomain editingDomain = getDiagramEditor()
					.getEditingDomain();
			CommandStack commandStack = editingDomain.getCommandStack();
			commandStack.execute(new RecordingCommand(editingDomain) {

				@Override
				protected void doExecute() {
					IPeCreateService peCreateService = Graphiti
							.getPeCreateService();
					IGaService gaService = Graphiti.getGaService();

					ContainerShape container = (ContainerShape) context
							.getSourcePictogramElement();
					ILocation location = context.getSourceLocation();
					int x = location.getX();
					int y = location.getY();
					// Point p = gaService.createPoint(x, y);

					ChopboxAnchor anchor = peCreateService
							.createChopboxAnchor(container);
					// gaService.setLocation(anchor, x, y);
					// anchor.setUseAnchorLocationAsConnectionEndpoint(true);

					Rectangle rect = gaService.createRectangle(anchor);
					gaService.setLocation(rect, x, y);

					anchor.setGraphicsAlgorithm(rect);
					anchor.setReferencedGraphicsAlgorithm(rect);

					IEC_Anchor obj = FbsFactory.eINSTANCE.createIEC_Anchor();
					obj.setIn(false);
					obj.setSource((EObject) bo);
					getDiagram().eResource().getContents().add(obj);
					// link(shape, obj);
					link(anchor, bo);

					// use anchor
					((CreateConnectionContext) context).setSourceAnchor(anchor);
				}
			});
		}

	}


looking the attached jpg.

but i dont want chopbox anchor because it starts from the middle of the shape.

any hints?

BR

Thomas



Re: Create dynamically anchors on a shape [message #903153 is a reply to message #903145] Wed, 22 August 2012 09:03 Go to previous messageGo to next message
Thomas Zöchbauer is currently offline Thomas ZöchbauerFriend
Messages: 10
Registered: August 2012
Junior Member
When i do this:


IPeCreateService peCreateService = Graphiti
							.getPeCreateService();
					IGaService gaService = Graphiti.getGaService();

					ContainerShape container = (ContainerShape) context
							.getSourcePictogramElement();

					ILocation location = context.getSourceLocation();
					int x = 0;// location.getX();
					int y = location.getY()-20;
					// Point p = gaService.createPoint(x, y);

					FixPointAnchor anchor = peCreateService
							.createFixPointAnchor(container);

					anchor.setLocation(gaService.createPoint(x, y));

					// anchor.setUseAnchorLocationAsConnectionEndpoint(true);

					Rectangle rect = gaService.createRectangle(anchor);
					gaService.setLocationAndSize(rect, 0, 0, 1, 1);

					// anchor.setGraphicsAlgorithm(rect);
					// anchor.setReferencedGraphicsAlgorithm(rect);

					IEC_Anchor obj = FbsFactory.eINSTANCE.createIEC_Anchor();
					obj.setIn(false);
					obj.setSource((EObject) bo);
					getDiagram().eResource().getContents().add(obj);
					// link(shape, obj);
					link(anchor, bo);

					// use anchor
					((CreateConnectionContext) context).setSourceAnchor(anchor);


its working. the next step is when i create the connection i have to look up for the right anchor.


looking something like this

@Override
	public Connection create(ICreateConnectionContext context) {
		// create the domain object connection here
		SignalFlow flow = FbsFactory.eINSTANCE.createSignalFlow();

		// check if horizontal

		int sx = context.getSourceLocation().getX();
		int sy = context.getSourceLocation().getY();

		int tx = context.getTargetLocation().getX();
		int ty = context.getTargetLocation().getY();

		if (Math.abs(tx - sx) >= Math.abs(ty - sy)) {
			flow.setHorizontal(true);
		} else {
			flow.setHorizontal(false);
		}

		Object bo = getBusinessObjectForPictogramElement(context
				.getSourcePictogramElement());
		if (bo instanceof StartLadder) {
			EList<Anchor> anchors = ((ContainerShape) context
					.getSourcePictogramElement()).getAnchors();

			Anchor a2use = null;

			for (Anchor anchor : anchors) {
				Object anchorBO = getBusinessObjectForPictogramElement(anchor);
				a2use = anchor;
				break;
			}

			((CreateConnectionContext) context).setSourceAnchor(a2use);

		}


It is both done in a #AbstractConnectionPattern

But there is a bug or missing implementation. Starting to create the connection brings result1.jpg

but creates the connection right, see result2.jpg

The reason is that i have no anchor defined on my containershape and i allow to canStartConnecting() (the laddergraphix), a "default chopbox" anchor is used.

I am able to handle this?

BR

Thomas
  • Attachment: result1.jpg
    (Size: 109.78KB, Downloaded 342 times)
  • Attachment: result2.jpg
    (Size: 106.88KB, Downloaded 1268 times)
Re: Create dynamically anchors on a shape [message #903411 is a reply to message #903153] Thu, 23 August 2012 14:21 Go to previous messageGo to next message
Thomas Zöchbauer is currently offline Thomas ZöchbauerFriend
Messages: 10
Registered: August 2012
Junior Member
Hi, i found an example where my needs are implemented (but in GMF, i think).... GEB automation IDE. When you are opening a new functionblcokdiagram (type: ladder) and create a connection on the start ladder, it follows the mouse move....

How can i hook-into to the GFConnectionCreationTool.class in package org.eclipse.gef.tools; ?? i think there i have to look for my needs.

BR
Thomas
Re: Create dynamically anchors on a shape [message #903706 is a reply to message #903153] Thu, 23 August 2012 12:00 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
The anchor you allow for starting the connection is the one used while
drawing the connection. If you do not want this behavior you will need to
retrict starting the connection to your anchor only.

I hope that answers your question

Michael
Re: Create dynamically anchors on a shape [message #903710 is a reply to message #903411] Fri, 24 August 2012 07:10 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Thomas,

Graphiti hides GEF in most areas from clients and it is not intended that
clients modify classes like GFConnectionCreationTool. If you want to replace
it your should look into DeafultPaletteBehavior where GFPaletteRoot is
created that defines again which tools will be added to the palette (beyond
others also GFConnectionCreationTool). But don't take this as the
recommendation to do this...

Did you read my other reply?

Michael
Re: Create dynamically anchors on a shape [message #904349 is a reply to message #903145] Tue, 28 August 2012 09:45 Go to previous message
Thomas Zöchbauer is currently offline Thomas ZöchbauerFriend
Messages: 10
Registered: August 2012
Junior Member
Thanks for the replay,

i think i am going to solve this problem with the

ConnectionFeatures, as described above, keeping it as simple as possible.

BR,

Thomas
Previous Topic:One CreateFeature for many palette entries
Next Topic:MoveContext
Goto Forum:
  


Current Time: Thu Mar 28 12:44:40 GMT 2024

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

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

Back to the top