Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Know the Co-ordinates(Move Shape into another shape completely)
Know the Co-ordinates [message #753456] Thu, 27 October 2011 10:42 Go to next message
Maqsood Ahmed is currently offline Maqsood AhmedFriend
Messages: 41
Registered: September 2010
Member
Hi ,
I have to restrict move of a shape into another shape , i have done the coding in the
canMoveShape method of my MoveFeature, but when the shape is completely inside another
shape then the validation fails.
Can someone tell me what's the best way to add such a restriction.

Regards,
Mak
Re: Know the Co-ordinates [message #753476 is a reply to message #753456] Thu, 27 October 2011 12:32 Go to previous messageGo to next message
Christian B is currently offline Christian BFriend
Messages: 68
Registered: August 2011
Member
can you please show us the code of your canMoveShape method?
Re: Know the Co-ordinates [message #753673 is a reply to message #753476] Fri, 28 October 2011 09:56 Go to previous messageGo to next message
Maqsood Ahmed is currently offline Maqsood AhmedFriend
Messages: 41
Registered: September 2010
Member
ContainerShape shapeToMove = (ContainerShape) context.getPictogramElement();

Object obj = getBusinessObjectForPictogramElement(shapeToMove);

if (obj instanceof A || obj instanceof B|| obj instanceof C) {

ContainerShape container = shapeToMove.getContainer();

int containerWidth = container.getGraphicsAlgorithm().getWidth();
int containerHeight = container.getGraphicsAlgorithm().getHeight();

int shapeWidth = shapeToMove.getGraphicsAlgorithm().getWidth();
int shapeHeight = shapeToMove.getGraphicsAlgorithm().getHeight();

int shapeX = context.getX();
int shapeY = context.getY();

EList<Shape> children = container.getChildren();
for (Shape node : children) {

if (node instanceof ContainerShape && node != shapeToMove) {

int nodeX = node.getGraphicsAlgorithm().getX();
int nodeY = node.getGraphicsAlgorithm().getY();

int nodeWitdth = node.getGraphicsAlgorithm().getWidth();
int nodeHeight = node.getGraphicsAlgorithm().getHeight();

if ((nodeY < shapeY && nodeY + nodeHeight > shapeY) || (nodeY > shapeY && shapeY + shapeHeight > nodeY)) {
if (shapeX > nodeX && shapeX < nodeX + nodeWitdth) {
System.out.println("FC == 1");
return false;
}
if (shapeX == nodeX) {
System.out.println("FC == 2");
return false;
}
if (shapeX < nodeX && shapeX + shapeWidth > nodeX) {
System.out.println("FC == 3");
return false;
}
} else if (nodeY == shapeY) {
if (nodeX < shapeX && nodeX + nodeWitdth > shapeX) {
System.out.println("FC == 4");
return false;
}
if (nodeX == shapeX || nodeX + nodeWitdth == shapeX + shapeWidth) {
System.out.println("FC ==5");
return false;
}
if (nodeX > shapeX && shapeX + shapeWidth < nodeX) {
System.out.println("FC == 6");
return false;
}
}

}
}

// move towards right
if ((shapeX + shapeWidth) > containerWidth) {
System.out.println("move Right");
return false;
}

// move towards left
if (shapeX < 0) {
System.out.println("move left");
return false;
}

// move towards bottom
if ((shapeY + shapeHeight) > containerHeight) {
System.out.println("bottom");
return false;
}

// move towards top;
if (shapeY < 30) {
System.out.println("top");
return false;
}
// if (shapeX + shapeWidth < GraphitiUtil.getCurrentGraphicalViewer().getDiagram().getChildren().get(0).getGraphicsAlgorithm().getWidth())
// {
// shapeToMove.getGraphicsAlgorithm().get
// System.out.println("core");
// return false;
// }
return true;

I have put system.out.print.. to knw the co-ordinates while i am holding(moving) the shape inside another shape completely.
Pls note : container is diagram , the above code checks generically if a shapeToMove can be moved to a new position taking into account all other diagram childern.

[Updated on: Fri, 28 October 2011 10:12]

Report message to a moderator

Re: Know the Co-ordinates [message #753676 is a reply to message #753673] Fri, 28 October 2011 10:06 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Hi,

I think you should not use

ContainerShape container = shapeToMove.getContainer();


but the

getTargetContainer() 


from the context.

Andreas
Re: Know the Co-ordinates [message #753946 is a reply to message #753676] Mon, 31 October 2011 06:27 Go to previous message
Maqsood Ahmed is currently offline Maqsood AhmedFriend
Messages: 41
Registered: September 2010
Member
Hi Andread,
Thanks for your reply. It was really useful, I din't notice that the
targetContainer 
was available in the context.
I have adapted accordingly.

Solved Laughing
Know the Co-ordinates
Move Shape into another shape completely, check using
context.getTargetContainer()

and you can return false where you do not want to allow.

You will have to restrict based on co-ordinates when moving within the same container(adding some padding etc..)

Regards
Mak

[Updated on: Mon, 31 October 2011 06:34]

Report message to a moderator

Previous Topic:Testing Graphiti Applications
Next Topic:Display workspace-located image
Goto Forum:
  


Current Time: Thu Apr 18 23:44:25 GMT 2024

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

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

Back to the top