noderect.cpp

Go to the documentation of this file.
00001 // $Id: noderect.cpp 1315 2006-06-14 09:51:34Z 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 
00099 /*
00100 */
00101 
00102 #include "camtypes.h"
00103 #include "noderect.h"
00104 
00105 // Code headers
00106 #include "aw_eps.h"
00107 #include "opsmpshp.h"
00108 
00109 // Resource headers
00110 //#include "simon.h"
00111 
00112 
00113 // Put my version Number into the About box
00114 DECLARE_SOURCE( "$Revision: 1315 $" );
00115 
00116 // Declare class and give details in memory dumps
00117 CC_IMPLEMENT_DYNCREATE(NodeRect, NodeSimpleShape)
00118 
00119 // Declare smart memory handling in Debug builds
00120 #define new CAM_DEBUG_NEW
00121 
00122 /***********************************************************************************************
00123 
00124 >   NodeRect::NodeRect( Node*               ContextNode,  
00125                         AttachNodeDirection Direction,  
00126                         const DocRect&      BoundingRect, 
00127                         BOOL                Locked = FALSE, 
00128                         BOOL                Mangled = FALSE,  
00129                         BOOL                Marked = FALSE, 
00130                         BOOL                Selected = FALSE, 
00131                         BOOL                Renderable = FALSE
00132                         )
00133 
00134     Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00135     Created:22/9/93             
00136     
00137     Inputs: ContextNode: Pointer to a node which this node is to be attached to.     
00138         
00139             Direction: 
00140             
00141                 Specifies the direction in which the node is to be attached to the 
00142                 ContextNode. The values this variable can take are as follows: 
00143                                   
00144                 PREV      : Attach node as a previous sibling of the context node
00145                 NEXT      : Attach node as a next sibling of the context node
00146                 FIRSTCHILD: Attach node as the first child of the context node
00147                 LASTCHILD : Attach node as a last child of the context node                               
00148                           
00149             BoundingRect: Bounding rectangle  
00150                                   
00151             The remaining inputs specify the status of the node: 
00152             
00153             Locked:     Is node locked ?
00154             Mangled:    Is node mangled ?
00155             Marked:     Is node marked ?
00156             Selected:   Is node selected ?
00157             
00158     Purpose: This constructor initialises the nodes flags and links it to ContextNode in the
00159             direction specified by Direction. All neccesary tree links are updated.         
00160             
00161     Note:   SetUpPath() must be called before the NodeRect is in a state in which it can be 
00162             used.       
00163                 
00164     SeeAlso: SetUpPath   
00165     
00166     Errors: An assertion error will occur if ContextNode is NULL
00167 
00168 ***********************************************************************************************/
00169 
00170 NodeRect::NodeRect(Node* ContextNode,  
00171                     AttachNodeDirection Direction,  
00172                     BOOL Locked, 
00173                     BOOL Mangled,  
00174                     BOOL Marked, 
00175                     BOOL Selected    
00176               ):NodeSimpleShape(ContextNode, Direction, Locked, Mangled, Marked, Selected )  
00177 {                         
00178 }                        
00179  
00180 /*********************************************************************************************
00181 
00182 >    NodeRect::NodeRect() 
00183 
00184      Author:    Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00185      Created:   22/9/93
00186      Purpose: This constructor creates a NodeRect linked to no other with all status
00187               flags false and an uninitialized bounding rectangle.           
00188             
00189      Note:    SetUpPath() must be called before the NodeRect is in a state in which it can be 
00190               used.         
00191                 
00192      SeeAlso: SetUpPath                                                        
00193 
00194 **********************************************************************************************/
00195 /* Technical Notes:   
00196 
00197 The default constructor is required so that SimpleCopy will work 
00198 */  
00199 
00200 NodeRect::NodeRect(): NodeSimpleShape()
00201 {
00202 }
00203 
00204 
00205 
00206 /***********************************************************************************************
00207 
00208 >   virtual Node* NodeRect::SimpleCopy()
00209 
00210     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00211     Created:    26/5/93
00212     Returns:    Pointer to a Node
00213     Purpose:    Makes a copy of all the data in the node
00214 
00215 ***********************************************************************************************/
00216 
00217 Node* NodeRect::SimpleCopy()
00218 {
00219     // Make a new NodeSimpleShape and then copy things into it
00220     NodeRect* NodeCopy = new NodeRect();
00221     if (NodeCopy)
00222         CopyNodeContents(NodeCopy);
00223     
00224     return NodeCopy;
00225 }            
00226 
00227 
00228 
00229 
00230 /********************************************************************************************
00231 
00232 >   virtual String NodeRect::Describe(BOOL Plural, BOOL Verbose = TRUE)
00233 
00234     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00235     Created:    25/6/93
00236     Inputs:     Plural: Flag indicating if the string description should be plural or
00237                 singular. 
00238     Retuns:     Description of the object                                    
00239     Purpose:    To return a description of the NodeRect object in either the singular or the 
00240                 plural. This method is called by the DescribeRange method.
00241                 The description will always begin with a lower case letter.   
00242     Errors:     A resource exception will be thrown if a problem occurs when loading the 
00243                 string resource. 
00244 
00245 ********************************************************************************************/
00246               
00247 String NodeRect::Describe(BOOL Plural, BOOL Verbose) 
00248 {     
00249     if (Plural)
00250         return(String(_R(IDS_RECTANGLE_DESCRP)));  
00251     else
00252         return(String(_R(IDS_RECTANGLE_DESCRS))); 
00253 }; 
00254 
00255 
00256 /********************************************************************************************
00257 
00258 >   void NodeRect::PreExportRender(RenderRegion* pRegion)
00259 
00260     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00261     Created:    17/08/94
00262     Inputs:     pRegion - the render region we are exporting to.
00263     Purpose:    Output data required to mark this object as a rectangle as opposed to an
00264                 arbitrary path.
00265 
00266 ********************************************************************************************/
00267 
00268 void NodeRect::PreExportRender(RenderRegion* pRegion)
00269 {
00270 #ifdef DO_EXPORT
00271     if (pRegion->IsKindOf(CC_RUNTIME_CLASS(ArtWorksEPSRenderRegion)))
00272     {
00273         // Output "ArtWorks rectangle" token
00274         EPSExportDC *pDC = (EPSExportDC *) pRegion->GetRenderDC();
00275         pDC->OutputToken(_T("ar"));
00276         pDC->OutputNewLine();
00277     }
00278 #endif
00279 }
00280 
00281 
00282 /***********************************************************************************************
00283 
00284 >   virtual void NodeRect::CreateShape(DocRect NewRect)
00285 
00286     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>, Changed by Rik
00287     Created:    22/9/93                          
00288     Inputs:     DocRect - representing the rectangle to be created.
00289     Purpose:    Creates a rectangle using a path.
00290 
00291 ***********************************************************************************************/
00292 
00293 void NodeRect::CreateShape(DocRect NewRect)
00294 {
00295     // Copy the rectangle into the parallelogram
00296     Parallel[0] = DocCoord(NewRect.lo.x, NewRect.hi.y);
00297     Parallel[1] = DocCoord(NewRect.hi.x, NewRect.hi.y);
00298     Parallel[2] = DocCoord(NewRect.hi.x, NewRect.lo.y);
00299     Parallel[3] = DocCoord(NewRect.lo.x, NewRect.lo.y);
00300 
00301     // build a path
00302     InkPath.FindStartOfPath();
00303 
00304     // Start at bottom left corner
00305     InkPath.InsertMoveTo(Parallel[0]);
00306     InkPath.InsertLineTo(Parallel[1]);
00307     InkPath.InsertLineTo(Parallel[2]);
00308     InkPath.InsertLineTo(Parallel[3]);
00309     InkPath.InsertLineTo(Parallel[0]);
00310 
00311     // Close the path properly
00312     InkPath.CloseSubPath();
00313 }
00314 
00315 /***********************************************************************************************
00316 
00317 >   virtual void NodeRect::UpdateShape()
00318 
00319     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>, Changed by Rik
00320     Created:    22/9/93                          
00321     Purpose:    Updates rectangle node to fit the current parallelogram
00322 
00323 ***********************************************************************************************/
00324 
00325 void NodeRect::UpdateShape()
00326 {
00327     // make sure the path seems to have the correct number of coords in it
00328     ENSURE(InkPath.GetNumCoords()==5, "NodeRect::UpdateShape found its path corrupt" );
00329 
00330     // Get the array of coords in the path
00331     DocCoord* Coords = InkPath.GetCoordArray();
00332 
00333     // Update them to what we now have
00334     Coords[0] = Parallel[0];
00335     Coords[1] = Parallel[1];
00336     Coords[2] = Parallel[2];
00337     Coords[3] = Parallel[3];
00338     Coords[4] = Parallel[0];
00339 }
00340 
00341 
00342 /********************************************************************************************
00343 
00344 >   void NodeRect::HandleBlobDrag(DocCoord& PointerPos, Spread* pSpread, INT32 FixedCorner)
00345 
00346     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00347     Created:    15/11/93
00348     Inputs:     PointerPos - The position the mouse pointer clicked
00349                 pSpread - the spread that the click was on
00350                 FixedCorner - The corner of the parallelogram that will stay fixed during
00351                 the drag
00352     Purpose:    When a drag is started on one of the paths blobs this is called. It tries to
00353                 fire up an operation that will perform a drag of all the selected points, 
00354                 including all the EORing of the relavent parts of the curve. If it fails it
00355                 will inform the user and not bother.
00356 
00357 ********************************************************************************************/
00358 
00359 void NodeRect::HandleBlobDrag(DocCoord& PointerPos, Spread* pSpread, INT32 FixedCorner)
00360 {
00361 #if !defined(EXCLUDE_FROM_RALPH)
00362     OpEditRectangle* pOpRect = new OpEditRectangle;
00363     if (pOpRect == NULL)
00364     {
00365         // Failed to get the memory to do the job
00366         TRACEUSER( "Rik", _T("The Node Rect Edit Operation failed to start\n") );
00367 
00368         // Inform the person doing the clicking that life is not looking so good
00369         InformError();
00370     }
00371     else
00372     {
00373         // Start the drag operation and pass in the Anchor Point to the operation
00374         pOpRect->DoDrag(PointerPos, pSpread, this, FixedCorner);
00375     }
00376 #endif
00377 }
00378 
00379 /********************************************************************************************
00380 
00381 >   virtual UINT32 NodeRect::GetNodeSize() const
00382 
00383     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00384     Created:    6/10/93
00385     Inputs:     -
00386     Outputs:    -
00387     Returns:    The size of the node in bytes 
00388 
00389     Purpose:    For finding the size of the node 
00390                 
00391     SeeAlso:    Node::GetSubtreeSize
00392 
00393 ********************************************************************************************/
00394 
00395 UINT32 NodeRect::GetNodeSize() const 
00396 {     
00397     return (sizeof(NodeRect)); 
00398 }  
00399 
00400 
00401 
00402 
00403 
00404 /********************************************************************************************
00405 
00406 >   BOOL NodeRect::SnapToCoords(DocCoord* pDocCoord)
00407 
00408     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00409     Created:    21/11/94
00410     Inputs:     pDocCoord - the coord to try and snap to
00411     Outputs:    pDocCoord - The snapped coord, if it was close enough to any of the magnetic
00412                 points for a rectangle.
00413     Returns:    TRUE if it was snapped, FALSE if not
00414     Purpose:    Snaps the point magnetically to the magnetic coords for a rectangle. These
00415                 are :- The Centre, The Corners, and the midpoints of its edges.
00416 
00417 ********************************************************************************************/
00418 
00419 BOOL NodeRect::SnapToCoords(DocCoord* pDocCoord)
00420 {
00421 #if !defined(EXCLUDE_FROM_RALPH)
00422     // First try and snap to all the places that the base class snaps for us
00423     BOOL IsSnapped = NodeSimpleShape::SnapToCoords(pDocCoord);
00424 
00425     // if it did not snap in the base class, try the extra points
00426     if (IsSnapped==FALSE)
00427     {
00428         // Try each of the corner of the rectangle
00429         for (INT32 i=0; i<4; i++)
00430         {
00431             if (IsMagneticallyClose(&Parallel[i], pDocCoord))
00432                 return TRUE;
00433         }
00434     }
00435 
00436     // send the result on
00437     return IsSnapped;
00438 #else
00439     return FALSE;
00440 #endif
00441 }
00442 
00443 

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