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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/VIEW/DIALOGS/raytraceableContourSurfaceDialog.h>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QLineEdit>
//#include <QtGui/qpushbutton.h>
#include <QtWidgets/QSlider>
#include <iostream>
namespace BALL
{
namespace VIEW
{
RaytraceableContourSurfaceDialog::RaytraceableContourSurfaceDialog(RaytraceableGrid* grid, QWidget* parent, const char* name, bool, Qt::WindowFlags fl )
: QDialog(parent, fl),
Ui_RaytraceableContourSurfaceDialogData(),
ModularWidget(name),
grid_(grid)
{
std::cout << "Constructor RT_CS_Dialog " << std::endl;
setupUi(this);
//setINIFileSectionName("Raytracing");
setObjectName(name);
registerWidget(this);
setObjectName(name);
// signals and slots connections
// Contour Threshold Range
connect( OK_button, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( cancel_button , SIGNAL( clicked() ), this, SLOT( reject() ) );
connect( add_button, SIGNAL( clicked() ), this, SLOT( add() ) );
connect( ContourSurfaceThresholdSlider, SIGNAL( valueChanged(int) ), this, SLOT( changedSliderThreshold(int) ) );
connect( ContourSurfaceThresholdLineEdit, SIGNAL( editingFinished() ), this, SLOT( changedEditThreshold() ) );
// Contour Threshold Range
connect( autoRangeButton, SIGNAL( clicked() ), this, SLOT ( setDefaultRangeValues_() ) );
connect( RangeLineEdit_min, SIGNAL( editingFinished() ), this, SLOT(changedRangeMin()) );
connect( RangeLineEdit_max, SIGNAL( editingFinished() ), this, SLOT(changedRangeMax()) );
connect( RangeLineEdit_steps, SIGNAL( editingFinished() ), this, SLOT(changedRangeSteps()) );
OK_button->setEnabled(true);
add_button->setEnabled(true);
cancel_button->setEnabled(true);
autoRangeButton->setEnabled(true);
// initialize slider and editLine
if (grid_ != 0)
{
setDefaultRangeValues_();
}
else
{
Log.error() << (String)tr("The grid is not valid") << std::endl;
}
}
RaytraceableContourSurfaceDialog::~RaytraceableContourSurfaceDialog()
{
// TODO
}
void RaytraceableContourSurfaceDialog::setDefaultRangeValues_()
{
//Log.info() << " setDefaultValues" << std::endl;
min_ = grid_->getGridMinValue();
max_ = grid_->getGridMaxValue();
current_threshold_ = (min_+ max_)/2.;
steps_ = 50;
QString str = QString("%1").arg((double)current_threshold_, 0,'g',3);
ContourSurfaceThresholdLineEdit->setText(str);
ContourSurfaceThresholdSlider->setRange(0,steps_);
ContourSurfaceThresholdSlider->setSliderPosition(steps_/2);
str = QString("%1").arg((double)max_, 0, 'g', 3);
RangeLineEdit_max->setText(str);
str = QString("%1").arg((double)min_, 0, 'g', 3);
RangeLineEdit_min->setText(str);
str = QString("%1").arg((double)steps_, 0, 'g', 3);
RangeLineEdit_steps->setText(str);
str = QString("%1").arg((double)current_threshold_, 0, 'g', 3);
ContourSurfaceThresholdLineEdit->setText(str);
}
void RaytraceableContourSurfaceDialog::add()
{
//std::cout << " model reated- close()" << std::endl;
//double new_threshold = 3.;
//addModel_(new_threshold);
addModel_(current_threshold_);
}
void RaytraceableContourSurfaceDialog::accept()
{
//std::cout << "new model created - waiting()" << std::endl;
// get the new threshold
//double new_threshold = 3.;
//addModel_(new_threshold);
addModel_(current_threshold_);
QDialog::accept();
}
void RaytraceableContourSurfaceDialog::reject()
{
// std::cout << "no model reated- close()" << std::endl;
QDialog::reject();
}
void RaytraceableContourSurfaceDialog::changedSliderThreshold(int sliderpos)
{
//std::cout << "call slider changed! " << std::endl;
current_threshold_ = min_ + (float)((max_ - min_)/steps_) * (float)sliderpos;
QString str = QString("%1").arg((double)current_threshold_, 0, 'g', 3);
ContourSurfaceThresholdLineEdit->setText(str);
}
void RaytraceableContourSurfaceDialog::changedEditThreshold()
{
// std::cout << "call edit th changed !" << std::endl;
float new_threshold = getValue_(ContourSurfaceThresholdLineEdit);
if (new_threshold > max_)
{
// ToDo: are there other restrictions??
// ToDo: appropriate error/info message
current_threshold_ = max_;
QString str = QString("%1").arg((double)current_threshold_, 0,'g',3);
ContourSurfaceThresholdLineEdit->setText(str);
}
else if(new_threshold < min_ )
{
current_threshold_ = min_;
QString str = QString("%1").arg((double)current_threshold_, 0,'g',3);
ContourSurfaceThresholdLineEdit->setText(str);
}
else
{
current_threshold_ = new_threshold;
}
// update the slider
ContourSurfaceThresholdSlider->setSliderPosition((int) ((current_threshold_-min_)/(max_ - min_) * steps_));
}
void RaytraceableContourSurfaceDialog::addModel_(float /*threshold*/)
{
// TODO: create a new model and add it to the representationlist
}
void RaytraceableContourSurfaceDialog::changedRangeMin()
{
//std::cout << "call min changed" << std::endl;
min_= getValue_(RangeLineEdit_min);
if (current_threshold_ < min_)
{
current_threshold_ = min_;
// update the value LineEdit
QString str = QString("%1").arg((double)current_threshold_, 0, 'g', 3);
ContourSurfaceThresholdLineEdit->setText(str);
}
// update the values slider
ContourSurfaceThresholdSlider->setSliderPosition((int) ((current_threshold_-min_)/(max_ - min_) * steps_));
}
void RaytraceableContourSurfaceDialog::changedRangeMax()
{
//std::cout << "call max changed" << std::endl;
max_= getValue_(RangeLineEdit_max);
if (current_threshold_ > max_)
{
current_threshold_ = max_;
// update the value LineEdit
QString str = QString("%1").arg((double)current_threshold_, 0, 'g', 3);
ContourSurfaceThresholdLineEdit->setText(str);
}
// update the value slider
ContourSurfaceThresholdSlider->setSliderPosition((int) ((current_threshold_-min_)/(max_ - min_) * steps_));
}
void RaytraceableContourSurfaceDialog::changedRangeSteps()
{
//std::cout << "call steps changed" << std::endl;
int new_steps = (int)getValue_(RangeLineEdit_steps);
if (new_steps < 1)
{
steps_ = 1; //(int)(max_ - min_);
QString str = QString("%1").arg((double)steps_, 0, 'g', 3);
RangeLineEdit_steps->setText(str);
// TO DO: appropriate error/info message??
}
else
{
steps_= new_steps;
}
// update the range and value slider
ContourSurfaceThresholdSlider->setRange(0,(int)steps_);
ContourSurfaceThresholdSlider->setSliderPosition((int) ((current_threshold_-min_)/(max_ - min_) * steps_));
}
float RaytraceableContourSurfaceDialog::getValue_(const QAbstractSlider* slider) const
{
return(slider->value());
}
float RaytraceableContourSurfaceDialog::getValue_(const QLineEdit* edit) const
{
return (edit->text()).toFloat();
}
} // VIEW and BALL namespace:
}
|