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

Last change on this file since 2322 was 2322, checked in by cmv, 23 years ago
  • passage xxstream.h en xxstream
  • compile avec gcc_3.2, gcc_2.96 et cxx En 3.2 le seek from ::end semble marcher (voir Eval/COS/pbseekios.cc)

rz+cmv 11/2/2003

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