1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <ctype.h>
|
---|
4 |
|
---|
5 | #include <typeinfo>
|
---|
6 | #include <iostream>
|
---|
7 | #include <string>
|
---|
8 | #include <list>
|
---|
9 | #include <map>
|
---|
10 |
|
---|
11 | #include "sopnamsp.h"
|
---|
12 | #include "strutil.h"
|
---|
13 | #include "datatypes.h"
|
---|
14 |
|
---|
15 | #include "nobjmgr.h"
|
---|
16 | #include "servnobjm.h"
|
---|
17 | #include "nomgadapter.h"
|
---|
18 | #include "pistdimgapp.h"
|
---|
19 |
|
---|
20 | #include "dvlist.h"
|
---|
21 |
|
---|
22 | // EVOL-PLANCK
|
---|
23 | #ifdef SANS_EVOLPLANCK
|
---|
24 | #include "fitsimage.h"
|
---|
25 | #else
|
---|
26 | #include "tvector.h"
|
---|
27 | #include "pitvmaad.h"
|
---|
28 | #include "piyfxdrw.h"
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #include "pisurfdr.h"
|
---|
32 | #include "pipodrw.h"
|
---|
33 |
|
---|
34 | #include "pintuple.h"
|
---|
35 | #include "pintup3d.h"
|
---|
36 | #include "pigfd1.h"
|
---|
37 | #include "pigfd2.h"
|
---|
38 |
|
---|
39 | #include "zthread.h"
|
---|
40 |
|
---|
41 |
|
---|
42 | //++
|
---|
43 | // Class NamedObjMgr
|
---|
44 | // Lib PI
|
---|
45 | // include nobjmgr.h
|
---|
46 | //
|
---|
47 | // Cette classe fournit les services nécéssaires à la gestion des objets
|
---|
48 | // (l'ensemble des objets PPersist de PEIDA++) au sein du programme
|
---|
49 | // d'analyse interactive *piapp* . Elle constitue en outre l'interface
|
---|
50 | // entre les fonctions utilisateur et l'application graphique.
|
---|
51 | //--
|
---|
52 | //++
|
---|
53 | // Links Voir aussi
|
---|
54 | // PIStdImgApp
|
---|
55 | // Services2NObjMgr
|
---|
56 | // PIACmd
|
---|
57 | //--
|
---|
58 |
|
---|
59 |
|
---|
60 | // ..................................................................
|
---|
61 | // ...... Gestion des objets nommes, variables globales ............
|
---|
62 | struct nobj_diritem {
|
---|
63 | int id; // Directory Id
|
---|
64 | int nobj; // Number of objects in directory
|
---|
65 | bool lock; // True -> directory locked, No Add, del or rename
|
---|
66 | bool keepold; // True -> When duplicate object name, old object moved to /old
|
---|
67 | };
|
---|
68 |
|
---|
69 | typedef map<string, nobj_diritem, less<string> > NObjDirList;
|
---|
70 |
|
---|
71 | struct nobj_item {
|
---|
72 | AnyDataObj* obj; // Object pointer
|
---|
73 | NObjMgrAdapter* obja; // Object adapter pointer
|
---|
74 | int oid; // object Id
|
---|
75 | int dirid; // Directory Id
|
---|
76 | list<int> wrsid; // List of Window Resource Id (Drawer, PIBaseWdg, ...)
|
---|
77 | // (for PIStdImgApp)
|
---|
78 | bool operator==(nobj_item const& b) const
|
---|
79 | { return (this->obj == b.obj); }
|
---|
80 | };
|
---|
81 |
|
---|
82 | typedef map<string, nobj_item, less<string> > NObjList;
|
---|
83 |
|
---|
84 | static NObjDirList* myDirs = NULL;
|
---|
85 | static NObjList* myObjs = NULL;
|
---|
86 | static int fgOInit = 0;
|
---|
87 | static int myNObj = 0;
|
---|
88 | static int myDirId = 0;
|
---|
89 | static string* currDir;
|
---|
90 |
|
---|
91 | static PIStdImgApp* myImgApp=NULL;
|
---|
92 | static Services2NObjMgr* servnobjm=NULL;
|
---|
93 |
|
---|
94 | static DVList* myVars = NULL; // Pour stocker les variables
|
---|
95 |
|
---|
96 | static string* TmpDir = NULL; // Repertoire pour les compilations / link dynamique
|
---|
97 |
|
---|
98 | // Pour gestion multithread
|
---|
99 | static ZMutex* myMutex = NULL;
|
---|
100 | // ..................................................................
|
---|
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 | myMutex = new ZMutex;
|
---|
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 | }
|
---|
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 zs(*myMutex); zs.NOp();
|
---|
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 zs(*myMutex); zs.NOp();
|
---|
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 zs(*myMutex); zs.NOp();
|
---|
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 zs(*myMutex); zs.NOp();
|
---|
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 zs(*myMutex); zs.NOp();
|
---|
292 | return(*myVars);
|
---|
293 | }
|
---|
294 |
|
---|
295 | /* --Methode-- */
|
---|
296 | bool NamedObjMgr::CreateDir(string & dirname)
|
---|
297 | {
|
---|
298 | ZSync zs(*myMutex); zs.NOp();
|
---|
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 ) myImgApp->LockMutex();
|
---|
324 | (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
|
---|
325 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
326 | }
|
---|
327 | if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
|
---|
328 | return(true);
|
---|
329 | }
|
---|
330 |
|
---|
331 | /* --Methode-- */
|
---|
332 | bool NamedObjMgr::DeleteDir(string & dirname)
|
---|
333 | {
|
---|
334 | if ( !CheckDirName(dirname) ) {
|
---|
335 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
336 | return(false);
|
---|
337 | }
|
---|
338 | ZSync zs(*myMutex); zs.NOp();
|
---|
339 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
340 | if (it == myDirs->end()) {
|
---|
341 | cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
|
---|
342 | return(false);
|
---|
343 | }
|
---|
344 | if ((*it).second.nobj > 0) {
|
---|
345 | cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
|
---|
346 | return(false);
|
---|
347 | }
|
---|
348 | if ((*it).second.lock ) {
|
---|
349 | cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
|
---|
350 | return(false);
|
---|
351 | }
|
---|
352 | if ((*it).second.id < 50) {
|
---|
353 | cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
|
---|
354 | return(false);
|
---|
355 | }
|
---|
356 |
|
---|
357 | if (myImgApp) {
|
---|
358 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
359 | (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
|
---|
360 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
361 | }
|
---|
362 | myDirs->erase(it);
|
---|
363 | if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
|
---|
364 | return(true);
|
---|
365 | }
|
---|
366 |
|
---|
367 | /* --Methode-- */
|
---|
368 | void NamedObjMgr::LockDir(string & dirname)
|
---|
369 | {
|
---|
370 | ZSync zs(*myMutex); zs.NOp();
|
---|
371 | if ( !CheckDirName(dirname) ) return;
|
---|
372 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
373 | if (it == myDirs->end()) return;
|
---|
374 | (*it).second.lock = true;
|
---|
375 | if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
|
---|
376 | return;
|
---|
377 | }
|
---|
378 |
|
---|
379 | /* --Methode-- */
|
---|
380 | void NamedObjMgr::UnlockDir(string & dirname)
|
---|
381 | {
|
---|
382 | ZSync zs(*myMutex); zs.NOp();
|
---|
383 | if ( !CheckDirName(dirname) ) return;
|
---|
384 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
385 | if (it == myDirs->end()) return;
|
---|
386 | (*it).second.lock = true;
|
---|
387 | if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
|
---|
388 | return;
|
---|
389 | }
|
---|
390 |
|
---|
391 | /* --Methode-- */
|
---|
392 | void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
|
---|
393 | {
|
---|
394 | ZSync zs(*myMutex); zs.NOp();
|
---|
395 | if ( !CheckDirName(dirname) ) return;
|
---|
396 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
397 | if (it == myDirs->end()) return;
|
---|
398 | (*it).second.keepold = keepold;
|
---|
399 | if (!verbeux) return;
|
---|
400 | cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << " -> ";
|
---|
401 | if ( keepold ) cout << " True " << endl;
|
---|
402 | else cout << " False " << endl;
|
---|
403 | return;
|
---|
404 | }
|
---|
405 |
|
---|
406 |
|
---|
407 | /* --Methode-- */
|
---|
408 | bool NamedObjMgr::SetCurrentDir(string & dirname)
|
---|
409 | {
|
---|
410 | ZSync zs(*myMutex); zs.NOp();
|
---|
411 | if ( !CheckDirName(dirname) ) {
|
---|
412 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
413 | return(false);
|
---|
414 | }
|
---|
415 | NObjDirList::iterator it = myDirs->find(dirname);
|
---|
416 | if (it == myDirs->end()) {
|
---|
417 | cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
|
---|
418 | return(false);
|
---|
419 | }
|
---|
420 | *currDir = dirname;
|
---|
421 | if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
|
---|
422 | return(true);
|
---|
423 | }
|
---|
424 |
|
---|
425 | /* --Methode-- */
|
---|
426 | void NamedObjMgr::GetCurrentDir(string & dirname)
|
---|
427 | {
|
---|
428 | ZSync zs(*myMutex); zs.NOp();
|
---|
429 | dirname = *currDir;
|
---|
430 | }
|
---|
431 |
|
---|
432 | /* --Methode-- */
|
---|
433 | void NamedObjMgr::ListDirs(string & patt)
|
---|
434 | {
|
---|
435 | ZSync zs(*myMutex); zs.NOp();
|
---|
436 | NObjDirList::iterator it;
|
---|
437 | string cn;
|
---|
438 | cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl;
|
---|
439 | int k = 0;
|
---|
440 | for(it= myDirs->begin(); it != myDirs->end(); it++) {
|
---|
441 | cn = (*it).first;
|
---|
442 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
443 | k++;
|
---|
444 | cout << k << "- " << (*it).first;
|
---|
445 | if ( (*it).second.lock ) cout << " Locked " ;
|
---|
446 | if ( (*it).second.keepold ) cout << " KeepOld " ;
|
---|
447 | cout << " (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl;
|
---|
448 |
|
---|
449 | }
|
---|
450 | }
|
---|
451 |
|
---|
452 | /* --Methode-- */
|
---|
453 | void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
|
---|
454 | {
|
---|
455 | ZSync zs(*myMutex); zs.NOp();
|
---|
456 | NObjDirList::iterator it;
|
---|
457 | string cn;
|
---|
458 | for(it= myDirs->begin(); it != myDirs->end(); it++) {
|
---|
459 | cn = (*it).first;
|
---|
460 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
461 | lstd.push_back(cn);
|
---|
462 | }
|
---|
463 | }
|
---|
464 |
|
---|
465 | /* --Methode-- */
|
---|
466 | void NamedObjMgr::CleanDir(string & dirname)
|
---|
467 | {
|
---|
468 | ZSync zs(*myMutex); zs.NOp();
|
---|
469 | CleanDir_P(dirname);
|
---|
470 | }
|
---|
471 |
|
---|
472 | /* --Methode-- */
|
---|
473 | void NamedObjMgr::CleanDir_P(string & dirname)
|
---|
474 | {
|
---|
475 | if ( !CheckDirName(dirname) ) {
|
---|
476 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl;
|
---|
477 | // return(false); $CHECK$ illegal return value in void function
|
---|
478 | }
|
---|
479 | NObjDirList::iterator itr = myDirs->find(dirname);
|
---|
480 | if (itr == myDirs->end()) {
|
---|
481 | cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - No such directory !" << endl;
|
---|
482 | // return(false); $CHECK$ illegal return value in void function
|
---|
483 | }
|
---|
484 |
|
---|
485 | int did = (*itr).second.id;
|
---|
486 | NObjList::iterator it;
|
---|
487 | list<int>::iterator iwr;
|
---|
488 | bool nodisp = true;
|
---|
489 | list<string> odel;
|
---|
490 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
491 | if ((*it).second.dirid != did) continue;
|
---|
492 | nodisp = true;
|
---|
493 | if (myImgApp)
|
---|
494 | for(iwr=(*it).second.wrsid.begin(); iwr != (*it).second.wrsid.end(); iwr++)
|
---|
495 | if (myImgApp->CheckWRsId(*iwr)) { nodisp = false; break; }
|
---|
496 | if (nodisp) odel.push_back((*it).first);
|
---|
497 | }
|
---|
498 | list<string>::iterator ii;
|
---|
499 | for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii,true);
|
---|
500 |
|
---|
501 | UpdateObjMgrWindow_P(did); // On met a jour la fenetre de gestion des objets
|
---|
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 zs(*myMutex); zs.NOp();
|
---|
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 ) myImgApp->LockMutex();
|
---|
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 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
615 | }
|
---|
616 | if (verbeux) cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
|
---|
617 | << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
|
---|
618 | return(true);
|
---|
619 | }
|
---|
620 |
|
---|
621 | bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
|
---|
622 | {
|
---|
623 | ZSync zs(*myMutex); zs.NOp();
|
---|
624 | NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
|
---|
625 | if (adap == NULL) {
|
---|
626 | cout << "NamedObjMgr::AddObj() No Adapter ! " << nom << endl;
|
---|
627 | return(false);
|
---|
628 | }
|
---|
629 | AnyDataObj * cloneobj = adap->CloneDataObj(true);
|
---|
630 | delete adap;
|
---|
631 | if (cloneobj == NULL) {
|
---|
632 | cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl;
|
---|
633 | return(false);
|
---|
634 | }
|
---|
635 | return ( AddObj_P(cloneobj , nom, crd) );
|
---|
636 | }
|
---|
637 |
|
---|
638 | /* --Methode-- */
|
---|
639 | bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
|
---|
640 | {
|
---|
641 | ZSync zs(*myMutex); zs.NOp();
|
---|
642 | return RenameObj_P(nom, nomnew);
|
---|
643 | }
|
---|
644 |
|
---|
645 | /* --Methode-- */
|
---|
646 | bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew)
|
---|
647 | {
|
---|
648 | string n1,r1,n2,r2;
|
---|
649 | int dids = ParseObjectName(nom, r1, n1);
|
---|
650 | NObjDirList::iterator itr1 = myDirs->find(r1);
|
---|
651 | int did = ParseObjectName(nomnew, r2, n2);
|
---|
652 | NObjDirList::iterator itr2 = myDirs->find(r2);
|
---|
653 |
|
---|
654 | if (did == 0) {
|
---|
655 | cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
|
---|
656 | return(false);
|
---|
657 | }
|
---|
658 | nom = '/' + r1 + '/' + n1;
|
---|
659 | nomnew = '/' + r2 + '/' + n2;
|
---|
660 | NObjList::iterator it1 = myObjs->find(nom);
|
---|
661 | if (it1 == myObjs->end()) {
|
---|
662 | cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl;
|
---|
663 | return(false);
|
---|
664 | }
|
---|
665 | if ((n2.length() < 1) || (! isalpha(n2[0])) ) {
|
---|
666 | cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
|
---|
667 | return(false);
|
---|
668 | }
|
---|
669 | NObjList::iterator it2 = myObjs->find(nomnew);
|
---|
670 | if (it2 != myObjs->end()) {
|
---|
671 | cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
|
---|
672 | return(false);
|
---|
673 | }
|
---|
674 |
|
---|
675 | if ( (*itr1).second.lock || (*itr2).second.lock ) {
|
---|
676 | cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !"
|
---|
677 | << endl;
|
---|
678 | return(false);
|
---|
679 | }
|
---|
680 |
|
---|
681 |
|
---|
682 | nobj_item no = (*it1).second;
|
---|
683 | no.dirid = did;
|
---|
684 | myObjs->erase(it1);
|
---|
685 | NObjDirList::iterator itr = myDirs->find(r1);
|
---|
686 | (*itr).second.nobj--;
|
---|
687 | (*myObjs)[nomnew] = no;
|
---|
688 | itr = myDirs->find(r2);
|
---|
689 | (*itr).second.nobj++;
|
---|
690 |
|
---|
691 | if (myImgApp != NULL) {
|
---|
692 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
693 | if ( (myImgApp->ObjMgrW())->Visible() ) {
|
---|
694 | (myImgApp->ObjMgrW())->DelObjList(dids, no.oid);
|
---|
695 | string oln = n2 + " (T= " + no.obja->GetDataObjType() + ")" ;
|
---|
696 | (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
|
---|
697 | }
|
---|
698 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
699 | }
|
---|
700 | if (verbeux)
|
---|
701 | cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
|
---|
702 | return(true);
|
---|
703 | }
|
---|
704 |
|
---|
705 | /* --Methode-- */
|
---|
706 | bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
|
---|
707 | {
|
---|
708 | ZSync zs(*myMutex); zs.NOp();
|
---|
709 | if(nomcp.length()<=0)
|
---|
710 | {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
|
---|
711 | return(false);}
|
---|
712 | NObjMgrAdapter* obnom = GetObjAdapter_P(nom);
|
---|
713 | if(obnom==NULL)
|
---|
714 | {cout<<"NamedObjMgr::CopyObj() Error - No "<<nom<<" object !"<<endl;
|
---|
715 | return(false);}
|
---|
716 | AnyDataObj* obnomcp = obnom->CloneDataObj();
|
---|
717 | if(obnomcp==NULL) return(false);
|
---|
718 | if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
|
---|
719 | return true;
|
---|
720 | }
|
---|
721 |
|
---|
722 | /* --Methode-- */
|
---|
723 | bool NamedObjMgr::DelObj(string & nom, bool fgd)
|
---|
724 | {
|
---|
725 | ZSync zs(*myMutex); zs.NOp();
|
---|
726 | return DelObj_P(nom, fgd);
|
---|
727 | }
|
---|
728 |
|
---|
729 | /* --Methode-- */
|
---|
730 | bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
|
---|
731 | {
|
---|
732 | string n1,r1;
|
---|
733 | int did = ParseObjectName(nom, r1, n1);
|
---|
734 | nom = '/' + r1 + '/' + n1;
|
---|
735 | NObjList::iterator it = myObjs->find(nom);
|
---|
736 | if (it == myObjs->end()) return(false);
|
---|
737 | NObjDirList::iterator itr = myDirs->find(r1);
|
---|
738 | if ( (*itr).second.lock ) {
|
---|
739 | cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
|
---|
740 | return(false);
|
---|
741 | }
|
---|
742 | list<int>::iterator ii;
|
---|
743 | if (myImgApp) {
|
---|
744 | //DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
|
---|
745 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
746 | bool fglock = (_fgimgapp) ? false : true;
|
---|
747 | if (fglock) myImgApp->LockMutex();
|
---|
748 | for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
|
---|
749 | myImgApp->DelWRsId((*ii));
|
---|
750 | if (fglock) myImgApp->UnlockMutex(true);
|
---|
751 | }
|
---|
752 | delete (*it).second.obja; // destruction de l'adaptateur
|
---|
753 | if (fgd) delete (*it).second.obj;
|
---|
754 |
|
---|
755 | if (myImgApp != NULL) {
|
---|
756 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
757 | if ( (myImgApp->ObjMgrW())->Visible() ) {
|
---|
758 | int olid = (*it).second.oid;
|
---|
759 | (myImgApp->ObjMgrW())->DelObjList(did, olid);
|
---|
760 | }
|
---|
761 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
762 | }
|
---|
763 | myObjs->erase(it);
|
---|
764 | (*itr).second.nobj--;
|
---|
765 |
|
---|
766 |
|
---|
767 | if (!verbeux) return(true);
|
---|
768 | if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
|
---|
769 | else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
|
---|
770 | return(true);
|
---|
771 | }
|
---|
772 |
|
---|
773 | /* --Methode-- */
|
---|
774 | bool NamedObjMgr::DelObj_Id(int oid)
|
---|
775 | {
|
---|
776 | ZSync zs(*myMutex); zs.NOp();
|
---|
777 | NObjList::iterator it;
|
---|
778 | string nom;
|
---|
779 | bool of = false;
|
---|
780 | for(it = myObjs->begin(); it != myObjs->end(); it++)
|
---|
781 | if ( (*it).second.oid == oid ) {
|
---|
782 | of = true; nom = (*it).first;
|
---|
783 | break;
|
---|
784 | }
|
---|
785 | if (of) return(DelObj_P(nom, true));
|
---|
786 | else return(false);
|
---|
787 | }
|
---|
788 |
|
---|
789 | /* --Methode-- */
|
---|
790 | void NamedObjMgr::DelObjects(string & patt, bool fgd)
|
---|
791 | {
|
---|
792 | ZSync zs(*myMutex); zs.NOp();
|
---|
793 | string n1,r1;
|
---|
794 | ParseObjectName(patt, r1, n1);
|
---|
795 | patt = '/' + r1 + '/' + n1;
|
---|
796 | NObjList::iterator it;
|
---|
797 | list<string> odel;
|
---|
798 | string cn;
|
---|
799 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
800 | cn = (*it).first;
|
---|
801 | if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
|
---|
802 | }
|
---|
803 | list<string>::iterator ii;
|
---|
804 | for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii, fgd);
|
---|
805 | }
|
---|
806 |
|
---|
807 | /* --Methode-- */
|
---|
808 | AnyDataObj* NamedObjMgr::GetObj(string & nom)
|
---|
809 | {
|
---|
810 | ZSync zs(*myMutex); zs.NOp();
|
---|
811 | return GetObj_P(nom);
|
---|
812 | }
|
---|
813 |
|
---|
814 | /* --Methode-- */
|
---|
815 | AnyDataObj* NamedObjMgr::GetObj_P(string & nom)
|
---|
816 | {
|
---|
817 | string n1,r1;
|
---|
818 | ParseObjectName(nom, r1, n1);
|
---|
819 | nom = '/' + r1 + '/' + n1;
|
---|
820 | NObjList::iterator it = myObjs->find(nom);
|
---|
821 | if (it == myObjs->end()) return(NULL);
|
---|
822 | return((*it).second.obj);
|
---|
823 | }
|
---|
824 |
|
---|
825 | /* --Methode-- */
|
---|
826 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
|
---|
827 | {
|
---|
828 | ZSync zs(*myMutex); zs.NOp();
|
---|
829 | return GetObjAdapter_P(nom);
|
---|
830 | }
|
---|
831 |
|
---|
832 | /* --Methode-- */
|
---|
833 | NObjMgrAdapter* NamedObjMgr::GetObjAdapter_P(string & nom)
|
---|
834 | {
|
---|
835 | string n1,r1;
|
---|
836 | ParseObjectName(nom, r1, n1);
|
---|
837 | nom = '/' + r1 + '/' + n1;
|
---|
838 | NObjList::iterator it = myObjs->find(nom);
|
---|
839 | if (it == myObjs->end()) return(NULL);
|
---|
840 | return((*it).second.obja);
|
---|
841 | }
|
---|
842 |
|
---|
843 | /* --Methode-- */
|
---|
844 | void NamedObjMgr::ListObjs(string & patt)
|
---|
845 | {
|
---|
846 | ZSync zs(*myMutex); zs.NOp();
|
---|
847 | int k;
|
---|
848 | AnyDataObj* obj=NULL;
|
---|
849 | string ctyp;
|
---|
850 | char strg[256];
|
---|
851 |
|
---|
852 | string n1,r1;
|
---|
853 | ParseObjectName(patt, r1, n1);
|
---|
854 | patt = '/' + r1 + '/' + n1;
|
---|
855 | cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
|
---|
856 | NObjList::iterator it; k = 0;
|
---|
857 | string cn;
|
---|
858 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
859 | cn = (*it).first;
|
---|
860 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
861 | obj = (*it).second.obj;
|
---|
862 | ctyp = typeid(*obj).name();
|
---|
863 | sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
|
---|
864 | ctyp = strg;
|
---|
865 | cout << ctyp << "\n" ;
|
---|
866 | k++;
|
---|
867 | }
|
---|
868 | cout << endl;
|
---|
869 | return;
|
---|
870 | }
|
---|
871 |
|
---|
872 | /* --Methode-- */
|
---|
873 | void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
|
---|
874 | {
|
---|
875 | ZSync zs(*myMutex); zs.NOp();
|
---|
876 | string n1,r1;
|
---|
877 | if (patt.length() < 1) return;
|
---|
878 | bool fgr = (patt[0] == '/') ? true : false;
|
---|
879 | ParseObjectName(patt, r1, n1);
|
---|
880 | patt = '/' + r1 + '/' + n1;
|
---|
881 | NObjList::iterator it;
|
---|
882 | string cn;
|
---|
883 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
884 | cn = (*it).first;
|
---|
885 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
886 | if (fgr) lst.push_back(cn);
|
---|
887 | else {
|
---|
888 | ParseObjectName(cn, r1, n1);
|
---|
889 | lst.push_back(n1);
|
---|
890 | }
|
---|
891 | }
|
---|
892 | }
|
---|
893 |
|
---|
894 | //++
|
---|
895 | // Titre Entrées-Sorties (I/O) sur les objets
|
---|
896 | //--
|
---|
897 | //++
|
---|
898 | // void ReadObj(PInPersist& s, int num=-1)
|
---|
899 | // Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
|
---|
900 | // et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
|
---|
901 | // sur le flot "s" sont créés et ajoutés à la liste.
|
---|
902 | // void ReadObj(string const & nomppf, string nobj="")
|
---|
903 | // Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
|
---|
904 | // à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
|
---|
905 | // composé à partir du nom de fichier.
|
---|
906 | //--
|
---|
907 |
|
---|
908 | /* --Methode-- */
|
---|
909 | void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
|
---|
910 | {
|
---|
911 | ZSync zs(*myMutex); zs.NOp();
|
---|
912 | PPersist* ppobj=NULL;
|
---|
913 | bool ok = true;
|
---|
914 | #ifdef SANS_EVOLPLANCK
|
---|
915 | TRY{
|
---|
916 | PInPersist pis(flnm);
|
---|
917 | ppobj = PPersistMgr::ReadObject(pis);
|
---|
918 | if (ppobj == NULL) ok = false;
|
---|
919 | } CATCH(merr)
|
---|
920 | { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
|
---|
921 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
922 | #else
|
---|
923 | try {
|
---|
924 | PInPersist pis(flnm);
|
---|
925 | ppobj = pis.ReadObject();
|
---|
926 | }
|
---|
927 | catch (IOExc iox) {
|
---|
928 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
929 | ok = false;
|
---|
930 | }
|
---|
931 | #endif
|
---|
932 | if (!ok) return;
|
---|
933 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
934 | AddObj_P(ppobj->DataObj(), nobj, true);
|
---|
935 | cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
|
---|
936 | return;
|
---|
937 | }
|
---|
938 | /* --Methode-- */
|
---|
939 | void NamedObjMgr::ReadObj(vector<string> & flnm_objname)
|
---|
940 | // flnm_objname[0] = nom du fichier .ppf
|
---|
941 | // flnm_objname[1...] = nom des tags des objects a lire
|
---|
942 | {
|
---|
943 | if(flnm_objname.size()<2) return;
|
---|
944 | ZSync zs(*myMutex); zs.NOp();
|
---|
945 | int nread=0;
|
---|
946 | try {
|
---|
947 | PInPersist pis(flnm_objname[0]);
|
---|
948 | for(int i=1;i<flnm_objname.size();i++) {
|
---|
949 | bool ok = pis.GotoNameTag(flnm_objname[i]);
|
---|
950 | if(!ok) {
|
---|
951 | cout<<"NamedObjMgr::ReadObj(...) Unknown object: "<<flnm_objname[i]<<endl;
|
---|
952 | continue;
|
---|
953 | }
|
---|
954 | PPersist *ppobj = pis.ReadObject();;
|
---|
955 | if(ppobj==NULL) {
|
---|
956 | cout<<"NamedObjMgr::ReadObj(...) impossible to read "<<flnm_objname[i]<<endl;
|
---|
957 | continue;
|
---|
958 | }
|
---|
959 | AddObj_P(ppobj->DataObj(),flnm_objname[i],true);
|
---|
960 | nread++;
|
---|
961 | cout<<"NamedObjMgr::ReadObj(...) object "<<flnm_objname[i]<<" read from file "<<endl;
|
---|
962 | }
|
---|
963 | } catch (IOExc iox) {
|
---|
964 | cerr<<"NamedObjMgr::ReadObj()/Error Exception - Msg= "<<iox.Msg()<<endl;
|
---|
965 | }
|
---|
966 | cout<<nread<<" objects have been read"<<endl;
|
---|
967 | return;
|
---|
968 | }
|
---|
969 |
|
---|
970 | /* --Methode-- */
|
---|
971 | void NamedObjMgr::ReadObj(PInPersist& s, int num)
|
---|
972 | {
|
---|
973 | ZSync zs(*myMutex); zs.NOp();
|
---|
974 | ReadObj_P(s, num);
|
---|
975 | }
|
---|
976 |
|
---|
977 | /* --Methode-- */
|
---|
978 | void NamedObjMgr::ReadObj_P(PInPersist& s, int num)
|
---|
979 | {
|
---|
980 | int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
|
---|
981 | #ifdef SANS_EVOLPLANCK
|
---|
982 | int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
|
---|
983 | #endif
|
---|
984 | int n0, n1;
|
---|
985 | bool ok = true;
|
---|
986 | PPersist* obj=NULL;
|
---|
987 | string nom;
|
---|
988 |
|
---|
989 | int nread = 0;
|
---|
990 | int nbtags = 0;
|
---|
991 | #ifdef SANS_EVOLPLANCK
|
---|
992 | nbtags = s.NbTags();
|
---|
993 | #else
|
---|
994 | nbtags = s.NbNameTags();
|
---|
995 | #endif
|
---|
996 | if ( (nbtags < 1) || (num >= nbtags) ) {
|
---|
997 | if (num >= 0) {
|
---|
998 | cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << " Error! NbTags ="
|
---|
999 | << nbtags << endl;
|
---|
1000 | return;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | #ifdef SANS_EVOLPLANCK
|
---|
1004 | TRY {
|
---|
1005 | obj = PPersistMgr::ReadObject(s);
|
---|
1006 | if (obj == NULL) ok = false;
|
---|
1007 | } CATCH(merr) {
|
---|
1008 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
1009 | ok = false;
|
---|
1010 | } ENDTRY;
|
---|
1011 | #else
|
---|
1012 | try {
|
---|
1013 | obj = s.ReadObject();
|
---|
1014 | }
|
---|
1015 | catch (IOExc iox) {
|
---|
1016 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1017 | ok = false;
|
---|
1018 | }
|
---|
1019 | #endif
|
---|
1020 |
|
---|
1021 | if (!ok) return;
|
---|
1022 | nom = "";
|
---|
1023 | AddObj_P(obj->DataObj(), nom, false);
|
---|
1024 | nread++;
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | if (num < 0) { n0 = 0; n1 = nbtags; }
|
---|
1028 | else { n0 = num; n1 = num+1; }
|
---|
1029 | for(i=n0; i<n1; i++) {
|
---|
1030 | #ifdef SANS_EVOLPLANCK
|
---|
1031 | key = s.TagKey(i, cid, ln);
|
---|
1032 | if (ln <= 0) nom = "";
|
---|
1033 | else nom = s.TagName(i);
|
---|
1034 | s.GotoTag(i);
|
---|
1035 | TRY {
|
---|
1036 | obj = PPersistMgr::ReadObject(s);
|
---|
1037 | if (obj == NULL) ok = false;
|
---|
1038 | } CATCH(merr) {
|
---|
1039 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
1040 | ok = false;
|
---|
1041 | } ENDTRY;
|
---|
1042 | #else
|
---|
1043 | s.GotoNameTagNum(i);
|
---|
1044 | nom = s.GetTagName(i);
|
---|
1045 | try {
|
---|
1046 | obj = s.ReadObject();
|
---|
1047 | }
|
---|
1048 | catch (IOExc iox) {
|
---|
1049 | cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1050 | ok = false;
|
---|
1051 | }
|
---|
1052 | #endif
|
---|
1053 | if (ok) { AddObj_P(obj->DataObj(), nom, true); nread++; }
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 | cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
|
---|
1057 | return;
|
---|
1058 | }
|
---|
1059 | /* --Methode-- */
|
---|
1060 | void NamedObjMgr::ReadAll(string const & flnm)
|
---|
1061 | {
|
---|
1062 | ZSync zs(*myMutex); zs.NOp();
|
---|
1063 | #ifdef SANS_EVOLPLANCK
|
---|
1064 | bool ok = true;
|
---|
1065 | PPersist* obj=NULL;
|
---|
1066 |
|
---|
1067 | PInPersist* ppin=NULL;
|
---|
1068 | TRY{
|
---|
1069 | ppin = new PInPersist(flnm);
|
---|
1070 | if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
|
---|
1071 | else obj = NULL;
|
---|
1072 | } CATCH(merr)
|
---|
1073 | { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
|
---|
1074 | (long)merr, PeidaExc(merr)); ok = false; }
|
---|
1075 | ENDTRY;
|
---|
1076 | if (!ok) return;
|
---|
1077 | if (obj) {
|
---|
1078 | string nom = servnobjm->FileName2Name(flnm);
|
---|
1079 | AddObj_P(obj->DataObj(), nom, false);
|
---|
1080 | }
|
---|
1081 | else ReadObj_P((*ppin), -1);
|
---|
1082 | delete ppin;
|
---|
1083 | #else
|
---|
1084 | try {
|
---|
1085 | PInPersist pis(flnm);
|
---|
1086 | if (pis.NbNameTags() >= 1) {
|
---|
1087 | if (pis.NbNameTags() < pis.NbTopLevelObjects()) {
|
---|
1088 | cout << "NamedObjMgr::ReadAll()/Warning File " << flnm << " NbNameTags="
|
---|
1089 | << pis.NbNameTags() << " < NbTopLevelObjects= "
|
---|
1090 | << pis.NbTopLevelObjects() << endl;
|
---|
1091 | cout << " ... Reading " << pis.NbNameTags() << " objects at NameTags " ;
|
---|
1092 | }
|
---|
1093 | ReadObj_P(pis, -1);
|
---|
1094 | return;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | string nom = servnobjm->FileName2Name(flnm);
|
---|
1098 | int kn = 1;
|
---|
1099 | for(int ii=0; ii<pis.NbTopLevelObjects(); ii++) {
|
---|
1100 | PPersist* obj = pis.ReadObject();
|
---|
1101 | if (!obj) continue;
|
---|
1102 | AddObj_P(obj->DataObj(), nom, false);
|
---|
1103 | kn++;
|
---|
1104 | nom += (string)MuTyV(kn);
|
---|
1105 | }
|
---|
1106 | }
|
---|
1107 | catch (IOExc& iox) {
|
---|
1108 | cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1109 | }
|
---|
1110 | #endif
|
---|
1111 | return;
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 |
|
---|
1115 | /* --Methode-- */
|
---|
1116 | void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
|
---|
1117 | {
|
---|
1118 | ZSync zs(*myMutex); zs.NOp();
|
---|
1119 | SaveObj_P(nom, s, keeppath);
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | static int key_for_write = 5000;
|
---|
1123 | /* --Methode-- */
|
---|
1124 | void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
|
---|
1125 | {
|
---|
1126 | if (nom.length() < 1) return;
|
---|
1127 | string nob,rep;
|
---|
1128 | ParseObjectName(nom, rep, nob);
|
---|
1129 | nom = '/' + rep + '/' + nob;
|
---|
1130 | NObjMgrAdapter* obja=NULL;
|
---|
1131 | string nomf = (keeppath) ? nom : nob;
|
---|
1132 | obja = GetObjAdapter_P(nom);
|
---|
1133 | if (obja == NULL) return;
|
---|
1134 | printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
|
---|
1135 | nom.c_str(), typeid(*(obja->GetDataObj())).name());
|
---|
1136 | obja->SavePPF(s, nomf);
|
---|
1137 | return;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | /* --Methode-- */
|
---|
1141 | void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
|
---|
1142 | {
|
---|
1143 | ZSync zs(*myMutex); zs.NOp();
|
---|
1144 | string n1,r1;
|
---|
1145 | if (patt.length() < 1) return;
|
---|
1146 | bool keeppath = (patt[0] == '/') ? true : false;
|
---|
1147 | ParseObjectName(patt, r1, n1);
|
---|
1148 | patt = '/' + r1 + '/' + n1;
|
---|
1149 |
|
---|
1150 | bool ok = true;
|
---|
1151 | POutPersist* pout=NULL;
|
---|
1152 | #ifdef SANS_EVOLPLANCK
|
---|
1153 | TRY{
|
---|
1154 | pout = new POutPersist(flnm);
|
---|
1155 | } CATCH(merr)
|
---|
1156 | { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
|
---|
1157 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
1158 | #else
|
---|
1159 | try {
|
---|
1160 | pout = new POutPersist(flnm);
|
---|
1161 | }
|
---|
1162 | catch (IOExc iox) {
|
---|
1163 | cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1164 | ok = false;
|
---|
1165 | }
|
---|
1166 | #endif
|
---|
1167 | if (!ok) return;
|
---|
1168 | NObjList::iterator it;
|
---|
1169 | string cn;
|
---|
1170 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
1171 | cn = (*it).first;
|
---|
1172 | if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
|
---|
1173 | SaveObj_P(cn, (*pout), keeppath);
|
---|
1174 | }
|
---|
1175 | delete pout;
|
---|
1176 | return;
|
---|
1177 | }
|
---|
1178 |
|
---|
1179 | /* --Methode-- */
|
---|
1180 | void NamedObjMgr::SaveListObjects(vector<string> &liste)
|
---|
1181 | // Les n-1 premiers elements (liste[0 -> n-2]) contiennent
|
---|
1182 | // les noms des objects a mettre dans le fichier ppf
|
---|
1183 | // dont le nom est le dernier argument (liste[n-1])
|
---|
1184 | {
|
---|
1185 | ZSync zs(*myMutex); zs.NOp();
|
---|
1186 |
|
---|
1187 | if(liste.size()<2) {
|
---|
1188 | cerr<<"NamedObjMgr::SaveListObjects()/Error not enough argument"<<endl;
|
---|
1189 | return;
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | // open ppf file
|
---|
1193 | string ppfname = liste[liste.size()-1];
|
---|
1194 | POutPersist* pout=NULL;
|
---|
1195 | try {
|
---|
1196 | pout = new POutPersist(ppfname);
|
---|
1197 | } catch(IOExc iox) {
|
---|
1198 | cerr<<"NamedObjMgr::SaveObjects()/Error Exception - Msg= "<<iox.Msg()<<endl;
|
---|
1199 | return;
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | // put objects in ppf file
|
---|
1203 | for(int i=0;i<liste.size()-1;i++) {
|
---|
1204 | bool keeppath = (liste[i][0] == '/') ? true : false;
|
---|
1205 | SaveObj_P(liste[i], (*pout), keeppath);
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | // close ppf file
|
---|
1209 | delete pout;
|
---|
1210 |
|
---|
1211 | return;
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | /* --Methode-- */
|
---|
1215 | void NamedObjMgr::SaveAll(string const& flnm)
|
---|
1216 | {
|
---|
1217 | ZSync zs(*myMutex); zs.NOp();
|
---|
1218 | bool ok = true;
|
---|
1219 |
|
---|
1220 | POutPersist* pout=NULL;
|
---|
1221 | #ifdef SANS_EVOLPLANCK
|
---|
1222 | TRY{
|
---|
1223 | pout = new POutPersist(flnm);
|
---|
1224 | } CATCH(merr)
|
---|
1225 | { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
|
---|
1226 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
1227 | #else
|
---|
1228 | try {
|
---|
1229 | pout = new POutPersist(flnm);
|
---|
1230 | }
|
---|
1231 | catch (IOExc iox) {
|
---|
1232 | cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl;
|
---|
1233 | ok = false;
|
---|
1234 | }
|
---|
1235 | #endif
|
---|
1236 | if (!ok) return;
|
---|
1237 | NObjList::iterator it;
|
---|
1238 | string no;
|
---|
1239 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
1240 | no = (*it).first;
|
---|
1241 | SaveObj_P(no, (*pout), true);
|
---|
1242 | }
|
---|
1243 | delete pout;
|
---|
1244 | return;
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 |
|
---|
1248 |
|
---|
1249 | /* --Methode-- */
|
---|
1250 | void NamedObjMgr::PrintObj(string& nom, int lev)
|
---|
1251 | {
|
---|
1252 | ZSync zs(*myMutex); zs.NOp();
|
---|
1253 | NObjMgrAdapter* obja=NULL;
|
---|
1254 | obja = GetObjAdapter_P(nom);
|
---|
1255 | if (obja == NULL) return;
|
---|
1256 | AnyDataObj* ob = obja->GetDataObj();
|
---|
1257 | if (ob == NULL) {
|
---|
1258 | cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl;
|
---|
1259 | return;
|
---|
1260 | }
|
---|
1261 | string ctyp = typeid(*ob).name();
|
---|
1262 | cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
|
---|
1263 | obja->Print(cout, lev);
|
---|
1264 |
|
---|
1265 | return;
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | /* --Methode-- */
|
---|
1269 | void NamedObjMgr::DisplayObj(string& nom, string dopt)
|
---|
1270 | {
|
---|
1271 | // Pas de display si option dopt = nodisp
|
---|
1272 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1273 |
|
---|
1274 | ZSync zs(*myMutex); zs.NOp();
|
---|
1275 |
|
---|
1276 | NObjMgrAdapter* obja=NULL;
|
---|
1277 | obja = GetObjAdapter_P(nom);
|
---|
1278 | if (obja == NULL) {
|
---|
1279 | cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
|
---|
1280 | return;
|
---|
1281 | }
|
---|
1282 | if (obja->GetDataObj() == NULL) {
|
---|
1283 | cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
|
---|
1284 | return;
|
---|
1285 | }
|
---|
1286 | if (!myImgApp) return;
|
---|
1287 |
|
---|
1288 | PIDrawer * dr = NULL;
|
---|
1289 | P2DArrayAdapter* arr = NULL;
|
---|
1290 | dr = obja->GetDrawer(dopt);
|
---|
1291 | if (!dr) arr = obja->Get2DArray(dopt);
|
---|
1292 |
|
---|
1293 | if (!dr && !arr) {
|
---|
1294 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1295 | cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
|
---|
1296 | return;
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 | int wrsid = 0;
|
---|
1300 |
|
---|
1301 | string n1,r1;
|
---|
1302 | ParseObjectName(nom, r1, n1);
|
---|
1303 |
|
---|
1304 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1305 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1306 |
|
---|
1307 | if (dr) {
|
---|
1308 | PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
|
---|
1309 | if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock);
|
---|
1310 | else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock);
|
---|
1311 | }
|
---|
1312 | else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, false, 0, fglock);
|
---|
1313 |
|
---|
1314 | AddWRsId_P(nom, wrsid);
|
---|
1315 | return;
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 | /* --Methode-- */
|
---|
1319 | void NamedObjMgr::DisplayImage(string& nom, string dopt, bool fgimagnav)
|
---|
1320 | {
|
---|
1321 | // Pas de display si option dopt = nodisp
|
---|
1322 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1323 |
|
---|
1324 | ZSync zs(*myMutex); zs.NOp();
|
---|
1325 |
|
---|
1326 | NObjMgrAdapter* obja=NULL;
|
---|
1327 | obja = GetObjAdapter_P(nom);
|
---|
1328 | if (obja == NULL) {
|
---|
1329 | cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
|
---|
1330 | return;
|
---|
1331 | }
|
---|
1332 | if (obja->GetDataObj() == NULL) {
|
---|
1333 | cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
|
---|
1334 | return;
|
---|
1335 | }
|
---|
1336 | if (!myImgApp) return;
|
---|
1337 |
|
---|
1338 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
1339 |
|
---|
1340 | if (!arr) {
|
---|
1341 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1342 | cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
|
---|
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 | wrsid = myImgApp->DispImage(arr, n1, dopt, fgimagnav, 0, fglock);
|
---|
1354 |
|
---|
1355 | AddWRsId_P(nom, wrsid);
|
---|
1356 | return;
|
---|
1357 | }
|
---|
1358 | /* --Methode-- */
|
---|
1359 | void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
|
---|
1360 | {
|
---|
1361 | // Pas de display si option dopt = nodisp
|
---|
1362 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1363 |
|
---|
1364 | ZSync zs(*myMutex); zs.NOp();
|
---|
1365 |
|
---|
1366 | NObjMgrAdapter* obja=NULL;
|
---|
1367 | obja = GetObjAdapter_P(nom);
|
---|
1368 | if (obja == NULL) {
|
---|
1369 | cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
|
---|
1370 | return;
|
---|
1371 | }
|
---|
1372 | if (obja->GetDataObj() == NULL) {
|
---|
1373 | cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
|
---|
1374 | return;
|
---|
1375 | }
|
---|
1376 | if (!myImgApp) return;
|
---|
1377 |
|
---|
1378 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
1379 |
|
---|
1380 | if (!arr) {
|
---|
1381 | string ctyp = typeid(*(obja->GetDataObj())).name();
|
---|
1382 | cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
|
---|
1383 | return;
|
---|
1384 | }
|
---|
1385 |
|
---|
1386 | if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
|
---|
1387 | cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
|
---|
1388 | << "x" << arr->YSize() << ") too big (max=250x250)" << endl;
|
---|
1389 | delete arr;
|
---|
1390 | return;
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | string n1,r1;
|
---|
1394 | ParseObjectName(nom, r1, n1);
|
---|
1395 |
|
---|
1396 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1397 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1398 |
|
---|
1399 | int wrsid = 0;
|
---|
1400 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
---|
1401 | wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
|
---|
1402 | AddWRsId_P(nom, wrsid);
|
---|
1403 | return;
|
---|
1404 | }
|
---|
1405 |
|
---|
1406 | /* --Methode-- */
|
---|
1407 | void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
|
---|
1408 | string& erx, string& ery, string& erz, string& wt,
|
---|
1409 | string& label, string dopt, bool fg3d)
|
---|
1410 | {
|
---|
1411 | // Pas de display si option dopt = nodisp
|
---|
1412 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1413 |
|
---|
1414 | ZSync zs(*myMutex); zs.NOp();
|
---|
1415 |
|
---|
1416 | AnyDataObj* obj=GetObj_P(nom);
|
---|
1417 | if (obj == NULL) {
|
---|
1418 | cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
|
---|
1419 | return;
|
---|
1420 | }
|
---|
1421 | if (!myImgApp) return;
|
---|
1422 |
|
---|
1423 | NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
|
---|
1424 | if (nt == NULL) {
|
---|
1425 | // if (typeid(*obj) != typeid(NTupleInterface)) {
|
---|
1426 | string ctyp = typeid(*obj).name();
|
---|
1427 | cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl;
|
---|
1428 | return;
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | int wrsid = 0;
|
---|
1432 | dopt = "defline " + dopt;
|
---|
1433 |
|
---|
1434 | string n1,r1;
|
---|
1435 | ParseObjectName(nom, r1, n1);
|
---|
1436 |
|
---|
1437 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1438 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1439 |
|
---|
1440 | if ( fg3d && (nmz.length()>0) ) { // Display 3D
|
---|
1441 | PINTuple3D* pin = new PINTuple3D(nt, false);
|
---|
1442 | pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
|
---|
1443 | pin->SelectWt(wt.c_str());
|
---|
1444 | pin->SelectLabel(label.c_str());
|
---|
1445 | pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
|
---|
1446 | string titre = nmz + "%" + nmy + "%" + nmz;
|
---|
1447 | wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock);
|
---|
1448 | }
|
---|
1449 | else {
|
---|
1450 | PINTuple* pin = new PINTuple(nt, false);
|
---|
1451 | pin->SelectXY(nmx.c_str(), nmy.c_str());
|
---|
1452 | pin->SelectWt(wt.c_str());
|
---|
1453 | pin->SelectLabel(label.c_str());
|
---|
1454 | pin->SelectErrBar(erx.c_str(), ery.c_str());
|
---|
1455 | string titre = nmy + "%" + nmx;
|
---|
1456 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock);
|
---|
1457 | }
|
---|
1458 |
|
---|
1459 | AddWRsId_P(nom, wrsid);
|
---|
1460 | return;
|
---|
1461 | }
|
---|
1462 |
|
---|
1463 | /* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
|
---|
1464 | void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
|
---|
1465 | // Pour le display 2D ou 3D d'un ``GeneralFitData''.
|
---|
1466 | //| nom = nom de l'objet GeneralFitData a representer.
|
---|
1467 | //| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
|
---|
1468 | //| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
|
---|
1469 | //| Pour le display 2D, numvary="" string vide.
|
---|
1470 | //| err = qu'elles erreurs faut il representer ?
|
---|
1471 | //| - 2D : x y xy (display y=f(x))
|
---|
1472 | //| - 3D : x y z xy xz yz xzy (display z=f(x,y))
|
---|
1473 | //| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
|
---|
1474 | //| les barres d'erreurs sont representees.
|
---|
1475 | //| opt = options generales pour le display.
|
---|
1476 | {
|
---|
1477 | // Pas de display si option dopt = nodisp
|
---|
1478 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1479 |
|
---|
1480 | ZSync zs(*myMutex); zs.NOp();
|
---|
1481 |
|
---|
1482 | AnyDataObj* obj=GetObj_P(nom);
|
---|
1483 | if(obj == NULL)
|
---|
1484 | {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
|
---|
1485 | return;}
|
---|
1486 | if(!myImgApp) return;
|
---|
1487 | if(typeid(*obj) != typeid(GeneralFitData))
|
---|
1488 | {string ctyp = typeid(*obj).name();
|
---|
1489 | cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl;
|
---|
1490 | return;}
|
---|
1491 |
|
---|
1492 | // Decodage des erreurs a representer
|
---|
1493 | bool errx=false, erry=false, errz=false;
|
---|
1494 | if(err.length()>0) {
|
---|
1495 | for(int i=0;i<(int_4)err.length();i++)
|
---|
1496 | if (err[i]=='x' || err[i]=='X') errx = true;
|
---|
1497 | else if(err[i]=='y' || err[i]=='Y') erry = true;
|
---|
1498 | else if(err[i]=='z' || err[i]=='Z') errz = true;
|
---|
1499 | }
|
---|
1500 | // Decodage des numeros de variables en abscisse
|
---|
1501 | int numvx=-1, numvy=-1;
|
---|
1502 | if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
|
---|
1503 | if(numvary.length()>0) numvy = atoi(numvary.c_str());
|
---|
1504 |
|
---|
1505 | string n1,r1;
|
---|
1506 | ParseObjectName(nom, r1, n1);
|
---|
1507 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1508 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1509 |
|
---|
1510 | int wrsid = 0;
|
---|
1511 | if(numvy>=0) { // display 3D
|
---|
1512 | PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
|
---|
1513 | pigfd->SelectXY(numvx,numvy);
|
---|
1514 | pigfd->SelectErrBar(errx,erry,errz);
|
---|
1515 | wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock);
|
---|
1516 | } else { // display 2D
|
---|
1517 | PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
|
---|
1518 | pigfd->SelectX(numvx);
|
---|
1519 | pigfd->SelectErrBar(errx,erry);
|
---|
1520 | wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock);
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | AddWRsId_P(nom, wrsid);
|
---|
1524 |
|
---|
1525 | return;
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 | /* --Methode-- */
|
---|
1529 | void NamedObjMgr::DisplayVector(string & nomvx, string& nomvy, string dopt)
|
---|
1530 | // Pour l'affichage 2-D de points avec coordonnees definies par deux vecteurs
|
---|
1531 | // nomvx et nomvy
|
---|
1532 | {
|
---|
1533 | // Pas de display si option dopt = nodisp
|
---|
1534 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
1535 |
|
---|
1536 | ZSync zs(*myMutex); zs.NOp();
|
---|
1537 |
|
---|
1538 | #ifdef SANS_EVOLPLANCK
|
---|
1539 | cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
|
---|
1540 | #else
|
---|
1541 |
|
---|
1542 | if(!myImgApp) return;
|
---|
1543 |
|
---|
1544 | AnyDataObj* obj;
|
---|
1545 | obj = GetObj_P(nomvx);
|
---|
1546 | if(obj == NULL) {
|
---|
1547 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl;
|
---|
1548 | return;
|
---|
1549 | }
|
---|
1550 | //Vector * vx = dynamic_cast<Vector *>(obj);
|
---|
1551 | BaseArray* bax = dynamic_cast<BaseArray *>(obj);
|
---|
1552 | if (bax == NULL) {
|
---|
1553 | cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl;
|
---|
1554 | return;
|
---|
1555 | }
|
---|
1556 |
|
---|
1557 | obj = GetObj_P(nomvy);
|
---|
1558 | if(obj == NULL) {
|
---|
1559 | cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
|
---|
1560 | return;
|
---|
1561 | }
|
---|
1562 | BaseArray* bay = dynamic_cast<BaseArray *>(obj);
|
---|
1563 | if (bay == NULL) {
|
---|
1564 | cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
|
---|
1565 | return;
|
---|
1566 | }
|
---|
1567 |
|
---|
1568 | Vector vx = *bax;
|
---|
1569 | Vector vy = *bay;
|
---|
1570 | Vector * cvx, * cvy;
|
---|
1571 |
|
---|
1572 | if (vx.Size() != vy.Size()) {
|
---|
1573 | cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl;
|
---|
1574 | if (vx.Size() < vy.Size()) {
|
---|
1575 | cvx = new Vector(vx);
|
---|
1576 | cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1)));
|
---|
1577 | }
|
---|
1578 | else {
|
---|
1579 | cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1)));
|
---|
1580 | cvy = new Vector(vy);
|
---|
1581 | }
|
---|
1582 | }
|
---|
1583 | else {
|
---|
1584 | cvx = new Vector(vx);
|
---|
1585 | cvy = new Vector(vy);
|
---|
1586 | }
|
---|
1587 |
|
---|
1588 | POVectorAdapter * avx = new POVectorAdapter(cvx, true);
|
---|
1589 | POVectorAdapter * avy = new POVectorAdapter(cvy, true);
|
---|
1590 | PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true);
|
---|
1591 |
|
---|
1592 | string nx,rx;
|
---|
1593 | ParseObjectName(nomvx, rx, nx);
|
---|
1594 | string ny,ry;
|
---|
1595 | ParseObjectName(nomvy, ry, ny);
|
---|
1596 |
|
---|
1597 | // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
|
---|
1598 | bool fglock = (_fgimgapp) ? false : true;
|
---|
1599 |
|
---|
1600 | string title = ny + " (Y) vs. " + nx + " (X)";
|
---|
1601 | // display 2D
|
---|
1602 | myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
|
---|
1603 |
|
---|
1604 | return;
|
---|
1605 |
|
---|
1606 | #endif
|
---|
1607 | }
|
---|
1608 |
|
---|
1609 | /* --Methode--
|
---|
1610 | void NamedObjMgr::DisplayImage(string& nom, string dopt)
|
---|
1611 | {
|
---|
1612 | cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
|
---|
1613 | }
|
---|
1614 | */
|
---|
1615 |
|
---|
1616 |
|
---|
1617 |
|
---|
1618 |
|
---|
1619 | /* --Methode--
|
---|
1620 | void NamedObjMgr::SetGraphicAttributes(string gratt)
|
---|
1621 | {
|
---|
1622 | bool fg = false;
|
---|
1623 | servnobjm->DecodeDispOption(gratt, fg);
|
---|
1624 | Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
|
---|
1625 | }
|
---|
1626 |
|
---|
1627 | void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
|
---|
1628 | {
|
---|
1629 | if (!myImgApp) return;
|
---|
1630 | if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
|
---|
1631 | else myImgApp->SetZone(nzx, nzy);
|
---|
1632 | }
|
---|
1633 | */
|
---|
1634 |
|
---|
1635 | /* --Methode-- */
|
---|
1636 | void NamedObjMgr::AddWRsId(string & nom, int wrsid)
|
---|
1637 | {
|
---|
1638 | ZSync zs(*myMutex); zs.NOp();
|
---|
1639 | AddWRsId_P(nom, wrsid);
|
---|
1640 | }
|
---|
1641 |
|
---|
1642 | /* --Methode-- */
|
---|
1643 | void NamedObjMgr::AddWRsId_P(string & nom, int wrsid)
|
---|
1644 | {
|
---|
1645 | if(wrsid != 0) {
|
---|
1646 | NObjList::iterator it = myObjs->find(nom);
|
---|
1647 | if (it == myObjs->end()) return;
|
---|
1648 | (*it).second.wrsid.push_back(wrsid);
|
---|
1649 | }
|
---|
1650 | return;
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 | /* --Methode-- */
|
---|
1654 | void NamedObjMgr::UpdateObjMgrWindow(int did)
|
---|
1655 | {
|
---|
1656 | if (!myImgApp) return;
|
---|
1657 | ZSync zs(*myMutex); zs.NOp();
|
---|
1658 | UpdateObjMgrWindow_P(did);
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | /* --Methode-- */
|
---|
1662 | void NamedObjMgr::UpdateObjMgrWindow_P(int did)
|
---|
1663 | {
|
---|
1664 | if (!myImgApp) return;
|
---|
1665 | if ( !_fgimgapp ) myImgApp->LockMutex();
|
---|
1666 | if ( !(myImgApp->ObjMgrW())->Visible() ||
|
---|
1667 | ( (myImgApp->ObjMgrW())->GetCurDirId() != did) ) {
|
---|
1668 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
1669 | return;
|
---|
1670 | }
|
---|
1671 |
|
---|
1672 | (myImgApp->ObjMgrW())->ClearObjList();
|
---|
1673 |
|
---|
1674 | NObjList::iterator it;
|
---|
1675 | string cn;
|
---|
1676 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
1677 | if ((*it).second.dirid != did) continue;
|
---|
1678 | cn = (*it).first.substr(1);
|
---|
1679 | // cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ;
|
---|
1680 | cn = cn.substr(cn.find('/')+1) + " (T= " + (*it).second.obja->GetDataObjType() + ")" ;
|
---|
1681 | (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
|
---|
1682 | }
|
---|
1683 | if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
|
---|
1684 | return;
|
---|
1685 | }
|
---|
1686 |
|
---|
1687 |
|
---|
1688 | /* Nouvelle-Fonction */
|
---|
1689 | void NamedObjMgr::RemoveSpacesFromName(string & nom)
|
---|
1690 | {
|
---|
1691 | // on supprime les blancs de debut et de fin
|
---|
1692 | size_t p = nom.find_first_not_of(" ");
|
---|
1693 | if(p>nom.length()) { nom = ""; return; }
|
---|
1694 | nom = nom.substr(p);
|
---|
1695 | p = nom.find(' ');
|
---|
1696 | if(p>nom.length()) p=nom.length();
|
---|
1697 | nom = nom.substr(0, p);
|
---|
1698 | }
|
---|
1699 |
|
---|
1700 | /* Nouvelle-Fonction */
|
---|
1701 | bool NamedObjMgr::CheckDirName(string & nom)
|
---|
1702 | {
|
---|
1703 | RemoveSpacesFromName(nom);
|
---|
1704 | if (nom.length() < 1) return(false);
|
---|
1705 | if (nom[0] == '/') nom = nom.substr(1) ;
|
---|
1706 | size_t p = nom.find('/');
|
---|
1707 | if (p < nom.length()) nom = nom.substr(0,p);
|
---|
1708 | if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
|
---|
1709 | return(true);
|
---|
1710 | }
|
---|
1711 |
|
---|
1712 | /* Nouvelle-Fonction */
|
---|
1713 | int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
|
---|
1714 | {
|
---|
1715 | RemoveSpacesFromName(nom);
|
---|
1716 | // Si le nom ne commence pas par un slash, c'est le repertoire courant
|
---|
1717 | if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
|
---|
1718 | else {
|
---|
1719 | string xx = nom.substr(1);
|
---|
1720 | size_t p = xx.find('/');
|
---|
1721 | if (p < xx.length()) {
|
---|
1722 | nomrep = xx.substr(0,p);
|
---|
1723 | nomobj = xx.substr(p+1);
|
---|
1724 | }
|
---|
1725 | else {
|
---|
1726 | nomrep = xx;
|
---|
1727 | nomobj = "";
|
---|
1728 | }
|
---|
1729 | }
|
---|
1730 | int rc = 0;
|
---|
1731 | NObjDirList::iterator it = myDirs->find(nomrep);
|
---|
1732 | if (it != myDirs->end()) rc = (*it).second.id;
|
---|
1733 | return(rc);
|
---|
1734 | }
|
---|
1735 |
|
---|