From da9306621bb30b015b5b71febf0de6b2f2380909 Mon Sep 17 00:00:00 2001 From: asl Date: Wed, 18 Dec 2013 09:25:45 +0000 Subject: [PATCH] debug of immersible zones creation --- src/HYDROData/HYDROData_ImmersibleZone.cxx | 35 ++++++------ src/HYDROData/HYDROData_ImmersibleZone.h | 8 ++- src/HYDROData/HYDROData_PolylineXY.cxx | 63 ++++++++++------------ src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx | 37 ++++++------- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 4 ++ 5 files changed, 68 insertions(+), 79 deletions(-) diff --git a/src/HYDROData/HYDROData_ImmersibleZone.cxx b/src/HYDROData/HYDROData_ImmersibleZone.cxx index 29bc3a6d..cd7e4817 100644 --- a/src/HYDROData/HYDROData_ImmersibleZone.cxx +++ b/src/HYDROData/HYDROData_ImmersibleZone.cxx @@ -109,9 +109,13 @@ void HYDROData_ImmersibleZone::Update() TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const { - TopoDS_Shape aResShape = TopoDS_Face(); + return generateTopShape( GetPolyline() ); +} + +TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline ) +{ + TopoDS_Face aResultFace = TopoDS_Face(); - Handle(HYDROData_PolylineXY) aPolyline = GetPolyline(); if( !aPolyline.IsNull() ) { TopoDS_Shape aPolylineShape = aPolyline->GetShape(); @@ -136,7 +140,8 @@ TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const } } if(aWiresList.IsEmpty()) - return aResShape; + return aResultFace; + BRepAlgo_FaceRestrictor aFR; TopoDS_Face aRefFace; TopoDS_Shape aS = aWiresList.First(); @@ -146,7 +151,8 @@ TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const aRefFace = aMakeFace.Face(); } if(aRefFace.IsNull()) - return aResShape; + return aResultFace; + aFR.Init(aRefFace,Standard_False, Standard_True); TopTools_ListIteratorOfListOfShape anIt( aWiresList ); for ( ; anIt.More(); anIt.Next() ) { @@ -157,25 +163,18 @@ TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const } aFR.Perform(); if (aFR.IsDone()) { - TopoDS_Compound aResult; - BRep_Builder aBB; - aBB.MakeCompound(aResult); for (; aFR.More(); aFR.Next()) { - const TopoDS_Face& aFF = aFR.Current(); - aBB.Add(aResult,aFF); - } - BRepCheck_Analyzer aChecker(aResult); - if(aChecker.IsValid()) - aResShape = aResult; -#ifdef HYDRODATA_IMZONE_DEB - else { - aResShape = aResult; + aResultFace = aFR.Current(); + break; } -#endif } } } - return aResShape; + BRepCheck_Analyzer anAnalyzer( aResultFace ); + if( anAnalyzer.IsValid() && aResultFace.ShapeType()==TopAbs_FACE ) + return aResultFace; + else + return TopoDS_Face(); } void HYDROData_ImmersibleZone::createGroupObjects() diff --git a/src/HYDROData/HYDROData_ImmersibleZone.h b/src/HYDROData/HYDROData_ImmersibleZone.h index 6370cf45..68ca0e9c 100644 --- a/src/HYDROData/HYDROData_ImmersibleZone.h +++ b/src/HYDROData/HYDROData_ImmersibleZone.h @@ -83,6 +83,9 @@ public: */ HYDRODATA_EXPORT virtual void RemovePolyline(); + HYDRODATA_EXPORT TopoDS_Shape generateTopShape() const; + HYDRODATA_EXPORT static TopoDS_Shape generateTopShape( const Handle(HYDROData_PolylineXY)& ); + protected: /** @@ -97,11 +100,6 @@ protected: private: - /** - * Generate the zone face. - */ - TopoDS_Shape generateTopShape() const; - /** * Create all necessary child group objects. */ diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index eaea172a..5129d6e8 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -244,50 +245,40 @@ void HYDROData_PolylineXY::Update() Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape; Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape; TopTools_ListIteratorOfListOfShape it(aSectionWiresList); - for(;it.More();it.Next()) { - TopoDS_Iterator it2(it.Value()); - for(;it2.More();it2.Next()) - aSeqEdges->Append(it2.Value()); + for(;it.More();it.Next()) + { + TopExp_Explorer it2(it.Value(), TopAbs_EDGE); + for(;it2.More();it2.Next()) + aSeqEdges->Append(it2.Current()); } BRep_Builder aBB; TopoDS_Compound aCmp; + TopoDS_Shape aResult; aBB.MakeCompound(aCmp); - if(aSeqEdges->Length() >1) { - ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,Precision::Confusion(),Standard_True,aSeqWires); - for (Standard_Integer i = 1; i <= aSeqWires->Length();i++) { - const TopoDS_Shape& aS1 = aSeqWires->Value(i); - aBB.Add(aCmp, aS1); + if(aSeqEdges->Length() >1) + { + ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires); + + if( aSeqWires->Length()==1 ) + aResult = aSeqWires->Value( 1 ); + else + { + for (Standard_Integer i = 1; i <= aSeqWires->Length();i++) + { + const TopoDS_Shape& aS1 = aSeqWires->Value(i); + aBB.Add(aCmp, aS1); + } + aResult = aCmp; + } } - } else if (aSeqEdges->Length() == 1) { + else if (aSeqEdges->Length() == 1) + { BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1))); - if (mkWire.IsDone()) - aBB.Add(aCmp, mkWire.Wire()); + if (mkWire.IsDone()) + aResult = mkWire.Wire(); } - -/* - if ( aMakeWire.IsDone() ) - { - aShape = aMakeWire.Shape(); - } - else if ( !aSectionWiresList.IsEmpty() ) - { - // build compound - TopoDS_Compound aCompound; - - BRep_Builder aBuilder; - aBuilder.MakeCompound( aCompound ); - - TopTools_ListIteratorOfListOfShape anIter( aSectionWiresList ); - for ( ; anIter.More(); anIter.Next() ) - { - aBuilder.Add( aCompound, anIter.Value() ); - } - - aShape = aCompound; - } -*/ - setPolylineShape( aCmp ); + setPolylineShape( aResult ); } /** diff --git a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx index 276d51af..1dc958e4 100644 --- a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx @@ -99,7 +99,7 @@ void HYDROGUI_ImmersibleZoneOp::startOperation() { Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() ); - if ( aPolylineObj.IsNull() || !aPolylineObj->IsClosed() ) + if ( aPolylineObj.IsNull() )//TODO: || !aPolylineObj->IsClosed() ) continue; QString aPolylineName = aPolylineObj->GetName(); @@ -185,11 +185,6 @@ bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags, } } - Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject : - Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) ); - if ( aZoneObj.IsNull() ) - return false; - Handle(HYDROData_PolylineXY) aZonePolyline; Handle(HYDROData_Bathymetry) aZoneBathymetry; @@ -207,6 +202,16 @@ bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags, HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) ); } + + if ( HYDROData_ImmersibleZone::generateTopShape( aZonePolyline ).IsNull() ) + { + theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ); + return false; + } + + Handle(HYDROData_ImmersibleZone) aZoneObj = myIsEdit ? myEditedObject : + Handle(HYDROData_ImmersibleZone)::DownCast( doc()->CreateObject( KIND_IMMERSIBLE_ZONE ) ); + aZoneObj->SetName( anObjectName ); if ( !myIsEdit ) @@ -235,17 +240,13 @@ void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName if ( !aPanel ) return; - TopoDS_Wire aWire; - TopoDS_Shape aShape; + TopoDS_Shape aZoneShape; Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINEXY ) ); if ( !aPolyline.IsNull() ) { - aShape = aPolyline->GetShape(); - if ( aShape.ShapeType() == TopAbs_WIRE ) { - aWire = TopoDS::Wire( aShape ); - } + aZoneShape = HYDROData_ImmersibleZone::generateTopShape( aPolyline ); } LightApp_Application* anApp = module()->getApp(); @@ -275,14 +276,10 @@ void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName myPreviewPrs->setFillingColor( aFillingColor, false, false ); myPreviewPrs->setBorderColor( aBorderColor, false, false ); - if ( !aWire.IsNull() ) { - myPreviewPrs->setFace( aWire ); - } else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND ) { - TopoDS_Compound aCompound = TopoDS::Compound( aShape ); - if ( !aCompound.IsNull() ) { - myPreviewPrs->setFaces( aCompound ); - } - } + TopoDS_Face aFace; + if( !aZoneShape.IsNull() ) + aFace = TopoDS::Face( aZoneShape ); + myPreviewPrs->setFace( aFace ); } void HYDROGUI_ImmersibleZoneOp::closePreview() diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index e2faf2ec..f0f517f5 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -136,6 +136,10 @@ does not exist or you have not enough permissions to open it. OBJECT_EXISTS_IN_DOCUMENT Object with name '%1' already exists in the document. + + ZONE_OBJECT_CANNOT_BE_CREATED + Zone can not be created + SAVE_ERROR Study could not be saved -- 2.39.2