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

Last change on this file since 330 was 295, checked in by ercodmgr, 26 years ago

Mise aux "normes" version DPC/Planck - Gestion des objets a travers

un adaptateur/interface NTuple par NamedObjMgr.
Enregistrement d'objets et de l'adaptateur (I/O PPersist, display, ...)
par ServNobjMgr .... Reza 13/05/99

File size: 6.1 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_dialog,
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/3;
37tsx = 5*bsx+6*spx; tsy = 7*bsy+4*spy;
38SetSize(tsx,tsy);
39objlist = new PIList(this, "objlist", tsx-spx, tsy-4*spy-bsy, spx/2, spy/2);
40objlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
41objlist->SetBorderWidth(2);
42
43int py = tsy-2*spy-bsy;
44int px = spx;
45mBut[0] = new PIButton(this, "Display", 100, bsx, bsy, px, py); px += (bsx+spx);
46mBut[1] = new PIButton(this, "Print", 200, bsx, bsy, px, py); px += (bsx+spx);
47mBut[2] = new PIButton(this, "SavePPF", 300, bsx, bsy, px, py); px += (bsx+spx);
48mBut[3] = new PIButton(this, "Delete", 400, bsx, bsy, px, py); px += (bsx+spx);
49mBut[4] = new PIButton(this, "Dismiss", 900, bsx, bsy, px, py); px += (bsx+spx);
50
51for(i=0; i<5; i++)
52 mBut[i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
53
54// FinishCreate(); pas necessaire ?
55}
56
57/* --Methode-- */
58ObjMgrWind::~ObjMgrWind()
59{
60int i;
61delete objlist;
62for(i=0; i<5; i++) delete mBut[i];
63}
64
65/* --Methode-- */
66void ObjMgrWind::Show()
67{
68dap->SetBlocked();
69PIWindow::Show();
70return;
71}
72
73/* --Methode-- */
74void ObjMgrWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
75{
76
77 // PIMessage ssg = ModMsg(msg);
78msg = UserMsg(msg);
79if (msg == 900) {
80 dap->SetReady();
81 this->Hide();
82 return;
83}
84
85string nom = "";
86if ( (msg == 100) || (msg == 200) || (msg == 300) || (msg == 400) ) {
87 string sel = objlist->GetSelectionStr();
88 // size_t p = sel.find_first_not_of(" \t");
89 // if (p<0) p = 0;
90 size_t l = sel.length();
91 size_t q = sel.find_first_of(" \t");
92 if (q > l) q = l;
93 nom = sel.substr(0, q);
94}
95
96NamedObjMgr* om = dap->ObjMgr();
97if (om == NULL) return;
98if (nom == "") return;
99
100switch (msg)
101 {
102 case 100:
103 om->DisplayObj(nom);
104 break;
105 case 200:
106 om->PrintObj(nom);
107 break;
108 case 300:
109 if (dap->mPpfout) om->SaveObj(nom, *(dap->mPpfout));
110 break;
111 case 400:
112 om->DelObj(nom);
113 break;
114
115 case 900:
116 dap->SetReady();
117 Hide();
118 break;
119
120 default:
121 // printf("DEBUG/ObjMgrW::Process %d %d \n", (int)msg, (int)ssg);
122 break;
123 }
124
125return;
126}
127
128
129/* ........................................................... */
130/* Classe PPInMgrWind interface de gestion d'objets nommes */
131/* ........................................................... */
132
133/* --Methode-- */
134PPInMgrWind::PPInMgrWind(PIStdImgApp *par)
135: PIWindow((PIMsgHandler *)par, "PPF-FileManager", PIWK_dialog,
136 400, 300, 250, 250)
137{
138int i;
139dap = par;
140
141int bsx, bsy;
142int tsx, tsy;
143int spx, spy;
144// On definit la taille a partir de la taille par defaut des composantes
145PIApplicationPrefCompSize(bsx, bsy);
146spx = bsx/4; spy = bsy/3;
147bsx *= 1.25;
148ttx = tsx = 3*bsx+8*spx; tty = tsy = 7*bsy+5*spy;
149SetSize(tsx,tsy);
150
151mLab[0] = new PILabel(this, "filename", tsx-spx, bsy-spy, spx/2, spy/2);
152mLab[0]->SetLabel("");
153mLab[0]->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic,PIBK_elastic);
154mLab[0]->SetBorderWidth(1);
155
156polx = spx/2; poly = bsy+1.5*spy;
157tolx = tsx-spx; toly = tsy-2*bsy-5*spy;
158int py = tsy-2*spy-bsy;
159int px = 2*spx;
160mBut[0] = new PIButton(this, "Read", 2500, bsx, bsy, px, py); px += (bsx+2*spx);
161mBut[1] = new PIButton(this, "ReadAll", 2600, bsx, bsy, px, py); px += (bsx+2*spx);
162mBut[2] = new PIButton(this, "Close", 2700, bsx, bsy, px, py); px += (bsx+2*spx);
163
164for(i=0; i<3; i++)
165 mBut[i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
166
167objlist = NULL;
168mLab[1] = NULL;
169mPin = NULL;
170
171// FinishCreate(); pas necessaire
172}
173
174/* --Methode-- */
175PPInMgrWind::~PPInMgrWind()
176{
177int i;
178if (objlist) delete objlist;
179delete mLab[0];
180for(i=0; i<3; i++) delete mBut[i];
181}
182
183/* --Methode-- */
184void PPInMgrWind::SetFile(string flnm)
185{
186char strg[128];
187char* nom;
188char noms[32];
189int i, cid, key, ln;
190
191bool ok = true;
192
193TRY {
194 mPin = new PInPersist(flnm);
195} CATCH(merr)
196 { printf("ObjMgrWind::SetFile Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
197 ok = false; } ENDTRY;
198
199if (!ok) { mPin = NULL; dap->SetReady(); return; }
200
201if (mPin->NbTags() < 1) {
202 delete mPin; mPin = NULL;
203 dap->ObjMgr()->ReadObj(flnm);
204 return;
205}
206
207if (objlist) delete objlist;
208SetSize(ttx,tty);
209mLab[0]->SetLabel(flnm);
210objlist = new PIList(this, "infileobjlist", tolx, toly, polx, poly);
211objlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
212objlist->SetBorderWidth(2);
213
214
215for(i=0; i<mPin->NbTags(); i++) {
216 key = mPin->TagKey(i, cid, ln);
217 if (ln <= 0) nom = "?";
218 else { strncpy(noms, mPin->TagName(i).c_str(), 31); noms[31] = '\0'; nom = noms; }
219// sprintf(strg, "%s (T=%s, Key=%d)", nom, dap->ObjMgr()->GetServiceObj()->PClassIdToClassName(cid), key);
220 sprintf(strg, "%s (T=%s, Key=%d)", nom, " DataObject ?", key);
221 objlist->AppendItem(strg, 5000+i);
222}
223
224}
225
226/* --Methode-- */
227void PPInMgrWind::Show()
228{
229if (mPin == NULL) return;
230dap->SetBlocked();
231PIWindow::Show();
232return;
233}
234
235/* --Methode-- */
236void PPInMgrWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
237{
238
239int sel;
240msg = UserMsg(msg);
241
242if (msg == 2700) {
243 delete mPin; mPin = NULL;
244 delete objlist; objlist = NULL;
245 dap->SetReady();
246 this->Hide();
247 return;
248}
249
250NamedObjMgr* om = dap->ObjMgr();
251switch (msg)
252 {
253 case 2500:
254 sel = (PIMessage)objlist->GetSelection() - 5000;
255 if (sel >= 0) om->ReadObj((*mPin), sel);
256 break;
257 case 2600:
258 om->ReadObj((*mPin), -1);
259 dap->SetReady();
260 this->Hide();
261 break;
262
263 default:
264 break;
265 }
266
267return;
268}
Note: See TracBrowser for help on using the repository browser.