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