1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/VIEW/DIALOGS/assignBondOrderConfigurationDialog.h>
#include <BALL/VIEW/KERNEL/common.h>
#include <BALL/VIEW/KERNEL/mainControl.h>
#include <BALL/SYSTEM/path.h>
#include <BALL/STRUCTURE/assignBondOrderProcessor.h>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QRadioButton>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QFileDialog>
namespace BALL
{
namespace VIEW
{
AssignBondOrderConfigurationDialog::AssignBondOrderConfigurationDialog(QWidget* parent, const char* name)
: QDialog(parent),
Ui_AssignBondOrderConfigurationDialogData(),
ModularWidget(name),
PreferencesEntry()
{
setupUi(this);
setINIFileSectionName("BONDORDERASSIGNER");
setObjectName(name);
// for preferences
registerWidgets_();
// for actions, icons...
ModularWidget::registerWidget(this);
hide();
// signals and slots connections
connect( browse_button, SIGNAL( clicked() ), this, SLOT( browseParameterFiles_() ) );
connect( penalty_balance_slider, SIGNAL( valueChanged(int) ), this, SLOT( balanceParameterChanged_() ) );
connect(overwrite_singleBO_box, SIGNAL(stateChanged(int)), this, SLOT(validateBOBoxes_()));
connect(overwrite_doubleBO_box, SIGNAL(stateChanged(int)), this, SLOT(validateBOBoxes_()));
connect(overwrite_tripleBO_box, SIGNAL(stateChanged(int)), this, SLOT(validateBOBoxes_()));
connect(overwrite_selected_bonds_box, SIGNAL(stateChanged(int)), this, SLOT(validateBOBoxes_()));
connect(ASTAR_button, SIGNAL(clicked()), this, SLOT(validateStrategies_()));
connect(ILP_button, SIGNAL(clicked()), this, SLOT(validateStrategies_()));
connect(FPT_button, SIGNAL(clicked()), this, SLOT(validateStrategies_()));
connect(all_optimal_solutions_button, SIGNAL(clicked()), this, SLOT(validateStrategies_()));
validateBOBoxes_();
validateStrategies_();
#ifndef BALL_HAS_LPSOLVE
ILP_button->setEnabled(false);
ILP_button->setChecked(false);
ASTAR_button->setChecked(true);
#endif
}
AssignBondOrderConfigurationDialog::~AssignBondOrderConfigurationDialog()
{
}
void AssignBondOrderConfigurationDialog::balanceParameterChanged_()
{
atom_type_penalty_label->setText(String((int)(100 - penalty_balance_slider->value())).c_str());
bond_length_penalty_label ->setText(String(penalty_balance_slider->value()).c_str());
}
void AssignBondOrderConfigurationDialog::validateBOBoxes_()
{
// if one of the bond orders is checked, the "selected" box must be
// de-activated and vice versa
bool selected_checked = overwrite_selected_bonds_box->isChecked();
if (selected_checked)
{
overwrite_singleBO_box->setChecked(!selected_checked);
overwrite_doubleBO_box->setChecked(!selected_checked);
overwrite_tripleBO_box->setChecked(!selected_checked);
}
overwrite_singleBO_box->setDisabled(selected_checked);
overwrite_doubleBO_box->setDisabled(selected_checked);
overwrite_tripleBO_box->setDisabled(selected_checked);
}
void AssignBondOrderConfigurationDialog::validateStrategies_()
{
// if the FPT strategy is selected we have to disable some functionality
bool FPT_clicked = FPT_button->isChecked();
bool ILP_clicked = ILP_button->isChecked();
bool touched = FPT_clicked || ILP_clicked;
if (touched)
{
add_hydrogens_checkBox->setChecked(!touched);
penalty_balance_slider->setValue(0);
}
hydrogen_check_options->setDisabled(touched);
bond_length_groupBox->setDisabled(touched);
ASTAR_groupBox->setDisabled(touched);
if (FPT_clicked)
{
all_optimal_solutions_button->setChecked(!FPT_clicked);
n_opt_solutions_button->setChecked(FPT_clicked);
overwrite_singleBO_box->setChecked(FPT_clicked);
overwrite_doubleBO_box->setChecked(FPT_clicked);
overwrite_tripleBO_box->setChecked(FPT_clicked);
overwrite_selected_bonds_box->setChecked(!FPT_clicked);
}
all_optimal_solutions_button->setDisabled(FPT_clicked);
restrictions_groupBox->setDisabled(FPT_clicked);
}
void AssignBondOrderConfigurationDialog::browseParameterFiles_()
{
// look up the full path of the parameter file
Path p;
String filename = p.find(ascii(parameter_file_edit->text()));
if (filename == "")
{
filename = ascii(parameter_file_edit->text());
}
QString tmp = filename.c_str();
QString result = QFileDialog::getOpenFileName(0, tr("Select the penalty parameter file"), tmp, "*.xml");
if (!result.isEmpty())
{
// store the new filename in the lineedit field
parameter_file_edit->setText(result);
}
}
void AssignBondOrderConfigurationDialog::reject()
{
hide();
PreferencesEntry::restoreValues();
}
void AssignBondOrderConfigurationDialog::accept()
{
hide();
PreferencesEntry::storeValues();
QDialog::accept();
}
String AssignBondOrderConfigurationDialog::getValue_(const QCheckBox* box) const
{
if (box->isChecked())
return "true";
else
return "false";
}
float AssignBondOrderConfigurationDialog::getValue_(const QLineEdit* edit) const
{
return ascii(edit->text()).toFloat();
}
void AssignBondOrderConfigurationDialog::initializeWidget(MainControl&)
{
}
void AssignBondOrderConfigurationDialog::dialogButtonClicked_(QAbstractButton* button)
{
if(!button) {
return;
}
switch(buttonBox->buttonRole(button)){
case QDialogButtonBox::ResetRole:
resetOptions();
break;
default:
return;
}
}
void AssignBondOrderConfigurationDialog::resetOptions()
{
PreferencesEntry::restoreDefaultValues();
}
}//namespace VIEW
}//namespace BALL
|