00001 // $Id: scunit.h 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 00100 #ifndef INC_SCUNITS 00101 #define INC_SCUNITS 00102 00103 // Definition of the scale units class 00104 00105 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 00107 /********************************************************************************************* 00108 00109 > class Qualfier : public CC_CLASS_MEMDUMP 00110 00111 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00112 Created: 02/05/96 00113 Purpose: A ScaleUnit is defined by: 00114 A range for which the scaled value is between 0 & 1 00115 A scaler which converts any value in its range to between 0 & 1 00116 A qualifier which may be prefixed or suffixed onto the value 00117 NB: There are no base units as such. 00118 00119 **********************************************************************************************/ 00120 class Qualifier : public CC_CLASS_MEMDUMP 00121 { 00122 CC_DECLARE_MEMDUMP(Qualifier); 00123 00124 public: 00125 enum QUALIFIER_SHOWN 00126 { 00127 IS_NOTSHOWN = 0, 00128 IS_SHOWN = 1 00129 }; 00130 00131 enum QUALIFIER_AFFIX // should be subclassed 00132 { 00133 SUFFIX = 0, 00134 PREFIX = 1, 00135 NONE = -1 00136 }; 00137 00138 Qualifier(); 00139 virtual ~Qualifier() { } 00140 00141 Qualifier& operator=(const Qualifier& OtherQualifier); 00142 00143 // Attribute access 00144 BOOL SetAttributes(const String_32& NewToken, QUALIFIER_SHOWN WhetherShown); 00145 String_32 GetToken() const; 00146 BOOL IsShown() const; 00147 00148 virtual BOOL MakeDisplayString(const StringBase& InString, StringBase* pOutString) const = 0; 00149 00150 virtual QUALIFIER_AFFIX GetAffix() const = 0; // DO NOT USE 00151 00152 protected: 00153 String_32 m_Token; 00154 // m_Affix is the affix type of the qualifier, eg.SU_PREFIX for $10 or SU_SUFFIX for 10p 00155 BOOL m_bShow; // whether qualifier shown 00156 00157 }; 00158 00159 00160 /********************************************************************************************* 00161 00162 > class PrefixQualifier : public Qualifier 00163 00164 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00165 Created: 02/05/96 00166 Purpose: A prefix qualifier is one of the form <QualifierToken><...>, e.g. 5.00 00167 00168 **********************************************************************************************/ 00169 class PrefixQualifier : public Qualifier 00170 { 00171 CC_DECLARE_MEMDUMP(PrefixQualifier); 00172 00173 public: 00174 virtual BOOL MakeDisplayString(const StringBase& InString, StringBase* pOutString) const; 00175 00176 QUALIFIER_AFFIX GetAffix() const { return PREFIX; } 00177 00178 }; 00179 00180 00181 /********************************************************************************************* 00182 00183 > class SuffixQualifier : public Qualifier 00184 00185 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00186 Created: 02/05/96 00187 Purpose: A suffix qualifier is one of the form <...><QualifierToken>, e.g. 5.00% 00188 00189 **********************************************************************************************/ 00190 class SuffixQualifier : public Qualifier 00191 { 00192 CC_DECLARE_MEMDUMP(SuffixQualifier); 00193 00194 public: 00195 virtual BOOL MakeDisplayString(const StringBase& InString, StringBase* pOutString) const; 00196 00197 QUALIFIER_AFFIX GetAffix() const { return SUFFIX; } 00198 00199 }; 00200 00201 00202 /********************************************************************************************* 00203 00204 > class SuffixQualifier : public Qualifier 00205 00206 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00207 Created: 02/05/96 00208 Purpose: A suffix qualifier is one of the form <...><QualifierToken>, e.g. 5.00% 00209 00210 **********************************************************************************************/ 00211 class NullQualifier : public Qualifier 00212 { 00213 CC_DECLARE_MEMDUMP(NullQualifier); 00214 00215 public: 00216 virtual BOOL MakeDisplayString(const StringBase& InString, StringBase* pOutString) const; 00217 00218 QUALIFIER_AFFIX GetAffix() const { return NONE; } 00219 00220 }; 00221 00222 00223 /********************************************************************************************* 00224 00225 > class ScaleUnit : public ListItem 00226 00227 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00228 Created: 02/05/96 00229 Purpose: A ScaleUnit is defined by: 00230 A range for which the scaled value is between 0 & 1 00231 A scaler which converts any value in its range to between 0 & 1 00232 A qualifier which may be prefixed or suffixed onto the value 00233 NB: There are no base units as such. 00234 00235 **********************************************************************************************/ 00236 class ScaleUnit : public ListItem 00237 { 00238 CC_DECLARE_DYNAMIC(ScaleUnit) 00239 00240 public: 00241 // Constructors 00242 ScaleUnit(); 00243 ScaleUnit(const double dScale, const double dMin, const double dMax); 00244 ScaleUnit(const double dScale, const UINT32 nDPtoShow); 00245 ScaleUnit(const ScaleUnit& UnitToCopy); 00246 00247 virtual ScaleUnit& operator =(const ScaleUnit& UnitToCopy); 00248 00249 virtual ~ScaleUnit(); 00250 00251 // Two ScaleUnits are equal if they have matching qualifiers & scales(?) 00252 virtual BOOL operator == (const ScaleUnit& RhsUnit) const; 00253 virtual BOOL operator != (const ScaleUnit& RhsUnit) const; 00254 00255 // Attributes 00256 00257 BOOL SetQualifier(Qualifier& NewQualifier); 00258 BOOL SetQualifier( const StringBase& QualifierParseString, 00259 const Qualifier::QUALIFIER_SHOWN WhetherShown); 00260 const Qualifier* GetQualifier() const; 00261 00262 BOOL SetDPtoShow(const UINT32 uNumber); 00263 UINT32 GetDPtoShow() const; 00264 00265 BOOL SetMin(const double dMin); 00266 double GetMin() const; 00267 BOOL SetMax(const double dMax); 00268 double GetMax() const; 00269 00270 BOOL SetScale(const double dScale); 00271 double GetScale() const; 00272 00273 BOOL SetRange(const double dMin, const double dMax); 00274 // Operations 00275 BOOL ConvertTo0to1(double& dValue) const; 00276 BOOL ConvertFrom0to1(double& dValue) const; 00277 00278 BOOL StringFromScale(double& dNumber, StringBase* pResult, const UINT32 uSigFigs) const; 00279 protected: 00280 00281 // By dividing by m_dScale we produce a number between 0 & 1 00282 00283 double m_dScale; 00284 00285 // m_pQualifier is the Qualifier used to identify unit 00286 00287 Qualifier* m_pQualifier; 00288 00289 // The number of decimal places to show 00290 00291 UINT32 m_nDPtoShow; 00292 00293 // The range for which our unit returns 0 - 1 00294 00295 double m_dMin; 00296 double m_dMax; 00297 00298 private: 00299 // Whether or not ScaleUnit created a new Qualifier 00300 BOOL m_bInternalQualifier; 00301 }; 00302 00303 00304 00305 00306 00307 /********************************************************************************************* 00308 00309 > class UnitGroup : public CC_CLASS_MEMDUMP 00310 00311 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00312 Created: 02/05/96 00313 Purpose: A UnitGroup is a set of ScaleUnits that are interconvertible 00314 Notes: It is possible to violate the integrity of the UnitGroup by changing 00315 ScaleUnits included in the group. Kindly use the UpdateUnit method provided. 00316 00317 **********************************************************************************************/ 00318 class UnitGroup : public CC_CLASS_MEMDUMP 00319 { 00320 CC_DECLARE_MEMDUMP(UnitGroup); 00321 public: 00322 00323 // Constructor & Destructor 00324 UnitGroup(); 00325 UnitGroup(const UnitGroup& GroupToCopy); 00326 BOOL IsValid() {return m_bConstructedOK;} 00327 00328 virtual ~UnitGroup(); 00329 00330 virtual UnitGroup& operator=(const UnitGroup& GroupToCopy); 00331 00332 virtual BOOL operator==(const UnitGroup& RhsGroup) const; 00333 virtual BOOL operator!=(const UnitGroup& RhsGroup) const; 00334 00335 // Group Member manipulation 00336 BOOL AddUnit(ScaleUnit* pUnit); 00337 BOOL AddUnit(ScaleUnit& NewUnit); 00338 ScaleUnit* UpdateUnit(const UINT32 uIndex, ScaleUnit& NewUnit); 00339 BOOL DeleteUnit(ScaleUnit& UnitToDelete); 00340 00341 // Operations for finding units & references given bits of info 00342 ScaleUnit* FindUnitFromQualifier(const String_32& qualifier) const; 00343 ScaleUnit* FindUnitFromIndex(const UINT32 uIndex) const; 00344 INT32 FindIndexFromUnit(const ScaleUnit& thisUnit) const; 00345 // Attributes 00346 UINT32 GetUnitCount() const; 00347 BOOL SetDefaultUnit(ScaleUnit* pUnit); 00348 ScaleUnit* GetDefaultUnit() const; 00349 // Conversion 00350 BOOL ScaleFromString(const StringBase& string, double& dNumber) const; 00351 00352 protected: 00353 List m_UnitList; 00354 List m_UnitRefList; 00355 ScaleUnit* m_pDefaultUnit; 00356 00357 // Overridables 00358 virtual void OnUnitChanged(const ScaleUnit& UpdatedUnit); 00359 virtual BOOL AllowDeletion(const ScaleUnit& UnitToDelete); 00360 virtual void OnDeleteCompletion(const ScaleUnit& DeletedUnit); 00361 00362 private: 00363 BOOL m_bConstructedOK; 00364 }; 00365 00366 00367 00368 /********************************************************************************************* 00369 00370 > class StandardUnit 00371 00372 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00373 Created: 02/05/96 00374 Purpose: A class utility defining standard units for use as you please, although 00375 corrupting them may cause some annoyance. 00376 Notes: Contains only static members. 00377 See Also: class UnitGroup, class ScaleUnit 00378 00379 **********************************************************************************************/ 00380 class StandardUnit : public CC_CLASS_MEMDUMP 00381 { 00382 CC_DECLARE_MEMDUMP(StandardUnit); 00383 00384 public: 00385 static BOOL Init(); 00386 static BOOL DeInit(); 00387 00388 static NullQualifier TheNullQualifier; // the Qualifier with no token 00389 // Declare some standard units & groups 00390 static ScaleUnit UnitPercent; // 0..100 00391 static ScaleUnit UnitDecimalD; // 0..255 with big D as qualifier 00392 static ScaleUnit UnitDecimald; // 0..255 with little d as qualifier 00393 static ScaleUnit UnitDegree; // 0..360 00394 00395 static UnitGroup PercentGroup; // UnitDecimald(D) & UnitPercent 00396 static UnitGroup AngleGroup; // UnitDegree 00397 }; 00398 00399 00400 //----------------------------------------------------------------------------------------- 00401 #endif // INC_SCUNITS 00402