00001 // $Id: moldshap.cpp 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 // Mould Geometry class implementation. 00099 // The mould geometry class defines the structure of derived classes such as MouldEnvelope 00100 // and MouldPerspective 00101 00102 #include "camtypes.h" 00103 #include "moldenv.h" 00104 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 //#include "paths.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "rndrgn.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 //#include "trans2d.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 //#include "tranform.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 00110 DECLARE_SOURCE("$Revision: 1282 $"); 00111 00112 CC_IMPLEMENT_DYNAMIC(MouldGeometry, CCObject) 00113 CC_IMPLEMENT_DYNAMIC(MouldTransform, TransformBase) 00114 00115 // Declare smart memory handling in Debug builds 00116 #define new CAM_DEBUG_NEW 00117 00118 /******************************************************************************************* 00119 00120 MouldGeometry::MouldGeometry() 00121 00122 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00123 Created: 2/02/94 00124 Inputs: 00125 Purpose: Construct a mould geometry 00126 00127 ********************************************************************************************/ 00128 00129 MouldGeometry::MouldGeometry() 00130 { 00131 MouldThreshold = 32; 00132 } 00133 00134 00135 /******************************************************************************************* 00136 00137 MouldGeometry::SetThreshold(const INT32 t) 00138 00139 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00140 Created: 2/02/94 00141 Inputs: 00142 Purpose: Set the threshold value for this mould object. Thresholds should be in the 00143 range 1..4095 inclusive. 00144 00145 ********************************************************************************************/ 00146 00147 void MouldGeometry::SetThreshold(const INT32 t) 00148 { 00149 if (t>0 && t<4096) 00150 MouldThreshold=t; 00151 } 00152 00153 /******************************************************************************************* 00154 00155 > virtual void MouldGeometry::MouldPathRender(Path* pPath, RenderRegion* pRegion) 00156 00157 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00158 Created: 2/12/94 00159 Inputs: pPath = pointer to a path to mould 00160 pRegion = pointer to a region to render into 00161 Purpose: This function renders a path directly. It uses the current setup manifold 00162 and generates a temporary render path. 00163 00164 ********************************************************************************************/ 00165 00166 void MouldGeometry::MouldPathRender(Path* pPath, RenderRegion* pRegion) 00167 { 00168 Path RenderPath; 00169 if (!(RenderPath.Initialise(12,12))) return; 00170 if (!MouldPathToPath(pPath,&RenderPath)) return; 00171 00172 pRegion->DrawPath(&RenderPath); 00173 } 00174 00175 00176 00177 /******************************************************************************************* 00178 00179 > virtual void MouldGeometry::MouldBitmapRender( KernelBitmap* pBlit, 00180 DocCoord*pParallel, 00181 RenderRegion* pRegion) 00182 00183 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00184 Created: 2/12/93 00185 Inputs: pBlit = pointer to a bitmap 00186 pParallel = pointer to a parallelogram 00187 pRegion = pointer to a region to render into 00188 Purpose: 00189 00190 ********************************************************************************************/ 00191 00192 void MouldGeometry::MouldBitmapRender( KernelBitmap* pBlit, 00193 DocCoord* pParallel, 00194 RenderRegion* pRegion) 00195 { 00196 } 00197 00198 00199 00200 /******************************************************************************************** 00201 00202 > virtual MouldGeometry* MouldPathShape::MakeCopy() 00203 00204 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00205 Created: 11/12/93 00206 Inputs: - 00207 Outputs: a pointer to a new mould geometry object. 00208 NULL if unable to create the object. 00209 Purpose: Make a copy of this mould geometry object and return it. 00210 00211 ********************************************************************************************/ 00212 00213 MouldGeometry* MouldGeometry::MakeCopy() 00214 { 00215 // create a new Geometry 00216 MouldGeometry* pGeometry = new MouldGeometry; 00217 if (pGeometry == NULL) 00218 return NULL; 00219 00220 BOOL ok = CopyContents(pGeometry); 00221 if (!ok) 00222 { 00223 delete pGeometry; 00224 return NULL; 00225 } 00226 00227 return (pGeometry); 00228 } 00229 00230 00231 /******************************************************************************************** 00232 00233 > BOOL MouldGeometry::CopyContents(MouldGeometry* pGeometry) 00234 00235 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00236 Created: 11/12/93 00237 Inputs: pGeometry = a pointer to copy of this geometry data. 00238 Outputs: 00239 Returns: TRUE if the data has been copied correctly 00240 FALSE if failed 00241 Purpose: Make a copy of this mouldgeometry classes private data 00242 00243 ********************************************************************************************/ 00244 00245 BOOL MouldGeometry::CopyContents(MouldGeometry* pGeometry) 00246 { 00247 ERROR3IF(pGeometry==NULL, "MouldGeometry::CopyContents() passed a null pointer"); 00248 00249 // copy all our locals here 00250 pGeometry->MouldThreshold = MouldThreshold; 00251 00252 return TRUE; 00253 } 00254 00255 00256 00257 00258 00259 /******************************************************************************************* 00260 00261 > virtual BOOL MouldGeometry::OnClick(DocCoord Coord, 00262 ClickType CType, 00263 ClickModifiers Mods, 00264 Spread* pSpread, 00265 NodeMould* pNodeMould) 00266 00267 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00268 Created: 2/12/93 00269 Inputs: Coord = coordinate of mouse 00270 CType = the type of click (single, double, drag) 00271 Mods = the click modifiers 00272 pSpread = a pointer to the spread the click occured over 00273 pNodeMould = a pointer to the parent mould object 00274 Purpose: 00275 00276 ********************************************************************************************/ 00277 00278 BOOL MouldGeometry::OnClick(DocCoord Coord, 00279 ClickType CType, 00280 ClickModifiers Mods, 00281 Spread* pSpread, 00282 NodeMould* pNodeMould) 00283 { 00284 // do nothing at the moment. 00285 return FALSE; 00286 } 00287 00288 00289 00290 /******************************************************************************************* 00291 00292 > virtual BOOL MouldGeometry::OnMouseMove(DocCoord Coord, 00293 Spread* pSpread, 00294 ClickModifiers Mods 00295 INT32* ctype, 00296 INT32* msgres) 00297 00298 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00299 Created: 2/12/93 00300 Inputs: Coord = coordinate of mouse 00301 Mods = the click modifiers 00302 pSpread = a pointer to the spread the click occured over 00303 Returns: ctype = the tool cursor type to use over this point 00304 msgres = the message resource type to use over this point 00305 Purpose: 00306 00307 ********************************************************************************************/ 00308 00309 BOOL MouldGeometry::OnMouseMove(DocCoord Coord, 00310 Spread* pSpread, 00311 ClickModifiers Mods, 00312 INT32* ctype, 00313 INT32* msgres) 00314 { 00315 // do nothing at the moment. 00316 return FALSE; 00317 } 00318 00319 00320 DocRect MouldGeometry::ConvRectToDocRect(RECT& rect0) 00321 { 00322 DocRect rect1; 00323 rect1.lo.x = rect0.left; 00324 rect1.lo.y = rect0.bottom; 00325 rect1.hi.x = rect0.right; 00326 rect1.hi.y = rect0.top; 00327 return rect1; 00328 } 00329 00330 00331 RECT MouldGeometry::ConvDocRectToRect(DocRect& rect0) 00332 { 00333 RECT rect1; 00334 rect1.left = rect0.lo.x; 00335 rect1.bottom= rect0.lo.y; 00336 rect1.right = rect0.hi.x; 00337 rect1.top = rect0.hi.y; 00338 return rect1; 00339 } 00340 00341 00342 00343 00344 /******************************************************************************************* 00345 00346 > MouldTransform::MouldTransform(MouldShape* pShape) 00347 00348 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00349 Created: 24/01/94 00350 Inputs: pShape = a pointer to a mould shape object 00351 Purpose: MouldTransform constructor sets the internal shape pointer. 00352 00353 ********************************************************************************************/ 00354 00355 MouldTransform::MouldTransform(MouldGeometry* pGeom) 00356 { 00357 ERROR3IF(pGeom==NULL, "MouldTransform constructor passed a null shape"); 00358 00359 pMouldGeom = pGeom; 00360 TransFills = TRUE; 00361 TransLines = TRUE; 00362 00363 // FIXED16 a(1); 00364 // SetScaleFactor(a); 00365 } 00366 00367 00368 /******************************************************************************************* 00369 00370 > MouldTransform::MouldTransform() 00371 00372 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00373 Created: 24/01/94 00374 Inputs: 00375 Purpose: MouldTransform destructor 00376 00377 ********************************************************************************************/ 00378 00379 MouldTransform::~MouldTransform() 00380 { 00381 // does nothing at moment 00382 } 00383 00384 00385 /******************************************************************************************* 00386 00387 > MouldTransform::Transform(DocCoord* Coords, INT32 NumCoords) 00388 00389 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00390 Created: 24/01/94 00391 Inputs: Coords = a pointer to a set of document coordinates 00392 NumCoords = the number of coordinates to transform. 00393 Outputs: Coords holds the results of the transformation. All coordinates will have 00394 been processed. 00395 Purpose: Takes each coordinate from Coords in turn, transforming it by the defined 00396 mould and writing back the result. 00397 00398 ********************************************************************************************/ 00399 00400 void MouldTransform::Transform(DocCoord* Coords, INT32 NumCoords) 00401 { 00402 ERROR3IF(Coords==NULL, "MouldTransform::Transform() called with illegal coord pointer"); 00403 00404 for (INT32 i=0; i<NumCoords; i++) 00405 pMouldGeom->MouldPoint(Coords[i],Coords[i]); 00406 } 00407 00408 00409 /******************************************************************************************* 00410 00411 > MouldTransform::TransformPath(Path* const pSource, Path* pDestin) 00412 00413 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00414 Created: 24/01/94 00415 Inputs: pSource = a pointer to the source path to transform 00416 pDestin = a pointer to an initialised path to take the result of the 00417 transformation. 00418 Outputs pDestin holds the result of the transformation 00419 Purpose: This function will create a destination path by transforming the coords in 00420 the source path. However, unlike MouldTransform::Transform() there is not 00421 a 1:1 correspondence between these points. ie this complex transform produces 00422 complex results. The output path can be much larger than the input. 00423 You could theoretically call the Transform function on the coordinates of the 00424 path. The nature of the transform (being none affine) will give you an 00425 inaccurate result for lines and an invalid result for curves. 00426 So its better to use this function for paths. 00427 I suppose the criteria is, if you dont mind a linear response in the output 00428 domain of what you are transforming, (such as simple transforms of grad 00429 fills) then you can use Transform() otherwise, use this function if you 00430 can represent your data as paths. 00431 00432 ********************************************************************************************/ 00433 00434 BOOL MouldTransform::TransformPath(Path* const pSource, Path* pDestin) 00435 { 00436 ERROR2IF(pSource==NULL,FALSE,"MouldTransform::TransformPath() called with a null source path"); 00437 ERROR2IF(pDestin==NULL,FALSE,"MouldTransform::TransformPath() called with a null source path"); 00438 00439 return pMouldGeom->MouldPathToPath(pSource,pDestin); 00440 } 00441