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