![]() |
MAK RTIspy API Documentation for HLA 1516
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2010 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 ********************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: .h,v $ $Revision: 1.2 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00009 #ifndef HlaBounceMainWindow_H_ 00010 #define HlaBounceMainWindow_H_ 00011 00012 #include "ballData.h" 00013 #include "regionData.h" 00014 #include <qmainwindow.h> 00015 00016 class BallController; 00017 class HlaBounceOptionsDialog; 00018 class QTimer; 00019 class QLabel; 00020 class QListWidget; 00021 class QListWidgetItem; 00022 class QPushButton; 00023 class QComboBox; 00024 class QGraphicsView; 00025 class HlaBounceGraphicsScene; 00026 class QGraphicsTextItem; 00027 class QVBoxLayout; 00028 class QHBoxLayout; 00029 class QSplitter; 00030 class QSpacerItem; 00031 class QSignalMapper; 00032 class QPlainTextEdit; 00033 class QMenu; 00034 class QTime; 00035 00036 class HlaBounceMainWindow : public QMainWindow 00037 { 00038 Q_OBJECT 00039 00040 public: 00041 00042 HlaBounceMainWindow(BallController* ballController, BallMap* ballData, 00043 DdmRegionMap* regionData, const char* protocolName); 00044 virtual ~HlaBounceMainWindow(); 00045 00046 public slots: 00047 00048 // Displays a connection error message and then exits the application 00049 void displayConnErrorAndExit(); 00050 00051 // Updates position of all balls at periodic intervals 00052 void updateBalls(); 00053 00054 // Creates (if necessary) and joins the federation 00055 void createAndJoinFederation(); 00056 00057 // Resigns from (and possibly destroys) the federation 00058 void resignFromFederation(); 00059 00060 // Subscribes to updates for ball objects 00061 void subscribeToBallUpdates(); 00062 00063 // Unsubscribes to updates for ball objects 00064 void unsubscribeToBallUpdates(); 00065 00066 // Adds a ball at the given location 00067 void addBall(); 00068 00069 // Removes the currently selected owned ball 00070 void removeBall(); 00071 00072 // Attempts to acquire ownership of selected ball 00073 void acquireBall(); 00074 00075 // Attempts to divest ownership of selected owned ball 00076 void divestBall(); 00077 00078 // Changes the ball color for this federate 00079 void changeBallColor(int newColor); 00080 00081 // Displays any pending text events and removes any expired ones 00082 void displayTextEvents(); 00083 00084 // Enters into mode where a DDM region can be added by drawing a rectangle 00085 // in the ball area 00086 void enterAddDdmRegionMode(); 00087 00088 // Exits add DDM region mode 00089 void exitAddDdmRegionMode(); 00090 00091 // Adds a DDM region at the given location 00092 void addDdmRegion(const QPointF& loc); 00093 00094 // Removes all of the DDM regions 00095 void removeDdmRegions(); 00096 00097 // Opens dialog to display configuration options 00098 void displayOptions(); 00099 00100 // Handle ball selection from list item 00101 void ballSelectedFromList(QWidget* list); 00102 00103 // Handle ball selection 00104 void ballSelected(); 00105 00106 protected: 00107 00108 // Creates and initializes the widgets to display the lists of balls 00109 void setupBallLists(); 00110 00111 // Creates and initializes the tool bar with the federate controls 00112 void setupToolBar(); 00113 00114 // Creates and initializes the widgets to display the ball graphics 00115 void setupGraphics(); 00116 00117 // Performs the window layout 00118 void layoutWindow(const QString& protocolName); 00119 00120 // Creates and initializes the menus 00121 void setupMenus(); 00122 00123 // Enables or disables the widgets based on current state 00124 void enableOrDisableWidgets(); 00125 00126 // Draw balls in new locations 00127 void drawBalls(); 00128 00129 // Draw regions in new locations 00130 void drawRegions(); 00131 00132 // Adds the given ball to one of the lists 00133 void addBallToList(Ball* ball); 00134 00135 // Removes the given ball from its list 00136 void removeBallFromList(Ball* ball); 00137 00138 // Rescales the graphics to fit the new screen size 00139 virtual void resizeEvent(QResizeEvent* event); 00140 00141 std::wstring convertToWString(const std::string& inString) const; 00142 std::string convertFromWString(const std::wstring& inString) const; 00143 00144 private: 00145 00146 // Default constructor not implemented 00147 HlaBounceMainWindow(); 00148 00149 protected: 00150 00151 BallController* myBallController; 00152 00153 BallMap* myBallData; 00154 std::map<std::wstring, QListWidgetItem*> myBallListItemMap; 00155 DdmRegionMap* myRegionData; 00156 00157 QTimer* myTimer; 00158 00159 QLabel* myOwnedBallsLabel; 00160 QListWidget* myOwnedBallsList; 00161 QLabel* myOtherBallsLabel; 00162 QListWidget* myOtherBallsList; 00163 QVBoxLayout* myListsLayout; 00164 QWidget* myListsLayoutWidget; 00165 QSignalMapper* myListSelectionSignalMapper; 00166 00167 QAction* myExitAction; 00168 QAction* myCreateAndJoinAction; 00169 QAction* myResignAndDestroyAction; 00170 QAction* mySubscribeAction; 00171 QAction* myUnsubscribeAction; 00172 QAction* myAddBallAction; 00173 QAction* myRemoveBallAction; 00174 QLabel* myColorLabel; 00175 QComboBox* myColorComboBox; 00176 QAction* myAddDdmRegionAction; 00177 QAction* myRemoveDdmRegionsAction; 00178 QAction* myAcquireBallAction; 00179 QAction* myDivestBallAction; 00180 QAction* myOptionsAction; 00181 QAction* myLogAction; 00182 QToolBar* myToolBar; 00183 00184 std::map<BallColor, QString> myColorImageMapping; 00185 std::map<BallColor, QString> myColorTextMapping; 00186 00187 QGraphicsView* myGraphicsView; 00188 HlaBounceGraphicsScene* myScene; 00189 QVBoxLayout* myGraphicsLayout; 00190 QWidget* myGraphicsLayoutWidget; 00191 00192 QSplitter* myListsGraphicsSplitter; 00193 QHBoxLayout* myCentralLayout; 00194 QWidget* myCentralWidget; 00195 00196 HlaBounceOptionsDialog* myOptionsDialog; 00197 QDialog* myLogDialog; 00198 QPlainTextEdit* myLogTextEdit; 00199 00200 std::map<QTime, QGraphicsTextItem*> myTextEventsByExpirationTime; 00201 00202 QMenu* myMenuFile; 00203 QMenu* myMenuFederation; 00204 QMenu* myMenuSubscription; 00205 QMenu* myMenuObjects; 00206 00207 bool myAddDdmRegionMode; 00208 00209 static const int theMinX; 00210 static const int theMinY; 00211 static const int theMaxX; 00212 static const int theMaxY; 00213 00214 static const int theIdKey; 00215 static const int theColorKey; 00216 00217 static const QString theIconDirectory; 00218 }; 00219 00220 inline std::wstring HlaBounceMainWindow::convertToWString(const std::string& inString) const 00221 { 00222 std::wstring temp; 00223 const char* in_val = inString.c_str(); 00224 while (*in_val != '\0') 00225 { 00226 temp += *in_val++; 00227 } 00228 return temp; 00229 } 00230 00231 inline std::string HlaBounceMainWindow::convertFromWString(const std::wstring& inString) const 00232 { 00233 std::string temp; 00234 const wchar_t* in_val = inString.c_str(); 00235 while (*in_val != L'\0') 00236 { 00237 temp += *in_val++; 00238 } 00239 return temp; 00240 } 00241 00242 #endif