http://www.jpicedt.org

jpicedt.graphic.model
Class PicPsCurve

java.lang.Object
  extended by jpicedt.graphic.model.AbstractElement
      extended by jpicedt.graphic.model.AbstractCurve
          extended by jpicedt.graphic.model.PicPsCurve
All Implemented Interfaces:
Element, PicMultiCurveConvertable, ActionFactory, CustomizerFactory

public class PicPsCurve
extends AbstractCurve
implements ActionFactory, CustomizerFactory, PicMultiCurveConvertable

A multicurve, either closed or not, going through a set of control points. This is the implementation of the (somewhat obscure) pstricks \pscurve function. There are three coefficients a,b,c altering the curvature.

Since:
jpicedt 1.4pre5
Version:
$Id: PicPsCurve.java,v 1.15 2013/03/27 07:01:24 vincentb1 Exp $
Author:
Vincent Guirardel, Sylvain Reynal

Nested Class Summary
 
Nested classes/interfaces inherited from class jpicedt.graphic.model.AbstractCurve
AbstractCurve.CtrlPtSubsetAbstractCurve, AbstractCurve.CurveToSegment, AbstractCurve.EndSegment, AbstractCurve.LineToSegment, AbstractCurve.PointType, AbstractCurve.Segment
 
Field Summary
protected static int A_SLIDER_MAX
          Max value of curvature coefficient accessible to Jslider in the geometry editor
protected static int A_SLIDER_MIN
          Min value of curvature coefficient accessible to JSlider in the geometry editor
protected static int B_SLIDER_MAX
           
protected static int B_SLIDER_MIN
           
protected static int C_SLIDER_MAX
           
protected static int C_SLIDER_MIN
           
protected  double curvatureA
          Curvature parameters a,b,c of pscurve.
protected  double curvatureB
           
protected  double curvatureC
           
protected static double DEFAULT_CURVATURE_A
          default values for the curvature parameters
protected static double DEFAULT_CURVATURE_B
           
protected static double DEFAULT_CURVATURE_C
           
protected  ArrayList<PicPoint> polygonPts
          An array of PicPoint's backing the geometry of the polygon.
 
Fields inherited from class jpicedt.graphic.model.AbstractCurve
bezierPts, isClosed
 
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, name, parent, view
 
Constructor Summary
PicPsCurve()
          Create a new empty open pscurve, with a default attribute set.
PicPsCurve(boolean closed)
          Create a new empty pscurve, open or closed, with a default attribute set bound to it.
PicPsCurve(boolean closed, PicAttributeSet set)
          Create a new empty pscurve with the given attribute set.
PicPsCurve(PicPoint[] polyPts, boolean closed, double a, double b, double c, PicAttributeSet set)
          Create a new pscurve initialized from the given array of PicPoint's.
PicPsCurve(PicPoint[] polygonPts, boolean closed, PicAttributeSet set)
          Create a new pscurve initialized from the given array of PicPoint's, using the default curvature values.
PicPsCurve(PicPsCurve poly)
          "cloning" constructor (to be used by clone())
 
Method Summary
 void addPoint(int ptIndex, PicPoint pt)
          Inserts the specified point at the specified index.
 void addPoint(PicPoint pt)
          adds the given point at the end of this pscurve.
 PicPsCurve clone()
          Overide Object.clone() method
 PicMultiCurve convertToMultiCurve()
          Convert this PicPsCurve to a PicMultiCurve, by simply relying on the appropriate constructor in class PicMultiCurve.
 ArrayList<PEAction> createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)
          Create an array of Action's related to this object
 AbstractCustomizer createCustomizer()
          Returns a Customizer for geometry editing
 Rectangle2D getBoundingBox(Rectangle2D r)
          Returns the bounding box (ie the surrounding rectangle) in double precision This implementation compute the bb from the union of : the bb as computed by super-class and the smallest rectangle that encompasses all the polygon-points.
 PicPoint getCtrlPt(int numPoint, PicPoint dest)
          Return a copy of the user-controlled point (ie a polygon point, not a bezier point) having the given index.
 double[] getCurvatures()
          Return an array containing the three curvature coefficients in an array, namely [a b c].
 String getDefaultName()
           
 PicPoint[] getFinalControlCurve()
          Return the 4 Bezier points of the final prolongation of the PicPsCurve.
 int getFirstPointIndex()
          Returns the index of the first user-controlled point that can be retrieved by getCtrlPt().
 PicPoint[] getInitialControlCurve()
          Returns the 4 Bezier points of the initial prolongation of the PicPsCurve.
 int getLastPointIndex()
          Returns the index of the last user-controlled point that can be retrieved by getCtrlPt().
protected  PicPoint getPolygonPt(int numPoint)
          Return a reference to the polygon point with the given index.
 void mirror(PicPoint ptOrg, PicVector normalVector)
          Effectue une réflexion sur this relativement à l'axe défini par ptOrg et normalVector.
 void removeLastPoint()
          Remove the last point of this PicPsCurve.
 void removePoint(int pos)
          Remove a point at the given position from this PicPsCurve, then fire a changed-update.
 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 setClosed(boolean state)
          Set close path state, then fires a changed-update.
 void setCtrlPt(int index, PicPoint pt, EditPointConstraint constraint)
          Set the user-controlled point with the given index to the given value.
 void shear(PicPoint ptOrg, double shx, double shy, UserConfirmationCache ucc)
          Shear this Element by the given params wrt to the given origin
 int splitSegment(int segIdx, PicPoint pt)
          Split the given polygon segment (starting from 0), by inserting a new polygon point at the appropriate position.
 String toString()
          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.
 
Methods inherited from class jpicedt.graphic.model.AbstractCurve
createShape, curveTo, diff1CurveTo, diff2CurveTo, getAlternateControlPoint, getBezierPt, getBezierPt, getBezierPtsCount, getBezierPtX, getBezierPtY, getCtrlPtSubset, getIncomingTangent, getMiminalSegmentList, getNearestSubdivisionPoint, getNumberOfSubdivisionPoints, getOutgoingTangent, getPBCBezierIndex, getPBCSegmentIndex, getPointType, getSegmentCount, getShapeBounds2D, hasValidSize, isClosed, isControlPoint, isPolygon, isSmooth, isStraight, isSymmetric, isValidBezierIndex, isValidSegmentIndex, lineTo, pointToSegmentIndex, removeLastSubdivisionPoint, removeSubdivisionPoint, segmentToPointIndex, setBezierPt, splitSegment, syncArrowGeometry
 
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, fireChangedUpdate, getAttribute, getAttributeSet, getDrawing, getName, getParent, getView, pullOutOfGroup, removeView, replaceBy, scale, scale, scale, setAttribute, setAttributeSet, setCtrlPt, setName, setParent, setViewFromFactory, shear
 
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, createShape, getAttribute, getAttributeSet, getCtrlPtSubset, getDrawing, getName, getParent, getView, removeView, replaceBy, scale, scale, scale, setAttribute, setAttributeSet, setCtrlPt, setParent, setViewFromFactory, shear, syncArrowGeometry
 

Field Detail

polygonPts

protected ArrayList<PicPoint> polygonPts
An array of PicPoint's backing the geometry of the polygon. Aka caching mechanism holding a list of user-controlled points.


curvatureA

protected double curvatureA
Curvature parameters a,b,c of pscurve.


curvatureB

protected double curvatureB

curvatureC

protected double curvatureC

DEFAULT_CURVATURE_A

protected static final double DEFAULT_CURVATURE_A
default values for the curvature parameters

See Also:
Constant Field Values

DEFAULT_CURVATURE_B

protected static final double DEFAULT_CURVATURE_B
See Also:
Constant Field Values

DEFAULT_CURVATURE_C

protected static final double DEFAULT_CURVATURE_C
See Also:
Constant Field Values

A_SLIDER_MIN

protected static final int A_SLIDER_MIN
Min value of curvature coefficient accessible to JSlider in the geometry editor

See Also:
Constant Field Values

B_SLIDER_MIN

protected static final int B_SLIDER_MIN
See Also:
Constant Field Values

C_SLIDER_MIN

protected static final int C_SLIDER_MIN
See Also:
Constant Field Values

A_SLIDER_MAX

protected static final int A_SLIDER_MAX
Max value of curvature coefficient accessible to Jslider in the geometry editor

See Also:
Constant Field Values

B_SLIDER_MAX

protected static final int B_SLIDER_MAX
See Also:
Constant Field Values

C_SLIDER_MAX

protected static final int C_SLIDER_MAX
See Also:
Constant Field Values
Constructor Detail

PicPsCurve

public PicPsCurve()
Create a new empty open pscurve, with a default attribute set.


PicPsCurve

public PicPsCurve(boolean closed)
Create a new empty pscurve, open or closed, with a default attribute set bound to it.

Parameters:
closed - whether the pscurve will be closed or not

PicPsCurve

public PicPsCurve(boolean closed,
                  PicAttributeSet set)
Create a new empty pscurve with the given attribute set.

Parameters:
set - attribute set to be bound to this element
closed - whether the generated multi-curve will be closed or not

PicPsCurve

public PicPsCurve(PicPoint[] polyPts,
                  boolean closed,
                  double a,
                  double b,
                  double c,
                  PicAttributeSet set)
Create a new pscurve initialized from the given array of PicPoint's.

Parameters:
polyPts - array of PicPoint's specifying the pscurve geometry.
set - attribute set to be bound to this element
closed - whether the generated multi-curve will be closed or not
a - the a-curvature value
b - the b-curvature value
c - the c-curvature value
Since:
jpicedt 1.4pre5

PicPsCurve

public PicPsCurve(PicPoint[] polygonPts,
                  boolean closed,
                  PicAttributeSet set)
Create a new pscurve initialized from the given array of PicPoint's, using the default curvature values.

Parameters:
polygonPts - array of PicPoint's specifying the polygon geometry.
set - attribute set to be bound to this element
closed - whether the generated multi-curve will be closed or not
Since:
jpicedt 1.4pre5

PicPsCurve

public PicPsCurve(PicPsCurve poly)
"cloning" constructor (to be used by clone())

Parameters:
poly - PicPsCurve to be cloned
Since:
jpicedt 1.4pre5
Method Detail

clone

public PicPsCurve clone()
Overide Object.clone() method

Specified by:
clone in interface Element
Specified by:
clone in class AbstractElement
Since:
jpicedt 1.4pre5

getDefaultName

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

getFirstPointIndex

public int getFirstPointIndex()
Returns the index of the first user-controlled point that can be retrieved by getCtrlPt(). This implementation returns 0.

Specified by:
getFirstPointIndex in interface Element

getLastPointIndex

public int getLastPointIndex()
Returns the index of the last user-controlled point that can be retrieved by getCtrlPt(). This default implementation returns the number of polygon-points minus one.

Specified by:
getLastPointIndex in interface Element

getCtrlPt

public PicPoint getCtrlPt(int numPoint,
                          PicPoint dest)
Return a copy of the user-controlled point (ie a polygon point, not a bezier point) having the given index.
Note: Bezier points may be accessed through a call to getBezierPt() in super class.

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 dest is null, allocates a new PicPoint and return it, otherwise directly modifies dest and returns it as well for convenience.

getPolygonPt

protected final PicPoint getPolygonPt(int numPoint)
Return a reference to the polygon point with the given index. This is equivalent to calling getCtrlPt(int,PicPoint), except that a mere reference is returned.


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
Overrides:
translate in class AbstractCurve
Parameters:
dx - The X coordinate of translation vector
dy - The Y coordinate of translation vector
Since:
PicEdt 1.0

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
Overrides:
scale in class AbstractCurve
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.

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
Overrides:
rotate in class AbstractCurve
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
Overrides:
mirror in class AbstractCurve
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
Overrides:
shear in class AbstractCurve
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.

setCtrlPt

public void setCtrlPt(int index,
                      PicPoint pt,
                      EditPointConstraint constraint)
Set the user-controlled point with the given index to the given value. This implementation sets the value of the polygon-point having the same index, then update the associated Bezier curve, and fires a changed-update event.

Specified by:
setCtrlPt in interface Element
Overrides:
setCtrlPt in class AbstractCurve
Parameters:
constraint - not used so far

addPoint

public void addPoint(PicPoint pt)
adds the given point at the end of this pscurve.

Specified by:
addPoint in class AbstractCurve

addPoint

public void addPoint(int ptIndex,
                     PicPoint pt)
Inserts the specified point at the specified index. Shifts the point currently at that position (if any) and any subsequent points to the right.


splitSegment

public int splitSegment(int segIdx,
                        PicPoint pt)
Split the given polygon segment (starting from 0), by inserting a new polygon point at the appropriate position. then fires a changed-update. For instance, spliting segment "2" yields the following polygon points : 0, 1, 2, insertion pt, 3, 4, etc…

Specified by:
splitSegment in class AbstractCurve
Parameters:
segIdx - index of the polygon segment that must be split.
pt - the PicPoint to be added
Returns:
the index of the user-controlled point which got inserted, according to the indexing scheme of set/getCtrlPt(). This may for instance allow a receiver to control the "new" segment shape by calling setCtrlPt() with this index as a parameter w/o the burden of computing an exact point index (a thing that may depend on the particular implementation of this method).

removePoint

public void removePoint(int pos)
Remove a point at the given position from this PicPsCurve, then fire a changed-update. This shifts any subsequent points to the left.

Nothing is done if this polygon has only one point.

Specified by:
removePoint in class AbstractCurve
Parameters:
pos - index of point to be removed

removeLastPoint

public void removeLastPoint()
Remove the last point of this PicPsCurve. This is a convenience call to removePoint(polygonPts.size()-1)


convertToMultiCurve

public PicMultiCurve convertToMultiCurve()
Convert this PicPsCurve to a PicMultiCurve, by simply relying on the appropriate constructor in class PicMultiCurve.

Specified by:
convertToMultiCurve in interface PicMultiCurveConvertable

getInitialControlCurve

public PicPoint[] getInitialControlCurve()
Returns the 4 Bezier points of the initial prolongation of the PicPsCurve. Used to draw the dotted control line when highlighted.


getFinalControlCurve

public PicPoint[] getFinalControlCurve()
Return the 4 Bezier points of the final prolongation of the PicPsCurve. Used to draw the dotted control line when highlighted.


setClosed

public void setClosed(boolean state)
Set close path state, then fires a changed-update.

Overrides:
setClosed in class AbstractCurve
Parameters:
state - The new closed value
See Also:
AbstractCurve.isClosed()

getCurvatures

public double[] getCurvatures()
Return an array containing the three curvature coefficients in an array, namely [a b c].


getBoundingBox

public Rectangle2D getBoundingBox(Rectangle2D r)
Returns the bounding box (ie the surrounding rectangle) in double precision This implementation compute the bb from the union of :

Specified by:
getBoundingBox in interface Element
Overrides:
getBoundingBox in class AbstractCurve
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.4pre5

toString

public String toString()
Used for debugging purpose.

Overrides:
toString in class AbstractCurve

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 AbstractCurve
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 class: AbstractCurve
Returns a Customizer for geometry editing

Specified by:
createCustomizer in interface CustomizerFactory
Overrides:
createCustomizer in class AbstractCurve
Returns:
A Customizer for geometry editing

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org