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