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