representationManager.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: representationManager.h,v 1.1.4.2 2007/03/28 13:11:43 amoll Exp $
00005 
00006 #ifndef  BALL_VIEW_KERNEL_REPRESENTATIONMANAGER_H
00007 #define  BALL_VIEW_KERNEL_REPRESENTATIONMANAGER_H
00008 
00009 #ifndef BALL_VIEW_KERNEL_REPRESENTATION_H
00010 # include <BALL/VIEW/KERNEL/representation.h>
00011 #endif
00012 
00013 #ifndef BALL_SYSTEM_MUTEX_H
00014 #include <BALL/SYSTEM/mutex.h>
00015 #endif
00016 
00017 #include <QtCore/qwaitcondition.h>
00018 
00019 #include <vector>
00020 
00021 using std::vector;
00022 
00023 namespace BALL
00024 {
00025   class Composite;
00026   class INIFile;
00027 
00028   namespace VIEW
00029   {
00030     class MainControl;
00031     class UpdateRepresentationThread;
00032     class ClippingPlane;
00033 
00044     class BALL_VIEW_EXPORT RepresentationManager
00045       : public Object
00046     {
00047       friend class Representation;
00048       friend class UpdateRepresentationThread;
00049       friend class BALLThread;
00050       friend class MainControl;
00051 
00052       public:
00053 
00054       BALL_CREATE(RepresentationManager)
00055 
00056       
00059 
00060 
00061       typedef HashSet<Representation*> RepresentationSet;
00062 
00064       typedef RepresentationList::Iterator RepresentationsIterator;
00065 
00067       typedef RepresentationList::ConstIterator RepresentationsConstIterator;
00068 
00070 
00073 
00077       RepresentationManager(MainControl* mc = 0);
00078 
00081       RepresentationManager(const RepresentationManager& pm);
00082 
00085       virtual ~RepresentationManager();
00086 
00088 
00091       
00093       const RepresentationManager& operator = (const RepresentationManager& pm);
00094 
00096       bool operator == (const RepresentationManager& pm) const;
00097       
00099       void clear();
00100 
00107       bool remove(Representation& representation, bool send_message = true);
00108 
00113       bool insert(Representation& representation, bool send_message = true);
00114 
00116       const RepresentationList& getRepresentations() const
00117         { return representations_;}
00118 
00120       Size getNumberOfRepresentations() const
00121         { return representations_.size();}
00122 
00124       Representation* createRepresentation();
00125 
00127       bool has(const Representation& representation) const;
00128       
00130       void dump(std::ostream& s, Size depth = 0) const;
00131 
00133       RepresentationsIterator begin() 
00134         { return representations_.begin();}
00135 
00137       RepresentationsConstIterator begin() const
00138         { return representations_.begin();}
00139       
00141       RepresentationsIterator end() 
00142         { return representations_.end();}
00143 
00145       RepresentationsConstIterator end() const
00146         { return representations_.end();}
00147 
00155       RepresentationList removedComposite(const Composite& composite, bool update = true);
00156 
00161       RepresentationList getRepresentationsOf(const Composite& composite);
00162 
00164       void rebuildAllRepresentations();
00165 
00167       const vector<ClippingPlane*>& getClippingPlanes() const { return clipping_planes_;}
00168 
00170       bool removeClippingPlane(ClippingPlane* plane);
00171 
00173       void insertClippingPlane(ClippingPlane* plane);
00174 
00176       void storeRepresentations(INIFile& out);
00177       
00179       void restoreRepresentations(const INIFile& in, const vector<const Composite*>& new_systems);
00180 
00182       void focusRepresentation(const Representation& rep);
00183       
00185       bool willBeUpdated(const Representation& rep) const;
00186 
00188       bool updateRunning() const ;
00189 
00191       bool startRendering(Representation* rep);
00192 
00194       void finishedRendering(Representation* rep);
00195       
00197       bool isBeeingRendered(const Representation* rep) const;
00198 
00199       protected:
00200     
00202       Representation* popRepresentationToUpdate();
00203 
00204       void finishedUpdate_(Representation* rep);
00205 
00206       /*_ Called by Representation::update() to start a multithreaded
00207           Update of the Representation.
00208           (Only used in Multithreaded code.)
00209       */
00210       void update_(Representation& rep);
00211 
00212       //_ List with all representations
00213       RepresentationList representations_;
00214       
00215       HashSet<Representation*> beeing_rendered_;
00216       HashSet<Representation*> beeing_updated_;
00217       HashSet<Representation*> to_update_;
00218 
00219       vector<ClippingPlane*> clipping_planes_;
00220       
00221       // we need to ensure that the mutex is always created correctly before
00222       // the thread that tries to access it!
00223       mutable Mutex               update_mutex_;
00224 
00225       UpdateRepresentationThread* thread_;
00226       bool                        no_update_;
00227       bool                        still_to_notify_;
00228 
00229       MainControl*  main_control_;
00230     };
00231 
00232   } // namespace VIEW
00233 } // namespace BALL
00234 
00235 #endif // BALL_VIEW_KERNEL_REPRESENTATIONMANAGER_H