http://www.jpicedt.org

jpicedt.graphic.model
Class PicParallelogram

java.lang.Object
  extended by jpicedt.graphic.model.AbstractElement
      extended by jpicedt.graphic.model.PicParallelogram
All Implemented Interfaces:
Element, PicMultiCurveConvertable, ActionFactory, CustomizerFactory
Direct Known Subclasses:
Drawing.BoundingBox, PicEllipse

public class PicParallelogram
extends AbstractElement
implements CustomizerFactory, ActionFactory, PicMultiCurveConvertable

A class implementing a parallelogram. Geometry is fully specified by three corner points (namely, the bottom-left, bottom-right and top-right corners). [SR:TODO] add rounded-corners feature.

Since:
jPicEdt 1.4
Version:
$Id: PicParallelogram.java,v 1.54 2013/10/07 19:16:33 vincentb1 Exp $
Author:
Vincent Guirardel, Sylvain Reynal.

Field Summary
protected  PicVector b2tVec
          see documentation for l2rVec
protected static int[] CTRL_PT_SIDE_BITMAP
           
static int FIRST_PT
          Index of first control-point
protected static int IN_SIDE_B
           
protected static int IN_SIDE_L
           
protected static int IN_SIDE_R
           
protected static int IN_SIDE_T
           
protected  PicVector l2rVec
          "l2rVec" is a vector pointing from P_BL to P_BR (or equally, from P_TL to P_TR) "b2tVec" is a vector pointing from P_BR to P_TR (or equally, from P_BL to P_TL) These two vectors simply define a convenient parallelogram's basis, and are updated by a call to updateParalleloBasis().
static int LAST_PT
          Index of last control-point
static int P_BL
          Bottom-Left corner (also first specification point)
static int P_BR
          Bottom-Right corner (also second specification point)
static int P_CENTER
          Parallelogram's centre
static int P_TL
          Top-Left corner
static int P_TR
          Top-Right corner (also third specification point)
protected  PicPoint ptBL
          Bottom-Left corner (specification point)
protected  PicPoint ptBR
          Bottom-Right corner (specification point)
protected  PicPoint ptTR
          Top-Right corner (specification point)
protected static int SIDE_0
          Numéro du premier côté indéxé
static int SIDE_B
          Bottom side mid-point
static int SIDE_L
          Left side mid-pint
static int SIDE_R
          Right side mid-point
static int SIDE_T
          Top side mid-point
 
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, name, parent, view
 
Constructor Summary
PicParallelogram()
          Creates a new PicParallelogram reduced to (0,0)
PicParallelogram(PicAttributeSet set)
          Creates a new PicParallelogram reduced to (0,0), with the given attribute set
PicParallelogram(PicParallelogram src)
          "cloning" constructor (to be used by clone())
PicParallelogram(PicPoint pt, PicAttributeSet set)
          Create a new PicParallelogram reduced to a point located at the given position
PicParallelogram(PicPoint ptBL, PicPoint ptTR)
          Create a new rectangle with axes parallel to X- and Y-axes, using the 2 given points to build the diagonal, and a default attribute set.
PicParallelogram(PicPoint ptBL, PicPoint ptBR, PicPoint ptTR)
          Create a new PicParallelogram object using the 3 given points as 3 consecutive specification points of the parallelogram (namely BL, BR and TR) and a default attribute set.
PicParallelogram(PicPoint ptBL, PicPoint ptBR, PicPoint ptTR, PicAttributeSet set)
          Create a new PicParallelogram object using the 3 given points as 3 consecutive points of the parallelogram.
PicParallelogram(RectangularShape rect)
          Create a new rectangular PicParallelogram object using the given Rectangle2D.
 
Method Summary
 PicParallelogram clone()
          Overrides Object.clone() method
 PicMultiCurve convertToMultiCurve()
          Return a polygon created from the sides of this parallelogram.
 ArrayList<PEAction> createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)
          Create an array of Action's related to this object
 AbstractCustomizer createCustomizer()
          Returns a customizer (Swing) component
 Shape createShape()
          Returns a GeneralPath that represents the shape of this PicParallelogram.
 PicVector getB2TVec()
           
 Rectangle2D getBoundingBox(Rectangle2D r)
          Returns the bounding box (ie the surrounding rectangle) in double precision Used for instance to determine the arguments of a \\begin{picture} command.
 PicPoint getCenter(PicPoint src)
          Return the parallelogram's centre
 PicPoint getCtrlPt(int numPoint, PicPoint src)
          Return the user-controlled point having the given index.
 CtrlPtSubset getCtrlPtSubset(ConvexZoneGroup csg, BitSet czExtension)
          Renvoie un la partie des points de contrôle qui satisfont à l'un des deux critères suivants: ceux compris dans l'ensemble de zones convexes csg, et ceux en relation avec les points de contrôle satisfaisant au première critère selon une relation définies par czExtension
 String getDefaultName()
           
 int getFirstPointIndex()
          Return the index of the first point that can be retrieved by getPoint
 Double getL2RtoXAxisAngle()
           
 PicVector getL2RVec()
           
 int getLastPointIndex()
          Return the index of the last point that can be retrieved by getPoint
 boolean isRectangle()
          Returns true if this parallelogram is a rectangle
 boolean isXYorYXRectangle()
           
 boolean isXYRectangle()
           
 void makeRectangle()
          Makes this parallelogram a rectangle [pending]
 void makeXYRectangle()
          Makes this parallelogram a rectangle with its sides parallel to the X- and Y-axes.
 void mirror(PicPoint ptOrg, PicVector normalVector)
          Effectue une réflexion sur this relativement à l'axe défini par ptOrg et normalVector.
 void rotate(PicPoint ptOrg, double angle)
          Rotate this Element by the given angle along the given point
 void scale(double ptOrgX, double ptOrgY, double sx, double sy, UserConfirmationCache ucc)
          Scale this object by (sx,sy) using (ptOrgX,ptOrgY) as the origin.
 void setCtrlPt(int index, PicPoint pt)
          Convenience call to setCtrlPt(int, PicPoint, EditPointConstraint) with a null constraint.
 void setCtrlPt(int numPoint, PicPoint pt, EditPointConstraint constraint)
          Set the coordinate of the control-point indexed by "numPoint" to the given value.
 void setGeometry(PicParallelogram para)
          Sets the coordinates of this element from those of the given source.
 void setGeometry(RectangularShape rect)
          Sets the coordinates of this element from the given shape.
 void shear(PicPoint ptOrg, double shx, double shy, UserConfirmationCache ucc)
          Shear this Element by the given params wrt to the given origin.
protected  PicVector toParalleloBasisCoordinates(PicPoint ptOrg, PicPoint ptSrc, PicVector ptDest)
          Compute the contravariant coordinate of the given point "ptSrc" along the "l2r" and "b2t" vectors of the parallelogram's basis, the origin of the basis being set at "ptOrg" This simply reduces to a contravariant change of coordinates from the cartesian basis to the (non-orthonormalized) parallelogram basis.
 String toString()
          Implementation of the Object.toString() method, used for debugging purpose
 void translate(double dx, double dy)
          Translate this Element by (dx,dy) ; this implementation translates the specification-points, then fires a changed-update event.
protected  void updateParalleloBasis()
          Compute the l2r and b2t vectors of the parallelogram basis from the location of the three specification-points of this parallelogram.
 
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, fireChangedUpdate, getAttribute, getAttributeSet, getDrawing, getName, getParent, getView, pullOutOfGroup, removeView, replaceBy, scale, scale, scale, setAttribute, setAttributeSet, setName, setParent, setViewFromFactory, shear, syncArrowGeometry
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jpicedt.graphic.model.Element
anchorPointsIterator, getAttribute, getAttributeSet, getDrawing, getName, getParent, getView, removeView, replaceBy, scale, scale, scale, setAttribute, setAttributeSet, setParent, setViewFromFactory, shear, syncArrowGeometry
 

Field Detail

P_BL

public static final int P_BL
Bottom-Left corner (also first specification point)

See Also:
Constant Field Values

P_BR

public static final int P_BR
Bottom-Right corner (also second specification point)

See Also:
Constant Field Values

P_TR

public static final int P_TR
Top-Right corner (also third specification point)

See Also:
Constant Field Values

P_TL

public static final int P_TL
Top-Left corner

See Also:
Constant Field Values

SIDE_0

protected static final int SIDE_0
Numéro du premier côté indéxé

See Also:
Constant Field Values

SIDE_B

public static final int SIDE_B
Bottom side mid-point

See Also:
Constant Field Values

SIDE_R

public static final int SIDE_R
Right side mid-point

See Also:
Constant Field Values

SIDE_T

public static final int SIDE_T
Top side mid-point

See Also:
Constant Field Values

SIDE_L

public static final int SIDE_L
Left side mid-pint

See Also:
Constant Field Values

P_CENTER

public static final int P_CENTER
Parallelogram's centre

See Also:
Constant Field Values

FIRST_PT

public static final int FIRST_PT
Index of first control-point

See Also:
Constant Field Values

LAST_PT

public static final int LAST_PT
Index of last control-point

See Also:
Constant Field Values

IN_SIDE_B

protected static final int IN_SIDE_B
See Also:
Constant Field Values

IN_SIDE_R

protected static final int IN_SIDE_R
See Also:
Constant Field Values

IN_SIDE_T

protected static final int IN_SIDE_T
See Also:
Constant Field Values

IN_SIDE_L

protected static final int IN_SIDE_L
See Also:
Constant Field Values

CTRL_PT_SIDE_BITMAP

protected static final int[] CTRL_PT_SIDE_BITMAP

ptBL

protected PicPoint ptBL
Bottom-Left corner (specification point)


ptBR

protected PicPoint ptBR
Bottom-Right corner (specification point)


ptTR

protected PicPoint ptTR
Top-Right corner (specification point)


l2rVec

protected PicVector l2rVec
"l2rVec" is a vector pointing from P_BL to P_BR (or equally, from P_TL to P_TR) "b2tVec" is a vector pointing from P_BR to P_TR (or equally, from P_BL to P_TL) These two vectors simply define a convenient parallelogram's basis, and are updated by a call to updateParalleloBasis(). They are used e.g. when moving a corner-point.

An essential function of these vectors is to "retain" the initial parallelogram basis even if the element becomes flat at some point during an edit operation.


b2tVec

protected PicVector b2tVec
see documentation for l2rVec

Constructor Detail

PicParallelogram

public PicParallelogram()
Creates a new PicParallelogram reduced to (0,0)

Since:
jpicedt 1.3.3

PicParallelogram

public PicParallelogram(PicAttributeSet set)
Creates a new PicParallelogram reduced to (0,0), with the given attribute set

Since:
jpicedt 1.3.3

PicParallelogram

public PicParallelogram(PicPoint ptBL,
                        PicPoint ptBR,
                        PicPoint ptTR)
Create a new PicParallelogram object using the 3 given points as 3 consecutive specification points of the parallelogram (namely BL, BR and TR) and a default attribute set.

Since:
jpicedt 1.4

PicParallelogram

public PicParallelogram(PicPoint ptBL,
                        PicPoint ptBR,
                        PicPoint ptTR,
                        PicAttributeSet set)
Create a new PicParallelogram object using the 3 given points as 3 consecutive points of the parallelogram.

Since:
jpicedt 1.3.3

PicParallelogram

public PicParallelogram(PicPoint ptBL,
                        PicPoint ptTR)
Create a new rectangle with axes parallel to X- and Y-axes, using the 2 given points to build the diagonal, and a default attribute set.

Since:
jpicedt 1.4

PicParallelogram

public PicParallelogram(PicPoint pt,
                        PicAttributeSet set)
Create a new PicParallelogram reduced to a point located at the given position

Since:
jpicedt 1.3.3

PicParallelogram

public PicParallelogram(PicParallelogram src)
"cloning" constructor (to be used by clone())

Parameters:
src - The PicParallelogram object to clone
Since:
jpicedt 1.3.3

PicParallelogram

public PicParallelogram(RectangularShape rect)
Create a new rectangular PicParallelogram object using the given Rectangle2D.

Since:
jpicedt 1.5
Method Detail

clone

public PicParallelogram clone()
Overrides Object.clone() method

Specified by:
clone in interface Element
Specified by:
clone in class AbstractElement
Since:
jpicedt 1.3.3

getDefaultName

public String getDefaultName()
Specified by:
getDefaultName in class AbstractElement
Returns:
a localised string that represents this object's name
Since:
jpicedt 1.3.3

getCtrlPt

public PicPoint getCtrlPt(int numPoint,
                          PicPoint src)
Return the user-controlled point having the given index. The general contract in Element is to return an IMMUTABLE instance of PicPoint, so that the only way to alter the geometry of this element is by calling the setCtrlPt method.

Specified by:
getCtrlPt in interface Element
Parameters:
numPoint - the point index, should be greater or equal to the value returned by getFirstPointIndex, and lower or equal to getLastPointIndex.
Returns:
the point indexed by numPoint ; if src is null, allocates a new PicPoint and return it, otherwise directly modifies src and returns it as well for convenience.

getFirstPointIndex

public int getFirstPointIndex()
Return the index of the first point that can be retrieved by getPoint

Specified by:
getFirstPointIndex in interface Element

getLastPointIndex

public int getLastPointIndex()
Return the index of the last point that can be retrieved by getPoint

Specified by:
getLastPointIndex in interface Element

updateParalleloBasis

protected void updateParalleloBasis()
Compute the l2r and b2t vectors of the parallelogram basis from the location of the three specification-points of this parallelogram.

Since:
jpicedt 1.3.3

toParalleloBasisCoordinates

protected PicVector toParalleloBasisCoordinates(PicPoint ptOrg,
                                                PicPoint ptSrc,
                                                PicVector ptDest)
Compute the contravariant coordinate of the given point "ptSrc" along the "l2r" and "b2t" vectors of the parallelogram's basis, the origin of the basis being set at "ptOrg" This simply reduces to a contravariant change of coordinates from the cartesian basis to the (non-orthonormalized) parallelogram basis.
To wind up : denoting OM = vec(ptOrg → ptSrc), (e1,e2) the cartesian basis (ie std model-coordinates), and (x',y') the new coords in the (l2r,b2t) basis, yields :
OM = x e1 + y e2 = x' l2r + y' b2t.
Change of coordinates is carried out by using elementary geometry. This yields :
where e3 denotes the z-axis unit vector of the (x,y,z) direct diedra.

Note that updateParalleloBasis must be called beforehands for this method to return a valid results [SR:pending] need to be cleaned up.

Parameters:
ptOrg - origin of parallelogram's basis
ptSrc - source point whose coordinates have to be converted
ptDest - if null, gets allocated and returned for convenience ; besides, it is perfectly safe to call this method with ptDest and one of ptOrg or ptSrc referencing the same PicPoint.
Returns:
the new coordinates (x',y') along (l2r,b2t), encapsulated in a PicVector
Since:
jpicedt 1.3.3

setCtrlPt

public void setCtrlPt(int numPoint,
                      PicPoint pt,
                      EditPointConstraint constraint)
Set the coordinate of the control-point indexed by "numPoint" to the given value. The control-policy for the default (null or DEFAULT) constraint is as follows :

The SQUARE constraint imposes that the parallelogram be a square. The square diagonal is computed from the current control-point and its opposite corner. Other spec' points are set accordingly.

The CENTER_FIXED constraint imposes that the parallelogram center be kept fixed. Spec' points are set accordingly.

Specified by:
setCtrlPt in interface Element
Parameters:
numPoint - one of P_TL, P_TR, P_BL, P_BR, SIDE_T, SIDE_B, SIDE_L, SIDE_R or P_CENTER.
constraint - either null or one of PicParallelogram.EditConstraint
Since:
jpicedt 1.3.3

setCtrlPt

public void setCtrlPt(int index,
                      PicPoint pt)
Convenience call to setCtrlPt(int, PicPoint, EditPointConstraint) with a null constraint.

Specified by:
setCtrlPt in interface Element
Overrides:
setCtrlPt in class AbstractElement

setGeometry

public void setGeometry(PicParallelogram para)
Sets the coordinates of this element from those of the given source. This methods fires a DrawingEvent.

Since:
jpicedt 1.5

setGeometry

public void setGeometry(RectangularShape rect)
Sets the coordinates of this element from the given shape. This methods fires a DrawingEvent.

Since:
jpicedt 1.5

getCenter

public PicPoint getCenter(PicPoint src)
Return the parallelogram's centre

Returns:
if src is null, allocates a new PicPoint and return it, otherwise directly modifies src and returns it as well for convenience.
Since:
jpicedt 1.3.3

rotate

public void rotate(PicPoint ptOrg,
                   double angle)
Rotate this Element by the given angle along the given point

Specified by:
rotate in interface Element
Parameters:
angle - rotation angle in radians

mirror

public void mirror(PicPoint ptOrg,
                   PicVector normalVector)
Effectue une réflexion sur this relativement à l'axe défini par ptOrg et normalVector.

Specified by:
mirror in interface Element
Parameters:
ptOrg - le PicPoint par lequel passe l'axe de réflexion.
normalVector - le PicVector normal à l'axe de réflexion.

shear

public void shear(PicPoint ptOrg,
                  double shx,
                  double shy,
                  UserConfirmationCache ucc)
Shear this Element by the given params wrt to the given origin.

Specified by:
shear in interface Element
ucc - une valeur UserConfirmationCache permettant de demander à l'utilisateur confirmation, de se souvenir de la dernière confirmation qu'il a donné, ou de ses préférences.

scale

public void scale(double ptOrgX,
                  double ptOrgY,
                  double sx,
                  double sy,
                  UserConfirmationCache ucc)
Scale this object by (sx,sy) using (ptOrgX,ptOrgY) as the origin. This implementation simply apply a scaling transform to all specification-points. Note that sx and sy may be negative. This method eventually fires a changed-update event.

Specified by:
scale in interface Element
ucc - une valeur UserConfirmationCache permettant de demander à l'utilisateur confirmation, de se souvenir de la dernière confirmation qu'il a donné, ou de ses préférences.

translate

public void translate(double dx,
                      double dy)
Translate this Element by (dx,dy) ; this implementation translates the specification-points, then fires a changed-update event.

Specified by:
translate in interface Element
Parameters:
dx - The X coordinate of translation vector
dy - The Y coordinate of translation vector
Since:
PicEdt 1.0

getCtrlPtSubset

public CtrlPtSubset getCtrlPtSubset(ConvexZoneGroup csg,
                                    BitSet czExtension)
Description copied from interface: Element
Renvoie un la partie des points de contrôle qui satisfont à l'un des deux critères suivants:
  1. ceux compris dans l'ensemble de zones convexes csg, et
  2. ceux en relation avec les points de contrôle satisfaisant au première critère selon une relation définies par czExtension

Specified by:
getCtrlPtSubset in interface Element
Overrides:
getCtrlPtSubset in class AbstractElement
Parameters:
csg - l'ensemble de zones convexes auquel on teste l'appartenance des points de contrôles
czExtension - ignoré
Returns:
null
Since:
jPicEdt 1.6
See Also:
jpicedt.graphic.model

convertToMultiCurve

public PicMultiCurve convertToMultiCurve()
Return a polygon created from the sides of this parallelogram.

Specified by:
convertToMultiCurve in interface PicMultiCurveConvertable
Since:
jpicedt 1.3.3

isRectangle

public boolean isRectangle()
Returns true if this parallelogram is a rectangle


makeRectangle

public void makeRectangle()
Makes this parallelogram a rectangle [pending]


isXYRectangle

public boolean isXYRectangle()
Returns:
true si le parallélogramme est rectangle, et que l'axe (BL, BR) est parallèle à l'axe des x, et l'axe (BL, TL) à l'axe des y.

isXYorYXRectangle

public boolean isXYorYXRectangle()
Returns:
true si le parallélogramme est rectangle, et que l'un de ses axes est parallèle à l'axe des x, et l'autre à l'axe des y.

getL2RtoXAxisAngle

public Double getL2RtoXAxisAngle()
Returns:
l'angle en radian que fait l'axe de (BL, BR) relativement à l'axe des x.
Since:
jPicEdt 1.6

getL2RVec

public final PicVector getL2RVec()
Returns:
le vecteur (BL, BR).
Since:
jPicEdt 1.6

getB2TVec

public final PicVector getB2TVec()
Returns:
le vecteur (BR, TR).
Since:
jPicEdt 1.6

makeXYRectangle

public void makeXYRectangle()
Makes this parallelogram a rectangle with its sides parallel to the X- and Y-axes. [pending]


createShape

public Shape createShape()
Returns a GeneralPath that represents the shape of this PicParallelogram.

Specified by:
createShape in interface Element
Overrides:
createShape in class AbstractElement

getBoundingBox

public Rectangle2D getBoundingBox(Rectangle2D r)
Returns the bounding box (ie the surrounding rectangle) in double precision Used for instance to determine the arguments of a \\begin{picture} command.

This implementation compute the bounding-box from the smallest rectangle that encompasses all the specification-points.

Specified by:
getBoundingBox in interface Element
Returns:
the bounding box (i.e. the surrounding rectangle) in double precision Used e.g. to determine the arguments of the \\begin{picture} command. If r is null, allocate a new rectangle and returns it. Otherwise the source rectangle is modified and returned for convenience. [todo:reynal] this really need to be improved : this method would probably better be moved to the attached view, since the latter knows exactly what the TRUE bounding box is.
Since:
jpicedt 1.3.3

toString

public String toString()
Implementation of the Object.toString() method, used for debugging purpose

Overrides:
toString in class AbstractElement

createActions

public ArrayList<PEAction> createActions(ActionDispatcher actionDispatcher,
                                         ActionLocalizer localizer,
                                         HitInfo hi)
Create an array of Action's related to this object

Specified by:
createActions in interface ActionFactory
Overrides:
createActions in class AbstractElement
Parameters:
actionDispatcher - dispatches events to the proper PECanvas
localizer - i18n localizer for PEAction's
hi - une HitInfo contenant les informations relatives à l'évènement-souris qui a déclencher le menu contextuel.

createCustomizer

public AbstractCustomizer createCustomizer()
Description copied from interface: CustomizerFactory
Returns a customizer (Swing) component

Specified by:
createCustomizer in interface CustomizerFactory
Returns:
a Customizer for geometry editing
Since:
jpicedt 1.4

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org