![]() |
VR-Forces 4.0.4 Class Documentation
|
The Environmental Process Listening example demonstrates the following:
This example demonstrates how to listen for and display informaiton about environmental process objects (the network representation of control objects and overlay objects in VR-Forces).
envProcessListen
To use the application:
Observe the output displaying details about the various control/overlay objects being simulated by VR-Forces.
//****************************************************************************** // Copyright (c) 2006 MAK Technologies, Inc. // All rights reserved. //****************************************************************************** //****************************************************************************** // $RCSfile: main.cxx,v $ $Revision: 1.10 $ $State: Exp $ //****************************************************************************** #include <vl/exerciseConn.h> #include <vrfExtObjects/refCtrlObjList.h> #include <matrix/LibMatrix.h> #include <vlutil/vlProcessControl.h> #include <vlutil/vlKeyboard.h> #include <vrfExtObjects/controlObjSR.h> #include <vrfExtObjects/vrfExtensions.h> #include <vrfExtObjects/reflCtrlObj.h> #include <vrfExtObjects/envObjState.h> #include <vrfExtObjects/envModelType.h> #include <vrfExtObjects/envSmokeState.h> #include <vlutil/vlPrint.h> #include <iostream> int keybrdTick(void); void printControlObjectState(DtControlObjectRepository* cosr, DtTime simTime); void controlObjectAddedCallback(DtReflectedControlObject* controlObject, void* userData); void controlObjectRemovedCallback(DtReflectedControlObject* controlObject, void* userData); void controlObjectUpdateCallback(DtReflectedControlObject* controlObject, void* userData); int main() { // Create a connection to the exercise or federation execution. #if DtHLA double rprFomVersion = 1.0; DtString execName("VR-Link"); DtString fedName("VRF-env-process-listen"); DtExerciseConn exConn(execName, fedName, new DtRprFomMapper(rprFomVersion)); #else int port = 3000; int exerciseId = 1; int siteId = 1; int applicationNum = 25; DtExerciseConn exConn(port, exerciseId, siteId, applicationNum, 0, // No Status, all errors will be fatal true); // use Async IO #endif // Initialize VR-Link time. DtClock* clock = exConn.clock(); // Create an object to manage entities that we hear about // on the network. DtReflectedControlObjectList rel(&exConn); // Register callbacks to be invoked when control objects (VR-Forces // environmental process objects) are added or removed from the network. rel.addControlObjectAdditionCallback(controlObjectAddedCallback, clock); rel.addControlObjectRemovalCallback(controlObjectRemovedCallback, clock); int forever = 1; while (forever) { // Check if user hit 'q' to quit. if (keybrdTick() == -1) break; // Tell VR-Link the current value of simulation time. clock->setSimTime(clock->elapsedRealTime()); // Process any incoming messages. exConn.drainInput(); // Sleep till next iteration. DtSleep(0.1); } return 0; } void controlObjectAddedCallback(DtReflectedControlObject* controlObject, void* userData) { DtClock* clock = (DtClock*)userData; if(controlObject && clock) { // Register a callback to be invoked when the object changes controlObject->addPostUpdateCallback(controlObjectUpdateCallback, clock); // Print out initial contents of object printControlObjectState(controlObject->cosr(), clock->simTime()); } } void controlObjectRemovedCallback(DtReflectedControlObject* controlObject, void* userData) { DtClock* clock = (DtClock*)userData; if(controlObject && clock) { controlObject->removePostUpdateCallback(controlObjectUpdateCallback, clock); } } void controlObjectUpdateCallback(DtReflectedControlObject* controlObject, void* userData) { DtClock* clock = (DtClock*)userData; if(controlObject && clock) { printControlObjectState(controlObject->cosr(), clock->simTime()); } } void printControlObjectState(DtControlObjectRepository* cosr, DtTime simTime) { DtInfo("************************************************************\n"); DtInfo("*************** Update at %f secs ***************\n", simTime); DtInfo("************************************************************\n"); DtInfo("environmentalProcessId: %s\n", cosr->environmentalProcessID().string()); DtInfo("globalId: %s\n", cosr->globalId().string()); DtInfo("name: %s\n", cosr->vrfObjectName().string()); DtInfo("label: %s\n", cosr->vrfObjectLabel().string()); DtInfo("parent: %s\n", cosr->parent().string()); DtInfo("kind: %d\n", cosr->kind()); DtInfo("category: %d\n", cosr->category()); DtInfo("forceType: %d\n", cosr->forceType()); DtInfo("color: %x\n", cosr->color()); DtInfo("environmentType: %s\n", cosr->environmentType().string()); DtInfo("closed figure: %s\n", cosr->closedFigure() ? "True" : "False"); DtInfo("projected: %s\n", cosr->projected() ? "True" : "False"); DtInfo("bound 2D: %s\n", cosr->bound2D() ? "True" : "False"); DtInfo("model type: %x\n", cosr->modelType()); DtInfo("environmental status: %s\n", cosr->environmentalStatus() ? "Active" : "Inactive"); DtInfo("sequence number: %d\n", cosr->sequenceNumber()); DtInfo("location: %s\n", cosr->location().string().string()); DtInfo("radius: %f\n", cosr->radius()); const DtControlObjectRepository::DtCOVertexList& vertexList = cosr->vertexList(); if(vertexList.size()) { DtInfo("number of vertices: %d\n", vertexList.size()); DtControlObjectRepository::DtCOVertexList::const_iterator iter = vertexList.begin(); DtControlObjectRepository::DtCOVertexList::const_iterator end = vertexList.end(); int index = 0; while (iter != end) { DtInfo("vertex %d: %s\n", index, (*iter).string().string()); ++index; ++iter; } } int numSubordinates = cosr->numberOfSubordinates(); DtInfo("number of subordinates: %d\n", numSubordinates); const DtGlobalObjectDesignatorList& subordinates = cosr->subordinates(); int index; for(index = 0; index < numSubordinates; ++index) { bool isValidIndex; const DtGlobalObjectDesignator& globalId = subordinates.object(index, &isValidIndex); if(isValidIndex) { DtInfo("subordinate %d: %s\n", index, globalId.string()); } } // Print record types and state here int max = cosr->numberOfEnvironmentalRecords(); for (int i = 0; i < max; i++) { DtNetEnvironmentalRecord* rec = cosr->recordPointer(i); int recType = rec->myType; switch (recType) { case DtEnvObjectStateRecordType: DtInfo("%d) DtEnvObjectStateRecordType\n", i); break; case DtEnvObjectStateRecordType_V4: DtInfo("%d) DtEnvObjectStateRecordType_V4\n", i); break; case DtEnvObjectStateRecordType_V3: DtInfo("%d) DtEnvObjectStateRecordType_V3\n", i); break; case DtEnvObjectStateRecordType_V2: DtInfo("%d) DtEnvObjectStateRecordType_V2\n", i); break; case DtEnvObjectStateRecordType_V1: DtInfo("%d) DtEnvObjectStateRecordType_V1\n", i); break; case DtEnvVrfObjectDataStateRecordType: DtInfo("%d) DtEnvVrfObjectDataStateRecordType\n", i); break; case DtRectangularVolRecord1Type: DtInfo("%d) DtRectangularVolRecord1Type\n", i); break; case IttBoundingVolumeKind: DtInfo("%d) IttBoundingVolumeKind\n", i); break; case DtPointRecord1Type: DtInfo("%d) DtPointRecord1Type\n", i); break; case IttBioStateKind: DtInfo("%d) IttBioStateKind\n", i); break; case IttGaussianPuffKind: DtInfo("%d) IttGaussianPuffKind\n", i); break; case IttUniformBoxKind: DtInfo("%d) IttUniformBoxKind\n", i); break; case IttChemStateKind: DtInfo("%d) IttChemStateKind\n", i); break; case IttRadStateKind: DtInfo("%d) IttRadStateKind\n", i); break; case IttChemLiquidStateKind: DtInfo("%d) IttChemLiquidStateKind\n", i); break; case DtEnvSmokeStateRecordType: DtInfo("%d) DtEnvSmokeStateRecordType\n", i); break; default: DtInfo("%d) UNKNOWN 0x%x\n", i, recType); break; } } DtInfo("\n"); } int keybrdTick() { char *keyPtr = DtPollInputLine(); if (keyPtr && (*keyPtr == 'q' || *keyPtr == 'Q')) return -1; else return 0; }