[165] | 1 | #include <stdio.h>
|
---|
| 2 | #include <stdlib.h>
|
---|
| 3 | #include <ctype.h>
|
---|
| 4 |
|
---|
[295] | 5 | #include <typeinfo>
|
---|
[2322] | 6 | #include <iostream>
|
---|
[165] | 7 | #include <string>
|
---|
| 8 | #include <list>
|
---|
| 9 | #include <map>
|
---|
| 10 |
|
---|
| 11 | #include "strutil.h"
|
---|
| 12 | #include "datatypes.h"
|
---|
| 13 |
|
---|
| 14 | #include "nobjmgr.h"
|
---|
| 15 | #include "servnobjm.h"
|
---|
[330] | 16 | #include "nomgadapter.h"
|
---|
[165] | 17 | #include "pistdimgapp.h"
|
---|
| 18 |
|
---|
[1164] | 19 | #include "dvlist.h"
|
---|
[165] | 20 |
|
---|
[293] | 21 | // EVOL-PLANCK
|
---|
| 22 | #ifdef SANS_EVOLPLANCK
|
---|
| 23 | #include "fitsimage.h"
|
---|
[1321] | 24 | #else
|
---|
| 25 | #include "fitsautoreader.h"
|
---|
[1525] | 26 | #include "tvector.h"
|
---|
| 27 | #include "pitvmaad.h"
|
---|
[1905] | 28 | #include "piyfxdrw.h"
|
---|
[293] | 29 | #endif
|
---|
| 30 |
|
---|
[295] | 31 | #include "pisurfdr.h"
|
---|
[165] | 32 | #include "pipodrw.h"
|
---|
[333] | 33 |
|
---|
[165] | 34 | #include "pintuple.h"
|
---|
| 35 | #include "pintup3d.h"
|
---|
| 36 | #include "pigfd1.h"
|
---|
| 37 | #include "pigfd2.h"
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | //++
|
---|
| 41 | // Class NamedObjMgr
|
---|
| 42 | // Lib PI
|
---|
| 43 | // include nobjmgr.h
|
---|
| 44 | //
|
---|
[344] | 45 | // Cette classe fournit les services nécéssaires à la gestion des objets
|
---|
[165] | 46 | // (l'ensemble des objets PPersist de PEIDA++) au sein du programme
|
---|
| 47 | // d'analyse interactive *piapp* . Elle constitue en outre l'interface
|
---|
| 48 | // entre les fonctions utilisateur et l'application graphique.
|
---|
| 49 | //--
|
---|
| 50 | //++
|
---|
| 51 | // Links Voir aussi
|
---|
| 52 | // PIStdImgApp
|
---|
| 53 | // Services2NObjMgr
|
---|
| 54 | // PIACmd
|
---|
| 55 | //--
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | // ..................................................................
|
---|
| 59 | // ...... Gestion des objets nommes, variables globales ............
|
---|
[331] | 60 | struct nobj_diritem {
|
---|
[344] | 61 | int id; // Directory Id
|
---|
| 62 | int nobj; // Number of objects in directory
|
---|
| 63 | bool lock; // True -> directory locked, No Add, del or rename
|
---|
| 64 | bool keepold; // True -> When duplicate object name, old object moved to /old
|
---|
[331] | 65 | };
|
---|
| 66 |
|
---|
| 67 | typedef map<string, nobj_diritem, less<string> > NObjDirList;
|
---|
| 68 |
|
---|
[165] | 69 | struct nobj_item {
|
---|
[344] | 70 | AnyDataObj* obj; // Object pointer
|
---|
| 71 | NObjMgrAdapter* obja; // Object adapter pointer
|
---|
| 72 | int oid; // object Id
|
---|
| 73 | int dirid; // Directory Id
|
---|
| 74 | list<int> wrsid; // List of Window Resource Id (Drawer, PIBaseWdg, ...)
|
---|
| 75 | // (for PIStdImgApp)
|
---|
[165] | 76 | bool operator==(nobj_item const& b) const
|
---|
| 77 | { return (this->obj == b.obj); }
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | typedef map<string, nobj_item, less<string> > NObjList;
|
---|
| 81 |
|
---|
[331] | 82 | static NObjDirList* myDirs = NULL;
|
---|
| 83 | static NObjList* myObjs = NULL;
|
---|
[165] | 84 | static int fgOInit = 0;
|
---|
| 85 | static int myNObj = 0;
|
---|
[331] | 86 | static int myDirId = 0;
|
---|
| 87 | static string* currDir;
|
---|
[165] | 88 |
|
---|
| 89 | static PIStdImgApp* myImgApp=NULL;
|
---|
| 90 | static Services2NObjMgr* servnobjm=NULL;
|
---|
| 91 |
|
---|
[1164] | 92 | static DVList* myVars = NULL; // Pour stocker les variables
|
---|
| 93 |
|
---|
[165] | 94 | static string* TmpDir; // Repertoire pour les compilations / link dynamique
|
---|
| 95 |
|
---|
[333] | 96 | // ..................................................................
|
---|
| 97 |
|
---|
[165] | 98 | //++
|
---|
| 99 | // Titre Constructeurs
|
---|
| 100 | //--
|
---|
| 101 | //++
|
---|
| 102 | // NamedObjMgr()
|
---|
| 103 | // Constructeur. Les différents instantiation de la classe "NamedObjMgr"
|
---|
| 104 | // dans une même application créent des objets qui travaillent sur la même
|
---|
| 105 | // liste d'objets. Les objets de cette classe ne possedent en effet pas
|
---|
| 106 | // de variables membres.
|
---|
| 107 | //--
|
---|
| 108 |
|
---|
| 109 | /* --Methode-- */
|
---|
[2490] | 110 | NamedObjMgr::NamedObjMgr(bool fgimgapp)
|
---|
[165] | 111 | {
|
---|
[2490] | 112 | _fgimgapp = fgimgapp;
|
---|
[165] | 113 | if (fgOInit == 0) {
|
---|
[333] | 114 | myNObj = 0;
|
---|
| 115 | myDirId = 0;
|
---|
[331] | 116 | myDirs = new NObjDirList;
|
---|
[165] | 117 | myObjs = new NObjList;
|
---|
[1164] | 118 | myVars = new DVList;
|
---|
[331] | 119 | currDir = new string("home");
|
---|
[333] | 120 | string dirn = "home";
|
---|
| 121 | CreateDir(dirn);
|
---|
[2132] | 122 | SetKeepOldDirAtt(dirn, false);
|
---|
[333] | 123 | dirn = "tmp";
|
---|
| 124 | CreateDir(dirn);
|
---|
[344] | 125 | SetKeepOldDirAtt(dirn, false);
|
---|
[466] | 126 | dirn = "autoc";
|
---|
[368] | 127 | CreateDir(dirn);
|
---|
| 128 | SetKeepOldDirAtt(dirn, false);
|
---|
[333] | 129 | dirn = "old";
|
---|
| 130 | CreateDir(dirn);
|
---|
[344] | 131 | SetKeepOldDirAtt(dirn, false);
|
---|
[333] | 132 | dirn = "home";
|
---|
| 133 | SetCurrentDir(dirn);
|
---|
| 134 | myDirId = 50;
|
---|
[165] | 135 | char* varenv;
|
---|
| 136 | TmpDir = new string("");
|
---|
[1276] | 137 | if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
|
---|
[165] | 138 | int l = (*TmpDir).length();
|
---|
| 139 | if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
|
---|
[333] | 140 | servnobjm = new Services2NObjMgr(this, (*TmpDir));
|
---|
[165] | 141 | }
|
---|
| 142 | fgOInit++;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | /* --Methode-- */
|
---|
| 147 | NamedObjMgr::~NamedObjMgr()
|
---|
| 148 | {
|
---|
| 149 | fgOInit--;
|
---|
[1164] | 150 | if (fgOInit == 0) {
|
---|
| 151 | string patt = "/*/*";
|
---|
| 152 | DelObjects(patt, true);
|
---|
| 153 | delete myObjs;
|
---|
| 154 | delete myDirs;
|
---|
| 155 | delete myVars;
|
---|
[165] | 156 | }
|
---|
[1164] | 157 | }
|
---|
[165] | 158 |
|
---|
| 159 | //++
|
---|
| 160 | // Titre Méthodes
|
---|
| 161 | //--
|
---|
| 162 | //++
|
---|
| 163 | // void SetImgApp(PIStdImgApp* app)
|
---|
| 164 | // Spécifie l'objet "PIStdImgApp" associé.
|
---|
| 165 | // PIStdImgApp* GetImgApp()
|
---|
| 166 | // Accès à l'objet "PIStdImgApp" associé.
|
---|
| 167 | //--
|
---|
| 168 |
|
---|
| 169 | /* --Methode-- */
|
---|
| 170 | void NamedObjMgr::SetImgApp(PIStdImgApp* app)
|
---|
| 171 | {
|
---|
| 172 | myImgApp = app;
|
---|
| 173 | servnobjm->SetImgApp(app);
|
---|
[333] | 174 |
|
---|
| 175 | NObjDirList::iterator it;
|
---|
| 176 | string cn;
|
---|
| 177 | for(it= myDirs->begin(); it != myDirs->end(); it++) {
|
---|
| 178 | cn = '/' + (*it).first;
|
---|
| 179 | (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id);
|
---|
| 180 | }
|
---|
[165] | 181 | }
|
---|
| 182 |
|
---|
[449] | 183 |
|
---|
| 184 | static bool verbeux = false; // true -> plus de message (creation/suppression d'objets)
|
---|
| 185 | void NamedObjMgr::SetVerbose(bool fg)
|
---|
| 186 | {
|
---|
| 187 | verbeux = fg;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
[165] | 190 | /* --Methode-- */
|
---|
| 191 | PIStdImgApp* NamedObjMgr::GetImgApp()
|
---|
| 192 | {
|
---|
| 193 | return(myImgApp);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | /* --Methode-- */
|
---|
| 197 | Services2NObjMgr* NamedObjMgr::GetServiceObj()
|
---|
| 198 | {
|
---|
| 199 | return(servnobjm);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[331] | 202 | /* --Methode-- */
|
---|
[1268] | 203 | string const& NamedObjMgr::GetTmpDir()
|
---|
[1265] | 204 | {
|
---|
| 205 | return *TmpDir;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | /* --Methode-- */
|
---|
[1268] | 209 | void NamedObjMgr::SetTmpDir(string const& tmpdir)
|
---|
[1265] | 210 | {
|
---|
| 211 | if(tmpdir.length()<1) return;
|
---|
| 212 | *TmpDir = tmpdir;
|
---|
[1276] | 213 | int l = (*TmpDir).length();
|
---|
| 214 | if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
|
---|
| 215 | servnobjm->SetTmpDir(*TmpDir);
|
---|
[1265] | 216 | }
|
---|
| 217 |
|
---|
| 218 | /* --Methode-- */
|
---|
[1164] | 219 | bool NamedObjMgr::SetVar(string const & key, string const & val)
|
---|
| 220 | {
|
---|
[2218] | 221 | if ((key.length() < 1) || (! isalpha(key[0])) ) {
|
---|
| 222 | cout << "NamedObjMgr::SetVar( " << key << " ...) Bad VarName " << endl;
|
---|
| 223 | return(false);
|
---|
| 224 | }
|
---|
[1199] | 225 | #ifdef SANS_EVOLPLANCK
|
---|
| 226 | bool fg = true;
|
---|
| 227 | #else
|
---|
[1164] | 228 | bool fg = myVars->HasKey(key);
|
---|
[1199] | 229 | #endif
|
---|
[1164] | 230 | myVars->SetS(key, val);
|
---|
[1224] | 231 | // cout << " DEBUG::SetVar " << *myVars << endl;
|
---|
[1164] | 232 | return(fg);
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | /* --Methode-- */
|
---|
| 236 | bool NamedObjMgr::HasVar(string const & key)
|
---|
| 237 | {
|
---|
[2218] | 238 | if ((key.length() < 1) || (! isalpha(key[0])) ) {
|
---|
| 239 | cout << "NamedObjMgr::HasVar( " << key << ") Bad VarName " << endl;
|
---|
| 240 | return(false);
|
---|
| 241 | }
|
---|
[1199] | 242 | #ifdef SANS_EVOLPLANCK
|
---|
[1547] | 243 | DVList::ValList::const_iterator it;
|
---|
| 244 | for(it=myVars->Begin(); it!= myVars->End(); it++)
|
---|
| 245 | if ((*it).first == key) return true;
|
---|
[1199] | 246 | return(false);
|
---|
| 247 | #else
|
---|
[1164] | 248 | return(myVars->HasKey(key));
|
---|
[1199] | 249 | #endif
|
---|
[1164] | 250 | }
|
---|
| 251 |
|
---|
| 252 | /* --Methode-- */
|
---|
| 253 | bool NamedObjMgr::DeleteVar(string const & key)
|
---|
| 254 | {
|
---|
[2218] | 255 | if ((key.length() < 1) || (! isalpha(key[0])) ) {
|
---|
| 256 | cout << "NamedObjMgr::DeleteVar( " << key << ") Bad VarName " << endl;
|
---|
| 257 | return(false);
|
---|
| 258 | }
|
---|
[1199] | 259 | #ifdef SANS_EVOLPLANCK
|
---|
| 260 | return(false);
|
---|
| 261 | #else
|
---|
[1164] | 262 | return(myVars->DeleteKey(key));
|
---|
[1199] | 263 | #endif
|
---|
[1164] | 264 | }
|
---|
| 265 |
|
---|
| 266 | /* --Methode-- */
|
---|
| 267 | string NamedObjMgr::GetVar(string const & key)
|
---|
| 268 | {
|
---|
[2218] | 269 | if ((key.length() < 1) || (! isalpha(key[0])) ) {
|
---|
| 270 | cout << "NamedObjMgr::GetVar( " << key << ") Bad VarName " << endl;
|
---|
| 271 | return("");
|
---|
| 272 | }
|
---|
[1224] | 273 | // cout << " DEBUG::GetVar " << *myVars << endl;
|
---|
[1164] | 274 | return(myVars->GetS(key));
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | /* --Methode-- */
|
---|
| 278 | DVList& NamedObjMgr::GetVarList()
|
---|
| 279 | {
|
---|
[1224] | 280 | // cout << " DEBUG::GetVarList " << *myVars << endl;
|
---|
[1164] | 281 | return(*myVars);
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | /* --Methode-- */
|
---|
[344] | 285 | bool NamedObjMgr::CreateDir(string & dirname)
|
---|
[331] | 286 | {
|
---|
[333] | 287 | if ( !CheckDirName(dirname) ) {
|
---|
| 288 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
[344] | 289 | return(false);
|
---|
[333] | 290 | }
|
---|
| 291 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
| 292 | if (it != myDirs->end()) {
|
---|
| 293 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
|
---|
[344] | 294 | return(false);
|
---|
[333] | 295 | }
|
---|
| 296 | myDirId++;
|
---|
| 297 | nobj_diritem di;
|
---|
| 298 | di.id = myDirId;
|
---|
| 299 | di.nobj = 0;
|
---|
[344] | 300 | di.lock = false;
|
---|
| 301 | di.keepold = false;
|
---|
[333] | 302 | (*myDirs)[dirname] = di;
|
---|
| 303 | if (myImgApp) {
|
---|
| 304 | string str = '/' + dirname;
|
---|
[2490] | 305 | if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
|
---|
[333] | 306 | (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
|
---|
| 307 | }
|
---|
[449] | 308 | if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
|
---|
[344] | 309 | return(true);
|
---|
[331] | 310 | }
|
---|
| 311 |
|
---|
| 312 | /* --Methode-- */
|
---|
[344] | 313 | bool NamedObjMgr::DeleteDir(string & dirname)
|
---|
[331] | 314 | {
|
---|
[333] | 315 | if ( !CheckDirName(dirname) ) {
|
---|
| 316 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
[344] | 317 | return(false);
|
---|
[333] | 318 | }
|
---|
| 319 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
| 320 | if (it == myDirs->end()) {
|
---|
| 321 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
|
---|
[344] | 322 | return(false);
|
---|
[333] | 323 | }
|
---|
| 324 | if ((*it).second.nobj > 0) {
|
---|
| 325 | cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
|
---|
[344] | 326 | return(false);
|
---|
[333] | 327 | }
|
---|
[344] | 328 | if ((*it).second.lock ) {
|
---|
| 329 | cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
|
---|
| 330 | return(false);
|
---|
| 331 | }
|
---|
[333] | 332 | if ((*it).second.id < 50) {
|
---|
| 333 | cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
|
---|
[344] | 334 | return(false);
|
---|
[333] | 335 | }
|
---|
| 336 |
|
---|
[2490] | 337 | if (myImgApp) {
|
---|
| 338 | if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
|
---|
[333] | 339 | (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
|
---|
[2490] | 340 | }
|
---|
[333] | 341 | myDirs->erase(it);
|
---|
[449] | 342 | if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
|
---|
[344] | 343 | return(true);
|
---|
[331] | 344 | }
|
---|
| 345 |
|
---|
| 346 | /* --Methode-- */
|
---|
[344] | 347 | void NamedObjMgr::LockDir(string & dirname)
|
---|
[331] | 348 | {
|
---|
[344] | 349 | if ( !CheckDirName(dirname) ) return;
|
---|
| 350 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
| 351 | if (it == myDirs->end()) return;
|
---|
| 352 | (*it).second.lock = true;
|
---|
[449] | 353 | if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
|
---|
[344] | 354 | return;
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 | /* --Methode-- */
|
---|
| 358 | void NamedObjMgr::UnlockDir(string & dirname)
|
---|
| 359 | {
|
---|
| 360 | if ( !CheckDirName(dirname) ) return;
|
---|
| 361 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
| 362 | if (it == myDirs->end()) return;
|
---|
| 363 | (*it).second.lock = true;
|
---|
[449] | 364 | if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
|
---|
[344] | 365 | return;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | /* --Methode-- */
|
---|
| 369 | void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
|
---|
| 370 | {
|
---|
| 371 | if ( !CheckDirName(dirname) ) return;
|
---|
| 372 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
| 373 | if (it == myDirs->end()) return;
|
---|
| 374 | (*it).second.keepold = keepold;
|
---|
[449] | 375 | if (!verbeux) return;
|
---|
[344] | 376 | cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << " -> ";
|
---|
| 377 | if ( keepold ) cout << " True " << endl;
|
---|
| 378 | else cout << " False " << endl;
|
---|
| 379 | return;
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 |
|
---|
| 383 | /* --Methode-- */
|
---|
| 384 | bool NamedObjMgr::SetCurrentDir(string & dirname)
|
---|
| 385 | {
|
---|
[333] | 386 | if ( !CheckDirName(dirname) ) {
|
---|
| 387 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
[344] | 388 | return(false);
|
---|
[333] | 389 | }
|
---|
| 390 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
| 391 | if (it == myDirs->end()) {
|
---|
| 392 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
|
---|
[344] | 393 | return(false);
|
---|
[333] | 394 | }
|
---|
| 395 | *currDir = dirname;
|
---|
[449] | 396 | if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
|
---|
[344] | 397 | return(true);
|
---|
[331] | 398 | }
|
---|
| 399 |
|
---|
| 400 | /* --Methode-- */
|
---|
[333] | 401 | void NamedObjMgr::GetCurrentDir(string & dirname)
|
---|
| 402 | {
|
---|
| 403 | dirname = *currDir;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | /* --Methode-- */
|
---|
| 407 | void NamedObjMgr::ListDirs(string & patt)
|
---|
| 408 | {
|
---|
| 409 | NObjDirList::iterator it;
|
---|
| 410 | string cn;
|
---|
| 411 | cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl;
|
---|
| 412 | int k = 0;
|
---|
| 413 | for(it= myDirs->begin(); it != myDirs->end(); it++) {
|
---|
| 414 | cn = (*it).first;
|
---|
| 415 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
| 416 | k++;
|
---|
[344] | 417 | cout << k << "- " << (*it).first;
|
---|
| 418 | if ( (*it).second.lock ) cout << " Locked " ;
|
---|
| 419 | if ( (*it).second.keepold ) cout << " KeepOld " ;
|
---|
| 420 | cout << " (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl;
|
---|
| 421 |
|
---|
[333] | 422 | }
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | /* --Methode-- */
|
---|
| 426 | void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
|
---|
| 427 | {
|
---|
| 428 | NObjDirList::iterator it;
|
---|
| 429 | string cn;
|
---|
| 430 | for(it= myDirs->begin(); it != myDirs->end(); it++) {
|
---|
| 431 | cn = (*it).first;
|
---|
| 432 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
| 433 | lstd.push_back(cn);
|
---|
| 434 | }
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | /* --Methode-- */
|
---|
[368] | 438 | void NamedObjMgr::CleanDir(string & dirname)
|
---|
[331] | 439 | {
|
---|
[368] | 440 | if ( !CheckDirName(dirname) ) {
|
---|
| 441 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
[380] | 442 | // return(false); $CHECK$ illegal return value in void function
|
---|
[368] | 443 | }
|
---|
| 444 | NObjDirList::iterator itr = myDirs->find(dirname);
|
---|
| 445 | if (itr == myDirs->end()) {
|
---|
| 446 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - No such directory !" << endl;
|
---|
[380] | 447 | // return(false); $CHECK$ illegal return value in void function
|
---|
[368] | 448 | }
|
---|
[331] | 449 |
|
---|
[368] | 450 | int did = (*itr).second.id;
|
---|
| 451 | NObjList::iterator it;
|
---|
| 452 | list<int>::iterator iwr;
|
---|
| 453 | bool nodisp = true;
|
---|
| 454 | list<string> odel;
|
---|
| 455 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
| 456 | if ((*it).second.dirid != did) continue;
|
---|
| 457 | nodisp = true;
|
---|
| 458 | if (myImgApp)
|
---|
| 459 | for(iwr=(*it).second.wrsid.begin(); iwr != (*it).second.wrsid.end(); iwr++)
|
---|
| 460 | if (myImgApp->CheckWRsId(*iwr)) { nodisp = false; break; }
|
---|
| 461 | if (nodisp) odel.push_back((*it).first);
|
---|
| 462 | }
|
---|
| 463 | list<string>::iterator ii;
|
---|
| 464 | for(ii=odel.begin(); ii != odel.end(); ii++) DelObj(*ii,true);
|
---|
[2490] | 465 | if (myImgApp) {
|
---|
| 466 | if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
|
---|
[685] | 467 | (myImgApp->ObjMgrW())->UpdateList(did);
|
---|
[331] | 468 | }
|
---|
[2490] | 469 | }
|
---|
[331] | 470 |
|
---|
[333] | 471 |
|
---|
[368] | 472 |
|
---|
[165] | 473 | //++
|
---|
| 474 | // Titre Gestion de la liste des objets
|
---|
| 475 | //--
|
---|
| 476 | //++
|
---|
[295] | 477 | // void AddObj(AnyDataObj* obj, string& nom)
|
---|
[165] | 478 | // Ajoute l'objet "obj" à la liste, identifié par "nom".
|
---|
| 479 | // Si un objet de même nom existe, l'ancien objet est renommé en concaténant
|
---|
| 480 | // un numéro à son nom.
|
---|
| 481 | // void DelObj(string const& nom, bool fgd=true)
|
---|
| 482 | // Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
|
---|
| 483 | // void DelObjects(string const& patt, bool fgd=true)
|
---|
| 484 | // Supprime l'ensemble des objets dont le nom correspond au patron "patt".
|
---|
| 485 | // Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
|
---|
[295] | 486 | // AnyDataObj* GetObj(string const& nom)
|
---|
[165] | 487 | // Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
|
---|
| 488 | // pas dans la liste.
|
---|
| 489 | // void RenameObj(string const& nom, string& nomnew)
|
---|
| 490 | // Change le nom d'un objet dans la liste.
|
---|
[463] | 491 | // void CopyObj(string const& nom, string& nomcp)
|
---|
| 492 | // Copy l'objet "nom" de la liste dans l'objet "nomcp" de la liste.
|
---|
[165] | 493 | //--
|
---|
| 494 |
|
---|
| 495 |
|
---|
| 496 | /* --Methode-- */
|
---|
[344] | 497 | bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
|
---|
[165] | 498 | {
|
---|
| 499 |
|
---|
[344] | 500 | if (obj == NULL) return(false);
|
---|
[333] | 501 | // On verifie si l'objet est deja dans la liste
|
---|
| 502 | NObjList::iterator it;
|
---|
| 503 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
| 504 | if ((*it).second.obj == obj) {
|
---|
| 505 | cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
|
---|
[344] | 506 | return(false);
|
---|
[333] | 507 | }
|
---|
| 508 | }
|
---|
| 509 | string nobj;
|
---|
| 510 | string nrep;
|
---|
| 511 | char buff[32];
|
---|
| 512 | int did = ParseObjectName(nom, nrep, nobj);
|
---|
| 513 | if (did == 0) {
|
---|
| 514 | if (!crd) {
|
---|
| 515 | cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
|
---|
[344] | 516 | return(false);
|
---|
[333] | 517 | }
|
---|
| 518 | else { CreateDir(nrep); did = myDirId; }
|
---|
| 519 | }
|
---|
[165] | 520 |
|
---|
[466] | 521 | // Si c'est le repertoire /autoc, on nettoie
|
---|
| 522 | if (nrep == "autoc") {
|
---|
[368] | 523 | CleanDir(nrep);
|
---|
| 524 | }
|
---|
| 525 |
|
---|
[165] | 526 | myNObj++;
|
---|
[2218] | 527 | if ((nobj.length() < 1) || (! isalpha(nobj[0]) ) ) {
|
---|
| 528 | cout << "NamedObjMgr::AddObj() bad object name " << nobj ;
|
---|
[333] | 529 | sprintf(buff,"O%d", myNObj);
|
---|
| 530 | nobj = buff;
|
---|
[2218] | 531 | cout << " changed to " << nobj << endl;
|
---|
[333] | 532 | }
|
---|
| 533 |
|
---|
| 534 | nom = '/' + nrep + '/' + nobj;
|
---|
[344] | 535 | NObjDirList::iterator itr = myDirs->find(nrep);
|
---|
| 536 | if ((*itr).second.lock) {
|
---|
| 537 | cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
|
---|
| 538 | return(false);
|
---|
| 539 | }
|
---|
[333] | 540 | it = myObjs->find(nom);
|
---|
[165] | 541 | if (it != myObjs->end()) { // l'objet existe deja
|
---|
[466] | 542 | if (nrep == "autoc") { // Dans /autoc , on garde les objets affiches, donc del. par Clean
|
---|
[368] | 543 | sprintf(buff, "%d", (*it).second.oid);
|
---|
[466] | 544 | string nomnew = "/autoc/" + nobj + buff;
|
---|
[368] | 545 | RenameObj(nom, nomnew);
|
---|
| 546 | }
|
---|
| 547 | else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
|
---|
[333] | 548 | string on,od;
|
---|
[335] | 549 | // ParseObjectName((*it).first, od, on);
|
---|
[333] | 550 | sprintf(buff, "%d", (*it).second.oid);
|
---|
[335] | 551 | string nomnew = "/old/" + nobj + buff;
|
---|
[333] | 552 | RenameObj(nom, nomnew);
|
---|
| 553 | }
|
---|
[344] | 554 | else { // Sinon, on remplace l'objet
|
---|
| 555 | cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
|
---|
| 556 | DelObj(nom);
|
---|
| 557 | }
|
---|
[165] | 558 | }
|
---|
| 559 |
|
---|
| 560 | nobj_item no;
|
---|
| 561 | no.obj = obj;
|
---|
[295] | 562 | no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
|
---|
[333] | 563 | no.oid = myNObj;
|
---|
| 564 | no.dirid = did;
|
---|
[331] | 565 | (*myObjs)[nom] = no;
|
---|
[333] | 566 |
|
---|
| 567 | (*itr).second.nobj++;
|
---|
| 568 |
|
---|
[2490] | 569 | if (myImgApp != NULL) {
|
---|
| 570 | if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
|
---|
| 571 | if ( (myImgApp->ObjMgrW())->Visible() ) {
|
---|
| 572 | string oln = nobj + " (T= " + no.obja->GetDataObjType() + ")" ;
|
---|
| 573 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
|
---|
[685] | 574 | }
|
---|
[2490] | 575 | }
|
---|
[449] | 576 | if (verbeux) cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
|
---|
[295] | 577 | << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
|
---|
[344] | 578 | return(true);
|
---|
[165] | 579 | }
|
---|
| 580 |
|
---|
[1224] | 581 | bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
|
---|
| 582 | {
|
---|
| 583 | NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
|
---|
| 584 | if (adap == NULL) {
|
---|
| 585 | cout << "NamedObjMgr::AddObj() No Adapter ! " << nom << endl;
|
---|
| 586 | return(false);
|
---|
| 587 | }
|
---|
[1315] | 588 | AnyDataObj * cloneobj = adap->CloneDataObj(true);
|
---|
[1224] | 589 | delete adap;
|
---|
| 590 | if (cloneobj == NULL) {
|
---|
| 591 | cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl;
|
---|
| 592 | return(false);
|
---|
| 593 | }
|
---|
| 594 | return ( AddObj(cloneobj , nom, crd) );
|
---|
| 595 | }
|
---|
| 596 |
|
---|
[165] | 597 | /* --Methode-- */
|
---|
[344] | 598 | bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
|
---|
[165] | 599 | {
|
---|
[333] | 600 | string n1,r1,n2,r2;
|
---|
[344] | 601 | int dids = ParseObjectName(nom, r1, n1);
|
---|
| 602 | NObjDirList::iterator itr1 = myDirs->find(r1);
|
---|
[333] | 603 | int did = ParseObjectName(nomnew, r2, n2);
|
---|
[344] | 604 | NObjDirList::iterator itr2 = myDirs->find(r2);
|
---|
| 605 |
|
---|
[333] | 606 | if (did == 0) {
|
---|
| 607 | cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
|
---|
[344] | 608 | return(false);
|
---|
[2218] | 609 | }
|
---|
[333] | 610 | nom = '/' + r1 + '/' + n1;
|
---|
| 611 | nomnew = '/' + r2 + '/' + n2;
|
---|
| 612 | NObjList::iterator it1 = myObjs->find(nom);
|
---|
| 613 | if (it1 == myObjs->end()) {
|
---|
| 614 | cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl;
|
---|
[344] | 615 | return(false);
|
---|
[2218] | 616 | }
|
---|
| 617 | if ((n2.length() < 1) || (! isalpha(n2[0])) ) {
|
---|
| 618 | cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
|
---|
| 619 | return(false);
|
---|
| 620 | }
|
---|
[333] | 621 | NObjList::iterator it2 = myObjs->find(nomnew);
|
---|
| 622 | if (it2 != myObjs->end()) {
|
---|
| 623 | cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
|
---|
[344] | 624 | return(false);
|
---|
[333] | 625 | }
|
---|
| 626 |
|
---|
[344] | 627 | if ( (*itr1).second.lock || (*itr2).second.lock ) {
|
---|
| 628 | cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !"
|
---|
| 629 | << endl;
|
---|
| 630 | return(false);
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 |
|
---|
[333] | 634 | nobj_item no = (*it1).second;
|
---|
| 635 | no.dirid = did;
|
---|
| 636 | myObjs->erase(it1);
|
---|
| 637 | NObjDirList::iterator itr = myDirs->find(r1);
|
---|
| 638 | (*itr).second.nobj--;
|
---|
| 639 | (*myObjs)[nomnew] = no;
|
---|
| 640 | itr = myDirs->find(r2);
|
---|
| 641 | (*itr).second.nobj++;
|
---|
[685] | 642 |
|
---|
[2490] | 643 | if (myImgApp != NULL) {
|
---|
| 644 | if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
|
---|
| 645 | if ( (myImgApp->ObjMgrW())->Visible() ) {
|
---|
| 646 | (myImgApp->ObjMgrW())->DelObjList(dids, no.oid);
|
---|
| 647 | string oln = n2 + " (T= " + no.obja->GetDataObjType() + ")" ;
|
---|
| 648 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
|
---|
| 649 | }
|
---|
[685] | 650 | }
|
---|
[449] | 651 | if (verbeux)
|
---|
| 652 | cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
|
---|
[344] | 653 | return(true);
|
---|
[331] | 654 | }
|
---|
| 655 |
|
---|
| 656 | /* --Methode-- */
|
---|
[463] | 657 | bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
|
---|
| 658 | {
|
---|
| 659 | if(nomcp.length()<=0)
|
---|
| 660 | {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
|
---|
| 661 | return(false);}
|
---|
| 662 | NObjMgrAdapter* obnom = GetObjAdapter(nom);
|
---|
| 663 | if(obnom==NULL)
|
---|
| 664 | {cout<<"NamedObjMgr::CopyObj() Error - No "<<nom<<" object !"<<endl;
|
---|
| 665 | return(false);}
|
---|
[1165] | 666 | AnyDataObj* obnomcp = obnom->CloneDataObj();
|
---|
[463] | 667 | if(obnomcp==NULL) return(false);
|
---|
| 668 | if(! AddObj(obnomcp,nomcp) ) {delete obnomcp; return(false);}
|
---|
| 669 | return true;
|
---|
| 670 | }
|
---|
| 671 |
|
---|
[1164] | 672 |
|
---|
[463] | 673 | /* --Methode-- */
|
---|
[344] | 674 | bool NamedObjMgr::DelObj(string & nom, bool fgd)
|
---|
[331] | 675 | {
|
---|
[333] | 676 | string n1,r1;
|
---|
[685] | 677 | int did = ParseObjectName(nom, r1, n1);
|
---|
[333] | 678 | nom = '/' + r1 + '/' + n1;
|
---|
[165] | 679 | NObjList::iterator it = myObjs->find(nom);
|
---|
[344] | 680 | if (it == myObjs->end()) return(false);
|
---|
| 681 | NObjDirList::iterator itr = myDirs->find(r1);
|
---|
| 682 | if ( (*itr).second.lock ) {
|
---|
| 683 | cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
|
---|
| 684 | return(false);
|
---|
| 685 | }
|
---|
[165] | 686 | list<int>::iterator ii;
|
---|
| 687 | if (myImgApp) {
|
---|
| 688 | //DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
|
---|
| 689 | for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
|
---|
| 690 | myImgApp->DelWRsId((*ii));
|
---|
| 691 | }
|
---|
[314] | 692 | delete (*it).second.obja; // destruction de l'adaptateur
|
---|
[165] | 693 | if (fgd) delete (*it).second.obj;
|
---|
[333] | 694 |
|
---|
[2490] | 695 | if (myImgApp != NULL) {
|
---|
| 696 | if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
|
---|
| 697 | if ( (myImgApp->ObjMgrW())->Visible() ) {
|
---|
| 698 | int olid = (*it).second.oid;
|
---|
| 699 | (myImgApp->ObjMgrW())->DelObjList(did, olid);
|
---|
| 700 | }
|
---|
[685] | 701 | }
|
---|
[165] | 702 | myObjs->erase(it);
|
---|
[333] | 703 | (*itr).second.nobj--;
|
---|
| 704 |
|
---|
[685] | 705 |
|
---|
[449] | 706 | if (!verbeux) return(true);
|
---|
[165] | 707 | if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
|
---|
| 708 | else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
|
---|
[344] | 709 | return(true);
|
---|
[165] | 710 | }
|
---|
| 711 |
|
---|
| 712 | /* --Methode-- */
|
---|
[344] | 713 | bool NamedObjMgr::DelObj_Id(int oid)
|
---|
[165] | 714 | {
|
---|
[333] | 715 | NObjList::iterator it;
|
---|
| 716 | string nom;
|
---|
| 717 | bool of = false;
|
---|
| 718 | for(it = myObjs->begin(); it != myObjs->end(); it++)
|
---|
| 719 | if ( (*it).second.oid == oid ) {
|
---|
| 720 | of = true; nom = (*it).first;
|
---|
| 721 | break;
|
---|
| 722 | }
|
---|
[344] | 723 | if (of) return(DelObj(nom, true));
|
---|
| 724 | else return(false);
|
---|
[331] | 725 | }
|
---|
| 726 |
|
---|
| 727 | /* --Methode-- */
|
---|
| 728 | void NamedObjMgr::DelObjects(string & patt, bool fgd)
|
---|
| 729 | {
|
---|
[333] | 730 | string n1,r1;
|
---|
| 731 | ParseObjectName(patt, r1, n1);
|
---|
| 732 | patt = '/' + r1 + '/' + n1;
|
---|
[165] | 733 | NObjList::iterator it;
|
---|
| 734 | list<string> odel;
|
---|
| 735 | string cn;
|
---|
| 736 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
| 737 | cn = (*it).first;
|
---|
| 738 | if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
|
---|
| 739 | }
|
---|
| 740 | list<string>::iterator ii;
|
---|
| 741 | for(ii=odel.begin(); ii != odel.end(); ii++) DelObj(*ii, fgd);
|
---|
| 742 | }
|
---|
| 743 |
|
---|
| 744 | /* --Methode-- */
|
---|
[331] | 745 | AnyDataObj* NamedObjMgr::GetObj(string & nom)
|
---|
[165] | 746 | {
|
---|
[333] | 747 | string n1,r1;
|
---|
| 748 | ParseObjectName(nom, r1, n1);
|
---|
| 749 | nom = '/' + r1 + '/' + n1;
|
---|
[165] | 750 | NObjList::iterator it = myObjs->find(nom);
|
---|
| 751 | if (it == myObjs->end()) return(NULL);
|
---|
| 752 | return((*it).second.obj);
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 | /* --Methode-- */
|
---|
[331] | 756 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
|
---|
[295] | 757 | {
|
---|
[333] | 758 | string n1,r1;
|
---|
| 759 | ParseObjectName(nom, r1, n1);
|
---|
| 760 | nom = '/' + r1 + '/' + n1;
|
---|
[295] | 761 | NObjList::iterator it = myObjs->find(nom);
|
---|
| 762 | if (it == myObjs->end()) return(NULL);
|
---|
| 763 | return((*it).second.obja);
|
---|
| 764 | }
|
---|
| 765 |
|
---|
| 766 | /* --Methode-- */
|
---|
[331] | 767 | void NamedObjMgr::ListObjs(string & patt)
|
---|
[165] | 768 | {
|
---|
[331] | 769 | int k;
|
---|
| 770 | AnyDataObj* obj=NULL;
|
---|
| 771 | string ctyp;
|
---|
| 772 | char strg[256];
|
---|
| 773 |
|
---|
[333] | 774 | string n1,r1;
|
---|
| 775 | ParseObjectName(patt, r1, n1);
|
---|
| 776 | patt = '/' + r1 + '/' + n1;
|
---|
| 777 | cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
|
---|
[331] | 778 | NObjList::iterator it; k = 0;
|
---|
[333] | 779 | string cn;
|
---|
[331] | 780 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
[333] | 781 | cn = (*it).first;
|
---|
| 782 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
[331] | 783 | obj = (*it).second.obj;
|
---|
| 784 | ctyp = typeid(*obj).name();
|
---|
| 785 | sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
|
---|
| 786 | ctyp = strg;
|
---|
| 787 | cout << ctyp << "\n" ;
|
---|
| 788 | k++;
|
---|
| 789 | }
|
---|
| 790 | cout << endl;
|
---|
[165] | 791 | return;
|
---|
| 792 | }
|
---|
| 793 |
|
---|
| 794 | /* --Methode-- */
|
---|
[333] | 795 | void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
|
---|
[165] | 796 | {
|
---|
[333] | 797 | string n1,r1;
|
---|
| 798 | if (patt.length() < 1) return;
|
---|
| 799 | bool fgr = (patt[0] == '/') ? true : false;
|
---|
| 800 | ParseObjectName(patt, r1, n1);
|
---|
| 801 | patt = '/' + r1 + '/' + n1;
|
---|
| 802 | NObjList::iterator it;
|
---|
| 803 | string cn;
|
---|
| 804 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
| 805 | cn = (*it).first;
|
---|
| 806 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
| 807 | if (fgr) lst.push_back(cn);
|
---|
| 808 | else {
|
---|
| 809 | ParseObjectName(cn, r1, n1);
|
---|
| 810 | lst.push_back(n1);
|
---|
| 811 | }
|
---|
| 812 | }
|
---|
[165] | 813 | }
|
---|
| 814 |
|
---|
| 815 | //++
|
---|
| 816 | // Titre Entrées-Sorties (I/O) sur les objets
|
---|
| 817 | //--
|
---|
| 818 | //++
|
---|
| 819 | // void ReadObj(PInPersist& s, int num=-1)
|
---|
| 820 | // Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
|
---|
| 821 | // et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
|
---|
| 822 | // sur le flot "s" sont créés et ajoutés à la liste.
|
---|
| 823 | // void ReadObj(string const & nomppf, string nobj="")
|
---|
| 824 | // Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
|
---|
| 825 | // à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
|
---|
| 826 | // composé à partir du nom de fichier.
|
---|
| 827 | //--
|
---|
| 828 |
|
---|
| 829 | /* --Methode-- */
|
---|
[331] | 830 | void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
|
---|
[165] | 831 | {
|
---|
[495] | 832 | PPersist* ppobj=NULL;
|
---|
[165] | 833 | bool ok = true;
|
---|
[495] | 834 | #ifdef SANS_EVOLPLANCK
|
---|
[165] | 835 | TRY{
|
---|
| 836 | PInPersist pis(flnm);
|
---|
[495] | 837 | ppobj = PPersistMgr::ReadObject(pis);
|
---|
| 838 | if (ppobj == NULL) ok = false;
|
---|
[165] | 839 | } CATCH(merr)
|
---|
| 840 | { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
|
---|
| 841 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
[495] | 842 | #else
|
---|
| 843 | try {
|
---|
| 844 | PInPersist pis(flnm);
|
---|
| 845 | ppobj = pis.ReadObject();
|
---|
| 846 | }
|
---|
| 847 | catch (IOExc iox) {
|
---|
| 848 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
| 849 | ok = false;
|
---|
| 850 | }
|
---|
| 851 | #endif
|
---|
[165] | 852 | if (!ok) return;
|
---|
| 853 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
[495] | 854 | AddObj(ppobj->DataObj(), nobj, true);
|
---|
[685] | 855 | cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
|
---|
[165] | 856 | return;
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | /* --Methode-- */
|
---|
| 860 | void NamedObjMgr::ReadObj(PInPersist& s, int num)
|
---|
| 861 | {
|
---|
[2180] | 862 | int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
|
---|
| 863 | #ifdef SANS_EVOLPLANCK
|
---|
| 864 | int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
|
---|
| 865 | #endif
|
---|
[165] | 866 | int n0, n1;
|
---|
| 867 | bool ok = true;
|
---|
| 868 | PPersist* obj=NULL;
|
---|
| 869 | string nom;
|
---|
| 870 |
|
---|
[449] | 871 | int nread = 0;
|
---|
[2460] | 872 | int nbtags = 0;
|
---|
| 873 | #ifdef SANS_EVOLPLANCK
|
---|
| 874 | nbtags = s.NbTags();
|
---|
| 875 | #else
|
---|
| 876 | nbtags = s.NbNameTags();
|
---|
| 877 | #endif
|
---|
| 878 | if ( (nbtags < 1) || (num >= nbtags) ) {
|
---|
[165] | 879 | if (num >= 0) {
|
---|
[495] | 880 | cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << " Error! NbTags ="
|
---|
[2460] | 881 | << nbtags << endl;
|
---|
[165] | 882 | return;
|
---|
| 883 | }
|
---|
[495] | 884 |
|
---|
| 885 | #ifdef SANS_EVOLPLANCK
|
---|
[165] | 886 | TRY {
|
---|
| 887 | obj = PPersistMgr::ReadObject(s);
|
---|
| 888 | if (obj == NULL) ok = false;
|
---|
| 889 | } CATCH(merr) {
|
---|
| 890 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
| 891 | ok = false;
|
---|
| 892 | } ENDTRY;
|
---|
[495] | 893 | #else
|
---|
| 894 | try {
|
---|
| 895 | obj = s.ReadObject();
|
---|
| 896 | }
|
---|
| 897 | catch (IOExc iox) {
|
---|
| 898 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
| 899 | ok = false;
|
---|
| 900 | }
|
---|
| 901 | #endif
|
---|
| 902 |
|
---|
[165] | 903 | if (!ok) return;
|
---|
| 904 | nom = "";
|
---|
[295] | 905 | AddObj(obj->DataObj(), nom);
|
---|
[449] | 906 | nread++;
|
---|
[165] | 907 | }
|
---|
| 908 |
|
---|
[2460] | 909 | if (num < 0) { n0 = 0; n1 = nbtags; }
|
---|
[165] | 910 | else { n0 = num; n1 = num+1; }
|
---|
| 911 | for(i=n0; i<n1; i++) {
|
---|
[495] | 912 | #ifdef SANS_EVOLPLANCK
|
---|
[165] | 913 | key = s.TagKey(i, cid, ln);
|
---|
| 914 | if (ln <= 0) nom = "";
|
---|
| 915 | else nom = s.TagName(i);
|
---|
| 916 | s.GotoTag(i);
|
---|
| 917 | TRY {
|
---|
| 918 | obj = PPersistMgr::ReadObject(s);
|
---|
| 919 | if (obj == NULL) ok = false;
|
---|
| 920 | } CATCH(merr) {
|
---|
| 921 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
| 922 | ok = false;
|
---|
| 923 | } ENDTRY;
|
---|
[495] | 924 | #else
|
---|
[2460] | 925 | s.GotoNameTagNum(i);
|
---|
[584] | 926 | nom = s.GetTagName(i);
|
---|
[495] | 927 | try {
|
---|
| 928 | obj = s.ReadObject();
|
---|
| 929 | }
|
---|
| 930 | catch (IOExc iox) {
|
---|
| 931 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
| 932 | ok = false;
|
---|
| 933 | }
|
---|
| 934 | #endif
|
---|
[449] | 935 | if (ok) { AddObj(obj->DataObj(), nom, true); nread++; }
|
---|
[165] | 936 | }
|
---|
| 937 |
|
---|
[449] | 938 | cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
|
---|
[165] | 939 | return;
|
---|
| 940 | }
|
---|
| 941 | /* --Methode-- */
|
---|
| 942 | void NamedObjMgr::ReadAll(string const & flnm)
|
---|
| 943 | {
|
---|
| 944 | bool ok = true;
|
---|
| 945 | PPersist* obj=NULL;
|
---|
| 946 |
|
---|
[2180] | 947 | PInPersist* ppin=NULL;
|
---|
[495] | 948 | #ifdef SANS_EVOLPLANCK
|
---|
[165] | 949 | TRY{
|
---|
| 950 | ppin = new PInPersist(flnm);
|
---|
| 951 | if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
|
---|
| 952 | else obj = NULL;
|
---|
| 953 | } CATCH(merr)
|
---|
| 954 | { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
|
---|
| 955 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
[495] | 956 | #else
|
---|
| 957 | try {
|
---|
| 958 | ppin = new PInPersist(flnm);
|
---|
[2460] | 959 | if (ppin->NbNameTags() < 1) obj = ppin->ReadObject();
|
---|
[495] | 960 | else obj = NULL;
|
---|
| 961 | }
|
---|
| 962 | catch (IOExc iox) {
|
---|
| 963 | cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
| 964 | ok = false;
|
---|
| 965 | }
|
---|
| 966 | #endif
|
---|
[165] | 967 | if (!ok) return;
|
---|
| 968 | if (obj) {
|
---|
| 969 | string nom = servnobjm->FileName2Name(flnm);
|
---|
[295] | 970 | AddObj(obj->DataObj(), nom);
|
---|
[165] | 971 | }
|
---|
| 972 | else ReadObj((*ppin), -1);
|
---|
| 973 | delete ppin;
|
---|
| 974 | return;
|
---|
| 975 | }
|
---|
| 976 |
|
---|
| 977 | /* --Methode-- */
|
---|
[331] | 978 | void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
|
---|
[165] | 979 | {
|
---|
| 980 |
|
---|
[293] | 981 | #ifdef SANS_EVOLPLANCK
|
---|
[2180] | 982 | bool ok = false;
|
---|
[709] | 983 | RzImage* obj=NULL;
|
---|
[495] | 984 | TRY{
|
---|
[165] | 985 | obj = RzReadFits((char*)flnm.c_str());
|
---|
| 986 | if (obj == NULL) ok = false;
|
---|
[709] | 987 | else ok = true;
|
---|
[165] | 988 | } CATCH(merr) {
|
---|
| 989 | printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
| 990 | ok = false;
|
---|
| 991 | } ENDTRY;
|
---|
[709] | 992 |
|
---|
| 993 | if (ok && (obj != NULL)) {
|
---|
[165] | 994 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
[295] | 995 | AddObj((AnyDataObj*)obj, nobj);
|
---|
[165] | 996 | }
|
---|
[1105] | 997 | #else
|
---|
[1321] | 998 | try {
|
---|
| 999 | FITS_AutoReader fiar(flnm);
|
---|
[1335] | 1000 | char bun[16];
|
---|
| 1001 | int nhdu = fiar.NbBlocks();
|
---|
[1321] | 1002 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
| 1003 | string name;
|
---|
| 1004 | AnyDataObj* obj;
|
---|
[1513] | 1005 | int kon = 1;
|
---|
[1321] | 1006 | for(int k=1; k<=nhdu; k++) {
|
---|
| 1007 | obj = fiar.ReadObject(k);
|
---|
[1330] | 1008 | if (obj) {
|
---|
[1321] | 1009 | cout << " NamedObjMgr::ReadFits() " << (string)typeid(*obj).name()
|
---|
| 1010 | << " read From HDU " << k << endl;
|
---|
[1513] | 1011 | if (typeid(*obj) == typeid(DVList)) {
|
---|
| 1012 | delete obj;
|
---|
| 1013 | continue;
|
---|
| 1014 | }
|
---|
| 1015 | if (kon > 1) {
|
---|
| 1016 | sprintf(bun, "%d", kon);
|
---|
[1330] | 1017 | name = nobj + bun;
|
---|
| 1018 | }
|
---|
| 1019 | else name = nobj;
|
---|
| 1020 | AddObj(obj, name);
|
---|
[1513] | 1021 | kon++;
|
---|
[1330] | 1022 | }
|
---|
[1321] | 1023 | else cerr << " NamedObjMgr::ReadFits() NULL pointer from FITS_AutoReader" << endl;
|
---|
| 1024 | }
|
---|
| 1025 | }
|
---|
| 1026 | catch(PThrowable & exc) {
|
---|
| 1027 | cerr << " NamedObjMgr::ReadFits() / Error - Catched Exception \n "
|
---|
| 1028 | << " Type= " << (string)typeid(exc).name()
|
---|
| 1029 | << " - Msg= " << exc.Msg() << endl;
|
---|
| 1030 |
|
---|
| 1031 | }
|
---|
[1105] | 1032 | #endif
|
---|
| 1033 |
|
---|
[165] | 1034 | return;
|
---|
| 1035 | }
|
---|
| 1036 |
|
---|
| 1037 |
|
---|
| 1038 | static int key_for_write = 5000;
|
---|
| 1039 | /* --Methode-- */
|
---|
[333] | 1040 | void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
|
---|
[165] | 1041 | {
|
---|
[333] | 1042 | if (nom.length() < 1) return;
|
---|
| 1043 | string nob,rep;
|
---|
| 1044 | ParseObjectName(nom, rep, nob);
|
---|
| 1045 | nom = '/' + rep + '/' + nob;
|
---|
[295] | 1046 | NObjMgrAdapter* obja=NULL;
|
---|
[333] | 1047 | string nomf = (keeppath) ? nom : nob;
|
---|
[295] | 1048 | obja = GetObjAdapter(nom);
|
---|
| 1049 | if (obja == NULL) return;
|
---|
[165] | 1050 | printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
|
---|
[295] | 1051 | nom.c_str(), typeid(*(obja->GetDataObj())).name());
|
---|
[333] | 1052 | obja->SavePPF(s, nomf);
|
---|
[165] | 1053 | return;
|
---|
| 1054 | }
|
---|
| 1055 |
|
---|
| 1056 | /* --Methode-- */
|
---|
[333] | 1057 | void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
|
---|
| 1058 | {
|
---|
| 1059 | string n1,r1;
|
---|
| 1060 | if (patt.length() < 1) return;
|
---|
| 1061 | bool keeppath = (patt[0] == '/') ? true : false;
|
---|
| 1062 | ParseObjectName(patt, r1, n1);
|
---|
| 1063 | patt = '/' + r1 + '/' + n1;
|
---|
| 1064 |
|
---|
| 1065 | bool ok = true;
|
---|
[2180] | 1066 | POutPersist* pout=NULL;
|
---|
[495] | 1067 | #ifdef SANS_EVOLPLANCK
|
---|
[333] | 1068 | TRY{
|
---|
| 1069 | pout = new POutPersist(flnm);
|
---|
| 1070 | } CATCH(merr)
|
---|
| 1071 | { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
|
---|
| 1072 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
[495] | 1073 | #else
|
---|
| 1074 | try {
|
---|
| 1075 | pout = new POutPersist(flnm);
|
---|
| 1076 | }
|
---|
| 1077 | catch (IOExc iox) {
|
---|
| 1078 | cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
| 1079 | ok = false;
|
---|
| 1080 | }
|
---|
| 1081 | #endif
|
---|
[333] | 1082 | if (!ok) return;
|
---|
| 1083 | NObjList::iterator it;
|
---|
| 1084 | string cn;
|
---|
| 1085 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
| 1086 | cn = (*it).first;
|
---|
| 1087 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
| 1088 | SaveObj(cn, (*pout), keeppath);
|
---|
| 1089 | }
|
---|
| 1090 | delete pout;
|
---|
| 1091 | return;
|
---|
| 1092 | }
|
---|
| 1093 |
|
---|
| 1094 | /* --Methode-- */
|
---|
[165] | 1095 | void NamedObjMgr::SaveAll(string const& flnm)
|
---|
| 1096 | {
|
---|
| 1097 | bool ok = true;
|
---|
| 1098 |
|
---|
[2180] | 1099 | POutPersist* pout=NULL;
|
---|
[495] | 1100 | #ifdef SANS_EVOLPLANCK
|
---|
[165] | 1101 | TRY{
|
---|
| 1102 | pout = new POutPersist(flnm);
|
---|
| 1103 | } CATCH(merr)
|
---|
| 1104 | { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
|
---|
| 1105 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
[495] | 1106 | #else
|
---|
| 1107 | try {
|
---|
| 1108 | pout = new POutPersist(flnm);
|
---|
| 1109 | }
|
---|
| 1110 | catch (IOExc iox) {
|
---|
| 1111 | cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
| 1112 | ok = false;
|
---|
| 1113 | }
|
---|
| 1114 | #endif
|
---|
[165] | 1115 | if (!ok) return;
|
---|
[332] | 1116 | NObjList::iterator it;
|
---|
| 1117 | string no;
|
---|
| 1118 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
| 1119 | no = (*it).first;
|
---|
[333] | 1120 | SaveObj(no, (*pout), true);
|
---|
[332] | 1121 | }
|
---|
[165] | 1122 | delete pout;
|
---|
| 1123 | return;
|
---|
| 1124 | }
|
---|
| 1125 |
|
---|
| 1126 | /* --Methode-- */
|
---|
[331] | 1127 | void NamedObjMgr::SaveFits(string& nom, string const & flnm)
|
---|
[165] | 1128 | {
|
---|
[295] | 1129 | NObjMgrAdapter* obja=NULL;
|
---|
| 1130 | obja = GetObjAdapter(nom);
|
---|
| 1131 | if (obja == NULL) return;
|
---|
| 1132 | obja->SaveFits(flnm);
|
---|
[293] | 1133 | return;
|
---|
[165] | 1134 | }
|
---|
| 1135 |
|
---|
| 1136 |
|
---|
| 1137 |
|
---|
| 1138 | /* --Methode-- */
|
---|
[331] | 1139 | void NamedObjMgr::PrintObj(string& nom)
|
---|
[165] | 1140 | {
|
---|
[295] | 1141 | NObjMgrAdapter* obja=NULL;
|
---|
| 1142 | obja = GetObjAdapter(nom);
|
---|
| 1143 | if (obja == NULL) return;
|
---|
[594] | 1144 | AnyDataObj* ob = obja->GetDataObj();
|
---|
| 1145 | if (ob == NULL) {
|
---|
| 1146 | cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl;
|
---|
| 1147 | return;
|
---|
| 1148 | }
|
---|
| 1149 | string ctyp = typeid(*ob).name();
|
---|
[295] | 1150 | cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
|
---|
| 1151 | obja->Print(cout);
|
---|
[165] | 1152 |
|
---|
| 1153 | return;
|
---|
| 1154 | }
|
---|
| 1155 |
|
---|
| 1156 | /* --Methode-- */
|
---|
[331] | 1157 | void NamedObjMgr::DisplayObj(string& nom, string dopt)
|
---|
[165] | 1158 | {
|
---|
[295] | 1159 | NObjMgrAdapter* obja=NULL;
|
---|
| 1160 | obja = GetObjAdapter(nom);
|
---|
| 1161 | if (obja == NULL) {
|
---|
[594] | 1162 | cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
|
---|
[165] | 1163 | return;
|
---|
| 1164 | }
|
---|
[594] | 1165 | if (obja->GetDataObj() == NULL) {
|
---|
| 1166 | cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
|
---|
| 1167 | return;
|
---|
| 1168 | }
|
---|
[165] | 1169 | if (!myImgApp) return;
|
---|
| 1170 |
|
---|
[295] | 1171 | PIDrawer * dr = NULL;
|
---|
| 1172 | P2DArrayAdapter* arr = NULL;
|
---|
| 1173 | dr = obja->GetDrawer(dopt);
|
---|
| 1174 | if (!dr) arr = obja->Get2DArray(dopt);
|
---|
[165] | 1175 |
|
---|
[295] | 1176 | if (!dr && !arr) {
|
---|
| 1177 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
[594] | 1178 | cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
|
---|
[295] | 1179 | return;
|
---|
| 1180 | }
|
---|
| 1181 |
|
---|
[165] | 1182 | int wrsid = 0;
|
---|
| 1183 |
|
---|
[344] | 1184 | string n1,r1;
|
---|
| 1185 | ParseObjectName(nom, r1, n1);
|
---|
| 1186 |
|
---|
[295] | 1187 | if (dr) {
|
---|
| 1188 | PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
|
---|
[1971] | 1189 | if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt);
|
---|
| 1190 | else wrsid = myImgApp->DispScDrawer( dr, n1, dopt);
|
---|
[295] | 1191 | }
|
---|
[1971] | 1192 | else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt);
|
---|
[165] | 1193 |
|
---|
[2402] | 1194 | AddWRsId(nom, wrsid);
|
---|
[295] | 1195 | return;
|
---|
| 1196 | }
|
---|
[165] | 1197 |
|
---|
[295] | 1198 | /* --Methode-- */
|
---|
[331] | 1199 | void NamedObjMgr::DisplayImage(string& nom, string dopt)
|
---|
[295] | 1200 | {
|
---|
| 1201 | NObjMgrAdapter* obja=NULL;
|
---|
| 1202 | obja = GetObjAdapter(nom);
|
---|
| 1203 | if (obja == NULL) {
|
---|
[449] | 1204 | cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
|
---|
[295] | 1205 | return;
|
---|
| 1206 | }
|
---|
[594] | 1207 | if (obja->GetDataObj() == NULL) {
|
---|
| 1208 | cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
|
---|
| 1209 | return;
|
---|
| 1210 | }
|
---|
[295] | 1211 | if (!myImgApp) return;
|
---|
| 1212 |
|
---|
| 1213 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
[165] | 1214 |
|
---|
[295] | 1215 | if (!arr) {
|
---|
| 1216 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
[449] | 1217 | cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
|
---|
[295] | 1218 | return;
|
---|
| 1219 | }
|
---|
[165] | 1220 |
|
---|
[344] | 1221 | string n1,r1;
|
---|
| 1222 | ParseObjectName(nom, r1, n1);
|
---|
| 1223 |
|
---|
[295] | 1224 | int wrsid = 0;
|
---|
[1971] | 1225 | wrsid = myImgApp->DispImage(arr, n1, dopt);
|
---|
[165] | 1226 |
|
---|
[2402] | 1227 | AddWRsId(nom, wrsid);
|
---|
[295] | 1228 | return;
|
---|
| 1229 | }
|
---|
| 1230 | /* --Methode-- */
|
---|
[331] | 1231 | void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
|
---|
[295] | 1232 | {
|
---|
| 1233 | NObjMgrAdapter* obja=NULL;
|
---|
| 1234 | obja = GetObjAdapter(nom);
|
---|
| 1235 | if (obja == NULL) {
|
---|
[449] | 1236 | cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
|
---|
[295] | 1237 | return;
|
---|
| 1238 | }
|
---|
[594] | 1239 | if (obja->GetDataObj() == NULL) {
|
---|
| 1240 | cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
|
---|
| 1241 | return;
|
---|
| 1242 | }
|
---|
[295] | 1243 | if (!myImgApp) return;
|
---|
| 1244 |
|
---|
| 1245 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
[165] | 1246 |
|
---|
[295] | 1247 | if (!arr) {
|
---|
| 1248 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
[449] | 1249 | cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
|
---|
[295] | 1250 | return;
|
---|
| 1251 | }
|
---|
[165] | 1252 |
|
---|
[295] | 1253 | if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
|
---|
| 1254 | cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
|
---|
[449] | 1255 | << "x" << arr->YSize() << ") too big (max=250x250)" << endl;
|
---|
[295] | 1256 | delete arr;
|
---|
| 1257 | return;
|
---|
[165] | 1258 | }
|
---|
| 1259 |
|
---|
[344] | 1260 | string n1,r1;
|
---|
| 1261 | ParseObjectName(nom, r1, n1);
|
---|
| 1262 |
|
---|
[295] | 1263 | int wrsid = 0;
|
---|
| 1264 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
---|
[1971] | 1265 | wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt);
|
---|
[2402] | 1266 | AddWRsId(nom, wrsid);
|
---|
[295] | 1267 | return;
|
---|
[165] | 1268 | }
|
---|
| 1269 |
|
---|
| 1270 | /* --Methode-- */
|
---|
[331] | 1271 | void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
|
---|
[486] | 1272 | string& erx, string& ery, string& erz, string& wt,
|
---|
| 1273 | string& label, string dopt, bool fg3d)
|
---|
[165] | 1274 | {
|
---|
[295] | 1275 | AnyDataObj* obj=GetObj(nom);
|
---|
[165] | 1276 | if (obj == NULL) {
|
---|
[449] | 1277 | cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
|
---|
[165] | 1278 | return;
|
---|
| 1279 | }
|
---|
| 1280 | if (!myImgApp) return;
|
---|
| 1281 |
|
---|
[326] | 1282 | NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
|
---|
| 1283 | if (nt == NULL) {
|
---|
| 1284 | // if (typeid(*obj) != typeid(NTupleInterface)) {
|
---|
[295] | 1285 | string ctyp = typeid(*obj).name();
|
---|
[449] | 1286 | cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl;
|
---|
[165] | 1287 | return;
|
---|
| 1288 | }
|
---|
| 1289 |
|
---|
| 1290 | int wrsid = 0;
|
---|
[1971] | 1291 | dopt = "defline " + dopt;
|
---|
[165] | 1292 |
|
---|
[344] | 1293 | string n1,r1;
|
---|
| 1294 | ParseObjectName(nom, r1, n1);
|
---|
| 1295 |
|
---|
[333] | 1296 | if ( fg3d && (nmz.length()>0) ) { // Display 3D
|
---|
[326] | 1297 | PINTuple3D* pin = new PINTuple3D(nt, false);
|
---|
[165] | 1298 | pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
|
---|
[486] | 1299 | pin->SelectWt(wt.c_str());
|
---|
| 1300 | pin->SelectLabel(label.c_str());
|
---|
[165] | 1301 | pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
|
---|
| 1302 | string titre = nmz + "%" + nmy + "%" + nmz;
|
---|
[1971] | 1303 | wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre);
|
---|
[165] | 1304 | }
|
---|
| 1305 | else {
|
---|
[326] | 1306 | PINTuple* pin = new PINTuple(nt, false);
|
---|
[165] | 1307 | pin->SelectXY(nmx.c_str(), nmy.c_str());
|
---|
[486] | 1308 | pin->SelectWt(wt.c_str());
|
---|
| 1309 | pin->SelectLabel(label.c_str());
|
---|
[165] | 1310 | pin->SelectErrBar(erx.c_str(), ery.c_str());
|
---|
[333] | 1311 | string titre = nmy + "%" + nmx;
|
---|
[1971] | 1312 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre);
|
---|
[165] | 1313 | }
|
---|
| 1314 |
|
---|
[2402] | 1315 | AddWRsId(nom, wrsid);
|
---|
[165] | 1316 | return;
|
---|
| 1317 | }
|
---|
| 1318 |
|
---|
[339] | 1319 | /* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
|
---|
[331] | 1320 | void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
|
---|
[165] | 1321 | // Pour le display 2D ou 3D d'un ``GeneralFitData''.
|
---|
| 1322 | //| nom = nom de l'objet GeneralFitData a representer.
|
---|
| 1323 | //| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
|
---|
| 1324 | //| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
|
---|
| 1325 | //| Pour le display 2D, numvary="" string vide.
|
---|
| 1326 | //| err = qu'elles erreurs faut il representer ?
|
---|
| 1327 | //| - 2D : x y xy (display y=f(x))
|
---|
| 1328 | //| - 3D : x y z xy xz yz xzy (display z=f(x,y))
|
---|
| 1329 | //| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
|
---|
| 1330 | //| les barres d'erreurs sont representees.
|
---|
| 1331 | //| opt = options generales pour le display.
|
---|
| 1332 | {
|
---|
[295] | 1333 | AnyDataObj* obj=GetObj(nom);
|
---|
[165] | 1334 | if(obj == NULL)
|
---|
[449] | 1335 | {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
|
---|
[165] | 1336 | return;}
|
---|
| 1337 | if(!myImgApp) return;
|
---|
[295] | 1338 | if(typeid(*obj) != typeid(GeneralFitData))
|
---|
| 1339 | {string ctyp = typeid(*obj).name();
|
---|
[449] | 1340 | cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl;
|
---|
[165] | 1341 | return;}
|
---|
| 1342 |
|
---|
| 1343 | // Decodage des erreurs a representer
|
---|
| 1344 | bool errx=false, erry=false, errz=false;
|
---|
| 1345 | if(err.length()>0) {
|
---|
[2180] | 1346 | for(int i=0;i<(int_4)err.length();i++)
|
---|
[165] | 1347 | if (err[i]=='x' || err[i]=='X') errx = true;
|
---|
| 1348 | else if(err[i]=='y' || err[i]=='Y') erry = true;
|
---|
| 1349 | else if(err[i]=='z' || err[i]=='Z') errz = true;
|
---|
| 1350 | }
|
---|
| 1351 | // Decodage des numeros de variables en abscisse
|
---|
[339] | 1352 | int numvx=-1, numvy=-1;
|
---|
| 1353 | if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
|
---|
| 1354 | if(numvary.length()>0) numvy = atoi(numvary.c_str());
|
---|
| 1355 |
|
---|
[344] | 1356 | string n1,r1;
|
---|
| 1357 | ParseObjectName(nom, r1, n1);
|
---|
| 1358 |
|
---|
[339] | 1359 | int wrsid = 0;
|
---|
| 1360 | if(numvy>=0) { // display 3D
|
---|
[165] | 1361 | PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
|
---|
| 1362 | pigfd->SelectXY(numvx,numvy);
|
---|
| 1363 | pigfd->SelectErrBar(errx,erry,errz);
|
---|
[1971] | 1364 | wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt);
|
---|
[339] | 1365 | } else { // display 2D
|
---|
[165] | 1366 | PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
|
---|
| 1367 | pigfd->SelectX(numvx);
|
---|
| 1368 | pigfd->SelectErrBar(errx,erry);
|
---|
[1971] | 1369 | wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt);
|
---|
[165] | 1370 | }
|
---|
| 1371 |
|
---|
[2402] | 1372 | AddWRsId(nom, wrsid);
|
---|
[1971] | 1373 |
|
---|
[165] | 1374 | return;
|
---|
| 1375 | }
|
---|
| 1376 |
|
---|
[1525] | 1377 | /* --Methode-- */
|
---|
| 1378 | void NamedObjMgr::DisplayVector(string & nomvx, string& nomvy, string dopt)
|
---|
| 1379 | // Pour l'affichage 2-D de points avec coordonnees definies par deux vecteurs
|
---|
| 1380 | // nomvx et nomvy
|
---|
| 1381 | {
|
---|
| 1382 | #ifdef SANS_EVOLPLANCK
|
---|
| 1383 | cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
|
---|
| 1384 | #else
|
---|
| 1385 |
|
---|
| 1386 | if(!myImgApp) return;
|
---|
| 1387 |
|
---|
| 1388 | AnyDataObj* obj;
|
---|
| 1389 | obj = GetObj(nomvx);
|
---|
| 1390 | if(obj == NULL) {
|
---|
| 1391 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl;
|
---|
| 1392 | return;
|
---|
| 1393 | }
|
---|
[2263] | 1394 | //Vector * vx = dynamic_cast<Vector *>(obj);
|
---|
| 1395 | BaseArray* bax = dynamic_cast<BaseArray *>(obj);
|
---|
| 1396 | if (bax == NULL) {
|
---|
| 1397 | cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl;
|
---|
[1525] | 1398 | return;
|
---|
| 1399 | }
|
---|
| 1400 |
|
---|
| 1401 | obj = GetObj(nomvy);
|
---|
| 1402 | if(obj == NULL) {
|
---|
| 1403 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
|
---|
| 1404 | return;
|
---|
| 1405 | }
|
---|
[2263] | 1406 | BaseArray* bay = dynamic_cast<BaseArray *>(obj);
|
---|
| 1407 | if (bay == NULL) {
|
---|
| 1408 | cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
|
---|
[1525] | 1409 | return;
|
---|
| 1410 | }
|
---|
| 1411 |
|
---|
[2263] | 1412 | Vector vx = *bax;
|
---|
| 1413 | Vector vy = *bay;
|
---|
[1525] | 1414 | Vector * cvx, * cvy;
|
---|
| 1415 |
|
---|
[2263] | 1416 | if (vx.Size() != vy.Size()) {
|
---|
[1525] | 1417 | cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl;
|
---|
[2263] | 1418 | if (vx.Size() < vy.Size()) {
|
---|
| 1419 | cvx = new Vector(vx);
|
---|
| 1420 | cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1)));
|
---|
[1525] | 1421 | }
|
---|
| 1422 | else {
|
---|
[2263] | 1423 | cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1)));
|
---|
| 1424 | cvy = new Vector(vy);
|
---|
[1525] | 1425 | }
|
---|
| 1426 | }
|
---|
| 1427 | else {
|
---|
[2263] | 1428 | cvx = new Vector(vx);
|
---|
| 1429 | cvy = new Vector(vy);
|
---|
[1525] | 1430 | }
|
---|
| 1431 |
|
---|
| 1432 | POVectorAdapter * avx = new POVectorAdapter(cvx, true);
|
---|
| 1433 | POVectorAdapter * avy = new POVectorAdapter(cvy, true);
|
---|
| 1434 | PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true);
|
---|
| 1435 |
|
---|
| 1436 | string nx,rx;
|
---|
| 1437 | ParseObjectName(nomvx, rx, nx);
|
---|
| 1438 | string ny,ry;
|
---|
| 1439 | ParseObjectName(nomvy, ry, ny);
|
---|
| 1440 |
|
---|
| 1441 | string title = ny + " (Y) vs. " + nx + " (X)";
|
---|
| 1442 | // display 2D
|
---|
[2180] | 1443 | myImgApp->DispScDrawer(vxydrw, title, dopt);
|
---|
[1525] | 1444 |
|
---|
| 1445 | return;
|
---|
| 1446 |
|
---|
| 1447 | #endif
|
---|
| 1448 | }
|
---|
| 1449 |
|
---|
[165] | 1450 | /* --Methode--
|
---|
[331] | 1451 | void NamedObjMgr::DisplayImage(string& nom, string dopt)
|
---|
[165] | 1452 | {
|
---|
| 1453 | cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
|
---|
| 1454 | }
|
---|
| 1455 | */
|
---|
| 1456 |
|
---|
| 1457 |
|
---|
| 1458 |
|
---|
| 1459 |
|
---|
[1971] | 1460 | /* --Methode--
|
---|
[165] | 1461 | void NamedObjMgr::SetGraphicAttributes(string gratt)
|
---|
| 1462 | {
|
---|
| 1463 | bool fg = false;
|
---|
| 1464 | servnobjm->DecodeDispOption(gratt, fg);
|
---|
[546] | 1465 | Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
|
---|
[165] | 1466 | }
|
---|
[333] | 1467 |
|
---|
[165] | 1468 | void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
|
---|
| 1469 | {
|
---|
| 1470 | if (!myImgApp) return;
|
---|
| 1471 | if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
|
---|
| 1472 | else myImgApp->SetZone(nzx, nzy);
|
---|
| 1473 | }
|
---|
[1971] | 1474 | */
|
---|
[165] | 1475 |
|
---|
| 1476 | /* --Methode-- */
|
---|
[333] | 1477 | void NamedObjMgr::AddWRsId(string & nom, int wrsid)
|
---|
[165] | 1478 | {
|
---|
[333] | 1479 | if(wrsid != 0) {
|
---|
| 1480 | NObjList::iterator it = myObjs->find(nom);
|
---|
| 1481 | if (it == myObjs->end()) return;
|
---|
| 1482 | (*it).second.wrsid.push_back(wrsid);
|
---|
[295] | 1483 | }
|
---|
[165] | 1484 | return;
|
---|
| 1485 | }
|
---|
| 1486 |
|
---|
| 1487 | /* --Methode-- */
|
---|
[333] | 1488 | void NamedObjMgr::UpdateObjMgrWindow(int did)
|
---|
[165] | 1489 | {
|
---|
[333] | 1490 | if (!myImgApp) return;
|
---|
[2490] | 1491 | if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
|
---|
| 1492 |
|
---|
[685] | 1493 | (myImgApp->ObjMgrW())->ClearObjList();
|
---|
[165] | 1494 |
|
---|
[333] | 1495 | NObjList::iterator it;
|
---|
| 1496 | string cn;
|
---|
| 1497 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
| 1498 | if ((*it).second.dirid != did) continue;
|
---|
| 1499 | cn = (*it).first.substr(1);
|
---|
[1321] | 1500 | // cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ;
|
---|
| 1501 | cn = cn.substr(cn.find('/')+1) + " (T= " + (*it).second.obja->GetDataObjType() + ")" ;
|
---|
[685] | 1502 | (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
|
---|
[165] | 1503 | }
|
---|
[333] | 1504 | }
|
---|
[165] | 1505 |
|
---|
| 1506 |
|
---|
[333] | 1507 | /* Nouvelle-Fonction */
|
---|
[1207] | 1508 | void NamedObjMgr::RemoveSpacesFromName(string & nom)
|
---|
[165] | 1509 | {
|
---|
[333] | 1510 | // on supprime les blancs de debut et de fin
|
---|
| 1511 | size_t p = nom.find_first_not_of(" ");
|
---|
| 1512 | if(p>nom.length()) { nom = ""; return; }
|
---|
| 1513 | nom = nom.substr(p);
|
---|
| 1514 | p = nom.find(' ');
|
---|
| 1515 | if(p>nom.length()) p=nom.length();
|
---|
| 1516 | nom = nom.substr(0, p);
|
---|
[165] | 1517 | }
|
---|
| 1518 |
|
---|
[333] | 1519 | /* Nouvelle-Fonction */
|
---|
[1207] | 1520 | bool NamedObjMgr::CheckDirName(string & nom)
|
---|
[165] | 1521 | {
|
---|
[333] | 1522 | RemoveSpacesFromName(nom);
|
---|
| 1523 | if (nom.length() < 1) return(false);
|
---|
| 1524 | if (nom[0] == '/') nom = nom.substr(1) ;
|
---|
| 1525 | size_t p = nom.find('/');
|
---|
| 1526 | if (p < nom.length()) nom = nom.substr(0,p);
|
---|
[2218] | 1527 | if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
|
---|
[333] | 1528 | return(true);
|
---|
[165] | 1529 | }
|
---|
| 1530 |
|
---|
[333] | 1531 | /* Nouvelle-Fonction */
|
---|
[1207] | 1532 | int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
|
---|
[165] | 1533 | {
|
---|
[333] | 1534 | RemoveSpacesFromName(nom);
|
---|
| 1535 | // Si le nom ne commence pas par un slash, c'est le repertoire courant
|
---|
| 1536 | if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
|
---|
[165] | 1537 | else {
|
---|
[333] | 1538 | string xx = nom.substr(1);
|
---|
| 1539 | size_t p = xx.find('/');
|
---|
| 1540 | if (p < xx.length()) {
|
---|
| 1541 | nomrep = xx.substr(0,p);
|
---|
| 1542 | nomobj = xx.substr(p+1);
|
---|
[165] | 1543 | }
|
---|
[333] | 1544 | else {
|
---|
| 1545 | nomrep = xx;
|
---|
| 1546 | nomobj = "";
|
---|
[165] | 1547 | }
|
---|
| 1548 | }
|
---|
[333] | 1549 | int rc = 0;
|
---|
| 1550 | NObjDirList::iterator it = myDirs->find(nomrep);
|
---|
| 1551 | if (it != myDirs->end()) rc = (*it).second.id;
|
---|
| 1552 | return(rc);
|
---|
[165] | 1553 | }
|
---|
| 1554 |
|
---|