nodershp.h

Go to the documentation of this file.
00001 // $Id: nodershp.h 1776 2007-06-27 11:16:49Z luke $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 /*
00100 */
00101 
00102 
00103 #ifndef INC_NODEREGSHAPE
00104 #define INC_NODEREGSHAPE
00105 
00106 //#include "doccoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "docrect.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "paths.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "trans2d.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "pathshap.h" //For the PathShape typedef enum - in camtypes.h [AUTOMATICALLY REMOVED]
00112 
00113 const UINT32 REGULARSHAPE_MINSIDES = 3;
00114 const UINT32 REGULARSHAPE_MAXSIDES = 99;
00115 
00116 const double QUICKSHAPE_RADIUS_TOLERANCE=100.0;
00117 const double QUICKSHAPE_ANGLE_TOLERANCE=0.02;   //Approximately one degree (remember that 2 PI radians = approx 6 radians = 360 degrees)
00118 const INT32 QUICKSHAPE_SCALARPRODUCT_TOLERANCE=1000;    //The square of the radius tolerance
00119 
00120 /*********************************************************************************************
00121 
00122 < ShapeClickEffect
00123 
00124     Comment:    Used to indicate 'areas of excitment' within a regular shape.  If nothing
00125                 excites the shape then SHAPE_CLICK_NONE is used.
00126 
00127 **********************************************************************************************/ 
00128 
00129 enum ShapeClickEffect { SHAPECLICK_NONE, SHAPECLICK_EDGE1,  SHAPECLICK_EDGE2, SHAPECLICK_CURVECHORD,
00130                         SHAPECLICK_CENTRE, SHAPECLICK_ELLIPSE, SHAPECLICK_RECTANGLE, SHAPECLICK_PRIMARY,
00131                         SHAPECLICK_STELLATION, SHAPECLICK_PRIMARYCURVE, SHAPECLICK_STELLATIONCURVE };
00132 
00133 
00134 /***********************************************************************************************
00135 
00136 >   class NodeRegularShape : public NodeSimpleShape
00137 
00138     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00139     Created:    16/11/94
00140     Purpose:    A NodeRegularShape represents an regularly shaped object.  It encompasses
00141                 NodeSimpleShape (but is not derived from it as it needs to do more things)
00142 
00143 ***********************************************************************************************/
00144 
00145 class NodeRegularShape : public NodeRenderableInk
00146 {
00147 // Give my name out in memory dumps
00148 CC_DECLARE_DYNCREATE(NodeRegularShape);
00149 
00150 // friend classes used to import and export regular shapes to and from the new file format.
00151 // friend class CXaraFileRegularShape;
00152 // friend class RegularShapeRecordHandler;
00153 // friend class EllipseRecordHandler;
00154 // friend class RectangleRecordHandler;
00155 // friend class PolygonRecordHandler;
00156 
00157 public:
00158     NodeRegularShape(); 
00159     ~NodeRegularShape(); 
00160     
00161     NodeRegularShape(Node* ContextNode,  
00162                 AttachNodeDirection Direction,  
00163                 BOOL Locked = FALSE, 
00164                 BOOL Mangled = FALSE,  
00165                 BOOL Marked = FALSE, 
00166                 BOOL Selected = FALSE    
00167               );
00168 
00169     // Initialise the shape
00170     BOOL SetUpShape();
00171     virtual Node* SimpleCopy();
00172     void CopyNodeContents(NodeRegularShape* NodeCopy);
00173     virtual void PolyCopyNodeContents(NodeRenderable* pNodeCopy);
00174 
00175     // virtual Functions to deal with bounding boxes
00176     virtual DocRect GetBoundingRect(BOOL DontUseAttrs=FALSE, BOOL HitTest=FALSE);
00177     virtual DocRect GetBlobBoundingRect();
00178 
00179     // Rendering Functions
00180     BOOL BuildShapePath(Path** RenderPath);
00181     virtual void Render( RenderRegion* pRender );
00182     virtual void RenderEorDrag( RenderRegion* );
00183     virtual void PreExportRender( RenderRegion* pRender ); 
00184     virtual BOOL ExportRender( RenderRegion* pRender ); 
00185 
00186     // Selection functions.
00187     virtual void RenderObjectBlobs(RenderRegion* pRender);
00188     virtual void RenderTinyBlobs(RenderRegion* pRender);
00189 
00190     // Functions to transform the shape
00191     virtual void Transform( TransformBase& );
00192     virtual void TransformCentreAndAxes( TransformBase& );
00193 
00194     // Information functions
00195     virtual UINT32 GetNodeSize() const;             // Returns size of node in bytes
00196     virtual String Describe(BOOL Plural, BOOL Verbose);
00197     ShapeClickEffect DetermineClickEffect(DocCoord* PointerPos, Spread* pSpread, INT32* pPointNum, DocCoord* pStart = NULL, DocCoord* pEnd = NULL);
00198  
00199     // Make Shapes functions
00200     virtual BOOL CanBecomeA(BecomeA* pBecomeA);
00201     virtual BOOL DoBecomeA(BecomeA* pBecomeA);
00202 
00203     // check to see if we have a variable width stroke applied to us, and get the real path
00204     virtual NodePath* GetVariableWidthStrokePath();
00205     virtual NodePath* GetSmoothVariableWidthStrokePath();
00206 
00207     // Debugging function
00208     #ifdef _DEBUG
00209         void    ShowDebugTreeDetails() const;
00210     #endif
00211     void GetDebugDetails( StringBase* Str );
00212 
00213     // Functions to deal with messages
00214     virtual BOOL OnClick( DocCoord, ClickType, ClickModifiers, Spread*);
00215     BOOL OnToolClick( DocCoord, ClickType, ClickModifiers, Spread*);
00216     virtual BOOL OnNodePopUp(Spread* pSpread, DocCoord PointerPos, ContextMenu* pMenu);
00217 
00218     // The natty Snap functions
00219     virtual BOOL Snap(DocCoord* pDocCoord);
00220     virtual BOOL Snap(DocRect* pDocRect,const DocCoord& PrevCoord,const DocCoord& CurCoord);
00221     virtual BOOL SnapToCoords(DocCoord* pDocCoord);
00222 
00223     virtual BOOL IsARegularShape() const;
00224     virtual double GetRotationAngle();
00225 
00226     // Various helper functions
00227 public:
00228     void PositionPointFromRatio(DocCoord* PosPoint, const DocCoord* EndPoint, const double Ratio);
00229     BOOL BuildPolygonPoints(DocCoord** pArray, INT32* NumPoints = NULL);
00230 
00231     BOOL MakeRectangle(const INT32 Width, const INT32 Height, const INT32 CurvatureRadius);
00232     BOOL MakeEllipse(const INT32 Width, const INT32 Height);
00233 
00234     // Curvature building functions
00235     double GetMajorRadiusSize();
00236 
00237 protected:
00238     void DeleteCachedPath();
00239     void InitialiseMemberVars();
00240 
00241 private:
00242     BOOL MakeRegular(DocCoord RegularPoint);
00243     BOOL MakeStraight(BOOL StraightenOne);
00244     BOOL ToggleCurvature();
00245     BOOL InsertShapeEdge(Path* RenderPath, Path* Edge, DocCoord NewEnd);
00246     BOOL BuildEllipsePath(Path* RenderPath);
00247     BOOL BuildPolygonPath(Path* RenderPath, DocCoord* PointsArray);    
00248     BOOL SmoothCurvatureJoin(Path* RenderPath, DocCoord* Coords, INT32 Index, BOOL MoveLeft); 
00249     void EmergencyFixShape();
00250 
00251     BOOL ClickEllipse(DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods, Spread* pSpread, BOOL DragCentre); 
00252     BOOL ClickCentre(DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods, Spread* pSpread); 
00253     BOOL ClickPrimary(DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods, Spread* pSpread, BOOL DragCentre); 
00254     BOOL ClickStellation(DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods, Spread* pSpread); 
00255     BOOL ClickPCurve(DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods, Spread* pSpread, DocCoord Start, DocCoord End); 
00256     BOOL ClickSCurve(DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods, Spread* pSpread, DocCoord Start, DocCoord End); 
00257     BOOL ClickEdge(DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods, Spread* pSpread, BOOL EdgeOne); 
00258 
00259 public:
00260     // Access functions
00261     UINT32  GetNumSides() const;
00262     void    SetNumSides(UINT32 NewNumSides);
00263     BOOL    IsCircular() const;
00264     void    SetCircular(BOOL Value);
00265     BOOL    IsStellated() const;
00266     void    SetStellated(BOOL Value);
00267     BOOL    IsPrimaryCurvature() const;
00268     void    SetPrimaryCurvature(BOOL Value); 
00269     BOOL    IsStellationCurvature() const;
00270     void    SetStellationCurvature(BOOL Value);
00271     double  GetStellRadiusToPrimary() const;
00272     void    SetStellRadiusToPrimary(double Value);
00273     double  GetPrimaryCurveToPrimary() const;
00274     void    SetPrimaryCurveToPrimary(double Value);
00275     double  GetStellCurveToStell() const;
00276     void    SetStellCurveToStell(double Value);
00277     double  GetStellationRatio() const;
00278     void    SetStellationRatio(double Value);
00279     void    SetCentrePoint(DocCoord Value);
00280     void    SetMinorAxes(DocCoord Value);
00281     void    SetMajorAxes(DocCoord Value);
00282     DocCoord GetCentrePoint();
00283     DocCoord GetMajorAxes();
00284     DocCoord GetMinorAxes();
00285     DocCoord GetUTCentrePoint() const   {return UTCentrePoint;};
00286     DocCoord GetUTMajorAxes() const     {return UTMajorAxes;};
00287     DocCoord GetUTMinorAxes() const     {return UTMinorAxes;};
00288     void    GetTransformMatrix(Matrix* store) const;
00289     void    SetTransformMatrix(const Matrix* newmatrix);
00290 
00291     BOOL IsARectangle() const;
00292     
00293     INT32 GetRectWidth();
00294     INT32 GetRectHeight();
00295 
00296     inline void InvalidateCache()                   {PathCacheInvalid = TRUE;};
00297     BOOL IsReformed();
00298 
00299     // Data vars
00300 public:
00301     // The paths are public to allow people to party all over them easily.
00302     Path    EdgePath1;          // First edge path from primary point to stellation point
00303     Path    EdgePath2;          // Second edge path from stellation point to primary point (not uses if not stellated)
00304 
00305 protected:
00306     UINT32  NumSides;           // Number of sides the shape has (gives primary angle) (unused if IsCircular)
00307     BOOL    Circular : 1;       // TRUE if the shape is based on a circle
00308     BOOL    Stellated : 1;      // TRUE if the shape is stellated.
00309     BOOL    PrimaryCurvature : 1;       // TRUE if there is primary curvature
00310     BOOL    StellationCurvature : 1;    // TRUE if there is stellation curvature
00311     double  StellRadiusToPrimary;   // Ratio of stellation radius to primary radius (unused if not stellated)
00312     double  PrimaryCurveToPrimary;  // Ratio of primary curvature radius to primary radius (unused if none)
00313     double  StellCurveToStell;      // Ratio of stellation curvature radius to stellation radius (unused if none)
00314     double  StellOffsetRatio;       // The ratio of the stellation offset (+-0.5 = 360/NumSides)
00315 
00316     // These values could be calculated on the fly, but are cached for speed
00317     DocCoord    UTCentrePoint;      // Centre point of the shape
00318     DocCoord    UTMajorAxes;        // Major axes from centre to the bounding ellipse
00319     DocCoord    UTMinorAxes;        // Minor axes from centre to the bounding ellipse
00320     Path*   CachedRenderPath;
00321     BOOL    PathCacheInvalid : 1;
00322     Matrix  TransformMatrix;
00323 
00324 // Version 2 file format functions
00325 public:
00326     virtual BOOL WritePreChildrenWeb(BaseCamelotFilter* pFilter);
00327     virtual BOOL WritePreChildrenNative(BaseCamelotFilter* pFilter);
00328 
00329     //PathShape functions (Graham 29/4/97)
00330 public:
00331     PathShape GetPathShape();
00332 
00333     BOOL IsRotated();
00334     BOOL AxesAreEqual();
00335     BOOL AxesArePerpendicular();
00336 
00337     virtual INT32 EstimateNodeComplexity (OpParam* details);
00338 
00339     // Karim MacDonald 25/11/1999
00340     // Extend functions.
00341     // Note that if a sub-class returns TRUE from IsTypeExtendible, it must
00342     // also provide complete implementations of ValidateExtend and Extend,
00343     // which should usually check/extend its children.
00344 public:
00345     virtual BOOL IsTypeExtendible() const { return TRUE; }
00346     virtual DocRect ValidateExtend(const ExtendParams& ExtParams);
00347     virtual void Extend(const ExtendParams& ExtParams);
00348 };
00349 
00350 
00351 #endif  // NODEREGSHAPE

Generated on Sat Nov 10 03:46:06 2007 for Camelot by  doxygen 1.4.4