Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Layout issue with Polygon in Composite Figure
Layout issue with Polygon in Composite Figure [message #217112] Tue, 03 February 2009 10:21 Go to next message
Christian Muth is currently offline Christian MuthFriend
Messages: 24
Registered: July 2009
Junior Member
Hi all,



my goal (one of many actually) with GMF is to create the following
figure:


|
| Root connection going into the decision figure.
|
|
V
+------------------------------------+
| /\ | The outer Rectangle is
| / \ | fill=false, outline=false
| _______/ \_______ |
| | \ / | | The Rhomb shall be placed
| | \ / | | centered, top inside the outer
| | \/ | | rectangle. So it looks like
| | | | the root connection above
| | | | connects to it although it
| | | | connects to the outer rectangle
+------|--------------------|--------+ instead.
| | | |
| | | | This is a non-collapsible
| V V | compartment, the rectangles
| +---------+ +---------+ | are seperate nodes which in
| | Label | | | | turn contain a label and
| |---------| | | | collapsible compartments
| | | | | | hosting other nodes as well
| | Compart-| | | | (sort of activity modelling)
| | ment | | | |
| +---------+ +---------+ |
| | | |
+------|--------------------|--------+
| |
V V
============================ This is kind of sync line from
| activity diagramming.
|
V
END



But I am already stuck at the very beginning:
I tried to adapt the procedure in:
http://wiki.eclipse.org/GMF_Tutorial_Part_3#Composite_Figure s
and also followed the hint working around:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=142010
(setting myUseLocalCoordinates=true in generated
....edit.parts.ResourceEditPart$ResourceFigure class)

But the generated diagram editor doesn't center a polygon inside the
outer rectangle while it does center an ellipse or rectangle.

If i create a .gmfgraph containing the following figure descriptor:

<descriptors
name="ResourceFigure">
<actualFigure
xsi:type="gmfgraph:Rectangle"
name="ResourceFigure"
outline="false"
fill="false">
<layout
xsi:type="gmfgraph:StackLayout"/>
<children
xsi:type="gmfgraph:Rectangle"
name="Inner"
outline="false"
fill="false">
<layout
xsi:type="gmfgraph:GridLayout"
equalWidth="false"/>
<children
xsi:type="gmfgraph:Ellipse"
name="DecisionRhomb">
<layoutData
xsi:type="gmfgraph:GridLayoutData"
verticalAlignment="BEGINNING"/>
<backgroundColor
xsi:type="gmfgraph:ConstantColor"
value="gray"/>
<size
x="25"
y="25"/>
</children>
<children
xsi:type="gmfgraph:Rectangle"
name="Body">
<layoutData
xsi:type="gmfgraph:GridLayoutData"
grabExcessHorizontalSpace="true"
grabExcessVerticalSpace="true"
verticalAlignment="FILL"
horizontalAlignment="FILL"/>
<backgroundColor
xsi:type="gmfgraph:ConstantColor"
value="gray"/>
<size
x="120"
y="200"/>
</children>
</children>
</actualFigure>
</descriptors>

It looks exactly like it should, the ellipse "DecisionRhomb" placed
centered above the "Body" rectangle which expands to its parent's
horizontal and vertical dimensions.

But if i chance the ellipse to a polygon in .gmfgraph:

<descriptors
name="ResourceFigure">
<actualFigure
xsi:type="gmfgraph:Rectangle"
name="ResourceFigure"
outline="false"
fill="false">
<layout
xsi:type="gmfgraph:StackLayout"/>
<children
xsi:type="gmfgraph:Rectangle"
name="Inner"
outline="false"
fill="false">
<layout
xsi:type="gmfgraph:GridLayout"
equalWidth="false"/>
<foregroundColor
xsi:type="gmfgraph:ConstantColor"
value="gray"/>
<children
xsi:type="gmfgraph:Polygon"
name="DecisionRhomb">
<layoutData
xsi:type="gmfgraph:GridLayoutData"
verticalAlignment="BEGINNING"/>
<template
x="20"/>
<template
x="40"
y="20"/>
<template
x="20"
y="40"/>
<template
y="20"/>
</children>
<children
xsi:type="gmfgraph:Rectangle"
name="Body">
<layoutData
xsi:type="gmfgraph:GridLayoutData"
grabExcessHorizontalSpace="true"
grabExcessVerticalSpace="true"
verticalAlignment="FILL"
horizontalAlignment="FILL"/>
<backgroundColor
xsi:type="gmfgraph:ConstantColor"
value="gray"/>
<size
x="120"
y="200"/>
</children>
</children>
</actualFigure>
</descriptors>


I either don't see the rhomb at all (myUseLocalCoordinates=false) or
top left with myUseLocalCoordinates=true.

How can the rhomb be aligned like the ellipse? Do i have to make a
custom rhomb shape?



Thanks a lot in advance,

Christian
Re: Layout issue with Polygon in Composite Figure [message #217132 is a reply to message #217112] Tue, 03 February 2009 11:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

Hello Christian,

perhaps these links can help you:

1. Here they descripe how to draw an ellipse inside of an ellipse.
Perhaps it`s easier to draw the romb and the rectangle in one figure?
http://wiki.eclipse.org/GMF_Newsgroup_Q_and_A#How_do_I_draw_ an_ellipse_inside_another_ellipse.3F
I had a simliar problem: I wanted a circle centered in a triangle. After
some fruitless approaches with one circle and one triangle I made one
figure where I draw both at once. First I draw the triangle, then I
calculate the radius of the in-circle and draw the circle accordingly.
That is also good, because then the circle becomes also bigger when the
triangle becomes bigger.

2. For the Figure, perhaps the Taipan Tutorial helps you:
http://wiki.eclipse.org/index.php/GMF_Tutorial#Quick_Start
As you can see, they use for the port some kind of christmas-tree :D
They use a own class for the port-figure.

Best wishes
Julia
Re: Layout issue with Polygon in Composite Figure [message #217165 is a reply to message #217132] Tue, 03 February 2009 16:24 Go to previous message
Christian Muth is currently offline Christian MuthFriend
Messages: 24
Registered: July 2009
Junior Member
Hi Julia,


thanks for the hints! Although I already knew these documentation
resources I rather tried composing the figure just with .gmfgraph which
wont work for Polygons in the given scenario.

So I followed your advice and created RhombFigure (everyone feel free to
use, modify and distribute):


____________________________________________________________ ______________
package org.eclipse.draw2d;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;

/**
* Draws a filled rhomb whose size is determined by its bounds.
* Each corner of the rhomb matches the middle of the corresponding edge
* given by {@link #getBounds()}.
*/
public class RhombFigure extends RectangleFigure {
private PointList cachedPointList;
private Rectangle oldBounds;

/**
* Constructs a new RhombFigure, sets <code>fill</code> to
<code>true</code>.
*/
public RhombFigure() {
super();
this.setFill(true);
}

/**
* Fills the rhomb.
* @see org.eclipse.draw2d.Shape#fillShape(org.eclipse.draw2d.Graphi cs)
*/
@Override
protected void fillShape(Graphics graphics) {
graphics.pushState();
graphics.fillPolygon(getPointList());
graphics.popState();
}

/**
* Outlines the rhomb.
* @see org.eclipse.draw2d.Shape#outlineShape(org.eclipse.draw2d.Gra phics)
*/
@Override
protected void outlineShape(Graphics graphics) {
graphics.pushState();
graphics.drawPolygon(getPointList());
graphics.popState();
}

/**
* Returns the PointList for a rhomb style polygon filling the
<code>Rectangle</code>
* returned by {@link org.eclipse.draw2d.RectangleFigure#getBounds()}.
*
* @return the desired <code>PointList</code> containing absolute
coordinates
*/
private PointList getPointList() {
Rectangle bounds = getBounds();

if (oldBounds == null || !(bounds.equals(oldBounds))) {
// need to recalculate since bounds changed

// use a copy - otherwise oldBounds never changes ;o)
this.oldBounds = bounds.getCopy();

// leave 1 px margin on each edge to avoid clipping
int left = bounds.x + 1;
int right = (left + bounds.width) - 2;
int center = left + (int)Math.floor((right - left) / 2);

int top = bounds.y + 1;
int bottom = top + bounds.height - 2;
int middle = top + (int)Math.floor((bottom - top) / 2);

this.cachedPointList = new PointList();
this.cachedPointList.addPoint(new Point(center, top));
this.cachedPointList.addPoint(new Point(right, middle));
this.cachedPointList.addPoint(new Point(center, bottom));
this.cachedPointList.addPoint(new Point(left, middle));
}

return this.cachedPointList;
}
}
____________________________________________________________ ______________

And modified my .gmfgraph to use the new Custom Figure:


<descriptors
name="ResourceFigure">
<actualFigure
xsi:type="gmfgraph:Rectangle"
name="ResourceFigure"
outline="false"
fill="false">
<layout
xsi:type="gmfgraph:StackLayout"/>
<children
xsi:type="gmfgraph:Rectangle"
name="Inner"
outline="false"
fill="false">
<layout
xsi:type="gmfgraph:GridLayout"
equalWidth="false"/>
<foregroundColor
xsi:type="gmfgraph:ConstantColor"
value="gray"/>
<children
xsi:type="gmfgraph:CustomFigure"
name="MyRhombFigure"
qualifiedClassName="org.eclipse.draw2d.RhombFigure">
<layoutData
xsi:type="gmfgraph:GridLayoutData"
verticalAlignment="BEGINNING"/>
<backgroundColor
xsi:type="gmfgraph:ConstantColor"
value="yellow"/>
<size
x="30"
y="30"/>
</children>
<children
xsi:type="gmfgraph:Rectangle"
name="Body">
<layoutData
xsi:type="gmfgraph:GridLayoutData"
grabExcessHorizontalSpace="true"
grabExcessVerticalSpace="true"
verticalAlignment="FILL"
horizontalAlignment="FILL"/>
<backgroundColor
xsi:type="gmfgraph:ConstantColor"
value="gray"/>
<size
x="120"
y="200"/>
</children>
</children>
</actualFigure>
</descriptors>



Maybe someone might find this useful...


Thanks all

Christian
Previous Topic:Problem with Save As functionality
Next Topic:Diagram Performance
Goto Forum:
  


Current Time: Tue Apr 23 09:21:10 GMT 2024

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

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

Back to the top