| 1 | #include <stdio.h> | 
|---|
| 2 | #include <stdlib.h> | 
|---|
| 3 | #include <ctype.h> | 
|---|
| 4 |  | 
|---|
| 5 | #include <typeinfo> | 
|---|
| 6 | #include <iostream> | 
|---|
| 7 | #include <string> | 
|---|
| 8 | #include <list> | 
|---|
| 9 | #include <map> | 
|---|
| 10 |  | 
|---|
| 11 | #include "sopnamsp.h" | 
|---|
| 12 | #include "strutil.h" | 
|---|
| 13 | #include "datatypes.h" | 
|---|
| 14 |  | 
|---|
| 15 | #include "nobjmgr.h" | 
|---|
| 16 | #include "servnobjm.h" | 
|---|
| 17 | #include "nomgadapter.h" | 
|---|
| 18 | #include "pistdimgapp.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "dvlist.h" | 
|---|
| 21 |  | 
|---|
| 22 | #include "tvector.h" | 
|---|
| 23 | #include "pitvmaad.h" | 
|---|
| 24 | #include "piyfxdrw.h" | 
|---|
| 25 |  | 
|---|
| 26 | #include "pisurfdr.h" | 
|---|
| 27 | #include "pipodrw.h" | 
|---|
| 28 |  | 
|---|
| 29 | #include "pintuple.h" | 
|---|
| 30 | #include "pintup3d.h" | 
|---|
| 31 | #include "pigfd1.h" | 
|---|
| 32 | #include "pigfd2.h" | 
|---|
| 33 |  | 
|---|
| 34 | #include "zthread.h" | 
|---|
| 35 |  | 
|---|
| 36 |  | 
|---|
| 37 | //++ | 
|---|
| 38 | // Class        NamedObjMgr | 
|---|
| 39 | // Lib          PI | 
|---|
| 40 | // include      nobjmgr.h | 
|---|
| 41 | // | 
|---|
| 42 | //      Cette classe fournit les services nécéssaires à la gestion des objets | 
|---|
| 43 | //      (l'ensemble des objets PPersist de PEIDA++) au sein du programme | 
|---|
| 44 | //      d'analyse interactive *piapp* . Elle constitue en outre l'interface | 
|---|
| 45 | //      entre les fonctions utilisateur et l'application graphique. | 
|---|
| 46 | //-- | 
|---|
| 47 | //++ | 
|---|
| 48 | // Links        Voir aussi | 
|---|
| 49 | // PIStdImgApp | 
|---|
| 50 | // Services2NObjMgr | 
|---|
| 51 | // PIACmd | 
|---|
| 52 | //-- | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 | // .................................................................. | 
|---|
| 56 | // ......  Gestion des objets nommes, variables globales ............ | 
|---|
| 57 | struct nobj_diritem { | 
|---|
| 58 | int id;                 // Directory Id | 
|---|
| 59 | int nobj;               // Number of objects in directory | 
|---|
| 60 | bool lock;              // True -> directory locked, No Add, del or rename | 
|---|
| 61 | bool keepold;           // True -> When duplicate object name, old object moved to /old | 
|---|
| 62 | }; | 
|---|
| 63 |  | 
|---|
| 64 | typedef map<string, nobj_diritem, less<string> > NObjDirList; | 
|---|
| 65 |  | 
|---|
| 66 | struct nobj_item { | 
|---|
| 67 | AnyDataObj* obj;             // Object pointer | 
|---|
| 68 | NObjMgrAdapter* obja;        // Object adapter pointer | 
|---|
| 69 | int oid;                     // object Id | 
|---|
| 70 | int dirid;                   // Directory Id | 
|---|
| 71 | list<int> wrsid;             // List of Window Resource Id (Drawer, PIBaseWdg, ...) | 
|---|
| 72 | // (for PIStdImgApp) | 
|---|
| 73 | bool operator==(nobj_item const& b) const | 
|---|
| 74 | { return (this->obj ==  b.obj); } | 
|---|
| 75 | }; | 
|---|
| 76 |  | 
|---|
| 77 | typedef map<string, nobj_item, less<string> > NObjList; | 
|---|
| 78 |  | 
|---|
| 79 | static NObjDirList* myDirs = NULL; | 
|---|
| 80 | static NObjList* myObjs = NULL; | 
|---|
| 81 | static int fgOInit = 0; | 
|---|
| 82 | static int myNObj = 0; | 
|---|
| 83 | static int myDirId = 0; | 
|---|
| 84 | static string* currDir; | 
|---|
| 85 |  | 
|---|
| 86 | static PIStdImgApp* myImgApp=NULL; | 
|---|
| 87 | static Services2NObjMgr* servnobjm=NULL; | 
|---|
| 88 |  | 
|---|
| 89 | static DVList* myVars = NULL;  // Pour stocker les variables | 
|---|
| 90 |  | 
|---|
| 91 | static string* TmpDir = NULL;  // Repertoire pour les compilations / link dynamique | 
|---|
| 92 |  | 
|---|
| 93 | // Pour gestion multithread | 
|---|
| 94 | static ZMutex* myMutex = NULL; | 
|---|
| 95 | static bool myMtxLocked = false;   // if myMutex has been locked | 
|---|
| 96 | static bool obmWvis = false;  // true -> ObjMgrWindow() is active/visible | 
|---|
| 97 | static bool obmWUpdReq = false; // true -> ObjMgrWindow Update requested | 
|---|
| 98 | // .................................................................. | 
|---|
| 99 | // .... Classe NObjMgrSync .... | 
|---|
| 100 | class NObjMgrSync { | 
|---|
| 101 | public: | 
|---|
| 102 | explicit NObjMgrSync(int sigbr) | 
|---|
| 103 | { | 
|---|
| 104 | myMtxLocked = true; | 
|---|
| 105 | myMutex->lock(); | 
|---|
| 106 | _sigbr = sigbr; | 
|---|
| 107 | } | 
|---|
| 108 | ~NObjMgrSync() | 
|---|
| 109 | { | 
|---|
| 110 | if (_sigbr == 1) myMutex->signal(); | 
|---|
| 111 | else  if (_sigbr == 2) myMutex->broadcast(); | 
|---|
| 112 | myMutex->unlock(); | 
|---|
| 113 | myMtxLocked = false; | 
|---|
| 114 | if (obmWUpdReq) { | 
|---|
| 115 | NamedObjMgr _momg; | 
|---|
| 116 | _momg.UpdateObjMgrWindow(-1); | 
|---|
| 117 | obmWUpdReq = false; | 
|---|
| 118 | } | 
|---|
| 119 | } | 
|---|
| 120 | inline int NOp() { return _sigbr; } | 
|---|
| 121 |  | 
|---|
| 122 | int _sigbr; | 
|---|
| 123 | }; | 
|---|
| 124 | //............................. | 
|---|
| 125 |  | 
|---|
| 126 | //++ | 
|---|
| 127 | // Titre        Constructeurs | 
|---|
| 128 | //-- | 
|---|
| 129 | //++ | 
|---|
| 130 | // NamedObjMgr() | 
|---|
| 131 | //      Constructeur. Les différents instantiation de la classe "NamedObjMgr" | 
|---|
| 132 | //      dans une même application créent des objets qui travaillent sur la même | 
|---|
| 133 | //      liste d'objets. Les objets de cette classe ne possedent en effet pas | 
|---|
| 134 | //      de variables membres. | 
|---|
| 135 | //-- | 
|---|
| 136 |  | 
|---|
| 137 | /* --Methode-- */ | 
|---|
| 138 | NamedObjMgr::NamedObjMgr(bool fgimgapp) | 
|---|
| 139 | { | 
|---|
| 140 | _fgimgapp = fgimgapp; | 
|---|
| 141 | if (fgOInit == 0) { | 
|---|
| 142 | myNObj = 0; | 
|---|
| 143 | myDirId = 0; | 
|---|
| 144 | myDirs = new NObjDirList; | 
|---|
| 145 | myObjs = new NObjList; | 
|---|
| 146 | myVars = new DVList; | 
|---|
| 147 | myMutex = new ZMutex; | 
|---|
| 148 | currDir = new string("home"); | 
|---|
| 149 | string dirn = "home"; | 
|---|
| 150 | CreateDir_P(dirn); | 
|---|
| 151 | SetKeepOldDirAtt(dirn, false); | 
|---|
| 152 | dirn = "tmp"; | 
|---|
| 153 | CreateDir_P(dirn); | 
|---|
| 154 | SetKeepOldDirAtt(dirn, false); | 
|---|
| 155 | dirn = "autoc"; | 
|---|
| 156 | CreateDir_P(dirn); | 
|---|
| 157 | SetKeepOldDirAtt(dirn, false); | 
|---|
| 158 | dirn = "old"; | 
|---|
| 159 | CreateDir_P(dirn); | 
|---|
| 160 | SetKeepOldDirAtt(dirn, false); | 
|---|
| 161 | dirn = "home"; | 
|---|
| 162 | SetCurrentDir(dirn); | 
|---|
| 163 | myDirId = 50; | 
|---|
| 164 | char* varenv; | 
|---|
| 165 | TmpDir = new string(""); | 
|---|
| 166 | if ( (varenv=getenv("TMPDIR")) != NULL )  (*TmpDir) = varenv; | 
|---|
| 167 | int l = (*TmpDir).length(); | 
|---|
| 168 | if ( (l>0) && ((*TmpDir)[l-1] != '/') )  (*TmpDir) += '/'; | 
|---|
| 169 | servnobjm = new Services2NObjMgr(*TmpDir); | 
|---|
| 170 | } | 
|---|
| 171 | fgOInit++; | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 |  | 
|---|
| 175 | /* --Methode-- */ | 
|---|
| 176 | NamedObjMgr::~NamedObjMgr() | 
|---|
| 177 | { | 
|---|
| 178 | fgOInit--; | 
|---|
| 179 | if (fgOInit == 0)  { | 
|---|
| 180 | string patt = "/*/*"; | 
|---|
| 181 | DelObjects(patt, true); | 
|---|
| 182 | delete myObjs; | 
|---|
| 183 | delete myDirs; | 
|---|
| 184 | delete myVars; | 
|---|
| 185 | delete myMutex; | 
|---|
| 186 | } | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | //++ | 
|---|
| 190 | // Titre        Méthodes | 
|---|
| 191 | //-- | 
|---|
| 192 | //++ | 
|---|
| 193 | // void SetImgApp(PIStdImgApp* app) | 
|---|
| 194 | //      Spécifie l'objet "PIStdImgApp" associé. | 
|---|
| 195 | // PIStdImgApp* GetImgApp() | 
|---|
| 196 | //      Accès à l'objet "PIStdImgApp" associé. | 
|---|
| 197 | //-- | 
|---|
| 198 |  | 
|---|
| 199 | /* --Methode-- */ | 
|---|
| 200 | void NamedObjMgr::SetImgApp(PIStdImgApp* app) | 
|---|
| 201 | { | 
|---|
| 202 | myImgApp = app; | 
|---|
| 203 | servnobjm->SetImgApp(app); | 
|---|
| 204 |  | 
|---|
| 205 | NObjDirList::iterator it; | 
|---|
| 206 | string cn; | 
|---|
| 207 | for(it= myDirs->begin(); it != myDirs->end(); it++) { | 
|---|
| 208 | cn = '/' + (*it).first; | 
|---|
| 209 | (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id); | 
|---|
| 210 | } | 
|---|
| 211 | } | 
|---|
| 212 |  | 
|---|
| 213 |  | 
|---|
| 214 | static bool verbeux = false;  // true -> plus de message (creation/suppression d'objets) | 
|---|
| 215 | void NamedObjMgr::SetVerbose(bool fg) | 
|---|
| 216 | { | 
|---|
| 217 | verbeux = fg; | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | /* --Methode-- */ | 
|---|
| 221 | PIStdImgApp* NamedObjMgr::GetImgApp() | 
|---|
| 222 | { | 
|---|
| 223 | return(myImgApp); | 
|---|
| 224 | } | 
|---|
| 225 |  | 
|---|
| 226 | /* --Methode-- */ | 
|---|
| 227 | Services2NObjMgr* NamedObjMgr::GetServiceObj() | 
|---|
| 228 | { | 
|---|
| 229 | return(servnobjm); | 
|---|
| 230 | } | 
|---|
| 231 |  | 
|---|
| 232 | /* --Methode-- */ | 
|---|
| 233 | string const& NamedObjMgr::GetTmpDir() | 
|---|
| 234 | { | 
|---|
| 235 | return *TmpDir; | 
|---|
| 236 | } | 
|---|
| 237 |  | 
|---|
| 238 | /* --Methode-- */ | 
|---|
| 239 | void NamedObjMgr::SetTmpDir(string const& tmpdir) | 
|---|
| 240 | { | 
|---|
| 241 | if(tmpdir.length()<1) return; | 
|---|
| 242 | *TmpDir = tmpdir; | 
|---|
| 243 | int l = (*TmpDir).length(); | 
|---|
| 244 | if ( (l>0) && ((*TmpDir)[l-1] != '/') )  (*TmpDir) += '/'; | 
|---|
| 245 | servnobjm->SetTmpDir(*TmpDir); | 
|---|
| 246 | } | 
|---|
| 247 |  | 
|---|
| 248 | /* --Methode-- */ | 
|---|
| 249 | bool NamedObjMgr::SetVar(string const & key, string const & val) | 
|---|
| 250 | { | 
|---|
| 251 | if ((key.length() < 1) || (! isalpha(key[0])) )   { | 
|---|
| 252 | cout << "NamedObjMgr::SetVar( " << key << " ...) Bad VarName " << endl; | 
|---|
| 253 | return(false); | 
|---|
| 254 | } | 
|---|
| 255 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 256 | bool fg = myVars->HasKey(key); | 
|---|
| 257 | myVars->SetS(key, val); | 
|---|
| 258 | //  cout << " DEBUG::SetVar " << *myVars << endl; | 
|---|
| 259 | return(fg); | 
|---|
| 260 | } | 
|---|
| 261 |  | 
|---|
| 262 | /* --Methode-- */ | 
|---|
| 263 | bool NamedObjMgr::HasVar(string const & key) | 
|---|
| 264 | { | 
|---|
| 265 | if ((key.length() < 1) || (! isalpha(key[0])) )   { | 
|---|
| 266 | cout << "NamedObjMgr::HasVar( " << key << ") Bad VarName " << endl; | 
|---|
| 267 | return(false); | 
|---|
| 268 | } | 
|---|
| 269 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 270 | return(myVars->HasKey(key)); | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | /* --Methode-- */ | 
|---|
| 274 | bool NamedObjMgr::DeleteVar(string const & key) | 
|---|
| 275 | { | 
|---|
| 276 | if ((key.length() < 1) || (! isalpha(key[0])) )   { | 
|---|
| 277 | cout << "NamedObjMgr::DeleteVar( " << key << ") Bad VarName " << endl; | 
|---|
| 278 | return(false); | 
|---|
| 279 | } | 
|---|
| 280 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 281 | return(myVars->DeleteKey(key)); | 
|---|
| 282 | } | 
|---|
| 283 |  | 
|---|
| 284 | /* --Methode-- */ | 
|---|
| 285 | string NamedObjMgr::GetVar(string const & key) | 
|---|
| 286 | { | 
|---|
| 287 | if ((key.length() < 1) || (! isalpha(key[0])) )   { | 
|---|
| 288 | cout << "NamedObjMgr::GetVar( " << key << ") Bad VarName " << endl; | 
|---|
| 289 | return(""); | 
|---|
| 290 | } | 
|---|
| 291 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 292 | //  cout << " DEBUG::GetVar " << *myVars << endl; | 
|---|
| 293 | return(myVars->GetS(key)); | 
|---|
| 294 | } | 
|---|
| 295 |  | 
|---|
| 296 | /* --Methode-- */ | 
|---|
| 297 | DVList& NamedObjMgr::GetVarList() | 
|---|
| 298 | { | 
|---|
| 299 | //  cout << " DEBUG::GetVarList " << *myVars << endl; | 
|---|
| 300 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 301 | return(*myVars); | 
|---|
| 302 | } | 
|---|
| 303 |  | 
|---|
| 304 | /* --Methode-- */ | 
|---|
| 305 | bool NamedObjMgr::CreateDir(string & dirname) | 
|---|
| 306 | { | 
|---|
| 307 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 308 | return CreateDir_P(dirname); | 
|---|
| 309 | } | 
|---|
| 310 |  | 
|---|
| 311 | /* --Methode-- */ | 
|---|
| 312 | bool NamedObjMgr::CreateDir_P(string & dirname) | 
|---|
| 313 | { | 
|---|
| 314 | if ( !CheckDirName(dirname) ) { | 
|---|
| 315 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl; | 
|---|
| 316 | return(false); | 
|---|
| 317 | } | 
|---|
| 318 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
| 319 | if (it != myDirs->end()) { | 
|---|
| 320 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl; | 
|---|
| 321 | return(false); | 
|---|
| 322 | } | 
|---|
| 323 | myDirId++; | 
|---|
| 324 | nobj_diritem di; | 
|---|
| 325 | di.id = myDirId; | 
|---|
| 326 | di.nobj = 0; | 
|---|
| 327 | di.lock = false; | 
|---|
| 328 | di.keepold = false; | 
|---|
| 329 | (*myDirs)[dirname] = di; | 
|---|
| 330 | if (myImgApp)  { | 
|---|
| 331 | string str = '/' + dirname; | 
|---|
| 332 | if ( !_fgimgapp )  myImgApp->LockMutex(); | 
|---|
| 333 | (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId); | 
|---|
| 334 | if ( !_fgimgapp )  myImgApp->UnlockMutex(true); | 
|---|
| 335 | } | 
|---|
| 336 | if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl; | 
|---|
| 337 | return(true); | 
|---|
| 338 | } | 
|---|
| 339 |  | 
|---|
| 340 | /* --Methode-- */ | 
|---|
| 341 | bool NamedObjMgr::DeleteDir(string & dirname) | 
|---|
| 342 | { | 
|---|
| 343 | if ( !CheckDirName(dirname) ) { | 
|---|
| 344 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl; | 
|---|
| 345 | return(false); | 
|---|
| 346 | } | 
|---|
| 347 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 348 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
| 349 | if (it == myDirs->end()) { | 
|---|
| 350 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl; | 
|---|
| 351 | return(false); | 
|---|
| 352 | } | 
|---|
| 353 | if ((*it).second.nobj > 0) { | 
|---|
| 354 | cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl; | 
|---|
| 355 | return(false); | 
|---|
| 356 | } | 
|---|
| 357 | if ((*it).second.lock ) { | 
|---|
| 358 | cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl; | 
|---|
| 359 | return(false); | 
|---|
| 360 | } | 
|---|
| 361 | if ((*it).second.id < 50) { | 
|---|
| 362 | cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl; | 
|---|
| 363 | return(false); | 
|---|
| 364 | } | 
|---|
| 365 |  | 
|---|
| 366 | if (myImgApp) { | 
|---|
| 367 | if ( !_fgimgapp )  myImgApp->LockMutex(); | 
|---|
| 368 | if ((myImgApp->ObjMgrW())->GetCurDirId() == (*it).second.id) { | 
|---|
| 369 | (myImgApp->ObjMgrW())->SetCurDir(*currDir); | 
|---|
| 370 | obmWUpdReq = true; | 
|---|
| 371 | } | 
|---|
| 372 | (myImgApp->ObjMgrW())->DelDirectory((*it).second.id); | 
|---|
| 373 |  | 
|---|
| 374 | if ( !_fgimgapp )  myImgApp->UnlockMutex(true); | 
|---|
| 375 | } | 
|---|
| 376 | myDirs->erase(it); | 
|---|
| 377 | if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl; | 
|---|
| 378 | return(true); | 
|---|
| 379 | } | 
|---|
| 380 |  | 
|---|
| 381 | /* --Methode-- */ | 
|---|
| 382 | void NamedObjMgr::LockDir(string & dirname) | 
|---|
| 383 | { | 
|---|
| 384 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 385 | if ( !CheckDirName(dirname) ) return; | 
|---|
| 386 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
| 387 | if (it == myDirs->end()) return; | 
|---|
| 388 | (*it).second.lock = true; | 
|---|
| 389 | if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl; | 
|---|
| 390 | return; | 
|---|
| 391 | } | 
|---|
| 392 |  | 
|---|
| 393 | /* --Methode-- */ | 
|---|
| 394 | void NamedObjMgr::UnlockDir(string & dirname) | 
|---|
| 395 | { | 
|---|
| 396 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 397 | if ( !CheckDirName(dirname) ) return; | 
|---|
| 398 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
| 399 | if (it == myDirs->end()) return; | 
|---|
| 400 | (*it).second.lock = true; | 
|---|
| 401 | if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl; | 
|---|
| 402 | return; | 
|---|
| 403 | } | 
|---|
| 404 |  | 
|---|
| 405 | /* --Methode-- */ | 
|---|
| 406 | void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold) | 
|---|
| 407 | { | 
|---|
| 408 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 409 | if ( !CheckDirName(dirname) ) return; | 
|---|
| 410 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
| 411 | if (it == myDirs->end()) return; | 
|---|
| 412 | (*it).second.keepold = keepold; | 
|---|
| 413 | if (!verbeux) return; | 
|---|
| 414 | cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << "  ->  "; | 
|---|
| 415 | if ( keepold ) cout << " True " << endl; | 
|---|
| 416 | else cout << " False " << endl; | 
|---|
| 417 | return; | 
|---|
| 418 | } | 
|---|
| 419 |  | 
|---|
| 420 |  | 
|---|
| 421 | /* --Methode-- */ | 
|---|
| 422 | bool NamedObjMgr::SetCurrentDir(string & dirname) | 
|---|
| 423 | { | 
|---|
| 424 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 425 | if ( !CheckDirName(dirname) ) { | 
|---|
| 426 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl; | 
|---|
| 427 | return(false); | 
|---|
| 428 | } | 
|---|
| 429 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
| 430 | if (it == myDirs->end()) { | 
|---|
| 431 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl; | 
|---|
| 432 | return(false); | 
|---|
| 433 | } | 
|---|
| 434 | *currDir = dirname; | 
|---|
| 435 | if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl; | 
|---|
| 436 | return(true); | 
|---|
| 437 | } | 
|---|
| 438 |  | 
|---|
| 439 | /* --Methode-- */ | 
|---|
| 440 | void NamedObjMgr::GetCurrentDir(string & dirname) | 
|---|
| 441 | { | 
|---|
| 442 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 443 | dirname = *currDir; | 
|---|
| 444 | } | 
|---|
| 445 |  | 
|---|
| 446 | /* --Methode-- */ | 
|---|
| 447 | void NamedObjMgr::ListDirs(string & patt) | 
|---|
| 448 | { | 
|---|
| 449 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 450 | NObjDirList::iterator it; | 
|---|
| 451 | string cn; | 
|---|
| 452 | cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl; | 
|---|
| 453 | int k = 0; | 
|---|
| 454 | for(it= myDirs->begin(); it != myDirs->end(); it++) { | 
|---|
| 455 | cn = (*it).first; | 
|---|
| 456 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; | 
|---|
| 457 | k++; | 
|---|
| 458 | cout << k << "- " << (*it).first; | 
|---|
| 459 | if ( (*it).second.lock )  cout << "  Locked " ; | 
|---|
| 460 | if ( (*it).second.keepold )   cout << "  KeepOld " ; | 
|---|
| 461 | cout << "  (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl; | 
|---|
| 462 |  | 
|---|
| 463 | } | 
|---|
| 464 | } | 
|---|
| 465 |  | 
|---|
| 466 | /* --Methode-- */ | 
|---|
| 467 | void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd) | 
|---|
| 468 | { | 
|---|
| 469 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 470 | NObjDirList::iterator it; | 
|---|
| 471 | string cn; | 
|---|
| 472 | for(it= myDirs->begin(); it != myDirs->end(); it++) { | 
|---|
| 473 | cn = (*it).first; | 
|---|
| 474 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; | 
|---|
| 475 | lstd.push_back(cn); | 
|---|
| 476 | } | 
|---|
| 477 | } | 
|---|
| 478 |  | 
|---|
| 479 | /* --Methode-- */ | 
|---|
| 480 | void NamedObjMgr::CleanDir(string & dirname) | 
|---|
| 481 | { | 
|---|
| 482 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 483 | CleanDir_P(dirname); | 
|---|
| 484 | } | 
|---|
| 485 |  | 
|---|
| 486 | /* --Methode-- */ | 
|---|
| 487 | void NamedObjMgr::CleanDir_P(string & dirname) | 
|---|
| 488 | { | 
|---|
| 489 | if ( !CheckDirName(dirname) ) { | 
|---|
| 490 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl; | 
|---|
| 491 | // return(false);  $CHECK$ illegal return value in void function | 
|---|
| 492 | } | 
|---|
| 493 | NObjDirList::iterator itr = myDirs->find(dirname); | 
|---|
| 494 | if (itr == myDirs->end()) { | 
|---|
| 495 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - No such directory !" << endl; | 
|---|
| 496 | // return(false);  $CHECK$ illegal return value in void function | 
|---|
| 497 | } | 
|---|
| 498 |  | 
|---|
| 499 | int did = (*itr).second.id; | 
|---|
| 500 | NObjList::iterator it; | 
|---|
| 501 | list<int>::iterator iwr; | 
|---|
| 502 | bool nodisp = true; | 
|---|
| 503 | list<string> odel; | 
|---|
| 504 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| 505 | if ((*it).second.dirid != did) continue; | 
|---|
| 506 | nodisp = true; | 
|---|
| 507 | if (myImgApp) | 
|---|
| 508 | for(iwr=(*it).second.wrsid.begin(); iwr != (*it).second.wrsid.end(); iwr++) | 
|---|
| 509 | if (myImgApp->CheckWRsId(*iwr)) { nodisp = false; break; } | 
|---|
| 510 | if (nodisp) odel.push_back((*it).first); | 
|---|
| 511 | } | 
|---|
| 512 | list<string>::iterator ii; | 
|---|
| 513 | for(ii=odel.begin(); ii != odel.end(); ii++)  DelObj_P(*ii,true); | 
|---|
| 514 |  | 
|---|
| 515 | if (obmWvis) UpdateObjMgrWindow_P(did);  // On met a jour la fenetre de gestion des objets | 
|---|
| 516 | } | 
|---|
| 517 |  | 
|---|
| 518 |  | 
|---|
| 519 |  | 
|---|
| 520 | //++ | 
|---|
| 521 | // Titre        Gestion de la liste des objets | 
|---|
| 522 | //-- | 
|---|
| 523 | //++ | 
|---|
| 524 | // void AddObj(AnyDataObj* obj, string& nom) | 
|---|
| 525 | //      Ajoute l'objet "obj" à la liste, identifié par "nom". | 
|---|
| 526 | //      Si un objet de même nom existe, l'ancien objet est renommé en concaténant | 
|---|
| 527 | //      un numéro à son nom. | 
|---|
| 528 | // void DelObj(string const& nom, bool fgd=true) | 
|---|
| 529 | //      Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true"  ("delete obj") | 
|---|
| 530 | // void DelObjects(string const& patt, bool fgd=true) | 
|---|
| 531 | //      Supprime l'ensemble des objets dont le nom correspond au patron "patt". | 
|---|
| 532 | //      Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true" | 
|---|
| 533 | // AnyDataObj*  GetObj(string const& nom) | 
|---|
| 534 | //      Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est | 
|---|
| 535 | //      pas dans la liste. | 
|---|
| 536 | // void  RenameObj(string const& nom, string& nomnew) | 
|---|
| 537 | //      Change le nom d'un objet dans la liste. | 
|---|
| 538 | // void  CopyObj(string const& nom, string& nomcp) | 
|---|
| 539 | //      Copy l'objet "nom" de la liste dans l'objet "nomcp" de la liste. | 
|---|
| 540 | //-- | 
|---|
| 541 |  | 
|---|
| 542 | /* --Methode-- */ | 
|---|
| 543 | bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd) | 
|---|
| 544 | { | 
|---|
| 545 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 546 | return AddObj_P(obj, nom, crd); | 
|---|
| 547 | } | 
|---|
| 548 |  | 
|---|
| 549 | /* --Methode-- */ | 
|---|
| 550 | bool NamedObjMgr::AddObj_P(AnyDataObj* obj, string & nom, bool crd) | 
|---|
| 551 | { | 
|---|
| 552 |  | 
|---|
| 553 | if (obj == NULL)  return(false); | 
|---|
| 554 | // On verifie si l'objet est deja dans la liste | 
|---|
| 555 | NObjList::iterator it; | 
|---|
| 556 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| 557 | if ((*it).second.obj == obj) { | 
|---|
| 558 | cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl; | 
|---|
| 559 | return(false); | 
|---|
| 560 | } | 
|---|
| 561 | } | 
|---|
| 562 | string nobj; | 
|---|
| 563 | string nrep; | 
|---|
| 564 | char buff[32]; | 
|---|
| 565 | int did = ParseObjectName(nom, nrep, nobj); | 
|---|
| 566 | if (did == 0) { | 
|---|
| 567 | if (!crd) { | 
|---|
| 568 | cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl; | 
|---|
| 569 | return(false); | 
|---|
| 570 | } | 
|---|
| 571 | else { CreateDir_P(nrep);  did =  myDirId; } | 
|---|
| 572 | } | 
|---|
| 573 |  | 
|---|
| 574 | // Si c'est le repertoire /autoc, on nettoie | 
|---|
| 575 | if (nrep == "autoc")  { | 
|---|
| 576 | CleanDir_P(nrep); | 
|---|
| 577 | } | 
|---|
| 578 |  | 
|---|
| 579 | myNObj++; | 
|---|
| 580 | if ( !CheckName(nobj) ) { | 
|---|
| 581 | sprintf(buff,"O%d", myNObj); | 
|---|
| 582 | cout << "NamedObjMgr::AddObj() Name changed: " << nom << " -> " << buff << endl; | 
|---|
| 583 | nobj = buff; | 
|---|
| 584 | } | 
|---|
| 585 |  | 
|---|
| 586 | nom = '/' + nrep + '/' + nobj; | 
|---|
| 587 | NObjDirList::iterator itr = myDirs->find(nrep); | 
|---|
| 588 | if ((*itr).second.lock) { | 
|---|
| 589 | cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl; | 
|---|
| 590 | return(false); | 
|---|
| 591 | } | 
|---|
| 592 | it = myObjs->find(nom); | 
|---|
| 593 | if (it != myObjs->end()) { // l'objet existe deja | 
|---|
| 594 | if (nrep == "autoc") {  // Dans /autoc , on garde les objets affiches, donc del. par Clean | 
|---|
| 595 | sprintf(buff, "%d", (*it).second.oid); | 
|---|
| 596 | string nomnew = "/autoc/" + nobj + buff; | 
|---|
| 597 | RenameObj_P(nom, nomnew); | 
|---|
| 598 | } | 
|---|
| 599 | else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old | 
|---|
| 600 | string on,od; | 
|---|
| 601 | //    ParseObjectName((*it).first, od, on); | 
|---|
| 602 | sprintf(buff, "%d", (*it).second.oid); | 
|---|
| 603 | string nomnew = "/old/" + nobj + buff; | 
|---|
| 604 | RenameObj_P(nom, nomnew); | 
|---|
| 605 | } | 
|---|
| 606 | else {  // Sinon, on remplace l'objet | 
|---|
| 607 | cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl; | 
|---|
| 608 | DelObj_P(nom); | 
|---|
| 609 | } | 
|---|
| 610 | } | 
|---|
| 611 |  | 
|---|
| 612 | nobj_item no; | 
|---|
| 613 | no.obj = obj; | 
|---|
| 614 | no.obja = servnobjm->GetAdapter(obj);  // L'adaptateur | 
|---|
| 615 | no.oid =  myNObj; | 
|---|
| 616 | no.dirid = did; | 
|---|
| 617 | (*myObjs)[nom] = no; | 
|---|
| 618 |  | 
|---|
| 619 | (*itr).second.nobj++; | 
|---|
| 620 |  | 
|---|
| 621 | if (obmWvis && (myImgApp != NULL)) { | 
|---|
| 622 | if ( !_fgimgapp )  myImgApp->LockMutex(); | 
|---|
| 623 | if ( (myImgApp->ObjMgrW())->Visible() ) { | 
|---|
| 624 | string oln = nobj + "  (T= " + no.obja->GetDataObjType() + ")" ; | 
|---|
| 625 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid); | 
|---|
| 626 | } | 
|---|
| 627 | if ( !_fgimgapp )  myImgApp->UnlockMutex(true); | 
|---|
| 628 | } | 
|---|
| 629 | if (verbeux) cout << "NamedObjMgr::AddObj()  Object " << nom << " ( " | 
|---|
| 630 | << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl; | 
|---|
| 631 | return(true); | 
|---|
| 632 | } | 
|---|
| 633 |  | 
|---|
| 634 | bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd) | 
|---|
| 635 | { | 
|---|
| 636 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 637 | NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj); | 
|---|
| 638 | if (adap == NULL) { | 
|---|
| 639 | cout << "NamedObjMgr::AddObj() No Adapter !   " << nom << endl; | 
|---|
| 640 | return(false); | 
|---|
| 641 | } | 
|---|
| 642 | AnyDataObj * cloneobj = adap->CloneDataObj(true); | 
|---|
| 643 | delete adap; | 
|---|
| 644 | if (cloneobj == NULL) { | 
|---|
| 645 | cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl; | 
|---|
| 646 | return(false); | 
|---|
| 647 | } | 
|---|
| 648 | return ( AddObj_P(cloneobj , nom, crd) ); | 
|---|
| 649 | } | 
|---|
| 650 |  | 
|---|
| 651 | /* --Methode-- */ | 
|---|
| 652 | bool NamedObjMgr::RenameObj(string & nom, string& nomnew) | 
|---|
| 653 | { | 
|---|
| 654 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 655 | return RenameObj_P(nom, nomnew); | 
|---|
| 656 | } | 
|---|
| 657 |  | 
|---|
| 658 | /* --Methode-- */ | 
|---|
| 659 | bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew) | 
|---|
| 660 | { | 
|---|
| 661 | string n1,r1,n2,r2; | 
|---|
| 662 | int dids = ParseObjectName(nom, r1, n1); | 
|---|
| 663 | NObjDirList::iterator itr1 = myDirs->find(r1); | 
|---|
| 664 | int did = ParseObjectName(nomnew, r2, n2); | 
|---|
| 665 | NObjDirList::iterator itr2 = myDirs->find(r2); | 
|---|
| 666 |  | 
|---|
| 667 | if (did == 0) { | 
|---|
| 668 | cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl; | 
|---|
| 669 | return(false); | 
|---|
| 670 | } | 
|---|
| 671 | nom = '/' + r1 + '/' + n1; | 
|---|
| 672 | nomnew = '/' + r2 + '/' + n2; | 
|---|
| 673 | NObjList::iterator it1 = myObjs->find(nom); | 
|---|
| 674 | if (it1 == myObjs->end()) { | 
|---|
| 675 | cout << "NamedObjMgr::RenameObj() Error -  No " << nom << " object !" << endl; | 
|---|
| 676 | return(false); | 
|---|
| 677 | } | 
|---|
| 678 |  | 
|---|
| 679 | if ( !CheckName(n2) ) { | 
|---|
| 680 | cout << "NamedObjMgr::RenameObj() Error -  bad new object name" << n2 << endl; | 
|---|
| 681 | return(false); | 
|---|
| 682 | } | 
|---|
| 683 | NObjList::iterator it2 = myObjs->find(nomnew); | 
|---|
| 684 | if (it2 != myObjs->end()) { | 
|---|
| 685 | cout << "NamedObjMgr::RenameObj() Error -  Object " << nomnew << " exist !" << endl; | 
|---|
| 686 | return(false); | 
|---|
| 687 | } | 
|---|
| 688 |  | 
|---|
| 689 | if ( (*itr1).second.lock || (*itr2).second.lock ) { | 
|---|
| 690 | cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !" | 
|---|
| 691 | << endl; | 
|---|
| 692 | return(false); | 
|---|
| 693 | } | 
|---|
| 694 |  | 
|---|
| 695 |  | 
|---|
| 696 | nobj_item no = (*it1).second; | 
|---|
| 697 | no.dirid = did; | 
|---|
| 698 | myObjs->erase(it1); | 
|---|
| 699 | NObjDirList::iterator itr = myDirs->find(r1); | 
|---|
| 700 | (*itr).second.nobj--; | 
|---|
| 701 | (*myObjs)[nomnew] = no; | 
|---|
| 702 | itr = myDirs->find(r2); | 
|---|
| 703 | (*itr).second.nobj++; | 
|---|
| 704 |  | 
|---|
| 705 | if (obmWvis && (myImgApp != NULL)) { | 
|---|
| 706 | if ( !_fgimgapp )  myImgApp->LockMutex(); | 
|---|
| 707 | if ( (myImgApp->ObjMgrW())->Visible() ) { | 
|---|
| 708 | (myImgApp->ObjMgrW())->DelObjList(dids, no.oid); | 
|---|
| 709 | string oln = n2 + "  (T= " + no.obja->GetDataObjType() + ")" ; | 
|---|
| 710 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid); | 
|---|
| 711 | } | 
|---|
| 712 | if ( !_fgimgapp )  myImgApp->UnlockMutex(true); | 
|---|
| 713 | } | 
|---|
| 714 | if (verbeux) | 
|---|
| 715 | cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl; | 
|---|
| 716 | return(true); | 
|---|
| 717 | } | 
|---|
| 718 |  | 
|---|
| 719 | /* --Methode-- */ | 
|---|
| 720 | bool NamedObjMgr::CopyObj(string & nom, string& nomcp) | 
|---|
| 721 | { | 
|---|
| 722 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 723 | if(nomcp.length()<=0) | 
|---|
| 724 | {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl; | 
|---|
| 725 | return(false);} | 
|---|
| 726 | NObjMgrAdapter* obnom = GetObjAdapter_P(nom); | 
|---|
| 727 | if(obnom==NULL) | 
|---|
| 728 | {cout<<"NamedObjMgr::CopyObj() Error -  No "<<nom<<" object !"<<endl; | 
|---|
| 729 | return(false);} | 
|---|
| 730 | AnyDataObj* obnomcp = obnom->CloneDataObj(); | 
|---|
| 731 | if(obnomcp==NULL) return(false); | 
|---|
| 732 | if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);} | 
|---|
| 733 | return true; | 
|---|
| 734 | } | 
|---|
| 735 |  | 
|---|
| 736 | /* --Methode-- */ | 
|---|
| 737 | bool NamedObjMgr::DelObj(string & nom, bool fgd) | 
|---|
| 738 | { | 
|---|
| 739 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 740 | return DelObj_P(nom, fgd); | 
|---|
| 741 | } | 
|---|
| 742 |  | 
|---|
| 743 | /* --Methode-- */ | 
|---|
| 744 | bool NamedObjMgr::DelObj_P(string & nom, bool fgd) | 
|---|
| 745 | { | 
|---|
| 746 | string n1,r1; | 
|---|
| 747 | int did = ParseObjectName(nom, r1, n1); | 
|---|
| 748 | nom = '/' + r1 + '/' + n1; | 
|---|
| 749 | NObjList::iterator it = myObjs->find(nom); | 
|---|
| 750 | if (it == myObjs->end()) return(false); | 
|---|
| 751 | NObjDirList::iterator itr = myDirs->find(r1); | 
|---|
| 752 | if ( (*itr).second.lock  ) { | 
|---|
| 753 | cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl; | 
|---|
| 754 | return(false); | 
|---|
| 755 | } | 
|---|
| 756 | list<int>::iterator ii; | 
|---|
| 757 | if (myImgApp) { | 
|---|
| 758 | //DBG  cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl; | 
|---|
| 759 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts | 
|---|
| 760 | bool fglock = (_fgimgapp) ? false : true; | 
|---|
| 761 | if (fglock) myImgApp->LockMutex(); | 
|---|
| 762 | for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++) | 
|---|
| 763 | myImgApp->DelWRsId((*ii)); | 
|---|
| 764 | if (fglock) myImgApp->UnlockMutex(true); | 
|---|
| 765 | } | 
|---|
| 766 | delete (*it).second.obja;  // destruction de l'adaptateur | 
|---|
| 767 | if (fgd) delete (*it).second.obj; | 
|---|
| 768 |  | 
|---|
| 769 | if (obmWvis && (myImgApp != NULL)) { | 
|---|
| 770 | if ( !_fgimgapp )  myImgApp->LockMutex(); | 
|---|
| 771 | if ( (myImgApp->ObjMgrW())->Visible() ) { | 
|---|
| 772 | int olid = (*it).second.oid; | 
|---|
| 773 | (myImgApp->ObjMgrW())->DelObjList(did, olid); | 
|---|
| 774 | } | 
|---|
| 775 | if ( !_fgimgapp )  myImgApp->UnlockMutex(true); | 
|---|
| 776 | } | 
|---|
| 777 | myObjs->erase(it); | 
|---|
| 778 | (*itr).second.nobj--; | 
|---|
| 779 |  | 
|---|
| 780 |  | 
|---|
| 781 | if (!verbeux) return(true); | 
|---|
| 782 | if (fgd) cout << "NamedObjMgr::DelObj()  Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl; | 
|---|
| 783 | else  cout << "NamedObjMgr::DelObj()  Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl; | 
|---|
| 784 | return(true); | 
|---|
| 785 | } | 
|---|
| 786 |  | 
|---|
| 787 | /* --Methode-- */ | 
|---|
| 788 | bool NamedObjMgr::DelObj_Id(int oid) | 
|---|
| 789 | { | 
|---|
| 790 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 791 | NObjList::iterator it; | 
|---|
| 792 | string nom; | 
|---|
| 793 | bool of = false; | 
|---|
| 794 | for(it = myObjs->begin(); it != myObjs->end(); it++) | 
|---|
| 795 | if ( (*it).second.oid == oid ) { | 
|---|
| 796 | of = true;  nom = (*it).first; | 
|---|
| 797 | break; | 
|---|
| 798 | } | 
|---|
| 799 | if (of) return(DelObj_P(nom, true)); | 
|---|
| 800 | else return(false); | 
|---|
| 801 | } | 
|---|
| 802 |  | 
|---|
| 803 | /* --Methode-- */ | 
|---|
| 804 | void NamedObjMgr::DelObjects(string & patt, bool fgd) | 
|---|
| 805 | { | 
|---|
| 806 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 807 | string n1,r1; | 
|---|
| 808 | ParseObjectName(patt, r1, n1); | 
|---|
| 809 | patt = '/' + r1 + '/' + n1; | 
|---|
| 810 | NObjList::iterator it; | 
|---|
| 811 | list<string> odel; | 
|---|
| 812 | string cn; | 
|---|
| 813 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| 814 | cn = (*it).first; | 
|---|
| 815 | if (csh_parse(cn.c_str(), patt.c_str()) != 0)  odel.push_back(cn); | 
|---|
| 816 | } | 
|---|
| 817 | list<string>::iterator ii; | 
|---|
| 818 | for(ii=odel.begin(); ii != odel.end(); ii++)  DelObj_P(*ii, fgd); | 
|---|
| 819 | } | 
|---|
| 820 |  | 
|---|
| 821 | /* --Methode-- */ | 
|---|
| 822 | AnyDataObj* NamedObjMgr::GetObj(string & nom) | 
|---|
| 823 | { | 
|---|
| 824 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 825 | return GetObj_P(nom); | 
|---|
| 826 | } | 
|---|
| 827 |  | 
|---|
| 828 | /* --Methode-- */ | 
|---|
| 829 | AnyDataObj* NamedObjMgr::GetObj_P(string & nom) | 
|---|
| 830 | { | 
|---|
| 831 | string n1,r1; | 
|---|
| 832 | ParseObjectName(nom, r1, n1); | 
|---|
| 833 | nom = '/' + r1 + '/' + n1; | 
|---|
| 834 | NObjList::iterator it = myObjs->find(nom); | 
|---|
| 835 | if (it == myObjs->end()) return(NULL); | 
|---|
| 836 | return((*it).second.obj); | 
|---|
| 837 | } | 
|---|
| 838 |  | 
|---|
| 839 | /* --Methode-- */ | 
|---|
| 840 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom) | 
|---|
| 841 | { | 
|---|
| 842 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 843 | return GetObjAdapter_P(nom); | 
|---|
| 844 | } | 
|---|
| 845 |  | 
|---|
| 846 | /* --Methode-- */ | 
|---|
| 847 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter_P(string & nom) | 
|---|
| 848 | { | 
|---|
| 849 | string n1,r1; | 
|---|
| 850 | ParseObjectName(nom, r1, n1); | 
|---|
| 851 | nom = '/' + r1 + '/' + n1; | 
|---|
| 852 | NObjList::iterator it = myObjs->find(nom); | 
|---|
| 853 | if (it == myObjs->end()) return(NULL); | 
|---|
| 854 | return((*it).second.obja); | 
|---|
| 855 | } | 
|---|
| 856 |  | 
|---|
| 857 | /* --Methode-- */ | 
|---|
| 858 | void NamedObjMgr::ListObjs(string & patt) | 
|---|
| 859 | { | 
|---|
| 860 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 861 | int k; | 
|---|
| 862 | AnyDataObj* obj=NULL; | 
|---|
| 863 | string ctyp; | 
|---|
| 864 | char strg[256]; | 
|---|
| 865 |  | 
|---|
| 866 | string n1,r1; | 
|---|
| 867 | ParseObjectName(patt, r1, n1); | 
|---|
| 868 | patt = '/' + r1 + '/' + n1; | 
|---|
| 869 | cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ; | 
|---|
| 870 | NObjList::iterator it;  k = 0; | 
|---|
| 871 | string cn; | 
|---|
| 872 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| 873 | cn = (*it).first; | 
|---|
| 874 | if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue; | 
|---|
| 875 | obj = (*it).second.obj; | 
|---|
| 876 | ctyp = typeid(*obj).name(); | 
|---|
| 877 | sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str()); | 
|---|
| 878 | ctyp = strg; | 
|---|
| 879 | cout << ctyp << "\n" ; | 
|---|
| 880 | k++; | 
|---|
| 881 | } | 
|---|
| 882 | cout << endl; | 
|---|
| 883 | return; | 
|---|
| 884 | } | 
|---|
| 885 |  | 
|---|
| 886 | /* --Methode-- */ | 
|---|
| 887 | void NamedObjMgr::GetObjList(string & patt, vector<string> &lst) | 
|---|
| 888 | { | 
|---|
| 889 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 890 | string n1,r1; | 
|---|
| 891 | if (patt.length() < 1)  return; | 
|---|
| 892 | bool fgr = (patt[0] == '/') ? true : false; | 
|---|
| 893 | ParseObjectName(patt, r1, n1); | 
|---|
| 894 | patt = '/' + r1 + '/' + n1; | 
|---|
| 895 | NObjList::iterator it; | 
|---|
| 896 | string cn; | 
|---|
| 897 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| 898 | cn = (*it).first; | 
|---|
| 899 | if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue; | 
|---|
| 900 | if (fgr) lst.push_back(cn); | 
|---|
| 901 | else { | 
|---|
| 902 | ParseObjectName(cn, r1, n1); | 
|---|
| 903 | lst.push_back(n1); | 
|---|
| 904 | } | 
|---|
| 905 | } | 
|---|
| 906 | } | 
|---|
| 907 |  | 
|---|
| 908 | //++ | 
|---|
| 909 | // Titre        Entrées-Sorties (I/O) sur les objets | 
|---|
| 910 | //-- | 
|---|
| 911 | //++ | 
|---|
| 912 | // void  ReadObj(PInPersist& s, int num=-1) | 
|---|
| 913 | //      Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s" | 
|---|
| 914 | //      et l'ajoute à la liste. Si "num" est négatif, tous les objets présents | 
|---|
| 915 | //      sur le flot "s" sont créés et ajoutés à la liste. | 
|---|
| 916 | // void  ReadObj(string const & nomppf, string nobj="") | 
|---|
| 917 | //      Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté | 
|---|
| 918 | //      à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est | 
|---|
| 919 | //      composé à partir du nom de fichier. | 
|---|
| 920 | //-- | 
|---|
| 921 |  | 
|---|
| 922 | /* --Methode-- */ | 
|---|
| 923 | void NamedObjMgr::ReadObj(string const & flnm, string & nobj) | 
|---|
| 924 | { | 
|---|
| 925 | PPersist* ppobj=NULL; | 
|---|
| 926 | bool ok = true; | 
|---|
| 927 | try { | 
|---|
| 928 | PInPersist pis(flnm); | 
|---|
| 929 | ppobj = pis.ReadObject(); | 
|---|
| 930 | } | 
|---|
| 931 | catch (IOExc iox) { | 
|---|
| 932 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
| 933 | ok = false; | 
|---|
| 934 | } | 
|---|
| 935 | if (!ok)  return; | 
|---|
| 936 | if (nobj.length()<1)  nobj = servnobjm->FileName2Name(flnm); | 
|---|
| 937 | AddObj(ppobj->DataObj(), nobj, true); | 
|---|
| 938 | cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl; | 
|---|
| 939 | return; | 
|---|
| 940 | } | 
|---|
| 941 | /* --Methode-- */ | 
|---|
| 942 | void NamedObjMgr::ReadObj(vector<string> & flnm_objname) | 
|---|
| 943 | // flnm_objname[0] = nom du fichier .ppf | 
|---|
| 944 | // flnm_objname[1...] = nom des tags des objects a lire | 
|---|
| 945 | { | 
|---|
| 946 | if(flnm_objname.size()<2) return; | 
|---|
| 947 | int nread=0; | 
|---|
| 948 | try { | 
|---|
| 949 | PInPersist pis(flnm_objname[0]); | 
|---|
| 950 | for(int i=1;i<flnm_objname.size();i++) { | 
|---|
| 951 | bool ok = pis.GotoNameTag(flnm_objname[i]); | 
|---|
| 952 | if(!ok) { | 
|---|
| 953 | cout<<"NamedObjMgr::ReadObj(...) Unknown object: "<<flnm_objname[i]<<endl; | 
|---|
| 954 | continue; | 
|---|
| 955 | } | 
|---|
| 956 | PPersist *ppobj = pis.ReadObject();; | 
|---|
| 957 | if(ppobj==NULL) { | 
|---|
| 958 | cout<<"NamedObjMgr::ReadObj(...) impossible to read "<<flnm_objname[i]<<endl; | 
|---|
| 959 | continue; | 
|---|
| 960 | } | 
|---|
| 961 | AddObj(ppobj->DataObj(),flnm_objname[i],true); | 
|---|
| 962 | nread++; | 
|---|
| 963 | cout<<"NamedObjMgr::ReadObj(...) object "<<flnm_objname[i]<<" read from file "<<endl; | 
|---|
| 964 | } | 
|---|
| 965 | } catch (IOExc iox) { | 
|---|
| 966 | cerr<<"NamedObjMgr::ReadObj()/Error Exception - Msg= "<<iox.Msg()<<endl; | 
|---|
| 967 | } | 
|---|
| 968 | cout<<nread<<" objects have been read"<<endl; | 
|---|
| 969 | return; | 
|---|
| 970 | } | 
|---|
| 971 |  | 
|---|
| 972 | /* --Methode-- */ | 
|---|
| 973 | void NamedObjMgr::ReadObj(PInPersist& s, int num) | 
|---|
| 974 | { | 
|---|
| 975 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 976 | ReadObj_P(s, num); | 
|---|
| 977 | } | 
|---|
| 978 |  | 
|---|
| 979 | /* --Methode-- */ | 
|---|
| 980 | void NamedObjMgr::ReadObj_P(PInPersist& s, int num) | 
|---|
| 981 | { | 
|---|
| 982 | int_4 i; // $CHECK$ int -> int_4 a cause de TagKey | 
|---|
| 983 | int n0, n1; | 
|---|
| 984 | bool ok = true; | 
|---|
| 985 | PPersist* obj=NULL; | 
|---|
| 986 | string nom; | 
|---|
| 987 |  | 
|---|
| 988 | int nread = 0; | 
|---|
| 989 | int nbtags = 0; | 
|---|
| 990 | nbtags = s.NbNameTags(); | 
|---|
| 991 | if ( (nbtags < 1) || (num >= nbtags) ) { | 
|---|
| 992 | if (num >= 0) { | 
|---|
| 993 | cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << "  Error! NbTags =" | 
|---|
| 994 | << nbtags << endl; | 
|---|
| 995 | return; | 
|---|
| 996 | } | 
|---|
| 997 |  | 
|---|
| 998 | try { | 
|---|
| 999 | obj = s.ReadObject(); | 
|---|
| 1000 | } | 
|---|
| 1001 | catch (IOExc iox) { | 
|---|
| 1002 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
| 1003 | ok = false; | 
|---|
| 1004 | } | 
|---|
| 1005 |  | 
|---|
| 1006 | if (!ok)  return; | 
|---|
| 1007 | nom = ""; | 
|---|
| 1008 | AddObj_P(obj->DataObj(), nom, false); | 
|---|
| 1009 | nread++; | 
|---|
| 1010 | } | 
|---|
| 1011 |  | 
|---|
| 1012 | if (num < 0) { n0 = 0; n1 = nbtags; } | 
|---|
| 1013 | else { n0 = num; n1 = num+1; } | 
|---|
| 1014 | for(i=n0; i<n1; i++) { | 
|---|
| 1015 | s.GotoNameTagNum(i); | 
|---|
| 1016 | nom = s.GetTagName(i); | 
|---|
| 1017 | try { | 
|---|
| 1018 | obj = s.ReadObject(); | 
|---|
| 1019 | } | 
|---|
| 1020 | catch (IOExc iox) { | 
|---|
| 1021 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
| 1022 | ok = false; | 
|---|
| 1023 | } | 
|---|
| 1024 | if (ok)  { AddObj_P(obj->DataObj(), nom, true);  nread++; } | 
|---|
| 1025 | } | 
|---|
| 1026 |  | 
|---|
| 1027 | cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl; | 
|---|
| 1028 | return; | 
|---|
| 1029 | } | 
|---|
| 1030 | /* --Methode-- */ | 
|---|
| 1031 | void NamedObjMgr::ReadAll(string const & flnm, bool atnametags) | 
|---|
| 1032 | // Lit tous les objets d'un fichier PPF | 
|---|
| 1033 | // si atnametags == true -> objets avec nametags seulement | 
|---|
| 1034 | //    sinon, tous les objets sequentiellement | 
|---|
| 1035 | { | 
|---|
| 1036 | try { | 
|---|
| 1037 | PInPersist pis(flnm); | 
|---|
| 1038 | if (atnametags && (pis.NbNameTags() >= 1))  { | 
|---|
| 1039 | if (pis.NbNameTags() < pis.NbTopLevelObjects()) { | 
|---|
| 1040 | cout << "NamedObjMgr::ReadAll()/Warning File " << flnm << " NbNameTags=" | 
|---|
| 1041 | << pis.NbNameTags() << " < NbTopLevelObjects= " | 
|---|
| 1042 | << pis.NbTopLevelObjects() << endl; | 
|---|
| 1043 | cout << " ... Reading " << pis.NbNameTags() << " objects at NameTags " ; | 
|---|
| 1044 | } | 
|---|
| 1045 | ReadObj(pis, -1); | 
|---|
| 1046 | return; | 
|---|
| 1047 | } | 
|---|
| 1048 |  | 
|---|
| 1049 | // On lit tous les objets sequentiellement ... | 
|---|
| 1050 | string nomr = servnobjm->FileName2Name(flnm); | 
|---|
| 1051 | string nom = nomr; | 
|---|
| 1052 | string nums; | 
|---|
| 1053 | int kn = 1; | 
|---|
| 1054 | bool fgrdok = true; | 
|---|
| 1055 | while (fgrdok) { | 
|---|
| 1056 | try { | 
|---|
| 1057 | PPersist* obj = pis.ReadObject(); | 
|---|
| 1058 | if (!obj) continue; | 
|---|
| 1059 | AddObj(obj->DataObj(), nom, false); | 
|---|
| 1060 | kn++;  nom = nomr + MuTyV(kn).Convert(nums); | 
|---|
| 1061 | } | 
|---|
| 1062 | catch (IOExc& iox) { | 
|---|
| 1063 | fgrdok = false; | 
|---|
| 1064 | } | 
|---|
| 1065 | } | 
|---|
| 1066 | cout<<"NamedObjMgr::ReadAll(" << flnm << " ,seq) "<< kn-1 << " objects read from File" << endl; | 
|---|
| 1067 | } | 
|---|
| 1068 | catch (IOExc& iox) { | 
|---|
| 1069 | cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
| 1070 | } | 
|---|
| 1071 | return; | 
|---|
| 1072 | } | 
|---|
| 1073 |  | 
|---|
| 1074 |  | 
|---|
| 1075 | /* --Methode-- */ | 
|---|
| 1076 | void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath) | 
|---|
| 1077 | { | 
|---|
| 1078 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1079 | SaveObj_P(nom, s, keeppath); | 
|---|
| 1080 | } | 
|---|
| 1081 |  | 
|---|
| 1082 | static int key_for_write = 5000; | 
|---|
| 1083 | /* --Methode-- */ | 
|---|
| 1084 | void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath) | 
|---|
| 1085 | { | 
|---|
| 1086 | if (nom.length() < 1) return; | 
|---|
| 1087 | string nob,rep; | 
|---|
| 1088 | ParseObjectName(nom, rep, nob); | 
|---|
| 1089 | nom = '/' + rep + '/' + nob; | 
|---|
| 1090 | NObjMgrAdapter* obja=NULL; | 
|---|
| 1091 | string nomf = (keeppath) ? nom : nob; | 
|---|
| 1092 | obja = GetObjAdapter_P(nom); | 
|---|
| 1093 | if (obja == NULL)  return; | 
|---|
| 1094 | printf("NamedObjMgr::SaveObj(%s, )  (Type=%s) \n", | 
|---|
| 1095 | nom.c_str(), typeid(*(obja->GetDataObj())).name()); | 
|---|
| 1096 | obja->SavePPF(s, nomf); | 
|---|
| 1097 | return; | 
|---|
| 1098 | } | 
|---|
| 1099 |  | 
|---|
| 1100 | /* --Methode-- */ | 
|---|
| 1101 | void NamedObjMgr::SaveObjects(string & patt, string const& flnm) | 
|---|
| 1102 | { | 
|---|
| 1103 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1104 | string n1,r1; | 
|---|
| 1105 | if (patt.length() < 1)  return; | 
|---|
| 1106 | bool keeppath = (patt[0] == '/') ? true : false; | 
|---|
| 1107 | ParseObjectName(patt, r1, n1); | 
|---|
| 1108 | patt = '/' + r1 + '/' + n1; | 
|---|
| 1109 |  | 
|---|
| 1110 | bool ok = true; | 
|---|
| 1111 | POutPersist* pout=NULL; | 
|---|
| 1112 | try { | 
|---|
| 1113 | pout = new POutPersist(flnm); | 
|---|
| 1114 | } | 
|---|
| 1115 | catch (IOExc iox) { | 
|---|
| 1116 | cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
| 1117 | ok = false; | 
|---|
| 1118 | } | 
|---|
| 1119 | if (!ok)  return; | 
|---|
| 1120 | NObjList::iterator it; | 
|---|
| 1121 | string cn; | 
|---|
| 1122 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| 1123 | cn = (*it).first; | 
|---|
| 1124 | if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue; | 
|---|
| 1125 | SaveObj_P(cn, (*pout), keeppath); | 
|---|
| 1126 | } | 
|---|
| 1127 | delete pout; | 
|---|
| 1128 | return; | 
|---|
| 1129 | } | 
|---|
| 1130 |  | 
|---|
| 1131 | /* --Methode-- */ | 
|---|
| 1132 | void NamedObjMgr::SaveListObjects(vector<string> &liste) | 
|---|
| 1133 | // Les n-1 premiers elements (liste[0 -> n-2]) contiennent | 
|---|
| 1134 | // les noms des objects a mettre  dans le fichier ppf | 
|---|
| 1135 | // dont le nom est le dernier argument (liste[n-1]) | 
|---|
| 1136 | { | 
|---|
| 1137 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1138 |  | 
|---|
| 1139 | if(liste.size()<2) { | 
|---|
| 1140 | cerr<<"NamedObjMgr::SaveListObjects()/Error not enough argument"<<endl; | 
|---|
| 1141 | return; | 
|---|
| 1142 | } | 
|---|
| 1143 |  | 
|---|
| 1144 | // open ppf file | 
|---|
| 1145 | string ppfname = liste[liste.size()-1]; | 
|---|
| 1146 | POutPersist* pout=NULL; | 
|---|
| 1147 | try { | 
|---|
| 1148 | pout = new POutPersist(ppfname); | 
|---|
| 1149 | } catch(IOExc iox) { | 
|---|
| 1150 | cerr<<"NamedObjMgr::SaveObjects()/Error Exception - Msg= "<<iox.Msg()<<endl; | 
|---|
| 1151 | return; | 
|---|
| 1152 | } | 
|---|
| 1153 |  | 
|---|
| 1154 | // put objects in ppf file | 
|---|
| 1155 | for(int i=0;i<liste.size()-1;i++) { | 
|---|
| 1156 | bool keeppath = (liste[i][0] == '/') ? true : false; | 
|---|
| 1157 | SaveObj_P(liste[i], (*pout), keeppath); | 
|---|
| 1158 | } | 
|---|
| 1159 |  | 
|---|
| 1160 | // close ppf file | 
|---|
| 1161 | delete pout; | 
|---|
| 1162 |  | 
|---|
| 1163 | return; | 
|---|
| 1164 | } | 
|---|
| 1165 |  | 
|---|
| 1166 | /* --Methode-- */ | 
|---|
| 1167 | void NamedObjMgr::SaveAll(string const& flnm) | 
|---|
| 1168 | { | 
|---|
| 1169 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1170 | bool ok = true; | 
|---|
| 1171 |  | 
|---|
| 1172 | POutPersist* pout=NULL; | 
|---|
| 1173 | try { | 
|---|
| 1174 | pout = new POutPersist(flnm); | 
|---|
| 1175 | } | 
|---|
| 1176 | catch (IOExc iox) { | 
|---|
| 1177 | cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
| 1178 | ok = false; | 
|---|
| 1179 | } | 
|---|
| 1180 | if (!ok)  return; | 
|---|
| 1181 | NObjList::iterator it; | 
|---|
| 1182 | string no; | 
|---|
| 1183 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| 1184 | no = (*it).first; | 
|---|
| 1185 | SaveObj_P(no, (*pout), true); | 
|---|
| 1186 | } | 
|---|
| 1187 | delete pout; | 
|---|
| 1188 | return; | 
|---|
| 1189 | } | 
|---|
| 1190 |  | 
|---|
| 1191 |  | 
|---|
| 1192 |  | 
|---|
| 1193 | /* --Methode-- */ | 
|---|
| 1194 | void NamedObjMgr::PrintObj(string& nom, int lev) | 
|---|
| 1195 | { | 
|---|
| 1196 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1197 | NObjMgrAdapter* obja=NULL; | 
|---|
| 1198 | obja = GetObjAdapter_P(nom); | 
|---|
| 1199 | if (obja == NULL)  return; | 
|---|
| 1200 | AnyDataObj* ob = obja->GetDataObj(); | 
|---|
| 1201 | if (ob == NULL) { | 
|---|
| 1202 | cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl; | 
|---|
| 1203 | return; | 
|---|
| 1204 | } | 
|---|
| 1205 | string ctyp = typeid(*ob).name(); | 
|---|
| 1206 | cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl; | 
|---|
| 1207 | obja->Print(cout, lev); | 
|---|
| 1208 |  | 
|---|
| 1209 | return; | 
|---|
| 1210 | } | 
|---|
| 1211 |  | 
|---|
| 1212 | /* --Methode-- */ | 
|---|
| 1213 | void NamedObjMgr::DisplayObj(string& nom, string dopt) | 
|---|
| 1214 | { | 
|---|
| 1215 | // Pas de display si option dopt = nodisp | 
|---|
| 1216 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return; | 
|---|
| 1217 |  | 
|---|
| 1218 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1219 |  | 
|---|
| 1220 | NObjMgrAdapter* obja=NULL; | 
|---|
| 1221 | obja = GetObjAdapter_P(nom); | 
|---|
| 1222 | if (obja == NULL) { | 
|---|
| 1223 | cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl; | 
|---|
| 1224 | return; | 
|---|
| 1225 | } | 
|---|
| 1226 | if (obja->GetDataObj() == NULL) { | 
|---|
| 1227 | cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl; | 
|---|
| 1228 | return; | 
|---|
| 1229 | } | 
|---|
| 1230 | if (!myImgApp)  return; | 
|---|
| 1231 |  | 
|---|
| 1232 | PIDrawer * dr = NULL; | 
|---|
| 1233 | P2DArrayAdapter* arr = NULL; | 
|---|
| 1234 | dr = obja->GetDrawer(dopt); | 
|---|
| 1235 | if (!dr) arr = obja->Get2DArray(dopt); | 
|---|
| 1236 |  | 
|---|
| 1237 | if (!dr && !arr) { | 
|---|
| 1238 | string ctyp = typeid(*(obja->GetDataObj())).name(); | 
|---|
| 1239 | cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl; | 
|---|
| 1240 | return; | 
|---|
| 1241 | } | 
|---|
| 1242 |  | 
|---|
| 1243 | int wrsid = 0; | 
|---|
| 1244 |  | 
|---|
| 1245 | string n1,r1; | 
|---|
| 1246 | ParseObjectName(nom, r1, n1); | 
|---|
| 1247 |  | 
|---|
| 1248 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts | 
|---|
| 1249 | bool fglock = (_fgimgapp) ? false : true; | 
|---|
| 1250 |  | 
|---|
| 1251 | if (dr) { | 
|---|
| 1252 | PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr); | 
|---|
| 1253 | if(dr3)  wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock); | 
|---|
| 1254 | else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock); | 
|---|
| 1255 | } | 
|---|
| 1256 | else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, false, 0, fglock); | 
|---|
| 1257 |  | 
|---|
| 1258 | AddWRsId_P(nom, wrsid); | 
|---|
| 1259 | return; | 
|---|
| 1260 | } | 
|---|
| 1261 |  | 
|---|
| 1262 | /* --Methode-- */ | 
|---|
| 1263 | void NamedObjMgr::DisplayImage(string& nom, string dopt, bool fgimagnav) | 
|---|
| 1264 | { | 
|---|
| 1265 | // Pas de display si option dopt = nodisp | 
|---|
| 1266 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return; | 
|---|
| 1267 |  | 
|---|
| 1268 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1269 |  | 
|---|
| 1270 | NObjMgrAdapter* obja=NULL; | 
|---|
| 1271 | obja = GetObjAdapter_P(nom); | 
|---|
| 1272 | if (obja == NULL) { | 
|---|
| 1273 | cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl; | 
|---|
| 1274 | return; | 
|---|
| 1275 | } | 
|---|
| 1276 | if (obja->GetDataObj() == NULL) { | 
|---|
| 1277 | cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl; | 
|---|
| 1278 | return; | 
|---|
| 1279 | } | 
|---|
| 1280 | if (!myImgApp)  return; | 
|---|
| 1281 |  | 
|---|
| 1282 | P2DArrayAdapter* arr = obja->Get2DArray(dopt); | 
|---|
| 1283 |  | 
|---|
| 1284 | if (!arr) { | 
|---|
| 1285 | string ctyp = typeid(*(obja->GetDataObj())).name(); | 
|---|
| 1286 | cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl; | 
|---|
| 1287 | return; | 
|---|
| 1288 | } | 
|---|
| 1289 |  | 
|---|
| 1290 | string n1,r1; | 
|---|
| 1291 | ParseObjectName(nom, r1, n1); | 
|---|
| 1292 |  | 
|---|
| 1293 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts | 
|---|
| 1294 | bool fglock = (_fgimgapp) ? false : true; | 
|---|
| 1295 |  | 
|---|
| 1296 | int wrsid = 0; | 
|---|
| 1297 | wrsid = myImgApp->DispImage(arr, n1, dopt, fgimagnav, 0, fglock); | 
|---|
| 1298 |  | 
|---|
| 1299 | AddWRsId_P(nom, wrsid); | 
|---|
| 1300 | return; | 
|---|
| 1301 | } | 
|---|
| 1302 | /* --Methode-- */ | 
|---|
| 1303 | void NamedObjMgr::DisplaySurf3D(string& nom, string dopt) | 
|---|
| 1304 | { | 
|---|
| 1305 | // Pas de display si option dopt = nodisp | 
|---|
| 1306 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return; | 
|---|
| 1307 |  | 
|---|
| 1308 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1309 |  | 
|---|
| 1310 | NObjMgrAdapter* obja=NULL; | 
|---|
| 1311 | obja = GetObjAdapter_P(nom); | 
|---|
| 1312 | if (obja == NULL) { | 
|---|
| 1313 | cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl; | 
|---|
| 1314 | return; | 
|---|
| 1315 | } | 
|---|
| 1316 | if (obja->GetDataObj() == NULL) { | 
|---|
| 1317 | cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl; | 
|---|
| 1318 | return; | 
|---|
| 1319 | } | 
|---|
| 1320 | if (!myImgApp)  return; | 
|---|
| 1321 |  | 
|---|
| 1322 | P2DArrayAdapter* arr = obja->Get2DArray(dopt); | 
|---|
| 1323 |  | 
|---|
| 1324 | if (!arr) { | 
|---|
| 1325 | string ctyp = typeid(*(obja->GetDataObj())).name(); | 
|---|
| 1326 | cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl; | 
|---|
| 1327 | return; | 
|---|
| 1328 | } | 
|---|
| 1329 |  | 
|---|
| 1330 | if ((arr->XSize() > 250) || (arr->YSize() > 250)) { | 
|---|
| 1331 | cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" <<  arr->XSize() | 
|---|
| 1332 | << "x" << arr->YSize() << ") too big (max=250x250)" << endl; | 
|---|
| 1333 | delete arr; | 
|---|
| 1334 | return; | 
|---|
| 1335 | } | 
|---|
| 1336 |  | 
|---|
| 1337 | string n1,r1; | 
|---|
| 1338 | ParseObjectName(nom, r1, n1); | 
|---|
| 1339 |  | 
|---|
| 1340 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts | 
|---|
| 1341 | bool fglock = (_fgimgapp) ? false : true; | 
|---|
| 1342 |  | 
|---|
| 1343 | int wrsid = 0; | 
|---|
| 1344 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true); | 
|---|
| 1345 | wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock); | 
|---|
| 1346 | AddWRsId_P(nom, wrsid); | 
|---|
| 1347 | return; | 
|---|
| 1348 | } | 
|---|
| 1349 |  | 
|---|
| 1350 | /* --Methode-- */ | 
|---|
| 1351 | void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz, | 
|---|
| 1352 | string& erx, string& ery, string& erz, string& wt, | 
|---|
| 1353 | string& label, string& colornm, bool coloridx, string dopt, bool fg3d) | 
|---|
| 1354 | { | 
|---|
| 1355 | // Pas de display si option dopt = nodisp | 
|---|
| 1356 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return; | 
|---|
| 1357 |  | 
|---|
| 1358 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1359 |  | 
|---|
| 1360 | AnyDataObj* obj=GetObj_P(nom); | 
|---|
| 1361 | if (obj == NULL) { | 
|---|
| 1362 | cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl; | 
|---|
| 1363 | return; | 
|---|
| 1364 | } | 
|---|
| 1365 | if (!myImgApp)  return; | 
|---|
| 1366 |  | 
|---|
| 1367 | NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj); | 
|---|
| 1368 | if (nt == NULL) { | 
|---|
| 1369 | // if (typeid(*obj) != typeid(NTupleInterface)) { | 
|---|
| 1370 | string ctyp = typeid(*obj).name(); | 
|---|
| 1371 | cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl; | 
|---|
| 1372 | return; | 
|---|
| 1373 | } | 
|---|
| 1374 |  | 
|---|
| 1375 | int wrsid = 0; | 
|---|
| 1376 | dopt = "defline " + dopt; | 
|---|
| 1377 |  | 
|---|
| 1378 | string n1,r1; | 
|---|
| 1379 | ParseObjectName(nom, r1, n1); | 
|---|
| 1380 |  | 
|---|
| 1381 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts | 
|---|
| 1382 | bool fglock = (_fgimgapp) ? false : true; | 
|---|
| 1383 |  | 
|---|
| 1384 | if ( fg3d && (nmz.length()>0) )  { // Display 3D | 
|---|
| 1385 | PINTuple3D* pin = new PINTuple3D(nt, false); | 
|---|
| 1386 | pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str()); | 
|---|
| 1387 | pin->SelectWt(wt.c_str()); | 
|---|
| 1388 | pin->SelectLabel(label.c_str()); | 
|---|
| 1389 | pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str()); | 
|---|
| 1390 | string titre = nmz + "%" + nmy + "%" + nmz; | 
|---|
| 1391 | wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock); | 
|---|
| 1392 | } | 
|---|
| 1393 | else { | 
|---|
| 1394 | PINTuple* pin = new PINTuple(nt, false); | 
|---|
| 1395 | pin->SelectXY(nmx.c_str(), nmy.c_str()); | 
|---|
| 1396 | pin->SelectWt(wt.c_str()); | 
|---|
| 1397 | pin->SelectLabel(label.c_str()); | 
|---|
| 1398 | pin->SelectErrBar(erx.c_str(), ery.c_str()); | 
|---|
| 1399 | if (colornm.length() > 0) {   // Juin 2007 : gestion de nom de colonne pour la couleur | 
|---|
| 1400 | if (coloridx) pin->SelectColorByIndex(colornm.c_str()); | 
|---|
| 1401 | else pin->SelectColorByName(colornm.c_str()); | 
|---|
| 1402 | } | 
|---|
| 1403 | string titre = nmy + "%" + nmx; | 
|---|
| 1404 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock); | 
|---|
| 1405 | } | 
|---|
| 1406 |  | 
|---|
| 1407 | AddWRsId_P(nom, wrsid); | 
|---|
| 1408 | return; | 
|---|
| 1409 | } | 
|---|
| 1410 |  | 
|---|
| 1411 | /* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */ | 
|---|
| 1412 | void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt) | 
|---|
| 1413 | //      Pour le display 2D ou 3D d'un ``GeneralFitData''. | 
|---|
| 1414 | //|  nom = nom de l'objet GeneralFitData a representer. | 
|---|
| 1415 | //|  numvarx = numero (nombre entier) de la 1ere variable d'abscisse. | 
|---|
| 1416 | //|  numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D). | 
|---|
| 1417 | //|            Pour le display 2D, numvary="" string vide. | 
|---|
| 1418 | //|  err = qu'elles erreurs faut il representer ? | 
|---|
| 1419 | //|      - 2D : x y xy   (display y=f(x)) | 
|---|
| 1420 | //|      - 3D : x y z xy xz yz xzy   (display z=f(x,y)) | 
|---|
| 1421 | //|      Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes | 
|---|
| 1422 | //|      les barres d'erreurs sont representees. | 
|---|
| 1423 | //|  opt = options generales pour le display. | 
|---|
| 1424 | { | 
|---|
| 1425 | // Pas de display si option dopt = nodisp | 
|---|
| 1426 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return; | 
|---|
| 1427 |  | 
|---|
| 1428 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1429 |  | 
|---|
| 1430 | AnyDataObj* obj=GetObj_P(nom); | 
|---|
| 1431 | if(obj == NULL) | 
|---|
| 1432 | {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl; | 
|---|
| 1433 | return;} | 
|---|
| 1434 | if(!myImgApp) return; | 
|---|
| 1435 | if(typeid(*obj) != typeid(GeneralFitData)) | 
|---|
| 1436 | {string ctyp = typeid(*obj).name(); | 
|---|
| 1437 | cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl; | 
|---|
| 1438 | return;} | 
|---|
| 1439 |  | 
|---|
| 1440 | // Decodage des erreurs a representer | 
|---|
| 1441 | bool errx=false, erry=false, errz=false; | 
|---|
| 1442 | if(err.length()>0) { | 
|---|
| 1443 | for(int i=0;i<(int_4)err.length();i++) | 
|---|
| 1444 | if     (err[i]=='x' || err[i]=='X') errx = true; | 
|---|
| 1445 | else if(err[i]=='y' || err[i]=='Y') erry = true; | 
|---|
| 1446 | else if(err[i]=='z' || err[i]=='Z') errz = true; | 
|---|
| 1447 | } | 
|---|
| 1448 | // Decodage des numeros de variables en abscisse | 
|---|
| 1449 | int numvx=-1, numvy=-1; | 
|---|
| 1450 | if(numvarx.length()>0) numvx = atoi(numvarx.c_str()); | 
|---|
| 1451 | if(numvary.length()>0) numvy = atoi(numvary.c_str()); | 
|---|
| 1452 |  | 
|---|
| 1453 | string n1,r1; | 
|---|
| 1454 | ParseObjectName(nom, r1, n1); | 
|---|
| 1455 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts | 
|---|
| 1456 | bool fglock = (_fgimgapp) ? false : true; | 
|---|
| 1457 |  | 
|---|
| 1458 | int wrsid = 0; | 
|---|
| 1459 | if(numvy>=0) {              // display 3D | 
|---|
| 1460 | PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false); | 
|---|
| 1461 | pigfd->SelectXY(numvx,numvy); | 
|---|
| 1462 | pigfd->SelectErrBar(errx,erry,errz); | 
|---|
| 1463 | wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock); | 
|---|
| 1464 | } else {                   // display 2D | 
|---|
| 1465 | PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false); | 
|---|
| 1466 | pigfd->SelectX(numvx); | 
|---|
| 1467 | pigfd->SelectErrBar(errx,erry); | 
|---|
| 1468 | wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock); | 
|---|
| 1469 | } | 
|---|
| 1470 |  | 
|---|
| 1471 | AddWRsId_P(nom, wrsid); | 
|---|
| 1472 |  | 
|---|
| 1473 | return; | 
|---|
| 1474 | } | 
|---|
| 1475 |  | 
|---|
| 1476 | /* --Methode-- */ | 
|---|
| 1477 | void NamedObjMgr::DisplayVector(string & nomvx, string& nomvy, string dopt) | 
|---|
| 1478 | //      Pour l'affichage 2-D de points avec coordonnees definies par deux vecteurs | 
|---|
| 1479 | //   nomvx et nomvy | 
|---|
| 1480 | { | 
|---|
| 1481 | // Pas de display si option dopt = nodisp | 
|---|
| 1482 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return; | 
|---|
| 1483 |  | 
|---|
| 1484 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1485 |  | 
|---|
| 1486 | if(!myImgApp) return; | 
|---|
| 1487 |  | 
|---|
| 1488 | AnyDataObj* obj; | 
|---|
| 1489 | obj = GetObj_P(nomvx); | 
|---|
| 1490 | if(obj == NULL) { | 
|---|
| 1491 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl; | 
|---|
| 1492 | return; | 
|---|
| 1493 | } | 
|---|
| 1494 | //Vector * vx = dynamic_cast<Vector *>(obj); | 
|---|
| 1495 | BaseArray* bax = dynamic_cast<BaseArray *>(obj); | 
|---|
| 1496 | if (bax == NULL) { | 
|---|
| 1497 | cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl; | 
|---|
| 1498 | return; | 
|---|
| 1499 | } | 
|---|
| 1500 |  | 
|---|
| 1501 | obj = GetObj_P(nomvy); | 
|---|
| 1502 | if(obj == NULL) { | 
|---|
| 1503 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl; | 
|---|
| 1504 | return; | 
|---|
| 1505 | } | 
|---|
| 1506 | BaseArray* bay = dynamic_cast<BaseArray *>(obj); | 
|---|
| 1507 | if (bay == NULL) { | 
|---|
| 1508 | cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl; | 
|---|
| 1509 | return; | 
|---|
| 1510 | } | 
|---|
| 1511 |  | 
|---|
| 1512 | Vector vx = *bax; | 
|---|
| 1513 | Vector vy = *bay; | 
|---|
| 1514 | Vector * cvx, * cvy; | 
|---|
| 1515 |  | 
|---|
| 1516 | if (vx.Size() != vy.Size()) { | 
|---|
| 1517 | cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl; | 
|---|
| 1518 | if (vx.Size() < vy.Size()) { | 
|---|
| 1519 | cvx = new Vector(vx); | 
|---|
| 1520 | cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1))); | 
|---|
| 1521 | } | 
|---|
| 1522 | else { | 
|---|
| 1523 | cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1))); | 
|---|
| 1524 | cvy = new Vector(vy); | 
|---|
| 1525 | } | 
|---|
| 1526 | } | 
|---|
| 1527 | else { | 
|---|
| 1528 | cvx = new Vector(vx); | 
|---|
| 1529 | cvy = new Vector(vy); | 
|---|
| 1530 | } | 
|---|
| 1531 |  | 
|---|
| 1532 | POVectorAdapter * avx = new POVectorAdapter(cvx, true); | 
|---|
| 1533 | POVectorAdapter * avy = new POVectorAdapter(cvy, true); | 
|---|
| 1534 | PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true); | 
|---|
| 1535 |  | 
|---|
| 1536 | string nx,rx; | 
|---|
| 1537 | ParseObjectName(nomvx, rx, nx); | 
|---|
| 1538 | string ny,ry; | 
|---|
| 1539 | ParseObjectName(nomvy, ry, ny); | 
|---|
| 1540 |  | 
|---|
| 1541 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts | 
|---|
| 1542 | bool fglock = (_fgimgapp) ? false : true; | 
|---|
| 1543 |  | 
|---|
| 1544 | string title = ny + " (Y) vs. " + nx + " (X)"; | 
|---|
| 1545 | // display 2D | 
|---|
| 1546 | myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock); | 
|---|
| 1547 |  | 
|---|
| 1548 | return; | 
|---|
| 1549 |  | 
|---|
| 1550 | } | 
|---|
| 1551 |  | 
|---|
| 1552 | /* --Methode-- | 
|---|
| 1553 | void NamedObjMgr::DisplayImage(string& nom, string dopt) | 
|---|
| 1554 | { | 
|---|
| 1555 | cout << "NamedObjMgr::DisplayImage() a faire ! " << endl; | 
|---|
| 1556 | } | 
|---|
| 1557 | */ | 
|---|
| 1558 |  | 
|---|
| 1559 |  | 
|---|
| 1560 |  | 
|---|
| 1561 |  | 
|---|
| 1562 | /* --Methode-- | 
|---|
| 1563 | void NamedObjMgr::SetGraphicAttributes(string gratt) | 
|---|
| 1564 | { | 
|---|
| 1565 | bool fg = false; | 
|---|
| 1566 | servnobjm->DecodeDispOption(gratt, fg); | 
|---|
| 1567 | Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt)); | 
|---|
| 1568 | } | 
|---|
| 1569 |  | 
|---|
| 1570 | void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr) | 
|---|
| 1571 | { | 
|---|
| 1572 | if (!myImgApp)  return; | 
|---|
| 1573 | if (fcr)  myImgApp->CreateGraphWin(nzx, nzy); | 
|---|
| 1574 | else myImgApp->SetZone(nzx, nzy); | 
|---|
| 1575 | } | 
|---|
| 1576 | */ | 
|---|
| 1577 |  | 
|---|
| 1578 | /* --Methode-- */ | 
|---|
| 1579 | int NamedObjMgr::NameToOId(string & nom) | 
|---|
| 1580 | { | 
|---|
| 1581 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1582 | return NameToOId_P(nom); | 
|---|
| 1583 | } | 
|---|
| 1584 |  | 
|---|
| 1585 | /* --Methode-- */ | 
|---|
| 1586 | int NamedObjMgr::NameToOId_P(string & nom) | 
|---|
| 1587 | { | 
|---|
| 1588 | string n1,r1; | 
|---|
| 1589 | ParseObjectName(nom, r1, n1); | 
|---|
| 1590 | nom = '/' + r1 + '/' + n1; | 
|---|
| 1591 | NObjList::iterator it = myObjs->find(nom); | 
|---|
| 1592 | if (it == myObjs->end()) return(-1); | 
|---|
| 1593 | else return((*it).second.oid); | 
|---|
| 1594 | } | 
|---|
| 1595 |  | 
|---|
| 1596 |  | 
|---|
| 1597 | /* --Methode-- */ | 
|---|
| 1598 | void NamedObjMgr::AddWRsId(string & nom, int wrsid) | 
|---|
| 1599 | { | 
|---|
| 1600 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1601 | AddWRsId_P(nom, wrsid); | 
|---|
| 1602 | } | 
|---|
| 1603 |  | 
|---|
| 1604 | /* --Methode-- */ | 
|---|
| 1605 | void NamedObjMgr::AddWRsId_P(string & nom, int wrsid) | 
|---|
| 1606 | { | 
|---|
| 1607 | if(wrsid != 0) { | 
|---|
| 1608 | NObjList::iterator it = myObjs->find(nom); | 
|---|
| 1609 | if (it == myObjs->end()) return; | 
|---|
| 1610 | (*it).second.wrsid.push_back(wrsid); | 
|---|
| 1611 | } | 
|---|
| 1612 | return; | 
|---|
| 1613 | } | 
|---|
| 1614 |  | 
|---|
| 1615 | /* --Methode-- */ | 
|---|
| 1616 | void NamedObjMgr::UpdateObjMgrWindow(int did) | 
|---|
| 1617 | { | 
|---|
| 1618 | if (!myImgApp)  return; | 
|---|
| 1619 | NObjMgrSync zs(0); zs.NOp(); | 
|---|
| 1620 | UpdateObjMgrWindow_P(did); | 
|---|
| 1621 | } | 
|---|
| 1622 |  | 
|---|
| 1623 | /* --Methode-- */ | 
|---|
| 1624 | void NamedObjMgr::SetObjMgrWindowVisibility(bool fgvis) | 
|---|
| 1625 | { | 
|---|
| 1626 | obmWvis = fgvis; | 
|---|
| 1627 | } | 
|---|
| 1628 |  | 
|---|
| 1629 | /* --Methode-- */ | 
|---|
| 1630 | void NamedObjMgr::UpdateObjMgrWindow_P(int did) | 
|---|
| 1631 | { | 
|---|
| 1632 | obmWUpdReq = false; | 
|---|
| 1633 | obmWvis = false; | 
|---|
| 1634 | if (!myImgApp)  return; | 
|---|
| 1635 | if ( !_fgimgapp )  myImgApp->LockMutex(); | 
|---|
| 1636 | // On ne fait rien si la fenetre non visible ou autre repertoire courant ds fenetre | 
|---|
| 1637 | if ( !(myImgApp->ObjMgrW())->Visible() || | 
|---|
| 1638 | ( (did >= 0) && (myImgApp->ObjMgrW())->GetCurDirId() != did) ) { | 
|---|
| 1639 | if ( !_fgimgapp )  myImgApp->UnlockMutex(true); | 
|---|
| 1640 | return; | 
|---|
| 1641 | } | 
|---|
| 1642 |  | 
|---|
| 1643 | // on change le repertoire courant de la fenetre si did<0 | 
|---|
| 1644 | if (did < 0) { | 
|---|
| 1645 | string cdir = *currDir; | 
|---|
| 1646 | cdir = '/' + cdir; | 
|---|
| 1647 | (myImgApp->ObjMgrW())->SetCurDir(cdir); | 
|---|
| 1648 | did = (myImgApp->ObjMgrW())->GetCurDirId(); | 
|---|
| 1649 | } | 
|---|
| 1650 |  | 
|---|
| 1651 | (myImgApp->ObjMgrW())->ClearObjList(); | 
|---|
| 1652 |  | 
|---|
| 1653 | NObjList::iterator it; | 
|---|
| 1654 | string cn; | 
|---|
| 1655 | int loid = 0; | 
|---|
| 1656 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| 1657 | if ((*it).second.dirid != did) continue; | 
|---|
| 1658 | cn = (*it).first.substr(1); | 
|---|
| 1659 | //  cn = cn.substr(cn.find('/')+1) + "  (T= " + typeid(*((*it).second.obj)).name() + ")" ; | 
|---|
| 1660 | cn = cn.substr(cn.find('/')+1) + "  (T= " + (*it).second.obja->GetDataObjType() + ")" ; | 
|---|
| 1661 | loid = (*it).second.oid; | 
|---|
| 1662 | (myImgApp->ObjMgrW())->AddObj(cn.c_str(), loid); | 
|---|
| 1663 | } | 
|---|
| 1664 | (myImgApp->ObjMgrW())->SelObjByOid(loid); | 
|---|
| 1665 |  | 
|---|
| 1666 | (myImgApp->ObjMgrW())->SetSensitive(); | 
|---|
| 1667 | if ( !_fgimgapp )  myImgApp->UnlockMutex(true); | 
|---|
| 1668 | obmWvis = true; | 
|---|
| 1669 | return; | 
|---|
| 1670 | } | 
|---|
| 1671 |  | 
|---|
| 1672 |  | 
|---|
| 1673 | /* Nouvelle-Fonction */ | 
|---|
| 1674 | void NamedObjMgr::RemoveSpacesFromName(string & nom) | 
|---|
| 1675 | { | 
|---|
| 1676 | // on supprime les blancs de debut et de fin | 
|---|
| 1677 | size_t p = nom.find_first_not_of(" "); | 
|---|
| 1678 | if(p>nom.length()) { nom = ""; return; } | 
|---|
| 1679 | nom = nom.substr(p); | 
|---|
| 1680 | p = nom.find(' '); | 
|---|
| 1681 | if(p>nom.length()) p=nom.length(); | 
|---|
| 1682 | nom = nom.substr(0, p); | 
|---|
| 1683 | } | 
|---|
| 1684 |  | 
|---|
| 1685 | /* Nouvelle-Fonction */ | 
|---|
| 1686 | bool NamedObjMgr::CheckDirName(string & nom) | 
|---|
| 1687 | { | 
|---|
| 1688 | RemoveSpacesFromName(nom); | 
|---|
| 1689 | if (nom.length() < 1)  return(false); | 
|---|
| 1690 | if (nom[0] == '/') nom = nom.substr(1) ; | 
|---|
| 1691 | size_t p = nom.find('/'); | 
|---|
| 1692 | if (p < nom.length()) nom = nom.substr(0,p); | 
|---|
| 1693 | if ((nom.length() < 1) || (! isalpha(nom[0]) ) )  return(false); | 
|---|
| 1694 | return(true); | 
|---|
| 1695 | } | 
|---|
| 1696 |  | 
|---|
| 1697 | /* Nouvelle-Fonction */ | 
|---|
| 1698 | int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj) | 
|---|
| 1699 | { | 
|---|
| 1700 | RemoveSpacesFromName(nom); | 
|---|
| 1701 | // Si le nom ne commence pas par un slash, c'est le repertoire courant | 
|---|
| 1702 | if (nom[0] != '/') { nomrep = *currDir;  nomobj = nom; } | 
|---|
| 1703 | else { | 
|---|
| 1704 | string xx = nom.substr(1); | 
|---|
| 1705 | size_t p = xx.find('/'); | 
|---|
| 1706 | if (p < xx.length())  { | 
|---|
| 1707 | nomrep = xx.substr(0,p); | 
|---|
| 1708 | nomobj = xx.substr(p+1); | 
|---|
| 1709 | } | 
|---|
| 1710 | else { | 
|---|
| 1711 | nomrep = xx; | 
|---|
| 1712 | nomobj = ""; | 
|---|
| 1713 | } | 
|---|
| 1714 | } | 
|---|
| 1715 | int rc = 0; | 
|---|
| 1716 | NObjDirList::iterator it = myDirs->find(nomrep); | 
|---|
| 1717 | if (it != myDirs->end())  rc = (*it).second.id; | 
|---|
| 1718 | return(rc); | 
|---|
| 1719 | } | 
|---|
| 1720 |  | 
|---|
| 1721 | /* Nouvelle-Fonction */ | 
|---|
| 1722 | bool NamedObjMgr::CheckName(string const & nom) | 
|---|
| 1723 | { | 
|---|
| 1724 | if (nom.length() < 1) return false; | 
|---|
| 1725 | if (! isalpha(nom[0]) ) return false; | 
|---|
| 1726 | for(int k=0; k<nom.length(); k++) | 
|---|
| 1727 | if ((!isalnum(nom[k])) && (nom[k] != '_')) return false; | 
|---|
| 1728 | return true; | 
|---|
| 1729 | } | 
|---|