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