NodeGridRect Class Reference

A class defining a rectangular grid node. More...

#include <grid.h>

Inheritance diagram for NodeGridRect:

NodeGrid NodeRenderablePaper NodeRenderableBounded NodeRenderable Node CCObject SimpleCCObject List of all members.

Public Member Functions

 NodeGridRect ()
 This constructor creates a NodeGridRect linked to no other nodes, with all status flags false, and NULL bounding and pasteboard rectangles.
String Describe (BOOL Plural, BOOL Verbose)
 To return a description of the Node object in either the singular or the plural. This method is called by the DescribeRange method.
void Render (RenderRegion *pRender)
 Renders the rectangular grid item.
void GetDebugDetails (StringBase *Str)
 For obtaining debug information about the Node.
BOOL Snap (DocCoord *pDocCoord)
 Snaps to given coord to the nearest grid point. If it is not appropriate to snap the coord to the grid (at the moment this means the coord lies outside the grid object's bounding box), then FALSE is returned.
BOOL Snap (DocCoord *pDocCoord, double XStep, double YStep)
 Same as Snap(pDocCoord), except the coord is snapped to grid points at the given intervals.
BOOL Snap (DocRect *pDocRect, const DocCoord &PrevCoord, const DocCoord &CurCoord)
 Snaps the given rect to the nearest position on the grid, preserving its width and height. The coords of the rect used for the snapping are determined by the PrevCoord and CurCoord coords supplied. This is done to allow the user to control how a selection rectangle is snapped to the grid by the direction of his/her last mouse movement. To force the bottom left hand corner of the rect to be snapped, supply PrevCoord=(0,0) and CurCoord(-1,-1). Scope: public.
BOOL SetGridParams (double Div, UINT32 SubDiv, UnitType Units, BOOL Scale=TRUE)
 Defines the grid.
double GetDivisions (BOOL Scale=TRUE)
 Used to get the number of Units between each main grid point.
UINT32 GetSubdivisions ()
 Used to get the number of subdivisions between each main grid point.
UnitType GetUnits (BOOL Scale=TRUE)
 Gets the units used by the grid.
GridType GetGridType ()
double GetMainStep ()
NodeSimpleCopy ()
 This method returns a shallow copy of the node with all Node pointers NULL. The function is virtual, and must be defined for all derived classes.
virtual UINT32 GetNodeSize () const
 For finding the size of a node, in concrete classes derived from Node.
virtual void PolyCopyNodeContents (NodeRenderable *pNodeCopy)
 Polymorphically copies the contents of this node to another.

Protected Member Functions

void CopyNodeContents (NodeGridRect *NodeCopy)
 This method copies the node's contents to the node pointed to by NodeCopy.

Private Member Functions

void RenderMainPoints (RenderRegion *pRender, DocRect RendRect, MILLIPOINT pixelWidth)
 Renders the main grid points within the given renderable rectangle.
void RenderSubPoints (RenderRegion *pRender, DocRect RendRect, MILLIPOINT pixelWidth)
 Renders the sub grid points within the given renderable rectangle.

Private Attributes

double MainXStep
double MainYStep
double SubXStep
double SubYStep
UnitType Units
double Divisions
UINT32 Subdivisions

Detailed Description

A class defining a rectangular grid node.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94 Base Classes: NodeGrid, NodeRenderablePaper, NodeRenderable, Node, CCObject
See the Node class for an important note about producing derived classes of Node.

See also:
NodeGrid, NodeRenderablePaper

Definition at line 306 of file grid.h.


Constructor & Destructor Documentation

NodeGridRect::NodeGridRect  ) 
 

This constructor creates a NodeGridRect linked to no other nodes, with all status flags false, and NULL bounding and pasteboard rectangles.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
[OUTPUTS] 
Returns:
-

Errors:

Definition at line 946 of file grid.cpp.

00946                           : NodeGrid()
00947 {   
00948     Units       = INCHES;
00949     Divisions   = 1.0;
00950     Subdivisions= 2;
00951 
00952     MainXStep = 72000.0;
00953     SubXStep  = MainXStep/Subdivisions;
00954     MainYStep = MainXStep;
00955     SubYStep  = SubXStep;
00956 }                    


Member Function Documentation

void NodeGridRect::CopyNodeContents NodeGridRect NodeCopy  )  [protected]
 

This method copies the node's contents to the node pointed to by NodeCopy.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
A copy of this node [OUTPUTS]
Returns:
-

Errors: An assertion failure will occur if NodeCopy is NULL

Scope: protected

Definition at line 1445 of file grid.cpp.

01446 {
01447     ENSURE(NodeCopy != NULL,"Trying to copy a NodeGridRect's contents to a NULL node");  
01448     NodeGrid::CopyNodeContents(NodeCopy); 
01449 
01450     NodeCopy->MainXStep     = this->MainXStep;
01451     NodeCopy->MainYStep     = this->MainYStep;
01452     NodeCopy->SubXStep      = this->SubXStep;   
01453     NodeCopy->SubYStep      = this->SubYStep;   
01454 
01455     NodeCopy->Units         = this->Units;
01456     NodeCopy->Divisions     = this->Divisions;
01457     NodeCopy->Subdivisions  = this->Subdivisions;
01458 }

String NodeGridRect::Describe BOOL  Plural,
BOOL  Verbose
[virtual]
 

To return a description of the Node object in either the singular or the plural. This method is called by the DescribeRange method.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
Plural,: Flag indicating if the string description should be plural or [INPUTS] singular.
- [OUTPUTS] Retuns: Description of the object
The description will always begin with a lower case letter.

Returns:
Errors: A resource exception will be thrown if a problem occurs when loading the string resource.
See also:
-

Reimplemented from NodeGrid.

Definition at line 986 of file grid.cpp.

00987 {   
00988 
00989     if (Plural)
00990         return (String(_R(IDS_GRIDRECT_DESCRP)));
00991     else
00992         return (String(_R(IDS_GRIDRECT_DESCRS)));
00993 }; 

void NodeGridRect::GetDebugDetails StringBase Str  )  [virtual]
 

For obtaining debug information about the Node.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
Str,: String giving debug info about the node [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Reimplemented from NodeGrid.

Definition at line 1500 of file grid.cpp.

01501 {          
01502     NodeGrid::GetDebugDetails(Str); 
01503 }

double NodeGridRect::GetDivisions BOOL  Scale = TRUE  )  [virtual]
 

Used to get the number of Units between each main grid point.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/10/95
Parameters:
Scale - account for scaling (only FALSE when saving for doc compatibility) [INPUTS]
Returns:
Number of Units between each main grid point

Reimplemented from NodeGrid.

Definition at line 1603 of file grid.cpp.

01604 {
01605     return NodeGrid::CalcDivisions(Scale);
01606 }

GridType NodeGridRect::GetGridType  )  [inline, virtual]
 

Reimplemented from NodeGrid.

Definition at line 334 of file grid.h.

00334 { return RECTANGULAR; }

double NodeGridRect::GetMainStep  )  [inline, virtual]
 

Reimplemented from NodeGrid.

Definition at line 336 of file grid.h.

00336 { return MainXStep; }

virtual UINT32 NodeGridRect::GetNodeSize  )  const [inline, virtual]
 

For finding the size of a node, in concrete classes derived from Node.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/10/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The size of the node in bytes

Errors: If this function has not been overloaded in a non-abstract class then an ENSURE failure will occur.

See also:
-

Reimplemented from NodeGrid.

Definition at line 339 of file grid.h.

00339 { return sizeof(*this); }

UINT32 NodeGridRect::GetSubdivisions  )  [virtual]
 

Used to get the number of subdivisions between each main grid point.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/3/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Num subdivisions

Errors: -

See also:
-

Reimplemented from NodeGrid.

Definition at line 1624 of file grid.cpp.

01625 {
01626     return Subdivisions;
01627 }

UnitType NodeGridRect::GetUnits BOOL  Scale = TRUE  )  [virtual]
 

Gets the units used by the grid.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/10/95
Parameters:
Scale - account for unit scaling (only FALSE when saving for compatibility with old docs) [INPUTS]
Returns:
Units used by the grid

Reimplemented from NodeGrid.

Definition at line 1640 of file grid.cpp.

01641 {
01642     DimScale* pDimScale = DimScale::GetPtrDimScale(this);
01643     ERROR2IF(pDimScale==NULL,NOTYPE,"NodeGridRect::GetUnits() - pDimScale==NULL");
01644 
01645     // if scaling turned on return scale units
01646     // (except if scaling is not to be accounted for  - ie during saving for compatibility with old docs)
01647     UnitType ScaleUnits = pDimScale->GetScaleUnits();
01648     if (Scale && ScaleUnits!=NOTYPE)
01649         return ScaleUnits;
01650 
01651     return Units;
01652 }

void NodeGridRect::PolyCopyNodeContents NodeRenderable pNodeCopy  )  [virtual]
 

Polymorphically copies the contents of this node to another.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/12/2003
Parameters:
- [OUTPUTS]
Returns:
Errors: An assertion failure will occur if NodeCopy is NULL Scope: protected

Reimplemented from NodeGrid.

Definition at line 1473 of file grid.cpp.

01474 {
01475     ENSURE(pNodeCopy, "Trying to copy a node's contents into a NULL node");
01476     ENSURE(IS_A(pNodeCopy, NodeGridRect), "PolyCopyNodeContents given wrong dest node type");
01477 
01478     if (IS_A(pNodeCopy, NodeGridRect))
01479         CopyNodeContents((NodeGridRect*)pNodeCopy);
01480 }

void NodeGridRect::Render RenderRegion pRender  )  [virtual]
 

Renders the rectangular grid item.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
pRender = a render region [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Reimplemented from NodeGrid.

Definition at line 1012 of file grid.cpp.

01013 {      
01014 #if !defined(EXCLUDE_FROM_RALPH)
01015 //  static INT32 bbb=0;
01016 //  if (IsUserName("MarkN")) TRACE( _T("\n-------------------------------------------------------------------\n"));
01017 //  if (IsUserName("MarkN")) TRACE( _T("NodeGridRect::Render - %ld\n\n"),bbb++);
01018 
01019     // See if the render region likes grids to be drawn....
01020     if (!pRender->WantsGrids())
01021         return;
01022 
01023     // If the grid is disabled, don't bother either
01024     if (IsDisabled())
01025         return;
01026 
01027     View* pView = pRender->GetRenderView();
01028     if ((pView == NULL) || (!IS_A(pView, DocView)))
01029         // No docview to render to.
01030         return;
01031 
01032     DocView *pDocView = (DocView *) pView;
01033 
01034     if (!pDocView->GetShowGridState() && Tool::GetCurrentID() != TOOLID_GRID) return;
01035 
01036     // Set up attributes for drawing grid points
01037     pRender->SaveContext();
01038 // Don't set line attributes because grid points are now plotted used filled rects
01039 //  pRender->SetLineWidth(0);                               // Means single-pixel lines
01040 //  pRender->SetLineColour(GridColour);                     // Grid blobs are in this colour
01041 
01042     // Set fill attributes for grid point rectangle plotting...
01043     pRender->SetLineWidth(0);
01044     pRender->SetLineColour(COLOUR_TRANS); 
01045     pRender->SetFillColour(GridColour);
01046         
01047     DocRect ClipRect = pRender->GetClipRect();              // Get the current clip rect
01048     DocRect RendRect;
01049 
01050     RendRect.lo.x = max(GridBoundingRect.lo.x,ClipRect.lo.x);   // hi and lo renderable grid points
01051     RendRect.lo.y = max(GridBoundingRect.lo.y,ClipRect.lo.y);   // derived from the clip rect and the 
01052     RendRect.hi.x = min(GridBoundingRect.hi.x,ClipRect.hi.x);   // node's bounding rect
01053     RendRect.hi.y = min(GridBoundingRect.hi.y,ClipRect.hi.y);
01054     
01055     if (RendRect.IsValid())
01056     {
01057         MILLIPOINT PixelWidth = pRender->GetScaledPixelWidth(); // the width of a single pixel 
01058 
01059         RenderMainPoints(pRender,RendRect,PixelWidth);          // Render the main grid points (crosshairs)
01060         RenderSubPoints(pRender,RendRect,PixelWidth);           // Render the sub grid points (dots)
01061     }
01062 
01063     pRender->RestoreContext();
01064 #endif
01065 }  

void NodeGridRect::RenderMainPoints RenderRegion pRender,
DocRect  RendRect,
MILLIPOINT  PixelWidth
[private]
 

Renders the main grid points within the given renderable rectangle.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/2/94
Parameters:
pRender = region to render to [INPUTS] RendRect = Rectangle defining the renderable portion of the grid PixelWidth = width of a pixel in millipoints
[OUTPUTS] 
Returns:

Errors: Scope: private

Definition at line 1085 of file grid.cpp.

01086 {
01087 #if !defined(EXCLUDE_FROM_RALPH)
01088     // Set the fp render step values to be the underlying main grid step value
01089     double fp_RenderXStep = MainXStep;
01090     double fp_RenderYStep = MainYStep;
01091 
01092     // Calculate the step for rendering the grid in relation to the width of a pixel and the
01093     // factors of the dominant unit
01094     CalcGridRenderSteps(PixelWidth,&fp_RenderXStep,fp_RenderXStep*::GetUnitMultiple(Units),Units);
01095     CalcGridRenderSteps(PixelWidth,&fp_RenderYStep,fp_RenderYStep*::GetUnitMultiple(Units),Units);
01096 
01097     // Snap the render rect to these adjusted steps so we render all points within the renderable
01098     // portion of the grid
01099     Snap(&RendRect.lo,fp_RenderXStep,fp_RenderYStep);
01100     Snap(&RendRect.hi,fp_RenderXStep,fp_RenderYStep);
01101 
01102     ENSURE(RendRect.IsValid(),"RendRect is invalid in NodeGridRect::RenderMainPoints");
01103         
01104     // Get fixed point versions of the fp values for speedy grid rendering
01105     MILLIPOINT RenderXStep = (MILLIPOINT)((fp_RenderXStep * GRID_REND_FACTOR)+0.5);
01106     MILLIPOINT RenderYStep = (MILLIPOINT)((fp_RenderYStep * GRID_REND_FACTOR)+0.5);
01107 
01108 //  DumpRect(RendRect,"RendRect");
01109 
01110     // Convert RendRect to fixed point values
01111     RendRect.lo.x *= GRID_REND_FACTOR;
01112     RendRect.lo.y *= GRID_REND_FACTOR;
01113     RendRect.hi.x *= GRID_REND_FACTOR;
01114     RendRect.hi.y *= GRID_REND_FACTOR;
01115 
01116     DocRect ScaledBB = GridBoundingRect;
01117     ScaledBB.lo.x *= GRID_REND_FACTOR;
01118     ScaledBB.lo.y *= GRID_REND_FACTOR;
01119     ScaledBB.hi.x *= GRID_REND_FACTOR;
01120     ScaledBB.hi.y *= GRID_REND_FACTOR;
01121 
01122     // Make sure the render rectangle region doesn't lie outside the bounding rect
01123     while (RendRect.lo.x <  ScaledBB.lo.x) RendRect.lo.x += RenderXStep;
01124     while (RendRect.lo.y <  ScaledBB.lo.y) RendRect.lo.y += RenderYStep;
01125     while (RendRect.hi.x >= ScaledBB.hi.x) RendRect.hi.x -= RenderXStep;
01126     while (RendRect.hi.y >= ScaledBB.hi.y) RendRect.hi.y -= RenderYStep;
01127 
01128     RendRect.hi.x += GRID_REND_FACTOR; // compensate for errors (i.e. add the bodge factor)
01129     RendRect.hi.y += GRID_REND_FACTOR; // compensate for errors
01130 
01131     // Render those grid points boy!
01132 
01133     DocCoord GridPoint,TrueGridPoint;
01134 
01135     const MILLIPOINT Pix = pRender->GetScaledPixelWidth();
01136 //  const MILLIPOINT PixBy2 = Pix/2;
01137     const MILLIPOINT Length = PIX_CROSSHAIR_SIZE * Pix;
01138 
01139     for (GridPoint.x=RendRect.lo.x;GridPoint.x<=RendRect.hi.x;GridPoint.x+=RenderXStep)
01140     {
01141         for (GridPoint.y=RendRect.lo.y;GridPoint.y<=RendRect.hi.y;GridPoint.y+=RenderYStep)
01142         {
01143             // Scale the fixed point grid coord down to get the true coord of the grid point
01144             TrueGridPoint.x = (GridPoint.x+(GRID_REND_FACTOR/2)) / GRID_REND_FACTOR;
01145             TrueGridPoint.y = (GridPoint.y+(GRID_REND_FACTOR/2)) / GRID_REND_FACTOR;
01146 
01147 //          pRender->DrawCross(TrueGridPoint, PIX_CROSSHAIR_SIZE);
01148             // Phil says: Don't use DrawPixel because it can't be trusted to plot the
01149             // same pixel under GDI as it does under GDraw!
01150             // Instead draw two rectangles centered around the required coord.
01151             DocRect Horz(TrueGridPoint.x-Length,TrueGridPoint.y,TrueGridPoint.x+Length+Pix,TrueGridPoint.y+Pix);
01152             pRender->DrawRect(&Horz);
01153 
01154             DocRect Vert(TrueGridPoint.x,TrueGridPoint.y-Length,TrueGridPoint.x+Pix,TrueGridPoint.y+Length+Pix);
01155             pRender->DrawRect(&Vert);
01156 
01157         }
01158     }
01159 #endif
01160 }

void NodeGridRect::RenderSubPoints RenderRegion pRender,
DocRect  RendRect,
MILLIPOINT  PixelWidth
[private]
 

Renders the sub grid points within the given renderable rectangle.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/2/94
Parameters:
pRender = region to render to [INPUTS] RendRect = Rectangle defining the renderable portion of the grid PixelWidth = width of a pixel in millipoints
[OUTPUTS] 
Returns:

Errors: Scope: private

Definition at line 1181 of file grid.cpp.

01182 {
01183 #if !defined(EXCLUDE_FROM_RALPH)
01184     // Set the fp render step values to be the underlying sub grid step value
01185     double fp_RenderXStep = SubXStep;
01186     double fp_RenderYStep = SubYStep;
01187 
01188     // Calculate the step for rendering the grid in relation to the width of a pixel and the
01189     // factors of the dominant unit
01190     CalcGridRenderSteps(PixelWidth,&fp_RenderXStep,MainXStep,Units);
01191     CalcGridRenderSteps(PixelWidth,&fp_RenderYStep,MainYStep,Units);
01192 
01193     // If the render step is greater than the main step then don't render the sub grid
01194     if (fp_RenderXStep >= MainXStep) return;
01195     if (fp_RenderYStep >= MainYStep) return;
01196 
01197     // Snap the render rect to the render steps so we render all points within the renderable
01198     // portion of the grid
01199 
01200     Snap(&RendRect.lo,fp_RenderXStep,fp_RenderYStep);
01201     Snap(&RendRect.hi,fp_RenderXStep,fp_RenderYStep);
01202 
01203     ENSURE(RendRect.IsValid(),"RendRect is invalid in NodeGridRect::RenderSubPoints");
01204 
01205     // Get fixed point versions of the fp values for speedy grid rendering
01206     MILLIPOINT RenderXStep = (MILLIPOINT)((fp_RenderXStep * GRID_REND_FACTOR)+0.5);
01207     MILLIPOINT RenderYStep = (MILLIPOINT)((fp_RenderYStep * GRID_REND_FACTOR)+0.5);
01208 
01209     // Convert RendRect to fixed point values
01210     RendRect.lo.x *= GRID_REND_FACTOR;
01211     RendRect.lo.y *= GRID_REND_FACTOR;
01212     RendRect.hi.x *= GRID_REND_FACTOR;
01213     RendRect.hi.y *= GRID_REND_FACTOR;
01214 
01215     DocRect ScaledBB = GridBoundingRect;
01216     ScaledBB.lo.x *= GRID_REND_FACTOR;
01217     ScaledBB.lo.y *= GRID_REND_FACTOR;
01218     ScaledBB.hi.x *= GRID_REND_FACTOR;
01219     ScaledBB.hi.y *= GRID_REND_FACTOR;
01220 
01221     // Make sure the render rectangle region doesn't lie outside the bounding rect
01222     while (RendRect.lo.x <  ScaledBB.lo.x) RendRect.lo.x += RenderXStep;
01223     while (RendRect.lo.y <  ScaledBB.lo.y) RendRect.lo.y += RenderYStep;
01224     while (RendRect.hi.x >= ScaledBB.hi.x) RendRect.hi.x -= RenderXStep;
01225     while (RendRect.hi.y >= ScaledBB.hi.y) RendRect.hi.y -= RenderYStep;
01226 
01227     RendRect.hi.x += GRID_REND_FACTOR; // compensate for errors (i.e. add the bodge factor)
01228     RendRect.hi.y += GRID_REND_FACTOR; // compensate for errors
01229 
01230     // Go ahead punk, render those points                                                   
01231 
01232     DocCoord GridPoint,TrueGridPoint;
01233 
01234     const MILLIPOINT Pix = pRender->GetScaledPixelWidth();
01235 //  const MILLIPOINT PixBy2 = Pix/2;
01236 
01237     for (GridPoint.x=RendRect.lo.x;GridPoint.x<=RendRect.hi.x;GridPoint.x+=RenderXStep)
01238     {
01239         for (GridPoint.y=RendRect.lo.y;GridPoint.y<=RendRect.hi.y;GridPoint.y+=RenderYStep)
01240         {
01241             // Scale the fixed point grid coord down to get the true coord of the grid point
01242             TrueGridPoint.x = (GridPoint.x+(GRID_REND_FACTOR/2)) / GRID_REND_FACTOR;
01243             TrueGridPoint.y = (GridPoint.y+(GRID_REND_FACTOR/2)) / GRID_REND_FACTOR;
01244 
01245 //          pRender->DrawPixel(TrueGridPoint);
01246             // Phil says: Don't use DrawPixel because it can't be trusted to plot the
01247             // same pixel under GDI as it does under GDraw!
01248             // Instead draw a rectangle 1*1 pixels around the required coord.
01249             DocRect Pixel(  TrueGridPoint.x,
01250                             TrueGridPoint.y,
01251                             TrueGridPoint.x+Pix,
01252                             TrueGridPoint.y+Pix);
01253             pRender->DrawRect(&Pixel);
01254         }
01255     }
01256 #endif
01257 }

BOOL NodeGridRect::SetGridParams double  Div,
UINT32  Subdiv,
UnitType  NewUnits,
BOOL  Scale = TRUE
[virtual]
 

Defines the grid.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/10/95
Parameters:
Div - Number of Units between each main grid point [INPUTS] Subdiv - Number of subdivisions between each main grid point NewUnits - The units the grid is defined in Scale - account for unit scaling (only FALSE when loading for compatibility with old docs)
Returns:
FALSE if fails

Reimplemented from NodeGrid.

Definition at line 1533 of file grid.cpp.

01534 {
01535     if (Div < 0)
01536     {
01537         ERROR3("NodeGridRect::SetGridParams() - Div < 0!");
01538         Div = 0.0;
01539     }
01540     if (Subdiv < 1)
01541     {
01542         ERROR3("NodeGridRect::SetGridParams() - SubDiv < 1!");
01543         Subdiv = 1;
01544     }
01545 
01546     DimScale* pDimScale = DimScale::GetPtrDimScale(this);
01547     ERROR2IF(pDimScale==NULL,FALSE,"NodeGridRect::SetGridParams() - pDimScale==NULL");
01548 
01549     // set the raw values in the grid - but only set units if scaling turned off
01550     // (except if scaling is not to be accounted for  - ie during loading for compatibility with old docs - yuk!)
01551     Divisions    = Div;
01552     Subdivisions = Subdiv;
01553     if (Scale==FALSE || pDimScale->GetScaleUnits()==NOTYPE)
01554         Units = NewUnits;
01555 
01556     // convert the divisions and units into a millipoint grid spacing (accounting for unit scaling) - yuk!
01557     double GridSpacing=0;
01558     if (Scale)
01559     {
01560         BOOL ok = pDimScale->ComponentsToMillipoint(&GridSpacing, Divisions, GetUnits());
01561         if (!ok) return FALSE;
01562     }
01563     else
01564     {
01565         DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
01566         ERROR2IF(pDocUnitList==NULL,FALSE,"DimScale::ComponentsToMillipoint() - pDocUnitList==NULL");
01567         Unit* pUnit = pDocUnitList->FindUnit(Units);
01568         ERROR2IF(pUnit==NULL,FALSE,"DimScale::ComponentsToMillipoint() - pUnit==NULL");
01569         GridSpacing = Div * pUnit->GetMillipoints();
01570     }
01571 
01572     if (GridSpacing<1)
01573     {
01574         ERROR3("NodeGridRect::SetGridParams() - GridSpacing < 1!");
01575         GridSpacing=1;
01576     }
01577 
01578     MainXStep = GridSpacing;
01579     SubXStep  = MainXStep/Subdivisions;
01580     if (SubXStep<1)
01581     {
01582         ERROR3("NodeGridRect::SetGridParams() - SubXStep < 1!");
01583         SubXStep=1;
01584     }
01585 
01586     MainYStep = MainXStep;
01587     SubYStep  = SubXStep;
01588     
01589     return TRUE;
01590 }

Node * NodeGridRect::SimpleCopy void   )  [virtual]
 

This method returns a shallow copy of the node with all Node pointers NULL. The function is virtual, and must be defined for all derived classes.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
[OUTPUTS] 
Returns:
A copy of the node, or NULL if memory runs out

Errors: If memory runs out when trying to copy, then ERROR is called with an out of memory error and the function returns NULL.

Scope: protected

Reimplemented from NodeGrid.

Definition at line 1417 of file grid.cpp.

01418 {
01419     NodeGridRect* NodeCopy = new NodeGridRect();   
01420     if (NodeCopy != NULL)
01421         CopyNodeContents(NodeCopy);   
01422     return (NodeCopy);
01423 }          

BOOL NodeGridRect::Snap DocRect pDocRect,
const DocCoord PrevCoord,
const DocCoord CurCoord
[virtual]
 

Snaps the given rect to the nearest position on the grid, preserving its width and height. The coords of the rect used for the snapping are determined by the PrevCoord and CurCoord coords supplied. This is done to allow the user to control how a selection rectangle is snapped to the grid by the direction of his/her last mouse movement. To force the bottom left hand corner of the rect to be snapped, supply PrevCoord=(0,0) and CurCoord(-1,-1). Scope: public.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/2/94
Parameters:
pDocCoord - the rectangle to snap [INPUTS] StartDrag - Start coord of drag EndDrag - End coord of drag
[OUTPUTS] 
Returns:
TRUE - the DocRect been snapped to the grid. FALSE - the DocRect has not been processed.

Reimplemented from NodeGrid.

Definition at line 1325 of file grid.cpp.

01326 {
01327     if (IsDisabled()) return FALSE;
01328 
01329     ENSURE(SubXStep !=0,"SubXStep ==0 in NodeGridRect::Snap");
01330     ENSURE(SubYStep !=0,"SubYStep ==0 in NodeGridRect::Snap");
01331     
01332     INT32 xdir = CurCoord.x - PrevCoord.x;
01333     INT32 ydir = CurCoord.y - PrevCoord.y;
01334     INT32 x,y,prevx, prevy;
01335     
01336     if (LastXDir == 0)  LastXDir = xdir;
01337     if (xdir == 0)      xdir = LastXDir;
01338     LastXDir = xdir;
01339 
01340     if (xdir <= 0) x = pDocRect->lo.x; else x = pDocRect->hi.x;
01341 
01342     if (LastYDir == 0)  LastYDir = ydir;
01343     if (ydir == 0)      ydir = LastYDir;
01344     LastYDir = ydir;
01345 
01346     if (ydir <= 0) y = pDocRect->lo.y; else y = pDocRect->hi.y;
01347 
01348     if (!GridBoundingRect.ContainsCoord(DocCoord(x,y)))
01349         return (FALSE);
01350 
01351     prevx   = x;
01352     prevy   = y;
01353     x       = SnapOrdinate(x,SubXStep,XOrigin);
01354     y       = SnapOrdinate(y,SubYStep,YOrigin);
01355 
01356     if (!GridBoundingRect.ContainsCoord(DocCoord(x,y)))
01357         return (FALSE);
01358 
01359     pDocRect->Translate(x-prevx,y-prevy);
01360 
01361     return (TRUE);
01362 }

BOOL NodeGridRect::Snap DocCoord pDocCoord,
double  XStep,
double  YStep
 

Same as Snap(pDocCoord), except the coord is snapped to grid points at the given intervals.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/2/94
Parameters:
pDocCoord - the coord to snap [INPUTS] XStep - the x step to use when snapping the point YStep - the y step to use when snapping the point
[OUTPUTS] 
Returns:
TRUE - the DocCoord has been snapped to the grid. FALSE - the DocCoord has not been processed.

Errors: Scope: public

Definition at line 1382 of file grid.cpp.

01383 {
01384     if (IsDisabled()) return FALSE;
01385 
01386     ENSURE(XStep!=0,"XStep==0 in NodeGridRect::Snap(pDocCoord,XStep,YStep");
01387     ENSURE(YStep!=0,"YStep==0 in NodeGridRect::Snap(pDocCoord,XStep,YStep"); 
01388 
01389     pDocCoord->x = SnapOrdinate(pDocCoord->x,XStep,XOrigin);
01390     pDocCoord->y = SnapOrdinate(pDocCoord->y,YStep,YOrigin);
01391 
01392     return (TRUE);
01393 }

BOOL NodeGridRect::Snap DocCoord pDocCoord  )  [virtual]
 

Snaps to given coord to the nearest grid point. If it is not appropriate to snap the coord to the grid (at the moment this means the coord lies outside the grid object's bounding box), then FALSE is returned.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/2/94
Parameters:
pDocCoord = a coord in Spread coords [INPUTS]
[OUTPUTS] 
Returns:
TRUE - the DocCoord has been snapped to the grid. FALSE - the DocCoord has not been processed.

Errors: Scope: public

Reimplemented from NodeGrid.

Definition at line 1278 of file grid.cpp.

01279 {
01280     if (IsDisabled()) return FALSE;
01281 
01282     ENSURE(SubXStep !=0,"SubXStep ==0 in NodeGridRect::Snap");
01283     ENSURE(SubYStep !=0,"SubYStep ==0 in NodeGridRect::Snap");
01284 
01285     if (!GridBoundingRect.ContainsCoord(DocCoord(pDocCoord->x,pDocCoord->y)))
01286         return (FALSE);
01287 
01288     MILLIPOINT x = SnapOrdinate(pDocCoord->x,SubXStep,XOrigin);
01289     MILLIPOINT y = SnapOrdinate(pDocCoord->y,SubYStep,YOrigin);
01290 
01291     if (!GridBoundingRect.ContainsCoord(DocCoord(x,y)))
01292         return (FALSE);
01293 
01294     pDocCoord->x = x;
01295     pDocCoord->y = y;
01296 
01297     return (TRUE);
01298 }


Member Data Documentation

double NodeGridRect::Divisions [private]
 

Definition at line 359 of file grid.h.

double NodeGridRect::MainXStep [private]
 

Definition at line 353 of file grid.h.

double NodeGridRect::MainYStep [private]
 

Definition at line 354 of file grid.h.

UINT32 NodeGridRect::Subdivisions [private]
 

Definition at line 360 of file grid.h.

double NodeGridRect::SubXStep [private]
 

Definition at line 355 of file grid.h.

double NodeGridRect::SubYStep [private]
 

Definition at line 356 of file grid.h.

UnitType NodeGridRect::Units [private]
 

Definition at line 358 of file grid.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:56:53 2007 for Camelot by  doxygen 1.4.4