00001 /*************************************************************************** 00002 * Copyright (C) 2003-2004 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.h> 00030 #include <qdatetime.h> 00031 #include <qobject.h> 00032 #include <qptrlist.h> 00033 00034 namespace GCS 00035 { 00036 00037 class GObject; 00038 class GEnergy; 00039 class GForm; 00040 class GElementID; 00041 class GElementListener; 00042 class GElementInfluence; 00043 class GAgent; 00044 00078 class GElement : public QObject 00079 { 00080 //defines GElement to be a Q_OBJECT; 00081 //this means that the signal and slot mechanism provided by Qt 00082 //can be used; 00083 Q_OBJECT 00084 00085 private: 00086 00090 GObject* Object; 00091 00096 QPtrList<GAgent> Agents; 00097 00106 QDateTime ParkTime; 00107 00108 public: 00109 00115 GElement(GObject* object); 00116 00122 virtual ~GElement(); 00123 00127 const GElementID& getElementID() const; 00128 00136 bool isParked(); 00137 00141 const QPtrList<GAgent>& getAgents() const; 00142 00146 const GObject* getObject() const; 00147 00148 protected slots: 00149 00156 void parentChangedInternal(const GCS::GElementID& oldParent, const GCS::GElementID& newParent); 00157 00158 public slots: 00159 00167 void receiveInfluence(GCS::GElementInfluence&); 00168 00177 void addAgent(GCS::GAgent* agent); 00178 00185 void removeAgent(GCS::GAgent* agent, bool del=FALSE); 00186 00187 signals: // signals used inside the element 00188 00205 void park(); 00206 00214 void execute(double seconds_elapsed); 00215 00224 void forwardInfluenceInternal(GCS::GElementInfluence&); 00225 00226 public: //these two methods are necessary to raise internal signals; 00227 00232 void parkElement(); 00233 00243 void executeElement(double seconds_delta_t_offset = 0); 00244 00245 signals: // signals related to influence 00246 00250 void sendInfluence(const GCS::GElementID& destination, 00251 GCS::GElementInfluence& influence); 00252 00256 void radiateInfluence(GCS::GElementInfluence& influence); 00257 00258 signals: // signals used for border communication (GWE) 00259 00260 //signals from GAgent 00261 00268 void parentChanged(GCS::GElement* element, const GCS::GElementID& oldParent, const GCS::GElementID& newParent); 00269 00273 void energyChanged(const GCS::GEnergy& changedEnergy); 00274 00278 void formChanged(const GCS::GForm& changedForm); 00279 00283 void agentChanged(const GCS::GAgent& changedAgent); 00284 00291 void childElementCreated(GCS::GElement* newElement); 00292 00299 void childElementRemoved(const GCS::GElementID& childID); 00300 }; 00301 00302 } 00303 00304 #endif
1.3.6