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

Last change on this file since 3370 was 3366, checked in by ansari, 18 years ago

Tentative pour regler le probleme de blocage de piapp suite a affichage de la fefenetre de gestion d'objets.

1/ Protection dans NamedObjMgr() pour eviter deadlock de mutex (ds NamedObjMgr::UpdateObjMgrWindow() en particulier)
2/ Introduction de la classe SOpExObj (fichier piacmd.h .cc) pour execution d'operations sur objets, initiees depuis la boucle d'evts, dans un thread separe.

Reza , 30/10/2007

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