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

Last change on this file since 1315 was 1315, checked in by ercodmgr, 25 years ago

Adaptateur pour TArray et flag share ds methode CloneDataObj() - Reza 9/11/2000

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