]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
#3485 ShowNPionts for Multiple Groups
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / WidgetShowNPoints.cxx
1
2
3 #include "vtkSphereSource.h"
4 #include "vtkRenderer.h"
5 #include "vtkTextActor3D.h"
6
7
8
9 #include <wx/button.h>
10 #include <wx/sizer.h>
11 #include <wx/filedlg.h>
12 #include <wx/msgdlg.h>
13 #include <wx/notebook.h>
14
15 #include "WidgetShowNPoints.h"
16
17
18 //----------------------------------------------------------------------
19 //----------------------------------------------------------------------
20 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
24     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
25   {
26     printf("EED WidgetShowNPoints::WidgetShowNPoints Start \n");
27         // EED 2022-05-19
28     //  mmodelShowNPoints                                = new ModelShowNPoints();
29                         mActualCollection= 0;
30     ModelShowNPoints*   modelShowNPoints = new ModelShowNPoints();
31     lstModelShowNPoints.push_back( modelShowNPoints );
32     lstViewShowNPoints.push_back( new  ViewShowNPoints( modelShowNPoints ) );
33       
34     mtype                                                       = type;
35     SetType(mtype);
36     wxPanel*    panelParent         = this;
37     wxSizer*    sizer                           = NULL;
38     wxSizer*    MNPsizer            = NULL;
39
40     wxNotebook* bookSetPoints       = NULL;
41     wxNotebook* bookGroupManager    = NULL;
42     wxPanel*    panel               = NULL;
43     wxPanel*    panel2              = NULL;
44
45       bookSetPoints     = new wxNotebook(panelParent,
46                           -1,
47                           wxDefaultPosition,
48                           wxDefaultSize,
49                           wxNB_TOP );
50       panel  = new wxPanel(bookSetPoints);
51
52
53     // Group Manager
54     if (mtype==4)
55     {
56           bookGroupManager   = new wxNotebook(panelParent, //bbGetWxParent(),
57                               -1,
58                               wxDefaultPosition,
59                               wxDefaultSize,
60                               wxNB_TOP );
61           panel2  = new wxPanel(bookGroupManager);
62           txtNrCollections                      = new wxStaticText(panel2,-1, _T("1   /  1 "));
63           wxButton *btnBackCollection           = new wxButton( panel2, -1, _T("<"));
64           wxButton *btnNextCollection           = new wxButton( panel2, -1, _T(">"));
65           wxButton *btnInsertCollectionBefore   = new wxButton( panel2, -1, _T("Insert Group Before"));
66           wxButton *btnInsertCollectionAfter    = new wxButton( panel2, -1, _T("Insert Group After"));
67           wxButton *btnDeleteCollection         = new wxButton( panel2, -1, _T("Delete Group "));
68           wxButton *btnSaveCollection           = new wxButton( panel2, -1, _T("Save Groups"));
69           wxButton *btnLoadCollection           = new wxButton( panel2, -1, _T("Load Groups"));
70
71           wxFlexGridSizer *sizer1               = new wxFlexGridSizer(1);
72           wxFlexGridSizer *sizer2               = new wxFlexGridSizer(2);
73           wxStaticText* txOpacity               = new wxStaticText(panel2, -1, wxString(_T("  Points Opacity  ")));
74           sdrOpacity                            = new wxSlider(panel2, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
75           wxStaticText* txRadio                 = new wxStaticText(panel2, -1, wxString(_T("  Points Radius  ")));
76           sdrRadio                              = new wxSlider(panel2, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
77
78           Connect(btnBackCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnBackCollection           );
79           Connect(btnNextCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnNextCollection           );
80           Connect(btnInsertCollectionBefore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionBefore   );
81           Connect(btnInsertCollectionAfter->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionAfter    );
82           Connect(btnDeleteCollection->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteCollection         );
83           Connect(sdrOpacity->GetId()               , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints                );
84           Connect(sdrRadio->GetId()                 , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints                );
85           Connect(btnSaveCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnSaveCollections          );
86           Connect(btnLoadCollection->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnLoadCollections          );
87
88         
89           sizer2->Add( btnBackCollection );
90           sizer2->Add( btnNextCollection );
91
92           sizer1->Add( txtNrCollections );
93           sizer1->Add( sizer2 );
94           sizer1->Add( btnInsertCollectionBefore );
95           sizer1->Add( btnInsertCollectionAfter );
96           sizer1->Add( btnDeleteCollection );
97         
98           sizer1->Add( txOpacity );
99           sizer1->Add( sdrOpacity );
100           sizer1->Add( txRadio );
101           sizer1->Add( sdrRadio );
102
103           sizer1->Add( btnSaveCollection );
104           sizer1->Add( btnLoadCollection );
105           MNPsizer                        = sizer1;
106           panel2->SetSizer( MNPsizer );
107           panel2->SetAutoLayout(true);
108           panel2->Layout();
109           bookGroupManager->AddPage(panel2 , _T("Groupts") );
110     } // if mtype 4
111
112         if ( (mtype==0) || (mtype==3) || (mtype==4) )
113         {
114                 // Widget interface
115                 askPointLabel                                   = new wxStaticText(panel, -1, _T("Point label :")); // JPR
116                 textCtrl                                                = new wxTextCtrl(panel, -1);
117                 wxButton    *btnAddPoint                = new wxButton( panel, -1, _T("Add Point"));
118                 wxButton    *btnInsertPoint             = new wxButton( panel, -1, _T("Insert Point"));//CFT
119                 wxButton    *btnSetPositionPoint= new wxButton( panel, -1, _T("Set nearest point"));
120                      cbTrackPoint       = new wxCheckBox(panel,-1, _T("Track Point") );
121         wxButton    *btnRenamePoint             = new wxButton( panel, -1, _T("Rename point"));
122                 wxButton    *btnEraseLastPoint  = new wxButton( panel, -1, _T("Erase Last point"));
123                 wxButton    *btnErasePoint              = new wxButton( panel, -1, _T("Erase point"));
124                 wxButton    *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
125                 wxButton    *btnSavePoints              = NULL;
126                 wxButton    *btnLoadPoints              = NULL;
127                 if ( mtype==0 )
128                 {
129                         btnSavePoints                           = new wxButton( panel, -1, _T("Save points"));
130                         btnLoadPoints                           = new wxButton( panel, -1, _T("Load points"));
131             Connect(btnSavePoints->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
132             Connect(btnLoadPoints->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
133                 } // if mtype
134                 txtNrPoints                                             = new wxStaticText(panel,-1, _T(" "));
135
136         wxStaticText* txOpacity;
137         wxStaticText* txRadio;
138         if ( (mtype==0) || (mtype==3) )
139         {
140             //NTU: Sliders for opacity and radio change
141             txOpacity         = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
142             sdrOpacity        = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
143             txRadio           = new wxStaticText(panel, -1, wxString(_T("  Points Radius  ")));
144             sdrRadio          = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
145             //NTU: Slider events
146             Connect(sdrOpacity->GetId()            , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
147             Connect(sdrRadio->GetId()            , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
148         } // if mtype 0 3
149
150                 Connect(btnAddPoint->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
151                 Connect(btnInsertPoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
152                 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
153                 Connect(btnRenamePoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
154                 Connect(btnEraseLastPoint->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
155                 Connect(btnErasePoint->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
156                 Connect(btnDeleteAllPoints->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
157         Connect(cbTrackPoint->GetId()       , wxEVT_CHECKBOX  , (wxObjectEventFunction) &WidgetShowNPoints::OnTrackPoint);
158
159
160         wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
161                 sizer1->Add(askPointLabel); // JPR
162                 sizer1->Add(textCtrl);
163                 sizer1->Add(btnAddPoint);
164                 sizer1->Add(btnInsertPoint);//CFT
165         sizer1->Add(cbTrackPoint);
166                 sizer1->Add(btnSetPositionPoint);
167                 sizer1->Add(btnRenamePoint);
168                 sizer1->Add(btnErasePoint);
169                 sizer1->Add(btnEraseLastPoint);
170                 sizer1->Add(btnDeleteAllPoints);
171                 sizer1->Add(txtNrPoints);
172         
173         if ( (mtype==0) || (mtype==3) )
174         {
175             sizer1->Add(txOpacity);
176             sizer1->Add(sdrOpacity,1,wxGROW );
177             sizer1->Add(txRadio);
178             sizer1->Add(sdrRadio,1,wxGROW );
179         }  // if mtype 0 3
180         if ( mtype==0 )
181                 {
182                         sizer1->Add(btnSavePoints);
183                         sizer1->Add(btnLoadPoints);
184                 } // if mtype 0
185                 sizer = sizer1;
186         }
187
188           if (mtype==1)
189           {
190                   // Widget interface
191                   wxButton *btnSetPositionPoint         = new wxButton( panel, -1, _T("Set nearest point"));
192                   txtNrPoints                                           = new wxStaticText(panel,-1, _T(" "));
193
194                   //NTU: Sliders for opacity and radio change
195                   wxStaticText* txOpacity                       = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
196                   sdrOpacity                                            = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
197                   wxStaticText* txRadio                         = new wxStaticText(panel, -1, wxString(_T("  Points Radio  ")));
198                   sdrRadio                                                      = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
199                   Connect(btnSetPositionPoint->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
200                   Connect(sdrOpacity->GetId()   , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
201                   Connect(sdrRadio->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
202
203           wxFlexGridSizer *sizer1            = new wxFlexGridSizer(1);
204                   sizer1->Add(btnSetPositionPoint);
205                   sizer1->Add(txtNrPoints);
206                   sizer1->Add(txOpacity);
207                   sizer1->Add(sdrOpacity,1,wxGROW );
208                   sizer1->Add(txRadio);
209                   sizer1->Add(sdrRadio,1,wxGROW );
210                   sizer = sizer1;
211           }
212     
213     if (mtype == 2) 
214         {
215                 askPointLabel                                           = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
216         wxButton                *btnAddPoint            = new wxButton(panel, -1,        _T("      Add  Point      "));
217         wxButton                *btnDeleteAllPoints = new wxButton(panel, -1, _T("      Delete All      "));
218         wxStaticText    *spacer                         = new wxStaticText(panel, -1, _T("\n")); // JPR
219                                          textCtrl                       = new wxTextCtrl(panel, -1);
220         Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
221         Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);    
222         wxFlexGridSizer *sizer1             = new wxFlexGridSizer(1);
223         sizer1->Add(askPointLabel);
224         sizer1->Add(btnAddPoint);
225         sizer1->Add(btnDeleteAllPoints);
226         sizer1->Add(spacer);
227         sizer1->Add(textCtrl);
228       //  sdrOpacity                          = new wxSlider();
229       //  sdrRadio                            = new wxSlider();
230         txtNrPoints                         = new wxStaticText(panel, -1, _T("\n\n\n"));
231         sizer                               = sizer1;
232         } // bbGetInputType 2
233
234             
235       panel->SetSizer(sizer);
236       panel->SetAutoLayout(true);
237       panel->Layout();
238       bookSetPoints->AddPage(panel , _T("Points") );
239
240     if ((mtype >= 0) && (mtype <= 3) )
241     {
242         if (sizer!=NULL)
243         {
244             wxFlexGridSizer *sizerParent             = new wxFlexGridSizer(1);
245             sizerParent->Add( bookSetPoints );
246             panelParent->SetSizer( sizerParent );
247             panelParent->SetAutoLayout(true);
248             panelParent->Layout();
249         } // if sizer
250     } // if  mtype 0 1 2 3
251       
252     if (mtype == 4)
253     {
254         if ((sizer!=NULL) && (MNPsizer!=NULL))
255         {
256             wxFlexGridSizer *sizerG             = new wxFlexGridSizer(2);
257             sizerG->Add(bookGroupManager);
258             sizerG->Add(bookSetPoints);
259             panelParent->SetSizer(sizerG);
260             panelParent->SetAutoLayout(true);
261             panelParent->Layout();
262         } // if sizer
263     } // if mtype 4
264 }
265
266 //------------------------------------------------------------------------
267 WidgetShowNPoints::~WidgetShowNPoints()
268 {
269 }
270
271 //------------------------------------------------------------------------
272 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
273 {
274     // EED 2022-05-19
275     // return mmodelShowNPoints;
276     return lstModelShowNPoints[ mActualCollection ];
277 }
278
279 // EED 2022-05-19
280 //------------------------------------------------------------------------
281 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
282 {
283     return lstViewShowNPoints[ mActualCollection ];
284 }
285
286
287 //------------------------------------------------------------------------
288 void WidgetShowNPoints::SetRadio(double radio)
289 {
290     // EED 2022-05-19
291     // GetModelShowNPoints()->SetRadio(radio);
292     int i,size = lstModelShowNPoints.size();
293     for (i=0;i<size;i++)
294     {
295         lstModelShowNPoints[i]->SetRadio( radio );
296     } // for i
297         //NTU: For Slider
298         sdrRadio->SetValue(radio);
299 }
300
301 //------------------------------------------------------------------------
302 void WidgetShowNPoints::SetColour(std::vector<double> colour)
303 {
304     // EED 2022-05-19
305     //this->mcolour = colour;
306     int i,size = lstViewShowNPoints.size();
307     for (i=0 ; i<size ; i++)
308     {
309         lstViewShowNPoints[i]->mcolour = colour;
310     } // for i
311 }
312
313 //------------------------------------------------------------------------
314 void WidgetShowNPoints::SetImage(vtkImageData* image)
315 {
316     // EED 2022-05-19
317         //GetModelShowNPoints()->SetImage(image);
318     int i,size = lstModelShowNPoints.size();
319     for (i=0 ; i<size ; i++)
320     {
321         lstModelShowNPoints[i]->SetImage(image);
322     } // for i
323 }
324
325 //------------------------------------------------------------------------
326 void WidgetShowNPoints::SetOpacity(double opacity)
327 {
328     // EED 2022-05-19
329         //this->mopacity=opacity;
330     int i,size = lstViewShowNPoints.size();
331     for (i=0 ; i<size ; i++)
332     {
333         lstViewShowNPoints[i]->mopacity = opacity;
334     } // for i
335         //NTU: For Slider
336         sdrOpacity->SetValue( opacity*100.0 );
337 }
338
339
340 //------------------------------------------------------------------------
341 void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
342 {
343     // EED 2022-05-19
344         //this->renderer        = renderer;
345     int i,size = lstViewShowNPoints.size();
346     for (i=0 ; i<size ; i++)
347     {
348         lstViewShowNPoints[i]->renderer = renderer;
349     } // for i
350 }
351
352 /* EED 2022-05-19
353 //------------------------------------------------------------------------
354         
355 void WidgetShowNPoints::RefreshPoint(int id)
356 {
357         double spc[3];
358         int x,y,z;
359         GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
360         GetModelShowNPoints()->GetImage()->GetSpacing(spc);
361         std::string label       = GetModelShowNPoints()->GetIdLabel(id);
362         double radio            = GetModelShowNPoints()->GetRadio();
363     lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
364     lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
365     lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
366     lstSourceSphere[id]->SetRadius( radio );
367 //EED 2017-01-01 Migration VTK7
368 #if VTK_MAJOR_VERSION <= 5
369         // ..
370 #else
371     lstSourceSphere[id]->Update();
372 #endif
373     lstActorsText[id]->SetInput( label.c_str()  );
374     lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
375 }
376
377 //------------------------------------------------------------------------
378 void WidgetShowNPoints::RefreshPoints()
379 {
380         int id,size=lstActorsSphere.size();
381         for (id=0;id<size;id++)
382         {
383                 RefreshPoint(id);
384         } // for
385         renderer->GetRenderWindow()->Render();
386 }
387
388 //------------------------------------------------------------------------
389 void WidgetShowNPoints::AddVtkPoint()
390 {
391         // Sphere
392         vtkSphereSource *vtksphere = vtkSphereSource::New();
393         vtksphere->SetThetaResolution (20);
394         vtksphere->SetPhiResolution (20);
395         vtksphere->SetRadius( 1 );
396         //NTU: For updating points
397         lstSourceSphere.push_back(vtksphere);
398         vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
399
400 //EED 2017-01-01 Migration VTK7
401 #if VTK_MAJOR_VERSION <= 5
402         sphereMapper->SetInput( vtksphere->GetOutput() );
403 #else
404         vtksphere->Update();
405         sphereMapper->SetInputData( vtksphere->GetOutput() );
406 #endif
407
408         vtkActor *sphereActor   = vtkActor::New();
409         sphereActor->SetMapper(sphereMapper);
410         sphereActor->SetOrigin(0, 0, 0);
411
412         lstActorsSphere.push_back(sphereActor);
413         if(renderer==NULL){
414                 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
415                 dialog.ShowModal();             
416                 return;
417         }
418         renderer->AddActor( sphereActor );
419         // Actor
420         vtkTextActor3D *textActor = vtkTextActor3D::New();
421 //      textActor->SetInput( strLabel.c_str()  );
422         renderer->AddActor( textActor );
423         lstActorsText.push_back(textActor);
424 }
425  */
426
427
428 //------------------------------------------------------------------------
429 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
430 {
431         GetModelShowNPoints()->AddPoint(x,y,z, label );
432     // EED 2022-05-19
433     //AddVtkPoint();
434     //RefreshPoint(lstActorsSphere.size()-1);
435     GetViewShowNPoints()->AddPoint();
436 }
437
438 //------------------------------------------------------------------------
439 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
440 {
441     // EED 2022-05-19
442         //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
443         //{
444     //    AddVtkPoint();
445         //} else {
446         //      AddPoint(x,y,z,label);
447         //}
448         //RefreshPoints();
449     if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
450     {
451         GetViewShowNPoints()->AddVtkPoint();
452     } else {
453         AddPoint(x,y,z,label);
454     }
455     GetViewShowNPoints()->RefreshPoints();
456 }
457
458 //------------------------------------------------------------------------
459 void WidgetShowNPoints::OnInsertPoint_()
460 {
461     // EED 2022-05-19
462     //if (this->renderer==NULL)
463     if (GetViewShowNPoints()->renderer==NULL)
464     {
465         return;
466     }
467
468     std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
469     if (point.size()==3)
470     {
471         InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
472         SetOutputBox();
473     } else {//mpoint.size
474         printf("creaMaracasVisu::ShowNPoints (not match point) \n");
475     }
476 }
477
478
479
480 //------------------------------------------------------------------------
481 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
482 {       
483     // EED 2022-05-19
484         //if (this->renderer==NULL)
485     if (GetViewShowNPoints()->renderer==NULL)
486         {
487                 return;
488         }
489
490         std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
491         if (point.size()==3)
492         {
493                 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
494                 SetOutputBox();
495         // EED 2022-05-19
496         //renderer->GetRenderWindow()->Render();
497         GetViewShowNPoints()->Render();
498         } else {//mpoint.size
499                 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
500         }
501 }
502
503 //------------------------------------------------------------------------
504 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
505 {
506     OnInsertPoint_();
507 }
508
509
510 //------------------------------------------------------------------------
511         void WidgetShowNPoints::SetOutputBox()
512         {
513 //EED           renderer->GetRenderWindow()->Render();
514                 wxString strTmp;
515                 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
516                 txtNrPoints->SetLabel( strTmp );
517                 //--BBTK
518
519 //EED 2017-06-03
520 //              mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
521 //              mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
522 //              mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
523 //              mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
524 //              mbbShowNPoints->bbSignalOutputModification();
525         }
526
527
528 //------------------------------------------------------------------------
529         void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
530         {
531
532 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
533 #if wxMAJOR_VERSION <= 2
534                 wxFileDialog* FD = new wxFileDialog( 0,
535                                             _T("Save points .."),
536                                             _T(""),
537                                             _T(""),
538                                             _T("(*.xls)|*.xls"),
539                                             wxSAVE | wxOVERWRITE_PROMPT,
540                                             wxDefaultPosition);
541 #else
542                 wxFileDialog* FD = new wxFileDialog( 0,
543                                             _T("Save points .."),
544                                             _T(""),
545                                             _T(""),
546                                             _T("(*.xls)|*.xls"),
547                                             wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
548                                             wxDefaultPosition);
549 #endif
550
551                 int result_FD = FD->ShowModal();
552                 // This line is need it by windows //EED
553                 FD->SetReturnCode( result_FD );
554                 if (FD->GetReturnCode()==wxID_OK)
555                 {
556                         std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
557                         GetModelShowNPoints()->SavePoints( filename );
558                 }       // dialog box
559         }
560
561
562 //------------------------------------------------------------------------
563         void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
564         {
565
566 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
567 #if wxMAJOR_VERSION <= 2
568                 wxFileDialog* FD = new wxFileDialog( 0,
569                                              _T("Load points .."),
570                                              _T(""),
571                                              _T(""),
572                                              _T("(*.xls)|*.xls"),
573                                              wxOPEN | wxFILE_MUST_EXIST,
574                                              wxDefaultPosition);
575 #else
576                 wxFileDialog* FD = new wxFileDialog( 0,
577                                              _T("Load points .."),
578                                              _T(""),
579                                              _T(""),
580                                              _T("(*.xls)|*.xls"),
581                                              wxFD_OPEN | wxFD_FILE_MUST_EXIST,
582                                              wxDefaultPosition);
583 #endif
584                 int i;
585                 //EED
586                 int result_FD = FD->ShowModal();
587                 // This line is need it by windows //EED
588                 FD->SetReturnCode( result_FD );
589                 if (FD->GetReturnCode()==wxID_OK)
590                 {
591
592                         std::string filename= (const char*) ( FD->GetPath().mb_str() ); 
593                         int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
594                         for (i=0;i<numberPointsRead;i++)
595                         {
596                 // EED 2022-05-19
597                 //AddVtkPoint();
598                 GetViewShowNPoints()->AddVtkPoint();
599                         }// for
600                         SetOutputBox();
601             // EED 2022-05-19
602                         //RefreshPoints();
603             GetViewShowNPoints()->RefreshPoints();
604                 }       // dialog box
605         }
606
607 //------------------------------------------------------------------------
608 void WidgetShowNPoints::OnSetPoint_()
609 {
610     int id=GetModelShowNPoints()->GetNearestPoint();
611     if((id==-1) && (mtype==1))
612     {
613         id=0;
614         AddPoint(0,0,0,"");
615         SetOutputBox();
616     }
617     if (id>=0)
618     {
619         GetModelShowNPoints()->SetPointId_mReferencePoint(id);
620         // EED 2022-05-19
621         //RefreshPoint(id);
622         //renderer->GetRenderWindow()->Render();
623         GetViewShowNPoints()->RefreshPoint(id);
624         GetViewShowNPoints()->Render();
625     } // if id
626     SetOutputBox();
627 }
628
629 //------------------------------------------------------------------------
630 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
631 {
632     OnSetPoint_();
633 }
634
635 //------------------------------------------------------------------------
636 void WidgetShowNPoints::TrackingPoint( )
637 {
638     if ( cbTrackPoint->GetValue() == true )
639     {
640         int id = GetModelShowNPoints()->IdInsidePoint();
641         if (id>=0)
642         {
643             idTrack=id;
644         }
645         
646         if (idTrack>=0)
647         {
648             GetModelShowNPoints()->SetPointId_mReferencePoint(idTrack);
649             GetViewShowNPoints()->RefreshPoint(idTrack);
650             GetViewShowNPoints()->Render();
651         } // if id
652     } // if trackPointFlag
653 }
654
655 //------------------------------------------------------------------------
656 void WidgetShowNPoints::OnTrackPoint_tool()
657 {
658     cbTrackPoint->SetValue( !cbTrackPoint->GetValue() );
659     OnTrackPoint_();
660 }
661
662 //------------------------------------------------------------------------
663 void WidgetShowNPoints::OnTrackPoint_()
664 {
665     idTrack         =   -1;
666     if ( cbTrackPoint->GetValue() == true )
667     {
668         idTrack = GetModelShowNPoints()->IdInsidePoint();
669     } // if trackPointFlag
670 }
671
672 //------------------------------------------------------------------------
673 void WidgetShowNPoints::OnTrackPoint(wxCommandEvent& event)
674 {
675     OnTrackPoint_();
676 }
677
678 //------------------------------------------------------------------------
679 void WidgetShowNPoints::StopTrackPoint( )
680 {
681     cbTrackPoint->SetValue(false);
682     idTrack=-1;
683 }
684
685 //------------------------------------------------------------------------
686         void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
687         {
688                 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
689                 if (id>=0)
690                 {
691             // EED 2022-05-19
692                         //lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
693                         //renderer->GetRenderWindow()->Render();
694             GetViewShowNPoints()->lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
695             GetViewShowNPoints()->Render();
696             SetOutputBox();
697                 }
698         }
699
700 //------------------------------------------------------------------------
701         void WidgetShowNPoints::ErasePoint(int id)
702         {
703         // EED 2022-05-19
704                 //if (this->renderer!=NULL)
705         if (GetViewShowNPoints()->renderer!=NULL)
706                 {
707                         if (id>=0)
708                         {
709                 // EED 2022-05-19
710                                 //renderer->RemoveActor( lstActorsSphere[id] );
711                                 //renderer->RemoveActor( lstActorsText[id] );
712                                 //lstActorsSphere[id]->Delete();
713                                 //lstActorsText[id]->Delete();
714                                 //lstSourceSphere[id]->Delete();
715                                 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
716                                 //lstActorsText.erase( lstActorsText.begin()+id );
717                                 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
718                 GetViewShowNPoints()->ErasePoint(id);
719                                 GetModelShowNPoints()->ErasePoint(id);
720                         } // if id
721                 } // if renderer
722         }
723
724 //------------------------------------------------------------------------
725     void WidgetShowNPoints::OnErasePoint_()
726     {
727         ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
728         SetOutputBox();
729         // EED 2022-05-19
730         //renderer->GetRenderWindow()->Render();
731         GetViewShowNPoints()->Render();
732         StopTrackPoint();
733     }
734
735 //------------------------------------------------------------------------
736         void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
737         {
738                 OnErasePoint_();
739         }
740
741 //------------------------------------------------------------------------
742         void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
743         {
744         // EED 2022-05-19
745         //ErasePoint( lstActorsSphere.size()-1 );
746         //renderer->GetRenderWindow()->Render();
747         int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
748         ErasePoint( id );
749         GetViewShowNPoints()->Render();
750         SetOutputBox();
751         StopTrackPoint();
752         }
753
754 //------------------------------------------------------------------------
755 void WidgetShowNPoints::DeleteAllPoints()
756 {
757     // EED 2022-05-19
758     //int id,size=lstActorsSphere.size();
759     int id,size=GetViewShowNPoints()->lstActorsSphere.size();
760     for (id=size-1;id>=0;id--)
761     {
762         ErasePoint(id);
763     }
764     SetOutputBox();
765     // EED 2022-05-19
766     //renderer->GetRenderWindow()->Render();
767     GetViewShowNPoints()->Render();
768 }
769
770
771 //------------------------------------------------------------------------
772 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
773 {
774         DeleteAllPoints();
775 }
776
777 //NTU: Method for updating points opacity and Radio
778
779 //------------------------------------------------------------------------
780 void WidgetShowNPoints::UpdatePoints_()
781 {
782     // EED 2022-05-19
783     //this->mopacity = sdrOpacity->GetValue()/100.0;
784     //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
785     //RefreshPoints();
786
787     double opacity  = sdrOpacity->GetValue()/100.0;
788     double radio    = sdrRadio->GetValue();
789     int i,size      = lstViewShowNPoints.size();
790     for (i=0 ; i<size ; i++)
791     {
792         lstViewShowNPoints[i]->mopacity = opacity;
793         lstModelShowNPoints[i]->SetRadio( radio ) ;
794     } // for i
795 //    GetViewShowNPoints()->RefreshPoints();
796 }
797
798 //------------------------------------------------------------------------
799 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
800 {
801     RefreshColourCollection();
802 }
803
804 //------------------------------------------------------------------------
805 void  WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
806 {
807         GetModelShowNPoints()->SetReferencePoint(point);
808     int i,size=lstModelShowNPoints.size();
809     for (i=0;i<size;i++)
810     {
811         lstModelShowNPoints[i]->SetReferencePoint(point);    // All collection
812     } // for i
813 }
814
815 //------------------------------------------------------------------------
816 void  WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX,  std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
817 {
818     // EED 2022-05-19
819         //if (this->renderer==NULL)
820     if (GetViewShowNPoints()->renderer==NULL)
821         {
822                 return;
823         }
824         int i,sizeX,sizeY,sizeZ,sizeLabels;
825         sizeX = (int)initLstPointsX.size();
826         sizeY = (int)initLstPointsY.size();
827         sizeZ = (int)initLstPointsZ.size();
828         sizeLabels = (int)initLstLabels.size();
829         int x,y,z;
830         std::string label;
831         if ( (sizeX==sizeY) && (sizeX==sizeZ) )
832         {
833                 for (i=0;i<sizeX;i++)
834                 {
835                         x               = initLstPointsX[i];
836                         y               = initLstPointsY[i];
837                         z               = initLstPointsZ[i];
838                         if (i<sizeLabels) 
839                         {
840                                 label   = initLstLabels[i];
841                         } else {
842                                 label="";
843                         }
844                         AddPoint( x,y,z,label );
845                 } // for i
846                 //      SetOutputBox(); 
847                 //      renderer->GetRenderWindow()->Render();
848         } // if size
849 }
850
851 //------------------------------------------------------------------------
852 void WidgetShowNPoints::SetType(int type)
853 {
854         mtype=type;
855 }
856
857 //------------------------------------------------------------------------
858 int WidgetShowNPoints::GetType()
859 {
860         return mtype;
861 }
862
863
864 //------------------------------------------------------------------------
865 double WidgetShowNPoints::GetRadio()
866 {
867         return sdrRadio->GetValue();
868 }
869 //------------------------------------------------------------------------
870 double WidgetShowNPoints::GetOpacity()
871 {
872         return sdrOpacity->GetValue()/100;
873 }
874
875 //------------------------------------------------------------------------
876 void WidgetShowNPoints::InsertCollection()
877 {
878     ModelShowNPoints*   model   = new ModelShowNPoints();
879     ViewShowNPoints*    view    = new ViewShowNPoints( model );
880     model->SetImage( lstModelShowNPoints[0]->GetImage() );
881     view->mopacity = lstViewShowNPoints[0]->mopacity;
882     view->renderer = lstViewShowNPoints[0]->renderer;
883     lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
884     lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
885     RefreshCollectionText();
886 }
887
888 //------------------------------------------------------------------------
889 void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
890 {
891     InsertCollection();
892     RefreshColourCollection();
893     StopTrackPoint();
894 }
895
896 //------------------------------------------------------------------------
897 void WidgetShowNPoints::OnInsertCollectionAfter_()
898 {
899     mActualCollection++;
900     InsertCollection();
901     RefreshColourCollection();
902     StopTrackPoint();
903 }
904
905 //------------------------------------------------------------------------
906 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
907 {
908     OnInsertCollectionAfter_();
909 }
910
911 //------------------------------------------------------------------------
912 void WidgetShowNPoints::DeleteCollection_()
913 {
914     if ( lstModelShowNPoints.size()>1 )
915     {
916         DeleteAllPoints();  // Actual Collection
917         lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
918         lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
919         if ( mActualCollection>=lstModelShowNPoints.size() )
920         {
921             mActualCollection--;
922         } // if
923     } else {
924         DeleteAllPoints();  // Actual Collection
925     } // if
926 }
927
928 //------------------------------------------------------------------------
929 void WidgetShowNPoints::OnDeleteCollection_()
930 {
931     DeleteCollection_();
932     RefreshCollectionText();
933     RefreshColourCollection();
934     StopTrackPoint();
935 }
936
937 //------------------------------------------------------------------------
938 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
939 {
940     OnDeleteCollection_();
941 }
942
943 //------------------------------------------------------------------------
944 void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
945 {
946     mActualCollection--;
947     if ( mActualCollection <0  )
948     {
949         mActualCollection=0;
950     } //if <=0
951     RefreshCollectionText();
952     RefreshColourCollection();
953     StopTrackPoint();
954 }
955
956 //------------------------------------------------------------------------
957 void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
958 {
959     mActualCollection++;
960     if ( mActualCollection >=lstModelShowNPoints.size() )
961     {
962         mActualCollection = lstModelShowNPoints.size()-1;
963     } //if <=0
964     RefreshCollectionText();
965     RefreshColourCollection();
966     StopTrackPoint();
967 }
968
969 //------------------------------------------------------------------------
970 void WidgetShowNPoints::DetectCollectionActive()
971 {
972     int id;
973     int i,size=lstModelShowNPoints.size();
974     for (i=0;i<size;i++)
975     {
976         id = lstModelShowNPoints[i]->IdInsidePoint();
977         if (id>=0)
978         {
979             mActualCollection=i;
980         } // if id>=0
981     } // for i
982     RefreshCollectionText();
983     RefreshColourCollection();
984 }
985
986 //------------------------------------------------------------------------
987 void WidgetShowNPoints::RefreshColourCollection()
988 {
989     UpdatePoints_();
990     std::vector<double> colourAll;
991     colourAll.push_back(1);
992     colourAll.push_back(0);
993     colourAll.push_back(0);
994     std::vector<double> colourActual;
995     colourActual.push_back(1);
996     colourActual.push_back(1);
997     colourActual.push_back(0);
998     SetColour( colourAll );                                             // For all collections
999     int i,size=lstViewShowNPoints.size();
1000     for (i=0;i<size;i++)
1001     {
1002         lstViewShowNPoints[i] -> mcolour = colourAll;    // All collection
1003         lstViewShowNPoints[i]->RefreshEachPoint();
1004     } // for i
1005     lstViewShowNPoints[mActualCollection] -> mcolour = colourActual;    // Actual collection
1006     lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
1007     lstViewShowNPoints[mActualCollection] -> renderer->GetRenderWindow()->Render();
1008 }
1009
1010 //------------------------------------------------------------------------
1011 void WidgetShowNPoints::RefreshCollectionText()
1012 {
1013     wxString strTmp;
1014     strTmp.Printf(_T("%d   /  %d "),  (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
1015     txtNrCollections->SetLabel( strTmp );
1016     SetOutputBox();
1017 }
1018
1019 //------------------------------------------------------------------------
1020 void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event)
1021 {
1022     //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1023     #if wxMAJOR_VERSION <= 2
1024             wxFileDialog* FD = new wxFileDialog( 0,
1025                                                 _T("Save groups of points .."),
1026                                                 _T(""),
1027                                                 _T(""),
1028                                                 _T("(*.xls)|*.xls"),
1029                                                 wxSAVE | wxOVERWRITE_PROMPT,
1030                                                 wxDefaultPosition);
1031     #else
1032             wxFileDialog* FD = new wxFileDialog( 0,
1033                                                 _T("Save groups of points .."),
1034                                                 _T(""),
1035                                                 _T(""),
1036                                                 _T("(*.xls)|*.xls"),
1037                                                 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
1038                                                 wxDefaultPosition);
1039     #endif
1040
1041             int result_FD = FD->ShowModal();
1042             // This line is need it by windows //EED
1043             FD->SetReturnCode( result_FD );
1044             if (FD->GetReturnCode()==wxID_OK)
1045             {
1046                 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1047
1048                 FILE *ff;
1049                 ff = fopen( filename.c_str() , "w+" );
1050                 if (ff!=NULL)
1051                 {
1052                     int i,size=lstModelShowNPoints.size();
1053                     fprintf(ff,"NumberOfGroups %d \n",size);
1054
1055                     for (i=0;i<size;i++)
1056                     {
1057                         lstModelShowNPoints[i]->SavePoints_(ff);
1058                     } // for i
1059
1060                     fclose(ff);
1061                 } else {   // else ff
1062                     printf("WidgetShowNPoints::Save Groups Points  ...Error... creating file \n");
1063                 } //ff
1064
1065                 
1066             }     // dialog box
1067     StopTrackPoint();
1068
1069 }
1070
1071 //------------------------------------------------------------------------
1072 void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
1073 {
1074     //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1075     #if wxMAJOR_VERSION <= 2
1076             wxFileDialog* FD = new wxFileDialog( 0,
1077                                                  _T("Load groups of points .."),
1078                                                  _T(""),
1079                                                  _T(""),
1080                                                  _T("(*.xls)|*.xls"),
1081                                                  wxOPEN | wxFILE_MUST_EXIST,
1082                                                  wxDefaultPosition);
1083     #else
1084             wxFileDialog* FD = new wxFileDialog( 0,
1085                                                  _T("Load groups of points .."),
1086                                                  _T(""),
1087                                                  _T(""),
1088                                                  _T("(*.xls)|*.xls"),
1089                                                  wxFD_OPEN | wxFD_FILE_MUST_EXIST,
1090                                                  wxDefaultPosition);
1091     #endif
1092             bool okEraseFirstGrout=false;
1093
1094             int result_FD = FD->ShowModal();
1095             // This line is need it by windows //EED
1096             FD->SetReturnCode( result_FD );
1097             if (FD->GetReturnCode()==wxID_OK)
1098             {
1099                 if (lstModelShowNPoints.size()==1)
1100                 {
1101                     if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGrout=true; }
1102                 }
1103                 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1104                 FILE *ff = fopen( filename.c_str() , "r+" );
1105                 if (ff!=NULL)
1106                 {
1107                     int i;
1108                     int iGroup,sizeGroups;
1109                     int iPoint,numberPointsRead;
1110                     char chartmp[256];
1111                     fscanf(ff," %s %d",chartmp,&sizeGroups);
1112                     for (iGroup=0;iGroup<sizeGroups;iGroup++)
1113                     {
1114                         mActualCollection = lstModelShowNPoints.size();
1115                         InsertCollection();
1116
1117                         int numberPointsRead= lstModelShowNPoints[mActualCollection]->ReadPoints_(ff);
1118                         for (i=0;i<numberPointsRead;i++)
1119                         {
1120                             // EED 2022-05-19
1121                             //AddVtkPoint();
1122                             GetViewShowNPoints()->AddVtkPoint();
1123                         }// for
1124                     } // for i
1125
1126                     fclose(ff);
1127                 } else {   // else ff
1128                     printf("WidgetShowNPoints::Load Group of Points  ...Error... reading file");
1129                 } //ff
1130                 if (okEraseFirstGrout==true)
1131                 {
1132                     mActualCollection=0;
1133                     DeleteCollection_();
1134                     mActualCollection = lstModelShowNPoints.size()-1;
1135                 }
1136                 RefreshCollectionText();
1137                 RefreshColourCollection();
1138             }     // dialog box
1139     StopTrackPoint();
1140 }
1141
1142
1143 //------------------------------------------------------------------------
1144 std::vector<int> WidgetShowNPoints::GetLstPointsX()
1145 {
1146     if (mtype!=4)
1147     {
1148         return GetModelShowNPoints()->GetLstPointsX();
1149     } else {
1150         std::vector<int> lst;
1151         int iP,s;
1152         int iG,sG=lstModelShowNPoints.size();
1153         for (iG=0 ; iG<sG ; iG++)
1154         {
1155             std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsX();
1156             s = lstTmp.size();
1157             for (iP=0 ; iP<s ; iP++)
1158             {
1159                 lst.push_back( lstTmp[iP] );
1160             } // for iP
1161         } // for iG
1162         return lst;
1163     } // if 4
1164 }
1165
1166 //------------------------------------------------------------------------
1167 std::vector<int> WidgetShowNPoints::GetLstPointsY()
1168 {
1169     if (mtype!=4)
1170     {
1171         return GetModelShowNPoints()->GetLstPointsY();
1172     } else {
1173         std::vector<int> lst;
1174         int iP,s;
1175         int iG,sG=lstModelShowNPoints.size();
1176         for (iG=0 ; iG<sG ; iG++)
1177         {
1178             std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsY();
1179             s = lstTmp.size();
1180             for (iP=0 ; iP<s ; iP++)
1181             {
1182                 lst.push_back( lstTmp[iP] );
1183             } // for iP
1184         } // for iG
1185         return lst;
1186     }
1187 }
1188
1189 //------------------------------------------------------------------------
1190 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
1191 {
1192     if (mtype!=4)
1193     {
1194         return GetModelShowNPoints()->GetLstPointsZ();
1195     } else {
1196         std::vector<int> lst;
1197         int iP,s;
1198         int iG,sG=lstModelShowNPoints.size();
1199         for (iG=0 ; iG<sG ; iG++)
1200         {
1201             std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsZ();
1202             s = lstTmp.size();
1203             for (iP=0 ; iP<s ; iP++)
1204             {
1205                 lst.push_back( lstTmp[iP] );
1206             } // for iP
1207         } // for iG
1208         return lst;
1209
1210     }
1211 }
1212
1213 //------------------------------------------------------------------------
1214 std::vector<std::string> WidgetShowNPoints::GetLstLabels()
1215 {
1216     if (mtype!=4)
1217     {
1218         return GetModelShowNPoints()->GetLstLabels();
1219     } else {
1220         std::vector< std::string > lst;
1221         int iP,s;
1222         int iG,sG=lstModelShowNPoints.size();
1223         for (iG=0 ; iG<sG ; iG++)
1224         {
1225             std::vector< std::string > lstTmp = lstModelShowNPoints[iG]->GetLstLabels();
1226             s = lstTmp.size();
1227             for (iP=0 ; iP<s ; iP++)
1228             {
1229                 lst.push_back( lstTmp[iP] );
1230             } // for iP
1231         } // for iG
1232         return lst;
1233     }
1234 }
1235
1236 //------------------------------------------------------------------------
1237 std::vector<int> WidgetShowNPoints::GetLstIndexs()
1238 {
1239     std::vector<int> lstIndexs;
1240     if (mtype!=4)
1241     {
1242         lstIndexs.push_back( GetModelShowNPoints()->GetLstPointsSize() );
1243     } else {
1244         int iG,sG=lstModelShowNPoints.size();
1245         for (iG=0 ; iG<sG ; iG++)
1246         {
1247             lstIndexs.push_back( lstModelShowNPoints[iG]->GetLstPointsSize() );
1248         } // for iG
1249     }
1250     return lstIndexs;
1251 }
1252
1253
1254 void WidgetShowNPoints::CreatePatch01()
1255 {
1256     if ( (lstModelShowNPoints.size()==1) && (GetModelShowNPoints()->GetLstPointsSize()==4) )
1257     {
1258         StopTrackPoint();
1259         double px,py,pz;
1260         double dx,dy,dz,s;
1261         std::vector<int> lstX = GetModelShowNPoints()->GetLstPointsX();
1262         std::vector<int> lstY = GetModelShowNPoints()->GetLstPointsY();
1263         std::vector<int> lstZ = GetModelShowNPoints()->GetLstPointsZ();
1264         
1265         // --- Group 0 ---
1266         ErasePoint( 2 );
1267         ErasePoint( 2 );
1268         dx=lstX[1]-lstX[0];
1269         dy=lstY[1]-lstY[0];
1270         dz=lstZ[1]-lstZ[0];
1271         s=0.33333;
1272         px = lstX[0] + dx*s;
1273         py = lstY[0] + dy*s;
1274         pz = lstZ[0] + dz*s;
1275         InsertPoint(px ,py, pz,"");
1276         s=s*2;
1277         px = lstX[0] + dx*s;
1278         py = lstY[0] + dy*s;
1279         pz = lstZ[0] + dz*s;
1280         InsertPoint(px ,py, pz,"");
1281
1282         // --- Group 1 ---
1283         OnInsertCollectionAfter_();
1284           px = (lstX[0]+lstX[3])/2;
1285           py = (lstY[0]+lstY[3])/2;
1286           pz = (lstZ[0]+lstZ[3])/2;
1287           InsertPoint(px ,py, pz,"");
1288           px = (lstX[1]+lstX[2])/2;
1289           py = (lstY[1]+lstY[2])/2;
1290           pz = (lstZ[1]+lstZ[2])/2;
1291           InsertPoint(px ,py, pz,"");
1292           px = (lstX[0]+lstX[1]+lstX[2]+lstX[3])/4;
1293           py = (lstY[0]+lstY[1]+lstY[2]+lstY[3])/4;
1294           pz = (lstZ[0]+lstZ[1]+lstZ[2]+lstZ[3])/4;
1295           InsertPoint(px ,py, pz,"");
1296
1297         
1298         // --- Group 2 ---
1299         OnInsertCollectionAfter_();
1300           px = lstX[3];
1301           py = lstY[3];
1302           pz = lstZ[3];
1303           InsertPoint(px ,py, pz,"");
1304           px = lstX[2];
1305           py = lstY[2];
1306           pz = lstZ[2];
1307           InsertPoint(px ,py, pz,"");
1308           dx=lstX[2]-lstX[3];
1309           dy=lstY[2]-lstY[3];
1310           dz=lstZ[2]-lstZ[3];
1311           s=0.33333;
1312           px = lstX[3] + dx*s;
1313           py = lstY[3] + dy*s;
1314           pz = lstZ[3] + dz*s;
1315           InsertPoint(px ,py, pz,"");
1316           s=s*2;
1317           px = lstX[3] + dx*s;
1318           py = lstY[3] + dy*s;
1319           pz = lstZ[3] + dz*s;
1320           InsertPoint(px ,py, pz,"");
1321
1322         
1323         SetOutputBox();
1324     } else {
1325             printf("EED WidgetShowNPoints::CreatePatch01  Warning patch not apply. Need juste one group with four points\n");
1326     } // if
1327 }