00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "GraphWindow.h"
00011 #include <QtCore/QTimer>
00012 #include <QtGui/QFormLayout>
00013 #include <SeExprEdShortEdit.h>
00014
00015 GraphWindow::
00016 GraphWindow(QWidget* parent)
00017 :QFrame(parent),time(0),animating(false)
00018 {
00019 variables["t"].val=0.;
00020
00021
00022
00023
00024 QVBoxLayout* mainvbox=new QVBoxLayout();
00025 mainvbox->setMargin(0);
00026 setLayout(mainvbox);
00027 QHBoxLayout* layout=new QHBoxLayout();
00028 mainvbox->addLayout(layout);
00029 status=new QStatusBar();
00030 mainvbox->addWidget(status);
00031
00032
00033
00034
00035
00036 graph=new Graph(status,_exprs);
00037 graph->setMinimumWidth(640);
00038 graph->setMinimumHeight(480);
00039 layout->addWidget(graph,2);
00040
00041
00042
00043
00044 QVBoxLayout* rightLayout=new QVBoxLayout();
00045
00046 layout->addLayout(rightLayout,1);
00047
00048
00049
00050 rightLayout->setMargin(0);
00051 for(int i=0;i<5;i++){
00052 SeExprEdShortEdit* shortEdit=new SeExprEdShortEdit(0);
00053 shortEdit->setMinimumWidth(512);
00054 rightLayout->addWidget(shortEdit);
00055 QObject::connect(shortEdit,SIGNAL(exprChanged()),this,SLOT(exprsEdited()));
00056 _edits.push_back(shortEdit);
00057 _exprs.push_back(new GrapherExpr("",variables));
00058 }
00059
00060
00061
00062 _edits[0]->setExpressionString("a=0.34483; #-10.0,10.0\nb=0.41379; #-10.0,10.0\nc=-0.34482; #-10.0,10.0\na*x^2+b*x+c");
00063
00064 _exprs[1]->setExpr("frequency=8.32724; # 0.1, 10.0\
00065 amp = -4; # 0.0, 10.0\
00066 fbm(frequency*x)*amp\
00067 ");
00068
00069 _exprs[2]->setExpr("""frequency=8.32724; # 0.1, 10.0\
00070 amp = 1; # 0.0, 10.0\
00071 sin(frequency*x)*amp-5\
00072 ");
00073
00074 rightLayout->addStretch(1);
00075
00076
00077
00078
00079 rootbutton=new QPushButton("Find Root");
00080 rightLayout->addWidget(rootbutton,0);
00081 connect(rootbutton,SIGNAL(clicked()),SLOT(findRootOrExtrema()));
00082 minbutton=new QPushButton("Find Min");
00083 rightLayout->addWidget(minbutton,0);
00084 connect(minbutton,SIGNAL(clicked()),SLOT(findRootOrExtrema()));
00085 maxbutton=new QPushButton("Find Max");
00086 rightLayout->addWidget(maxbutton,0);
00087 timeSlider=new QSlider(Qt::Horizontal);
00088 QFormLayout* formLayout=new QFormLayout();
00089 rightLayout->addLayout(formLayout);
00090 formLayout->addRow(new QLabel("t"),timeSlider);
00091 timeSlider->setMinimum(0);
00092 timeSlider->setMaximum(24);
00093 timeSlider->setValue(0);
00094 connect(maxbutton,SIGNAL(clicked()),SLOT(findRootOrExtrema()));
00095
00096
00097
00098 QTimer::singleShot(1,this,SLOT(updateTime()));
00099
00100 }
00101
00102 GraphWindow::
00103 ~GraphWindow()
00104 {
00105 for(unsigned int i=0;i<_exprs.size();i++) delete _exprs[i];
00106 }
00107
00108 void GraphWindow::
00109 findRootOrExtrema()
00110 {
00111 Graph::OperationCode code=Graph::NONE;
00112 QObject* sender=QObject::sender();
00113 if(sender==rootbutton) code=Graph::FIND_ROOT;
00114 else if(sender==minbutton) code=Graph::FIND_MIN;
00115 else if(sender==maxbutton) code=Graph::FIND_MAX;
00116
00117 std::vector<int> selected;
00118 if(selected.size() != 1){
00119 status->showMessage("You need to select exactly 1 function");
00120 }else{
00121 graph->scheduleRoot(code,selected[0]);
00122 if(sender==rootbutton) status->showMessage("Click on initial guess");
00123 else status->showMessage("Select solve region");
00124 }
00125 }
00126
00127 void GraphWindow::
00128 updateTime()
00129 {
00130 if(animating){
00131 time+=1./24;
00132 if(time>1) time=0;
00133 timeSlider->setValue(time*24);
00134 variables["t"].val=time;
00135 graph->repaint();
00136 }
00137 QTimer::singleShot(50.,this,SLOT(updateTime()));
00138 }
00139
00140 void GraphWindow::
00141 exprsEdited()
00142 {
00143 for(size_t i=0;i<_edits.size();i++){
00144 SeExprEdShortEdit& edit=*_edits[i];
00145 _exprs[i]->setExpr(edit.getExpressionString());
00146 _exprs[i]->isValid();
00147 }
00148 graph->repaint();
00149 }