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

Last change on this file since 769 was 709, checked in by ercodmgr, 26 years ago

petites Corrections diverses - Reza 21/01/2000

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