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

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

Amelioration de la syntaxe de l'interpreteur, gestion de quotes, ligne suite
Commande linkff2 (2eme groupe de link, pour utilisation par CxxExecutor
Amelioration de la gestion de TMPDIR

Reza 2/11/2000

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