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