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

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

Extension de l'interface NObjMgrAdapter et ajout de DVList pour les variables globales ds NamedObjMgr - Reza 30/8/2000

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