From 60683af93df1c43c2441644f6c3ae4d7c9f82013 Mon Sep 17 00:00:00 2001 From: isn Date: Tue, 19 May 2015 15:11:53 +0300 Subject: [PATCH] #refs 518 --- src/HYDROGUI/CMakeLists.txt | 2 + src/HYDROGUI/HYDROGUI_Polyline.cxx | 133 +++++++++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_Polyline.h | 55 ++++++++++++ src/HYDROGUI/HYDROGUI_Shape.cxx | 8 +- 4 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 src/HYDROGUI/HYDROGUI_Polyline.cxx create mode 100644 src/HYDROGUI/HYDROGUI_Polyline.h diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index d1586649..6f684a9c 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -63,6 +63,7 @@ set(PROJECT_HEADERS HYDROGUI_Region.h HYDROGUI_RemoveImageRefsOp.h HYDROGUI_Shape.h + HYDROGUI_Polyline.h HYDROGUI_ShapeBathymetry.h HYDROGUI_ShapeImage.h HYDROGUI_ShowHideOp.h @@ -173,6 +174,7 @@ set(PROJECT_SOURCES HYDROGUI_Region.cxx HYDROGUI_RemoveImageRefsOp.cxx HYDROGUI_Shape.cxx + HYDROGUI_Polyline.cxx HYDROGUI_ShapeBathymetry.cxx HYDROGUI_ShapeImage.cxx HYDROGUI_ShowHideOp.cxx diff --git a/src/HYDROGUI/HYDROGUI_Polyline.cxx b/src/HYDROGUI/HYDROGUI_Polyline.cxx new file mode 100644 index 00000000..e624cb3d --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Polyline.cxx @@ -0,0 +1,133 @@ +// 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 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE (HYDROGUI_Polyline, AIS_Shape) +IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Polyline, AIS_Shape) + + +HYDROGUI_Polyline::HYDROGUI_Polyline(const TopoDS_Shape& shape) + : AIS_Shape(shape) +{ +} + +HYDROGUI_Polyline::~HYDROGUI_Polyline() +{ +} + +void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, + const Handle(Prs3d_Presentation)& aPrs, + const Standard_Integer aMode) +{ + AIS_Shape::Compute(aPresentationManager, aPrs, aMode); + + TopExp_Explorer Exp ( myshape, TopAbs_EDGE ); + for ( ; Exp.More(); Exp.Next() ) { + TopoDS_Vertex aV1, aV2; + TopoDS_Edge anEdge = TopoDS::Edge(Exp.Current()); + + if ( anEdge.IsNull() ) + continue; + TopExp::Vertices(anEdge, aV1, aV2); + gp_Pnt aP = BRep_Tool::Pnt(aV1); + gp_Vec aDirVec; + double aFp, aLp; + Handle(Geom_Curve) C = BRep_Tool::Curve(anEdge,aFp,aLp); + if ( C.IsNull() ) + continue; + + Bnd_Box aBB; + BRepBndLib::Add(anEdge, aBB); + Standard_Real aXmin,aYmin,aZmin,aXmax,aYmax,aZmax; + aBB.Get(aXmin,aYmin,aZmin,aXmax,aYmax,aZmax); + Standard_Real aLen = Max(Abs(aXmax - aXmin), Max (Abs(aZmax - aZmin), Abs(aYmax - aYmin))); + + GeomAdaptor_Curve aAdC; + aAdC.Load(C, aFp, aLp); + double aLenC; + double aLenH; + int aNbSegments = 20; + double aArrLen = aLen / 10.; + double anIncr = (aLp-aFp)/aNbSegments; + double aMaxRatio = 0; + double aMaxRatioStep = 1; + for (double t = aFp; t < aLp - anIncr; t += anIncr) + { + aLenC = GCPnts_AbscissaPoint::Length(aAdC, t, t + anIncr); + aLenH = C->Value (t).Distance (C->Value (t + anIncr)); + if ( aLenH / aLenC > aMaxRatio) { + aMaxRatio = aLenH / aLenC; + aMaxRatioStep = t; + } + } + + bool UseD1 = false; + if (Abs(aMaxRatioStep) < Precision::Confusion()) + { + aMaxRatioStep = (aLp - aFp)/2.0; + UseD1 = true; + } + + if (Abs(aLp - aMaxRatioStep) < Precision::Confusion()) + { + aMaxRatioStep = (aLp - aFp)/2.0; + UseD1 = true; + } + + gp_Pnt aPnt1 = C->Value (aMaxRatioStep); + gp_Vec aDir; + if (!UseD1) { + GCPnts_AbscissaPoint aAbsPoint(aAdC, -aArrLen, aMaxRatioStep); + double aParam = aAbsPoint.Parameter(); + gp_Pnt aPnt2 = C->Value (aParam); + gp_XYZ D = aPnt1.XYZ(); + D.Subtract (aPnt2.XYZ()); + aDir = D; + } + else + C->D1(aMaxRatioStep, C->Value (aMaxRatioStep), aDir); + + if ( anEdge.Orientation() == TopAbs_REVERSED ) + aDir = -aDir; + + Prs3d_Arrow::Draw(aPrs, aPnt1, aDir, M_PI/180.*12., aArrLen); + } +} diff --git a/src/HYDROGUI/HYDROGUI_Polyline.h b/src/HYDROGUI/HYDROGUI_Polyline.h new file mode 100644 index 00000000..e14c5403 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Polyline.h @@ -0,0 +1,55 @@ +// 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 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_Polyline_HeaderFile +#define _HYDROGUI_Polyline_HeaderFile + +#include +#include + +#include +#include +#include +#include +#include +#include + +class TopoDS_Shape; + +class HYDROGUI_Polyline : public AIS_Shape +{ +public: + + Standard_EXPORT HYDROGUI_Polyline(const TopoDS_Shape& shape); + Standard_EXPORT ~HYDROGUI_Polyline(); + + Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, + const Handle(Prs3d_Presentation)& aPresentation, + const Standard_Integer aMode = 0); + +public: + DEFINE_STANDARD_RTTI(HYDROGUI_Polyline); +}; + +DEFINE_STANDARD_HANDLE(HYDROGUI_Polyline, AIS_Shape) + +#endif diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 08900fbe..182c586b 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -482,7 +483,12 @@ Handle_AIS_InteractiveObject HYDROGUI_Shape::createShape() const if( myTopoShape.IsNull() ) return Handle_AIS_InteractiveObject(); else - return new AIS_Shape( myTopoShape ); + if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) || + myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D)) || + myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) )) + return new HYDROGUI_PrsShape(myTopoShape); + else + return new AIS_Shape( myTopoShape ); } void HYDROGUI_Shape::buildShape() -- 2.39.2