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