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

Last change on this file since 2810 was 2762, checked in by ansari, 20 years ago

Suite corrections ZSync + correction (probable) du probleme de plantage a la fin lie a imagnav - reste a corriger menu::del_cur_widget - Reza 24/05/2005

File size: 47.4 KB
RevLine 
[165]1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
[295]5#include <typeinfo>
[2322]6#include <iostream>
[165]7#include <string>
8#include <list>
9#include <map>
10
[2615]11#include "sopnamsp.h"
[165]12#include "strutil.h"
13#include "datatypes.h"
14
15#include "nobjmgr.h"
16#include "servnobjm.h"
[330]17#include "nomgadapter.h"
[165]18#include "pistdimgapp.h"
19
[1164]20#include "dvlist.h"
[165]21
[293]22// EVOL-PLANCK
23#ifdef SANS_EVOLPLANCK
24#include "fitsimage.h"
[1321]25#else
26#include "fitsautoreader.h"
[1525]27#include "tvector.h"
28#include "pitvmaad.h"
[1905]29#include "piyfxdrw.h"
[293]30#endif
31
[295]32#include "pisurfdr.h"
[165]33#include "pipodrw.h"
[333]34
[165]35#include "pintuple.h"
36#include "pintup3d.h"
37#include "pigfd1.h"
38#include "pigfd2.h"
39
[2491]40#include "zthread.h"
[165]41
[2491]42
[165]43//++
44// Class NamedObjMgr
45// Lib PI
46// include nobjmgr.h
47//
[344]48// Cette classe fournit les services nécéssaires à la gestion des objets
[165]49// (l'ensemble des objets PPersist de PEIDA++) au sein du programme
50// d'analyse interactive *piapp* . Elle constitue en outre l'interface
51// entre les fonctions utilisateur et l'application graphique.
52//--
53//++
54// Links Voir aussi
55// PIStdImgApp
56// Services2NObjMgr
57// PIACmd
58//--
59
60
61// ..................................................................
62// ...... Gestion des objets nommes, variables globales ............
[331]63struct nobj_diritem {
[344]64 int id; // Directory Id
65 int nobj; // Number of objects in directory
66 bool lock; // True -> directory locked, No Add, del or rename
67 bool keepold; // True -> When duplicate object name, old object moved to /old
[331]68};
69
70typedef map<string, nobj_diritem, less<string> > NObjDirList;
71
[165]72struct nobj_item {
[344]73 AnyDataObj* obj; // Object pointer
74 NObjMgrAdapter* obja; // Object adapter pointer
75 int oid; // object Id
76 int dirid; // Directory Id
77 list<int> wrsid; // List of Window Resource Id (Drawer, PIBaseWdg, ...)
78 // (for PIStdImgApp)
[165]79 bool operator==(nobj_item const& b) const
80 { return (this->obj == b.obj); }
81};
82
83typedef map<string, nobj_item, less<string> > NObjList;
84
[331]85static NObjDirList* myDirs = NULL;
86static NObjList* myObjs = NULL;
[165]87static int fgOInit = 0;
88static int myNObj = 0;
[331]89static int myDirId = 0;
90static string* currDir;
[165]91
92static PIStdImgApp* myImgApp=NULL;
93static Services2NObjMgr* servnobjm=NULL;
94
[1164]95static DVList* myVars = NULL; // Pour stocker les variables
96
[2755]97static string* TmpDir = NULL; // Repertoire pour les compilations / link dynamique
[165]98
[2491]99// Pour gestion multithread
[2755]100static ZMutex* myMutex = NULL;
[333]101// ..................................................................
102
[165]103//++
104// Titre Constructeurs
105//--
106//++
107// NamedObjMgr()
108// Constructeur. Les différents instantiation de la classe "NamedObjMgr"
109// dans une même application créent des objets qui travaillent sur la même
110// liste d'objets. Les objets de cette classe ne possedent en effet pas
111// de variables membres.
112//--
113
114/* --Methode-- */
[2490]115NamedObjMgr::NamedObjMgr(bool fgimgapp)
[165]116{
[2490]117_fgimgapp = fgimgapp;
[165]118if (fgOInit == 0) {
[333]119 myNObj = 0;
120 myDirId = 0;
[331]121 myDirs = new NObjDirList;
[165]122 myObjs = new NObjList;
[1164]123 myVars = new DVList;
[2755]124 myMutex = new ZMutex;
[331]125 currDir = new string("home");
[333]126 string dirn = "home";
[2491]127 CreateDir_P(dirn);
[2132]128 SetKeepOldDirAtt(dirn, false);
[333]129 dirn = "tmp";
[2491]130 CreateDir_P(dirn);
[344]131 SetKeepOldDirAtt(dirn, false);
[466]132 dirn = "autoc";
[2491]133 CreateDir_P(dirn);
[368]134 SetKeepOldDirAtt(dirn, false);
[333]135 dirn = "old";
[2491]136 CreateDir_P(dirn);
[344]137 SetKeepOldDirAtt(dirn, false);
[333]138 dirn = "home";
139 SetCurrentDir(dirn);
140 myDirId = 50;
[165]141 char* varenv;
142 TmpDir = new string("");
[1276]143 if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
[165]144 int l = (*TmpDir).length();
145 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
[2491]146 servnobjm = new Services2NObjMgr(*TmpDir);
[165]147 }
148fgOInit++;
149}
150
151
152/* --Methode-- */
153NamedObjMgr::~NamedObjMgr()
154{
155fgOInit--;
[1164]156if (fgOInit == 0) {
157 string patt = "/*/*";
158 DelObjects(patt, true);
159 delete myObjs;
160 delete myDirs;
161 delete myVars;
[2491]162 delete myMutex;
[165]163}
[1164]164}
[165]165
166//++
167// Titre Méthodes
168//--
169//++
170// void SetImgApp(PIStdImgApp* app)
171// Spécifie l'objet "PIStdImgApp" associé.
172// PIStdImgApp* GetImgApp()
173// Accès à l'objet "PIStdImgApp" associé.
174//--
175
176/* --Methode-- */
177void NamedObjMgr::SetImgApp(PIStdImgApp* app)
178{
179myImgApp = app;
180servnobjm->SetImgApp(app);
[333]181
182NObjDirList::iterator it;
183string cn;
184for(it= myDirs->begin(); it != myDirs->end(); it++) {
185 cn = '/' + (*it).first;
186 (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id);
187 }
[165]188}
189
[449]190
191static bool verbeux = false; // true -> plus de message (creation/suppression d'objets)
192void NamedObjMgr::SetVerbose(bool fg)
193{
194verbeux = fg;
195}
196
[165]197/* --Methode-- */
198PIStdImgApp* NamedObjMgr::GetImgApp()
199{
200return(myImgApp);
201}
202
203/* --Methode-- */
204Services2NObjMgr* NamedObjMgr::GetServiceObj()
205{
206return(servnobjm);
207}
208
[331]209/* --Methode-- */
[1268]210string const& NamedObjMgr::GetTmpDir()
[1265]211{
212return *TmpDir;
213}
214
215/* --Methode-- */
[1268]216void NamedObjMgr::SetTmpDir(string const& tmpdir)
[1265]217{
218if(tmpdir.length()<1) return;
219*TmpDir = tmpdir;
[1276]220int l = (*TmpDir).length();
221if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
222servnobjm->SetTmpDir(*TmpDir);
[1265]223}
224
225/* --Methode-- */
[1164]226bool NamedObjMgr::SetVar(string const & key, string const & val)
227{
[2218]228 if ((key.length() < 1) || (! isalpha(key[0])) ) {
229 cout << "NamedObjMgr::SetVar( " << key << " ...) Bad VarName " << endl;
230 return(false);
231 }
[2755]232 ZSync zs(*myMutex); zs.NOp();
[1199]233#ifdef SANS_EVOLPLANCK
234 bool fg = true;
235#else
[1164]236 bool fg = myVars->HasKey(key);
[1199]237#endif
[1164]238 myVars->SetS(key, val);
[1224]239 // cout << " DEBUG::SetVar " << *myVars << endl;
[1164]240 return(fg);
241}
242
243/* --Methode-- */
244bool NamedObjMgr::HasVar(string const & key)
245{
[2218]246 if ((key.length() < 1) || (! isalpha(key[0])) ) {
247 cout << "NamedObjMgr::HasVar( " << key << ") Bad VarName " << endl;
248 return(false);
249 }
[2755]250 ZSync zs(*myMutex); zs.NOp();
[1199]251#ifdef SANS_EVOLPLANCK
[1547]252 DVList::ValList::const_iterator it;
253 for(it=myVars->Begin(); it!= myVars->End(); it++)
254 if ((*it).first == key) return true;
[1199]255 return(false);
256#else
[1164]257 return(myVars->HasKey(key));
[1199]258#endif
[1164]259}
260
261/* --Methode-- */
262bool NamedObjMgr::DeleteVar(string const & key)
263{
[2218]264 if ((key.length() < 1) || (! isalpha(key[0])) ) {
265 cout << "NamedObjMgr::DeleteVar( " << key << ") Bad VarName " << endl;
266 return(false);
267 }
[2755]268 ZSync zs(*myMutex); zs.NOp();
[1199]269#ifdef SANS_EVOLPLANCK
270 return(false);
271#else
[1164]272 return(myVars->DeleteKey(key));
[1199]273#endif
[1164]274}
275
276/* --Methode-- */
277string NamedObjMgr::GetVar(string const & key)
278{
[2218]279 if ((key.length() < 1) || (! isalpha(key[0])) ) {
280 cout << "NamedObjMgr::GetVar( " << key << ") Bad VarName " << endl;
281 return("");
282 }
[2755]283 ZSync zs(*myMutex); zs.NOp();
[1224]284 // cout << " DEBUG::GetVar " << *myVars << endl;
[1164]285 return(myVars->GetS(key));
286}
287
288/* --Methode-- */
289DVList& NamedObjMgr::GetVarList()
290{
[1224]291 // cout << " DEBUG::GetVarList " << *myVars << endl;
[2755]292 ZSync zs(*myMutex); zs.NOp();
[1164]293 return(*myVars);
294}
295
296/* --Methode-- */
[344]297bool NamedObjMgr::CreateDir(string & dirname)
[331]298{
[2755]299 ZSync zs(*myMutex); zs.NOp();
[2491]300 return CreateDir_P(dirname);
301}
302
303/* --Methode-- */
304bool NamedObjMgr::CreateDir_P(string & dirname)
305{
[333]306if ( !CheckDirName(dirname) ) {
307 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
[344]308 return(false);
[333]309 }
310NObjDirList::iterator it = myDirs->find(dirname);
311if (it != myDirs->end()) {
312 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
[344]313 return(false);
[333]314 }
315myDirId++;
316nobj_diritem di;
317di.id = myDirId;
318di.nobj = 0;
[344]319di.lock = false;
320di.keepold = false;
[333]321(*myDirs)[dirname] = di;
322if (myImgApp) {
323 string str = '/' + dirname;
[2492]324 if ( !_fgimgapp ) myImgApp->LockMutex();
[333]325 (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
[2492]326 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
327}
[449]328if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
[344]329return(true);
[331]330}
331
332/* --Methode-- */
[344]333bool NamedObjMgr::DeleteDir(string & dirname)
[331]334{
[333]335if ( !CheckDirName(dirname) ) {
336 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
[344]337 return(false);
[333]338 }
[2755]339ZSync zs(*myMutex); zs.NOp();
[333]340NObjDirList::iterator it = myDirs->find(dirname);
341if (it == myDirs->end()) {
342 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
[344]343 return(false);
[333]344 }
345if ((*it).second.nobj > 0) {
346 cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
[344]347 return(false);
[333]348 }
[344]349if ((*it).second.lock ) {
350 cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
351 return(false);
352 }
[333]353if ((*it).second.id < 50) {
354 cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
[344]355 return(false);
[333]356 }
357
[2490]358if (myImgApp) {
[2492]359 if ( !_fgimgapp ) myImgApp->LockMutex();
[333]360 (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
[2492]361 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2490]362}
[333]363myDirs->erase(it);
[449]364if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
[344]365return(true);
[331]366}
367
368/* --Methode-- */
[344]369void NamedObjMgr::LockDir(string & dirname)
[331]370{
[2755]371ZSync zs(*myMutex); zs.NOp();
[344]372if ( !CheckDirName(dirname) ) return;
373NObjDirList::iterator it = myDirs->find(dirname);
374if (it == myDirs->end()) return;
375(*it).second.lock = true;
[449]376if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
[344]377return;
378}
379
380/* --Methode-- */
381void NamedObjMgr::UnlockDir(string & dirname)
382{
[2755]383ZSync zs(*myMutex); zs.NOp();
[344]384if ( !CheckDirName(dirname) ) return;
385NObjDirList::iterator it = myDirs->find(dirname);
386if (it == myDirs->end()) return;
387(*it).second.lock = true;
[449]388if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
[344]389return;
390}
391
392/* --Methode-- */
393void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
394{
[2755]395ZSync zs(*myMutex); zs.NOp();
[344]396if ( !CheckDirName(dirname) ) return;
397NObjDirList::iterator it = myDirs->find(dirname);
398if (it == myDirs->end()) return;
399(*it).second.keepold = keepold;
[449]400if (!verbeux) return;
[344]401cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << " -> ";
402if ( keepold ) cout << " True " << endl;
403else cout << " False " << endl;
404return;
405}
406
407
408/* --Methode-- */
409bool NamedObjMgr::SetCurrentDir(string & dirname)
410{
[2755]411ZSync zs(*myMutex); zs.NOp();
[333]412if ( !CheckDirName(dirname) ) {
413 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
[344]414 return(false);
[333]415 }
416NObjDirList::iterator it = myDirs->find(dirname);
417if (it == myDirs->end()) {
418 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
[344]419 return(false);
[333]420 }
421*currDir = dirname;
[449]422if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
[344]423return(true);
[331]424}
425
426/* --Methode-- */
[333]427void NamedObjMgr::GetCurrentDir(string & dirname)
428{
[2755]429ZSync zs(*myMutex); zs.NOp();
[333]430dirname = *currDir;
431}
432
433/* --Methode-- */
434void NamedObjMgr::ListDirs(string & patt)
435{
[2755]436ZSync zs(*myMutex); zs.NOp();
[333]437NObjDirList::iterator it;
438string cn;
439cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl;
440int k = 0;
441for(it= myDirs->begin(); it != myDirs->end(); it++) {
442 cn = (*it).first;
443 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
444 k++;
[344]445 cout << k << "- " << (*it).first;
446 if ( (*it).second.lock ) cout << " Locked " ;
447 if ( (*it).second.keepold ) cout << " KeepOld " ;
448 cout << " (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl;
449
[333]450 }
451}
452
453/* --Methode-- */
454void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
455{
[2755]456ZSync zs(*myMutex); zs.NOp();
[333]457NObjDirList::iterator it;
458string cn;
459for(it= myDirs->begin(); it != myDirs->end(); it++) {
460 cn = (*it).first;
461 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
462 lstd.push_back(cn);
463 }
464}
465
466/* --Methode-- */
[368]467void NamedObjMgr::CleanDir(string & dirname)
[331]468{
[2755]469ZSync zs(*myMutex); zs.NOp();
[2491]470CleanDir_P(dirname);
471}
472
473/* --Methode-- */
474void NamedObjMgr::CleanDir_P(string & dirname)
475{
[368]476if ( !CheckDirName(dirname) ) {
477 cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl;
[380]478 // return(false); $CHECK$ illegal return value in void function
[368]479 }
480NObjDirList::iterator itr = myDirs->find(dirname);
481if (itr == myDirs->end()) {
482 cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - No such directory !" << endl;
[380]483 // return(false); $CHECK$ illegal return value in void function
[368]484 }
[331]485
[368]486int did = (*itr).second.id;
487NObjList::iterator it;
488list<int>::iterator iwr;
489bool nodisp = true;
490list<string> odel;
491for(it = myObjs->begin(); it != myObjs->end(); it++) {
492 if ((*it).second.dirid != did) continue;
493 nodisp = true;
494 if (myImgApp)
495 for(iwr=(*it).second.wrsid.begin(); iwr != (*it).second.wrsid.end(); iwr++)
496 if (myImgApp->CheckWRsId(*iwr)) { nodisp = false; break; }
497 if (nodisp) odel.push_back((*it).first);
498 }
499list<string>::iterator ii;
[2757]500for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii,true);
[2762]501
502UpdateObjMgrWindow_P(did); // On met a jour la fenetre de gestion des objets
[331]503}
504
[333]505
[368]506
[165]507//++
508// Titre Gestion de la liste des objets
509//--
510//++
[295]511// void AddObj(AnyDataObj* obj, string& nom)
[165]512// Ajoute l'objet "obj" à la liste, identifié par "nom".
513// Si un objet de même nom existe, l'ancien objet est renommé en concaténant
514// un numéro à son nom.
515// void DelObj(string const& nom, bool fgd=true)
516// Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
517// void DelObjects(string const& patt, bool fgd=true)
518// Supprime l'ensemble des objets dont le nom correspond au patron "patt".
519// Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
[295]520// AnyDataObj* GetObj(string const& nom)
[165]521// Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
522// pas dans la liste.
523// void RenameObj(string const& nom, string& nomnew)
524// Change le nom d'un objet dans la liste.
[463]525// void CopyObj(string const& nom, string& nomcp)
526// Copy l'objet "nom" de la liste dans l'objet "nomcp" de la liste.
[165]527//--
528
529/* --Methode-- */
[344]530bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
[165]531{
[2755]532 ZSync zs(*myMutex); zs.NOp();
[2491]533 return AddObj_P(obj, nom, crd);
534}
[165]535
[2491]536/* --Methode-- */
537bool NamedObjMgr::AddObj_P(AnyDataObj* obj, string & nom, bool crd)
538{
539
[344]540if (obj == NULL) return(false);
[333]541// On verifie si l'objet est deja dans la liste
542NObjList::iterator it;
543for(it = myObjs->begin(); it != myObjs->end(); it++) {
544 if ((*it).second.obj == obj) {
545 cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
[344]546 return(false);
[333]547 }
548 }
549string nobj;
550string nrep;
551char buff[32];
552int did = ParseObjectName(nom, nrep, nobj);
553if (did == 0) {
554 if (!crd) {
555 cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
[344]556 return(false);
[333]557 }
[2491]558 else { CreateDir_P(nrep); did = myDirId; }
[333]559 }
[165]560
[466]561// Si c'est le repertoire /autoc, on nettoie
562if (nrep == "autoc") {
[2491]563 CleanDir_P(nrep);
[368]564 }
565
[165]566myNObj++;
[2218]567if ((nobj.length() < 1) || (! isalpha(nobj[0]) ) ) {
568 cout << "NamedObjMgr::AddObj() bad object name " << nobj ;
[333]569 sprintf(buff,"O%d", myNObj);
570 nobj = buff;
[2218]571 cout << " changed to " << nobj << endl;
[333]572 }
573
574nom = '/' + nrep + '/' + nobj;
[344]575NObjDirList::iterator itr = myDirs->find(nrep);
576if ((*itr).second.lock) {
577 cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
578 return(false);
579 }
[333]580it = myObjs->find(nom);
[165]581if (it != myObjs->end()) { // l'objet existe deja
[466]582 if (nrep == "autoc") { // Dans /autoc , on garde les objets affiches, donc del. par Clean
[368]583 sprintf(buff, "%d", (*it).second.oid);
[466]584 string nomnew = "/autoc/" + nobj + buff;
[2491]585 RenameObj_P(nom, nomnew);
[368]586 }
587 else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
[333]588 string on,od;
[335]589// ParseObjectName((*it).first, od, on);
[333]590 sprintf(buff, "%d", (*it).second.oid);
[335]591 string nomnew = "/old/" + nobj + buff;
[2491]592 RenameObj_P(nom, nomnew);
[333]593 }
[344]594 else { // Sinon, on remplace l'objet
595 cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
[2491]596 DelObj_P(nom);
[344]597 }
[165]598 }
599
600nobj_item no;
601no.obj = obj;
[295]602no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
[333]603no.oid = myNObj;
604no.dirid = did;
[331]605(*myObjs)[nom] = no;
[333]606
607(*itr).second.nobj++;
608
[2490]609if (myImgApp != NULL) {
[2492]610 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]611 if ( (myImgApp->ObjMgrW())->Visible() ) {
612 string oln = nobj + " (T= " + no.obja->GetDataObjType() + ")" ;
613 (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
[685]614 }
[2492]615 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2490]616}
[449]617if (verbeux) cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
[295]618 << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
[344]619return(true);
[165]620}
621
[1224]622bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
623{
[2755]624ZSync zs(*myMutex); zs.NOp();
[1224]625NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
626if (adap == NULL) {
627 cout << "NamedObjMgr::AddObj() No Adapter ! " << nom << endl;
628 return(false);
629}
[1315]630AnyDataObj * cloneobj = adap->CloneDataObj(true);
[1224]631delete adap;
632if (cloneobj == NULL) {
633 cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl;
634 return(false);
635}
[2491]636return ( AddObj_P(cloneobj , nom, crd) );
[1224]637}
638
[165]639/* --Methode-- */
[344]640bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
[165]641{
[2755]642 ZSync zs(*myMutex); zs.NOp();
[2491]643 return RenameObj_P(nom, nomnew);
644}
645
646/* --Methode-- */
647bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew)
648{
[333]649string n1,r1,n2,r2;
[344]650int dids = ParseObjectName(nom, r1, n1);
651NObjDirList::iterator itr1 = myDirs->find(r1);
[333]652int did = ParseObjectName(nomnew, r2, n2);
[344]653NObjDirList::iterator itr2 = myDirs->find(r2);
654
[333]655if (did == 0) {
656 cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
[344]657 return(false);
[2218]658}
[333]659nom = '/' + r1 + '/' + n1;
660nomnew = '/' + r2 + '/' + n2;
661NObjList::iterator it1 = myObjs->find(nom);
662if (it1 == myObjs->end()) {
663 cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl;
[344]664 return(false);
[2218]665}
666if ((n2.length() < 1) || (! isalpha(n2[0])) ) {
667 cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
668 return(false);
669}
[333]670NObjList::iterator it2 = myObjs->find(nomnew);
671if (it2 != myObjs->end()) {
672 cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
[344]673 return(false);
[333]674 }
675
[344]676if ( (*itr1).second.lock || (*itr2).second.lock ) {
677 cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !"
678 << endl;
679 return(false);
680 }
681
682
[333]683nobj_item no = (*it1).second;
684no.dirid = did;
685myObjs->erase(it1);
686NObjDirList::iterator itr = myDirs->find(r1);
687(*itr).second.nobj--;
688(*myObjs)[nomnew] = no;
689itr = myDirs->find(r2);
690(*itr).second.nobj++;
[685]691
[2490]692if (myImgApp != NULL) {
[2492]693 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]694 if ( (myImgApp->ObjMgrW())->Visible() ) {
695 (myImgApp->ObjMgrW())->DelObjList(dids, no.oid);
696 string oln = n2 + " (T= " + no.obja->GetDataObjType() + ")" ;
697 (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
698 }
[2492]699 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[685]700}
[449]701if (verbeux)
702 cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
[344]703return(true);
[331]704}
705
706/* --Methode-- */
[463]707bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
708{
[2755]709ZSync zs(*myMutex); zs.NOp();
[463]710if(nomcp.length()<=0)
711 {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
712 return(false);}
[2755]713NObjMgrAdapter* obnom = GetObjAdapter_P(nom);
[463]714if(obnom==NULL)
715 {cout<<"NamedObjMgr::CopyObj() Error - No "<<nom<<" object !"<<endl;
716 return(false);}
[1165]717AnyDataObj* obnomcp = obnom->CloneDataObj();
[463]718if(obnomcp==NULL) return(false);
[2491]719if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
[463]720return true;
721}
722
723/* --Methode-- */
[344]724bool NamedObjMgr::DelObj(string & nom, bool fgd)
[331]725{
[2755]726 ZSync zs(*myMutex); zs.NOp();
[2491]727 return DelObj_P(nom, fgd);
728}
729
730/* --Methode-- */
731bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
732{
[333]733string n1,r1;
[685]734int did = ParseObjectName(nom, r1, n1);
[333]735nom = '/' + r1 + '/' + n1;
[165]736NObjList::iterator it = myObjs->find(nom);
[344]737if (it == myObjs->end()) return(false);
738NObjDirList::iterator itr = myDirs->find(r1);
739if ( (*itr).second.lock ) {
740 cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
741 return(false);
742 }
[165]743list<int>::iterator ii;
744if (myImgApp) {
745//DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
[2492]746// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
747 bool fglock = (_fgimgapp) ? false : true;
748 if (fglock) myImgApp->LockMutex();
[165]749 for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
750 myImgApp->DelWRsId((*ii));
[2492]751 if (fglock) myImgApp->UnlockMutex(true);
[165]752}
[314]753delete (*it).second.obja; // destruction de l'adaptateur
[165]754if (fgd) delete (*it).second.obj;
[333]755
[2490]756if (myImgApp != NULL) {
[2492]757 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]758 if ( (myImgApp->ObjMgrW())->Visible() ) {
759 int olid = (*it).second.oid;
760 (myImgApp->ObjMgrW())->DelObjList(did, olid);
761 }
[2492]762 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[685]763}
[165]764myObjs->erase(it);
[333]765(*itr).second.nobj--;
766
[685]767
[449]768if (!verbeux) return(true);
[165]769if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
770else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
[344]771return(true);
[165]772}
773
774/* --Methode-- */
[344]775bool NamedObjMgr::DelObj_Id(int oid)
[165]776{
[2755]777ZSync zs(*myMutex); zs.NOp();
[333]778NObjList::iterator it;
779string nom;
780bool of = false;
781for(it = myObjs->begin(); it != myObjs->end(); it++)
782 if ( (*it).second.oid == oid ) {
783 of = true; nom = (*it).first;
784 break;
785 }
[2757]786if (of) return(DelObj_P(nom, true));
[344]787else return(false);
[331]788}
789
790/* --Methode-- */
791void NamedObjMgr::DelObjects(string & patt, bool fgd)
792{
[2755]793ZSync zs(*myMutex); zs.NOp();
[333]794string n1,r1;
795ParseObjectName(patt, r1, n1);
796patt = '/' + r1 + '/' + n1;
[165]797NObjList::iterator it;
798list<string> odel;
799string cn;
800for(it = myObjs->begin(); it != myObjs->end(); it++) {
801 cn = (*it).first;
802 if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
803 }
804list<string>::iterator ii;
[2491]805for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii, fgd);
[165]806}
807
808/* --Methode-- */
[331]809AnyDataObj* NamedObjMgr::GetObj(string & nom)
[165]810{
[2755]811ZSync zs(*myMutex); zs.NOp();
812return GetObj_P(nom);
813}
814
815/* --Methode-- */
816AnyDataObj* NamedObjMgr::GetObj_P(string & nom)
817{
[333]818string n1,r1;
819ParseObjectName(nom, r1, n1);
820nom = '/' + r1 + '/' + n1;
[165]821NObjList::iterator it = myObjs->find(nom);
822if (it == myObjs->end()) return(NULL);
823return((*it).second.obj);
824}
825
826/* --Methode-- */
[331]827NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
[295]828{
[2755]829ZSync zs(*myMutex); zs.NOp();
830return GetObjAdapter_P(nom);
831}
832
833/* --Methode-- */
834NObjMgrAdapter* NamedObjMgr::GetObjAdapter_P(string & nom)
835{
[333]836string n1,r1;
837ParseObjectName(nom, r1, n1);
838nom = '/' + r1 + '/' + n1;
[295]839NObjList::iterator it = myObjs->find(nom);
840if (it == myObjs->end()) return(NULL);
841return((*it).second.obja);
842}
843
844/* --Methode-- */
[331]845void NamedObjMgr::ListObjs(string & patt)
[165]846{
[2755]847ZSync zs(*myMutex); zs.NOp();
[331]848int k;
849AnyDataObj* obj=NULL;
850string ctyp;
851char strg[256];
852
[333]853string n1,r1;
854ParseObjectName(patt, r1, n1);
855patt = '/' + r1 + '/' + n1;
856 cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
[331]857NObjList::iterator it; k = 0;
[333]858string cn;
[331]859for(it = myObjs->begin(); it != myObjs->end(); it++) {
[333]860 cn = (*it).first;
861 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
[331]862 obj = (*it).second.obj;
863 ctyp = typeid(*obj).name();
864 sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
865 ctyp = strg;
866 cout << ctyp << "\n" ;
867 k++;
868}
869cout << endl;
[165]870return;
871}
872
873/* --Methode-- */
[333]874void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
[165]875{
[2755]876ZSync zs(*myMutex); zs.NOp();
[333]877string n1,r1;
878if (patt.length() < 1) return;
879bool fgr = (patt[0] == '/') ? true : false;
880ParseObjectName(patt, r1, n1);
881patt = '/' + r1 + '/' + n1;
882NObjList::iterator it;
883string cn;
884for(it = myObjs->begin(); it != myObjs->end(); it++) {
885 cn = (*it).first;
886 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
887 if (fgr) lst.push_back(cn);
888 else {
889 ParseObjectName(cn, r1, n1);
890 lst.push_back(n1);
891 }
892 }
[165]893}
894
895//++
896// Titre Entrées-Sorties (I/O) sur les objets
897//--
898//++
899// void ReadObj(PInPersist& s, int num=-1)
900// Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
901// et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
902// sur le flot "s" sont créés et ajoutés à la liste.
903// void ReadObj(string const & nomppf, string nobj="")
904// Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
905// à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
906// composé à partir du nom de fichier.
907//--
908
909/* --Methode-- */
[331]910void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
[165]911{
[2755]912ZSync zs(*myMutex); zs.NOp();
[495]913PPersist* ppobj=NULL;
[165]914bool ok = true;
[495]915#ifdef SANS_EVOLPLANCK
[165]916TRY{
917 PInPersist pis(flnm);
[495]918 ppobj = PPersistMgr::ReadObject(pis);
919 if (ppobj == NULL) ok = false;
[165]920} CATCH(merr)
921 { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
922 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]923#else
924try {
925 PInPersist pis(flnm);
926 ppobj = pis.ReadObject();
927 }
928catch (IOExc iox) {
929 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
930 ok = false;
931 }
932#endif
[165]933if (!ok) return;
934if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
[2491]935AddObj_P(ppobj->DataObj(), nobj, true);
[685]936cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
[165]937return;
938}
[2645]939/* --Methode-- */
940void NamedObjMgr::ReadObj(vector<string> & flnm_objname)
941// flnm_objname[0] = nom du fichier .ppf
942// flnm_objname[1...] = nom des tags des objects a lire
943{
944if(flnm_objname.size()<2) return;
[2755]945ZSync zs(*myMutex); zs.NOp();
[2645]946int nread=0;
947try {
948 PInPersist pis(flnm_objname[0]);
949 for(int i=1;i<flnm_objname.size();i++) {
950 bool ok = pis.GotoNameTag(flnm_objname[i]);
951 if(!ok) {
952 cout<<"NamedObjMgr::ReadObj(...) Unknown object: "<<flnm_objname[i]<<endl;
953 continue;
954 }
955 PPersist *ppobj = pis.ReadObject();;
956 if(ppobj==NULL) {
957 cout<<"NamedObjMgr::ReadObj(...) impossible to read "<<flnm_objname[i]<<endl;
958 continue;
959 }
960 AddObj_P(ppobj->DataObj(),flnm_objname[i],true);
961 nread++;
962 cout<<"NamedObjMgr::ReadObj(...) object "<<flnm_objname[i]<<" read from file "<<endl;
963 }
964} catch (IOExc iox) {
965 cerr<<"NamedObjMgr::ReadObj()/Error Exception - Msg= "<<iox.Msg()<<endl;
966}
967cout<<nread<<" objects have been read"<<endl;
968return;
969}
[165]970
971/* --Methode-- */
972void NamedObjMgr::ReadObj(PInPersist& s, int num)
973{
[2755]974ZSync zs(*myMutex); zs.NOp();
975ReadObj_P(s, num);
976}
977
978/* --Methode-- */
979void NamedObjMgr::ReadObj_P(PInPersist& s, int num)
980{
[2180]981int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
982#ifdef SANS_EVOLPLANCK
983int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
984#endif
[165]985int n0, n1;
986bool ok = true;
987PPersist* obj=NULL;
988string nom;
989
[449]990int nread = 0;
[2460]991int nbtags = 0;
992#ifdef SANS_EVOLPLANCK
993nbtags = s.NbTags();
994#else
995nbtags = s.NbNameTags();
996#endif
997if ( (nbtags < 1) || (num >= nbtags) ) {
[165]998 if (num >= 0) {
[495]999 cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << " Error! NbTags ="
[2460]1000 << nbtags << endl;
[165]1001 return;
1002 }
[495]1003
1004#ifdef SANS_EVOLPLANCK
[165]1005 TRY {
1006 obj = PPersistMgr::ReadObject(s);
1007 if (obj == NULL) ok = false;
1008 } CATCH(merr) {
1009 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1010 ok = false;
1011 } ENDTRY;
[495]1012#else
1013try {
1014 obj = s.ReadObject();
1015 }
1016catch (IOExc iox) {
1017 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
1018 ok = false;
1019 }
1020#endif
1021
[165]1022 if (!ok) return;
1023 nom = "";
[2491]1024 AddObj_P(obj->DataObj(), nom, false);
[449]1025 nread++;
[165]1026}
1027
[2460]1028if (num < 0) { n0 = 0; n1 = nbtags; }
[165]1029else { n0 = num; n1 = num+1; }
1030for(i=n0; i<n1; i++) {
[495]1031#ifdef SANS_EVOLPLANCK
[165]1032 key = s.TagKey(i, cid, ln);
1033 if (ln <= 0) nom = "";
1034 else nom = s.TagName(i);
1035 s.GotoTag(i);
1036 TRY {
1037 obj = PPersistMgr::ReadObject(s);
1038 if (obj == NULL) ok = false;
1039 } CATCH(merr) {
1040 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1041 ok = false;
1042 } ENDTRY;
[495]1043#else
[2460]1044 s.GotoNameTagNum(i);
[584]1045 nom = s.GetTagName(i);
[495]1046 try {
1047 obj = s.ReadObject();
1048 }
1049 catch (IOExc iox) {
1050 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
1051 ok = false;
1052 }
1053#endif
[2491]1054 if (ok) { AddObj_P(obj->DataObj(), nom, true); nread++; }
[165]1055}
1056
[449]1057cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
[165]1058return;
1059}
1060/* --Methode-- */
1061void NamedObjMgr::ReadAll(string const & flnm)
1062{
[2755]1063ZSync zs(*myMutex); zs.NOp();
[2701]1064#ifdef SANS_EVOLPLANCK
[165]1065bool ok = true;
1066PPersist* obj=NULL;
1067
[2180]1068PInPersist* ppin=NULL;
[165]1069TRY{
1070 ppin = new PInPersist(flnm);
1071 if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
1072 else obj = NULL;
1073} CATCH(merr)
1074 { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
[2701]1075 (long)merr, PeidaExc(merr)); ok = false; }
1076ENDTRY;
[165]1077if (!ok) return;
1078if (obj) {
1079 string nom = servnobjm->FileName2Name(flnm);
[2491]1080 AddObj_P(obj->DataObj(), nom, false);
[165]1081 }
[2755]1082else ReadObj_P((*ppin), -1);
[165]1083delete ppin;
[2701]1084#else
1085try {
1086 PInPersist pis(flnm);
1087 if (pis.NbNameTags() >= 1) {
1088 if (pis.NbNameTags() < pis.NbTopLevelObjects()) {
1089 cout << "NamedObjMgr::ReadAll()/Warning File " << flnm << " NbNameTags="
1090 << pis.NbNameTags() << " < NbTopLevelObjects= "
1091 << pis.NbTopLevelObjects() << endl;
1092 cout << " ... Reading " << pis.NbNameTags() << " objects at NameTags " ;
1093 }
[2755]1094 ReadObj_P(pis, -1);
[2701]1095 return;
1096 }
1097
1098 string nom = servnobjm->FileName2Name(flnm);
1099 int kn = 1;
1100 for(int ii=0; ii<pis.NbTopLevelObjects(); ii++) {
1101 PPersist* obj = pis.ReadObject();
1102 if (!obj) continue;
1103 AddObj_P(obj->DataObj(), nom, false);
1104 kn++;
1105 nom += (string)MuTyV(kn);
1106 }
1107}
1108catch (IOExc& iox) {
1109 cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
1110}
1111#endif
[165]1112return;
1113}
1114
1115/* --Methode-- */
[331]1116void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
[165]1117{
[2755]1118ZSync zs(*myMutex); zs.NOp();
[293]1119#ifdef SANS_EVOLPLANCK
[2180]1120bool ok = false;
[709]1121RzImage* obj=NULL;
[495]1122TRY{
[165]1123 obj = RzReadFits((char*)flnm.c_str());
1124 if (obj == NULL) ok = false;
[709]1125 else ok = true;
[165]1126} CATCH(merr) {
1127 printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1128 ok = false;
1129} ENDTRY;
[709]1130
1131if (ok && (obj != NULL)) {
[165]1132 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
[2491]1133 AddObj_P((AnyDataObj*)obj, nobj);
[165]1134}
[1105]1135#else
[1321]1136 try {
1137 FITS_AutoReader fiar(flnm);
[1335]1138 char bun[16];
1139 int nhdu = fiar.NbBlocks();
[1321]1140 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
1141 string name;
1142 AnyDataObj* obj;
[1513]1143 int kon = 1;
[1321]1144 for(int k=1; k<=nhdu; k++) {
1145 obj = fiar.ReadObject(k);
[1330]1146 if (obj) {
[1321]1147 cout << " NamedObjMgr::ReadFits() " << (string)typeid(*obj).name()
1148 << " read From HDU " << k << endl;
[1513]1149 if (typeid(*obj) == typeid(DVList)) {
1150 delete obj;
1151 continue;
1152 }
1153 if (kon > 1) {
1154 sprintf(bun, "%d", kon);
[1330]1155 name = nobj + bun;
1156 }
1157 else name = nobj;
[2491]1158 AddObj_P(obj, name, false);
[1513]1159 kon++;
[1330]1160 }
[1321]1161 else cerr << " NamedObjMgr::ReadFits() NULL pointer from FITS_AutoReader" << endl;
1162 }
1163 }
1164 catch(PThrowable & exc) {
1165 cerr << " NamedObjMgr::ReadFits() / Error - Catched Exception \n "
1166 << " Type= " << (string)typeid(exc).name()
1167 << " - Msg= " << exc.Msg() << endl;
1168
1169 }
[1105]1170#endif
1171
[165]1172return;
1173}
1174
[2491]1175/* --Methode-- */
1176void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
1177{
[2755]1178 ZSync zs(*myMutex); zs.NOp();
[2491]1179 SaveObj_P(nom, s, keeppath);
1180}
[165]1181
1182static int key_for_write = 5000;
1183/* --Methode-- */
[2491]1184void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
[165]1185{
[333]1186if (nom.length() < 1) return;
1187string nob,rep;
1188ParseObjectName(nom, rep, nob);
1189nom = '/' + rep + '/' + nob;
[295]1190NObjMgrAdapter* obja=NULL;
[333]1191string nomf = (keeppath) ? nom : nob;
[2755]1192obja = GetObjAdapter_P(nom);
[295]1193if (obja == NULL) return;
[165]1194printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
[295]1195 nom.c_str(), typeid(*(obja->GetDataObj())).name());
[333]1196obja->SavePPF(s, nomf);
[165]1197return;
1198}
1199
1200/* --Methode-- */
[333]1201void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
1202{
[2755]1203ZSync zs(*myMutex); zs.NOp();
[333]1204string n1,r1;
1205if (patt.length() < 1) return;
1206bool keeppath = (patt[0] == '/') ? true : false;
1207ParseObjectName(patt, r1, n1);
1208patt = '/' + r1 + '/' + n1;
1209
1210bool ok = true;
[2180]1211POutPersist* pout=NULL;
[495]1212#ifdef SANS_EVOLPLANCK
[333]1213TRY{
1214 pout = new POutPersist(flnm);
1215} CATCH(merr)
1216 { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
1217 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1218#else
1219try {
1220 pout = new POutPersist(flnm);
1221}
1222catch (IOExc iox) {
1223 cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl;
1224 ok = false;
1225}
1226#endif
[333]1227if (!ok) return;
1228NObjList::iterator it;
1229string cn;
1230for(it = myObjs->begin(); it != myObjs->end(); it++) {
1231 cn = (*it).first;
1232 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
[2491]1233 SaveObj_P(cn, (*pout), keeppath);
[333]1234 }
1235delete pout;
1236return;
1237}
1238
1239/* --Methode-- */
[2669]1240void NamedObjMgr::SaveListObjects(vector<string> &liste)
1241// Les n-1 premiers elements (liste[0 -> n-2]) contiennent
1242// les noms des objects a mettre dans le fichier ppf
1243// dont le nom est le dernier argument (liste[n-1])
1244{
[2755]1245 ZSync zs(*myMutex); zs.NOp();
[2669]1246
1247 if(liste.size()<2) {
1248 cerr<<"NamedObjMgr::SaveListObjects()/Error not enough argument"<<endl;
1249 return;
1250 }
1251
1252 // open ppf file
1253 string ppfname = liste[liste.size()-1];
1254 POutPersist* pout=NULL;
1255 try {
1256 pout = new POutPersist(ppfname);
1257 } catch(IOExc iox) {
1258 cerr<<"NamedObjMgr::SaveObjects()/Error Exception - Msg= "<<iox.Msg()<<endl;
1259 return;
1260 }
1261
1262 // put objects in ppf file
1263 for(int i=0;i<liste.size()-1;i++) {
1264 bool keeppath = (liste[i][0] == '/') ? true : false;
1265 SaveObj_P(liste[i], (*pout), keeppath);
1266 }
1267
1268 // close ppf file
1269 delete pout;
1270
1271 return;
1272}
1273
1274/* --Methode-- */
[165]1275void NamedObjMgr::SaveAll(string const& flnm)
1276{
[2755]1277ZSync zs(*myMutex); zs.NOp();
[165]1278bool ok = true;
1279
[2180]1280POutPersist* pout=NULL;
[495]1281#ifdef SANS_EVOLPLANCK
[165]1282TRY{
1283 pout = new POutPersist(flnm);
1284} CATCH(merr)
1285 { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
1286 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1287#else
1288try {
1289 pout = new POutPersist(flnm);
1290}
1291catch (IOExc iox) {
1292 cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl;
1293 ok = false;
1294}
1295#endif
[165]1296if (!ok) return;
[332]1297NObjList::iterator it;
1298string no;
1299for(it = myObjs->begin(); it != myObjs->end(); it++) {
1300 no = (*it).first;
[2491]1301 SaveObj_P(no, (*pout), true);
[332]1302 }
[165]1303delete pout;
1304return;
1305}
1306
1307/* --Methode-- */
[331]1308void NamedObjMgr::SaveFits(string& nom, string const & flnm)
[165]1309{
[2755]1310ZSync zs(*myMutex); zs.NOp();
[2491]1311
[295]1312NObjMgrAdapter* obja=NULL;
[2755]1313obja = GetObjAdapter_P(nom);
[295]1314if (obja == NULL) return;
[2672]1315cout << " SaveFits: Object" << nom << " to FITS file " << flnm << endl;
[295]1316obja->SaveFits(flnm);
[293]1317return;
[165]1318}
1319
1320
1321
1322/* --Methode-- */
[331]1323void NamedObjMgr::PrintObj(string& nom)
[165]1324{
[2755]1325ZSync zs(*myMutex); zs.NOp();
[295]1326NObjMgrAdapter* obja=NULL;
[2755]1327obja = GetObjAdapter_P(nom);
[295]1328if (obja == NULL) return;
[594]1329AnyDataObj* ob = obja->GetDataObj();
1330if (ob == NULL) {
1331 cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl;
1332 return;
1333 }
1334string ctyp = typeid(*ob).name();
[295]1335cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
1336obja->Print(cout);
[165]1337
1338return;
1339}
1340
1341/* --Methode-- */
[331]1342void NamedObjMgr::DisplayObj(string& nom, string dopt)
[165]1343{
[2677]1344// Pas de display si option dopt = nodisp
1345if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1346
[2755]1347ZSync zs(*myMutex); zs.NOp();
[2491]1348
[295]1349NObjMgrAdapter* obja=NULL;
[2755]1350obja = GetObjAdapter_P(nom);
[295]1351if (obja == NULL) {
[594]1352 cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
[165]1353 return;
1354}
[594]1355if (obja->GetDataObj() == NULL) {
1356 cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
1357 return;
1358 }
[165]1359if (!myImgApp) return;
1360
[295]1361PIDrawer * dr = NULL;
1362P2DArrayAdapter* arr = NULL;
1363dr = obja->GetDrawer(dopt);
1364if (!dr) arr = obja->Get2DArray(dopt);
[165]1365
[295]1366if (!dr && !arr) {
1367 string ctyp = typeid(*(obja->GetDataObj())).name();
[594]1368 cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
[295]1369 return;
1370 }
1371
[165]1372int wrsid = 0;
1373
[344]1374string n1,r1;
1375ParseObjectName(nom, r1, n1);
1376
[2491]1377// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1378bool fglock = (_fgimgapp) ? false : true;
1379
[295]1380if (dr) {
1381 PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
[2491]1382 if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock);
1383 else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock);
[295]1384 }
[2651]1385else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, false, 0, fglock);
[165]1386
[2762]1387AddWRsId_P(nom, wrsid);
[295]1388return;
1389}
[165]1390
[295]1391/* --Methode-- */
[2651]1392void NamedObjMgr::DisplayImage(string& nom, string dopt, bool fgimagnav)
[295]1393{
[2677]1394// Pas de display si option dopt = nodisp
1395if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1396
[2755]1397ZSync zs(*myMutex); zs.NOp();
[2491]1398
[295]1399NObjMgrAdapter* obja=NULL;
[2755]1400obja = GetObjAdapter_P(nom);
[295]1401if (obja == NULL) {
[449]1402 cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
[295]1403 return;
1404}
[594]1405if (obja->GetDataObj() == NULL) {
1406 cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
1407 return;
1408 }
[295]1409if (!myImgApp) return;
1410
1411P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]1412
[295]1413if (!arr) {
1414 string ctyp = typeid(*(obja->GetDataObj())).name();
[449]1415 cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
[295]1416 return;
1417 }
[165]1418
[344]1419string n1,r1;
1420ParseObjectName(nom, r1, n1);
1421
[2491]1422// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1423bool fglock = (_fgimgapp) ? false : true;
1424
[295]1425int wrsid = 0;
[2651]1426wrsid = myImgApp->DispImage(arr, n1, dopt, fgimagnav, 0, fglock);
[165]1427
[2762]1428AddWRsId_P(nom, wrsid);
[295]1429return;
1430}
1431/* --Methode-- */
[331]1432void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
[295]1433{
[2677]1434// Pas de display si option dopt = nodisp
1435if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1436
[2755]1437ZSync zs(*myMutex); zs.NOp();
[2491]1438
[295]1439NObjMgrAdapter* obja=NULL;
[2755]1440obja = GetObjAdapter_P(nom);
[295]1441if (obja == NULL) {
[449]1442 cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
[295]1443 return;
1444}
[594]1445if (obja->GetDataObj() == NULL) {
1446 cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
1447 return;
1448 }
[295]1449if (!myImgApp) return;
1450
1451P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]1452
[295]1453if (!arr) {
1454 string ctyp = typeid(*(obja->GetDataObj())).name();
[449]1455 cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
[295]1456 return;
1457 }
[165]1458
[295]1459if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
1460 cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
[449]1461 << "x" << arr->YSize() << ") too big (max=250x250)" << endl;
[295]1462 delete arr;
1463 return;
[165]1464 }
1465
[344]1466string n1,r1;
1467ParseObjectName(nom, r1, n1);
1468
[2491]1469// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1470bool fglock = (_fgimgapp) ? false : true;
1471
[295]1472int wrsid = 0;
1473PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
[2491]1474wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
[2762]1475AddWRsId_P(nom, wrsid);
[295]1476return;
[165]1477}
1478
1479/* --Methode-- */
[331]1480void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
[486]1481 string& erx, string& ery, string& erz, string& wt,
1482 string& label, string dopt, bool fg3d)
[165]1483{
[2677]1484// Pas de display si option dopt = nodisp
1485if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1486
[2755]1487ZSync zs(*myMutex); zs.NOp();
[2491]1488
[2755]1489AnyDataObj* obj=GetObj_P(nom);
[165]1490if (obj == NULL) {
[449]1491 cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
[165]1492 return;
1493}
1494if (!myImgApp) return;
1495
[326]1496NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
1497if (nt == NULL) {
1498// if (typeid(*obj) != typeid(NTupleInterface)) {
[295]1499 string ctyp = typeid(*obj).name();
[449]1500 cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl;
[165]1501 return;
1502 }
1503
1504int wrsid = 0;
[1971]1505dopt = "defline " + dopt;
[165]1506
[344]1507string n1,r1;
1508ParseObjectName(nom, r1, n1);
1509
[2491]1510// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1511bool fglock = (_fgimgapp) ? false : true;
1512
[333]1513if ( fg3d && (nmz.length()>0) ) { // Display 3D
[326]1514 PINTuple3D* pin = new PINTuple3D(nt, false);
[165]1515 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
[486]1516 pin->SelectWt(wt.c_str());
1517 pin->SelectLabel(label.c_str());
[165]1518 pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
1519 string titre = nmz + "%" + nmy + "%" + nmz;
[2491]1520 wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock);
[165]1521}
1522else {
[326]1523 PINTuple* pin = new PINTuple(nt, false);
[165]1524 pin->SelectXY(nmx.c_str(), nmy.c_str());
[486]1525 pin->SelectWt(wt.c_str());
1526 pin->SelectLabel(label.c_str());
[165]1527 pin->SelectErrBar(erx.c_str(), ery.c_str());
[333]1528 string titre = nmy + "%" + nmx;
[2491]1529 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock);
[165]1530 }
1531
[2762]1532AddWRsId_P(nom, wrsid);
[165]1533return;
1534}
1535
[339]1536/* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
[331]1537void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
[165]1538// Pour le display 2D ou 3D d'un ``GeneralFitData''.
1539//| nom = nom de l'objet GeneralFitData a representer.
1540//| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
1541//| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
1542//| Pour le display 2D, numvary="" string vide.
1543//| err = qu'elles erreurs faut il representer ?
1544//| - 2D : x y xy (display y=f(x))
1545//| - 3D : x y z xy xz yz xzy (display z=f(x,y))
1546//| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
1547//| les barres d'erreurs sont representees.
1548//| opt = options generales pour le display.
1549{
[2677]1550// Pas de display si option dopt = nodisp
1551if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1552
[2755]1553ZSync zs(*myMutex); zs.NOp();
[2491]1554
[2755]1555AnyDataObj* obj=GetObj_P(nom);
[165]1556if(obj == NULL)
[449]1557 {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
[165]1558 return;}
1559if(!myImgApp) return;
[295]1560if(typeid(*obj) != typeid(GeneralFitData))
1561 {string ctyp = typeid(*obj).name();
[449]1562 cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl;
[165]1563 return;}
1564
1565// Decodage des erreurs a representer
1566bool errx=false, erry=false, errz=false;
1567if(err.length()>0) {
[2180]1568 for(int i=0;i<(int_4)err.length();i++)
[165]1569 if (err[i]=='x' || err[i]=='X') errx = true;
1570 else if(err[i]=='y' || err[i]=='Y') erry = true;
1571 else if(err[i]=='z' || err[i]=='Z') errz = true;
1572}
1573// Decodage des numeros de variables en abscisse
[339]1574 int numvx=-1, numvy=-1;
1575 if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
1576 if(numvary.length()>0) numvy = atoi(numvary.c_str());
1577
[344]1578 string n1,r1;
1579 ParseObjectName(nom, r1, n1);
[2491]1580 // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1581 bool fglock = (_fgimgapp) ? false : true;
[344]1582
[339]1583 int wrsid = 0;
1584 if(numvy>=0) { // display 3D
[165]1585 PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
1586 pigfd->SelectXY(numvx,numvy);
1587 pigfd->SelectErrBar(errx,erry,errz);
[2491]1588 wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock);
[339]1589} else { // display 2D
[165]1590 PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
1591 pigfd->SelectX(numvx);
1592 pigfd->SelectErrBar(errx,erry);
[2491]1593 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock);
[165]1594}
1595
[2762]1596AddWRsId_P(nom, wrsid);
[1971]1597
[165]1598return;
1599}
1600
[1525]1601/* --Methode-- */
1602void NamedObjMgr::DisplayVector(string & nomvx, string& nomvy, string dopt)
1603// Pour l'affichage 2-D de points avec coordonnees definies par deux vecteurs
1604// nomvx et nomvy
1605{
[2677]1606// Pas de display si option dopt = nodisp
1607if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1608
[2755]1609ZSync zs(*myMutex); zs.NOp();
[2491]1610
[1525]1611#ifdef SANS_EVOLPLANCK
1612 cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
1613#else
1614
1615if(!myImgApp) return;
1616
1617AnyDataObj* obj;
[2755]1618obj = GetObj_P(nomvx);
[1525]1619if(obj == NULL) {
1620 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl;
1621 return;
1622}
[2263]1623//Vector * vx = dynamic_cast<Vector *>(obj);
1624BaseArray* bax = dynamic_cast<BaseArray *>(obj);
1625if (bax == NULL) {
1626 cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl;
[1525]1627 return;
1628}
1629
[2755]1630obj = GetObj_P(nomvy);
[1525]1631if(obj == NULL) {
1632 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
1633 return;
1634}
[2263]1635BaseArray* bay = dynamic_cast<BaseArray *>(obj);
1636if (bay == NULL) {
1637 cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
[1525]1638 return;
1639}
1640
[2263]1641Vector vx = *bax;
1642Vector vy = *bay;
[1525]1643Vector * cvx, * cvy;
1644
[2263]1645if (vx.Size() != vy.Size()) {
[1525]1646 cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl;
[2263]1647 if (vx.Size() < vy.Size()) {
1648 cvx = new Vector(vx);
1649 cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1)));
[1525]1650 }
1651 else {
[2263]1652 cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1)));
1653 cvy = new Vector(vy);
[1525]1654 }
1655}
1656else {
[2263]1657 cvx = new Vector(vx);
1658 cvy = new Vector(vy);
[1525]1659}
1660
1661POVectorAdapter * avx = new POVectorAdapter(cvx, true);
1662POVectorAdapter * avy = new POVectorAdapter(cvy, true);
1663PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true);
1664
1665string nx,rx;
1666ParseObjectName(nomvx, rx, nx);
1667string ny,ry;
1668ParseObjectName(nomvy, ry, ny);
1669
[2491]1670// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1671bool fglock = (_fgimgapp) ? false : true;
1672
[1525]1673string title = ny + " (Y) vs. " + nx + " (X)";
1674// display 2D
[2491]1675myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
[1525]1676
1677return;
1678
1679#endif
1680}
1681
[165]1682/* --Methode--
[331]1683void NamedObjMgr::DisplayImage(string& nom, string dopt)
[165]1684{
1685 cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
1686}
1687*/
1688
1689
1690
1691
[1971]1692/* --Methode--
[165]1693void NamedObjMgr::SetGraphicAttributes(string gratt)
1694{
1695bool fg = false;
1696servnobjm->DecodeDispOption(gratt, fg);
[546]1697Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
[165]1698}
[333]1699
[165]1700void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
1701{
1702if (!myImgApp) return;
1703if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
1704else myImgApp->SetZone(nzx, nzy);
1705}
[1971]1706*/
[165]1707
1708/* --Methode-- */
[333]1709void NamedObjMgr::AddWRsId(string & nom, int wrsid)
[165]1710{
[2762]1711ZSync zs(*myMutex); zs.NOp();
1712AddWRsId_P(nom, wrsid);
1713}
1714
1715/* --Methode-- */
1716void NamedObjMgr::AddWRsId_P(string & nom, int wrsid)
1717{
[333]1718if(wrsid != 0) {
1719 NObjList::iterator it = myObjs->find(nom);
1720 if (it == myObjs->end()) return;
1721 (*it).second.wrsid.push_back(wrsid);
[295]1722 }
[165]1723return;
1724}
1725
1726/* --Methode-- */
[333]1727void NamedObjMgr::UpdateObjMgrWindow(int did)
[165]1728{
[333]1729if (!myImgApp) return;
[2762]1730ZSync zs(*myMutex); zs.NOp();
1731UpdateObjMgrWindow_P(did);
1732}
1733
1734/* --Methode-- */
1735void NamedObjMgr::UpdateObjMgrWindow_P(int did)
1736{
1737if (!myImgApp) return;
[2492]1738if ( !_fgimgapp ) myImgApp->LockMutex();
[2762]1739if ( !(myImgApp->ObjMgrW())->Visible() ||
1740 ( (myImgApp->ObjMgrW())->GetCurDirId() != did) ) {
1741 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
1742 return;
1743 }
[2490]1744
[685]1745(myImgApp->ObjMgrW())->ClearObjList();
[165]1746
[333]1747NObjList::iterator it;
1748string cn;
1749for(it = myObjs->begin(); it != myObjs->end(); it++) {
1750 if ((*it).second.dirid != did) continue;
1751 cn = (*it).first.substr(1);
[1321]1752 // cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ;
1753 cn = cn.substr(cn.find('/')+1) + " (T= " + (*it).second.obja->GetDataObjType() + ")" ;
[685]1754 (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
[165]1755 }
[2492]1756if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2762]1757return;
[333]1758}
[165]1759
1760
[333]1761/* Nouvelle-Fonction */
[1207]1762void NamedObjMgr::RemoveSpacesFromName(string & nom)
[165]1763{
[333]1764// on supprime les blancs de debut et de fin
1765size_t p = nom.find_first_not_of(" ");
1766if(p>nom.length()) { nom = ""; return; }
1767nom = nom.substr(p);
1768p = nom.find(' ');
1769if(p>nom.length()) p=nom.length();
1770nom = nom.substr(0, p);
[165]1771}
1772
[333]1773/* Nouvelle-Fonction */
[1207]1774bool NamedObjMgr::CheckDirName(string & nom)
[165]1775{
[333]1776RemoveSpacesFromName(nom);
1777if (nom.length() < 1) return(false);
1778if (nom[0] == '/') nom = nom.substr(1) ;
1779size_t p = nom.find('/');
1780if (p < nom.length()) nom = nom.substr(0,p);
[2218]1781if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
[333]1782return(true);
[165]1783}
1784
[333]1785/* Nouvelle-Fonction */
[1207]1786int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
[165]1787{
[333]1788RemoveSpacesFromName(nom);
1789// Si le nom ne commence pas par un slash, c'est le repertoire courant
1790if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
[165]1791else {
[333]1792 string xx = nom.substr(1);
1793 size_t p = xx.find('/');
1794 if (p < xx.length()) {
1795 nomrep = xx.substr(0,p);
1796 nomobj = xx.substr(p+1);
[165]1797 }
[333]1798 else {
1799 nomrep = xx;
1800 nomobj = "";
[165]1801 }
1802 }
[333]1803int rc = 0;
1804NObjDirList::iterator it = myDirs->find(nomrep);
1805if (it != myDirs->end()) rc = (*it).second.id;
1806return(rc);
[165]1807}
1808
Note: See TracBrowser for help on using the repository browser.