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