simpleDDMSimple1516.cxx and simpleDDMFedAmb1516.cxx (simpleDDMFedAmb1516.h) have the RTI calls and federate ambassador calls for the HLA 1516 version of rtisimple.
This page has the code for the following files:
simpleDDMSimple1516.cxx
#ifdef DtHLA1516
#ifdef WIN32
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <winsock2.h>
#include <process.h>
#include <windows.h>
#else
#include <unistd.h>
#include <stdio.h>
#endif
#include <cstdlib>
using namespace rti1516;
using namespace std;
:
myHourlyInteraction(L"hourlyChime"),
myQuarterlyInteraction(L"quarterlyChime"),
mySecondsDimensionName(L"seconds"),
myUTCDimensionName(L"UTCn"),
myInterClassName(L"Chimes"),
myClassName(L"BaseEntity"),
myAttrName(L"clockPosition"),
myRTIamb(0),
myFedAmb(0)
{
theAmbData.position = 0;
myFederationName = L"MAKsimpleDDM";
myFederationFile = L"MAKsimpleDDM.xml";
myFederateType = L"rtisimple1516";
}
{
{
}
{
}
}
:
myHourlyInteraction(data.myHourlyInteraction),
myQuarterlyInteraction(data.myQuarterlyInteraction),
mySecondsDimensionName(data.mySecondsDimensionName),
myUTCDimensionName(data.myUTCDimensionName),
myInterClassName(data.myInterClassName),
myClassName(data.myClassName),
myAttrName(data.myAttrName)
{
}
{
vector< wstring > args;
RTIambassadorFactory* rtiAmbFactory = new RTIambassadorFactory();
std::auto_ptr< RTIambassador > rtiAmbAP = rtiAmbFactory->createRTIambassador(args);
}
{
wcout << L"createFederationExecution "
try
{
}
catch(FederationExecutionAlreadyExists& ex)
{
wcout << L"Could not create Federation Execution: "
<< L"FederationExecutionAlreadyExists: "
<< ex.what() << endl;
return false;
}
catch(rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl
<< L"Could not create Federation Execution: " << endl;
exit(0);
}
myRTIamb->evokeMultipleCallbacks(0.1, 0.2);
wcout << L"Federation Created." << endl;
return true;
}
{
bool joined=false;
const int maxTry = 10;
int numTries = 0;
wcout << L"joinFederationExecution "
while (!joined && numTries++ < maxTry)
{
try
{
joined = true;
}
catch(FederationExecutionDoesNotExist)
{
wcout << L"FederationExecutionDoesNotExist, try "
<< numTries << L" out of "
<< maxTry << endl;
continue;
}
catch(rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl;
return false;
}
myRTIamb->evokeMultipleCallbacks(0.1, 0.2);
}
if (joined)
{
wcout << L"Joined Federation." << endl;
return true;
}
else
{
wcout << L"Giving up." << endl;
exit(0);
}
}
{
}
{
try
{
}
catch (rti1516::Exception& ex)
{
wcout << L"Caught Exception getting DimensionHandle \n"
<< ex.what() << L" " << endl;
return false;
}
try
{
{
}
else
{
}
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: " << ex.what() << endl
<< L"Could not create Region" << endl;
return false;
}
{
RangeBounds secondsRangeBounds;
RangeBounds UTCRangeBounds;
UTCRangeBounds.setLowerBound(myUTCZone);
UTCRangeBounds.setUpperBound(myUTCZone + 1);
try
{
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl
<< L"Could not changeBounds " << endl;
}
}
else
{
RangeBounds secondsRangeBounds;
RangeBounds UTCRangeBounds;
UTCRangeBounds.setLowerBound(myUTCZone);
UTCRangeBounds.setUpperBound(myUTCZone + 1);
try
{
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl
<< L"Could not notify about region mods" << endl;
return false;
}
}
{
}
return true;
}
{
try
{
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl;
wcout << L"Could not get object class handle: "
return false;
}
try
{
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl;
wcout << L"Could not get attribute handle "
<< myAttrName << endl;
return false;
}
string initialPosition("0");
VariableLengthData(initialPosition.c_str(), initialPosition.length()+1)));
{
return false;
}
try
{
{
}
else
{
myRTIamb->subscribeObjectClassAttributesWithRegions(
}
myRTIamb->evokeMultipleCallbacks(0.1, 0.2);
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl;
wcout << L"Could not "
return false;
}
{
wstring objectName(L"UTC_publisher_");
wstringstream zoneID;
objectName += zoneID.str();
try
{
myRTIamb->reserveObjectInstanceName(objectName);
int count = 0;
{
myRTIamb->evokeMultipleCallbacks(0.001, 0.2);
}
{
wcout << L"Failed waiting for reserve object name "
<< objectName.c_str() << endl;
return false;
}
else
{
#if 0
#endif
objectName);
}
myRTIamb->evokeMultipleCallbacks(0.1, 0.2);
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl
<< L"Could not Register Object "
<< objectName
<< L" with class "
return false;
}
wcout << L"Registered object "
<< objectName
<< L" with class name "
}
return true;
}
{
try
{
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl;
wcout << L"Could not get interaction class handle: "
return false;
}
wstring paramName;
try
{
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl;
wcout << L"Could not get parameter handle "
return false;
}
try
{
{
myRTIamb->evokeMultipleCallbacks(0.1, 0.2);
}
else
{
myRTIamb->subscribeInteractionClassWithRegions(
myRTIamb->evokeMultipleCallbacks(0.1, 0.2);
}
}
catch (rti1516::Exception& ex)
{
wcout << L"rti1516 Exception: "
<< ex.what() << endl;
wcout << L"Could not "
<< L" to interaction class." << endl;
return false;
}
{
wcout
<< L"Subscribed to interaction class: "
<< endl;
}
return true;
}
{
stringstream ss;
ss << "1516-" << myUpdateCount++;
string tagForThisUpdate(ss.str());
try
{
VariableLengthData(tagForThisUpdate.c_str(),
tagForThisUpdate.size()+1));
}
catch (rti1516::Exception& ex)
{
wcout << L"Caught Exception in update Attribute Values\n"
<< ex.what() << endl;
}
}
{
stringstream ss;
ss << "1516-" << myUpdateCount++;
string tagForThisUpdate(ss.str());
try
{
VariableLengthData(
VariableLengthData(tagForThisUpdate.c_str(),
tagForThisUpdate.size() + 1) );
}
catch (rti1516::Exception& ex)
{
wcout << L"Caught Exception in send Interaction With Regions\n"
<< ex.what() << endl;
}
}
{
stringstream ss;
ss << "1516-" << myUpdateCount++;
string tagForThisUpdate(ss.str());
try
{
VariableLengthData(
VariableLengthData(tagForThisUpdate.c_str(),
tagForThisUpdate.size() + 1) );
}
catch (rti1516::Exception& ex)
{
wcout << L"Caught Exception in send Interaction With Regions\n"
<< ex.what() << endl;
}
}
{
{
myUTCZone = newUTC;
{
}
else
{
}
}
{
try
{
RangeBounds secondsRangeBounds;
RangeBounds UTCRangeBounds;
UTCRangeBounds.setUpperBound(newUTC + 1);
UTCRangeBounds.setLowerBound(newUTC);
secondsRangeBounds.setUpperBound(upperSeconds);
secondsRangeBounds.setLowerBound(lowerSeconds);
secondsRangeBounds =
myUTCZone = UTCRangeBounds.getLowerBound();
}
catch (rti1516::Exception& ex)
{
wcout << L"Caught Exception\n"
<< ex.what()
<< L" " << endl;
}
}
else
{
try
{
RangeBounds secondsRangeBounds;
RangeBounds UTCRangeBounds;
UTCRangeBounds.setUpperBound(newUTC + 1);
UTCRangeBounds.setLowerBound(newUTC);
secondsRangeBounds.setUpperBound(upperSeconds);
secondsRangeBounds.setLowerBound(lowerSeconds);
secondsRangeBounds =
myUTCZone = UTCRangeBounds.getLowerBound();
}
catch (rti1516::Exception& ex)
{
wcout << L"Caught Exception when changing bounds\n"
<< ex.what() << L" " << endl;
}
}
}
{
try
{
}
catch(rti1516::Exception& ex)
{
wcout << L"rti1516 Exception (during evoke Multiple Callbacks): "
<< ex.what() << endl;
return false;
}
return true;
}
{
try
{
myRTIamb->evokeMultipleCallbacks(atLeast, atMost);
}
catch(rti1516::Exception& ex)
{
wcout << L"rti1516 Exception (during evoke Multiple Callbacks): "
<< ex.what() << endl;
return false;
}
return true;
}
{
{
string pos_string;
ostringstream oss ;
oss << pos;
pos_string = oss.str();
AttributeHandleValueMap::iterator iter =
iter->second.setData(pos_string.c_str(), pos_string.length()+1);
}
else
{
wcout << L"You must initialize the maps before calling this function.";
}
}
#endif
simpleDDMFedAmb1516.cxx
#ifdef WIN32
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#endif
#include <stdio.h>
#include <iomanip>
#include <iostream>
#include <cstdlib>
using namespace std;
using namespace rti1516;
void printAttributes(const AttributeHandleValueMap& attributes,
{
AttributeHandleValueMap::const_iterator iter = attributes.begin();
AttributeHandleValueMap::const_iterator theEnd = attributes.end();
for (; iter != theEnd; iter++)
{
wcout << iter->first.toString().c_str() << L" "
<<
DtToWString((
char*)iter->second.data()).c_str() << endl;
}
}
void printParamValues(ParameterHandleValueMap const& paramVals)
{
ParameterHandleValueMap::const_iterator iter;
for (iter = paramVals.begin(); iter != paramVals.end(); iter++)
{
wcout << iter->first.toString().c_str() << L" "
<<
DtToWString((
char*)iter->second.data()).c_str() << endl;
}
}
NullFederateAmbassador(),
myData(data)
{
}
{
}
std::wstring const & theObjectInstanceName)
throw (
UnknownName,
FederateInternalError)
{
wcout << L"objectInstanceNameReservationSucceeded: "
<< theObjectInstanceName.c_str() << endl;
myData.myNameReservationReturned =
myData.myNameReservationSucceeded = true;
}
std::wstring const & theObjectInstanceName)
throw (
UnknownName,
FederateInternalError)
{
wcout << L"objectInstanceNameReservationFailed: "
<< theObjectInstanceName.c_str() << endl;
myData.myNameReservationReturned = true;
myData.myNameReservationSucceeded = false;
}
ObjectInstanceHandle theObject,
std::wstring const & theObjectInstanceName)
throw (
CouldNotDiscover,
ObjectClassNotKnown,
FederateInternalError)
{
wcout << L"discoverObjectInstance: "
<< theObjectInstanceName.c_str() << L"("
<< theObject.toString().c_str() << L") of class "
<< myData.objectClassMap[theObjectClass].c_str() << L"( "
<< theObjectClass.toString().c_str() << L")" << endl;
myData.objectInstanceMap[theObject] = theObjectInstanceName;
}
ObjectInstanceHandle theObject,
AttributeHandleValueMap const & theAttributeValues,
VariableLengthData const & theUserSuppliedTag,
throw (
ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
AttributeHandleValueMap::const_iterator iter
= theAttributeValues.find(myData.myPositionHandle);
if (iter != theAttributeValues.end() && iter->second.size() > 0)
{
myData.position = atoi((char*)iter->second.data());
cout << "Received Pos (" << myData.position;
if ( myData.position < myData.lowerListen )
{
cout << ") less than subscribe Region [";
}
else if ( myData.position > myData.upperListen )
{
cout << ") greater than subscribe Region [";
}
else
{
cout << ") inside subscribe Region [";
}
cout << myData.lowerListen << "," << myData.upperListen << ")\n";
}
}
(ObjectInstanceHandle theObject,
AttributeHandleValueMap const & theAttributeValues,
VariableLengthData const & theUserSuppliedTag,
RegionHandleSet const & theSentRegionHandleSet)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
sentOrder,theType);
}
(ObjectInstanceHandle theObject,
AttributeHandleValueMap const & theAttributeValues,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
sentOrder,theType);
}
(ObjectInstanceHandle theObject,
AttributeHandleValueMap const & theAttributeValues,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
RegionHandleSet const & theSentRegionHandleSet)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
sentOrder,theType);
}
(ObjectInstanceHandle theObject,
AttributeHandleValueMap const & theAttributeValues,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
InvalidLogicalTime,
FederateInternalError)
{
sentOrder,theType);
}
(ObjectInstanceHandle theObject,
AttributeHandleValueMap const & theAttributeValues,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
RegionHandleSet const & theSentRegionHandleSet)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
InvalidLogicalTime,
FederateInternalError)
{
sentOrder,theType);
}
ParameterHandleValueMap const & theParameterValues,
VariableLengthData const & theUserSuppliedTag,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ?
(const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
ParameterHandleValueMap const & theParameterValues,
VariableLengthData const & theUserSuppliedTag,
RegionHandleSet const & theSentRegionHandleSet)
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ?
(const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< L"#regions: " << theSentRegionHandleSet.size() << L" "
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
ParameterHandleValueMap const & theParameterValues,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ?
(const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< theTime.toString() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
ParameterHandleValueMap const & theParameterValues,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
RegionHandleSet const & theSentRegionHandleSet)
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ?
(const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< theTime.toString() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< L"#regions: " << theSentRegionHandleSet.size() << L" "
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
ParameterHandleValueMap const & theParameterValues,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
InvalidLogicalTime,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ?
(const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< theTime.toString() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theHandle.toString() << L" "
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
ParameterHandleValueMap const & theParameterValues,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
RegionHandleSet const & theSentRegionHandleSet)
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
InvalidLogicalTime,
FederateInternalError) {
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
throw (
ObjectInstanceNotKnown,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ") << endl;
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (
ObjectInstanceNotKnown,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theTime.toString().c_str() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ") << endl;
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (
ObjectInstanceNotKnown,
InvalidLogicalTime,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theTime.toString().c_str() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theHandle.toString().c_str() << endl;
}
ObjectInstanceHandle theObject,
AttributeHandleSet const & theAttributes)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
if ( myData.enableScopeAdvisories )
{
cout<< "********************************\n"
<< "****Attributes entering scope***\n"
<< "********************************\n";
}
}
ObjectInstanceHandle theObject,
AttributeHandleSet const & theAttributes)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
if ( myData.enableScopeAdvisories )
{
cout<< "********************************\n"
<< "****Attributes exiting scope****\n"
<< "********************************\n";
}
}
moc_simpleDDMAclock.cxx
simpleDDMAclock.cxx
#ifdef SIMPLEDDMGUI
#include <QWidget>
#include <QtCore/QDateTime>
#include <QtGui/QPainter>
#include <QtGui/QBitmap>
#include <QPushButton>
#include <QLineEdit>
#include <QtCore/QSize>
#include <QSizePolicy>
#include <QLayout>
#include <QtCore/QTimer>
#include <QApplication>
#include <string>
const int analogClock::degreesInACircle = 360;
const int analogClock::numHoursOnOurClock = 12;
const int analogClock::numTicksPerDegree = 16;
const unsigned int analogClock::NUMSECONDSPERMINUTE = 60;
const unsigned int analogClock::NUMMINUTESPERHOUR = 60;
const unsigned int analogClock::NUMSECONDSPERHOUR =
NUMSECONDSPERMINUTE * NUMMINUTESPERHOUR;
bool isClockWise,
int zone,
bool displayRegion,
const char *name )
:
myMinSeconds(0),
myMinHour(0.0f),
myMinMinutes(0),
myMaxSeconds(1),
myMaxMinutes(1),
myMaxHour(1.0f),
myHours(-1.0f),
myMinutes(0),
mySeconds(0),
myPublisher(isPublisher),
clockWise(isClockWise),
myDrawArc(displayRegion),
myUTCzone(zone),
initialized(false)
{
internalTimer = new QTimer(this);
connect(internalTimer, SIGNAL(timeout()), this, SLOT(update()));
internalTimer->start(1000);
resize(200, 200);
vLayout = new QVBoxLayout( this );
setLayout( vLayout );
vSpacer = new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding );
vLayout->addItem(vSpacer);
hLayout = new QHBoxLayout( this );
vLayout->addLayout( hLayout );
hSpacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Minimum );
clockwiseButton = new QPushButton(this);
setUTCButton = new QPushButton(this);
utcLineEdit = new QLineEdit(this);
}
{
{
}
QWidget::closeEvent(arg);
}
{
}
{
{
}
else
{
utcLineEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
}
{
}
else
{
}
{
{
}
else
{
}
}
}
{
{
{
{
}
}
else
{
}
}
}
{
}
{
{
QPainter paint( this );
}
}
{
const int widthOfWindow = 1000;
const int heightOfWindow = 1300;
const int diameterOfCircle = 1000;
const int radiusOfCircle = (int)(diameterOfCircle / 2.0f);
const float timeLineWidthPercent = .88f;
const float circleInUsePercentage = .9f;
const int circleDiameterInUse = (int)((float)diameterOfCircle * circleInUsePercentage);
const int wOrigin = - ( circleDiameterInUse / 2 );
const int widthOfLeftHash = (int)(wOrigin * timeLineWidthPercent);
const int widthOfRightHash = (int)(( wOrigin + circleDiameterInUse ) * timeLineWidthPercent);
const int heightOfTopOfHash = (wOrigin + (int)(circleDiameterInUse * 1.15f));
const int heightOfBottomOfHash = (wOrigin + (int)(circleDiameterInUse * 1.2f));
const int heightOfTimeline = (int)((heightOfTopOfHash + heightOfBottomOfHash) / 2.0f);
const int heightOfCurrentPositionTick = heightOfTimeline + (int)( diameterOfCircle * .02f );
const int numDegreesPerHour = 30;
const int numDegreesPerMinute = numDegreesPerHour / 5;
const int numDegreesPerSecond = numDegreesPerMinute;
const int QT3oclockOffset = 90;
const int lengthOfHourHand = (int) ( radiusOfCircle * .4f);
const int lengthOfMinuteHand = (int) ( radiusOfCircle * .6f);
const int lengthOfSecondHand = (int) (radiusOfCircle * .8f);
const int widthOfHourHand = (int) (radiusOfCircle * .03f);
const int widthOfMinuteHand = (int) (radiusOfCircle * .025f);
const int widthOfSecondHand = (int) (radiusOfCircle * .016f);
QColor minuteColor;
QColor secondColor;
QColor hourColor;
QColor BlackColor = QColor(0,0,0);
paint->save();
{
minuteColor = QColor(150,0,40);
secondColor = QColor(0,0,150);
hourColor = QColor(150,40,170);
}
else
{
minuteColor = BlackColor;
secondColor = BlackColor;
hourColor = BlackColor;
}
QPen arcPenStyle;
arcPenStyle.setWidth(4);
paint->setWindow( -radiusOfCircle, -radiusOfCircle,
widthOfWindow,
heightOfWindow );
paint->setBrushOrigin(QPoint(0,0));
QRect v = paint->viewport();
int d = qMin( v.width(), v.height() );
paint->setViewport( v.left() + (v.width()-d)/2,
v.top() + (v.height()-d)/2, d, d );
paint->save();
arcPenStyle.setColor(hourColor);
paint->setPen(arcPenStyle);
{
paint->drawArc( -radiusOfCircle,
-radiusOfCircle,
diameterOfCircle,
diameterOfCircle,
(int)(-myMinHoursinQT),
(int)( -lenInQt) );
arcPenStyle.setWidth(3);
paint->setPen(arcPenStyle);
int startingWidth = (int)(((float)wOrigin * timeLineWidthPercent) +
((float)circleDiameterInUse * timeLineWidthPercent));
int endingWidth = (int)(((float)wOrigin * timeLineWidthPercent) +
((
float)
myMaxHour / (float)numHoursOnOurClock) *
((float)circleDiameterInUse * timeLineWidthPercent));
paint->drawLine(
QPoint(startingWidth,heightOfBottomOfHash),
QPoint(endingWidth,heightOfBottomOfHash) );
}
arcPenStyle.setColor(BlackColor);
arcPenStyle.setWidth(2);
paint->setPen(arcPenStyle);
paint->drawLine(
QPoint(widthOfLeftHash,heightOfTopOfHash),
QPoint(widthOfLeftHash,heightOfBottomOfHash ));
paint->drawLine(
QPoint(widthOfRightHash,heightOfTopOfHash),
QPoint(widthOfRightHash,heightOfBottomOfHash ));
arcPenStyle.setWidth(2);
paint->setPen(arcPenStyle);
paint->drawLine(
QPoint(widthOfLeftHash,heightOfTimeline),
QPoint(widthOfRightHash, heightOfTimeline) );
arcPenStyle.setWidth(7);
paint->setPen(arcPenStyle);
{
float centerOfCurrentPosition = ((wOrigin * timeLineWidthPercent) +
* (circleDiameterInUse * timeLineWidthPercent));
paint->drawLine(
QPoint( (int)(centerOfCurrentPosition - 2.5f) , heightOfCurrentPositionTick) ,
QPoint( (int)(centerOfCurrentPosition + 2.5f) , heightOfCurrentPositionTick) );
}
paint->restore();
{
const int numPts = 4;
QPointF pts[numPts];
paint->save();
float numHoursInDegrees = (
myHours * numDegreesPerHour) - QT3oclockOffset;
float numMinutesInDegrees = (
myMinutes * numDegreesPerMinute) - QT3oclockOffset;
float numSecondsInDegrees = (
mySeconds * numDegreesPerSecond) - QT3oclockOffset;
paint->rotate( numHoursInDegrees );
pts[0].setX( -widthOfHourHand );
pts[0].setY( 0 );
pts[1].setX( 0 );
pts[1].setY( -widthOfHourHand );
pts[2].setX( lengthOfHourHand );
pts[2].setY( 0 );
pts[3].setX( 0 );
pts[3].setY( widthOfHourHand );
paint->setPen(Qt::NoPen);
paint->setBrush(hourColor);
paint->drawConvexPolygon( pts, numPts );
paint->setPen(Qt::SolidLine);
paint->restore();
paint->save();
paint->setPen(Qt::NoPen);
paint->setBrush(minuteColor);
paint->rotate( numMinutesInDegrees );
pts[0].setX( -widthOfMinuteHand );
pts[0].setY( 0 );
pts[1].setX( 0 );
pts[1].setY( -widthOfMinuteHand );
pts[2].setX( lengthOfMinuteHand );
pts[2].setY( 0 );
pts[3].setX( 0 );
pts[3].setY( widthOfMinuteHand );
paint->drawConvexPolygon( pts, numPts );
paint->setPen(Qt::SolidLine);
paint->setBrush(Qt::SolidPattern);
paint->restore();
paint->save();
paint->setPen(Qt::NoPen);
paint->setBrush(secondColor);
paint->rotate( numSecondsInDegrees );
pts[0].setX( -widthOfSecondHand );
pts[0].setY( 0 );
pts[1].setX( 0 );
pts[1].setY( -widthOfSecondHand );
pts[2].setX( lengthOfSecondHand );
pts[2].setY( 0 );
pts[3].setX( 0 );
pts[3].setY( widthOfSecondHand );
paint->drawConvexPolygon( pts, numPts );
paint->setPen(Qt::SolidLine);
paint->restore();
}
paint->setBrushOrigin(QPoint(50,50));
{
paint->drawLine( (int)(radiusOfCircle *.93), 0,
(int)(radiusOfCircle * .95), 0 );
paint->rotate( 30 );
}
paint->restore();
}
#endif // SIMPLEDDMGUI
simpleDDMDisplay.cxx
#ifdef SIMPLEDDMGUI
#include "qapplication.h"
#ifdef WIN32
#include <winsock2.h>
#include <process.h>
#include <windows.h>
#else
#include <unistd.h>
#include <pthread.h>
#endif
#ifdef WIN32
DWORD WINAPI qtWindowThreadProc( LPVOID lpParam )
#else
void* qtWindowThreadProc(void* lpParam)
#endif
{
clockDisplay* ourParent = (clockDisplay*) lpParam;
int numberOfArgs = 0;
QApplication ourQapp(numberOfArgs, args);
ourParent->a = &ourQapp;
ourParent->ourAnalogClock =
new analogClock( ourParent->isPublisher(),
ourParent->isClockWise(),
ourParent->zone(),
ourParent->areRegionsDisplayed() );
ourParent->ourAnalogClock->resize( 300, 300 );
ourParent->setHasAClock(true);
ourParent->ourAnalogClock->show();
int result = ourParent->a->exec();
ourParent->setHasAClock(false);
ourParent->closed = true;
#ifdef WIN32
return 0;
#else
return 0;
#endif
}
clockDisplay::clockDisplay(bool pub, bool cw, bool showReg, int zone)
:
mySeconds(0),
myMinutes(0),
myHours(0.0f),
myUpperBoundRegion(0),
myLowerBoundRegion(1),
myAreRegionsDisplayed(showReg),
myHaveAClock(false),
closed(false),
closing(false),
myIsPublisher(pub),
myIsClockWise(cw),
myUTCZone(zone)
{
initializeQTDisplay();
}
clockDisplay::~clockDisplay()
{
setHasAClock(false);
}
void clockDisplay::initializeQTDisplay()
{
#ifdef WIN32
DWORD name;
HANDLE qtThread;
qtThread = CreateThread(
NULL, 0, qtWindowThreadProc,
this, 0, &name );
{
ExitProcess(0);
}
while ( false == hasAClock() )
Sleep(150);
Sleep(300);
#else
pthread_t windowThread;
pthread_create( &windowThread,
NULL, qtWindowThreadProc,
this);
while ( false == hasAClock() )
{
usleep(150);
}
#endif //ifdef Win32
}
void clockDisplay::setTime(int seconds)
{
if ( hasAClock() )
{
ourAnalogClock->setTime(seconds);
ourAnalogClock->update();
}
}
void clockDisplay::setTime(float hour, float min, float sec)
{
if ( hasAClock() )
{
ourAnalogClock->setTime(hour, min, sec);
ourAnalogClock->update();
}
}
void clockDisplay::setBoundsRegionInSeconds(int lower, int upper)
{
if ( hasAClock() )
{
if ( myAreRegionsDisplayed )
{
ourAnalogClock->setRangeInSeconds(lower, upper);
ourAnalogClock->update();
}
}
}
bool clockDisplay::isClockWise()
{
if (hasAClock())
{
return ourAnalogClock->getClockWise();
}
else
{
return myIsClockWise;
}
}
void clockDisplay::toggleClockWise()
{
if (hasAClock())
{
ourAnalogClock->toggle();
}
else
{
myIsClockWise = !myIsClockWise;
}
}
int clockDisplay::zone()
{
if (hasAClock())
{
return ourAnalogClock->zone();
}
else
{
return myUTCZone;
}
}
void clockDisplay::setZone(int newZone)
{
if ( hasAClock() )
{
ourAnalogClock->setZone(newZone);
myUTCZone = newZone;
}
else
{
myUTCZone = newZone;
}
}
#endif // SIMPLEDDMGUI
simpleDDMFederate.cxx
#ifdef WIN32
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <winsock2.h>
#include <process.h>
#include <windows.h>
#else
#include <unistd.h>
#include <stdio.h>
#endif
using namespace std;
const unsigned int simpleDDMFederate::LOWESTSecondsInRegion = 0;
const unsigned int simpleDDMFederate::GREATESTSecondsInRegion = NUMSECONDSPERHOUR * 12;
const unsigned int simpleDDMFederate::LOWESTUTCInRegion = 0 ;
const unsigned int simpleDDMFederate::GREATESTUTCInRegion = 23;
:
myListenUpperBound(GREATESTSecondsInRegion),
myListenLowerBound(LOWESTSecondsInRegion),
mySendUpperBound(LOWESTSecondsInRegion+1),
mySendLowerBound(LOWESTSecondsInRegion),
myIsPublisher(false),
myCurrentposition(0),
myUpdateCount(0),
mySizeToInc(1),
mySendRangeSize(500.0f),
myEnableScopeAdvisories(false),
myInitialized(false),
myClosed(false),
myMapsInitialized(false),
myRegionValid(false),
myUTCZone(LOWESTUTCInRegion)
{
}
:
myListenUpperBound(data.myListenUpperBound),
myListenLowerBound(data.myListenLowerBound),
mySendUpperBound(data.mySendUpperBound),
mySendLowerBound(data.mySendLowerBound),
myIsPublisher(data.myIsPublisher),
myCurrentposition(data.myCurrentposition),
myUpdateCount(data.myUpdateCount),
mySizeToInc(data.mySizeToInc),
mySendRangeSize(data.mySendRangeSize),
myEnableScopeAdvisories(data.myEnableScopeAdvisories),
myInitialized(data.myInitialized),
myClosed(data.myClosed),
myMapsInitialized(data.myMapsInitialized),
myRegionValid(data.myRegionValid),
myUTCZone(LOWESTUTCInRegion)
{
}
{
}
simpleDDMKeyboard.cxx
#ifdef WIN32
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <conio.h>
#else
#include <unistd.h>
#endif
{
#ifndef WIN32
tcgetattr(0,&initial_settings);
#endif
}
{
#ifndef WIN32
tcsetattr(0, TCSANOW, &initial_settings);
#endif
}
{
#ifdef WIN32
return _kbhit();
#else
unsigned char ch;
int nread;
nread = read(0,&ch,1);
if (nread == 1)
{
return 1;
}
return 0;
#endif
}
{
char ch;
#ifdef WIN32
ch = _getch();
#else
{
}
else
read(0,&ch,1);
#endif
return ch;
}
{
char key = ' ';
return 0;
if (key == 'q' || key == 'Q')
{
return -1;
}
return 1;
return 2;
return 3;
return 4;
else if (key == 'p' || key == 'P')
return 5;
else
return 6;
}
simpleDDMMain.cxx
#ifdef WIN32
#pragma warning(disable: 4290)
#pragma warning(disable: 4786)
#include <winsock2.h>
#include <process.h>
#include <windows.h>
#include <exception>
#include <string>
#else
#include <unistd.h>
#include <stdio.h>
#endif
#include <iterator>
#ifdef SIMPLEDDMGUI
#endif //defined SIMPLEDDMGUI
#if defined(DtHLA13)
#elif defined(DtHLA13DLC)
#elif defined(DtHLA1516)
#elif defined(DtHLA1516E)
#else
#endif
using namespace std;
#ifndef SIMPLEDDMGUI
class clockDisplay {};
#endif //defined SIMPLEDDMGUI
template< class T >
const string& value,
T& dest );
void changeBounds( int lower,
int upper,
int zone,
clockDisplay* aClock = 0);
void SetPosition( int seconds,
clockDisplay* aDisplay = 0 );
void SetPositionAndChangeBounds( int seconds,
clockDisplay* aDisplay = 0 );
clockDisplay* aDisplay = 0);
clockDisplay* aDisplay = 0);
clockDisplay* aDisplay);
bool theUseGui = true;
bool theDisplayRegionExtents = true;
float theSendRangeTolerance(20.0f);
float theSizeOfToleratedSendRange(1);
const int theDefaultZone = 0;
int theCurrentPosition(0);
int theLastPosition(0);
int theZone(theDefaultZone);
bool theClockWise = true;
bool theChangeClockwiseDirection = false;
bool thePauseClock = false;
#ifdef WIN32
unsigned int theSleepInterval = 2;
#else
unsigned int theSleepInterval = 200;
#endif
bool thePrintUpdate = true;
static int thePositionUpperBound(simpleDDMFederate::GREATESTSecondsInRegion);
static int thePositionLowerBound(simpleDDMFederate::LOWESTSecondsInRegion);
static int theMaximumRange(simpleDDMFederate::GREATESTSecondsInRegion - simpleDDMFederate::LOWESTSecondsInRegion);
int main(int argc, char** argv)
{
std::cout << "MAK simpleDDM " << std::endl;
clockDisplay* ourDisplay = 0;
#if defined(DtHLA13)
#elif defined(DtHLA1516)
#elif defined(DtHLA1516E)
ourFed = new simpleDDMFederate1516e();
#else
ourFed = new simpleDDMFederate1516_2025();
#endif
if (!parseCmdLine(argc, argv, ourFed))
return 0;
try
{
if ( theUseGui )
{
ourDisplay = createDisplay(ourFed);
}
{
return 0;
}
{
return 0;
}
{
SetPosition(theCurrentPosition, ourFed);
}
ourFed->
tick(0.0000001, 0.005);
bool finished(false);
while (!finished)
{
{
if (theUseGui)
{
if (syncOurZoneWithGui(ourFed, ourDisplay))
{
#ifdef SIMPLEDDMGUI
ourDisplay->zone(),
ourFed,
ourDisplay );
#endif
}
}
if (ourFed->
position() != theCurrentPosition )
{
theCurrentPosition = ourFed->
position();
SetPosition(theCurrentPosition, ourFed, ourDisplay);
}
}
else
{
checkForClockwiseChange(ourFed, ourDisplay);
if( !thePauseClock )
{
if ( theClockWise )
{
theLastPosition = theCurrentPosition;
if ( theCurrentPosition >= thePositionUpperBound )
{
theCurrentPosition = thePositionLowerBound
+ (theCurrentPosition - thePositionUpperBound);
}
}
else
{
theLastPosition = theCurrentPosition;
if ( theCurrentPosition < thePositionLowerBound )
{
theCurrentPosition = thePositionUpperBound
- (thePositionLowerBound - theCurrentPosition);
}
}
SetPositionAndChangeBounds(theCurrentPosition, ourFed, ourDisplay);
if ( (theCurrentPosition % (60 * 60 * 3)) == 0 )
{
}
else if ( (theCurrentPosition % ( 60 * 60 )) == 0 )
{
}
}
}
if (!ourFed->
tick(0.0000001, 0.005))
{
finished = true;
}
if (checkInput(ourFed, ourDisplay) < 0)
{
finished = true;
}
#ifdef WIN32
Sleep(theSleepInterval);
#else
usleep(theSleepInterval);
#endif
}
if( ourFed )
{
delete ourFed;
ourFed = 0;
}
}
#if defined(DtHLA13) || defined(DtHLA13DLC)
#if defined(DtHLA13)
catch (RTI::Exception& ex)
#elif defined(DtHLA13DLC)
#endif
{
cout << "RTI Exception (main loop): "
if( ourFed )
{
delete ourFed;
}
}
#else
#if defined(DtHLA1516)
catch (rti1516::Exception& ex)
#elif defined(DtHLA1516E)
catch (rti1516e::Exception& ex)
#elif defined(DtHLA1516_2025)
catch (rti1516_2025::Exception& ex)
#endif
{
cout <<
"RTI Exception (main loop): " <<
DtToString(ex.what()) << endl;
if( ourFed )
{
delete ourFed;
}
}
#endif
catch ( ... )
{
cout << "Caught unknown exception "
<< endl;
if( ourFed )
{
delete ourFed;
}
return 1;
}
return 0;
}
{
clockDisplay* tempDisplay = 0;
#ifdef SIMPLEDDMGUI
theClockWise,
theDisplayRegionExtents,
theZone != 0);
{
theZone, ourFed, tempDisplay );
}
else
{
theZone, ourFed, tempDisplay );
}
#endif
return tempDisplay;
}
void SetPosition( int seconds,
clockDisplay* aDisplay )
{
if (thePrintUpdate && !theUseGui && aFederate->
isPublisher())
{
cout << ".";
}
#ifdef SIMPLEDDMGUI
if (aDisplay)
{
aDisplay->setTime(seconds);
}
#endif
}
void SetPositionAndChangeBounds( int seconds,
clockDisplay* aDisplay )
{
int lowerPos(0);
int upperPos(0);
bool updated(false);
SetPosition(seconds, aFederate, aDisplay);
{
{
changeBounds( thePositionLowerBound,
thePositionUpperBound, theZone, aFederate, aDisplay);
}
return;
}
if ( theClockWise )
{
if ( theCurrentPosition < theLastPosition)
{
updated = true;
lowerPos = theCurrentPosition;
if (upperPos > thePositionUpperBound)
{
upperPos = thePositionUpperBound;
}
}
else if ( (theCurrentPosition + theSizeOfToleratedSendRange) >= aFederate->
sendUpperBound() )
{
if ( (theCurrentPosition + aFederate->
sendRangeSize()) < thePositionUpperBound )
{
updated = true;
lowerPos = theCurrentPosition;
}
{
updated = true;
lowerPos = theCurrentPosition;
upperPos = thePositionUpperBound;
}
}
if (updated)
{
changeBounds( lowerPos, upperPos, theZone, aFederate, aDisplay);
}
}
else
{
if ( theCurrentPosition > theLastPosition)
{
updated = true;
upperPos = theCurrentPosition;
if (lowerPos < thePositionLowerBound)
{
updated = true;
lowerPos = thePositionLowerBound;
}
}
else if ( (theCurrentPosition - theSizeOfToleratedSendRange) <= aFederate->
sendLowerBound() )
{
if ( (theCurrentPosition - aFederate->
sendRangeSize()) > thePositionLowerBound )
{
updated = true;
upperPos = theCurrentPosition;
}
{
updated = true;
lowerPos = thePositionLowerBound;
upperPos = theCurrentPosition;
}
}
if (updated)
{
changeBounds(lowerPos, upperPos, theZone, aFederate, aDisplay);
}
}
}
void changeBounds( int lower,
int upper,
int zone,
clockDisplay* aDisplay)
{
if ( (lower < (int)simpleDDMFederate::LOWESTSecondsInRegion) ||
(upper > (int)simpleDDMFederate::GREATESTSecondsInRegion) )
{
cout << "The limits on seconds Subscriptions are [" << simpleDDMFederate::LOWESTSecondsInRegion
<< " , " << simpleDDMFederate::GREATESTSecondsInRegion << ")\n";
}
else if (lower >= upper)
{
cout << "You must set the Lowerbound to be < your Upper bound\n";
}
else if ( (zone < (int)simpleDDMFederate::LOWESTUTCInRegion) ||
(zone >= (int)simpleDDMFederate::GREATESTUTCInRegion) )
{
cout << "The limits on theZone are [" << simpleDDMFederate::LOWESTUTCInRegion
<< " , " << simpleDDMFederate::GREATESTUTCInRegion << ")\n";
#ifdef SIMPLEDDMGUI
if ( aDisplay)
{
aDisplay->setZone(theZone);
}
#endif
}
else
{
theZone = zone;
if (thePrintUpdate && !aDisplay && aFederate->
isPublisher())
{
cout << endl;
}
cout << "Setting Bounds to seconds Range ("
<< lower << "," << upper << ")" << " in zone " << zone << endl;
#ifdef SIMPLEDDMGUI
if ( aDisplay )
{
aDisplay->setBoundsRegionInSeconds(lower, upper );
aDisplay->setZone(zone);
}
#endif
}
}
clockDisplay* aDisplay)
{
bool zoneWasChanged = false;
#ifdef SIMPLEDDMGUI
if ( theUseGui && aDisplay)
{
if ( aFederate->
zone() != aDisplay->zone() )
{
zoneWasChanged = true;
}
}
#endif
return zoneWasChanged;
}
clockDisplay* aDisplay)
{
bool directionWasChanged = false;
#ifndef SIMPLEDDMGUI
if (theChangeClockwiseDirection)
{
theClockWise = !theClockWise;
directionWasChanged = true;
theChangeClockwiseDirection = false;
cout << "Change direction to " << (theClockWise ? "ClockWise" : "CounterClockWise") << endl;
}
#else
if ( theUseGui && aDisplay)
{
if (theChangeClockwiseDirection)
{
aDisplay->toggleClockWise();
theClockWise = aDisplay->isClockWise();
directionWasChanged = true;
theChangeClockwiseDirection = false;
}
else
if ( theClockWise != aDisplay->isClockWise() )
{
theClockWise = aDisplay->isClockWise();
directionWasChanged = true;
}
}
#endif
return directionWasChanged;
}
clockDisplay* aDisplay)
{
int result = 1;
int keyboardReturnCode = theInput.keybrdTick();
if (keyboardReturnCode < 0)
{
result = -1;
}
else if (keyboardReturnCode == 1)
{
{
changeBounds(
aFederate,
aDisplay);
}
}
else if (keyboardReturnCode == 2)
{
{
theZone = aFederate->
zone();
changeBounds(
aFederate,
aDisplay);
}
}
else if (keyboardReturnCode == 3)
{
{
theChangeClockwiseDirection = theClockWise;
}
}
else if (keyboardReturnCode == 4)
{
{
theChangeClockwiseDirection = !theClockWise;
}
}
else if (keyboardReturnCode == 5)
{
{
thePauseClock = !thePauseClock;
}
}
else if (keyboardReturnCode != 0)
{
{
cout << "Left Arrow - counter clockwise\n"
<< "Right Arrow - clockwise\n"
<< "P,p - pause/unpause\n"
<< "Q,q - quit\n";
}
else
{
cout << "Up Arrow - increase listen zone\n"
<< "Down Arrow - decrease listen zone\n"
<< "Q,q - quit\n";
}
}
return result;
}
{
float pertinentRange = 500.0f;
int maxSecondsSubscribe(simpleDDMFederate::GREATESTSecondsInRegion);
int minSecondsSubscribe(simpleDDMFederate::LOWESTSecondsInRegion);
vector< string > cmdArgs;
copy( argv + 1, argv + argc, back_inserter( cmdArgs ));
vector< string >::const_iterator cur = cmdArgs.begin();
vector< string >::const_iterator last = cmdArgs.end();
int mult(1);
while ( cur != last )
{
vector< string >::const_iterator next = cur + 1;
if ( *cur == "-h" )
{
return false;
}
else if (*cur == "-fedFile" )
{
++cur;
}
else if (*cur == "-maxSubscribe" )
{
if ( !convert<int> (*cur, *next, maxSecondsSubscribe ) )
return false;
++cur;
}
else if (*cur == "-minSubscribe" )
{
if ( !convert<int> (*cur, *next, minSecondsSubscribe ) )
return false;
++cur;
}
else if (*cur == "-maxSubscribeH" )
{
float maxSecondsSubscribeH;
if ( !convert<float> (*cur, *next, maxSecondsSubscribeH ) )
return false;
++cur;
maxSecondsSubscribe = ((int)(maxSecondsSubscribeH * 60.0f * 60.0f));
}
else if (*cur == "-minSubscribeH" )
{
float minSecondsSubscribeH;
if ( !convert<float> (*cur, *next, minSecondsSubscribeH ) )
return false;
++cur;
minSecondsSubscribe = ((int)(minSecondsSubscribeH * 60.0f * 60.0f));
}
else if (*cur == "-scopeAdvisories" )
{
int tmpscopeAdvisory(-1);
if ( !convert<int> (*cur, *next, tmpscopeAdvisory ) )
return false;
if ( tmpscopeAdvisory == 0 || tmpscopeAdvisory == 1 )
else
return false;
++cur;
}
else if (*cur == "-isPublisher" )
{
int intisPub(0);
if (!convert<int>(*cur, *next, intisPub))
return false;
++cur;
}
else if (*cur == "-clockWise" )
{
int intCW(0);
if (!convert<int>(*cur, *next, intCW))
return false;
theClockWise = intCW != 0;
++cur;
}
else if (*cur == "-increment" )
{
int inc;
if (!convert<int> (*cur, *next, inc) )
return false;
if (inc < 0)
{
}
else if ( inc == 0 )
{
cout << " The publisher has to increment > 0\nTo set your increment to be a fraction"
<< " negative numbers are assigned as follows: (-1 * (1 / input))\n";
return false;
}
else
++cur;
}
else if (*cur == "-multiplier" )
{
if (!convert<int> (*cur, *next, mult))
return 0;
++cur;
}
else if (*cur == "-wait" )
{
int waitTime = 2;
if (!convert<int> (*cur, *next, waitTime) || waitTime < 0)
return false;
#ifdef WIN32
theSleepInterval = waitTime;
#else
theSleepInterval = waitTime * 100;
#endif
++cur;
}
else if (*cur == "-range" )
{
if (!convert<float> (*cur, *next, pertinentRange) )
return false;
++cur;
}
else if (*cur == "-sendRangeTolerance")
{
if (!convert<float> (*cur, *next, theSendRangeTolerance ))
return false;
++cur;
}
else if (*cur == "-timeZone" )
{
if ( !convert<int> (*cur, *next, theZone ) )
return false;
if ( theZone > (int)simpleDDMFederate::GREATESTUTCInRegion
|| theZone < (int)simpleDDMFederate::LOWESTUTCInRegion )
{
return false;
}
++cur;
}
else if (*cur == "-printUpdate" )
{
int printUpdateSwitch(-1);
if ( !convert<int> (*cur, *next, printUpdateSwitch ) )
return false;
if ( printUpdateSwitch == 0 || printUpdateSwitch == 1 )
thePrintUpdate = printUpdateSwitch == 1;
else
return false;
++cur;
}
else if (*cur == "-displayRegion")
{
int tmpdisplayRegion(-1);
if (!convert<int> (*cur, *next, tmpdisplayRegion ))
return false;
if ( tmpdisplayRegion == 0 || tmpdisplayRegion == 1 )
theDisplayRegionExtents = tmpdisplayRegion == 1;
else
return false;
++cur;
}
else if (*cur == "-useGUI" )
{
#ifdef SIMPLEDDMGUI
int intUseGUI(0);
if (!convert<int>(*cur, *next, intUseGUI ))
return false;
if ( theUseGui == 0 || theUseGui == 1 )
theUseGui = intUseGUI == 1;
else
return false;
++cur;
#else
cerr << "Cannot use -useGUI. The GUI is not available in this version of the example.\n"
return false;
#endif
}
else
{
cerr << "Unrecognized command line option: "
<< *cur << "\n"
return false;
}
++cur;
}
if ( (minSecondsSubscribe < (int)simpleDDMFederate::LOWESTSecondsInRegion) ||
(maxSecondsSubscribe > (int)simpleDDMFederate::GREATESTSecondsInRegion) )
{
cout << "The limits on seconds Subscriptions are [" << simpleDDMFederate::LOWESTSecondsInRegion
<< " , " << simpleDDMFederate::GREATESTSecondsInRegion << ")\nExiting...";
return false;
}
if (minSecondsSubscribe >= maxSecondsSubscribe)
{
cout << "You cannot set the Lowerbound to be < your Upper bound\nExiting...\n";
return false;
}
if ( mult < 1 )
{
cout << "You cannot set a multiplier to less than unity\nExiting...\n";
return false;
}
if ( pertinentRange < 0 )
{
cout << "You must have a non-Zero sized range \nExiting...\n";
return false;
}
if ( (theZone < (int)simpleDDMFederate::LOWESTUTCInRegion) ||
(theZone >= (int)simpleDDMFederate::GREATESTUTCInRegion) )
{
cout << "The limits on theZone are [" << simpleDDMFederate::LOWESTUTCInRegion
<< " , " << simpleDDMFederate::GREATESTUTCInRegion << ")\nExiting...";
return false;
}
if ( theSendRangeTolerance > 100 || theSendRangeTolerance < 0 )
{
cout << "The tolerance parameter is expressed as a percentage of your Range\n"
<< " it must be between [1,100]\n";
return false;
}
{
ourFed->
changeBounds(minSecondsSubscribe, maxSecondsSubscribe, theZone);
cout << "Setting initial Bounds to seconds Range ("
<< minSecondsSubscribe << "," << maxSecondsSubscribe << ")"
<< " in zone " << theZone << endl;
}
else
{
cout << "No initial bounds specifed, setting to seconds Range ("
<< 0 << "," << 1 << ")" << " in zone " << theZone << endl;
}
theCurrentPosition = (0);
theSizeOfToleratedSendRange =
((float)ourFed->
sendRangeSize() * (theSendRangeTolerance / 100.0f));
return true;
}
template< class T >
const string& value,
T& dest )
{
{
cerr << "Bad Parameter Value\n"
<< "Param: " << param
<< "\tValue: " << value << endl;
return false;
}
return true;
}
simpleDDMAclock.h
#ifndef ANALOGCLOCK_H
#define ANALOGCLOCK_H
#include <QWidget>
#include <math.h>
#include <QLineEdit>
class QPushButton;
class QVBoxLayout;
class QHBoxLayout;
class QSpacerItem;
{
Q_OBJECT
public:
analogClock(
bool isPublisher,
bool isClockWise,
int zone,
bool displayRegions,
QWidget *parent=0,
const char *name=0 );
inline void setTime(
float hour = 12.0f,
float minute = 0,
float second = 0);
protected:
private:
private slots:
public slots:
private:
};
{
float second = seconds;
}
{
}
{
}
{
}
{
}
{
}
{
}
#endif // ACLOCK_H
simpleDDMDisplay.h
#ifndef DISPLAYFORREGIONEXAMPLE_H_
#define DISPLAYFORREGIONEXAMPLE_H_
#ifdef SIMPLEDDMGUI
#include <vector>
#include <string>
class QApplication;
class clockDisplay
{
public:
clockDisplay( bool pub = false, bool cw = true,
bool showReg = true, int zone = 0 );
~clockDisplay();
clockDisplay(clockDisplay& data);
protected:
void initializeQTDisplay();
public:
float upperBoundRegion();
float lowerBoundRegion();
bool areRegionsDisplayed();
bool isPublisher();
bool isClockWise();
void toggleClockWise();
bool hasAClock();
void setHasAClock(bool newVal);
int zone();
void setZone(int newZone);
void setBoundsRegionInSeconds(int lower, int upper);
void setTime(int seconds);
void setTime(float hour, float min, float sec);
bool myHaveAClock;
bool closed;
bool closing;
QApplication* a;
private:
float mySeconds;
float myMinutes;
float myHours;
float myUpperBoundRegion;
float myLowerBoundRegion;
bool myAreRegionsDisplayed;
bool myIsPublisher;
bool myIsClockWise;
int myUTCZone;
};
inline float clockDisplay::upperBoundRegion()
{
return myUpperBoundRegion;
}
inline float clockDisplay::lowerBoundRegion()
{
return myLowerBoundRegion;
}
inline bool clockDisplay::areRegionsDisplayed()
{
return myAreRegionsDisplayed;
}
inline bool clockDisplay::isPublisher()
{
return myIsPublisher;
}
inline bool clockDisplay::hasAClock()
{
return myHaveAClock;
}
inline void clockDisplay::setHasAClock(bool newVal)
{
myHaveAClock = newVal;
}
#endif // SIMPLEDDMGUI
#endif // DISPLAYFORREGIONEXAMPLE_H_
simpleDDMFedAmb1516.h
#ifndef MyFederateAmbassador_H_
#define MyFederateAmbassador_H_
#include <map>
#include <RTI/RTI1516.h>
#include <RTI/NullFederateAmbassador.h>
#include <string>
{
public:
};
{
public:
virtual
void
(std::wstring const & theObjectInstanceName)
throw (rti1516::UnknownName,
rti1516::FederateInternalError);
virtual
void
(std::wstring const & theObjectInstanceName)
throw (rti1516::UnknownName,
rti1516::FederateInternalError);
virtual
void
(rti1516::ObjectInstanceHandle theObject,
std::wstring const & theObjectInstanceName)
throw (rti1516::CouldNotDiscover,
rti1516::ObjectClassNotKnown,
rti1516::FederateInternalError);
virtual
void
(rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
throw (rti1516::ObjectInstanceNotKnown,
rti1516::AttributeNotRecognized,
rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError);
virtual
void
(rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::ObjectInstanceNotKnown,
rti1516::AttributeNotRecognized,
rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError);
virtual
void
(rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
throw (rti1516::ObjectInstanceNotKnown,
rti1516::AttributeNotRecognized,
rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError);
virtual
void
(rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::ObjectInstanceNotKnown,
rti1516::AttributeNotRecognized,
rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError);
virtual
void
(rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
rti1516::MessageRetractionHandle theHandle)
throw (rti1516::ObjectInstanceNotKnown,
rti1516::AttributeNotRecognized,
rti1516::AttributeNotSubscribed,
rti1516::InvalidLogicalTime,
rti1516::FederateInternalError);
virtual
void
(rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
rti1516::MessageRetractionHandle theHandle,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::ObjectInstanceNotKnown,
rti1516::AttributeNotRecognized,
rti1516::AttributeNotSubscribed,
rti1516::InvalidLogicalTime,
rti1516::FederateInternalError);
virtual
void
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
throw (rti1516::InteractionClassNotRecognized,
rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed,
rti1516::FederateInternalError);
virtual
void
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::InteractionClassNotRecognized,
rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed,
rti1516::FederateInternalError);
virtual
void
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
throw (rti1516::InteractionClassNotRecognized,
rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed,
rti1516::FederateInternalError);
virtual
void
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::InteractionClassNotRecognized,
rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed,
rti1516::FederateInternalError);
virtual
void
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
rti1516::MessageRetractionHandle theHandle)
throw (rti1516::InteractionClassNotRecognized,
rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed,
rti1516::InvalidLogicalTime,
rti1516::FederateInternalError);
virtual
void
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
rti1516::MessageRetractionHandle theHandle,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::InteractionClassNotRecognized,
rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed,
rti1516::InvalidLogicalTime,
rti1516::FederateInternalError);
virtual
void
rti1516::VariableLengthData const & theUserSuppliedTag,
throw (rti1516::ObjectInstanceNotKnown,
rti1516::FederateInternalError);
virtual
void
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
throw (rti1516::ObjectInstanceNotKnown,
rti1516::FederateInternalError);
virtual
void
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::LogicalTime const & theTime,
rti1516::MessageRetractionHandle theHandle)
throw (rti1516::ObjectInstanceNotKnown,
rti1516::InvalidLogicalTime,
rti1516::FederateInternalError);
virtual
void
(rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleSet const & theAttributes)
throw (rti1516::ObjectInstanceNotKnown,
rti1516::AttributeNotRecognized,
rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError) ;
virtual
void
(rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleSet const & theAttributes)
throw (rti1516::ObjectInstanceNotKnown,
rti1516::AttributeNotRecognized,
rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError) ;
public:
};
#endif
simpleDDMFederate.h
#ifndef REGIONEXAMPLE_H_
#define REGIONEXAMPLE_H_
#include <sstream>
#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
{
public:
virtual void sendUpdate(
int currentPosition ) = 0;
virtual void changeBounds(
int lower,
int upper,
int UTCZone) = 0;
virtual bool tick(
double atMost=0.0f) = 0;
virtual bool tick(
double atLeast,
double atMost) = 0;
{
};
protected:
private:
};
{
}
{
{
}
else
{
}
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
#endif
simpleDDMKeyboard.h
#ifndef MYKBHIT_H_
#define MYKBHIT_H_
#ifndef WIN32
#include <termios.h>
#endif
{
public:
enum
{
#ifdef WIN32
#else
#endif
};
protected:
private:
#ifndef WIN32
#endif
};
#endif
simpleDDMSimple1516.h
#ifndef REGIONEXAMPLE1516_H_
#define REGIONEXAMPLE1516_H_
#include <wchar.h>
#include <string.h>
#include <RTI/RTI1516.h>
#include <RTI/RTIambassadorFactory.h>
{
public:
bool tick(
double atMost=0.0f);
bool tick(
double atLeast,
double atMost);
protected:
private:
};
{
}
{
}
{
}
{
}
{
}
{
}
#endif
simpleDDMStringUtil.h
#ifndef stringUtil_H_
#define stringUtil_H_
#include <string>
#include <sstream>
std::string
DtToString(
const std::wstring &in_val);
{
std::wstring temp;
while (*in_val != '\0')
temp += *in_val++;
return temp;
}
inline std::string
DtToString(
const std::wstring &in_val)
{
std::string temp;
std::wstring::const_iterator b = in_val.begin();
const std::wstring::const_iterator e = in_val.end();
while (b != e)
{
temp += static_cast<char>(*b);
++b;
}
return temp;
}
inline std::string
usage()
{
std::ostringstream ostr;
ostr << "Usage:\n"
<< std::setw( 20 ) << " -fedFile "
<< "specify the Fed file name \n"
<< std::setw ( 32 ) << " " << "1.3 Default: (MAKSimpleDDM.fed) \n"
<< std::setw ( 32 ) << " " << "1516 Default: (MAKSimpleDDM.xml) \n"
<< "\nSubscriber parameters\n"
<< std::setw( 20 ) << " -maxSubscribe "
<< "Simple DDM uses just one extent and dimension, \n"
<< std::setw( 32 ) << " " << "this is the subscribers upper range \n"
<< std::setw( 32 ) << " " << "(in seconds)\n"
<< std::setw( 20 ) << " -minSubscribe "
<< "Simple DDM uses just one extent and dimension, \n"
<< std::setw( 32 ) << " " << "this is the subscriber's lower range \n"
<< std::setw( 32 ) << " " << "(in seconds)\n"
<< std::setw( 20 ) << " -maxSubscribeH "
<< "Simple DDM uses just one extent and dimension, \n"
<< std::setw( 32 ) << " " << "this is the subscribers upper range\n"
<< std::setw( 32 ) << " " << "(in hours)\n"
<< std::setw( 20 ) << " -minSubscribeH "
<< "Simple DDM uses just one extent and dimension, \n"
<< std::setw( 32 ) << " " << "this the subscriber's lower range \n"
<< std::setw( 32 ) << " " << "(in hours)\n"
<< std::setw( 20 ) << " -scopeAdvisories "
<< "Whether or not the user wants to receive \n"
<< std::setw( 32 ) << " " << "scoping advisory notices (0 || 1)\n"
<< "\nPublisher parameters\n"
<< std::setw( 20 ) << " -isPublisher "
<< "Whether the application should as publisher or \n"
<< std::setw( 32 ) << " " << "subscriber. (default 0)\n"
<< std::setw( 20 ) << " -clockWise "
<< "Whether the object moves in CW or CCW direction \n"
<< std::setw( 32 ) << " " << "1 = CW (default)\n"
<< std::setw( 20 ) << " -increment "
<< "Increment that the publisher will advance by in seconds\n"
<< std::setw( 32 ) << " " << "modified by multiplier\n"
<< std::setw( 20 ) << " -multiplier "
<< "Multiplier for both advancement upon the extent\n"
<< std::setw( 32 ) << " " << "and lookahead on the extent\n"
<< std::setw( 20 ) << " -wait "
<< "Time interval (in milliseconds) to wait inbetween each update cycle.\n"
<< std::setw( 20 ) << " -range "
<< "Lookahead multiplier that the listening range \n"
<< std::setw( 32 ) << " " << "will subscribe to\n"
<< std::setw( 20 ) << " -sendRangeTolerance "
<< " Describes a percentage of the sending range, \n"
<< std::setw( 32 ) << " " << "how close the sender can get to the \n"
<< std::setw( 32 ) << " " << "extents of the sending range before \n"
<< std::setw( 32 ) << " " << "the Lower and Upper Bound of the \n"
<< std::setw( 32 ) << " " << "sender are re-sent\n"
<< std::setw( 20 ) << " -timeZone"
<< " Sets the UTC zone of the publisher \n"
<< std::setw( 32 ) << " " << "Acceptable Values are from 0 .. 23 \n"
<< std::setw( 32 ) << " " << " Default value is 0, representing GMT\n"
<< std::setw( 20 ) << " -printUpdate "
<< "When GUI is disabled, prints a dot for each update to better\n"
<< std::setw( 32 ) << " " << "distinguish bounds changes\n"
<< "\nDisplay Options \n"
<< std::setw( 20 ) << " -displayRegion "
<< "Whether or not there is distinction in shading \n"
<< std::setw( 32 ) << " " << "in extent of a region and the entire \n"
<< std::setw( 32 ) << " " << "dimension (0 || 1)\n"
#ifdef SIMPLEDDMGUI
<< std::setw( 20 ) << " -useGUI "
<< "Whether the application should run in GUI or \n"
<< std::setw( 32 ) << " " << "console mode. \n"
#endif
<< std::endl;
return ostr.str();
}
#endif