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