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 ............
|
---|
62 | struct 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 |
|
---|
69 | typedef map<string, nobj_diritem, less<string> > NObjDirList;
|
---|
70 |
|
---|
71 | struct 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 |
|
---|
82 | typedef map<string, nobj_item, less<string> > NObjList;
|
---|
83 |
|
---|
84 | static NObjDirList* myDirs = NULL;
|
---|
85 | static NObjList* myObjs = NULL;
|
---|
86 | static int fgOInit = 0;
|
---|
87 | static int myNObj = 0;
|
---|
88 | static int myDirId = 0;
|
---|
89 | static string* currDir;
|
---|
90 |
|
---|
91 | static PIStdImgApp* myImgApp=NULL;
|
---|
92 | static Services2NObjMgr* servnobjm=NULL;
|
---|
93 |
|
---|
94 | static DVList* myVars = NULL; // Pour stocker les variables
|
---|
95 |
|
---|
96 | static string* TmpDir = NULL; // Repertoire pour les compilations / link dynamique
|
---|
97 |
|
---|
98 | // Pour gestion multithread
|
---|
99 | static ZMutex* myMutex = NULL;
|
---|
100 | static bool myMtxLocked = false; // if myMutex has been locked
|
---|
101 | static bool obmWvis = false; // true -> ObjMgrWindow() is active/visible
|
---|
102 | static bool obmWUpdReq = false; // true -> ObjMgrWindow Update requested
|
---|
103 | // ..................................................................
|
---|
104 | // .... Classe NObjMgrSync ....
|
---|
105 | class NObjMgrSync {
|
---|
106 | public:
|
---|
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-- */
|
---|
142 | NamedObjMgr::NamedObjMgr(bool fgimgapp)
|
---|
143 | {
|
---|
144 | _fgimgapp = fgimgapp;
|
---|
145 | if (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 | }
|
---|
175 | fgOInit++;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | /* --Methode-- */
|
---|
180 | NamedObjMgr::~NamedObjMgr()
|
---|
181 | {
|
---|
182 | fgOInit--;
|
---|
183 | if (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-- */
|
---|
204 | void NamedObjMgr::SetImgApp(PIStdImgApp* app)
|
---|
205 | {
|
---|
206 | myImgApp = app;
|
---|
207 | servnobjm->SetImgApp(app);
|
---|
208 |
|
---|
209 | NObjDirList::iterator it;
|
---|
210 | string cn;
|
---|
211 | for(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 |
|
---|
218 | static bool verbeux = false; // true -> plus de message (creation/suppression d'objets)
|
---|
219 | void NamedObjMgr::SetVerbose(bool fg)
|
---|
220 | {
|
---|
221 | verbeux = fg;
|
---|
222 | }
|
---|
223 |
|
---|
224 | /* --Methode-- */
|
---|
225 | PIStdImgApp* NamedObjMgr::GetImgApp()
|
---|
226 | {
|
---|
227 | return(myImgApp);
|
---|
228 | }
|
---|
229 |
|
---|
230 | /* --Methode-- */
|
---|
231 | Services2NObjMgr* NamedObjMgr::GetServiceObj()
|
---|
232 | {
|
---|
233 | return(servnobjm);
|
---|
234 | }
|
---|
235 |
|
---|
236 | /* --Methode-- */
|
---|
237 | string const& NamedObjMgr::GetTmpDir()
|
---|
238 | {
|
---|
239 | return *TmpDir;
|
---|
240 | }
|
---|
241 |
|
---|
242 | /* --Methode-- */
|
---|
243 | void NamedObjMgr::SetTmpDir(string const& tmpdir)
|
---|
244 | {
|
---|
245 | if(tmpdir.length()<1) return;
|
---|
246 | *TmpDir = tmpdir;
|
---|
247 | int l = (*TmpDir).length();
|
---|
248 | if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
|
---|
249 | servnobjm->SetTmpDir(*TmpDir);
|
---|
250 | }
|
---|
251 |
|
---|
252 | /* --Methode-- */
|
---|
253 | bool 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-- */
|
---|
271 | bool 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-- */
|
---|
289 | bool 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-- */
|
---|
304 | string 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-- */
|
---|
316 | DVList& NamedObjMgr::GetVarList()
|
---|
317 | {
|
---|
318 | // cout << " DEBUG::GetVarList " << *myVars << endl;
|
---|
319 | NObjMgrSync zs(0); zs.NOp();
|
---|
320 | return(*myVars);
|
---|
321 | }
|
---|
322 |
|
---|
323 | /* --Methode-- */
|
---|
324 | bool NamedObjMgr::CreateDir(string & dirname)
|
---|
325 | {
|
---|
326 | NObjMgrSync zs(0); zs.NOp();
|
---|
327 | return CreateDir_P(dirname);
|
---|
328 | }
|
---|
329 |
|
---|
330 | /* --Methode-- */
|
---|
331 | bool NamedObjMgr::CreateDir_P(string & dirname)
|
---|
332 | {
|
---|
333 | if ( !CheckDirName(dirname) ) {
|
---|
334 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
335 | return(false);
|
---|
336 | }
|
---|
337 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
338 | if (it != myDirs->end()) {
|
---|
339 | cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
|
---|
340 | return(false);
|
---|
341 | }
|
---|
342 | myDirId++;
|
---|
343 | nobj_diritem di;
|
---|
344 | di.id = myDirId;
|
---|
345 | di.nobj = 0;
|
---|
346 | di.lock = false;
|
---|
347 | di.keepold = false;
|
---|
348 | (*myDirs)[dirname] = di;
|
---|
349 | if (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 | }
|
---|
355 | if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
|
---|
356 | return(true);
|
---|
357 | }
|
---|
358 |
|
---|
359 | /* --Methode-- */
|
---|
360 | bool NamedObjMgr::DeleteDir(string & dirname)
|
---|
361 | {
|
---|
362 | if ( !CheckDirName(dirname) ) {
|
---|
363 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
364 | return(false);
|
---|
365 | }
|
---|
366 | NObjMgrSync zs(0); zs.NOp();
|
---|
367 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
368 | if (it == myDirs->end()) {
|
---|
369 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
|
---|
370 | return(false);
|
---|
371 | }
|
---|
372 | if ((*it).second.nobj > 0) {
|
---|
373 | cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
|
---|
374 | return(false);
|
---|
375 | }
|
---|
376 | if ((*it).second.lock ) {
|
---|
377 | cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
|
---|
378 | return(false);
|
---|
379 | }
|
---|
380 | if ((*it).second.id < 50) {
|
---|
381 | cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
|
---|
382 | return(false);
|
---|
383 | }
|
---|
384 |
|
---|
385 | if (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 | }
|
---|
395 | myDirs->erase(it);
|
---|
396 | if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
|
---|
397 | return(true);
|
---|
398 | }
|
---|
399 |
|
---|
400 | /* --Methode-- */
|
---|
401 | void NamedObjMgr::LockDir(string & dirname)
|
---|
402 | {
|
---|
403 | NObjMgrSync zs(0); zs.NOp();
|
---|
404 | if ( !CheckDirName(dirname) ) return;
|
---|
405 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
406 | if (it == myDirs->end()) return;
|
---|
407 | (*it).second.lock = true;
|
---|
408 | if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
|
---|
409 | return;
|
---|
410 | }
|
---|
411 |
|
---|
412 | /* --Methode-- */
|
---|
413 | void NamedObjMgr::UnlockDir(string & dirname)
|
---|
414 | {
|
---|
415 | NObjMgrSync zs(0); zs.NOp();
|
---|
416 | if ( !CheckDirName(dirname) ) return;
|
---|
417 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
418 | if (it == myDirs->end()) return;
|
---|
419 | (*it).second.lock = true;
|
---|
420 | if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
|
---|
421 | return;
|
---|
422 | }
|
---|
423 |
|
---|
424 | /* --Methode-- */
|
---|
425 | void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
|
---|
426 | {
|
---|
427 | NObjMgrSync zs(0); zs.NOp();
|
---|
428 | if ( !CheckDirName(dirname) ) return;
|
---|
429 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
430 | if (it == myDirs->end()) return;
|
---|
431 | (*it).second.keepold = keepold;
|
---|
432 | if (!verbeux) return;
|
---|
433 | cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << " -> ";
|
---|
434 | if ( keepold ) cout << " True " << endl;
|
---|
435 | else cout << " False " << endl;
|
---|
436 | return;
|
---|
437 | }
|
---|
438 |
|
---|
439 |
|
---|
440 | /* --Methode-- */
|
---|
441 | bool NamedObjMgr::SetCurrentDir(string & dirname)
|
---|
442 | {
|
---|
443 | NObjMgrSync zs(0); zs.NOp();
|
---|
444 | if ( !CheckDirName(dirname) ) {
|
---|
445 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
446 | return(false);
|
---|
447 | }
|
---|
448 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
449 | if (it == myDirs->end()) {
|
---|
450 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
|
---|
451 | return(false);
|
---|
452 | }
|
---|
453 | *currDir = dirname;
|
---|
454 | if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
|
---|
455 | return(true);
|
---|
456 | }
|
---|
457 |
|
---|
458 | /* --Methode-- */
|
---|
459 | void NamedObjMgr::GetCurrentDir(string & dirname)
|
---|
460 | {
|
---|
461 | NObjMgrSync zs(0); zs.NOp();
|
---|
462 | dirname = *currDir;
|
---|
463 | }
|
---|
464 |
|
---|
465 | /* --Methode-- */
|
---|
466 | void NamedObjMgr::ListDirs(string & patt)
|
---|
467 | {
|
---|
468 | NObjMgrSync zs(0); zs.NOp();
|
---|
469 | NObjDirList::iterator it;
|
---|
470 | string cn;
|
---|
471 | cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl;
|
---|
472 | int k = 0;
|
---|
473 | for(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-- */
|
---|
486 | void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
|
---|
487 | {
|
---|
488 | NObjMgrSync zs(0); zs.NOp();
|
---|
489 | NObjDirList::iterator it;
|
---|
490 | string cn;
|
---|
491 | for(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-- */
|
---|
499 | void NamedObjMgr::CleanDir(string & dirname)
|
---|
500 | {
|
---|
501 | NObjMgrSync zs(0); zs.NOp();
|
---|
502 | CleanDir_P(dirname);
|
---|
503 | }
|
---|
504 |
|
---|
505 | /* --Methode-- */
|
---|
506 | void NamedObjMgr::CleanDir_P(string & dirname)
|
---|
507 | {
|
---|
508 | if ( !CheckDirName(dirname) ) {
|
---|
509 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
510 | // return(false); $CHECK$ illegal return value in void function
|
---|
511 | }
|
---|
512 | NObjDirList::iterator itr = myDirs->find(dirname);
|
---|
513 | if (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 |
|
---|
518 | int did = (*itr).second.id;
|
---|
519 | NObjList::iterator it;
|
---|
520 | list<int>::iterator iwr;
|
---|
521 | bool nodisp = true;
|
---|
522 | list<string> odel;
|
---|
523 | for(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 | }
|
---|
531 | list<string>::iterator ii;
|
---|
532 | for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii,true);
|
---|
533 |
|
---|
534 | if (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-- */
|
---|
562 | bool 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-- */
|
---|
569 | bool NamedObjMgr::AddObj_P(AnyDataObj* obj, string & nom, bool crd)
|
---|
570 | {
|
---|
571 |
|
---|
572 | if (obj == NULL) return(false);
|
---|
573 | // On verifie si l'objet est deja dans la liste
|
---|
574 | NObjList::iterator it;
|
---|
575 | for(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 | }
|
---|
581 | string nobj;
|
---|
582 | string nrep;
|
---|
583 | char buff[32];
|
---|
584 | int did = ParseObjectName(nom, nrep, nobj);
|
---|
585 | if (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
|
---|
594 | if (nrep == "autoc") {
|
---|
595 | CleanDir_P(nrep);
|
---|
596 | }
|
---|
597 |
|
---|
598 | myNObj++;
|
---|
599 | if ( !CheckName(nobj) ) {
|
---|
600 | sprintf(buff,"O%d", myNObj);
|
---|
601 | cout << "NamedObjMgr::AddObj() Name changed: " << nom << " -> " << buff << endl;
|
---|
602 | nom = buff;
|
---|
603 | }
|
---|
604 |
|
---|
605 | nom = '/' + nrep + '/' + nobj;
|
---|
606 | NObjDirList::iterator itr = myDirs->find(nrep);
|
---|
607 | if ((*itr).second.lock) {
|
---|
608 | cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
|
---|
609 | return(false);
|
---|
610 | }
|
---|
611 | it = myObjs->find(nom);
|
---|
612 | if (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 |
|
---|
631 | nobj_item no;
|
---|
632 | no.obj = obj;
|
---|
633 | no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
|
---|
634 | no.oid = myNObj;
|
---|
635 | no.dirid = did;
|
---|
636 | (*myObjs)[nom] = no;
|
---|
637 |
|
---|
638 | (*itr).second.nobj++;
|
---|
639 |
|
---|
640 | if (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 | }
|
---|
648 | if (verbeux) cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
|
---|
649 | << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
|
---|
650 | return(true);
|
---|
651 | }
|
---|
652 |
|
---|
653 | bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
|
---|
654 | {
|
---|
655 | NObjMgrSync zs(0); zs.NOp();
|
---|
656 | NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
|
---|
657 | if (adap == NULL) {
|
---|
658 | cout << "NamedObjMgr::AddObj() No Adapter ! " << nom << endl;
|
---|
659 | return(false);
|
---|
660 | }
|
---|
661 | AnyDataObj * cloneobj = adap->CloneDataObj(true);
|
---|
662 | delete adap;
|
---|
663 | if (cloneobj == NULL) {
|
---|
664 | cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl;
|
---|
665 | return(false);
|
---|
666 | }
|
---|
667 | return ( AddObj_P(cloneobj , nom, crd) );
|
---|
668 | }
|
---|
669 |
|
---|
670 | /* --Methode-- */
|
---|
671 | bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
|
---|
672 | {
|
---|
673 | NObjMgrSync zs(0); zs.NOp();
|
---|
674 | return RenameObj_P(nom, nomnew);
|
---|
675 | }
|
---|
676 |
|
---|
677 | /* --Methode-- */
|
---|
678 | bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew)
|
---|
679 | {
|
---|
680 | string n1,r1,n2,r2;
|
---|
681 | int dids = ParseObjectName(nom, r1, n1);
|
---|
682 | NObjDirList::iterator itr1 = myDirs->find(r1);
|
---|
683 | int did = ParseObjectName(nomnew, r2, n2);
|
---|
684 | NObjDirList::iterator itr2 = myDirs->find(r2);
|
---|
685 |
|
---|
686 | if (did == 0) {
|
---|
687 | cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
|
---|
688 | return(false);
|
---|
689 | }
|
---|
690 | nom = '/' + r1 + '/' + n1;
|
---|
691 | nomnew = '/' + r2 + '/' + n2;
|
---|
692 | NObjList::iterator it1 = myObjs->find(nom);
|
---|
693 | if (it1 == myObjs->end()) {
|
---|
694 | cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl;
|
---|
695 | return(false);
|
---|
696 | }
|
---|
697 |
|
---|
698 | if ( !CheckName(n2) ) {
|
---|
699 | cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
|
---|
700 | return(false);
|
---|
701 | }
|
---|
702 | NObjList::iterator it2 = myObjs->find(nomnew);
|
---|
703 | if (it2 != myObjs->end()) {
|
---|
704 | cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
|
---|
705 | return(false);
|
---|
706 | }
|
---|
707 |
|
---|
708 | if ( (*itr1).second.lock || (*itr2).second.lock ) {
|
---|
709 | cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !"
|
---|
710 | << endl;
|
---|
711 | return(false);
|
---|
712 | }
|
---|
713 |
|
---|
714 |
|
---|
715 | nobj_item no = (*it1).second;
|
---|
716 | no.dirid = did;
|
---|
717 | myObjs->erase(it1);
|
---|
718 | NObjDirList::iterator itr = myDirs->find(r1);
|
---|
719 | (*itr).second.nobj--;
|
---|
720 | (*myObjs)[nomnew] = no;
|
---|
721 | itr = myDirs->find(r2);
|
---|
722 | (*itr).second.nobj++;
|
---|
723 |
|
---|
724 | if (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 | }
|
---|
733 | if (verbeux)
|
---|
734 | cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
|
---|
735 | return(true);
|
---|
736 | }
|
---|
737 |
|
---|
738 | /* --Methode-- */
|
---|
739 | bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
|
---|
740 | {
|
---|
741 | NObjMgrSync zs(0); zs.NOp();
|
---|
742 | if(nomcp.length()<=0)
|
---|
743 | {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
|
---|
744 | return(false);}
|
---|
745 | NObjMgrAdapter* obnom = GetObjAdapter_P(nom);
|
---|
746 | if(obnom==NULL)
|
---|
747 | {cout<<"NamedObjMgr::CopyObj() Error - No "<<nom<<" object !"<<endl;
|
---|
748 | return(false);}
|
---|
749 | AnyDataObj* obnomcp = obnom->CloneDataObj();
|
---|
750 | if(obnomcp==NULL) return(false);
|
---|
751 | if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
|
---|
752 | return true;
|
---|
753 | }
|
---|
754 |
|
---|
755 | /* --Methode-- */
|
---|
756 | bool NamedObjMgr::DelObj(string & nom, bool fgd)
|
---|
757 | {
|
---|
758 | NObjMgrSync zs(0); zs.NOp();
|
---|
759 | return DelObj_P(nom, fgd);
|
---|
760 | }
|
---|
761 |
|
---|
762 | /* --Methode-- */
|
---|
763 | bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
|
---|
764 | {
|
---|
765 | string n1,r1;
|
---|
766 | int did = ParseObjectName(nom, r1, n1);
|
---|
767 | nom = '/' + r1 + '/' + n1;
|
---|
768 | NObjList::iterator it = myObjs->find(nom);
|
---|
769 | if (it == myObjs->end()) return(false);
|
---|
770 | NObjDirList::iterator itr = myDirs->find(r1);
|
---|
771 | if ( (*itr).second.lock ) {
|
---|
772 | cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
|
---|
773 | return(false);
|
---|
774 | }
|
---|
775 | list<int>::iterator ii;
|
---|
776 | if (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 | }
|
---|
785 | delete (*it).second.obja; // destruction de l'adaptateur
|
---|
786 | if (fgd) delete (*it).second.obj;
|
---|
787 |
|
---|
788 | if (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 | }
|
---|
796 | myObjs->erase(it);
|
---|
797 | (*itr).second.nobj--;
|
---|
798 |
|
---|
799 |
|
---|
800 | if (!verbeux) return(true);
|
---|
801 | if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
|
---|
802 | else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
|
---|
803 | return(true);
|
---|
804 | }
|
---|
805 |
|
---|
806 | /* --Methode-- */
|
---|
807 | bool NamedObjMgr::DelObj_Id(int oid)
|
---|
808 | {
|
---|
809 | NObjMgrSync zs(0); zs.NOp();
|
---|
810 | NObjList::iterator it;
|
---|
811 | string nom;
|
---|
812 | bool of = false;
|
---|
813 | for(it = myObjs->begin(); it != myObjs->end(); it++)
|
---|
814 | if ( (*it).second.oid == oid ) {
|
---|
815 | of = true; nom = (*it).first;
|
---|
816 | break;
|
---|
817 | }
|
---|
818 | if (of) return(DelObj_P(nom, true));
|
---|
819 | else return(false);
|
---|
820 | }
|
---|
821 |
|
---|
822 | /* --Methode-- */
|
---|
823 | void NamedObjMgr::DelObjects(string & patt, bool fgd)
|
---|
824 | {
|
---|
825 | NObjMgrSync zs(0); zs.NOp();
|
---|
826 | string n1,r1;
|
---|
827 | ParseObjectName(patt, r1, n1);
|
---|
828 | patt = '/' + r1 + '/' + n1;
|
---|
829 | NObjList::iterator it;
|
---|
830 | list<string> odel;
|
---|
831 | string cn;
|
---|
832 | for(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 | }
|
---|
836 | list<string>::iterator ii;
|
---|
837 | for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii, fgd);
|
---|
838 | }
|
---|
839 |
|
---|
840 | /* --Methode-- */
|
---|
841 | AnyDataObj* NamedObjMgr::GetObj(string & nom)
|
---|
842 | {
|
---|
843 | NObjMgrSync zs(0); zs.NOp();
|
---|
844 | return GetObj_P(nom);
|
---|
845 | }
|
---|
846 |
|
---|
847 | /* --Methode-- */
|
---|
848 | AnyDataObj* NamedObjMgr::GetObj_P(string & nom)
|
---|
849 | {
|
---|
850 | string n1,r1;
|
---|
851 | ParseObjectName(nom, r1, n1);
|
---|
852 | nom = '/' + r1 + '/' + n1;
|
---|
853 | NObjList::iterator it = myObjs->find(nom);
|
---|
854 | if (it == myObjs->end()) return(NULL);
|
---|
855 | return((*it).second.obj);
|
---|
856 | }
|
---|
857 |
|
---|
858 | /* --Methode-- */
|
---|
859 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
|
---|
860 | {
|
---|
861 | NObjMgrSync zs(0); zs.NOp();
|
---|
862 | return GetObjAdapter_P(nom);
|
---|
863 | }
|
---|
864 |
|
---|
865 | /* --Methode-- */
|
---|
866 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter_P(string & nom)
|
---|
867 | {
|
---|
868 | string n1,r1;
|
---|
869 | ParseObjectName(nom, r1, n1);
|
---|
870 | nom = '/' + r1 + '/' + n1;
|
---|
871 | NObjList::iterator it = myObjs->find(nom);
|
---|
872 | if (it == myObjs->end()) return(NULL);
|
---|
873 | return((*it).second.obja);
|
---|
874 | }
|
---|
875 |
|
---|
876 | /* --Methode-- */
|
---|
877 | void NamedObjMgr::ListObjs(string & patt)
|
---|
878 | {
|
---|
879 | NObjMgrSync zs(0); zs.NOp();
|
---|
880 | int k;
|
---|
881 | AnyDataObj* obj=NULL;
|
---|
882 | string ctyp;
|
---|
883 | char strg[256];
|
---|
884 |
|
---|
885 | string n1,r1;
|
---|
886 | ParseObjectName(patt, r1, n1);
|
---|
887 | patt = '/' + r1 + '/' + n1;
|
---|
888 | cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
|
---|
889 | NObjList::iterator it; k = 0;
|
---|
890 | string cn;
|
---|
891 | for(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 | }
|
---|
901 | cout << endl;
|
---|
902 | return;
|
---|
903 | }
|
---|
904 |
|
---|
905 | /* --Methode-- */
|
---|
906 | void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
|
---|
907 | {
|
---|
908 | NObjMgrSync zs(0); zs.NOp();
|
---|
909 | string n1,r1;
|
---|
910 | if (patt.length() < 1) return;
|
---|
911 | bool fgr = (patt[0] == '/') ? true : false;
|
---|
912 | ParseObjectName(patt, r1, n1);
|
---|
913 | patt = '/' + r1 + '/' + n1;
|
---|
914 | NObjList::iterator it;
|
---|
915 | string cn;
|
---|
916 | for(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-- */
|
---|
942 | void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
|
---|
943 | {
|
---|
944 | PPersist* ppobj=NULL;
|
---|
945 | bool ok = true;
|
---|
946 | #ifdef SANS_EVOLPLANCK
|
---|
947 | TRY{
|
---|
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
|
---|
955 | try {
|
---|
956 | PInPersist pis(flnm);
|
---|
957 | ppobj = pis.ReadObject();
|
---|
958 | }
|
---|
959 | catch (IOExc iox) {
|
---|
960 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
961 | ok = false;
|
---|
962 | }
|
---|
963 | #endif
|
---|
964 | if (!ok) return;
|
---|
965 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
966 | AddObj(ppobj->DataObj(), nobj, true);
|
---|
967 | cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
|
---|
968 | return;
|
---|
969 | }
|
---|
970 | /* --Methode-- */
|
---|
971 | void 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 | {
|
---|
975 | if(flnm_objname.size()<2) return;
|
---|
976 | int nread=0;
|
---|
977 | try {
|
---|
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 | }
|
---|
997 | cout<<nread<<" objects have been read"<<endl;
|
---|
998 | return;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | /* --Methode-- */
|
---|
1002 | void NamedObjMgr::ReadObj(PInPersist& s, int num)
|
---|
1003 | {
|
---|
1004 | NObjMgrSync zs(0); zs.NOp();
|
---|
1005 | ReadObj_P(s, num);
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | /* --Methode-- */
|
---|
1009 | void NamedObjMgr::ReadObj_P(PInPersist& s, int num)
|
---|
1010 | {
|
---|
1011 | int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
|
---|
1012 | #ifdef SANS_EVOLPLANCK
|
---|
1013 | int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
|
---|
1014 | #endif
|
---|
1015 | int n0, n1;
|
---|
1016 | bool ok = true;
|
---|
1017 | PPersist* obj=NULL;
|
---|
1018 | string nom;
|
---|
1019 |
|
---|
1020 | int nread = 0;
|
---|
1021 | int nbtags = 0;
|
---|
1022 | #ifdef SANS_EVOLPLANCK
|
---|
1023 | nbtags = s.NbTags();
|
---|
1024 | #else
|
---|
1025 | nbtags = s.NbNameTags();
|
---|
1026 | #endif
|
---|
1027 | if ( (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
|
---|
1043 | try {
|
---|
1044 | obj = s.ReadObject();
|
---|
1045 | }
|
---|
1046 | catch (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 |
|
---|
1058 | if (num < 0) { n0 = 0; n1 = nbtags; }
|
---|
1059 | else { n0 = num; n1 = num+1; }
|
---|
1060 | for(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 |
|
---|
1087 | cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
|
---|
1088 | return;
|
---|
1089 | }
|
---|
1090 | /* --Methode-- */
|
---|
1091 | void NamedObjMgr::ReadAll(string const & flnm)
|
---|
1092 | {
|
---|
1093 | #ifdef SANS_EVOLPLANCK
|
---|
1094 | bool ok = true;
|
---|
1095 | PPersist* obj=NULL;
|
---|
1096 |
|
---|
1097 | PInPersist* ppin=NULL;
|
---|
1098 | TRY{
|
---|
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; }
|
---|
1105 | ENDTRY;
|
---|
1106 | if (!ok) return;
|
---|
1107 | if (obj) {
|
---|
1108 | string nom = servnobjm->FileName2Name(flnm);
|
---|
1109 | AddObj(obj->DataObj(), nom, false);
|
---|
1110 | }
|
---|
1111 | else ReadObj((*ppin), -1);
|
---|
1112 | delete ppin;
|
---|
1113 | #else
|
---|
1114 | try {
|
---|
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 | }
|
---|
1137 | catch (IOExc& iox) {
|
---|
1138 | cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1139 | }
|
---|
1140 | #endif
|
---|
1141 | return;
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 |
|
---|
1145 | /* --Methode-- */
|
---|
1146 | void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
|
---|
1147 | {
|
---|
1148 | NObjMgrSync zs(0); zs.NOp();
|
---|
1149 | SaveObj_P(nom, s, keeppath);
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | static int key_for_write = 5000;
|
---|
1153 | /* --Methode-- */
|
---|
1154 | void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
|
---|
1155 | {
|
---|
1156 | if (nom.length() < 1) return;
|
---|
1157 | string nob,rep;
|
---|
1158 | ParseObjectName(nom, rep, nob);
|
---|
1159 | nom = '/' + rep + '/' + nob;
|
---|
1160 | NObjMgrAdapter* obja=NULL;
|
---|
1161 | string nomf = (keeppath) ? nom : nob;
|
---|
1162 | obja = GetObjAdapter_P(nom);
|
---|
1163 | if (obja == NULL) return;
|
---|
1164 | printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
|
---|
1165 | nom.c_str(), typeid(*(obja->GetDataObj())).name());
|
---|
1166 | obja->SavePPF(s, nomf);
|
---|
1167 | return;
|
---|
1168 | }
|
---|
1169 |
|
---|
1170 | /* --Methode-- */
|
---|
1171 | void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
|
---|
1172 | {
|
---|
1173 | NObjMgrSync zs(0); zs.NOp();
|
---|
1174 | string n1,r1;
|
---|
1175 | if (patt.length() < 1) return;
|
---|
1176 | bool keeppath = (patt[0] == '/') ? true : false;
|
---|
1177 | ParseObjectName(patt, r1, n1);
|
---|
1178 | patt = '/' + r1 + '/' + n1;
|
---|
1179 |
|
---|
1180 | bool ok = true;
|
---|
1181 | POutPersist* pout=NULL;
|
---|
1182 | #ifdef SANS_EVOLPLANCK
|
---|
1183 | TRY{
|
---|
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
|
---|
1189 | try {
|
---|
1190 | pout = new POutPersist(flnm);
|
---|
1191 | }
|
---|
1192 | catch (IOExc iox) {
|
---|
1193 | cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1194 | ok = false;
|
---|
1195 | }
|
---|
1196 | #endif
|
---|
1197 | if (!ok) return;
|
---|
1198 | NObjList::iterator it;
|
---|
1199 | string cn;
|
---|
1200 | for(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 | }
|
---|
1205 | delete pout;
|
---|
1206 | return;
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | /* --Methode-- */
|
---|
1210 | void 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-- */
|
---|
1245 | void NamedObjMgr::SaveAll(string const& flnm)
|
---|
1246 | {
|
---|
1247 | NObjMgrSync zs(0); zs.NOp();
|
---|
1248 | bool ok = true;
|
---|
1249 |
|
---|
1250 | POutPersist* pout=NULL;
|
---|
1251 | #ifdef SANS_EVOLPLANCK
|
---|
1252 | TRY{
|
---|
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
|
---|
1258 | try {
|
---|
1259 | pout = new POutPersist(flnm);
|
---|
1260 | }
|
---|
1261 | catch (IOExc iox) {
|
---|
1262 | cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1263 | ok = false;
|
---|
1264 | }
|
---|
1265 | #endif
|
---|
1266 | if (!ok) return;
|
---|
1267 | NObjList::iterator it;
|
---|
1268 | string no;
|
---|
1269 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
1270 | no = (*it).first;
|
---|
1271 | SaveObj_P(no, (*pout), true);
|
---|
1272 | }
|
---|
1273 | delete pout;
|
---|
1274 | return;
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 |
|
---|
1278 |
|
---|
1279 | /* --Methode-- */
|
---|
1280 | void NamedObjMgr::PrintObj(string& nom, int lev)
|
---|
1281 | {
|
---|
1282 | NObjMgrSync zs(0); zs.NOp();
|
---|
1283 | NObjMgrAdapter* obja=NULL;
|
---|
1284 | obja = GetObjAdapter_P(nom);
|
---|
1285 | if (obja == NULL) return;
|
---|
1286 | AnyDataObj* ob = obja->GetDataObj();
|
---|
1287 | if (ob == NULL) {
|
---|
1288 | cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl;
|
---|
1289 | return;
|
---|
1290 | }
|
---|
1291 | string ctyp = typeid(*ob).name();
|
---|
1292 | cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
|
---|
1293 | obja->Print(cout, lev);
|
---|
1294 |
|
---|
1295 | return;
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | /* --Methode-- */
|
---|
1299 | void NamedObjMgr::DisplayObj(string& nom, string dopt)
|
---|
1300 | {
|
---|
1301 | // Pas de display si option dopt = nodisp
|
---|
1302 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1303 |
|
---|
1304 | NObjMgrSync zs(0); zs.NOp();
|
---|
1305 |
|
---|
1306 | NObjMgrAdapter* obja=NULL;
|
---|
1307 | obja = GetObjAdapter_P(nom);
|
---|
1308 | if (obja == NULL) {
|
---|
1309 | cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
|
---|
1310 | return;
|
---|
1311 | }
|
---|
1312 | if (obja->GetDataObj() == NULL) {
|
---|
1313 | cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
|
---|
1314 | return;
|
---|
1315 | }
|
---|
1316 | if (!myImgApp) return;
|
---|
1317 |
|
---|
1318 | PIDrawer * dr = NULL;
|
---|
1319 | P2DArrayAdapter* arr = NULL;
|
---|
1320 | dr = obja->GetDrawer(dopt);
|
---|
1321 | if (!dr) arr = obja->Get2DArray(dopt);
|
---|
1322 |
|
---|
1323 | if (!dr && !arr) {
|
---|
1324 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1325 | cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
|
---|
1326 | return;
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | int wrsid = 0;
|
---|
1330 |
|
---|
1331 | string n1,r1;
|
---|
1332 | ParseObjectName(nom, r1, n1);
|
---|
1333 |
|
---|
1334 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1335 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1336 |
|
---|
1337 | if (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 | }
|
---|
1342 | else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, false, 0, fglock);
|
---|
1343 |
|
---|
1344 | AddWRsId_P(nom, wrsid);
|
---|
1345 | return;
|
---|
1346 | }
|
---|
1347 |
|
---|
1348 | /* --Methode-- */
|
---|
1349 | void NamedObjMgr::DisplayImage(string& nom, string dopt, bool fgimagnav)
|
---|
1350 | {
|
---|
1351 | // Pas de display si option dopt = nodisp
|
---|
1352 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1353 |
|
---|
1354 | NObjMgrSync zs(0); zs.NOp();
|
---|
1355 |
|
---|
1356 | NObjMgrAdapter* obja=NULL;
|
---|
1357 | obja = GetObjAdapter_P(nom);
|
---|
1358 | if (obja == NULL) {
|
---|
1359 | cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
|
---|
1360 | return;
|
---|
1361 | }
|
---|
1362 | if (obja->GetDataObj() == NULL) {
|
---|
1363 | cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
|
---|
1364 | return;
|
---|
1365 | }
|
---|
1366 | if (!myImgApp) return;
|
---|
1367 |
|
---|
1368 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
1369 |
|
---|
1370 | if (!arr) {
|
---|
1371 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1372 | cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
|
---|
1373 | return;
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | string n1,r1;
|
---|
1377 | ParseObjectName(nom, r1, n1);
|
---|
1378 |
|
---|
1379 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1380 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1381 |
|
---|
1382 | int wrsid = 0;
|
---|
1383 | wrsid = myImgApp->DispImage(arr, n1, dopt, fgimagnav, 0, fglock);
|
---|
1384 |
|
---|
1385 | AddWRsId_P(nom, wrsid);
|
---|
1386 | return;
|
---|
1387 | }
|
---|
1388 | /* --Methode-- */
|
---|
1389 | void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
|
---|
1390 | {
|
---|
1391 | // Pas de display si option dopt = nodisp
|
---|
1392 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1393 |
|
---|
1394 | NObjMgrSync zs(0); zs.NOp();
|
---|
1395 |
|
---|
1396 | NObjMgrAdapter* obja=NULL;
|
---|
1397 | obja = GetObjAdapter_P(nom);
|
---|
1398 | if (obja == NULL) {
|
---|
1399 | cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
|
---|
1400 | return;
|
---|
1401 | }
|
---|
1402 | if (obja->GetDataObj() == NULL) {
|
---|
1403 | cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
|
---|
1404 | return;
|
---|
1405 | }
|
---|
1406 | if (!myImgApp) return;
|
---|
1407 |
|
---|
1408 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
1409 |
|
---|
1410 | if (!arr) {
|
---|
1411 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1412 | cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
|
---|
1413 | return;
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | if ((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 |
|
---|
1423 | string n1,r1;
|
---|
1424 | ParseObjectName(nom, r1, n1);
|
---|
1425 |
|
---|
1426 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1427 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1428 |
|
---|
1429 | int wrsid = 0;
|
---|
1430 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
---|
1431 | wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
|
---|
1432 | AddWRsId_P(nom, wrsid);
|
---|
1433 | return;
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | /* --Methode-- */
|
---|
1437 | void 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
|
---|
1442 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1443 |
|
---|
1444 | NObjMgrSync zs(0); zs.NOp();
|
---|
1445 |
|
---|
1446 | AnyDataObj* obj=GetObj_P(nom);
|
---|
1447 | if (obj == NULL) {
|
---|
1448 | cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
|
---|
1449 | return;
|
---|
1450 | }
|
---|
1451 | if (!myImgApp) return;
|
---|
1452 |
|
---|
1453 | NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
|
---|
1454 | if (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 |
|
---|
1461 | int wrsid = 0;
|
---|
1462 | dopt = "defline " + dopt;
|
---|
1463 |
|
---|
1464 | string n1,r1;
|
---|
1465 | ParseObjectName(nom, r1, n1);
|
---|
1466 |
|
---|
1467 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1468 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1469 |
|
---|
1470 | if ( 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 | }
|
---|
1479 | else {
|
---|
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 |
|
---|
1493 | AddWRsId_P(nom, wrsid);
|
---|
1494 | return;
|
---|
1495 | }
|
---|
1496 |
|
---|
1497 | /* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
|
---|
1498 | void 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
|
---|
1512 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1513 |
|
---|
1514 | NObjMgrSync zs(0); zs.NOp();
|
---|
1515 |
|
---|
1516 | AnyDataObj* obj=GetObj_P(nom);
|
---|
1517 | if(obj == NULL)
|
---|
1518 | {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
|
---|
1519 | return;}
|
---|
1520 | if(!myImgApp) return;
|
---|
1521 | if(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
|
---|
1527 | bool errx=false, erry=false, errz=false;
|
---|
1528 | if(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 |
|
---|
1557 | AddWRsId_P(nom, wrsid);
|
---|
1558 |
|
---|
1559 | return;
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 | /* --Methode-- */
|
---|
1563 | void 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
|
---|
1568 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1569 |
|
---|
1570 | NObjMgrSync zs(0); zs.NOp();
|
---|
1571 |
|
---|
1572 | #ifdef SANS_EVOLPLANCK
|
---|
1573 | cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
|
---|
1574 | #else
|
---|
1575 |
|
---|
1576 | if(!myImgApp) return;
|
---|
1577 |
|
---|
1578 | AnyDataObj* obj;
|
---|
1579 | obj = GetObj_P(nomvx);
|
---|
1580 | if(obj == NULL) {
|
---|
1581 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl;
|
---|
1582 | return;
|
---|
1583 | }
|
---|
1584 | //Vector * vx = dynamic_cast<Vector *>(obj);
|
---|
1585 | BaseArray* bax = dynamic_cast<BaseArray *>(obj);
|
---|
1586 | if (bax == NULL) {
|
---|
1587 | cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl;
|
---|
1588 | return;
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 | obj = GetObj_P(nomvy);
|
---|
1592 | if(obj == NULL) {
|
---|
1593 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
|
---|
1594 | return;
|
---|
1595 | }
|
---|
1596 | BaseArray* bay = dynamic_cast<BaseArray *>(obj);
|
---|
1597 | if (bay == NULL) {
|
---|
1598 | cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
|
---|
1599 | return;
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | Vector vx = *bax;
|
---|
1603 | Vector vy = *bay;
|
---|
1604 | Vector * cvx, * cvy;
|
---|
1605 |
|
---|
1606 | if (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 | }
|
---|
1617 | else {
|
---|
1618 | cvx = new Vector(vx);
|
---|
1619 | cvy = new Vector(vy);
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 | POVectorAdapter * avx = new POVectorAdapter(cvx, true);
|
---|
1623 | POVectorAdapter * avy = new POVectorAdapter(cvy, true);
|
---|
1624 | PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true);
|
---|
1625 |
|
---|
1626 | string nx,rx;
|
---|
1627 | ParseObjectName(nomvx, rx, nx);
|
---|
1628 | string ny,ry;
|
---|
1629 | ParseObjectName(nomvy, ry, ny);
|
---|
1630 |
|
---|
1631 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1632 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1633 |
|
---|
1634 | string title = ny + " (Y) vs. " + nx + " (X)";
|
---|
1635 | // display 2D
|
---|
1636 | myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
|
---|
1637 |
|
---|
1638 | return;
|
---|
1639 |
|
---|
1640 | #endif
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | /* --Methode--
|
---|
1644 | void NamedObjMgr::DisplayImage(string& nom, string dopt)
|
---|
1645 | {
|
---|
1646 | cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
|
---|
1647 | }
|
---|
1648 | */
|
---|
1649 |
|
---|
1650 |
|
---|
1651 |
|
---|
1652 |
|
---|
1653 | /* --Methode--
|
---|
1654 | void NamedObjMgr::SetGraphicAttributes(string gratt)
|
---|
1655 | {
|
---|
1656 | bool fg = false;
|
---|
1657 | servnobjm->DecodeDispOption(gratt, fg);
|
---|
1658 | Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
|
---|
1662 | {
|
---|
1663 | if (!myImgApp) return;
|
---|
1664 | if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
|
---|
1665 | else myImgApp->SetZone(nzx, nzy);
|
---|
1666 | }
|
---|
1667 | */
|
---|
1668 |
|
---|
1669 | /* --Methode-- */
|
---|
1670 | int NamedObjMgr::NameToOId(string & nom)
|
---|
1671 | {
|
---|
1672 | NObjMgrSync zs(0); zs.NOp();
|
---|
1673 | return NameToOId_P(nom);
|
---|
1674 | }
|
---|
1675 |
|
---|
1676 | /* --Methode-- */
|
---|
1677 | int NamedObjMgr::NameToOId_P(string & nom)
|
---|
1678 | {
|
---|
1679 | string n1,r1;
|
---|
1680 | ParseObjectName(nom, r1, n1);
|
---|
1681 | nom = '/' + r1 + '/' + n1;
|
---|
1682 | NObjList::iterator it = myObjs->find(nom);
|
---|
1683 | if (it == myObjs->end()) return(-1);
|
---|
1684 | else return((*it).second.oid);
|
---|
1685 | }
|
---|
1686 |
|
---|
1687 |
|
---|
1688 | /* --Methode-- */
|
---|
1689 | void NamedObjMgr::AddWRsId(string & nom, int wrsid)
|
---|
1690 | {
|
---|
1691 | NObjMgrSync zs(0); zs.NOp();
|
---|
1692 | AddWRsId_P(nom, wrsid);
|
---|
1693 | }
|
---|
1694 |
|
---|
1695 | /* --Methode-- */
|
---|
1696 | void NamedObjMgr::AddWRsId_P(string & nom, int wrsid)
|
---|
1697 | {
|
---|
1698 | if(wrsid != 0) {
|
---|
1699 | NObjList::iterator it = myObjs->find(nom);
|
---|
1700 | if (it == myObjs->end()) return;
|
---|
1701 | (*it).second.wrsid.push_back(wrsid);
|
---|
1702 | }
|
---|
1703 | return;
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 | /* --Methode-- */
|
---|
1707 | void NamedObjMgr::UpdateObjMgrWindow(int did)
|
---|
1708 | {
|
---|
1709 | if (!myImgApp) return;
|
---|
1710 | if (myMtxLocked) {
|
---|
1711 | obmWUpdReq = true;
|
---|
1712 | obmWvis = false;
|
---|
1713 | (myImgApp->ObjMgrW())->SetUnSensitive();
|
---|
1714 | return;
|
---|
1715 | }
|
---|
1716 | NObjMgrSync zs(0); zs.NOp();
|
---|
1717 | if (did < 0) {
|
---|
1718 | string cdir = *currDir;
|
---|
1719 | cdir = '/' + cdir;
|
---|
1720 | (myImgApp->ObjMgrW())->SetCurDir(cdir);
|
---|
1721 | did = (myImgApp->ObjMgrW())->GetCurDirId();
|
---|
1722 | }
|
---|
1723 |
|
---|
1724 | UpdateObjMgrWindow_P(did);
|
---|
1725 | (myImgApp->ObjMgrW())->SetSensitive();
|
---|
1726 | obmWUpdReq = false;
|
---|
1727 | obmWvis = true;
|
---|
1728 | }
|
---|
1729 |
|
---|
1730 | /* --Methode-- */
|
---|
1731 | void NamedObjMgr::SetObjMgrWindowVisibility(bool fgvis)
|
---|
1732 | {
|
---|
1733 | obmWvis = fgvis;
|
---|
1734 | }
|
---|
1735 |
|
---|
1736 | /* --Methode-- */
|
---|
1737 | void NamedObjMgr::UpdateObjMgrWindow_P(int did)
|
---|
1738 | {
|
---|
1739 | if (!myImgApp) return;
|
---|
1740 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
1741 | if ( !(myImgApp->ObjMgrW())->Visible() ||
|
---|
1742 | ( (myImgApp->ObjMgrW())->GetCurDirId() != did) ) {
|
---|
1743 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
1744 | return;
|
---|
1745 | }
|
---|
1746 |
|
---|
1747 | (myImgApp->ObjMgrW())->ClearObjList();
|
---|
1748 |
|
---|
1749 | NObjList::iterator it;
|
---|
1750 | string cn;
|
---|
1751 | for(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 | }
|
---|
1758 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
1759 | return;
|
---|
1760 | }
|
---|
1761 |
|
---|
1762 |
|
---|
1763 | /* Nouvelle-Fonction */
|
---|
1764 | void NamedObjMgr::RemoveSpacesFromName(string & nom)
|
---|
1765 | {
|
---|
1766 | // on supprime les blancs de debut et de fin
|
---|
1767 | size_t p = nom.find_first_not_of(" ");
|
---|
1768 | if(p>nom.length()) { nom = ""; return; }
|
---|
1769 | nom = nom.substr(p);
|
---|
1770 | p = nom.find(' ');
|
---|
1771 | if(p>nom.length()) p=nom.length();
|
---|
1772 | nom = nom.substr(0, p);
|
---|
1773 | }
|
---|
1774 |
|
---|
1775 | /* Nouvelle-Fonction */
|
---|
1776 | bool NamedObjMgr::CheckDirName(string & nom)
|
---|
1777 | {
|
---|
1778 | RemoveSpacesFromName(nom);
|
---|
1779 | if (nom.length() < 1) return(false);
|
---|
1780 | if (nom[0] == '/') nom = nom.substr(1) ;
|
---|
1781 | size_t p = nom.find('/');
|
---|
1782 | if (p < nom.length()) nom = nom.substr(0,p);
|
---|
1783 | if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
|
---|
1784 | return(true);
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | /* Nouvelle-Fonction */
|
---|
1788 | int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
|
---|
1789 | {
|
---|
1790 | RemoveSpacesFromName(nom);
|
---|
1791 | // Si le nom ne commence pas par un slash, c'est le repertoire courant
|
---|
1792 | if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
|
---|
1793 | else {
|
---|
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 | }
|
---|
1805 | int rc = 0;
|
---|
1806 | NObjDirList::iterator it = myDirs->find(nomrep);
|
---|
1807 | if (it != myDirs->end()) rc = (*it).second.id;
|
---|
1808 | return(rc);
|
---|
1809 | }
|
---|
1810 |
|
---|
1811 | /* Nouvelle-Fonction */
|
---|
1812 | bool NamedObjMgr::CheckName(string const & nom)
|
---|
1813 | {
|
---|
1814 | if (nom.length() < 1) return false;
|
---|
1815 | if (! isalpha(nom[0]) ) return false;
|
---|
1816 | for(int k=0; k<nom.length(); k++)
|
---|
1817 | if ((!isalnum(nom[k])) && (nom[k] != '_')) return false;
|
---|
1818 | return true;
|
---|
1819 | }
|
---|