]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
#3485 ShowNPionts for Multiple Groups
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / WidgetShowNPoints.cxx
index f7fa68f29570aefedf98041f7cb6a7350fc772f6..8b17078b3213ccb4a202770fcd0da589a5cce2ad 100644 (file)
@@ -10,6 +10,7 @@
 #include <wx/sizer.h>
 #include <wx/filedlg.h>
 #include <wx/msgdlg.h>
+#include <wx/notebook.h>
 
 #include "WidgetShowNPoints.h"
 
   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
   {
+    printf("EED WidgetShowNPoints::WidgetShowNPoints Start \n");
        // EED 2022-05-19
     //  mmodelShowNPoints                               = new ModelShowNPoints();
-      mActualLstPoints=0;
-      ModelShowNPoints* modelShowNPoints = new ModelShowNPoints();
-      lstModelShowNPoints.push_back( modelShowNPoints );
-      lstViewShowNPoints.push_back( new  ViewShowNPoints( modelShowNPoints ) );
-      
+                        mActualCollection= 0;
+    ModelShowNPoints*   modelShowNPoints = new ModelShowNPoints();
+    lstModelShowNPoints.push_back( modelShowNPoints );
+    lstViewShowNPoints.push_back( new  ViewShowNPoints( modelShowNPoints ) );
       
     mtype                                                      = type;
     SetType(mtype);
-    wxPanel    *panel                                  = this;
-    wxSizer *sizer                                     = NULL;
+    wxPanel*    panelParent         = this;
+    wxSizer*    sizer                          = NULL;
+    wxSizer*    MNPsizer            = NULL;
+
+    wxNotebook* bookSetPoints       = NULL;
+    wxNotebook* bookGroupManager    = NULL;
+    wxPanel*    panel               = NULL;
+    wxPanel*    panel2              = NULL;
+
+
+      
+
+      bookSetPoints     = new wxNotebook(panelParent,
+                          -1,
+                          wxDefaultPosition,
+                          wxDefaultSize,
+                          wxNB_TOP );
+      panel  = new wxPanel(bookSetPoints);
 
-       if ((mtype==0) || (mtype==3))
+
+    // Group Manager
+    if (mtype==4)
+    {
+          bookGroupManager   = new wxNotebook(panelParent, //bbGetWxParent(),
+                              -1,
+                              wxDefaultPosition,
+                              wxDefaultSize,
+                              wxNB_TOP );
+          panel2  = new wxPanel(bookGroupManager);
+          txtNrCollections                      = new wxStaticText(panel2,-1, _T("1   /  1 "));
+          wxButton *btnBackCollection           = new wxButton( panel2, -1, _T("<"));
+          wxButton *btnNextCollection           = new wxButton( panel2, -1, _T(">"));
+          wxButton *btnInsertCollectionBefore   = new wxButton( panel2, -1, _T("Insert Before"));
+          wxButton *btnInsertCollectionAfter    = new wxButton( panel2, -1, _T("Insert After"));
+          wxButton *btnDeleteCollection         = new wxButton( panel2, -1, _T("Delete"));
+
+          Connect(btnInsertCollectionBefore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionBefore);
+          Connect(btnInsertCollectionAfter->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionAfter);
+          Connect(btnDeleteCollection->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteCollection);
+          Connect(btnBackCollection->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnBackCollection);
+          Connect(btnNextCollection->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnNextCollection);
+
+          wxFlexGridSizer *sizer1               = new wxFlexGridSizer(1);
+          wxFlexGridSizer *sizer2               = new wxFlexGridSizer(2);
+        
+          sizer2->Add( btnBackCollection );
+          sizer2->Add( btnNextCollection );
+
+          sizer1->Add( txtNrCollections );
+          sizer1->Add( sizer2 );
+          sizer1->Add( btnInsertCollectionBefore );
+          sizer1->Add( btnInsertCollectionAfter );
+          sizer1->Add( btnDeleteCollection );
+          MNPsizer                        = sizer1;
+          panel2->SetSizer( MNPsizer );
+          panel2->SetAutoLayout(true);
+          panel2->Layout();
+          bookGroupManager->AddPage(panel2 , _T("Collection") );
+    } // if mtype 4
+
+       if ( (mtype==0) || (mtype==3) || (mtype==4) )
        {
                // Widget interface
                askPointLabel                                   = new wxStaticText(panel, -1, _T("Point label :")); // JPR
                wxButton *btnDeleteAllPoints    = new wxButton( panel, -1, _T("Delete all points"));
                wxButton *btnSavePoints                 = NULL;
                wxButton *btnLoadPoints                 = NULL;
-               if (mtype==0)
+               if ( (mtype==0) || (mtype==4) )
                {
                        btnSavePoints                           = new wxButton( panel, -1, _T("Save points"));
                        btnLoadPoints                           = new wxButton( panel, -1, _T("Load points"));
-               }
+               } // if mtype
                txtNrPoints                                             = new wxStaticText(panel,-1, _T(" "));
 
                //NTU: Sliders for opacity and radio change
-               wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T("  Points Opacity  ")));
-               sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
-               wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T("  Points Radius  ")));
-               sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
-
-               wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
-               //    sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
+               wxStaticText* txOpacity         = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
+               sdrOpacity                      = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
+               wxStaticText* txRadio           = new wxStaticText(panel, -1, wxString(_T("  Points Radius  ")));
+               sdrRadio                        = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
 
                Connect(btnAddPoint->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
                Connect(btnInsertPoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
                Connect(btnEraseLastPoint->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
                Connect(btnErasePoint->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
                Connect(btnDeleteAllPoints->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
-               if (mtype==0)
+               if ((mtype==0) || (mtype==4) )
                {
-                       Connect(btnSavePoints->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
-                       Connect(btnLoadPoints->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
+                       Connect(btnSavePoints->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
+                       Connect(btnLoadPoints->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
                }
                //NTU: Slider events
                Connect(sdrOpacity->GetId()                     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
                Connect(sdrRadio->GetId()                       , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
 
+        wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
                sizer1->Add(askPointLabel); // JPR
                sizer1->Add(textCtrl);
                sizer1->Add(btnAddPoint);
                sizer1->Add(sdrOpacity,1,wxGROW );
                sizer1->Add(txRadio);
                sizer1->Add(sdrRadio,1,wxGROW );
-               if (mtype==0)
+        if ((mtype==0) || (mtype==4) )
                {
                        sizer1->Add(btnSavePoints);
                        sizer1->Add(btnLoadPoints);
                  txtNrPoints                                           = new wxStaticText(panel,-1, _T(" "));
 
                  //NTU: Sliders for opacity and radio change
-                 wxStaticText* txOpacity                       = new wxStaticText(this, -1, wxString(_T("  Points Opacity  ")));
-                 sdrOpacity                                            = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
-                 wxStaticText* txRadio                         = new wxStaticText(this, -1, wxString(_T("  Points Radio  ")));
-                 sdrRadio                                                      = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
-                 wxFlexGridSizer *sizer1                       = new wxFlexGridSizer(1);
+                 wxStaticText* txOpacity                       = new wxStaticText(panel, -1, wxString(_T("  Points Opacity  ")));
+                 sdrOpacity                                            = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
+                 wxStaticText* txRadio                         = new wxStaticText(panel, -1, wxString(_T("  Points Radio  ")));
+                 sdrRadio                                                      = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
                  Connect(btnSetPositionPoint->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
                  Connect(sdrOpacity->GetId()   , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
                  Connect(sdrRadio->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
 
+          wxFlexGridSizer *sizer1            = new wxFlexGridSizer(1);
                  sizer1->Add(btnSetPositionPoint);
                  sizer1->Add(txtNrPoints);
                  sizer1->Add(txOpacity);
         wxButton               *btnDeleteAllPoints = new wxButton(panel, -1, _T("      Delete All      "));
         wxStaticText   *spacer                         = new wxStaticText(panel, -1, _T("\n")); // JPR
                                         textCtrl                       = new wxTextCtrl(panel, -1);
-        wxFlexGridSizer *sizer1                        = new wxFlexGridSizer(1);
         Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
         Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);    
-        sizer1->Add(askPointLabel); 
+        wxFlexGridSizer *sizer1             = new wxFlexGridSizer(1);
+        sizer1->Add(askPointLabel);
         sizer1->Add(btnAddPoint);
         sizer1->Add(btnDeleteAllPoints);
         sizer1->Add(spacer);
         sizer1->Add(textCtrl);
-        sdrOpacity  = new wxSlider();
-        sdrRadio    = new wxSlider();
-        txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
-        sizer = sizer1;
+      //  sdrOpacity                          = new wxSlider();
+      //  sdrRadio                            = new wxSlider();
+        txtNrPoints                         = new wxStaticText(panel, -1, _T("\n\n\n"));
+        sizer                               = sizer1;
        } // bbGetInputType 2
 
-       if (sizer!=NULL)
-       {
-               panel->SetSizer(sizer);
-               panel->SetAutoLayout(true);
-               panel->Layout();
-       } // if sizer
+            
+      panel->SetSizer(sizer);
+      panel->SetAutoLayout(true);
+      panel->Layout();
+      bookSetPoints->AddPage(panel , _T("Set Points") );
+
+    if ((mtype >= 0) && (mtype <= 3) )
+    {
+        if (sizer!=NULL)
+        {
+            wxFlexGridSizer *sizerParent             = new wxFlexGridSizer(1);
+            sizerParent->Add( bookSetPoints );
+            panelParent->SetSizer( sizerParent );
+            panelParent->SetAutoLayout(true);
+            panelParent->Layout();
+        } // if sizer
+    } // if  mtype 0 1 2 3
+      
+    if (mtype == 4)
+    {
+        if ((sizer!=NULL) && (MNPsizer!=NULL))
+        {
+            wxFlexGridSizer *sizerG             = new wxFlexGridSizer(2);
+            sizerG->Add(bookGroupManager);
+            sizerG->Add(bookSetPoints);
+            panelParent->SetSizer(sizerG);
+            panelParent->SetAutoLayout(true);
+            panelParent->Layout();
+        } // if sizer
+    } // if mtype 4
 }
 
 //------------------------------------------------------------------------
@@ -167,14 +247,14 @@ ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
 {
     // EED 2022-05-19
     // return mmodelShowNPoints;
-    return lstModelShowNPoints[ mActualLstPoints ];
+    return lstModelShowNPoints[ mActualCollection ];
 }
 
 // EED 2022-05-19
 //------------------------------------------------------------------------
 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
 {
-    return lstViewShowNPoints[ mActualLstPoints ];
+    return lstViewShowNPoints[ mActualCollection ];
 }
 
 
@@ -634,10 +714,10 @@ void  WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX,  std
                return;
        }
        int i,sizeX,sizeY,sizeZ,sizeLabels;
-       sizeX=(int)initLstPointsX.size();
-       sizeY=(int)initLstPointsY.size();
-       sizeZ=(int)initLstPointsZ.size();
-       sizeLabels=(int)initLstLabels.size();
+       sizeX = (int)initLstPointsX.size();
+       sizeY = (int)initLstPointsY.size();
+       sizeZ = (int)initLstPointsZ.size();
+       sizeLabels = (int)initLstLabels.size();
        int x,y,z;
        std::string label;
        if ( (sizeX==sizeY) && (sizeX==sizeZ) )
@@ -683,3 +763,72 @@ double WidgetShowNPoints::GetOpacity()
 {
        return sdrOpacity->GetValue()/100;
 }
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::InsertCollection()
+{
+    ModelShowNPoints*   model   = new ModelShowNPoints();
+    ViewShowNPoints*    view    = new ViewShowNPoints( model );
+    model->SetImage( lstModelShowNPoints[0]->GetImage() );
+    view->mopacity = lstViewShowNPoints[0]->mopacity;
+    view->renderer = lstViewShowNPoints[0]->renderer;
+    lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
+    lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
+    RefreshCollectionText();
+}
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
+{
+    InsertCollection();
+}
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
+{
+    mActualCollection++;
+    InsertCollection();
+}
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
+{
+    if ( lstModelShowNPoints.size()>=1 )
+    {
+        DeleteAllPoints();  // Actual Collection
+        lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
+        mActualCollection--;
+    }
+    RefreshCollectionText();
+}
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
+{
+    mActualCollection--;
+    if ( mActualCollection <0  )
+    {
+        mActualCollection=0;
+    } //if <=0
+    RefreshCollectionText();
+}
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
+{
+    mActualCollection++;
+    if ( mActualCollection >=lstModelShowNPoints.size() )
+    {
+        mActualCollection = lstModelShowNPoints.size()-1;
+    } //if <=0
+    RefreshCollectionText();
+}
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::RefreshCollectionText()
+{
+    wxString strTmp;
+    strTmp.Printf(_T("%d   /  %d "),  (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
+    txtNrCollections->SetLabel( strTmp );
+    SetOutputBox();
+}