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

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

Ajout methode NamedObjMgr::DisplayVector() et commande vecplot , Reza 13/6/2001

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