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