00001 // $Id: convert.h 1269 2006-06-08 09:27:36Z 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 // The following few functions and types are used in convert.cpp 00100 // to allow convertion between strings and millipoints. There main 00101 // use will probably be for interacting with users via dialog boxes. 00102 00103 /* 00104 */ 00105 00106 #ifndef INC_CONVERT 00107 #define INC_CONVERT 00108 00109 #include "unittype.h" 00110 00111 class Node; 00112 //class DimScale; 00113 00114 /*********************************************************************************************** 00115 00116 > class Convert : public CCObject 00117 00118 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00119 Created: 12/9/95 00120 Purpose: This class is used to convert things from one form to another. Mainly contains 00121 static functions. 00122 Started life as a series of conversion functions before being made to see the 00123 light and profess the one and only true class. 00124 At present in the Winoil class as it needs converting to TCHARs and using the 00125 MFC forms of scanf and sprintf .. 00126 00127 Note by Rik who did the original functions 11/5/93:- 00128 00129 These functions will provide a means of converting from Doc Coords (millipoints) 00130 to Strings and visa versa. For example, convert 72000 millipoints to the string 00131 1in or 72pt as well as converting from the string '1in72pt' to 144000 00132 millipoints. The units to convert to can be chosen, as can the number of 00133 decimal points. When converting from string back to millipoints, all the valid 00134 units are added together. If an error is detected (ie '4cm72zx' ), then 00135 everything up to the error will be used (4cm). 00136 00137 SeeAlso: DimScale, Spread, Layer 00138 00139 ***********************************************************************************************/ 00140 00141 class Convert 00142 { 00143 00144 public: 00145 // Allows us to declare preferences, read the current number formats from the operating 00146 // system etc. 00147 static BOOL Init(); 00148 00149 // This is the setting function for the values below, as these are read from the OS. 00150 static BOOL GetCurrentNumberFormat(); 00151 00152 // Allows other classes to find out factors about the current number format which the 00153 // conversion class is using. 00154 static char GetDecimalPointChar(); 00155 static char GetThousandsSepChar(); 00156 static UINT32 GetNumberDecimalPlaces(); 00157 00158 // Just incase we decide these are required to overide the OS's defaults. 00159 static BOOL SetDecimalPointChar(char NewDecimalPoint); 00160 static BOOL SetThousandsSepChar(char NewThousandsSep); 00161 static BOOL SetNumberDecimalPlaces(UINT32 NewDPs); 00162 00163 public: 00164 // Now for some actual conversion functions 00165 static MILLIPOINT StringToMillipoints( const StringBase &, UnitType, BOOL* ); 00166 static void NumberToString( MILLIPOINT Number, StringBase* MyString ); 00167 static BOOL MillipointsToString( double, UnitType, StringBase*, INT32 DecimalPlaces = -1); 00168 static double StringToDouble( const StringBase &, UnitType, BOOL * ); 00169 static BOOL StringToDouble( const StringBase &InputString, double *Number); 00170 static BOOL DoubleToString( double Number, StringBase* OutputString, INT32 DecimalPlaces = -1 ); 00171 00172 static BOOL StringToComponents(const StringBase &InputString,double* pValue,UnitType* pUnits); 00173 static double ConvertToNewUnits(double Value,UnitType Units,UnitType NewUnits); 00174 static BOOL ConvertDoubleToMillipoint(double Value,MILLIPOINT* pResult); 00175 static void ConvertMillipointToDouble(MILLIPOINT Value,double* pResult); 00176 00177 static BOOL LongToString( INT32 Number, StringBase* OutputString ); 00178 static BOOL StringToLong( const StringBase &InputString, INT32* Number ); 00179 00180 // Convert memory values to strings and strings to memory values 00181 static UINT32 StringToBytes(const StringBase &pString, BOOL *Valid); 00182 static BOOL BytesToString(StringBase* pString, UINT32 Bytes); 00183 00184 // Some useful functions 00185 static BOOL ReplaceDecimalPoint(StringBase* pString); 00186 static BOOL StripTrailingZeros(StringBase* pString); 00187 static BOOL IsCharUnitType(TCHAR Char); 00188 static BOOL IsCharStartOfNumber(TCHAR Char); 00189 static BOOL ReadUnitType(const StringBase &Str,INT32* pPos,UnitType* pUnitType); 00190 static BOOL ReadNumber(const StringBase &Str,INT32* pPos,double* pResult); 00191 00192 // This defines a name for a pointer to the "string parser" function that takes 00193 // a string and calculates the number from it, returning TRUE if it is valid. 00194 00195 typedef BOOL (*PFNSTRINGTOINT32)(const StringBase &, INT32*); 00196 typedef BOOL (*PFNSTRINGTODOUBLE)(const StringBase &, double*); 00197 00198 protected: 00199 // These are the default display options 00200 static char DecimalPoint; // Character to separate whole part of number from fractional part 00201 static char ThousandSep; // Character to separate thousands, e.g. 10,000 00202 static char MinusSign; // What to show if go less than zero 00203 static UINT32 NumDecimalPlaces; // Number of decimal places to display to by default 00204 00205 }; 00206 00207 /*********************************************************************************************** 00208 00209 > class DimScale : public CCObject 00210 00211 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00212 Created: 14/6/93 00213 Purpose: This class is used to scale millipoint dimension values to and from a user-set 00214 preference. 00215 E.g. the user may specify that 1 mile = 2 centimetres. This class will record 00216 the units (in this case miles) and the scale factor used to convert internal 00217 millipoint values to and from the units the user wishes to work in. 00218 00219 SeeAlso: Spread, Layer 00220 00221 ***********************************************************************************************/ 00222 00223 class DimScale : public CCObject 00224 { 00225 CC_DECLARE_DYNAMIC( DimScale ) 00226 public: 00227 DimScale(); 00228 00229 BOOL IsActive(); 00230 void SetActiveState(BOOL State); 00231 00232 double GetScaleFactor(); 00233 BOOL SetScaleFactor(double NewScaleFactor); 00234 BOOL SetScaleFactor(); // Sets the scale factor using 'Drawing' and 'Real' strings 00235 00236 UnitType GetUnits(); 00237 UnitType GetScaleUnits(); 00238 00239 String_32 GetDrawingScaleStr(); 00240 BOOL SetDrawingScaleStr(String_32& NewStr); 00241 String_32 GetRealScaleStr(); 00242 BOOL SetRealScaleStr(String_32& NewStr); 00243 00244 BOOL ConvertToUnits(double Value,String_256* pStr,BOOL UnitSpecifier=TRUE, 00245 INT32 dp=-1, UnitType units=NOTYPE, BOOL bSquare = FALSE); 00246 BOOL ConvertToMillipoints(const StringBase& Str, MILLIPOINT* pMpValue); 00247 BOOL ConvertToDouble(const StringBase& Str,double* pResult); 00248 00249 BOOL ComponentsToMillipoint(double* pMillipoint, double Number, UnitType Units); 00250 00251 DimScale& operator=(const DimScale& other); 00252 BOOL operator==(const DimScale& other); 00253 00254 static BOOL Init(); // Must be called before any other call in this class 00255 static void Deinit(); // Cleans up before the program quits 00256 static DimScale* GetPtrDimScale(Node* pNode); 00257 static DimScale* GetPtrDefaultDimScale(); 00258 00259 private: 00260 BOOL Active; 00261 double ScaleFactor; 00262 String_32 DrawingScaleStr; 00263 String_32 RealScaleStr; 00264 00265 // // The default DimScale object is an inactive one that is used as a fall-back in the 00266 // // frightening event of one not being found by DimScale::GetPtrDimScale(Node*) 00267 // static DimScale * pDefaultDimScale; 00268 }; 00269 00270 #endif // INC_CONVERT