GElement.h

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2005 by Raphael Langerhorst                        *
00003  *   raphael-langerhorst@gmx.at                                            *
00004  *                                                                         *
00005  *   Permission is hereby granted, free of charge, to any person obtaining *
00006  *   a copy of this software and associated documentation files (the       *
00007  *   "Software"), to deal in the Software without restriction, including   *
00008  *   without limitation the rights to use, copy, modify, merge, publish,   *
00009  *   distribute, sublicense, and/or sell copies of the Software, and to    *
00010  *   permit persons to whom the Software is furnished to do so, subject to *
00011  *   the following conditions:                                             *
00012  *                                                                         *
00013  *   The above copyright notice and this permission notice shall be        *
00014  *   included in all copies or substantial portions of the Software.       *
00015  *                                                                         *
00016  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
00017  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
00018  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
00019  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
00020  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
00021  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
00022  *   OTHER DEALINGS IN THE SOFTWARE.                                       *
00023  ***************************************************************************/
00024 
00025 
00026 #ifndef GELEMENTH
00027 #define GELEMENTH
00028 
00029 #include <QDataStream>
00030 #include <QDateTime>
00031 #include <QObject>
00032 // #include <q3ptrlist.h>
00033 #include <QEvent>
00034 #include <qdom.h>
00035 #include <QCustomEvent>
00036 #include <QStringList>
00037 
00038 
00039 namespace GCS
00040 {
00041 
00042 class GObject;
00043 class GEnergy;
00044 class GForm;
00045 class GMatrix44;
00046 class GElementID;
00047 class GElementInfluence;
00048 class GAgent;
00049 
00083 class GElement : public QObject
00084 {
00085   //defines GElement to be a Q_OBJECT;
00086   //this means that the signal and slot mechanism provided by Qt
00087   //can be used;
00088   Q_OBJECT
00089 
00090   private:
00091 
00095     GObject* Object;
00096 
00101     QList<GAgent*> Agents;
00102     
00111     QDateTime ParkTime;
00112     
00113   protected:
00114   
00126     virtual ~GElement();
00127 
00128   public:
00129 
00138     GElement(GObject* object, const QDateTime& park_time = QDateTime::currentDateTime());
00139 
00143     const GElementID& getElementID() const;
00144     
00150     QDateTime getParkTime() const;
00151 
00159     bool isParked();
00160     
00164     QList<const GAgent*> getAgents() const;
00165     
00169     const GObject* getObject() const;
00170     
00174     GObject* getObject();
00175 
00181     QStringList getAvailableActions() const;
00182     
00188     QString getActionDescription(const QString& action) const;
00189     
00196     virtual void customEvent(QEvent* event);
00197     
00198     typedef enum {ELEMENTCHANGED=65031, SENDINFLUENCE=65032, RADIATEINFLUENCE=65033,
00199                   PARENTCHANGED=65034, INFLUENCERECEIVED=65035, ACTIONPERFORMED=65036,
00200                   ENERGYCHANGED=65037, FORMCHANGED=65038, ELEMENTDATACHANGED=65039,
00201                   CHILDCREATED=65040, CHILDREMOVED=65041, DELETESELF=65042} ElementSignalType;
00202     
00203   protected slots:
00204     
00205     //BEGIN slots used internally to synchronize agent signals into the main thread
00206     
00212     void collectElementChanged();
00213     
00214     void collectSendInfluence(const GCS::GElementInfluence& influence,
00215                               const GCS::GElementID& destination);
00216     
00217     void collectRadiateInfluence(const GCS::GElementInfluence& influence,
00218                                  double radius_factor);
00219     
00220     void collectParentChanged(const GCS::GElementID& oldParent, const GCS::GElementID& newParent, const GCS::GMatrix44& transformation);
00221     
00222     void collectInfluenceReceived(const GCS::GElementInfluence& influence);
00223     
00224     void collectActionPerformed(const QString& action, QStringList params, const QString& agent);
00225     
00226     void collectEnergyChanged(const GCS::GEnergy& changedEnergy);
00227     
00228     void collectFormChanged(const GCS::GForm& changedForm);
00229     
00230     void collectElementDataChanged(const QString& xmlpath);
00231     
00232     void collectChildCreated(GCS::GElement* newElement);
00233     
00234     void collectChildRemoved(const GCS::GElementID& childID);
00235     
00236     //END slots used internally to synchronize agent signals into the main thread
00237     
00247     void checkReadyDelete();
00248 
00249     
00250   public slots:
00251   
00262     virtual void deleteSelf();
00263 
00271     void receiveInfluence(const GCS::GElementInfluence&);
00272     
00283     void performAction(const QString& action, QStringList params, const QString& agent = QString());
00284 
00293     void addAgent(GCS::GAgent* agent);
00294     
00301     void removeAgent(GCS::GAgent* agent, bool del=FALSE);
00302 
00303   signals:  // signals used inside the element
00304   
00321     void park();
00322 
00330     void execute(double seconds_elapsed);
00331 
00340     void forwardInfluenceInternal(const GCS::GElementInfluence&);
00341     
00349     void notifyReparentingInternal(const GCS::GElementID& old_parent, const GCS::GElementID& new_parent, const GCS::GMatrix44& transformation);
00350     
00351     
00352   public: //these two methods are necessary to raise internal signals;
00353     
00358     void parkElement();
00359     
00369     void executeElement(double seconds_delta_t_offset = 0);
00370     
00371   signals:  // signals related to influence
00372     
00376     void sendInfluence(const GCS::GElementInfluence& influence, const GCS::GElementID& destination);
00377 
00381     void radiateInfluence(const GCS::GElementInfluence& influence, double radius_factor);
00382 
00383   signals:  // signals used for border communication (GWE)
00384     
00393     void elementChanged(const GCS::GElementID& element);
00394     
00395     //BEGIN signals that are important for consistent distributed data management
00396     
00403     void parentChanged(const GCS::GElementID& newParent, const GCS::GElementID& oldParent, const GCS::GMatrix44& transformation);
00404     
00411     void influenceReceived(const GCS::GElementInfluence& influence);
00412     
00418     void actionPerformed(const QString& action, QStringList params, const QString& agent);
00419     
00420     //END signals that are important for consistent distributed data management
00421     
00422     //signals from GAgent
00423     
00427     void energyChanged(const GCS::GEnergy& changedEnergy);
00428 
00432     void formChanged(const GCS::GForm& changedForm);
00433 
00438     void elementDataChanged(const QString& xmlpath);
00439     
00447     void childElementCreated(GCS::GElement* newElement);
00448     
00456     void childElementRemoved(const GCS::GElementID& childID);
00457 };
00458 
00459 }
00460 
00461 #endif

Generated on Thu Nov 16 07:49:12 2006 for G System by  doxygen 1.4.7