Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

PolygonShapeEditor Class Reference

a class to edit a PolygonShape by interpreting user interactions. More...

#include <PolygonShapeEditor.h>

List of all members.

Public Methods

Constructing/deconstructing
Properties and information retrieval
Event handlers

Public Slots

Signals

Private Methods

abstracted user actions
private utility function

Private Attributes


Detailed Description

This class is supposed to do th actual creating/editing of the contour lines represented by an instance of PolygonShape.

This is my new Implenetation of the old PolygonShapeEditor. This new version makes full use of the enhanced Features of the new PolygonShape class. As a result, here are some highlights of the new variant:

Note:
Now follows a very detailed description of how the Interpreter figures out what ever the user is intending to do. I doubt that anyone besides me is realy interested in the gory details, but i put it down aswell, just to make sure i know what the editor should act like, and how far we are away from it. So please everybody feel free to skip this part ;-)

STATEs and MODEs: There are currently four state variables to reflect the current state of interpretation:

Todo:
Only rectangular regions are implemented so far. The code for spherical regions is implemented, but needs testing and adaequat UI representation

Interpretation of User Interactions: From the Interpretors point of view, there are five basic things the user can do apart from the usual things like asking stupid questions or looking concerned due to serious damage or criticizing this imaculate artwork of software: He can

This is how the interpreter decides what to do: Imagine the interpreter as some kind of state machine (DFA) Its initial state is IS_READY In State IS_TRANSFORM In State IS_DRAW In State IS_REGION In State IS_CANCEL


Constructor & Destructor Documentation

PolygonShapeEditor::PolygonShapeEditor ( QWidget * parent = 0,
const char * name = 0,
WFlags fl = 0 )
 

This will create an editor instance.

Note:
All parameters will be passed to the QWidget constructor. Please note that initialy no PolygonShape is set, so editing is only possible after seting it with setShape(PolygonShape *)

Todo:
Have to check if mShape is null. Right now, no such check is performed, which could lead to seg faults if the user tries to edit a shape before pointing the editor to it.

PolygonShapeEditor::~PolygonShapeEditor ( )
 

Does nothing.


Member Function Documentation

void PolygonShapeEditor::setRadius ( float r ) [slot]
 

Sets the radius of the nodes. A node will be regarded as "under the mouse" if the distance between this node and the mouse coordinates is equal or less than radius

Parameters:
r   the new radius
See also:
getRadius(), mRadius

void PolygonShapeEditor::setRestricted ( bool preserve = true ) [slot]
 

Parameters:
preserve   if true, restricted mode is enabled
See also:
getRestricted(), mRestricted

void PolygonShapeEditor::setEditMode ( int mode ) [slot]
 

Parameters:
mode   the new edit mode. Should be one of the modes mentioned at getEditMode()
See also:
getEditMode(), mEditMode

void PolygonShapeEditor::setRegionMode ( int mode ) [slot]
 

Parameters:
mode   the new region mode. Should be one of the modes mentioned at getRegionMode()
See also:
getRegionMode(), mRegionMode

void PolygonShapeEditor::nextEditMode ( ) [slot]
 

This is usefull for instance to connect WheelEvents to it

void PolygonShapeEditor::previousEditMode ( ) [slot]
 

This is usefull for instance to connect WheelEvents to it

void PolygonShapeEditor::editModeChanged ( int mode ) [signal]
 

Parameters:
mode   the new edit mode

void PolygonShapeEditor::regionModeChanged ( int mode ) [signal]
 

Parameters:
mode   the new region mode

void PolygonShapeEditor::shapeChanged ( ) [signal]
 

This signal is emitted on every modification done to the nodes/edges of the current PolygonShape. Use this to decide when to redraw the shape.

void PolygonShapeEditor::setShape ( PolygonShape * s )
 

tells the Editor to edit the PolygonShape pointed at by s

PolygonShape * PolygonShapeEditor::getShape ( )
 

Returns:
a pointer to the PolygonShape currently edited by this editor

float PolygonShapeEditor::getRadius ( )
 

The size of a node specifies the radius of its sensitive area. A node will be regarded as beeing "under the mouse" if the position of the mouse pointer is within a distance from the node's position smaller than or equal to this radius.

Returns:
the virtual radius (aka size) of the nodes

bool PolygonShapeEditor::getRestricted ( )
 

while being in restirced mode, the editor will only allow isomorph modifications of the edited PolygonShape, i.e. all operation that would modify the shape's topology are be prohibited. In paritcular, no nodes/edges will be added/removed, while by the editor.

Note:
restricted mode is what is typicaly desired during waping. As our warping algorithms rely on on the fact that the original and the transformed shape are isomorph to each other, adding or removing nodes during this phase could lead to unpredictable results.
Returns:
true if the editor is currently in restricted mode

int PolygonShapeEditor::getEditMode ( )
 

Returns:
the current transformation mode of the editor. the returned value is one of MODE_DRAW, MODE_TRANSLATE, MODE_SCALE, MODE_ROTATE

int PolygonShapeEditor::getRegionMode ( )
 

Returns:
the current region mode. The returned value is one of the returned value is REGION_BOX or REGION_CIRCLE

QPopupMenu * PolygonShapeEditor::getPopup ( )
 

The editor is equiped with a popup menu that will show when you click the right mouse button while in state IS_READY. In this menu the user may choose the edit mode, the region mode and is given the oporunity to remove all selected nodes from the shape being edited. You can retrieve a pointer to this popup to make it available at different locations within your application.

Returns:
a pointer to the popup menu used in this editor

VECTOR3D PolygonShapeEditor::getCenter ( )
 

Returns:
the origin assumed for rotation/scalation

Edge PolygonShapeEditor::getEditEdge ( )
 

Actualy their are two slightly different semantics connected to this method:

  • during the drawing of a strip, the current Edge is returned
  • while doing a region select, this will return an edge consisting of the start point (where the button was pressed) and the current mouse position. Use this to draw a box, or a circle (first point is center), or what ever you feel like.
Returns:
an Edge composed of the two points.

int PolygonShapeEditor::getEditorState ( )
 

This might be usefull to decide what to draw (or not to draw) during rendering. You might for example want to draw the selection box during a region select.

Returns:
the current state of the editor. The returned value will be one of STATE_READY, STATE_DRAWING_STRIP, STATE_TRANSLATING, STATE_SCALING, STATE_ROTATING, STATE_SELECTING_CIRCLE, STATE_SELECTING_BOX

void PolygonShapeEditor::glPanelMoveEvent ( QMouseEvent * e,
VECTOR3D point )
 

Parameters:
e   the QMouseEvent representing this event
point   the mouse position in 3-D space. Please Note that the editor does nothing to asure that this is on the image plane. So projection to this plane (if desired!) and the like should be done BEFORE passing the position to this method

void PolygonShapeEditor::glPanelPressEvent ( QMouseEvent * e,
VECTOR3D point )
 

Parameters:
e   the QMouseEvent representing this event
point   the mouse position in 3-D space. Please Note that the editor does nothing to asure that this is on the image plane. So projection to this plane (if desired!) and the like should be done BEFORE passing the position to this method

void PolygonShapeEditor::glPanelReleaseEvent ( QMouseEvent * e,
VECTOR3D point )
 

Parameters:
e   the QMouseEvent representing this event
point   the mouse position in 3-D space. Please Note that the editor does nothing to asure that this is on the image plane. So projection to this plane (if desired!) and the like should be done BEFORE passing the position to this method

void PolygonShapeEditor::doTransform ( VECTOR3D point ) [private]
 

this method will pass point on to the apropriate transformation method, determined by the value of mEditMode

Parameters:
point   the mouse position. will be passed on to the apropriate transformation method.
See also:
doTranslate(VECTOR3D), doScale(VECTOR3D), doRotate(VECTOR3D)

void PolygonShapeEditor::finishTransform ( ) [private]
 

this method will call the apropriate transformation method, determined by the value of mEditMode

See also:
finishTranslate(), finishScale(), finishRotate()

void PolygonShapeEditor::cancelTransform ( ) [private]
 

this method will call the apropriate transformation method, determined by the value of mEditMode

See also:
cancelTranslate(), cancelScale(), cancelRotate()

void PolygonShapeEditor::doRegion ( VECTOR3D point ) [private]
 

this method will pass point on to the apropriate region select method, determined by the value of mRegionMode

Parameters:
point   the mouse position. will be passed on to the apropriate method.
See also:
doBox(VECTOR3D), doCircle(VECTOR3D)

void PolygonShapeEditor::finishRegion ( ) [private]
 

this method will call the apropriate region select method, determined by the value of mRegionMode

See also:
finishBox(), finishCircle()

void PolygonShapeEditor::cancelRegion ( ) [private]
 

this method will call the apropriate region select method, determined by the value of mRegionMode

See also:
cancelBox(), cancelCircle()

int PolygonShapeEditor::doStrip ( VECTOR3D point ) [private]
 

You can leeeave your hat on...;-) Hehe, nasty you! No, not what you think. This starts or continues drawing a strip of lines.

Returns:
the value returned by PolygonShape::continueStrip(VECTOR3D)

int PolygonShapeEditor::finishStrip ( VECTOR3D point ) [private]
 

Finish a Strip, taking point as the last point.

Returns:
the value returned by PolygonShape::continueStrip(VECTOR3D)

int PolygonShapeEditor::cancelStrip ( ) [private]
 

Cancels a strip, that is, the current line is not added.

Returns:
the key of the node last added to the strip.

VECTOR3D PolygonShapeEditor::doTranslate ( VECTOR3D point ) [private]
 

starts or continues translations of selected nodes

Parameters:
point   the position of the mouse. the translation is calculated so that the mouse positoin before the start of scalation is mapped exactly to the current mouse position.
Returns:
a VECTOR3D representing the difference of the new position to the positions before the call of this method

VECTOR3D PolygonShapeEditor::finishTranslate ( ) [private]
 

Returns:
a VECTOR3D representing the total difference of the new node positions to the positions before the beginnung of the translation

VECTOR3D PolygonShapeEditor::cancelTranslate ( ) [private]
 

resets selected nodes to their old positions.

Returns:
a VECTOR3D representing the total difference of the positions the node would had before canceling the translation to the positions before the beginnung of the translation

VECTOR3D PolygonShapeEditor::doScale ( VECTOR3D point ) [private]
 

starts or continues scaling of selected nodes

Parameters:
point   the position of the mouse. the factors are calculated so that the mouse positoin before the start of scalation is mapped exactly to the current mouse position.
Returns:
a VECTOR3D containing the factors along each axis that where applied by this method call.

VECTOR3D PolygonShapeEditor::finishScale ( ) [private]
 

Returns:
a VECTOR3D containing the total factors along each axis that were aplied since the begining of the scalation.

VECTOR3D PolygonShapeEditor::cancelScale ( ) [private]
 

resets selected nodes to their old positions.

Returns:
a VECTOR3D containing the factors along each axis that would have been applied since the begining of scalation if the user hadn't canceled.

float PolygonShapeEditor::doRotate ( VECTOR3D point ) [private]
 

starts or continues rotating along the z axis

Note:
theoreticaly there would be no problem to alow another axis But actualy i din't see the point in that regarding our situation. Apart that, i wouldn't know how to communicate this to the user.
Parameters:
point   the position of the mouse. the angle is calculated so that the mouse positoin before the start of scalation is mapped exactly to the current mouse position.
Returns:
the angle about which the selected points are rotated during this method call.

float PolygonShapeEditor::finishRotate ( ) [private]
 

Returns:
the total angle applied since the beginning of the rotation

float PolygonShapeEditor::cancelRotate ( ) [private]
 

resets selected nodes to their old positions.

Returns:
the total angle that would have been applied if the user hadn't canceled

void PolygonShapeEditor::doBox ( VECTOR3D point ) [private]
 

Parameters:
point   if the selection has just started, this will be the first corner of the box. Otherwise it will be the opposite corner

void PolygonShapeEditor::finishBox ( ) [private]
 

everything in the marked rectangluar region becomes selected

void PolygonShapeEditor::cancelBox ( ) [private]
 

selection is left unchanged

void PolygonShapeEditor::doCircle ( VECTOR3D point ) [private]
 

Parameters:
point   if selection has just started, this will be the center of the spheric region. Otherwise, the distance between this point an the center will be taken as the radius of the region.

void PolygonShapeEditor::finishCircle ( ) [private]
 

everything in the spheric region becomes selected

void PolygonShapeEditor::cancelCircle ( ) [private]
 

selection is left unchanged

int PolygonShapeEditor::findNode ( VECTOR3D point ) [private]
 

Returns:
the key of a node which is under the mouse or -1 if there is no such node.

VECTOR3D PolygonShapeEditor::getFactors ( VECTOR3D from,
VECTOR3D to ) [private]
 

calculates facors that map the components of from to their pendants in to. This method is need in doScale(VECTOR3D) to set up the transformation matrix

Returns:
a VECTOR3D containing the three factors

float PolygonShapeEditor::radians ( VECTOR3D v ) [private]
 

Returns:
the polar angel of v in radians

float PolygonShapeEditor::getAngle ( VECTOR3D from,
VECTOR3D to ) [private]
 

calculate the angle between two line going from mCenter to from and from mCenter to to

Returns:
the angle between this lines at mCenter

void PolygonShapeEditor::fillMatrix ( float * matrix ) [private]
 

fills a float[16] array so it represents 4x4 Identity

Parameters:
matrix   should point to memory big enough to store a float[16] array

void PolygonShapeEditor::translate ( float * matrix,
VECTOR3D t ) [private]
 

alters matrix to represent an translation.

Parameters:
matrix   is assumed to represent 4x4 Identity as produced by fillMatrix(float *)
t   the VECTOR3D along which the translation should accure

void PolygonShapeEditor::rotate ( float * matrix,
VECTOR3D c,
float rad ) [private]
 

alters matrix to represent a rotation around an axis oriented by the line R*(0,0,1) + c along angle angle rad

Parameters:
matrix   is assumed to represent 4x4 Identity as produced by fillMatrix(float *)
c   the center assumed for the rotation
rad   the rotation angle in radians

void PolygonShapeEditor::scale ( float * matrix,
VECTOR3D c,
VECTOR3D s ) [private]
 

alters a matrix to represent an affine scalation with moved origin

Parameters:
matrix   is assumed to represent 4x4 Identity as produced by fillMatrix(float *)
c   the center assumed for the rotation
s   a VECTOR3D holding the three factors


Member Data Documentation

QPopupMenu * PolygonShapeEditor::mPopup [private]
 

See also:
getPopup()

int PolygonShapeEditor::mState [private]
 

See also:
getEditorState

int PolygonShapeEditor::mIState [private]
 

This holds the state in which the interpretation has currently reached The value of mIStae is always one of the following: IS_READY, IS_TRANSFORM, IS_REGION, IS_DRAW, IS_CANCEL

int PolygonShapeEditor::mEditMode [private]
 

See also:
getEditMode()

int PolygonShapeEditor::mRegionMode [private]
 

See also:
getRegionMode()

VECTOR3D PolygonShapeEditor::mCenter [private]
 

See also:
getCenter(), setCenter(VECTOR3D)

float PolygonShapeEditor::mRadius [private]
 

See also:
getRadius()

PolygonShape * PolygonShapeEditor::mShape [private]
 

A pointer to the Shape that is to be edited. Maybe null.

See also:
getShape(), setShape(PolygonShape *)

bool PolygonShapeEditor::mRestricted [private]
 

See also:
getRestricted(), setRestricted(bool)

bool PolygonShapeEditor::mDeselectLast [private]
 

OK, i admitt, this is a hack. It solves the following problem:

if the user shift-clicks on a node, that is selected and immediatly after this begins a transformation, it is assumed,that he/she did not actualy want to deselect the node. On the other hand, if no translation accurs, he propably wants to deselect the node. So we have to remember if the node should be deselected again on mouse up.

Yust keep it like this ;-=)

int PolygonShapeEditor::mLastKey [private]
 

the key of the node that was selected before a transformation

See also:
mDeselectLast


The documentation for this class was generated from the following file:
Generated at Fri Apr 19 16:53:06 2002 for GLFramework by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001