Salome HOME
0023115: [CEA 1545] Regression on KindOfShape method
[modules/geom.git] / src / MeasureGUI / MeasureGUI_AngleDlg.cxx
index 6c6cff6482eae7a6ed1c0b55858107fa7df83039..64c51cc78b4d3213e4a9320e4ebcc8304b05b578 100644 (file)
@@ -1,28 +1,26 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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, or (at your option) any later version.
 //
-//  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.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-//
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // GEOM GEOMGUI : GUI for Geometry component
-//  File   : MeasureGUI_AngleDlg.cxx
-//  Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
-//
+// File   : MeasureGUI_AngleDlg.cxx
+// Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
+
 #include "MeasureGUI_AngleDlg.h"
 #include "MeasureGUI_Widgets.h"
 
@@ -30,6 +28,8 @@
 #include <GEOMBase.h>
 #include <GeometryGUI.h>
 
+#include <Basics_OCCTVersion.hxx>
+
 #include <SUIT_Session.h>
 #include <SUIT_Desktop.h>
 #include <SUIT_ResourceMgr.h>
 #include <gce_MakePln.hxx>
 #include <Precision.hxx>
 #include <AIS.hxx>
+#include <Prs3d_LineAspect.hxx> 
+#include <IntTools_EdgeEdge.hxx>
+#include <IntTools_SequenceOfCommonPrts.hxx>
+#include <IntTools_CommonPrt.hxx>
 
 // QT Includes
 #include <qlineedit.h>
@@ -95,7 +99,7 @@ MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent)
   myGrp->GroupBox1->setTitle(tr("GEOM_MEASURE_ANGLE_OBJ"));
   myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
   myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
-  myGrp->TextLabel3->setText(tr("GEOM_MEASURE_ANGLE_IS"));
+  myGrp->TextLabel3->setText(tr(aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" ) == "deg" ? "GEOM_MEASURE_ANGLE_DEG" : "GEOM_MEASURE_ANGLE_RAD"));
   myGrp->LineEdit3->setReadOnly(true);
   myGrp->PushButton1->setIcon(image1);
   myGrp->PushButton2->setIcon(image1);
@@ -108,7 +112,7 @@ MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent)
   /***************************************************************/
 
   // Help page reference
-  myHelpFileName = "using_measurement_tools_page.html#angle_anchor";
+  myHelpFileName = "angle_page.html";
 
   // Initialisation
   Init();
@@ -131,7 +135,10 @@ void MeasureGUI_AngleDlg::Init()
   // init variables
   myGrp->LineEdit1->setText("");
   myGrp->LineEdit2->setText("");
-  myObj = myObj2 = GEOM::GEOM_Object::_nil();
+  myGrp->LineEdit1->setEnabled(true);
+  myGrp->LineEdit2->setEnabled(false);
+  myObj.nullify();
+  myObj2.nullify();
 
   mySelBtn   = myGrp->PushButton1;
   mySelEdit  = myGrp->LineEdit1;
@@ -144,7 +151,7 @@ void MeasureGUI_AngleDlg::Init()
   connect(mySelEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
   connect(mySelBtn2,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
 
-  globalSelection(GEOM_LINE);
+  activateSelection();  
   MeasureGUI_Skeleton::Init();
 }
 
@@ -154,18 +161,7 @@ void MeasureGUI_AngleDlg::Init()
 //=================================================================================
 void MeasureGUI_AngleDlg::SelectionIntoArgument()
 {
-  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
-  SALOME_ListIO aSelList;
-  aSelMgr->selectedObjects(aSelList);
-
-  GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
-
-  if (aSelList.Extent() > 0) {
-    Standard_Boolean testResult = Standard_False;
-    aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
-    if (!testResult)
-      aSelectedObject = GEOM::GEOM_Object::_nil();
-  }
+  GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_EDGE );
 
   // clear selection
   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
@@ -175,12 +171,12 @@ void MeasureGUI_AngleDlg::SelectionIntoArgument()
 
   if (myEditCurrentArgument == mySelEdit) {
     myObj = aSelectedObject;
-    if (!myObj->_is_nil() && myObj2->_is_nil())
+    if (myObj && !myObj2)
       myGrp->PushButton2->click();
   }
   else {
     myObj2 = aSelectedObject;
-    if (!myObj2->_is_nil() && myObj->_is_nil())
+    if (myObj2 && !myObj)
       myGrp->PushButton1->click();
   }
 
@@ -193,12 +189,13 @@ void MeasureGUI_AngleDlg::SelectionIntoArgument()
 //=================================================================================
 void MeasureGUI_AngleDlg::processObject()
 {
-  myGrp->LineEdit1->setText(!myObj->_is_nil()  ? GEOMBase::GetName(myObj ) : "");
-  myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : "");
+  myGrp->LineEdit1->setText(myObj  ? GEOMBase::GetName(myObj.get()) : "");
+  myGrp->LineEdit2->setText(myObj2 ? GEOMBase::GetName(myObj2.get()) : "");
 
   double anAngle = 0.;
   if (getParameters(anAngle)) {
-    myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(anAngle));
+    // To avoid the using different angle values in viewer and dialog,
+    // the value from presentation is used in both cases (see buildPrs())
     redisplayPreview();
   }
   else {
@@ -215,17 +212,18 @@ bool MeasureGUI_AngleDlg::getParameters (double& theAngle)
 {
   QString msg;
   if (isValid(msg)) {
+    GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
     try {
-      theAngle = GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetAngle(myObj, myObj2);
+      theAngle = anOper->GetAngle(myObj.get(), myObj2.get());
     }
     catch(const SALOME::SALOME_Exception& e) {
       SalomeApp_Tools::QtCatchCorbaException(e);
       return false;
     }
 
-    bool isDone = getOperation()->IsDone();
+    bool isDone = anOper->IsDone();
     if (!isDone) {
-      CORBA::String_var aMsg = getOperation()->GetErrorCode();
+      CORBA::String_var aMsg = anOper->GetErrorCode();
       SUIT_MessageBox::warning(this,
                                QObject::tr("WRN_WARNING"),
                                QObject::tr(aMsg.in()));
@@ -258,7 +256,7 @@ void MeasureGUI_AngleDlg::SetEditCurrentArgument()
   }
 
   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
-  globalSelection(GEOM_LINE);
+  activateSelection();
   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
           this, SLOT(SelectionIntoArgument()));
 
@@ -300,63 +298,33 @@ void MeasureGUI_AngleDlg::LineEditReturnPressed()
 SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
 {
   double anAngle = 0.;
+  myGrp->LineEdit3->setText("");
 
   SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
 
-  if (myObj->_is_nil() || myObj2->_is_nil() || !getParameters(anAngle) ||
+  if (!myObj || !myObj2 || !getParameters(anAngle) ||
        vw->getViewManager()->getType() != OCCViewer_Viewer::Type())
     return 0;
 
   if (anAngle > Precision::Angular()) {
     try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
       OCC_CATCH_SIGNALS;
-#endif
       TopoDS_Shape S1, S2;
-      if (GEOMBase::GetShape(myObj , S1, TopAbs_EDGE) &&
-           GEOMBase::GetShape(myObj2, S2, TopAbs_EDGE)) {
+      if (GEOMBase::GetShape(myObj.get() , S1, TopAbs_EDGE) &&
+        GEOMBase::GetShape(myObj2.get(), S2, TopAbs_EDGE)) {
         TopoDS_Edge anEdge1 = TopoDS::Edge(S1);
         TopoDS_Edge anEdge2 = TopoDS::Edge(S2);
 
-        // Build a plane for angle dimension presentation {P11, P12, P3}
-        TopoDS_Vertex V11, V12, V21, V22;
-        TopExp::Vertices(anEdge1, V11, V12);
-        TopExp::Vertices(anEdge2, V21, V22);
-
-        gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
-        gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge1));
-
-        gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
-        gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge2));
-
-        //        *P3
-        //         \
-        //          \
-        //           *P22
-        //          /
-        //         /
-        // P11    /         P12
-        // *-----/----------*
-        //  \   /
-        //   \ /
-        //    *P21
-        gp_Pnt aP3 (aP22.XYZ() + aP11.XYZ() - aP21.XYZ());
-
-        gce_MakePln gce_MP(aP11, aP12, aP3);
-        Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
-
-        // Build the angle dimension presentation
-        QString aLabel;
-        aLabel.sprintf("%.1f", anAngle);
-
-        Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension
-          (anEdge1, anEdge2, aPlane, anAngle * PI180,
-            TCollection_ExtendedString((Standard_CString)aLabel.toLatin1().data()));
+        Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension( anEdge1, anEdge2 );
+
+        Handle(Prs3d_DimensionAspect) aDimensionStyle = new Prs3d_DimensionAspect;
+
         Handle(Geom_Line) geom_lin1,geom_lin2;
         gp_Pnt ptat11,ptat12,ptat21,ptat22;
         Standard_Boolean isInfinite1,isInfinite2;
         Handle(Geom_Curve) extCurv;
         Standard_Integer extShape;
+        Handle(Geom_Plane) aPlane;
         if (AIS::ComputeGeometry(anEdge1,
                                   anEdge2,
                                   extShape,
@@ -370,20 +338,46 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
                                   isInfinite1,
                                   isInfinite2,
                                   aPlane)) {
-          Standard_Real arrSize1 = anIO->ArrowSize();
-          Standard_Real arrSize2 = anIO->ArrowSize();
+          Standard_Real arrSize1 = aDimensionStyle->ArrowAspect()->Length();
+          Standard_Real arrSize2 = aDimensionStyle->ArrowAspect()->Length();
           if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.;
           if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.;
-          Standard_Real arrowSize = Max(arrSize1,arrSize2);
-          anIO->SetArrowSize(arrowSize);
+          aDimensionStyle->ArrowAspect()->SetLength( Max(arrSize1, arrSize2) );
         }
 
+        SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+        int w = resMgr->integerValue( "Geometry", "measures_line_width", 1 );
+        QString aUnitsAngle = resMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
+
+        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 );
+        anIO->SetDisplayUnits( aUnitsAngle.toLatin1().data() );
+        if (aUnitsAngle == "rad")
+          anIO->SetDisplaySpecialSymbol(AIS_DSS_No);
+
         SOCC_Prs* aPrs =
           dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
 
         if (aPrs)
           aPrs->AddObject(anIO);
 
+        // set angle value into dialog
+        double anAngle = anIO->GetValue();
+        QString anAngleLabel = "GEOM_MEASURE_ANGLE_RAD";
+        if (aUnitsAngle == "deg") {
+          // using degrees instead of radians
+          anAngle *= 180. / M_PI;
+          anAngleLabel = "GEOM_MEASURE_ANGLE_DEG";
+        }
+        myGrp->TextLabel3->setText(tr(anAngleLabel.toLatin1().data()));
+        int aPrecision = resMgr->integerValue( "Geometry", "angle_precision", 6 );
+        myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(anAngle, aPrecision));
+
         return aPrs;
       }
     }
@@ -400,5 +394,15 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
 //=================================================================================
 bool MeasureGUI_AngleDlg::isValid (QString& msg)
 {
-  return MeasureGUI_Skeleton::isValid(msg) && !myObj2->_is_nil();
+  return MeasureGUI_Skeleton::isValid(msg) && myObj2;
+}
+
+//=================================================================================
+// function : activateSelection()
+// purpose  :
+//=================================================================================
+void MeasureGUI_AngleDlg::activateSelection()
+{
+  globalSelection(GEOM_LINE);
+  localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
 }