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