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

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

Suite modifs pour piapp multi-thread - introduction de lock lors de la mise a jour de la fenetre ObjMgr par NamedObjMgr - Reza 1 Jan 2004

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