00001
00002
00003
00004 #include "pPlotter.h"
00005
00006
00007
00008
00009
00010
00011 #ifndef WX_PRECOMP
00012 #include <wx/wx.h>
00013 #endif
00014
00015
00016
00017
00018
00019 IMPLEMENT_CLASS(pPlotter, wxPanel)
00020
00021
00022
00023
00024 BEGIN_DECLARE_EVENT_TYPES()
00025 DECLARE_EVENT_TYPE( wxEVT_NW_TEXT_MESAGGE, -1 )
00026 END_DECLARE_EVENT_TYPES()
00027
00028 DEFINE_EVENT_TYPE( wxEVT_NW_TEXT_MESAGGE )
00029
00030
00031
00032
00033 DECLARE_EVENT_TYPE(wxEVT_ADDED_POINT, -1)
00034 DECLARE_EVENT_TYPE(wxEVT_REMOVED_POINT, -1)
00035 DECLARE_EVENT_TYPE(wxEVT_MOVED_POINT, -1)
00036 DECLARE_EVENT_TYPE(wxEVT_CHANGED_POINT, -1)
00037 DECLARE_EVENT_TYPE(wxEVT_ON_COLOR_BAR, -1)
00038
00039
00040
00041
00042 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION, -1)
00043 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE, -1)
00044 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD, -1)
00045 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE, -1)
00046 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES, -1)
00047
00048
00049
00050
00051 DECLARE_EVENT_TYPE(wxEVT_TSBAR, -1)
00052 DECLARE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL, -1)
00053 DECLARE_EVENT_TYPE(wxEVT_TSBAR_START, -1)
00054 DECLARE_EVENT_TYPE(wxEVT_TSBAR_END, -1)
00055 DECLARE_EVENT_TYPE(wxEVT_TSBAR_MOVED, -1)
00056 DECLARE_EVENT_TYPE(wxEVT_SELECTION_END, -1)
00057
00058
00059
00060
00061
00062 BEGIN_EVENT_TABLE(pPlotter, wxPanel)
00063
00064
00065
00066
00067 EVT_COMMAND (-1,wxEVT_PPLOTTER_CHANGED_FUNCTION, pPlotter::onChangeFunction)
00068 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_MOVE, pPlotter::onMovePoint_Plotter)
00069 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_ADD, pPlotter::onAddedPoint_Plotter)
00070 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_DELETE, pPlotter::onRemovedPoint_Plotter)
00071 EVT_COMMAND (-1,wxEVT_PPLOTTER_GUIDELINES, pPlotter::onGuideLines)
00072
00073
00074 EVT_COMMAND (-1,wxEVT_ADDED_POINT, pPlotter :: onAdded_ColorPoint )
00075 EVT_COMMAND (-1,wxEVT_REMOVED_POINT, pPlotter :: onRemoved_ColorPoint )
00076 EVT_COMMAND (-1,wxEVT_MOVED_POINT, pPlotter :: onMoved_ColorPoint )
00077 EVT_COMMAND (-1,wxEVT_CHANGED_POINT, pPlotter :: onChanged_ColorPoint )
00078 EVT_COMMAND (-1,wxEVT_ON_COLOR_BAR, pPlotter :: onColorBar )
00079
00080
00081 EVT_COMMAND (-1,wxEVT_TSBAR, pPlotter::onBarrange)
00082 EVT_COMMAND (-1,wxEVT_SELECTION_END, pPlotter::onSelectionEnd)
00083 EVT_COMMAND (-1,wxEVT_TSBAR_MOVED, pPlotter::onMovedBar)
00084 EVT_COMMAND (-1,wxEVT_TSBAR_ACTUAL, pPlotter:: onActualChange_Bar)
00085 EVT_COMMAND (-1,wxEVT_TSBAR_START, pPlotter::onStartChange_Bar)
00086 EVT_COMMAND (-1,wxEVT_TSBAR_END, pPlotter::onEndChange_Bar)
00087
00088 END_EVENT_TABLE()
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 pPlotter :: pPlotter (wxWindow *parent,int nWidth, int nHeight)
00099 :wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
00100 {
00101 SetBackgroundColour(wxColour(255,255,255));
00102 m_plot = new pPlotterWindow( this, -1, wxPoint(0,0), wxSize(nWidth,nHeight), wxSUNKEN_BORDER );
00103
00104
00105 m_plot->AddLayer( new pPlotterScaleX() );
00106 m_plot->AddLayer( new pPlotterScaleY() );
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 mpWindow* mplotWindow = ((mpWindow*)m_plot);
00143 float minReal_X = 0;
00144 float maxReal_X =(float)mplotWindow->getMaxScrX();
00145
00146
00147
00148
00149 color_bar = new pColorBar(this, (m_plot->GetSize()).GetWidth(),40, true);
00150 color_bar -> setRepresentedValues ((int)minReal_X, (int)maxReal_X);
00151 color_bar -> setDeviceBlitStart (70,0);
00152 color_bar -> setVisibleRange ((int)minReal_X,(int) maxReal_X);
00153 color_bar -> setDeviceEndMargin (50);
00154
00155
00156
00157 barrange = new mBarRange(this, (m_plot->GetSize()).GetWidth(),30);
00158 barrange -> setVisibleLabels (false);
00159 barrange -> setRepresentedValues (minReal_X, maxReal_X);
00160 barrange -> setDeviceBlitStart (70,0);
00161 barrange -> setDeviceEndMargin (50);
00162
00163
00164
00165
00166
00167
00168 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00169 sizer->Add( m_plot, 4, wxEXPAND);
00170 sizer->Add( color_bar,0, wxEXPAND );
00171 sizer->Add( barrange, 0, wxEXPAND );
00172
00173
00174
00175
00176 SetAutoLayout(true);
00177 SetSizer(sizer);
00178 Layout();
00179
00180 Refresh();
00181 }
00182
00183
00184 pPlotter :: ~pPlotter ()
00185 {
00186
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196 void pPlotter::setAll()
00197 {
00198 actualFunction = m_plot->getActualFunction();
00199
00200 if (actualFunction != NULL)
00201 {
00202 barrange -> setActiveStateTo(true);
00203 color_bar -> setActiveStateTo(true);
00204
00205 text.Clear();
00206 text = _T("minX=");
00207 double realMin_X = actualFunction->getMinX();
00208 text = text + realMin_X;
00209 text = text + _T(" maxX=");
00210 double realMax_X = actualFunction->getMaxX();
00211 text = text + realMax_X;
00212
00213 int minShowed = actualFunction->getMinXShowed();
00214 int maxShowed = actualFunction->getMaxXShowed();
00215
00216 barrange -> setRepresentedValues (realMin_X, realMax_X);
00217 barrange->SetStart( minShowed );
00218 barrange->SetEnd( maxShowed );
00219
00220
00221 std::vector<pColorPoint *> actualColorPoints;
00222 actualFunction -> getColorPoints(actualColorPoints);
00223 if(actualColorPoints.empty())
00224 color_bar ->reinitiateColorBar (realMin_X, realMax_X);
00225 else
00226 color_bar ->reinitiateColorBarTo(actualColorPoints);
00227
00228 color_bar -> setVisibleRange (minShowed, maxShowed);
00229
00230
00231 color_bar -> RefreshForce();
00232 barrange -> RefreshForce();
00233
00234 sendTMessage(text);
00235 }
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 void pPlotter :: onAdded_ColorPoint(wxCommandEvent& event)
00247 {
00248 text.Clear();
00249 text = _T( "Last event was on color bar: Color point added, total#");
00250
00251 actualFunction = m_plot->getActualFunction();
00252 if(actualFunction!=NULL)
00253 {
00254 std::vector<pColorPoint *> actualColorPoints;
00255 color_bar ->getAddedColorsPointsList(actualColorPoints);
00256 actualFunction -> setColorPoints(actualColorPoints);
00257 text << actualColorPoints.size();
00258
00259 sendTMessage(text);
00260 }
00261 }
00262 void pPlotter :: onRemoved_ColorPoint(wxCommandEvent& event)
00263 {
00264 text.Clear();
00265 text = _T( "Last event on color bar: Color point removed total#");
00266
00267 actualFunction = m_plot->getActualFunction();
00268 std::vector<pColorPoint *> actualColorPoints;
00269 color_bar ->getAddedColorsPointsList(actualColorPoints);
00270 actualFunction -> setColorPoints(actualColorPoints);
00271 text << actualColorPoints.size();
00272
00273 sendTMessage(text);
00274 }
00275 void pPlotter :: onMoved_ColorPoint(wxCommandEvent& event)
00276 {
00277 text.Clear();
00278 text = _T( "Last event was on color bar: Color point moved to: ");
00279 int lastReal_X = (int)(color_bar->getLastMovedColorPoint())->getRealX();
00280 text << lastReal_X;
00281
00282 barrange ->setRealX_vertical_line (lastReal_X);
00283 barrange -> RefreshForce();
00284
00285 m_plot->setRealGuideX (lastReal_X);
00286 m_plot->UpdateAll();
00287
00288 sendTMessage(text);
00289 }
00290 void pPlotter:: onChanged_ColorPoint(wxCommandEvent& event)
00291 {
00292 text.Clear();
00293 sendTMessage(_T("Last event was on color bar: Color point changed color"));
00294 }
00295
00296 void pPlotter :: onColorBar( wxCommandEvent& event )
00297 {
00298 if( (barrange->getRealX_vertical_line())!=-1)
00299 {
00300 barrange ->setRealX_vertical_line (-1);
00301 m_plot->setRealGuideX (-1);
00302
00303 barrange -> RefreshForce();
00304 m_plot->UpdateAll();
00305 }
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 void pPlotter :: onChangeFunction (wxCommandEvent& event)
00317 {
00318 actualFunction = m_plot->getActualFunction();
00319
00320 if (actualFunction != NULL)
00321 {
00322 if( !barrange->isActive() )
00323 {
00324 barrange -> setActiveStateTo(true);
00325 color_bar -> setActiveStateTo(true);
00326 }
00327
00328 text.Clear();
00329 text = _T("Last event was on plotter: function changed, minX=");
00330 double realMin_X = actualFunction->getMinX();
00331 text << realMin_X;
00332 text << _T(" maxX=");
00333 double realMax_X = actualFunction->getMaxX();
00334 text << realMax_X;
00335
00336 int minShowed = actualFunction->getMinXShowed();
00337 int maxShowed = actualFunction->getMaxXShowed();
00338
00339 barrange -> setRepresentedValues (realMin_X, realMax_X);
00340 barrange->SetStart( minShowed );
00341 barrange->SetEnd( maxShowed );
00342
00343 std::vector<pColorPoint *> actualColorPoints;
00344 actualFunction -> getColorPoints(actualColorPoints);
00345 if(actualColorPoints.empty())
00346 color_bar ->reinitiateColorBar (realMin_X, realMax_X);
00347 else
00348 color_bar ->reinitiateColorBarTo(actualColorPoints);
00349
00350 color_bar -> setVisibleRange ((int)realMin_X, maxShowed);
00351
00352
00353 color_bar -> RefreshForce();
00354 barrange -> RefreshForce();
00355
00356 sendTMessage(text);
00357 }
00358 }
00359
00360
00361
00362
00363
00364
00365 void pPlotter :: onAddedPoint_Plotter (wxCommandEvent& event)
00366 {
00367 text.Clear();
00368 m_plot->writeInText(text);
00369 sendTMessage(text);
00370 }
00371
00372
00373
00374
00375 void pPlotter :: onRemovedPoint_Plotter (wxCommandEvent& event)
00376 {
00377 text.Clear();
00378 m_plot->writeInText(text);
00379 sendTMessage(text);
00380 }
00381
00382
00383
00384
00385 void pPlotter :: onMovePoint_Plotter (wxCommandEvent& event)
00386 {
00387 text.Clear();
00388 m_plot->writeInText(text);
00389 sendTMessage(text);
00390 }
00391
00392
00393
00394 void pPlotter::onGuideLines(wxCommandEvent& event)
00395 {
00396
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 void pPlotter::onBarrange(wxCommandEvent& event)
00408 {
00409
00410 }
00411
00412
00413
00414 void pPlotter::onActualChange_Bar(wxCommandEvent& event)
00415 {
00416 text.Clear();
00417 text = _T( "Last event was on min-max bar: Actual triangle moved to: " );
00418 int lastActual_X = barrange->GetActual();
00419
00420 text << lastActual_X;
00421
00422 color_bar ->setRealX_vertical_line (lastActual_X);
00423 m_plot->setRealGuideX (lastActual_X);
00424
00425 color_bar -> RefreshForce();
00426 m_plot->UpdateAll();
00427
00428 sendTMessage(text);
00429 }
00430
00431
00432
00433
00434 void pPlotter::onStartChange_Bar(wxCommandEvent& event)
00435 {
00436 text.Clear();
00437
00438 text = _T( "Last event was on min-max bar: Start triangle moved to: ");
00439 int realMin_X = barrange->GetStart();
00440 text += wxString::Format(_T("%d"), realMin_X);
00441 double realMax_X = m_plot->getMaxScrX();
00442
00443 color_bar -> setVisibleRange (realMin_X, (int)realMax_X);
00444
00445 m_plot->actualizeViewRange(realMin_X, (int)realMax_X);
00446
00447
00448
00449
00450 float startP=(float)barrange->getStartShowPorcentage();
00451 float endP=(float)barrange->getEndShowPorcentage();
00452 m_plot->moveFunctions(startP,endP);
00453
00454
00455 color_bar -> RefreshForce();
00456 m_plot -> UpdateAll();
00457 sendTMessage(text);
00458 }
00459
00460 void pPlotter::onEndChange_Bar(wxCommandEvent& event)
00461 {
00462 text.Clear();
00463 text += _T("Last event was on min-max bar: End triangle moved to: ");
00464 int realMax_X = barrange->GetEnd();
00465 text += wxString::Format(_T("%d"),realMax_X);
00466 double realMin_X = m_plot->getMinScrX();
00467 color_bar -> setVisibleRange ((int)realMin_X, realMax_X);
00468 m_plot->actualizeViewRange((int)realMin_X,realMax_X);
00469
00470 float startP=(float)barrange->getStartShowPorcentage();
00471 float endP=(float)barrange->getEndShowPorcentage();
00472 m_plot->moveFunctions(startP,endP);
00473
00474 color_bar -> RefreshForce();
00475 m_plot -> UpdateAll();
00476
00477 sendTMessage(text);
00478 }
00479
00480 void pPlotter :: onSelectionEnd(wxCommandEvent& event)
00481 {
00482 if( (color_bar->getRealX_vertical_line())!=-1)
00483 {
00484 color_bar ->setRealX_vertical_line (-1);
00485 m_plot->setRealGuideX (-1);
00486
00487 color_bar -> RefreshForce();
00488 m_plot->UpdateAll();
00489 }
00490 }
00491 void pPlotter :: onMovedBar(wxCommandEvent& event)
00492 {
00493 text.Clear();
00494 text = _T( "Last event was on min-max bar: Moved bar to min:" );
00495
00496 int realMin_X = barrange->GetStart();
00497 text += wxString::Format(_T("%d"),realMin_X);
00498 text += _T(" max:");
00499
00500 int realMax_X = barrange->GetEnd();
00501 text += wxString::Format(_T("%d"),realMax_X);
00502
00503 color_bar -> setVisibleRange (realMin_X, realMax_X);
00504
00505 float startP=(float)barrange->getStartShowPorcentage();
00506 float endP=(float)barrange->getEndShowPorcentage();
00507 m_plot->moveFunctions(startP,endP);
00508
00509 color_bar -> RefreshForce();
00510 m_plot -> UpdateAll();
00511
00512 sendTMessage(text);
00513 }
00514
00515
00516
00517
00518
00519 void pPlotter :: sendTMessage(wxString theText)
00520 {
00521
00522 wxCommandEvent puntualMSG_Event( wxEVT_NW_TEXT_MESAGGE, GetId() );
00523 puntualMSG_Event.SetEventObject(this);
00524
00525 GetEventHandler()->ProcessEvent( puntualMSG_Event );
00526 }
00527
00528
00529
00530
00531
00532 void pPlotter :: setTextMessage(wxString nMessage)
00533 {
00534 text = nMessage;
00535 }
00536
00537
00538
00539
00540
00541 wxString pPlotter :: getTextMessage()
00542 {
00543 return text;
00544 }
00549 int pPlotter:: addFunction(pGraphicalFunction * function)
00550 {
00551 return m_plot->addFunction(function);
00552 }
00556 pGraphicalFunction* pPlotter::getFunctionForVectors( double* vectorX, int sizeX,double * vectorY, int sizeY )
00557 {
00558 return m_plot->getFunctionForVectors(vectorX,sizeX, vectorY, sizeY );
00559 }
00560
00561
00562
00563 void pPlotter::setType(int t)
00564 {
00565 m_plot->setType(t);
00566 }
00567
00568
00569
00570 pGraphicalFunction* pPlotter:: getFunction(int index)
00571 {
00572 return m_plot->getFunction(index);
00573 }
00574
00575
00576
00577 int pPlotter::addFunctionToMove(pGraphicalFunction * function)
00578 {
00579 return m_plot->addFunctionToMove(function);
00580 }
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591 void pPlotter:: moveFunctions(float porcentageMinX,float porcentageMaxX)
00592 {
00593 m_plot->moveFunctions(porcentageMinX,porcentageMaxX);
00594 }
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00612 int pPlotter::getColorPointsSize()
00613 {
00614 return color_bar->getColorPointsSize();
00615 }
00616
00617
00618
00619
00620 void pPlotter::getBarColorDataAt(int index,double& x, int& red,int& green,int& blue)
00621 {
00622 color_bar->getDataAt(index,x,red,green,blue);
00623 }
00624
00625
00626
00627
00628
00629 bool pPlotter::addColorPoint(int x,int red,int green, int blue)
00630 {
00631 wxColour color= wxColour(red,green,blue);
00632 return color_bar->addColorPoint((double)x, color);
00633 }
00634 void pPlotter::eraseColorPoints()
00635 {
00636 int min=(int)color_bar->getMinValue();
00637 int max=(int)color_bar->getMaxValue();
00638 color_bar->reinitiateColorBar(min,max);
00639 }
00640
00641
00642
00643
00644 float pPlotter::getMaxShowedPorcentage()
00645 {
00646 return barrange->getEndShowPorcentage();
00647 }
00648 float pPlotter::getMinShowedPorcentage()
00649 {
00650 return barrange->getStartShowPorcentage();
00651 }
00652 float pPlotter::getActualShowedPorcentage()
00653 {
00654 return barrange->getActualShowPorcentage();
00655 }
00656
00657
00658
00659
00660 void pPlotter::setActual(pGraphicalFunction* nActual)
00661 {
00662 m_plot->setActualFunction(nActual);
00663 }
00664 void pPlotter::update()
00665 {
00666
00667 if(m_plot->getType()==2)
00668 {
00669 pGraphicalFunction* tf= m_plot->getActualFunction();
00670 if(tf->getType()==2)
00671 {
00672 tf->clearSplineVectors();
00673 tf->addSplinesPoints();
00674 tf->initializeSplineVectors();
00675 }
00676 }
00677
00678 m_plot->UpdateAll();
00679 }
00680
00681
00682
00683
00684 void pPlotter::setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
00685 bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
00686 bool delPoint,bool load,bool save)
00687 {
00688 m_plot->setPopUpMenu(startD, stopD, smooth, line, zoomIn,
00689 zoomOut, showPoints, noShowPoints, changeColor, addP,
00690 delPoint, load, save);
00691 }
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00723 void pPlotter::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value, int histogramsize)
00724 {
00725 if(actualFunction != NULL){
00726 double* xval = actualFunction->getX_RealValues();
00727 double* yval = actualFunction->getY_RealValues();
00728
00729 actualFunction->getScaleY();
00730 for(int i = 0; i < actualFunction->getSizePoints();i++){
00731 greylevel.push_back(xval[i]);
00732 value.push_back(yval[i]/histogramsize);
00733 }
00734 }
00735 }
00736
00741 void pPlotter::GetValuesColorPointsFunction(std::vector<double>& greylevel,
00742 std::vector<double>& red,
00743 std::vector<double>& green,
00744 std::vector<double>& blue)
00745 {
00746
00747 if(color_bar != NULL){
00748
00749 std::vector<pColorPoint*> colors;
00750 color_bar->getAddedColorsPointsList(colors);
00751
00752 for(int i = 0; i < colors.size();i++){
00753 pColorPoint* pcolor = colors[i];
00754
00755 greylevel.push_back(pcolor->getRealX());
00756 wxColour colour = pcolor->getColor();
00757
00758 double _red = (double)(colour.Red())/255.0;
00759 double _green = (double)(colour.Green())/255.0;
00760 double _blue = (double)(colour.Blue())/255.0;
00761
00762 red.push_back(_red);
00763 green.push_back(_green);
00764 blue.push_back(_blue);
00765 }
00766 }
00767 }
00768
00769
00770
00771