| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
#include <vjConfig.h> |
|---|
| 36 |
#include <Kernel/vjDisplayManager.h> |
|---|
| 37 |
#include <Kernel/vjDisplay.h> |
|---|
| 38 |
#include <Kernel/vjSurfaceDisplay.h> |
|---|
| 39 |
#include <Kernel/vjSimDisplay.h> |
|---|
| 40 |
#include <Kernel/vjDrawManager.h> |
|---|
| 41 |
#include <Kernel/vjKernel.h> |
|---|
| 42 |
#include <Math/vjCoord.h> |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
vjSingletonImp(vjDisplayManager); |
|---|
| 46 |
|
|---|
| 47 |
std::vector<vjDisplay*> vjDisplayManager::getAllDisplays() |
|---|
| 48 |
{ |
|---|
| 49 |
std::vector<vjDisplay*> ret_val; |
|---|
| 50 |
ret_val.insert(ret_val.end(), mActiveDisplays.begin(), mActiveDisplays.end()); |
|---|
| 51 |
ret_val.insert(ret_val.end(), mInactiveDisplays.begin(), mInactiveDisplays.end()); |
|---|
| 52 |
return ret_val; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
void vjDisplayManager::setDrawManager(vjDrawManager* drawMgr) |
|---|
| 57 |
{ |
|---|
| 58 |
vjDEBUG(vjDBG_DISP_MGR,3) << "vjDisplayManager: Setting draw manager.\n" << vjDEBUG_FLUSH; |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
mDrawManager = drawMgr; |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
if(mDrawManager != NULL) |
|---|
| 65 |
{ |
|---|
| 66 |
for(unsigned int i=0;i<mActiveDisplays.size();i++) |
|---|
| 67 |
{ |
|---|
| 68 |
mDrawManager->addDisplay(mActiveDisplays[i]); |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
bool vjDisplayManager::configAdd(vjConfigChunk* chunk) |
|---|
| 76 |
{ |
|---|
| 77 |
vjASSERT(configCanHandle(chunk)); |
|---|
| 78 |
|
|---|
| 79 |
std::string chunk_type = (std::string)chunk->getType(); |
|---|
| 80 |
|
|---|
| 81 |
if( (chunk_type == std::string("surfaceDisplay")) |
|---|
| 82 |
|| (chunk_type == std::string("simDisplay")) ) |
|---|
| 83 |
{ |
|---|
| 84 |
return configAddDisplay(chunk); |
|---|
| 85 |
} |
|---|
| 86 |
else if(chunk_type == std::string("displaySystem")) |
|---|
| 87 |
{ |
|---|
| 88 |
|
|---|
| 89 |
mDisplaySystemChunk = chunk; |
|---|
| 90 |
return true; |
|---|
| 91 |
|
|---|
| 92 |
} |
|---|
| 93 |
else |
|---|
| 94 |
{ return false; } |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
bool vjDisplayManager::configRemove(vjConfigChunk* chunk) |
|---|
| 100 |
{ |
|---|
| 101 |
vjASSERT(configCanHandle(chunk)); |
|---|
| 102 |
|
|---|
| 103 |
std::string chunk_type = (std::string)chunk->getType(); |
|---|
| 104 |
|
|---|
| 105 |
if( (chunk_type == std::string("surfaceDisplay")) |
|---|
| 106 |
|| (chunk_type == std::string("simDisplay")) ) |
|---|
| 107 |
{ |
|---|
| 108 |
return configRemoveDisplay(chunk); |
|---|
| 109 |
} |
|---|
| 110 |
else if(chunk_type == std::string("displaySystem")) |
|---|
| 111 |
{ |
|---|
| 112 |
|
|---|
| 113 |
mDisplaySystemChunk = NULL; |
|---|
| 114 |
return true; |
|---|
| 115 |
|
|---|
| 116 |
} |
|---|
| 117 |
else |
|---|
| 118 |
{ return false; } |
|---|
| 119 |
|
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
bool vjDisplayManager::configCanHandle(vjConfigChunk* chunk) |
|---|
| 127 |
{ |
|---|
| 128 |
return ( ((std::string)chunk->getType() == std::string("surfaceDisplay")) |
|---|
| 129 |
|| ((std::string)chunk->getType() == std::string("simDisplay")) |
|---|
| 130 |
|| ((std::string)chunk->getType() == std::string("displaySystem")) ); |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
bool vjDisplayManager::configAddDisplay(vjConfigChunk* chunk) |
|---|
| 142 |
{ |
|---|
| 143 |
vjASSERT(configCanHandle(chunk)); |
|---|
| 144 |
|
|---|
| 145 |
vjDEBUG_BEGIN(vjDBG_DISP_MGR,vjDBG_STATE_LVL) << "------- vjDisplayManager::configAddDisplay -------\n" << vjDEBUG_FLUSH; |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
vjDisplay* cur_disp = findDisplayNamed(chunk->getProperty("name")); |
|---|
| 151 |
if(cur_disp != NULL) |
|---|
| 152 |
{ |
|---|
| 153 |
vjDEBUG(vjDBG_DISP_MGR,vjDBG_CONFIG_LVL) << "Removing old window: " << cur_disp->getName().c_str() << vjDEBUG_FLUSH; |
|---|
| 154 |
closeDisplay(cur_disp,true); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
if((std::string)chunk->getType() == std::string("surfaceDisplay")) |
|---|
| 159 |
{ |
|---|
| 160 |
vjDisplay* newDisp = new vjSurfaceDisplay(); |
|---|
| 161 |
newDisp->config(chunk); |
|---|
| 162 |
addDisplay(newDisp, true); |
|---|
| 163 |
vjDEBUG(vjDBG_DISP_MGR,vjDBG_STATE_LVL) << "Adding display: " |
|---|
| 164 |
<< newDisp->getName().c_str() |
|---|
| 165 |
<< std::endl << vjDEBUG_FLUSH; |
|---|
| 166 |
vjDEBUG(vjDBG_DISP_MGR,vjDBG_STATE_LVL) << "Display: " << newDisp |
|---|
| 167 |
<< std::endl << vjDEBUG_FLUSH; |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
if((std::string)chunk->getType() == std::string("simDisplay")) |
|---|
| 171 |
{ |
|---|
| 172 |
vjDisplay* newDisp = new vjSimDisplay(); |
|---|
| 173 |
newDisp->config(chunk); |
|---|
| 174 |
addDisplay(newDisp, true); |
|---|
| 175 |
vjDEBUG(vjDBG_DISP_MGR,vjDBG_WARNING_LVL) << "Adding Display: " |
|---|
| 176 |
<< newDisp->getName().c_str() |
|---|
| 177 |
<< std::endl << vjDEBUG_FLUSH; |
|---|
| 178 |
vjDEBUG(vjDBG_DISP_MGR,vjDBG_VERB_LVL) << "Display: " << newDisp |
|---|
| 179 |
<< std::endl << std::flush |
|---|
| 180 |
<< vjDEBUG_FLUSH; |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
vjDEBUG_END(vjDBG_DISP_MGR,vjDBG_STATE_LVL) << "------- vjDisplayManager::configAddDisplay Done. --------\n" << vjDEBUG_FLUSH; |
|---|
| 184 |
return true; |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
bool vjDisplayManager::configRemoveDisplay(vjConfigChunk* chunk) |
|---|
| 191 |
{ |
|---|
| 192 |
vjASSERT(configCanHandle(chunk)); |
|---|
| 193 |
|
|---|
| 194 |
vjDEBUG_BEGIN(vjDBG_DISP_MGR,4) << "------- vjDisplayManager::configRemoveDisplay -------\n" << vjDEBUG_FLUSH; |
|---|
| 195 |
|
|---|
| 196 |
bool success_flag(false); |
|---|
| 197 |
|
|---|
| 198 |
if((std::string)chunk->getType() == std::string("surfaceDisplay") || |
|---|
| 199 |
(std::string)chunk->getType() == std::string("simDisplay")) |
|---|
| 200 |
{ |
|---|
| 201 |
vjDisplay* remove_disp = findDisplayNamed(chunk->getProperty("name")); |
|---|
| 202 |
if(remove_disp != NULL) |
|---|
| 203 |
{ |
|---|
| 204 |
closeDisplay(remove_disp, true); |
|---|
| 205 |
success_flag = true; |
|---|
| 206 |
} |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
vjDEBUG_END(vjDBG_DISP_MGR,4) << "------- vjDisplayManager::configRemoveDisplay done. --------\n" << vjDEBUG_FLUSH; |
|---|
| 210 |
return success_flag; |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
int vjDisplayManager::addDisplay(vjDisplay* disp, bool notifyDrawMgr) |
|---|
| 218 |
{ |
|---|
| 219 |
vjDEBUG(vjDBG_DISP_MGR,4) << "vjDisplayManager::addDisplay \n" << vjDEBUG_FLUSH; |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
if(disp->isActive()) |
|---|
| 225 |
mActiveDisplays.push_back(disp); |
|---|
| 226 |
else |
|---|
| 227 |
mInactiveDisplays.push_back(disp); |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
if((notifyDrawMgr) && (mDrawManager != NULL) && (disp->isActive())) |
|---|
| 231 |
mDrawManager->addDisplay(disp);; |
|---|
| 232 |
|
|---|
| 233 |
return 1; |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
int vjDisplayManager::closeDisplay(vjDisplay* disp, bool notifyDrawMgr) |
|---|
| 242 |
{ |
|---|
| 243 |
vjASSERT(isMemberDisplay(disp)); |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
if((notifyDrawMgr) && (mDrawManager != NULL) && (disp->isActive())) |
|---|
| 247 |
mDrawManager->removeDisplay(disp); |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
unsigned int num_before_close = mActiveDisplays.size() + mInactiveDisplays.size(); |
|---|
| 251 |
mActiveDisplays.erase( std::remove(mActiveDisplays.begin(), mActiveDisplays.end(), disp), |
|---|
| 252 |
mActiveDisplays.end()); |
|---|
| 253 |
mInactiveDisplays.erase( std::remove(mInactiveDisplays.begin(), mInactiveDisplays.end(), disp), |
|---|
| 254 |
mInactiveDisplays.end()); |
|---|
| 255 |
vjASSERT(num_before_close == (1+mActiveDisplays.size() + mInactiveDisplays.size())); |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
return 1; |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
bool vjDisplayManager::isMemberDisplay(vjDisplay* disp) |
|---|
| 269 |
{ |
|---|
| 270 |
std::vector<vjDisplay*>::iterator i; |
|---|
| 271 |
|
|---|
| 272 |
i = std::find(mActiveDisplays.begin(),mActiveDisplays.end(),disp); |
|---|
| 273 |
if(i != mActiveDisplays.end()) |
|---|
| 274 |
return true; |
|---|
| 275 |
|
|---|
| 276 |
i = std::find(mInactiveDisplays.begin(),mInactiveDisplays.end(),disp); |
|---|
| 277 |
if(i != mInactiveDisplays.end()) |
|---|
| 278 |
return true; |
|---|
| 279 |
|
|---|
| 280 |
return false; |
|---|
| 281 |
} |
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
vjDisplay* vjDisplayManager::findDisplayNamed(std::string name) |
|---|
| 286 |
{ |
|---|
| 287 |
std::vector<vjDisplay*>::iterator i; |
|---|
| 288 |
|
|---|
| 289 |
for(i = mActiveDisplays.begin();i!=mActiveDisplays.end();i++) |
|---|
| 290 |
if((*i)->getName() == name) |
|---|
| 291 |
return (*i); |
|---|
| 292 |
|
|---|
| 293 |
for(i = mInactiveDisplays.begin();i!=mInactiveDisplays.end();i++) |
|---|
| 294 |
if((*i)->getName() == name) |
|---|
| 295 |
return (*i); |
|---|
| 296 |
|
|---|
| 297 |
return NULL; |
|---|
| 298 |
} |
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
void vjDisplayManager::updateProjections() |
|---|
| 302 |
{ |
|---|
| 303 |
|
|---|
| 304 |
for (std::vector<vjDisplay*>::iterator i = mActiveDisplays.begin(); i != mActiveDisplays.end(); i++) |
|---|
| 305 |
(*i)->updateProjections(); |
|---|
| 306 |
|
|---|
| 307 |
for (std::vector<vjDisplay*>::iterator j = mInactiveDisplays.begin(); j != mInactiveDisplays.end(); j++) |
|---|
| 308 |
(*j)->updateProjections(); |
|---|
| 309 |
|
|---|
| 310 |
if(mDrawManager != NULL) |
|---|
| 311 |
mDrawManager->updateProjections(); |
|---|
| 312 |
} |
|---|
| 313 |
|
|---|
| 314 |
|
|---|