Package jpicedt.graphic.model
Class PicMultiCurve
- java.lang.Object
-
- jpicedt.graphic.model.AbstractElement
-
- jpicedt.graphic.model.DefaultLeafElement
-
- jpicedt.graphic.model.AbstractCurve
-
- jpicedt.graphic.model.PicMultiCurve
-
- All Implemented Interfaces:
Element,PicMultiCurveConvertable,PicObjectConstants,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 thesetPoint()method instead of having them tightly bound to the class. Besides,setSmooth()andsetSymmetric()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.28.2.1 2007/09/02 11:56:27 reynal Exp $
- Author:
- Vincent Guirardel, Sylvain Reynal
-
-
Field Summary
Fields Modifier and Type Field Description static BasicEditPointConstraintFREELYpredefined constraint for setPoint()static BasicEditPointConstraintSMOOTHNESSpredefined constraint for setPoint()static BasicEditPointConstraintSYMMETRYpredefined constraint for setPoint()-
Fields inherited from class jpicedt.graphic.model.AbstractCurve
FIRST_CURVE_END_POINT, FIRST_SEGMENT_CONTROL_POINT, INVALID_POINT_INDEX, isClosed, LAST_CURVE_END_POINT, SECOND_SEGMENT_CONTROL_POINT, SUBDIVISION_POINT
-
Fields inherited from class jpicedt.graphic.model.DefaultLeafElement
nodeConnections, nodeName, pts
-
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, parent, view
-
Fields inherited from interface jpicedt.graphic.model.PicObjectConstants
ARROW_GLOBAL_SCALE_LENGTH, ARROW_GLOBAL_SCALE_WIDTH, ARROW_INSET_SCALE, ARROW_LENGTH_SCALE, ARROW_WIDTH_LINEWIDTH_SCALE, ARROW_WIDTH_MINIMUM_MM, BRACKET_LENGTH_SCALE, CROSSHATCH, CROSSHATCH_FILLED, DASH_OPAQUE, DASH_TRANSPARENT, DASH1, DASH2, DASH3, DASHED, DIMEN, DOT_SEP, DOT_SEP1, DOT_SEP2, DOT_SEP3, DOTTED, DOUBLE_COLOR, DOUBLE_LINE, DOUBLE_SEP, FILL_COLOR, FILL_STYLE, HATCH_ANGLE, HATCH_COLOR, HATCH_SEP, HATCH_WIDTH, HLINES, HLINES_FILLED, INNER, LEFT_ARROW, LINE_COLOR, LINE_STYLE, LINE_WIDTH, MIDDLE, NONE, OUTER, OVER_STRIKE, OVER_STRIKE_COLOR, OVER_STRIKE_WIDTH, POLYDOTS_ANGLE, POLYDOTS_CIRCLE, POLYDOTS_DISK, POLYDOTS_PENTAGON, POLYDOTS_PENTAGON_FILLED, POLYDOTS_PLUS, POLYDOTS_SCALE_H, POLYDOTS_SCALE_V, POLYDOTS_SIZE_LINEWIDTH_SCALE, POLYDOTS_SIZE_MINIMUM_MM, POLYDOTS_SQUARE, POLYDOTS_SQUARE_FILLED, POLYDOTS_STYLE, POLYDOTS_SUPERIMPOSE, POLYDOTS_TRIANGLE, POLYDOTS_TRIANGLE_FILLED, PS_POINT, PST_CUSTOM, RBRACKET_LENGTH_SCALE, RIGHT_ARROW, SHADOW, SHADOW_ANGLE, SHADOW_COLOR, SHADOW_SIZE, SOLID, TBAR_WIDTH_LINEWIDTH_SCALE, TBAR_WIDTH_MINIMUM_MM, TEXT_BOX_CIRCLE, TEXT_BOX_NO_FRAME, TEXT_BOX_OVAL, TEXT_BOX_RECTANGLE, TEXT_FRAME, TEXT_HALIGN_CENTER, TEXT_HALIGN_LEFT, TEXT_HALIGN_RIGHT, TEXT_HOR_ALIGN, TEXT_ROTATION, TEXT_VALIGN_BASELINE, TEXT_VALIGN_BOTTOM, TEXT_VALIGN_CENTER, TEXT_VALIGN_TOP, TEXT_VERT_ALIGN, VLINES, VLINES_FILLED
-
-
Constructor Summary
Constructors Constructor Description 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 attributePicMultiCurve(PicMultiCurve curve)"cloning" constructor (to be used by clone())PicMultiCurve(PicPsCurve curve)constructor for conversion of pscurve into multiCurvePicMultiCurve(PicSmoothPolygon poly)constructor for conversion of smoothPoly into multiCurvePicMultiCurve(PicPoint pt1)Create a new open multi curve reduced to the given point, and a default attribute set.PicMultiCurve(PicPoint[] pts, 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 setPicMultiCurve(PicPoint pt1, PicPoint pt2)Create a new line, i.e.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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPoint(PicPoint pt)Adds a new subdivision point to the end of this curve.java.lang.Objectclone()Override Object.clone() methodPicMultiCurveconvertToMultiCurve()converts this ELement to a PicMultiCurve, i.e., itself (no copy).PEAction[]createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)Create an array of Action's related to this objectAbstractCustomizercreateCustomizer()Returns a Customizer for geometry editingvoidcurveTo(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 usesplitSegmentinstead, since this method does nothing in this case ;-)doubledistance(PicMultiCurve other)Returns the shortest distance b/w the end-points of this curve and those of the given one.PicMultiCurveConvertablefetchClosestCurve(java.util.Collection l)Returns the curve in the given collection that is closest to this one in the sense of the distance() method.java.lang.StringgetName()Returns a non-localised string representing this object's name This default implementation returns the class name.voidjoin(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.voidremovePoint(int index)Removes the point with the given index from this curve.voidremoveSubdivisionPoint(int subdivIndex)Removes a subdivision point from this curve, together with its two neighbouring control points.voidreverseIndexing()Reverse the order in which points are stored in the protected pts array.voidsetClosed(boolean state)close or open this curve, that is, remove or add an end-point.
This methods fires a DrawingEvent of type GEOMETRY_CHANGE .voidsetPoint(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.voidsetSmooth()changes the smoothness feature of all the subdivision points at once.voidsetSmooth(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.voidsetStraight()Straighten ALL segments (ie make this curve a polygon).voidsetStraight(int segIndex)changes the straightness feature for the given segment by making its control- and end-points identical.voidsetSymmetric()force the symmetry feature of all the subdivision points at once.voidsetSymmetric(int subdivIndex)Force the SYMMETRY feature of the given subdivision point.intsplitSegment(int seg_idx, PicPoint pt)Adds a new point to a (maybe curved) segment then fires a changed-update.java.lang.StringtoString()Return a string for debugging purpose.-
Methods inherited from class jpicedt.graphic.model.AbstractCurve
getAlternateControlPoint, getIncomingTangent, getNearestSubdivisionPoint, getNumberOfSegments, getNumberOfSubdivisionPoints, getOutgoingTangent, getPBCBezierIndex, getPBCSegmentIndex, getPointType, getShapeBounds2D, getSpecificationPoint, hasValidSize, isClosed, isControlPoint, isPolygon, isSmooth, isStraight, isSymmetric, isValidBezierIndex, isValidSegmentIndex, lineTo, pointToSegmentIndex, removeLastSubdivisionPoint, segmentToPointIndex, splitSegment
-
Methods inherited from class jpicedt.graphic.model.DefaultLeafElement
addConnection, fireChangedUpdate, forwardChangedUpdate, getAllowsChildren, getBoundingBox, getFirstPointIndex, getLastPointIndex, getNodeName, getNumberOfSpecificationPoints, getPoint, getPoint, getPointX, getPointY, getSpecificationPoint, getSpecificationPointX, getSpecificationPointY, isNode, isNodeable, iterator, nodeConnectionOrigin, nodeReferencePoint, nodeReferencePointX, nodeReferencePointY, removeAllConnections, removeConnection, rotate, scale, setNodeName, setPoint, setSpecificationPoint, shear, translate
-
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, getAttribute, getAttributeSet, getDrawing, getParent, getView, removeView, scale, setAttribute, setAttributeSet, setParent, setViewFromFactory
-
-
-
-
Field Detail
-
SYMMETRY
public static final BasicEditPointConstraint SYMMETRY
predefined constraint for setPoint()
-
SMOOTHNESS
public static final BasicEditPointConstraint SMOOTHNESS
predefined constraint for setPoint()
-
FREELY
public static final BasicEditPointConstraint FREELY
predefined constraint for setPoint()
-
-
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 notset- 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[] pts, PicAttributeSet set)
Create a new multi-curve filled with the given array of PicPoint's, each segment being a curved Bezier segment.- if the number of points mod 3 equals 0, then it will be closed.
- if the number of points mod 3 equals 1 then the curve will be open,
- if the number of points mod 3 equals 2, curve is open and last segment is a straight one.
-
PicMultiCurve
public PicMultiCurve(PicSmoothPolygon poly)
constructor for conversion of smoothPoly into multiCurve- Parameters:
poly- the smoothPoly to be converted
-
PicMultiCurve
public PicMultiCurve(PicPsCurve curve)
constructor for conversion of pscurve into multiCurve- Parameters:
poly- the PsCurve 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 java.lang.Object clone()
Override Object.clone() method- Specified by:
clonein interfaceElement- Overrides:
clonein classDefaultLeafElement
-
getName
public java.lang.String getName()
Description copied from class:DefaultLeafElementReturns a non-localised string representing this object's name This default implementation returns the class name.- Specified by:
getNamein interfaceElement- Overrides:
getNamein classDefaultLeafElement- 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:
convertToMultiCurvein interfacePicMultiCurveConvertable
-
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(java.util.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
-
reverseIndexing
public void reverseIndexing()
Reverse the order in which points are stored in the protected pts 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
-
setPoint
public void setPoint(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.and(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.
- Specified by:
setPointin interfaceElement- Overrides:
setPointin classAbstractCurveconstraint- not used here- See Also:
EditPointConstraintCollator
-
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 and 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 onlineTo()andcurveTo()methods.- Specified by:
addPointin classAbstractCurve
-
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 usesplitSegmentinstead, since this method does nothing in this case ;-)- Overrides:
curveToin classAbstractCurve- Parameters:
ptCtrl1- first control point of the new Bezier segmentptCtrl2- second control point of the new Bezier segmentptEnd- 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:
splitSegmentin classAbstractCurve- Parameters:
seg_idx- index of the segment to be splitpt- 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/getPoint(). This may for instance allow a receiver to control the "new" segment shape by calling setPoint() 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:
removeSubdivisionPointin classAbstractCurve- Parameters:
index- 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 toremoveSubdivisionPoint. 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:
removePointin classAbstractCurve- 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:
setClosedin classAbstractCurve- Parameters:
state- The new close value
-
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.
-
toString
public java.lang.String toString()
Return a string for debugging purpose.- Overrides:
toStringin classAbstractCurve
-
createActions
public PEAction[] createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)
Create an array of Action's related to this object- Specified by:
createActionsin interfaceActionFactory- Overrides:
createActionsin classAbstractCurve- Parameters:
actionDispatcher- dispatches events to the proper PECanvaslocalizer- i18n localizer for PEAction'shi- a HitInfo containing information related to the mouse-event which triggered the popup menu.
-
createCustomizer
public AbstractCustomizer createCustomizer()
Returns a Customizer for geometry editing- Specified by:
createCustomizerin interfaceCustomizerFactory- Overrides:
createCustomizerin classAbstractCurve
-
-