IpsaSimulator Class Reference
[libipsa classes]

Main class for loading and simulating IPSA scenes. More...

#include <IpsaSimulator.h>

Collaboration diagram for IpsaSimulator:

Collaboration graph
[legend]

List of all members.

Public Member Functions

SoNode * getSceneGraph ()
bool getVerbosity ()
 IpsaSimulator ()
bool isScheduled ()
void reload ()
void reset ()
void save (const std::string &saveFile)
void schedule ()
void setDelegate (IpsaSimulatorDelegate *delegate)
void setSceneryFilename (const std::string &newFile)
void setVerbosity (bool verbosityOn=true)
virtual ~IpsaSimulator ()

Static Public Member Functions

static void ExpandFileNodes (SoNode *root)

Protected Member Functions

void applyPrefixNodes ()
virtual bool buildScenery ()
SoSeparator * createPhysicsWorldIfMissing (SoNode *root)
SoNode * readSceneryFromFile (bool expandFileNodesInGraph=true)

Protected Attributes

IpsaSimulatorDelegatedelegate
bool isIpsaScheduled
std::string sceneryFilename
SoSeparator * simulationRoot
bool verboseOutput


Detailed Description

Main class for loading and simulating IPSA scenes.

Create an instance of this class to use it. This is done in the QtEmbedding executable for example and usually looks like this:

 #include "IpsaSimulator.h"

 int main (int argc, char ** argv)
 {
 // create an instance of the IpsaSimulator
 IpsaSimulator simulator();
 return 0;
 }

To change how the shown scenery is built it is possible to set the IpsaSimulator::delegate using the IpsaSimulator::setDelegate(IpsaSimulatorDelegat*) method.

 #include <IPSA/IpsaSimulator.h>
 #include <IPSA/IpsaSimulatorDelegate.h>
 #include <IPSA/ipsaclasses.h>
 #include <iostream>

 class MyIpsaSimulator : public IpsaSimulator, public IpsaSimulatorDelegate
 {
 public:
     MyIpsaSimulator() : IpsaSimulator(parent, embed)
     {
         this-ipsaSimulator->setDelegate(this);
     }
 protected:
     virtual SoNode* createScenery();
 };

 SoNode* MyIpsaSimulator::createScenery()
 {
     SoNode* root = new SoSeparator;
     root->ref();
     // create your own scenegraph
     // ...

     // the remaining code
     return root;
 }

 int main (int argc, char ** argv)
 {
     MyIpsaSimulator simulator();
     viewer.reload();
     return 0;
 }

Definition at line 35 of file IpsaSimulator.h.


Constructor & Destructor Documentation

IpsaSimulator::IpsaSimulator (  ) 

The constructor of the IpsaSimulator class.
It calls SoWorldPhysics::initClasses().

Definition at line 149 of file IpsaSimulator.cpp.

References SoWorldPhysics::initClasses().

IpsaSimulator::~IpsaSimulator (  )  [virtual]

The virtual destructor of the IpsaSimulator class.

Definition at line 163 of file IpsaSimulator.cpp.

References SoWorldPhysics::DeInit().


Member Function Documentation

void IpsaSimulator::applyPrefixNodes (  )  [protected]

Searches all SoPrefixNodes in the scenegraph of the viewer and calls SoPrefixNode::updatePrefixes() on all of them.

Definition at line 314 of file IpsaSimulator.cpp.

References simulationRoot, and SoPrefixNode::updatePrefixes().

Referenced by buildScenery().

bool IpsaSimulator::buildScenery (  )  [protected, virtual]

The virtual method IpsaSimulator::buildScenery() is used to create a scenegraph.
If IpsaSimulator::delegate has been set through IpsaSimulator::setDelegate(IpsaSimulatorDelegate*) the delegate is used to construct the scenery. Otherwise the scenegraph is constructed by reading in the file stored in IpsaSimulator::sceneryFilename.

Returns:
true if everything went well.

false if no scenery could be created.

Definition at line 198 of file IpsaSimulator.cpp.

References SoWorldPhysics::ApplyActionToWorldPhysicNodesInGraph(), applyPrefixNodes(), createPhysicsWorldIfMissing(), IpsaSimulatorDelegate::createScenery(), delegate, SoWorldPhysics::InitialiseWorldCB(), readSceneryFromFile(), and simulationRoot.

Referenced by reload().

SoSeparator * IpsaSimulator::createPhysicsWorldIfMissing ( SoNode *  root  )  [protected]

Searches through the supplied Inventor tree and creates a default SoWorldPhysics if none was found and adds root as a child node.

Parameters:
root the node to search through
Returns:
root if at least one SoWorldPhysics was present, the SoWorldPhysics which has been created otherwise

Definition at line 278 of file IpsaSimulator.cpp.

Referenced by buildScenery().

void IpsaSimulator::ExpandFileNodes ( SoNode *  root  )  [static]

This routine searches for and expands all SoFile nodes in the given scene graph. It does this by making all the children of a SoFile node the children of its parent. (Code for this function taken from ivcat)

Parameters:
root the Inventor node to perform the expansion on.

Definition at line 344 of file IpsaSimulator.cpp.

Referenced by readSceneryFromFile().

SoNode * IpsaSimulator::getSceneGraph (  ) 

IpsaSimulator::getVerbosity (  )  [inline]

Returns:
true if IpsaSimulator::verbosity is on, false otherwise

Definition at line 44 of file IpsaSimulator.h.

Referenced by IpsaViewerWidget::getVerbosity(), IpsaViewer::getVerbosity(), ListAllJoints::vExecute(), and ListAllBodies::vExecute().

IpsaSimulator::isScheduled (  )  [inline]

Returns:
true if the current SoWorldPhysics instances are schedule, false otherwise.

Definition at line 50 of file IpsaSimulator.h.

Referenced by IpsaViewer::createViewerButtons(), IpsaViewerWidget::isScheduled(), IpsaViewer::isScheduled(), IpsaViewerWidget::schedule(), and IpsaViewer::schedule().

SoNode * IpsaSimulator::readSceneryFromFile ( bool  expandFileNodesInGraph = true  )  [protected]

This method tries to read the scenegraph from the file IpsaSimulator::sceneryFilename and sets it as the scenegraph of the current innstance of IpsaSimulator. Before the scenegraph is set it may get expanded depending on the parameter of the method.

Parameters:
expandFileNodesInGraph perform expansion if true (default) or not otherwise.
Returns:
true if everything went well and the scenegraph could be read.

false if the file couldn't be opened or a problem was encountered while reading the file.

Definition at line 235 of file IpsaSimulator.cpp.

References ExpandFileNodes(), and sceneryFilename.

Referenced by buildScenery().

void IpsaSimulator::reload (  ) 

Resets the simulation by deleting the scene and calling IpsaSimulator::buildScenery() again.

Definition at line 432 of file IpsaSimulator.cpp.

References buildScenery(), SoWorldPhysics::DeInit(), SoWorldPhysics::Init(), isIpsaScheduled, schedule(), and simulationRoot.

Referenced by IpsaViewerWidget::reload(), and IpsaViewer::reloadSimulation().

void IpsaSimulator::reset (  ) 

void IpsaSimulator::save ( const std::string &  saveFile  ) 

Save current inventor scenegraph to file at location saveFile. Do nothing if saveFile is empty.

Definition at line 468 of file IpsaSimulator.cpp.

References simulationRoot.

Referenced by IpsaViewer::run(), IpsaViewerWidget::save(), and IpsaViewer::saveSceneToFile().

void IpsaSimulator::schedule (  ) 

Schedules ALL SoWorldPhysics if IpsaSimulator::isScheduled is set to false and unschedules ALL SoWorldPhyiscs if the IpsaSimulator::isScheduled is set to true. Afterwards IpsaSimulator::isScheduled is inverted to reflect the current state.

Definition at line 488 of file IpsaSimulator.cpp.

References SoWorldPhysics::ApplyActionToWorldPhysicNodesInGraph(), isIpsaScheduled, SoWorldPhysics::ScheduleWorldCB(), simulationRoot, and SoWorldPhysics::UnscheduleWorldCB().

Referenced by reload(), reset(), IpsaViewer::run(), IpsaViewerWidget::schedule(), and IpsaViewer::schedule().

void IpsaSimulator::setDelegate ( IpsaSimulatorDelegate delegate  ) 

This method sets a delegate object which must inherit from IpsaSimulatorDelegate.

Definition at line 172 of file IpsaSimulator.cpp.

IpsaSimulator::setSceneryFilename ( const std::string &  newFile  )  [inline]

Set IpsaSimulator::sceneFilename to a new file. After calling IpsaSimulator::buildScenery() the new file is read.

Definition at line 46 of file IpsaSimulator.h.

Referenced by IpsaViewer::IpsaViewer(), IpsaViewerWidget::setSceneryFilename(), and IpsaViewer::setSceneryFilename().

IpsaSimulator::setVerbosity ( bool  verbosityOn = true  )  [inline]

Sets the IpsaSimulator::verbosity flag.

Parameters:
verbosityOn true for turning verbosity on, false for turning it of (default = true)

Definition at line 43 of file IpsaSimulator.h.

Referenced by IpsaViewerWidget::setVerbosity(), IpsaViewer::setVerbosity(), and SetVerbosity::vExecute().


Member Data Documentation

This object is used to delegate the creation of the scenegraph to. It implements the IpsaSimulatorDelegate interface.

Definition at line 72 of file IpsaSimulator.h.

Referenced by buildScenery().

Contains true if the current SoWorldPhysics instances are scheduled, false otherwise.

Definition at line 67 of file IpsaSimulator.h.

Referenced by reload(), reset(), and schedule().

This is the filename of the inventor scenegraph which can be loaded by the IpsaSimulator::readSceneryFromFile() method.

Definition at line 68 of file IpsaSimulator.h.

Referenced by readSceneryFromFile().

SoSeparator* IpsaSimulator::simulationRoot [protected]

Used by commands to determine if the output should be verbose.

Definition at line 66 of file IpsaSimulator.h.


The documentation for this class was generated from the following files:

Get IPSA - Inventor Physics Simulation API at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on Sat Mar 10 20:00:19 2012 for IPSA by  doxygen 1.5.8