http://www.jpicedt.org

jpicedt.graphic.model
Class PicMultiCurve

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

public class PicMultiCurve
extends AbstractCurve
implements CustomizerFactory, PicMultiCurveConvertable

PicMultiCurve is basically an AbstractCurve where each subdivision point has additionnal features regarding 2nd-order smoothness and symmetry. These features, however, are dynamic in the sense that they may be enforced by passing geometric constraints to the setCtrlPt() method instead of having them tightly bound to the class. Besides, setSmooth() and setSymmetric() methods may be used to dynamically enforce these features w/o having to move control-points.

Since:
jpicedt 1.3.3
Version:
$Id: PicMultiCurve.java,v 1.45 2013/03/27 07:01:44 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
 
Fields inherited from class jpicedt.graphic.model.AbstractCurve
bezierPts, isClosed
 
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, name, parent, view
 
Constructor Summary
PicMultiCurve()
          Create a new empty open multi curve, with a default attribute set.
PicMultiCurve(boolean closed)
          Create a new empty multi curve, with a default attribute set.
PicMultiCurve(boolean closed, PicAttributeSet set)
          Create a new empty multi curve with the given set of attribute
PicMultiCurve(PicMultiCurve curve)
          "cloning" constructor (to be used by clone())
PicMultiCurve(PicPoint pt1)
          Create a new open multi curve reduced to the given point, and a default attribute set.
PicMultiCurve(PicPoint[] bezierPts, PicAttributeSet set)
          Create a new multi-curve filled with the given array of PicPoint's, each segment being a curved Bezier segment.
PicMultiCurve(PicPoint pt1, PicAttributeSet set)
          Create a new open multi curve reduced to the given point, and the given attribute set
PicMultiCurve(PicPoint pt1, PicPoint pt2)
          Create a new line, i.e. a new straight open curve using the two given points, and a default attribute set.
PicMultiCurve(PicPoint pt1, PicPoint pt2, PicAttributeSet set)
          Create a new straight open multi curve with the two given points, and the given attribute set.
PicMultiCurve(PicPoint pt1, PicPoint ctrl1, PicPoint ctrl2, PicPoint pt2)
          Create an open single cubic bezier curve from the four given points, and a default attribute set.
PicMultiCurve(PicPsCurve curve)
          Constructor for conversion of PicPsCurve into PicMultiCurve.
PicMultiCurve(PicSmoothPolygon poly)
          Constructor for conversion of PicSmoothPolygon into PicMultiCurve.
 
Method Summary
 void addPoint(PicPoint pt)
          Adds a new subdivision point to the end of this curve.
 PicMultiCurve clone()
          Override Object.clone() method.
 PicMultiCurve convertToMultiCurve()
          converts this ELement to a PicMultiCurve, i.e., itself (no copy).
 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
 void curveTo(PicPoint ptCtrl1, PicPoint ptCtrl2, PicPoint ptEnd)
          If this curve if OPEN and NON-EMPTY, adds the given points (2 control points and an endpoint) to the end of the curve, then fire a GEOMETRY_CHANGE event.
 double distance(PicMultiCurve other)
          Returns the shortest distance b/w the end-points of this curve and those of the given one.
 PicMultiCurveConvertable fetchClosestCurve(Collection l)
          Returns the curve in the given collection that is closest to this one in the sense of the distance() method.
 PicPoint getCtrlPt(int numPoint, PicPoint dest)
          Return a copy of the user-controlled point having the given index.
 String getDefaultName()
           
 int getFirstPointIndex()
          Returns the index of the first user-controlled point that can be retrieved by getCtrlPt().
 int getLastPointIndex()
          Returns the index of the last user-controlled point that can be retrieved by getCtrlPt().
 void join(PicMultiCurveConvertable c)
          Join this curve and the given Element after proper conversion of the latter to a PicMultiCurve, by appending the control points of the given curve to this one.
static void main(String[] args)
          Pour faire des tests de debug.
 void mirror(PicPoint ptOrg, PicVector normalVector)
          Effectue une réflexion sur this relativement à l'axe défini par ptOrg et normalVector.
 void removePoint(int index)
          Removes the point with the given index from this curve.
 void removeSubdivisionPoint(int subdivIndex)
          Removes a subdivision point from this curve, together with its two neighbouring control points.
 void reverseIndexing()
          Reverse the order in which points are stored in the protected bezierPts array.
 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)
          Scale this object by (sx,sy) using (ptOrgX,ptOrgY) as the origin.
 void setClosed(boolean state)
          close or open this curve, that is, remove or add an end-point.
 void setCtrlPt(int index, PicPoint pt, EditPointConstraint constraint)
          Set the coordinates of a Bezier point having the given index to the given location, possibly moving other control-points according to the given constraint.
 void setSmooth()
          changes the smoothness feature of all the subdivision points at once.
 void setSmooth(int subdivIndex)
          Forces the smoothness feature of the given subdivision point by moving alternate control-points.
 void setStraight()
          Straighten ALL segments (ie make this curve a polygon).
 void setStraight(int segIndex)
          changes the straightness feature for the given segment by making its control- and end-points identical.
 void setSymmetric()
          force the symmetry feature of all the subdivision points at once.
 void setSymmetric(int subdivIndex)
          Force the SYMMETRY feature of the given subdivision point.
 void shear(PicPoint ptOrg, double shx, double shy)
          Shear this Element by the given params wrt to the given origin
 int splitSegment(int seg_idx, PicPoint pt)
          Adds a new point to a (maybe curved) segment then fires a changed-update.
 String toString()
          Return a string 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, diff1CurveTo, diff2CurveTo, getAlternateControlPoint, getBezierPt, getBezierPt, getBezierPtsCount, getBezierPtX, getBezierPtY, getBoundingBox, getCtrlPtSubset, getIncomingTangent, getMiminalSegmentList, getNearestSubdivisionPoint, getNumberOfSubdivisionPoints, getOutgoingTangent, getPBCBezierIndex, getPBCSegmentIndex, getPointType, getSegmentCount, getShapeBounds2D, hasValidSize, isClosed, isControlPoint, isPolygon, isSmooth, isStraight, isSymmetric, isValidBezierIndex, isValidSegmentIndex, lineTo, pointToSegmentIndex, removeLastSubdivisionPoint, scale, segmentToPointIndex, setBezierPt, shear, splitSegment, syncArrowGeometry
 
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, fireChangedUpdate, getAttribute, getAttributeSet, getDrawing, getName, getParent, getView, pullOutOfGroup, removeView, replaceBy, scale, scale, setAttribute, setAttributeSet, setCtrlPt, setName, setParent, setViewFromFactory
 
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, getBoundingBox, getCtrlPtSubset, getDrawing, getName, getParent, getView, removeView, replaceBy, scale, scale, scale, setAttribute, setAttributeSet, setCtrlPt, setParent, setViewFromFactory, shear, syncArrowGeometry
 

Constructor Detail

PicMultiCurve

public PicMultiCurve()
Create a new empty open multi curve, with a default attribute set.


PicMultiCurve

public PicMultiCurve(boolean closed)
Create a new empty multi curve, with a default attribute set.

Parameters:
closed - whether this curve is closed or not

PicMultiCurve

public PicMultiCurve(boolean closed,
                     PicAttributeSet set)
Create a new empty multi curve with the given set of attribute

Parameters:
closed - whether this curve is closed or not
set - attribute set to be bound to this element

PicMultiCurve

public PicMultiCurve(PicPoint pt1)
Create a new open multi curve reduced to the given point, and a default attribute set.


PicMultiCurve

public PicMultiCurve(PicPoint pt1,
                     PicAttributeSet set)
Create a new open multi curve reduced to the given point, and the given attribute set


PicMultiCurve

public PicMultiCurve(PicPoint pt1,
                     PicPoint pt2)
Create a new line, i.e. a new straight open curve using the two given points, and a default attribute set.


PicMultiCurve

public PicMultiCurve(PicPoint pt1,
                     PicPoint pt2,
                     PicAttributeSet set)
Create a new straight open multi curve with the two given points, and the given attribute set.


PicMultiCurve

public PicMultiCurve(PicPoint pt1,
                     PicPoint ctrl1,
                     PicPoint ctrl2,
                     PicPoint pt2)
Create an open single cubic bezier curve from the four given points, and a default attribute set.


PicMultiCurve

public PicMultiCurve(PicPoint[] bezierPts,
                     PicAttributeSet set)
Create a new multi-curve filled with the given array of PicPoint's, each segment being a curved Bezier segment. Smoothness and symmetry properties are automatically asserted by checking if the given points do satisfy them.


PicMultiCurve

public PicMultiCurve(PicSmoothPolygon poly)
Constructor for conversion of PicSmoothPolygon into PicMultiCurve.

Parameters:
poly - The PicSmoothPolygon to be converted

PicMultiCurve

public PicMultiCurve(PicPsCurve curve)
Constructor for conversion of PicPsCurve into PicMultiCurve.

Parameters:
curve - The PicPsCurve to be converted

PicMultiCurve

public PicMultiCurve(PicMultiCurve curve)
"cloning" constructor (to be used by clone())

Parameters:
curve - The curve to be cloned.
Method Detail

clone

public PicMultiCurve clone()
Override Object.clone() method.

Specified by:
clone in interface Element
Specified by:
clone in class AbstractElement

getDefaultName

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

convertToMultiCurve

public PicMultiCurve convertToMultiCurve()
converts this ELement to a PicMultiCurve, i.e., itself (no copy).

Specified by:
convertToMultiCurve in interface PicMultiCurveConvertable

distance

public double distance(PicMultiCurve other)
Returns the shortest distance b/w the end-points of this curve and those of the given one.

Since:
jpicedt 1.4pre5

fetchClosestCurve

public PicMultiCurveConvertable fetchClosestCurve(Collection l)
Returns the curve in the given collection that is closest to this one in the sense of the distance() method. In case of two or more curves being equally close to this one, the first occurence in the collection is returned.

Parameters:
l - a list of PicMultiCurveConvertable's ; l may contain this curve, in which case it's simply skipped.
Returns:
null if l doesn't contain any PicMultiCurveConvertable.
Since:
jpicedt 1.4pre5

getFirstPointIndex

public int getFirstPointIndex()
Returns the index of the first user-controlled point that can be retrieved by getCtrlPt(). This default 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 specification points minus one.

Specified by:
getLastPointIndex in interface Element

reverseIndexing

public void reverseIndexing()
Reverse the order in which points are stored in the protected bezierPts array. If the curve is open, this results in the origin being swapped with the last point, etc… May be useful when, e.g., joining two curves.

Since:
jpicedt 1.4pre5

join

public void join(PicMultiCurveConvertable c)
Join this curve and the given Element after proper conversion of the latter to a PicMultiCurve, by appending the control points of the given curve to this one. The order in which points are appended, i.e., wheter an index-reverse takes place before appending (see reverseIndexing()), is such that both curves get joined along their shortest path. If both curves are not in contact, a segment is added between them (through a call to lineTo()).

Since:
jpicedt 1.4pre5

getCtrlPt

public PicPoint getCtrlPt(int numPoint,
                          PicPoint dest)
Return a copy of the user-controlled point having the given index. If src is null, allocates a new PicPoint and return it, otherwise directly modifies src and returns it as well for convenience.

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 index ; if dest is null, concrete implementation of this method should allocate a new PicPoint and return it, otherwise directly modify dest and return it as well for convenience.

setCtrlPt

public void setCtrlPt(int index,
                      PicPoint pt,
                      EditPointConstraint constraint)
Set the coordinates of a Bezier point having the given index to the given location, possibly moving other control-points according to the given constraint. Available constraints are :
SMOOTHNESS
enforces smoothness at nearby subdivision-point when moving a control-point ; N/A otherwise
SYMMETRY
enforces symmetry at nearby subdivision-point when moving a control-point ; N/A otherwise
SMOOTHNESS_SYMMETRY
a combination of both.
FREELY
control-points are freely moved w/o any constraint being put on alternate control-points
null (default)
only the given point index gets moved ; this is aka editing a single specification point. This is applicable for both subdivision- and control-points.
Except in the default case, subdivision-points generally "drag" their control-points with them, with the exception of straight-segment end-points which need a somewhat more complex handling.

Specified by:
setCtrlPt in interface Element
Overrides:
setCtrlPt in class AbstractCurve
constraint - not used here

addPoint

public void addPoint(PicPoint pt)
Adds a new subdivision point to the end of this curve. As far as control-points location goes, a SMOOTHNESS_SYMMETRY constraint is imposed (which as a nice side-effect results in the added segment automagically inheriting its "straightness" property from the last segment of the original curve).
This implementation relies on lineTo() and curveTo() methods.

Specified by:
addPoint in class AbstractCurve

curveTo

public void curveTo(PicPoint ptCtrl1,
                    PicPoint ptCtrl2,
                    PicPoint ptEnd)
If this curve if OPEN and NON-EMPTY, adds the given points (2 control points and an endpoint) to the end of the curve, then fire a GEOMETRY_CHANGE event.
If the curve is closed, you should use splitSegment instead, since this method does nothing in this case ;-)

Overrides:
curveTo in class AbstractCurve
Parameters:
ptCtrl1 - first control point of the new Bezier segment
ptCtrl2 - second control point of the new Bezier segment
ptEnd - second end-point of the new Bezier segment

splitSegment

public int splitSegment(int seg_idx,
                        PicPoint pt)
Adds a new point to a (maybe curved) segment then fires a changed-update. Control-points are computed automagically.

Specified by:
splitSegment in class AbstractCurve
Parameters:
seg_idx - index of the segment to be split
pt - point at which segment is to be split
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).

removeSubdivisionPoint

public void removeSubdivisionPoint(int subdivIndex)
Removes a subdivision point from this curve, together with its two neighbouring control points. This shifts any ensuing points to the "left", and creates a new segment by concatenating dangling control-points. Nothing is done if this curve is reduced to a single point.
If both neighbouring segments had the same straightness value beforehands, the latter property is simply inherited by the new segment. Otherwise, we set it to false as this is the more flexible approach.

This method fires a DrawingEvent of type GEOMETRY_CHANGE..

Overrides:
removeSubdivisionPoint in class AbstractCurve
Parameters:
subdivIndex - index of the subdivision point to be removed with respect to the SUBDIVISION point numbering scheme, e.g. 0 for the first subdivision point (= first curve end-point).

removePoint

public void removePoint(int index)
Removes the point with the given index from this curve. If this is a subdivision point, we simply delegate to removeSubdivisionPoint. Else, this means removing a control point, and we just "straighten" the corresponding segment end-point by moving the control-point to the location of the nearest subdivision-point (hence this has no effect on straight segments).
This method fires a DrawingEvent of type GEOMETRY_CHANGE.

Specified by:
removePoint in class AbstractCurve
Parameters:
index - any valid control- or subdivision- index to be removed

setClosed

public void setClosed(boolean state)
close or open this curve, that is, remove or add an end-point.
This methods fires a DrawingEvent of type GEOMETRY_CHANGE .

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

setSmooth

public void setSmooth(int subdivIndex)
Forces the smoothness feature of the given subdivision point by moving alternate control-points.
If one neightbouring segment is straight, it imposes the location of the alternate control.
If both segments are straight, this method can't do anything unfortunately.
If both segments are curved, the resulting tangent is computed from the external bissector of both control vectors, yet retaining norm of control-vectors.
This method fires a drawing-event of type GEOMETRY_CHANGE.

Parameters:
subdivIndex - index of the subdivision point, e.g. 0,1,2... for the 1st,2nd,3rd,... subdivision point.

setSmooth

public void setSmooth()
changes the smoothness feature of all the subdivision points at once. This method indirectly calls setSmooth(int), hence fires drawing-events of type GEOMETRY_CHANGE.


setSymmetric

public void setSymmetric(int subdivIndex)
Force the SYMMETRY feature of the given subdivision point. This is straightforwardly carried out by setting the length of both control-vectors to their "mean value". This method does nothing if at least one neighbouring segment is straight.

Parameters:
subdivIndex - index of the subdivision point, e.g. 0,1,2... for the 1st,2nd,3rd,... subdivision point.

setSymmetric

public void setSymmetric()
force the symmetry feature of all the subdivision points at once. This method indirectly calls setSymmetric(int), hence fires drawing-events of type GEOMETRY_CHANGE.


setStraight

public void setStraight(int segIndex)
changes the straightness feature for the given segment by making its control- and end-points identical. We then force smoothness on each end-point depending on the "old" smoothness value, that is, before straightening this segment.


setStraight

public void setStraight()
Straighten ALL segments (ie make this curve a polygon). This method indirectly calls setStraight(int), hence fires drawing-events of type GEOMETRY_CHANGE.


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)
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 AbstractElement

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)
Shear this Element by the given params wrt to the given origin

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

toString

public String toString()
Return a string 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()
Returns a Customizer for geometry editing

Specified by:
createCustomizer in interface CustomizerFactory
Overrides:
createCustomizer in class AbstractCurve

main

public static void main(String[] args)
Pour faire des tests de debug.

Since:
jPicEdt 1.5.2

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org