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