grid.h

Go to the documentation of this file.
00001 // $Id: grid.h 1282 2006-06-09 09:46:49Z alex $
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 // NodeGrid header
00099 
00100 #ifndef INC_GRID_H
00101 #define INC_GRID_H
00102 
00103 //#include "npaper.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "doccolor.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 //#include "units.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 
00107 // The following enum defines the eight select blobs of a grid in a specific way. These values are used to
00108 // reference the coords available from NodeGrid::GetBlobCoords.
00109 //
00110 // Some code relies on the way the enum is defined...
00111 //
00112 //  Each grid has eight select blobs, four corner points and four mid line points
00113 //  The four corner   points are numbered 0 to 3 in a clockwise direction around the grid rectangle
00114 //  The four mid line points are numbered 4 to 7 in a clockwise direction around the grid rectangle
00115 //  NoGridBlob must be negative
00116 //  BottomLeft must be 0
00117 //  LeftMiddle must be 4
00118 enum GridBlobType
00119 {
00120     NoGridBlob = -1,
00121     BottomLeft,
00122     TopLeft,
00123     TopRight,
00124     BottomRight,
00125 
00126     LeftMiddle,
00127     TopMiddle,
00128     RightMiddle,
00129     BottomMiddle,
00130 
00131     NumGridBlobTypes
00132 };
00133 
00134 struct GridFlagsType                // Grid flags type definition
00135 {
00136     BOOL    Selected        : 1;    // TRUE if selected by grid tool
00137     BOOL    RelativeOrigin  : 1;    // TRUE if origin relative to bottom left of grid bounds
00138     BOOL    DefaultGrid     : 1;    // TRUE if it's a Default grid that covers whole of spread
00139     BOOL    Disabled        : 1;    // TRUE if the grid is disabled (i.e. can't snap, render, select, etc)
00140 };
00141 
00142 enum GridType { INVALID_GRID_TYPE,RECTANGULAR,ISOMETRIC};
00143 
00144 #define NUM_GRID_TYPES 2
00145 
00146 class ProcessGrid;
00147 
00148 /***********************************************************************************************
00149 
00150 >    class NodeGrid : public NodeRenderablePaper
00151 
00152      Author:        Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00153      Created:       8/2/94
00154      Base Classes:  NodeRenderablePaper, NodeRenderable, Node, CCObject        
00155      Purpose:       An abstract class defining the common elements of grid nodes.
00156 
00157                     See the Node class for an important note about producing derived 
00158                     classes of Node. 
00159 
00160      SeeAlso:       NodeRenderablePaper   
00161     
00162 ***********************************************************************************************/
00163 
00164 class NodeGrid: public NodeRenderablePaper
00165 {   
00166     CC_DECLARE_DYNAMIC( NodeGrid ) 
00167 
00168 public:  
00169     NodeGrid(); 
00170 
00171     virtual SubtreeRenderState RenderSubtree(RenderRegion* pRender, Node** ppNextNode = NULL, BOOL bClip = TRUE);
00172               
00173     virtual String Describe(BOOL Plural, BOOL Verbose);             
00174                    
00175     virtual void Render( RenderRegion* pRender );
00176         
00177     #ifdef _DEBUG                         
00178     virtual void ShowDebugTreeDetails() const;   
00179     #endif
00180     
00181     virtual void GetDebugDetails(StringBase* Str);   // This is used by the Debug Tree dialog
00182                                                      // It will probably be deleted when we ship !. 
00183     virtual BOOL Snap(DocCoord* pDocCoord);
00184     virtual BOOL Snap(DocRect* pDocRect,const DocCoord& PrevCoord,const DocCoord& CurCoord);
00185 
00186     // MOVE THESE INTO GRID.CPP 
00187     BOOL IsGridSelected() const;
00188     void SetGridSelected(BOOL selected);
00189     BOOL IsDefault() const;
00190     void SetDefault(BOOL Default);
00191     BOOL IsDisabled() const;
00192     void SetDisabled(BOOL Disabled);
00193     virtual BOOL IsRenderedAsInk() const {return TRUE;}
00194 
00195     DocRect GetBoundingRect();
00196     void    SetBoundingRect(const DocRect& BRect);
00197     DocRect GetBlobBoundingRect();
00198 
00199     DocCoord GetBlobCoord(GridBlobType GridBlob);
00200 
00201     void SetOrigin(MILLIPOINT X,MILLIPOINT Y);
00202     void GetOrigin(MILLIPOINT* pX,MILLIPOINT* pY);
00203     
00204     virtual BOOL SetGridParams(double,UINT32,UnitType,BOOL Scale=TRUE) { return FALSE; }
00205 
00206     virtual double   CalcDivisions(BOOL Scale);
00207 
00208     virtual double   GetDivisions(BOOL Scale=TRUE) { return 1.0;}
00209     virtual UnitType GetUnits(    BOOL Scale=TRUE) { return INCHES; }
00210     virtual UINT32       GetSubdivisions()  { return 1;}
00211     virtual GridType GetGridType()      { return INVALID_GRID_TYPE; }
00212     virtual double   GetMainStep()      { return 72000.0; }
00213 
00214     static void RecalcNumSelectedGrids(Spread* pSpread);
00215     static void ProcessAllGrids(ProcessGrid* pProcessGrid);
00216     static void ProcessGridsInSpread(ProcessGrid* pProcessGrid,Spread* pSpread);
00217     static void ForceRedrawAllGrids();
00218     static void MakeDefaultGrid(Spread* pSpread, BOOL Scale=TRUE);
00219 
00220     // Call this before starting a drag that will use the DocRect version of the snap function
00221     static void ResetDocRectSnap();
00222 
00223     //  A set of access functions to the various vars of the grid system
00224     static UINT32   GetNumSelectedGrids();
00225     static UINT32   GetNumNonDefaultSelectedGrids();
00226     static GridType GetTypeForDefaultGrid();
00227     static BOOL     GetDefaultGridDisabled();
00228     static double   GetDefaultDivisions();
00229     static UINT32       GetDefaultSubdivisions();
00230     static UnitType GetDefaultUnits();
00231     static GridType GetDefaultGridType();
00232 
00233     static void     SetTypeForDefaultGrid(GridType GType);
00234     static void     SetDefaultGridDisabled(BOOL state);
00235     static void     SetDefaultDivisions(double Div);
00236     static void     SetDefaultSubdivisions(UINT32 Sub);
00237     static void     SetDefaultUnits(UnitType UType);
00238     static void     SetDefaultGridType(GridType GType);
00239 
00240     virtual void PolyCopyNodeContents(NodeRenderable* pNodeCopy);
00241 
00242     // Version 2 file format functions
00243     virtual BOOL WritePreChildrenWeb(BaseCamelotFilter* pFilter);
00244     virtual BOOL WritePreChildrenNative(BaseCamelotFilter* pFilter);
00245 
00246 protected:
00247     // Functions to write the actual data out
00248     virtual BOOL WriteGridAndRulerSettings(BaseCamelotFilter* pFilter);
00249     virtual BOOL WriteGirdAndRulerOrigin(BaseCamelotFilter* pFilter);
00250 
00251 protected:
00252     virtual Node* SimpleCopy();
00253     virtual UINT32 GetNodeSize() const              { return sizeof(*this); }
00254     void CopyNodeContents(NodeGrid* NodeCopy);
00255     void UpdateBlobsData();     // Updates the internal select blob coords data
00256 
00257     void CalcGridRenderSteps(MILLIPOINT PixelWidth,double* pStep,double DomStep,UnitType Units);
00258 
00259     MILLIPOINT SnapOrdinate(MILLIPOINT ord,double Step,MILLIPOINT origin);
00260 
00261     // REMEMBER TO UPDATE CopyNodeContents
00262 
00263     MILLIPOINT  XOrigin;            // X origin of first grid point relative to spread's (0,0) coord
00264     MILLIPOINT  YOrigin;            // Y origin of first grid point relative to spread's (0,0) coord
00265 
00266     DocColour       GridColour; 
00267     DocRect         GridBoundingRect;
00268 
00269     static INT32    LastXDir;
00270     static INT32    LastYDir;
00271 
00272 private:
00273     GridFlagsType   GridFlags;
00274     DocCoord        BlobCoords[NumGridBlobTypes];
00275 
00276     static UINT32 NumSelected;
00277     static UINT32 NumNonDefaultSelected;
00278 
00279     static GridType TypeForDefaultGrid;
00280     static BOOL     DefaultGridDisabled;
00281     static double   DefaultDivisions;
00282     static UINT32       DefaultSubdivisions;
00283     static UnitType DefaultUnits;
00284     static GridType DefaultGridType;
00285 
00286 protected:
00287     void DumpRect(DocRect& R,TCHAR* S);
00288 };
00289 
00290 /***********************************************************************************************
00291 
00292 >    class NodeGridRect : public NodeGrid
00293 
00294      Author:        Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00295      Created:       8/2/94
00296      Base Classes:  NodeGrid, NodeRenderablePaper, NodeRenderable, Node, CCObject        
00297      Purpose:       A class defining a rectangular grid node.
00298 
00299                     See the Node class for an important note about producing derived 
00300                     classes of Node. 
00301 
00302      SeeAlso:       NodeGrid, NodeRenderablePaper   
00303     
00304 ***********************************************************************************************/
00305 
00306 class NodeGridRect: public NodeGrid
00307 {   
00308     CC_DECLARE_DYNAMIC( NodeGridRect ) 
00309 
00310 public:  
00311     NodeGridRect(); 
00312     
00313     String Describe(BOOL Plural, BOOL Verbose);             
00314                    
00315     void Render( RenderRegion* pRender );
00316         
00317     #ifdef _DEBUG                         
00318     void ShowDebugTreeDetails() const;   
00319     #endif
00320     
00321     void GetDebugDetails(StringBase* Str);   // This is used by the Debug Tree dialog
00322                                                      // It will probably be deleted when we ship !. 
00323 
00324     BOOL Snap(DocCoord* pDocCoord); 
00325     BOOL Snap(DocCoord* pDocCoord,double XStep,double YStep);   
00326     BOOL Snap(DocRect* pDocRect,const DocCoord& PrevCoord,const DocCoord& CurCoord);
00327 
00328 
00329     BOOL SetGridParams(double Div,UINT32 SubDiv,UnitType Units, BOOL Scale=TRUE);
00330 
00331     double   GetDivisions(BOOL Scale=TRUE);
00332     UINT32     GetSubdivisions();
00333     UnitType GetUnits(BOOL Scale=TRUE);
00334     GridType GetGridType() { return RECTANGULAR; }
00335 
00336     double   GetMainStep() { return MainXStep; }
00337 
00338     Node* SimpleCopy();   
00339     virtual UINT32 GetNodeSize() const              { return sizeof(*this); }
00340 
00341     virtual void PolyCopyNodeContents(NodeRenderable* pNodeCopy);
00342 
00343 protected:
00344     void CopyNodeContents(NodeGridRect* NodeCopy);
00345 
00346 private:
00347     
00348     void RenderMainPoints(RenderRegion* pRender,DocRect RendRect,MILLIPOINT pixelWidth);
00349     void RenderSubPoints(RenderRegion* pRender,DocRect RendRect,MILLIPOINT pixelWidth);
00350 
00351     // ***** REMEMBER TO UPDATE CopyNodeContents
00352 
00353     double      MainXStep;  // X distance between each main grid point
00354     double      MainYStep;  // Y distance between each main grid point
00355     double      SubXStep;   // X distance between each sub grid point
00356     double      SubYStep;   // Y distance between each sub grid point
00357 
00358     UnitType    Units;
00359     double      Divisions;      // defunct, now calc'ed from grid MainStep and units (so independent of scaling)
00360     UINT32      Subdivisions;
00361 };
00362 
00363 /***********************************************************************************************
00364 
00365 >    class NodeGridIso : public NodeGrid
00366 
00367      Author:        Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00368      Created:       8/2/94
00369      Base Classes:  NodeGrid, NodeRenderablePaper, NodeRenderable, Node, CCObject        
00370      Purpose:       A class defining an isometric grid node.
00371 
00372                     See the Node class for an important note about producing derived 
00373                     classes of Node. 
00374 
00375      SeeAlso:       NodeGrid, NodeRenderablePaper   
00376     
00377 ***********************************************************************************************/
00378 
00379 class NodeGridIso: public NodeGrid
00380 {   
00381     CC_DECLARE_DYNAMIC( NodeGridIso ) 
00382 
00383 public:  
00384     NodeGridIso(); 
00385     
00386     String Describe(BOOL Plural, BOOL Verbose);             
00387                    
00388     void Render( RenderRegion* pRender );
00389         
00390     #ifdef _DEBUG                         
00391     void ShowDebugTreeDetails() const;   
00392     #endif
00393     
00394     void GetDebugDetails(StringBase* Str);   // This is used by the Debug Tree dialog
00395                                                      // It will probably be deleted when we ship !. 
00396 
00397     BOOL Snap(DocCoord* pDocCoord); 
00398     BOOL Snap(DocCoord* pDocCoord,double Step); 
00399     BOOL Snap(DocRect* pDocRect,const DocCoord& PrevCoord,const DocCoord& CurCoord);
00400 
00401     BOOL SetGridParams(double Div, UINT32 SubDiv, UnitType Units, BOOL Scale=TRUE);
00402 
00403     double   GetDivisions(BOOL Scale=TRUE);
00404     UINT32     GetSubdivisions();
00405     UnitType GetUnits(BOOL Scale=TRUE);
00406     GridType GetGridType() { return ISOMETRIC; }
00407 
00408     double   GetMainStep() { return MainStep; }
00409 
00410     Node* SimpleCopy();   
00411     virtual UINT32 GetNodeSize() const              { return sizeof(*this); }
00412 
00413     virtual void PolyCopyNodeContents(NodeRenderable* pNodeCopy);
00414 
00415 protected:
00416     void CopyNodeContents(NodeGridIso* NodeCopy);
00417 
00418 private:
00419     
00420     void RenderPoints(RenderRegion* pRender,DocRect RendRect,MILLIPOINT pixelWidth);
00421 
00422     void RenderSubPoints(   RenderRegion* pRender,
00423                             const DocCoord& MainGridPoint,
00424                             MILLIPOINT MainRenderStep,
00425                             MILLIPOINT SubRenderStep,
00426                             MILLIPOINT pixelWidth,
00427                             DocRect& ScaledBB);
00428 
00429     MILLIPOINT CalcYOrigin(MILLIPOINT x,double Step);
00430 
00431     // ***** REMEMBER TO UPDATE CopyNodeContents
00432 
00433     double      MainStep;   // distance between each main grid point
00434     double      SubStep;    // distance between each sub grid point
00435 
00436     UnitType    Units;
00437     double      Divisions;      // defunct, now calc'ed from grid MainStep and units (so independent of scaling)
00438     UINT32      Subdivisions;
00439 };
00440 
00441 
00442 /********************************************************************************************
00443 
00444 >   class ProcessGrid : SimpleCCObject
00445 
00446     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00447     Created:    18/7/94
00448     Purpose:    An abstract class used for processing a grid
00449 
00450 ********************************************************************************************/
00451 
00452 class ProcessGrid : public SimpleCCObject
00453 {
00454 public:
00455     virtual ~ProcessGrid() { }
00456     virtual void Process(NodeGrid* pGrid) = 0;
00457 
00458     Document*   pDoc;
00459     Chapter*    pChapter;
00460     Spread*     pSpread;
00461 };
00462 
00463 /********************************************************************************************
00464 
00465 >   class ProcessGridForceRedraw : ProcessGrid
00466 
00467     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00468     Created:    18/7/94
00469     Purpose:    Forces a redraw on the given grid
00470 
00471 ********************************************************************************************/
00472 
00473 class ProcessGridForceRedraw : public ProcessGrid
00474 {
00475 public:
00476     void Process(NodeGrid* pGrid);
00477 };
00478 
00479 
00480 /********************************************************************************************
00481 
00482 >   class ProcessGridUnitMsg : ProcessGrid
00483 
00484     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00485     Created:    18/7/94
00486     Purpose:    Something has happened to the units system
00487 
00488 ********************************************************************************************/
00489 
00490 class ProcessGridUnitMsg : public ProcessGrid
00491 {
00492 public:
00493     ProcessGridUnitMsg(UnitMsg* pThisUnitMsg);
00494 
00495     void Process(NodeGrid* pGrid);
00496 
00497 private:
00498     UnitMsg* pUnitMsg;
00499 };
00500 
00501 
00502 #endif // INC_GRID_H

Generated on Sat Nov 10 03:45:28 2007 for Camelot by  doxygen 1.4.4