]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
f97d8cd6fb1221642cd2ef60cb2824fd8b634066
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / WidgetShowNPoints.cxx
1
2
3 #include "vtkSphereSource.h"
4 #include "vtkRenderer.h"
5 #include "vtkTextActor3D.h"
6
7
8
9 #include <wx/button.h>
10 #include <wx/sizer.h>
11 #include <wx/filedlg.h>
12 #include <wx/msgdlg.h>
13 #include <wx/notebook.h>
14
15 #include "WidgetShowNPoints.h"
16
17
18 //----------------------------------------------------------------------
19 //----------------------------------------------------------------------
20 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
24     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
25   {
26     printf("EED WidgetShowNPoints::WidgetShowNPoints Start \n");
27         // EED 2022-05-19
28     //  mmodelShowNPoints                                = new ModelShowNPoints();
29                         mActualCollection= 0;
30     ModelShowNPoints*   modelShowNPoints = new ModelShowNPoints();
31     lstModelShowNPoints.push_back( modelShowNPoints );
32     lstViewShowNPoints.push_back( new  ViewShowNPoints( modelShowNPoints ) );
33       
34     mtype                                                       = type;
35     SetType(mtype);
36     wxPanel*    panelParent         = this;
37     wxSizer*    sizer                           = NULL;
38     wxSizer*    MNPsizer            = NULL;
39
40     wxNotebook* bookSetPoints       = NULL;
41     wxNotebook* bookGroupManager    = NULL;
42     wxPanel*    panel               = NULL;
43     wxPanel*    panel2              = NULL;
44
45
46       
47
48       bookSetPoints     = new wxNotebook(panelParent,
49                           -1,
50                           wxDefaultPosition,
51                           wxDefaultSize,
52                           wxNB_TOP );
53       panel  = new wxPanel(bookSetPoints);
54
55
56     // Group Manager
57     if (mtype==4)
58     {
59           bookGroupManager   = new wxNotebook(panelParent, //bbGetWxParent(),
60                               -1,
61                               wxDefaultPosition,
62                               wxDefaultSize,
63                               wxNB_TOP );
64           panel2  = new wxPanel(bookGroupManager);
65           txtNrCollections                      = new wxStaticText(panel2,-1, _T("1   /  1 "));
66           wxButton *btnBackCollection           = new wxButton( panel2, -1, _T("<"));
67           wxButton *btnNextCollection           = new wxButton( panel2, -1, _T(">"));
68           wxButton *btnInsertCollectionBefore   = new wxButton( panel2, -1, _T("Insert Before"));
69           wxButton *btnInsertCollectionAfter    = new wxButton( panel2, -1, _T("Insert After"));
70           wxButton *btnDeleteCollection         = new wxButton( panel2, -1, _T("Delete"));
71
72           Connect(btnInsertCollectionBefore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionBefore);
73           Connect(btnInsertCollectionAfter->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionAfter);
74           Connect(btnDeleteCollection->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteCollection);
75           Connect(btnBackCollection->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnBackCollection);
76           Connect(btnNextCollection->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnNextCollection);
77
78           wxFlexGridSizer *sizer1               = new wxFlexGridSizer(1);
79           wxFlexGridSizer *sizer2               = new wxFlexGridSizer(2);
80         
81           sizer2->Add( btnBackCollection );
82           sizer2->Add( btnNextCollection );
83
84           sizer1->Add( txtNrCollections );
85           sizer1->Add( sizer2 );
86           sizer1->Add( btnInsertCollectionBefore );
87           sizer1->Add( btnInsertCollectionAfter );
88           sizer1->Add( btnDeleteCollection );
89           MNPsizer                        = sizer1;
90           panel2->SetSizer( MNPsizer );
91           panel2->SetAutoLayout(true);
92           panel2->Layout();
93           bookGroupManager->AddPage(panel2 , _T("Collection") );
94     } // if mtype 4
95
96         if ( (mtype==0) || (mtype==3) || (mtype==4) )
97         {
98                 // Widget interface
99                 askPointLabel                                   = new wxStaticText(panel, -1, _T("Point label :")); // JPR
100                 textCtrl                                                = new wxTextCtrl(panel, -1);
101                 wxButton *btnAddPoint                   = new wxButton( panel, -1, _T("Add Point"));
102                 wxButton *btnInsertPoint                = new wxButton( panel, -1, _T("Insert Point"));//CFT
103                 wxButton *btnSetPositionPoint   = new wxButton( panel, -1, _T("Set nearest point"));
104                 wxButton *btnRenamePoint                = new wxButton( panel, -1, _T("Rename point"));
105                 wxButton *btnEraseLastPoint             = new wxButton( panel, -1, _T("Erase Last point"));
106                 wxButton *btnErasePoint                 = new wxButton( panel, -1, _T("Erase point"));
107                 wxButton *btnDeleteAllPoints    = new wxButton( panel, -1, _T("Delete all points"));
108                 wxButton *btnSavePoints                 = NULL;
109                 wxButton *btnLoadPoints                 = NULL;
110                 if ( (mtype==0) || (mtype==4) )
111                 {
112                         btnSavePoints                           = new wxButton( panel, -1, _T("Save points"));
113                         btnLoadPoints                           = new wxButton( panel, -1, _T("Load points"));
114                 } // if mtype
115                 txtNrPoints                                             = new wxStaticText(panel,-1, _T(" "));
116
117                 //NTU: Sliders for opacity and radio change
118                 wxStaticText* txOpacity         = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
119                 sdrOpacity                      = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
120                 wxStaticText* txRadio           = new wxStaticText(panel, -1, wxString(_T("  Points Radius  ")));
121                 sdrRadio                        = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
122
123                 Connect(btnAddPoint->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
124                 Connect(btnInsertPoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
125                 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
126                 Connect(btnRenamePoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
127                 Connect(btnEraseLastPoint->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
128                 Connect(btnErasePoint->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
129                 Connect(btnDeleteAllPoints->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
130                 if ((mtype==0) || (mtype==4) )
131                 {
132                         Connect(btnSavePoints->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
133                         Connect(btnLoadPoints->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
134                 }
135                 //NTU: Slider events
136                 Connect(sdrOpacity->GetId()                     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
137                 Connect(sdrRadio->GetId()                       , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
138
139         wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
140                 sizer1->Add(askPointLabel); // JPR
141                 sizer1->Add(textCtrl);
142                 sizer1->Add(btnAddPoint);
143                 sizer1->Add(btnInsertPoint);//CFT
144                 sizer1->Add(btnSetPositionPoint);
145                 sizer1->Add(btnRenamePoint);
146                 sizer1->Add(btnErasePoint);
147                 sizer1->Add(btnEraseLastPoint);
148                 sizer1->Add(btnDeleteAllPoints);
149                 sizer1->Add(txtNrPoints);
150                 sizer1->Add(txOpacity);
151                 sizer1->Add(sdrOpacity,1,wxGROW );
152                 sizer1->Add(txRadio);
153                 sizer1->Add(sdrRadio,1,wxGROW );
154         if ((mtype==0) || (mtype==4) )
155                 {
156                         sizer1->Add(btnSavePoints);
157                         sizer1->Add(btnLoadPoints);
158                 }
159                 sizer = sizer1;
160         }
161
162           if (mtype==1)
163           {
164                   // Widget interface
165                   wxButton *btnSetPositionPoint         = new wxButton( panel, -1, _T("Set nearest point"));
166                   txtNrPoints                                           = new wxStaticText(panel,-1, _T(" "));
167
168                   //NTU: Sliders for opacity and radio change
169                   wxStaticText* txOpacity                       = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
170                   sdrOpacity                                            = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
171                   wxStaticText* txRadio                         = new wxStaticText(panel, -1, wxString(_T("  Points Radio  ")));
172                   sdrRadio                                                      = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
173                   Connect(btnSetPositionPoint->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
174                   Connect(sdrOpacity->GetId()   , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
175                   Connect(sdrRadio->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
176
177           wxFlexGridSizer *sizer1            = new wxFlexGridSizer(1);
178                   sizer1->Add(btnSetPositionPoint);
179                   sizer1->Add(txtNrPoints);
180                   sizer1->Add(txOpacity);
181                   sizer1->Add(sdrOpacity,1,wxGROW );
182                   sizer1->Add(txRadio);
183                   sizer1->Add(sdrRadio,1,wxGROW );
184                   sizer = sizer1;
185           }
186     
187     if (mtype == 2) 
188         {
189                 askPointLabel                                           = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
190         wxButton                *btnAddPoint            = new wxButton(panel, -1,        _T("      Add  Point      "));
191         wxButton                *btnDeleteAllPoints = new wxButton(panel, -1, _T("      Delete All      "));
192         wxStaticText    *spacer                         = new wxStaticText(panel, -1, _T("\n")); // JPR
193                                          textCtrl                       = new wxTextCtrl(panel, -1);
194         Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
195         Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);    
196         wxFlexGridSizer *sizer1             = new wxFlexGridSizer(1);
197         sizer1->Add(askPointLabel);
198         sizer1->Add(btnAddPoint);
199         sizer1->Add(btnDeleteAllPoints);
200         sizer1->Add(spacer);
201         sizer1->Add(textCtrl);
202       //  sdrOpacity                          = new wxSlider();
203       //  sdrRadio                            = new wxSlider();
204         txtNrPoints                         = new wxStaticText(panel, -1, _T("\n\n\n"));
205         sizer                               = sizer1;
206         } // bbGetInputType 2
207
208             
209       panel->SetSizer(sizer);
210       panel->SetAutoLayout(true);
211       panel->Layout();
212       bookSetPoints->AddPage(panel , _T("Set Points") );
213
214     if ((mtype >= 0) && (mtype <= 3) )
215     {
216         if (sizer!=NULL)
217         {
218             wxFlexGridSizer *sizerParent             = new wxFlexGridSizer(1);
219             sizerParent->Add( bookSetPoints );
220             panelParent->SetSizer( sizerParent );
221             panelParent->SetAutoLayout(true);
222             panelParent->Layout();
223         } // if sizer
224     } // if  mtype 0 1 2 3
225       
226     if (mtype == 4)
227     {
228         if ((sizer!=NULL) && (MNPsizer!=NULL))
229         {
230             wxFlexGridSizer *sizerG             = new wxFlexGridSizer(2);
231             sizerG->Add(bookGroupManager);
232             sizerG->Add(bookSetPoints);
233             panelParent->SetSizer(sizerG);
234             panelParent->SetAutoLayout(true);
235             panelParent->Layout();
236         } // if sizer
237     } // if mtype 4
238 }
239
240 //------------------------------------------------------------------------
241 WidgetShowNPoints::~WidgetShowNPoints()
242 {
243 }
244
245 //------------------------------------------------------------------------
246 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
247 {
248     // EED 2022-05-19
249     // return mmodelShowNPoints;
250     return lstModelShowNPoints[ mActualCollection ];
251 }
252
253 // EED 2022-05-19
254 //------------------------------------------------------------------------
255 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
256 {
257     return lstViewShowNPoints[ mActualCollection ];
258 }
259
260
261 //------------------------------------------------------------------------
262 void WidgetShowNPoints::SetRadio(double radio)
263 {
264     // EED 2022-05-19
265     // GetModelShowNPoints()->SetRadio(radio);
266     int i,size = lstModelShowNPoints.size();
267     for (i=0;i<size;i++)
268     {
269         lstModelShowNPoints[i]->SetRadio( radio );
270     } // for i
271         //NTU: For Slider
272         sdrRadio->SetValue(radio);
273 }
274
275 //------------------------------------------------------------------------
276 void WidgetShowNPoints::SetColour(std::vector<double> colour)
277 {
278     // EED 2022-05-19
279     //this->mcolour = colour;
280     int i,size = lstViewShowNPoints.size();
281     for (i=0 ; i<size ; i++)
282     {
283         lstViewShowNPoints[i]->mcolour = colour;
284     } // for i
285 }
286
287 //------------------------------------------------------------------------
288 void WidgetShowNPoints::SetImage(vtkImageData* image)
289 {
290     // EED 2022-05-19
291         //GetModelShowNPoints()->SetImage(image);
292     int i,size = lstModelShowNPoints.size();
293     for (i=0 ; i<size ; i++)
294     {
295         lstModelShowNPoints[i]->SetImage(image);
296     } // for i
297 }
298
299 //------------------------------------------------------------------------
300 void WidgetShowNPoints::SetOpacity(double opacity)
301 {
302     // EED 2022-05-19
303         //this->mopacity=opacity;
304     int i,size = lstViewShowNPoints.size();
305     for (i=0 ; i<size ; i++)
306     {
307         lstViewShowNPoints[i]->mopacity = opacity;
308     } // for i
309         //NTU: For Slider
310         sdrOpacity->SetValue( opacity*100.0 );
311 }
312
313
314 //------------------------------------------------------------------------
315 void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
316 {
317     // EED 2022-05-19
318         //this->renderer        = renderer;
319     int i,size = lstViewShowNPoints.size();
320     for (i=0 ; i<size ; i++)
321     {
322         lstViewShowNPoints[i]->renderer = renderer;
323     } // for i
324 }
325
326 /* EED 2022-05-19
327 //------------------------------------------------------------------------
328         
329 void WidgetShowNPoints::RefreshPoint(int id)
330 {
331         double spc[3];
332         int x,y,z;
333         GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
334         GetModelShowNPoints()->GetImage()->GetSpacing(spc);
335         std::string label       = GetModelShowNPoints()->GetIdLabel(id);
336         double radio            = GetModelShowNPoints()->GetRadio();
337     lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
338     lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
339     lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
340     lstSourceSphere[id]->SetRadius( radio );
341 //EED 2017-01-01 Migration VTK7
342 #if VTK_MAJOR_VERSION <= 5
343         // ..
344 #else
345     lstSourceSphere[id]->Update();
346 #endif
347     lstActorsText[id]->SetInput( label.c_str()  );
348     lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
349 }
350
351 //------------------------------------------------------------------------
352 void WidgetShowNPoints::RefreshPoints()
353 {
354         int id,size=lstActorsSphere.size();
355         for (id=0;id<size;id++)
356         {
357                 RefreshPoint(id);
358         } // for
359         renderer->GetRenderWindow()->Render();
360 }
361
362 //------------------------------------------------------------------------
363 void WidgetShowNPoints::AddVtkPoint()
364 {
365         // Sphere
366         vtkSphereSource *vtksphere = vtkSphereSource::New();
367         vtksphere->SetThetaResolution (20);
368         vtksphere->SetPhiResolution (20);
369         vtksphere->SetRadius( 1 );
370         //NTU: For updating points
371         lstSourceSphere.push_back(vtksphere);
372         vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
373
374 //EED 2017-01-01 Migration VTK7
375 #if VTK_MAJOR_VERSION <= 5
376         sphereMapper->SetInput( vtksphere->GetOutput() );
377 #else
378         vtksphere->Update();
379         sphereMapper->SetInputData( vtksphere->GetOutput() );
380 #endif
381
382         vtkActor *sphereActor   = vtkActor::New();
383         sphereActor->SetMapper(sphereMapper);
384         sphereActor->SetOrigin(0, 0, 0);
385
386         lstActorsSphere.push_back(sphereActor);
387         if(renderer==NULL){
388                 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
389                 dialog.ShowModal();             
390                 return;
391         }
392         renderer->AddActor( sphereActor );
393         // Actor
394         vtkTextActor3D *textActor = vtkTextActor3D::New();
395 //      textActor->SetInput( strLabel.c_str()  );
396         renderer->AddActor( textActor );
397         lstActorsText.push_back(textActor);
398 }
399  */
400
401
402 //------------------------------------------------------------------------
403 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
404 {
405         GetModelShowNPoints()->AddPoint(x,y,z, label );
406     // EED 2022-05-19
407     //AddVtkPoint();
408     //RefreshPoint(lstActorsSphere.size()-1);
409     GetViewShowNPoints()->AddPoint();
410 }
411
412 //------------------------------------------------------------------------
413 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
414 {
415     // EED 2022-05-19
416         //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
417         //{
418     //    AddVtkPoint();
419         //} else {
420         //      AddPoint(x,y,z,label);
421         //}
422         //RefreshPoints();
423     if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
424     {
425         GetViewShowNPoints()->AddVtkPoint();
426     } else {
427         AddPoint(x,y,z,label);
428     }
429     GetViewShowNPoints()->RefreshPoints();
430
431 }
432
433 //------------------------------------------------------------------------
434 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
435 {       
436     // EED 2022-05-19
437         //if (this->renderer==NULL)
438     if (GetViewShowNPoints()->renderer==NULL)
439         {
440                 return;
441         }
442
443         std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
444         if (point.size()==3)
445         {
446                 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
447                 SetOutputBox();
448         // EED 2022-05-19
449         //renderer->GetRenderWindow()->Render();
450         GetViewShowNPoints()->Render();
451         } else {//mpoint.size
452                 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
453         }
454 }
455
456 //------------------------------------------------------------------------
457 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
458 {       
459     // EED 2022-05-19
460     //if (this->renderer==NULL)
461     if (GetViewShowNPoints()->renderer==NULL)
462         {
463                 return;
464         }
465
466         std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
467         if (point.size()==3)
468         {
469                 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
470                 SetOutputBox();
471         } else {//mpoint.size
472                 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
473         }
474 }
475
476
477 //------------------------------------------------------------------------
478         void WidgetShowNPoints::SetOutputBox()
479         {
480 //EED           renderer->GetRenderWindow()->Render();
481                 wxString strTmp;
482                 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
483                 txtNrPoints->SetLabel( strTmp );
484                 //--BBTK
485
486 //EED 2017-06-03
487 //              mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
488 //              mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
489 //              mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
490 //              mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
491 //              mbbShowNPoints->bbSignalOutputModification();
492         }
493
494
495 //------------------------------------------------------------------------
496         void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
497         {
498
499 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
500 #if wxMAJOR_VERSION <= 2
501                 wxFileDialog* FD = new wxFileDialog( 0,
502                                             _T("Save points .."),
503                                             _T(""),
504                                             _T(""),
505                                             _T("(*.xls)|*.xls"),
506                                             wxSAVE | wxOVERWRITE_PROMPT,
507                                             wxDefaultPosition);
508 #else
509                 wxFileDialog* FD = new wxFileDialog( 0,
510                                             _T("Save points .."),
511                                             _T(""),
512                                             _T(""),
513                                             _T("(*.xls)|*.xls"),
514                                             wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
515                                             wxDefaultPosition);
516 #endif
517
518                 int result_FD = FD->ShowModal();
519                 // This line is need it by windows //EED
520                 FD->SetReturnCode( result_FD );
521                 if (FD->GetReturnCode()==wxID_OK)
522                 {
523                         std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
524                         GetModelShowNPoints()->SavePoints( filename );
525                 }       // dialog box
526         }
527
528
529 //------------------------------------------------------------------------
530         void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
531         {
532
533 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
534 #if wxMAJOR_VERSION <= 2
535                 wxFileDialog* FD = new wxFileDialog( 0,
536                                              _T("Load points .."),
537                                              _T(""),
538                                              _T(""),
539                                              _T("(*.xls)|*.xls"),
540                                              wxOPEN | wxFILE_MUST_EXIST,
541                                              wxDefaultPosition);
542 #else
543                 wxFileDialog* FD = new wxFileDialog( 0,
544                                              _T("Load points .."),
545                                              _T(""),
546                                              _T(""),
547                                              _T("(*.xls)|*.xls"),
548                                              wxFD_OPEN | wxFD_FILE_MUST_EXIST,
549                                              wxDefaultPosition);
550 #endif
551                 int i;
552                 //EED
553                 int result_FD = FD->ShowModal();
554                 // This line is need it by windows //EED
555                 FD->SetReturnCode( result_FD );
556                 if (FD->GetReturnCode()==wxID_OK)
557                 {
558
559                         std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
560                         int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
561                         for (i=0;i<numberPointsRead;i++)
562                         {
563                 // EED 2022-05-19
564                 //AddVtkPoint();
565                 GetViewShowNPoints()->AddVtkPoint();
566                         }// for
567                         SetOutputBox();
568             // EED 2022-05-19
569                         //RefreshPoints();
570             GetViewShowNPoints()->RefreshPoints();
571                 }       // dialog box
572         }
573
574         //------------------------------------------------------------------------
575         void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
576         {
577                 int id=GetModelShowNPoints()->GetNearestPoint();
578                 if((id==-1) && (mtype==1))
579                 {
580                         id=0;
581                         AddPoint(0,0,0,"");
582                         SetOutputBox();
583                 }
584         
585                 if (id>=0)
586                 {
587                         GetModelShowNPoints()->SetPointId_mReferencePoint(id);
588             // EED 2022-05-19
589                         //RefreshPoint(id);
590                         //renderer->GetRenderWindow()->Render();
591             GetViewShowNPoints()->RefreshPoint(id);
592             GetViewShowNPoints()->Render();
593                 } // if id
594                 SetOutputBox();
595         }
596         
597 //------------------------------------------------------------------------
598         void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
599         {
600                 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
601                 if (id>=0)
602                 {
603             // EED 2022-05-19
604                         //lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
605                         //renderer->GetRenderWindow()->Render();
606             GetViewShowNPoints()->lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
607             GetViewShowNPoints()->Render();
608             SetOutputBox();
609                 }
610         }
611
612 //------------------------------------------------------------------------
613         void WidgetShowNPoints::ErasePoint(int id)
614         {
615         // EED 2022-05-19
616                 //if (this->renderer!=NULL)
617         if (GetViewShowNPoints()->renderer!=NULL)
618                 {
619                         if (id>=0)
620                         {
621                 // EED 2022-05-19
622                                 //renderer->RemoveActor( lstActorsSphere[id] );
623                                 //renderer->RemoveActor( lstActorsText[id] );
624                                 //lstActorsSphere[id]->Delete();
625                                 //lstActorsText[id]->Delete();
626                                 //lstSourceSphere[id]->Delete();
627                                 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
628                                 //lstActorsText.erase( lstActorsText.begin()+id );
629                                 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
630                 GetViewShowNPoints()->ErasePoint(id);
631                                 GetModelShowNPoints()->ErasePoint(id);
632                         } // if id
633                 } // if renderer
634         }
635
636 //------------------------------------------------------------------------
637         void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
638         {
639                 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
640                 SetOutputBox();
641         // EED 2022-05-19
642                 //renderer->GetRenderWindow()->Render();
643         GetViewShowNPoints()->Render();
644         }
645
646 //------------------------------------------------------------------------
647         void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
648         {
649         // EED 2022-05-19
650         //ErasePoint( lstActorsSphere.size()-1 );
651         //renderer->GetRenderWindow()->Render();
652         int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
653         ErasePoint( id );
654         GetViewShowNPoints()->Render();
655         SetOutputBox();
656         }
657
658 //------------------------------------------------------------------------
659 void WidgetShowNPoints::DeleteAllPoints()
660 {
661     // EED 2022-05-19
662         //int id,size=lstActorsSphere.size();
663     int id,size=GetViewShowNPoints()->lstActorsSphere.size();
664         for (id=size-1;id>=0;id--)
665         {
666                 ErasePoint(id);
667         }
668         SetOutputBox();
669     // EED 2022-05-19
670         //renderer->GetRenderWindow()->Render();
671     GetViewShowNPoints()->Render();
672 }
673
674 //------------------------------------------------------------------------
675 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
676 {
677         DeleteAllPoints();
678 }
679
680 //NTU: Method for updating points opacity and Radio
681
682 //------------------------------------------------------------------------
683 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
684 {
685     // EED 2022-05-19
686         //this->mopacity = sdrOpacity->GetValue()/100.0;
687     //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
688     //RefreshPoints();
689
690     double opacity  = sdrOpacity->GetValue()/100.0;
691     double radio    = sdrRadio->GetValue();
692     int i,size      = lstViewShowNPoints.size();
693     for (i=0 ; i<size ; i++)
694     {
695         lstViewShowNPoints[i]->mopacity = opacity;
696         lstModelShowNPoints[i]->SetRadio( radio ) ;
697     } // for i
698     GetViewShowNPoints()->RefreshPoints();
699 }
700
701 //------------------------------------------------------------------------
702 void  WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
703 {
704         GetModelShowNPoints()->SetReferencePoint(point);
705 }
706
707 //------------------------------------------------------------------------
708 void  WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX,  std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
709 {
710     // EED 2022-05-19
711         //if (this->renderer==NULL)
712     if (GetViewShowNPoints()->renderer==NULL)
713         {
714                 return;
715         }
716         int i,sizeX,sizeY,sizeZ,sizeLabels;
717         sizeX = (int)initLstPointsX.size();
718         sizeY = (int)initLstPointsY.size();
719         sizeZ = (int)initLstPointsZ.size();
720         sizeLabels = (int)initLstLabels.size();
721         int x,y,z;
722         std::string label;
723         if ( (sizeX==sizeY) && (sizeX==sizeZ) )
724         {
725                 for (i=0;i<sizeX;i++)
726                 {
727                         x               = initLstPointsX[i];
728                         y               = initLstPointsY[i];
729                         z               = initLstPointsZ[i];
730                         if (i<sizeLabels) 
731                         {
732                                 label   = initLstLabels[i];
733                         } else {
734                                 label="";
735                         }
736                         AddPoint( x,y,z,label );
737                 } // for i
738                 //      SetOutputBox(); 
739                 //      renderer->GetRenderWindow()->Render();
740         } // if size
741 }
742
743 //------------------------------------------------------------------------
744 void WidgetShowNPoints::SetType(int type)
745 {
746         mtype=type;
747 }
748
749 //------------------------------------------------------------------------
750 int WidgetShowNPoints::GetType()
751 {
752         return mtype;
753 }
754
755
756 //------------------------------------------------------------------------
757 double WidgetShowNPoints::GetRadio()
758 {
759         return sdrRadio->GetValue();
760 }
761 //------------------------------------------------------------------------
762 double WidgetShowNPoints::GetOpacity()
763 {
764         return sdrOpacity->GetValue()/100;
765 }
766
767 //------------------------------------------------------------------------
768 void WidgetShowNPoints::InsertCollection()
769 {
770     ModelShowNPoints*   model   = new ModelShowNPoints();
771     ViewShowNPoints*    view    = new ViewShowNPoints( model );
772     model->SetImage( lstModelShowNPoints[0]->GetImage() );
773     view->mopacity = lstViewShowNPoints[0]->mopacity;
774     view->renderer = lstViewShowNPoints[0]->renderer;
775     lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
776     lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
777     RefreshCollectionText();
778 }
779
780 //------------------------------------------------------------------------
781 void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
782 {
783     InsertCollection();
784 }
785
786 //------------------------------------------------------------------------
787 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
788 {
789     mActualCollection++;
790     InsertCollection();
791 }
792
793 //------------------------------------------------------------------------
794 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
795 {
796     if ( lstModelShowNPoints.size()>1 )
797     {
798         DeleteAllPoints();  // Actual Collection
799         lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
800         lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
801         if ( mActualCollection>=lstModelShowNPoints.size() )
802         {
803             mActualCollection--;
804         } // if
805     }
806     RefreshCollectionText();
807 }
808
809 //------------------------------------------------------------------------
810 void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
811 {
812     mActualCollection--;
813     if ( mActualCollection <0  )
814     {
815         mActualCollection=0;
816     } //if <=0
817     RefreshCollectionText();
818 }
819
820 //------------------------------------------------------------------------
821 void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
822 {
823     mActualCollection++;
824     if ( mActualCollection >=lstModelShowNPoints.size() )
825     {
826         mActualCollection = lstModelShowNPoints.size()-1;
827     } //if <=0
828     RefreshCollectionText();
829 }
830
831 //------------------------------------------------------------------------
832 void WidgetShowNPoints::RefreshCollectionText()
833 {
834     wxString strTmp;
835     strTmp.Printf(_T("%d   /  %d "),  (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
836     txtNrCollections->SetLabel( strTmp );
837     SetOutputBox();
838 }