source: Sophya/trunk/SophyaPI/PIext/pisiadw.cc@ 2380

Last change on this file since 2380 was 2380, checked in by ansari, 22 years ago

modifs suite ajout colormap MultiCol64 et corrections diverses - Reza 15/5/2003

File size: 8.2 KB
Line 
1#include "machdefs.h"
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5
6#include <typeinfo>
7
8#include "perrors.h"
9#include "ctimer.h"
10
11#include "nbmath.h"
12
13#include "pistdimgapp.h"
14#include "nobjmgr.h"
15#include "servnobjm.h"
16
17
18
19/* ........................................................... */
20/* Classe ObjMgrWind interface de gestion d'objets nommes */
21/* ........................................................... */
22
23/* --Methode-- */
24ObjMgrWind::ObjMgrWind(PIStdImgApp *par)
25: PIWindow((PIMsgHandler *)par, "objmgr", PIWK_normal,
26 400, 300, 250, 250)
27{
28int i;
29dap = par;
30
31int bsx, bsy;
32int tsx, tsy;
33int spx, spy;
34// On definit la taille a partir de la taille par defaut des composantes
35PIApplicationPrefCompSize(bsx, bsy);
36spx = bsx/4; spy = bsy/4;
37tsx = 4.0*bsx+3*spx; tsy = 6*bsy+7*spy;
38SetSize(tsx,tsy);
39dirlist = new PIOptMenu(this, "dirlist", 2.5*bsx, bsy, spx+0.25*bsx, spy);
40dirlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
41objlist = new PIList(this, "objlist", 3*bsx, tsy-3*spy-bsy, spx, 2*spy+bsy);
42objlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
43// objlist->SetBorderWidth(2);
44
45int py = spy;
46int px = 2*spx+3*bsx;
47mBut[0] = new PIButton(this, "SetCurObj", 10, bsx, bsy, px, py); py += (bsy+spy);
48mBut[1] = new PIButton(this, "Display", 20, bsx, bsy, px, py); py += (bsy+spy);
49mBut[2] = new PIButton(this, "Print", 30, bsx, bsy, px, py); py += (bsy+spy);
50mBut[3] = new PIButton(this, "SavePPF", 40, bsx, bsy, px, py); py += (bsy+spy);
51mBut[4] = new PIButton(this, "Delete", 50, bsx, bsy, px, py); py += (bsy+spy);
52mBut[5] = new PIButton(this, "Dismiss", 90, bsx, bsy, px, py); py += (bsy+spy);
53
54for(i=0; i<6; i++)
55 mBut[i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
56
57// FinishCreate(); pas necessaire ?
58}
59
60/* --Methode-- */
61ObjMgrWind::~ObjMgrWind()
62{
63int i;
64delete dirlist;
65delete objlist;
66for(i=0; i<6; i++) delete mBut[i];
67}
68
69/* --Methode-- */
70void ObjMgrWind::Show()
71{
72// dap->SetBlocked(); Ce n'est plus necessaire - Reza 11/12/99
73string cdir;
74dap->ObjMgr()->GetCurrentDir(cdir);
75cdir = '/' + cdir;
76dirlist->SetValueStr(cdir);
77dap->ObjMgr()->UpdateObjMgrWindow(dirlist->GetValue()-30000);
78PIWindow::Show();
79return;
80}
81
82
83/* --Methode-- */
84void ObjMgrWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
85{
86
87if (sender == objlist) return; // Changement de selection d'objet - on ne fait rien
88 // PIMessage ssg = ModMsg(msg);
89msg = UserMsg(msg);
90if (msg == 90) {
91 dap->SetReady();
92 this->Hide();
93 return;
94 }
95else if (msg >= 30000) {
96 dap->ObjMgr()->UpdateObjMgrWindow(msg-30000);
97 return;
98 }
99/*
100 else if (msg == 10) {
101 string cdir = dirlist->GetValueStr();
102 dap->ObjMgr()->SetCurrentDir(cdir);
103 return;
104 }
105*/
106
107string nom = "";
108string sel = "";
109if ( (msg == 10) || (msg == 20) || (msg == 30) || (msg == 40) || (msg == 50) ) {
110 sel = objlist->GetSelectionStr();
111 // size_t p = sel.find_first_not_of(" \t");
112 // if (p<0) p = 0;
113 size_t l = sel.length();
114 size_t q = sel.find_first_of(" \t");
115 if (q > l) q = l;
116 nom = dirlist->GetValueStr() + '/' + sel.substr(0, q);
117 }
118
119NamedObjMgr* om = dap->ObjMgr();
120if (om == NULL) return;
121if (sel.length() < 1) return;
122if (nom.length() < 1) return;
123
124switch (msg)
125 {
126 case 10:
127 {
128 string cmd = "set cobj " + nom ;
129 cout << " Setting current object ($cobj) to " << nom << endl;
130 dap->CmdInterpreter()->Interpret(cmd);
131 }
132 break;
133 case 20:
134 om->DisplayObj(nom);
135 break;
136 case 30:
137 om->PrintObj(nom);
138 break;
139 case 40:
140 if (dap->mPpfout) om->SaveObj(nom, *(dap->mPpfout), false);
141 break;
142 case 50:
143 om->DelObj(nom);
144 // objlist->DeleteItemMsg(objlist->GetSelection());
145 // dap->ObjMgr()->UpdateObjMgrWindow(dirlist->GetValue()-30000);
146 break;
147
148 default:
149 // printf("DEBUG/ObjMgrW::Process %d %d \n", (int)msg, (int)ssg);
150 break;
151 }
152
153return;
154}
155
156/* --Methode-- */
157void ObjMgrWind::UpdateList(int did)
158{
159if (!Visible()) return;
160if (did != (dirlist->GetValue()-30000) ) return;
161dap->ObjMgr()->UpdateObjMgrWindow(did);
162return;
163}
164
165/* --Methode-- */
166void ObjMgrWind::AddObjList(int did, const char * objn, int oid)
167{
168if (!Visible()) return;
169if (did != (dirlist->GetValue()-30000) ) return;
170mNitem++; objlist->AppendItem(objn, oid);
171}
172
173/* --Methode-- */
174void ObjMgrWind::DelObjList(int did, int oid)
175{
176if (!Visible()) return;
177//DBG printf("DBG-DelObjList %d , %d , (%d) \n", did, dirlist->GetValue()-30000, oid);
178if (did != (dirlist->GetValue()-30000) ) return;
179objlist->DeleteItemMsg(oid);
180}
181
182/* ........................................................... */
183/* Classe PPInMgrWind interface de gestion d'objets nommes */
184/* ........................................................... */
185
186/* --Methode-- */
187PPInMgrWind::PPInMgrWind(PIStdImgApp *par)
188: PIWindow((PIMsgHandler *)par, "PPF-FileManager", PIWK_dialog,
189 400, 300, 250, 250)
190{
191int i;
192dap = par;
193
194int bsx, bsy;
195int tsx, tsy;
196int spx, spy;
197// On definit la taille a partir de la taille par defaut des composantes
198PIApplicationPrefCompSize(bsx, bsy);
199spx = bsx/4; spy = bsy/3;
200bsx *= 1.25;
201ttx = tsx = 3*bsx+8*spx; tty = tsy = 7*bsy+5*spy;
202SetSize(tsx,tsy);
203
204mLab[0] = new PILabel(this, "filename", tsx-spx, bsy-spy, spx/2, spy/2);
205mLab[0]->SetLabel("");
206mLab[0]->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic,PIBK_elastic);
207mLab[0]->SetBorderWidth(1);
208
209polx = spx/2; poly = bsy+1.5*spy;
210tolx = tsx-spx; toly = tsy-2*bsy-5*spy;
211int py = tsy-2*spy-bsy;
212int px = 2*spx;
213mBut[0] = new PIButton(this, "Read", 2500, bsx, bsy, px, py); px += (bsx+2*spx);
214mBut[1] = new PIButton(this, "ReadAll", 2600, bsx, bsy, px, py); px += (bsx+2*spx);
215mBut[2] = new PIButton(this, "Close", 2700, bsx, bsy, px, py); px += (bsx+2*spx);
216
217for(i=0; i<3; i++)
218 mBut[i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
219
220objlist = NULL;
221mLab[1] = NULL;
222mPin = NULL;
223
224// FinishCreate(); pas necessaire
225}
226
227/* --Methode-- */
228PPInMgrWind::~PPInMgrWind()
229{
230int i;
231if (objlist) delete objlist;
232delete mLab[0];
233for(i=0; i<3; i++) delete mBut[i];
234}
235
236/* --Methode-- */
237void PPInMgrWind::SetFile(string flnm)
238{
239char strg[128];
240char* nom;
241char noms[32];
242int i, cid, key, ln;
243
244bool ok = true;
245#ifdef SANS_EVOLPLANCK
246TRY {
247 mPin = new PInPersist(flnm);
248} CATCH(merr)
249 { printf("ObjMgrWind::SetFile Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
250 ok = false; } ENDTRY;
251#else
252try {
253 mPin = new PInPersist(flnm);
254 }
255catch (IOExc iox) {
256 cerr << "ObjMgrWind::SetFile/Error Exception - Msg= " << iox.Msg() << endl;
257 ok = false;
258 }
259#endif
260
261if (!ok) { mPin = NULL; dap->SetReady(); return; }
262
263if (mPin->NbTags() < 1) {
264 delete mPin; mPin = NULL;
265 string no="";
266 dap->ObjMgr()->ReadObj(flnm,no);
267 return;
268}
269if (objlist) delete objlist;
270SetSize(ttx,tty);
271mLab[0]->SetLabel(flnm);
272objlist = new PIList(this, "infileobjlist", tolx, toly, polx, poly);
273objlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
274objlist->SetBorderWidth(2);
275
276
277#ifdef SANS_EVOLPLANCK
278for(i=0; i<mPin->NbTags(); i++) {
279 key = mPin->TagKey(i, cid, ln); // $CHECK$ non-const & reference initialized to temporary, car int -> long&
280 if (ln <= 0) nom = "?";
281 else { strncpy(noms, mPin->TagName(i).c_str(), 31); noms[31] = '\0'; nom = noms; }
282 sprintf(strg, "%s (T=%s, Key=%d)", nom, dap->ObjMgr()->GetServiceObj()->PClassIdToClassName(cid), key);
283 // sprintf(strg, "%s (T=%s, Key=%d)", nom, " DataObject ?", key); Attention SANS_EVOLPLANCK
284 objlist->AppendItem(strg, 5000+i);
285}
286#else
287string tn;
288for(i=0; i<mPin->NbTags(); i++) {
289 tn = mPin->GetTagName(i);
290 objlist->AppendItem(tn.c_str(), 5000+i);
291}
292#endif
293
294}
295
296/* --Methode-- */
297void PPInMgrWind::Show()
298{
299if (mPin == NULL) return;
300dap->SetBlocked();
301PIWindow::Show();
302return;
303}
304
305/* --Methode-- */
306void PPInMgrWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
307{
308
309int sel;
310msg = UserMsg(msg);
311
312if (msg == 2700) {
313 delete mPin; mPin = NULL;
314 delete objlist; objlist = NULL;
315 dap->SetReady();
316 this->Hide();
317 return;
318}
319
320NamedObjMgr* om = dap->ObjMgr();
321switch (msg)
322 {
323 case 2500:
324 sel = (PIMessage)objlist->GetSelection() - 5000;
325 if (sel >= 0) om->ReadObj((*mPin), sel);
326 break;
327 case 2600:
328 om->ReadObj((*mPin), -1);
329 dap->SetReady();
330 this->Hide();
331 break;
332
333 default:
334 break;
335 }
336
337return;
338}
Note: See TracBrowser for help on using the repository browser.