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

Last change on this file since 3279 was 3269, checked in by ansari, 18 years ago

Ajout des commandes nt2dcn et nt2dci , modifs PINtuple pour permettre l'utilisation d'une colonne pour specifier la couleur de trace de chaque marker - Reza 19/06/2007

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