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