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