source: Sophya/trunk/SophyaPI/PIext/nobjmgr.cc@ 1513

Last change on this file since 1513 was 1513, checked in by ansari, 24 years ago

Modifs cosmetiques ... Reza 31/5/2001

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