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

Last change on this file since 179 was 165, checked in by ercodmgr, 27 years ago

Creation du module PIext en regroupant des fichiers de Drawer/Wdg pour
Objets ds PEIDA/Outils++, Images++, ... et des classes de ProgPI,
lie a piapp (PIStdImgApp, NamedObjMgr, ...) Reza 18/12/98

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