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