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

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

Adaptation aux modifs interface PPersist - Reza 22 Nov 2003

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