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

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

Tentative pour regler le probleme de blocage de piapp suite a affichage de la fefenetre de gestion d'objets.

1/ Protection dans NamedObjMgr() pour eviter deadlock de mutex (ds NamedObjMgr::UpdateObjMgrWindow() en particulier)
2/ Introduction de la classe SOpExObj (fichier piacmd.h .cc) pour execution d'operations sur objets, initiees depuis la boucle d'evts, dans un thread separe.

Reza , 30/10/2007

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