VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Environmental Process Listening Example (envProcessListen)

The Environmental Process Listening example demonstrates the following:

How to Run

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).

Usage

envProcessListen

To use the application:

  1. Start VR-Forces from the start menu.
  2. Start envProcessListen for the correct protocol.
  3. Create a new scenario in VR-Forces.
  4. Create control objects and/or overlay objects.

Observe the output displaying details about the various control/overlay objects being simulated by VR-Forces.

Main Application File

//******************************************************************************
// Copyright (c) 2006 MAK Technologies, Inc.
// All rights reserved.
//******************************************************************************
//******************************************************************************
// $RCSfile: main.cxx,v $ $Revision: 1.10 $ $State: Exp $
//******************************************************************************
#include <vl/exerciseConn.h>
#include <vl/exerciseConnInitializer.h>
#include <matrix/LibMatrix.h>
#include <vlutil/vlProcessControl.h>
#include <vlutil/vlKeyboard.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(int argc, char** argv)
{
// Create a connection to the exercise or federation execution.
DtVrlApplicationInitializer exConnInit(argc, argv, "Env Proc Listen");
#if DtHLA
exConnInit.setRprFomVersion(2.0);
exConnInit.setExecName("MAK-RPR-2.0");
exConnInit.setFederateName("VRF-env-process-listen");
exConnInit.setFedFileName("RPR_FOM_v2.0_1516-2010.xml");
#else
exConnInit.setPort(3000);
exConnInit.setExerciseId(1);
exConnInit.setSiteId(1);
exConnInit.setApplicationNumber(25);
exConnInit.setUseAsynchIO(true);
#endif
exConnInit.parseCmdLine();
DtExerciseConn exConn(exConnInit);
// Initialize VR-Link time.
DtClock* clock = exConn.clock();
// Create an object to manage entities that we hear about
// on the network.
// 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());
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;
}

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)