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

Last change on this file since 1207 was 1207, checked in by ercodmgr, 25 years ago
  • refonte de piaffiting avec les fits adapteurs
  • addapteur de fit pour les objets existants
  • entree des Image<T> dans les fits (retour !!!)

cmv 29/9/00

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