]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/MeasureGUI/MeasureGUI_AngleDlg.cxx
Salome HOME
Copyright update 2022
[modules/geom.git] / src / MeasureGUI / MeasureGUI_AngleDlg.cxx
index ccce76eb6e68852b3eb45b02345d292a4eec9ffc..4ace870c08792511872f08512c30cd2bc0c546fa 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
@@ -28,8 +28,6 @@
 #include <GEOMBase.h>
 #include <GeometryGUI.h>
 
-#include <Basics_OCCTVersion.hxx>
-
 #include <SUIT_Session.h>
 #include <SUIT_Desktop.h>
 #include <SUIT_ResourceMgr.h>
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 
+#include <Basics_OCCTVersion.hxx>
+
 // OCCT Includes
 #include <AIS_AngleDimension.hxx>
-#include <AIS_ListIteratorOfListOfInteractive.hxx>
+//#include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeVertex.hxx>
 #include <Geom_Plane.hxx>
 #include <gce_MakePln.hxx>
 #include <Precision.hxx>
+
+#if OCC_VERSION_LARGE >= 0x070400ff
+#include <PrsDim.hxx>
+#else
 #include <AIS.hxx>
-#include <AIS_Drawer.hxx>
+#endif
+
 #include <Prs3d_LineAspect.hxx> 
 #include <IntTools_EdgeEdge.hxx>
 #include <IntTools_SequenceOfCommonPrts.hxx>
@@ -113,7 +118,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();
@@ -136,7 +141,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;
@@ -149,7 +157,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();
 }
 
@@ -159,15 +167,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) {
-    aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
-  }
+  GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_EDGE );
 
   // clear selection
   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
@@ -177,12 +177,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();
   }
 
@@ -195,8 +195,8 @@ 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)) {
@@ -220,7 +220,7 @@ bool MeasureGUI_AngleDlg::getParameters (double& theAngle)
   if (isValid(msg)) {
     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
     try {
-      theAngle = anOper->GetAngle(myObj, myObj2);
+      theAngle = anOper->GetAngle(myObj.get(), myObj2.get());
     }
     catch(const SALOME::SALOME_Exception& e) {
       SalomeApp_Tools::QtCatchCorbaException(e);
@@ -262,7 +262,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()));
 
@@ -304,21 +304,20 @@ 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_LARGE > 0x06010000
       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);
 
@@ -332,19 +331,17 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
         Handle(Geom_Curve) extCurv;
         Standard_Integer extShape;
         Handle(Geom_Plane) aPlane;
-        if (AIS::ComputeGeometry(anEdge1,
-                                  anEdge2,
-                                  extShape,
-                                  geom_lin1,
-                                  geom_lin2,
-                                  ptat11,
-                                  ptat12,
-                                  ptat21,
-                                  ptat22,
-                                  extCurv,
-                                  isInfinite1,
-                                  isInfinite2,
-                                  aPlane)) {
+#if OCC_VERSION_LARGE >= 0x070400ff
+        if (PrsDim::ComputeGeometry (anEdge1, anEdge2,
+#else
+        if (AIS::ComputeGeometry    (anEdge1, anEdge2,
+#endif
+                                     extShape,
+                                     geom_lin1, geom_lin2,
+                                     ptat11, ptat12, ptat21, ptat22,
+                                     extCurv,
+                                     isInfinite1, isInfinite2,
+                                     aPlane)) {
           Standard_Real arrSize1 = aDimensionStyle->ArrowAspect()->Length();
           Standard_Real arrSize2 = aDimensionStyle->ArrowAspect()->Length();
           if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.;
@@ -363,9 +360,13 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
         aDimensionStyle->MakeArrows3d( Standard_True );
 
         anIO->SetDimensionAspect( aDimensionStyle );
-        anIO->SetDisplayUnits( aUnitsAngle.toLatin1().data() );
+        anIO->SetDisplayUnits( aUnitsAngle.toUtf8().data() );
         if (aUnitsAngle == "rad")
+#if OCC_VERSION_LARGE >= 0x070400ff
+          anIO->SetDisplaySpecialSymbol(PrsDim_DisplaySpecialSymbol_No);
+#else
           anIO->SetDisplaySpecialSymbol(AIS_DSS_No);
+#endif
 
         SOCC_Prs* aPrs =
           dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
@@ -381,14 +382,14 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
           anAngle *= 180. / M_PI;
           anAngleLabel = "GEOM_MEASURE_ANGLE_DEG";
         }
-        myGrp->TextLabel3->setText(tr(anAngleLabel.toLatin1().data()));
+        myGrp->TextLabel3->setText(tr(anAngleLabel.toUtf8().data()));
         int aPrecision = resMgr->integerValue( "Geometry", "angle_precision", 6 );
         myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(anAngle, aPrecision));
 
         return aPrs;
       }
     }
-    catch(Standard_Failure) {
+    catch(Standard_Failure&) {
     }
   }
 
@@ -401,5 +402,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( TopAbs_EDGE );
 }