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