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