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

Last change on this file since 2490 was 2490, checked in by ansari, 22 years ago

Suite modifs pour piapp multi-thread - introduction de lock lors de la mise a jour de la fenetre ObjMgr par NamedObjMgr - Reza 1 Jan 2004

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