]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Lot 1 (linear&poly distance)
authorisn <isn@opencascade.com>
Fri, 28 Sep 2018 17:38:31 +0000 (20:38 +0300)
committerisn <isn@opencascade.com>
Mon, 8 Oct 2018 11:03:00 +0000 (14:03 +0300)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_MeasurementToolDlg.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_MeasurementToolDlg.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_MeasurementToolOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_MeasurementToolOp.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/resources/HYDROGUI_images.ts
src/HYDROGUI/resources/HYDROGUI_msg_en.ts
src/HYDROGUI/resources/icon_meas_tools.png [new file with mode: 0644]

index 5d7211b2b0cd953eef126dec764d9f869a642ce6..683a4e8bc9986344ec87f3bf1ef99b654582c070 100644 (file)
@@ -157,6 +157,8 @@ set(PROJECT_HEADERS
     HYDROGUI_ShowAttrPolyOp.h
     HYDROGUI_SetBoundaryTypePolygonOp.h
     HYDROGUI_SetBoundaryTypePolygonDlg.h
+    HYDROGUI_MeasurementToolOp.h
+    HYDROGUI_MeasurementToolDlg.h
 )
 
 QT_WRAP_MOC(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
@@ -316,6 +318,8 @@ set(PROJECT_SOURCES
     HYDROGUI_ShowAttrPolyOp.cxx
     HYDROGUI_SetBoundaryTypePolygonOp.cxx
     HYDROGUI_SetBoundaryTypePolygonDlg.cxx
+    HYDROGUI_MeasurementToolOp.cxx
+    HYDROGUI_MeasurementToolDlg.cxx
 )
 
 add_definitions(
diff --git a/src/HYDROGUI/HYDROGUI_MeasurementToolDlg.cxx b/src/HYDROGUI/HYDROGUI_MeasurementToolDlg.cxx
new file mode 100644 (file)
index 0000000..a623a7b
--- /dev/null
@@ -0,0 +1,131 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// 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 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
+//
+
+#include "HYDROGUI_MeasurementToolDlg.h"
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QLineEdit>
+
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
+#include <CurveCreator_Utils.hxx>
+#include <SUIT_ViewWindow.h>
+#include <QMouseEvent>
+#include <gp_Pnt.hxx>
+#include <QTableWidget>
+#include <QGroupBox>
+#include <QFormLayout>
+#include <QLabel>
+#include <QComboBox>
+
+#include <QRadioButton>
+#include <QStringList>
+
+
+HYDROGUI_MeasurementToolDlg::HYDROGUI_MeasurementToolDlg( QWidget* theParent )
+  : QDialog( theParent ), myExit (false)
+{  
+  QFormLayout* aMLayout = new QFormLayout( this );
+
+  mySwitcherLD = new QRadioButton(tr("LINEAR_DISTANCE"));
+  QRadioButton* aSwitcherPD = new QRadioButton(tr("POLYLINE_DISTANCE"));
+
+  myPolylinesCBox = new QComboBox( this );
+
+  aMLayout->addRow(mySwitcherLD);
+  aMLayout->addRow(aSwitcherPD, myPolylinesCBox);
+
+  myTotalDst = new QLineEdit( this );
+  myTotalDst->setReadOnly(true);
+
+  aMLayout->addRow(new QLabel(tr("TOTAL_DST")), myTotalDst);
+
+  QPushButton* aClearButton = new QPushButton( tr("CLEAR") );
+
+  QPushButton* aCloseButton = new QPushButton( tr("CLOSE"), this );
+
+  QGroupBox* aPolyLenGroup = new QGroupBox(tr("POLYLINES_LENGTH"));
+  QVBoxLayout* aPolyLayout = new QVBoxLayout( aPolyLenGroup );
+
+  aMLayout->addRow(aClearButton, aCloseButton);
+  ////
+  connect( aClearButton, SIGNAL( clicked() ), this, SLOT( onClear () ) );
+  connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
+  connect( this, SIGNAL( rejected() ), this, SLOT( onExit () ) );
+  connect( mySwitcherLD, SIGNAL( toggled(bool) ), this, SLOT( onSetMode (bool) ) );
+  connect( myPolylinesCBox, SIGNAL( currentIndexChanged(int) ), this, SLOT( onClear () ) );
+
+  mySwitcherLD->setChecked(true);
+
+  setLayout(aMLayout);
+}
+
+HYDROGUI_MeasurementToolDlg::~HYDROGUI_MeasurementToolDlg()
+{
+}
+
+void HYDROGUI_MeasurementToolDlg::setTotalDst(QString strVal)
+{
+  myTotalDst->setText(strVal);
+}
+
+bool HYDROGUI_MeasurementToolDlg::IsLDChecked() const
+{
+  return mySwitcherLD->isChecked();
+}
+
+void HYDROGUI_MeasurementToolDlg::setPolylineNames(QStringList thePolyNames)
+{
+  myPolylinesCBox->clear();
+  foreach (QString aName, thePolyNames)
+    myPolylinesCBox->addItem(aName);
+}
+
+int HYDROGUI_MeasurementToolDlg::currentSelectedPolyline() const
+{
+  return myPolylinesCBox->currentIndex();
+}
+
+bool HYDROGUI_MeasurementToolDlg::GetExitFlag() const
+{
+  return myExit;
+}
+
+void HYDROGUI_MeasurementToolDlg::onExit()
+{
+  myExit = true;
+  emit doExit();
+}
+
+void HYDROGUI_MeasurementToolDlg::onClear()
+{
+  emit clearLine();
+}
+
+void HYDROGUI_MeasurementToolDlg::onSetMode(bool mode)
+{
+  emit onClear();
+  if (mode)
+    myPolylinesCBox->setDisabled(true);
+  else
+    myPolylinesCBox->setDisabled(false);
+}
+
+
+
diff --git a/src/HYDROGUI/HYDROGUI_MeasurementToolDlg.h b/src/HYDROGUI/HYDROGUI_MeasurementToolDlg.h
new file mode 100644 (file)
index 0000000..177402a
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// 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 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
+//
+
+
+
+#ifndef HYDROGUI_MEASUREMENTTOOLDLG_H
+#define HYDROGUI_MEASUREMENTTOOLDLG_H
+
+#include <QDialog>
+#include <QStringList>
+
+class QLineEdit;
+class QRadioButton;
+class QComboBox;
+
+class HYDROGUI_MeasurementToolDlg : public QDialog
+{
+  Q_OBJECT
+
+public:
+
+  HYDROGUI_MeasurementToolDlg( QWidget* theParent );
+  virtual ~HYDROGUI_MeasurementToolDlg();
+
+  void setTotalDst(QString strVal);
+  int currentSelectedPolyline() const;
+  bool GetExitFlag() const;
+  bool IsLDChecked() const;
+  void setPolylineNames(QStringList thePolyNames);
+
+private slots:
+  void onClear();  
+  void onSetMode(bool mode);
+  void onExit();
+
+signals:
+  void clearLine();
+  void doExit();
+
+private:
+
+  bool myExit;
+  QLineEdit* myTotalDst;
+  QRadioButton* mySwitcherLD;
+  QComboBox* myPolylinesCBox;
+};
+
+#endif
diff --git a/src/HYDROGUI/HYDROGUI_MeasurementToolOp.cxx b/src/HYDROGUI/HYDROGUI_MeasurementToolOp.cxx
new file mode 100644 (file)
index 0000000..f0fd354
--- /dev/null
@@ -0,0 +1,384 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// 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 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
+//
+
+#include "HYDROGUI_MeasurementToolOp.h"
+
+#include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_Module.h"
+
+#include <HYDROData_Object.h>
+#include <HYDROData_IPolyline.h>
+
+#include <LightApp_Application.h>
+
+#include <SUIT_Desktop.h>
+#include <HYDROGUI_Tool2.h>
+#include <HYDROGUI_MeasurementToolDlg.h>
+#include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewPort3d.h>
+#include <OCCViewer_ViewWindow.h>
+#include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Compound.hxx>
+#include <AIS_Shape.hxx>
+#include <CurveCreator_Utils.hxx>
+#include <QMouseEvent>
+#include <TopExp.hxx>
+#include <HYDROData_Iterator.h>
+#include <HYDROData_PolylineXY.h>
+#include <GCPnts_AbscissaPoint.hxx>
+#include <TopExp_Explorer.hxx>
+#include <BRepAdaptor_Curve.hxx>
+#include <TopoDS.hxx>
+#include <vector>
+#include <utility>
+#include <Prs3d_Drawer.hxx>
+#include <BRepAlgo.hxx>
+#include <BRepAdaptor_Curve.hxx>
+#include <BRepLib_MakeEdge.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
+#include <BRepLib_MakePolygon.hxx>
+
+
+HYDROGUI_MeasurementToolOp::HYDROGUI_MeasurementToolOp( HYDROGUI_Module* theModule )
+  : HYDROGUI_Operation( theModule ),
+  myMeasDlg(0),
+  myLineMaker(NULL),
+  myAISLineM(NULL),
+  myDist(0),
+ // myFAd(NULL),
+  myFu(0)
+{
+  setName( tr( "MEASUREMENT_TOOL" ) );
+}
+
+HYDROGUI_MeasurementToolOp::~HYDROGUI_MeasurementToolOp()
+{
+  if (myLineMaker)
+    delete myLineMaker;
+}
+
+void HYDROGUI_MeasurementToolOp::startOperation()
+{
+  HYDROGUI_Operation::startOperation();
+
+  myMeasDlg = new HYDROGUI_MeasurementToolDlg( module()->getApp()->desktop() );
+  myMeasDlg->setModal( false );
+  myMeasDlg->setWindowTitle(getName());
+  myMeasDlg->show(); 
+
+  //Tool: draw a distance line
+  LightApp_Application* anApp = module()->getApp();
+  OCCViewer_ViewManager* aViewManager =
+    dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
+
+  setPreviewManager( aViewManager );
+
+  connect( myMeasDlg, SIGNAL( clearLine() ), this, SLOT( onClearLine() ) );
+
+  connect( myMeasDlg, SIGNAL( doExit() ), this, SLOT( onExit() ) );
+
+  OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
+
+  disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+    aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+  connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+    this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+
+  //polyline names
+  HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
+  QStringList aPolylineNames;
+  myPolyObjs.clear();
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
+    myPolyObjs.push_back(aPolylineObj);
+    aPolylineNames << aPolylineObj->GetName();
+  }
+  myMeasDlg->setPolylineNames(aPolylineNames);
+}
+
+void HYDROGUI_MeasurementToolOp::onClearLine()
+{
+  eraseLine();
+  myDist = 0;
+  //myPolyObjs.clear();
+  myMeasDlg->setTotalDst(0);
+  delete myLineMaker;
+  myLineMaker = NULL;
+  myFW = TopoDS_Wire();
+}
+
+void HYDROGUI_MeasurementToolOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
+{
+  OCCViewer_ViewManager* aViewManager = getPreviewManager();
+  if ( !aViewManager )
+    return;
+
+  OCCViewer_ViewWindow* aViewWindow = (OCCViewer_ViewWindow*)aViewManager->getActiveView();
+  if ( !aViewWindow )
+    return;
+
+  OCCViewer_ViewPort3d* aViewPort = aViewWindow->getViewPort();
+  if ( !aViewPort )
+    return;
+
+  Handle(V3d_View) aView = aViewPort->getView();
+  if ( aView.IsNull() )
+    return;
+
+  OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
+  if ( !aViewer )
+    return;
+
+  Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+  if ( aCtx.IsNull() )
+    return;  
+
+  gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), aView );
+
+  TopoDS_Shape aRes;
+
+  if (myMeasDlg->IsLDChecked())
+  {
+    if (!myLineMaker)
+    {
+      myLineMaker = new BRepLib_MakePolygon();
+      myLineMaker->Add(aPnt);
+      aRes = myLineMaker->FirstVertex(); 
+    }
+    else
+    {   
+      myLineMaker->Add(aPnt);
+      aRes = myLineMaker->Shape();
+      const TopoDS_Edge& aLE = myLineMaker->Edge();
+      TopoDS_Vertex aFV = TopExp::FirstVertex(aLE, true);
+      TopoDS_Vertex aLV = TopExp::LastVertex(aLE, true);
+      double aNDist = BRep_Tool::Pnt(aFV).Distance(BRep_Tool::Pnt(aLV));
+      myDist += aNDist;
+      myMeasDlg->setTotalDst(QString::number(myDist));
+    }
+
+    if ( !myAISLineM.IsNull() )
+    {
+      if ( aCtx->HasOpenedContext() )
+        aCtx->CloseLocalContext();
+      aCtx->Erase( myAISLineM, Standard_False );
+    }
+  }
+  else
+  {
+    double prec = 70; //minimum precision
+    int selectInd = myMeasDlg->currentSelectedPolyline();
+    if (selectInd == -1)
+      return;
+    Handle(HYDROData_PolylineXY) aPolylineObj = myPolyObjs[selectInd];
+    TopoDS_Shape aShape = aPolylineObj->GetShape();
+    TopExp_Explorer exp(aShape, TopAbs_WIRE);
+    double fdist_min = RealLast();
+    TopoDS_Wire minWire;
+    BRepAdaptor_Curve minC;
+    double minU;
+    for (;exp.More(); exp.Next())
+    {
+      TopoDS_Wire W = TopoDS::Wire(exp.Current());
+      if (W.IsNull())
+        continue;
+      TopExp_Explorer expW(W, TopAbs_EDGE);
+      if (!expW.More())
+        continue;      
+      TopoDS_Edge E = TopoDS::Edge(expW.Current());
+      expW.Next();
+      if (expW.More())
+        E = BRepAlgo::ConcatenateWireC0(W);
+      BRepAdaptor_Curve Ad(E);
+      Handle(Geom_BSplineCurve) aBsp = Ad.Curve().BSpline();
+      std::vector<double> params;
+      double Fp = Ad.FirstParameter();
+      double Lp = Ad.LastParameter();
+      params.push_back(Fp);
+      params.push_back(Lp);
+      if (!aBsp.IsNull())
+      {
+        TColStd_Array1OfReal aKnots = aBsp->Knots();
+        for (int i = 1; i <= aKnots.Size(); i++)
+        {
+          if (aKnots(i) > Fp && aKnots(i) < Lp)
+            params.push_back(aKnots(i));
+        }
+      }
+      //in some cases, extrema gives inaccurate result -> 
+      //split bspline by knot params and try to find minimum distance
+      //on each interval
+      std::sort(params.begin(), params.end());
+      for (int i = 0; i < params.size() - 1; i++ )
+      {
+        //Extrema_ExtPC extrema(aPnt, Ad, params[i], params[i+1]);
+        GeomAPI_ProjectPointOnCurve aProj; //extrema wrapper
+        aProj.Init (aPnt, Ad.Curve().Curve(), params[i], params[i+1]);
+        if (aProj.NbPoints() > 0)
+        {
+          double fdist = aProj.LowerDistance();
+          gp_Pnt aFP = aProj.NearestPoint();
+          int x1=-1, y1=-1, x2=-1, y2=-1;
+          CurveCreator_Utils::ConvertPointToClick(aPnt, aView, x1, y1);
+          CurveCreator_Utils::ConvertPointToClick(aFP, aView, x2, y2);
+          gp_Pnt2d pp1((double)x1, (double)y1);
+          gp_Pnt2d pp2((double)x2, (double)y2);
+          int aWinSX, aWinSY;
+          aView->Window()->Size(aWinSX, aWinSY);
+          double pd = pp1.Distance(pp2);
+          double WinDiagDist = sqrt ((double)aWinSX*(double)aWinSX + (double)aWinSY*(double)aWinSY);
+          if (fdist <= prec || pd / WinDiagDist < 0.08)
+          {
+            if (fdist < fdist_min) 
+            {
+              fdist_min = fdist;           
+              minWire = W;
+              minU = aProj.LowerDistanceParameter();
+              minC.Initialize(E);
+            }
+          }
+        }
+      }
+    }
+    //
+    if (!minWire.IsNull())
+    {
+      if (myFW.IsNull())
+      {
+        myFu = minU;
+        myFW = minWire;
+        aRes = BRepLib_MakeVertex(aPnt);
+      }
+      else
+      {
+        if (myFW.IsSame(minWire))
+        {
+          //calc distance on current curve 
+          double LenAlongCurv = GCPnts_AbscissaPoint::Length(minC, myFu, minU);          
+          myFW = TopoDS_Wire();
+          if (!BRep_Tool::IsClosed(minWire))
+          {
+            aRes = BRepLib_MakeEdge(minC.Curve().Curve(), Min(myFu, minU), Max (myFu, minU));
+            myMeasDlg->setTotalDst(QString::number(LenAlongCurv));
+          }
+          else
+          {
+            double Len2 = GCPnts_AbscissaPoint::Length(minC) - LenAlongCurv;
+            if (LenAlongCurv < Len2)
+              aRes = BRepLib_MakeEdge(minC.Curve().Curve(), Min(myFu, minU), Max (myFu, minU));
+            else
+            {
+              TopoDS_Compound aCmpEd;
+              BRep_Builder aB;
+              aB.MakeCompound(aCmpEd);
+              aB.Add(aCmpEd, BRepLib_MakeEdge(minC.Curve().Curve(), minC.FirstParameter(), Min(myFu, minU)));
+              aB.Add(aCmpEd, BRepLib_MakeEdge(minC.Curve().Curve(), Max(myFu, minU), minC.LastParameter()));
+              aRes = aCmpEd;
+            }
+            myMeasDlg->setTotalDst(QString::number(LenAlongCurv) + ", " + QString::number(Len2));
+          }
+        }
+      }
+    }
+  }
+
+  if (aRes.IsNull())
+    return;
+
+  aCtx->Erase( myAISLineM, Standard_False );
+
+  myAISLineM = new AIS_Shape( aRes );
+
+  myAISLineM->SetColor( Quantity_NOC_ORANGE );
+  //Handle(Prs3d_Drawer) aHA = myAISLineM->HilightAttributes();
+
+  myAISLineM->SetWidth( 3 );
+  //Handle(Prs3d_PointAspect) anAspect = mySplitPointPreview->Attributes()->PointAspect();
+  //anAspect->SetScale(2.0);
+  //anAspect->SetTypeOfMarker(Aspect_TOM_RING1);
+  //anAspect->SetColor(Quantity_NOC_BLACK);
+  //mySplitPointPreview->Attributes()->SetPointAspect( anAspect );
+  
+  aCtx->SetZLayer(myAISLineM, Graphic3d_ZLayerId_Topmost);
+
+  if ( aCtx->HasOpenedContext() )
+    aCtx->CloseLocalContext();
+  aCtx->Display( myAISLineM, Standard_False );  
+  aCtx->UpdateCurrentViewer();
+}
+
+void HYDROGUI_MeasurementToolOp::eraseLine()
+{
+  OCCViewer_ViewManager* aViewManager = getPreviewManager();
+  if ( aViewManager )
+  {
+    if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+    {
+      if ( !myAISLineM.IsNull() )
+      {
+        Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+        if ( !aCtx.IsNull() )
+        {
+          if ( aCtx->HasOpenedContext() )
+            aCtx->CloseLocalContext();
+          aCtx->Erase( myAISLineM, Standard_False );
+        }
+        myAISLineM.Nullify();
+        aCtx->UpdateCurrentViewer();
+      }      
+    }
+  }
+}
+
+void HYDROGUI_MeasurementToolOp::abortOperation()
+{
+  if (!myMeasDlg->GetExitFlag())
+    myMeasDlg->done(0);
+}
+
+void HYDROGUI_MeasurementToolOp::onExit()
+{
+  onClearLine();
+  OCCViewer_ViewManager* aViewManager = getPreviewManager();
+  OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
+
+  if (aViewManager && aViewer)
+  {
+    disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+      this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+
+    connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+      aViewManager->getOCCViewer(), SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+  }
+
+  if (myLineMaker)
+    delete myLineMaker;
+
+  this->blockSignals(true);
+  HYDROGUI_Operation::abort();
+  this->blockSignals(false);
+}
+
+
+
+
+
diff --git a/src/HYDROGUI/HYDROGUI_MeasurementToolOp.h b/src/HYDROGUI/HYDROGUI_MeasurementToolOp.h
new file mode 100644 (file)
index 0000000..c09389e
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// 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 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
+//
+
+#ifndef HYDROGUI_MEASUREMENTTOOLOP_H
+#define HYDROGUI_MEASUREMENTTOOLOP_H
+
+#include "HYDROGUI_Operation.h"
+
+#include <HYDROData_Entity.h>
+#include <TopoDS_Wire.hxx>
+#include <AIS_Shape.hxx>
+
+class HYDROGUI_MeasurementToolDlg;
+class QMouseEvent;
+class SUIT_ViewWindow;
+class HYDROData_PolylineXY;
+class BRepLib_MakePolygon;
+
+class HYDROGUI_MeasurementToolOp : public HYDROGUI_Operation
+{
+  Q_OBJECT
+
+public:
+  HYDROGUI_MeasurementToolOp( HYDROGUI_Module* theModule );
+  virtual ~HYDROGUI_MeasurementToolOp();
+
+protected:
+  virtual void startOperation();
+  virtual void abortOperation();
+
+protected slots:
+  void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
+  void onClearLine();
+  void onExit();
+
+private:
+  void eraseLine();
+
+private:
+
+  Handle(AIS_Shape) myAISLineM;
+  BRepLib_MakePolygon* myLineMaker; 
+  HYDROGUI_MeasurementToolDlg* myMeasDlg;
+  double myDist;
+  TopoDS_Wire myFW;
+  double myFu;
+  std::vector<Handle(HYDROData_PolylineXY)> myPolyObjs;
+
+};
+
+#endif
\ No newline at end of file
index cf5d70f819c6374412437608ecd18ea27f427953..8c459d9a845488ca46928c816227f92096870f45 100644 (file)
@@ -45,6 +45,7 @@
 #include "HYDROGUI_UpdateObjectOp.h"
 #include "HYDROGUI_VisualStateOp.h"
 #include "HYDROGUI_ImmersibleZoneOp.h"
+#include "HYDROGUI_MeasurementToolOp.h"
 #include "HYDROGUI_ImportGeomObjectOp.h"
 #include "HYDROGUI_ImportObstacleFromFileOp.h"
 #include "HYDROGUI_TranslateObstacleOp.h"
@@ -147,6 +148,8 @@ void HYDROGUI_Module::createActions()
   createAction( ExportSinusXId, "EXPORT_SINUSX", "EXPORT_SINUSX_ICO" );
   createAction( ImportLandCoverMapId, "IMPORT_LANDCOVER_MAP", "IMPORT_LANDCOVER_MAP_ICO" );
 
+  createAction( MeasurementToolId, "MEASUREMENT_TOOL", "MEASUREMENT_TOOL_ICO" );
+
   createAction( ImportBCPolygonId, "IMPORT_BC_POLYGON", "IMPORT_BC_POLYGON_ICO" );
 
   createAction( CreatePolylineId, "CREATE_POLYLINE", "CREATE_POLYLINE_ICO" );
@@ -288,6 +291,8 @@ void HYDROGUI_Module::createMenus()
   createMenu( CreateChannelId, aHydroId, -1, -1 );
   createMenu( CreateDigueId, aHydroId, -1, -1 );
 
+  createMenu( MeasurementToolId, aHydroId, -1, -1 );
+
   int aNewImageId = createMenu( tr( "MEN_DESK_IMAGE" ), aHydroId, -1 );
   createMenu( ImportImageId, aNewImageId, -1, -1 );
   createMenu( separator(), aNewImageId );
@@ -355,6 +360,7 @@ void HYDROGUI_Module::createToolbars()
   createTool( ImportLandCoverMapId, aToolBar );
 
   createTool( ImportBCPolygonId, aToolBar );
+  createTool( MeasurementToolId, aToolBar );
 
   createTool( ImportBathymetryId, aToolBar );
   createTool( CreatePolylineId, aToolBar );
@@ -632,6 +638,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case ImportBCPolygonId:
     anOp = new HYDROGUI_ImportBCPolygonOp( aModule );
     break;
+  case MeasurementToolId:
+    anOp = new HYDROGUI_MeasurementToolOp( aModule );
+    break;
   case ObserveImageId:
     anOp = new HYDROGUI_ObserveImageOp( aModule );
     break;
index e17c2d28a74532081db34a54cc6f65302e0160f3..c1aac72b7a90df8f52a634a006df3b51f233285b 100644 (file)
@@ -115,6 +115,7 @@ enum OperationId
   ImportSinusXId,
   ExportSinusXId,
   ImportBCPolygonId, 
+  MeasurementToolId, 
   
   ExportToShapeFileID,
   ImportLandCoverMapId,
index c2d892480bf345ea55fe1feff89ce4d86c171fd3..ba88e887ebd96aa84beed6a2135500334f8dd167 100644 (file)
       <source>IMPORT_BC_POLYGON_ICO</source>
       <translation>icon_bc_import.png</translation>
     </message> 
+    <message>
+      <source>MEASUREMENT_TOOL_ICO</source>
+      <translation>icon_meas_tools.png</translation>
+    </message>
  </context>
 </TS>
index d725e9c1fb9d47b03ebedbed109e3b6d47c81c27..a3fa8e5005fd0147291a204cd4e629e0fb7a6d3f 100644 (file)
@@ -1051,6 +1051,10 @@ Would you like to remove all references from the image?</translation>
       <source>DSK_IMPORT_SINUSX</source>
       <translation>Import from SinusX</translation>
     </message>
+    <message>
+      <source>DSK_MEASUREMENT_TOOL</source>
+      <translation>Measurement tool</translation>
+    </message>
     <message>
       <source>DSK_IMPORT_BC_POLYGON</source>
       <translation>Import boundary polygons from SHP file</translation>
@@ -1448,6 +1452,10 @@ Would you like to remove all references from the image?</translation>
       <source>MEN_IMPORT_SINUSX</source>
       <translation>Import from SinusX</translation>
     </message>
+    <message>
+      <source>MEN_MEASUREMENT_TOOL</source>
+      <translation>Measurement tool</translation>
+    </message>
     <message>
       <source>MEN_EXPORT_SINUSX</source>
       <translation>Export to SinusX</translation>
@@ -1804,6 +1812,10 @@ Would you like to remove all references from the image?</translation>
       <source>STB_IMPORT_SINUSX</source>
       <translation>Import from SinusX</translation>
     </message>
+    <message>
+      <source>STB_MEASUREMENT_TOOL</source>
+      <translation>Measurement tool</translation>
+    </message>
     <message>
       <source>STB_EXPORT_SINUSX</source>
       <translation>Export to SinusX</translation>
@@ -3716,7 +3728,37 @@ Polyline should consist from one not closed curve.</translation>
       <source>SELECTION_TOOL</source>
       <translation>Selection tool</translation>
     </message>
+  </context>
+  <context>
+    <name>HYDROGUI_MeasurementToolDlg</name>
+     <message>
+      <source>LINEAR_DISTANCE</source>
+      <translation>Linear distance</translation>
+    </message>
+     <message>
+      <source>POLYLINE_DISTANCE</source>
+      <translation>Distance on polyline:</translation>
+    </message>
+     <message>
+      <source>TOTAL_DST</source>
+      <translation>Distance:</translation>
+    </message>
+     <message>
+      <source>CLEAR</source>
+      <translation>Clear</translation>
+    </message>
+      <message>
+      <source>CLOSE</source>
+      <translation>Close</translation>
+    </message>
+  </context>
 
+  <context>
+    <name>HYDROGUI_MeasurementToolOp</name>
+     <message>
+      <source>MEASUREMENT_TOOL</source>
+      <translation>Measurement Tool</translation>
+    </message>
   </context>
 
 </TS>
diff --git a/src/HYDROGUI/resources/icon_meas_tools.png b/src/HYDROGUI/resources/icon_meas_tools.png
new file mode 100644 (file)
index 0000000..d2b2c54
Binary files /dev/null and b/src/HYDROGUI/resources/icon_meas_tools.png differ