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