| 1 | /* |
| 2 | * File: MainPanelClassic.cpp |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Oct 28, 2010 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id: MainPanel.cpp 67 2010-09-13 14:06:31Z dekeljacob $ |
| 9 | * |
| 10 | * This program is free software: you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation, either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "HerculesStudio.h" |
| 26 | #include "MainPanelClassic.h" |
| 27 | #include "Environment.h" |
| 28 | #include "PanelButton.h" |
| 29 | #include "Preferences.h" |
| 30 | #include "MipsLed.h" |
| 31 | #include "MipsGauge.h" |
| 32 | |
| 33 | #include <sstream> |
| 34 | |
| 35 | |
| 36 | MainPanelClassic::MainPanelClassic(QWidget *parent) |
| 37 | : MainPanel(parent) |
| 38 | { |
| 39 | setupUi(parent); |
| 40 | setLoadAddress(Preferences::getInstance().iplDevice().c_str()); |
| 41 | doConnect(); |
| 42 | } |
| 43 | |
| 44 | MainPanelClassic::~MainPanelClassic() |
| 45 | { |
| 46 | delete mMips; |
| 47 | delete mYellowLow; |
| 48 | delete mYellowHigh; |
| 49 | } |
| 50 | |
| 51 | void MainPanelClassic::setupUi(QWidget *) |
| 52 | { |
| 53 | const QColor black(50,50,50); |
| 54 | const QColor white(255,255,20); |
| 55 | QBrush blackBrush(black); |
| 56 | QPalette blackPalette(white, black); |
| 57 | this->setPalette(blackPalette); |
| 58 | this->setAutoFillBackground(true); |
| 59 | |
| 60 | QString iconsPath = Environment::getIconsPath().c_str(); |
| 61 | mPowerOnButton = new PanelButton(iconsPath + "/poweronoffu.gif", iconsPath + "/poweronoffd.gif", this); |
| 62 | mPowerOffButton = new PanelButton(iconsPath + "/poweroffu.gif", iconsPath + "/poweroffd.gif", this); |
| 63 | mInterruptButton = new PanelButton(iconsPath + "/interruptu.gif", iconsPath + "/interruptd.gif", this); |
| 64 | mLoadButton = new PanelButton(iconsPath + "/loadu.gif", iconsPath + "/loadd.gif", this); |
| 65 | |
| 66 | mRestartButton = new PanelButton(iconsPath + "/restartu.gif", iconsPath + "/restartd.gif", this); |
| 67 | mStoreButton = new PanelButton(iconsPath + "/storeu.gif", iconsPath + "/stored.gif", this); |
| 68 | mStopButton = new PanelButton(iconsPath + "/stopu.gif", iconsPath + "/stopd.gif", this); |
| 69 | mStartButton = new PanelButton(iconsPath + "/startu.gif", iconsPath + "/startd.gif", this); |
| 70 | |
| 71 | mPowerOnButton->setToolTip("Power On"); |
| 72 | mPowerOffButton->setToolTip("Power Off"); |
| 73 | mInterruptButton->setToolTip("Interrupt"); |
| 74 | mLoadButton->setToolTip("Load (IPL)"); |
| 75 | mRestartButton->setToolTip("Restart"); |
| 76 | mStoreButton->setToolTip("Store"); |
| 77 | mStopButton->setToolTip("Stop all CPUs"); |
| 78 | mStartButton->setToolTip("Start all CPUs"); |
| 79 | |
| 80 | QFont font; |
| 81 | font.setPointSize(6); |
| 82 | mSys = new QLabel(this); |
| 83 | mSys->setPixmap(*mYellowLow); |
| 84 | mSysText = new QLabel("SYS",this); |
| 85 | mSysText->setFont(font); |
| 86 | mMan = new QLabel(this); |
| 87 | mMan->setPixmap(*mYellowLow); |
| 88 | mManText = new QLabel("MAN",this); |
| 89 | mManText->setFont(font); |
| 90 | mWait = new QLabel(this); |
| 91 | mWait->setPixmap(*mYellowLow); //path = iconsPath + "/yellowhigh.png"; |
| 92 | |
| 93 | mPSW = new QLabel(this); |
| 94 | QFont pswFont("Mono", 10); |
| 95 | mPSW->setFont(pswFont); |
| 96 | |
| 97 | mWaitText = new QLabel("WAIT",this); |
| 98 | mWaitText->setFont(font); |
| 99 | mLoad = new QLabel(this); |
| 100 | mLoad->setPixmap(*mYellowLow); |
| 101 | mLoadText = new QLabel("LOAD",this); |
| 102 | mLoadText->setFont(font); |
| 103 | mLcd0 = new QLCDNumber(1,this);; |
| 104 | mLcd0->setSegmentStyle(QLCDNumber::Flat); |
| 105 | mLcd0->setFrameStyle(QFrame::NoFrame); |
| 106 | mLcd0->resize(20,20); |
| 107 | mLcd0->setMode(QLCDNumber::Hex); |
| 108 | mLcd1 = new QLCDNumber(1,this); |
| 109 | mLcd1->setSegmentStyle(QLCDNumber::Flat); |
| 110 | mLcd1->setFrameStyle(QFrame::NoFrame); |
| 111 | mLcd1->resize(20,20); |
| 112 | mLcd1->setMode(QLCDNumber::Hex); |
| 113 | mLcd2 = new QLCDNumber(1,this); |
| 114 | mLcd2->setSegmentStyle(QLCDNumber::Flat); |
| 115 | mLcd2->setFrameStyle(QFrame::NoFrame); |
| 116 | mLcd2->resize(20,20); |
| 117 | mLcd2->setMode(QLCDNumber::Hex); |
| 118 | mLcd3 = new QLCDNumber(1,this); |
| 119 | mLcd3->setSegmentStyle(QLCDNumber::Flat); |
| 120 | mLcd3->setFrameStyle(QFrame::NoFrame); |
| 121 | mLcd3->resize(20,20); |
| 122 | mLcd3->setMode(QLCDNumber::Hex); |
| 123 | |
| 124 | QString path = Environment::getIconsPath().c_str(); |
| 125 | QPixmap pixMap(path + "/dial1.gif"); |
| 126 | mDial0 = new ClickLabel(this,mLcd0); |
| 127 | mDial0->setPixmap(pixMap); |
| 128 | mDial1 = new ClickLabel(this,mLcd1); |
| 129 | mDial1->setPixmap(pixMap); |
| 130 | mDial2 = new ClickLabel(this,mLcd2); |
| 131 | mDial2->setPixmap(pixMap); |
| 132 | mDial3 = new ClickLabel(this,mLcd3); |
| 133 | mDial3->setPixmap(pixMap); |
| 134 | |
| 135 | mDial0->setToolTip("Click to select IPL address"); |
| 136 | mDial1->setToolTip("Click to select IPL address"); |
| 137 | mDial2->setToolTip("Click to select IPL address"); |
| 138 | mDial3->setToolTip("Click to select IPL address"); |
| 139 | |
| 140 | if (Preferences::getInstance().mipsAsGauge()) |
| 141 | mMips = new MipsGauge(this); |
| 142 | else |
| 143 | mMips = new MipsLed(this); |
| 144 | mMips->setActive(false); |
| 145 | } |
| 146 | |
| 147 | void MainPanelClassic::resizeEvent(QResizeEvent * ) |
| 148 | { |
| 149 | int width = this->size().rwidth(); |
| 150 | mPowerOnButton->move(width-90,15); |
| 151 | mPowerOffButton->move(width-50,15); |
| 152 | mInterruptButton->move(width-90,45); |
| 153 | mLoadButton->move(width-50,45); |
| 154 | mRestartButton->move(width-510,15); |
| 155 | mStoreButton->move(width-550,15); |
| 156 | mStopButton->move(width-510,45); |
| 157 | mStartButton->move(width-550,45); |
| 158 | |
| 159 | mSys->move(width-200,60); |
| 160 | mSysText->move(width-200,50); |
| 161 | mMan->move(width-172,60); |
| 162 | mManText->move(width-172,50); |
| 163 | mWait->move(width-144,60); |
| 164 | mWaitText->move(width-144,50); |
| 165 | mLoad->move(width-116,60); |
| 166 | mLoadText->move(width-116,50); |
| 167 | |
| 168 | mLcd0->move(width-250,5); |
| 169 | mLcd1->move(width-310,5); |
| 170 | mLcd2->move(width-370,5); |
| 171 | mLcd3->move(width-430,5); |
| 172 | |
| 173 | mDial0->move(width-270,30); |
| 174 | mDial1->move(width-330,30); |
| 175 | mDial2->move(width-390,30); |
| 176 | mDial3->move(width-450,30); |
| 177 | |
| 178 | mMips->move(width-680,20); |
| 179 | |
| 180 | mPSW->setGeometry(width-550,110,48*12,12); |
| 181 | |
| 182 | } |
| 183 | |
| 184 | void MainPanelClassic::updateLcd(QLCDNumber * lcd, int inc) |
| 185 | { |
| 186 | lcd->display(lcd->intValue()+inc); |
| 187 | if (lcd->intValue() > 15) |
| 188 | lcd->display(0); |
| 189 | if (lcd->intValue() < 0) |
| 190 | lcd->display(15); |
| 191 | hOutDebug(5,"update " << lcd->intValue()); |
| 192 | } |
| 193 | |
| 194 | |
| 195 | void MainPanelClassic::setDormant() |
| 196 | { |
| 197 | mMips->setActive(false); |
| 198 | QString iconsPath = Environment::getIconsPath().c_str(); |
| 199 | ((PanelButton *)mPowerOnButton)->replaceButton(iconsPath + "/poweronoffu.gif", iconsPath + "/poweronoffd.gif"); |
| 200 | } |
| 201 | |
| 202 | void MainPanelClassic::standby() |
| 203 | { |
| 204 | mMips->setActive(true); |
| 205 | QString iconsPath = Environment::getIconsPath().c_str(); |
| 206 | ((PanelButton *)mPowerOnButton)->replaceButton(iconsPath + "/powerononu.gif", iconsPath + "/poweronond.gif"); |
| 207 | } |
| 208 | |
| 209 | bool MainPanelClassic::notify(const QByteArray& statusLine) |
| 210 | { |
| 211 | bool ret = true; |
| 212 | if (statusLine.startsWith("SYS=")) |
| 213 | { |
| 214 | QChar sysVal = statusLine[4]; |
| 215 | if (sysVal == '1') |
| 216 | mSys->setPixmap(*mYellowHigh); |
| 217 | else |
| 218 | mSys->setPixmap(*mYellowLow); |
| 219 | |
| 220 | } |
| 221 | else if (statusLine.startsWith("LOAD=")) |
| 222 | { |
| 223 | QChar sysVal = statusLine[4]; |
| 224 | if (sysVal == '1') |
| 225 | mLoad->setPixmap(*mYellowHigh); |
| 226 | else |
| 227 | mLoad->setPixmap(*mYellowLow); |
| 228 | |
| 229 | } |
| 230 | else if (statusLine.startsWith("MIPS=")) |
| 231 | { |
| 232 | double d = statusLine.mid(5).toDouble(); |
| 233 | if (d > mMipsHWM) |
| 234 | { |
| 235 | mMipsHWM = d; |
| 236 | std::stringstream ss; |
| 237 | ss << "High Water Mark:" << d; |
| 238 | mMips->setToolTip(ss.str().c_str()); |
| 239 | } |
| 240 | mMips->display(d); |
| 241 | } |
| 242 | //STATUS=CPU0000 PSW=00000000 00000000 0000000000000000 M.W..... instcount=0 |
| 243 | else if ( (statusLine.startsWith("STATUS=")) && (statusLine.length() > 56) ) |
| 244 | { |
| 245 | if (statusLine[54] == 'M') |
| 246 | mMan->setPixmap(*mYellowHigh); |
| 247 | else |
| 248 | mMan->setPixmap(*mYellowLow); |
| 249 | |
| 250 | if (statusLine[56] == 'W') |
| 251 | mWait->setPixmap(*mYellowHigh); |
| 252 | else |
| 253 | mWait->setPixmap(*mYellowLow); |
| 254 | } |
| 255 | else ret = false; |
| 256 | |
| 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | void MainPanelClassic::switchMips() |
| 261 | { |
| 262 | bool updated = false; |
| 263 | if (Preferences::getInstance().mipsAsGauge()) |
| 264 | { |
| 265 | MipsLed * oldMips = dynamic_cast<MipsLed *>(mMips); |
| 266 | if (oldMips != NULL) |
| 267 | { |
| 268 | Mips * gauge = new MipsGauge(this); |
| 269 | mMips = gauge; |
| 270 | mMips->setToolTip(oldMips->toolTip()); |
| 271 | oldMips->deleteLater(); |
| 272 | updated = true; |
| 273 | } |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | MipsGauge * oldMips = dynamic_cast<MipsGauge *>(mMips); |
| 278 | if (oldMips != NULL) |
| 279 | { |
| 280 | Mips * lcd = new MipsLed(this); |
| 281 | mMips = lcd; |
| 282 | mMips->setToolTip(oldMips->toolTip()); |
| 283 | oldMips->deleteLater(); |
| 284 | updated = true; |
| 285 | } |
| 286 | } |
| 287 | if (updated) |
| 288 | { |
| 289 | mMips->setActive(true); |
| 290 | int width = this->size().rwidth(); |
| 291 | mMips->move(width-680,20); |
| 292 | } |
| 293 | |
| 294 | } |
| 295 | |
| 296 | |
| 297 | |
| 298 | QSize MainPanelClassic::sizeHint() const |
| 299 | { |
| 300 | return QSize(100, 100); |
| 301 | } |
| 302 | |
| 303 | bool MainPanelClassic::isStopped() const |
| 304 | { |
| 305 | return mStopped; |
| 306 | } |
| 307 | |
| 308 | template<class T> void MainPanelClassic::animateOne(int x, int y, T* button, int step) |
| 309 | { |
| 310 | for (int i = 0; i<=x; i+=step) |
| 311 | { |
| 312 | button->move(i,y); |
| 313 | this->repaint(); |
| 314 | } |
| 315 | button->move(x,y); |
| 316 | } |
| 317 | |
| 318 | void MainPanelClassic::animate() |
| 319 | { |
| 320 | int width = this->size().rwidth(); |
| 321 | |
| 322 | mPowerOnButton->move(width,15); |
| 323 | mPowerOffButton->move(width,15); |
| 324 | mInterruptButton->move(width,45); |
| 325 | mLoadButton->move(width,45); |
| 326 | mRestartButton->move(width,15); |
| 327 | mStoreButton->move(width,15); |
| 328 | mStopButton->move(width,45); |
| 329 | mStartButton->move(width,45); |
| 330 | |
| 331 | mDial0->move(width,30); |
| 332 | mDial1->move(width,30); |
| 333 | mDial2->move(width,30); |
| 334 | mDial3->move(width,30); |
| 335 | |
| 336 | mStoreButton->move(width,15); |
| 337 | mStopButton->move(width,45); |
| 338 | mStartButton->move(width,45); |
| 339 | |
| 340 | mLcd0->move(width,5); |
| 341 | mLcd1->move(width,5); |
| 342 | mLcd2->move(width,5); |
| 343 | mLcd3->move(width,5); |
| 344 | |
| 345 | mSys->move(width,60); |
| 346 | mSysText->move(width,50); |
| 347 | mMan->move(width,60); |
| 348 | mManText->move(width,50); |
| 349 | mWait->move(width,60); |
| 350 | mWaitText->move(width,50); |
| 351 | mLoad->move(width,60); |
| 352 | mLoadText->move(width,50); |
| 353 | |
| 354 | |
| 355 | animateOne(width-90,15,mPowerOnButton,5); |
| 356 | animateOne(width-50,15,mPowerOffButton,5); |
| 357 | animateOne(width-90,45,mInterruptButton,5); |
| 358 | animateOne(width-50,45,mLoadButton,5); |
| 359 | |
| 360 | animateOne(width-510,15,mRestartButton,5); |
| 361 | mStoreButton->move(width-550,15); |
| 362 | mStopButton->move(width-510,45); |
| 363 | mStartButton->move(width-550,45); |
| 364 | |
| 365 | animateOne(width-270,30,mDial0,2); |
| 366 | animateOne(width-330,30,mDial1,15); |
| 367 | animateOne(width-390,30,mDial2,15); |
| 368 | animateOne(width-450,30,mDial3,15); |
| 369 | |
| 370 | mSys->move(width-200,60); |
| 371 | mSysText->move(width-200,50); |
| 372 | mMan->move(width-172,60); |
| 373 | mManText->move(width-172,50); |
| 374 | mWait->move(width-144,60); |
| 375 | mWaitText->move(width-144,50); |
| 376 | mLoad->move(width-116,60); |
| 377 | mLoadText->move(width-116,50); |
| 378 | |
| 379 | mLcd0->move(width-250,5); |
| 380 | mLcd1->move(width-310,5); |
| 381 | mLcd2->move(width-370,5); |
| 382 | mLcd3->move(width-430,5); |
| 383 | |
| 384 | mMips->move(width-680,20); |
| 385 | |
| 386 | } |