]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
c5b080843b2745bd1237be6e83fefa5a3bcd0b05
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / WidgetShowNPoints.cxx
1
2 #include <wx/button.h>
3 #include <wx/sizer.h>
4 #include <wx/filedlg.h>
5 #include <wx/msgdlg.h>
6 #include <wx/notebook.h>
7
8
9 #include <vtkStaticPointLocator.h>
10 #include <vtkPointData.h>
11 #include <vtkDataArray.h>
12 #include <vtkMath.h>
13 #include <vtkStaticPointLocator.h>
14 #include <vtkPoints.h>
15
16 #include "vtkSphereSource.h"
17 #include "vtkRenderer.h"
18 #include "vtkTextActor3D.h"
19
20 #include "WidgetShowNPoints.h"
21 #include <creaContoursFactory.h>
22
23
24 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 //----------------------------------------------------------------------
29   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
30     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
31   {
32       aux_mesh      =   NULL;
33       aux_mesh_spc.push_back(1);
34       aux_mesh_spc.push_back(1);
35       aux_mesh_spc.push_back(1);
36       aux_mesh_type = 0;   // 0:Patch  1:CloseSpline1  2:CloseSpline2
37       
38         // EED 2022-05-19
39     //  mmodelShowNPoints                                   = new ModelShowNPoints();
40                         idUndoRedo          = 0;
41                         maxUndoRedo         = 0;        
42 #if defined(_WIN32)
43                                                 char * val = getenv( "TEMP" );
44                                                 if (val == NULL) 
45                                                 { 
46                                                         UndoRedoDir = std::string("");  
47                                                 } else { 
48                                                         UndoRedoDir = std::string(val)+"\\creatools"; 
49                                                         std::string cmd1 = "mkdir "+ UndoRedoDir;
50                                                         system( cmd1.c_str() );
51                                                         // Erasing files of more than 1 day old  ( -1 )
52                                                         std::string cmd2 = "ForFiles /p \"" + UndoRedoDir + "\" /s /d -1 /c \"cmd /c del @file \"";
53                                                         system( cmd2.c_str() );
54                                                 }
55 #elif defined(__GNUC__)
56
57
58     #if defined(MACOSX)
59                                                 UndoRedoDir         = "/tmp/creatools";
60     #else  // Linux
61                                                 UndoRedoDir         = "/tmp/creatools";
62     #endif
63         
64     std::string cmd1 = "mkdir "+ UndoRedoDir;
65     system( cmd1.c_str() );
66         // Erasing files of more than 1 day old  ( +1 )
67         std::string cmd= "find "+UndoRedoDir+" -name \"UndoRedo_collection_*.undoredo\" -type f -mtime +1 -delete";
68         system( cmd.c_str() );
69
70 #else
71                                                 UndoRedoDir         = "./";
72 #endif
73    
74    
75                         mActualCollection   = 0;
76     ModelShowNPoints*   modelShowNPoints    = new ModelShowNPoints();
77     lstModelShowNPoints.push_back( modelShowNPoints );
78     lstViewShowNPoints.push_back( new  ViewShowNPoints( modelShowNPoints ) );
79       
80     mtype                                                       = type;
81     SetType(mtype);
82     wxPanel*        panelParent         = this;
83     wxSizer*        sizer                               = NULL;
84     wxSizer*        MNPsizer            = NULL;
85     wxNotebook*     bookSetPoints       = NULL;
86     wxNotebook*     bookGroupManager    = NULL;
87     wxPanel*        panel               = NULL;
88     wxPanel*        panel2              = NULL;
89                     txtNrCollections    = NULL;
90                     txtNrPoints         = NULL;
91                 cbVisuActualCollection  = NULL;
92                     bookSetPoints       = new wxNotebook(panelParent, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP );
93                     panel               = new wxPanel(bookSetPoints);
94
95       wxSize sizeButton( 50  ,  -1 );
96       wxSize sizeSlider( 90  ,  -1 );
97
98     // Group Manager
99     if (mtype==4)
100     {
101           bookGroupManager   = new wxNotebook(panelParent, //bbGetWxParent(),
102                               -1,
103                               wxDefaultPosition,
104                               wxDefaultSize,
105                               wxNB_TOP );
106           panel2  = new wxPanel(bookGroupManager);
107           cbVisuActualCollection                = new wxCheckBox    ( panel2,-1, _T("A.V.")   ,   wxDefaultPosition, sizeButton );
108           txtNrCollections                      = new wxStaticText  ( panel2,-1, _T("    1/1    "));
109           wxButton *btnBackCollection           = new wxButton      ( panel2, -1, _T("<")     ,   wxDefaultPosition, sizeButton );
110           wxButton *btnNextCollection           = new wxButton      ( panel2, -1, _T(">")     ,   wxDefaultPosition, sizeButton );
111           wxButton *btnInsertCollectionBefore   = new wxButton      ( panel2, -1, _T("+<")    ,   wxDefaultPosition, sizeButton );
112           wxButton *btnInsertCollectionAfter    = new wxButton      ( panel2, -1, _T("+>")    ,   wxDefaultPosition, sizeButton );
113           wxButton *btnDeleteCollection         = new wxButton      ( panel2, -1, _T("-")     ,   wxDefaultPosition, sizeButton );
114           wxButton *btnResetCollection          = new wxButton      ( panel2, -1, _T("--")    ,   wxDefaultPosition, sizeButton );
115           wxButton *btnSaveCollection           = new wxButton      ( panel2, -1, _T("Save")  ,   wxDefaultPosition, sizeButton );
116           wxButton *btnLoadCollection           = new wxButton      ( panel2, -1, _T("Load")  ,   wxDefaultPosition, sizeButton );
117           wxButton *btnUndo                     = new wxButton      ( panel2, -1, _T("Undo")  ,   wxDefaultPosition, sizeButton );
118           wxButton *btnRedo                     = new wxButton      ( panel2, -1, _T("Redo")  ,   wxDefaultPosition, sizeButton );
119
120          sCtrlRadio = new wxSpinCtrl( panel2, -1  , wxEmptyString, wxDefaultPosition, sizeButton );
121          sCtrlRadio->SetRange(1,10);
122          sCtrlRadio->SetValue( 2 );
123          sCtrlOpacity= new wxSpinCtrl( panel2, -1  , wxEmptyString, wxDefaultPosition, sizeButton );
124          sCtrlOpacity->SetRange(0,10);
125          sCtrlOpacity->SetValue( 10 );
126         
127           wxFlexGridSizer *sizer1               = new wxFlexGridSizer(1);
128           wxFlexGridSizer *sizer2               = new wxFlexGridSizer(2);
129           wxFlexGridSizer *sizer3               = new wxFlexGridSizer(3);
130           wxFlexGridSizer *sizer4               = new wxFlexGridSizer(3);
131           wxFlexGridSizer *sizer5               = new wxFlexGridSizer(2);
132           wxFlexGridSizer *sizer5a              = new wxFlexGridSizer(2);
133           wxFlexGridSizer *sizer6               = new wxFlexGridSizer(2);
134           wxFlexGridSizer *sizer7               = new wxFlexGridSizer(2);
135           wxFlexGridSizer *sizer8               = new wxFlexGridSizer(2);
136         
137           cbVisuActualCollection      -> SetToolTip( _T("Visu actual collection") );
138           btnInsertCollectionBefore   -> SetToolTip( _T("+  Add group before") );
139           btnInsertCollectionAfter    -> SetToolTip( _T("+>  Add group after") );
140           btnDeleteCollection         -> SetToolTip( _T("-  Erase group") );
141           btnResetCollection          -> SetToolTip( _T("-- Reset : Erase all groups") );
142           sCtrlRadio                  -> SetToolTip( _T("Radio")   );
143           sCtrlOpacity                -> SetToolTip( _T("Opacity") );
144
145 //          sdrOpacity                            = new wxSlider(panel2, -1, 0, 0, 100, wxDefaultPosition, sizeSlider, wxSL_LABELS);
146 //          sdrRadio                              = new wxSlider(panel2, -1, 0, 1, 50, wxDefaultPosition, sizeSlider, wxSL_LABELS);
147 //          sdrRadio                    -> SetToolTip( _T("Radio")   );
148 //          sdrOpacity                  -> SetToolTip( _T("Opacity") );
149         
150           Connect(cbVisuActualCollection->GetId()   , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnVisuActualCollection     );
151           Connect(btnBackCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) & WidgetShowNPoints::OnBackCollection           );
152           Connect(btnNextCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) & WidgetShowNPoints::OnNextCollection           );
153           Connect(btnInsertCollectionBefore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionBefore   );
154           Connect(btnInsertCollectionAfter->GetId() , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionAfter    );
155           Connect(btnDeleteCollection->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteCollection         );
156         
157 //        Connect(sdrOpacity->GetId()               , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) & WidgetShowNPoints::UpdatePoints               );
158 //        Connect(sdrRadio->GetId()                 , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) & WidgetShowNPoints::UpdatePoints               );
159           Connect( sCtrlRadio->GetId()              ,wxEVT_COMMAND_SPINCTRL_UPDATED ,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &WidgetShowNPoints::UpdatePoints);
160           Connect( sCtrlOpacity->GetId()            ,wxEVT_COMMAND_SPINCTRL_UPDATED ,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &WidgetShowNPoints::UpdatePoints);
161         
162           Connect(btnSaveCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) & WidgetShowNPoints::OnSaveCollections          );
163           Connect(btnLoadCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) & WidgetShowNPoints::OnLoadCollections          );
164           Connect(btnResetCollection->GetId()       , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) & WidgetShowNPoints::OnResetCollections         );
165           Connect(btnUndo->GetId()                  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnUndo                      );
166           Connect(btnRedo->GetId()                  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRedo                      );
167
168           sizer2->Add( btnBackCollection );
169           sizer2->Add( btnNextCollection );
170           sizer3->Add( btnInsertCollectionBefore );
171           sizer3->Add( btnInsertCollectionAfter );
172           sizer4->Add( btnLoadCollection );
173           sizer4->Add( btnSaveCollection );
174 //          sizer5->Add( txRadio ,wxGROW );
175 //          sizer5->Add( sdrRadio ,wxGROW );
176 //          sizer5->Add( txOpacity ,wxGROW );
177 //          sizer5->Add( sdrOpacity ,wxGROW );
178         
179           sizer5->Add( sCtrlRadio );
180           sizer5->Add( sCtrlOpacity );
181
182           sizer6->Add( btnDeleteCollection );
183           sizer6->Add( btnResetCollection );
184         
185          sizer7->Add( cbVisuActualCollection );
186          sizer7->Add( txtNrCollections );
187
188          sizer8->Add( btnUndo        );
189          sizer8->Add( btnRedo        );
190
191           sizer1->Add( sizer7 );
192           sizer1->Add( sizer2 );
193           sizer1->Add( sizer3 );
194           sizer1->Add( sizer6 );
195           sizer1->Add( sizer4 );
196           sizer1->Add( sizer5 );
197           sizer1->Add( sizer8 );
198
199 //          sizer1->Add( sizer5 ,wxGROW );
200
201           MNPsizer                        = sizer1;
202           panel2->SetSizer( MNPsizer );
203           panel2->SetAutoLayout(true);
204           panel2->Layout();
205           bookGroupManager->AddPage(panel2 , _T("Groups") );
206     } // if mtype 4
207
208         if ( (mtype==0) || (mtype==3) || (mtype==4) )
209         {
210                 // Widget interface
211 //              askPointLabel                                       = new wxStaticText(panel, -1, _T("Label:")); // JPR
212                 textCtrl                                                    = new wxTextCtrl(panel, -1, wxEmptyString   ,   wxDefaultPosition, sizeButton);
213                 wxButton    *btnBackPoint                   = new wxButton( panel, -1, _T("<")          ,   wxDefaultPosition, sizeButton );
214                 wxButton    *btnNextPoint                   = new wxButton( panel, -1, _T(">")          ,   wxDefaultPosition, sizeButton );
215         wxButton    *btnAddPoint            = new wxButton( panel, -1, _T("+")          ,   wxDefaultPosition, sizeButton );
216         wxButton    *btnInsertPoint         = new wxButton( panel, -1, _T("(+)")        ,   wxDefaultPosition, sizeButton );
217                     cbAutoAddPoints         = new wxCheckBox(panel,-1, _T("Auto")       ,   wxDefaultPosition, sizeButton );
218         wxButton    *btnMovePointUp         = new wxButton( panel, -1, _T("<-")         ,   wxDefaultPosition, sizeButton );
219         wxButton    *btnMovePointDown       = new wxButton( panel, -1, _T("->")         ,   wxDefaultPosition, sizeButton );
220         wxButton    *btnSetPositionPoint    = new wxButton( panel, -1, _T("Set")        ,   wxDefaultPosition, sizeButton );
221                      cbTrackPoint           = new wxCheckBox(panel,-1, _T("Tra.")       ,   wxDefaultPosition, sizeButton );
222         wxButton    *btnRenamePoint                 = new wxButton( panel, -1, _T("Ren.")       ,   wxDefaultPosition, sizeButton );
223         wxButton    *btnErasePoint          = new wxButton( panel, -1, _T("-")          ,   wxDefaultPosition, sizeButton );
224 //              wxButton    *btnEraseLastPoint      = new wxButton( panel, -1, _T("- lst")      ,   wxDefaultPosition, sizeButton );
225                 wxButton    *btnDeleteAllPoints     = new wxButton( panel, -1, _T("--")         ,   wxDefaultPosition, sizeButton );
226         wxButton    *btnUndo                = NULL;
227         wxButton    *btnRedo                = NULL;
228                 wxButton    *btnSavePoints                  = NULL;
229                 wxButton    *btnLoadPoints                  = NULL;
230         btnBackPoint        -> SetToolTip( _T("Select befor point")                         );
231         btnNextPoint        -> SetToolTip( _T("Select next point")                          );
232         cbAutoAddPoints     -> SetToolTip( _T("Auto Add point")                             );
233         btnAddPoint         -> SetToolTip( _T("+  Add point")                               );
234         btnInsertPoint      -> SetToolTip( _T("(+)  Insert point")                          );
235         btnMovePointUp      -> SetToolTip( _T("Move point Up in the normal direction")      );
236         btnMovePointDown    -> SetToolTip( _T("Move point Down in the normal direction")    );
237         btnRenamePoint      -> SetToolTip( _T("Rename label for each point")                );
238         textCtrl            -> SetToolTip( _T("Point label")                                );
239         btnErasePoint       -> SetToolTip( _T("-  Erase point")                             );
240 //        btnEraseLastPoint   -> SetToolTip( _T("- lst  Erase last point")                  );
241         btnDeleteAllPoints  -> SetToolTip( _T("-- Erase all points")                        );
242                 if ( mtype==0 )
243                 {
244             btnUndo             = new wxButton( panel, -1, _T("Undo")       ,   wxDefaultPosition, sizeButton   );
245             btnRedo             = new wxButton( panel, -1, _T("Redo")       ,   wxDefaultPosition, sizeButton   );
246                         btnSavePoints           = new wxButton( panel, -1, _T("Save")       ,   wxDefaultPosition, sizeButton   );
247                         btnLoadPoints       = new wxButton( panel, -1, _T("Load")       ,   wxDefaultPosition, sizeButton   );
248             Connect(btnSavePoints->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints    );
249             Connect(btnLoadPoints->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints    );
250             Connect(btnUndo->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnUndo          );
251             Connect(btnRedo->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRedo          );
252                 } // if mtype
253                 txtNrPoints                                             = new wxStaticText(panel,-1, _T("   -/-"));
254         wxStaticText* txOpacity;
255         wxStaticText* txRadio;
256         if ( (mtype==0) || (mtype==3) )
257         {
258             //NTU: Sliders for opacity and radio change
259 //            txOpacity         = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
260 //            sdrOpacity        = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
261 //            txRadio           = new wxStaticText(panel, -1, wxString(_T("  Points Radius  ")));
262 //            sdrRadio          = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
263 //            //NTU: Slider events
264 //            Connect(sdrOpacity->GetId()          , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
265 //            Connect(sdrRadio->GetId()            , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
266             
267             sCtrlRadio = new wxSpinCtrl( panel, -1  , wxEmptyString, wxDefaultPosition, sizeButton );
268             sCtrlRadio->SetRange(1,10);
269             sCtrlRadio->SetValue( 2 );
270             sCtrlOpacity= new wxSpinCtrl( panel, -1  , wxEmptyString, wxDefaultPosition, sizeButton );
271             sCtrlOpacity->SetRange(0,10);
272             sCtrlOpacity->SetValue( 10 );
273             Connect( sCtrlRadio->GetId()              ,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &WidgetShowNPoints::UpdatePoints);
274             Connect( sCtrlOpacity->GetId()            ,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &WidgetShowNPoints::UpdatePoints);
275
276             
277         } // if mtype 0 3
278         Connect(cbAutoAddPoints->GetId()    , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WidgetShowNPoints::OnAutoAddPoints       );
279         Connect(btnBackPoint->GetId()       , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnBackPoint           );
280         Connect(btnNextPoint->GetId()       , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnNextPoint           );
281                 Connect(btnAddPoint->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint            );
282                 Connect(btnInsertPoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint         );
283         Connect(btnMovePointUp->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnMovePointUp         );
284         Connect(btnMovePointDown->GetId()   , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnMovePointDown       );
285                 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint            );
286                 Connect(btnRenamePoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint         );
287 //              Connect(btnEraseLastPoint->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint      );
288                 Connect(btnErasePoint->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint          );
289                 Connect(btnDeleteAllPoints->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints     );
290         Connect(cbTrackPoint->GetId()       , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WidgetShowNPoints::OnTrackPoint          );
291         wxFlexGridSizer *sizer0 = new wxFlexGridSizer(1);
292         wxFlexGridSizer *sizer1 = new wxFlexGridSizer(2);
293         wxFlexGridSizer *sizer2 = new wxFlexGridSizer(3);
294         wxFlexGridSizer *sizer3 = new wxFlexGridSizer(2);
295         wxFlexGridSizer *sizer4 = new wxFlexGridSizer(3);
296 //        wxFlexGridSizer *sizer5 = new wxFlexGridSizer(2);
297         wxFlexGridSizer *sizer6 = new wxFlexGridSizer(2);
298         wxFlexGridSizer *sizer7 = new wxFlexGridSizer(2);
299         wxFlexGridSizer *sizer8 = new wxFlexGridSizer(2);
300         sizer1->Add( textCtrl               );
301         sizer1->Add( btnRenamePoint         );
302         sizer2->Add( btnAddPoint            );
303         sizer2->Add( btnInsertPoint         );
304 //        sizer2->Add( cbAutoAddPoints      );
305         sizer3->Add( btnSetPositionPoint    );
306         sizer3->Add( cbTrackPoint           );
307         sizer4->Add( btnErasePoint          );
308 //        sizer4->Add( btnEraseLastPoint    );
309         sizer4->Add( btnDeleteAllPoints     );
310 //        sizer5->Add( btnUndo                );
311 //        sizer5->Add( btnRedo                );
312         sizer6->Add( btnBackPoint           );
313         sizer6->Add( btnNextPoint           );
314         sizer7->Add( btnMovePointUp         );
315         sizer7->Add( btnMovePointDown       );
316         sizer8->Add( cbAutoAddPoints        );
317         sizer8->Add( txtNrPoints            );
318         //              sizer0->Add(askPointLabel); // JPR
319         sizer0->Add(sizer8);
320         sizer0->Add(sizer6);
321         sizer0->Add(sizer2);
322         sizer0->Add(sizer7);
323                 sizer0->Add(sizer3);
324         sizer0->Add(sizer4);
325         sizer0->Add(sizer1);
326   //      sizer0->Add(sizer5);
327         if ( (mtype==0) || (mtype==3) )
328         {
329             wxFlexGridSizer *sizer5 = new wxFlexGridSizer(2);
330 //            sizer5->Add(txRadio);
331 //            sizer5->Add(sdrRadio,1,wxGROW );
332 //            sizer5->Add(txOpacity);
333 //            sizer5->Add(sdrOpacity,1,wxGROW );
334             sizer5->Add( sCtrlRadio      );
335             sizer5->Add( sCtrlOpacity    );
336             sizer0->Add(sizer5);
337         }  // if mtype 0 3
338         if ( mtype==0 )
339                 {
340             wxFlexGridSizer *sizer5 = new wxFlexGridSizer(2);
341             wxFlexGridSizer *sizer6 = new wxFlexGridSizer(2);
342                         sizer6->Add( btnSavePoints  );
343                         sizer6->Add( btnLoadPoints  );
344             sizer5->Add( btnUndo        );
345             sizer5->Add( btnRedo        );
346             sizer0->Add( sizer6         );
347             sizer0->Add( sizer5         );
348                 } // if mtype 0
349                 sizer = sizer0;
350         }
351
352           if (mtype==1)
353           {
354                   // Widget interface
355                   wxButton *btnSetPositionPoint         = new wxButton( panel, -1, _T("Set nearest point"));
356                   txtNrPoints                                           = new wxStaticText(panel,-1, _T("-/-"));
357
358                   //NTU: Sliders for opacity and radio change
359 //          sdrRadio                            = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
360 //          sdrOpacity                        = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
361 //          Connect(sdrOpacity->GetId()           , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
362 //          Connect(sdrRadio->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
363                   wxStaticText* txOpacity                       = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
364                   wxStaticText* txRadio                         = new wxStaticText(panel, -1, wxString(_T("  Points Radio  ")));
365           
366           sCtrlRadio = new wxSpinCtrl( panel, -1  , wxEmptyString, wxDefaultPosition, sizeButton );
367           sCtrlRadio->SetRange(1,10);
368           sCtrlRadio->SetValue( 2 );
369           sCtrlOpacity= new wxSpinCtrl( panel, -1  , wxEmptyString, wxDefaultPosition, sizeButton );
370           sCtrlOpacity->SetRange(0,10);
371           sCtrlOpacity->SetValue( 10 );
372           Connect( sCtrlRadio->GetId()              ,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &WidgetShowNPoints::UpdatePoints);
373           Connect( sCtrlOpacity->GetId()            ,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &WidgetShowNPoints::UpdatePoints);
374                   Connect(btnSetPositionPoint->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
375           wxFlexGridSizer *sizer1           = new wxFlexGridSizer(1);
376                   sizer1->Add(btnSetPositionPoint);
377                   sizer1->Add(txtNrPoints);
378                   sizer1->Add(txRadio);
379                   //sizer1->Add(sdrRadio,1,wxGROW );
380           //sizer1->Add(sdrOpacity,1,wxGROW );
381           sizer1->Add(sCtrlRadio );
382           sizer1->Add(sCtrlOpacity);
383                   sizer = sizer1;
384           }
385     
386     if (mtype == 2) 
387         {
388                 askPointLabel                                           = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
389         wxButton                *btnAddPoint            = new wxButton(panel    , -1, _T("      Add  Point      "));
390         wxButton                *btnDeleteAllPoints = new wxButton(panel    , -1, _T("      Delete All      "));
391         wxStaticText    *spacer                         = new wxStaticText(panel, -1, _T("\n")); // JPR
392                                          textCtrl                       = new wxTextCtrl(panel, -1);
393         Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
394         Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);    
395         wxFlexGridSizer *sizer1             = new wxFlexGridSizer(1);
396         sizer1->Add(askPointLabel);
397         sizer1->Add(btnAddPoint);
398         sizer1->Add(btnDeleteAllPoints);
399         sizer1->Add(spacer);
400         sizer1->Add(textCtrl);
401       //  sdrOpacity                          = new wxSlider();
402       //  sdrRadio                            = new wxSlider();
403         txtNrPoints                         = new wxStaticText(panel, -1, _T("\n\n\n"));
404         sizer                               = sizer1;
405         } // bbGetInputType 2
406
407     panel->SetSizer(sizer);
408     panel->SetAutoLayout(true);
409     panel->Layout();
410     bookSetPoints->AddPage(panel , _T("Points") );
411
412     if ((mtype >= 0) && (mtype <= 3) )
413     {
414         if (sizer!=NULL)
415         {
416             wxFlexGridSizer *sizerParent             = new wxFlexGridSizer(1);
417             sizerParent->Add( bookSetPoints );
418             panelParent->SetSizer( sizerParent );
419             panelParent->SetAutoLayout(true);
420             panelParent->Layout();
421         } // if sizer
422     } // if  mtype 0 1 2 3
423       
424     if (mtype == 4)
425     {
426         if ((sizer!=NULL) && (MNPsizer!=NULL))
427         {
428             wxFlexGridSizer *sizerG             = new wxFlexGridSizer(2);
429             sizerG->Add(bookGroupManager);
430             sizerG->Add(bookSetPoints);
431             panelParent->SetSizer(sizerG);
432             panelParent->SetAutoLayout(true);
433             panelParent->Layout();
434         } // if sizer
435     } // if mtype 4
436 }
437
438 //------------------------------------------------------------------------
439 WidgetShowNPoints::~WidgetShowNPoints()
440 {
441 }
442
443 //------------------------------------------------------------------------
444 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
445 {
446     // EED 2022-05-19
447     // return mmodelShowNPoints;
448     return lstModelShowNPoints[ mActualCollection ];
449 }
450
451 //------------------------------------------------------------------------
452 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints(int id)
453 {
454         if(id >= 0 && id < lstModelShowNPoints.size())
455         {
456                 return lstModelShowNPoints[ id ];       
457         }
458 }
459
460 // EED 2022-05-19
461 //------------------------------------------------------------------------
462 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
463 {
464     return lstViewShowNPoints[ mActualCollection ];
465 }
466
467
468 //------------------------------------------------------------------------
469 void WidgetShowNPoints::SetRadio(double radio)
470 {
471     // EED 2022-05-19
472     // GetModelShowNPoints()->SetRadio(radio);
473     int i,size = lstModelShowNPoints.size();
474     for (i=0;i<size;i++)
475     {
476         lstModelShowNPoints[i]->SetRadio( radio );
477     } // for i
478         //NTU: For Slider
479 //      sdrRadio->SetValue(radio);
480     sCtrlRadio->SetValue(radio);
481 }
482
483 //------------------------------------------------------------------------
484 void WidgetShowNPoints::SetColour(std::vector<double> colour)
485 {
486     // EED 2022-05-19
487     //this->mcolour = colour;
488     int i,size = lstViewShowNPoints.size();
489     for (i=0 ; i<size ; i++)
490     {
491         lstViewShowNPoints[i]->mcolour = colour;
492     } // for i
493 }
494
495 //------------------------------------------------------------------------
496 void WidgetShowNPoints::SetImage(vtkImageData* image)
497 {
498     // EED 2022-05-19
499         //GetModelShowNPoints()->SetImage(image);
500     int i,size = lstModelShowNPoints.size();
501     for (i=0 ; i<size ; i++)
502     {
503         lstModelShowNPoints[i]->SetImage(image);
504     } // for i
505 }
506
507 //------------------------------------------------------------------------
508 void WidgetShowNPoints::SetOpacity(double opacity)
509 {
510     // EED 2022-05-19
511         //this->mopacity=opacity;
512     int i,size = lstViewShowNPoints.size();
513     for (i=0 ; i<size ; i++)
514     {
515         lstViewShowNPoints[i]->mopacity = opacity;
516     } // for i
517         //NTU: For Slider
518 //      sdrOpacity->SetValue( opacity*100.0 );
519     sCtrlOpacity->SetValue( opacity*10.0 );
520
521 }
522
523
524 //------------------------------------------------------------------------
525 void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
526 {
527     // EED 2022-05-19
528         //this->renderer        = renderer;
529     int i,size = lstViewShowNPoints.size();
530     for (i=0 ; i<size ; i++)
531     {
532         lstViewShowNPoints[i]->renderer = renderer;
533     } // for i
534 }
535
536 /* EED 2022-05-19
537 //------------------------------------------------------------------------
538         
539 void WidgetShowNPoints::RefreshPoint(int id)
540 {
541         double spc[3];
542         int x,y,z;
543         GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
544         GetModelShowNPoints()->GetImage()->GetSpacing(spc);
545         std::string label       = GetModelShowNPoints()->GetIdLabel(id);
546         double radio            = GetModelShowNPoints()->GetRadio();
547     lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
548     lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
549     lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
550     lstSourceSphere[id]->SetRadius( radio );
551 //EED 2017-01-01 Migration VTK7
552 #if VTK_MAJOR_VERSION <= 5
553         // ..
554 #else
555     lstSourceSphere[id]->Update();
556 #endif
557     lstActorsText[id]->SetInput( label.c_str()  );
558     lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
559 }
560
561 //------------------------------------------------------------------------
562 void WidgetShowNPoints::RefreshPoints()
563 {
564         int id,size=lstActorsSphere.size();
565         for (id=0;id<size;id++)
566         {
567                 RefreshPoint(id);
568         } // for
569         renderer->GetRenderWindow()->Render();
570 }
571
572 //------------------------------------------------------------------------
573 void WidgetShowNPoints::AddVtkPoint()
574 {
575         // Sphere
576         vtkSphereSource *vtksphere = vtkSphereSource::New();
577         vtksphere->SetThetaResolution (20);
578         vtksphere->SetPhiResolution (20);
579         vtksphere->SetRadius( 1 );
580         //NTU: For updating points
581         lstSourceSphere.push_back(vtksphere);
582         vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
583
584 //EED 2017-01-01 Migration VTK7
585 #if VTK_MAJOR_VERSION <= 5
586         sphereMapper->SetInput( vtksphere->GetOutput() );
587 #else
588         vtksphere->Update();
589         sphereMapper->SetInputData( vtksphere->GetOutput() );
590 #endif
591
592         vtkActor *sphereActor   = vtkActor::New();
593         sphereActor->SetMapper(sphereMapper);
594         sphereActor->SetOrigin(0, 0, 0);
595
596         lstActorsSphere.push_back(sphereActor);
597         if(renderer==NULL){
598                 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
599                 dialog.ShowModal();             
600                 return;
601         }
602         renderer->AddActor( sphereActor );
603         // Actor
604         vtkTextActor3D *textActor = vtkTextActor3D::New();
605 //      textActor->SetInput( strLabel.c_str()  );
606         renderer->AddActor( textActor );
607         lstActorsText.push_back(textActor);
608 }
609  */
610
611
612 void WidgetShowNPoints::SetCurrentPoint(int idCurrentPoint )
613 {
614     int size = GetModelShowNPoints()->GetLstPointsSize();
615     if (idCurrentPoint<0)       { idCurrentPoint = size-1;  }
616     if (idCurrentPoint>=size )  { idCurrentPoint = 0;       }
617     GetModelShowNPoints()->SetIdCurrentPoint( idCurrentPoint );
618     RefreshCollectionText();
619     RefreshColourCollection();
620 }
621
622 void WidgetShowNPoints::OnBackPoint(wxCommandEvent &event)
623 {
624     SetCurrentPoint(  GetModelShowNPoints()->GetIdCurrentPoint() - 1 );
625 }
626
627 void WidgetShowNPoints::OnNextPoint(wxCommandEvent &event)
628 {
629     SetCurrentPoint(  GetModelShowNPoints()->GetIdCurrentPoint() + 1 );
630 }
631
632
633 //------------------------------------------------------------------------
634 void WidgetShowNPoints::AddPoint(double x, double y, double z, std::string label)
635 {
636         GetModelShowNPoints()->AddPoint(x,y,z, label );
637     // EED 2022-05-19
638     //AddVtkPoint();
639     //RefreshPoint(lstActorsSphere.size()-1);
640     GetViewShowNPoints()->AddPoint();
641 }
642
643 //------------------------------------------------------------------------
644 void WidgetShowNPoints::InsertPoint(double x, double y, double z, std::string label)//CFT
645 {
646     // EED 2022-05-19
647         //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
648         //{
649     //    AddVtkPoint();
650         //} else {
651         //      AddPoint(x,y,z,label);
652         //}
653         //RefreshPoints();
654     if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
655     {
656         GetViewShowNPoints()->AddVtkPoint();
657     } else {
658         AddPoint(x,y,z,label);
659     }
660     GetViewShowNPoints()->RefreshPoints();
661 }
662
663 //------------------------------------------------------------------------
664 void WidgetShowNPoints::OnInsertPoint_()
665 {
666     // EED 2022-05-19
667     //if (this->renderer==NULL)
668     
669     StopAutoAddPoints();
670     StopTrackPoint();
671     if (GetViewShowNPoints()->renderer==NULL)
672     {
673         return;
674     }
675     std::vector<double> point = GetModelShowNPoints()->GetReferencePoint();
676     if (point.size()==3)
677     {
678         InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
679         SetOutputBox();
680     } else {//mpoint.size
681         printf("creaMaracasVisu::ShowNPoints (not match point) \n");
682     }
683     RefreshCollectionText();
684     RefreshColourCollection();
685     UndoRedo_SaveCollection();
686 }
687
688 //------------------------------------------------------------------------
689 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
690 {
691     OnInsertPoint_();
692 }
693
694 //------------------------------------------------------------------------
695 void WidgetShowNPoints::OnAddPoint__()
696 {       
697     // EED 2022-05-19
698         //if (this->renderer==NULL)
699     if (GetViewShowNPoints()->renderer==NULL)
700         {
701                 return;
702         }
703         std::vector<double> point = GetModelShowNPoints()->GetReferencePoint();
704         if (point.size()==3)
705         {
706                 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
707         SetOutputBox();
708         // EED 2022-05-19
709         //renderer->GetRenderWindow()->Render();
710         GetViewShowNPoints()->Render();
711         UndoRedo_SaveCollection();
712         } else {//mpoint.size
713                 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
714         }
715 }
716
717 void WidgetShowNPoints::OnAddPoint_()
718 {
719     StopAutoAddPoints();
720     StopTrackPoint();
721     OnAddPoint__();
722 }
723
724 //------------------------------------------------------------------------
725 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
726 {
727     OnAddPoint_();
728 }
729
730 //------------------------------------------------------------------------
731 void WidgetShowNPoints::AutoAddPoints()
732 {
733     if ( cbAutoAddPoints->GetValue() == true )
734     {
735         OnAddPoint__();
736         RefreshCollectionText();
737         RefreshColourCollection();
738     } // if cbAutoAddPoints
739 }
740
741 //------------------------------------------------------------------------
742 void WidgetShowNPoints::OnAutoAddPoints_tool()
743 {
744     StopTrackPoint();
745     cbAutoAddPoints->SetValue( !cbAutoAddPoints->GetValue() );
746 }
747
748 //------------------------------------------------------------------------
749 void WidgetShowNPoints::OnAutoAddPoints_()
750 {
751     StopTrackPoint();
752 }
753
754 //------------------------------------------------------------------------
755 void WidgetShowNPoints::OnAutoAddPoints(wxCommandEvent& event)
756 {
757     StopTrackPoint();
758 }
759
760 //------------------------------------------------------------------------
761 void WidgetShowNPoints::StopAutoAddPoints( )
762 {
763     cbAutoAddPoints->SetValue(false);
764 }
765
766 //------------------------------------------------------------------------
767         void WidgetShowNPoints::SetOutputBox()
768         {
769                 wxString strTmp;
770         if (GetModelShowNPoints()->GetIdCurrentPoint()<0)
771         {
772             strTmp.Printf(_T("   -/%d") , GetModelShowNPoints()->GetLstPointsSize() );
773         } else {
774             strTmp.Printf(_T("   %d/%d"), GetModelShowNPoints()->GetIdCurrentPoint()+1 , GetModelShowNPoints()->GetLstPointsSize() );
775         }// if IdCurrent<0
776                 txtNrPoints->SetLabel( strTmp );
777                 //--BBTK
778
779 //EED 2017-06-03
780 //              mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
781 //              mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
782 //              mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
783 //              mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
784 //              mbbShowNPoints->bbSignalOutputModification();
785         }
786
787
788 //------------------------------------------------------------------------
789         void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
790         {
791
792 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
793 #if wxMAJOR_VERSION <= 2
794                 wxFileDialog* FD = new wxFileDialog( 0,
795                                             _T("Save points .."),
796                                             _T(""),
797                                             _T(""),
798                                             _T("(*.xls)|*.xls"),
799                                             wxSAVE | wxOVERWRITE_PROMPT,
800                                             wxDefaultPosition);
801 #else
802                 wxFileDialog* FD = new wxFileDialog( 0,
803                                             _T("Save points .."),
804                                             _T(""),
805                                             _T(""),
806                                             _T("(*.xls)|*.xls"),
807                                             wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
808                                             wxDefaultPosition);
809 #endif
810
811                 int result_FD = FD->ShowModal();
812                 // This line is need it by windows //EED
813                 FD->SetReturnCode( result_FD );
814                 if (FD->GetReturnCode()==wxID_OK)
815                 {
816                         std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
817                         GetModelShowNPoints()->SavePoints( filename );
818                 }       // dialog box
819         }
820
821
822 //------------------------------------------------------------------------
823         void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
824         {
825
826 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
827 #if wxMAJOR_VERSION <= 2
828                 wxFileDialog* FD = new wxFileDialog( 0,
829                                              _T("Load points .."),
830                                              _T(""),
831                                              _T(""),
832                                              _T("(*.xls)|*.xls"),
833                                              wxOPEN | wxFILE_MUST_EXIST,
834                                              wxDefaultPosition);
835 #else
836                 wxFileDialog* FD = new wxFileDialog( 0,
837                                              _T("Load points .."),
838                                              _T(""),
839                                              _T(""),
840                                              _T("(*.xls)|*.xls"),
841                                              wxFD_OPEN | wxFD_FILE_MUST_EXIST,
842                                              wxDefaultPosition);
843 #endif
844                 int i;
845                 //EED
846                 int result_FD = FD->ShowModal();
847                 // This line is need it by windows //EED
848                 FD->SetReturnCode( result_FD );
849                 if (FD->GetReturnCode()==wxID_OK)
850                 {
851
852                         std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
853                         int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
854                         for (i=0;i<numberPointsRead;i++)
855                         {
856                 // EED 2022-05-19
857                 //AddVtkPoint();
858                 GetViewShowNPoints()->AddVtkPoint();
859                         }// for
860                         SetOutputBox();
861             // EED 2022-05-19
862                         //RefreshPoints();
863             GetViewShowNPoints()->RefreshPoints();
864                 }       // dialog box
865         }
866
867 //------------------------------------------------------------------------
868 void WidgetShowNPoints::OnSetPoint_()
869 {
870     StopAutoAddPoints();
871     StopTrackPoint();
872
873     //int id=GetModelShowNPoints()->GetNearestPoint();
874     int id=GetModelShowNPoints()->GetIdCurrentPoint();
875
876     if((id==-1) && (mtype==1))
877     {
878         id=0;
879         AddPoint(0,0,0,"");
880         SetOutputBox();
881     }
882     if (id>=0)
883     {
884         GetModelShowNPoints()->SetPointId_mReferencePoint(id);
885         // EED 2022-05-19
886         //RefreshPoint(id);
887         //renderer->GetRenderWindow()->Render();
888         GetViewShowNPoints()->RefreshPoint(id);
889         GetViewShowNPoints()->Render();
890     } // if id
891     RefreshCollectionText();
892     RefreshColourCollection();
893     SetOutputBox();
894     UndoRedo_SaveCollection();
895 }
896
897 //------------------------------------------------------------------------
898 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
899 {
900     OnSetPoint_();
901 }
902
903 //------------------------------------------------------------------------
904 void WidgetShowNPoints::MovePoint_(double step)
905 {
906     step=step;
907     StopAutoAddPoints();
908     StopTrackPoint();
909     int id=GetModelShowNPoints()->GetIdCurrentPoint();
910     if (aux_mesh!=NULL)
911     {
912         if((GetLstModelShowNPointsSize()>=2)  //Check condition
913             && (GetModelShowNPoints()->GetLstPointsSize()>0)
914             && (aux_mesh != NULL)
915             && (aux_mesh_spc.size() == 3))
916         {
917             double              x,y,z;
918             double              p[3];
919             double              normal[3];      // point to modify and normal
920             std::vector<double> pN(3);          // new point
921             vtkStaticPointLocator   *pointLocator   = vtkStaticPointLocator::New();
922             pointLocator->SetDataSet( aux_mesh );
923             pointLocator->BuildLocator();
924             
925     //        int idControlPoint = wsp->GetModelShowNPoints()->GetNearestPoint();
926             int idControlPoint = GetModelShowNPoints()->GetIdCurrentPoint();
927             if(idControlPoint >= 0)
928             {
929                 GetModelShowNPoints()->GetIdPoint(idControlPoint, &x, &y, &z);
930                 p[0] = x * aux_mesh_spc[0];
931                 p[1] = y * aux_mesh_spc[1];
932                 p[2] = z * aux_mesh_spc[2];
933                 long int idMeshPoint = pointLocator->FindClosestPoint(p);
934                 vtkDataArray *dataArrayNormals = aux_mesh->GetPointData()->GetNormals();
935                 if (dataArrayNormals!=NULL)
936                 {
937                     dataArrayNormals->GetTuple(idMeshPoint, normal);
938                     
939                     int direction = step;
940     //                pN[0] = p[0] / spc[0] + direction*normal[0];
941     //                pN[1] = p[1] / spc[1] + direction*normal[1];
942     //                pN[2] = p[2] / spc[2] + direction*normal[2];
943                     pN[0] = x + (direction * normal[0]);
944                     pN[1] = y + (direction * normal[1]);
945                     pN[2] = z + (direction * normal[2]);
946                     GetModelShowNPoints()->SetPointById(idControlPoint, pN);
947         //          GetViewShowNPoints()->RefreshPoint(idControlPoint);
948     //                RefreshCollectionText();
949     //                RefreshColourCollection();
950     //                SetOutputBox();
951                     UndoRedo_SaveCollection();
952                 } else {
953                     printf("Error!  WidgetShowNPoints::MovePoint_  Missing normals in aux_mesh  \n");
954                 }
955             } // if idControlPoint
956         } // if wsp->GetLstModelShowNPointsSiz->size()>=2
957     } else {
958         if (id>=0) {
959             int i,j,sizeG,sizeP;
960             double max=100000;
961             double minX=max,minY=max,minZ=max;
962             double maxX=-max,maxY=-max,maxZ=-max;
963             sizeG = lstModelShowNPoints.size();
964             for (i=0; i<sizeG; i++)
965             {
966                 std::vector<double> lstX = lstModelShowNPoints[i]->GetLstPointsX();
967                 std::vector<double> lstY = lstModelShowNPoints[i]->GetLstPointsY();
968                 std::vector<double> lstZ = lstModelShowNPoints[i]->GetLstPointsZ();
969                 sizeP=lstX.size();
970                 for (j=0; j<sizeP; j++)
971                 {
972                     if ( lstX[j]<minX ) { minX=lstX[j]; }
973                     if ( lstY[j]<minY ) { minY=lstY[j]; }
974                     if ( lstZ[j]<minZ ) { minZ=lstZ[j]; }
975                     if ( lstX[j]>maxX ) { maxX=lstX[j]; }
976                     if ( lstY[j]>maxY ) { maxY=lstY[j]; }
977                     if ( lstZ[j]>maxZ ) { maxZ=lstZ[j]; }
978                 } // for j
979             } // for i
980             double pc[3];
981             pc[0]=(minX+maxX) /2 ;  pc[1]=(minY+maxY) /2 ;  pc[2]=(minZ+maxZ) /2 ;
982             double p[3];
983             p[0]=GetModelShowNPoints()->GetLstPointsX()[id];
984             p[1]=GetModelShowNPoints()->GetLstPointsY()[id];
985             p[2]=GetModelShowNPoints()->GetLstPointsZ()[id];
986             double v[3];
987             v[0] = p[0]-pc[0];
988             v[1] = p[1]-pc[1];
989             v[2] = p[2]-pc[2];
990             double mag=sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] );
991             std::vector<double> point;
992             if (mag!=0)
993             {
994                 v[0] = v[0]/mag;
995                 v[1] = v[1]/mag;
996                 v[2] = v[2]/mag;
997             } else {
998                 v[0] = 0;
999                 v[1] = 0;
1000                 v[2] = 0;
1001             }// if mag
1002             point.push_back( p[0] + step*v[0] );
1003             point.push_back( p[1] + step*v[1] );
1004             point.push_back( p[2] + step*v[2] );
1005             GetModelShowNPoints()->SetPointById(id,point);
1006             UndoRedo_SaveCollection();
1007      } // if id
1008     } // if aux_mesh
1009  RefreshCollectionText();
1010  RefreshColourCollection();
1011 }
1012
1013 //------------------------------------------------------------------------
1014 void WidgetShowNPoints::OnMovePointUp(wxCommandEvent& event)
1015 {
1016     MovePoint_(-1);
1017 }
1018
1019 //------------------------------------------------------------------------
1020 void WidgetShowNPoints::OnMovePointDown(wxCommandEvent& event)
1021 {
1022     MovePoint_(+1);
1023 }
1024
1025 //------------------------------------------------------------------------
1026 void WidgetShowNPoints::TrackingPoint( )
1027 {
1028     if ( cbTrackPoint->GetValue() == true )
1029     {
1030 //        int id = GetModelShowNPoints()->IdInsidePoint();
1031 //        if (id>=0)
1032 //        {
1033 //            idTrack=id;
1034 //        }
1035         
1036 //       int idTrack = GetModelShowNPoints()->GetIdCurrentPoint();
1037         int idTrack = GetModelShowNPoints()->GetNearestPoint();
1038
1039         
1040         if (idTrack>=0)
1041         {
1042             GetModelShowNPoints()->SetPointId_mReferencePoint(idTrack);
1043             
1044             RefreshCollectionText();
1045             RefreshColourCollection();
1046
1047 //            GetViewShowNPoints()->RefreshPoint(idTrack);
1048 //            GetViewShowNPoints()->Render();
1049             UndoRedo_SaveCollection();
1050         } // if id
1051     } // if trackPointFlag
1052 }
1053
1054 //------------------------------------------------------------------------
1055 void WidgetShowNPoints::OnTrackPoint_tool()
1056 {
1057     cbTrackPoint->SetValue( !cbTrackPoint->GetValue() );
1058     OnTrackPoint_();
1059 }
1060
1061 //------------------------------------------------------------------------
1062 void WidgetShowNPoints::OnTrackPoint_()
1063 {
1064     StopAutoAddPoints();
1065
1066 //    idTrack         =   -1;
1067     if ( cbTrackPoint->GetValue() == true )
1068     {
1069         // EED 2023-06-23
1070 //        idTrack = GetModelShowNPoints()->IdInsidePoint();
1071 //        idTrack = GetModelShowNPoints()->GetIdCurrentPoint();
1072     } // if trackPointFlag
1073 }
1074
1075 //------------------------------------------------------------------------
1076 void WidgetShowNPoints::OnTrackPoint(wxCommandEvent& event)
1077 {
1078     OnTrackPoint_();
1079 }
1080
1081 //------------------------------------------------------------------------
1082 void WidgetShowNPoints::StopTrackPoint( )
1083 {
1084     cbTrackPoint->SetValue(false);
1085 //    idTrack=-1;
1086 }
1087
1088 //------------------------------------------------------------------------
1089         void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
1090         {
1091                 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
1092                 if (id>=0)
1093                 {
1094             // EED 2022-05-19
1095                         //lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
1096                         //renderer->GetRenderWindow()->Render();
1097             GetViewShowNPoints()->lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
1098             GetViewShowNPoints()->Render();
1099             SetOutputBox();
1100             UndoRedo_SaveCollection();
1101                 } // if id
1102         }
1103
1104 //------------------------------------------------------------------------
1105         bool WidgetShowNPoints::ErasePoint(int id)
1106         {
1107         // EED 2022-05-19
1108                 //if (this->renderer!=NULL)
1109         bool ok=false;
1110         if (GetViewShowNPoints()->renderer!=NULL)
1111                 {
1112                         if (id>=0)
1113                         {
1114                 // EED 2022-05-19
1115                                 //renderer->RemoveActor( lstActorsSphere[id] );
1116                                 //renderer->RemoveActor( lstActorsText[id] );
1117                                 //lstActorsSphere[id]->Delete();
1118                                 //lstActorsText[id]->Delete();
1119                                 //lstSourceSphere[id]->Delete();
1120                                 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
1121                                 //lstActorsText.erase( lstActorsText.begin()+id );
1122                                 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
1123                 GetViewShowNPoints()->ErasePoint(id);
1124                                 GetModelShowNPoints()->ErasePoint(id);
1125                 ok=true;
1126                         } // if id
1127                 } // if renderer
1128         return ok;
1129         }
1130
1131 //------------------------------------------------------------------------
1132     void WidgetShowNPoints::OnErasePoint_()
1133     {
1134         StopAutoAddPoints();
1135         StopTrackPoint();
1136
1137         //ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
1138         if (ErasePoint( GetModelShowNPoints()->GetIdCurrentPoint() ) == true)
1139         {
1140             SetOutputBox();
1141             // EED 2022-05-19
1142             //renderer->GetRenderWindow()->Render();
1143             //        GetViewShowNPoints()->Render();
1144             RefreshCollectionText();
1145             RefreshColourCollection();
1146             StopTrackPoint();
1147             UndoRedo_SaveCollection();
1148         }
1149     }
1150
1151 //------------------------------------------------------------------------
1152         void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
1153         {
1154                 OnErasePoint_();
1155         }
1156
1157 //------------------------------------------------------------------------
1158         void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
1159         {
1160         // EED 2022-05-19
1161         //ErasePoint( lstActorsSphere.size()-1 );
1162         //renderer->GetRenderWindow()->Render();
1163         StopAutoAddPoints();
1164         StopTrackPoint();
1165
1166         int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
1167         ErasePoint( id );
1168         
1169         RefreshCollectionText();
1170         RefreshColourCollection();
1171         
1172         UndoRedo_SaveCollection();
1173         GetViewShowNPoints()->Render();
1174         SetOutputBox();
1175         StopTrackPoint();
1176         }
1177
1178 //------------------------------------------------------------------------
1179 void WidgetShowNPoints::DeleteAllPoints_()
1180 {
1181     // EED 2022-05-19
1182     //int id,size=lstActorsSphere.size();
1183     int id,size=GetViewShowNPoints()->lstActorsSphere.size();
1184     for (id=size-1;id>=0;id--)
1185     {
1186         ErasePoint(id);
1187     }// for id
1188 }
1189
1190 void WidgetShowNPoints::OnDeleteAllPoints_()
1191 {
1192     StopAutoAddPoints();
1193     StopTrackPoint();
1194
1195     DeleteAllPoints_();
1196     UndoRedo_SaveCollection();
1197 }
1198
1199 //------------------------------------------------------------------------
1200 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
1201 {
1202         OnDeleteAllPoints_();
1203     SetOutputBox();
1204     GetViewShowNPoints()->Render();
1205 }
1206
1207 //NTU: Method for updating points opacity and Radio
1208
1209 //------------------------------------------------------------------------
1210 void WidgetShowNPoints::UpdatePoints_()
1211 {
1212     // EED 2022-05-19
1213     //this->mopacity = sdrOpacity->GetValue()/100.0;
1214     //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
1215     //RefreshPoints();
1216
1217 //    double opacity  = sdrOpacity->GetValue()/100.0;
1218 //    double radio    = sdrRadio->GetValue();
1219     double opacity  = (sCtrlOpacity->GetValue()*10)/100.0;
1220      double radio    = sCtrlRadio->GetValue();
1221       
1222     int i,size      = lstViewShowNPoints.size();
1223     for (i=0 ; i<size ; i++)
1224     {
1225         lstViewShowNPoints[i]->mopacity = opacity;
1226         lstModelShowNPoints[i]->SetRadio( radio ) ;
1227     } // for i
1228 //    GetViewShowNPoints()->RefreshPoints();
1229 }
1230
1231 //------------------------------------------------------------------------
1232 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
1233 {
1234     RefreshColourCollection();
1235 }
1236
1237 //------------------------------------------------------------------------
1238 void  WidgetShowNPoints::SetReferencePoint(std::vector<double> point)
1239 {
1240         GetModelShowNPoints()->SetReferencePoint(point);
1241     int i,size=lstModelShowNPoints.size();
1242     for (i=0;i<size;i++)
1243     {
1244         lstModelShowNPoints[i]->SetReferencePoint(point);    // All collection
1245     } // for i
1246 }
1247
1248 //------------------------------------------------------------------------
1249 void WidgetShowNPoints::SetActualCollection( int actual )
1250 {
1251     if (actual<0)
1252     {
1253         actual=0;
1254     } // if actual<0
1255     
1256     if (actual>lstModelShowNPoints.size()-1 )
1257     {
1258         actual=lstModelShowNPoints.size()-1;
1259     } // if actual<0
1260
1261     mActualCollection=actual;
1262 }
1263
1264
1265 //------------------------------------------------------------------------
1266 void  WidgetShowNPoints::SetInitLstPoints( std::vector<double> initLstPointsX,  std::vector<double> initLstPointsY, std::vector<double> initLstPointsZ, std::vector<std::string> initLstLabels,   std::vector<int> initLstIndexs )
1267 {
1268     if (GetViewShowNPoints()->renderer==NULL)
1269     {
1270         return;
1271     }
1272     double x,y,z;
1273     std::string label;
1274     int i,sizeX,sizeY,sizeZ,sizeTmp,sizeLabels;
1275     int ii,iIndexs,sizeIndexs;
1276     
1277     sizeX       = (int)initLstPointsX.size();
1278     sizeY       = (int)initLstPointsY.size();
1279     sizeZ       = (int)initLstPointsZ.size();
1280     sizeLabels  = (int)initLstLabels.size();
1281     sizeIndexs  = (int)initLstIndexs.size();
1282     
1283     if (sizeIndexs==0)
1284     {
1285         initLstIndexs.push_back(sizeX);
1286         sizeIndexs  = (int)initLstIndexs.size();
1287     }
1288     
1289     if ( (sizeX==sizeY) && (sizeX==sizeZ) )
1290     {
1291         i=0;
1292         for (iIndexs=0;iIndexs<sizeIndexs;iIndexs++ )
1293         {
1294             if (iIndexs!=0)
1295             {
1296                 InsertCollectionAfter_();
1297             }// if last iIndexs
1298             sizeTmp = initLstIndexs[iIndexs];
1299             for (ii=0;ii<sizeTmp;ii++)
1300             {
1301                 x        = initLstPointsX[i];
1302                 y        = initLstPointsY[i];
1303                 z        = initLstPointsZ[i];
1304                 if (i<sizeLabels)
1305                 {
1306                     label    = initLstLabels[i];
1307                 } else {
1308                     label="";
1309                 }
1310                 AddPoint( x,y,z,label );
1311                 i++;
1312             } // for i
1313
1314             
1315         }// for ii
1316         //    SetOutputBox();
1317         //    renderer->GetRenderWindow()->Render();
1318     } // if size
1319
1320     
1321
1322     
1323     /*
1324     
1325     // EED 2022-05-19
1326         //if (this->renderer==NULL)
1327     if (GetViewShowNPoints()->renderer==NULL)
1328         {
1329                 return;
1330         }
1331         int i,sizeX,sizeY,sizeZ,sizeLabels;
1332         sizeX = (int)initLstPointsX.size();
1333         sizeY = (int)initLstPointsY.size();
1334         sizeZ = (int)initLstPointsZ.size();
1335         sizeLabels = (int)initLstLabels.size();
1336         double x,y,z;
1337         std::string label;
1338         if ( (sizeX==sizeY) && (sizeX==sizeZ) )
1339         {
1340                 for (i=0;i<sizeX;i++)
1341                 {
1342                         x               = initLstPointsX[i];
1343                         y               = initLstPointsY[i];
1344                         z               = initLstPointsZ[i];
1345                         if (i<sizeLabels) 
1346                         {
1347                                 label   = initLstLabels[i];
1348                         } else {
1349                                 label="";
1350                         }
1351                         AddPoint( x,y,z,label );
1352                 } // for i
1353                 //      SetOutputBox(); 
1354                 //      renderer->GetRenderWindow()->Render();
1355         } // if size
1356      
1357    */
1358 }
1359
1360 //------------------------------------------------------------------------
1361 void WidgetShowNPoints::SetType(int type)
1362 {
1363         mtype=type;
1364 }
1365
1366 //------------------------------------------------------------------------
1367 int WidgetShowNPoints::GetType()
1368 {
1369         return mtype;
1370 }
1371
1372
1373 //------------------------------------------------------------------------
1374 double WidgetShowNPoints::GetRadio()
1375 {
1376 //      return sdrRadio->GetValue();
1377     return sCtrlRadio->GetValue();
1378 }
1379 //------------------------------------------------------------------------
1380 double WidgetShowNPoints::GetOpacity()
1381 {
1382 //    return sdrOpacity->GetValue()/100;
1383     return (sCtrlOpacity->GetValue()*10)/100.0;
1384 }
1385
1386 //------------------------------------------------------------------------
1387 void WidgetShowNPoints::InsertCollection()
1388 {
1389     ModelShowNPoints*   model   = new ModelShowNPoints();
1390     ViewShowNPoints*    view    = new ViewShowNPoints( model );
1391     view->mopacity              = lstViewShowNPoints[0]->mopacity;
1392     view->renderer              = lstViewShowNPoints[0]->renderer;
1393     model->SetImage( lstModelShowNPoints[0]->GetImage() );
1394     lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
1395     lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
1396 }
1397
1398 //------------------------------------------------------------------------
1399 void WidgetShowNPoints::InsertCollectionBefore_()  
1400 {
1401     InsertCollection();
1402     RefreshCollectionText();
1403     RefreshColourCollection();
1404     StopTrackPoint();
1405 }
1406
1407 //------------------------------------------------------------------------
1408 void WidgetShowNPoints::OnInsertCollectionBefore_()
1409 {
1410     InsertCollectionBefore_();
1411     CreatePointsIntoNewCollection();
1412     UndoRedo_SaveCollection();
1413 }
1414
1415
1416 //------------------------------------------------------------------------
1417 void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
1418 {
1419     OnInsertCollectionBefore_();
1420 }
1421
1422
1423 //------------------------------------------------------------------------
1424 void WidgetShowNPoints::InsertCollectionAfter_()
1425 {
1426     mActualCollection++;
1427     InsertCollection();
1428     RefreshCollectionText();
1429     RefreshColourCollection();
1430     StopTrackPoint();
1431 }
1432
1433
1434 //------------------------------------------------------------------------
1435 void WidgetShowNPoints::OnInsertCollectionAfter_()
1436 {
1437     InsertCollectionAfter_();
1438     CreatePointsIntoNewCollection();
1439     UndoRedo_SaveCollection();
1440 }
1441
1442 //------------------------------------------------------------------------
1443 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
1444 {
1445     OnInsertCollectionAfter_();
1446 }
1447
1448 //------------------------------------------------------------------------
1449 void WidgetShowNPoints::CreatePointsIntoNewCollection()
1450 {
1451     int c1          = mActualCollection-1;
1452     int c2          = mActualCollection+1;
1453     int modelSize   = lstModelShowNPoints.size();
1454     if (aux_mesh_type==2)  // SplineClose2
1455     {
1456         if (c1==-1)         { c1=modelSize-1;   }
1457         if (c2==modelSize)  { c2=0;             }
1458     } // if aux_mesh_type
1459     
1460     if ( (c1!=c2) && (c1>=0) && (c1<modelSize) && (c2>=0) && (c2<modelSize) )
1461     {
1462         std::vector<double> c1LstX = lstModelShowNPoints[c1]->GetLstPointsX();
1463         std::vector<double> c1LstY = lstModelShowNPoints[c1]->GetLstPointsY();
1464         std::vector<double> c1LstZ = lstModelShowNPoints[c1]->GetLstPointsZ();
1465         std::vector<double> c2LstX = lstModelShowNPoints[c2]->GetLstPointsX();
1466         std::vector<double> c2LstY = lstModelShowNPoints[c2]->GetLstPointsY();
1467         std::vector<double> c2LstZ = lstModelShowNPoints[c2]->GetLstPointsZ();
1468         std::vector<double> c1LstXX;
1469         std::vector<double> c1LstYY;
1470         std::vector<double> c1LstZZ;
1471         std::vector<double> c2LstXX;
1472         std::vector<double> c2LstYY;
1473         std::vector<double> c2LstZZ;
1474         creaContoursFactory     f;
1475         manualContourModel      *m;
1476         double                  x,y,z;
1477         int                     i,ii,size;
1478         int                     sc; // sizeContour
1479         
1480         if ( (c1LstX.size()!=0) && (c2LstX.size()!=0) )
1481         {
1482             // ----------------- Spline 1 --------------------
1483             sc          = 100;
1484             size        = c1LstX.size();
1485             m           = (manualContourModel*)f.getContourModel( 1 );  // Spline
1486             //        m->SetNumberOfPointsSpline( bbGetInputNbPoints() );
1487             m->SetNumberOfPointsSpline( sc );
1488             m->SetCloseContour( false );
1489             for (i=0;i<size;i++)
1490             {
1491                 m->AddPoint( c1LstX[i] , c1LstY[i] , c1LstZ[i] );
1492             } // for
1493             m->UpdateSpline();
1494             for (i=0;i<sc;i++)
1495             {
1496                 m->GetSpline_i_Point(i,&x,&y,&z);
1497                 c1LstXX.push_back(x);
1498                 c1LstYY.push_back(y);
1499                 c1LstZZ.push_back(z);
1500             } // for
1501             delete m;
1502             // ----------------- Spline 2 --------------------
1503             size        = c2LstX.size();
1504             m           = (manualContourModel*)f.getContourModel( 1 );  // Spline
1505             //        m->SetNumberOfPointsSpline( bbGetInputNbPoints() );
1506             m->SetNumberOfPointsSpline( sc );
1507             m->SetCloseContour( false );
1508             for (i=0;i<size;i++)
1509             {
1510                 m->AddPoint( c2LstX[i] , c2LstY[i] , c2LstZ[i] );
1511             } // for
1512             m->UpdateSpline();
1513             for (i=0;i<sc;i++)
1514             {
1515                 m->GetSpline_i_Point(i,&x,&y,&z);
1516                 c2LstXX.push_back(x);
1517                 c2LstYY.push_back(y);
1518                 c2LstZZ.push_back(z);
1519             } // for
1520             delete m;
1521             // ----------------- Add new Points --------------------
1522             vtkPoints               *points         = NULL;
1523             vtkStaticPointLocator   *pointLocator   = NULL;
1524             if (aux_mesh!=NULL)
1525             {
1526                 points         = aux_mesh->GetPoints();
1527                 pointLocator   = vtkStaticPointLocator::New();
1528                 pointLocator->SetDataSet( aux_mesh );
1529                 pointLocator->BuildLocator();
1530             } // if aux_mesh
1531             
1532             double p[3], pM[3];
1533             if ( c1LstX.size()<c2LstX.size() ) { size=c2LstX.size(); } else { size=c1LstX.size(); }
1534             for (ii=0;ii<size;ii++)
1535             {
1536                 i = (int) ((double)ii/((double)size-1)*(sc-1));
1537                 x = (c1LstXX[i]+c2LstXX[i])/2;
1538                 y = (c1LstYY[i]+c2LstYY[i])/2;
1539                 z = (c1LstZZ[i]+c2LstZZ[i])/2;
1540                 if (aux_mesh!=NULL)
1541                 {
1542                     p[0]  = x * aux_mesh_spc[0];
1543                     p[1]  = y * aux_mesh_spc[1];
1544                     p[2]  = z * aux_mesh_spc[2];
1545                     points->GetPoint( pointLocator->FindClosestPoint(p) , pM );
1546                     x = pM[0] / aux_mesh_spc[0];
1547                     y = pM[1] / aux_mesh_spc[1];
1548                     z = pM[2] / aux_mesh_spc[2];
1549                 } // aux_mesh
1550                 AddPoint(x,y,z,"");
1551             }
1552             if (pointLocator!=NULL) { pointLocator->Delete(); }
1553             RefreshCollectionText();
1554             RefreshColourCollection();
1555         } // if size of c1LstX c2LstX
1556     }  // if c1 && c2
1557 }
1558
1559 //------------------------------------------------------------------------
1560 void WidgetShowNPoints::DeleteCollection_()
1561 {
1562     if ( lstModelShowNPoints.size()>1 )
1563     {
1564         DeleteAllPoints_();  // Actual Collection
1565         lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
1566         lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
1567         if ( mActualCollection>=lstModelShowNPoints.size() )
1568         {
1569             mActualCollection--;
1570         } // if
1571     } else {
1572         DeleteAllPoints_();  // Actual Collection
1573     } // if
1574 }
1575
1576 //------------------------------------------------------------------------
1577 void WidgetShowNPoints::OnDeleteCollection_()
1578 {
1579     DeleteCollection_();
1580     SetOutputBox();
1581     GetViewShowNPoints()->Render();
1582     RefreshCollectionText();
1583     RefreshColourCollection();
1584     StopTrackPoint();
1585     UndoRedo_SaveCollection();
1586 }
1587
1588 //------------------------------------------------------------------------
1589 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
1590 {
1591     OnDeleteCollection_();
1592 }
1593
1594 //------------------------------------------------------------------------
1595 void WidgetShowNPoints::ResetCollections_()
1596 {
1597     int i,size=lstModelShowNPoints.size();
1598     for (i=0;i<size;i++)
1599     {
1600         DeleteCollection_();
1601     }
1602     GetViewShowNPoints()->Render();
1603     RefreshCollectionText();
1604     RefreshColourCollection();
1605     StopTrackPoint();
1606 }
1607
1608
1609 //------------------------------------------------------------------------
1610 void WidgetShowNPoints::OnResetCollections_()
1611 {
1612     ResetCollections_();
1613     UndoRedo_SaveCollection();
1614 }
1615
1616
1617 //------------------------------------------------------------------------
1618 void WidgetShowNPoints::OnResetCollections(wxCommandEvent &event)
1619 {
1620     OnResetCollections_();
1621 }
1622
1623 //------------------------------------------------------------------------
1624 void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
1625 {
1626     mActualCollection--;
1627     if ( mActualCollection <0  )
1628     {
1629 //        mActualCollection=0;
1630          mActualCollection = lstModelShowNPoints.size()-1;
1631     } //if <=0
1632     RefreshCollectionText();
1633     RefreshColourCollection();
1634     StopTrackPoint();
1635     UndoRedo_SaveCollection();
1636 }
1637
1638 //------------------------------------------------------------------------
1639 void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
1640 {
1641     mActualCollection++;
1642     if ( mActualCollection >=lstModelShowNPoints.size() )
1643     {
1644 //        mActualCollection = lstModelShowNPoints.size()-1;
1645          mActualCollection = 0;
1646     } //if mActualCollection >= size
1647     RefreshCollectionText();
1648     RefreshColourCollection();
1649     StopTrackPoint();
1650     UndoRedo_SaveCollection();
1651 }
1652
1653 //------------------------------------------------------------------------
1654 void WidgetShowNPoints::DetectCollectionActive()
1655 {
1656     int id;
1657     int i,size=lstModelShowNPoints.size();
1658     for (i=0;i<size;i++)
1659     {
1660         id = lstModelShowNPoints[i]->IdInsidePoint();
1661         if (id>=0)
1662         {
1663             mActualCollection=i;
1664         } // if id>=0
1665     } // for i
1666     RefreshCollectionText();
1667     RefreshColourCollection();
1668 }
1669
1670 //------------------------------------------------------------------------
1671 void WidgetShowNPoints::RefreshColourCollection()
1672 {
1673     UpdatePoints_();
1674     std::vector<double> colourAll;
1675     colourAll.push_back(1);
1676     colourAll.push_back(0);
1677     colourAll.push_back(0);
1678     std::vector<double> colourActualGroup;
1679     colourActualGroup.push_back(1);
1680     colourActualGroup.push_back(1);
1681     colourActualGroup.push_back(0);
1682
1683     // For all collections
1684     SetColour( colourAll );
1685     int i,size=lstViewShowNPoints.size();
1686     for (i=0;i<size;i++)
1687     {
1688         lstViewShowNPoints[i] -> mcolour    = colourAll;
1689         lstViewShowNPoints[i] -> ratioRadio = 1;
1690         if ((cbVisuActualCollection!=NULL) && (cbVisuActualCollection->GetValue()==true))
1691         {
1692             lstViewShowNPoints[i] -> mopacity   = 0.0;
1693         } else {
1694             lstViewShowNPoints[i] -> mopacity   = sCtrlOpacity->GetValue()*10.0/100.0;
1695         }
1696         lstViewShowNPoints[i]->RefreshEachPoint();
1697     } // for i
1698     
1699     // Actual collection
1700     lstViewShowNPoints[mActualCollection] -> mcolour = colourActualGroup;
1701     lstViewShowNPoints[mActualCollection] -> mopacity   = sCtrlOpacity->GetValue()*10.0/100.0;
1702     lstViewShowNPoints[mActualCollection] -> ratioRadio = 1.1;
1703     lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
1704     
1705     //Actual Point
1706     int curPnt = lstModelShowNPoints[mActualCollection] -> GetIdCurrentPoint();
1707     size=lstModelShowNPoints[mActualCollection]->GetLstPointsSize();
1708     if ((curPnt>=0)  && (curPnt<size  ) )
1709     {
1710         std::vector<double> colourActualPoint;
1711         colourActualPoint.push_back(0);
1712         colourActualPoint.push_back(0);
1713         colourActualPoint.push_back(1);
1714         double radio          = GetModelShowNPoints()->GetRadio();
1715         lstViewShowNPoints[mActualCollection] -> mcolour  = colourActualPoint;
1716         lstViewShowNPoints[mActualCollection]->RefreshPoint( curPnt   );
1717         lstViewShowNPoints[mActualCollection] -> mcolour = colourActualGroup;
1718     } // if
1719     lstViewShowNPoints[mActualCollection] -> renderer->GetRenderWindow()->Render();
1720 }
1721
1722 //------------------------------------------------------------------------
1723 void WidgetShowNPoints::RefreshCollectionText()
1724 {
1725     if ((mtype==4) && (txtNrCollections!=NULL))  // Just for Collection interface
1726     {
1727         wxString strTmp;
1728         strTmp.Printf(_T("   %d/%d"),  (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
1729         txtNrCollections->SetLabel( strTmp );
1730     } // if mtype 4
1731     SetOutputBox();
1732 }
1733
1734
1735 //------------------------------------------------------------------------
1736 void WidgetShowNPoints::OnSaveCollections_( std::string filename )
1737 {
1738     FILE *ff;
1739     ff = fopen( filename.c_str() , "w+" );
1740     if (ff!=NULL)
1741     {
1742         int i,size = lstModelShowNPoints.size();
1743         fprintf(ff,"NumberOfGroups %d \n",size);
1744         for (i=0 ; i<size ; i++)
1745         {
1746             lstModelShowNPoints[i]->SavePoints_(ff);
1747         } // for i
1748         fclose(ff);
1749     } else {   // else ff
1750         printf("WidgetShowNPoints::Save Groups Points  ...Error... creating file \n");
1751     } //ff
1752
1753 }
1754
1755
1756 //------------------------------------------------------------------------
1757 void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event)
1758 {
1759     //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1760     #if wxMAJOR_VERSION <= 2
1761             wxFileDialog* FD = new wxFileDialog( 0,
1762                                                 _T("Save groups of points .."),
1763                                                 _T(""),
1764                                                 _T(""),
1765                                                 _T("(*.xls)|*.xls"),
1766                                                 wxSAVE | wxOVERWRITE_PROMPT,
1767                                                 wxDefaultPosition);
1768     #else
1769             wxFileDialog* FD = new wxFileDialog( 0,
1770                                                 _T("Save groups of points .."),
1771                                                 _T(""),
1772                                                 _T(""),
1773                                                 _T("(*.xls)|*.xls"),
1774                                                 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
1775                                                 wxDefaultPosition);
1776     #endif
1777
1778             int result_FD = FD->ShowModal();
1779             // This line is need it by windows //EED
1780             FD->SetReturnCode( result_FD );
1781             if (FD->GetReturnCode()==wxID_OK)
1782             {
1783                 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1784                 OnSaveCollections_( filename );
1785             }     // dialog box
1786     StopTrackPoint();
1787 }
1788
1789 //------------------------------------------------------------------------
1790 void WidgetShowNPoints::OnLoadCollections_( std::string filename )
1791 {
1792     bool okEraseFirstGroup=false;
1793     if (lstModelShowNPoints.size()==1)
1794     {
1795         if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGroup=true; }
1796     }
1797     FILE *ff = fopen( filename.c_str() , "r+" );
1798     if (ff!=NULL)
1799     {
1800         int i;
1801         int iGroup,sizeGroups;
1802         int iPoint,numberPointsRead;
1803         char chartmp[256];
1804         fscanf(ff," %s %d",chartmp,&sizeGroups);
1805         for (iGroup=0;iGroup<sizeGroups;iGroup++)
1806         {
1807             mActualCollection = lstModelShowNPoints.size();
1808             InsertCollection();
1809             int numberPointsRead= lstModelShowNPoints[mActualCollection]->ReadPoints_(ff);
1810             for (i=0;i<numberPointsRead;i++)
1811             {
1812                 // EED 2022-05-19
1813                 //AddVtkPoint();
1814                 GetViewShowNPoints()->AddVtkPoint();
1815             }// for
1816         } // for i
1817
1818         fclose(ff);
1819     } else {   // else ff
1820         printf("WidgetShowNPoints::Load Group of Points  ...Error... reading file");
1821     } //ff
1822     if (okEraseFirstGroup==true)
1823     {
1824         mActualCollection=0;
1825         DeleteCollection_();
1826         mActualCollection = lstModelShowNPoints.size()-1;
1827     }
1828     GetViewShowNPoints()->Render();
1829     RefreshCollectionText();
1830     RefreshColourCollection();
1831     StopTrackPoint();
1832 }
1833
1834 //------------------------------------------------------------------------
1835 void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
1836 {
1837     //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1838     #if wxMAJOR_VERSION <= 2
1839             wxFileDialog* FD = new wxFileDialog( 0,
1840                                                  _T("Load groups of points .."),
1841                                                  _T(""),
1842                                                  _T(""),
1843                                                  _T("(*.xls)|*.xls"),
1844                                                  wxOPEN | wxFILE_MUST_EXIST,
1845                                                  wxDefaultPosition);
1846     #else
1847             wxFileDialog* FD = new wxFileDialog( 0,
1848                                                  _T("Load groups of points .."),
1849                                                  _T(""),
1850                                                  _T(""),
1851                                                  _T("(*.xls)|*.xls"),
1852                                                  wxFD_OPEN | wxFD_FILE_MUST_EXIST,
1853                                                  wxDefaultPosition);
1854     #endif
1855             int result_FD = FD->ShowModal();
1856             // This line is need it by windows //EED
1857             FD->SetReturnCode( result_FD );
1858             if (FD->GetReturnCode()==wxID_OK)
1859             {
1860                 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1861                 OnLoadCollections_( filename );
1862                 UndoRedo_SaveCollection();
1863             }     // dialog box
1864 }
1865
1866 //------------------------------------------------------------------------
1867 void WidgetShowNPoints::GetCollectionPoint(int idCol,int idPoint, double *pPoint)
1868 {
1869     double x,y,z;
1870     lstModelShowNPoints[idCol]->GetIdPoint(idPoint,&x,&y,&z);
1871     pPoint[0] = x;
1872     pPoint[1] = y;
1873     pPoint[2] = z;
1874 }
1875 //------------------------------------------------------------------------
1876 void WidgetShowNPoints::SetCollectionPoint(int idCol, int idPoint, std::vector<double> modPoint)
1877 {
1878         if(idCol >= 0 && idCol < lstModelShowNPoints.size())
1879         {
1880                 lstModelShowNPoints[idCol]->SetPointById(idPoint, modPoint);
1881                 lstViewShowNPoints[idCol]->RefreshPoint(idPoint);
1882         }
1883         else{
1884                 printf("WidgetShowNPoints::SetCollectionPoint  ...Error... Invalid collection, out of range");
1885         }
1886 }
1887 //------------------------------------------------------------------------
1888 std::vector<double> WidgetShowNPoints::GetLstPointsX()
1889 {
1890     if (mtype!=4)
1891     {
1892         return GetModelShowNPoints()->GetLstPointsX();
1893     } else {
1894         std::vector<double> lst;
1895         int iP,s;
1896         int iG,sG=lstModelShowNPoints.size();
1897         for (iG=0 ; iG<sG ; iG++)
1898         {
1899             std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsX();
1900             s = lstTmp.size();
1901             for (iP=0 ; iP<s ; iP++)
1902             {
1903                 lst.push_back( lstTmp[iP] );
1904             } // for iP
1905         } // for iG
1906         return lst;
1907     } // if 4
1908 }
1909
1910 //------------------------------------------------------------------------
1911 std::vector<double> WidgetShowNPoints::GetLstPointsY()
1912 {
1913     if (mtype!=4)
1914     {
1915         return GetModelShowNPoints()->GetLstPointsY();
1916     } else {
1917         std::vector<double> lst;
1918         int iP,s;
1919         int iG,sG=lstModelShowNPoints.size();
1920         for (iG=0 ; iG<sG ; iG++)
1921         {
1922             std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsY();
1923             s = lstTmp.size();
1924             for (iP=0 ; iP<s ; iP++)
1925             {
1926                 lst.push_back( lstTmp[iP] );
1927             } // for iP
1928         } // for iG
1929         return lst;
1930     }
1931 }
1932
1933 //------------------------------------------------------------------------
1934 std::vector<double> WidgetShowNPoints::GetLstPointsZ()
1935 {
1936     if (mtype!=4)
1937     {
1938         return GetModelShowNPoints()->GetLstPointsZ();
1939     } else {
1940         std::vector<double> lst;
1941         int iP,s;
1942         int iG,sG=lstModelShowNPoints.size();
1943         for (iG=0 ; iG<sG ; iG++)
1944         {
1945             std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsZ();
1946             s = lstTmp.size();
1947             for (iP=0 ; iP<s ; iP++)
1948             {
1949                 lst.push_back( lstTmp[iP] );
1950             } // for iP
1951         } // for iG
1952         return lst;
1953
1954     }
1955 }
1956
1957 //------------------------------------------------------------------------
1958 std::vector<std::string> WidgetShowNPoints::GetLstLabels()
1959 {
1960     if (mtype!=4)
1961     {
1962         return GetModelShowNPoints()->GetLstLabels();
1963     } else {
1964         std::vector< std::string > lst;
1965         int iP,s;
1966         int iG,sG=lstModelShowNPoints.size();
1967         for (iG=0 ; iG<sG ; iG++)
1968         {
1969             std::vector< std::string > lstTmp = lstModelShowNPoints[iG]->GetLstLabels();
1970             s = lstTmp.size();
1971             for (iP=0 ; iP<s ; iP++)
1972             {
1973                 lst.push_back( lstTmp[iP] );
1974             } // for iP
1975         } // for iG
1976         return lst;
1977     }
1978 }
1979
1980 //------------------------------------------------------------------------
1981 std::vector<int> WidgetShowNPoints::GetLstIndexs()
1982 {
1983     std::vector<int> lstIndexs;
1984     if (mtype!=4)
1985     {
1986         lstIndexs.push_back( GetModelShowNPoints()->GetLstPointsSize() );
1987     } else {
1988         int iG,sG=lstModelShowNPoints.size();
1989         for (iG=0 ; iG<sG ; iG++)
1990         {
1991             lstIndexs.push_back( lstModelShowNPoints[iG]->GetLstPointsSize() );
1992         } // for iG
1993     }
1994     return lstIndexs;
1995 }
1996
1997 //------------------------------------------------------------------------
1998 std::vector<int> WidgetShowNPoints::GetLstSelectedIndexs()
1999 {
2000     std::vector<int> lstSelectedIndexs;
2001     if ( (cbVisuActualCollection!=NULL) && (cbVisuActualCollection->GetValue()==true) )
2002     {
2003         lstSelectedIndexs.push_back( mActualCollection );
2004     }
2005     return lstSelectedIndexs;
2006 }
2007
2008 //------------------------------------------------------------------------
2009 int WidgetShowNPoints::GetLstModelShowNPointsSize()
2010 {
2011     return lstModelShowNPoints.size();
2012 }
2013
2014 //------------------------------------------------------------------------
2015 void WidgetShowNPoints::InvertLstPoints_()
2016 {
2017     int i,size=lstModelShowNPoints.size();
2018     
2019     for (i=0 ;  i < size ; i++)
2020     {
2021         lstModelShowNPoints[i]->InversLstPoints();
2022     } // for iM
2023      
2024     /*
2025     ModelShowNPoints* tmpModel;
2026     int size2=size/2;
2027     for (i=0 ;  i < size2 ; i++)
2028     {
2029         tmpModel                        = lstModelShowNPoints[i];
2030         lstModelShowNPoints[i]          = lstModelShowNPoints[size-1-i];
2031         lstModelShowNPoints[size-1-i]   = tmpModel;
2032     } // for iM
2033      */
2034 }
2035
2036 //------------------------------------------------------------------------
2037 void WidgetShowNPoints::OnInvertLstPoints_()
2038 {
2039     StopAutoAddPoints();
2040     StopTrackPoint();
2041     InvertLstPoints_();
2042     SetOutputBox();
2043     UndoRedo_SaveCollection();
2044 }
2045
2046
2047 //------------------------------------------------------------------------
2048 std::string WidgetShowNPoints::GetUndoRedoFileName()
2049 {
2050     char buff[20];
2051     sprintf(buff,"%p_%d",this, idUndoRedo);
2052     return  UndoRedoDir+"/"+"UndoRedo_collection_" + std::string(buff) + ".undoredo";
2053 }
2054
2055
2056 //------------------------------------------------------------------------
2057 void WidgetShowNPoints::OnUndo(wxCommandEvent &event)
2058 {
2059     ResetCollections_();
2060 //    if (idUndoRedo==maxUndoRedo+1)
2061 //    {
2062 //       idUndoRedo--;
2063 //    } // if idUndoRedo+1
2064     idUndoRedo--;
2065     idUndoRedo--;
2066     if (idUndoRedo<0)
2067     {
2068         idUndoRedo=-1;
2069     } else {
2070         OnLoadCollections_( GetUndoRedoFileName() );
2071     }// if idUndoRedo
2072     idUndoRedo++;
2073
2074 }
2075
2076 //------------------------------------------------------------------------
2077 void WidgetShowNPoints::OnRedo(wxCommandEvent &event)
2078 {
2079     if (idUndoRedo>maxUndoRedo)
2080     {
2081         idUndoRedo=maxUndoRedo+1;
2082     } else {
2083         ResetCollections_();
2084         OnLoadCollections_( GetUndoRedoFileName() );
2085         idUndoRedo++;
2086     }// if idUndoRedo
2087 }
2088
2089 //------------------------------------------------------------------------
2090 void WidgetShowNPoints::UndoRedo_SaveCollection()
2091 {
2092     OnSaveCollections_( GetUndoRedoFileName() );
2093     maxUndoRedo = idUndoRedo;
2094     idUndoRedo++;
2095 }
2096
2097 //------------------------------------------------------------------------
2098 void WidgetShowNPoints::SetAuxMesh(vtkPolyData* mesh, std::vector<double> spc, std::vector<double> params)
2099 {
2100     aux_mesh        = mesh;
2101     aux_mesh_spc    = spc;
2102     if (params.size()==1)
2103     {
2104         aux_mesh_type   = params[0];
2105     } else {
2106         aux_mesh_type   = 0;
2107     }// if params size
2108 }
2109
2110 //------------------------------------------------------------------------
2111 void WidgetShowNPoints::OnVisuActualCollection(wxCommandEvent &event)
2112 {
2113     printf("EED WidgetShowNPoints::OnVisuActualCollection  \n");
2114     RefreshCollectionText();
2115     RefreshColourCollection();
2116 }