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