From 8e79913fc37eacbd1edf9dc08632b6f8bc7250d8 Mon Sep 17 00:00:00 2001 From: adv Date: Mon, 24 Mar 2014 05:08:37 +0000 Subject: [PATCH] Stream object creation improved to do not use the transaction during it modification. --- src/HYDROData/HYDROData_Stream.cxx | 184 +++++++++---- src/HYDROData/HYDROData_Stream.h | 58 +++- src/HYDROGUI/HYDROGUI_StreamOp.cxx | 421 ++++++++++++++++++----------- src/HYDROGUI/HYDROGUI_StreamOp.h | 5 + 4 files changed, 450 insertions(+), 218 deletions(-) diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 3b67a6b5..128239ea 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -151,34 +151,33 @@ bool HYDROData_Stream::IsHas2dPrs() const return true; } -void HYDROData_Stream::UpdatePrs() +bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis, + const HYDROData_SequenceOfObjects& theProfiles, + PrsDefinition& thePrs ) { - HYDROData_NaturalObject::Update(); + if ( theHydAxis.IsNull() || theProfiles.Length() < 2 ) + return false; - Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); - HYDROData_SequenceOfObjects aRefProfiles = GetProfiles(); - if ( aHydAxis.IsNull() || aRefProfiles.Length() < 2 ) - return; - - bool anIsFirst = true; gp_Pnt aPrevFirstPoint, aPrevLastPoint; - Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length()); - Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length()); - TopTools_Array1OfShape anArrOfProfiles(1, aRefProfiles.Length()); - TopTools_Array1OfShape anArrOf2DProfiles(1, aRefProfiles.Length()); + Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length()); + Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length()); + TopTools_Array1OfShape anArrOfProfiles(1, theProfiles.Length()); + TopTools_Array1OfShape anArrOf2DProfiles(1, theProfiles.Length()); // Pre-processing - HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles ); + HYDROData_SequenceOfObjects::Iterator anIter( theProfiles ); for (int i=1 ; anIter.More(); anIter.Next(),i++ ) { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( anIter.Value() ); if ( aProfile.IsNull() ) - continue; + continue; + const TopoDS_Shape& aProf3d = aProfile->GetShape3D(); gp_XY aPnt1, aPnt2; if ( !aProfile->GetLeftPoint( aPnt1 ) || !aProfile->GetRightPoint( aPnt2 ) ) continue; + anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape(); anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape()); @@ -203,37 +202,45 @@ void HYDROData_Stream::UpdatePrs() // Construct of the 3D presentation Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt); if(aBSpline.IsNull()) - return; + return false; + TopoDS_Edge anEdgLeft, anEdgRight; + BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline); if(aMakeEdge.IsDone()) anEdgLeft = aMakeEdge.Edge(); + if(anEdgLeft.IsNull()) - return; + return false; + aBSpline.Nullify(); aBSpline = buildInterpolationCurve (anArrayOfLPnt); if(aBSpline.IsNull()) - return; + return false; + aMakeEdge.Init(aBSpline); if(aMakeEdge.IsDone()) anEdgRight = aMakeEdge.Edge(); + if(anEdgRight.IsNull()) - return; + return false; + BRep_Builder aBB; TopoDS_Compound aCmp; aBB.MakeCompound(aCmp); - anIter.Init( aRefProfiles ); + anIter.Init( theProfiles ); for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ ) aBB.Add(aCmp, anArrOfProfiles.Value(i)); + aBB.Add(aCmp,anEdgLeft); aBB.Add(aCmp,anEdgRight); BRepCheck_Analyzer aCh(aCmp); if(aCh.IsValid()) - SetShape3D(aCmp); + thePrs.myPrs3D = aCmp; #ifdef DEB_UPDATE else { BRepTools::Write(aCmp, "str3d.brep"); - SetShape3D(aCmp); + thePrs.myPrs3D = aCmp; } #endif @@ -246,26 +253,32 @@ void HYDROData_Stream::UpdatePrs() aPnt.SetZ(.0); anArrayOfLPnt->SetValue(i, aPnt); } + aBSpline.Nullify(); aBSpline = buildInterpolationCurve (anArrayOfFPnt); if(aBSpline.IsNull()) - return; + return false; + aMakeEdge.Init(aBSpline); if(aMakeEdge.IsDone()) anEdgLeft = aMakeEdge.Edge(); + aBSpline.Nullify(); aBSpline = buildInterpolationCurve (anArrayOfLPnt); if(aBSpline.IsNull()) - return; + return false; + aMakeEdge.Init(aBSpline); if(aMakeEdge.IsDone()) anEdgRight = aMakeEdge.Edge(); if(anEdgRight.IsNull()) - return; + 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(); @@ -274,16 +287,16 @@ void HYDROData_Stream::UpdatePrs() BRepBuilderAPI_MakeWire aMakeWire; aMakeWire.Add( aBotEdge ); - aBotEdge = aMakeWire.Edge(); + thePrs.myInlet = aMakeWire.Edge(); aMakeWire.Add( anEdgLeft ); - anEdgLeft = aMakeWire.Edge(); + thePrs.myLeftBank = aMakeWire.Edge(); aMakeWire.Add( aTopEdge ); - aTopEdge = aMakeWire.Edge(); + thePrs.myOutlet = aMakeWire.Edge(); aMakeWire.Add( anEdgRight ); - anEdgRight = aMakeWire.Edge(); + thePrs.myRightBank = aMakeWire.Edge(); TopoDS_Wire aSectProfileWire; if(aMakeWire.IsDone()) @@ -300,40 +313,58 @@ void HYDROData_Stream::UpdatePrs() aBB.Add(aCmp,aFace); for(int i=1;i <= anArrOf2DProfiles.Length(); i++) aBB.Add(aCmp,anArrOf2DProfiles.Value(i)); + aCh.Init(aCmp); if(aCh.IsValid()) - SetTopShape(aCmp); + thePrs.myPrs2D = aCmp; #ifdef DEB_UPDATE else { BRepTools::Write(aCmp, "str2d.brep"); - SetTopShape(aCmp); + thePrs.myPrs2D = aCmp; } -#endif +#endif + + return true; +} + +void HYDROData_Stream::UpdatePrs() +{ + HYDROData_NaturalObject::Update(); + + Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); + HYDROData_SequenceOfObjects aRefProfiles = GetProfiles(); + + PrsDefinition aResultPrs; + if ( !CreatePresentations( aHydAxis, aRefProfiles, aResultPrs ) ) + return; + + SetShape3D( aResultPrs.myPrs3D ); + SetTopShape( aResultPrs.myPrs2D ); // Create the stream groups QString aLeftGroupName = GetName() + "_Left_Bank"; Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject(); aLeftGroup->SetName( aLeftGroupName ); - aLeftGroup->AddShape( anEdgLeft ); + aLeftGroup->AddShape( aResultPrs.myLeftBank ); QString aRightGroupName = GetName() + "_Right_Bank"; Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject(); aRightGroup->SetName( aRightGroupName ); - aRightGroup->AddShape( anEdgRight ); + aRightGroup->AddShape( aResultPrs.myRightBank ); QString anInGroupName = GetName() + "_Inlet"; Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject(); anInGroup->SetName( anInGroupName ); - anInGroup->AddShape( aBotEdge ); + anInGroup->AddShape( aResultPrs.myInlet ); QString anOutGroupName = GetName() + "_Outlet"; Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject(); anOutGroup->SetName( anOutGroupName ); - anOutGroup->AddShape( aTopEdge ); + anOutGroup->AddShape( aResultPrs.myOutlet ); } QColor HYDROData_Stream::DefaultFillingColor() @@ -456,10 +487,18 @@ void HYDROData_Stream::RemoveHydraulicAxis() SetToUpdate( true ); } +bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, + const TopoDS_Face& thePlane, + Standard_Real& theOutPar ) const +{ + Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); + return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar ); +} + bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis, - const Handle(HYDROData_Profile)& theProfile, - const TopoDS_Face& thePlane, - Standard_Real& outPar) + const Handle(HYDROData_Profile)& theProfile, + const TopoDS_Face& thePlane, + Standard_Real& theOutPar ) { if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) ) return false; @@ -512,7 +551,7 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH Standard_Integer anIndx(0); BRepExtrema_ExtCC aCC; aCC.Initialize(anEdg2); - outPar = 0.0; + theOutPar = 0.0; anExplo.Init(aHydraulicWire, TopAbs_EDGE); for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) { const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current()); @@ -534,10 +573,10 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH const gp_Pnt& aPnt = aCC.PointOnE1(anIndx); if(aNum > 1) { TopExp::Vertices(anEdg1, aV1, aV2, Standard_True); - outPar += BRep_Tool::Pnt(aV1).Distance(aPnt); + theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt); } else { Standard_Real aPar = aCC.ParameterOnE1(anIndx); - outPar = aPar; + theOutPar = aPar; } hasInt = true; break; @@ -545,12 +584,12 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH // no ints-n if(aNum > 1) { TopExp::Vertices(anEdg1, aV1, aV2); - outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2)); + theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2)); } } } else if(aNum > 1) { TopExp::Vertices(anEdg1, aV1, aV2); - outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2)); + theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2)); } } if(hasInt) @@ -558,15 +597,6 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH return false; } -bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane, - Standard_Real& outPar ) const -{ - Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); - - return HasIntersection( aHydAxis, theProfile, thePlane, outPar ); -} - - bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile ) { if ( theProfile.IsNull() ) @@ -593,6 +623,52 @@ bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile ) return true; } +bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles, + const bool& theIsToOrder ) +{ + if ( theIsToOrder ) + { + for ( int i = 1; i <= theProfiles.Length(); ++i ) + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) ); + if ( aProfile.IsNull() ) + continue; + + if ( !AddProfile( aProfile ) ) + return false; + } + } + else // Just store the sequence of objects as is + { + bool anIsToUpdate = true; + + HYDROData_SequenceOfObjects anOldProfiles = GetProfiles(); + if ( anOldProfiles.Length() == theProfiles.Length() ) + { + anIsToUpdate = false; + + for ( int i = 1; i <= theProfiles.Length(); ++i ) + { + Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i ); + Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i ); + if ( !IsEqual( anOldProfile, aNewProfile ) ) + { + anIsToUpdate = true; + break; + } + } + } + + SetReferenceObjects( theProfiles, DataTag_Profile ); + + if ( anIsToUpdate ) + SetToUpdate( true ); + } + + return true; +} + HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const { return GetReferenceObjects( DataTag_Profile ); @@ -667,7 +743,7 @@ void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& } bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, - TopoDS_Face& thePlane ) const + TopoDS_Face& thePlane ) { if ( !IsValidAsAxis( theHydAxis ) ) return false; @@ -727,7 +803,7 @@ void HYDROData_Stream::updateProfilesOrder() continue; aDM.Bind( aPar, aProfile ); - aList.Append( aPar ); + aList.Append( aPar ); } if ( aList.IsEmpty() ) diff --git a/src/HYDROData/HYDROData_Stream.h b/src/HYDROData/HYDROData_Stream.h index 2b47bd78..f44f2d24 100644 --- a/src/HYDROData/HYDROData_Stream.h +++ b/src/HYDROData/HYDROData_Stream.h @@ -3,8 +3,12 @@ #define HYDROData_Stream_HeaderFile #include "HYDROData_NaturalObject.h" + #include +#include + #include + DEFINE_STANDARD_HANDLE(HYDROData_Stream, HYDROData_NaturalObject) class Handle(HYDROData_PolylineXY); @@ -17,6 +21,18 @@ class TColStd_Array1OfReal; */ class HYDROData_Stream : public HYDROData_NaturalObject { +public: + + struct PrsDefinition + { + TopoDS_Shape myPrs3D; + TopoDS_Shape myPrs2D; + TopoDS_Edge myLeftBank; + TopoDS_Edge myRightBank; + TopoDS_Edge myInlet; + TopoDS_Edge myOutlet; + }; + protected: /** * Enumeration of tags corresponding to the persistent object parameters. @@ -30,8 +46,20 @@ protected: }; public: + DEFINE_STANDARD_RTTI(HYDROData_Stream); +public: + + /** + * Creates the presentations(2D and 3D) by given hydraulic axis and profiles. + */ + HYDRODATA_EXPORT static bool CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis, + const HYDROData_SequenceOfObjects& theProfiles, + PrsDefinition& thePrs ); + +public: + /** * Returns the kind of this object. Must be redefined in all objects of known type. */ @@ -136,27 +164,36 @@ public: * if axis presented by set of edges the returns a common length of segments till the intersection point. */ HYDRODATA_EXPORT static bool HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis, - const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane, - Standard_Real& outPar); + const Handle(HYDROData_Profile)& theProfile, + const TopoDS_Face& thePlane, + Standard_Real& theOutPar ); /** * Returns true if profile has the intersection with reference hydraulic axis. * Returns the parameter of inresection point on axis if axis is presented by one curve, * if axis presented by set of edges the returns a common length of segments till the intersection point. */ - HYDRODATA_EXPORT virtual bool HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane, - Standard_Real& outPar) const; + HYDRODATA_EXPORT virtual bool HasIntersection( const Handle(HYDROData_Profile)& theProfile, + const TopoDS_Face& thePlane, + Standard_Real& theOutPar ) const; - /** - * Builds a planar face - */ - HYDRODATA_EXPORT virtual bool BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, TopoDS_Face& thePlane) const; + /** + * Builds a planar face + */ + HYDRODATA_EXPORT static bool BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, + TopoDS_Face& thePlane ); /** * Add new one reference profile object for stream. */ HYDRODATA_EXPORT virtual bool AddProfile( const Handle(HYDROData_Profile)& theProfile ); + /** + * Add new one reference profile object for stream. + */ + HYDRODATA_EXPORT virtual bool SetProfiles( const HYDROData_SequenceOfObjects& theProfiles, + const bool& theIsToOrder = true ); + /** * Returns all reference profile objects of stream. */ @@ -195,7 +232,8 @@ protected: /** * Builds b-spline using interpolation algorithm. */ - Handle(Geom_BSplineCurve) buildInterpolationCurve(const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt); + static Handle(Geom_BSplineCurve) buildInterpolationCurve( + const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt ); /** * Returns default filling color for new object. @@ -236,3 +274,5 @@ protected: }; #endif + + diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index b85cfb80..cabf8c67 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -52,6 +52,32 @@ #include #include #include + +void insertProfileInToOrder( const QString& theProfileName, + const double& theProfilePar, + QStringList& theProfiles, + QList& theProfileParams ) +{ + bool anIsInserted = false; + for ( int k = 0; k < theProfileParams.length(); ++k ) + { + const double& aParam = theProfileParams.value( k ); + if ( theProfilePar < aParam ) + { + theProfiles.insert( k, theProfileName ); + theProfileParams.insert( k, theProfilePar ); + anIsInserted = true; + break; + } + } + + if ( !anIsInserted ) + { + theProfiles << theProfileName; + theProfileParams << theProfilePar; + } +} + HYDROGUI_StreamOp::HYDROGUI_StreamOp( HYDROGUI_Module* theModule, bool theIsEdit ) : HYDROGUI_Operation( theModule ), myIsEdit( theIsEdit ), @@ -69,36 +95,62 @@ void HYDROGUI_StreamOp::startOperation() { HYDROGUI_Operation::startOperation(); - // We start operation in the document - startDocOperation(); + myEditedObject.Nullify(); + myHydAxis.clear(); + myProfiles.clear(); + myProfileParams.clear(); // Get panel and reset its state HYDROGUI_StreamDlg* aPanel = (HYDROGUI_StreamDlg*)inputPanel(); aPanel->reset(); - // Get/create the edited object - if( myIsEdit ) { - myEditedObject = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); - if ( !myEditedObject.IsNull() && myEditedObject->IsMustBeUpdated() ) { - myEditedObject->Update(); + QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) ); + if ( myIsEdit ) + { + myEditedObject = + Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if ( !myEditedObject.IsNull() ) + { + anObjectName = myEditedObject->GetName(); + + // Hydraulic axis + Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis(); + if ( !aHydraulicAxis.IsNull() ) + { + myHydAxis = aHydraulicAxis->GetName(); + + TopoDS_Face aPlane; + if ( HYDROData_Stream::BuildFace( aHydraulicAxis, aPlane ) ) + { + // Stream profiles + HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles(); + for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i ) + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) ); + if ( aProfile.IsNull() ) + continue; + + QString aProfileName = aProfile->GetName(); + + Standard_Real aProfilePar = 0.0; + HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar ); + + myProfiles << aProfileName; + myProfileParams << aProfilePar; + } + } + } } - } else { - myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) ); - } - - // Get the edited object name - QString anObjectName; - if ( !myIsEdit ) { - anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) ); - } else if ( !myEditedObject.IsNull() ) { - anObjectName = myEditedObject->GetName(); } // Update the panel // set the edited object name aPanel->setObjectName( anObjectName ); + // set the existing 2D polylines names to the panel aPanel->setAxisNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) ); + // synchronize the panel state with the edited object state updatePanelData(); @@ -109,15 +161,12 @@ void HYDROGUI_StreamOp::startOperation() void HYDROGUI_StreamOp::abortOperation() { erasePreview(); - abortDocOperation(); - HYDROGUI_Operation::abortOperation(); } void HYDROGUI_StreamOp::commitOperation() { erasePreview(); - HYDROGUI_Operation::commitOperation(); } @@ -138,37 +187,54 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, QString& theErrorMsg ) { HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel || myEditedObject.IsNull() ) { + if ( !aPanel ) return false; - } // Check whether the object name is not empty QString anObjectName = aPanel->getObjectName().simplified(); - if ( anObjectName.isEmpty() ) { + if ( anObjectName.isEmpty() ) + { theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); return false; } // Check that there are no other objects with the same name in the document - if( myEditedObject->GetName() != anObjectName ) + if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) { Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); - if( !anObject.IsNull() ) { + if( !anObject.IsNull() ) + { theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName ); return false; } } + 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) aHydraulicAxis = myEditedObject->GetHydraulicAxis(); - if ( aHydraulicAxis.IsNull() ) { + 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; } // Check if at least 2 profiles is set - HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles(); - if ( aProfiles.Length() < 2 ) { + HYDROData_SequenceOfObjects aRefProfiles; + for ( int i = 0; i < myProfiles.length(); ++i ) + { + QString aProfileName = myProfiles.value( i ); + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + if ( !aProfile.IsNull() ) + aRefProfiles.Append( aProfile ); + } + + if ( aRefProfiles.Length() < 2 ) + { theErrorMsg = tr( "PROFILES_NOT_DEFINED" ); return false; } @@ -176,6 +242,12 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, // Set the object name myEditedObject->SetName( anObjectName ); + myEditedObject->SetHydraulicAxis( aHydAxis ); + myEditedObject->SetProfiles( aRefProfiles, false ); + + if ( myEditedObject->IsMustBeUpdated() ) + myEditedObject->Update(); + if ( !myIsEdit ) { myEditedObject->SetFillingColor( HYDROData_Stream::DefaultFillingColor() ); @@ -200,33 +272,68 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, void HYDROGUI_StreamOp::createPreview() { - if ( myEditedObject.IsNull() ) { - return; - } - LightApp_Application* anApp = module()->getApp(); if ( !getPreviewManager() ) + { setPreviewManager( ::qobject_cast( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); + } OCCViewer_ViewManager* aViewManager = getPreviewManager(); - if ( aViewManager && !myPreviewPrs ) { - if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) { + if ( aViewManager && !myPreviewPrs ) + { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) + { Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); - if ( !aCtx.IsNull() ) { - myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject, getPreviewZLayer() ); + if ( !aCtx.IsNull() ) + { + myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + + QColor aFillingColor = HYDROData_Stream::DefaultFillingColor(); + QColor aBorderColor = HYDROData_Stream::DefaultBorderColor(); + if ( !myEditedObject.IsNull() ) + { + aFillingColor = myEditedObject->GetFillingColor(); + aBorderColor = myEditedObject->GetBorderColor(); + } + + myPreviewPrs->setFillingColor( aFillingColor, false, false ); + myPreviewPrs->setBorderColor( aBorderColor, false, false ); } } } - if ( myPreviewPrs ) { - myPreviewPrs->update( true ); + if ( !aViewManager || !myPreviewPrs ) + return; + + Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) ); + + HYDROData_SequenceOfObjects aRefProfiles; + for ( int i = 0; i < myProfiles.length(); ++i ) + { + QString aProfileName = myProfiles.value( i ); + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + if ( !aProfile.IsNull() ) + aRefProfiles.Append( aProfile ); } + + HYDROData_Stream::PrsDefinition aPrsDef; + if ( !HYDROData_Stream::CreatePresentations( aHydAxis, aRefProfiles, aPrsDef ) ) + { + erasePreview(); + return; + } + + myPreviewPrs->setShape( aPrsDef.myPrs2D ); } void HYDROGUI_StreamOp::erasePreview() { - if( myPreviewPrs ) { + if( myPreviewPrs ) + { delete myPreviewPrs; myPreviewPrs = 0; } @@ -234,67 +341,78 @@ void HYDROGUI_StreamOp::erasePreview() void HYDROGUI_StreamOp::onAddProfiles() { - if ( myEditedObject.IsNull() ) { + Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) ); + if ( aHydAxis.IsNull() ) + return; + + TopoDS_Face aPlane; + if ( !HYDROData_Stream::BuildFace( aHydAxis, aPlane ) ) return; - } // Get the current profiles list - HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles(); - - // TODO: to be optimized - QStringList aCurrentProfiles; - for( int i = 1, n = aProfiles.Length(); i <= n; i++ ) { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) ); - if ( !aProfile.IsNull() ) { - aCurrentProfiles << aProfile->GetName(); - } - } + QStringList aCurrentProfiles = myProfiles; // Get the selected profiles ( in the Object Browser ) - QStringList anInvalidProfiles, anExistingProfiles, aHasNoIntersectionProfiles; + QStringList anInvalidProfiles; + QStringList anExistingProfiles; + QStringList aHasNoIntersectionProfiles; + QStringList aVerifiedProfiles; - HYDROData_SequenceOfObjects aVerifiedProfiles; HYDROData_SequenceOfObjects aSelectedProfiles = HYDROGUI_Tool::GetSelectedObjects( module() ); - Handle(HYDROData_PolylineXY) aHydAxis = myEditedObject->GetHydraulicAxis(); - if ( aHydAxis.IsNull() ) - return; - TopoDS_Face aPlane; - if(!myEditedObject->BuildFace(aHydAxis, aPlane)) - return; - Standard_Real aPar(.0); - for( int i = 1, n = aSelectedProfiles.Length(); i <= n; i++ ) { + + for( int i = 1, n = aSelectedProfiles.Length(); i <= n; i++ ) + { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aSelectedProfiles.Value( i ) ); - if ( !aProfile.IsNull() ) { - QString aProfileName = aProfile->GetName(); - - // Check the profile, if all is ok - add it to the list - if ( !aProfile->IsValid() ) { // check whether the profile is valid - anInvalidProfiles << aProfileName; - } else if ( aCurrentProfiles.contains( aProfileName ) ) { // check whether the profile is already added - anExistingProfiles << aProfileName; - } else if ( !myEditedObject->HasIntersection( aProfile, aPlane, aPar ) ) { // check whether the profile has intersection - aHasNoIntersectionProfiles << aProfileName; - } else { - aVerifiedProfiles.Append( aProfile ); - } + if ( aProfile.IsNull() ) + continue; + + QString aProfileName = aProfile->GetName(); + Standard_Real aProfilePar = 0.0; + + // Check the profile, if all is ok - add it to the list + if ( !aProfile->IsValid() ) + { + // check whether the profile is valid + anInvalidProfiles << aProfileName; + } + else if ( aCurrentProfiles.contains( aProfileName ) ) + { + // check whether the profile is already added + anExistingProfiles << aProfileName; + } + else if ( !HYDROData_Stream::HasIntersection( aHydAxis, aProfile, aPlane, aProfilePar ) ) + { + // check whether the profile has intersection + aHasNoIntersectionProfiles << aProfileName; + } + else + { + // Insert profile in correct place + insertProfileInToOrder( aProfileName, aProfilePar, myProfiles, myProfileParams ); + aVerifiedProfiles << aProfileName; } } // Show message box with the ignored profiles - if ( !anInvalidProfiles.isEmpty() || !anExistingProfiles.isEmpty() || - !aHasNoIntersectionProfiles.isEmpty() ) { + if ( !anInvalidProfiles.isEmpty() || + !anExistingProfiles.isEmpty() || + !aHasNoIntersectionProfiles.isEmpty() ) + { QString aMessage = tr( "IGNORED_PROFILES" ); - if ( !anInvalidProfiles.isEmpty() ) { + if ( !anInvalidProfiles.isEmpty() ) + { aMessage.append( "\n\n" ); aMessage.append( tr("INVALID_PROFILES").arg( anInvalidProfiles.join( "\n" ) ) ); } - if ( !anExistingProfiles.isEmpty() ) { + if ( !anExistingProfiles.isEmpty() ) + { aMessage.append( "\n\n" ); aMessage.append( tr("EXISTING_PROFILES").arg( anExistingProfiles.join( "\n" ) ) ); } - if ( !aHasNoIntersectionProfiles.isEmpty() ) { + if ( !aHasNoIntersectionProfiles.isEmpty() ) + { aMessage.append( "\n\n" ); aMessage.append( tr("NOT_INTERSECTED_PROFILES").arg( aHasNoIntersectionProfiles.join( "\n" ) ) ); } @@ -302,13 +420,8 @@ void HYDROGUI_StreamOp::onAddProfiles() SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), aMessage ); } - // Update the stream object - for( int i = 1, n = aVerifiedProfiles.Length(); i <= n; i++ ) { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aVerifiedProfiles.Value( i ) ); - myEditedObject->AddProfile( aProfile ); - } - myEditedObject->UpdatePrs(); + if ( aVerifiedProfiles.isEmpty() ) + return; // Update the panel updatePanelData(); @@ -319,37 +432,43 @@ void HYDROGUI_StreamOp::onAddProfiles() void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove ) { - if ( myEditedObject.IsNull() ) { - return; - } - - bool isRemoved = false; + QStringList aToRemove = theProfilesToRemove; // Take the Object Browser selection into account HYDROData_SequenceOfObjects aSelectedObjects = HYDROGUI_Tool::GetSelectedObjects( module() ); - for( int i = 1, n = aSelectedObjects.Length(); i <= n; i++ ) { + for( int i = 1, n = aSelectedObjects.Length(); i <= n; i++ ) + { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aSelectedObjects.Value( i ) ); - if ( !aProfile.IsNull() && !theProfilesToRemove.contains(aProfile->GetName()) ) { - if ( myEditedObject->RemoveProfile( aProfile ) ) { - isRemoved = true; - } - } + if ( aProfile.IsNull() ) + continue; + + QString aProfileName = aProfile->GetName(); + aToRemove.append( aProfileName ); } + aToRemove.removeDuplicates(); + if ( aToRemove.isEmpty() ) + return; + + bool isRemoved = false; + // Remove profiles - foreach( const QString& aProfileName, theProfilesToRemove ) { - Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); - if ( myEditedObject->RemoveProfile( aProfile ) ) { - isRemoved = true; - } - } + for ( int i = 0; i < aToRemove.length(); ++i ) + { + const QString& aProfileName = aToRemove.value( i ); + + int aProfileId = myProfiles.indexOf( aProfileName ); + if ( aProfileId < 0 ) + continue; - if ( isRemoved ) { - // Update the edited stream object - myEditedObject->UpdatePrs(); + myProfiles.removeAt( aProfileId ); + myProfileParams.removeAt( aProfileId ); + isRemoved = true; + } + if ( isRemoved ) + { // Update the panel updatePanelData(); @@ -360,17 +479,14 @@ void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis ) { - if ( myEditedObject.IsNull() ) { - return; - } - // Get axis object - Handle(HYDROData_PolylineXY) anAxis = Handle(HYDROData_PolylineXY)::DownCast( + Handle(HYDROData_PolylineXY) aNewAxis = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theNewAxis, KIND_POLYLINEXY ) ); // Prepare data for intersection check TopoDS_Face aPlane; - if ( !myEditedObject->BuildFace(anAxis, aPlane) ) { + if ( !HYDROData_Stream::BuildFace( aNewAxis, aPlane ) ) + { SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "BAD_SELECTED_POLYLINE_TLT" ), tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) ); @@ -379,24 +495,36 @@ void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis ) return; } - Standard_Real aPar(.0); + QStringList aNewProfiles; + QList aNewProfileParams; + QStringList aHasNoIntersectionProfiles; // Get list of profiles which do not intersect the axis - QStringList aHasNoIntersectionProfiles; - HYDROData_SequenceOfObjects aCurrentProfiles = myEditedObject->GetProfiles(); - for( int anIndex = 1, aLength = aCurrentProfiles.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aCurrentProfiles.Value( anIndex ) ); - if ( !aProfile.IsNull() ) { - if ( !HYDROData_Stream::HasIntersection( anAxis, aProfile, aPlane, aPar ) ) { - aHasNoIntersectionProfiles << aProfile->GetName(); - } + for ( int i = 0; i < myProfiles.length(); ++i ) + { + QString aProfileName = myProfiles.value( i ); + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + if ( aProfile.IsNull() ) + continue; + + Standard_Real aProfilePar = 0.0; + if ( HYDROData_Stream::HasIntersection( aNewAxis, aProfile, aPlane, aProfilePar ) ) + { + // Insert profile in correct place + insertProfileInToOrder( aProfileName, aProfilePar, aNewProfiles, aNewProfileParams ); + } + else + { + aHasNoIntersectionProfiles << aProfile->GetName(); } } // If there are profiles which don't intersect the new axis - show confirmation message box bool isConfirmed = true; - if ( !aHasNoIntersectionProfiles.isEmpty() ) { + if ( !aHasNoIntersectionProfiles.isEmpty() ) + { SUIT_MessageBox::StandardButtons aButtons = SUIT_MessageBox::Yes | SUIT_MessageBox::No; @@ -409,13 +537,17 @@ void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis ) } // Check if the user has confirmed axis change - if ( !isConfirmed ) { + if ( !isConfirmed ) + { // To restore the old axis updatePanelData(); - } else { - // Set axis - myEditedObject->SetHydraulicAxis( anAxis ); - myEditedObject->UpdatePrs(); + } + else + { + // Update data + myHydAxis = theNewAxis; + myProfiles = aNewProfiles; + myProfileParams = aNewProfileParams; // Update the panel updatePanelData(); @@ -428,30 +560,9 @@ void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis ) void HYDROGUI_StreamOp::updatePanelData() { HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel || myEditedObject.IsNull() ) { + if ( !aPanel ) return; - } - - // Hydraulic axis - Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis(); - if ( !aHydraulicAxis.IsNull() ) { - aPanel->setAxisName( aHydraulicAxis->GetName() ); - } else { - aPanel->setAxisName( "" ); - } - - // Stream profiles - QStringList aProfiles; - - HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles(); - for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i ) { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) ); - if ( !aProfile.IsNull() ) { - QString aProfileName = aProfile->GetName(); - aProfiles << aProfileName; - } - } - aPanel->setProfiles( aProfiles ); + aPanel->setAxisName( myHydAxis ); + aPanel->setProfiles( myProfiles ); } diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.h b/src/HYDROGUI/HYDROGUI_StreamOp.h index cee48b2d..1173b679 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.h +++ b/src/HYDROGUI/HYDROGUI_StreamOp.h @@ -26,6 +26,7 @@ #include "HYDROGUI_Operation.h" #include +#include class HYDROGUI_Shape; @@ -64,6 +65,10 @@ private: Handle(HYDROData_Stream) myEditedObject; HYDROGUI_Shape* myPreviewPrs; + + QString myHydAxis; + QStringList myProfiles; + QList myProfileParams; }; #endif -- 2.39.2