marketDefaults.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE:  marketDefaults.h
00004 
00005     DESCRIPTION:  Market Specific Defaults API
00006 
00007     CREATED BY: Cleve Ard
00008 
00009     HISTORY: created 5/19/2003
00010 
00011  *> Copyright (c) 2003, All Rights Reserved.
00012  **********************************************************************/
00013 #pragma once
00014 
00015 #include "coreexp.h"
00016 #include "maxheap.h"
00017 #include "strclass.h"
00018 #include "maxtypes.h"
00019 #include "plugapi.h"
00020 #include "ParamDimension.h"
00021 #include "point3.h"
00022 #include "point4.h"
00023 
00024 // forward declarations
00025 class MarketDefaults;
00026 class MarketDefaults13;
00027 class Point3;
00028 class Point4;
00029 class ReferenceTarget;
00030 class Mtl;
00031 class Texmap;
00032 
00033 // Get the market default settings. We can handle multiple
00034 // files, so third parties can add there own market defaults.
00035 // Name should be the name, without and extension, for the
00036 // default to be retrieved. NULL will retrieve the defaults
00037 // for Autodesk/Discreet settings.
00038 CoreExport MarketDefaults* GetMarketDefaults(const MCHAR* name = NULL);
00039 
00041 
00050 CoreExport MSTR GetMarketDefaultsFileName(const MCHAR* name = NULL);
00051 
00053 
00060 CoreExport MSTR GetMarketDefaultsWriteLocation();
00061 
00063 
00069 class MarketDefaults: public MaxHeapOperators {
00070 public:
00071     typedef bool (*FloatValidator)(float&);
00072     typedef bool (*IntValidator)(int&);
00073     typedef bool (*Point3Validator)(Point3&);
00074     typedef bool (*Point4Validator)(Point4&);
00075     typedef bool (*StringValidator)(MSTR&);
00076     typedef bool (*AnimatableValidator)(Animatable*&);
00077     typedef bool (*ClassIDValidator)(Class_ID&);
00078 
00079     // This class generates range checkers for values. 
00080     template<class T, int low, int high> class Range;
00081 
00082     CoreExport virtual ~MarketDefaults();
00083 
00084     // This function rejects NULL animatable objects
00085     CoreExport static bool CheckNULL(Animatable*& obj);
00086 
00087     // This function rejects Null strings
00088     CoreExport static bool CheckNULL(MSTR& str);
00089 
00090     // This function rejects Class_ID(0, 0) and
00091     // Class_ID(STANDIN_CLASS_ID, 0)
00092     CoreExport static bool CheckNULL(Class_ID& id);
00093 
00094     // High level access to defaults. These return the default
00095     // value, based on the class ID of the object and the name
00096     // of the setting. A default value is supplied, to be used
00097     // when the setting name is not present for the class ID.
00098     // The validator and dimension are only used for setting
00099     // names that are found. The dimension is used to convert
00100     // the UI values in the settings file to internal values
00101     // before the validator is called. The validator may change
00102     // the value. It returns true if the retrieved value is to
00103     // be used, or false if the default value is to be used.
00104     virtual int GetInt(
00105         SClass_ID           objectSuperClass,
00106         const Class_ID&     objectClass,
00107         const MCHAR*        name,
00108         int                 defaultValue,
00109         IntValidator        validator = NULL,
00110         int                 dimension = DIM_NONE
00111     ) = 0;
00112 
00113     int GetTime(
00114         SClass_ID           objectSuperClass,
00115         const Class_ID&     objectClass,
00116         const MCHAR*        name,
00117         int                 defaultValue,
00118         IntValidator        validator = NULL
00119     )
00120     {
00121         return GetInt(objectSuperClass, objectClass, name, defaultValue, validator, DIM_TIME);
00122     }
00123 
00124     virtual float GetFloat(
00125         SClass_ID           objectSuperClass,
00126         const Class_ID&     objectClass,
00127         const MCHAR*        name,
00128         float               defaultValue,
00129         FloatValidator      validator = NULL,
00130         int                 dimension = DIM_NONE
00131     ) = 0;
00132 
00133     float GetAngle(
00134         SClass_ID           objectSuperClass,
00135         const Class_ID&     objectClass,
00136         const MCHAR*        name,
00137         float               defaultValue,
00138         FloatValidator      validator = NULL
00139     )
00140     {
00141         return GetFloat(objectSuperClass, objectClass, name, defaultValue, validator, DIM_ANGLE);
00142     }
00143 
00144     float GetPercentage(
00145         SClass_ID           objectSuperClass,
00146         const Class_ID&     objectClass,
00147         const MCHAR*        name,
00148         float               defaultValue,
00149         FloatValidator      validator = NULL
00150     )
00151     {
00152         return GetFloat(objectSuperClass, objectClass, name, defaultValue, validator, DIM_PERCENT);
00153     }
00154 
00155     float GetWorld(
00156         SClass_ID           objectSuperClass,
00157         const Class_ID&     objectClass,
00158         const MCHAR*        name,
00159         float               defaultValue,
00160         FloatValidator      validator = NULL
00161     )
00162     {
00163         return GetFloat(objectSuperClass, objectClass, name, defaultValue, validator, DIM_WORLD);
00164     }
00165 
00166     float GetColorChannel(
00167         SClass_ID           objectSuperClass,
00168         const Class_ID&     objectClass,
00169         const MCHAR*        name,
00170         float               defaultValue,
00171         FloatValidator      validator = NULL
00172     )
00173     {
00174         return GetFloat(objectSuperClass, objectClass, name, defaultValue, validator, DIM_COLOR255);
00175     }
00176 
00177     virtual Point3 GetPoint3(
00178         SClass_ID           objectSuperClass,
00179         const Class_ID&     objectClass,
00180         const MCHAR*        name,
00181         const Point3&       defaultValue,
00182         Point3Validator     validator = NULL,
00183         int                 dimension = DIM_NONE
00184     ) = 0;
00185 
00186     Point3 GetRGBA(
00187         SClass_ID           objectSuperClass,
00188         const Class_ID&     objectClass,
00189         const MCHAR*        name,
00190         const Point3&       defaultValue,
00191         Point3Validator     validator = NULL
00192     )
00193     {
00194         return GetPoint3(objectSuperClass, objectClass, name, defaultValue, validator, DIM_COLOR255);
00195     }
00196 
00197     virtual Point4 GetPoint4(
00198         SClass_ID           objectSuperClass,
00199         const Class_ID&     objectClass,
00200         const MCHAR*        name,
00201         const Point4&       defaultValue,
00202         Point4Validator     validator = NULL,
00203         int                 dimension = DIM_NONE
00204         ) = 0;
00205 
00206     Point4 GetFRGBA(
00207         SClass_ID           objectSuperClass,
00208         const Class_ID&     objectClass,
00209         const MCHAR*        name,
00210         const Point4&       defaultValue,
00211         Point4Validator     validator = NULL
00212         )
00213     {
00214         return GetPoint4(objectSuperClass, objectClass, name, defaultValue, validator, DIM_COLOR);
00215     }
00216 
00217     virtual MSTR GetString(
00218         SClass_ID           objectSuperClass,
00219         const Class_ID&     objectClass,
00220         const MCHAR*        name,
00221         const MCHAR*        defaultValue,
00222         StringValidator     validator = NULL
00223     ) = 0;
00224 
00225     virtual Class_ID GetClassID(
00226         SClass_ID           objectSuperClass,
00227         const Class_ID&     objectClass,
00228         const MCHAR*        name,
00229         const Class_ID&     defaultID,
00230         ClassIDValidator    validator = NULL
00231     ) = 0;
00232 
00233     virtual Animatable* CreateInstance(
00234         SClass_ID           objectSuperClass,
00235         const Class_ID&     objectClass,
00236         const MCHAR*        name,
00237         SClass_ID           superClass,
00238         const Class_ID&     defaultInstance,
00239         AnimatableValidator validator = NULL
00240     ) = 0;
00241     
00242     CoreExport ReferenceTarget* CreateRefTarget(
00243         SClass_ID           objectSuperClass,
00244         const Class_ID&     objectClass,
00245         const MCHAR*        name,
00246         SClass_ID           superClass,
00247         const Class_ID&     defaultInstance,
00248         AnimatableValidator validator = NULL
00249     );
00250 
00251     CoreExport Mtl* CreateMtl(
00252         SClass_ID           objectSuperClass,
00253         const Class_ID&     objectClass,
00254         const MCHAR*        name,
00255         const Class_ID&     defaultInstance,
00256         AnimatableValidator validator = NULL
00257     );
00258 
00259     CoreExport Texmap* CreateTexmap(
00260         SClass_ID           objectSuperClass,
00261         const Class_ID&     objectClass,
00262         const MCHAR*        name,
00263         const Class_ID&     defaultInstance,
00264         AnimatableValidator validator = NULL
00265     );
00266 
00267     // This is the low level interface into the defaults.
00268     // This interface lets you retrive raw values directly from the
00269     // defaults.
00270     virtual bool SectionExists(const MCHAR* section) = 0;
00271     virtual bool SectionExists(SClass_ID sid, const Class_ID& id) = 0;
00272     virtual void SetSectionName(const MCHAR* section) = 0;
00273     virtual void SetSectionName(SClass_ID sid, const Class_ID& id) = 0;
00274     virtual const MCHAR* GetSectionName() = 0;
00275     virtual void DeleteSection(const MCHAR* section) = 0;
00276     virtual void DeleteSection(SClass_ID sid, const Class_ID& id) = 0;
00277 
00278     virtual bool KeyExists(const MCHAR* key) = 0;
00279     virtual bool DeleteKey(const MCHAR* key) = 0;
00280 
00281     virtual bool PutInt(
00282         const MCHAR*    key,
00283         int             val
00284     ) = 0;
00285     virtual bool PutIntArray(
00286         const MCHAR*    key,
00287         int             ct,
00288         const int*      array
00289     ) = 0;
00290     virtual bool PutFloat(
00291         const MCHAR*    key,
00292         float val
00293     ) = 0;
00294     virtual bool PutFloatArray(
00295         const MCHAR*    key,
00296         int             ct,
00297         const float*    array
00298     ) = 0; 
00299     virtual bool PutString(
00300         const MCHAR*    key,
00301         const MCHAR*    str
00302     ) = 0;
00303 
00304     virtual bool GetInt(
00305         const MCHAR*    key,
00306         int&            val
00307     ) = 0;
00308     virtual bool GetIntArray(
00309         const MCHAR*    key,
00310         int&            ct,
00311         int*            array,
00312         int             arrayCt
00313     ) = 0;
00314     virtual bool GetFloat(
00315         const MCHAR*    key,
00316         float&          val
00317     ) = 0;
00318     virtual bool GetFloatArray(
00319         const MCHAR*    key,
00320         int&            ct,
00321         float*          array,
00322         int             arrayCt
00323     ) = 0;
00324     virtual bool GetString(
00325         const MCHAR*    key,
00326         MCHAR*          buf,
00327         int             bufSize
00328     ) = 0;
00329 };
00330 
00331 // Get the market default settings for R13.
00332 CoreExport MarketDefaults13* GetMarketDefaults13(const MCHAR* name = NULL);
00333 
00334 // This class is the extension for R13 with new type.
00335 class MarketDefaults13 : public MarketDefaults
00336 {
00337 public:
00338     typedef bool (*Point2Validator)(Point2&);
00339 
00340     virtual Point2 GetPoint2(
00341         SClass_ID           objectSuperClass,
00342         const Class_ID&     objectClass,
00343         const MCHAR*        name,
00344         const Point2&       defaultValue,
00345         Point2Validator     validator = NULL,
00346         int                 dimension = DIM_NONE
00347         ) = 0;
00348 };
00349 
00350 
00351 
00352 // This class generates range checkers for values. 
00353 template<class T, int low, int high> class MarketDefaults::Range : public MaxHeapOperators
00354 {
00355 public:
00356     // Return whether val is in the range including the endpoints
00357     static bool CheckII(T& val);
00358 
00359     // Return whether val is in the range excluding the low endpoint
00360     static bool CheckEI(T& val);
00361 
00362     // Return whether val is in the range excluding the high endpoint
00363     static bool CheckIE(T& val);
00364 
00365     // Return whether val is in the range excluding the endpoints
00366     static bool CheckEE(T& val);
00367 
00368     // Correct val to fall within the givin range including the endpoints
00369     static bool Correct(T& val);
00370 
00371     // Correct val if it is above the given range. Fail if it is below.
00372     static bool CorrectHigh(T& val);
00373 
00374     // Correct val if it is below the given range. Fail if it is above.
00375     static bool CorrectLow(T& val);
00376 };
00377 
00378 template<class T, int low, int high> bool MarketDefaults::Range<T, low, high>::CheckII(T& val)
00379 {
00380     return val >= T(low) && val <= T(high);
00381 }
00382 
00383 template<class T, int low, int high> bool MarketDefaults::Range<T, low, high>::CheckEI(T& val)
00384 {
00385     return val > T(low) && val <= T(high);
00386 }
00387 
00388 template<class T, int low, int high> bool MarketDefaults::Range<T, low, high>::CheckIE(T& val)
00389 {
00390     return val >= T(low) && val < T(high);
00391 }
00392 
00393 template<class T, int low, int high> bool MarketDefaults::Range<T, low, high>::CheckEE(T& val)
00394 {
00395     return val > T(low) && val < T(high);
00396 }
00397 
00398 template<class T, int low, int high> bool MarketDefaults::Range<T, low, high>::Correct(T& val)
00399 {
00400     if (val < T(low))
00401         val = T(low);
00402     else if (val > T(high))
00403         val = T(high);
00404     return true;
00405 }
00406 
00407 template<class T, int low, int high> bool MarketDefaults::Range<T, low, high>::CorrectHigh(T& val)
00408 {
00409     if (val < T(low))
00410         return false;
00411     if (val > T(high))
00412         val = T(high);
00413     return true;
00414 }
00415 
00416 template<class T, int low, int high> bool MarketDefaults::Range<T, low, high>::CorrectLow(T& val)
00417 {
00418     if (val > T(high))
00419         return false;
00420     if (val < T(low))
00421         val = T(low);
00422     return true;
00423 }
00424