units.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: units.h
00004 
00005     DESCRIPTION: Include file for real-world units support
00006 
00007     CREATED BY: Tom Hudson
00008 
00009     HISTORY:
00010 
00011  *> Copyright (c) 1995, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 #include "maxheap.h"
00016 #include "strclass.h"
00017 #include "maxtypes.h"
00018 
00019 // The unit types we support
00020 #define UNITS_INCHES        0
00021 #define UNITS_FEET          1
00022 #define UNITS_MILES         2
00023 #define UNITS_MILLIMETERS   3
00024 #define UNITS_CENTIMETERS   4
00025 #define UNITS_METERS        5
00026 #define UNITS_KILOMETERS    6
00027 
00028 #define MAX_UNIT_TYPES 7
00029 
00030 // The unit display types
00031 #define UNITDISP_GENERIC    0
00032 #define UNITDISP_METRIC     1
00033 #define UNITDISP_US         2
00034 #define UNITDISP_CUSTOM     3
00035 
00036 #define MAX_UNITDISP_TYPES 4
00037 
00038 // Metric display options
00039 #define UNIT_METRIC_DISP_MM 0
00040 #define UNIT_METRIC_DISP_CM 1
00041 #define UNIT_METRIC_DISP_M  2
00042 #define UNIT_METRIC_DISP_KM 3
00043 
00044 #define MAX_METRIC_DISP_TYPES 4
00045 
00046 // US display options
00047 #define UNIT_US_DISP_FRAC_IN    0
00048 #define UNIT_US_DISP_DEC_IN     1
00049 #define UNIT_US_DISP_FRAC_FT    2
00050 #define UNIT_US_DISP_DEC_FT     3
00051 #define UNIT_US_DISP_FT_FRAC_IN 4
00052 #define UNIT_US_DISP_FT_DEC_IN  5
00053 
00054 #define MAX_US_DISP_TYPES 6
00055 
00056 // US display options
00057 #define UNIT_FRAC_1_1   0
00058 #define UNIT_FRAC_1_2   1
00059 #define UNIT_FRAC_1_4   2
00060 #define UNIT_FRAC_1_8   3
00061 #define UNIT_FRAC_1_10  4
00062 #define UNIT_FRAC_1_16  5
00063 #define UNIT_FRAC_1_32  6
00064 #define UNIT_FRAC_1_64  7
00065 #define UNIT_FRAC_1_100 8
00066 
00067 #define MAX_FRAC_TYPES 9
00068 
00069 // Units designator types
00070 #define UNIT_DESIG_MM       0
00071 #define UNIT_DESIG_CM       1
00072 #define UNIT_DESIG_M        2
00073 #define UNIT_DESIG_KM       3
00074 #define UNIT_DESIG_IN       4
00075 #define UNIT_DESIG_FT       5
00076 #define UNIT_DESIG_CUSTOM   6
00077 
00078 #define UNIT_DESIG_TYPES     7
00079 
00080 // Display information structure
00081 
00086 struct DispInfo: public MaxHeapOperators {
00093     int dispType;               // Display type (UNITDISP_GENERIC, UNITDISP_METRIC, UNITDISP_US, UNITDISP_CUSTOM)
00100     int metricDisp;             // Metric display option
00109     int usDisp;                 // US display option
00121     int usFrac;                 // US fraction option
00123     MSTR customName;            // Custom unit name
00125     float customValue;          // Custom unit value
00130     int customUnit;             // Custom unit reference
00131     };
00132 
00133 // Get the master scale in terms of the specified unit type
00134 // i.e. GetMasterScale(UNITS_INCHES) gives number of inches per unit
00135 // Returns -1.0 if invalid unit type supplied
00136 CoreExport double GetMasterScale(int type);
00137 
00139 
00146 CoreExport double GetRelativeScale(int fromType, float fromScale, int toType, float toScale);
00147 
00148 CoreExport void GetMasterUnitInfo(int *type,float *scale);
00149 CoreExport int SetMasterUnitInfo(int type,float scale);
00150 CoreExport void GetUnitDisplayInfo(DispInfo *info);
00151 CoreExport int SetUnitDisplayInfo(DispInfo *info);
00152 CoreExport int GetUnitDisplayType();
00153 CoreExport int SetUnitDisplayType(int type);
00154 CoreExport BOOL IsValidUnitCharacter(int ch);   // Returns TRUE if character valid for unit type
00155 
00156 // The US unit defaults
00157 #define US_UNIT_DEFAULT_FEET 0
00158 #define US_UNIT_DEFAULT_INCHES 1
00159 
00160 // Get/set the default units for US entry fields -- Inches or feet
00161 CoreExport void SetUSDefaultUnit(int type);
00162 CoreExport int GetUSDefaultUnit();
00163 
00164 CoreExport MCHAR *GetFirstUnitName();
00165 CoreExport MCHAR *GetNextUnitName();
00166 CoreExport MCHAR *GetFirstMetricDisp();
00167 CoreExport MCHAR *GetNextMetricDisp();
00168 CoreExport MCHAR *GetFirstUSDisp();
00169 CoreExport MCHAR *GetNextUSDisp();
00170 CoreExport MCHAR *GetFirstFraction();
00171 CoreExport MCHAR *GetNextFraction();
00172 CoreExport MCHAR *FormatUniverseValue(float value);
00173 CoreExport float DecodeUniverseValue(MCHAR *string, BOOL *valid = NULL);
00174 
00175 
00176 //
00177 // Time units
00178 //
00179 
00180 // Ways to display time
00181 enum TimeDisp {
00182     DISPTIME_FRAMES,
00183     DISPTIME_SMPTE,
00184     DISPTIME_FRAMETICKS,
00185     DISPTIME_TIMETICKS
00186     };
00187 
00188 // Formats a time value into a string based on the current frame rate, etc.
00189 CoreExport void TimeToString(TimeValue t,MSTR &string);
00190 CoreExport BOOL StringToTime(MSTR string,TimeValue &t);
00191 
00192 CoreExport int GetFrameRate();
00193 CoreExport void SetFrameRate(int rate);
00194 CoreExport int GetTicksPerFrame();
00195 CoreExport void SetTicksPerFrame(int ticks);
00196 CoreExport TimeDisp GetTimeDisplayMode();
00197 CoreExport void SetTimeDisplayMode(TimeDisp m);
00198 CoreExport int LegalFrameRate(int r);
00199 
00200 // Register a default value for a distance value.  The section and key are used
00201 // to place the default in the .INI file.  The default has separate values for
00202 // both Imperial and Mtric systems.  The Imperial default is given in inches
00203 // and the Metric default is given in Meters.
00204 CoreExport void RegisterDistanceDefault(MCHAR* section, MCHAR* key, float inchesDefault, float metersDefault);
00205 
00206 // Restore a default value for a distance value.  The section and key are used
00207 // to place the default in the .INI file.  The default has separate values for
00208 // both Imperial and Metric systems.  The Imperial default is given in inches
00209 // and the Metric default is given in Meters.
00210 CoreExport void RestoreDistanceDefault(MCHAR* section, MCHAR* key, float inchesDefault, float metersDefault);
00211 
00212 // Get the default for the given section and key in the defaults file.
00213 // The system returns the default relative to the current system units.
00214 // If the units are Imperial (inches, feet, etc.) it returns the Imperial
00215 // version of the default, otherwise it returns the Metric version.
00216 // In either case the default value is returned in the current system units.
00217 CoreExport float GetDistanceDefault(MCHAR* section, MCHAR* key);
00218 
00219 // Sets the defaults for the given section and key in the defaults file.
00220 // The system sets the default relative to the current system units.
00221 // If the units are Imperial (inches, feet, etc.) it sets the Imperial
00222 // version of the default, otherwise it sets the Metric version.
00223 CoreExport void SetDistanceDefault(MCHAR* section, MCHAR* key, float value);
00224