Veda/InterfacePrefObject.h

Go to the documentation of this file.
00001 /*! \file 
00002     \author victorien ferry & www.m4nkind.com
00003     \brief This file applies the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 , read file COPYING.
00004 */
00005 #ifndef COM_M4NKIND_InterfacePrefObject_H
00006 #define COM_M4NKIND_InterfacePrefObject_H
00007 
00008 #include "BaseObject.h"
00009 #include "PackULong_Flags.h"
00010 #include "PackLong.h"
00011 #include "PackULong_Enums.h"
00012 #include "PackList.h"
00013 #include "PackObjectReference.h"
00014 #include "PackFloat_FixedPoint.h"
00015 #include "PackFloatByte_Limits.h"
00016 class BaseContext;
00017 
00018 /*!
00019     \class  InterfacePrefObject
00020     \ingroup BaseObjectInheritedDocGroup BaseObjectInherited_Veda
00021     \brief  This class provide a unified way to stock preferences and states informations about
00022             a GUI that would edit a AzurVeda Context, so it is saved within a context. Basically,
00023             an editor should use Get()/Set() and serialization, to keep the current objects
00024             edited and previewed. 
00025             It is not registered to BaseContext by default. you got to register it or not, 
00026             according to your needs. Thus, it has to be registered first if you use inherited 
00027             classes. ( through BaseContext::RegisterClassList() of course ).
00028             As editor preferences may be only useful during edition, it is
00029             of course possible to flush these objects from the context, like any other objects.
00030             This class has no sense in non editable mode and should just not be used in such compilation mode.
00031 */
00032 
00033 class InterfacePrefObject : public BaseObject
00034 {
00035 /*==================================================================
00036                                 PUBLIC
00037 ==================================================================*/
00038 public:
00039 
00040     /*!
00041         \brief  Constructor. There should only be members initialisation there.
00042     */
00043     InterfacePrefObject(void);
00044 
00045     /*!
00046         \brief  Class Inheritance Descriptors. Also forces a destructor. See BASEOBJECT_DECLARE_... in .cpp
00047     */
00048     BASEOBJECT_DEFINE_CLASS(InterfacePrefObject);
00049 #ifdef _ENGINE_EDITABLE_
00050     /*!
00051         \brief  get the size of the whole byte chunk that will be written by Serialize_Out().
00052                 Special process: purge all null pointer links in the object before serialization.
00053         \return byte size of the serialisation to do.
00054     */
00055     virtual unsigned int  GetSerializedDescriptionSize(void);
00056 #endif
00057 #ifdef _ENGINE_EDITABLE_
00058     /*!
00059         \brief  Only one preference object can have the active flag at the same time,
00060                 in the context. This one is returned if it exists.
00061                 If there is no preference object or no active one,
00062                 a new peference object is created, set active, and returned.
00063         \param  _pContext the context where to search the active preference..
00064         \return a preference object or NULL.
00065     */
00066     static  InterfacePrefObject *GetContextActivePref(BaseContext *_pContext,bool _createOneIfNone=false);
00067 #endif
00068 #ifdef _ENGINE_EDITABLE_
00069     /*!
00070         \brief  Set the edited object in interface. It affects the current active 
00071                 Preference object in the context. (it creates one if there wasnt one).
00072                 The _ObjectToEdit must belong to _pContext.
00073                 if _ObjectToEdit is NULL, the edited object is set to NULL 
00074                 (no edit.)
00075         \param  _ObjectToEdit the object to preview.
00076         \param _EditViewIndex if the editor support multiple object edition, an abstract index of the view affected.
00077     */
00078     void    SetContextEditedObject(BaseObject *_ObjectToEdit,unsigned int _EditViewIndex=0);
00079 #endif
00080 #ifdef _ENGINE_EDITABLE_
00081     /*!
00082         \brief  Get a current edited object for a context.
00083                     If there are none, return 0L.
00084         \param _EditViewIndex if there is support for multiple editors, the index of the editor affected.
00085         \return the current edtited object or 0L.
00086     */
00087     BaseObject *GetContextEditedObject(unsigned int _EditViewIndex=0);
00088 #endif
00089 #ifdef _ENGINE_EDITABLE_
00090     /*!
00091         \brief  Edit Previous: scroll down the history of edited object. May Change result of GetContextPreviewObject().
00092         \param _RenderViewIndex if the viewer support multiple previews, the index of the preview affected.
00093     */
00094     void EditPrevious(unsigned int _RenderViewIndex=0);
00095 #endif
00096 #ifdef _ENGINE_EDITABLE_
00097     /*!
00098         \brief  Edit Next: scroll up the history of edited object. May Change result of GetContextPreviewObject().
00099         \param _RenderViewIndex if the viewer support multiple previews, the index of the preview affected.
00100     */
00101     void EditNext(unsigned int _RenderViewIndex=0);
00102 #endif
00103     class PackObjectReferenceSpecial;
00104     friend class PackObjectReferenceSpecial;
00105     /*!
00106         \brief   nested class to patch PackObjectReference so that
00107                     If set to null pointer, it deletes 
00108     */
00109     class   PackObjectReferenceSpecial  : public PackObjectReference
00110     {   public:
00111 
00112         /*! \brief constructor */
00113         PackObjectReferenceSpecial() : PackObjectReference(){};
00114 #ifdef _ENGINE_EDITABLE_
00115         /*!
00116             \brief  see PackObjectReference::Set()
00117         */
00118         virtual enum_SetReferenceResult SetObjectPointer( BaseObject * _Object );   
00119 #endif
00120     };
00121 
00122     class PackULong_Flags_Activate;
00123     friend class PackULong_Flags_Activate;
00124     /*!
00125         \brief   nested class to patch the activate flag edition
00126     */
00127     class PackULong_Flags_Activate : public PackULong_Flags
00128     { public:
00129 #ifdef _ENGINE_EDITABLE_
00130         /*!
00131             \brief  change the value:
00132             \param  _value 28b unsigned int value.
00133         */
00134         virtual void    Set(unsigned int _value); 
00135 #endif
00136     };
00137     /*!
00138         \brief   Nested class that describes a reference to an object preview.
00139     */
00140     class PreviewEdited : public PackStruct
00141     {
00142     public:
00143         //! the reference to an object:
00144         PackObjectReferenceSpecial  mSer_Reference;
00145         //! for previous/next
00146         static const unsigned int m_PF_HistoryFlag=1;
00147         //! if true, the preview is in play mode.
00148         static const unsigned int m_PF_PlayState=2;
00149         //! flag for history browsing:
00150         PackULong_Flags     mSer_Flag;
00151         //! rectangle of the preview viewport. def is(0,0,1,1)
00152         PackFloat           mSer_Corner1;
00153         //! rectangle of the preview viewport. def is(0,0,1,1)
00154         PackFloat           mSer_Corner2;
00155         //! Position
00156         PackFloat           mSer_PreviewPosition;
00157         //!  Rotation
00158         PackFloat           mSer_PreviewRotation;
00159         //!  preview time lapse start
00160         PackFloat           mSer_PreviewStartTime;
00161         //!  preview time lapse end
00162         PackFloat           mSer_PreviewEndTime;
00163         //! preview time current time:
00164         PackFloat           mSer_PreviewCurrentTime;
00165         //! TimePreviewer: playspeed, default 1.0
00166         PackFloat           mSer_PlaySpeed;
00167 
00168         PreviewEdited(void) : PackStruct()
00169             ,mSer_Corner1(PackFloat::vd_XY)
00170             ,mSer_Corner2(PackFloat::vd_XY)
00171             ,mSer_PreviewPosition(PackFloat::vd_XYZ)
00172             ,mSer_PreviewRotation(PackFloat::vd_XYZ)
00173             ,mSer_PreviewStartTime(PackFloat::vd_X)
00174             ,mSer_PreviewEndTime(PackFloat::vd_X)
00175             ,mSer_PreviewCurrentTime(PackFloat::vd_X)
00176             ,mSer_PlaySpeed(PackFloat::vd_X)
00177         {
00178             // Note the "InfoString" of the members are null (0L), so that 
00179             // modifying them is not managed by undo and does not produce update events.
00180             REGISTER_MEMBER_REFERENCE(mSer_Reference ,/*"Object"*/0L, BaseObject::m_Description );
00181             REGISTER_MEMBER_PACKULONG(mSer_Flag ,0L,0 );
00182             REGISTER_MEMBER_PACKFLOAT_XY(mSer_Corner1 ,0L,0.0f,0.0f );
00183             REGISTER_MEMBER_PACKFLOAT_XY(mSer_Corner2 ,0L,1.0f,1.0f );
00184             REGISTER_MEMBER_PACKFLOAT_XYZ(mSer_PreviewPosition ,0L,0.0f,0.0f,0.0f );
00185             REGISTER_MEMBER_PACKFLOAT_XYZ(mSer_PreviewRotation ,0L,0.0f,0.0f,0.0f );
00186             REGISTER_MEMBER_PACKFLOAT(mSer_PreviewStartTime ,0L/*"Start"*/,0.0f );
00187             REGISTER_MEMBER_PACKFLOAT(mSer_PreviewEndTime ,0L/*"End"*/,360.0f );
00188             REGISTER_MEMBER_PACKFLOAT(mSer_PreviewCurrentTime ,0L/*"Time"*/,0.0f );
00189             REGISTER_MEMBER_PACKFLOAT(mSer_PlaySpeed ,0L/*"Speed"*/,1.0f );
00190 #ifdef _ENGINE_EDITABLE_
00191             m_PreviewConfiguration.m_pManager = this;
00192 #endif
00193         };
00194 #ifdef _ENGINE_EDITABLE_
00195         /*!
00196             \brief   fill a PreviewConfiguration class, to return the object contract for preview.
00197         */
00198         class InterfacePreviewConfiguration  : public PreviewConfiguration
00199         { public:
00200             PreviewEdited   *m_pManager;
00201 
00202             //! \brief  Set a viewport scale in 0.0,0.0,1.0,1.0 units. useful to zoom 2D previews..
00203             virtual void    SetViewportScale(float _x1,float _y1,float _x2,float _y2) const
00204             {  
00205                 m_pManager->mSer_Corner1.Set(_x1);
00206                 m_pManager->mSer_Corner1.Set(1,_y1);
00207                 m_pManager->mSer_Corner2.Set(_x2);
00208                 m_pManager->mSer_Corner2.Set(1,_y2);  } ;
00209             //! \brief  return a viewport scale in 0.0,0.0,1.0,1.0 units. useful to zoom 2D previews..
00210             virtual void    GetViewportScale(float &_x1,float &_y1,float &_x2,float &_y2) const
00211             {  
00212                 _x1 = m_pManager->mSer_Corner1.Get(0);
00213                 _y1 = m_pManager->mSer_Corner1.Get(1);
00214                 _x2 = m_pManager->mSer_Corner2.Get(0);
00215                 _y2 = m_pManager->mSer_Corner2.Get(1);  } ;
00216             //! \brief  set an edited object position in a preview.
00217             virtual void    SetPreviewPosition(float _PositionX,float _PositionY,float _PositionZ ) const
00218             {    m_pManager->mSer_PreviewPosition.Set(_PositionX);
00219                  m_pManager->mSer_PreviewPosition.Set(1,_PositionY);
00220                  m_pManager->mSer_PreviewPosition.Set(2,_PositionZ);                
00221             };
00222             //! \brief  return an edited object position in a preview.
00223             virtual void    GetPreviewPosition(float &_PositionX,float &_PositionY,float &_PositionZ ) const
00224             {   _PositionX = m_pManager->mSer_PreviewPosition.Get(0);
00225                 _PositionY = m_pManager->mSer_PreviewPosition.Get(1);
00226                 _PositionZ = m_pManager->mSer_PreviewPosition.Get(2);               
00227             };
00228             //! \brief  set a rotation in a preview.
00229             void    SetPreviewRotation(float _Xaxis,float _YAxis,float _ZAxis)
00230             {   m_pManager->mSer_PreviewRotation.Set( _Xaxis);
00231                 m_pManager->mSer_PreviewRotation.Set(1,_YAxis);
00232                 m_pManager->mSer_PreviewRotation.Set(2,_ZAxis);             
00233             };
00234             //! \brief  return a rotation in a preview.
00235             virtual void    GetPreviewRotation(float &_Xaxis,float &_YAxis,float &_ZAxis) const 
00236             {   _Xaxis = m_pManager->mSer_PreviewRotation.Get(0);
00237                 _YAxis = m_pManager->mSer_PreviewRotation.Get(1);
00238                 _ZAxis = m_pManager->mSer_PreviewRotation.Get(2);               
00239             };
00240             //! \brief  return 0L or a pointer on a focused member, or sub-member, or member of another object that may be linked to this one.
00241             virtual const BaseType  *GetFocusedObjectPointer() const
00242             {   return 0L; //TODO
00243             };
00244             //! \brief  return a draw preference flag.(draw grid, etc...)
00245             virtual unsigned int    GetDrawPreferenceFlag() const 
00246             {
00247                 return 0L;// TODO
00248             };
00249             //! \brief preview time lapse start
00250             virtual double  GetPreviewStartTime() const
00251             {
00252                 return m_pManager->mSer_PreviewStartTime.Get();
00253             };
00254             //! \brief preview time end start
00255             virtual double  GetPreviewEndTime() const 
00256             {
00257                 return m_pManager->mSer_PreviewEndTime.Get();           
00258             };
00259 
00260             /*!
00261                 \brief  Set the start time of the time range displayed in seconds.
00262                 \param _timeSec Start time of the time range displayed in seconds.
00263             */
00264             inline void SetPreviewStartTime(float _timeSec){    m_pManager->mSer_PreviewStartTime.Set( _timeSec );};        
00265             /*!
00266                 \brief  Start time of the time range displayed in seconds.
00267                 \return Start time of the time range displayed in seconds.
00268             */
00269             inline float    GetPreviewStartTime(){ return m_pManager->mSer_PreviewStartTime.Get(); };
00270             /*!
00271                 \brief  Set End time of the time range displayed in seconds.
00272                 \param  _timeSec End time of the time range displayed in seconds.
00273             */
00274             inline void SetPreviewEndTime(float _timeSec){      m_pManager->mSer_PreviewEndTime.Set(_timeSec); };
00275             /*!
00276                 \brief  End time of the time range displayed in seconds.
00277                 \return End time of the time range displayed in seconds.
00278             */
00279             inline float    GetPreviewEndTime(){ return m_pManager->mSer_PreviewEndTime.Get(); };
00280             /*!
00281                 \brief  A GUI preview can manage a Video Recorder-like interface.
00282                         An interface pref object can handle a preview time, but this is just
00283                         an interface state information, it is not necessarily used directly by the context for playing.
00284                 \param  _timeSec the current time position in seconds.
00285             */
00286             inline void SetPreviewCurrentTime(float _timeSec){  m_pManager->mSer_PreviewCurrentTime.Set(_timeSec); };
00287             /*!
00288                 \brief  A GUI preview can manage a Video Recorder-like interface.
00289                         An interface pref object can handle a preview time, but this is just
00290                         an interface state information, it is not necessarily used directly by the context for playing.
00291                 \return the current time position in seconds.
00292             */
00293             inline float    GetPreviewCurrentTime(){ return m_pManager->mSer_PreviewCurrentTime.Get(); };
00294             /*!
00295                 \brief  Set Play Speed rate. 1.0 means normal. >1.0 means faster, 0.0 mean pause, <0.0 means reverse.
00296                 \param  _speedRate  Play Speed rate.
00297             */
00298             inline void SetPlaySpeed(float _speedRate){     m_pManager->mSer_PlaySpeed.Set( _speedRate ); };
00299             /*!
00300                 \brief  Play Speed rate. 1.0 means normal. >1.0 means faster, 0.0 mean pause, <0.0 means reverse.
00301                 \return Play Speed rate.
00302             */
00303             inline float    GetPlaySpeed(){ return m_pManager->mSer_PlaySpeed.Get(); };         
00304             /*!
00305                 \brief  set play state.
00306                 \param  _isPlaying true to play, stop to pause.
00307             */
00308             inline void SetPlayState(bool _isPlaying){ if(_isPlaying)m_pManager->mSer_Flag.AddFlags(m_PF_PlayState);
00309                                                         else m_pManager->mSer_Flag.RemoveFlags(m_PF_PlayState); };
00310             /*!
00311                 \brief  set play state.
00312                 \return true to play, stop to pause.
00313             */
00314             inline bool GetPlayState(){ return m_pManager->mSer_Flag.TestFlags(m_PF_PlayState); };
00315 
00316         };
00317         InterfacePreviewConfiguration   m_PreviewConfiguration;
00318 #endif
00319     };
00320     /*!
00321         \brief  static method passed to the list to create new elements.
00322         \return a new PartToPlay object.
00323     */
00324     static BaseType *NewPreviewEdited(){ return new PreviewEdited(); };
00325     /*!
00326         \brief  static method passed to the list to create new elements.
00327         \return a new PartToPlay object.
00328     */
00329     static BaseType *NewPreviewIndexList(){ return new PackList(NewPreviewEdited); };
00330 #ifdef _ENGINE_EDITABLE_
00331     /*!
00332         \brief  Set the Preview object. It affects the current active 
00333                 Preference object in the context. (it creates one if there wasnt one).
00334                 The _ObjectToPreview must belong to _pContext.
00335                 if _ObjectToPreview is NULL, the Preview object is set to NULL 
00336                 (no preview.)
00337         \param  _ObjectToPreview the object to preview.
00338         \param _RenderViewIndex if the viewer support multiple previews, an abstract index of the preview affected.
00339     */
00340     void    SetContextPreviewObject(BaseObject *_ObjectToPreview,unsigned int _RenderViewIndex=0);
00341 #endif
00342 #ifdef _ENGINE_EDITABLE_
00343     /*!
00344         \brief  Get a current Preview object for a context.
00345                     If there are none, return 0L.
00346         \param _RenderViewIndex if the viewer support multiple previews, the index of the preview affected.
00347         \param _pPreviewConfiguration if not nul, return a pointer to the configuration preview to it.
00348         \return the current Preview object or 0L.
00349     */
00350     BaseObject *GetContextPreviewObject(unsigned int _RenderViewIndex=0,InterfacePrefObject::PreviewEdited::InterfacePreviewConfiguration **_ppPreviewConfiguration=0L);
00351 #endif
00352 #ifdef _ENGINE_EDITABLE_
00353     /*!
00354         \brief  Preview Previous: scroll down the history of previewed object. May Change result of GetContextPreviewObject().
00355         \param _RenderViewIndex if the viewer support multiple previews, the index of the preview affected.
00356     */
00357     void PreviewPrevious(unsigned int _RenderViewIndex=0);
00358 #endif
00359 #ifdef _ENGINE_EDITABLE_
00360     /*!
00361         \brief  Preview Next: scroll up the history of previewed object. May Change result of GetContextPreviewObject().
00362         \param _RenderViewIndex if the viewer support multiple previews, the index of the preview affected.
00363     */
00364     void PreviewNext(unsigned int _RenderViewIndex=0);
00365 #endif
00366     /*!
00367         \brief   Nested class that describes a reference to an object
00368     */
00369     class Edited : public PackStruct
00370     {
00371     public:
00372         //! the reference to an object:
00373         PackObjectReferenceSpecial  mSer_Reference;
00374         //! a serialized but not edited value, just to manage the case when this InterfacePrefObject is edited:(PackObjectReference can't self recurse.)
00375         PackULong_Flags         mSer_Flag;
00376 
00377         //! for previous/next
00378         static const unsigned int m_EF_HistoryFlag=1;
00379         //!
00380         static const unsigned int m_EF_SelfReference=2;
00381         Edited(void) : PackStruct()
00382         {
00383             REGISTER_MEMBER_REFERENCE(mSer_Reference ,0L/*"Object"*/, BaseObject::m_Description );
00384             // we serialize mSer_SelfPrefEditionFlag but don't edit it:
00385             REGISTER_MEMBER( mSer_Flag,0L);
00386         };
00387     };
00388     /*!
00389         \brief  static method passed to the list to create new elements.
00390         \return a new PartToPlay object.
00391     */
00392     static BaseType *NewEdited(){ return new Edited(); };
00393 
00394     /*!
00395         \brief  static method passed to the list to create new elements.
00396         \return a new PartToPlay object.
00397     */
00398     static BaseType *NewEditorIndexList(){ return new PackList(NewEdited); };
00399 #ifdef _ENGINE_EDITABLE_
00400     /*!
00401         \brief  the sound main volume, from an interface editor point of view, not a context point of view.
00402         \param _volume volume [0.0,1.0]
00403     */
00404     inline void SetSoundMainVolume(float _volume){  mSer_SoundMachineMainVolume.Set(_volume); };
00405 #endif
00406 #ifdef _ENGINE_EDITABLE_
00407     /*!
00408         \brief  the sound main volume, from an interface editor point of view, not a context point of view.
00409         \return volume [0.0,1.0]
00410     */
00411     inline float    GetSoundMainVolume(){ return mSer_SoundMachineMainVolume.Get(); };
00412 #endif
00413 #ifdef _ENGINE_EDITABLE_
00414     /*!
00415         \brief  a context can have zero, one , or more InterfacePrefObject, but only one
00416                 must be active at the same time. Find it with GetContextActivePref()
00417         \return true if it is the active pref, false if not.
00418     */
00419     inline bool IsActive(){ return (mSer_Flags.Get() & ipof_Active); };
00420 #endif
00421 #ifdef _ENGINE_EDITABLE_
00422     /*!
00423         \brief  all reference to this object will be closed. used by deletion done by ClassNode.
00424                 special close.
00425     */
00426     virtual void CloseReferences();
00427 #endif
00428 /*==================================================================
00429                                 PROTECTED
00430 ==================================================================*/
00431 protected:
00432     //! mSer_Flags states.
00433     static const unsigned int   ipof_Active=1;
00434     //! mSer_Flags states.
00435     static const unsigned int   ipof_IsPlaying=1<<1;
00436     //! Draw Path As Lines.
00437     static const unsigned int   ipof_DrawPathAsLines=1<<2;
00438     //! at destruction, we lock, to escape unfinite loop:
00439     bool        m_isBeingDestroyed;
00440 
00441     //! Flags ipof_...
00442     PackULong_Flags_Activate    mSer_Flags;
00443 
00444     // ------------- preview conf ------------
00445     //! the way the preview are all shown on the interface.
00446     PackULong_Enums         mSer_PreviewShapeConfiguration;
00447     //! list by possible multiple preview
00448     PackList                mSer_PreviewIndexList;
00449     // ------------- object editor ------------
00450     //! 
00451     PackULong_Enums         mSer_ObjectEditorShapeConfiguration;
00452     //! list by possible multiple editors
00453     PackList                mSer_EditorIndexList;
00454         
00455     // ------------ sound -------------
00456     //! TimePreviewer: playspeed, default 1.0
00457     PackFloatByte_Limits    mSer_SoundMachineMainVolume;
00458     
00459     // ------------ Protected Tools ------
00460 #ifdef _ENGINE_EDITABLE_
00461     /*
00462         \brief protected: if not done, create a preview history list for an indexed view.
00463         \param  optionnal index of the view.
00464         \return the list, which itself manages PreviewEdited objects.
00465     */
00466     PackList    *GetOrCreatePreviewIndexList( unsigned int _RenderViewIndex=0);
00467 #endif
00468 #ifdef _ENGINE_EDITABLE_
00469     /*
00470         \brief protected: if not done, create a Editor history list for an indexed view.
00471         \param  optionnal index of the view.
00472         \return the list, which itself manages PreviewEdited objects.
00473     */
00474     PackList    *GetOrCreateEditorIndexList( unsigned int _RenderViewIndex=0);
00475 #endif
00476 #ifdef _ENGINE_EDITABLE_
00477     /*
00478         \brief protected tool, delete all edition or preview preference that are linked to nothing.
00479     */
00480     void    PurgePreferenceToDeadObjects();
00481 #endif
00482 };
00483 
00484 // end of file
00485 #endif

      /\/\        4         N         k         !         N         D
                      _______  _ __ ___  _____            ___ _ _  ____
     ___________  __//___   /________  |/    / ___________\_______/    \
    /   _   _   \/   _     /    _   /      _/_/____/    _       __     /
   /    /   /       /     /    /    \      \/     /    /    \   \     /
  \\___/___/___/    ¯    _____/_____/       ______\___/_____/\________\\
               \________/_ ___ __ l____\      /elD!  
                 http://www.m4nkind.com \____/