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