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

Last change on this file since 4078 was 4037, checked in by ansari, 14 years ago

modif mineure dans nobjmgr.cc NamedObjMgr::DisplayVector()- commande vecplot - Reza 14/11/2011

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