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