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