Salome HOME
Porting to OCCT development version: Standard_PI -> M_PI
[modules/geom.git] / src / MeasureGUI / MeasureGUI_DistanceDlg.cxx
index f33a3415bddb389c9d85e78d2bb1111bed87155b..ecd82d3e35da0da7828446ab776b51c56a6530bd 100644 (file)
-//  GEOM GEOMGUI : GUI for Geometry component
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  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. 
-// 
-//  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 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// 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.
 //
+// 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
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//  File   : MeasureGUI_DistanceDlg.cxx
-//  Author : Nicolas REJNERI
-//  Module : GEOM
-//  $Header$
 
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : MeasureGUI_DistanceDlg.cxx
+// Author : Nicolas REJNERI, Open CASCADE S.A.S.
+//
 #include "MeasureGUI_DistanceDlg.h"
-
-#include "QAD_RightFrame.h"
-#include "OCCViewer_Viewer3d.h"
-
+#include "MeasureGUI_Widgets.h"
+
+#include <DlgRef.h>
+#include <GEOMBase.h>
+#include <GeometryGUI.h>
+
+#include <SUIT_Session.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_ViewWindow.h>
+#include <SUIT_ViewManager.h>
+#include <SOCC_Prs.h>
+#include <SOCC_ViewModel.h>
+#include <SalomeApp_Tools.h>
+#include <SalomeApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+
+// OCCT Includes
 #include <Geom_Plane.hxx>
-#include <TopoDS_Edge.hxx>
-#include <BRepExtrema_DistShapeShape.hxx>
 #include <AIS_LengthDimension.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeVertex.hxx>
-#include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <gce_MakePln.hxx>
 #include <Precision.hxx>
 
-#include "utilities.h"
-
-using namespace std;
-
 //=================================================================================
 // class    : MeasureGUI_DistanceDlg()
-// purpose  : Constructs a MeasureGUI_DistanceDlg which is a child of 'parent', with the 
+// purpose  : Constructs a MeasureGUI_DistanceDlg which is a child of 'parent', with the
 //            name 'name' and widget flags set to 'f'.
 //            The dialog will by default be modeless, unless you set 'modal' to
-//            TRUE to construct a modal dialog.
+//            true to construct a modal dialog.
 //=================================================================================
-MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
-  :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg (GeometryGUI* GUI, QWidget* parent)
+  : MeasureGUI_Skeleton(GUI, parent)
 {
-  QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MINDIST")));
-  QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
+  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+  QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MINDIST")));
+  QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
 
-  setCaption(tr("GEOM_MINDIST_TITLE"));
+  setWindowTitle(tr("GEOM_MINDIST_TITLE"));
 
   /***************************************************************/
-  GroupConstructors->setTitle(tr("GEOM_DISTANCE"));
-  RadioButton1->setPixmap(image0);
-
-  GroupC1 = new MeasureGUI_2Sel1LineEdit_QTD(this, "GroupC1");
-  GroupC1->GroupBox1->setTitle(tr("GEOM_MINDIST_OBJ"));
-  GroupC1->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
-  GroupC1->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
-  GroupC1->TextLabel3->setText(tr("GEOM_LENGTH"));
-  GroupC1->LineEdit3->setReadOnly(TRUE);
-  GroupC1->PushButton1->setPixmap(image1);
-  GroupC1->PushButton2->setPixmap(image1);
-
-  Layout1->addWidget(GroupC1, 1, 0);
+  mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISTANCE"));
+  mainFrame()->RadioButton1->setIcon(image0);
+
+  myGrp = new MeasureGUI_2Sel4LineEdit(centralWidget());
+  myGrp->GroupBox1->setTitle(tr("GEOM_MINDIST_OBJ"));
+  myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
+  myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
+  myGrp->TextLabel3->setText(tr("GEOM_LENGTH"));
+  myGrp->TextLabel4->setText(tr("GEOM_DX"));
+  myGrp->TextLabel5->setText(tr("GEOM_DY"));
+  myGrp->TextLabel6->setText(tr("GEOM_DZ"));
+  myGrp->LineEdit3->setReadOnly(true);
+  myGrp->PushButton1->setIcon(image1);
+  myGrp->PushButton2->setIcon(image1);
+  myGrp->LineEdit1->setReadOnly(true);
+  myGrp->LineEdit2->setReadOnly(true);
+  myGrp->LineEdit4->setReadOnly(true);
+  myGrp->LineEdit5->setReadOnly(true);
+  myGrp->LineEdit6->setReadOnly(true);
+
+  QVBoxLayout* layout = new QVBoxLayout(centralWidget());
+  layout->setMargin(0); layout->setSpacing(6);
+  layout->addWidget(myGrp);
   /***************************************************************/
 
-  /* Initialisation */
+  myHelpFileName = "using_measurement_tools_page.html#min_distance_anchor";
+
+  // Initialisation
   Init();
 }
 
-
 //=================================================================================
 // function : ~MeasureGUI_DistanceDlg()
 // purpose  : Destroys the object and frees any allocated resources
 //=================================================================================
 MeasureGUI_DistanceDlg::~MeasureGUI_DistanceDlg()
-{  
-  /* no need to delete child widgets, Qt does it all for us */
+{
 }
 
-
 //=================================================================================
 // function : Init()
 // purpose  :
 //=================================================================================
 void MeasureGUI_DistanceDlg::Init()
 {
-  /* init variables */
-  myEditCurrentArgument = GroupC1->LineEdit1;
+  // init variables
+  myGrp->LineEdit1->setText("");
+  myGrp->LineEdit2->setText("");
+  myObj = myObj2 = GEOM::GEOM_Object::_nil();
 
-  myOkShape1 = myOkShape2 = false;
+  mySelBtn   = myGrp->PushButton1;
+  mySelEdit  = myGrp->LineEdit1;
 
-   /* signals and slots connections */
-  connect(buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
-  connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
-  connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
+  myEditCurrentArgument = myGrp->LineEdit1;
 
-  connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-  connect(GroupC1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
+  // signals and slots connections
+  connect(myGrp->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
+  connect(myGrp->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
 
-  connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
-  connect(GroupC1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+  MeasureGUI_Skeleton::Init();
+}
 
-  connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+//=================================================================================
+// function : SelectionIntoArgument()
+// purpose  : Called when selection has changed
+//=================================================================================
+void MeasureGUI_DistanceDlg::SelectionIntoArgument()
+{
+  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+  SALOME_ListIO aSelList;
+  aSelMgr->selectedObjects(aSelList);
 
-  /* displays Dialog */
-  GroupC1->show();
-  this->show();
+  GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
 
-  return;
-}
+  if (aSelList.Extent() > 0) {
+    aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
+  }
+
+  // clear selection
+  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
+  myGeomGUI->getApp()->selectionMgr()->clearSelected();
+  connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+          this, SLOT(SelectionIntoArgument()));
+
+  if (myEditCurrentArgument == myGrp->LineEdit1) {
+    myObj = aSelectedObject;
+    if (!myObj->_is_nil() && myObj2->_is_nil())
+      myGrp->PushButton2->click();
+  }
+  else {
+    myObj2 = aSelectedObject;
+    if (!myObj2->_is_nil() && myObj->_is_nil())
+      myGrp->PushButton1->click();
+  }
 
+  processObject();
+}
 
 //=================================================================================
-// function : ClickOnCancel()
-// purpose  :
+// function : processObject()
+// purpose  : Fill dialogs fields in accordance with myObj and myObj2
 //=================================================================================
-void MeasureGUI_DistanceDlg::ClickOnCancel()
+void MeasureGUI_DistanceDlg::processObject()
 {
-  this->EraseDistance();
-  MeasureGUI_Skeleton::ClickOnCancel();
-  return;
-}
+  myGrp->LineEdit1->setText(!myObj->_is_nil()  ? GEOMBase::GetName(myObj ) : "");
+  myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : "");
+
+  gp_Pnt aPnt1, aPnt2;
+  double aDist = 0.;
+  if (getParameters(aDist, aPnt1, aPnt2)) {
+    SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+    int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
+
+    myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(aDist, aPrecision));
 
+    gp_XYZ aVec = aPnt2.XYZ() - aPnt1.XYZ();
+    myGrp->LineEdit4->setText(DlgRef::PrintDoubleValue(aVec.X(), aPrecision));
+    myGrp->LineEdit5->setText(DlgRef::PrintDoubleValue(aVec.Y(), aPrecision));
+    myGrp->LineEdit6->setText(DlgRef::PrintDoubleValue(aVec.Z(), aPrecision));
+
+    redisplayPreview();
+  }
+  else {
+    myGrp->LineEdit3->setText("");
+    myGrp->LineEdit4->setText("");
+    myGrp->LineEdit5->setText("");
+    myGrp->LineEdit6->setText("");
+    erasePreview();
+  }
+}
 
 //=================================================================================
-// function : SelectionIntoArgument()
-// purpose  : Called when selection has changed
+// function : getParameters()
+// purpose  : Get distance between objects
 //=================================================================================
-void MeasureGUI_DistanceDlg::SelectionIntoArgument()
+bool MeasureGUI_DistanceDlg::getParameters (double& theDistance,
+                                            gp_Pnt& thePnt1,
+                                            gp_Pnt& thePnt2)
 {
-  myGeomBase->EraseSimulationShape();
-  mySimulationTopoDs.Nullify();
-  this->EraseDistance();
-  myEditCurrentArgument->setText("");
-  QString aString = "";
-
-  GroupC1->LineEdit3->setText("");
-
-  int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
-  if(nbSel != 1) {
-    if(myEditCurrentArgument == GroupC1->LineEdit1)
-      myOkShape1 = false;
-    else if(myEditCurrentArgument == GroupC1->LineEdit2)
-      myOkShape2 = false;
-    return;
-  }
+  QString msg;
+  if (isValid(msg)) {
+    GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
+
+    try {
+      double x1, y1, z1, x2, y2, z2;
+      theDistance = anOper->GetMinDistance(myObj, myObj2, x1, y1, z1, x2, y2, z2);
 
-  /*  nbSel == 1  */
-  TopoDS_Shape S;
-  if(!myGeomBase->GetTopoFromSelection(mySelection, S))
-    return;
-
-  Standard_Boolean testResult;
-  Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
-  
-  if(myEditCurrentArgument == GroupC1->LineEdit1) {
-    myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
-    if(!testResult)
-      return;
-    myShape1 = S;
-    myEditCurrentArgument->setText(aString);
-    myOkShape1 = true;
-  }    
-  else if(myEditCurrentArgument == GroupC1->LineEdit2) {
-    myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
-    if(!testResult)
-      return;
-    myShape2 = S;
-    myEditCurrentArgument->setText(aString);
-    myOkShape2 = true;
+      thePnt1.SetCoord(x1, y1, z1);
+      thePnt2.SetCoord(x2, y2, z2);
+    }
+    catch(const SALOME::SALOME_Exception& e) {
+      SalomeApp_Tools::QtCatchCorbaException(e);
+      return false;
+    }
+
+    return anOper->IsDone();
   }
 
-  if(myOkShape1 && myOkShape2)
-    this->MakeDistanceSimulationAndDisplay(myShape1 ,myShape2);
-  return; 
+  return false;
 }
 
-
 //=================================================================================
 // function : SetEditCurrentArgument()
 // purpose  :
@@ -197,19 +236,28 @@ void MeasureGUI_DistanceDlg::SetEditCurrentArgument()
 {
   QPushButton* send = (QPushButton*)sender();
 
-  if(send == GroupC1->PushButton1) {
-    GroupC1->LineEdit1->setFocus();
-    myEditCurrentArgument = GroupC1->LineEdit1;
+  if (send == myGrp->PushButton1) {
+    myEditCurrentArgument = myGrp->LineEdit1;
+
+    myGrp->PushButton2->setDown(false);
+    myGrp->LineEdit2->setEnabled(false);
   }
-  else if(send == GroupC1->PushButton2) {
-    GroupC1->LineEdit2->setFocus();
-    myEditCurrentArgument = GroupC1->LineEdit2;
+  else {
+    myEditCurrentArgument = myGrp->LineEdit2;
+
+    myGrp->PushButton1->setDown(false);
+    myGrp->LineEdit1->setEnabled(false);
   }
 
-  this->SelectionIntoArgument();
-  return;
-}
+  // enable line edit
+  myEditCurrentArgument->setEnabled(true);
+  myEditCurrentArgument->setFocus();
+  // after setFocus(), because it will be setDown(false) when loses focus
+  send->setDown(true);
 
+  // seems we need it only to avoid preview disappearing, caused by selection mode change
+  redisplayPreview();
+}
 
 //=================================================================================
 // function : LineEditReturnPressed()
@@ -218,156 +266,86 @@ void MeasureGUI_DistanceDlg::SetEditCurrentArgument()
 void MeasureGUI_DistanceDlg::LineEditReturnPressed()
 {
   QLineEdit* send = (QLineEdit*)sender();
-  if(send == GroupC1->LineEdit1)
-    myEditCurrentArgument = GroupC1->LineEdit1;
-  else if(send == GroupC1->LineEdit2)
-    myEditCurrentArgument = GroupC1->LineEdit2;
-  else
-    return;
-
-  MeasureGUI_Skeleton::LineEditReturnPressed();
-  return;
-}
 
+  if (send == myGrp->LineEdit1 || send == myGrp->LineEdit2) {
+    myEditCurrentArgument = send;
+
+    LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+    SALOME_ListIO aSelList;
+    aSelMgr->selectedObjects(aSelList);
+
+    if (GEOMBase::SelectionByNameInDialogs(this, myGrp->LineEdit1->text(), aSelList))
+      myGrp->LineEdit1->setText(myGrp->LineEdit1->text());
+  }
+}
 
 //=================================================================================
-// function : ActivateThisDialog()
+// function : buildPrs()
 // purpose  :
 //=================================================================================
-void MeasureGUI_DistanceDlg::ActivateThisDialog()
+SALOME_Prs* MeasureGUI_DistanceDlg::buildPrs()
 {
-  MeasureGUI_Skeleton::ActivateThisDialog();
-  connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
-  if(!mySimulationTopoDs.IsNull())
-    myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
-  return;
-}
+  double aDist = 0.;
+  gp_Pnt aPnt1(0, 0, 0), aPnt2(0, 0, 0);
 
+  SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
 
-//=================================================================================
-// function : enterEvent()
-// purpose  : when mouse enter onto the QWidget
-//=================================================================================
-void MeasureGUI_DistanceDlg::enterEvent(QEvent* e)
-{
-  if(GroupConstructors->isEnabled())
-    return;
-  this->ActivateThisDialog();
-  return;
-}
+  if (myObj->_is_nil() || myObj2->_is_nil() ||
+       !getParameters(aDist, aPnt1, aPnt2) ||
+       vw->getViewManager()->getType() != OCCViewer_Viewer::Type())
+    return 0;
+
+  try
+  {
+    if (aDist <= 1.e-9) {
+      BRepBuilderAPI_MakeVertex aMaker(aPnt1);
+      return getDisplayer()->BuildPrs(aMaker.Vertex());
+    }
+    else {
+      BRepBuilderAPI_MakeEdge MakeEdge(aPnt1, aPnt2);
+      TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(aPnt1);
+      TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(aPnt2);
 
+      QString aLabel;
+      aLabel.sprintf("%.1f", aDist);
 
-//=================================================================================
-// function : closeEvent()
-// purpose  :
-//=================================================================================
-void MeasureGUI_DistanceDlg::closeEvent(QCloseEvent* e)
-{
-  /* same than click on cancel button */
-  this->ClickOnCancel();
-  return;
-}
+      gp_Pnt aPnt3((aPnt1.X() + aPnt2.X()) / 2,
+                    (aPnt1.Y() + aPnt2.Y()) / 2,
+                    (aPnt1.Z() + aPnt2.Z()) / 2);
 
+      gp_Vec va(aPnt3, aPnt1);
+      gp_Vec vb(aPnt3, aPnt2);
 
-//=================================================================================
-// function : MakeDistanceSimulationAndDisplay()
-// purpose  :
-//=================================================================================
-void MeasureGUI_DistanceDlg::MakeDistanceSimulationAndDisplay(const TopoDS_Shape& S1, const TopoDS_Shape& S2) 
-{
-  myGeomBase->EraseSimulationShape();
-  mySimulationTopoDs.Nullify();
-  GroupC1->LineEdit3->setText("");
-  
-  BRepExtrema_DistShapeShape dst(S1, S2);
-
-  try {
-    if(dst.IsDone()) {
-      gp_Pnt P1, P2;
-      Standard_Real Dist = 1.e9;
-      for(int i = 1; i <= dst.NbSolution(); i++) {
-       P1 = (dst.PointOnShape1(i));
-       P2 = (dst.PointOnShape2(i));
-
-       Standard_Real MinDist = P1.Distance(P2);
-       if(Dist > MinDist)
-         Dist = MinDist;
+      if (va.IsParallel(vb, Precision::Angular())) {
+        aPnt3.SetY((aPnt1.Y() + aPnt2.Y()) / 2 + 100);
+        aPnt3.SetZ((aPnt1.Z() + aPnt2.Z()) / 2);
       }
 
-      if(Dist <= 1.e-9) {
-       BRepBuilderAPI_MakeVertex MakeVertex(P1);
-       mySimulationTopoDs = MakeVertex.Vertex();
-       myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
-
-       GroupC1->LineEdit3->setText("0.0");
-      } 
-      else {
-       BRepBuilderAPI_MakeEdge MakeEdge(P1, P2);
-       mySimulationTopoDs = MakeEdge.Edge();
-
-       TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
-       TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
-
-       QString S;
-       S.sprintf("%.1f", Dist);
-
-       gp_Pnt P3;
-       P3.SetX((P1.X() + P2.X()) / 2);
-       P3.SetY((P1.Y() + P2.Y()) / 2);
-       P3.SetZ(((P1.Z() + P2.Z()) / 2) + 100);
-       gp_Vec va(P3, P1);
-       gp_Vec vb(P3, P2);
-       if(va.IsParallel(vb, Precision::Angular())) {
-         P3.SetY(((P1.Y() + P2.Y()) / 2) + 100);
-         P3.SetZ(((P1.Z() + P2.Z()) / 2));
-       }
-       gce_MakePln gce_MP(P1, P2, P3);
-       gp_Pln gp_P = gce_MP.Value();
-       Handle(Geom_Plane) P = new Geom_Plane(gp_P);
-
-       char* aCopyS = CORBA::string_dup(S);
-       Handle(AIS_LengthDimension) Distance = new AIS_LengthDimension(V1, V2, P, Dist, TCollection_ExtendedString(aCopyS));
-       delete(aCopyS);
-
-       GroupC1->LineEdit3->setText(S);
-
-       if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
-         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
-         Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
-         ic->Display(Distance);
-         ic->UpdateCurrentViewer();
-       }
-      }
+      gce_MakePln gce_MP(aPnt1, aPnt2, aPnt3);
+      Handle(Geom_Plane) P = new Geom_Plane(gce_MP.Value());
+
+      Handle(AIS_LengthDimension) anIO = new AIS_LengthDimension(
+        aVert1, aVert2, P, aDist, TCollection_ExtendedString((Standard_CString)aLabel.toLatin1().constData()));
+      anIO->SetArrowSize(aDist/20);
+
+      SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
+
+      if (aPrs)
+        aPrs->AddObject(anIO);
+
+      return aPrs;
     }
   }
   catch(Standard_Failure) {
-    MESSAGE("Catch intercepted in MakeDistanceSimulationAndDisplay()");
+    return 0;
   }
-  return;
 }
 
-
 //=================================================================================
-// function : EraseDistance()
+// function : isValid()
 // purpose  :
 //=================================================================================
-void MeasureGUI_DistanceDlg::EraseDistance()
+bool MeasureGUI_DistanceDlg::isValid (QString& msg)
 {
-  int count = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
-  for(int i = 0; i < count; i++) {
-    if (QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC ) {
-      OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
-      Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
-
-      AIS_ListOfInteractive L;
-      ic->DisplayedObjects(AIS_KOI_Relation, -1, L);
-      AIS_ListIteratorOfListOfInteractive ite(L);
-      while (ite.More()) {
-       ic->Remove(ite.Value());
-       ic->UpdateCurrentViewer();
-       ite.Next();
-      }
-    }
-  }
-  return;
+  return MeasureGUI_Skeleton::isValid(msg) && !myObj2->_is_nil();
 }