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

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

Ajout de cxxexecutor (Execution C++ en ligne ds piapp) - CMV+Reza 11/10/2000

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