From: asl Date: Thu, 26 Dec 2013 04:39:20 +0000 (+0000) Subject: new implementation for channels creation X-Git-Tag: BR_hydro_v_0_7~55 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b1621e0247d3beb26d1ea81b25fca8cc9dd76c2d;p=modules%2Fhydro.git new implementation for channels creation --- diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 10aeff0e..4ef25b8b 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -25,6 +25,7 @@ set(PROJECT_HEADERS HYDROData_Obstacle.h HYDROData_ObstacleAltitude.h HYDROData_OperationsFactory.h + HYDROData_Pipes.h HYDROData_PolylineXY.h HYDROData_Polyline3D.h HYDROData_Profile.h @@ -67,6 +68,7 @@ set(PROJECT_SOURCES HYDROData_Obstacle.cxx HYDROData_ObstacleAltitude.cxx HYDROData_OperationsFactory.cxx + HYDROData_Pipes.cxx HYDROData_PolylineXY.cxx HYDROData_Polyline3D.cxx HYDROData_Profile.cxx diff --git a/src/HYDROData/HYDROData_Channel.cxx b/src/HYDROData/HYDROData_Channel.cxx index 9499aea8..15335a69 100644 --- a/src/HYDROData/HYDROData_Channel.cxx +++ b/src/HYDROData/HYDROData_Channel.cxx @@ -8,10 +8,12 @@ #include "HYDROData_Projection.h" #include "HYDROData_ShapesGroup.h" #include "HYDROData_ShapesTool.h" +#include "HYDROData_Pipes.h" #include #include #include +#include #include @@ -107,67 +109,17 @@ void HYDROData_Channel::Update() if(aProfileWire.IsNull()) 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(); - BRepCheck_Analyzer aCheck(aChannel); - if(aCheck.IsValid()) - { - //BRepTools::Write(aChannel, "ChanV.brep"); - SetShape3D( aMkSweep.Shape()); - } else { -#ifdef DEB_CHANNEL - cout <<"NOT VALID" <SetName( anOutGroupName ); anOutGroup->SetShapes( aProjOutletEdges ); + */ } QColor HYDROData_Channel::DefaultFillingColor() diff --git a/src/HYDROData/HYDROData_Pipes.cxx b/src/HYDROData/HYDROData_Pipes.cxx new file mode 100644 index 00000000..28f2d905 --- /dev/null +++ b/src/HYDROData/HYDROData_Pipes.cxx @@ -0,0 +1,242 @@ +// File: HYDROData_Pipes.cxx +// Created: 25.12.13 16:39:40 +// Author: jgv@ROLEX +// Copyright: Open CASCADE 2013 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +HYDROData_Canal3dAnd2d::HYDROData_Canal3dAnd2d(const TopoDS_Wire& Profile, + const TopoDS_Wire& Guideline) + : myProfile(Profile), myGuideline(Guideline) +{ + TopExp::Vertices(myProfile, myLeftVertex, myRightVertex); + + ProjectWireOntoXOY(myGuideline, myProjectedGuideline); + Make2dProfile(); + SetMiddlePoint2d(); + SetMiddlePoint3d(); +} + +Standard_Boolean HYDROData_Canal3dAnd2d::ProjectWireOntoXOY(const TopoDS_Wire& aWire, + TopoDS_Wire& ProjectedWire) +{ + gp_Pln XOY; //default plane + TopoDS_Face theXOYface = BRepLib_MakeFace(XOY); + + BRepOffsetAPI_NormalProjection OrtProj(theXOYface); + OrtProj.Add(aWire); + //OrtProj.SetParams(...); ??? + OrtProj.Build(); + TopTools_ListOfShape Wires; + OrtProj.BuildWire(Wires); + + if (Wires.Extent() != 1) + return Standard_False; + + ProjectedWire = TopoDS::Wire(Wires.First()); + return Standard_True; +} + +TopoDS_Vertex HYDROData_Canal3dAnd2d::ProjectVertexOntoXOY(const TopoDS_Vertex& aVertex) +{ + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + gp_Pnt aProjPoint(aPoint.X(), aPoint.Y(), 0.); + TopoDS_Vertex aProjVertex = BRepLib_MakeVertex(aProjPoint); + return aProjVertex; +} + +void HYDROData_Canal3dAnd2d::Make2dProfile() +{ + TopoDS_Vertex ProjectedLeftVertex = ProjectVertexOntoXOY(myLeftVertex); + TopoDS_Vertex ProjectedRightVertex = ProjectVertexOntoXOY(myRightVertex); + TopoDS_Edge anEdge = BRepLib_MakeEdge(ProjectedLeftVertex, ProjectedRightVertex); + myProjectedProfile = BRepLib_MakeWire(anEdge); +} + +void HYDROData_Canal3dAnd2d::SetMiddlePoint2d() +{ + TopoDS_Vertex V1, V2; + TopExp::Vertices(myProjectedProfile, V1, V2); + gp_Pnt Pnt1 = BRep_Tool::Pnt(V1); + gp_Pnt Pnt2 = BRep_Tool::Pnt(V2); + myMiddlePoint2d.SetXYZ(0.5*(Pnt1.XYZ() + Pnt2.XYZ())); +} + +void HYDROData_Canal3dAnd2d::SetMiddlePoint3d() +{ + gp_Lin MidLin(myMiddlePoint2d, gp::DZ()); + TopoDS_Edge MidEdge = BRepLib_MakeEdge(MidLin); + TopoDS_Iterator itw(myProfile); + for (; itw.More(); itw.Next()) + { + const TopoDS_Edge& anEdge = TopoDS::Edge(itw.Value()); + BRepExtrema_ExtCC ExtremaEE(MidEdge, anEdge); + if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) + { + for (Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++) + { + if (ExtremaEE.SquareDistance(i) <= Precision::Confusion()) + { + myMiddlePoint3d = ExtremaEE.PointOnE1(i); + break; + } + } + } + } +} + +TopoDS_Wire HYDROData_Canal3dAnd2d::SetTransformedProfile(const TopoDS_Wire& aProfile, + const TopoDS_Wire& aGuideline, + const gp_Pnt& aMiddlePoint) +{ + TopoDS_Wire aTransformedProfile; + + TopoDS_Iterator itw(myProjectedGuideline); + TopoDS_Edge FirstEdge = TopoDS::Edge(itw.Value()); + Standard_Real fpar, lpar; + Handle(Geom_Curve) FirstCurve = BRep_Tool::Curve(FirstEdge, fpar, lpar); + gp_Pnt StartPnt; + gp_Vec StartVec; + FirstCurve->D1(fpar, StartPnt, StartVec); + + TopoDS_Vertex FirstOnGuide, LastOnGuide; + TopExp::Vertices(aGuideline, FirstOnGuide, LastOnGuide); + gp_Pnt StartPointOnGuide = BRep_Tool::Pnt(FirstOnGuide); + + gp_Trsf Translation, Rotation; + Translation.SetTranslation(aMiddlePoint, StartPointOnGuide); + aTransformedProfile = + TopoDS::Wire(BRepBuilderAPI_Transform(aProfile, Translation, Standard_True)); //copy + + gp_Vec Vertical(0.,0.,1.); + TopoDS_Vertex LeftVertex, RightVertex; + TopExp::Vertices(aTransformedProfile, LeftVertex, RightVertex); + gp_Pnt LeftPoint = BRep_Tool::Pnt(LeftVertex); + gp_Pnt RightPoint = BRep_Tool::Pnt(RightVertex); + gp_Vec LeftToRight(LeftPoint, RightPoint); + gp_Vec NormalToProfile = Vertical ^ LeftToRight; + + gp_Vec AxisOfRotation = NormalToProfile ^ StartVec; + if (AxisOfRotation.Magnitude() <= gp::Resolution()) + { + if (Vertical * LeftToRight < 0.) + { + gp_Ax1 theVertical(StartPointOnGuide, gp::DZ()); + Rotation.SetRotation(theVertical, M_PI); + } + } + else + { + gp_Ax1 theAxis(StartPointOnGuide, AxisOfRotation); + Standard_Real theAngle = NormalToProfile.AngleWithRef(StartVec, AxisOfRotation); + Rotation.SetRotation(theAxis, theAngle); + } + + aTransformedProfile = + TopoDS::Wire(BRepBuilderAPI_Transform(aTransformedProfile, Rotation, Standard_True)); //copy + + return aTransformedProfile; +} + +Standard_Boolean HYDROData_Canal3dAnd2d::Create3dPresentation() +{ + myTransformedProfile3d = SetTransformedProfile(myProfile, myGuideline, myMiddlePoint3d); + + mySweep3d = new BRepOffsetAPI_MakePipeShell(myGuideline); + mySweep3d->SetMode(gp::DZ()); //optional + mySweep3d->Add(myTransformedProfile3d); + //mySweep3d->SetTransitionMode(BRepBuilderAPI_RightCorner); //optional + mySweep3d->Build(); + if (!mySweep3d->IsDone()) + return Standard_False; + + myPipe3d = mySweep3d->Shape(); + return Standard_True; +} + +Standard_Boolean HYDROData_Canal3dAnd2d::Create2dPresentation() +{ + myTransformedProfile2d = SetTransformedProfile(myProjectedProfile, myProjectedGuideline, myMiddlePoint2d); + + mySweep2d = new BRepOffsetAPI_MakePipeShell(myProjectedGuideline); + mySweep2d->SetMode(gp::DZ()); //optional + mySweep2d->Add(myTransformedProfile2d); + //mySweep2d->SetTransitionMode(BRepBuilderAPI_RightCorner); //optional + mySweep2d->Build(); + if (!mySweep2d->IsDone()) + return Standard_False; + + myPipe2d = mySweep2d->Shape(); + myInlet = TopoDS::Wire(mySweep2d->FirstShape()); + myOutlet = TopoDS::Wire(mySweep2d->LastShape()); + TopoDS_Vertex V1, V2, V3, V4; + TopExp::Vertices(myTransformedProfile2d, V1, V2); + TopExp::Vertices(myInlet, V3, V4); + gp_Pnt P1 = BRep_Tool::Pnt(V1); + gp_Pnt P3 = BRep_Tool::Pnt(V3); + if (P1.IsEqual(P3, Precision::Confusion())) + { myLeftVertex2d = V3; myRightVertex2d = V4; } + else + { myLeftVertex2d = V4; myRightVertex2d = V3; } + + return Standard_True; +} + +TopoDS_Wire HYDROData_Canal3dAnd2d::GetBank(const TopoDS_Vertex& aFreeVertex) +{ + TopoDS_Wire aBank; + + TopTools_ListOfShape GeneratedShapes; + GeneratedShapes = mySweep2d->Generated(aFreeVertex); + BRepLib_MakeWire MW; + MW.Add(GeneratedShapes); + aBank = MW.Wire(); + + return aBank; +} + +TopoDS_Shape HYDROData_Canal3dAnd2d::Get3dPresentation() +{ + return myPipe3d; +} + +TopoDS_Shape HYDROData_Canal3dAnd2d::Get2dPresentation() +{ + return myPipe2d; +} + +TopoDS_Wire HYDROData_Canal3dAnd2d::GetInlet() +{ + return myInlet; +} + +TopoDS_Wire HYDROData_Canal3dAnd2d::GetOutlet() +{ + return myOutlet; +} + +TopoDS_Wire HYDROData_Canal3dAnd2d::GetLeftBank() +{ + return GetBank(myLeftVertex2d); +} + +TopoDS_Wire HYDROData_Canal3dAnd2d::GetRightBank() +{ + return GetBank(myRightVertex2d); +} diff --git a/src/HYDROData/HYDROData_Pipes.h b/src/HYDROData/HYDROData_Pipes.h new file mode 100644 index 00000000..8e9ba195 --- /dev/null +++ b/src/HYDROData/HYDROData_Pipes.h @@ -0,0 +1,72 @@ + +#ifndef HYDROData_Pipes_HeaderFile +#define HYDROData_Pipes_HeaderFile + +#include +#include +#include + +class BRepOffsetAPI_MakePipeShell; + +class HYDROData_Canal3dAnd2d +{ +public: + HYDROData_Canal3dAnd2d( const TopoDS_Wire& Profile, + const TopoDS_Wire& Guideline ); + + Standard_Boolean Create3dPresentation(); + + Standard_Boolean Create2dPresentation(); + + Standard_Boolean ProjectWireOntoXOY(const TopoDS_Wire& aWire, + TopoDS_Wire& ProjectedWire); + + void Make2dProfile(); + + TopoDS_Vertex ProjectVertexOntoXOY(const TopoDS_Vertex& aVertex); + + void SetMiddlePoint2d(); + + void SetMiddlePoint3d(); + + TopoDS_Wire SetTransformedProfile(const TopoDS_Wire& aProfile, + const TopoDS_Wire& aGuideline, + const gp_Pnt& aMiddlePoint); + + TopoDS_Wire GetBank(const TopoDS_Vertex& aFreeVertex); + + //Queries + TopoDS_Shape Get3dPresentation(); + TopoDS_Shape Get2dPresentation(); + TopoDS_Wire GetLeftBank(); + TopoDS_Wire GetRightBank(); + TopoDS_Wire GetInlet(); + TopoDS_Wire GetOutlet(); + +private: + + TopoDS_Wire myProfile; + TopoDS_Wire myGuideline; + TopoDS_Vertex myLeftVertex; + TopoDS_Vertex myRightVertex; + TopoDS_Vertex myLeftVertex2d; + TopoDS_Vertex myRightVertex2d; + gp_Pnt myMiddlePoint2d; + gp_Pnt myMiddlePoint3d; + + TopoDS_Wire myProjectedProfile; + TopoDS_Wire myProjectedGuideline; + TopoDS_Wire myTransformedProfile3d; + TopoDS_Wire myTransformedProfile2d; + BRepOffsetAPI_MakePipeShell* mySweep3d; + BRepOffsetAPI_MakePipeShell* mySweep2d; + + TopoDS_Shape myPipe3d; + TopoDS_Shape myPipe2d; + TopoDS_Wire myInlet; + TopoDS_Wire myOutlet; + //TopoDS_Shape myLeftBank; + //TopoDS_Shape myRightBank; +}; + +#endif