opshear.cpp

Go to the documentation of this file.
00001 // $Id: opshear.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 // The Shear transform Operation
00099 
00100 /*
00101 */
00102 
00103 #include "camtypes.h"
00104 #include "opshear.h"
00105 
00106 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "trans2d.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "rik.h"
00111 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "clikdrag.h"
00113 
00114 
00115 DECLARE_SOURCE("$Revision: 1282 $");
00116 
00117 // An implement to match the Declare in the .h file.
00118 CC_IMPLEMENT_DYNCREATE(OpShearTrans, TransOperation)
00119 
00120 // This will get Camelot to display the filename and linenumber of any memory allocations
00121 // that are not released at program exit
00122 #define new CAM_DEBUG_NEW
00123 
00124 
00125 
00126 
00127 /********************************************************************************************
00128 
00129 >   OpShearTrans::OpShearTrans()
00130 
00131     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00132     Created:    20/7/93
00133     Purpose:    Constructor. Does nothing.
00134 
00135 ********************************************************************************************/
00136 
00137 OpShearTrans::OpShearTrans(): TransOperation()
00138 {
00139     // Reset all the infomation about things
00140     SelWidth = SelHeight = 0;
00141 
00142     // Default to horizontal
00143     IsHorizontal = TRUE;
00144 
00145     // Start off with no shearing at all
00146     ShearBy = FIXED16(0);
00147 
00148     // Set status help text
00149     StatusHelpID = _R(IDS_SHEARTRANS_STATUS1);
00150     StatusHelpID2=_R(IDS_SHEARTRANS_STATUS2);
00151 }
00152 
00153 
00154 
00155 /********************************************************************************************
00156 
00157 >   void OpShearTrans::SetStartBlob(INT32 StartBlob)
00158 
00159     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00160     Created:    25/7/94
00161     Inputs:     StartBlob  - the Number of the blob that the operation was initiated on,
00162                 if applicabale. They are numbered as follows :-
00163                 MonoOn
00164                 1  2  3
00165                 4     5
00166                 6  7  8
00167                 MonoOff
00168                 All operations that were not started from one of the 8 blobs should use 0
00169     Purpose:    Allows the operations to know how it was started. This operation is
00170                 interested in the horizontal / vertical nature of the transform
00171 
00172 ********************************************************************************************/
00173 
00174 void OpShearTrans::SetStartBlob(INT32 StartBlob)
00175 {
00176     // Only blobs 2, 7, 4 and 5 are relavant. All others are a problem
00177     ENSURE( (StartBlob==2) || (StartBlob==4) || (StartBlob==5) || (StartBlob==7),
00178             "Shear started a blob that it should not have done");
00179 
00180     // blobs 2 and 7 are the Middle Top and Middle Bottom blobs
00181     // and would suggest horizontal shearing
00182     if ((StartBlob==2) || (StartBlob==7))
00183         IsHorizontal = TRUE;
00184     else
00185         IsHorizontal = FALSE;
00186 
00187 }
00188 
00189 
00190 
00191 
00192 /********************************************************************************************
00193 >   virtual void OpShearTrans::InitTransformImmediate(OpParam* pParam)
00194 
00195     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00196     Created:    4/11/94
00197     Inputs:     pParam      ---     pointer an OpParam whose Param2 member is a pointer
00198                                     to a FIXED16 that represents the angle in degrees to 
00199                                     shear by.
00200     Outputs:    -
00201     Returns:    -
00202     Purpose:    
00203     Errors:     -
00204     SeeAlso:    -
00205 ********************************************************************************************/
00206 
00207 void OpShearTrans::InitTransformImmediate(OpParam* pParam)
00208 {
00209     FIXED16 pDegreesShearAngle = *((FIXED16*)PVOID(pParam->Param2));
00210     double ShearAngle = pDegreesShearAngle.MakeDouble();
00211 
00212     if (ShearAngle < -89.0)                     // Clip the shear angle to a sensible range
00213         ShearAngle = -89.0;
00214 
00215     if (ShearAngle > 89.0)
00216         ShearAngle = 89.0;
00217 
00218     ShearAngle = (ShearAngle*2*PI)/360.0;       // Convert to Radians
00219     ShearBy = (FIXED16)(tan(ShearAngle));       // And get the Shear distance to bung in the matrix
00220 }
00221 
00222 
00223 
00224 
00225 /********************************************************************************************
00226 
00227 >   virtual void OpShearTrans::InitTransformOnDrag(DocCoord PointerPos, ClickModifiers ClickMods)
00228 
00229     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00230     Created:    19/7/94
00231     Inputs:     PointerPos - The position of the mouse at the start of the drag
00232                 ClickMods - the keyboard modifiers that were active at the start of the drag
00233     Purpose:    Sets up the parameters needed to build the transform matrix at the start
00234                 of the drag. This base class version of this function does nothing.
00235 
00236 ********************************************************************************************/
00237 
00238 void OpShearTrans::InitTransformOnDrag(DocCoord PointerPos, ClickModifiers ClickMods)
00239 {
00240     // Make a note of the latest position of the mouse
00241     LastPos = PointerPos;
00242 
00243     // At the start of the drag the Shear factor will always by none
00244     ShearBy = FIXED16(0);
00245 
00246     // Find out how big the selection is
00247 //  SelRange* Selection = GetApplication()->FindSelection();
00248 //  DocRect SelRect = Selection->GetBoundingRect();
00249 
00250     // Find the width and the height of the selection
00251 //  SelWidth = SelRect.Width();
00252 //  SelHeight = SelRect.Height();
00253 
00254     // Use the Width and Height of the object AS PASSED IN from the caller
00255     // (If we just use the width/height of the selection, we may get it all horribly wrong, as
00256     // they may want to scale with or without including the effects of attributes, which
00257     // can significantly affect the size of the bounding rectangle to be used)
00258     SelWidth  = BoundingData.Width;
00259     SelHeight = BoundingData.Height;
00260 }
00261 
00262 
00263 
00264 
00265 /********************************************************************************************
00266 
00267 >   virtual void OpShearTrans::UpdateTransformOnDrag(DocCoord PointerPos, Spread*, ClickModifiers& ClickMods)
00268 
00269     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00270     Created:    19/7/94
00271     Inputs:     PointerPos - The latest position of the mouse
00272                 Spread the mouse is over - not used
00273                 Clickmodifiers in place - not used
00274     Purpose:    Does the calculations needed when the mouse moves to keep all the params
00275                 needed to build the rotation matrix up to date.
00276 
00277 ********************************************************************************************/
00278 
00279 void OpShearTrans::UpdateTransformOnDrag(DocCoord PointerPos, Spread* pClickSpread, ClickModifiers& ClickMods)
00280 {
00281     // Make sure that the cursor does not wrap around at the edge of spreads
00282     if (pClickSpread != StartSpread)
00283         PointerPos = MakeRelativeToSpread(StartSpread, pClickSpread, PointerPos);
00284 
00285     if (!ClickMods.Constrain)
00286         DocView::SnapSelected(pClickSpread, &PointerPos, FALSE, TRUE);
00287 
00288     // Make a note of the latest position of the mouse
00289     LastPos = PointerPos;
00290 
00291     double dx = PointerPos.x - CentreOfTrans.x;
00292     double dy = PointerPos.y - CentreOfTrans.y;
00293 
00294     // Work out the shear factor and angle
00295     double ShearAngle;
00296     if (IsHorizontal)
00297     {
00298         // Work out the horizontal shearing
00299         dy = StartPos.y - CentreOfTrans.y;
00300         ShearBy = FIXED16( dx / dy);
00301         ShearAngle = atan2(dx, dy);
00302     }
00303     else
00304     {
00305         // Work out the vertical shearing
00306         dx = StartPos.x - CentreOfTrans.x;
00307         ShearBy = FIXED16( dy / dx);
00308         ShearAngle = atan2(dy, dx);
00309     }
00310 
00311     // Update the boundingdata infomation about the constrain
00312     ShearAngle = (ShearAngle / (2.0*PI)) * 360.0;
00313     BoundingData.Shear = (ANGLE) ShearAngle;
00314     BoundingData.ShearChanged = TRUE;
00315 }
00316 
00317 
00318 
00319 
00320 
00321 /********************************************************************************************
00322 
00323 >   void OpShearTrans::ConstrainDrag(DocCoord* PointerPos)
00324 
00325     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00326     Created:    6/9/94
00327     Outputs:    PointerPos - Adjusts the mouse position so that it is constrained
00328     Purpose:    Constrains the drag by the constrain angle. If the angle becomes too shallow
00329                 (eg 90 degrees) the constrain will stop constraining and let it move freely.
00330 
00331 ********************************************************************************************/
00332 
00333 void OpShearTrans::ConstrainDrag(DocCoord* PointerPos)
00334 {
00335     // Make a copy of the coord in case we want to put it back
00336     DocCoord WorkingCopy = *PointerPos;
00337     BOOL UseWorkingCopy = FALSE;
00338 
00339     // Snap the pointer coord so that it runs along one of the rays
00340     DocView::ConstrainToAngle(CentreOfTrans, &WorkingCopy);
00341 
00342     // find out the x & y distance from the centre
00343     INT32 dx = WorkingCopy.x - CentreOfTrans.x;
00344     INT32 dy = WorkingCopy.y - CentreOfTrans.y;
00345 
00346     if (IsHorizontal)
00347     {
00348         if (dy!=0)
00349         {
00350             // This is a horizontal drag, so make sure that the pointer pos
00351             // lies on the horizon line level with the starting position
00352             // We need 64 bit numbers in the middle of the calculation so
00353             // use something that does it for us.
00354             dx = Mul32Div32(dx, StartPos.y-CentreOfTrans.y, dy);
00355 
00356             // only need to change the x component as that is all that is used
00357             WorkingCopy.x = CentreOfTrans.x + dx;
00358             WorkingCopy.y = StartPos.y;
00359             UseWorkingCopy = TRUE;
00360         }
00361     }
00362     else
00363     {
00364         if (dx!=0)
00365         {
00366             // Same but in the other axis
00367             dy = Mul32Div32(dy, StartPos.x-CentreOfTrans.x, dx) ;
00368 
00369             // Only change the y component this time
00370             WorkingCopy.y = CentreOfTrans.y + dy;
00371             WorkingCopy.x = StartPos.x;
00372             UseWorkingCopy = TRUE;
00373         }
00374     }
00375 
00376     // See if the constrain was valid
00377     if (UseWorkingCopy)
00378         *PointerPos = WorkingCopy;
00379 }
00380 
00381 /********************************************************************************************
00382 
00383 >   void OpShearTrans::BuildMatrix()
00384 
00385     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00386     Created:    19/7/94
00387     Purpose:    Builds the transform matrix required to Shear the selection about the
00388                 point CentreOfRot
00389 
00390 ********************************************************************************************/
00391 
00392 void OpShearTrans::BuildMatrix()
00393 {
00394     // Translate to the origin
00395     Transform = Matrix(-CentreOfTrans.x, -CentreOfTrans.y);
00396 
00397     // We will need a matrix to put the shear in
00398     Matrix Shear;
00399 
00400     // Work out how much to shear the selection by
00401     if (IsHorizontal)
00402     {
00403         // Build the shear matrix for a horizontal shear
00404         Shear = Matrix(FIXED16(1), FIXED16(0), FIXED16(ShearBy), FIXED16(1), 0, 0);
00405     }
00406     else
00407     {
00408         // Build the shear matrix for a vertical shear
00409         Shear = Matrix(FIXED16(1), FIXED16(ShearBy), FIXED16(0), FIXED16(1), 0, 0);
00410     }
00411 
00412     // Apply the shear
00413     Transform *= Shear;
00414 
00415     // Translate back again
00416     Transform *= Matrix(CentreOfTrans.x, CentreOfTrans.y);
00417 }
00418 
00419 
00420 
00421 
00422 /********************************************************************************************
00423 
00424 >   BOOL OpShearTrans::Declare()
00425 
00426     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00427     Created:    5/7/93
00428     Returns:    TRUE if all went OK, False otherwise
00429     Purpose:    Adds the operation to the list of all known operations
00430 
00431 ********************************************************************************************/
00432 
00433 BOOL OpShearTrans::Declare()
00434 {
00435     return (RegisterOpDescriptor(
00436                                 0, 
00437                                 _R(IDS_SHEARTRANS),
00438                                 CC_RUNTIME_CLASS(OpShearTrans),
00439                                 OPTOKEN_SHEAR,
00440                                 TransOperation::GetState)); 
00441 }
00442 
00443 
00444 

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