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