brpress.cpp

Go to the documentation of this file.
00001 // $Id: brpress.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 
00099 // brush pressure classes implementation
00100 
00101 #include "camtypes.h"
00102 #include "brpress.h"
00103 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 #include "pen.h"
00105 #include "ndbldpth.h"
00106 
00107 CC_IMPLEMENT_MEMDUMP(PressureItem, CCObject);
00108 
00109 /********************************************************************************************
00110 
00111 >   PressureItem::PressureItem(UINT32 Pressure, double Proportion, MILLIPOINT Distance)
00112 
00113     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00114     Created:    7/1/97
00115     Inputs:     Pressure - the pressure value
00116                 Proportion - the proportional distance along the path
00117                 Distance - the absolute distance along the path
00118     Purpose:    constructor with initialisation
00119                 
00120     Notes:      
00121 ********************************************************************************************/
00122 
00123 PressureItem::PressureItem(UINT32 Pressure, double Proportion, MILLIPOINT Distance)
00124 {
00125     m_Pressure = Pressure;
00126     m_Proportion = Proportion;
00127     m_Distance = Distance;
00128 }
00129 
00130 /********************************************************************************************
00131 
00132 >   PressureItem::PressureItem(PressureItem& Other)
00133 
00134     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00135     Created:    7/1/97
00136     Inputs:     Other
00137     Purpose:    copy constructor
00138                 
00139     Notes:      
00140 ********************************************************************************************/
00141 
00142 PressureItem::PressureItem(const PressureItem& Other)
00143 {
00144     m_Pressure = Other.m_Pressure;
00145     m_Proportion = Other.m_Proportion;
00146     m_Distance = Other.m_Distance;
00147 }
00148 
00149 
00150 /********************************************************************************************
00151 
00152 >   PressureItem::PressureItem(PressureItem& Other)
00153 
00154     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00155     Created:    7/1/97
00156     Inputs:     Other
00157     Purpose:    copy constructor
00158                 
00159     Notes:      
00160 ********************************************************************************************/
00161 
00162 PressureItem PressureItem::operator =(const PressureItem& Other)
00163 {
00164     m_Pressure = Other.m_Pressure;
00165     m_Proportion = Other.m_Proportion;
00166     m_Distance = Other.m_Distance;
00167 
00168     return *this;
00169 }
00170 
00171 
00172 /********************************************************************************************
00173 
00174 >   PressureItem::WorkOutProportion(MILLIPOINT PathLength)
00175 
00176     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00177     Created:    13/12/99
00178 
00179     Inputs:     length of the path that this object is on
00180     Purpose:    calculates how far along the path we are and sets the member variable
00181 
00182 ********************************************************************************************/
00183 
00184 void PressureItem::WorkOutProportion(MILLIPOINT PathLength)
00185 {
00186     if (m_Distance < 0 || m_Distance > PathLength)
00187     {
00188         ERROR3("Attempting to calculate proportional distance with invalid data");
00189         TRACEUSER( "Diccon", _T("Invalid distance: %d, Path Length: %d\n"), m_Distance, PathLength );
00190         m_Proportion = 1.0;
00191         return;
00192     }
00193     m_Proportion = (double)((double)m_Distance / (double)PathLength);
00194     //if (m_Proportion < 0)
00195 //  TRACEUSER( "Diccon", _T("Proportion: %f\n"), m_Proportion);
00196 
00197 }
00198 
00199         
00200 /********************************************************************************************
00201 
00202 
00203 >   BOOL PressureItem::WriteNative(BaseCamelotFilter *pFilter)
00204 
00205     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00206     Created:    13/12/99
00207     Inputs:     pFilter - filter to write to
00208     Returns:    TRUE if the Node has written out a record to the filter
00209     Purpose:    Writes out a record of this PressureItem to the record supplied.  Note that because
00210                 PressureItems are generally part of a larger object they do not have their own tag etc.
00211                 This function is merely a convenience function.
00212 
00213     SeeAlso:    AttrBrushType::WritePreChildrenNative; BrushAttrRecordHandler::HandleRecord
00214 
00215 ********************************************************************************************/
00216 
00217 BOOL PressureItem::WriteNative(CXaraFileRecord* pRecord)
00218 {
00219     ERROR2IF(pRecord == NULL, FALSE, "Record is NULL in PressureItem::WriteNative");
00220     
00221     BOOL ok = pRecord->WriteINT32((INT32)m_Pressure);
00222     if (ok) ok = pRecord->WriteDOUBLE(m_Proportion);
00223     if (ok) ok = pRecord->WriteINT32(m_Distance);
00224 
00225     return ok;
00226 }
00227 
00228 
00229 
00230 
00231 
00232 /********************************************************************************************
00233 
00234 >   BrushPointInfo::BrushPointInfo()
00235 
00236     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00237     Created:    13/12/99
00238 
00239     Inputs:     -
00240     Purpose:    Default Constuctor for BrushPointInfo
00241 
00242 ********************************************************************************************/
00243 
00244 BrushPointInfo::BrushPointInfo()
00245 {
00246     m_Pressure = MAXPRESSURE / 2;
00247     m_Tangent = 0.0;
00248     m_Point = DocCoord(0, 0);
00249 }
00250 
00251 
00252 /********************************************************************************************
00253 
00254 >   BrushPointInfo::BrushPointInfo(DocCoord Point, double Tangent, UINT32 Pressure)
00255 
00256     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00257     Created:    13/12/99
00258 
00259     Inputs:     -
00260     Purpose:    initialising Constuctor for BrushPointInfo
00261 
00262 ********************************************************************************************/
00263 
00264 BrushPointInfo::BrushPointInfo(DocCoord Point, double Tangent, UINT32 Pressure)
00265 {
00266     m_Point = Point;
00267     m_Tangent = Tangent;
00268     m_Pressure = Pressure;
00269 }
00270 
00271 
00272 /********************************************************************************************
00273 
00274 >   BrushPointInfo BrushPointInfo::operator=(BrushPointInfo &Other)
00275 
00276     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00277     Created:    13/12/99
00278 
00279     Inputs:     -
00280     Purpose:    initialising Constuctor for BrushPointInfo
00281 
00282 ********************************************************************************************/
00283 
00284 BrushPointInfo& BrushPointInfo::operator =(BrushPointInfo &Other)
00285 {
00286     m_Point = Other.m_Point;
00287     m_Tangent = Other.m_Tangent;
00288     m_Pressure = Other.m_Pressure;
00289 
00290     return *(this);
00291 }
00292 
00293 
00294 /********************************************************************************************
00295 
00296 >   TimeStampBrushPoint::TimeStampBrushPoint()
00297 
00298     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00299     Created:    13/12/99
00300 
00301     Inputs:     -
00302     Purpose:    Default Constuctor for TimeStampBrushPoint
00303 
00304 ********************************************************************************************/
00305 
00306 TimeStampBrushPoint::TimeStampBrushPoint() : BrushPointInfo()
00307 {
00308     m_Distance = -1;
00309     m_Proportion = -1;
00310 }
00311 
00312 
00313 /********************************************************************************************
00314 
00315 >   TimeStampBrushPoint::TimeStampBrushPoint(CPathPointInfo)
00316 
00317     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00318     Created:    13/12/99
00319 
00320     Inputs:     -
00321     Purpose:    Constuctor for TimeStampBrushPoint
00322 
00323 ********************************************************************************************/
00324 
00325 TimeStampBrushPoint::TimeStampBrushPoint(CPathPointInfo PathInfo)
00326 {
00327     m_Point = PathInfo.m_Point;
00328     m_Tangent = PathInfo.m_Tangent;
00329     m_Distance = -1;
00330     m_Proportion = -1;
00331 }
00332 
00333 /********************************************************************************************
00334 
00335 >   TimeStampBrushPoint::TimeStampBrushPoint(CPathPointInfo)
00336 
00337     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00338     Created:    13/12/99
00339 
00340     Inputs:     -
00341     Purpose:    Constuctor for TimeStampBrushPoint
00342 
00343 ********************************************************************************************/
00344 
00345 TimeStampBrushPoint::TimeStampBrushPoint(CPathPointInfo PathInfo, MILLIPOINT Distance)
00346 {
00347     m_Point = PathInfo.m_Point;
00348     m_Tangent = PathInfo.m_Tangent;
00349     m_Distance = Distance;
00350     m_Proportion = -1;
00351 }
00352 
00353 
00354 /********************************************************************************************
00355 
00356 >   TimeStampBrushPoint::TimeStampBrushPoint(DocCoord Point, double Tangent, MILLIPOINT Distance)
00357 
00358     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00359     Created:    13/12/99
00360 
00361     Inputs:     -
00362     Purpose:    Constuctor for TimeStampBrushPoint
00363 
00364 ********************************************************************************************/
00365 
00366 TimeStampBrushPoint::TimeStampBrushPoint(DocCoord Point, double Tangent, MILLIPOINT Distance)
00367 {
00368     m_Point = Point;
00369     m_Tangent = Tangent;
00370     m_Distance = Distance;
00371 }
00372 
00373 /********************************************************************************************
00374 
00375 >   TimeStampBrushPoint TimeStampBrushPoint::operator=(TimeStampBrushPoint Other)
00376 
00377     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00378     Created:    13/12/99
00379 
00380     Inputs:     Other - the TSBP to assign
00381     Purpose:    assignment operator
00382 ********************************************************************************************/
00383 
00384 TimeStampBrushPoint TimeStampBrushPoint::operator=(TimeStampBrushPoint Other)
00385 {
00386     m_Point = Other.m_Point;
00387     m_Tangent = Other.m_Tangent;
00388     m_Distance = Other.m_Distance;
00389     m_Proportion = Other.m_Proportion;
00390 
00391     return *this;
00392 }
00393 
00394 /********************************************************************************************
00395 
00396 >   TimeStampBrushPoint::WorkOutProportion(MILLIPOINT PathLength)
00397 
00398     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00399     Created:    13/12/99
00400 
00401     Inputs:     length of the path that this object is on
00402     Purpose:    calculates how far along the path we are and sets the member variable
00403 
00404 ********************************************************************************************/
00405 
00406 void TimeStampBrushPoint::WorkOutProportion(MILLIPOINT PathLength)
00407 {
00408     if (m_Distance < 0 || m_Distance > PathLength)
00409     {
00410     //  ERROR3("Attempting to calculate proportional distance with invalid data");
00411         TRACEUSER( "Diccon", _T("Invalid distance: %d, Path Length: %d\n"), m_Distance, PathLength );
00412         m_Proportion = 1.0;
00413         return;
00414     }
00415     m_Proportion = (double)((double)m_Distance / (double)PathLength);
00416     //if (m_Proportion < 0)
00417 //  TRACEUSER( "Diccon", _T("Proportion: %f\n"), m_Proportion);
00418 
00419 }
00420 
00421 
00422 /********************************************************************************************
00423 
00424 >   static INT32 TimeStampBrushPoint::ComparePointInfo(void* Point1, void* Point2)
00425 
00426     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00427     Created:    6/10/99
00428     Inputs:     Point1, Point2- the distances to be compared
00429     Returns:    -1, if Dist1 < Dist2
00430                 0 , if Dist1 == Dist2
00431                 1, if Dist1 > Dist2
00432     Purpose:    Compares the two points by their distances, note that they are specified as void*
00433                 so that I can supply this fn.to qsort
00434     SeeAlso:    -
00435 
00436 ********************************************************************************************/
00437 
00438 INT32 TimeStampBrushPoint::ComparePointInfo(const void* Point1, const void* Point2)
00439 {
00440     TimeStampBrushPoint* pPoint1 = (TimeStampBrushPoint*)Point1;
00441     TimeStampBrushPoint* pPoint2 = (TimeStampBrushPoint*)Point2;
00442     
00443     if (pPoint1->m_Distance < pPoint2->m_Distance)
00444         return -1;
00445     if (pPoint1->m_Distance > pPoint2->m_Distance)
00446         return 1;
00447 
00448     return 0;
00449 }
00450 
00451         
00452 /********************************************************************************************
00453 
00454 
00455 >   BOOL TimeStampBrushPoint::WriteNative(BaseCamelotFilter *pFilter)
00456 
00457     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00458     Created:    13/12/99
00459     Inputs:     pFilter - filter to write to
00460     Returns:    TRUE if the Node has written out a record to the filter
00461     Purpose:    Writes out a record of this TSBP to the record supplied.  Note that because
00462                 TSBPs are generally part of a larger object they do not have their own tag etc.
00463                 This function is merely a convenience function.
00464 
00465     SeeAlso:    AttrBrushType::WritePreChildrenNative; BrushAttrRecordHandler::HandleRecord
00466 
00467 ********************************************************************************************/
00468 
00469 BOOL TimeStampBrushPoint::WriteNative(CXaraFileRecord* pRecord)
00470 {
00471     ERROR2IF(pRecord == NULL, FALSE, "Record is NULL in TimeStampBrushPoint::WriteNative");
00472     
00473     BOOL ok    = pRecord->WriteCoord(m_Point);
00474     TRACEUSER( "Diccon", _T("Wrote Point %d, %d\n"), m_Point.x, m_Point.y );
00475     if (ok) ok = pRecord->WriteDOUBLE(m_Tangent);
00476     if (ok) ok = pRecord->WriteDOUBLE(m_Proportion);
00477     if (ok) ok = pRecord->WriteINT32(m_Distance);
00478 
00479     return ok;
00480 }
00481 

Generated on Sat Nov 10 03:44:30 2007 for Camelot by  doxygen 1.4.4