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

Last change on this file since 2616 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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