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

Last change on this file since 333 was 333, checked in by ercodmgr, 26 years ago

Trace de NTuple en 2D avec Marker de taille proportionnelle a Weight
Introduction des repertoires dans la gestion d'objets NameObjMgr
Reorganisation NamedObjMgr et Services2NObjMgr, ajout de commandes , ...
Reza 12/7/99

File size: 27.5 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#if defined(__KCC__)
11using std::string ;
12#include <list.h>
13#include <map.h>
14#endif
15
16#include "strutil.h"
17#include "datatypes.h"
18
19#include "nobjmgr.h"
20#include "servnobjm.h"
21#include "nomgadapter.h"
22#include "pistdimgapp.h"
23
24
25// EVOL-PLANCK
26#ifdef SANS_EVOLPLANCK
27#include "fitsimage.h"
28#endif
29
30#include "pisurfdr.h"
31#include "pipodrw.h"
32
33#include "pintuple.h"
34#include "pintup3d.h"
35#include "pigfd1.h"
36#include "pigfd2.h"
37
38
39//++
40// Class NamedObjMgr
41// Lib PI
42// include nobjmgr.h
43//
44// Cette classe fournit les services nécéssaire àla gestion des objets
45// (l'ensemble des objets PPersist de PEIDA++) au sein du programme
46// d'analyse interactive *piapp* . Elle constitue en outre l'interface
47// entre les fonctions utilisateur et l'application graphique.
48//--
49//++
50// Links Voir aussi
51// PIStdImgApp
52// Services2NObjMgr
53// PIACmd
54//--
55
56
57// ..................................................................
58// ...... Gestion des objets nommes, variables globales ............
59struct nobj_diritem {
60 int id;
61 int nobj;
62};
63
64typedef map<string, nobj_diritem, less<string> > NObjDirList;
65
66struct nobj_item {
67 AnyDataObj* obj;
68 NObjMgrAdapter* obja;
69 int oid;
70 int dirid;
71 list<int> wrsid;
72 bool operator==(nobj_item const& b) const
73 { return (this->obj == b.obj); }
74};
75
76typedef map<string, nobj_item, less<string> > NObjList;
77
78static NObjDirList* myDirs = NULL;
79static NObjList* myObjs = NULL;
80static int fgOInit = 0;
81static int myNObj = 0;
82static int myDirId = 0;
83static string* currDir;
84
85static PIStdImgApp* myImgApp=NULL;
86static Services2NObjMgr* servnobjm=NULL;
87
88static string* TmpDir; // Repertoire pour les compilations / link dynamique
89
90// Pour completer le nom de l'objet avec le nom du repertoire
91static void RemoveSpacesFromName(string & nom);
92static bool CheckDirName(string & nom);
93static int ParseObjectName(string & nom, string & nomrep, string & nomobj);
94// ..................................................................
95
96//++
97// Titre Constructeurs
98//--
99//++
100// NamedObjMgr()
101// Constructeur. Les différents instantiation de la classe "NamedObjMgr"
102// dans une même application créent des objets qui travaillent sur la même
103// liste d'objets. Les objets de cette classe ne possedent en effet pas
104// de variables membres.
105//--
106
107/* --Methode-- */
108NamedObjMgr::NamedObjMgr()
109{
110if (fgOInit == 0) {
111 myNObj = 0;
112 myDirId = 0;
113 myDirs = new NObjDirList;
114 myObjs = new NObjList;
115 currDir = new string("home");
116 string dirn = "home";
117 CreateDir(dirn);
118 dirn = "tmp";
119 CreateDir(dirn);
120 dirn = "old";
121 CreateDir(dirn);
122 dirn = "home";
123 SetCurrentDir(dirn);
124 myDirId = 50;
125 char* varenv;
126 TmpDir = new string("");
127 if ( (varenv=getenv("PEIDA_TMP")) != NULL ) (*TmpDir) = varenv;
128 else if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
129 int l = (*TmpDir).length();
130 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
131 servnobjm = new Services2NObjMgr(this, (*TmpDir));
132 }
133fgOInit++;
134}
135
136
137/* --Methode-- */
138NamedObjMgr::~NamedObjMgr()
139{
140fgOInit--;
141if (fgOInit == 0) delete myObjs;
142}
143
144//++
145// Titre Méthodes
146//--
147//++
148// void SetImgApp(PIStdImgApp* app)
149// Spécifie l'objet "PIStdImgApp" associé.
150// PIStdImgApp* GetImgApp()
151// Accès à l'objet "PIStdImgApp" associé.
152//--
153
154/* --Methode-- */
155void NamedObjMgr::SetImgApp(PIStdImgApp* app)
156{
157myImgApp = app;
158servnobjm->SetImgApp(app);
159
160NObjDirList::iterator it;
161string cn;
162for(it= myDirs->begin(); it != myDirs->end(); it++) {
163 cn = '/' + (*it).first;
164 (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id);
165 }
166}
167
168/* --Methode-- */
169PIStdImgApp* NamedObjMgr::GetImgApp()
170{
171return(myImgApp);
172}
173
174/* --Methode-- */
175Services2NObjMgr* NamedObjMgr::GetServiceObj()
176{
177return(servnobjm);
178}
179
180/* --Methode-- */
181void NamedObjMgr::CreateDir(string & dirname)
182{
183if ( !CheckDirName(dirname) ) {
184 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
185 return;
186 }
187NObjDirList::iterator it = myDirs->find(dirname);
188if (it != myDirs->end()) {
189 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
190 return;
191 }
192myDirId++;
193nobj_diritem di;
194di.id = myDirId;
195di.nobj = 0;
196(*myDirs)[dirname] = di;
197if (myImgApp) {
198 string str = '/' + dirname;
199 (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
200 }
201cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
202}
203
204/* --Methode-- */
205void NamedObjMgr::DeleteDir(string & dirname)
206{
207if ( !CheckDirName(dirname) ) {
208 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
209 return;
210 }
211NObjDirList::iterator it = myDirs->find(dirname);
212if (it == myDirs->end()) {
213 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
214 return;
215 }
216if ((*it).second.nobj > 0) {
217 cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
218 return;
219 }
220if ((*it).second.id < 50) {
221 cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
222 return;
223 }
224
225if (myImgApp)
226 (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
227myDirs->erase(it);
228cout << "amedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
229}
230
231/* --Methode-- */
232void NamedObjMgr::SetCurrentDir(string & dirname)
233{
234if ( !CheckDirName(dirname) ) {
235 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
236 return;
237 }
238NObjDirList::iterator it = myDirs->find(dirname);
239if (it == myDirs->end()) {
240 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
241 return;
242 }
243*currDir = dirname;
244cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
245}
246
247/* --Methode-- */
248void NamedObjMgr::GetCurrentDir(string & dirname)
249{
250dirname = *currDir;
251}
252
253/* --Methode-- */
254void NamedObjMgr::ListDirs(string & patt)
255{
256NObjDirList::iterator it;
257string cn;
258cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl;
259int k = 0;
260for(it= myDirs->begin(); it != myDirs->end(); it++) {
261 cn = (*it).first;
262 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
263 k++;
264 cout << k << "- " << (*it).first << " (NbObj= " << (*it).second.nobj << ")" << endl;
265 }
266}
267
268/* --Methode-- */
269void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
270{
271NObjDirList::iterator it;
272string cn;
273for(it= myDirs->begin(); it != myDirs->end(); it++) {
274 cn = (*it).first;
275 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
276 lstd.push_back(cn);
277 }
278}
279
280/* --Methode-- */
281void NamedObjMgr::CleanTmpDir()
282{
283}
284
285/* --Methode-- */
286void NamedObjMgr::CleanOldDir()
287{
288}
289
290
291//++
292// Titre Gestion de la liste des objets
293//--
294//++
295// void AddObj(AnyDataObj* obj, string& nom)
296// Ajoute l'objet "obj" à la liste, identifié par "nom".
297// Si un objet de même nom existe, l'ancien objet est renommé en concaténant
298// un numéro à son nom.
299// void DelObj(string const& nom, bool fgd=true)
300// Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
301// void DelObjects(string const& patt, bool fgd=true)
302// Supprime l'ensemble des objets dont le nom correspond au patron "patt".
303// Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
304// AnyDataObj* GetObj(string const& nom)
305// Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
306// pas dans la liste.
307// void RenameObj(string const& nom, string& nomnew)
308// Change le nom d'un objet dans la liste.
309//--
310
311
312/* --Methode-- */
313void NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
314{
315
316if (obj == NULL) return;
317// On verifie si l'objet est deja dans la liste
318NObjList::iterator it;
319for(it = myObjs->begin(); it != myObjs->end(); it++) {
320 if ((*it).second.obj == obj) {
321 cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
322 return;
323 }
324 }
325string nobj;
326string nrep;
327char buff[32];
328int did = ParseObjectName(nom, nrep, nobj);
329if (did == 0) {
330 if (!crd) {
331 cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
332 return;
333 }
334 else { CreateDir(nrep); did = myDirId; }
335 }
336
337myNObj++;
338if (nobj.length() < 1) {
339 sprintf(buff,"O%d", myNObj);
340 nobj = buff;
341 }
342
343nom = '/' + nrep + '/' + nobj;
344it = myObjs->find(nom);
345if (it != myObjs->end()) { // l'objet existe deja
346 if (nrep == "tmp") { // Les objets de /tmp sont jetes
347 cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
348 DelObj(nom);
349 }
350 else { // On met l'ancien objet dans /old
351 string on,od;
352 ParseObjectName((*it).first, od, on);
353 sprintf(buff, "%d", (*it).second.oid);
354 string nomnew = "/old/" + on + buff;
355 RenameObj(nom, nomnew);
356 }
357 }
358
359nobj_item no;
360no.obj = obj;
361no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
362no.oid = myNObj;
363no.dirid = did;
364(*myObjs)[nom] = no;
365
366NObjDirList::iterator itr = myDirs->find(nrep);
367(*itr).second.nobj++;
368
369cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
370 << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
371return;
372}
373
374/* --Methode-- */
375void NamedObjMgr::RenameObj(string & nom, string& nomnew)
376{
377string n1,r1,n2,r2;
378ParseObjectName(nom, r1, n1);
379int did = ParseObjectName(nomnew, r2, n2);
380if (did == 0) {
381 cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
382 return;
383 }
384nom = '/' + r1 + '/' + n1;
385nomnew = '/' + r2 + '/' + n2;
386NObjList::iterator it1 = myObjs->find(nom);
387if (it1 == myObjs->end()) {
388 cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl;
389 return;
390 }
391NObjList::iterator it2 = myObjs->find(nomnew);
392if (it2 != myObjs->end()) {
393 cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
394 return;
395 }
396
397nobj_item no = (*it1).second;
398no.dirid = did;
399myObjs->erase(it1);
400NObjDirList::iterator itr = myDirs->find(r1);
401(*itr).second.nobj--;
402(*myObjs)[nomnew] = no;
403itr = myDirs->find(r2);
404(*itr).second.nobj++;
405cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
406return;
407}
408
409/* --Methode-- */
410void NamedObjMgr::DelObj(string & nom, bool fgd)
411{
412string n1,r1;
413ParseObjectName(nom, r1, n1);
414nom = '/' + r1 + '/' + n1;
415NObjList::iterator it = myObjs->find(nom);
416if (it == myObjs->end()) return;
417list<int>::iterator ii;
418if (myImgApp) {
419//DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
420 for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
421 myImgApp->DelWRsId((*ii));
422}
423delete (*it).second.obja; // destruction de l'adaptateur
424if (fgd) delete (*it).second.obj;
425
426myObjs->erase(it);
427NObjDirList::iterator itr = myDirs->find(r1);
428(*itr).second.nobj--;
429
430if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
431else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
432return;
433}
434
435/* --Methode-- */
436void NamedObjMgr::DelObj_Id(int oid)
437{
438NObjList::iterator it;
439string nom;
440bool of = false;
441for(it = myObjs->begin(); it != myObjs->end(); it++)
442 if ( (*it).second.oid == oid ) {
443 of = true; nom = (*it).first;
444 break;
445 }
446if (of) DelObj(nom, true);
447}
448
449/* --Methode-- */
450void NamedObjMgr::DelObjects(string & patt, bool fgd)
451{
452string n1,r1;
453ParseObjectName(patt, r1, n1);
454patt = '/' + r1 + '/' + n1;
455NObjList::iterator it;
456list<string> odel;
457string cn;
458for(it = myObjs->begin(); it != myObjs->end(); it++) {
459 cn = (*it).first;
460 if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
461 }
462list<string>::iterator ii;
463for(ii=odel.begin(); ii != odel.end(); ii++) DelObj(*ii, fgd);
464}
465
466/* --Methode-- */
467AnyDataObj* NamedObjMgr::GetObj(string & nom)
468{
469string n1,r1;
470ParseObjectName(nom, r1, n1);
471nom = '/' + r1 + '/' + n1;
472NObjList::iterator it = myObjs->find(nom);
473if (it == myObjs->end()) return(NULL);
474return((*it).second.obj);
475}
476
477/* --Methode-- */
478NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
479{
480string n1,r1;
481ParseObjectName(nom, r1, n1);
482nom = '/' + r1 + '/' + n1;
483NObjList::iterator it = myObjs->find(nom);
484if (it == myObjs->end()) return(NULL);
485return((*it).second.obja);
486}
487
488/* --Methode-- */
489void NamedObjMgr::ListObjs(string & patt)
490{
491int k;
492AnyDataObj* obj=NULL;
493string ctyp;
494char strg[256];
495
496string n1,r1;
497ParseObjectName(patt, r1, n1);
498patt = '/' + r1 + '/' + n1;
499 cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
500NObjList::iterator it; k = 0;
501string cn;
502for(it = myObjs->begin(); it != myObjs->end(); it++) {
503 cn = (*it).first;
504 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
505 obj = (*it).second.obj;
506 ctyp = typeid(*obj).name();
507 sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
508 ctyp = strg;
509 cout << ctyp << "\n" ;
510 k++;
511}
512cout << endl;
513return;
514}
515
516/* --Methode-- */
517void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
518{
519string n1,r1;
520if (patt.length() < 1) return;
521bool fgr = (patt[0] == '/') ? true : false;
522ParseObjectName(patt, r1, n1);
523patt = '/' + r1 + '/' + n1;
524NObjList::iterator it;
525string cn;
526for(it = myObjs->begin(); it != myObjs->end(); it++) {
527 cn = (*it).first;
528 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
529 if (fgr) lst.push_back(cn);
530 else {
531 ParseObjectName(cn, r1, n1);
532 lst.push_back(n1);
533 }
534 }
535}
536
537//++
538// Titre Entrées-Sorties (I/O) sur les objets
539//--
540//++
541// void ReadObj(PInPersist& s, int num=-1)
542// Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
543// et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
544// sur le flot "s" sont créés et ajoutés à la liste.
545// void ReadObj(string const & nomppf, string nobj="")
546// Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
547// à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
548// composé à partir du nom de fichier.
549//--
550
551/* --Methode-- */
552void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
553{
554PPersist* obj=NULL;
555bool ok = true;
556
557TRY{
558 PInPersist pis(flnm);
559 obj = PPersistMgr::ReadObject(pis);
560 if (obj == NULL) ok = false;
561} CATCH(merr)
562 { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
563 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
564
565if (!ok) return;
566if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
567AddObj(obj->DataObj(), nobj, true);
568return;
569}
570
571/* --Methode-- */
572void NamedObjMgr::ReadObj(PInPersist& s, int num)
573{
574int i, cid, key, ln;
575int n0, n1;
576bool ok = true;
577PPersist* obj=NULL;
578string nom;
579
580if ( (s.NbTags() < 1) || (num >= s.NbTags()) ) {
581 if (num >= 0) {
582 printf("NamedObjMgr::ReadObj(PInPersist, %d) Error! NbTags = %d \n", num, s.NbTags());
583 return;
584 }
585 TRY {
586 obj = PPersistMgr::ReadObject(s);
587 if (obj == NULL) ok = false;
588 } CATCH(merr) {
589 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
590 ok = false;
591 } ENDTRY;
592 if (!ok) return;
593 nom = "";
594 AddObj(obj->DataObj(), nom);
595}
596
597if (num < 0) { n0 = 0; n1 = s.NbTags(); }
598else { n0 = num; n1 = num+1; }
599for(i=n0; i<n1; i++) {
600 key = s.TagKey(i, cid, ln);
601 if (ln <= 0) nom = "";
602 else nom = s.TagName(i);
603 s.GotoTag(i);
604 TRY {
605 obj = PPersistMgr::ReadObject(s);
606 if (obj == NULL) ok = false;
607 } CATCH(merr) {
608 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
609 ok = false;
610 } ENDTRY;
611 if (ok) AddObj(obj->DataObj(), nom, true);
612}
613
614return;
615}
616/* --Methode-- */
617void NamedObjMgr::ReadAll(string const & flnm)
618{
619bool ok = true;
620PPersist* obj=NULL;
621
622PInPersist* ppin;
623TRY{
624 ppin = new PInPersist(flnm);
625 if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
626 else obj = NULL;
627} CATCH(merr)
628 { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
629 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
630
631if (!ok) return;
632if (obj) {
633 string nom = servnobjm->FileName2Name(flnm);
634 AddObj(obj->DataObj(), nom);
635 }
636else ReadObj((*ppin), -1);
637delete ppin;
638return;
639}
640
641/* --Methode-- */
642void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
643{
644bool ok = true;
645RzImage* obj;
646
647TRY{
648// obj = RzReadFits((char*)flnm.c_str(), ImgOffX, ImgOffY, ImgSizX, ImgSizY, ImgBitSgn);
649#ifdef SANS_EVOLPLANCK
650 obj = RzReadFits((char*)flnm.c_str());
651#else
652 printf("NamedObjMgr::ReadFITS( NON-Disponible EVOL-PLANCK) \n");
653 obj = NULL;
654#endif
655 if (obj == NULL) ok = false;
656} CATCH(merr) {
657 printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
658 ok = false;
659} ENDTRY;
660if (ok) {
661 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
662 AddObj((AnyDataObj*)obj, nobj);
663}
664return;
665}
666
667
668static int key_for_write = 5000;
669/* --Methode-- */
670void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
671{
672if (nom.length() < 1) return;
673string nob,rep;
674ParseObjectName(nom, rep, nob);
675nom = '/' + rep + '/' + nob;
676NObjMgrAdapter* obja=NULL;
677string nomf = (keeppath) ? nom : nob;
678obja = GetObjAdapter(nom);
679if (obja == NULL) return;
680printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
681 nom.c_str(), typeid(*(obja->GetDataObj())).name());
682obja->SavePPF(s, nomf);
683return;
684}
685
686/* --Methode-- */
687void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
688{
689string n1,r1;
690if (patt.length() < 1) return;
691bool keeppath = (patt[0] == '/') ? true : false;
692ParseObjectName(patt, r1, n1);
693patt = '/' + r1 + '/' + n1;
694
695bool ok = true;
696POutPersist* pout;
697TRY{
698 pout = new POutPersist(flnm);
699} CATCH(merr)
700 { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
701 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
702if (!ok) return;
703NObjList::iterator it;
704string cn;
705for(it = myObjs->begin(); it != myObjs->end(); it++) {
706 cn = (*it).first;
707 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
708 SaveObj(cn, (*pout), keeppath);
709 }
710delete pout;
711return;
712}
713
714/* --Methode-- */
715void NamedObjMgr::SaveAll(string const& flnm)
716{
717bool ok = true;
718
719POutPersist* pout;
720TRY{
721 pout = new POutPersist(flnm);
722} CATCH(merr)
723 { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
724 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
725if (!ok) return;
726NObjList::iterator it;
727string no;
728for(it = myObjs->begin(); it != myObjs->end(); it++) {
729 no = (*it).first;
730 SaveObj(no, (*pout), true);
731 }
732delete pout;
733return;
734}
735
736/* --Methode-- */
737void NamedObjMgr::SaveFits(string& nom, string const & flnm)
738{
739NObjMgrAdapter* obja=NULL;
740obja = GetObjAdapter(nom);
741if (obja == NULL) return;
742obja->SaveFits(flnm);
743return;
744}
745
746
747
748/* --Methode-- */
749void NamedObjMgr::PrintObj(string& nom)
750{
751NObjMgrAdapter* obja=NULL;
752obja = GetObjAdapter(nom);
753if (obja == NULL) return;
754
755string ctyp = typeid(*obja->GetDataObj()).name();
756cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
757obja->Print(cout);
758
759return;
760}
761
762/* --Methode-- */
763void NamedObjMgr::DisplayObj(string& nom, string dopt)
764{
765NObjMgrAdapter* obja=NULL;
766obja = GetObjAdapter(nom);
767if (obja == NULL) {
768 cout << "NamedObjMgr::DisplayObj() Error , Pas d'objet de nom " << nom << endl;
769 return;
770}
771if (!myImgApp) return;
772
773PIDrawer * dr = NULL;
774P2DArrayAdapter* arr = NULL;
775dr = obja->GetDrawer(dopt);
776if (!dr) arr = obja->Get2DArray(dopt);
777
778if (!dr && !arr) {
779 string ctyp = typeid(*(obja->GetDataObj())).name();
780 cout << "NamedObjMgr::DisplayObj() Error , Pas de display pour " << ctyp << endl;
781 return;
782 }
783
784int wrsid = 0;
785bool fgsr = true;
786int opt = servnobjm->DecodeDispOption(dopt, fgsr);
787
788if (dr) {
789 PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
790 if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, nom, opt);
791 else wrsid = myImgApp->DispScDrawer( dr, nom, opt);
792 }
793else if (arr) wrsid = myImgApp->DispImage(arr, nom, opt);
794
795if(wrsid != 0) {
796 NObjList::iterator it = myObjs->find(nom);
797 if (it == myObjs->end()) return;
798 (*it).second.wrsid.push_back(wrsid);
799 }
800if (fgsr) myImgApp->RestoreGraphicAtt();
801return;
802}
803
804/* --Methode-- */
805void NamedObjMgr::DisplayImage(string& nom, string dopt)
806{
807NObjMgrAdapter* obja=NULL;
808obja = GetObjAdapter(nom);
809if (obja == NULL) {
810 cout << "NamedObjMgr::DisplayImage() Error , Pas d'objet de nom " << nom << endl;
811 return;
812}
813if (!myImgApp) return;
814
815P2DArrayAdapter* arr = obja->Get2DArray(dopt);
816
817if (!arr) {
818 string ctyp = typeid(*(obja->GetDataObj())).name();
819 cout << "NamedObjMgr::DisplayImage() Error , Non supporte pour " << ctyp << endl;
820 return;
821 }
822
823int wrsid = 0;
824bool fgsr = true;
825int opt = servnobjm->DecodeDispOption(dopt, fgsr);
826wrsid = myImgApp->DispImage(arr, nom, opt);
827
828if(wrsid != 0) {
829 NObjList::iterator it = myObjs->find(nom);
830 if (it == myObjs->end()) return;
831 (*it).second.wrsid.push_back(wrsid);
832 }
833if (fgsr) myImgApp->RestoreGraphicAtt();
834return;
835}
836/* --Methode-- */
837void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
838{
839NObjMgrAdapter* obja=NULL;
840obja = GetObjAdapter(nom);
841if (obja == NULL) {
842 cout << "NamedObjMgr::DisplayImage() Error , Pas d'objet de nom " << nom << endl;
843 return;
844}
845if (!myImgApp) return;
846
847P2DArrayAdapter* arr = obja->Get2DArray(dopt);
848
849if (!arr) {
850 string ctyp = typeid(*(obja->GetDataObj())).name();
851 cout << "NamedObjMgr::DisplaySurf3D() Error , Non supporte pour " << ctyp << endl;
852 return;
853 }
854
855if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
856 cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
857 << "x" << arr->YSize() << ") trop grand (max=250x250)" << endl;
858 delete arr;
859 return;
860 }
861
862int wrsid = 0;
863bool fgsr = true;
864int opt = servnobjm->DecodeDispOption(dopt, fgsr);
865PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
866wrsid = myImgApp->Disp3DDrawer(sdr, nom, opt);
867if(wrsid >= 0) {
868 NObjList::iterator it = myObjs->find(nom);
869 if (it == myObjs->end()) return;
870 (*it).second.wrsid.push_back(wrsid);
871 }
872
873if (fgsr) myImgApp->RestoreGraphicAtt();
874return;
875}
876
877/* --Methode-- */
878void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
879 string& erx, string& ery, string& erz, string dopt, bool fg3d)
880{
881AnyDataObj* obj=GetObj(nom);
882if (obj == NULL) {
883 cout << "NamedObjMgr::DisplayNT() Error , Pas d'objet de nom " << nom << endl;
884 return;
885}
886if (!myImgApp) return;
887
888NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
889if (nt == NULL) {
890// if (typeid(*obj) != typeid(NTupleInterface)) {
891 string ctyp = typeid(*obj).name();
892 cout << "NamedObjMgr::DisplayNT() Error , Objet n'est pas un NTuple " << ctyp << endl;
893 return;
894 }
895
896int wrsid = 0;
897bool fgsr = true;
898dopt = "defline," + dopt;
899int opt = servnobjm->DecodeDispOption(dopt, fgsr);
900
901if ( fg3d && (nmz.length()>0) ) { // Display 3D
902 PINTuple3D* pin = new PINTuple3D(nt, false);
903 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
904 pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
905 string titre = nmz + "%" + nmy + "%" + nmz;
906 wrsid = myImgApp->Disp3DDrawer(pin, nom, opt, titre);
907}
908else {
909 PINTuple* pin = new PINTuple(nt, false);
910 pin->SelectXY(nmx.c_str(), nmy.c_str());
911 pin->SelectErrBar(erx.c_str(), ery.c_str());
912 if ( nmz.length()>0 ) pin->SelectWt(nmz.c_str());
913 string titre = nmy + "%" + nmx;
914 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, nom, opt, titre);
915 }
916
917if(wrsid >= 0) {
918 NObjList::iterator it = myObjs->find(nom);
919 if (it == myObjs->end()) return;
920 (*it).second.wrsid.push_back(wrsid);
921 }
922
923if (fgsr) myImgApp->RestoreGraphicAtt();
924return;
925}
926
927/* --Methode-- cmv 13/10/98 */
928void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
929// Pour le display 2D ou 3D d'un ``GeneralFitData''.
930//| nom = nom de l'objet GeneralFitData a representer.
931//| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
932//| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
933//| Pour le display 2D, numvary="" string vide.
934//| err = qu'elles erreurs faut il representer ?
935//| - 2D : x y xy (display y=f(x))
936//| - 3D : x y z xy xz yz xzy (display z=f(x,y))
937//| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
938//| les barres d'erreurs sont representees.
939//| opt = options generales pour le display.
940{
941AnyDataObj* obj=GetObj(nom);
942if(obj == NULL)
943 {cout << "NamedObjMgr::DisplayGFD() Error , Pas d'objet de nom " << nom << endl;
944 return;}
945if(!myImgApp) return;
946if(typeid(*obj) != typeid(GeneralFitData))
947 {string ctyp = typeid(*obj).name();
948 cout<<"NamedObjMgr::DisplayGFD() Error , Objet n'est pas un GeneralFitData "<<ctyp<<endl;
949 return;}
950
951// Decodage des options classiques
952bool fgsr = true;
953int opt = servnobjm->DecodeDispOption(dopt, fgsr);
954// Decodage des erreurs a representer
955bool errx=false, erry=false, errz=false;
956if(err.length()>0) {
957 for(int i=0;i<err.length();i++)
958 if (err[i]=='x' || err[i]=='X') errx = true;
959 else if(err[i]=='y' || err[i]=='Y') erry = true;
960 else if(err[i]=='z' || err[i]=='Z') errz = true;
961}
962// Decodage des numeros de variables en abscisse
963int numvx=-1, numvy=-1;
964if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
965if(numvary.length()>0) numvy = atoi(numvary.c_str());
966
967int wrsid = 0;
968if(numvy>=0) { // Display 3D
969 PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
970 pigfd->SelectXY(numvx,numvy);
971 pigfd->SelectErrBar(errx,erry,errz);
972 wrsid = myImgApp->Disp3DDrawer(pigfd,nom,opt);
973} else { // Display 2D
974 PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
975 pigfd->SelectX(numvx);
976 pigfd->SelectErrBar(errx,erry);
977 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,nom,opt);
978}
979
980if(wrsid >= 0) {
981 NObjList::iterator it = myObjs->find(nom);
982 if (it == myObjs->end()) return;
983 (*it).second.wrsid.push_back(wrsid);
984}
985if (fgsr) myImgApp->RestoreGraphicAtt();
986return;
987}
988
989/* --Methode--
990void NamedObjMgr::DisplayImage(string& nom, string dopt)
991{
992 cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
993}
994*/
995
996
997
998
999/* --Methode-- */
1000void NamedObjMgr::SetGraphicAttributes(string gratt)
1001{
1002bool fg = false;
1003servnobjm->DecodeDispOption(gratt, fg);
1004}
1005
1006/* --Methode-- */
1007void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
1008{
1009if (!myImgApp) return;
1010if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
1011else myImgApp->SetZone(nzx, nzy);
1012}
1013
1014/* --Methode-- */
1015void NamedObjMgr::AddWRsId(string & nom, int wrsid)
1016{
1017if(wrsid != 0) {
1018 NObjList::iterator it = myObjs->find(nom);
1019 if (it == myObjs->end()) return;
1020 (*it).second.wrsid.push_back(wrsid);
1021 }
1022return;
1023}
1024
1025/* --Methode-- */
1026void NamedObjMgr::UpdateObjMgrWindow(int did)
1027{
1028if (!myImgApp) return;
1029(myImgApp->ObjMgrW())->ClearHelpList();
1030
1031NObjList::iterator it;
1032string cn;
1033for(it = myObjs->begin(); it != myObjs->end(); it++) {
1034 if ((*it).second.dirid != did) continue;
1035 cn = (*it).first.substr(1);
1036 cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ;
1037 (myImgApp->ObjMgrW())->AddObj(cn.c_str());
1038 }
1039}
1040
1041
1042/* Nouvelle-Fonction */
1043void RemoveSpacesFromName(string & nom)
1044{
1045// on supprime les blancs de debut et de fin
1046size_t p = nom.find_first_not_of(" ");
1047if(p>nom.length()) { nom = ""; return; }
1048nom = nom.substr(p);
1049p = nom.find(' ');
1050if(p>nom.length()) p=nom.length();
1051nom = nom.substr(0, p);
1052}
1053
1054/* Nouvelle-Fonction */
1055bool CheckDirName(string & nom)
1056{
1057RemoveSpacesFromName(nom);
1058if (nom.length() < 1) return(false);
1059if (nom[0] == '/') nom = nom.substr(1) ;
1060size_t p = nom.find('/');
1061if (p < nom.length()) nom = nom.substr(0,p);
1062if (nom.length() < 1) return(false);
1063return(true);
1064}
1065
1066/* Nouvelle-Fonction */
1067int ParseObjectName(string & nom, string & nomrep, string & nomobj)
1068{
1069RemoveSpacesFromName(nom);
1070// Si le nom ne commence pas par un slash, c'est le repertoire courant
1071if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
1072else {
1073 string xx = nom.substr(1);
1074 size_t p = xx.find('/');
1075 if (p < xx.length()) {
1076 nomrep = xx.substr(0,p);
1077 nomobj = xx.substr(p+1);
1078 }
1079 else {
1080 nomrep = xx;
1081 nomobj = "";
1082 }
1083 }
1084int rc = 0;
1085NObjDirList::iterator it = myDirs->find(nomrep);
1086if (it != myDirs->end()) rc = (*it).second.id;
1087return(rc);
1088}
1089
Note: See TracBrowser for help on using the repository browser.