Salome HOME
Fix for the 0052398: TC7.4.0: fatal error during redo in the "3D Sketch
[modules/geom.git] / src / EntityGUI / EntityGUI_3DSketcherDlg.cxx
index c0ad5d1bbe30cfb4d126f560c11dbde6961c3ec1..609b7e8a39e0df80382b3f456d542de996da21e7 100755 (executable)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -65,9 +65,8 @@
 #include <Geom_Plane.hxx>
 #include <SelectMgr_Selection.hxx>
 #include <gce_MakePln.hxx>
-#include <Prs3d_AngleAspect.hxx>
 #include <Prs3d_LineAspect.hxx>
-#include <Prs3d_LengthAspect.hxx>
+#include <Prs3d_DimensionAspect.hxx>
 #if OCC_VERSION_LARGE > 0x06050300
 #include <Prs3d_TextAspect.hxx>
 #include <Prs3d_Presentation.hxx>
@@ -220,7 +219,8 @@ EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg (GeometryGUI* theGeometryGUI, Q
     myOK(false),
     myLineWidth(lineWidth),
     myGeometryGUI(theGeometryGUI),
-    myLengthIORedoList()
+    myLengthIORedoList(),
+    myIsUndoRedo(false)
 {
   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_UNDO")));
@@ -616,6 +616,7 @@ void EntityGUI_3DSketcherDlg::UpdatePointCoordinates()
 //=================================================================================
 void EntityGUI_3DSketcherDlg::ClickOnUndo()
 {
+  myIsUndoRedo = true;
   if (myPointsList.count() > 0) {
     
     myRedoList.append(myPointsList.last());
@@ -636,6 +637,7 @@ void EntityGUI_3DSketcherDlg::ClickOnUndo()
     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
     
     // Remove last point from list
+    myWorkPoint = myPointsList.last();
     myPointsList.removeLast();
     GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
     UpdateButtonsState();
@@ -645,6 +647,7 @@ void EntityGUI_3DSketcherDlg::ClickOnUndo()
 
     updateViewer();
   }
+  myIsUndoRedo = false;
 }
 
 //=================================================================================
@@ -653,6 +656,7 @@ void EntityGUI_3DSketcherDlg::ClickOnUndo()
 //=================================================================================
 void EntityGUI_3DSketcherDlg::ClickOnRedo()
 {
+  myIsUndoRedo = true;
   if (myRedoList.count() > 0) {
     
     myPointsList.append(myRedoList.last());
@@ -673,6 +677,7 @@ void EntityGUI_3DSketcherDlg::ClickOnRedo()
     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
     
     // Remove last point from redo list
+    myWorkPoint = myRedoList.last();
     myRedoList.removeLast();
     GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
     UpdateButtonsState();
@@ -682,6 +687,7 @@ void EntityGUI_3DSketcherDlg::ClickOnRedo()
 
     updateViewer();
   }
+  myIsUndoRedo = false;
 }
 
 //=================================================================================
@@ -1243,7 +1249,13 @@ gp_Dir EntityGUI_3DSketcherDlg::getPresentationPlane() const
   bool twoAngles = GroupAngles->checkBox->isChecked();
   
   XYZ Last    = getLastPoint();
-  XYZ Current = getCurrentPoint();
+  XYZ Current;
+  if( myIsUndoRedo ) {
+      Current = myWorkPoint;
+  } else {
+    Current = getCurrentPoint();
+  }
+  
   XYZ Penultimate = getPenultimatePoint();
   
   gp_Pnt P1 = gp_Pnt(Last.x,Last.y,Last.z);
@@ -1304,7 +1316,9 @@ gp_Dir EntityGUI_3DSketcherDlg::getPresentationPlane() const
       }
     }
     // If no angles, the plane is the one formed by the last edge and the current one
-    aNormal = gp_Dir(Vec1.Crossed(Vec2)); 
+    if(Abs(Vec1.CrossMagnitude(Vec2)) > Precision::Confusion()) {
+      aNormal = gp_Dir(Vec1.Crossed(Vec2)); 
+    }
   }
   return aNormal;
 }
@@ -1652,9 +1666,6 @@ Handle(AIS_LengthDimension) EntityGUI_3DSketcherDlg::createAISLengthDimension(do
                                                                               gp_Pnt P2, 
                                                                               gp_Dir theNormal)
 {
-  // Convert length to string
-  std::string aLength_str = doubleToString(theLength);
-  
   // Plane construction
   gce_MakePln gce_MP(P1, theNormal);
   Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
@@ -1662,20 +1673,24 @@ Handle(AIS_LengthDimension) EntityGUI_3DSketcherDlg::createAISLengthDimension(do
   TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(P1);
   TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(P2);
 
-  Handle(AIS_LengthDimension) anIO =
-    new AIS_LengthDimension(aVert1,
-                            aVert2,
-                            aPlane,
-                            theLength,
-                            TCollection_ExtendedString(aLength_str.c_str()));
-  anIO->SetArrowSize(theLength/20);
+  Handle(AIS_LengthDimension) anIO = new AIS_LengthDimension( aVert1, aVert2, aPlane->Pln() );
+
+  anIO->SetCustomValue( theLength );
 
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-  int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
-  Handle(Prs3d_LengthAspect) asp = new Prs3d_LengthAspect();
-  asp->LineAspect()->SetWidth(w);
-  anIO->Attributes()->SetLengthAspect(asp);
-  
+  int w = resMgr->integerValue( "Geometry", "measures_line_width", 1 );
+
+  Handle(Prs3d_DimensionAspect) aDimensionStyle = new Prs3d_DimensionAspect;
+
+  aDimensionStyle->ArrowAspect()->SetLength( theLength / 20.0 );
+  aDimensionStyle->LineAspect()->SetWidth( w );
+  aDimensionStyle->MakeText3d( Standard_False );
+  aDimensionStyle->SetTextHorizontalPosition( Prs3d_DTHP_Center );
+  aDimensionStyle->SetTextVerticalPosition( Prs3d_DTVP_Center );
+  aDimensionStyle->MakeArrows3d( Standard_True );
+  anIO->SetFlyout( 0.0 );
+  anIO->SetDimensionAspect( aDimensionStyle );
+
   return anIO;
 }
 
@@ -1696,33 +1711,25 @@ Handle(AIS_AngleDimension) EntityGUI_3DSketcherDlg::createAISAngleDimension(doub
   if (Abs(theAngle) < Precision::Angular() ||
       aLength < Precision::Confusion())
     return NULL;
-  
-  // Convert angles to string
-  std::string Angle_str = doubleToString(theAngle);
-  
-  // Construction of the plane
-  gce_MakePln gce_MP2(P0, P1, P2);
-  Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP2.Value());
-  
-  TopoDS_Vertex V0 = BRepBuilderAPI_MakeVertex(P0);
-  TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
-  TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
-  
-  TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(V0, V1);
-  TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(V0, V2);
 
-  Handle(AIS_AngleDimension) anIO =
-    new AIS_AngleDimension(anEdge1, anEdge2, aPlane, theAngle * M_PI / 180.,
-                           TCollection_ExtendedString(Angle_str.c_str()));
-    
-  anIO->SetArrowSize((theAngle * M_PI / 180) * (aLength/20));
-  
+  Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension( P1, P0, P2 );
+
+  anIO->SetCustomValue( theAngle );
+
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-  int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
-  Handle(Prs3d_AngleAspect) asp = new Prs3d_AngleAspect();
-  asp->LineAspect()->SetWidth(w);
-  anIO->Attributes()->SetAngleAspect(asp);
-  
+  int w = resMgr->integerValue( "Geometry", "measures_line_width", 1 );
+
+  Handle(Prs3d_DimensionAspect) aDimensionStyle = new Prs3d_DimensionAspect;
+
+  aDimensionStyle->ArrowAspect()->SetLength( (theAngle * M_PI / 180.0) * (aLength / 20.0) );
+  aDimensionStyle->LineAspect()->SetWidth( w );
+  aDimensionStyle->SetTextHorizontalPosition( Prs3d_DTHP_Center );
+  aDimensionStyle->SetTextVerticalPosition( Prs3d_DTVP_Center );
+  aDimensionStyle->MakeText3d( Standard_False );
+  aDimensionStyle->MakeArrows3d( Standard_True );
+
+  anIO->SetDimensionAspect( aDimensionStyle );
+
   return anIO;
 }