Resizing of a Polygon - Bug? [message #698965] |
Wed, 20 July 2011 14:57 |
Joerg Reichert Messages: 80 Registered: July 2009 Location: Leipzig |
Member |
|
|
Hello,
I am trying to resize a polygon figure following the suggestion made here:
http://www.eclipse.org/forums/index.php/mv/msg/174043/554130/#msg_554130
I encounter a strange behavior using the |> icon at figure to resize only the width. In the resizeShape method also the height of the shape had changed, so the figure gets lower and lower with each width resize, when pulling the figure wider as well as when narrowing the shape. How much lower seems to depend on the original height. For 208 the next height is 170, so factor 0.817, for 41 next is 37, so factor 0.87, when 30 it is factor 0.9.
@Override
public void resizeShape(IResizeShapeContext context) {
super.resizeShape(context);
double width = context.getWidth();
double height = context.getHeight(); // here the height has changed
...
}
In the add feature I use this code to create the hexagon figure:
ContainerShape hierarchyShape = peService.createContainerShape(diagram,
true);
int textWidth = MetaBIStyleUtil.getTextWidth(hierarchy.getName());
int textHeight = 30;
int hexagonLonger = 10;
int hexagonHeighter = 5;
int hexagonHeight = textHeight + (2 * hexagonHeighter);
int hexagonMiddleHeight = Math.round(hexagonHeight / 2);
int hexagonLongEdge = IMAGE_WIDTH + textWidth + (2 * hexagonLonger);
int hexagonShortEdge = IMAGE_WIDTH + textWidth;
int hexagonStartXLong = 5;
int hexagonStartXShort = 5 + hexagonLonger;
int hexagonStartY = 5;
Point upperLeftCorner = StylesFactory.eINSTANCE.createPoint();
upperLeftCorner.setX(hexagonStartXShort);
upperLeftCorner.setY(hexagonStartY);
Point upperRightCorner = StylesFactory.eINSTANCE.createPoint();
upperRightCorner.setX(hexagonStartXShort + hexagonShortEdge);
upperRightCorner.setY(hexagonStartY);
Point middleRightCorner = StylesFactory.eINSTANCE.createPoint();
middleRightCorner.setX(hexagonStartXLong + hexagonLongEdge);
middleRightCorner.setY(hexagonStartY + hexagonMiddleHeight);
Point lowerRightCorner = StylesFactory.eINSTANCE.createPoint();
lowerRightCorner.setX(hexagonStartXLong + hexagonLongEdge);
lowerRightCorner.setY(hexagonStartY + hexagonHeight);
Point lowerLeftCorner = StylesFactory.eINSTANCE.createPoint();
lowerLeftCorner.setX(hexagonStartXLong);
lowerLeftCorner.setY(hexagonStartY + hexagonHeight);
Point middleLeftCorner = StylesFactory.eINSTANCE.createPoint();
middleLeftCorner.setX(hexagonStartXLong);
middleLeftCorner.setY(hexagonStartY + hexagonMiddleHeight);
Collection<Point> points = new ArrayList<Point>();
points.add(upperLeftCorner);
points.add(upperRightCorner);
points.add(middleRightCorner);
points.add(lowerRightCorner);
points.add(lowerLeftCorner);
points.add(middleLeftCorner);
Polygon hierarchyHexagon = gaService.createPolygon(hierarchyShape,
points);
(I actually let start the figure in (5,5), when starting in (0, 0) the problem is not so obvious (as the y coord is 0 and so multiplication has no effect) but it still exists).
I do not if this is a bug in GEF or Graphiti.
Joerg
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
|
|
|
(no subject) [message #699373 is a reply to message #698965] |
Thu, 21 July 2011 12:57 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
That's appears kind of strange but I'll try to explain.
The outermost points of a graphics algorithm define its size. In the case of
your ploygon the outermost points. So if you start in 0,0 and have a point
in 100,100 the size will be 100,100 (width,height). If you start in 5,5 the
size will be 95,95.
My quickly written resize algorithm assumes that your shape starts at 0,0,
otherwise you would have to add your offsets (5,5 in the upper example) to
what you get as size information from the polygon. So calculating the resize
factor using
float scaleX = new Float(width + 5) / new Float(maxX);
float scaleY = new Float(height + 5) / new Float(maxY);
should fix that in your case (conversion to float additionally fixes general
rounding issues).
Let me know if that helps or if I'm on the wrong track...
Michael
"Joerg Reichert" schrieb im Newsbeitrag
news:j06pp8$nde$1@news.eclipse.org...
Hello,
I am trying to resize a polygon figure following the suggestion made here:
http://www.eclipse.org/forums/index.php/mv/msg/174043/554130/#msg_554130
I encounter a strange behavior using the |> icon at figure to resize only
the width. In the resizeShape method also the height of the shape had
changed, so the figure gets lower and lower with each width resize, when
pulling the figure wider as well as when narrowing the shape. How much lower
seems to depend on the original height. For 208 the next height is 170, so
factor 0.817, for 41 next is 37, so factor 0.87, when 30 it is factor 0.9.
@Override
public void resizeShape(IResizeShapeContext context) {
super.resizeShape(context);
double width = context.getWidth();
double height = context.getHeight(); // here the height has changed
...
}
In the add feature I use this code to create the hexagon figure:
ContainerShape hierarchyShape = peService.createContainerShape(diagram,
true);
int textWidth = MetaBIStyleUtil.getTextWidth(hierarchy.getName());
int textHeight = 30;
int hexagonLonger = 10;
int hexagonHeighter = 5;
int hexagonHeight = textHeight + (2 * hexagonHeighter);
int hexagonMiddleHeight = Math.round(hexagonHeight / 2);
int hexagonLongEdge = IMAGE_WIDTH + textWidth + (2 * hexagonLonger);
int hexagonShortEdge = IMAGE_WIDTH + textWidth;
int hexagonStartXLong = 5;
int hexagonStartXShort = 5 + hexagonLonger;
int hexagonStartY = 5;
Point upperLeftCorner = StylesFactory.eINSTANCE.createPoint();
upperLeftCorner.setX(hexagonStartXShort);
upperLeftCorner.setY(hexagonStartY);
Point upperRightCorner = StylesFactory.eINSTANCE.createPoint();
upperRightCorner.setX(hexagonStartXShort + hexagonShortEdge);
upperRightCorner.setY(hexagonStartY);
Point middleRightCorner = StylesFactory.eINSTANCE.createPoint();
middleRightCorner.setX(hexagonStartXLong + hexagonLongEdge);
middleRightCorner.setY(hexagonStartY + hexagonMiddleHeight);
Point lowerRightCorner = StylesFactory.eINSTANCE.createPoint();
lowerRightCorner.setX(hexagonStartXLong + hexagonLongEdge);
lowerRightCorner.setY(hexagonStartY + hexagonHeight);
Point lowerLeftCorner = StylesFactory.eINSTANCE.createPoint();
lowerLeftCorner.setX(hexagonStartXLong);
lowerLeftCorner.setY(hexagonStartY + hexagonHeight);
Point middleLeftCorner = StylesFactory.eINSTANCE.createPoint();
middleLeftCorner.setX(hexagonStartXLong);
middleLeftCorner.setY(hexagonStartY + hexagonMiddleHeight);
Collection<Point> points = new ArrayList<Point>();
points.add(upperLeftCorner);
points.add(upperRightCorner);
points.add(middleRightCorner);
points.add(lowerRightCorner);
points.add(lowerLeftCorner);
points.add(middleLeftCorner);
Polygon hierarchyHexagon = gaService.createPolygon(hierarchyShape,
points);
(I actually let start the figure in (5,5), when starting in (0, 0) the
problem is not so obvious (as the y coord is 0 and so multiplication has no
effect) but it still exists).
I do not if this is a bug in GEF or Graphiti.
Joerg
--
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
|
|
|
|
Powered by
FUDForum. Page generated in 0.03242 seconds