Skip to content

Commit cca8d88

Browse files
committed
Attempt at cleaning up module color change logic--needs redo
1 parent a9e47f4 commit cca8d88

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

src/Interface/Application/GuiApplication.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ int GuiApplication::run(int argc, const char* argv[])
4949
}
5050
catch (std::exception& e)
5151
{
52-
QMessageBox::critical(0, "Critical error", "Unhandled exception: " + QString(e.what()) + "\nExiting now.");
52+
//QMessageBox::critical(0, "Critical error", "Unhandled exception: " + QString(e.what()) + "\nExiting now.");
53+
std::cout << "Unhandled exception: " << e.what() << std::endl;
5354
return 1;
5455
}
5556
catch (...)
5657
{
57-
QMessageBox::critical(0, "Critical error", "Unknown unhandled exception: exiting now.");
58+
//QMessageBox::critical(0, "Critical error", "Unknown unhandled exception: exiting now.");
59+
std::cout << "Unhandled exception: Unknown" << std::endl;
5860
return 1;
5961
}
6062
}

src/Interface/Application/ModuleWidget.cc

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ void ModuleWidgetDisplayMini::setupButtons(bool hasUI, QObject* module)
399399

400400
void ModuleWidgetDisplayMini::setupIcons()
401401
{
402-
402+
403403
}
404404

405405
QAbstractButton* ModuleWidgetDisplayMini::getOptionsButton() const
@@ -447,6 +447,20 @@ void ModuleWidgetDisplayMini::adjustLayout(QLayout* layout)
447447
// #endif
448448
}
449449

450+
static const int UNSET = -1;
451+
static const int SELECTED = -50;
452+
static const int ERRORED = -100;
453+
static bool isUnsetOrSelected(int state)
454+
{
455+
return UNSET == state || SELECTED == state;
456+
}
457+
458+
typedef boost::bimap<QString, int> ColorStateLookup;
459+
typedef ColorStateLookup::value_type ColorStatePair;
460+
static ColorStateLookup colorStateLookup;
461+
void fillColorStateLookup(const QString& background);
462+
463+
450464
ModuleWidget::ModuleWidget(NetworkEditor* ed, const QString& name, SCIRun::Dataflow::Networks::ModuleHandle theModule, boost::shared_ptr<SCIRun::Gui::DialogErrorControl> dialogErrorControl,
451465
QWidget* parent /* = 0 */)
452466
: QStackedWidget(parent), HasNotes(theModule->get_id(), true),
@@ -459,6 +473,7 @@ ModuleWidget::ModuleWidget(NetworkEditor* ed, const QString& name, SCIRun::Dataf
459473
isMini_(globalMiniMode_),
460474
errored_(false),
461475
theModule_(theModule),
476+
previousModuleState_(UNSET),
462477
moduleId_(theModule->get_id()),
463478
dialog_(nullptr),
464479
dockable_(nullptr),
@@ -472,6 +487,8 @@ ModuleWidget::ModuleWidget(NetworkEditor* ed, const QString& name, SCIRun::Dataf
472487
miniIndex_(0),
473488
isViewScene_(name == "ViewScene")
474489
{
490+
fillColorStateLookup(defaultBackgroundColor_);
491+
475492
setupModuleActions();
476493
setupLogging();
477494

@@ -932,7 +949,10 @@ void ModuleWidget::trackConnections()
932949
void ModuleWidget::execute()
933950
{
934951
{
952+
//qDebug() << "executing()";
935953
errored_ = false;
954+
//previousModuleState_ = (int)ModuleInterface::Completed;
955+
//std::cout << "execute() prev = " << previousModuleState_ << std::endl;
936956
//colorLocked_ = true; //TODO
937957
timer_.restart();
938958
theModule_->do_execute();
@@ -957,31 +977,60 @@ boost::signals2::connection ModuleWidget::connectErrorListener(const ErrorSignal
957977
return theModule_->connectErrorListener(subscriber);
958978
}
959979

980+
void fillColorStateLookup(const QString& background)
981+
{
982+
if (colorStateLookup.empty())
983+
{
984+
colorStateLookup.insert(ColorStatePair(moduleRGBA(205,190,112), (int)ModuleInterface::Waiting));
985+
colorStateLookup.insert(ColorStatePair(moduleRGBA(170,204,170), (int)ModuleInterface::Executing));
986+
colorStateLookup.insert(ColorStatePair(background, (int)ModuleInterface::Completed));
987+
colorStateLookup.insert(ColorStatePair(moduleRGBA(0,255,255), SELECTED));
988+
colorStateLookup.insert(ColorStatePair(moduleRGBA(176, 23, 31), ERRORED));
989+
}
990+
}
991+
992+
//primitive state machine
993+
//TODO: slot should set previousModuleState_
960994
void ModuleWidget::updateBackgroundColorForModuleState(int moduleState)
961995
{
996+
//qDebug() << "updateColor to " << moduleState;
997+
//std::cout << "update prev = " << previousModuleState_ << std::endl;
962998
switch (moduleState)
963999
{
9641000
case (int)ModuleInterface::Waiting:
965-
Q_EMIT backgroundColorUpdated(moduleRGBA(205,190,112));
1001+
if (isUnsetOrSelected(previousModuleState_) || previousModuleState_ == (int)ModuleInterface::Completed)
1002+
{
1003+
Q_EMIT backgroundColorUpdated(moduleRGBA(205,190,112));
1004+
}
9661005
break;
9671006
case (int)ModuleInterface::Executing:
968-
Q_EMIT backgroundColorUpdated(moduleRGBA(170,204,170));
1007+
if (isUnsetOrSelected(previousModuleState_) || previousModuleState_ == (int)ModuleInterface::Waiting)
1008+
{
1009+
Q_EMIT backgroundColorUpdated(moduleRGBA(170,204,170));
1010+
}
9691011
break;
9701012
case (int)ModuleInterface::Completed:
971-
if (!errored_)
972-
Q_EMIT backgroundColorUpdated(defaultBackgroundColor_);
1013+
//if (isUnsetOrSelected(previousModuleState_) || previousModuleState_ == (int)ModuleInterface::Executing)
1014+
{
1015+
if (!errored_)
1016+
Q_EMIT backgroundColorUpdated(defaultBackgroundColor_);
1017+
}
9731018
break;
9741019
}
9751020
}
9761021

9771022
void ModuleWidget::updateBackgroundColor(const QString& color)
9781023
{
1024+
//std::cout << "color set to: " << color.toStdString() << std::endl;
9791025
if (!colorLocked_)
9801026
{
9811027
QString rounded;
9821028
if (SCIRunMainWindow::Instance()->newInterface())
9831029
rounded = "color: white; border-radius: 7px;";
9841030
setStyleSheet(rounded + " background-color: " + color);
1031+
//qDebug() << "looking up color: " << color << "\n";
1032+
previousModuleState_ = colorStateLookup.left.at(color);
1033+
//qDebug() << "state set to: " << previousModuleState_;
9851034
}
9861035
}
9871036

@@ -1209,4 +1258,4 @@ void ModuleWidget::changeDisplay(int oldIndex, int newIndex)
12091258
setCurrentIndex(newIndex);
12101259
resize(size);
12111260
Q_EMIT displayChanged();
1212-
}
1261+
}

src/Interface/Application/ModuleWidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ private Q_SLOTS:
182182
bool isMini_, errored_;
183183

184184
SCIRun::Dataflow::Networks::ModuleHandle theModule_;
185+
std::atomic<int> previousModuleState_;
185186

186187
void addPorts(int index);
187188
void createPorts(const SCIRun::Dataflow::Networks::ModuleInfoProvider& moduleInfoProvider);
@@ -223,7 +224,7 @@ private Q_SLOTS:
223224
bool deleting_;
224225
const QString defaultBackgroundColor_;
225226
int fullIndex_, miniIndex_;
226-
bool isViewScene_; //TODO: lots of special logic around this case.
227+
bool isViewScene_; //TODO: lots of special logic around this case.
227228

228229
static bool globalMiniMode_;
229230
};

0 commit comments

Comments
 (0)