Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to transform Rectangle to 3d Cube
How to transform Rectangle to 3d Cube [message #205363] Thu, 15 December 2005 18:05 Go to next message
Svetoslav Rusev is currently offline Svetoslav RusevFriend
Messages: 2
Registered: July 2009
Junior Member
Hi all,
I have a rectangle which extends org.eclipse.draw2d.Figure and I need to
transform it to 3d Cube in GEF. How can I easily do that? Does anyone has
an example of 3d figures drawn in GEF?
Thank you!
Re: How to transform Rectangle to 3d Cube [message #205425 is a reply to message #205363] Fri, 16 December 2005 13:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tfrangoullides.instream.co.uk

Svet,

Geoshapes in GMF project has 3D rectangle, maybe that is what you are
looking for. I've pasted the code below in case its' useful.

Hope that helps,
Tas.


public class GeoShape3DRectangleFigure extends GeoShapeFigure
implements IPolygonAnchorableFigure {

/**
* Constructor - Creates a 3D Rectangle with a Default size
*
* @param width initial or preferred width of the figure
* @param height initial or preferred height of the figure
* @param spacing <code>int</code> that is the margin between children in
logical units
*/
public GeoShape3DRectangleFigure(int width, int height, int spacing) {
super(width, height, spacing);
}

/* (non-Javadoc)
* @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Gra phics)
*/
protected void paintFigure(Graphics g) {

List points = computePoints( getBounds() );

PointList outline = new PointList();
for( int index = 0; index < 6; index++ ) {
outline.addPoint( (Point)points.get( index ) );
}

Point p2 = (Point) points.get( 1 );
Point p4 = (Point) points.get( 3 );
Point p6 = (Point) points.get( 5 );
Point p7 = (Point) points.get( 6 );

// Draw the shape with the fill color
g.fillPolygon( outline );

// Draw the shapes outline
g.drawPolygon( outline );

// Draw the remaining lines
g.drawLine( p6, p7 );
g.drawLine( p7, p4 );
g.drawLine( p7, p2 );
}

private List computePoints( Rectangle rect ) {

List toReturn = new ArrayList();

int scaleWidth = (int) (rect.width * 0.25);
int scaleHeight = (int) (rect.height * 0.25);

Rectangle r1 = new Rectangle( rect.x, rect.y, rect.width - scaleWidth,
rect.height - scaleHeight );
Rectangle r2 = new Rectangle( r1.x + scaleWidth, r1.y + scaleHeight,
r1.width, r1.height );

Point p1 = new Point( r1.x, r1.y );
Point p2 = new Point( r1.x + r1.width, r1.y );
Point p3 = new Point( r2.x + r2.width - 1, r2.y );
Point p4 = new Point( p3.x, r2.y + r2.height - 1 );
Point p5 = new Point( r2.x, p4.y );
Point p6 = new Point( r1.x, r1.y + r1.height );
Point p7 = new Point( p2.x, p6.y );

toReturn.add( p1 );
toReturn.add( p2 );
toReturn.add( p3 );
toReturn.add( p4 );
toReturn.add( p5 );
toReturn.add( p6 );
toReturn.add( p7 );

return toReturn;
}

/* (non-Javadoc)
* @see
org.eclipse.gmf.runtime.diagram.ui.geoshapes.internal.draw2d .figures.IPolygonAnchorableFigure#getPolygonPoints()
*/
public PointList getPolygonPoints() {

List points = computePoints( getBounds() );

PointList outline = new PointList();
for( int index = 0; index < 6; index++ ) {
outline.addPoint( (Point)points.get( index ) );
}

// Close the polygon
outline.addPoint( (Point)points.get( 0 ) );

return outline;
}

}

Svet Rusev wrote:

> Hi all,
> I have a rectangle which extends org.eclipse.draw2d.Figure and I need to
> transform it to 3d Cube in GEF. How can I easily do that? Does anyone has
> an example of 3d figures drawn in GEF?
> Thank you!
Re: How to transform Rectangle to 3d Cube [message #205449 is a reply to message #205425] Fri, 16 December 2005 19:00 Go to previous message
Svetoslav Rusev is currently offline Svetoslav RusevFriend
Messages: 2
Registered: July 2009
Junior Member
Thank you Tas!

I have taken the paintFigure method with all the dependant methods from
GeoShape3DRectangleFigure class and it worked perfect for me.

Tas Frangoullides wrote:

> Svet,

> Geoshapes in GMF project has 3D rectangle, maybe that is what you are
> looking for. I've pasted the code below in case its' useful.

> Hope that helps,
> Tas.


> public class GeoShape3DRectangleFigure extends GeoShapeFigure
> implements IPolygonAnchorableFigure {

> /**
> * Constructor - Creates a 3D Rectangle with a Default size
> *
> * @param width initial or preferred width of the figure
> * @param height initial or preferred height of the figure
> * @param spacing <code>int</code> that is the margin between
children in
> logical units
> */
> public GeoShape3DRectangleFigure(int width, int height, int spacing)
{
> super(width, height, spacing);
> }

> /* (non-Javadoc)
> * @see
org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Gra phics)
> */
> protected void paintFigure(Graphics g) {

> List points = computePoints( getBounds() );

> PointList outline = new PointList();
> for( int index = 0; index < 6; index++ ) {
> outline.addPoint( (Point)points.get( index ) );
> }

> Point p2 = (Point) points.get( 1 );
> Point p4 = (Point) points.get( 3 );
> Point p6 = (Point) points.get( 5 );
> Point p7 = (Point) points.get( 6 );

> // Draw the shape with the fill color
> g.fillPolygon( outline );

> // Draw the shapes outline
> g.drawPolygon( outline );

> // Draw the remaining lines
> g.drawLine( p6, p7 );
> g.drawLine( p7, p4 );
> g.drawLine( p7, p2 );
> }

> private List computePoints( Rectangle rect ) {

> List toReturn = new ArrayList();

> int scaleWidth = (int) (rect.width * 0.25);
> int scaleHeight = (int) (rect.height * 0.25);

> Rectangle r1 = new Rectangle( rect.x, rect.y, rect.width -
scaleWidth,
> rect.height - scaleHeight );
> Rectangle r2 = new Rectangle( r1.x + scaleWidth, r1.y +
scaleHeight,
> r1.width, r1.height );

> Point p1 = new Point( r1.x, r1.y );
> Point p2 = new Point( r1.x + r1.width, r1.y );
> Point p3 = new Point( r2.x + r2.width - 1, r2.y );
> Point p4 = new Point( p3.x, r2.y + r2.height - 1 );
> Point p5 = new Point( r2.x, p4.y );
> Point p6 = new Point( r1.x, r1.y + r1.height );
> Point p7 = new Point( p2.x, p6.y );

> toReturn.add( p1 );
> toReturn.add( p2 );
> toReturn.add( p3 );
> toReturn.add( p4 );
> toReturn.add( p5 );
> toReturn.add( p6 );
> toReturn.add( p7 );

> return toReturn;
> }

> /* (non-Javadoc)
> * @see
>
org.eclipse.gmf.runtime.diagram.ui.geoshapes.internal.draw2d .figures.IPolygonAnchorableFigure#getPolygonPoints()
> */
> public PointList getPolygonPoints() {

> List points = computePoints( getBounds() );

> PointList outline = new PointList();
> for( int index = 0; index < 6; index++ ) {
> outline.addPoint( (Point)points.get( index ) );
> }

> // Close the polygon
> outline.addPoint( (Point)points.get( 0 ) );

> return outline;
> }

> }

> Svet Rusev wrote:

>> Hi all,
>> I have a rectangle which extends org.eclipse.draw2d.Figure and I need to
>> transform it to 3d Cube in GEF. How can I easily do that? Does anyone has
>> an example of 3d figures drawn in GEF?
>> Thank you!
Previous Topic:PropertySheet and CelleEditor updates
Next Topic:auto-connnection
Goto Forum:
  


Current Time: Fri Apr 26 03:17:14 GMT 2024

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

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

Back to the top