00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00100 #include "../include/IPSA/viewer/IpsaViewer.h"
00101 #include "../include/IPSA/ipsaclasses.h"
00102 #include "../include/IPSA/IpsaSimulator.h"
00103
00104
00105 #include <iostream>
00106
00107 #include <Inventor/SoDB.h>
00108 #include <Inventor/SoInput.h>
00109 #include <Inventor/SoFullPath.h>
00110 #include <Inventor/nodes/SoFile.h>
00111 #include <Inventor/nodes/SoGroup.h>
00112 #include <Inventor/nodes/SoNode.h>
00113 #include <Inventor/actions/SoSearchAction.h>
00114 #include <Inventor/actions/SoWriteAction.h>
00115 #include <Inventor/lists/SbPList.h>
00116 #include <Inventor/lists/SoPathList.h>
00117
00118 #ifndef USE_SOWIN
00119 #include "../include/IPSA/viewer/IpsaDialog.h"
00120 #include <qobject.h>
00121 #include <qpushbutton.h>
00122 #endif // USE_SOWIN
00123
00135 IpsaViewer::IpsaViewer(std::string filename , SO_WINDOW parent, const char *name, SbBool embed)
00136 : SO_EXAMINER_VIEWER(parent, name, embed, SO_FULL_VIEWER::BUILD_ALL, SO_FULL_VIEWER::BROWSER, FALSE),
00137 saveFile(""),
00138 ipsaSimulator(new IpsaSimulator)
00139 {
00140 ipsaSimulator->setSceneryFilename(filename);
00141 window = parent;
00142
00143 SO_WINDOW widget = this->buildWidget(window);
00144 this->setBaseWidget(widget);
00145 this->setTitle(name);
00146 this->setFeedbackVisibility(true);
00147 this->setFeedbackSize(35);
00148 #ifndef USE_SOWIN
00149 dialog = new IpsaDialog(ipsaSimulator, widget);
00150 #endif
00151 }
00152
00153
00158 IpsaViewer::~IpsaViewer()
00159 {
00160 delete ipsaSimulator;
00161 }
00162
00163
00176 bool IpsaViewer::run(bool doSchedule, std::string scenerySaveFile)
00177 {
00178 if (NULL == window)
00179 return false;
00180
00181 this->reloadSimulation();
00182
00183
00184 saveFile = scenerySaveFile;
00185 ipsaSimulator->save(saveFile);
00186
00187 this->show();
00188
00189 if (doSchedule)
00190 ipsaSimulator->schedule();
00191
00192 SO_PLATFORM::show(this->window);
00193 SO_PLATFORM::mainLoop();
00194
00195 return true;
00196 }
00197
00198
00206 void IpsaViewer::createViewerButtons(SO_WINDOW parent, SbPList* buttonlist)
00207 {
00208 SO_EXAMINER_VIEWER::createViewerButtons(parent, buttonlist);
00209 #ifndef USE_SOWIN
00210 if (ipsaSimulator->isScheduled())
00211 scheduleButton = new QPushButton("U", window);
00212 else
00213 scheduleButton = new QPushButton("S", window);
00214 QObject::connect(scheduleButton, SIGNAL(clicked()), this, SLOT(schedule()));
00215 this->addAppPushButton(scheduleButton);
00216
00217 QPushButton* dialogButton = new QPushButton("Dlg", window);
00218 QObject::connect(dialogButton, SIGNAL(clicked()), this, SLOT(showDialog()));
00219 this->addAppPushButton(dialogButton);
00220
00221 QPushButton* resetButton = new QPushButton("Rst", window);
00222 QObject::connect(resetButton, SIGNAL(clicked()), this, SLOT(resetSimulation()));
00223 this->addAppPushButton(resetButton);
00224
00225 QPushButton* saveButton = new QPushButton("Save", window);
00226 QObject::connect(saveButton, SIGNAL(clicked()), this, SLOT(saveSceneToFile()));
00227 this->addAppPushButton(saveButton);
00228 #endif // USE_SOWIN
00229 }
00230
00231
00235 void IpsaViewer::showDialog()
00236 {
00237 #ifndef USE_SOWIN
00238 dialog->reloadData();
00239 if (dialog->isShown())
00240 dialog->raise();
00241 else
00242 dialog->show();
00243 #endif // USE_SOWIN
00244 }
00245
00246
00251 void IpsaViewer::reloadSimulation()
00252 {
00253 ipsaSimulator->reload();
00254 this->setSceneGraph(ipsaSimulator->getSceneGraph());
00255 this->viewAll();
00256 }
00257
00261 void IpsaViewer::resetSimulation()
00262 {
00263 ipsaSimulator->reset();
00264 }
00265
00266
00271 void IpsaViewer::saveSceneToFile()
00272 {
00273 if (saveFile.empty())
00274 return;
00275
00276 ipsaSimulator->save(saveFile);
00277 }
00278
00279
00284 void IpsaViewer::schedule()
00285 {
00286 ipsaSimulator->schedule();
00287 #ifndef USE_SOWIN
00288 if (ipsaSimulator->isScheduled())
00289 scheduleButton->setText("U");
00290 else
00291 scheduleButton->setText("S");
00292 #endif
00293 }
00294
00295
00299 bool IpsaViewer::isScheduled()
00300 {
00301 return ipsaSimulator->isScheduled();
00302 }
00303
00304
00310 void IpsaViewer::setVerbosity(bool verbosityOn)
00311 {
00312 ipsaSimulator->setVerbosity(verbosityOn);
00313 }
00314
00315
00319 bool IpsaViewer::getVerbosity()
00320 {
00321 return ipsaSimulator->getVerbosity();
00322 }
00323
00324
00329 void IpsaViewer::setSceneryFilename(const std::string& newFile)
00330 {
00331 ipsaSimulator->setSceneryFilename(newFile);
00332 }