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

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

compil avec PEIDA pour les modifs de l'interface adapteur - Reza 22/9/2000

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