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

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

Ajout de cxxexecutor (Execution C++ en ligne ds piapp) - CMV+Reza 11/10/2000

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