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; // Repertoire pour les compilations / link dynamique
|
---|
98 |
|
---|
99 | // Pour gestion multithread
|
---|
100 | static ZMutex* myMutex;
|
---|
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 | currDir = new string("home");
|
---|
125 | string dirn = "home";
|
---|
126 | CreateDir_P(dirn);
|
---|
127 | SetKeepOldDirAtt(dirn, false);
|
---|
128 | dirn = "tmp";
|
---|
129 | CreateDir_P(dirn);
|
---|
130 | SetKeepOldDirAtt(dirn, false);
|
---|
131 | dirn = "autoc";
|
---|
132 | CreateDir_P(dirn);
|
---|
133 | SetKeepOldDirAtt(dirn, false);
|
---|
134 | dirn = "old";
|
---|
135 | CreateDir_P(dirn);
|
---|
136 | SetKeepOldDirAtt(dirn, false);
|
---|
137 | dirn = "home";
|
---|
138 | SetCurrentDir(dirn);
|
---|
139 | myDirId = 50;
|
---|
140 | char* varenv;
|
---|
141 | TmpDir = new string("");
|
---|
142 | if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
|
---|
143 | int l = (*TmpDir).length();
|
---|
144 | if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
|
---|
145 | servnobjm = new Services2NObjMgr(*TmpDir);
|
---|
146 | myMutex = new ZMutex;
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
293 | return(*myVars);
|
---|
294 | }
|
---|
295 |
|
---|
296 | /* --Methode-- */
|
---|
297 | bool NamedObjMgr::CreateDir(string & dirname)
|
---|
298 | {
|
---|
299 | ZSync(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
430 | dirname = *currDir;
|
---|
431 | }
|
---|
432 |
|
---|
433 | /* --Methode-- */
|
---|
434 | void NamedObjMgr::ListDirs(string & patt)
|
---|
435 | {
|
---|
436 | ZSync(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*myMutex);
|
---|
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(*ii,true);
|
---|
501 | if (myImgApp) {
|
---|
502 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
503 | (myImgApp->ObjMgrW())->UpdateList(did);
|
---|
504 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
505 | }
|
---|
506 | }
|
---|
507 |
|
---|
508 |
|
---|
509 |
|
---|
510 | //++
|
---|
511 | // Titre Gestion de la liste des objets
|
---|
512 | //--
|
---|
513 | //++
|
---|
514 | // void AddObj(AnyDataObj* obj, string& nom)
|
---|
515 | // Ajoute l'objet "obj" à la liste, identifié par "nom".
|
---|
516 | // Si un objet de même nom existe, l'ancien objet est renommé en concaténant
|
---|
517 | // un numéro à son nom.
|
---|
518 | // void DelObj(string const& nom, bool fgd=true)
|
---|
519 | // Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
|
---|
520 | // void DelObjects(string const& patt, bool fgd=true)
|
---|
521 | // Supprime l'ensemble des objets dont le nom correspond au patron "patt".
|
---|
522 | // Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
|
---|
523 | // AnyDataObj* GetObj(string const& nom)
|
---|
524 | // Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
|
---|
525 | // pas dans la liste.
|
---|
526 | // void RenameObj(string const& nom, string& nomnew)
|
---|
527 | // Change le nom d'un objet dans la liste.
|
---|
528 | // void CopyObj(string const& nom, string& nomcp)
|
---|
529 | // Copy l'objet "nom" de la liste dans l'objet "nomcp" de la liste.
|
---|
530 | //--
|
---|
531 |
|
---|
532 | /* --Methode-- */
|
---|
533 | bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
|
---|
534 | {
|
---|
535 | ZSync(*myMutex);
|
---|
536 | return AddObj_P(obj, nom, crd);
|
---|
537 | }
|
---|
538 |
|
---|
539 | /* --Methode-- */
|
---|
540 | bool NamedObjMgr::AddObj_P(AnyDataObj* obj, string & nom, bool crd)
|
---|
541 | {
|
---|
542 |
|
---|
543 | if (obj == NULL) return(false);
|
---|
544 | // On verifie si l'objet est deja dans la liste
|
---|
545 | NObjList::iterator it;
|
---|
546 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
547 | if ((*it).second.obj == obj) {
|
---|
548 | cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
|
---|
549 | return(false);
|
---|
550 | }
|
---|
551 | }
|
---|
552 | string nobj;
|
---|
553 | string nrep;
|
---|
554 | char buff[32];
|
---|
555 | int did = ParseObjectName(nom, nrep, nobj);
|
---|
556 | if (did == 0) {
|
---|
557 | if (!crd) {
|
---|
558 | cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
|
---|
559 | return(false);
|
---|
560 | }
|
---|
561 | else { CreateDir_P(nrep); did = myDirId; }
|
---|
562 | }
|
---|
563 |
|
---|
564 | // Si c'est le repertoire /autoc, on nettoie
|
---|
565 | if (nrep == "autoc") {
|
---|
566 | CleanDir_P(nrep);
|
---|
567 | }
|
---|
568 |
|
---|
569 | myNObj++;
|
---|
570 | if ((nobj.length() < 1) || (! isalpha(nobj[0]) ) ) {
|
---|
571 | cout << "NamedObjMgr::AddObj() bad object name " << nobj ;
|
---|
572 | sprintf(buff,"O%d", myNObj);
|
---|
573 | nobj = buff;
|
---|
574 | cout << " changed to " << nobj << endl;
|
---|
575 | }
|
---|
576 |
|
---|
577 | nom = '/' + nrep + '/' + nobj;
|
---|
578 | NObjDirList::iterator itr = myDirs->find(nrep);
|
---|
579 | if ((*itr).second.lock) {
|
---|
580 | cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
|
---|
581 | return(false);
|
---|
582 | }
|
---|
583 | it = myObjs->find(nom);
|
---|
584 | if (it != myObjs->end()) { // l'objet existe deja
|
---|
585 | if (nrep == "autoc") { // Dans /autoc , on garde les objets affiches, donc del. par Clean
|
---|
586 | sprintf(buff, "%d", (*it).second.oid);
|
---|
587 | string nomnew = "/autoc/" + nobj + buff;
|
---|
588 | RenameObj_P(nom, nomnew);
|
---|
589 | }
|
---|
590 | else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
|
---|
591 | string on,od;
|
---|
592 | // ParseObjectName((*it).first, od, on);
|
---|
593 | sprintf(buff, "%d", (*it).second.oid);
|
---|
594 | string nomnew = "/old/" + nobj + buff;
|
---|
595 | RenameObj_P(nom, nomnew);
|
---|
596 | }
|
---|
597 | else { // Sinon, on remplace l'objet
|
---|
598 | cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
|
---|
599 | DelObj_P(nom);
|
---|
600 | }
|
---|
601 | }
|
---|
602 |
|
---|
603 | nobj_item no;
|
---|
604 | no.obj = obj;
|
---|
605 | no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
|
---|
606 | no.oid = myNObj;
|
---|
607 | no.dirid = did;
|
---|
608 | (*myObjs)[nom] = no;
|
---|
609 |
|
---|
610 | (*itr).second.nobj++;
|
---|
611 |
|
---|
612 | if (myImgApp != NULL) {
|
---|
613 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
614 | if ( (myImgApp->ObjMgrW())->Visible() ) {
|
---|
615 | string oln = nobj + " (T= " + no.obja->GetDataObjType() + ")" ;
|
---|
616 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
|
---|
617 | }
|
---|
618 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
619 | }
|
---|
620 | if (verbeux) cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
|
---|
621 | << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
|
---|
622 | return(true);
|
---|
623 | }
|
---|
624 |
|
---|
625 | bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
|
---|
626 | {
|
---|
627 | ZSync(*myMutex);
|
---|
628 | NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
|
---|
629 | if (adap == NULL) {
|
---|
630 | cout << "NamedObjMgr::AddObj() No Adapter ! " << nom << endl;
|
---|
631 | return(false);
|
---|
632 | }
|
---|
633 | AnyDataObj * cloneobj = adap->CloneDataObj(true);
|
---|
634 | delete adap;
|
---|
635 | if (cloneobj == NULL) {
|
---|
636 | cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl;
|
---|
637 | return(false);
|
---|
638 | }
|
---|
639 | return ( AddObj_P(cloneobj , nom, crd) );
|
---|
640 | }
|
---|
641 |
|
---|
642 | /* --Methode-- */
|
---|
643 | bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
|
---|
644 | {
|
---|
645 | ZSync(*myMutex);
|
---|
646 | return RenameObj_P(nom, nomnew);
|
---|
647 | }
|
---|
648 |
|
---|
649 | /* --Methode-- */
|
---|
650 | bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew)
|
---|
651 | {
|
---|
652 | string n1,r1,n2,r2;
|
---|
653 | int dids = ParseObjectName(nom, r1, n1);
|
---|
654 | NObjDirList::iterator itr1 = myDirs->find(r1);
|
---|
655 | int did = ParseObjectName(nomnew, r2, n2);
|
---|
656 | NObjDirList::iterator itr2 = myDirs->find(r2);
|
---|
657 |
|
---|
658 | if (did == 0) {
|
---|
659 | cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
|
---|
660 | return(false);
|
---|
661 | }
|
---|
662 | nom = '/' + r1 + '/' + n1;
|
---|
663 | nomnew = '/' + r2 + '/' + n2;
|
---|
664 | NObjList::iterator it1 = myObjs->find(nom);
|
---|
665 | if (it1 == myObjs->end()) {
|
---|
666 | cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl;
|
---|
667 | return(false);
|
---|
668 | }
|
---|
669 | if ((n2.length() < 1) || (! isalpha(n2[0])) ) {
|
---|
670 | cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
|
---|
671 | return(false);
|
---|
672 | }
|
---|
673 | NObjList::iterator it2 = myObjs->find(nomnew);
|
---|
674 | if (it2 != myObjs->end()) {
|
---|
675 | cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
|
---|
676 | return(false);
|
---|
677 | }
|
---|
678 |
|
---|
679 | if ( (*itr1).second.lock || (*itr2).second.lock ) {
|
---|
680 | cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !"
|
---|
681 | << endl;
|
---|
682 | return(false);
|
---|
683 | }
|
---|
684 |
|
---|
685 |
|
---|
686 | nobj_item no = (*it1).second;
|
---|
687 | no.dirid = did;
|
---|
688 | myObjs->erase(it1);
|
---|
689 | NObjDirList::iterator itr = myDirs->find(r1);
|
---|
690 | (*itr).second.nobj--;
|
---|
691 | (*myObjs)[nomnew] = no;
|
---|
692 | itr = myDirs->find(r2);
|
---|
693 | (*itr).second.nobj++;
|
---|
694 |
|
---|
695 | if (myImgApp != NULL) {
|
---|
696 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
697 | if ( (myImgApp->ObjMgrW())->Visible() ) {
|
---|
698 | (myImgApp->ObjMgrW())->DelObjList(dids, no.oid);
|
---|
699 | string oln = n2 + " (T= " + no.obja->GetDataObjType() + ")" ;
|
---|
700 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
|
---|
701 | }
|
---|
702 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
703 | }
|
---|
704 | if (verbeux)
|
---|
705 | cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
|
---|
706 | return(true);
|
---|
707 | }
|
---|
708 |
|
---|
709 | /* --Methode-- */
|
---|
710 | bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
|
---|
711 | {
|
---|
712 | ZSync(*myMutex);
|
---|
713 | if(nomcp.length()<=0)
|
---|
714 | {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
|
---|
715 | return(false);}
|
---|
716 | NObjMgrAdapter* obnom = GetObjAdapter(nom);
|
---|
717 | if(obnom==NULL)
|
---|
718 | {cout<<"NamedObjMgr::CopyObj() Error - No "<<nom<<" object !"<<endl;
|
---|
719 | return(false);}
|
---|
720 | AnyDataObj* obnomcp = obnom->CloneDataObj();
|
---|
721 | if(obnomcp==NULL) return(false);
|
---|
722 | if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
|
---|
723 | return true;
|
---|
724 | }
|
---|
725 |
|
---|
726 | /* --Methode-- */
|
---|
727 | bool NamedObjMgr::DelObj(string & nom, bool fgd)
|
---|
728 | {
|
---|
729 | ZSync(*myMutex);
|
---|
730 | return DelObj_P(nom, fgd);
|
---|
731 | }
|
---|
732 |
|
---|
733 | /* --Methode-- */
|
---|
734 | bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
|
---|
735 | {
|
---|
736 | string n1,r1;
|
---|
737 | int did = ParseObjectName(nom, r1, n1);
|
---|
738 | nom = '/' + r1 + '/' + n1;
|
---|
739 | NObjList::iterator it = myObjs->find(nom);
|
---|
740 | if (it == myObjs->end()) return(false);
|
---|
741 | NObjDirList::iterator itr = myDirs->find(r1);
|
---|
742 | if ( (*itr).second.lock ) {
|
---|
743 | cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
|
---|
744 | return(false);
|
---|
745 | }
|
---|
746 | list<int>::iterator ii;
|
---|
747 | if (myImgApp) {
|
---|
748 | //DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
|
---|
749 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
750 | bool fglock = (_fgimgapp) ? false : true;
|
---|
751 | if (fglock) myImgApp->LockMutex();
|
---|
752 | for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
|
---|
753 | myImgApp->DelWRsId((*ii));
|
---|
754 | if (fglock) myImgApp->UnlockMutex(true);
|
---|
755 | }
|
---|
756 | delete (*it).second.obja; // destruction de l'adaptateur
|
---|
757 | if (fgd) delete (*it).second.obj;
|
---|
758 |
|
---|
759 | if (myImgApp != NULL) {
|
---|
760 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
761 | if ( (myImgApp->ObjMgrW())->Visible() ) {
|
---|
762 | int olid = (*it).second.oid;
|
---|
763 | (myImgApp->ObjMgrW())->DelObjList(did, olid);
|
---|
764 | }
|
---|
765 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
766 | }
|
---|
767 | myObjs->erase(it);
|
---|
768 | (*itr).second.nobj--;
|
---|
769 |
|
---|
770 |
|
---|
771 | if (!verbeux) return(true);
|
---|
772 | if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
|
---|
773 | else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
|
---|
774 | return(true);
|
---|
775 | }
|
---|
776 |
|
---|
777 | /* --Methode-- */
|
---|
778 | bool NamedObjMgr::DelObj_Id(int oid)
|
---|
779 | {
|
---|
780 | ZSync(*myMutex);
|
---|
781 | NObjList::iterator it;
|
---|
782 | string nom;
|
---|
783 | bool of = false;
|
---|
784 | for(it = myObjs->begin(); it != myObjs->end(); it++)
|
---|
785 | if ( (*it).second.oid == oid ) {
|
---|
786 | of = true; nom = (*it).first;
|
---|
787 | break;
|
---|
788 | }
|
---|
789 | if (of) return(DelObj(nom, true));
|
---|
790 | else return(false);
|
---|
791 | }
|
---|
792 |
|
---|
793 | /* --Methode-- */
|
---|
794 | void NamedObjMgr::DelObjects(string & patt, bool fgd)
|
---|
795 | {
|
---|
796 | ZSync(*myMutex);
|
---|
797 | string n1,r1;
|
---|
798 | ParseObjectName(patt, r1, n1);
|
---|
799 | patt = '/' + r1 + '/' + n1;
|
---|
800 | NObjList::iterator it;
|
---|
801 | list<string> odel;
|
---|
802 | string cn;
|
---|
803 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
804 | cn = (*it).first;
|
---|
805 | if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
|
---|
806 | }
|
---|
807 | list<string>::iterator ii;
|
---|
808 | for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii, fgd);
|
---|
809 | }
|
---|
810 |
|
---|
811 | /* --Methode-- */
|
---|
812 | AnyDataObj* NamedObjMgr::GetObj(string & nom)
|
---|
813 | {
|
---|
814 | ZSync(*myMutex);
|
---|
815 | string n1,r1;
|
---|
816 | ParseObjectName(nom, r1, n1);
|
---|
817 | nom = '/' + r1 + '/' + n1;
|
---|
818 | NObjList::iterator it = myObjs->find(nom);
|
---|
819 | if (it == myObjs->end()) return(NULL);
|
---|
820 | return((*it).second.obj);
|
---|
821 | }
|
---|
822 |
|
---|
823 | /* --Methode-- */
|
---|
824 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
|
---|
825 | {
|
---|
826 | ZSync(*myMutex);
|
---|
827 | string n1,r1;
|
---|
828 | ParseObjectName(nom, r1, n1);
|
---|
829 | nom = '/' + r1 + '/' + n1;
|
---|
830 | NObjList::iterator it = myObjs->find(nom);
|
---|
831 | if (it == myObjs->end()) return(NULL);
|
---|
832 | return((*it).second.obja);
|
---|
833 | }
|
---|
834 |
|
---|
835 | /* --Methode-- */
|
---|
836 | void NamedObjMgr::ListObjs(string & patt)
|
---|
837 | {
|
---|
838 | ZSync(*myMutex);
|
---|
839 | int k;
|
---|
840 | AnyDataObj* obj=NULL;
|
---|
841 | string ctyp;
|
---|
842 | char strg[256];
|
---|
843 |
|
---|
844 | string n1,r1;
|
---|
845 | ParseObjectName(patt, r1, n1);
|
---|
846 | patt = '/' + r1 + '/' + n1;
|
---|
847 | cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
|
---|
848 | NObjList::iterator it; k = 0;
|
---|
849 | string cn;
|
---|
850 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
851 | cn = (*it).first;
|
---|
852 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
853 | obj = (*it).second.obj;
|
---|
854 | ctyp = typeid(*obj).name();
|
---|
855 | sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
|
---|
856 | ctyp = strg;
|
---|
857 | cout << ctyp << "\n" ;
|
---|
858 | k++;
|
---|
859 | }
|
---|
860 | cout << endl;
|
---|
861 | return;
|
---|
862 | }
|
---|
863 |
|
---|
864 | /* --Methode-- */
|
---|
865 | void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
|
---|
866 | {
|
---|
867 | ZSync(*myMutex);
|
---|
868 | string n1,r1;
|
---|
869 | if (patt.length() < 1) return;
|
---|
870 | bool fgr = (patt[0] == '/') ? true : false;
|
---|
871 | ParseObjectName(patt, r1, n1);
|
---|
872 | patt = '/' + r1 + '/' + n1;
|
---|
873 | NObjList::iterator it;
|
---|
874 | string cn;
|
---|
875 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
876 | cn = (*it).first;
|
---|
877 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
878 | if (fgr) lst.push_back(cn);
|
---|
879 | else {
|
---|
880 | ParseObjectName(cn, r1, n1);
|
---|
881 | lst.push_back(n1);
|
---|
882 | }
|
---|
883 | }
|
---|
884 | }
|
---|
885 |
|
---|
886 | //++
|
---|
887 | // Titre Entrées-Sorties (I/O) sur les objets
|
---|
888 | //--
|
---|
889 | //++
|
---|
890 | // void ReadObj(PInPersist& s, int num=-1)
|
---|
891 | // Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
|
---|
892 | // et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
|
---|
893 | // sur le flot "s" sont créés et ajoutés à la liste.
|
---|
894 | // void ReadObj(string const & nomppf, string nobj="")
|
---|
895 | // Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
|
---|
896 | // à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
|
---|
897 | // composé à partir du nom de fichier.
|
---|
898 | //--
|
---|
899 |
|
---|
900 | /* --Methode-- */
|
---|
901 | void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
|
---|
902 | {
|
---|
903 | ZSync(*myMutex);
|
---|
904 | PPersist* ppobj=NULL;
|
---|
905 | bool ok = true;
|
---|
906 | #ifdef SANS_EVOLPLANCK
|
---|
907 | TRY{
|
---|
908 | PInPersist pis(flnm);
|
---|
909 | ppobj = PPersistMgr::ReadObject(pis);
|
---|
910 | if (ppobj == NULL) ok = false;
|
---|
911 | } CATCH(merr)
|
---|
912 | { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
|
---|
913 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
914 | #else
|
---|
915 | try {
|
---|
916 | PInPersist pis(flnm);
|
---|
917 | ppobj = pis.ReadObject();
|
---|
918 | }
|
---|
919 | catch (IOExc iox) {
|
---|
920 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
921 | ok = false;
|
---|
922 | }
|
---|
923 | #endif
|
---|
924 | if (!ok) return;
|
---|
925 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
926 | AddObj_P(ppobj->DataObj(), nobj, true);
|
---|
927 | cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
|
---|
928 | return;
|
---|
929 | }
|
---|
930 | /* --Methode-- */
|
---|
931 | void NamedObjMgr::ReadObj(vector<string> & flnm_objname)
|
---|
932 | // flnm_objname[0] = nom du fichier .ppf
|
---|
933 | // flnm_objname[1...] = nom des tags des objects a lire
|
---|
934 | {
|
---|
935 | if(flnm_objname.size()<2) return;
|
---|
936 | ZSync(*myMutex);
|
---|
937 | int nread=0;
|
---|
938 | try {
|
---|
939 | PInPersist pis(flnm_objname[0]);
|
---|
940 | for(int i=1;i<flnm_objname.size();i++) {
|
---|
941 | bool ok = pis.GotoNameTag(flnm_objname[i]);
|
---|
942 | if(!ok) {
|
---|
943 | cout<<"NamedObjMgr::ReadObj(...) Unknown object: "<<flnm_objname[i]<<endl;
|
---|
944 | continue;
|
---|
945 | }
|
---|
946 | PPersist *ppobj = pis.ReadObject();;
|
---|
947 | if(ppobj==NULL) {
|
---|
948 | cout<<"NamedObjMgr::ReadObj(...) impossible to read "<<flnm_objname[i]<<endl;
|
---|
949 | continue;
|
---|
950 | }
|
---|
951 | AddObj_P(ppobj->DataObj(),flnm_objname[i],true);
|
---|
952 | nread++;
|
---|
953 | cout<<"NamedObjMgr::ReadObj(...) object "<<flnm_objname[i]<<" read from file "<<endl;
|
---|
954 | }
|
---|
955 | } catch (IOExc iox) {
|
---|
956 | cerr<<"NamedObjMgr::ReadObj()/Error Exception - Msg= "<<iox.Msg()<<endl;
|
---|
957 | }
|
---|
958 | cout<<nread<<" objects have been read"<<endl;
|
---|
959 | return;
|
---|
960 | }
|
---|
961 |
|
---|
962 | /* --Methode-- */
|
---|
963 | void NamedObjMgr::ReadObj(PInPersist& s, int num)
|
---|
964 | {
|
---|
965 | ZSync(*myMutex);
|
---|
966 | int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
|
---|
967 | #ifdef SANS_EVOLPLANCK
|
---|
968 | int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
|
---|
969 | #endif
|
---|
970 | int n0, n1;
|
---|
971 | bool ok = true;
|
---|
972 | PPersist* obj=NULL;
|
---|
973 | string nom;
|
---|
974 |
|
---|
975 | int nread = 0;
|
---|
976 | int nbtags = 0;
|
---|
977 | #ifdef SANS_EVOLPLANCK
|
---|
978 | nbtags = s.NbTags();
|
---|
979 | #else
|
---|
980 | nbtags = s.NbNameTags();
|
---|
981 | #endif
|
---|
982 | if ( (nbtags < 1) || (num >= nbtags) ) {
|
---|
983 | if (num >= 0) {
|
---|
984 | cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << " Error! NbTags ="
|
---|
985 | << nbtags << endl;
|
---|
986 | return;
|
---|
987 | }
|
---|
988 |
|
---|
989 | #ifdef SANS_EVOLPLANCK
|
---|
990 | TRY {
|
---|
991 | obj = PPersistMgr::ReadObject(s);
|
---|
992 | if (obj == NULL) ok = false;
|
---|
993 | } CATCH(merr) {
|
---|
994 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
995 | ok = false;
|
---|
996 | } ENDTRY;
|
---|
997 | #else
|
---|
998 | try {
|
---|
999 | obj = s.ReadObject();
|
---|
1000 | }
|
---|
1001 | catch (IOExc iox) {
|
---|
1002 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1003 | ok = false;
|
---|
1004 | }
|
---|
1005 | #endif
|
---|
1006 |
|
---|
1007 | if (!ok) return;
|
---|
1008 | nom = "";
|
---|
1009 | AddObj_P(obj->DataObj(), nom, false);
|
---|
1010 | nread++;
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | if (num < 0) { n0 = 0; n1 = nbtags; }
|
---|
1014 | else { n0 = num; n1 = num+1; }
|
---|
1015 | for(i=n0; i<n1; i++) {
|
---|
1016 | #ifdef SANS_EVOLPLANCK
|
---|
1017 | key = s.TagKey(i, cid, ln);
|
---|
1018 | if (ln <= 0) nom = "";
|
---|
1019 | else nom = s.TagName(i);
|
---|
1020 | s.GotoTag(i);
|
---|
1021 | TRY {
|
---|
1022 | obj = PPersistMgr::ReadObject(s);
|
---|
1023 | if (obj == NULL) ok = false;
|
---|
1024 | } CATCH(merr) {
|
---|
1025 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
1026 | ok = false;
|
---|
1027 | } ENDTRY;
|
---|
1028 | #else
|
---|
1029 | s.GotoNameTagNum(i);
|
---|
1030 | nom = s.GetTagName(i);
|
---|
1031 | try {
|
---|
1032 | obj = s.ReadObject();
|
---|
1033 | }
|
---|
1034 | catch (IOExc iox) {
|
---|
1035 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1036 | ok = false;
|
---|
1037 | }
|
---|
1038 | #endif
|
---|
1039 | if (ok) { AddObj_P(obj->DataObj(), nom, true); nread++; }
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
|
---|
1043 | return;
|
---|
1044 | }
|
---|
1045 | /* --Methode-- */
|
---|
1046 | void NamedObjMgr::ReadAll(string const & flnm)
|
---|
1047 | {
|
---|
1048 | ZSync(*myMutex);
|
---|
1049 | bool ok = true;
|
---|
1050 | PPersist* obj=NULL;
|
---|
1051 |
|
---|
1052 | PInPersist* ppin=NULL;
|
---|
1053 | #ifdef SANS_EVOLPLANCK
|
---|
1054 | TRY{
|
---|
1055 | ppin = new PInPersist(flnm);
|
---|
1056 | if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
|
---|
1057 | else obj = NULL;
|
---|
1058 | } CATCH(merr)
|
---|
1059 | { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
|
---|
1060 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
1061 | #else
|
---|
1062 | try {
|
---|
1063 | ppin = new PInPersist(flnm);
|
---|
1064 | if (ppin->NbNameTags() < 1) obj = ppin->ReadObject();
|
---|
1065 | else obj = NULL;
|
---|
1066 | }
|
---|
1067 | catch (IOExc iox) {
|
---|
1068 | cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1069 | ok = false;
|
---|
1070 | }
|
---|
1071 | #endif
|
---|
1072 | if (!ok) return;
|
---|
1073 | if (obj) {
|
---|
1074 | string nom = servnobjm->FileName2Name(flnm);
|
---|
1075 | AddObj_P(obj->DataObj(), nom, false);
|
---|
1076 | }
|
---|
1077 | else ReadObj((*ppin), -1);
|
---|
1078 | delete ppin;
|
---|
1079 | return;
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | /* --Methode-- */
|
---|
1083 | void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
|
---|
1084 | {
|
---|
1085 | ZSync(*myMutex);
|
---|
1086 | #ifdef SANS_EVOLPLANCK
|
---|
1087 | bool ok = false;
|
---|
1088 | RzImage* obj=NULL;
|
---|
1089 | TRY{
|
---|
1090 | obj = RzReadFits((char*)flnm.c_str());
|
---|
1091 | if (obj == NULL) ok = false;
|
---|
1092 | else ok = true;
|
---|
1093 | } CATCH(merr) {
|
---|
1094 | printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
1095 | ok = false;
|
---|
1096 | } ENDTRY;
|
---|
1097 |
|
---|
1098 | if (ok && (obj != NULL)) {
|
---|
1099 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
1100 | AddObj_P((AnyDataObj*)obj, nobj);
|
---|
1101 | }
|
---|
1102 | #else
|
---|
1103 | try {
|
---|
1104 | FITS_AutoReader fiar(flnm);
|
---|
1105 | char bun[16];
|
---|
1106 | int nhdu = fiar.NbBlocks();
|
---|
1107 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
1108 | string name;
|
---|
1109 | AnyDataObj* obj;
|
---|
1110 | int kon = 1;
|
---|
1111 | for(int k=1; k<=nhdu; k++) {
|
---|
1112 | obj = fiar.ReadObject(k);
|
---|
1113 | if (obj) {
|
---|
1114 | cout << " NamedObjMgr::ReadFits() " << (string)typeid(*obj).name()
|
---|
1115 | << " read From HDU " << k << endl;
|
---|
1116 | if (typeid(*obj) == typeid(DVList)) {
|
---|
1117 | delete obj;
|
---|
1118 | continue;
|
---|
1119 | }
|
---|
1120 | if (kon > 1) {
|
---|
1121 | sprintf(bun, "%d", kon);
|
---|
1122 | name = nobj + bun;
|
---|
1123 | }
|
---|
1124 | else name = nobj;
|
---|
1125 | AddObj_P(obj, name, false);
|
---|
1126 | kon++;
|
---|
1127 | }
|
---|
1128 | else cerr << " NamedObjMgr::ReadFits() NULL pointer from FITS_AutoReader" << endl;
|
---|
1129 | }
|
---|
1130 | }
|
---|
1131 | catch(PThrowable & exc) {
|
---|
1132 | cerr << " NamedObjMgr::ReadFits() / Error - Catched Exception \n "
|
---|
1133 | << " Type= " << (string)typeid(exc).name()
|
---|
1134 | << " - Msg= " << exc.Msg() << endl;
|
---|
1135 |
|
---|
1136 | }
|
---|
1137 | #endif
|
---|
1138 |
|
---|
1139 | return;
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | /* --Methode-- */
|
---|
1143 | void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
|
---|
1144 | {
|
---|
1145 | ZSync(*myMutex);
|
---|
1146 | SaveObj_P(nom, s, keeppath);
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | static int key_for_write = 5000;
|
---|
1150 | /* --Methode-- */
|
---|
1151 | void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
|
---|
1152 | {
|
---|
1153 | if (nom.length() < 1) return;
|
---|
1154 | string nob,rep;
|
---|
1155 | ParseObjectName(nom, rep, nob);
|
---|
1156 | nom = '/' + rep + '/' + nob;
|
---|
1157 | NObjMgrAdapter* obja=NULL;
|
---|
1158 | string nomf = (keeppath) ? nom : nob;
|
---|
1159 | obja = GetObjAdapter(nom);
|
---|
1160 | if (obja == NULL) return;
|
---|
1161 | printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
|
---|
1162 | nom.c_str(), typeid(*(obja->GetDataObj())).name());
|
---|
1163 | obja->SavePPF(s, nomf);
|
---|
1164 | return;
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | /* --Methode-- */
|
---|
1168 | void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
|
---|
1169 | {
|
---|
1170 | ZSync(*myMutex);
|
---|
1171 | string n1,r1;
|
---|
1172 | if (patt.length() < 1) return;
|
---|
1173 | bool keeppath = (patt[0] == '/') ? true : false;
|
---|
1174 | ParseObjectName(patt, r1, n1);
|
---|
1175 | patt = '/' + r1 + '/' + n1;
|
---|
1176 |
|
---|
1177 | bool ok = true;
|
---|
1178 | POutPersist* pout=NULL;
|
---|
1179 | #ifdef SANS_EVOLPLANCK
|
---|
1180 | TRY{
|
---|
1181 | pout = new POutPersist(flnm);
|
---|
1182 | } CATCH(merr)
|
---|
1183 | { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
|
---|
1184 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
1185 | #else
|
---|
1186 | try {
|
---|
1187 | pout = new POutPersist(flnm);
|
---|
1188 | }
|
---|
1189 | catch (IOExc iox) {
|
---|
1190 | cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1191 | ok = false;
|
---|
1192 | }
|
---|
1193 | #endif
|
---|
1194 | if (!ok) return;
|
---|
1195 | NObjList::iterator it;
|
---|
1196 | string cn;
|
---|
1197 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
1198 | cn = (*it).first;
|
---|
1199 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
1200 | SaveObj_P(cn, (*pout), keeppath);
|
---|
1201 | }
|
---|
1202 | delete pout;
|
---|
1203 | return;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | /* --Methode-- */
|
---|
1207 | void NamedObjMgr::SaveAll(string const& flnm)
|
---|
1208 | {
|
---|
1209 | ZSync(*myMutex);
|
---|
1210 | bool ok = true;
|
---|
1211 |
|
---|
1212 | POutPersist* pout=NULL;
|
---|
1213 | #ifdef SANS_EVOLPLANCK
|
---|
1214 | TRY{
|
---|
1215 | pout = new POutPersist(flnm);
|
---|
1216 | } CATCH(merr)
|
---|
1217 | { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
|
---|
1218 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
1219 | #else
|
---|
1220 | try {
|
---|
1221 | pout = new POutPersist(flnm);
|
---|
1222 | }
|
---|
1223 | catch (IOExc iox) {
|
---|
1224 | cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1225 | ok = false;
|
---|
1226 | }
|
---|
1227 | #endif
|
---|
1228 | if (!ok) return;
|
---|
1229 | NObjList::iterator it;
|
---|
1230 | string no;
|
---|
1231 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
1232 | no = (*it).first;
|
---|
1233 | SaveObj_P(no, (*pout), true);
|
---|
1234 | }
|
---|
1235 | delete pout;
|
---|
1236 | return;
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | /* --Methode-- */
|
---|
1240 | void NamedObjMgr::SaveFits(string& nom, string const & flnm)
|
---|
1241 | {
|
---|
1242 | ZSync(*myMutex);
|
---|
1243 |
|
---|
1244 | NObjMgrAdapter* obja=NULL;
|
---|
1245 | obja = GetObjAdapter(nom);
|
---|
1246 | if (obja == NULL) return;
|
---|
1247 | obja->SaveFits(flnm);
|
---|
1248 | return;
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 |
|
---|
1252 |
|
---|
1253 | /* --Methode-- */
|
---|
1254 | void NamedObjMgr::PrintObj(string& nom)
|
---|
1255 | {
|
---|
1256 | ZSync(*myMutex);
|
---|
1257 | NObjMgrAdapter* obja=NULL;
|
---|
1258 | obja = GetObjAdapter(nom);
|
---|
1259 | if (obja == NULL) return;
|
---|
1260 | AnyDataObj* ob = obja->GetDataObj();
|
---|
1261 | if (ob == NULL) {
|
---|
1262 | cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl;
|
---|
1263 | return;
|
---|
1264 | }
|
---|
1265 | string ctyp = typeid(*ob).name();
|
---|
1266 | cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
|
---|
1267 | obja->Print(cout);
|
---|
1268 |
|
---|
1269 | return;
|
---|
1270 | }
|
---|
1271 |
|
---|
1272 | /* --Methode-- */
|
---|
1273 | void NamedObjMgr::DisplayObj(string& nom, string dopt)
|
---|
1274 | {
|
---|
1275 | ZSync(*myMutex);
|
---|
1276 |
|
---|
1277 | NObjMgrAdapter* obja=NULL;
|
---|
1278 | obja = GetObjAdapter(nom);
|
---|
1279 | if (obja == NULL) {
|
---|
1280 | cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
|
---|
1281 | return;
|
---|
1282 | }
|
---|
1283 | if (obja->GetDataObj() == NULL) {
|
---|
1284 | cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
|
---|
1285 | return;
|
---|
1286 | }
|
---|
1287 | if (!myImgApp) return;
|
---|
1288 |
|
---|
1289 | PIDrawer * dr = NULL;
|
---|
1290 | P2DArrayAdapter* arr = NULL;
|
---|
1291 | dr = obja->GetDrawer(dopt);
|
---|
1292 | if (!dr) arr = obja->Get2DArray(dopt);
|
---|
1293 |
|
---|
1294 | if (!dr && !arr) {
|
---|
1295 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1296 | cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
|
---|
1297 | return;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | int wrsid = 0;
|
---|
1301 |
|
---|
1302 | string n1,r1;
|
---|
1303 | ParseObjectName(nom, r1, n1);
|
---|
1304 |
|
---|
1305 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1306 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1307 |
|
---|
1308 | if (dr) {
|
---|
1309 | PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
|
---|
1310 | if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock);
|
---|
1311 | else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock);
|
---|
1312 | }
|
---|
1313 | else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, false, 0, fglock);
|
---|
1314 |
|
---|
1315 | AddWRsId(nom, wrsid);
|
---|
1316 | return;
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | /* --Methode-- */
|
---|
1320 | void NamedObjMgr::DisplayImage(string& nom, string dopt, bool fgimagnav)
|
---|
1321 | {
|
---|
1322 | ZSync(*myMutex);
|
---|
1323 |
|
---|
1324 | NObjMgrAdapter* obja=NULL;
|
---|
1325 | obja = GetObjAdapter(nom);
|
---|
1326 | if (obja == NULL) {
|
---|
1327 | cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
|
---|
1328 | return;
|
---|
1329 | }
|
---|
1330 | if (obja->GetDataObj() == NULL) {
|
---|
1331 | cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
|
---|
1332 | return;
|
---|
1333 | }
|
---|
1334 | if (!myImgApp) return;
|
---|
1335 |
|
---|
1336 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
1337 |
|
---|
1338 | if (!arr) {
|
---|
1339 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1340 | cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
|
---|
1341 | return;
|
---|
1342 | }
|
---|
1343 |
|
---|
1344 | string n1,r1;
|
---|
1345 | ParseObjectName(nom, r1, n1);
|
---|
1346 |
|
---|
1347 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1348 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1349 |
|
---|
1350 | int wrsid = 0;
|
---|
1351 | wrsid = myImgApp->DispImage(arr, n1, dopt, fgimagnav, 0, fglock);
|
---|
1352 |
|
---|
1353 | AddWRsId(nom, wrsid);
|
---|
1354 | return;
|
---|
1355 | }
|
---|
1356 | /* --Methode-- */
|
---|
1357 | void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
|
---|
1358 | {
|
---|
1359 | ZSync(*myMutex);
|
---|
1360 |
|
---|
1361 | NObjMgrAdapter* obja=NULL;
|
---|
1362 | obja = GetObjAdapter(nom);
|
---|
1363 | if (obja == NULL) {
|
---|
1364 | cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
|
---|
1365 | return;
|
---|
1366 | }
|
---|
1367 | if (obja->GetDataObj() == NULL) {
|
---|
1368 | cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
|
---|
1369 | return;
|
---|
1370 | }
|
---|
1371 | if (!myImgApp) return;
|
---|
1372 |
|
---|
1373 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
1374 |
|
---|
1375 | if (!arr) {
|
---|
1376 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1377 | cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
|
---|
1378 | return;
|
---|
1379 | }
|
---|
1380 |
|
---|
1381 | if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
|
---|
1382 | cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
|
---|
1383 | << "x" << arr->YSize() << ") too big (max=250x250)" << endl;
|
---|
1384 | delete arr;
|
---|
1385 | return;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | string n1,r1;
|
---|
1389 | ParseObjectName(nom, r1, n1);
|
---|
1390 |
|
---|
1391 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1392 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1393 |
|
---|
1394 | int wrsid = 0;
|
---|
1395 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
---|
1396 | wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
|
---|
1397 | AddWRsId(nom, wrsid);
|
---|
1398 | return;
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | /* --Methode-- */
|
---|
1402 | void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
|
---|
1403 | string& erx, string& ery, string& erz, string& wt,
|
---|
1404 | string& label, string dopt, bool fg3d)
|
---|
1405 | {
|
---|
1406 | ZSync(*myMutex);
|
---|
1407 |
|
---|
1408 | AnyDataObj* obj=GetObj(nom);
|
---|
1409 | if (obj == NULL) {
|
---|
1410 | cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
|
---|
1411 | return;
|
---|
1412 | }
|
---|
1413 | if (!myImgApp) return;
|
---|
1414 |
|
---|
1415 | NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
|
---|
1416 | if (nt == NULL) {
|
---|
1417 | // if (typeid(*obj) != typeid(NTupleInterface)) {
|
---|
1418 | string ctyp = typeid(*obj).name();
|
---|
1419 | cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl;
|
---|
1420 | return;
|
---|
1421 | }
|
---|
1422 |
|
---|
1423 | int wrsid = 0;
|
---|
1424 | dopt = "defline " + dopt;
|
---|
1425 |
|
---|
1426 | string n1,r1;
|
---|
1427 | ParseObjectName(nom, r1, n1);
|
---|
1428 |
|
---|
1429 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1430 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1431 |
|
---|
1432 | if ( fg3d && (nmz.length()>0) ) { // Display 3D
|
---|
1433 | PINTuple3D* pin = new PINTuple3D(nt, false);
|
---|
1434 | pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
|
---|
1435 | pin->SelectWt(wt.c_str());
|
---|
1436 | pin->SelectLabel(label.c_str());
|
---|
1437 | pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
|
---|
1438 | string titre = nmz + "%" + nmy + "%" + nmz;
|
---|
1439 | wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock);
|
---|
1440 | }
|
---|
1441 | else {
|
---|
1442 | PINTuple* pin = new PINTuple(nt, false);
|
---|
1443 | pin->SelectXY(nmx.c_str(), nmy.c_str());
|
---|
1444 | pin->SelectWt(wt.c_str());
|
---|
1445 | pin->SelectLabel(label.c_str());
|
---|
1446 | pin->SelectErrBar(erx.c_str(), ery.c_str());
|
---|
1447 | string titre = nmy + "%" + nmx;
|
---|
1448 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock);
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 | AddWRsId(nom, wrsid);
|
---|
1452 | return;
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 | /* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
|
---|
1456 | void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
|
---|
1457 | // Pour le display 2D ou 3D d'un ``GeneralFitData''.
|
---|
1458 | //| nom = nom de l'objet GeneralFitData a representer.
|
---|
1459 | //| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
|
---|
1460 | //| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
|
---|
1461 | //| Pour le display 2D, numvary="" string vide.
|
---|
1462 | //| err = qu'elles erreurs faut il representer ?
|
---|
1463 | //| - 2D : x y xy (display y=f(x))
|
---|
1464 | //| - 3D : x y z xy xz yz xzy (display z=f(x,y))
|
---|
1465 | //| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
|
---|
1466 | //| les barres d'erreurs sont representees.
|
---|
1467 | //| opt = options generales pour le display.
|
---|
1468 | {
|
---|
1469 | ZSync(*myMutex);
|
---|
1470 |
|
---|
1471 | AnyDataObj* obj=GetObj(nom);
|
---|
1472 | if(obj == NULL)
|
---|
1473 | {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
|
---|
1474 | return;}
|
---|
1475 | if(!myImgApp) return;
|
---|
1476 | if(typeid(*obj) != typeid(GeneralFitData))
|
---|
1477 | {string ctyp = typeid(*obj).name();
|
---|
1478 | cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl;
|
---|
1479 | return;}
|
---|
1480 |
|
---|
1481 | // Decodage des erreurs a representer
|
---|
1482 | bool errx=false, erry=false, errz=false;
|
---|
1483 | if(err.length()>0) {
|
---|
1484 | for(int i=0;i<(int_4)err.length();i++)
|
---|
1485 | if (err[i]=='x' || err[i]=='X') errx = true;
|
---|
1486 | else if(err[i]=='y' || err[i]=='Y') erry = true;
|
---|
1487 | else if(err[i]=='z' || err[i]=='Z') errz = true;
|
---|
1488 | }
|
---|
1489 | // Decodage des numeros de variables en abscisse
|
---|
1490 | int numvx=-1, numvy=-1;
|
---|
1491 | if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
|
---|
1492 | if(numvary.length()>0) numvy = atoi(numvary.c_str());
|
---|
1493 |
|
---|
1494 | string n1,r1;
|
---|
1495 | ParseObjectName(nom, r1, n1);
|
---|
1496 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1497 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1498 |
|
---|
1499 | int wrsid = 0;
|
---|
1500 | if(numvy>=0) { // display 3D
|
---|
1501 | PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
|
---|
1502 | pigfd->SelectXY(numvx,numvy);
|
---|
1503 | pigfd->SelectErrBar(errx,erry,errz);
|
---|
1504 | wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock);
|
---|
1505 | } else { // display 2D
|
---|
1506 | PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
|
---|
1507 | pigfd->SelectX(numvx);
|
---|
1508 | pigfd->SelectErrBar(errx,erry);
|
---|
1509 | wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock);
|
---|
1510 | }
|
---|
1511 |
|
---|
1512 | AddWRsId(nom, wrsid);
|
---|
1513 |
|
---|
1514 | return;
|
---|
1515 | }
|
---|
1516 |
|
---|
1517 | /* --Methode-- */
|
---|
1518 | void NamedObjMgr::DisplayVector(string & nomvx, string& nomvy, string dopt)
|
---|
1519 | // Pour l'affichage 2-D de points avec coordonnees definies par deux vecteurs
|
---|
1520 | // nomvx et nomvy
|
---|
1521 | {
|
---|
1522 | ZSync(*myMutex);
|
---|
1523 |
|
---|
1524 | #ifdef SANS_EVOLPLANCK
|
---|
1525 | cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
|
---|
1526 | #else
|
---|
1527 |
|
---|
1528 | if(!myImgApp) return;
|
---|
1529 |
|
---|
1530 | AnyDataObj* obj;
|
---|
1531 | obj = GetObj(nomvx);
|
---|
1532 | if(obj == NULL) {
|
---|
1533 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl;
|
---|
1534 | return;
|
---|
1535 | }
|
---|
1536 | //Vector * vx = dynamic_cast<Vector *>(obj);
|
---|
1537 | BaseArray* bax = dynamic_cast<BaseArray *>(obj);
|
---|
1538 | if (bax == NULL) {
|
---|
1539 | cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl;
|
---|
1540 | return;
|
---|
1541 | }
|
---|
1542 |
|
---|
1543 | obj = GetObj(nomvy);
|
---|
1544 | if(obj == NULL) {
|
---|
1545 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
|
---|
1546 | return;
|
---|
1547 | }
|
---|
1548 | BaseArray* bay = dynamic_cast<BaseArray *>(obj);
|
---|
1549 | if (bay == NULL) {
|
---|
1550 | cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
|
---|
1551 | return;
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | Vector vx = *bax;
|
---|
1555 | Vector vy = *bay;
|
---|
1556 | Vector * cvx, * cvy;
|
---|
1557 |
|
---|
1558 | if (vx.Size() != vy.Size()) {
|
---|
1559 | cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl;
|
---|
1560 | if (vx.Size() < vy.Size()) {
|
---|
1561 | cvx = new Vector(vx);
|
---|
1562 | cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1)));
|
---|
1563 | }
|
---|
1564 | else {
|
---|
1565 | cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1)));
|
---|
1566 | cvy = new Vector(vy);
|
---|
1567 | }
|
---|
1568 | }
|
---|
1569 | else {
|
---|
1570 | cvx = new Vector(vx);
|
---|
1571 | cvy = new Vector(vy);
|
---|
1572 | }
|
---|
1573 |
|
---|
1574 | POVectorAdapter * avx = new POVectorAdapter(cvx, true);
|
---|
1575 | POVectorAdapter * avy = new POVectorAdapter(cvy, true);
|
---|
1576 | PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true);
|
---|
1577 |
|
---|
1578 | string nx,rx;
|
---|
1579 | ParseObjectName(nomvx, rx, nx);
|
---|
1580 | string ny,ry;
|
---|
1581 | ParseObjectName(nomvy, ry, ny);
|
---|
1582 |
|
---|
1583 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1584 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1585 |
|
---|
1586 | string title = ny + " (Y) vs. " + nx + " (X)";
|
---|
1587 | // display 2D
|
---|
1588 | myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
|
---|
1589 |
|
---|
1590 | return;
|
---|
1591 |
|
---|
1592 | #endif
|
---|
1593 | }
|
---|
1594 |
|
---|
1595 | /* --Methode--
|
---|
1596 | void NamedObjMgr::DisplayImage(string& nom, string dopt)
|
---|
1597 | {
|
---|
1598 | cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
|
---|
1599 | }
|
---|
1600 | */
|
---|
1601 |
|
---|
1602 |
|
---|
1603 |
|
---|
1604 |
|
---|
1605 | /* --Methode--
|
---|
1606 | void NamedObjMgr::SetGraphicAttributes(string gratt)
|
---|
1607 | {
|
---|
1608 | bool fg = false;
|
---|
1609 | servnobjm->DecodeDispOption(gratt, fg);
|
---|
1610 | Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
|
---|
1611 | }
|
---|
1612 |
|
---|
1613 | void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
|
---|
1614 | {
|
---|
1615 | if (!myImgApp) return;
|
---|
1616 | if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
|
---|
1617 | else myImgApp->SetZone(nzx, nzy);
|
---|
1618 | }
|
---|
1619 | */
|
---|
1620 |
|
---|
1621 | /* --Methode-- */
|
---|
1622 | void NamedObjMgr::AddWRsId(string & nom, int wrsid)
|
---|
1623 | {
|
---|
1624 | if(wrsid != 0) {
|
---|
1625 | NObjList::iterator it = myObjs->find(nom);
|
---|
1626 | if (it == myObjs->end()) return;
|
---|
1627 | (*it).second.wrsid.push_back(wrsid);
|
---|
1628 | }
|
---|
1629 | return;
|
---|
1630 | }
|
---|
1631 |
|
---|
1632 | /* --Methode-- */
|
---|
1633 | void NamedObjMgr::UpdateObjMgrWindow(int did)
|
---|
1634 | {
|
---|
1635 | if (!myImgApp) return;
|
---|
1636 | ZSync(*myMutex);
|
---|
1637 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
1638 |
|
---|
1639 | (myImgApp->ObjMgrW())->ClearObjList();
|
---|
1640 |
|
---|
1641 | NObjList::iterator it;
|
---|
1642 | string cn;
|
---|
1643 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
1644 | if ((*it).second.dirid != did) continue;
|
---|
1645 | cn = (*it).first.substr(1);
|
---|
1646 | // cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ;
|
---|
1647 | cn = cn.substr(cn.find('/')+1) + " (T= " + (*it).second.obja->GetDataObjType() + ")" ;
|
---|
1648 | (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
|
---|
1649 | }
|
---|
1650 |
|
---|
1651 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 |
|
---|
1655 | /* Nouvelle-Fonction */
|
---|
1656 | void NamedObjMgr::RemoveSpacesFromName(string & nom)
|
---|
1657 | {
|
---|
1658 | // on supprime les blancs de debut et de fin
|
---|
1659 | size_t p = nom.find_first_not_of(" ");
|
---|
1660 | if(p>nom.length()) { nom = ""; return; }
|
---|
1661 | nom = nom.substr(p);
|
---|
1662 | p = nom.find(' ');
|
---|
1663 | if(p>nom.length()) p=nom.length();
|
---|
1664 | nom = nom.substr(0, p);
|
---|
1665 | }
|
---|
1666 |
|
---|
1667 | /* Nouvelle-Fonction */
|
---|
1668 | bool NamedObjMgr::CheckDirName(string & nom)
|
---|
1669 | {
|
---|
1670 | RemoveSpacesFromName(nom);
|
---|
1671 | if (nom.length() < 1) return(false);
|
---|
1672 | if (nom[0] == '/') nom = nom.substr(1) ;
|
---|
1673 | size_t p = nom.find('/');
|
---|
1674 | if (p < nom.length()) nom = nom.substr(0,p);
|
---|
1675 | if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
|
---|
1676 | return(true);
|
---|
1677 | }
|
---|
1678 |
|
---|
1679 | /* Nouvelle-Fonction */
|
---|
1680 | int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
|
---|
1681 | {
|
---|
1682 | RemoveSpacesFromName(nom);
|
---|
1683 | // Si le nom ne commence pas par un slash, c'est le repertoire courant
|
---|
1684 | if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
|
---|
1685 | else {
|
---|
1686 | string xx = nom.substr(1);
|
---|
1687 | size_t p = xx.find('/');
|
---|
1688 | if (p < xx.length()) {
|
---|
1689 | nomrep = xx.substr(0,p);
|
---|
1690 | nomobj = xx.substr(p+1);
|
---|
1691 | }
|
---|
1692 | else {
|
---|
1693 | nomrep = xx;
|
---|
1694 | nomobj = "";
|
---|
1695 | }
|
---|
1696 | }
|
---|
1697 | int rc = 0;
|
---|
1698 | NObjDirList::iterator it = myDirs->find(nomrep);
|
---|
1699 | if (it != myDirs->end()) rc = (*it).second.id;
|
---|
1700 | return(rc);
|
---|
1701 | }
|
---|
1702 |
|
---|