1 /** @file chooseRanges.cpp
2 @package snark14Display
3 @author Bruno M. Carvalho and Deniz Sarioz
4 licensed under (open-source) QPL v1.0
5 which accompanies this distribution in the file QPL
12 #include "chooseRanges.hpp"
13 #include "displaylines.hpp"
14 #include "SnarkDisplay.hpp"
17 #include "line_real_set_t.hpp"
18 #include "line_real_t.hpp"
20 #define EPSILON 0.00000001
23 * Constructs a chooseRangesDialog which is a child of 'parent', with the
24 * name 'name' and widget flags set to 'fl', initial topleft position to (x,y)
26 * The dialog will by default be modeless, unless you set 'modal' to
27 * TRUE to construct a modal dialog.
29 chooseRangesDialog::chooseRangesDialog( QWidget* parent, const char* name, bool modal, WFlags fl , int x, int y,
30 unsigned ee_index, bool forPBP, unsigned PBPYVar, globalYVar_t GlobalYVar, int minX, int maxX, double minY, double maxY) : QDialog( parent, name, modal, fl )
32 this->ee_index = ee_index;
33 this->forPBP = forPBP;
34 this->PBPYVar = PBPYVar;
35 this->GlobalYVar = GlobalYVar;
39 YVarName = tr("e(%1)").arg(PBPYVar);
42 case AVERAGE: YVarName = "Average"; break;
43 case DISTANCE: YVarName = "Distance"; break;
44 case RELERR: YVarName = "Relative Error"; break;
45 case VARIANCE: YVarName = "Variance"; break;
46 case STDDEV: YVarName = "Standard Deviation"; break;
47 case RESIDUAL: YVarName = "Residual"; break;
48 case KULLBACK: YVarName = "Kullback-Leibler Distance"; break;
49 default: std::cerr << "Invalid GlobalYVar in chooseRangesDialog ctor!" << std::endl;
54 setName( "chooseRangesDialogWindow" );
56 fullname = tr("%1 :: %2").arg(name).arg(YVarName); // weird QT syntax, don't sweat it
58 setCaption( fullname );
63 QBoxLayout *topLayout = new QVBoxLayout( this );
65 minx = new QLineEdit( this, "minx" );
66 maxx = new QLineEdit( this, "maxx" );
67 miny = new QLineEdit( this, "miny" );
68 maxy = new QLineEdit( this, "maxy" );
70 QBoxLayout* x_extrema_layout = new QHBoxLayout( topLayout );
71 minxlabel = new QLabel( this, "minxlabel" );
72 minxlabel->setText( tr( "Min Iter:" ) );
73 maxxlabel = new QLabel( this, "maxxlabel" );
74 maxxlabel->setText( tr( "Max Iter:" ) );
75 x_extrema_layout->addWidget(minxlabel);
76 x_extrema_layout->addWidget(minx);
77 x_extrema_layout->addWidget(maxxlabel);
78 x_extrema_layout->addWidget(maxx);
80 QBoxLayout* y_extrema_layout = new QHBoxLayout( topLayout );
81 minylabel = new QLabel( this, "minxlabel" );
82 minylabel->setText( tr( "Min Y:" ) );
83 maxylabel = new QLabel( this, "maxxlabel" );
84 maxylabel->setText( tr( "Max Y:" ) );
85 y_extrema_layout->addWidget(minylabel);
86 y_extrema_layout->addWidget(miny);
87 y_extrema_layout->addWidget(maxylabel);
88 y_extrema_layout->addWidget(maxy);
90 minx->setText( tr("%1") . arg( minX ) );
91 maxx->setText( tr("%1") . arg( maxX ) );
92 miny->setText( tr("%1") . arg( minY ) );
93 maxy->setText( tr("%1") . arg( maxY ) );
95 QString plottext(tr("plot %1").arg(YVarName));
96 plotbutton = new QPushButton( this, "plotbutton" );
97 plotbutton->setText( plottext );
98 plotbutton->setEnabled(true);
99 QObject::connect(plotbutton,SIGNAL(clicked()),this,SLOT(proceed()));
100 topLayout->addWidget( plotbutton );
102 closebutton = new QPushButton( this, "closebutton" );
103 closebutton->setText( tr( "Close Window" ) );
104 QObject::connect(closebutton,SIGNAL(clicked()),this,SLOT(closeWindow()));
106 topLayout->addWidget( closebutton );
107 topLayout->activate();
111 * Destroys the object and frees any allocated resources
113 chooseRangesDialog::~chooseRangesDialog()
115 // no need to delete child widgets, Qt does it all for us
118 void chooseRangesDialog::closeWindow()
124 void chooseRangesDialog::closeEvent(QCloseEvent * e)
129 /** Called when plotbutton "Plot" is clicked:
130 based on the sameExtremaForAllCheckBox state,
131 either spawns plots or new dialog boxes.
132 Does some checks before sending params to plots (no garbage out).
134 @author Bruno M. Carvalho
136 void chooseRangesDialog::proceed()
138 if(std::verbose>=2) {
139 std::cout << "in chooseRangesDialog::proceed()" << std::endl;
141 bool complain = false;
142 // attempt to call plot windows after error checking
144 int minXVal = minx->text().toInt(&ok);
145 if((!ok) || (minXVal < 0) ) complain=true; // allow minXVal to be 0
146 int maxXVal = maxx->text().toInt(&ok);
147 if(!ok) complain=true;
148 if(maxXVal <= 0) complain=true;
149 if(minXVal >= maxXVal) complain=true;
150 double minYVal = miny->text().toDouble(&ok);
151 if(!ok) complain=true;
152 double maxYVal = maxy->text().toDouble(&ok);
153 if(!ok) complain=true;
154 // allow negative values for minYVal, even though there are no negative ones in data
155 if(maxYVal <= 0) complain=true;
156 if(minYVal >= maxYVal) complain=true;
158 std::cerr << "Invalid combination of X and Y parameters." << std::endl;
159 } else { // passed error checks
160 if(std::verbose>=2) {
161 std::cout << "Plotting with iter: [" << minXVal
162 << "," << maxXVal << "]; y: [" << minYVal << ","
163 << maxYVal << "]" << std::endl;
165 /// spawnPlots(true, minXVal, maxXVal, minYVal, maxYVal);
166 // std::cout << "PLOTTING!" << std::endl;
167 line_real_set_t LRS(minXVal, maxXVal, minYVal, maxYVal);
168 /// int PMWidth = 550; // pixmap width, etc
169 /// sd_line_t::WIDTH = 550;
170 int PMWidth = sd_line_t::WIDTH;
171 /// int PMHeight = 450;
172 /// sd_line_t::HEIGHT = 450;
173 int PMHeight = sd_line_t::HEIGHT;
174 QPixmap* myPixmapP = new QPixmap(PMWidth,PMHeight);
175 myPixmapP->fill( Qt::white );
176 QPainter* myPainterP = new QPainter;
177 myPainterP->begin(myPixmapP);
178 // do the thing with the plot
180 myEES.addPBPVarLines(LRS, PBPYVar, ee_index);
182 myEES.addGlobVarLines(LRS, GlobalYVar, ee_index);
184 plot_t* myPlotterP = new plot_t(LRS);
185 /// plot_t myPlotter(LRS); // now combine LRS with myPainterP
186 myPlotterP->setName(fullname);
187 QString xAxisLabel = "Iteration"; // as in all evals
188 myPlotterP->setXAxisName(xAxisLabel);
189 myPlotterP->setYAxisName(YVarName); // YVarName is an instance variable
190 myPlotterP->plot(*myPainterP);
191 displaylineswindow *dwp = new displaylineswindow( this , fullname, myPixmapP, false, 0,
192 -20+this->pos().x(), 20+this->pos().y() );
193 dwp->show(); // and display!
195 } // --chooseRangesDialog::proceed()