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