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

Last change on this file since 3461 was 3374, checked in by ansari, 18 years ago

suite corrections pour eviter blocage: Request UpdateObjMgrWindow() -> SOpExObj::AddOpe()/run() - Reza 05/11/2007

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