]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
#3533 Update Curent contour and actual point ShowNPoints in Undo Redo
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / WidgetShowNPoints.cxx
index c5b080843b2745bd1237be6e83fefa5a3bcd0b05..36c6a840eb1893f82033e0fbbbc8a1cd4ef93265 100644 (file)
                               wxDefaultSize,
                               wxNB_TOP );
           panel2  = new wxPanel(bookGroupManager);
-          cbVisuActualCollection                = new wxCheckBox    ( panel2,-1, _T("A.V.")   ,   wxDefaultPosition, sizeButton );
+          cbVisuActualCollection                = new wxCheckBox    ( panel2,-1, _T("Cur.")   ,   wxDefaultPosition, sizeButton );
           txtNrCollections                      = new wxStaticText  ( panel2,-1, _T("    1/1    "));
           wxButton *btnBackCollection           = new wxButton      ( panel2, -1, _T("<")     ,   wxDefaultPosition, sizeButton );
           wxButton *btnNextCollection           = new wxButton      ( panel2, -1, _T(">")     ,   wxDefaultPosition, sizeButton );
           wxFlexGridSizer *sizer7               = new wxFlexGridSizer(2);
           wxFlexGridSizer *sizer8               = new wxFlexGridSizer(2);
         
-          cbVisuActualCollection      -> SetToolTip( _T("Visu actual collection") );
+          cbVisuActualCollection      -> SetToolTip( _T("Current group") );
           btnInsertCollectionBefore   -> SetToolTip( _T("+  Add group before") );
           btnInsertCollectionAfter    -> SetToolTip( _T("+>  Add group after") );
           btnDeleteCollection         -> SetToolTip( _T("-  Erase group") );
@@ -668,10 +668,12 @@ void WidgetShowNPoints::OnInsertPoint_()
     
     StopAutoAddPoints();
     StopTrackPoint();
+
     if (GetViewShowNPoints()->renderer==NULL)
     {
         return;
     }
+    UndoRedo_SaveCollection(); //A
     std::vector<double> point = GetModelShowNPoints()->GetReferencePoint();
     if (point.size()==3)
     {
@@ -682,7 +684,7 @@ void WidgetShowNPoints::OnInsertPoint_()
     }
     RefreshCollectionText();
     RefreshColourCollection();
-    UndoRedo_SaveCollection();
+    UndoRedo_SaveCollection(); //B
 }
 
 //------------------------------------------------------------------------
@@ -703,12 +705,13 @@ void WidgetShowNPoints::OnAddPoint__()
        std::vector<double> point = GetModelShowNPoints()->GetReferencePoint();
        if (point.size()==3)
        {
+        UndoRedo_SaveCollection(); //A
                AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
         SetOutputBox();
         // EED 2022-05-19
         //renderer->GetRenderWindow()->Render();
         GetViewShowNPoints()->Render();
-        UndoRedo_SaveCollection();
+        UndoRedo_SaveCollection(); //B
        } else {//mpoint.size
                printf("creaMaracasVisu::ShowNPoints (not match point) \n");
        }
@@ -867,6 +870,8 @@ void WidgetShowNPoints::StopAutoAddPoints( )
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnSetPoint_()
 {
+    UndoRedo_SaveCollection(); //A
+
     StopAutoAddPoints();
     StopTrackPoint();
 
@@ -891,7 +896,7 @@ void WidgetShowNPoints::OnSetPoint_()
     RefreshCollectionText();
     RefreshColourCollection();
     SetOutputBox();
-    UndoRedo_SaveCollection();
+    UndoRedo_SaveCollection(); //B
 }
 
 //------------------------------------------------------------------------
@@ -935,7 +940,6 @@ void WidgetShowNPoints::MovePoint_(double step)
                 if (dataArrayNormals!=NULL)
                 {
                     dataArrayNormals->GetTuple(idMeshPoint, normal);
-                    
                     int direction = step;
     //                pN[0] = p[0] / spc[0] + direction*normal[0];
     //                pN[1] = p[1] / spc[1] + direction*normal[1];
@@ -943,12 +947,13 @@ void WidgetShowNPoints::MovePoint_(double step)
                     pN[0] = x + (direction * normal[0]);
                     pN[1] = y + (direction * normal[1]);
                     pN[2] = z + (direction * normal[2]);
+                    UndoRedo_SaveCollection(); //A
                     GetModelShowNPoints()->SetPointById(idControlPoint, pN);
         //          GetViewShowNPoints()->RefreshPoint(idControlPoint);
     //                RefreshCollectionText();
     //                RefreshColourCollection();
     //                SetOutputBox();
-                    UndoRedo_SaveCollection();
+                    UndoRedo_SaveCollection(); //B
                 } else {
                     printf("Error!  WidgetShowNPoints::MovePoint_  Missing normals in aux_mesh  \n");
                 }
@@ -999,11 +1004,12 @@ void WidgetShowNPoints::MovePoint_(double step)
                 v[1] = 0;
                 v[2] = 0;
             }// if mag
+            UndoRedo_SaveCollection(); //A
             point.push_back( p[0] + step*v[0] );
             point.push_back( p[1] + step*v[1] );
             point.push_back( p[2] + step*v[2] );
             GetModelShowNPoints()->SetPointById(id,point);
-            UndoRedo_SaveCollection();
+            UndoRedo_SaveCollection(); //B
      } // if id
     } // if aux_mesh
  RefreshCollectionText();
@@ -1039,6 +1045,7 @@ void WidgetShowNPoints::TrackingPoint( )
         
         if (idTrack>=0)
         {
+            UndoRedo_SaveCollection(); //A
             GetModelShowNPoints()->SetPointId_mReferencePoint(idTrack);
             
             RefreshCollectionText();
@@ -1046,7 +1053,7 @@ void WidgetShowNPoints::TrackingPoint( )
 
 //            GetViewShowNPoints()->RefreshPoint(idTrack);
 //            GetViewShowNPoints()->Render();
-            UndoRedo_SaveCollection();
+            UndoRedo_SaveCollection(); //B
         } // if id
     } // if trackPointFlag
 }
@@ -1094,10 +1101,11 @@ void WidgetShowNPoints::StopTrackPoint( )
             // EED 2022-05-19
                        //lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
                        //renderer->GetRenderWindow()->Render();
+            UndoRedo_SaveCollection(); //A
             GetViewShowNPoints()->lstActorsText[id]->SetInput(  (const char*) ( textCtrl->GetValue().mb_str() ) );
             GetViewShowNPoints()->Render();
             SetOutputBox();
-            UndoRedo_SaveCollection();
+            UndoRedo_SaveCollection(); //B
                } // if id
        }
 
@@ -1135,6 +1143,7 @@ void WidgetShowNPoints::StopTrackPoint( )
         StopTrackPoint();
 
         //ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
+        UndoRedo_SaveCollection(); //A
         if (ErasePoint( GetModelShowNPoints()->GetIdCurrentPoint() ) == true)
         {
             SetOutputBox();
@@ -1144,7 +1153,7 @@ void WidgetShowNPoints::StopTrackPoint( )
             RefreshCollectionText();
             RefreshColourCollection();
             StopTrackPoint();
-            UndoRedo_SaveCollection();
+            UndoRedo_SaveCollection(); //B
         }
     }
 
@@ -1163,13 +1172,14 @@ void WidgetShowNPoints::StopTrackPoint( )
         StopAutoAddPoints();
         StopTrackPoint();
 
+        UndoRedo_SaveCollection(); //A
         int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
         ErasePoint( id );
         
         RefreshCollectionText();
         RefreshColourCollection();
         
-        UndoRedo_SaveCollection();
+        UndoRedo_SaveCollection(); //B
         GetViewShowNPoints()->Render();
         SetOutputBox();
         StopTrackPoint();
@@ -1192,8 +1202,9 @@ void WidgetShowNPoints::OnDeleteAllPoints_()
     StopAutoAddPoints();
     StopTrackPoint();
 
+    UndoRedo_SaveCollection(); //A
     DeleteAllPoints_();
-    UndoRedo_SaveCollection();
+    UndoRedo_SaveCollection(); //B
 }
 
 //------------------------------------------------------------------------
@@ -1407,9 +1418,10 @@ void WidgetShowNPoints::InsertCollectionBefore_()
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnInsertCollectionBefore_()
 {
+    UndoRedo_SaveCollection(); //A
     InsertCollectionBefore_();
     CreatePointsIntoNewCollection();
-    UndoRedo_SaveCollection();
+    UndoRedo_SaveCollection(); //B
 }
 
 
@@ -1434,9 +1446,10 @@ void WidgetShowNPoints::InsertCollectionAfter_()
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnInsertCollectionAfter_()
 {
+    UndoRedo_SaveCollection(); //A
     InsertCollectionAfter_();
     CreatePointsIntoNewCollection();
-    UndoRedo_SaveCollection();
+    UndoRedo_SaveCollection(); //B
 }
 
 //------------------------------------------------------------------------
@@ -1576,13 +1589,14 @@ void WidgetShowNPoints::DeleteCollection_()
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnDeleteCollection_()
 {
+    UndoRedo_SaveCollection(); //A
     DeleteCollection_();
     SetOutputBox();
     GetViewShowNPoints()->Render();
     RefreshCollectionText();
     RefreshColourCollection();
     StopTrackPoint();
-    UndoRedo_SaveCollection();
+    UndoRedo_SaveCollection(); //B
 }
 
 //------------------------------------------------------------------------
@@ -1609,8 +1623,9 @@ void WidgetShowNPoints::ResetCollections_()
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnResetCollections_()
 {
+    UndoRedo_SaveCollection(); //A
     ResetCollections_();
-    UndoRedo_SaveCollection();
+    UndoRedo_SaveCollection(); //B
 }
 
 
@@ -1632,7 +1647,7 @@ void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
     RefreshCollectionText();
     RefreshColourCollection();
     StopTrackPoint();
-    UndoRedo_SaveCollection();
+//    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
@@ -1647,7 +1662,7 @@ void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
     RefreshCollectionText();
     RefreshColourCollection();
     StopTrackPoint();
-    UndoRedo_SaveCollection();
+//    UndoRedo_SaveCollection();
 }
 
 //------------------------------------------------------------------------
@@ -1667,55 +1682,64 @@ void WidgetShowNPoints::DetectCollectionActive()
     RefreshColourCollection();
 }
 
+
+
+
 //------------------------------------------------------------------------
 void WidgetShowNPoints::RefreshColourCollection()
 {
     UpdatePoints_();
     std::vector<double> colourAll;
-    colourAll.push_back(1);
-    colourAll.push_back(0);
     colourAll.push_back(0);
+    colourAll.push_back(1);
+    colourAll.push_back(1);
     std::vector<double> colourActualGroup;
     colourActualGroup.push_back(1);
-    colourActualGroup.push_back(1);
     colourActualGroup.push_back(0);
-
+    colourActualGroup.push_back(0);
     // For all collections
     SetColour( colourAll );
-    int i,size=lstViewShowNPoints.size();
-    for (i=0;i<size;i++)
+    int sizeLstPoints;
+    int iCollection,sizeLstCollection=lstViewShowNPoints.size();
+    for ( iCollection=0 ; iCollection<sizeLstCollection ; iCollection++ )
     {
-        lstViewShowNPoints[i] -> mcolour    = colourAll;
-        lstViewShowNPoints[i] -> ratioRadio = 1;
-        if ((cbVisuActualCollection!=NULL) && (cbVisuActualCollection->GetValue()==true))
+        if (iCollection==mActualCollection)
         {
-            lstViewShowNPoints[i] -> mopacity   = 0.0;
+            // Actual collection
+            lstViewShowNPoints[mActualCollection] -> mcolour = colourActualGroup;
+            lstViewShowNPoints[mActualCollection] -> mopacity   = sCtrlOpacity->GetValue()*10.0/100.0;
+            lstViewShowNPoints[mActualCollection] -> ratioRadio = 1.2;
+            lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
+            
+            //Actual Point
+            int curPnt      = lstModelShowNPoints[mActualCollection]->GetIdCurrentPoint();
+            sizeLstPoints   = lstModelShowNPoints[mActualCollection]->GetLstPointsSize();
+            if ((curPnt>=0)  && (curPnt<sizeLstPoints  ) )
+            {
+                std::vector<double> colourActualPoint;
+                colourActualPoint.push_back(1);
+                colourActualPoint.push_back(1);
+                colourActualPoint.push_back(0);
+                double radio          = GetModelShowNPoints()->GetRadio();
+                lstViewShowNPoints[mActualCollection] -> mcolour  = colourActualPoint;
+                lstViewShowNPoints[mActualCollection]->RefreshPoint( curPnt   );
+                lstViewShowNPoints[mActualCollection] -> mcolour = colourActualGroup;
+            } // if
+            lstViewShowNPoints[mActualCollection]->TryToShowActorsInRender(true);
         } else {
-            lstViewShowNPoints[i] -> mopacity   = sCtrlOpacity->GetValue()*10.0/100.0;
-        }
-        lstViewShowNPoints[i]->RefreshEachPoint();
+            lstViewShowNPoints[iCollection] -> mcolour    = colourAll;
+            lstViewShowNPoints[iCollection] -> ratioRadio = 1;
+            if ((cbVisuActualCollection!=NULL) && (cbVisuActualCollection->GetValue()==true))
+            {
+                lstViewShowNPoints[iCollection]->TryToShowActorsInRender(false);
+      //          lstViewShowNPoints[i] -> mopacity   = 0.0;
+            } else {
+                lstViewShowNPoints[iCollection]->TryToShowActorsInRender(true);
+      //          lstViewShowNPoints[i] -> mopacity   = sCtrlOpacity->GetValue()*10.0/100.0;
+            }
+            lstViewShowNPoints[iCollection]->RefreshEachPoint();
+        }// if mActualCollection
     } // for i
-    
-    // Actual collection
-    lstViewShowNPoints[mActualCollection] -> mcolour = colourActualGroup;
-    lstViewShowNPoints[mActualCollection] -> mopacity   = sCtrlOpacity->GetValue()*10.0/100.0;
-    lstViewShowNPoints[mActualCollection] -> ratioRadio = 1.1;
-    lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
-    
-    //Actual Point
-    int curPnt = lstModelShowNPoints[mActualCollection] -> GetIdCurrentPoint();
-    size=lstModelShowNPoints[mActualCollection]->GetLstPointsSize();
-    if ((curPnt>=0)  && (curPnt<size  ) )
-    {
-        std::vector<double> colourActualPoint;
-        colourActualPoint.push_back(0);
-        colourActualPoint.push_back(0);
-        colourActualPoint.push_back(1);
-        double radio          = GetModelShowNPoints()->GetRadio();
-        lstViewShowNPoints[mActualCollection] -> mcolour  = colourActualPoint;
-        lstViewShowNPoints[mActualCollection]->RefreshPoint( curPnt   );
-        lstViewShowNPoints[mActualCollection] -> mcolour = colourActualGroup;
-    } // if
     lstViewShowNPoints[mActualCollection] -> renderer->GetRenderWindow()->Render();
 }
 
@@ -1752,6 +1776,25 @@ void WidgetShowNPoints::OnSaveCollections_( std::string filename )
 
 }
 
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnSaveCollectionsIdsCurrent_( std::string filename )
+{
+    FILE *ff;
+    ff = fopen( filename.c_str() , "w+" );
+    if (ff!=NULL)
+    {
+        int i,size = lstModelShowNPoints.size();
+        fprintf(ff,"ActualCollection %d \n",mActualCollection);
+        fprintf(ff,"NumberOfGroups %d \n",size);
+        for (i=0 ; i<size ; i++)
+        {
+            fprintf(ff,"CurrentIdPoint %d \n",lstModelShowNPoints[i]->GetIdCurrentPoint());
+        } // for i
+        fclose(ff);
+    } else {   // else ff
+        printf("WidgetShowNPoints::Save Groups Points  ...Error... creating file \n");
+    } //ff
+}
 
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event)
@@ -1831,6 +1874,31 @@ void WidgetShowNPoints::OnLoadCollections_( std::string filename )
     StopTrackPoint();
 }
 
+
+//------------------------------------------------------------------------
+void WidgetShowNPoints::OnLoadCollectionsIdsCurrent_( std::string filename )
+{
+    FILE *ff = fopen( filename.c_str() , "r+" );
+    int iGroup,sizeGroups;
+    int IdCurrentPoint;
+    char chartmp[256];
+    fscanf(ff," %s %d",chartmp,&mActualCollection);     // ActualCollection
+    fscanf(ff," %s %d",chartmp,&sizeGroups);            // NumberOfGroups
+    for (iGroup=0;iGroup<sizeGroups;iGroup++)
+    {
+        fscanf(ff," %s %d",chartmp,&IdCurrentPoint);  // CurrentPointId
+        lstModelShowNPoints[iGroup]->SetIdCurrentPoint( IdCurrentPoint );
+    } // for iGroup
+    
+    GetViewShowNPoints()->Render();
+    RefreshCollectionText();
+    RefreshColourCollection();
+
+}
+
+
+
+
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
 {
@@ -1858,8 +1926,9 @@ void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
             if (FD->GetReturnCode()==wxID_OK)
             {
                 std::string filename= (const char*) ( FD->GetPath().mb_str() );
+                UndoRedo_SaveCollection(); // A
                 OnLoadCollections_( filename );
-                UndoRedo_SaveCollection();
+                UndoRedo_SaveCollection(); // B
             }     // dialog box
 }
 
@@ -2036,11 +2105,12 @@ void WidgetShowNPoints::InvertLstPoints_()
 //------------------------------------------------------------------------
 void WidgetShowNPoints::OnInvertLstPoints_()
 {
+    UndoRedo_SaveCollection(); // A
     StopAutoAddPoints();
     StopTrackPoint();
     InvertLstPoints_();
     SetOutputBox();
-    UndoRedo_SaveCollection();
+    UndoRedo_SaveCollection(); // B
 }
 
 
@@ -2068,6 +2138,7 @@ void WidgetShowNPoints::OnUndo(wxCommandEvent &event)
         idUndoRedo=-1;
     } else {
         OnLoadCollections_( GetUndoRedoFileName() );
+        OnLoadCollectionsIdsCurrent_( GetUndoRedoFileName()+".current" );
     }// if idUndoRedo
     idUndoRedo++;
 
@@ -2082,6 +2153,7 @@ void WidgetShowNPoints::OnRedo(wxCommandEvent &event)
     } else {
         ResetCollections_();
         OnLoadCollections_( GetUndoRedoFileName() );
+        OnLoadCollectionsIdsCurrent_( GetUndoRedoFileName()+".current" );
         idUndoRedo++;
     }// if idUndoRedo
 }
@@ -2090,6 +2162,7 @@ void WidgetShowNPoints::OnRedo(wxCommandEvent &event)
 void WidgetShowNPoints::UndoRedo_SaveCollection()
 {
     OnSaveCollections_( GetUndoRedoFileName() );
+    OnSaveCollectionsIdsCurrent_( GetUndoRedoFileName()+".current" );
     maxUndoRedo = idUndoRedo;
     idUndoRedo++;
 }