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