]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
#3516 Join points tool
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / WidgetShowNPoints.cxx
1
2 #include "vtkSphereSource.h"
3 #include "vtkRenderer.h"
4 #include "vtkTextActor3D.h"
5
6 #include <wx/button.h>
7 #include <wx/sizer.h>
8 #include <wx/filedlg.h>
9 #include <wx/msgdlg.h>
10 #include <wx/notebook.h>
11
12 #include "WidgetShowNPoints.h"
13
14 //----------------------------------------------------------------------
15 //----------------------------------------------------------------------
16 //----------------------------------------------------------------------
17 //----------------------------------------------------------------------
18 //----------------------------------------------------------------------
19   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
20     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
21   {
22         // EED 2022-05-19
23     //  mmodelShowNPoints                                   = new ModelShowNPoints();
24                         idUndoRedo          = 0;
25                         maxUndoRedo         = 0;        
26 #if defined(_WIN32)
27                                                 char * val = getenv( "TEMP" );
28                                                 if (val == NULL) 
29                                                 { 
30                                                         UndoRedoDir = std::string("");  
31                                                 } else { 
32                                                         UndoRedoDir = std::string(val)+"\\creatools"; 
33                                                         printf("WidgetShowNPoints::WidgetShowNPoints  UndoRedoDir = %s   %p \n", UndoRedoDir.c_str() , this );
34                                                         std::string cmd1 = "mkdir "+ UndoRedoDir;
35                                                         system( cmd1.c_str() );
36                                                         // Erasing files of more than 1 day old  ( -1 )
37                                                         std::string cmd2 = "ForFiles /p \"" + UndoRedoDir + "\" /s /d -1 /c \"cmd /c del @file \"";
38                                                         system( cmd2.c_str() );
39                                                 }
40 #elif defined(__GNUC__)
41
42
43     #if defined(MACOSX)
44                                                 UndoRedoDir         = "/tmp/creatools";
45     #else  // Linux
46                                                 UndoRedoDir         = "/tmp/creatools";
47     #endif
48         
49         printf("WidgetShowNPoints::WidgetShowNPoints  UndoRedoDir = %s   %p \n", UndoRedoDir.c_str() , this );
50     std::string cmd1 = "mkdir "+ UndoRedoDir;
51     system( cmd1.c_str() );
52         // Erasing files of more than 1 day old  ( +1 )
53         std::string cmd= "find "+UndoRedoDir+" -name \"UndoRedo_collection_*.undoredo\" -type f -mtime +1 -delete";
54         system( cmd.c_str() );
55
56 #else
57                                                 UndoRedoDir         = "./";
58 #endif
59    
60    
61                         mActualCollection   = 0;
62     ModelShowNPoints*   modelShowNPoints    = new ModelShowNPoints();
63     lstModelShowNPoints.push_back( modelShowNPoints );
64     lstViewShowNPoints.push_back( new  ViewShowNPoints( modelShowNPoints ) );
65       
66     mtype                                                       = type;
67     SetType(mtype);
68     wxPanel*    panelParent         = this;
69     wxSizer*    sizer                           = NULL;
70     wxSizer*    MNPsizer            = NULL;
71     wxNotebook* bookSetPoints       = NULL;
72     wxNotebook* bookGroupManager    = NULL;
73     wxPanel*    panel               = NULL;
74     wxPanel*    panel2              = NULL;
75                 txtNrCollections    = NULL;
76       bookSetPoints     = new wxNotebook(panelParent,
77                           -1,
78                           wxDefaultPosition,
79                           wxDefaultSize,
80                           wxNB_TOP );
81       panel  = new wxPanel(bookSetPoints);
82       txtNrCollections = NULL;
83
84       wxSize sizeButton;
85       sizeButton.Set( 45  ,  -1 );
86       wxSize sizeSlider;
87       sizeSlider.Set( 90  ,  -1 );
88
89     // Group Manager
90     if (mtype==4)
91     {
92           bookGroupManager   = new wxNotebook(panelParent, //bbGetWxParent(),
93                               -1,
94                               wxDefaultPosition,
95                               wxDefaultSize,
96                               wxNB_TOP );
97           panel2  = new wxPanel(bookGroupManager);
98           txtNrCollections                      = new wxStaticText(panel2,-1, _T("1   /  1 "));
99           wxButton *btnBackCollection           = new wxButton( panel2, -1, _T("<")     ,   wxDefaultPosition, sizeButton );
100           wxButton *btnNextCollection           = new wxButton( panel2, -1, _T(">")     ,   wxDefaultPosition, sizeButton );
101           wxButton *btnInsertCollectionBefore   = new wxButton( panel2, -1, _T("+<")    ,   wxDefaultPosition, sizeButton );
102           wxButton *btnInsertCollectionAfter    = new wxButton( panel2, -1, _T("+>")    ,   wxDefaultPosition, sizeButton );
103           wxButton *btnDeleteCollection         = new wxButton( panel2, -1, _T("-")     ,   wxDefaultPosition, sizeButton );
104           wxButton *btnResetCollection          = new wxButton( panel2, -1, _T("--")    ,   wxDefaultPosition, sizeButton );
105           wxButton *btnSaveCollection           = new wxButton( panel2, -1, _T("Save")  ,   wxDefaultPosition, sizeButton );
106           wxButton *btnLoadCollection           = new wxButton( panel2, -1, _T("Load")  ,   wxDefaultPosition, sizeButton );
107           wxFlexGridSizer *sizer1               = new wxFlexGridSizer(1);
108           wxFlexGridSizer *sizer2               = new wxFlexGridSizer(2);
109           wxFlexGridSizer *sizer3               = new wxFlexGridSizer(3);
110           wxFlexGridSizer *sizer4               = new wxFlexGridSizer(3);
111           wxFlexGridSizer *sizer5               = new wxFlexGridSizer(1);
112           wxFlexGridSizer *sizer6               = new wxFlexGridSizer(2);
113  //         wxStaticText* txOpacity               = new wxStaticText(panel2, -1, wxString(_T("Op:")));
114         
115           btnInsertCollectionBefore   -> SetToolTip( _T("+  Add group before") );
116           btnInsertCollectionAfter    -> SetToolTip( _T("+>  Add group after") );
117           btnDeleteCollection         -> SetToolTip( _T("-  Erase group") );
118           btnResetCollection          -> SetToolTip( _T("-- Reset : Erase all groups") );
119
120           sdrOpacity                            = new wxSlider(panel2, -1, 0, 0, 100, wxDefaultPosition, sizeSlider, wxSL_LABELS);
121 //          wxStaticText* txRadio                 = new wxStaticText(panel2, -1, wxString(_T("R:")));
122           sdrRadio                              = new wxSlider(panel2, -1, 0, 1, 50, wxDefaultPosition, sizeSlider, wxSL_LABELS);
123
124           sdrRadio                    -> SetToolTip( _T("Radio") );
125           sdrOpacity                  -> SetToolTip( _T("Opacity") );
126         
127           Connect(btnBackCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnBackCollection           );
128           Connect(btnNextCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnNextCollection           );
129           Connect(btnInsertCollectionBefore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionBefore   );
130           Connect(btnInsertCollectionAfter->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionAfter    );
131           Connect(btnDeleteCollection->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteCollection         );
132           Connect(sdrOpacity->GetId()               , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints                );
133           Connect(sdrRadio->GetId()                 , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints                );
134           Connect(btnSaveCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnSaveCollections          );
135           Connect(btnLoadCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnLoadCollections          );
136           Connect(btnResetCollection->GetId()       , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnResetCollections         );
137         
138           sizer2->Add( btnBackCollection );
139           sizer2->Add( btnNextCollection );
140           sizer3->Add( btnInsertCollectionBefore );
141           sizer3->Add( btnInsertCollectionAfter );
142           sizer4->Add( btnLoadCollection );
143           sizer4->Add( btnSaveCollection );
144 //          sizer5->Add( txRadio ,wxGROW );
145           sizer5->Add( sdrRadio ,wxGROW );
146 //          sizer5->Add( txOpacity ,wxGROW );
147           sizer5->Add( sdrOpacity ,wxGROW );
148           sizer6->Add( btnDeleteCollection );
149           sizer6->Add( btnResetCollection );
150
151           sizer1->Add( txtNrCollections );
152           sizer1->Add( sizer2 );
153           sizer1->Add( sizer3 );
154           sizer1->Add( sizer6 );
155           sizer1->Add( sizer4 );
156           sizer1->Add( sizer5 ,wxGROW );
157
158           MNPsizer                        = sizer1;
159           panel2->SetSizer( MNPsizer );
160           panel2->SetAutoLayout(true);
161           panel2->Layout();
162           bookGroupManager->AddPage(panel2 , _T("Groups") );
163     } // if mtype 4
164
165         if ( (mtype==0) || (mtype==3) || (mtype==4) )
166         {
167                 // Widget interface
168 //              askPointLabel                                       = new wxStaticText(panel, -1, _T("Label:")); // JPR
169                 textCtrl                                                    = new wxTextCtrl(panel, -1, wxEmptyString   ,    wxDefaultPosition, sizeButton);
170                     cbAutoAddPoints         = new wxCheckBox(panel,-1, _T("Auto")       ,   wxDefaultPosition, sizeButton );
171                 wxButton    *btnAddPoint                    = new wxButton( panel, -1, _T("+")          ,   wxDefaultPosition, sizeButton );
172                 wxButton    *btnInsertPoint                 = new wxButton( panel, -1, _T("(+)")        ,   wxDefaultPosition, sizeButton );//CFT
173                 wxButton    *btnSetPositionPoint    = new wxButton( panel, -1, _T("Set")        ,   wxDefaultPosition, sizeButton );
174                      cbTrackPoint           = new wxCheckBox(panel,-1, _T("Tra.")       ,   wxDefaultPosition, sizeButton );
175         wxButton    *btnRenamePoint                 = new wxButton( panel, -1, _T("Ren.")       ,   wxDefaultPosition, sizeButton );
176         wxButton    *btnErasePoint          = new wxButton( panel, -1, _T("-")          ,   wxDefaultPosition, sizeButton );
177                 wxButton    *btnEraseLastPoint      = new wxButton( panel, -1, _T("- lst")      ,   wxDefaultPosition, sizeButton );
178                 wxButton    *btnDeleteAllPoints     = new wxButton( panel, -1, _T("--")         ,   wxDefaultPosition, sizeButton );
179         wxButton    *btnUndo                = new wxButton( panel, -1, _T("Undo")       ,   wxDefaultPosition, sizeButton );
180         wxButton    *btnRedo                = new wxButton( panel, -1, _T("Redo")       ,   wxDefaultPosition, sizeButton );
181                 wxButton    *btnSavePoints                  = NULL;
182                 wxButton    *btnLoadPoints                  = NULL;
183                 
184         cbAutoAddPoints     -> SetToolTip( _T("Auto Add point")          );
185         btnAddPoint         -> SetToolTip( _T("+  Add point")          );
186         btnInsertPoint      -> SetToolTip( _T("(-)  Insert point")       );
187         btnErasePoint       -> SetToolTip( _T("-  Erase point")        );
188         btnEraseLastPoint   -> SetToolTip( _T("- lst  Erase last point")   );
189         btnDeleteAllPoints  -> SetToolTip( _T("-- Erase all points")   );
190         
191                 if ( mtype==0 )
192                 {
193                         btnSavePoints                           = new wxButton( panel, -1, _T("Save points"));
194                         btnLoadPoints                           = new wxButton( panel, -1, _T("Load points"));
195             Connect(btnSavePoints->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
196             Connect(btnLoadPoints->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
197                 } // if mtype
198                 txtNrPoints                                             = new wxStaticText(panel,-1, _T(" "));
199
200         wxStaticText* txOpacity;
201         wxStaticText* txRadio;
202         if ( (mtype==0) || (mtype==3) )
203         {
204             //NTU: Sliders for opacity and radio change
205             txOpacity         = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
206             sdrOpacity        = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
207             txRadio           = new wxStaticText(panel, -1, wxString(_T("  Points Radius  ")));
208             sdrRadio          = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
209             //NTU: Slider events
210             Connect(sdrOpacity->GetId()          , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
211             Connect(sdrRadio->GetId()            , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
212         } // if mtype 0 3
213         Connect(cbAutoAddPoints->GetId()    , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WidgetShowNPoints::OnAutoAddPoints);
214                 Connect(btnAddPoint->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
215                 Connect(btnInsertPoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
216                 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
217                 Connect(btnRenamePoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
218                 Connect(btnEraseLastPoint->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
219                 Connect(btnErasePoint->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
220                 Connect(btnDeleteAllPoints->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
221         Connect(cbTrackPoint->GetId()       , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WidgetShowNPoints::OnTrackPoint);
222         Connect(btnUndo->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnUndo);
223         Connect(btnRedo->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRedo);
224         wxFlexGridSizer *sizer0 = new wxFlexGridSizer(1);
225         wxFlexGridSizer *sizer1 = new wxFlexGridSizer(2);
226         wxFlexGridSizer *sizer2 = new wxFlexGridSizer(2);
227         wxFlexGridSizer *sizer3 = new wxFlexGridSizer(2);
228         wxFlexGridSizer *sizer4 = new wxFlexGridSizer(2);
229         wxFlexGridSizer *sizer5 = new wxFlexGridSizer(2);
230         sizer1->Add( textCtrl               );
231         sizer1->Add( btnRenamePoint         );
232         sizer2->Add( cbAutoAddPoints        );
233         sizer2->Add( new wxStaticText(panel, -1, _T(" "))            );
234         sizer2->Add( btnAddPoint            );
235         sizer2->Add( btnInsertPoint         );//CFT
236         sizer3->Add( btnSetPositionPoint    );
237         sizer3->Add( cbTrackPoint           );
238         sizer4->Add( btnErasePoint          );
239         sizer4->Add( btnEraseLastPoint      );
240         sizer4->Add( btnDeleteAllPoints     );
241         sizer5->Add( btnUndo                );
242         sizer5->Add( btnRedo                );
243 //              sizer0->Add(askPointLabel); // JPR
244         sizer0->Add(txtNrPoints);
245         sizer0->Add(sizer2);
246         sizer0->Add(sizer1);
247                 sizer0->Add(sizer3);
248         sizer0->Add(sizer4);
249         sizer0->Add(sizer5);
250         if ( (mtype==0) || (mtype==3) )
251         {
252             wxFlexGridSizer *sizer5 = new wxFlexGridSizer(1);
253             sizer5->Add(txRadio);
254             sizer5->Add(sdrRadio,1,wxGROW );
255             sizer5->Add(txOpacity);
256             sizer5->Add(sdrOpacity,1,wxGROW );
257             sizer0->Add(sizer5);
258         }  // if mtype 0 3
259         if ( mtype==0 )
260                 {
261             wxFlexGridSizer *sizer6 = new wxFlexGridSizer(2);
262                         sizer6->Add(btnSavePoints);
263                         sizer6->Add(btnLoadPoints);
264             sizer0->Add(sizer6);
265                 } // if mtype 0
266                 sizer = sizer0;
267         }
268
269           if (mtype==1)
270           {
271                   // Widget interface
272                   wxButton *btnSetPositionPoint         = new wxButton( panel, -1, _T("Set nearest point"));
273                   txtNrPoints                                           = new wxStaticText(panel,-1, _T(" "));
274
275                   //NTU: Sliders for opacity and radio change
276                   wxStaticText* txOpacity                       = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
277                   sdrOpacity                                            = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
278                   wxStaticText* txRadio                         = new wxStaticText(panel, -1, wxString(_T("  Points Radio  ")));
279                   sdrRadio                                                      = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
280                   Connect(btnSetPositionPoint->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
281                   Connect(sdrOpacity->GetId()   , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
282                   Connect(sdrRadio->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
283
284           wxFlexGridSizer *sizer1            = new wxFlexGridSizer(1);
285                   sizer1->Add(btnSetPositionPoint);
286                   sizer1->Add(txtNrPoints);
287                   sizer1->Add(txRadio);
288                   sizer1->Add(sdrRadio,1,wxGROW );
289           sizer1->Add(txOpacity);
290           sizer1->Add(sdrOpacity,1,wxGROW );
291                   sizer = sizer1;
292           }
293     
294     if (mtype == 2) 
295         {
296                 askPointLabel                                           = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
297         wxButton                *btnAddPoint            = new wxButton(panel, -1,        _T("      Add  Point      "));
298         wxButton                *btnDeleteAllPoints = new wxButton(panel, -1, _T("      Delete All      "));
299         wxStaticText    *spacer                         = new wxStaticText(panel, -1, _T("\n")); // JPR
300                                          textCtrl                       = new wxTextCtrl(panel, -1);
301         Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
302         Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);    
303         wxFlexGridSizer *sizer1             = new wxFlexGridSizer(1);
304         sizer1->Add(askPointLabel);
305         sizer1->Add(btnAddPoint);
306         sizer1->Add(btnDeleteAllPoints);
307         sizer1->Add(spacer);
308         sizer1->Add(textCtrl);
309       //  sdrOpacity                          = new wxSlider();
310       //  sdrRadio                            = new wxSlider();
311         txtNrPoints                         = new wxStaticText(panel, -1, _T("\n\n\n"));
312         sizer                               = sizer1;
313         } // bbGetInputType 2
314
315     panel->SetSizer(sizer);
316     panel->SetAutoLayout(true);
317     panel->Layout();
318     bookSetPoints->AddPage(panel , _T("Points") );
319
320     if ((mtype >= 0) && (mtype <= 3) )
321     {
322         if (sizer!=NULL)
323         {
324             wxFlexGridSizer *sizerParent             = new wxFlexGridSizer(1);
325             sizerParent->Add( bookSetPoints );
326             panelParent->SetSizer( sizerParent );
327             panelParent->SetAutoLayout(true);
328             panelParent->Layout();
329         } // if sizer
330     } // if  mtype 0 1 2 3
331       
332     if (mtype == 4)
333     {
334         if ((sizer!=NULL) && (MNPsizer!=NULL))
335         {
336             wxFlexGridSizer *sizerG             = new wxFlexGridSizer(2);
337             sizerG->Add(bookGroupManager);
338             sizerG->Add(bookSetPoints);
339             panelParent->SetSizer(sizerG);
340             panelParent->SetAutoLayout(true);
341             panelParent->Layout();
342         } // if sizer
343     } // if mtype 4
344 }
345
346 //------------------------------------------------------------------------
347 WidgetShowNPoints::~WidgetShowNPoints()
348 {
349 }
350
351 //------------------------------------------------------------------------
352 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
353 {
354     // EED 2022-05-19
355     // return mmodelShowNPoints;
356     return lstModelShowNPoints[ mActualCollection ];
357 }
358
359 //------------------------------------------------------------------------
360 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints(int id)
361 {
362         if(id >= 0 && id < lstModelShowNPoints.size())
363         {
364                 return lstModelShowNPoints[ id ];       
365         }
366 }
367
368 // EED 2022-05-19
369 //------------------------------------------------------------------------
370 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
371 {
372     return lstViewShowNPoints[ mActualCollection ];
373 }
374
375
376 //------------------------------------------------------------------------
377 void WidgetShowNPoints::SetRadio(double radio)
378 {
379     // EED 2022-05-19
380     // GetModelShowNPoints()->SetRadio(radio);
381     int i,size = lstModelShowNPoints.size();
382     for (i=0;i<size;i++)
383     {
384         lstModelShowNPoints[i]->SetRadio( radio );
385     } // for i
386         //NTU: For Slider
387         sdrRadio->SetValue(radio);
388 }
389
390 //------------------------------------------------------------------------
391 void WidgetShowNPoints::SetColour(std::vector<double> colour)
392 {
393     // EED 2022-05-19
394     //this->mcolour = colour;
395     int i,size = lstViewShowNPoints.size();
396     for (i=0 ; i<size ; i++)
397     {
398         lstViewShowNPoints[i]->mcolour = colour;
399     } // for i
400 }
401
402 //------------------------------------------------------------------------
403 void WidgetShowNPoints::SetImage(vtkImageData* image)
404 {
405     // EED 2022-05-19
406         //GetModelShowNPoints()->SetImage(image);
407     int i,size = lstModelShowNPoints.size();
408     for (i=0 ; i<size ; i++)
409     {
410         lstModelShowNPoints[i]->SetImage(image);
411     } // for i
412 }
413
414 //------------------------------------------------------------------------
415 void WidgetShowNPoints::SetOpacity(double opacity)
416 {
417     // EED 2022-05-19
418         //this->mopacity=opacity;
419     int i,size = lstViewShowNPoints.size();
420     for (i=0 ; i<size ; i++)
421     {
422         lstViewShowNPoints[i]->mopacity = opacity;
423     } // for i
424         //NTU: For Slider
425         sdrOpacity->SetValue( opacity*100.0 );
426 }
427
428
429 //------------------------------------------------------------------------
430 void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
431 {
432     // EED 2022-05-19
433         //this->renderer        = renderer;
434     int i,size = lstViewShowNPoints.size();
435     for (i=0 ; i<size ; i++)
436     {
437         lstViewShowNPoints[i]->renderer = renderer;
438     } // for i
439 }
440
441 /* EED 2022-05-19
442 //------------------------------------------------------------------------
443         
444 void WidgetShowNPoints::RefreshPoint(int id)
445 {
446         double spc[3];
447         int x,y,z;
448         GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
449         GetModelShowNPoints()->GetImage()->GetSpacing(spc);
450         std::string label       = GetModelShowNPoints()->GetIdLabel(id);
451         double radio            = GetModelShowNPoints()->GetRadio();
452     lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
453     lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
454     lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
455     lstSourceSphere[id]->SetRadius( radio );
456 //EED 2017-01-01 Migration VTK7
457 #if VTK_MAJOR_VERSION <= 5
458         // ..
459 #else
460     lstSourceSphere[id]->Update();
461 #endif
462     lstActorsText[id]->SetInput( label.c_str()  );
463     lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
464 }
465
466 //------------------------------------------------------------------------
467 void WidgetShowNPoints::RefreshPoints()
468 {
469         int id,size=lstActorsSphere.size();
470         for (id=0;id<size;id++)
471         {
472                 RefreshPoint(id);
473         } // for
474         renderer->GetRenderWindow()->Render();
475 }
476
477 //------------------------------------------------------------------------
478 void WidgetShowNPoints::AddVtkPoint()
479 {
480         // Sphere
481         vtkSphereSource *vtksphere = vtkSphereSource::New();
482         vtksphere->SetThetaResolution (20);
483         vtksphere->SetPhiResolution (20);
484         vtksphere->SetRadius( 1 );
485         //NTU: For updating points
486         lstSourceSphere.push_back(vtksphere);
487         vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
488
489 //EED 2017-01-01 Migration VTK7
490 #if VTK_MAJOR_VERSION <= 5
491         sphereMapper->SetInput( vtksphere->GetOutput() );
492 #else
493         vtksphere->Update();
494         sphereMapper->SetInputData( vtksphere->GetOutput() );
495 #endif
496
497         vtkActor *sphereActor   = vtkActor::New();
498         sphereActor->SetMapper(sphereMapper);
499         sphereActor->SetOrigin(0, 0, 0);
500
501         lstActorsSphere.push_back(sphereActor);
502         if(renderer==NULL){
503                 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
504                 dialog.ShowModal();             
505                 return;
506         }
507         renderer->AddActor( sphereActor );
508         // Actor
509         vtkTextActor3D *textActor = vtkTextActor3D::New();
510 //      textActor->SetInput( strLabel.c_str()  );
511         renderer->AddActor( textActor );
512         lstActorsText.push_back(textActor);
513 }
514  */
515
516
517 //------------------------------------------------------------------------
518 void WidgetShowNPoints::AddPoint(double x, double y, double z, std::string label)
519 {
520         GetModelShowNPoints()->AddPoint(x,y,z, label );
521     // EED 2022-05-19
522     //AddVtkPoint();
523     //RefreshPoint(lstActorsSphere.size()-1);
524     GetViewShowNPoints()->AddPoint();
525 }
526
527 //------------------------------------------------------------------------
528 void WidgetShowNPoints::InsertPoint(double x, double y, double z, std::string label)//CFT
529 {
530     // EED 2022-05-19
531         //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
532         //{
533     //    AddVtkPoint();
534         //} else {
535         //      AddPoint(x,y,z,label);
536         //}
537         //RefreshPoints();
538     if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
539     {
540         GetViewShowNPoints()->AddVtkPoint();
541     } else {
542         AddPoint(x,y,z,label);
543     }
544     GetViewShowNPoints()->RefreshPoints();
545 }
546
547 //------------------------------------------------------------------------
548 void WidgetShowNPoints::OnInsertPoint_()
549 {
550     // EED 2022-05-19
551     //if (this->renderer==NULL)
552     
553     StopAutoAddPoints();
554     StopTrackPoint();
555     if (GetViewShowNPoints()->renderer==NULL)
556     {
557         return;
558     }
559     std::vector<double> point = GetModelShowNPoints()->GetReferencePoint();
560     if (point.size()==3)
561     {
562         InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
563         SetOutputBox();
564     } else {//mpoint.size
565         printf("creaMaracasVisu::ShowNPoints (not match point) \n");
566     }
567     UndoRedo_SaveCollection();
568 }
569
570 //------------------------------------------------------------------------
571 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
572 {
573     OnInsertPoint_();
574 }
575
576 //------------------------------------------------------------------------
577 void WidgetShowNPoints::OnAddPoint__()
578 {       
579     // EED 2022-05-19
580         //if (this->renderer==NULL)
581     if (GetViewShowNPoints()->renderer==NULL)
582         {
583                 return;
584         }
585         std::vector<double> point = GetModelShowNPoints()->GetReferencePoint();
586         if (point.size()==3)
587         {
588                 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
589         SetOutputBox();
590         // EED 2022-05-19
591         //renderer->GetRenderWindow()->Render();
592         GetViewShowNPoints()->Render();
593         } else {//mpoint.size
594                 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
595         }
596     UndoRedo_SaveCollection();
597 }
598
599 void WidgetShowNPoints::OnAddPoint_()
600 {
601     StopAutoAddPoints();
602     StopTrackPoint();
603     OnAddPoint__();
604 }
605
606 //------------------------------------------------------------------------
607 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
608 {
609     OnAddPoint_();
610 }
611
612 //------------------------------------------------------------------------
613 void WidgetShowNPoints::AutoAddPoints()
614 {
615     if ( cbAutoAddPoints->GetValue() == true )
616     {
617         OnAddPoint__();
618     } // if cbAutoAddPoints
619 }
620
621 //------------------------------------------------------------------------
622 void WidgetShowNPoints::OnAutoAddPoints_tool()
623 {
624     StopTrackPoint();
625     cbAutoAddPoints->SetValue( !cbAutoAddPoints->GetValue() );
626 }
627
628 //------------------------------------------------------------------------
629 void WidgetShowNPoints::OnAutoAddPoints_()
630 {
631     StopTrackPoint();
632     printf("EED WidgetShowNPoints::OnAutoAddPoints_ \n");
633 }
634
635 //------------------------------------------------------------------------
636 void WidgetShowNPoints::OnAutoAddPoints(wxCommandEvent& event)
637 {
638     StopTrackPoint();
639     printf("EED WidgetShowNPoints::OnAutoAddPoints \n");
640 }
641
642 //------------------------------------------------------------------------
643 void WidgetShowNPoints::StopAutoAddPoints( )
644 {
645     cbAutoAddPoints->SetValue(false);
646 }
647
648 //------------------------------------------------------------------------
649         void WidgetShowNPoints::SetOutputBox()
650         {
651 //EED           renderer->GetRenderWindow()->Render();
652                 wxString strTmp;
653                 strTmp.Printf(_T("Nbr pnts: %d"), GetModelShowNPoints()->GetLstPointsSize() );
654                 txtNrPoints->SetLabel( strTmp );
655                 //--BBTK
656
657 //EED 2017-06-03
658 //              mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
659 //              mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
660 //              mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
661 //              mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
662 //              mbbShowNPoints->bbSignalOutputModification();
663         }
664
665
666 //------------------------------------------------------------------------
667         void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
668         {
669
670 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
671 #if wxMAJOR_VERSION <= 2
672                 wxFileDialog* FD = new wxFileDialog( 0,
673                                             _T("Save points .."),
674                                             _T(""),
675                                             _T(""),
676                                             _T("(*.xls)|*.xls"),
677                                             wxSAVE | wxOVERWRITE_PROMPT,
678                                             wxDefaultPosition);
679 #else
680                 wxFileDialog* FD = new wxFileDialog( 0,
681                                             _T("Save points .."),
682                                             _T(""),
683                                             _T(""),
684                                             _T("(*.xls)|*.xls"),
685                                             wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
686                                             wxDefaultPosition);
687 #endif
688
689                 int result_FD = FD->ShowModal();
690                 // This line is need it by windows //EED
691                 FD->SetReturnCode( result_FD );
692                 if (FD->GetReturnCode()==wxID_OK)
693                 {
694                         std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
695                         GetModelShowNPoints()->SavePoints( filename );
696                 }       // dialog box
697         }
698
699
700 //------------------------------------------------------------------------
701         void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
702         {
703
704 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
705 #if wxMAJOR_VERSION <= 2
706                 wxFileDialog* FD = new wxFileDialog( 0,
707                                              _T("Load points .."),
708                                              _T(""),
709                                              _T(""),
710                                              _T("(*.xls)|*.xls"),
711                                              wxOPEN | wxFILE_MUST_EXIST,
712                                              wxDefaultPosition);
713 #else
714                 wxFileDialog* FD = new wxFileDialog( 0,
715                                              _T("Load points .."),
716                                              _T(""),
717                                              _T(""),
718                                              _T("(*.xls)|*.xls"),
719                                              wxFD_OPEN | wxFD_FILE_MUST_EXIST,
720                                              wxDefaultPosition);
721 #endif
722                 int i;
723                 //EED
724                 int result_FD = FD->ShowModal();
725                 // This line is need it by windows //EED
726                 FD->SetReturnCode( result_FD );
727                 if (FD->GetReturnCode()==wxID_OK)
728                 {
729
730                         std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
731                         int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
732                         for (i=0;i<numberPointsRead;i++)
733                         {
734                 // EED 2022-05-19
735                 //AddVtkPoint();
736                 GetViewShowNPoints()->AddVtkPoint();
737                         }// for
738                         SetOutputBox();
739             // EED 2022-05-19
740                         //RefreshPoints();
741             GetViewShowNPoints()->RefreshPoints();
742                 }       // dialog box
743         }
744
745 //------------------------------------------------------------------------
746 void WidgetShowNPoints::OnSetPoint_()
747 {
748     StopAutoAddPoints();
749     StopTrackPoint();
750
751     int id=GetModelShowNPoints()->GetNearestPoint();
752     if((id==-1) && (mtype==1))
753     {
754         id=0;
755         AddPoint(0,0,0,"");
756         SetOutputBox();
757     }
758     if (id>=0)
759     {
760         GetModelShowNPoints()->SetPointId_mReferencePoint(id);
761         // EED 2022-05-19
762         //RefreshPoint(id);
763         //renderer->GetRenderWindow()->Render();
764         GetViewShowNPoints()->RefreshPoint(id);
765         GetViewShowNPoints()->Render();
766     } // if id
767     SetOutputBox();
768     UndoRedo_SaveCollection();
769 }
770
771 //------------------------------------------------------------------------
772 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
773 {
774     OnSetPoint_();
775 }
776
777 //------------------------------------------------------------------------
778 void WidgetShowNPoints::TrackingPoint( )
779 {
780     if ( cbTrackPoint->GetValue() == true )
781     {
782         int id = GetModelShowNPoints()->IdInsidePoint();
783         if (id>=0)
784         {
785             idTrack=id;
786         }
787         
788         if (idTrack>=0)
789         {
790             GetModelShowNPoints()->SetPointId_mReferencePoint(idTrack);
791             GetViewShowNPoints()->RefreshPoint(idTrack);
792             GetViewShowNPoints()->Render();
793             UndoRedo_SaveCollection();
794         } // if id
795     } // if trackPointFlag
796 }
797
798 //------------------------------------------------------------------------
799 void WidgetShowNPoints::OnTrackPoint_tool()
800 {
801     cbTrackPoint->SetValue( !cbTrackPoint->GetValue() );
802     OnTrackPoint_();
803 }
804
805 //------------------------------------------------------------------------
806 void WidgetShowNPoints::OnTrackPoint_()
807 {
808     StopAutoAddPoints();
809
810     idTrack         =   -1;
811     if ( cbTrackPoint->GetValue() == true )
812     {
813         idTrack = GetModelShowNPoints()->IdInsidePoint();
814     } // if trackPointFlag
815 }
816
817 //------------------------------------------------------------------------
818 void WidgetShowNPoints::OnTrackPoint(wxCommandEvent& event)
819 {
820     printf("WidgetShowNPoints::OnTrackPoint  \n");
821     OnTrackPoint_();
822 }
823
824 //------------------------------------------------------------------------
825 void WidgetShowNPoints::StopTrackPoint( )
826 {
827     cbTrackPoint->SetValue(false);
828     idTrack=-1;
829 }
830
831 //------------------------------------------------------------------------
832         void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
833         {
834                 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
835                 if (id>=0)
836                 {
837             // EED 2022-05-19
838                         //lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
839                         //renderer->GetRenderWindow()->Render();
840             GetViewShowNPoints()->lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
841             GetViewShowNPoints()->Render();
842             SetOutputBox();
843             UndoRedo_SaveCollection();
844                 } // if id
845         }
846
847 //------------------------------------------------------------------------
848         void WidgetShowNPoints::ErasePoint(int id)
849         {
850         // EED 2022-05-19
851                 //if (this->renderer!=NULL)
852         if (GetViewShowNPoints()->renderer!=NULL)
853                 {
854                         if (id>=0)
855                         {
856                 // EED 2022-05-19
857                                 //renderer->RemoveActor( lstActorsSphere[id] );
858                                 //renderer->RemoveActor( lstActorsText[id] );
859                                 //lstActorsSphere[id]->Delete();
860                                 //lstActorsText[id]->Delete();
861                                 //lstSourceSphere[id]->Delete();
862                                 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
863                                 //lstActorsText.erase( lstActorsText.begin()+id );
864                                 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
865                 GetViewShowNPoints()->ErasePoint(id);
866                                 GetModelShowNPoints()->ErasePoint(id);
867                         } // if id
868                 } // if renderer
869         }
870
871 //------------------------------------------------------------------------
872     void WidgetShowNPoints::OnErasePoint_()
873     {
874         StopAutoAddPoints();
875         StopTrackPoint();
876
877         ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
878         SetOutputBox();
879         // EED 2022-05-19
880         //renderer->GetRenderWindow()->Render();
881         GetViewShowNPoints()->Render();
882         StopTrackPoint();
883         UndoRedo_SaveCollection();
884     }
885
886 //------------------------------------------------------------------------
887         void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
888         {
889                 OnErasePoint_();
890         }
891
892 //------------------------------------------------------------------------
893         void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
894         {
895         // EED 2022-05-19
896         //ErasePoint( lstActorsSphere.size()-1 );
897         //renderer->GetRenderWindow()->Render();
898         StopAutoAddPoints();
899         StopTrackPoint();
900
901         int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
902         ErasePoint( id );
903         UndoRedo_SaveCollection();
904         GetViewShowNPoints()->Render();
905         SetOutputBox();
906         StopTrackPoint();
907         }
908
909 //------------------------------------------------------------------------
910 void WidgetShowNPoints::DeleteAllPoints_()
911 {
912     // EED 2022-05-19
913     //int id,size=lstActorsSphere.size();
914     int id,size=GetViewShowNPoints()->lstActorsSphere.size();
915     for (id=size-1;id>=0;id--)
916     {
917         ErasePoint(id);
918     }// for id
919 }
920
921 void WidgetShowNPoints::OnDeleteAllPoints_()
922 {
923     StopAutoAddPoints();
924     StopTrackPoint();
925
926     DeleteAllPoints_();
927     UndoRedo_SaveCollection();
928 }
929
930 //------------------------------------------------------------------------
931 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
932 {
933         OnDeleteAllPoints_();
934     SetOutputBox();
935     GetViewShowNPoints()->Render();
936 }
937
938 //NTU: Method for updating points opacity and Radio
939
940 //------------------------------------------------------------------------
941 void WidgetShowNPoints::UpdatePoints_()
942 {
943     // EED 2022-05-19
944     //this->mopacity = sdrOpacity->GetValue()/100.0;
945     //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
946     //RefreshPoints();
947
948     double opacity  = sdrOpacity->GetValue()/100.0;
949     double radio    = sdrRadio->GetValue();
950     int i,size      = lstViewShowNPoints.size();
951     for (i=0 ; i<size ; i++)
952     {
953         lstViewShowNPoints[i]->mopacity = opacity;
954         lstModelShowNPoints[i]->SetRadio( radio ) ;
955     } // for i
956 //    GetViewShowNPoints()->RefreshPoints();
957 }
958
959 //------------------------------------------------------------------------
960 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
961 {
962     RefreshColourCollection();
963 }
964
965 //------------------------------------------------------------------------
966 void  WidgetShowNPoints::SetReferencePoint(std::vector<double> point)
967 {
968         GetModelShowNPoints()->SetReferencePoint(point);
969     int i,size=lstModelShowNPoints.size();
970     for (i=0;i<size;i++)
971     {
972         lstModelShowNPoints[i]->SetReferencePoint(point);    // All collection
973     } // for i
974 }
975
976 //------------------------------------------------------------------------
977 void  WidgetShowNPoints::SetInitLstPoints( std::vector<double> initLstPointsX,  std::vector<double> initLstPointsY, std::vector<double> initLstPointsZ, std::vector<std::string> initLstLabels,   std::vector<int> initLstIndexs )
978 {
979     if (GetViewShowNPoints()->renderer==NULL)
980     {
981         return;
982     }
983     double x,y,z;
984     std::string label;
985     int i,sizeX,sizeY,sizeZ,sizeTmp,sizeLabels;
986     int ii,iIndexs,sizeIndexs;
987     
988     sizeX       = (int)initLstPointsX.size();
989     sizeY       = (int)initLstPointsY.size();
990     sizeZ       = (int)initLstPointsZ.size();
991     sizeLabels  = (int)initLstLabels.size();
992     sizeIndexs  = (int)initLstIndexs.size();
993     
994     if (sizeIndexs==0)
995     {
996         initLstIndexs.push_back(sizeX);
997         sizeIndexs  = (int)initLstIndexs.size();
998     }
999     
1000     if ( (sizeX==sizeY) && (sizeX==sizeZ) )
1001     {
1002         i=0;
1003         for (iIndexs=0;iIndexs<sizeIndexs;iIndexs++ )
1004         {
1005             if (iIndexs!=0)
1006             {
1007                 InsertCollectionAfter_();
1008             }// if last iIndexs
1009             sizeTmp = initLstIndexs[iIndexs];
1010             for (ii=0;ii<sizeTmp;ii++)
1011             {
1012                 x        = initLstPointsX[i];
1013                 y        = initLstPointsY[i];
1014                 z        = initLstPointsZ[i];
1015                 if (i<sizeLabels)
1016                 {
1017                     label    = initLstLabels[i];
1018                 } else {
1019                     label="";
1020                 }
1021                 AddPoint( x,y,z,label );
1022                 i++;
1023             } // for i
1024
1025             
1026         }// for ii
1027         //    SetOutputBox();
1028         //    renderer->GetRenderWindow()->Render();
1029     } // if size
1030
1031     
1032
1033     
1034     /*
1035     
1036     // EED 2022-05-19
1037         //if (this->renderer==NULL)
1038     if (GetViewShowNPoints()->renderer==NULL)
1039         {
1040                 return;
1041         }
1042         int i,sizeX,sizeY,sizeZ,sizeLabels;
1043         sizeX = (int)initLstPointsX.size();
1044         sizeY = (int)initLstPointsY.size();
1045         sizeZ = (int)initLstPointsZ.size();
1046         sizeLabels = (int)initLstLabels.size();
1047         double x,y,z;
1048         std::string label;
1049         if ( (sizeX==sizeY) && (sizeX==sizeZ) )
1050         {
1051                 for (i=0;i<sizeX;i++)
1052                 {
1053                         x               = initLstPointsX[i];
1054                         y               = initLstPointsY[i];
1055                         z               = initLstPointsZ[i];
1056                         if (i<sizeLabels) 
1057                         {
1058                                 label   = initLstLabels[i];
1059                         } else {
1060                                 label="";
1061                         }
1062                         AddPoint( x,y,z,label );
1063                 } // for i
1064                 //      SetOutputBox(); 
1065                 //      renderer->GetRenderWindow()->Render();
1066         } // if size
1067      
1068    */
1069 }
1070
1071 //------------------------------------------------------------------------
1072 void WidgetShowNPoints::SetType(int type)
1073 {
1074         mtype=type;
1075 }
1076
1077 //------------------------------------------------------------------------
1078 int WidgetShowNPoints::GetType()
1079 {
1080         return mtype;
1081 }
1082
1083
1084 //------------------------------------------------------------------------
1085 double WidgetShowNPoints::GetRadio()
1086 {
1087         return sdrRadio->GetValue();
1088 }
1089 //------------------------------------------------------------------------
1090 double WidgetShowNPoints::GetOpacity()
1091 {
1092         return sdrOpacity->GetValue()/100;
1093 }
1094
1095 //------------------------------------------------------------------------
1096 void WidgetShowNPoints::InsertCollection()
1097 {
1098     ModelShowNPoints*   model   = new ModelShowNPoints();
1099     ViewShowNPoints*    view    = new ViewShowNPoints( model );
1100     model->SetImage( lstModelShowNPoints[0]->GetImage() );
1101     view->mopacity = lstViewShowNPoints[0]->mopacity;
1102     view->renderer = lstViewShowNPoints[0]->renderer;
1103     lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
1104     lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
1105 }
1106
1107 //------------------------------------------------------------------------
1108 void WidgetShowNPoints::InsertCollectionBefore_()
1109 {
1110     InsertCollection();
1111     RefreshCollectionText();
1112     RefreshColourCollection();
1113     StopTrackPoint();
1114 }
1115
1116 //------------------------------------------------------------------------
1117 void WidgetShowNPoints::OnInsertCollectionBefore_()
1118 {
1119     InsertCollectionBefore_();
1120     UndoRedo_SaveCollection();
1121 }
1122
1123
1124 //------------------------------------------------------------------------
1125 void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
1126 {
1127     OnInsertCollectionBefore_();
1128 }
1129
1130
1131 //------------------------------------------------------------------------
1132 void WidgetShowNPoints::InsertCollectionAfter_()
1133 {
1134     mActualCollection++;
1135     InsertCollection();
1136     RefreshCollectionText();
1137     RefreshColourCollection();
1138     StopTrackPoint();
1139 }
1140
1141 //------------------------------------------------------------------------
1142 void WidgetShowNPoints::OnInsertCollectionAfter_()
1143 {
1144     InsertCollectionAfter_();
1145     UndoRedo_SaveCollection();
1146 }
1147
1148 //------------------------------------------------------------------------
1149 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
1150 {
1151     OnInsertCollectionAfter_();
1152 }
1153
1154 //------------------------------------------------------------------------
1155 void WidgetShowNPoints::DeleteCollection_()
1156 {
1157     if ( lstModelShowNPoints.size()>1 )
1158     {
1159         DeleteAllPoints_();  // Actual Collection
1160         lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
1161         lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
1162         if ( mActualCollection>=lstModelShowNPoints.size() )
1163         {
1164             mActualCollection--;
1165         } // if
1166     } else {
1167         DeleteAllPoints_();  // Actual Collection
1168     } // if
1169 }
1170
1171 //------------------------------------------------------------------------
1172 void WidgetShowNPoints::OnDeleteCollection_()
1173 {
1174     DeleteCollection_();
1175     SetOutputBox();
1176     GetViewShowNPoints()->Render();
1177     RefreshCollectionText();
1178     RefreshColourCollection();
1179     StopTrackPoint();
1180     UndoRedo_SaveCollection();
1181 }
1182
1183 //------------------------------------------------------------------------
1184 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
1185 {
1186     OnDeleteCollection_();
1187 }
1188
1189 //------------------------------------------------------------------------
1190 void WidgetShowNPoints::ResetCollections_()
1191 {
1192     int i,size=lstModelShowNPoints.size();
1193     for (i=0;i<size;i++)
1194     {
1195         DeleteCollection_();
1196     }
1197     GetViewShowNPoints()->Render();
1198     RefreshCollectionText();
1199     RefreshColourCollection();
1200     StopTrackPoint();
1201 }
1202
1203
1204 //------------------------------------------------------------------------
1205 void WidgetShowNPoints::OnResetCollections_()
1206 {
1207     ResetCollections_();
1208     UndoRedo_SaveCollection();
1209 }
1210
1211
1212 //------------------------------------------------------------------------
1213 void WidgetShowNPoints::OnResetCollections(wxCommandEvent &event)
1214 {
1215     OnResetCollections_();
1216 }
1217
1218 //------------------------------------------------------------------------
1219 void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
1220 {
1221     mActualCollection--;
1222     if ( mActualCollection <0  )
1223     {
1224         mActualCollection=0;
1225     } //if <=0
1226     RefreshCollectionText();
1227     RefreshColourCollection();
1228     StopTrackPoint();
1229     UndoRedo_SaveCollection();
1230 }
1231
1232 //------------------------------------------------------------------------
1233 void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
1234 {
1235     mActualCollection++;
1236     if ( mActualCollection >=lstModelShowNPoints.size() )
1237     {
1238         mActualCollection = lstModelShowNPoints.size()-1;
1239     } //if <=0
1240     RefreshCollectionText();
1241     RefreshColourCollection();
1242     StopTrackPoint();
1243     UndoRedo_SaveCollection();
1244 }
1245
1246 //------------------------------------------------------------------------
1247 void WidgetShowNPoints::DetectCollectionActive()
1248 {
1249     int id;
1250     int i,size=lstModelShowNPoints.size();
1251     for (i=0;i<size;i++)
1252     {
1253         id = lstModelShowNPoints[i]->IdInsidePoint();
1254         if (id>=0)
1255         {
1256             mActualCollection=i;
1257         } // if id>=0
1258     } // for i
1259     RefreshCollectionText();
1260     RefreshColourCollection();
1261 }
1262
1263 //------------------------------------------------------------------------
1264 void WidgetShowNPoints::RefreshColourCollection()
1265 {
1266     UpdatePoints_();
1267     std::vector<double> colourAll;
1268     colourAll.push_back(1);
1269     colourAll.push_back(0);
1270     colourAll.push_back(0);
1271     std::vector<double> colourActual;
1272     colourActual.push_back(1);
1273     colourActual.push_back(1);
1274     colourActual.push_back(0);
1275     SetColour( colourAll );                                             // For all collections
1276     int i,size=lstViewShowNPoints.size();
1277     for (i=0;i<size;i++)
1278     {
1279         lstViewShowNPoints[i] -> mcolour = colourAll;    // All collection
1280         lstViewShowNPoints[i]->RefreshEachPoint();
1281     } // for i
1282     lstViewShowNPoints[mActualCollection] -> mcolour = colourActual;    // Actual collection
1283     lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
1284     lstViewShowNPoints[mActualCollection] -> renderer->GetRenderWindow()->Render();
1285 }
1286
1287 //------------------------------------------------------------------------
1288 void WidgetShowNPoints::RefreshCollectionText()
1289 {
1290     if ((mtype==4) && (txtNrCollections!=NULL))  // Just for Collection interface
1291     {
1292         wxString strTmp;
1293         strTmp.Printf(_T("%d   /  %d "),  (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
1294         txtNrCollections->SetLabel( strTmp );
1295     } // if mtype 4
1296     SetOutputBox();
1297 }
1298
1299
1300 //------------------------------------------------------------------------
1301 void WidgetShowNPoints::OnSaveCollections_( std::string filename )
1302 {
1303     FILE *ff;
1304     ff = fopen( filename.c_str() , "w+" );
1305     if (ff!=NULL)
1306     {
1307         int i,size = lstModelShowNPoints.size();
1308         fprintf(ff,"NumberOfGroups %d \n",size);
1309         for (i=0 ; i<size ; i++)
1310         {
1311             lstModelShowNPoints[i]->SavePoints_(ff);
1312         } // for i
1313         fclose(ff);
1314     } else {   // else ff
1315         printf("WidgetShowNPoints::Save Groups Points  ...Error... creating file \n");
1316     } //ff
1317
1318 }
1319
1320
1321 //------------------------------------------------------------------------
1322 void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event)
1323 {
1324     //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1325     #if wxMAJOR_VERSION <= 2
1326             wxFileDialog* FD = new wxFileDialog( 0,
1327                                                 _T("Save groups of points .."),
1328                                                 _T(""),
1329                                                 _T(""),
1330                                                 _T("(*.xls)|*.xls"),
1331                                                 wxSAVE | wxOVERWRITE_PROMPT,
1332                                                 wxDefaultPosition);
1333     #else
1334             wxFileDialog* FD = new wxFileDialog( 0,
1335                                                 _T("Save groups of points .."),
1336                                                 _T(""),
1337                                                 _T(""),
1338                                                 _T("(*.xls)|*.xls"),
1339                                                 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
1340                                                 wxDefaultPosition);
1341     #endif
1342
1343             int result_FD = FD->ShowModal();
1344             // This line is need it by windows //EED
1345             FD->SetReturnCode( result_FD );
1346             if (FD->GetReturnCode()==wxID_OK)
1347             {
1348                 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1349                 OnSaveCollections_( filename );
1350             }     // dialog box
1351     StopTrackPoint();
1352 }
1353
1354 //------------------------------------------------------------------------
1355 void WidgetShowNPoints::OnLoadCollections_( std::string filename )
1356 {
1357     bool okEraseFirstGroup=false;
1358     if (lstModelShowNPoints.size()==1)
1359     {
1360         if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGroup=true; }
1361     }
1362     FILE *ff = fopen( filename.c_str() , "r+" );
1363     if (ff!=NULL)
1364     {
1365         int i;
1366         int iGroup,sizeGroups;
1367         int iPoint,numberPointsRead;
1368         char chartmp[256];
1369         fscanf(ff," %s %d",chartmp,&sizeGroups);
1370         for (iGroup=0;iGroup<sizeGroups;iGroup++)
1371         {
1372             mActualCollection = lstModelShowNPoints.size();
1373             InsertCollection();
1374             int numberPointsRead= lstModelShowNPoints[mActualCollection]->ReadPoints_(ff);
1375             for (i=0;i<numberPointsRead;i++)
1376             {
1377                 // EED 2022-05-19
1378                 //AddVtkPoint();
1379                 GetViewShowNPoints()->AddVtkPoint();
1380             }// for
1381         } // for i
1382
1383         fclose(ff);
1384     } else {   // else ff
1385         printf("WidgetShowNPoints::Load Group of Points  ...Error... reading file");
1386     } //ff
1387     if (okEraseFirstGroup==true)
1388     {
1389         mActualCollection=0;
1390         DeleteCollection_();
1391         mActualCollection = lstModelShowNPoints.size()-1;
1392     }
1393     GetViewShowNPoints()->Render();
1394     RefreshCollectionText();
1395     RefreshColourCollection();
1396     StopTrackPoint();
1397 }
1398
1399 //------------------------------------------------------------------------
1400 void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
1401 {
1402     //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1403     #if wxMAJOR_VERSION <= 2
1404             wxFileDialog* FD = new wxFileDialog( 0,
1405                                                  _T("Load groups of points .."),
1406                                                  _T(""),
1407                                                  _T(""),
1408                                                  _T("(*.xls)|*.xls"),
1409                                                  wxOPEN | wxFILE_MUST_EXIST,
1410                                                  wxDefaultPosition);
1411     #else
1412             wxFileDialog* FD = new wxFileDialog( 0,
1413                                                  _T("Load groups of points .."),
1414                                                  _T(""),
1415                                                  _T(""),
1416                                                  _T("(*.xls)|*.xls"),
1417                                                  wxFD_OPEN | wxFD_FILE_MUST_EXIST,
1418                                                  wxDefaultPosition);
1419     #endif
1420             int result_FD = FD->ShowModal();
1421             // This line is need it by windows //EED
1422             FD->SetReturnCode( result_FD );
1423             if (FD->GetReturnCode()==wxID_OK)
1424             {
1425                 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1426                 OnLoadCollections_( filename );
1427                 UndoRedo_SaveCollection();
1428             }     // dialog box
1429 }
1430
1431 //------------------------------------------------------------------------
1432 void WidgetShowNPoints::GetCollectionPoint(int idCol,int idPoint, double *pPoint)
1433 {
1434     double x,y,z;
1435     lstModelShowNPoints[idCol]->GetIdPoint(idPoint,&x,&y,&z);
1436     pPoint[0] = x;
1437     pPoint[1] = y;
1438     pPoint[2] = z;
1439 }
1440 //------------------------------------------------------------------------
1441 void WidgetShowNPoints::SetCollectionPoint(int idCol, int idPoint, std::vector<double> modPoint)
1442 {
1443         if(idCol >= 0 && idCol < lstModelShowNPoints.size())
1444         {
1445                 lstModelShowNPoints[idCol]->SetPointById(idPoint, modPoint);
1446                 lstViewShowNPoints[idCol]->RefreshPoint(idPoint);
1447         }
1448         else{
1449                 printf("WidgetShowNPoints::SetCollectionPoint  ...Error... Invalid collection, out of range");
1450         }
1451 }
1452 //------------------------------------------------------------------------
1453 std::vector<double> WidgetShowNPoints::GetLstPointsX()
1454 {
1455     if (mtype!=4)
1456     {
1457         return GetModelShowNPoints()->GetLstPointsX();
1458     } else {
1459         std::vector<double> lst;
1460         int iP,s;
1461         int iG,sG=lstModelShowNPoints.size();
1462         for (iG=0 ; iG<sG ; iG++)
1463         {
1464             std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsX();
1465             s = lstTmp.size();
1466             for (iP=0 ; iP<s ; iP++)
1467             {
1468                 lst.push_back( lstTmp[iP] );
1469             } // for iP
1470         } // for iG
1471         return lst;
1472     } // if 4
1473 }
1474
1475 //------------------------------------------------------------------------
1476 std::vector<double> WidgetShowNPoints::GetLstPointsY()
1477 {
1478     if (mtype!=4)
1479     {
1480         return GetModelShowNPoints()->GetLstPointsY();
1481     } else {
1482         std::vector<double> lst;
1483         int iP,s;
1484         int iG,sG=lstModelShowNPoints.size();
1485         for (iG=0 ; iG<sG ; iG++)
1486         {
1487             std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsY();
1488             s = lstTmp.size();
1489             for (iP=0 ; iP<s ; iP++)
1490             {
1491                 lst.push_back( lstTmp[iP] );
1492             } // for iP
1493         } // for iG
1494         return lst;
1495     }
1496 }
1497
1498 //------------------------------------------------------------------------
1499 std::vector<double> WidgetShowNPoints::GetLstPointsZ()
1500 {
1501     if (mtype!=4)
1502     {
1503         return GetModelShowNPoints()->GetLstPointsZ();
1504     } else {
1505         std::vector<double> lst;
1506         int iP,s;
1507         int iG,sG=lstModelShowNPoints.size();
1508         for (iG=0 ; iG<sG ; iG++)
1509         {
1510             std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsZ();
1511             s = lstTmp.size();
1512             for (iP=0 ; iP<s ; iP++)
1513             {
1514                 lst.push_back( lstTmp[iP] );
1515             } // for iP
1516         } // for iG
1517         return lst;
1518
1519     }
1520 }
1521
1522 //------------------------------------------------------------------------
1523 std::vector<std::string> WidgetShowNPoints::GetLstLabels()
1524 {
1525     if (mtype!=4)
1526     {
1527         return GetModelShowNPoints()->GetLstLabels();
1528     } else {
1529         std::vector< std::string > lst;
1530         int iP,s;
1531         int iG,sG=lstModelShowNPoints.size();
1532         for (iG=0 ; iG<sG ; iG++)
1533         {
1534             std::vector< std::string > lstTmp = lstModelShowNPoints[iG]->GetLstLabels();
1535             s = lstTmp.size();
1536             for (iP=0 ; iP<s ; iP++)
1537             {
1538                 lst.push_back( lstTmp[iP] );
1539             } // for iP
1540         } // for iG
1541         return lst;
1542     }
1543 }
1544
1545 //------------------------------------------------------------------------
1546 std::vector<int> WidgetShowNPoints::GetLstIndexs()
1547 {
1548     std::vector<int> lstIndexs;
1549     if (mtype!=4)
1550     {
1551         lstIndexs.push_back( GetModelShowNPoints()->GetLstPointsSize() );
1552     } else {
1553         int iG,sG=lstModelShowNPoints.size();
1554         for (iG=0 ; iG<sG ; iG++)
1555         {
1556             lstIndexs.push_back( lstModelShowNPoints[iG]->GetLstPointsSize() );
1557         } // for iG
1558     }
1559     return lstIndexs;
1560 }
1561 //------------------------------------------------------------------------
1562 int WidgetShowNPoints::GetLstModelShowNPointsSize()
1563 {
1564     return lstModelShowNPoints.size();
1565 }
1566
1567 //------------------------------------------------------------------------
1568 void WidgetShowNPoints::InvertLstPoints_()
1569 {
1570     int i,size=lstModelShowNPoints.size();
1571     
1572     for (i=0 ;  i < size ; i++)
1573     {
1574         lstModelShowNPoints[i]->InversLstPoints();
1575     } // for iM
1576      
1577     /*
1578     ModelShowNPoints* tmpModel;
1579     int size2=size/2;
1580     for (i=0 ;  i < size2 ; i++)
1581     {
1582         tmpModel                        = lstModelShowNPoints[i];
1583         lstModelShowNPoints[i]          = lstModelShowNPoints[size-1-i];
1584         lstModelShowNPoints[size-1-i]   = tmpModel;
1585     } // for iM
1586      */
1587 }
1588
1589 //------------------------------------------------------------------------
1590 void WidgetShowNPoints::OnInvertLstPoints_()
1591 {
1592     StopAutoAddPoints();
1593     StopTrackPoint();
1594
1595     InvertLstPoints_();
1596     SetOutputBox();
1597     UndoRedo_SaveCollection();
1598 }
1599
1600
1601 //------------------------------------------------------------------------
1602 std::string WidgetShowNPoints::GetUndoRedoFileName()
1603 {
1604     char buff[20];
1605     sprintf(buff,"%p_%d",this, idUndoRedo);
1606     return  UndoRedoDir+"/"+"UndoRedo_collection_" + std::string(buff) + ".undoredo";
1607 }
1608
1609
1610 //------------------------------------------------------------------------
1611 void WidgetShowNPoints::OnUndo(wxCommandEvent &event)
1612 {
1613     ResetCollections_();
1614 //    if (idUndoRedo==maxUndoRedo+1)
1615 //    {
1616 //       idUndoRedo--;
1617 //    } // if idUndoRedo+1
1618     idUndoRedo--;
1619     idUndoRedo--;
1620     if (idUndoRedo<0)
1621     {
1622         idUndoRedo=-1;
1623     } else {
1624         OnLoadCollections_( GetUndoRedoFileName() );
1625     }// if idUndoRedo
1626     idUndoRedo++;
1627
1628 }
1629
1630 //------------------------------------------------------------------------
1631 void WidgetShowNPoints::OnRedo(wxCommandEvent &event)
1632 {
1633     if (idUndoRedo>maxUndoRedo)
1634     {
1635         idUndoRedo=maxUndoRedo+1;
1636     } else {
1637         ResetCollections_();
1638         OnLoadCollections_( GetUndoRedoFileName() );
1639         idUndoRedo++;
1640     }// if idUndoRedo
1641 }
1642
1643 //------------------------------------------------------------------------
1644 void WidgetShowNPoints::UndoRedo_SaveCollection()
1645 {
1646     OnSaveCollections_( GetUndoRedoFileName() );
1647     maxUndoRedo = idUndoRedo;
1648     idUndoRedo++;
1649 }
1650
1651