| [165] | 1 | #include <stdio.h> | 
|---|
|  | 2 | #include <stdlib.h> | 
|---|
|  | 3 | #include <ctype.h> | 
|---|
|  | 4 |  | 
|---|
| [295] | 5 | #include <typeinfo> | 
|---|
| [165] | 6 | #include <iostream.h> | 
|---|
|  | 7 | #include <string> | 
|---|
|  | 8 | #include <list> | 
|---|
|  | 9 | #include <map> | 
|---|
|  | 10 |  | 
|---|
|  | 11 | #include "strutil.h" | 
|---|
|  | 12 | #include "datatypes.h" | 
|---|
|  | 13 |  | 
|---|
|  | 14 | #include "nobjmgr.h" | 
|---|
|  | 15 | #include "servnobjm.h" | 
|---|
| [330] | 16 | #include "nomgadapter.h" | 
|---|
| [165] | 17 | #include "pistdimgapp.h" | 
|---|
|  | 18 |  | 
|---|
| [1164] | 19 | #include "dvlist.h" | 
|---|
| [165] | 20 |  | 
|---|
| [293] | 21 | // EVOL-PLANCK | 
|---|
|  | 22 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 23 | #include "fitsimage.h" | 
|---|
|  | 24 | #endif | 
|---|
|  | 25 |  | 
|---|
| [295] | 26 | #include "pisurfdr.h" | 
|---|
| [165] | 27 | #include "pipodrw.h" | 
|---|
| [333] | 28 |  | 
|---|
| [165] | 29 | #include "pintuple.h" | 
|---|
|  | 30 | #include "pintup3d.h" | 
|---|
|  | 31 | #include "pigfd1.h" | 
|---|
|  | 32 | #include "pigfd2.h" | 
|---|
|  | 33 |  | 
|---|
|  | 34 |  | 
|---|
|  | 35 | //++ | 
|---|
|  | 36 | // Class        NamedObjMgr | 
|---|
|  | 37 | // Lib          PI | 
|---|
|  | 38 | // include      nobjmgr.h | 
|---|
|  | 39 | // | 
|---|
| [344] | 40 | //      Cette classe fournit les services nécéssaires à la gestion des objets | 
|---|
| [165] | 41 | //      (l'ensemble des objets PPersist de PEIDA++) au sein du programme | 
|---|
|  | 42 | //      d'analyse interactive *piapp* . Elle constitue en outre l'interface | 
|---|
|  | 43 | //      entre les fonctions utilisateur et l'application graphique. | 
|---|
|  | 44 | //-- | 
|---|
|  | 45 | //++ | 
|---|
|  | 46 | // Links        Voir aussi | 
|---|
|  | 47 | // PIStdImgApp | 
|---|
|  | 48 | // Services2NObjMgr | 
|---|
|  | 49 | // PIACmd | 
|---|
|  | 50 | //-- | 
|---|
|  | 51 |  | 
|---|
|  | 52 |  | 
|---|
|  | 53 | // .................................................................. | 
|---|
|  | 54 | // ......  Gestion des objets nommes, variables globales ............ | 
|---|
| [331] | 55 | struct nobj_diritem { | 
|---|
| [344] | 56 | int id;                 // Directory Id | 
|---|
|  | 57 | int nobj;               // Number of objects in directory | 
|---|
|  | 58 | bool lock;              // True -> directory locked, No Add, del or rename | 
|---|
|  | 59 | bool keepold;           // True -> When duplicate object name, old object moved to /old | 
|---|
| [331] | 60 | }; | 
|---|
|  | 61 |  | 
|---|
|  | 62 | typedef map<string, nobj_diritem, less<string> > NObjDirList; | 
|---|
|  | 63 |  | 
|---|
| [165] | 64 | struct nobj_item { | 
|---|
| [344] | 65 | AnyDataObj* obj;             // Object pointer | 
|---|
|  | 66 | NObjMgrAdapter* obja;        // Object adapter pointer | 
|---|
|  | 67 | int oid;                     // object Id | 
|---|
|  | 68 | int dirid;                   // Directory Id | 
|---|
|  | 69 | list<int> wrsid;             // List of Window Resource Id (Drawer, PIBaseWdg, ...) | 
|---|
|  | 70 | // (for PIStdImgApp) | 
|---|
| [165] | 71 | bool operator==(nobj_item const& b) const | 
|---|
|  | 72 | { return (this->obj ==  b.obj); } | 
|---|
|  | 73 | }; | 
|---|
|  | 74 |  | 
|---|
|  | 75 | typedef map<string, nobj_item, less<string> > NObjList; | 
|---|
|  | 76 |  | 
|---|
| [331] | 77 | static NObjDirList* myDirs = NULL; | 
|---|
|  | 78 | static NObjList* myObjs = NULL; | 
|---|
| [165] | 79 | static int fgOInit = 0; | 
|---|
|  | 80 | static int myNObj = 0; | 
|---|
| [331] | 81 | static int myDirId = 0; | 
|---|
|  | 82 | static string* currDir; | 
|---|
| [165] | 83 |  | 
|---|
|  | 84 | static PIStdImgApp* myImgApp=NULL; | 
|---|
|  | 85 | static Services2NObjMgr* servnobjm=NULL; | 
|---|
|  | 86 |  | 
|---|
| [1164] | 87 | static DVList* myVars = NULL;  // Pour stocker les variables | 
|---|
|  | 88 |  | 
|---|
| [165] | 89 | static string* TmpDir;  // Repertoire pour les compilations / link dynamique | 
|---|
|  | 90 |  | 
|---|
| [333] | 91 | // .................................................................. | 
|---|
|  | 92 |  | 
|---|
| [165] | 93 | //++ | 
|---|
|  | 94 | // Titre        Constructeurs | 
|---|
|  | 95 | //-- | 
|---|
|  | 96 | //++ | 
|---|
|  | 97 | // NamedObjMgr() | 
|---|
|  | 98 | //      Constructeur. Les différents instantiation de la classe "NamedObjMgr" | 
|---|
|  | 99 | //      dans une même application créent des objets qui travaillent sur la même | 
|---|
|  | 100 | //      liste d'objets. Les objets de cette classe ne possedent en effet pas | 
|---|
|  | 101 | //      de variables membres. | 
|---|
|  | 102 | //-- | 
|---|
|  | 103 |  | 
|---|
|  | 104 | /* --Methode-- */ | 
|---|
|  | 105 | NamedObjMgr::NamedObjMgr() | 
|---|
|  | 106 | { | 
|---|
|  | 107 | if (fgOInit == 0) { | 
|---|
| [333] | 108 | myNObj = 0; | 
|---|
|  | 109 | myDirId = 0; | 
|---|
| [331] | 110 | myDirs = new NObjDirList; | 
|---|
| [165] | 111 | myObjs = new NObjList; | 
|---|
| [1164] | 112 | myVars = new DVList; | 
|---|
| [331] | 113 | currDir = new string("home"); | 
|---|
| [333] | 114 | string dirn = "home"; | 
|---|
|  | 115 | CreateDir(dirn); | 
|---|
| [344] | 116 | SetKeepOldDirAtt(dirn, true); | 
|---|
| [333] | 117 | dirn = "tmp"; | 
|---|
|  | 118 | CreateDir(dirn); | 
|---|
| [344] | 119 | SetKeepOldDirAtt(dirn, false); | 
|---|
| [466] | 120 | dirn = "autoc"; | 
|---|
| [368] | 121 | CreateDir(dirn); | 
|---|
|  | 122 | SetKeepOldDirAtt(dirn, false); | 
|---|
| [333] | 123 | dirn = "old"; | 
|---|
|  | 124 | CreateDir(dirn); | 
|---|
| [344] | 125 | SetKeepOldDirAtt(dirn, false); | 
|---|
| [333] | 126 | dirn = "home"; | 
|---|
|  | 127 | SetCurrentDir(dirn); | 
|---|
|  | 128 | myDirId = 50; | 
|---|
| [165] | 129 | char* varenv; | 
|---|
|  | 130 | TmpDir = new string(""); | 
|---|
|  | 131 | if ( (varenv=getenv("PEIDA_TMP")) != NULL )  (*TmpDir) = varenv; | 
|---|
|  | 132 | else if ( (varenv=getenv("TMPDIR")) != NULL )  (*TmpDir) = varenv; | 
|---|
|  | 133 | int l = (*TmpDir).length(); | 
|---|
|  | 134 | if ( (l>0) && ((*TmpDir)[l-1] != '/') )  (*TmpDir) += '/'; | 
|---|
| [333] | 135 | servnobjm = new Services2NObjMgr(this, (*TmpDir)); | 
|---|
| [165] | 136 | } | 
|---|
|  | 137 | fgOInit++; | 
|---|
|  | 138 | } | 
|---|
|  | 139 |  | 
|---|
|  | 140 |  | 
|---|
|  | 141 | /* --Methode-- */ | 
|---|
|  | 142 | NamedObjMgr::~NamedObjMgr() | 
|---|
|  | 143 | { | 
|---|
|  | 144 | fgOInit--; | 
|---|
| [1164] | 145 | if (fgOInit == 0)  { | 
|---|
|  | 146 | string patt = "/*/*"; | 
|---|
|  | 147 | DelObjects(patt, true); | 
|---|
|  | 148 | delete myObjs; | 
|---|
|  | 149 | delete myDirs; | 
|---|
|  | 150 | delete myVars; | 
|---|
| [165] | 151 | } | 
|---|
| [1164] | 152 | } | 
|---|
| [165] | 153 |  | 
|---|
|  | 154 | //++ | 
|---|
|  | 155 | // Titre        Méthodes | 
|---|
|  | 156 | //-- | 
|---|
|  | 157 | //++ | 
|---|
|  | 158 | // void SetImgApp(PIStdImgApp* app) | 
|---|
|  | 159 | //      Spécifie l'objet "PIStdImgApp" associé. | 
|---|
|  | 160 | // PIStdImgApp* GetImgApp() | 
|---|
|  | 161 | //      Accès à l'objet "PIStdImgApp" associé. | 
|---|
|  | 162 | //-- | 
|---|
|  | 163 |  | 
|---|
|  | 164 | /* --Methode-- */ | 
|---|
|  | 165 | void NamedObjMgr::SetImgApp(PIStdImgApp* app) | 
|---|
|  | 166 | { | 
|---|
|  | 167 | myImgApp = app; | 
|---|
|  | 168 | servnobjm->SetImgApp(app); | 
|---|
| [333] | 169 |  | 
|---|
|  | 170 | NObjDirList::iterator it; | 
|---|
|  | 171 | string cn; | 
|---|
|  | 172 | for(it= myDirs->begin(); it != myDirs->end(); it++) { | 
|---|
|  | 173 | cn = '/' + (*it).first; | 
|---|
|  | 174 | (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id); | 
|---|
|  | 175 | } | 
|---|
| [165] | 176 | } | 
|---|
|  | 177 |  | 
|---|
| [449] | 178 |  | 
|---|
|  | 179 | static bool verbeux = false;  // true -> plus de message (creation/suppression d'objets) | 
|---|
|  | 180 | void NamedObjMgr::SetVerbose(bool fg) | 
|---|
|  | 181 | { | 
|---|
|  | 182 | verbeux = fg; | 
|---|
|  | 183 | } | 
|---|
|  | 184 |  | 
|---|
| [165] | 185 | /* --Methode-- */ | 
|---|
|  | 186 | PIStdImgApp* NamedObjMgr::GetImgApp() | 
|---|
|  | 187 | { | 
|---|
|  | 188 | return(myImgApp); | 
|---|
|  | 189 | } | 
|---|
|  | 190 |  | 
|---|
|  | 191 | /* --Methode-- */ | 
|---|
|  | 192 | Services2NObjMgr* NamedObjMgr::GetServiceObj() | 
|---|
|  | 193 | { | 
|---|
|  | 194 | return(servnobjm); | 
|---|
|  | 195 | } | 
|---|
|  | 196 |  | 
|---|
| [331] | 197 | /* --Methode-- */ | 
|---|
| [1164] | 198 | bool NamedObjMgr::SetVar(string const & key, string const & val) | 
|---|
|  | 199 | { | 
|---|
| [1199] | 200 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 201 | bool fg = true; | 
|---|
|  | 202 | #else | 
|---|
| [1164] | 203 | bool fg = myVars->HasKey(key); | 
|---|
| [1199] | 204 | #endif | 
|---|
| [1164] | 205 | myVars->SetS(key, val); | 
|---|
|  | 206 | return(fg); | 
|---|
|  | 207 | } | 
|---|
|  | 208 |  | 
|---|
|  | 209 | /* --Methode-- */ | 
|---|
|  | 210 | bool NamedObjMgr::HasVar(string const & key) | 
|---|
|  | 211 | { | 
|---|
| [1199] | 212 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 213 | return(false); | 
|---|
|  | 214 | #else | 
|---|
| [1164] | 215 | return(myVars->HasKey(key)); | 
|---|
| [1199] | 216 | #endif | 
|---|
| [1164] | 217 | } | 
|---|
|  | 218 |  | 
|---|
|  | 219 | /* --Methode-- */ | 
|---|
|  | 220 | bool NamedObjMgr::DeleteVar(string const & key) | 
|---|
|  | 221 | { | 
|---|
| [1199] | 222 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 223 | return(false); | 
|---|
|  | 224 | #else | 
|---|
| [1164] | 225 | return(myVars->DeleteKey(key)); | 
|---|
| [1199] | 226 | #endif | 
|---|
| [1164] | 227 | } | 
|---|
|  | 228 |  | 
|---|
|  | 229 | /* --Methode-- */ | 
|---|
|  | 230 | string NamedObjMgr::GetVar(string const & key) | 
|---|
|  | 231 | { | 
|---|
|  | 232 | return(myVars->GetS(key)); | 
|---|
|  | 233 | } | 
|---|
|  | 234 |  | 
|---|
|  | 235 | /* --Methode-- */ | 
|---|
|  | 236 | DVList& NamedObjMgr::GetVarList() | 
|---|
|  | 237 | { | 
|---|
|  | 238 | return(*myVars); | 
|---|
|  | 239 | } | 
|---|
|  | 240 |  | 
|---|
|  | 241 | /* --Methode-- */ | 
|---|
| [344] | 242 | bool NamedObjMgr::CreateDir(string & dirname) | 
|---|
| [331] | 243 | { | 
|---|
| [333] | 244 | if ( !CheckDirName(dirname) ) { | 
|---|
|  | 245 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl; | 
|---|
| [344] | 246 | return(false); | 
|---|
| [333] | 247 | } | 
|---|
|  | 248 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
|  | 249 | if (it != myDirs->end()) { | 
|---|
|  | 250 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl; | 
|---|
| [344] | 251 | return(false); | 
|---|
| [333] | 252 | } | 
|---|
|  | 253 | myDirId++; | 
|---|
|  | 254 | nobj_diritem di; | 
|---|
|  | 255 | di.id = myDirId; | 
|---|
|  | 256 | di.nobj = 0; | 
|---|
| [344] | 257 | di.lock = false; | 
|---|
|  | 258 | di.keepold = false; | 
|---|
| [333] | 259 | (*myDirs)[dirname] = di; | 
|---|
|  | 260 | if (myImgApp)  { | 
|---|
|  | 261 | string str = '/' + dirname; | 
|---|
|  | 262 | (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId); | 
|---|
|  | 263 | } | 
|---|
| [449] | 264 | if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl; | 
|---|
| [344] | 265 | return(true); | 
|---|
| [331] | 266 | } | 
|---|
|  | 267 |  | 
|---|
|  | 268 | /* --Methode-- */ | 
|---|
| [344] | 269 | bool NamedObjMgr::DeleteDir(string & dirname) | 
|---|
| [331] | 270 | { | 
|---|
| [333] | 271 | if ( !CheckDirName(dirname) ) { | 
|---|
|  | 272 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl; | 
|---|
| [344] | 273 | return(false); | 
|---|
| [333] | 274 | } | 
|---|
|  | 275 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
|  | 276 | if (it == myDirs->end()) { | 
|---|
|  | 277 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl; | 
|---|
| [344] | 278 | return(false); | 
|---|
| [333] | 279 | } | 
|---|
|  | 280 | if ((*it).second.nobj > 0) { | 
|---|
|  | 281 | cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl; | 
|---|
| [344] | 282 | return(false); | 
|---|
| [333] | 283 | } | 
|---|
| [344] | 284 | if ((*it).second.lock ) { | 
|---|
|  | 285 | cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl; | 
|---|
|  | 286 | return(false); | 
|---|
|  | 287 | } | 
|---|
| [333] | 288 | if ((*it).second.id < 50) { | 
|---|
|  | 289 | cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl; | 
|---|
| [344] | 290 | return(false); | 
|---|
| [333] | 291 | } | 
|---|
|  | 292 |  | 
|---|
|  | 293 | if (myImgApp) | 
|---|
|  | 294 | (myImgApp->ObjMgrW())->DelDirectory((*it).second.id); | 
|---|
|  | 295 | myDirs->erase(it); | 
|---|
| [449] | 296 | if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl; | 
|---|
| [344] | 297 | return(true); | 
|---|
| [331] | 298 | } | 
|---|
|  | 299 |  | 
|---|
|  | 300 | /* --Methode-- */ | 
|---|
| [344] | 301 | void NamedObjMgr::LockDir(string & dirname) | 
|---|
| [331] | 302 | { | 
|---|
| [344] | 303 | if ( !CheckDirName(dirname) ) return; | 
|---|
|  | 304 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
|  | 305 | if (it == myDirs->end()) return; | 
|---|
|  | 306 | (*it).second.lock = true; | 
|---|
| [449] | 307 | if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl; | 
|---|
| [344] | 308 | return; | 
|---|
|  | 309 | } | 
|---|
|  | 310 |  | 
|---|
|  | 311 | /* --Methode-- */ | 
|---|
|  | 312 | void NamedObjMgr::UnlockDir(string & dirname) | 
|---|
|  | 313 | { | 
|---|
|  | 314 | if ( !CheckDirName(dirname) ) return; | 
|---|
|  | 315 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
|  | 316 | if (it == myDirs->end()) return; | 
|---|
|  | 317 | (*it).second.lock = true; | 
|---|
| [449] | 318 | if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl; | 
|---|
| [344] | 319 | return; | 
|---|
|  | 320 | } | 
|---|
|  | 321 |  | 
|---|
|  | 322 | /* --Methode-- */ | 
|---|
|  | 323 | void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold) | 
|---|
|  | 324 | { | 
|---|
|  | 325 | if ( !CheckDirName(dirname) ) return; | 
|---|
|  | 326 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
|  | 327 | if (it == myDirs->end()) return; | 
|---|
|  | 328 | (*it).second.keepold = keepold; | 
|---|
| [449] | 329 | if (!verbeux) return; | 
|---|
| [344] | 330 | cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << "  ->  "; | 
|---|
|  | 331 | if ( keepold ) cout << " True " << endl; | 
|---|
|  | 332 | else cout << " False " << endl; | 
|---|
|  | 333 | return; | 
|---|
|  | 334 | } | 
|---|
|  | 335 |  | 
|---|
|  | 336 |  | 
|---|
|  | 337 | /* --Methode-- */ | 
|---|
|  | 338 | bool NamedObjMgr::SetCurrentDir(string & dirname) | 
|---|
|  | 339 | { | 
|---|
| [333] | 340 | if ( !CheckDirName(dirname) ) { | 
|---|
|  | 341 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl; | 
|---|
| [344] | 342 | return(false); | 
|---|
| [333] | 343 | } | 
|---|
|  | 344 | NObjDirList::iterator it = myDirs->find(dirname); | 
|---|
|  | 345 | if (it == myDirs->end()) { | 
|---|
|  | 346 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl; | 
|---|
| [344] | 347 | return(false); | 
|---|
| [333] | 348 | } | 
|---|
|  | 349 | *currDir = dirname; | 
|---|
| [449] | 350 | if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl; | 
|---|
| [344] | 351 | return(true); | 
|---|
| [331] | 352 | } | 
|---|
|  | 353 |  | 
|---|
|  | 354 | /* --Methode-- */ | 
|---|
| [333] | 355 | void NamedObjMgr::GetCurrentDir(string & dirname) | 
|---|
|  | 356 | { | 
|---|
|  | 357 | dirname = *currDir; | 
|---|
|  | 358 | } | 
|---|
|  | 359 |  | 
|---|
|  | 360 | /* --Methode-- */ | 
|---|
|  | 361 | void NamedObjMgr::ListDirs(string & patt) | 
|---|
|  | 362 | { | 
|---|
|  | 363 | NObjDirList::iterator it; | 
|---|
|  | 364 | string cn; | 
|---|
|  | 365 | cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl; | 
|---|
|  | 366 | int k = 0; | 
|---|
|  | 367 | for(it= myDirs->begin(); it != myDirs->end(); it++) { | 
|---|
|  | 368 | cn = (*it).first; | 
|---|
|  | 369 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; | 
|---|
|  | 370 | k++; | 
|---|
| [344] | 371 | cout << k << "- " << (*it).first; | 
|---|
|  | 372 | if ( (*it).second.lock )  cout << "  Locked " ; | 
|---|
|  | 373 | if ( (*it).second.keepold )   cout << "  KeepOld " ; | 
|---|
|  | 374 | cout << "  (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl; | 
|---|
|  | 375 |  | 
|---|
| [333] | 376 | } | 
|---|
|  | 377 | } | 
|---|
|  | 378 |  | 
|---|
|  | 379 | /* --Methode-- */ | 
|---|
|  | 380 | void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd) | 
|---|
|  | 381 | { | 
|---|
|  | 382 | NObjDirList::iterator it; | 
|---|
|  | 383 | string cn; | 
|---|
|  | 384 | for(it= myDirs->begin(); it != myDirs->end(); it++) { | 
|---|
|  | 385 | cn = (*it).first; | 
|---|
|  | 386 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; | 
|---|
|  | 387 | lstd.push_back(cn); | 
|---|
|  | 388 | } | 
|---|
|  | 389 | } | 
|---|
|  | 390 |  | 
|---|
|  | 391 | /* --Methode-- */ | 
|---|
| [368] | 392 | void NamedObjMgr::CleanDir(string & dirname) | 
|---|
| [331] | 393 | { | 
|---|
| [368] | 394 | if ( !CheckDirName(dirname) ) { | 
|---|
|  | 395 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl; | 
|---|
| [380] | 396 | // return(false);  $CHECK$ illegal return value in void function | 
|---|
| [368] | 397 | } | 
|---|
|  | 398 | NObjDirList::iterator itr = myDirs->find(dirname); | 
|---|
|  | 399 | if (itr == myDirs->end()) { | 
|---|
|  | 400 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - No such directory !" << endl; | 
|---|
| [380] | 401 | // return(false);  $CHECK$ illegal return value in void function | 
|---|
| [368] | 402 | } | 
|---|
| [331] | 403 |  | 
|---|
| [368] | 404 | int did = (*itr).second.id; | 
|---|
|  | 405 | NObjList::iterator it; | 
|---|
|  | 406 | list<int>::iterator iwr; | 
|---|
|  | 407 | bool nodisp = true; | 
|---|
|  | 408 | list<string> odel; | 
|---|
|  | 409 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
|  | 410 | if ((*it).second.dirid != did) continue; | 
|---|
|  | 411 | nodisp = true; | 
|---|
|  | 412 | if (myImgApp) | 
|---|
|  | 413 | for(iwr=(*it).second.wrsid.begin(); iwr != (*it).second.wrsid.end(); iwr++) | 
|---|
|  | 414 | if (myImgApp->CheckWRsId(*iwr)) { nodisp = false; break; } | 
|---|
|  | 415 | if (nodisp) odel.push_back((*it).first); | 
|---|
|  | 416 | } | 
|---|
|  | 417 | list<string>::iterator ii; | 
|---|
|  | 418 | for(ii=odel.begin(); ii != odel.end(); ii++)  DelObj(*ii,true); | 
|---|
| [685] | 419 | if (myImgApp) | 
|---|
|  | 420 | (myImgApp->ObjMgrW())->UpdateList(did); | 
|---|
| [331] | 421 | } | 
|---|
|  | 422 |  | 
|---|
| [333] | 423 |  | 
|---|
| [368] | 424 |  | 
|---|
| [165] | 425 | //++ | 
|---|
|  | 426 | // Titre        Gestion de la liste des objets | 
|---|
|  | 427 | //-- | 
|---|
|  | 428 | //++ | 
|---|
| [295] | 429 | // void AddObj(AnyDataObj* obj, string& nom) | 
|---|
| [165] | 430 | //      Ajoute l'objet "obj" à la liste, identifié par "nom". | 
|---|
|  | 431 | //      Si un objet de même nom existe, l'ancien objet est renommé en concaténant | 
|---|
|  | 432 | //      un numéro à son nom. | 
|---|
|  | 433 | // void DelObj(string const& nom, bool fgd=true) | 
|---|
|  | 434 | //      Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true"  ("delete obj") | 
|---|
|  | 435 | // void DelObjects(string const& patt, bool fgd=true) | 
|---|
|  | 436 | //      Supprime l'ensemble des objets dont le nom correspond au patron "patt". | 
|---|
|  | 437 | //      Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true" | 
|---|
| [295] | 438 | // AnyDataObj*  GetObj(string const& nom) | 
|---|
| [165] | 439 | //      Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est | 
|---|
|  | 440 | //      pas dans la liste. | 
|---|
|  | 441 | // void  RenameObj(string const& nom, string& nomnew) | 
|---|
|  | 442 | //      Change le nom d'un objet dans la liste. | 
|---|
| [463] | 443 | // void  CopyObj(string const& nom, string& nomcp) | 
|---|
|  | 444 | //      Copy l'objet "nom" de la liste dans l'objet "nomcp" de la liste. | 
|---|
| [165] | 445 | //-- | 
|---|
|  | 446 |  | 
|---|
|  | 447 |  | 
|---|
|  | 448 | /* --Methode-- */ | 
|---|
| [344] | 449 | bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd) | 
|---|
| [165] | 450 | { | 
|---|
|  | 451 |  | 
|---|
| [344] | 452 | if (obj == NULL)  return(false); | 
|---|
| [333] | 453 | // On verifie si l'objet est deja dans la liste | 
|---|
|  | 454 | NObjList::iterator it; | 
|---|
|  | 455 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
|  | 456 | if ((*it).second.obj == obj) { | 
|---|
|  | 457 | cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl; | 
|---|
| [344] | 458 | return(false); | 
|---|
| [333] | 459 | } | 
|---|
|  | 460 | } | 
|---|
|  | 461 | string nobj; | 
|---|
|  | 462 | string nrep; | 
|---|
|  | 463 | char buff[32]; | 
|---|
|  | 464 | int did = ParseObjectName(nom, nrep, nobj); | 
|---|
|  | 465 | if (did == 0) { | 
|---|
|  | 466 | if (!crd) { | 
|---|
|  | 467 | cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl; | 
|---|
| [344] | 468 | return(false); | 
|---|
| [333] | 469 | } | 
|---|
|  | 470 | else { CreateDir(nrep);  did =  myDirId; } | 
|---|
|  | 471 | } | 
|---|
| [165] | 472 |  | 
|---|
| [466] | 473 | // Si c'est le repertoire /autoc, on nettoie | 
|---|
|  | 474 | if (nrep == "autoc")  { | 
|---|
| [368] | 475 | CleanDir(nrep); | 
|---|
|  | 476 | } | 
|---|
|  | 477 |  | 
|---|
| [165] | 478 | myNObj++; | 
|---|
| [333] | 479 | if (nobj.length() < 1) { | 
|---|
|  | 480 | sprintf(buff,"O%d", myNObj); | 
|---|
|  | 481 | nobj = buff; | 
|---|
|  | 482 | } | 
|---|
|  | 483 |  | 
|---|
|  | 484 | nom = '/' + nrep + '/' + nobj; | 
|---|
| [344] | 485 | NObjDirList::iterator itr = myDirs->find(nrep); | 
|---|
|  | 486 | if ((*itr).second.lock) { | 
|---|
|  | 487 | cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl; | 
|---|
|  | 488 | return(false); | 
|---|
|  | 489 | } | 
|---|
| [333] | 490 | it = myObjs->find(nom); | 
|---|
| [165] | 491 | if (it != myObjs->end()) { // l'objet existe deja | 
|---|
| [466] | 492 | if (nrep == "autoc") {  // Dans /autoc , on garde les objets affiches, donc del. par Clean | 
|---|
| [368] | 493 | sprintf(buff, "%d", (*it).second.oid); | 
|---|
| [466] | 494 | string nomnew = "/autoc/" + nobj + buff; | 
|---|
| [368] | 495 | RenameObj(nom, nomnew); | 
|---|
|  | 496 | } | 
|---|
|  | 497 | else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old | 
|---|
| [333] | 498 | string on,od; | 
|---|
| [335] | 499 | //    ParseObjectName((*it).first, od, on); | 
|---|
| [333] | 500 | sprintf(buff, "%d", (*it).second.oid); | 
|---|
| [335] | 501 | string nomnew = "/old/" + nobj + buff; | 
|---|
| [333] | 502 | RenameObj(nom, nomnew); | 
|---|
|  | 503 | } | 
|---|
| [344] | 504 | else {  // Sinon, on remplace l'objet | 
|---|
|  | 505 | cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl; | 
|---|
|  | 506 | DelObj(nom); | 
|---|
|  | 507 | } | 
|---|
| [165] | 508 | } | 
|---|
|  | 509 |  | 
|---|
|  | 510 | nobj_item no; | 
|---|
|  | 511 | no.obj = obj; | 
|---|
| [295] | 512 | no.obja = servnobjm->GetAdapter(obj);  // L'adaptateur | 
|---|
| [333] | 513 | no.oid =  myNObj; | 
|---|
|  | 514 | no.dirid = did; | 
|---|
| [331] | 515 | (*myObjs)[nom] = no; | 
|---|
| [333] | 516 |  | 
|---|
|  | 517 | (*itr).second.nobj++; | 
|---|
|  | 518 |  | 
|---|
| [685] | 519 | if ( (myImgApp != NULL) && (myImgApp->ObjMgrW())->Visible() ) { | 
|---|
|  | 520 | string oln = nobj + "  (T= " + typeid(*obj).name() + ")" ; | 
|---|
|  | 521 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid); | 
|---|
|  | 522 | } | 
|---|
| [449] | 523 | if (verbeux) cout << "NamedObjMgr::AddObj()  Object " << nom << " ( " | 
|---|
| [295] | 524 | << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl; | 
|---|
| [344] | 525 | return(true); | 
|---|
| [165] | 526 | } | 
|---|
|  | 527 |  | 
|---|
|  | 528 | /* --Methode-- */ | 
|---|
| [344] | 529 | bool NamedObjMgr::RenameObj(string & nom, string& nomnew) | 
|---|
| [165] | 530 | { | 
|---|
| [333] | 531 | string n1,r1,n2,r2; | 
|---|
| [344] | 532 | int dids = ParseObjectName(nom, r1, n1); | 
|---|
|  | 533 | NObjDirList::iterator itr1 = myDirs->find(r1); | 
|---|
| [333] | 534 | int did = ParseObjectName(nomnew, r2, n2); | 
|---|
| [344] | 535 | NObjDirList::iterator itr2 = myDirs->find(r2); | 
|---|
|  | 536 |  | 
|---|
| [333] | 537 | if (did == 0) { | 
|---|
|  | 538 | cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl; | 
|---|
| [344] | 539 | return(false); | 
|---|
| [333] | 540 | } | 
|---|
|  | 541 | nom = '/' + r1 + '/' + n1; | 
|---|
|  | 542 | nomnew = '/' + r2 + '/' + n2; | 
|---|
|  | 543 | NObjList::iterator it1 = myObjs->find(nom); | 
|---|
|  | 544 | if (it1 == myObjs->end()) { | 
|---|
|  | 545 | cout << "NamedObjMgr::RenameObj() Error -  No " << nom << " object !" << endl; | 
|---|
| [344] | 546 | return(false); | 
|---|
| [333] | 547 | } | 
|---|
|  | 548 | NObjList::iterator it2 = myObjs->find(nomnew); | 
|---|
|  | 549 | if (it2 != myObjs->end()) { | 
|---|
|  | 550 | cout << "NamedObjMgr::RenameObj() Error -  Object " << nomnew << " exist !" << endl; | 
|---|
| [344] | 551 | return(false); | 
|---|
| [333] | 552 | } | 
|---|
|  | 553 |  | 
|---|
| [344] | 554 | if ( (*itr1).second.lock || (*itr2).second.lock ) { | 
|---|
|  | 555 | cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !" | 
|---|
|  | 556 | << endl; | 
|---|
|  | 557 | return(false); | 
|---|
|  | 558 | } | 
|---|
|  | 559 |  | 
|---|
|  | 560 |  | 
|---|
| [333] | 561 | nobj_item no = (*it1).second; | 
|---|
|  | 562 | no.dirid = did; | 
|---|
|  | 563 | myObjs->erase(it1); | 
|---|
|  | 564 | NObjDirList::iterator itr = myDirs->find(r1); | 
|---|
|  | 565 | (*itr).second.nobj--; | 
|---|
|  | 566 | (*myObjs)[nomnew] = no; | 
|---|
|  | 567 | itr = myDirs->find(r2); | 
|---|
|  | 568 | (*itr).second.nobj++; | 
|---|
| [685] | 569 |  | 
|---|
|  | 570 | if ( (myImgApp != NULL) && (myImgApp->ObjMgrW())->Visible() ) { | 
|---|
|  | 571 | (myImgApp->ObjMgrW())->DelObjList(dids, no.oid); | 
|---|
|  | 572 | string oln = n2 + "  (T= " + typeid(*(no.obj)).name() + ")" ; | 
|---|
|  | 573 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid); | 
|---|
|  | 574 | } | 
|---|
| [449] | 575 | if (verbeux) | 
|---|
|  | 576 | cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl; | 
|---|
| [344] | 577 | return(true); | 
|---|
| [331] | 578 | } | 
|---|
|  | 579 |  | 
|---|
|  | 580 | /* --Methode-- */ | 
|---|
| [463] | 581 | bool NamedObjMgr::CopyObj(string & nom, string& nomcp) | 
|---|
|  | 582 | { | 
|---|
|  | 583 | if(nomcp.length()<=0) | 
|---|
|  | 584 | {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl; | 
|---|
|  | 585 | return(false);} | 
|---|
|  | 586 | NObjMgrAdapter* obnom = GetObjAdapter(nom); | 
|---|
|  | 587 | if(obnom==NULL) | 
|---|
|  | 588 | {cout<<"NamedObjMgr::CopyObj() Error -  No "<<nom<<" object !"<<endl; | 
|---|
|  | 589 | return(false);} | 
|---|
| [1165] | 590 | AnyDataObj* obnomcp = obnom->CloneDataObj(); | 
|---|
| [463] | 591 | if(obnomcp==NULL) return(false); | 
|---|
|  | 592 | if(! AddObj(obnomcp,nomcp) ) {delete obnomcp; return(false);} | 
|---|
|  | 593 | return true; | 
|---|
|  | 594 | } | 
|---|
|  | 595 |  | 
|---|
| [1164] | 596 |  | 
|---|
| [463] | 597 | /* --Methode-- */ | 
|---|
| [344] | 598 | bool NamedObjMgr::DelObj(string & nom, bool fgd) | 
|---|
| [331] | 599 | { | 
|---|
| [333] | 600 | string n1,r1; | 
|---|
| [685] | 601 | int did = ParseObjectName(nom, r1, n1); | 
|---|
| [333] | 602 | nom = '/' + r1 + '/' + n1; | 
|---|
| [165] | 603 | NObjList::iterator it = myObjs->find(nom); | 
|---|
| [344] | 604 | if (it == myObjs->end()) return(false); | 
|---|
|  | 605 | NObjDirList::iterator itr = myDirs->find(r1); | 
|---|
|  | 606 | if ( (*itr).second.lock  ) { | 
|---|
|  | 607 | cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl; | 
|---|
|  | 608 | return(false); | 
|---|
|  | 609 | } | 
|---|
| [165] | 610 | list<int>::iterator ii; | 
|---|
|  | 611 | if (myImgApp) { | 
|---|
|  | 612 | //DBG  cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl; | 
|---|
|  | 613 | for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++) | 
|---|
|  | 614 | myImgApp->DelWRsId((*ii)); | 
|---|
|  | 615 | } | 
|---|
| [314] | 616 | delete (*it).second.obja;  // destruction de l'adaptateur | 
|---|
| [165] | 617 | if (fgd) delete (*it).second.obj; | 
|---|
| [333] | 618 |  | 
|---|
| [685] | 619 | if ( (myImgApp != NULL) && (myImgApp->ObjMgrW())->Visible() ) { | 
|---|
|  | 620 | int olid = (*it).second.oid; | 
|---|
|  | 621 | (myImgApp->ObjMgrW())->DelObjList(did, olid); | 
|---|
|  | 622 | } | 
|---|
| [165] | 623 | myObjs->erase(it); | 
|---|
| [333] | 624 | (*itr).second.nobj--; | 
|---|
|  | 625 |  | 
|---|
| [685] | 626 |  | 
|---|
| [449] | 627 | if (!verbeux) return(true); | 
|---|
| [165] | 628 | if (fgd) cout << "NamedObjMgr::DelObj()  Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl; | 
|---|
|  | 629 | else  cout << "NamedObjMgr::DelObj()  Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl; | 
|---|
| [344] | 630 | return(true); | 
|---|
| [165] | 631 | } | 
|---|
|  | 632 |  | 
|---|
|  | 633 | /* --Methode-- */ | 
|---|
| [344] | 634 | bool NamedObjMgr::DelObj_Id(int oid) | 
|---|
| [165] | 635 | { | 
|---|
| [333] | 636 | NObjList::iterator it; | 
|---|
|  | 637 | string nom; | 
|---|
|  | 638 | bool of = false; | 
|---|
|  | 639 | for(it = myObjs->begin(); it != myObjs->end(); it++) | 
|---|
|  | 640 | if ( (*it).second.oid == oid ) { | 
|---|
|  | 641 | of = true;  nom = (*it).first; | 
|---|
|  | 642 | break; | 
|---|
|  | 643 | } | 
|---|
| [344] | 644 | if (of) return(DelObj(nom, true)); | 
|---|
|  | 645 | else return(false); | 
|---|
| [331] | 646 | } | 
|---|
|  | 647 |  | 
|---|
|  | 648 | /* --Methode-- */ | 
|---|
|  | 649 | void NamedObjMgr::DelObjects(string & patt, bool fgd) | 
|---|
|  | 650 | { | 
|---|
| [333] | 651 | string n1,r1; | 
|---|
|  | 652 | ParseObjectName(patt, r1, n1); | 
|---|
|  | 653 | patt = '/' + r1 + '/' + n1; | 
|---|
| [165] | 654 | NObjList::iterator it; | 
|---|
|  | 655 | list<string> odel; | 
|---|
|  | 656 | string cn; | 
|---|
|  | 657 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
|  | 658 | cn = (*it).first; | 
|---|
|  | 659 | if (csh_parse(cn.c_str(), patt.c_str()) != 0)  odel.push_back(cn); | 
|---|
|  | 660 | } | 
|---|
|  | 661 | list<string>::iterator ii; | 
|---|
|  | 662 | for(ii=odel.begin(); ii != odel.end(); ii++)  DelObj(*ii, fgd); | 
|---|
|  | 663 | } | 
|---|
|  | 664 |  | 
|---|
|  | 665 | /* --Methode-- */ | 
|---|
| [331] | 666 | AnyDataObj* NamedObjMgr::GetObj(string & nom) | 
|---|
| [165] | 667 | { | 
|---|
| [333] | 668 | string n1,r1; | 
|---|
|  | 669 | ParseObjectName(nom, r1, n1); | 
|---|
|  | 670 | nom = '/' + r1 + '/' + n1; | 
|---|
| [165] | 671 | NObjList::iterator it = myObjs->find(nom); | 
|---|
|  | 672 | if (it == myObjs->end()) return(NULL); | 
|---|
|  | 673 | return((*it).second.obj); | 
|---|
|  | 674 | } | 
|---|
|  | 675 |  | 
|---|
|  | 676 | /* --Methode-- */ | 
|---|
| [331] | 677 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom) | 
|---|
| [295] | 678 | { | 
|---|
| [333] | 679 | string n1,r1; | 
|---|
|  | 680 | ParseObjectName(nom, r1, n1); | 
|---|
|  | 681 | nom = '/' + r1 + '/' + n1; | 
|---|
| [295] | 682 | NObjList::iterator it = myObjs->find(nom); | 
|---|
|  | 683 | if (it == myObjs->end()) return(NULL); | 
|---|
|  | 684 | return((*it).second.obja); | 
|---|
|  | 685 | } | 
|---|
|  | 686 |  | 
|---|
|  | 687 | /* --Methode-- */ | 
|---|
| [331] | 688 | void NamedObjMgr::ListObjs(string & patt) | 
|---|
| [165] | 689 | { | 
|---|
| [331] | 690 | int k; | 
|---|
|  | 691 | AnyDataObj* obj=NULL; | 
|---|
|  | 692 | string ctyp; | 
|---|
|  | 693 | char strg[256]; | 
|---|
|  | 694 |  | 
|---|
| [333] | 695 | string n1,r1; | 
|---|
|  | 696 | ParseObjectName(patt, r1, n1); | 
|---|
|  | 697 | patt = '/' + r1 + '/' + n1; | 
|---|
|  | 698 | cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ; | 
|---|
| [331] | 699 | NObjList::iterator it;  k = 0; | 
|---|
| [333] | 700 | string cn; | 
|---|
| [331] | 701 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
| [333] | 702 | cn = (*it).first; | 
|---|
|  | 703 | if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue; | 
|---|
| [331] | 704 | obj = (*it).second.obj; | 
|---|
|  | 705 | ctyp = typeid(*obj).name(); | 
|---|
|  | 706 | sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str()); | 
|---|
|  | 707 | ctyp = strg; | 
|---|
|  | 708 | cout << ctyp << "\n" ; | 
|---|
|  | 709 | k++; | 
|---|
|  | 710 | } | 
|---|
|  | 711 | cout << endl; | 
|---|
| [165] | 712 | return; | 
|---|
|  | 713 | } | 
|---|
|  | 714 |  | 
|---|
|  | 715 | /* --Methode-- */ | 
|---|
| [333] | 716 | void NamedObjMgr::GetObjList(string & patt, vector<string> &lst) | 
|---|
| [165] | 717 | { | 
|---|
| [333] | 718 | string n1,r1; | 
|---|
|  | 719 | if (patt.length() < 1)  return; | 
|---|
|  | 720 | bool fgr = (patt[0] == '/') ? true : false; | 
|---|
|  | 721 | ParseObjectName(patt, r1, n1); | 
|---|
|  | 722 | patt = '/' + r1 + '/' + n1; | 
|---|
|  | 723 | NObjList::iterator it; | 
|---|
|  | 724 | string cn; | 
|---|
|  | 725 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
|  | 726 | cn = (*it).first; | 
|---|
|  | 727 | if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue; | 
|---|
|  | 728 | if (fgr) lst.push_back(cn); | 
|---|
|  | 729 | else { | 
|---|
|  | 730 | ParseObjectName(cn, r1, n1); | 
|---|
|  | 731 | lst.push_back(n1); | 
|---|
|  | 732 | } | 
|---|
|  | 733 | } | 
|---|
| [165] | 734 | } | 
|---|
|  | 735 |  | 
|---|
|  | 736 | //++ | 
|---|
|  | 737 | // Titre        Entrées-Sorties (I/O) sur les objets | 
|---|
|  | 738 | //-- | 
|---|
|  | 739 | //++ | 
|---|
|  | 740 | // void  ReadObj(PInPersist& s, int num=-1) | 
|---|
|  | 741 | //      Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s" | 
|---|
|  | 742 | //      et l'ajoute à la liste. Si "num" est négatif, tous les objets présents | 
|---|
|  | 743 | //      sur le flot "s" sont créés et ajoutés à la liste. | 
|---|
|  | 744 | // void  ReadObj(string const & nomppf, string nobj="") | 
|---|
|  | 745 | //      Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté | 
|---|
|  | 746 | //      à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est | 
|---|
|  | 747 | //      composé à partir du nom de fichier. | 
|---|
|  | 748 | //-- | 
|---|
|  | 749 |  | 
|---|
|  | 750 | /* --Methode-- */ | 
|---|
| [331] | 751 | void NamedObjMgr::ReadObj(string const & flnm, string & nobj) | 
|---|
| [165] | 752 | { | 
|---|
| [495] | 753 | PPersist* ppobj=NULL; | 
|---|
| [165] | 754 | bool ok = true; | 
|---|
| [495] | 755 | #ifdef SANS_EVOLPLANCK | 
|---|
| [165] | 756 | TRY{ | 
|---|
|  | 757 | PInPersist pis(flnm); | 
|---|
| [495] | 758 | ppobj = PPersistMgr::ReadObject(pis); | 
|---|
|  | 759 | if (ppobj == NULL) ok = false; | 
|---|
| [165] | 760 | }  CATCH(merr) | 
|---|
|  | 761 | { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", | 
|---|
|  | 762 | (long)merr, PeidaExc(merr));  ok = false; } ENDTRY; | 
|---|
| [495] | 763 | #else | 
|---|
|  | 764 | try { | 
|---|
|  | 765 | PInPersist pis(flnm); | 
|---|
|  | 766 | ppobj = pis.ReadObject(); | 
|---|
|  | 767 | } | 
|---|
|  | 768 | catch (IOExc iox) { | 
|---|
|  | 769 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
|  | 770 | ok = false; | 
|---|
|  | 771 | } | 
|---|
|  | 772 | #endif | 
|---|
| [165] | 773 | if (!ok)  return; | 
|---|
|  | 774 | if (nobj.length()<1)  nobj = servnobjm->FileName2Name(flnm); | 
|---|
| [495] | 775 | AddObj(ppobj->DataObj(), nobj, true); | 
|---|
| [685] | 776 | cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl; | 
|---|
| [165] | 777 | return; | 
|---|
|  | 778 | } | 
|---|
|  | 779 |  | 
|---|
|  | 780 | /* --Methode-- */ | 
|---|
|  | 781 | void NamedObjMgr::ReadObj(PInPersist& s, int num) | 
|---|
|  | 782 | { | 
|---|
| [380] | 783 | int_4 i, cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey | 
|---|
| [165] | 784 | int n0, n1; | 
|---|
|  | 785 | bool ok = true; | 
|---|
|  | 786 | PPersist* obj=NULL; | 
|---|
|  | 787 | string nom; | 
|---|
|  | 788 |  | 
|---|
| [449] | 789 | int nread = 0; | 
|---|
| [165] | 790 | if ( (s.NbTags() < 1) || (num >= s.NbTags()) ) { | 
|---|
|  | 791 | if (num >= 0) { | 
|---|
| [495] | 792 | cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << "  Error! NbTags =" | 
|---|
|  | 793 | << s.NbTags() << endl; | 
|---|
| [165] | 794 | return; | 
|---|
|  | 795 | } | 
|---|
| [495] | 796 |  | 
|---|
|  | 797 | #ifdef SANS_EVOLPLANCK | 
|---|
| [165] | 798 | TRY { | 
|---|
|  | 799 | obj = PPersistMgr::ReadObject(s); | 
|---|
|  | 800 | if (obj == NULL)  ok = false; | 
|---|
|  | 801 | }  CATCH(merr) { | 
|---|
|  | 802 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr)); | 
|---|
|  | 803 | ok = false; | 
|---|
|  | 804 | } ENDTRY; | 
|---|
| [495] | 805 | #else | 
|---|
|  | 806 | try { | 
|---|
|  | 807 | obj = s.ReadObject(); | 
|---|
|  | 808 | } | 
|---|
|  | 809 | catch (IOExc iox) { | 
|---|
|  | 810 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
|  | 811 | ok = false; | 
|---|
|  | 812 | } | 
|---|
|  | 813 | #endif | 
|---|
|  | 814 |  | 
|---|
| [165] | 815 | if (!ok)  return; | 
|---|
|  | 816 | nom = ""; | 
|---|
| [295] | 817 | AddObj(obj->DataObj(), nom); | 
|---|
| [449] | 818 | nread++; | 
|---|
| [165] | 819 | } | 
|---|
|  | 820 |  | 
|---|
|  | 821 | if (num < 0) { n0 = 0; n1 = s.NbTags(); } | 
|---|
|  | 822 | else { n0 = num; n1 = num+1; } | 
|---|
|  | 823 | for(i=n0; i<n1; i++) { | 
|---|
| [495] | 824 | #ifdef SANS_EVOLPLANCK | 
|---|
| [165] | 825 | key = s.TagKey(i, cid, ln); | 
|---|
|  | 826 | if (ln <= 0)  nom = ""; | 
|---|
|  | 827 | else nom = s.TagName(i); | 
|---|
|  | 828 | s.GotoTag(i); | 
|---|
|  | 829 | TRY { | 
|---|
|  | 830 | obj = PPersistMgr::ReadObject(s); | 
|---|
|  | 831 | if (obj == NULL)  ok = false; | 
|---|
|  | 832 | }  CATCH(merr) { | 
|---|
|  | 833 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr)); | 
|---|
|  | 834 | ok = false; | 
|---|
|  | 835 | } ENDTRY; | 
|---|
| [495] | 836 | #else | 
|---|
|  | 837 | s.GotoTagNum(i); | 
|---|
| [584] | 838 | nom = s.GetTagName(i); | 
|---|
| [495] | 839 | try { | 
|---|
|  | 840 | obj = s.ReadObject(); | 
|---|
|  | 841 | } | 
|---|
|  | 842 | catch (IOExc iox) { | 
|---|
|  | 843 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
|  | 844 | ok = false; | 
|---|
|  | 845 | } | 
|---|
|  | 846 | #endif | 
|---|
| [449] | 847 | if (ok)  { AddObj(obj->DataObj(), nom, true);  nread++; } | 
|---|
| [165] | 848 | } | 
|---|
|  | 849 |  | 
|---|
| [449] | 850 | cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl; | 
|---|
| [165] | 851 | return; | 
|---|
|  | 852 | } | 
|---|
|  | 853 | /* --Methode-- */ | 
|---|
|  | 854 | void NamedObjMgr::ReadAll(string const & flnm) | 
|---|
|  | 855 | { | 
|---|
|  | 856 | bool ok = true; | 
|---|
|  | 857 | PPersist* obj=NULL; | 
|---|
|  | 858 |  | 
|---|
|  | 859 | PInPersist* ppin; | 
|---|
| [495] | 860 | #ifdef SANS_EVOLPLANCK | 
|---|
| [165] | 861 | TRY{ | 
|---|
|  | 862 | ppin = new PInPersist(flnm); | 
|---|
|  | 863 | if (ppin->NbTags() < 1)  obj = PPersistMgr::ReadObject((*ppin)); | 
|---|
|  | 864 | else obj = NULL; | 
|---|
|  | 865 | }  CATCH(merr) | 
|---|
|  | 866 | { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n", | 
|---|
|  | 867 | (long)merr, PeidaExc(merr));  ok = false; } ENDTRY; | 
|---|
| [495] | 868 | #else | 
|---|
|  | 869 | try { | 
|---|
|  | 870 | ppin = new PInPersist(flnm); | 
|---|
|  | 871 | if (ppin->NbTags() < 1)  obj = ppin->ReadObject(); | 
|---|
|  | 872 | else   obj = NULL; | 
|---|
|  | 873 | } | 
|---|
|  | 874 | catch (IOExc iox) { | 
|---|
|  | 875 | cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
|  | 876 | ok = false; | 
|---|
|  | 877 | } | 
|---|
|  | 878 | #endif | 
|---|
| [165] | 879 | if (!ok)  return; | 
|---|
|  | 880 | if (obj) { | 
|---|
|  | 881 | string nom = servnobjm->FileName2Name(flnm); | 
|---|
| [295] | 882 | AddObj(obj->DataObj(), nom); | 
|---|
| [165] | 883 | } | 
|---|
|  | 884 | else ReadObj((*ppin), -1); | 
|---|
|  | 885 | delete ppin; | 
|---|
|  | 886 | return; | 
|---|
|  | 887 | } | 
|---|
|  | 888 |  | 
|---|
|  | 889 | /* --Methode-- */ | 
|---|
| [331] | 890 | void NamedObjMgr::ReadFits(string const & flnm, string & nobj) | 
|---|
| [165] | 891 | { | 
|---|
| [709] | 892 | bool ok = false; | 
|---|
| [165] | 893 |  | 
|---|
| [293] | 894 | #ifdef SANS_EVOLPLANCK | 
|---|
| [709] | 895 | RzImage* obj=NULL; | 
|---|
| [495] | 896 | TRY{ | 
|---|
| [165] | 897 | obj = RzReadFits((char*)flnm.c_str()); | 
|---|
|  | 898 | if (obj == NULL)   ok = false; | 
|---|
| [709] | 899 | else ok = true; | 
|---|
| [165] | 900 | }  CATCH(merr) { | 
|---|
|  | 901 | printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr)); | 
|---|
|  | 902 | ok = false; | 
|---|
|  | 903 | } ENDTRY; | 
|---|
| [709] | 904 |  | 
|---|
|  | 905 | if (ok && (obj != NULL)) { | 
|---|
| [165] | 906 | if (nobj.length()<1)  nobj = servnobjm->FileName2Name(flnm); | 
|---|
| [295] | 907 | AddObj((AnyDataObj*)obj, nobj); | 
|---|
| [165] | 908 | } | 
|---|
| [1105] | 909 | #else | 
|---|
|  | 910 | cerr << " NamedObjMgr::ReadFits() Vide ! A faire Reza ! " << endl; | 
|---|
|  | 911 | #endif | 
|---|
|  | 912 |  | 
|---|
| [165] | 913 | return; | 
|---|
|  | 914 | } | 
|---|
|  | 915 |  | 
|---|
|  | 916 |  | 
|---|
|  | 917 | static int key_for_write = 5000; | 
|---|
|  | 918 | /* --Methode-- */ | 
|---|
| [333] | 919 | void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath) | 
|---|
| [165] | 920 | { | 
|---|
| [333] | 921 | if (nom.length() < 1) return; | 
|---|
|  | 922 | string nob,rep; | 
|---|
|  | 923 | ParseObjectName(nom, rep, nob); | 
|---|
|  | 924 | nom = '/' + rep + '/' + nob; | 
|---|
| [295] | 925 | NObjMgrAdapter* obja=NULL; | 
|---|
| [333] | 926 | string nomf = (keeppath) ? nom : nob; | 
|---|
| [295] | 927 | obja = GetObjAdapter(nom); | 
|---|
|  | 928 | if (obja == NULL)  return; | 
|---|
| [165] | 929 | printf("NamedObjMgr::SaveObj(%s, )  (Type=%s) \n", | 
|---|
| [295] | 930 | nom.c_str(), typeid(*(obja->GetDataObj())).name()); | 
|---|
| [333] | 931 | obja->SavePPF(s, nomf); | 
|---|
| [165] | 932 | return; | 
|---|
|  | 933 | } | 
|---|
|  | 934 |  | 
|---|
|  | 935 | /* --Methode-- */ | 
|---|
| [333] | 936 | void NamedObjMgr::SaveObjects(string & patt, string const& flnm) | 
|---|
|  | 937 | { | 
|---|
|  | 938 | string n1,r1; | 
|---|
|  | 939 | if (patt.length() < 1)  return; | 
|---|
|  | 940 | bool keeppath = (patt[0] == '/') ? true : false; | 
|---|
|  | 941 | ParseObjectName(patt, r1, n1); | 
|---|
|  | 942 | patt = '/' + r1 + '/' + n1; | 
|---|
|  | 943 |  | 
|---|
|  | 944 | bool ok = true; | 
|---|
|  | 945 | POutPersist* pout; | 
|---|
| [495] | 946 | #ifdef SANS_EVOLPLANCK | 
|---|
| [333] | 947 | TRY{ | 
|---|
|  | 948 | pout = new POutPersist(flnm); | 
|---|
|  | 949 | }  CATCH(merr) | 
|---|
|  | 950 | { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n", | 
|---|
|  | 951 | (long)merr, PeidaExc(merr));  ok = false; } ENDTRY; | 
|---|
| [495] | 952 | #else | 
|---|
|  | 953 | try { | 
|---|
|  | 954 | pout = new POutPersist(flnm); | 
|---|
|  | 955 | } | 
|---|
|  | 956 | catch (IOExc iox) { | 
|---|
|  | 957 | cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
|  | 958 | ok = false; | 
|---|
|  | 959 | } | 
|---|
|  | 960 | #endif | 
|---|
| [333] | 961 | if (!ok)  return; | 
|---|
|  | 962 | NObjList::iterator it; | 
|---|
|  | 963 | string cn; | 
|---|
|  | 964 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
|  | 965 | cn = (*it).first; | 
|---|
|  | 966 | if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue; | 
|---|
|  | 967 | SaveObj(cn, (*pout), keeppath); | 
|---|
|  | 968 | } | 
|---|
|  | 969 | delete pout; | 
|---|
|  | 970 | return; | 
|---|
|  | 971 | } | 
|---|
|  | 972 |  | 
|---|
|  | 973 | /* --Methode-- */ | 
|---|
| [165] | 974 | void NamedObjMgr::SaveAll(string const& flnm) | 
|---|
|  | 975 | { | 
|---|
|  | 976 | bool ok = true; | 
|---|
|  | 977 |  | 
|---|
|  | 978 | POutPersist* pout; | 
|---|
| [495] | 979 | #ifdef SANS_EVOLPLANCK | 
|---|
| [165] | 980 | TRY{ | 
|---|
|  | 981 | pout = new POutPersist(flnm); | 
|---|
|  | 982 | }  CATCH(merr) | 
|---|
|  | 983 | { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n", | 
|---|
|  | 984 | (long)merr, PeidaExc(merr));  ok = false; } ENDTRY; | 
|---|
| [495] | 985 | #else | 
|---|
|  | 986 | try { | 
|---|
|  | 987 | pout = new POutPersist(flnm); | 
|---|
|  | 988 | } | 
|---|
|  | 989 | catch (IOExc iox) { | 
|---|
|  | 990 | cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl; | 
|---|
|  | 991 | ok = false; | 
|---|
|  | 992 | } | 
|---|
|  | 993 | #endif | 
|---|
| [165] | 994 | if (!ok)  return; | 
|---|
| [332] | 995 | NObjList::iterator it; | 
|---|
|  | 996 | string no; | 
|---|
|  | 997 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
|  | 998 | no = (*it).first; | 
|---|
| [333] | 999 | SaveObj(no, (*pout), true); | 
|---|
| [332] | 1000 | } | 
|---|
| [165] | 1001 | delete pout; | 
|---|
|  | 1002 | return; | 
|---|
|  | 1003 | } | 
|---|
|  | 1004 |  | 
|---|
|  | 1005 | /* --Methode-- */ | 
|---|
| [331] | 1006 | void NamedObjMgr::SaveFits(string& nom, string const & flnm) | 
|---|
| [165] | 1007 | { | 
|---|
| [295] | 1008 | NObjMgrAdapter* obja=NULL; | 
|---|
|  | 1009 | obja = GetObjAdapter(nom); | 
|---|
|  | 1010 | if (obja == NULL)  return; | 
|---|
|  | 1011 | obja->SaveFits(flnm); | 
|---|
| [293] | 1012 | return; | 
|---|
| [165] | 1013 | } | 
|---|
|  | 1014 |  | 
|---|
|  | 1015 |  | 
|---|
|  | 1016 |  | 
|---|
|  | 1017 | /* --Methode-- */ | 
|---|
| [331] | 1018 | void NamedObjMgr::PrintObj(string& nom) | 
|---|
| [165] | 1019 | { | 
|---|
| [295] | 1020 | NObjMgrAdapter* obja=NULL; | 
|---|
|  | 1021 | obja = GetObjAdapter(nom); | 
|---|
|  | 1022 | if (obja == NULL)  return; | 
|---|
| [594] | 1023 | AnyDataObj* ob = obja->GetDataObj(); | 
|---|
|  | 1024 | if (ob == NULL) { | 
|---|
|  | 1025 | cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl; | 
|---|
|  | 1026 | return; | 
|---|
|  | 1027 | } | 
|---|
|  | 1028 | string ctyp = typeid(*ob).name(); | 
|---|
| [295] | 1029 | cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl; | 
|---|
|  | 1030 | obja->Print(cout); | 
|---|
| [165] | 1031 |  | 
|---|
|  | 1032 | return; | 
|---|
|  | 1033 | } | 
|---|
|  | 1034 |  | 
|---|
|  | 1035 | /* --Methode-- */ | 
|---|
| [331] | 1036 | void NamedObjMgr::DisplayObj(string& nom, string dopt) | 
|---|
| [165] | 1037 | { | 
|---|
| [295] | 1038 | NObjMgrAdapter* obja=NULL; | 
|---|
|  | 1039 | obja = GetObjAdapter(nom); | 
|---|
|  | 1040 | if (obja == NULL) { | 
|---|
| [594] | 1041 | cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl; | 
|---|
| [165] | 1042 | return; | 
|---|
|  | 1043 | } | 
|---|
| [594] | 1044 | if (obja->GetDataObj() == NULL) { | 
|---|
|  | 1045 | cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl; | 
|---|
|  | 1046 | return; | 
|---|
|  | 1047 | } | 
|---|
| [165] | 1048 | if (!myImgApp)  return; | 
|---|
|  | 1049 |  | 
|---|
| [295] | 1050 | PIDrawer * dr = NULL; | 
|---|
|  | 1051 | P2DArrayAdapter* arr = NULL; | 
|---|
|  | 1052 | dr = obja->GetDrawer(dopt); | 
|---|
|  | 1053 | if (!dr) arr = obja->Get2DArray(dopt); | 
|---|
| [165] | 1054 |  | 
|---|
| [295] | 1055 | if (!dr && !arr) { | 
|---|
|  | 1056 | string ctyp = typeid(*(obja->GetDataObj())).name(); | 
|---|
| [594] | 1057 | cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl; | 
|---|
| [295] | 1058 | return; | 
|---|
|  | 1059 | } | 
|---|
|  | 1060 |  | 
|---|
| [165] | 1061 | int wrsid = 0; | 
|---|
|  | 1062 | bool fgsr = true; | 
|---|
|  | 1063 | int opt = servnobjm->DecodeDispOption(dopt, fgsr); | 
|---|
|  | 1064 |  | 
|---|
| [344] | 1065 | string n1,r1; | 
|---|
|  | 1066 | ParseObjectName(nom, r1, n1); | 
|---|
|  | 1067 |  | 
|---|
| [295] | 1068 | if (dr) { | 
|---|
|  | 1069 | PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr); | 
|---|
| [344] | 1070 | if(dr3)  wrsid = myImgApp->Disp3DDrawer(dr3, n1, opt); | 
|---|
|  | 1071 | else wrsid = myImgApp->DispScDrawer( dr, n1, opt); | 
|---|
| [295] | 1072 | } | 
|---|
| [344] | 1073 | else if (arr) wrsid = myImgApp->DispImage(arr, n1, opt); | 
|---|
| [165] | 1074 |  | 
|---|
| [295] | 1075 | if(wrsid != 0) { | 
|---|
|  | 1076 | NObjList::iterator it = myObjs->find(nom); | 
|---|
|  | 1077 | if (it == myObjs->end()) return; | 
|---|
|  | 1078 | (*it).second.wrsid.push_back(wrsid); | 
|---|
|  | 1079 | } | 
|---|
|  | 1080 | if (fgsr) myImgApp->RestoreGraphicAtt(); | 
|---|
|  | 1081 | return; | 
|---|
|  | 1082 | } | 
|---|
| [165] | 1083 |  | 
|---|
| [295] | 1084 | /* --Methode-- */ | 
|---|
| [331] | 1085 | void NamedObjMgr::DisplayImage(string& nom, string dopt) | 
|---|
| [295] | 1086 | { | 
|---|
|  | 1087 | NObjMgrAdapter* obja=NULL; | 
|---|
|  | 1088 | obja = GetObjAdapter(nom); | 
|---|
|  | 1089 | if (obja == NULL) { | 
|---|
| [449] | 1090 | cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl; | 
|---|
| [295] | 1091 | return; | 
|---|
|  | 1092 | } | 
|---|
| [594] | 1093 | if (obja->GetDataObj() == NULL) { | 
|---|
|  | 1094 | cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl; | 
|---|
|  | 1095 | return; | 
|---|
|  | 1096 | } | 
|---|
| [295] | 1097 | if (!myImgApp)  return; | 
|---|
|  | 1098 |  | 
|---|
|  | 1099 | P2DArrayAdapter* arr = obja->Get2DArray(dopt); | 
|---|
| [165] | 1100 |  | 
|---|
| [295] | 1101 | if (!arr) { | 
|---|
|  | 1102 | string ctyp = typeid(*(obja->GetDataObj())).name(); | 
|---|
| [449] | 1103 | cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl; | 
|---|
| [295] | 1104 | return; | 
|---|
|  | 1105 | } | 
|---|
| [165] | 1106 |  | 
|---|
| [344] | 1107 | string n1,r1; | 
|---|
|  | 1108 | ParseObjectName(nom, r1, n1); | 
|---|
|  | 1109 |  | 
|---|
| [295] | 1110 | int wrsid = 0; | 
|---|
|  | 1111 | bool fgsr = true; | 
|---|
|  | 1112 | int opt = servnobjm->DecodeDispOption(dopt, fgsr); | 
|---|
| [344] | 1113 | wrsid = myImgApp->DispImage(arr, n1, opt); | 
|---|
| [165] | 1114 |  | 
|---|
| [295] | 1115 | if(wrsid != 0) { | 
|---|
|  | 1116 | NObjList::iterator it = myObjs->find(nom); | 
|---|
|  | 1117 | if (it == myObjs->end()) return; | 
|---|
|  | 1118 | (*it).second.wrsid.push_back(wrsid); | 
|---|
|  | 1119 | } | 
|---|
|  | 1120 | if (fgsr) myImgApp->RestoreGraphicAtt(); | 
|---|
|  | 1121 | return; | 
|---|
|  | 1122 | } | 
|---|
|  | 1123 | /* --Methode-- */ | 
|---|
| [331] | 1124 | void NamedObjMgr::DisplaySurf3D(string& nom, string dopt) | 
|---|
| [295] | 1125 | { | 
|---|
|  | 1126 | NObjMgrAdapter* obja=NULL; | 
|---|
|  | 1127 | obja = GetObjAdapter(nom); | 
|---|
|  | 1128 | if (obja == NULL) { | 
|---|
| [449] | 1129 | cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl; | 
|---|
| [295] | 1130 | return; | 
|---|
|  | 1131 | } | 
|---|
| [594] | 1132 | if (obja->GetDataObj() == NULL) { | 
|---|
|  | 1133 | cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl; | 
|---|
|  | 1134 | return; | 
|---|
|  | 1135 | } | 
|---|
| [295] | 1136 | if (!myImgApp)  return; | 
|---|
|  | 1137 |  | 
|---|
|  | 1138 | P2DArrayAdapter* arr = obja->Get2DArray(dopt); | 
|---|
| [165] | 1139 |  | 
|---|
| [295] | 1140 | if (!arr) { | 
|---|
|  | 1141 | string ctyp = typeid(*(obja->GetDataObj())).name(); | 
|---|
| [449] | 1142 | cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl; | 
|---|
| [295] | 1143 | return; | 
|---|
|  | 1144 | } | 
|---|
| [165] | 1145 |  | 
|---|
| [295] | 1146 | if ((arr->XSize() > 250) || (arr->YSize() > 250)) { | 
|---|
|  | 1147 | cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" <<  arr->XSize() | 
|---|
| [449] | 1148 | << "x" << arr->YSize() << ") too big (max=250x250)" << endl; | 
|---|
| [295] | 1149 | delete arr; | 
|---|
|  | 1150 | return; | 
|---|
| [165] | 1151 | } | 
|---|
|  | 1152 |  | 
|---|
| [344] | 1153 | string n1,r1; | 
|---|
|  | 1154 | ParseObjectName(nom, r1, n1); | 
|---|
|  | 1155 |  | 
|---|
| [295] | 1156 | int wrsid = 0; | 
|---|
|  | 1157 | bool fgsr = true; | 
|---|
|  | 1158 | int opt = servnobjm->DecodeDispOption(dopt, fgsr); | 
|---|
|  | 1159 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true); | 
|---|
| [344] | 1160 | wrsid = myImgApp->Disp3DDrawer(sdr, n1, opt); | 
|---|
| [295] | 1161 | if(wrsid >= 0) { | 
|---|
| [165] | 1162 | NObjList::iterator it = myObjs->find(nom); | 
|---|
|  | 1163 | if (it == myObjs->end()) return; | 
|---|
|  | 1164 | (*it).second.wrsid.push_back(wrsid); | 
|---|
|  | 1165 | } | 
|---|
| [295] | 1166 |  | 
|---|
|  | 1167 | if (fgsr) myImgApp->RestoreGraphicAtt(); | 
|---|
|  | 1168 | return; | 
|---|
| [165] | 1169 | } | 
|---|
|  | 1170 |  | 
|---|
|  | 1171 | /* --Methode-- */ | 
|---|
| [331] | 1172 | void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz, | 
|---|
| [486] | 1173 | string& erx, string& ery, string& erz, string& wt, | 
|---|
|  | 1174 | string& label, string dopt, bool fg3d) | 
|---|
| [165] | 1175 | { | 
|---|
| [295] | 1176 | AnyDataObj* obj=GetObj(nom); | 
|---|
| [165] | 1177 | if (obj == NULL) { | 
|---|
| [449] | 1178 | cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl; | 
|---|
| [165] | 1179 | return; | 
|---|
|  | 1180 | } | 
|---|
|  | 1181 | if (!myImgApp)  return; | 
|---|
|  | 1182 |  | 
|---|
| [326] | 1183 | NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj); | 
|---|
|  | 1184 | if (nt == NULL) { | 
|---|
|  | 1185 | // if (typeid(*obj) != typeid(NTupleInterface)) { | 
|---|
| [295] | 1186 | string ctyp = typeid(*obj).name(); | 
|---|
| [449] | 1187 | cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl; | 
|---|
| [165] | 1188 | return; | 
|---|
|  | 1189 | } | 
|---|
|  | 1190 |  | 
|---|
|  | 1191 | int wrsid = 0; | 
|---|
|  | 1192 | bool fgsr = true; | 
|---|
| [326] | 1193 | dopt = "defline," + dopt; | 
|---|
| [165] | 1194 | int opt = servnobjm->DecodeDispOption(dopt, fgsr); | 
|---|
|  | 1195 |  | 
|---|
| [344] | 1196 | string n1,r1; | 
|---|
|  | 1197 | ParseObjectName(nom, r1, n1); | 
|---|
|  | 1198 |  | 
|---|
| [333] | 1199 | if ( fg3d && (nmz.length()>0) )  { // Display 3D | 
|---|
| [326] | 1200 | PINTuple3D* pin = new PINTuple3D(nt, false); | 
|---|
| [165] | 1201 | pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str()); | 
|---|
| [486] | 1202 | pin->SelectWt(wt.c_str()); | 
|---|
|  | 1203 | pin->SelectLabel(label.c_str()); | 
|---|
| [165] | 1204 | pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str()); | 
|---|
|  | 1205 | string titre = nmz + "%" + nmy + "%" + nmz; | 
|---|
| [344] | 1206 | wrsid = myImgApp->Disp3DDrawer(pin, n1, opt, titre); | 
|---|
| [165] | 1207 | } | 
|---|
|  | 1208 | else { | 
|---|
| [326] | 1209 | PINTuple* pin = new PINTuple(nt, false); | 
|---|
| [546] | 1210 | pin->SetStats(Services2NObjMgr::GetStatsOption(dopt)); | 
|---|
| [165] | 1211 | pin->SelectXY(nmx.c_str(), nmy.c_str()); | 
|---|
| [486] | 1212 | pin->SelectWt(wt.c_str()); | 
|---|
|  | 1213 | pin->SelectLabel(label.c_str()); | 
|---|
| [165] | 1214 | pin->SelectErrBar(erx.c_str(), ery.c_str()); | 
|---|
| [333] | 1215 | string titre = nmy + "%" + nmx; | 
|---|
| [344] | 1216 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, opt, titre); | 
|---|
| [165] | 1217 | } | 
|---|
|  | 1218 |  | 
|---|
|  | 1219 | if(wrsid >= 0) { | 
|---|
|  | 1220 | NObjList::iterator it = myObjs->find(nom); | 
|---|
|  | 1221 | if (it == myObjs->end()) return; | 
|---|
|  | 1222 | (*it).second.wrsid.push_back(wrsid); | 
|---|
|  | 1223 | } | 
|---|
|  | 1224 |  | 
|---|
|  | 1225 | if (fgsr) myImgApp->RestoreGraphicAtt(); | 
|---|
|  | 1226 | return; | 
|---|
|  | 1227 | } | 
|---|
|  | 1228 |  | 
|---|
| [339] | 1229 | /* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */ | 
|---|
| [331] | 1230 | void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt) | 
|---|
| [165] | 1231 | //      Pour le display 2D ou 3D d'un ``GeneralFitData''. | 
|---|
|  | 1232 | //|  nom = nom de l'objet GeneralFitData a representer. | 
|---|
|  | 1233 | //|  numvarx = numero (nombre entier) de la 1ere variable d'abscisse. | 
|---|
|  | 1234 | //|  numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D). | 
|---|
|  | 1235 | //|            Pour le display 2D, numvary="" string vide. | 
|---|
|  | 1236 | //|  err = qu'elles erreurs faut il representer ? | 
|---|
|  | 1237 | //|      - 2D : x y xy   (display y=f(x)) | 
|---|
|  | 1238 | //|      - 3D : x y z xy xz yz xzy   (display z=f(x,y)) | 
|---|
|  | 1239 | //|      Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes | 
|---|
|  | 1240 | //|      les barres d'erreurs sont representees. | 
|---|
|  | 1241 | //|  opt = options generales pour le display. | 
|---|
|  | 1242 | { | 
|---|
| [295] | 1243 | AnyDataObj* obj=GetObj(nom); | 
|---|
| [165] | 1244 | if(obj == NULL) | 
|---|
| [449] | 1245 | {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl; | 
|---|
| [165] | 1246 | return;} | 
|---|
|  | 1247 | if(!myImgApp) return; | 
|---|
| [295] | 1248 | if(typeid(*obj) != typeid(GeneralFitData)) | 
|---|
|  | 1249 | {string ctyp = typeid(*obj).name(); | 
|---|
| [449] | 1250 | cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl; | 
|---|
| [165] | 1251 | return;} | 
|---|
|  | 1252 |  | 
|---|
|  | 1253 | // Decodage des options classiques | 
|---|
|  | 1254 | bool fgsr = true; | 
|---|
|  | 1255 | int opt = servnobjm->DecodeDispOption(dopt, fgsr); | 
|---|
|  | 1256 | // Decodage des erreurs a representer | 
|---|
|  | 1257 | bool errx=false, erry=false, errz=false; | 
|---|
|  | 1258 | if(err.length()>0) { | 
|---|
|  | 1259 | for(int i=0;i<err.length();i++) | 
|---|
|  | 1260 | if     (err[i]=='x' || err[i]=='X') errx = true; | 
|---|
|  | 1261 | else if(err[i]=='y' || err[i]=='Y') erry = true; | 
|---|
|  | 1262 | else if(err[i]=='z' || err[i]=='Z') errz = true; | 
|---|
|  | 1263 | } | 
|---|
|  | 1264 | // Decodage des numeros de variables en abscisse | 
|---|
| [339] | 1265 | int numvx=-1, numvy=-1; | 
|---|
|  | 1266 | if(numvarx.length()>0) numvx = atoi(numvarx.c_str()); | 
|---|
|  | 1267 | if(numvary.length()>0) numvy = atoi(numvary.c_str()); | 
|---|
|  | 1268 |  | 
|---|
| [344] | 1269 | string n1,r1; | 
|---|
|  | 1270 | ParseObjectName(nom, r1, n1); | 
|---|
|  | 1271 |  | 
|---|
| [339] | 1272 | int wrsid = 0; | 
|---|
|  | 1273 | if(numvy>=0) {              // display 3D | 
|---|
| [165] | 1274 | PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false); | 
|---|
|  | 1275 | pigfd->SelectXY(numvx,numvy); | 
|---|
|  | 1276 | pigfd->SelectErrBar(errx,erry,errz); | 
|---|
| [344] | 1277 | wrsid = myImgApp->Disp3DDrawer(pigfd,n1,opt); | 
|---|
| [339] | 1278 | } else {                   // display 2D | 
|---|
| [165] | 1279 | PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false); | 
|---|
|  | 1280 | pigfd->SelectX(numvx); | 
|---|
|  | 1281 | pigfd->SelectErrBar(errx,erry); | 
|---|
| [344] | 1282 | wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,opt); | 
|---|
| [165] | 1283 | } | 
|---|
|  | 1284 |  | 
|---|
|  | 1285 | if(wrsid >= 0) { | 
|---|
|  | 1286 | NObjList::iterator it = myObjs->find(nom); | 
|---|
|  | 1287 | if (it == myObjs->end()) return; | 
|---|
|  | 1288 | (*it).second.wrsid.push_back(wrsid); | 
|---|
|  | 1289 | } | 
|---|
|  | 1290 | if (fgsr) myImgApp->RestoreGraphicAtt(); | 
|---|
|  | 1291 | return; | 
|---|
|  | 1292 | } | 
|---|
|  | 1293 |  | 
|---|
|  | 1294 | /* --Methode-- | 
|---|
| [331] | 1295 | void NamedObjMgr::DisplayImage(string& nom, string dopt) | 
|---|
| [165] | 1296 | { | 
|---|
|  | 1297 | cout << "NamedObjMgr::DisplayImage() a faire ! " << endl; | 
|---|
|  | 1298 | } | 
|---|
|  | 1299 | */ | 
|---|
|  | 1300 |  | 
|---|
|  | 1301 |  | 
|---|
|  | 1302 |  | 
|---|
|  | 1303 |  | 
|---|
|  | 1304 | /* --Methode-- */ | 
|---|
|  | 1305 | void NamedObjMgr::SetGraphicAttributes(string gratt) | 
|---|
|  | 1306 | { | 
|---|
|  | 1307 | bool fg = false; | 
|---|
|  | 1308 | servnobjm->DecodeDispOption(gratt, fg); | 
|---|
| [546] | 1309 | Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt)); | 
|---|
| [165] | 1310 | } | 
|---|
| [333] | 1311 |  | 
|---|
| [165] | 1312 | /* --Methode-- */ | 
|---|
|  | 1313 | void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr) | 
|---|
|  | 1314 | { | 
|---|
|  | 1315 | if (!myImgApp)  return; | 
|---|
|  | 1316 | if (fcr)  myImgApp->CreateGraphWin(nzx, nzy); | 
|---|
|  | 1317 | else myImgApp->SetZone(nzx, nzy); | 
|---|
|  | 1318 | } | 
|---|
|  | 1319 |  | 
|---|
|  | 1320 | /* --Methode-- */ | 
|---|
| [333] | 1321 | void NamedObjMgr::AddWRsId(string & nom, int wrsid) | 
|---|
| [165] | 1322 | { | 
|---|
| [333] | 1323 | if(wrsid != 0) { | 
|---|
|  | 1324 | NObjList::iterator it = myObjs->find(nom); | 
|---|
|  | 1325 | if (it == myObjs->end()) return; | 
|---|
|  | 1326 | (*it).second.wrsid.push_back(wrsid); | 
|---|
| [295] | 1327 | } | 
|---|
| [165] | 1328 | return; | 
|---|
|  | 1329 | } | 
|---|
|  | 1330 |  | 
|---|
|  | 1331 | /* --Methode-- */ | 
|---|
| [333] | 1332 | void NamedObjMgr::UpdateObjMgrWindow(int did) | 
|---|
| [165] | 1333 | { | 
|---|
| [333] | 1334 | if (!myImgApp)  return; | 
|---|
| [685] | 1335 | (myImgApp->ObjMgrW())->ClearObjList(); | 
|---|
| [165] | 1336 |  | 
|---|
| [333] | 1337 | NObjList::iterator it; | 
|---|
|  | 1338 | string cn; | 
|---|
|  | 1339 | for(it = myObjs->begin(); it != myObjs->end(); it++) { | 
|---|
|  | 1340 | if ((*it).second.dirid != did) continue; | 
|---|
|  | 1341 | cn = (*it).first.substr(1); | 
|---|
|  | 1342 | cn = cn.substr(cn.find('/')+1) + "  (T= " + typeid(*((*it).second.obj)).name() + ")" ; | 
|---|
| [685] | 1343 | (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid); | 
|---|
| [165] | 1344 | } | 
|---|
| [333] | 1345 | } | 
|---|
| [165] | 1346 |  | 
|---|
|  | 1347 |  | 
|---|
| [333] | 1348 | /* Nouvelle-Fonction */ | 
|---|
| [1207] | 1349 | void NamedObjMgr::RemoveSpacesFromName(string & nom) | 
|---|
| [165] | 1350 | { | 
|---|
| [333] | 1351 | // on supprime les blancs de debut et de fin | 
|---|
|  | 1352 | size_t p = nom.find_first_not_of(" "); | 
|---|
|  | 1353 | if(p>nom.length()) { nom = ""; return; } | 
|---|
|  | 1354 | nom = nom.substr(p); | 
|---|
|  | 1355 | p = nom.find(' '); | 
|---|
|  | 1356 | if(p>nom.length()) p=nom.length(); | 
|---|
|  | 1357 | nom = nom.substr(0, p); | 
|---|
| [165] | 1358 | } | 
|---|
|  | 1359 |  | 
|---|
| [333] | 1360 | /* Nouvelle-Fonction */ | 
|---|
| [1207] | 1361 | bool NamedObjMgr::CheckDirName(string & nom) | 
|---|
| [165] | 1362 | { | 
|---|
| [333] | 1363 | RemoveSpacesFromName(nom); | 
|---|
|  | 1364 | if (nom.length() < 1)  return(false); | 
|---|
|  | 1365 | if (nom[0] == '/') nom = nom.substr(1) ; | 
|---|
|  | 1366 | size_t p = nom.find('/'); | 
|---|
|  | 1367 | if (p < nom.length()) nom = nom.substr(0,p); | 
|---|
|  | 1368 | if (nom.length() < 1)  return(false); | 
|---|
|  | 1369 | return(true); | 
|---|
| [165] | 1370 | } | 
|---|
|  | 1371 |  | 
|---|
| [333] | 1372 | /* Nouvelle-Fonction */ | 
|---|
| [1207] | 1373 | int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj) | 
|---|
| [165] | 1374 | { | 
|---|
| [333] | 1375 | RemoveSpacesFromName(nom); | 
|---|
|  | 1376 | // Si le nom ne commence pas par un slash, c'est le repertoire courant | 
|---|
|  | 1377 | if (nom[0] != '/') { nomrep = *currDir;  nomobj = nom; } | 
|---|
| [165] | 1378 | else { | 
|---|
| [333] | 1379 | string xx = nom.substr(1); | 
|---|
|  | 1380 | size_t p = xx.find('/'); | 
|---|
|  | 1381 | if (p < xx.length())  { | 
|---|
|  | 1382 | nomrep = xx.substr(0,p); | 
|---|
|  | 1383 | nomobj = xx.substr(p+1); | 
|---|
| [165] | 1384 | } | 
|---|
| [333] | 1385 | else { | 
|---|
|  | 1386 | nomrep = xx; | 
|---|
|  | 1387 | nomobj = ""; | 
|---|
| [165] | 1388 | } | 
|---|
|  | 1389 | } | 
|---|
| [333] | 1390 | int rc = 0; | 
|---|
|  | 1391 | NObjDirList::iterator it = myDirs->find(nomrep); | 
|---|
|  | 1392 | if (it != myDirs->end())  rc = (*it).second.id; | 
|---|
|  | 1393 | return(rc); | 
|---|
| [165] | 1394 | } | 
|---|
|  | 1395 |  | 
|---|