00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _GLIBCXX_SSTREAM
00018 #include <sstream>
00019 #endif
00020
00021 #ifndef STATECONTROL_H
00022 #include "StateControl.h"
00023 #endif
00024
00025 #ifndef DISPATCHER_H
00026 #include "Dispatcher.h"
00027 #endif
00028
00029 #ifndef _ASSERT_H
00030 #include <assert.h>
00031 #endif
00032
00033 #ifndef GLOBALS_H
00034 #include "Globals.h"
00035 #endif
00036
00037 #ifndef OSGDB_READFILE
00038 #include <osgDB/ReadFile>
00039 #endif
00040
00041 #ifndef OSG_VEC3D
00042 #include <osg/Vec3d>
00043 #endif
00044
00045 #ifndef OSG_QUAT
00046 #include <osg/Quat>
00047 #endif
00048
00049 #ifndef OSG_POSTIONATTITUDETRANSFORM
00050 #include <osg/PositionAttitudeTransform>
00051 #endif
00052
00053 #ifndef OSG_AUTOTRANSFORM
00054 #include <osg/AutoTransform>
00055 #endif
00056
00057 #ifndef OSG_VEC4
00058 #include <osg/Vec4>
00059 #endif
00060
00061 #ifndef OSG_MATRIX
00062 #include <osg/Matrix>
00063 #endif
00064
00065 #ifndef OSG_MATRIXTRANSFORM
00066 #include <osg/MatrixTransform>
00067 #endif
00068
00069 #ifndef OSG_GEOMETRY
00070 #include <osg/Geometry>
00071 #endif
00072
00073 #ifndef OSG_STATESET
00074 #include <osg/StateSet>
00075 #endif
00076
00077 #ifndef OSGTEXT_TEXT
00078 #include <osgText/Text>
00079 #endif
00080
00081 #ifndef OSGPRODUCER_VIEWER
00082 #include <osgProducer/Viewer>
00083 #endif
00084
00085
00086 TraplasObject::TraplasObject(){}
00087
00088 TraplasObject::~TraplasObject(){}
00089
00090 void TraplasObject::initLabel(){
00091
00092 osgText::Text* objectText = new osgText::Text();
00093 objectText->setCharacterSize(FONTSIZE_LABELS);
00094 objectText->setAxisAlignment(osgText::Text::SCREEN);
00095 objectText->setDrawMode(osgText::Text::TEXT | osgText::Text::ALIGNMENT | osgText::Text::CENTER_TOP);
00096 objectText->setAlignment(osgText::Text::CENTER_TOP);
00097 objectText->setPosition(osg::Vec3d(0,-6,0));
00098 objectText->setColor(osg::Vec4d(1.0f, 0.0f, 0.0f, 1.0f) );
00099 label = new osg::Geode();
00100 label->addDrawable(objectText);
00101
00102 osg::StateSet* txtStateSet = new osg::StateSet();
00103 txtStateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
00104 label->setStateSet(txtStateSet);
00105
00106
00107
00108 osg::AutoTransform* at = dynamic_cast<osg::AutoTransform*>(model->getParent(0));
00109 assert(at != NULL);
00110 at->addChild(label);
00111
00112 return;
00113 }
00114
00115 osg::Vec3d TraplasObject::getPosition(){
00116
00117
00118 osg::PositionAttitudeTransform* pat = dynamic_cast<osg::PositionAttitudeTransform*>(model->getParent(0)->getParent(0));
00119 assert (pat != NULL);
00120
00121 return pat->getPosition();
00122 }
00123
00124 void TraplasObject::setDescription(string descript){
00125 description = descript;
00126 model->setName(descript);
00127 }
00128
00129 bool TraplasObject::select(){
00130 selected = !selected;
00131
00132
00133 osg::AutoTransform* tmp_at = dynamic_cast<osg::AutoTransform*>(getModel()->getParent(0));
00134 assert(tmp_at != NULL);
00135 osg::Geode* tmpg = dynamic_cast<osg::Geode*>(tmp_at->getChild(1));
00136 assert(tmpg != NULL);
00137 osgText::Text* tmpt = dynamic_cast<osgText::Text*>(tmpg->getDrawable(0));
00138 assert(tmpt != NULL);
00139 if(selected)tmpt->setColor(osg::Vec4d(0.0f, 1.0f, 0.0f, 1.0f) );
00140 else tmpt->setColor(osg::Vec4d(1.0f, 0.0f, 0.0f, 1.0f) );
00141
00142
00143 return selected;
00144 }
00145
00146 bool TraplasObject::setLabel( shared_ptr<string> desc ){
00147 osgText::Text* t = dynamic_cast<osgText::Text*>(label->getDrawable(0));
00148 if(t == NULL) return false;
00149 t->setText(*desc);
00150 return true;
00151 }
00152
00153 string TraplasObject::toString(){ return ""; }
00154
00155
00156 Cargo::Cargo(int carg_id, int type_carg, osg::Node* carg_model){
00157 id = carg_id, type = type_carg, model = carg_model;
00158 ostringstream s;
00159 s << id;
00160 setDescription( s.str() );
00161
00162 selected = false;
00163
00164 carg_model->setUserData( (TraplasObject*)this);
00165
00166 }
00167
00168 string Cargo::toString(){
00169 ostringstream cs;
00170 cs << description;
00171 return cs.str();
00172 }
00173
00174
00175
00176 Transport::Transport(int transport_id, int type_transport, double spd, osg::Node* trans_model){
00177 destination = "";
00178 carg = -1;
00179 c_desc = "";
00180 id = transport_id, type = type_transport, speed = spd, model = trans_model;
00181
00182 ostringstream s;
00183 s << id;
00184 setDescription( s.str() );
00185
00186 selected = false;
00187
00188 trans_model->setUserData( (TraplasObject*)this);
00189
00190 }
00191
00192 bool Transport::setSpeed(double s_spd){
00193 speed = s_spd;
00194 return true;
00195 }
00196
00197 bool Transport::setDestination(string s_dest){
00198 destination = s_dest;
00199 return true;
00200 }
00201
00202 bool Transport::setCargo(int s_carg, string desc){
00203 carg = s_carg;
00204 c_desc = desc;
00205
00206 return true;
00207 }
00208
00209 int Transport::clearCargo(){
00210 int cleared = carg;
00211 c_desc = "";
00212 carg = -1;
00213 return cleared;
00214 }
00215
00216 string Transport::toString(){
00217 ostringstream st;
00218 st << description << "\nSpeed: " << speed;
00219 if(destination != ""){
00220 st << "\nDestination: " << destination ;
00221 }
00222 if(carg != -1)
00223 st << "\nCargo: " << c_desc;
00224 return st.str();
00225 }
00226
00227
00228
00229 Infrastructure::Infrastructure(int infrastructure_id, int type_infrastructure, double spd, int tile_type, unsigned int cap, double dist, osg::Node* infra_model){
00230 id = infrastructure_id, type= type_infrastructure, speed = spd, model = infra_model;
00231 capacity = cap, distance = dist;
00232
00233 ostringstream s;
00234 s << id;
00235 setDescription( s.str() );
00236
00237 selected = false;
00238
00239 infra_model->setUserData( (TraplasObject*)this);
00240 }
00241
00242 bool Infrastructure::setSpeed(double s_spd){
00243 speed = s_spd;
00244 return true;
00245 }
00246
00247 int Infrastructure::removeCarg(int r_carg){
00248 if(cargoSet.find(r_carg) != cargoSet.end()){
00249 cargoSet.erase(r_carg);
00250 return r_carg;
00251 }
00252 else return -1;
00253 }
00254
00255 bool Infrastructure::addCarg(int a_carg){
00256 pair<std::_Rb_tree_const_iterator<int>, bool> thing = cargoSet.insert(a_carg);
00257 return thing.second;
00258 }
00259
00260 bool Infrastructure::addArc(int to){
00261 int* arc = NULL;
00262 arc = new int(to);
00263 arcs[to]=arc;
00264
00265 return true;
00266 }
00267
00268 bool Infrastructure::isArc(int end){
00269 int* arc = arcs[end];
00270 return (arc != NULL);
00271 }
00272
00273 string Infrastructure::toString(){
00274 ostringstream is;
00275 is << description << '\n' << "Speed: " << speed << '\n' << "Capacity" << capacity;
00276 return is.str();
00277 }
00278