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

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

HelpToTex + CopyObj (ds Adapter) et PawExecutor cmv+Reza 12/10/99

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