#include "HYDROData_Profile.h"
#include "HYDROData_PolylineXY.h"
#include "HYDROData_Projection.h"
+#include "HYDROData_ShapesGroup.h"
+#include "HYDROData_ShapesTool.h"
-#include <TopoDS.hxx>
-#include <TopoDS_Wire.hxx>
#include <BRepOffsetAPI_MakePipeShell.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <BRepCheck_Analyzer.hxx>
+
+#include <TopExp.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Wire.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Face.hxx>
-#include <TopExp.hxx>
+
//#define DEB_CHANNEL 1
#ifdef DEB_CHANNEL
#include <BRepTools.hxx>
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" <<endl;
- BRepTools::Write(aChannel, "ChanNV.brep");
+ cout <<"NOT VALID" <<endl;
+ BRepTools::Write(aChannel, "ChanNV.brep");
#endif
- }
+ }
}
+ TopoDS_Shape a3dShape = GetShape3D();
+ if ( a3dShape.IsNull() )
+ return;
+
// build 2d shape -- temporary solution!!
- TopoDS_Face aProj = HYDROData_Projection::MakeProjection( GetShape3D() );
+ TopoDS_Face aProj = HYDROData_Projection::MakeProjection( a3dShape );
SetTopShape( aProj );
+ if ( aProj.IsNull() )
+ return;
- /*
- //aMkSweep.Generated() - it seems doesn't work
- //TopoDS_Vertex aV1,aV2;
- //TopExp::Vertices (aProfileWire, aV1, aV2);
- //const TopTools_ListOfShape& aList1 = aMkSweep.Generated(aV1);
- //const TopTools_ListOfShape& aList2 = aMkSweep.Generated(aV2);
- //cout <<"List1 = " << aList1.Extent() <<endl;
- //cout <<"List2 = " << aList2.Extent() <<endl;
- TopoDS_Wire aPathWire2d = TopoDS::Wire(aGuideLine->GetPolylineXY()->GetShape());
- if(aPathWire2d.IsNull())
+ // Create the channel groups
+ TopoDS_Shape aFirstShape = aMkSweep.FirstShape();
+ TopoDS_Shape aLastShape = aMkSweep.LastShape();
+ if ( aFirstShape.IsNull() || aFirstShape.ShapeType() != TopAbs_WIRE ||
+ aLastShape.IsNull() || aLastShape.ShapeType() != TopAbs_WIRE )
return;
- TopoDS_Wire aProfileWire2d = TopoDS::Wire( aProfile->GetTopShape() );
- if(aProfileWire2d.IsNull())
- return;
- //BRepTools::Write(aPathWire2d, "PathWire2.brep");
- //BRepTools::Write(aProfileWire2d, "ProfileWire2.brep");
- //BRepOffsetAPI_MakePipeShell aMkSweep2d(aPathWire2d);
- //aMkSweep2d.Add(aProfileWire2d,Standard_True, Standard_True);
- //aMkSweep2d.SetTransitionMode(BRepBuilderAPI_RightCorner);
- //aMkSweep2d.SetMode(Standard_True);
- //aMkSweep2d.Build();
- BRepOffsetAPI_MakePipe aMkSweep2d(aPathWire2d, aProfileWire2d);
- aMkSweep2d.Build();
- if(aMkSweep2d.IsDone()) {
- const TopoDS_Shape& aChannel2d = aMkSweep2d.Shape();
- BRepCheck_Analyzer aCheck(aChannel2d);
- if(aCheck.IsValid())
- {
- //BRepTools::Write(aChannel2d, "Chan2dV.brep");
- SetTopShape( aChannel2d);
- }
-#ifdef DEB_CHANNEL
- else {
- cout <<"NOT VALID" <<endl;
- BRepTools::Write(aChannel2d, "Chan2dNV.brep");
- }
-#endif
- }*/
+
+ TopoDS_Wire anInletWire = TopoDS::Wire( aFirstShape );
+ TopoDS_Wire anOutletWire = TopoDS::Wire( aLastShape );
+
+ TopoDS_Vertex anInletFirstVert, anInletLastVert;
+ TopExp::Vertices( anInletWire, anInletFirstVert, anInletLastVert );
+
+ const TopTools_ListOfShape& aGeneratedLeftEdges = aMkSweep.Generated( anInletFirstVert );
+ const TopTools_ListOfShape& aGeneratedRightEdges = aMkSweep.Generated( anInletLastVert );
+
+ TopTools_SequenceOfShape aProjEdges;
+ HYDROData_ShapesTool::ExploreShapeToShapes( aProj, TopAbs_EDGE, aProjEdges );
+
+ TopTools_SequenceOfShape aProjLeftEdges;
+ findEdges( aProjEdges, aGeneratedLeftEdges, aProjLeftEdges );
+
+ TopTools_SequenceOfShape aProjRightEdges;
+ findEdges( aProjEdges, aGeneratedRightEdges, aProjRightEdges );
+
+ TopTools_SequenceOfShape aProjInletEdges;
+ findEdges( aProjEdges, anInletWire, aProjInletEdges );
+
+ TopTools_SequenceOfShape aProjOutletEdges;
+ findEdges( aProjEdges, anOutletWire, aProjOutletEdges );
+
+ QString aLeftGroupName = GetName() + "_Left_Bank";
+
+ Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
+ aLeftGroup->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()
{
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 );
+}
+
#include <TopExp.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Wire.hxx>
#include <TopTools_SequenceOfShape.hxx>
}
}
+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 );
}
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 );
};