opscale2.cpp

Go to the documentation of this file.
00001 // $Id: opscale2.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 // Operation for doing an interactive scale of the selection
00099 
00100 /*
00101 */
00102 
00103 
00104 #include "camtypes.h"
00105 #include "opscale2.h"
00106 
00107 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "rik.h"
00109 #include "selector.h"
00110 //#include "clikdrag.h"
00111 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "selstr.h"
00113 
00114 
00115 
00116 
00117 // This is not compulsory, but you may as well put it in so that the correct version
00118 // of your file can be registered in the .exe
00119 DECLARE_SOURCE("$Revision: 1282 $");
00120 
00121 // An implement to match the Declare in the .h file.
00122 // If you have many classes, it is recommended to place them all together, here at the start of the file
00123 //CC_IMPLEMENT_DYNCREATE(OpScale2Trans, OpScaleTrans)
00124 
00125 // This will get Camelot to display the filename and linenumber of any memory allocations
00126 // that are not released at program exit
00127 #define new CAM_DEBUG_NEW
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 /********************************************************************************************
00137 
00138 >   OpScale2Trans();
00139 
00140     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00141     Created:    6/11/96
00142     Purpose:    default constructor
00143 
00144 ********************************************************************************************/
00145 
00146 /*OpScale2Trans::OpScale2Trans()
00147     : OpScaleTrans()
00148 {
00149 }*/
00150 
00151 
00152 
00153 
00154 /********************************************************************************************
00155 
00156 >   virtual  ~OpScale2Trans();
00157 
00158     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00159     Created:    6/11/96
00160     Purpose:    destructor
00161 
00162 ********************************************************************************************/
00163 
00164 /*OpScale2Trans::~OpScale2Trans()
00165 {
00166 }*/
00167 
00168 
00169 
00170 
00171 /********************************************************************************************
00172 
00173 >   OpScale2Trans( const OpScale2Trans& );
00174 
00175     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00176     Created:    6/11/96
00177     Purpose:    copy constructor
00178 
00179 ********************************************************************************************/
00180 /*
00181 OpScale2Trans::OpScale2Trans( const OpScale2Trans& Other )
00182     : OpScaleTrans( Other )
00183 {
00184 }
00185 */
00186 
00187 /********************************************************************************************
00188 
00189 >   OpScale2Trans&  operator=( const OpScale2Trans& );
00190 
00191     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00192     Created:    6/11/96
00193     Purpose:    assignment operator:  delegates to virtual Assign()
00194 
00195 ********************************************************************************************/
00196 /*
00197 OpScale2Trans&  OpScale2Trans::operator=( const OpScale2Trans& Other )
00198 {
00199     Assign( Other );
00200 
00201     return  *this;
00202 }
00203 */
00204 
00205 
00206 
00207 /********************************************************************************************
00208 
00209 >   virtual  OpScale2Trans*  Clone ()   const;
00210 
00211     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00212     Created:    6/11/96
00213     Purpose:    clone function
00214 
00215 ********************************************************************************************/
00216 /*
00217 OpScale2Trans*  OpScale2Trans::Clone ()   const
00218 {
00219 
00220    OpScale2Trans*  Clone  =  new OpScale2Trans( *this );
00221 
00222    if( !Clone )
00223       throw  "OpScale2Trans::Clone()\n\nCouldn't get memory for a OpScale2Trans\n";
00224 
00225    return  Clone;
00226 
00227 }
00228 */
00229 
00230 
00231 
00232 /********************************************************************************************
00233 
00234 >   private: virtual void  Assign( const OpScale2Trans& );
00235 
00236     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00237     Created:    6/11/96
00238     Purpose:    virtual assignment
00239 
00240 ********************************************************************************************/
00241 /*
00242 void  OpScale2Trans::Assign( const OpScale2Trans& Other )
00243 {
00244 
00245     OpScaleTrans::operator=( Other );
00246 
00247 }
00248 */
00249 
00250 
00251 
00252 /********************************************************************************************
00253 
00254 >   static BOOL OpScale2Trans::Declare()
00255 
00256     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00257     Created:    5/7/93
00258     Returns:    TRUE if all went OK, False otherwise
00259     Purpose:    Adds the operation to the list of all known operations
00260 
00261 ********************************************************************************************/
00262 
00263 /*BOOL OpScale2Trans::Declare()
00264 {
00265     return  RegisterOpDescriptor( 0, _R(IDS_SCALETRANS), CC_RUNTIME_CLASS(OpScale2Trans),
00266                                   OPTOKEN_SCALE2, OpScaleTrans::GetState              );
00267 }*/
00268 
00269 
00270 
00271 
00272 
00273 
00274 
00275 
00276 /********************************************************************************************
00277 
00278 >   virtual void  DoWithParam( OpDescriptor* pDescriptor,  OpParam* pOpParam )
00279 
00280     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com> (adapted from Rik)
00281     Created:    6/11/97
00282     Inputs:     pDescriptor - The operations descriptor
00283                 pOpParam    - The parameters for this operation
00284     Purpose:    override: slightly change to allow the scale factors setup and 
00285                 operation execution to be delegated to a separate function - IterateToConvergence()
00286     See also:   TransOperation::DoWithParam()
00287 
00288 ********************************************************************************************/
00289 
00290 /*void OpScale2Trans::DoWithParam( OpDescriptor*,  OpParam* pOpParam )
00291 {
00292 
00293     // Get at my data
00294     TransformData* TransData = (TransformData*)(pOpParam->Param1);
00295 
00296     // copy across all the relavent bits of data for the transform
00297     CentreOfTrans   = TransData->CentreOfTrans;
00298     LockAspect      = TransData->LockAspect;
00299     LeaveCopy       = TransData->LeaveCopy;
00300     ScaleLines      = TransData->ScaleLines;
00301     TransFills      = TransData->TransFills;
00302     TransformRange  = TransData->pRange;        // if NULL use the selection
00303 
00304     // It is not possible to move between spreads in an immediate operation
00305     CanChangeToNewSpread = FALSE;
00306 
00307     // Where was this operation started from, and are we interested
00308     SetStartBlob(TransData->StartBlob);
00309 
00310     // Find the Selection and fail if it is not there
00311     Selection = GetApplication()->FindSelection();
00312     if (Selection==NULL)
00313     {
00314         FailAndExecute();
00315         End();
00316         return;
00317     }
00318 
00319 
00321     IterateToConvergence( pOpParam );
00322 
00323 
00324     // mark the selection cache as invalid (bounding rects etc will no longer be correct)
00325     Selection->Update();
00326 
00327 
00328     // End the operation
00329     End();  
00330 
00331 }*/
00332 
00333 
00334 
00335 
00336 /********************************************************************************************
00337 
00338 >   protected: virtual INT32 IterateToConvergence ( OpParam* pParam );
00339 
00340     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00341     Created:    7/11/97
00342     Inputs:     pParam -  The parameters for this operation
00343     Returns:    dummy
00344     Purpose:    Calculate the scaling by iterative improvement
00345                     1.  set scale & matrix, accumulate matrix
00346                     2.  do a transform
00347                     3.  compare resultant width with intended width
00348                     4.  call to do the whole transform
00349 
00350 ********************************************************************************************/
00351 
00352 /*INT32  OpScale2Trans::IterateToConvergence ( OpParam* pParam )
00353 {
00354 
00355     const MILLIPOINT    IntendedWidth_k       =  ( (MILLIPOINT*)( pParam->Param2 ) )[0];
00356     const INT32         MaxWidthInaccuracy_k  =  (INT32)37;   // 0.05 * 1/96 inches (in millipoints) = 0.05 pixels
00357     const BOOL          OriginalSucceedAndDiscard_k  =  OpFlags.SucceedAndDiscard;
00358     const UINT32            MaxIterations_k       =  8;          // must be >= 1
00359 
00360     Matrix              AccumulatedScaling;      // default identity
00361     DocRect             BoundingRect          =  Selection->GetBoundingRect();
00362     INT32               WidthInaccuracy;
00363     Matrix              tmp;
00364     UINT32              i                     =  MaxIterations_k;
00365 
00366 
00367 
00369 
00370     OpFlags.SucceedAndDiscard  =  TRUE;   // suppress undo   // ???
00371 
00372     do
00373     {
00374         if( !InitTransformImmediate2( pParam,  BoundingRect ) )
00375             return  Failure( OriginalSucceedAndDiscard_k );
00376         BuildMatrix();
00377 
00379         FIXED16   abcd[4];
00380         ( tmp *= Transform ).GetComponents( abcd, 0 );
00381         if( abcd[0]  ==  0 )        break;
00382         else                        AccumulatedScaling  =  tmp;
00383 
00384 
00385         if( !CompleteTransformation() )
00386             return  Failure( OriginalSucceedAndDiscard_k );
00387         Selection->Update();
00388 
00389 
00390         BoundingRect     =  Selection->GetBoundingRect();
00391         WidthInaccuracy  =  BoundingRect.Width() - IntendedWidth_k;
00392         if( WidthInaccuracy < 0 )   WidthInaccuracy  =  -WidthInaccuracy;
00393     }
00395     while(     ( --i )
00396            &&  ( WidthInaccuracy > MaxWidthInaccuracy_k )  );
00397 
00398 
00399 
00401     ApplyAsSingleTransform( AccumulatedScaling,  OriginalSucceedAndDiscard_k );
00402 
00403 
00404     return  1;
00405 
00406 }*/
00407 
00408 
00409 
00410 
00411 /********************************************************************************************
00412 
00413   > protected: virtual INT32 OpScale2Trans::ApplyAsSingleTransform( Matrix& AccumulatedScaling,
00414                                                                   const BOOL OriginalSucceedAndDiscard_k )
00415 
00416     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00417     Created:    7/11/97
00418     Inputs:     AccumulatedScaling           - the whole transform
00419                 OriginalSucceedAndDiscard_k  - original undo flag
00420     Returns:    dummy
00421     Purpose:    1.  undo all iterated transforms, undo off
00422                 2.  do the accumulated transform, undo set to original state
00423     SeeAlso:    OpScaleTrans::IterateToConvergence()
00424 
00425 ********************************************************************************************/
00426 
00427 /*INT32 OpScale2Trans::ApplyAsSingleTransform( Matrix& AccumulatedScaling,  const BOOL OriginalSucceedAndDiscard_k )
00428 {
00429 
00431 
00432     Transform  =  AccumulatedScaling.Inverse();     // set  TransScaleFactor = YScaleFactor  ???
00433 
00434     if( !CompleteTransformation() )
00435         return  Failure( OriginalSucceedAndDiscard_k );
00436 
00437     Selection->Update();
00438     
00439 
00440 
00442 
00443     OpFlags.SucceedAndDiscard  =  OriginalSucceedAndDiscard_k;   // reset undo on/off choice
00444     Transform  =  AccumulatedScaling;               // set  TransScaleFactor = YScaleFactor  ???
00445 
00446     if( !CompleteTransformation() )
00447         return  Failure( OriginalSucceedAndDiscard_k );
00448 
00449     Selection->Update();
00450 
00451 
00452 
00453     return  1;
00454 
00455 }*/
00456 
00457 
00458 
00459 
00460 /********************************************************************************************
00461 
00462   > protected: OpScale2Trans::Failure ( const BOOL OriginalSucceedAndDiscard_k );
00463 
00464     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00465     Created:    7/11/97
00466     Inputs:     original undo flag
00467     Returns:    dummy
00468     Purpose:    acts like a 'catch' block:  general fail recovery
00469 
00470 ********************************************************************************************/
00471 
00472 /*INT32  OpScale2Trans::Failure ( const BOOL OriginalSucceedAndDiscard_k )
00473 {
00474 
00475     OpFlags.SucceedAndDiscard  =  OriginalSucceedAndDiscard_k;   // reset undo on/off choice
00476     FailAndExecute();
00477 
00478     return  0;
00479 
00480 }*/
00481 
00482 
00483             
00484             
00485 /********************************************************************************************
00486 
00487   > protected: virtual BOOL OpScale2Trans::InitTransformImmediate2( OpParam* pParam,  const DocRect& BoundingRect )
00488 
00489     Author:     Harrison_Ainsworth (Xara Group Ltd) <camelotdev@xara.com>
00490     Created:    7/11/97
00491     Inputs:     pParam       -  The parameters for this operation
00492                 BoundingRect -  (of the selection)
00493     Returns:    TRUE - all ok,  FALSE - fixed pt over/underflow
00494     Purpose:    override: calculate scale factors from the relative change in size
00495     SeeAlso:    OpScaleTrans::InitTransformImmediate()
00496 
00497 ********************************************************************************************/
00498 
00499 /*BOOL OpScale2Trans::InitTransformImmediate2( OpParam* pParam,  const DocRect& BoundingRect )
00500 {
00502     MILLIPOINT* pParams   =  (MILLIPOINT*)( pParam->Param2 );
00503     MILLIPOINT  Width     =  pParams[0];
00504     MILLIPOINT  Height    =  pParams[1];
00505 
00506 
00508     double      fpXscale  =  (double)Width  / BoundingRect.Width();
00509     double      fpYscale  =  (double)Height / BoundingRect.Height();
00510 
00511 
00514     if( pSelTool->BeyondFixedRange(fpXscale) || pSelTool->BeyondFixedRange(fpYscale) )
00515     {
00516         TRACEUSER( "Harrison", _T("Under/overflow in OpScale2Trans::InitTransformImmediate\n"));
00517         //pInfoBarOp->ReportEditError(_R(IDS_SEL_ERROR_TOO_SMALL_OR_LARGE));
00518         ToolInformError(TOOLID_SELECTOR, _R(IDS_SEL_ERROR_TOO_SMALL_OR_LARGE));
00519         return  FALSE;
00520     }
00521 
00522 
00523     FIXED16 fxParams[2];
00524     fxParams[0]  =  fpXscale;
00525     fxParams[1]  =  fpYscale;
00526 
00527     OpScaleTrans::InitTransformImmediate( &OpParam((INT32)pParam->Param1, (INT32)fxParams) );
00528 
00529 
00530     return  TRUE;
00531 }*/
00532 
00533 
00534 

Generated on Sat Nov 10 03:47:49 2007 for Camelot by  doxygen 1.4.4