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

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

GetTmpDir SetTmpDir ds nobjmgr.h
re-ecriture commande sur piconsole en bleu/bleu_gras
suppression OBJ ds CrMakeFile

rz+cmv 31/10/00

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