From f9b8b591033deed2dbf24dceaa860faf1d323749 Mon Sep 17 00:00:00 2001 From: adv Date: Mon, 23 Dec 2013 11:20:56 +0000 Subject: [PATCH] Creation of group for channel (Feature #242). --- src/HYDROData/HYDROData_Channel.cxx | 179 ++++++++++++++++++------- src/HYDROData/HYDROData_Channel.h | 12 ++ src/HYDROData/HYDROData_ShapesTool.cxx | 47 ++++++- src/HYDROData/HYDROData_ShapesTool.h | 20 ++- 4 files changed, 201 insertions(+), 57 deletions(-) diff --git a/src/HYDROData/HYDROData_Channel.cxx b/src/HYDROData/HYDROData_Channel.cxx index 63db110e..9499aea8 100644 --- a/src/HYDROData/HYDROData_Channel.cxx +++ b/src/HYDROData/HYDROData_Channel.cxx @@ -6,15 +6,20 @@ #include "HYDROData_Profile.h" #include "HYDROData_PolylineXY.h" #include "HYDROData_Projection.h" +#include "HYDROData_ShapesGroup.h" +#include "HYDROData_ShapesTool.h" -#include -#include #include #include #include + +#include + +#include +#include #include #include -#include + //#define DEB_CHANNEL 1 #ifdef DEB_CHANNEL #include @@ -95,75 +100,97 @@ void HYDROData_Channel::Update() return; // build 3d shape - TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D()); + TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D()); if(aPathWire.IsNull()) return; - TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() ); + TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() ); if(aProfileWire.IsNull()) - return; + return; BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire); aMkSweep.Add(aProfileWire,Standard_True, Standard_True); aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner); //aMkSweep.SetMode(Standard_True); aMkSweep.Build(); - if(aMkSweep.IsDone()) { - const TopoDS_Shape& aChannel = aMkSweep.Shape(); + if(aMkSweep.IsDone()) { + const TopoDS_Shape& aChannel = aMkSweep.Shape(); BRepCheck_Analyzer aCheck(aChannel); if(aCheck.IsValid()) - { + { //BRepTools::Write(aChannel, "ChanV.brep"); SetShape3D( aMkSweep.Shape()); - } else { + } else { #ifdef DEB_CHANNEL - cout <<"NOT VALID" <SetName( aLeftGroupName ); + aLeftGroup->SetShapes( aProjLeftEdges ); + + QString aRightGroupName = GetName() + "_Right_Bank"; + + Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject(); + aRightGroup->SetName( aRightGroupName ); + aRightGroup->SetShapes( aProjRightEdges ); + + QString anInGroupName = GetName() + "_Inlet"; + + Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject(); + anInGroup->SetName( anInGroupName ); + anInGroup->SetShapes( aProjInletEdges ); + + QString anOutGroupName = GetName() + "_Outlet"; + + Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject(); + anOutGroup->SetName( anOutGroupName ); + anOutGroup->SetShapes( aProjOutletEdges ); } QColor HYDROData_Channel::DefaultFillingColor() @@ -272,3 +299,53 @@ ObjectKind HYDROData_Channel::getAltitudeObjectType() const { return KIND_OBSTACLE_ALTITUDE; } + +void HYDROData_Channel::findEdges( const TopTools_SequenceOfShape& theInShapes, + const TopTools_ListOfShape& theEdges3D, + TopTools_SequenceOfShape& theOutShapes ) const +{ + theOutShapes.Clear(); + if ( theEdges3D.IsEmpty() || theInShapes.IsEmpty() ) + return; + + const TopoDS_Shape& aFirstShape3D = theEdges3D.First(); + const TopoDS_Shape& aLastShape3D = theEdges3D.Last(); + + TopoDS_Vertex aFirstVert, aLastVert, aDummyVert; + if ( !HYDROData_ShapesTool::Vertices( aFirstShape3D, aFirstVert, aDummyVert ) || + !HYDROData_ShapesTool::Vertices( aLastShape3D, aDummyVert, aLastVert ) ) + return; + + bool isStarted = false; + for ( int i = 1, n = theInShapes.Length(); i <= n; ++i ) + { + const TopoDS_Shape& anInShape = theInShapes.Value( i ); + + TopoDS_Vertex aShapeFirstVert, aShapeLastVert; + if ( !HYDROData_ShapesTool::Vertices( anInShape, aShapeFirstVert, aShapeLastVert ) ) + continue; + + if ( !isStarted ) + { + isStarted = HYDROData_ShapesTool::IsVerticesEquals( aFirstVert, aShapeFirstVert, true ); + } + + if ( isStarted ) + { + theOutShapes.Append( anInShape ); + + if ( HYDROData_ShapesTool::IsVerticesEquals( aLastVert, aShapeLastVert, true ) ) + break; + } + } +} + +void HYDROData_Channel::findEdges( const TopTools_SequenceOfShape& theProjShapes, + const TopoDS_Shape& theEdge3D, + TopTools_SequenceOfShape& theOutShapes ) const +{ + TopTools_ListOfShape aTmpList; + aTmpList.Append( theEdge3D ); + findEdges( theProjShapes, aTmpList, theOutShapes ); +} + diff --git a/src/HYDROData/HYDROData_Channel.h b/src/HYDROData/HYDROData_Channel.h index da1fe347..e9301036 100644 --- a/src/HYDROData/HYDROData_Channel.h +++ b/src/HYDROData/HYDROData_Channel.h @@ -6,6 +6,8 @@ class Handle(HYDROData_Polyline3D); class Handle(HYDROData_Profile); +class TopTools_SequenceOfShape; +class TopTools_ListOfShape; DEFINE_STANDARD_HANDLE(HYDROData_Channel, HYDROData_ArtificialObject) @@ -124,6 +126,16 @@ protected: */ virtual ObjectKind getAltitudeObjectType() const; +private: + + void findEdges( const TopTools_SequenceOfShape& theInShapes, + const TopTools_ListOfShape& theEdges3D, + TopTools_SequenceOfShape& theOutShapes ) const; + + void findEdges( const TopTools_SequenceOfShape& theInShapes, + const TopoDS_Shape& theEdge3D, + TopTools_SequenceOfShape& theOutShapes ) const; + protected: friend class HYDROData_Iterator; diff --git a/src/HYDROData/HYDROData_ShapesTool.cxx b/src/HYDROData/HYDROData_ShapesTool.cxx index 283d64c0..9bf73f26 100644 --- a/src/HYDROData/HYDROData_ShapesTool.cxx +++ b/src/HYDROData/HYDROData_ShapesTool.cxx @@ -9,8 +9,11 @@ #include +#include +#include #include #include +#include #include @@ -33,22 +36,58 @@ void HYDROData_ShapesTool::ExploreShapeToShapes( const TopoDS_Shape& theIn } } +bool HYDROData_ShapesTool::Vertices( const TopoDS_Shape& theInShape, + TopoDS_Vertex& theFirstVertex, + TopoDS_Vertex& theLastVertex, + const bool theIsCumOri ) +{ + if ( theInShape.IsNull() ) + return false; + + if ( theInShape.ShapeType() == TopAbs_EDGE ) + { + TopoDS_Edge anEdge = TopoDS::Edge( theInShape ); + TopExp::Vertices( anEdge, theFirstVertex, theLastVertex, theIsCumOri ); + } + else if ( theInShape.ShapeType() == TopAbs_WIRE ) + { + TopoDS_Wire aWire = TopoDS::Wire( theInShape ); + TopExp::Vertices( aWire, theFirstVertex, theLastVertex ); + } + else + { + return false; + } + + return true; +} + bool HYDROData_ShapesTool::IsVerticesEquals( const TopoDS_Vertex& theFirstVert, - const TopoDS_Vertex& theSecondVert ) + const TopoDS_Vertex& theSecondVert, + const bool theIs2D ) { gp_Pnt aFirstPoint = BRep_Tool::Pnt( theFirstVert ); gp_Pnt aSecondPoint = BRep_Tool::Pnt( theSecondVert ); + + // Set the Z coord to zero for 2D equations + if ( theIs2D ) + { + aFirstPoint.SetZ( 0.0 ); + aSecondPoint.SetZ( 0.0 ); + } + return aFirstPoint.IsEqual( aSecondPoint, Precision::Confusion() ); } bool HYDROData_ShapesTool::IsEdgesEquals( const TopoDS_Edge& theFirstEdge, - const TopoDS_Edge& theSecondEdge ) + const TopoDS_Edge& theSecondEdge, + const bool theIs2D ) { TopoDS_Vertex aFFirstVert, aFLastVert, aSFirstVert, aSLastVert; TopExp::Vertices( theFirstEdge, aFFirstVert, aFLastVert ); TopExp::Vertices( theSecondEdge, aSFirstVert, aSLastVert ); - return IsVerticesEquals( aFFirstVert, aSFirstVert ) && - IsVerticesEquals( aFLastVert, aSLastVert ); + return IsVerticesEquals( aFFirstVert, aSFirstVert, theIs2D ) && + IsVerticesEquals( aFLastVert, aSLastVert, theIs2D ); } diff --git a/src/HYDROData/HYDROData_ShapesTool.h b/src/HYDROData/HYDROData_ShapesTool.h index e676bf85..893f4c50 100644 --- a/src/HYDROData/HYDROData_ShapesTool.h +++ b/src/HYDROData/HYDROData_ShapesTool.h @@ -25,23 +25,39 @@ public: const TopAbs_ShapeEnum& theExpType, TopTools_SequenceOfShape& theOutShapes ); + /** + * \brief Gets the first and last vertex from shape. Shape can be an Edge or Wire. + * \param theInShape object to explore + * \param theFirstVertex[out] first shape vertex + * \param theLastVertex[out] last shape vertex + * \return true if shape is of correct type + */ + static bool Vertices( const TopoDS_Shape& theInShape, + TopoDS_Vertex& theFirstVertex, + TopoDS_Vertex& theLastVertex, + const bool theIsCumOri = false ); + /** * \brief Compare two vertices on coordinates equation. * \param theFirstVert first vertex * \param theSecondVert second vertex + * \param theIs2D flag indicating the 2D equation (ie. z coord will be ignored) * \return \c true if cooredinates of vertices is equals */ static bool IsVerticesEquals( const TopoDS_Vertex& theFirstVert, - const TopoDS_Vertex& theSecondVert ); + const TopoDS_Vertex& theSecondVert, + const bool theIs2D = false ); /** * \brief Compare two edges on points coordinates equation. * \param theFirstVert first edge * \param theSecondVert second edge + * \param theIs2D flag indicating the 2D equation (ie. z coord will be ignored) * \return \c true if coordinates of all points of given edges is equals */ static bool IsEdgesEquals( const TopoDS_Edge& theFirstEdge, - const TopoDS_Edge& theSecondEdge ); + const TopoDS_Edge& theSecondEdge, + const bool theIs2D = false ); }; -- 2.39.2