| 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <ctype.h>
|
|---|
| 4 |
|
|---|
| 5 | #include <typeinfo>
|
|---|
| 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"
|
|---|
| 21 | #include "nomgadapter.h"
|
|---|
| 22 | #include "pistdimgapp.h"
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | // EVOL-PLANCK
|
|---|
| 26 | #ifdef SANS_EVOLPLANCK
|
|---|
| 27 | #include "fitsimage.h"
|
|---|
| 28 | #endif
|
|---|
| 29 |
|
|---|
| 30 | #include "pisurfdr.h"
|
|---|
| 31 | #include "pipodrw.h"
|
|---|
| 32 |
|
|---|
| 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 | //
|
|---|
| 44 | // Cette classe fournit les services nécéssaires à la gestion des objets
|
|---|
| 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 ............
|
|---|
| 59 | struct nobj_diritem {
|
|---|
| 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
|
|---|
| 64 | };
|
|---|
| 65 |
|
|---|
| 66 | typedef map<string, nobj_diritem, less<string> > NObjDirList;
|
|---|
| 67 |
|
|---|
| 68 | struct nobj_item {
|
|---|
| 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)
|
|---|
| 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 |
|
|---|
| 81 | static NObjDirList* myDirs = NULL;
|
|---|
| 82 | static NObjList* myObjs = NULL;
|
|---|
| 83 | static int fgOInit = 0;
|
|---|
| 84 | static int myNObj = 0;
|
|---|
| 85 | static int myDirId = 0;
|
|---|
| 86 | static string* currDir;
|
|---|
| 87 |
|
|---|
| 88 | static PIStdImgApp* myImgApp=NULL;
|
|---|
| 89 | static Services2NObjMgr* servnobjm=NULL;
|
|---|
| 90 |
|
|---|
| 91 | static string* TmpDir; // Repertoire pour les compilations / link dynamique
|
|---|
| 92 |
|
|---|
| 93 | static bool BeQuiet = false; // Moins de messages ...
|
|---|
| 94 |
|
|---|
| 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 |
|
|---|
| 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) {
|
|---|
| 116 | myNObj = 0;
|
|---|
| 117 | myDirId = 0;
|
|---|
| 118 | myDirs = new NObjDirList;
|
|---|
| 119 | myObjs = new NObjList;
|
|---|
| 120 | currDir = new string("home");
|
|---|
| 121 | string dirn = "home";
|
|---|
| 122 | CreateDir(dirn);
|
|---|
| 123 | SetKeepOldDirAtt(dirn, true);
|
|---|
| 124 | dirn = "tmp";
|
|---|
| 125 | CreateDir(dirn);
|
|---|
| 126 | SetKeepOldDirAtt(dirn, false);
|
|---|
| 127 | dirn = "func";
|
|---|
| 128 | CreateDir(dirn);
|
|---|
| 129 | SetKeepOldDirAtt(dirn, false);
|
|---|
| 130 | dirn = "old";
|
|---|
| 131 | CreateDir(dirn);
|
|---|
| 132 | SetKeepOldDirAtt(dirn, false);
|
|---|
| 133 | dirn = "home";
|
|---|
| 134 | SetCurrentDir(dirn);
|
|---|
| 135 | myDirId = 50;
|
|---|
| 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) += '/';
|
|---|
| 142 | servnobjm = new Services2NObjMgr(this, (*TmpDir));
|
|---|
| 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);
|
|---|
| 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 | }
|
|---|
| 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 |
|
|---|
| 191 | /* --Methode-- */
|
|---|
| 192 | bool NamedObjMgr::CreateDir(string & dirname)
|
|---|
| 193 | {
|
|---|
| 194 | if ( !CheckDirName(dirname) ) {
|
|---|
| 195 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
|
|---|
| 196 | return(false);
|
|---|
| 197 | }
|
|---|
| 198 | NObjDirList::iterator it = myDirs->find(dirname);
|
|---|
| 199 | if (it != myDirs->end()) {
|
|---|
| 200 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
|
|---|
| 201 | return(false);
|
|---|
| 202 | }
|
|---|
| 203 | myDirId++;
|
|---|
| 204 | nobj_diritem di;
|
|---|
| 205 | di.id = myDirId;
|
|---|
| 206 | di.nobj = 0;
|
|---|
| 207 | di.lock = false;
|
|---|
| 208 | di.keepold = false;
|
|---|
| 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;
|
|---|
| 215 | return(true);
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | /* --Methode-- */
|
|---|
| 219 | bool NamedObjMgr::DeleteDir(string & dirname)
|
|---|
| 220 | {
|
|---|
| 221 | if ( !CheckDirName(dirname) ) {
|
|---|
| 222 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
|
|---|
| 223 | return(false);
|
|---|
| 224 | }
|
|---|
| 225 | NObjDirList::iterator it = myDirs->find(dirname);
|
|---|
| 226 | if (it == myDirs->end()) {
|
|---|
| 227 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
|
|---|
| 228 | return(false);
|
|---|
| 229 | }
|
|---|
| 230 | if ((*it).second.nobj > 0) {
|
|---|
| 231 | cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
|
|---|
| 232 | return(false);
|
|---|
| 233 | }
|
|---|
| 234 | if ((*it).second.lock ) {
|
|---|
| 235 | cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
|
|---|
| 236 | return(false);
|
|---|
| 237 | }
|
|---|
| 238 | if ((*it).second.id < 50) {
|
|---|
| 239 | cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
|
|---|
| 240 | return(false);
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | if (myImgApp)
|
|---|
| 244 | (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
|
|---|
| 245 | myDirs->erase(it);
|
|---|
| 246 | cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
|
|---|
| 247 | return(true);
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | /* --Methode-- */
|
|---|
| 251 | void NamedObjMgr::LockDir(string & dirname)
|
|---|
| 252 | {
|
|---|
| 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 | {
|
|---|
| 289 | if ( !CheckDirName(dirname) ) {
|
|---|
| 290 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
|
|---|
| 291 | return(false);
|
|---|
| 292 | }
|
|---|
| 293 | NObjDirList::iterator it = myDirs->find(dirname);
|
|---|
| 294 | if (it == myDirs->end()) {
|
|---|
| 295 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
|
|---|
| 296 | return(false);
|
|---|
| 297 | }
|
|---|
| 298 | *currDir = dirname;
|
|---|
| 299 | cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
|
|---|
| 300 | return(true);
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | /* --Methode-- */
|
|---|
| 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++;
|
|---|
| 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 |
|
|---|
| 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-- */
|
|---|
| 341 | void NamedObjMgr::CleanDir(string & dirname)
|
|---|
| 342 | {
|
|---|
| 343 | if ( !CheckDirName(dirname) ) {
|
|---|
| 344 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl;
|
|---|
| 345 | // return(false); $CHECK$ illegal return value in void function
|
|---|
| 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); $CHECK$ illegal return value in void function
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 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);
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 | //++
|
|---|
| 373 | // Titre Gestion de la liste des objets
|
|---|
| 374 | //--
|
|---|
| 375 | //++
|
|---|
| 376 | // void AddObj(AnyDataObj* obj, string& nom)
|
|---|
| 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"
|
|---|
| 385 | // AnyDataObj* GetObj(string const& nom)
|
|---|
| 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-- */
|
|---|
| 394 | bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
|
|---|
| 395 | {
|
|---|
| 396 |
|
|---|
| 397 | if (obj == NULL) return(false);
|
|---|
| 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;
|
|---|
| 403 | return(false);
|
|---|
| 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;
|
|---|
| 413 | return(false);
|
|---|
| 414 | }
|
|---|
| 415 | else { CreateDir(nrep); did = myDirId; }
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | // Si c'est le repertoire /func, on nettoie
|
|---|
| 419 | if (nrep == "func") {
|
|---|
| 420 | BeQuiet = true;
|
|---|
| 421 | CleanDir(nrep);
|
|---|
| 422 | BeQuiet = false;
|
|---|
| 423 | }
|
|---|
| 424 |
|
|---|
| 425 | myNObj++;
|
|---|
| 426 | if (nobj.length() < 1) {
|
|---|
| 427 | sprintf(buff,"O%d", myNObj);
|
|---|
| 428 | nobj = buff;
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | nom = '/' + nrep + '/' + nobj;
|
|---|
| 432 | NObjDirList::iterator itr = myDirs->find(nrep);
|
|---|
| 433 | if ((*itr).second.lock) {
|
|---|
| 434 | cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
|
|---|
| 435 | return(false);
|
|---|
| 436 | }
|
|---|
| 437 | it = myObjs->find(nom);
|
|---|
| 438 | if (it != myObjs->end()) { // l'objet existe deja
|
|---|
| 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
|
|---|
| 445 | string on,od;
|
|---|
| 446 | // ParseObjectName((*it).first, od, on);
|
|---|
| 447 | sprintf(buff, "%d", (*it).second.oid);
|
|---|
| 448 | string nomnew = "/old/" + nobj + buff;
|
|---|
| 449 | RenameObj(nom, nomnew);
|
|---|
| 450 | }
|
|---|
| 451 | else { // Sinon, on remplace l'objet
|
|---|
| 452 | cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
|
|---|
| 453 | DelObj(nom);
|
|---|
| 454 | }
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 | nobj_item no;
|
|---|
| 458 | no.obj = obj;
|
|---|
| 459 | no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
|
|---|
| 460 | no.oid = myNObj;
|
|---|
| 461 | no.dirid = did;
|
|---|
| 462 | (*myObjs)[nom] = no;
|
|---|
| 463 |
|
|---|
| 464 | (*itr).second.nobj++;
|
|---|
| 465 |
|
|---|
| 466 | cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
|
|---|
| 467 | << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
|
|---|
| 468 | return(true);
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | /* --Methode-- */
|
|---|
| 472 | bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
|
|---|
| 473 | {
|
|---|
| 474 | string n1,r1,n2,r2;
|
|---|
| 475 | int dids = ParseObjectName(nom, r1, n1);
|
|---|
| 476 | NObjDirList::iterator itr1 = myDirs->find(r1);
|
|---|
| 477 | int did = ParseObjectName(nomnew, r2, n2);
|
|---|
| 478 | NObjDirList::iterator itr2 = myDirs->find(r2);
|
|---|
| 479 |
|
|---|
| 480 | if (did == 0) {
|
|---|
| 481 | cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
|
|---|
| 482 | return(false);
|
|---|
| 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;
|
|---|
| 489 | return(false);
|
|---|
| 490 | }
|
|---|
| 491 | NObjList::iterator it2 = myObjs->find(nomnew);
|
|---|
| 492 | if (it2 != myObjs->end()) {
|
|---|
| 493 | cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
|
|---|
| 494 | return(false);
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 513 | return(true);
|
|---|
| 514 | }
|
|---|
| 515 |
|
|---|
| 516 | /* --Methode-- */
|
|---|
| 517 | bool NamedObjMgr::DelObj(string & nom, bool fgd)
|
|---|
| 518 | {
|
|---|
| 519 | string n1,r1;
|
|---|
| 520 | ParseObjectName(nom, r1, n1);
|
|---|
| 521 | nom = '/' + r1 + '/' + n1;
|
|---|
| 522 | NObjList::iterator it = myObjs->find(nom);
|
|---|
| 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 | }
|
|---|
| 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 | }
|
|---|
| 535 | delete (*it).second.obja; // destruction de l'adaptateur
|
|---|
| 536 | if (fgd) delete (*it).second.obj;
|
|---|
| 537 |
|
|---|
| 538 | myObjs->erase(it);
|
|---|
| 539 | (*itr).second.nobj--;
|
|---|
| 540 |
|
|---|
| 541 | if (BeQuiet) return(true);
|
|---|
| 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;
|
|---|
| 544 | return(true);
|
|---|
| 545 | }
|
|---|
| 546 |
|
|---|
| 547 | /* --Methode-- */
|
|---|
| 548 | bool NamedObjMgr::DelObj_Id(int oid)
|
|---|
| 549 | {
|
|---|
| 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 | }
|
|---|
| 558 | if (of) return(DelObj(nom, true));
|
|---|
| 559 | else return(false);
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | /* --Methode-- */
|
|---|
| 563 | void NamedObjMgr::DelObjects(string & patt, bool fgd)
|
|---|
| 564 | {
|
|---|
| 565 | string n1,r1;
|
|---|
| 566 | ParseObjectName(patt, r1, n1);
|
|---|
| 567 | patt = '/' + r1 + '/' + n1;
|
|---|
| 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-- */
|
|---|
| 580 | AnyDataObj* NamedObjMgr::GetObj(string & nom)
|
|---|
| 581 | {
|
|---|
| 582 | string n1,r1;
|
|---|
| 583 | ParseObjectName(nom, r1, n1);
|
|---|
| 584 | nom = '/' + r1 + '/' + n1;
|
|---|
| 585 | NObjList::iterator it = myObjs->find(nom);
|
|---|
| 586 | if (it == myObjs->end()) return(NULL);
|
|---|
| 587 | return((*it).second.obj);
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | /* --Methode-- */
|
|---|
| 591 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
|
|---|
| 592 | {
|
|---|
| 593 | string n1,r1;
|
|---|
| 594 | ParseObjectName(nom, r1, n1);
|
|---|
| 595 | nom = '/' + r1 + '/' + n1;
|
|---|
| 596 | NObjList::iterator it = myObjs->find(nom);
|
|---|
| 597 | if (it == myObjs->end()) return(NULL);
|
|---|
| 598 | return((*it).second.obja);
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | /* --Methode-- */
|
|---|
| 602 | void NamedObjMgr::ListObjs(string & patt)
|
|---|
| 603 | {
|
|---|
| 604 | int k;
|
|---|
| 605 | AnyDataObj* obj=NULL;
|
|---|
| 606 | string ctyp;
|
|---|
| 607 | char strg[256];
|
|---|
| 608 |
|
|---|
| 609 | string n1,r1;
|
|---|
| 610 | ParseObjectName(patt, r1, n1);
|
|---|
| 611 | patt = '/' + r1 + '/' + n1;
|
|---|
| 612 | cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
|
|---|
| 613 | NObjList::iterator it; k = 0;
|
|---|
| 614 | string cn;
|
|---|
| 615 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
|---|
| 616 | cn = (*it).first;
|
|---|
| 617 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
|---|
| 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;
|
|---|
| 626 | return;
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 | /* --Methode-- */
|
|---|
| 630 | void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
|
|---|
| 631 | {
|
|---|
| 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 | }
|
|---|
| 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-- */
|
|---|
| 665 | void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
|
|---|
| 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);
|
|---|
| 680 | AddObj(obj->DataObj(), nobj, true);
|
|---|
| 681 | return;
|
|---|
| 682 | }
|
|---|
| 683 |
|
|---|
| 684 | /* --Methode-- */
|
|---|
| 685 | void NamedObjMgr::ReadObj(PInPersist& s, int num)
|
|---|
| 686 | {
|
|---|
| 687 | int_4 i, cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
|
|---|
| 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 = "";
|
|---|
| 707 | AddObj(obj->DataObj(), nom);
|
|---|
| 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;
|
|---|
| 724 | if (ok) AddObj(obj->DataObj(), nom, true);
|
|---|
| 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);
|
|---|
| 747 | AddObj(obj->DataObj(), nom);
|
|---|
| 748 | }
|
|---|
| 749 | else ReadObj((*ppin), -1);
|
|---|
| 750 | delete ppin;
|
|---|
| 751 | return;
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | /* --Methode-- */
|
|---|
| 755 | void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
|
|---|
| 756 | {
|
|---|
| 757 | bool ok = true;
|
|---|
| 758 | RzImage* obj;
|
|---|
| 759 |
|
|---|
| 760 | TRY{
|
|---|
| 761 | // obj = RzReadFits((char*)flnm.c_str(), ImgOffX, ImgOffY, ImgSizX, ImgSizY, ImgBitSgn);
|
|---|
| 762 | #ifdef SANS_EVOLPLANCK
|
|---|
| 763 | obj = RzReadFits((char*)flnm.c_str());
|
|---|
| 764 | #else
|
|---|
| 765 | printf("NamedObjMgr::ReadFITS( NON-Disponible EVOL-PLANCK) \n");
|
|---|
| 766 | obj = NULL;
|
|---|
| 767 | #endif
|
|---|
| 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);
|
|---|
| 775 | AddObj((AnyDataObj*)obj, nobj);
|
|---|
| 776 | }
|
|---|
| 777 | return;
|
|---|
| 778 | }
|
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 | static int key_for_write = 5000;
|
|---|
| 782 | /* --Methode-- */
|
|---|
| 783 | void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
|
|---|
| 784 | {
|
|---|
| 785 | if (nom.length() < 1) return;
|
|---|
| 786 | string nob,rep;
|
|---|
| 787 | ParseObjectName(nom, rep, nob);
|
|---|
| 788 | nom = '/' + rep + '/' + nob;
|
|---|
| 789 | NObjMgrAdapter* obja=NULL;
|
|---|
| 790 | string nomf = (keeppath) ? nom : nob;
|
|---|
| 791 | obja = GetObjAdapter(nom);
|
|---|
| 792 | if (obja == NULL) return;
|
|---|
| 793 | printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
|
|---|
| 794 | nom.c_str(), typeid(*(obja->GetDataObj())).name());
|
|---|
| 795 | obja->SavePPF(s, nomf);
|
|---|
| 796 | return;
|
|---|
| 797 | }
|
|---|
| 798 |
|
|---|
| 799 | /* --Methode-- */
|
|---|
| 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-- */
|
|---|
| 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;
|
|---|
| 839 | NObjList::iterator it;
|
|---|
| 840 | string no;
|
|---|
| 841 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
|---|
| 842 | no = (*it).first;
|
|---|
| 843 | SaveObj(no, (*pout), true);
|
|---|
| 844 | }
|
|---|
| 845 | delete pout;
|
|---|
| 846 | return;
|
|---|
| 847 | }
|
|---|
| 848 |
|
|---|
| 849 | /* --Methode-- */
|
|---|
| 850 | void NamedObjMgr::SaveFits(string& nom, string const & flnm)
|
|---|
| 851 | {
|
|---|
| 852 | NObjMgrAdapter* obja=NULL;
|
|---|
| 853 | obja = GetObjAdapter(nom);
|
|---|
| 854 | if (obja == NULL) return;
|
|---|
| 855 | obja->SaveFits(flnm);
|
|---|
| 856 | return;
|
|---|
| 857 | }
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 |
|
|---|
| 861 | /* --Methode-- */
|
|---|
| 862 | void NamedObjMgr::PrintObj(string& nom)
|
|---|
| 863 | {
|
|---|
| 864 | NObjMgrAdapter* obja=NULL;
|
|---|
| 865 | obja = GetObjAdapter(nom);
|
|---|
| 866 | if (obja == NULL) return;
|
|---|
| 867 |
|
|---|
| 868 | string ctyp = typeid(*obja->GetDataObj()).name();
|
|---|
| 869 | cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
|
|---|
| 870 | obja->Print(cout);
|
|---|
| 871 |
|
|---|
| 872 | return;
|
|---|
| 873 | }
|
|---|
| 874 |
|
|---|
| 875 | /* --Methode-- */
|
|---|
| 876 | void NamedObjMgr::DisplayObj(string& nom, string dopt)
|
|---|
| 877 | {
|
|---|
| 878 | NObjMgrAdapter* obja=NULL;
|
|---|
| 879 | obja = GetObjAdapter(nom);
|
|---|
| 880 | if (obja == NULL) {
|
|---|
| 881 | cout << "NamedObjMgr::DisplayObj() Error , Pas d'objet de nom " << nom << endl;
|
|---|
| 882 | return;
|
|---|
| 883 | }
|
|---|
| 884 | if (!myImgApp) return;
|
|---|
| 885 |
|
|---|
| 886 | PIDrawer * dr = NULL;
|
|---|
| 887 | P2DArrayAdapter* arr = NULL;
|
|---|
| 888 | dr = obja->GetDrawer(dopt);
|
|---|
| 889 | if (!dr) arr = obja->Get2DArray(dopt);
|
|---|
| 890 |
|
|---|
| 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 |
|
|---|
| 897 | int wrsid = 0;
|
|---|
| 898 | bool fgsr = true;
|
|---|
| 899 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
|---|
| 900 |
|
|---|
| 901 | string n1,r1;
|
|---|
| 902 | ParseObjectName(nom, r1, n1);
|
|---|
| 903 |
|
|---|
| 904 | if (dr) {
|
|---|
| 905 | PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
|
|---|
| 906 | if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, opt);
|
|---|
| 907 | else wrsid = myImgApp->DispScDrawer( dr, n1, opt);
|
|---|
| 908 | }
|
|---|
| 909 | else if (arr) wrsid = myImgApp->DispImage(arr, n1, opt);
|
|---|
| 910 |
|
|---|
| 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 | }
|
|---|
| 919 |
|
|---|
| 920 | /* --Methode-- */
|
|---|
| 921 | void NamedObjMgr::DisplayImage(string& nom, string dopt)
|
|---|
| 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);
|
|---|
| 932 |
|
|---|
| 933 | if (!arr) {
|
|---|
| 934 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
|---|
| 935 | cout << "NamedObjMgr::DisplayImage() Error , Non supporte pour " << ctyp << endl;
|
|---|
| 936 | return;
|
|---|
| 937 | }
|
|---|
| 938 |
|
|---|
| 939 | string n1,r1;
|
|---|
| 940 | ParseObjectName(nom, r1, n1);
|
|---|
| 941 |
|
|---|
| 942 | int wrsid = 0;
|
|---|
| 943 | bool fgsr = true;
|
|---|
| 944 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
|---|
| 945 | wrsid = myImgApp->DispImage(arr, n1, opt);
|
|---|
| 946 |
|
|---|
| 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-- */
|
|---|
| 956 | void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
|
|---|
| 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);
|
|---|
| 967 |
|
|---|
| 968 | if (!arr) {
|
|---|
| 969 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
|---|
| 970 | cout << "NamedObjMgr::DisplaySurf3D() Error , Non supporte pour " << ctyp << endl;
|
|---|
| 971 | return;
|
|---|
| 972 | }
|
|---|
| 973 |
|
|---|
| 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;
|
|---|
| 979 | }
|
|---|
| 980 |
|
|---|
| 981 | string n1,r1;
|
|---|
| 982 | ParseObjectName(nom, r1, n1);
|
|---|
| 983 |
|
|---|
| 984 | int wrsid = 0;
|
|---|
| 985 | bool fgsr = true;
|
|---|
| 986 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
|---|
| 987 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
|---|
| 988 | wrsid = myImgApp->Disp3DDrawer(sdr, n1, opt);
|
|---|
| 989 | if(wrsid >= 0) {
|
|---|
| 990 | NObjList::iterator it = myObjs->find(nom);
|
|---|
| 991 | if (it == myObjs->end()) return;
|
|---|
| 992 | (*it).second.wrsid.push_back(wrsid);
|
|---|
| 993 | }
|
|---|
| 994 |
|
|---|
| 995 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
|---|
| 996 | return;
|
|---|
| 997 | }
|
|---|
| 998 |
|
|---|
| 999 | /* --Methode-- */
|
|---|
| 1000 | void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
|
|---|
| 1001 | string& erx, string& ery, string& erz, string dopt, bool fg3d)
|
|---|
| 1002 | {
|
|---|
| 1003 | AnyDataObj* obj=GetObj(nom);
|
|---|
| 1004 | if (obj == NULL) {
|
|---|
| 1005 | cout << "NamedObjMgr::DisplayNT() Error , Pas d'objet de nom " << nom << endl;
|
|---|
| 1006 | return;
|
|---|
| 1007 | }
|
|---|
| 1008 | if (!myImgApp) return;
|
|---|
| 1009 |
|
|---|
| 1010 | NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
|
|---|
| 1011 | if (nt == NULL) {
|
|---|
| 1012 | // if (typeid(*obj) != typeid(NTupleInterface)) {
|
|---|
| 1013 | string ctyp = typeid(*obj).name();
|
|---|
| 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;
|
|---|
| 1020 | dopt = "defline," + dopt;
|
|---|
| 1021 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
|---|
| 1022 |
|
|---|
| 1023 | string n1,r1;
|
|---|
| 1024 | ParseObjectName(nom, r1, n1);
|
|---|
| 1025 |
|
|---|
| 1026 | if ( fg3d && (nmz.length()>0) ) { // Display 3D
|
|---|
| 1027 | PINTuple3D* pin = new PINTuple3D(nt, false);
|
|---|
| 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;
|
|---|
| 1031 | wrsid = myImgApp->Disp3DDrawer(pin, n1, opt, titre);
|
|---|
| 1032 | }
|
|---|
| 1033 | else {
|
|---|
| 1034 | PINTuple* pin = new PINTuple(nt, false);
|
|---|
| 1035 | pin->SelectXY(nmx.c_str(), nmy.c_str());
|
|---|
| 1036 | pin->SelectErrBar(erx.c_str(), ery.c_str());
|
|---|
| 1037 | if ( nmz.length()>0 ) pin->SelectWt(nmz.c_str());
|
|---|
| 1038 | string titre = nmy + "%" + nmx;
|
|---|
| 1039 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, opt, titre);
|
|---|
| 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 |
|
|---|
| 1052 | /* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
|
|---|
| 1053 | void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
|
|---|
| 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 | {
|
|---|
| 1066 | AnyDataObj* obj=GetObj(nom);
|
|---|
| 1067 | if(obj == NULL)
|
|---|
| 1068 | {cout << "NamedObjMgr::DisplayGFD() Error , Pas d'objet de nom " << nom << endl;
|
|---|
| 1069 | return;}
|
|---|
| 1070 | if(!myImgApp) return;
|
|---|
| 1071 | if(typeid(*obj) != typeid(GeneralFitData))
|
|---|
| 1072 | {string ctyp = typeid(*obj).name();
|
|---|
| 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
|
|---|
| 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 |
|
|---|
| 1092 | string n1,r1;
|
|---|
| 1093 | ParseObjectName(nom, r1, n1);
|
|---|
| 1094 |
|
|---|
| 1095 | int wrsid = 0;
|
|---|
| 1096 | if(numvy>=0) { // display 3D
|
|---|
| 1097 | PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
|
|---|
| 1098 | pigfd->SelectXY(numvx,numvy);
|
|---|
| 1099 | pigfd->SelectErrBar(errx,erry,errz);
|
|---|
| 1100 | wrsid = myImgApp->Disp3DDrawer(pigfd,n1,opt);
|
|---|
| 1101 | } else { // display 2D
|
|---|
| 1102 | PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
|
|---|
| 1103 | pigfd->SelectX(numvx);
|
|---|
| 1104 | pigfd->SelectErrBar(errx,erry);
|
|---|
| 1105 | wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,opt);
|
|---|
| 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--
|
|---|
| 1118 | void NamedObjMgr::DisplayImage(string& nom, string dopt)
|
|---|
| 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 | }
|
|---|
| 1133 |
|
|---|
| 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-- */
|
|---|
| 1143 | void NamedObjMgr::AddWRsId(string & nom, int wrsid)
|
|---|
| 1144 | {
|
|---|
| 1145 | if(wrsid != 0) {
|
|---|
| 1146 | NObjList::iterator it = myObjs->find(nom);
|
|---|
| 1147 | if (it == myObjs->end()) return;
|
|---|
| 1148 | (*it).second.wrsid.push_back(wrsid);
|
|---|
| 1149 | }
|
|---|
| 1150 | return;
|
|---|
| 1151 | }
|
|---|
| 1152 |
|
|---|
| 1153 | /* --Methode-- */
|
|---|
| 1154 | void NamedObjMgr::UpdateObjMgrWindow(int did)
|
|---|
| 1155 | {
|
|---|
| 1156 | if (!myImgApp) return;
|
|---|
| 1157 | (myImgApp->ObjMgrW())->ClearHelpList();
|
|---|
| 1158 |
|
|---|
| 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());
|
|---|
| 1166 | }
|
|---|
| 1167 | }
|
|---|
| 1168 |
|
|---|
| 1169 |
|
|---|
| 1170 | /* Nouvelle-Fonction */
|
|---|
| 1171 | void RemoveSpacesFromName(string & nom)
|
|---|
| 1172 | {
|
|---|
| 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);
|
|---|
| 1180 | }
|
|---|
| 1181 |
|
|---|
| 1182 | /* Nouvelle-Fonction */
|
|---|
| 1183 | bool CheckDirName(string & nom)
|
|---|
| 1184 | {
|
|---|
| 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);
|
|---|
| 1192 | }
|
|---|
| 1193 |
|
|---|
| 1194 | /* Nouvelle-Fonction */
|
|---|
| 1195 | int ParseObjectName(string & nom, string & nomrep, string & nomobj)
|
|---|
| 1196 | {
|
|---|
| 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; }
|
|---|
| 1200 | else {
|
|---|
| 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);
|
|---|
| 1206 | }
|
|---|
| 1207 | else {
|
|---|
| 1208 | nomrep = xx;
|
|---|
| 1209 | nomobj = "";
|
|---|
| 1210 | }
|
|---|
| 1211 | }
|
|---|
| 1212 | int rc = 0;
|
|---|
| 1213 | NObjDirList::iterator it = myDirs->find(nomrep);
|
|---|
| 1214 | if (it != myDirs->end()) rc = (*it).second.id;
|
|---|
| 1215 | return(rc);
|
|---|
| 1216 | }
|
|---|
| 1217 |
|
|---|