From: isn Date: Tue, 11 Oct 2016 13:44:57 +0000 (+0300) Subject: stream/channel/dtm presentation redisign + bug fixes for old brep proj, etc.. (draft) X-Git-Tag: v1.6~58^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ede8ad1e5f7dc5a42b5d016e8a02ab5f908ea16d;p=modules%2Fhydro.git stream/channel/dtm presentation redisign + bug fixes for old brep proj, etc.. (draft) --- diff --git a/src/HYDROData/HYDROData_DTM.cxx b/src/HYDROData/HYDROData_DTM.cxx index dba55733..f44f98a2 100644 --- a/src/HYDROData/HYDROData_DTM.cxx +++ b/src/HYDROData/HYDROData_DTM.cxx @@ -31,6 +31,17 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -133,26 +144,28 @@ void HYDROData_DTM::SetSpatialStep( double theSpatialStep ) void HYDROData_DTM::PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W ) { BRepLib_MakeWire WM; - for (int i =0; i < pnts.size() - 1; i++) + if (pnts.empty()) + return; + for (int i = 0; i < pnts.size() - 1; i++) { gp_Pnt p1(pnts[i].X, pnts[i].Y, pnts[i].Z); gp_Pnt p2(pnts[i+1].X, pnts[i+1].Y, pnts[i+1].Z); WM.Add(BRepLib_MakeEdge(p1, p2).Edge()); } - W = WM.Wire(); + if (WM.IsDone()) + W = WM.Wire(); } -TopoDS_Compound HYDROData_DTM::Create3DShape(const AltitudePoints& left, - const AltitudePoints& right, - const std::vector& main_profiles) +TopTools_IndexedMapOfOrientedShape HYDROData_DTM::Create3DShape(const AltitudePoints& left, + const AltitudePoints& right, + const std::vector& main_profiles) { - BRep_Builder BB; - TopoDS_Compound cmp; - BB.MakeCompound(cmp); + TopTools_IndexedMapOfOrientedShape ll; TopoDS_Wire LWire, RWire; PointToWire(left, LWire); PointToWire(right, RWire); - BB.Add(cmp, LWire.Oriented(TopAbs_FORWARD)); + if (!LWire.IsNull()) + ll.Add(LWire.Oriented(TopAbs_FORWARD)); for (int k = 0; k < main_profiles.size(); k++) { @@ -161,46 +174,201 @@ TopoDS_Compound HYDROData_DTM::Create3DShape(const AltitudePoints& left, TopAbs_Orientation Ori = TopAbs_INTERNAL; if (k == 0 || k == main_profiles.size() - 1) Ori = TopAbs_FORWARD; - BB.Add(cmp, W.Oriented(Ori)); + ll.Add(W.Oriented(Ori)); } - BB.Add(cmp, RWire.Oriented(TopAbs_FORWARD)); + if (!RWire.IsNull()) + ll.Add(RWire.Oriented(TopAbs_FORWARD)); //yes, add subshapes in this order (left + profiles + right) - //otherwise the projected wire will be non-manifold!!! + //otherwise the projected wire will be non-manifold - return cmp; + return ll; } + void HYDROData_DTM::Update() { - HYDROData_SequenceOfObjects objs = GetProfiles(); - int aLower = objs.Lower(), anUpper = objs.Upper(); - size_t n = anUpper-aLower+1; + AltitudePoints points; + TopoDS_Shape Out3dPres; + TopoDS_Shape Out2dPres; + TopoDS_Shape OutLeftB; + TopoDS_Shape OutRightB; + TopoDS_Shape OutInlet; + TopoDS_Shape OutOutlet; + + HYDROData_SequenceOfObjects objs = GetProfiles(); + double ddz = GetDDZ(); + double step = GetSpatialStep(); + CreateProfilesFromDTM( objs, ddz, step, points, Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, true, true ); + SetAltitudePoints( points ); + + SetShape( DataTag_LeftBankShape, OutLeftB); + SetShape( DataTag_RightBankShape, OutRightB); + SetShape( DataTag_InletShape, OutInlet); + SetShape( DataTag_OutletShape, OutOutlet ); + SetShape( DataTag_3DShape, Out3dPres ); + SetShape( DataTag_2DShape, Out2dPres ); + +} + +void HYDROData_DTM::GetPresentationShapes( TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet ) +{ + //without update! + OutLeftB = GetShape( DataTag_LeftBankShape); + OutRightB = GetShape( DataTag_RightBankShape); + OutInlet = GetShape( DataTag_InletShape); + OutOutlet = GetShape( DataTag_OutletShape ); + Out3dPres = GetShape( DataTag_3DShape ); + Out2dPres = GetShape( DataTag_2DShape ); +} + +void HYDROData_DTM::CreateProfilesFromDTM (const HYDROData_SequenceOfObjects& InpProfiles, + double ddz, + double step, + AltitudePoints& points, + TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet, + bool Create3dPres, + bool Create2dPres) +{ + + int aLower = InpProfiles.Lower(), anUpper = InpProfiles.Upper(); + size_t n = anUpper - aLower + 1; std::vector profiles; - profiles.reserve( n ); + profiles.reserve( n ); for( int i=aLower; i<=anUpper; i++ ) { - Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( objs.Value( i ) ); + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( InpProfiles.Value( i ) ); if( !aProfile.IsNull() ) profiles.push_back( aProfile ); } - - double ddz = GetDDZ(); - double step = GetSpatialStep(); const double EPS = 1E-3; - AltitudePoints points; AltitudePoints left; AltitudePoints right; std::vector main_profiles; if( ddz>EPS && step>EPS ) - points = Interpolate( profiles, ddz, step, left, right, main_profiles ); + CreateProfiles(profiles, ddz, step, left, right, points, main_profiles, + Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, Create3dPres, Create2dPres ); +} + +void HYDROData_DTM::ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire) +{ + //its also possible to use BrepAlgo_NormalProjection here! + BRepTools_WireExplorer ex(TopoDS::Wire(inpWire.Oriented(TopAbs_FORWARD))); + BRepLib_MakeWire WM; + for (;ex.More();ex.Next()) + { + const TopoDS_Edge& CE = ex.Current(); + double f, l; + Handle(Geom_Curve) C3d = BRep_Tool::Curve(CE, f, l); + Handle(Geom_Curve) ProjectedCurve = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d, f, l), RefPlane, RefPlane->Position().Direction(), Standard_True); + TopoDS_Edge ProjEdge = BRepLib_MakeEdge(ProjectedCurve); + WM.Add(ProjEdge); //auto sharing between edges if vertex is coincident + } + outWire = WM.Wire(); + outWire.Orientation(inpWire.Orientation()); //take from the original wire +} - TopoDS_Compound cmp = Create3DShape( left, right, main_profiles); - SetShape(DataTag_DTM_Shape, cmp); //more safe way is to add each wire (left/right banks etc. with separate tag) - SetAltitudePoints( points ); +void HYDROData_DTM::Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF ) +{ + Handle_Geom_Plane refpl = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1)); + BRepLib_MakeWire WM; + TopoDS_Iterator it(cmp); + //TopTools_IndexedMapOfShape IntW; + for (;it.More(); it.Next()) + { + const TopoDS_Wire& W = TopoDS::Wire(it.Value()); + if (W.Orientation() != TopAbs_INTERNAL) + { + //use list of edges to protect againts non-manifold cases. + //auto sharing between edges will be added automatically + TopTools_IndexedMapOfShape ME; + TopTools_ListOfShape LE; + TopExp::MapShapes(W, TopAbs_EDGE, ME); + for (int i = 1; i <= ME.Extent(); i++) + LE.Append(ME(i)); + WM.Add(LE); + } + //else + // IntW.Add(W); + } + + TopoDS_Wire outW; + ProjWireOnPlane(WM.Wire(), refpl, outW); + BRepBuilderAPI_MakeFace mf(refpl, outW); //check inside is true by def + outF = mf.Face(); + + ///!!! the internal wires cant be added with 'internal' ori. + // it's possible to do with brep builder yet the result will not be correct! + // more proper way is to use BOP operation here. + /*for (int i = 1; i <= IntW.Extent(); i++) + { + TopoDS_Wire outIW; + const TopoDS_Wire& W = TopoDS::Wire(IntW(i)); + ProjWireOnPlane(W, refpl, outIW); + BB.Add(outF, outIW); + }*/ +} + +void HYDROData_DTM::CreateProfiles(const std::vector& theProfiles, + double theDDZ, + double theSpatialStep, + AltitudePoints& theOutLeft, + AltitudePoints& theOutRight, + AltitudePoints& theOutPoints, + std::vector& theOutMainProfiles, + TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet, + bool Create3dPres, + bool Create2dPres) +{ + if (theProfiles.empty()) + return; + theOutPoints = Interpolate( theProfiles, theDDZ, theSpatialStep, theOutLeft, theOutRight, theOutMainProfiles ); + //note that if Create3dPres is false => Create2dPres flag is meaningless! + if (Create3dPres) + { + TopTools_IndexedMapOfOrientedShape ll = Create3DShape( theOutLeft, theOutRight, theOutMainProfiles); + + if (ll.IsEmpty()) + return; + BRep_Builder BB; + TopoDS_Compound cmp; + BB.MakeCompound(cmp); + for (int i = 1; i <= ll.Extent(); i++) + BB.Add(cmp, ll(i)); + + Out3dPres = cmp; + + //same order as in HYDROData_DTM::Update() + OutLeftB = ll(1); + OutRightB = ll(ll.Extent()); + OutInlet = ll(2); + OutOutlet = ll(ll.Extent() - 1); + + if (Create2dPres) + { + TopoDS_Face outF; + Get2dFaceFrom3dPres(cmp, outF); + Out2dPres = outF; + }; + } } diff --git a/src/HYDROData/HYDROData_DTM.h b/src/HYDROData/HYDROData_DTM.h index 6892c66b..fec5fe05 100644 --- a/src/HYDROData/HYDROData_DTM.h +++ b/src/HYDROData/HYDROData_DTM.h @@ -30,7 +30,10 @@ class gp_Pnt; class gp_Vec2d; class TopoDS_Edge; class TopoDS_Wire; +class TopoDS_Face; class TopoDS_Compound; +class Handle_Geom_Plane; +class TopTools_IndexedMapOfOrientedShape; DEFINE_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry ) @@ -49,7 +52,12 @@ protected: DataTag_Profiles, DataTag_DDZ, DataTag_SpatialStep, - DataTag_DTM_Shape, + DataTag_LeftBankShape, + DataTag_RightBankShape, + DataTag_InletShape, + DataTag_OutletShape, + DataTag_3DShape, + DataTag_2DShape }; public: @@ -141,9 +149,53 @@ protected: static void PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W ); - static TopoDS_Compound Create3DShape(const AltitudePoints& left, - const AltitudePoints& right, - const std::vector& main_profiles); + static void ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire); + + static TopTools_IndexedMapOfOrientedShape Create3DShape(const AltitudePoints& left, + const AltitudePoints& right, + const std::vector& main_profiles); + + static void CreateProfiles(const std::vector& theProfiles, + double theDDZ, + double theSpatialStep, + AltitudePoints& theOutLeft, + AltitudePoints& theOutRight, + AltitudePoints& theOutPoints, + std::vector& theOutMainProfiles, + TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet, + bool Create3dPres, + bool Create2dPres ); + + static void Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF ); + + void GetPresentationShapes( TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet ); +public: + + HYDRODATA_EXPORT static void CreateProfilesFromDTM ( const HYDROData_SequenceOfObjects& InpProfiles, + double ddz, + double step, + AltitudePoints& points, + TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet, + bool Create3dPres, + bool Create2dPres ); }; + + + #endif diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 06a85fef..6fbe09f4 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -64,16 +64,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include #include @@ -86,6 +76,7 @@ #include #include +#include #include @@ -210,6 +201,21 @@ bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM, if( profiles.Length() < 2 ) return false; + TopoDS_Shape Out3dPres; + TopoDS_Shape Out2dPres; + TopoDS_Shape OutLeftB; + TopoDS_Shape OutRightB; + TopoDS_Shape OutInlet; + TopoDS_Shape OutOutlet; + + theDTM->GetPresentationShapes(Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet); + + thePrs.myInlet = TopoDS::Wire(OutInlet); + thePrs.myOutlet = TopoDS::Wire(OutOutlet); + thePrs.myLeftBank = TopoDS::Wire(OutLeftB); + thePrs.myRightBank = TopoDS::Wire(OutRightB); + thePrs.myPrs2D = Out2dPres; + thePrs.myPrs3D = Out3dPres; /*std::vector profiles3d; profiles3d.reserve(profiles.Length()); @@ -228,7 +234,6 @@ bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM, profiles3d.push_back( TopoDS::Wire(aProfileShape) ); }*/ - CreatePresentationsIntern( theDTM, thePrs ); return true; } @@ -282,7 +287,7 @@ QColor HYDROData_Stream::DefaultBorderColor() const bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis ) { if ( theHydAxis.IsNull() ) - return false; + return true; TopoDS_Shape aHydraulicShape = theHydAxis->GetShape(); if ( aHydraulicShape.IsNull() || @@ -392,23 +397,32 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProf return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar ); } +#include + bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis, const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane, Standard_Real& theOutPar ) { - if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) ) + if ( theProfile.IsNull() /*|| !IsValidAsAxis( theHydAxis )*/ ) return false; + if (theHydAxis.IsNull()) + return true; //empty h_axis; its's OK + TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() ); - if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() ) + if ( aProfileWire.IsNull() ) return false; - BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction()); - if(!aProjector.IsDone()) + //BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction()); + BRepAlgo_NormalProjection nproj(thePlane); + nproj.Add(aProfileWire); + nproj.SetDefaultParams(); + nproj.Build(); + if(!nproj.IsDone()) return false; - TopoDS_Shape aPrjProfile = aProjector.Shape(); + TopoDS_Shape aPrjProfile = nproj.Projection(); if(aPrjProfile.IsNull()) return false; TopoDS_Vertex aV1, aV2; @@ -644,21 +658,21 @@ void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, TopoDS_Face& thePlane ) { - if ( !IsValidAsAxis( theHydAxis ) ) - return false; - - TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); - - gp_Ax2 aX2(gp::XOY()); - gp_Ax3 aX3(aX2); - gp_Pln aPln(aX3); - Bnd_Box B; - BRepBndLib::Add(aHydraulicWire,B); - Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; - B.Get(axmin,aymin,azmin,axmax,aymax,azmax); - BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation - if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false; - thePlane = TopoDS::Face(aMkr.Shape()); + //if ( !IsValidAsAxis( theHydAxis ) ) + // return false; + + //TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); + // + //gp_Ax2 aX2(gp::XOY()); + //gp_Ax3 aX3(aX2); + //gp_Pln aPln(aX3); + //Bnd_Box B; + //BRepBndLib::Add(aHydraulicWire,B); + //Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; + //B.Get(axmin,aymin,azmin,axmax,aymax,azmax); + //BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation + //if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false; + thePlane = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1))).Face(); return true; } @@ -1045,231 +1059,6 @@ void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination, } } -static void ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire) -{ - BRepTools_WireExplorer ex(TopoDS::Wire(inpWire.Oriented(TopAbs_FORWARD))); - BRepLib_MakeWire WM; - for (;ex.More();ex.Next()) - { - const TopoDS_Edge& CE = ex.Current(); - double f, l; - Handle(Geom_Curve) C3d = BRep_Tool::Curve(CE, f, l); - Handle(Geom_Curve) ProjectedCurve = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d, f, l), RefPlane, RefPlane->Position().Direction(), Standard_True); - TopoDS_Edge ProjEdge = BRepLib_MakeEdge(ProjectedCurve); - WM.Add(ProjEdge); //auto sharing between edges if vertex is coincident - } - outWire = WM.Wire(); - outWire.Orientation(inpWire.Orientation()); //take from the original wire -} - - -static void Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF ) -{ - Handle_Geom_Plane refpl = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1)); - BRepLib_MakeWire WM; - TopoDS_Iterator it(cmp); - //TopTools_IndexedMapOfShape IntW; - for (;it.More(); it.Next()) - { - const TopoDS_Wire& W = TopoDS::Wire(it.Value()); - if (W.Orientation() != TopAbs_INTERNAL) - { - //use list of edges to protect againts non-manifold cases. - //auto sharing between edges will be added automatically - TopTools_IndexedMapOfShape ME; - TopTools_ListOfShape LE; - TopExp::MapShapes(W, TopAbs_EDGE, ME); - for (int i = 1; i <= ME.Extent(); i++) - LE.Append(ME(i)); - WM.Add(LE); - } - //else - // IntW.Add(W); - } - - TopoDS_Wire outW; - ProjWireOnPlane(WM.Wire(), refpl, outW); - BRepBuilderAPI_MakeFace mf(refpl, outW); //check inside is true by def - outF = mf.Face(); - - ///!!! the internal wires cant be added with 'internal' ori. - // it's possible to do with brep builder yet the result will not be correct! - // more proper way is to use BOP operation here. - /*for (int i = 1; i <= IntW.Extent(); i++) - { - TopoDS_Wire outIW; - const TopoDS_Wire& W = TopoDS::Wire(IntW(i)); - ProjWireOnPlane(W, refpl, outIW); - BB.Add(outF, outIW); - }*/ -} - -void HYDROData_Stream::CreatePresentationsIntern( const Handle_HYDROData_DTM& theDTM, - PrsDefinition& thePrs ) -{ - TopoDS_Compound cmp = TopoDS::Compound(theDTM->GetShape(HYDROData_DTM::DataTag_DTM_Shape)); - thePrs.myPrs3D = cmp; - NCollection_Sequence WW; - TopoDS_Iterator it(cmp); - for (;it.More(); it.Next()) - WW.Append(TopoDS::Wire(it.Value())); - - //same order as in HYDROData_DTM::Update() - thePrs.myLeftBank = WW.First(); - thePrs.myRightBank = WW.Last(); - thePrs.myInlet = WW(1); //TODO check this!! - thePrs.myOutlet = WW(WW.Length() - 1); - - TopoDS_Face outF; - Get2dFaceFrom3dPres(cmp, outF); - thePrs.myPrs2D = outF; - - /*if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) { - return false; - } - - if ( theArrayOfFPnt->Length() != theArrayOfLPnt->Length() ) { - return false; - } - - // Construct of the 3D presentation - Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (theArrayOfFPnt); - if(aBSpline.IsNull()) - return false; - - TopoDS_Edge anEdgLeft, anEdgRight; - - BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline); - if(aMakeEdge.IsDone()) - anEdgLeft = aMakeEdge.Edge(); - - if(anEdgLeft.IsNull()) - return false; - - aBSpline.Nullify(); - aBSpline = buildInterpolationCurve (theArrayOfLPnt); - if(aBSpline.IsNull()) - return false; - - aMakeEdge.Init(aBSpline); - if(aMakeEdge.IsDone()) - anEdgRight = aMakeEdge.Edge(); - - if(anEdgRight.IsNull()) - return false; - - BRep_Builder aBB; - TopoDS_Compound aCmp; - aBB.MakeCompound(aCmp); - for (int i=1 ; i < theArrOfProfiles->Length() +1; i++ ) - aBB.Add(aCmp, theArrOfProfiles->Value(i)); - - aBB.Add(aCmp,anEdgLeft); - aBB.Add(aCmp,anEdgRight); - BRepCheck_Analyzer aCh(aCmp); - if(aCh.IsValid()) - thePrs.myPrs3D = aCmp; -#ifdef DEB_UPDATE - else { - BRepTools::Write(aCmp, "str3d.brep"); - thePrs.myPrs3D = aCmp; - } -#endif - - // Construct the top presentation - int aNbPoints = theArrayOfFPnt->Length(); - Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints); - Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints); - for( int i=1; i <= aNbPoints; i++ ) { - gp_Pnt aPnt = theArrayOfFPnt->Value(i); - aPnt.SetZ(.0); // make 2d - anArrayOfFPnt->SetValue(i, aPnt); - aPnt = theArrayOfLPnt->Value(i); - aPnt.SetZ(.0); - anArrayOfLPnt->SetValue(i, aPnt); - } - - aBSpline.Nullify(); - aBSpline = buildInterpolationCurve (anArrayOfFPnt); - if(aBSpline.IsNull()) - return false; - - aMakeEdge.Init(aBSpline); - if(aMakeEdge.IsDone()) - anEdgLeft = aMakeEdge.Edge(); - - aBSpline.Nullify(); - aBSpline = buildInterpolationCurve (anArrayOfLPnt); - if(aBSpline.IsNull()) - return false; - - aMakeEdge.Init(aBSpline); - if(aMakeEdge.IsDone()) - anEdgRight = aMakeEdge.Edge(); - if(anEdgRight.IsNull()) - return false; - - BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1)); - TopoDS_Edge aBotEdge, aTopEdge; - if(aMakeEdge2.IsDone()) - aBotEdge = aMakeEdge2.Edge(); - - BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length())); - if(aMakeEdge3.IsDone()) - aTopEdge = aMakeEdge3.Edge(); - - // Make wire for 2D presentation with updating of corresponding edges - BRepBuilderAPI_MakeWire aMakeWire; - - aMakeWire.Add( aBotEdge ); - thePrs.myInlet = aMakeWire.Edge(); - - aMakeWire.Add( anEdgLeft ); - thePrs.myLeftBank = aMakeWire.Edge(); - - aMakeWire.Add( aTopEdge ); - thePrs.myOutlet = aMakeWire.Edge(); - - aMakeWire.Add( anEdgRight ); - thePrs.myRightBank = aMakeWire.Edge(); - - TopoDS_Wire aSectProfileWire; - if(aMakeWire.IsDone()) - aSectProfileWire = aMakeWire.Wire(); - - BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True ); - TopoDS_Face aFace; - aMakeFace.Build(); - if( aMakeFace.IsDone() ) - aFace = aMakeFace.Face(); - - TopoDS_Shape aPrs2D; - - if ( !theArrOf2DProfiles.IsNull() ) { - aCmp.Nullify(); - aBB.MakeCompound(aCmp); - aBB.Add(aCmp,aFace); - for(int i=1;i <= theArrOf2DProfiles->Length(); i++) - aBB.Add(aCmp, theArrOf2DProfiles->Value(i)); - - aPrs2D = aCmp; - } else { - aPrs2D = aFace; - } - - aCh.Init(aPrs2D); - if(aCh.IsValid()) - thePrs.myPrs2D = aPrs2D; -#ifdef DEB_UPDATE - else { - BRepTools::Write(aPrs2D, "str2d.brep"); - thePrs.myPrs2D = aPrs2D; - } -#endif - - return true;*/ -} - void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt, const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt, const Handle(TopTools_HArray1OfShape) theArrOfProfiles, @@ -1293,11 +1082,13 @@ void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) } std::vector dummy; - TopoDS_Compound cmp = HYDROData_DTM::Create3DShape(left, right, dummy); - TopoDS_Iterator it(cmp); - thePrs.myLeftBank = TopoDS::Wire(it.Value()); - it.Next(); - thePrs.myRightBank = TopoDS::Wire(it.Value()); + TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy); + + if (!ll.IsEmpty()) + { + thePrs.myLeftBank = TopoDS::Wire(ll(1)); + thePrs.myRightBank = TopoDS::Wire(ll(2)); + } thePrs.myInlet = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that thePrs.myOutlet = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper())); @@ -1313,6 +1104,6 @@ void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) thePrs.myPrs3D = newCmp; - Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D) ); + HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D) ); } \ No newline at end of file diff --git a/src/HYDROData/HYDROData_Stream.h b/src/HYDROData/HYDROData_Stream.h index e17e3bd4..36a1a248 100644 --- a/src/HYDROData/HYDROData_Stream.h +++ b/src/HYDROData/HYDROData_Stream.h @@ -83,13 +83,6 @@ public: HYDRODATA_EXPORT static bool CreatePresentations( const Handle_HYDROData_DTM& theDTM, PrsDefinition& thePrs ); - /** - * Creates the presentations(2D and 3D) by given first points, last points and profiles. - * If 2D profiles is null - they will not used in the presentation. - */ - HYDRODATA_EXPORT static void CreatePresentationsIntern( const Handle_HYDROData_DTM& theDTM, - PrsDefinition& thePrs ); - HYDRODATA_EXPORT static void CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt, const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt, const Handle(TopTools_HArray1OfShape) theArrOfProfiles, diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx index 208b483f..a1cc548f 100644 --- a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx @@ -119,10 +119,11 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin } // Connect signals and slots - connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), - this, SIGNAL( AxisChanged( const QString& ) ) ); + connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( AxisChanged( const QString& ) ) ); connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) ); connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) ); + connect( myDDZ, SIGNAL( valueChanged (double) ), this, SLOT (onDDZValueChanged(double))); + connect( mySpatialStep, SIGNAL( valueChanged (double) ), this, SLOT (onSSValueChanged(double))); } HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg() @@ -137,8 +138,8 @@ void HYDROGUI_StreamDlg::reset() myAxes->clear(); myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() ); - myAddButton->setEnabled( false ); - myRemoveButton->setEnabled( false ); + myAddButton->setEnabled( true ); + myRemoveButton->setEnabled( true ); blockSignals( isBlocked ); } @@ -171,7 +172,7 @@ void HYDROGUI_StreamDlg::setAxisName( const QString& theName ) if ( aNewId != myAxes->currentIndex() ) { myAxes->setCurrentIndex( aNewId ); } - myAddButton->setEnabled( myAxes->currentIndex() > -1 ); + //myAddButton->setEnabled( myAxes->currentIndex() > -1 ); blockSignals( isBlocked ); } @@ -216,6 +217,17 @@ void HYDROGUI_StreamDlg::onRemoveProfiles() emit RemoveProfiles( aSelectedProfiles ); } +void HYDROGUI_StreamDlg::onDDZValueChanged(double d) +{ + emit DDZValueChanged( d ); +} + +void HYDROGUI_StreamDlg::onSSValueChanged(double d) +{ + emit SSValueChanged( d ); +} + + void HYDROGUI_StreamDlg::setDDZ( const double theDDZ ) { myDDZ->setValue( theDDZ ); diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.h b/src/HYDROGUI/HYDROGUI_StreamDlg.h index ee2c4441..11a6fd90 100644 --- a/src/HYDROGUI/HYDROGUI_StreamDlg.h +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.h @@ -60,9 +60,13 @@ signals: void AddProfiles(); void RemoveProfiles( const QStringList& ); void AxisChanged( const QString& ); + void DDZValueChanged (double d); + void SSValueChanged (double d); private slots: void onRemoveProfiles(); + void onDDZValueChanged(double d); + void onSSValueChanged(double d); private: QGroupBox* myObjectNameGroup; diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index 0e7020de..467d1285 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -151,8 +152,11 @@ void HYDROGUI_StreamOp::startOperation() // set the existing 2D polylines names to the panel aPanel->setAxisNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) ); - aPanel->setDDZ( myEditedObject->GetDDZ() ); - aPanel->setSpatialStep( myEditedObject->GetSpatialStep() ); + if (myIsEdit) + { + aPanel->setDDZ( myEditedObject->GetDDZ() ); + aPanel->setSpatialStep( myEditedObject->GetSpatialStep() ); + } // synchronize the panel state with the edited object state updatePanelData(); @@ -183,6 +187,8 @@ HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const connect( aPanel, SIGNAL( AxisChanged( const QString& ) ), this, SLOT( onAxisChanged( const QString& ) ) ); + connect( aPanel, SIGNAL( DDZValueChanged( double ) ), this, SLOT( onDDZValueChanged( double ) ) ); + connect( aPanel, SIGNAL( SSValueChanged( double ) ), this, SLOT( onSSValueChanged( double ) ) ); return aPanel; } @@ -216,14 +222,13 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, if ( myEditedObject.IsNull() ) // Create new data model object myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) ); - // Check if the axis is set Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) ); - if ( aHydAxis.IsNull() ) - { - theErrorMsg = tr( "AXIS_NOT_DEFINED" ); - return false; - } + //if ( aHydAxis.IsNull() ) + //{ + // theErrorMsg = tr( "AXIS_NOT_DEFINED" ); + // return false; + //} // Check if at least 2 profiles is set HYDROData_SequenceOfObjects aRefProfiles; @@ -318,7 +323,9 @@ void HYDROGUI_StreamOp::createPreview() HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) ); HYDROData_SequenceOfObjects aRefProfiles; - for ( int i = 0; i < myProfiles.length(); ++i ) + //std::vector aRefProfiles; + int plen = myProfiles.length(); + for ( int i = 0; i < plen; ++i ) { QString aProfileName = myProfiles.value( i ); @@ -329,11 +336,27 @@ void HYDROGUI_StreamOp::createPreview() } HYDROData_Stream::PrsDefinition aPrsDef; - /*TODO: if ( !HYDROData_Stream::CreatePresentations( aHydAxis, aRefProfiles, aPrsDef ) ) - { - erasePreview(); - return; - }*/ + + TopoDS_Shape Out3dPres; + TopoDS_Shape Out2dPres; + TopoDS_Shape OutLeftB; + TopoDS_Shape OutRightB; + TopoDS_Shape OutInlet; + TopoDS_Shape OutOutlet; + + HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); + double ddz = aPanel->getDDZ(); + double ss = aPanel->getSpatialStep(); + + HYDROData_DTM::CreateProfilesFromDTM( aRefProfiles, ddz, ss, HYDROData_Bathymetry::AltitudePoints(), Out3dPres, Out2dPres, OutLeftB, OutRightB, + OutInlet, OutOutlet, true, true); + + aPrsDef.myInlet = TopoDS::Wire(OutInlet); + aPrsDef.myOutlet = TopoDS::Wire(OutOutlet); + aPrsDef.myLeftBank = TopoDS::Wire(OutLeftB); + aPrsDef.myRightBank = TopoDS::Wire(OutRightB); + aPrsDef.myPrs2D = Out2dPres; + aPrsDef.myPrs3D = Out3dPres; myPreviewPrs->setShape( aPrsDef.myPrs2D ); } @@ -351,10 +374,11 @@ void HYDROGUI_StreamOp::onAddProfiles() { Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) ); - if ( aHydAxis.IsNull() ) - return; + //if ( aHydAxis.IsNull() ) + // return; TopoDS_Face aPlane; + if ( !HYDROData_Stream::BuildFace( aHydAxis, aPlane ) ) return; @@ -398,6 +422,7 @@ void HYDROGUI_StreamOp::onAddProfiles() else { // Insert profile in correct place + // if hidr axis is null => the params (myProfileParams) will be igrored. So ordering will be the same as in the aSelectedProfiles insertProfileInToOrder( aProfileName, aProfilePar, myProfiles, myProfileParams ); aVerifiedProfiles << aProfileName; } @@ -472,6 +497,16 @@ void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove } } +void HYDROGUI_StreamOp::onDDZValueChanged( double d ) +{ + createPreview(); +} + +void HYDROGUI_StreamOp::onSSValueChanged( double d ) +{ + createPreview(); +} + void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis ) { // Get axis object diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.h b/src/HYDROGUI/HYDROGUI_StreamOp.h index 277bb0a8..cb45e50d 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.h +++ b/src/HYDROGUI/HYDROGUI_StreamOp.h @@ -51,6 +51,8 @@ private slots: void onAddProfiles(); void onRemoveProfiles( const QStringList& ); void onAxisChanged( const QString& ); + void onDDZValueChanged( double d ); + void onSSValueChanged( double d ); private: void createPreview();