From: adv Date: Fri, 21 Mar 2014 10:03:17 +0000 (+0000) Subject: Channel and digue objects creation improved to do not use the transaction during... X-Git-Tag: BR_hydro_v1_0_1~33 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ffb8db1342d5e9eaed69dc15dd51eacfd77da0bd;p=modules%2Fhydro.git Channel and digue objects creation improved to do not use the transaction during it modification. --- diff --git a/src/HYDROData/HYDROData_Channel.cxx b/src/HYDROData/HYDROData_Channel.cxx index 1f2b6355..cc8706e5 100644 --- a/src/HYDROData/HYDROData_Channel.cxx +++ b/src/HYDROData/HYDROData_Channel.cxx @@ -19,7 +19,6 @@ #include #include #include -#include //#define DEB_CHANNEL 1 #ifdef DEB_CHANNEL @@ -85,22 +84,18 @@ TopoDS_Shape HYDROData_Channel::GetShape3D() const return getShape3D(); } -void HYDROData_Channel::Update() +bool HYDROData_Channel::CreatePresentaions( const Handle(HYDROData_Polyline3D)& theGuideLine, + const Handle(HYDROData_Profile)& theProfile, + PrsDefinition& thePrs ) { - HYDROData_ArtificialObject::Update(); - - Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine(); - Handle(HYDROData_Profile) aProfile = GetProfile(); - if ( aGuideLine.IsNull() || aProfile.IsNull() ) - return; + if ( theGuideLine.IsNull() || theProfile.IsNull() ) + return false; // build 3d shape - TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D()); - if(aPathWire.IsNull()) - return; - TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() ); - if(aProfileWire.IsNull()) - return; + TopoDS_Wire aPathWire = TopoDS::Wire( theGuideLine->GetShape3D() ); + TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetShape3D() ); + if ( aPathWire.IsNull() || aProfileWire.IsNull() ) + return false; #ifdef DEB_CHANNEL BRepTools::Write( aPathWire, "guideline.brep" ); @@ -109,45 +104,57 @@ void HYDROData_Channel::Update() HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire ); if( aChannelConstructor.GetStatus() != 0 ) - return; + return false; aChannelConstructor.Create3dPresentation(); aChannelConstructor.Create2dPresentation(); - SetShape3D( aChannelConstructor.Get3dPresentation() ); - SetTopShape( aChannelConstructor.Get2dPresentation() ); + thePrs.myPrs3D = aChannelConstructor.Get3dPresentation(); + thePrs.myPrs2D = aChannelConstructor.Get2dPresentation(); + + thePrs.myLeftBank = aChannelConstructor.GetLeftBank(); + thePrs.myRightBank = aChannelConstructor.GetRightBank(); + thePrs.myInlet = aChannelConstructor.GetInlet(); + thePrs.myOutlet = aChannelConstructor.GetOutlet(); #ifdef DEB_CHANNEL - BRepTools::Write( aChannelConstructor.Get2dPresentation(), "channel2d.brep" ); - BRepTools::Write( aChannelConstructor.Get3dPresentation(), "channel3d.brep" ); + BRepTools::Write( thePrs.myPrs2D, "channel2d.brep" ); + BRepTools::Write( thePrs.myPrs3D, "channel3d.brep" ); + HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", thePrs.myPrs2D, TopAbs_EDGE ); + HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", thePrs.myLeftBank, TopAbs_EDGE ); + HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", thePrs.myRightBank, TopAbs_EDGE ); + HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", thePrs.myInlet, TopAbs_EDGE ); + HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", thePrs.myOutlet, TopAbs_EDGE ); #endif - TopAbs_ShapeEnum aType = GetTopShape().ShapeType(); + return true; +} - // Create groups for channel - TopoDS_Wire aLeftBank = aChannelConstructor.GetLeftBank(); - TopoDS_Wire aRightBank = aChannelConstructor.GetRightBank(); - TopoDS_Wire anInlet = aChannelConstructor.GetInlet(); - TopoDS_Wire anOutlet = aChannelConstructor.GetOutlet(); +void HYDROData_Channel::Update() +{ + HYDROData_ArtificialObject::Update(); -#ifdef DEB_CHANNEL - HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", GetTopShape(), TopAbs_EDGE ); - HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", aLeftBank, TopAbs_EDGE ); - HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", aRightBank, TopAbs_EDGE ); - HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", anInlet, TopAbs_EDGE ); - HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", anOutlet, TopAbs_EDGE ); -#endif + Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine(); + Handle(HYDROData_Profile) aProfile = GetProfile(); + + PrsDefinition aResultPrs; + if ( !CreatePresentaions( aGuideLine, aProfile, aResultPrs ) ) + return; + + SetShape3D( aResultPrs.myPrs3D ); + SetTopShape( aResultPrs.myPrs2D ); + // Create groups for channel TopTools_SequenceOfShape aLeftBankEdges; - HYDROData_ShapesTool::ExploreShapeToShapes( aLeftBank, TopAbs_EDGE, aLeftBankEdges ); + HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myLeftBank, TopAbs_EDGE, aLeftBankEdges ); TopTools_SequenceOfShape aRightBankEdges; - HYDROData_ShapesTool::ExploreShapeToShapes( aRightBank, TopAbs_EDGE, aRightBankEdges ); + HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myRightBank, TopAbs_EDGE, aRightBankEdges ); TopTools_SequenceOfShape anInletEdges; - HYDROData_ShapesTool::ExploreShapeToShapes( anInlet, TopAbs_EDGE, anInletEdges ); + HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myInlet, TopAbs_EDGE, anInletEdges ); TopTools_SequenceOfShape anOutletEdges; - HYDROData_ShapesTool::ExploreShapeToShapes( anOutlet, TopAbs_EDGE, anOutletEdges ); + HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myOutlet, TopAbs_EDGE, anOutletEdges ); QString aLeftGroupName = GetName() + "_Left_Bank"; diff --git a/src/HYDROData/HYDROData_Channel.h b/src/HYDROData/HYDROData_Channel.h index b3b4483c..f497f36e 100644 --- a/src/HYDROData/HYDROData_Channel.h +++ b/src/HYDROData/HYDROData_Channel.h @@ -4,6 +4,9 @@ #include "HYDROData_ArtificialObject.h" +#include +#include + class Handle(HYDROData_Polyline3D); class Handle(HYDROData_Profile); class TopTools_SequenceOfShape; @@ -17,6 +20,18 @@ DEFINE_STANDARD_HANDLE(HYDROData_Channel, HYDROData_ArtificialObject) */ class HYDROData_Channel : public HYDROData_ArtificialObject { +public: + + struct PrsDefinition + { + TopoDS_Shape myPrs3D; + TopoDS_Face myPrs2D; + TopoDS_Wire myLeftBank; + TopoDS_Wire myRightBank; + TopoDS_Wire myInlet; + TopoDS_Wire myOutlet; + }; + protected: /** * Enumeration of tags corresponding to the persistent object parameters. @@ -29,8 +44,20 @@ protected: }; public: + DEFINE_STANDARD_RTTI(HYDROData_Channel); +public: + + /** + * Creates the presentation by given guide line and profile. + */ + HYDRODATA_EXPORT static bool CreatePresentaions( const Handle(HYDROData_Polyline3D)& theGuideLine, + const Handle(HYDROData_Profile)& theProfile, + PrsDefinition& thePrs ); + +public: + /** * Returns the kind of this object. Must be redefined in all objects of known type. */ diff --git a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx index fe415317..4078af04 100644 --- a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx @@ -59,41 +59,42 @@ void HYDROGUI_ChannelOp::startOperation() { HYDROGUI_Operation::startOperation(); - // We start operation in the document - startDocOperation(); - HYDROGUI_ChannelDlg* aPanel = ::qobject_cast( inputPanel() ); aPanel->blockSignals( true ); aPanel->reset(); - myEditedObject = getObjectToEdit(); + myEditedObject.Nullify(); QString aSelectedGuideLine, aSelectedProfile; QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CHANNEL_NAME" ) ); - if ( myIsEdit && !myEditedObject.IsNull() ) + if ( myIsEdit ) { - anObjectName = myEditedObject->GetName(); + myEditedObject = + Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if ( !myEditedObject.IsNull() ) + { + anObjectName = myEditedObject->GetName(); - Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine(); - if ( !aRefGuideLine.IsNull() ) - aSelectedGuideLine = aRefGuideLine->GetName(); + Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine(); + if ( !aRefGuideLine.IsNull() ) + aSelectedGuideLine = aRefGuideLine->GetName(); - Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile(); - if ( !aRefProfile.IsNull() ) - aSelectedProfile = aRefProfile->GetName(); + Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile(); + if ( !aRefProfile.IsNull() ) + aSelectedProfile = aRefProfile->GetName(); + } } // collect information about existing 3d polylines QStringList aGuideLines; - QStringList anAllGuideLines = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINE ); - foreach( QString aGuideLine, anAllGuideLines ) + HYDROData_Iterator aPolylinesIt( doc(), KIND_POLYLINE ); + for ( ; aPolylinesIt.More(); aPolylinesIt.Next() ) { - Handle( HYDROData_Polyline3D ) aPolyline3d = - Handle( HYDROData_Polyline3D )::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aGuideLine, KIND_POLYLINE ) ); + Handle(HYDROData_Polyline3D) aPolyline3d = + Handle(HYDROData_Polyline3D)::DownCast( aPolylinesIt.Current() ); if( !aPolyline3d.IsNull() ) { TopoDS_Shape aShape = aPolyline3d->GetShape3D(); @@ -101,7 +102,7 @@ void HYDROGUI_ChannelOp::startOperation() { TopoDS_Wire aWire = TopoDS::Wire( aShape ); if( !aWire.Closed() ) - aGuideLines.append( aGuideLine ); + aGuideLines.append( aPolyline3d->GetName() ); } } } @@ -119,22 +120,18 @@ void HYDROGUI_ChannelOp::startOperation() aPanel->blockSignals( false ); - onCreatePreview( true ); + onCreatePreview(); } - void HYDROGUI_ChannelOp::abortOperation() { erasePreview(); - abortDocOperation(); - HYDROGUI_Operation::abortOperation(); } void HYDROGUI_ChannelOp::commitOperation() { erasePreview(); - HYDROGUI_Operation::commitOperation(); } @@ -170,17 +167,39 @@ bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags, } } + if ( myEditedObject.IsNull() ) - return false; + myEditedObject = createNewObject(); // Create new data model object myEditedObject->SetName( anObjectName ); if ( !myIsEdit ) { - myEditedObject->SetFillingColor( HYDROData_Channel::DefaultFillingColor() ); - myEditedObject->SetBorderColor( HYDROData_Channel::DefaultBorderColor() ); + myEditedObject->SetFillingColor( getDefaultFillingColor() ); + myEditedObject->SetBorderColor( getDefaultBorderColor() ); } + QString aGuideLineName = aPanel->getGuideLineName(); + QString aProfileName = aPanel->getProfileName(); + if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() ) + { + myEditedObject->RemoveGuideLine(); + myEditedObject->RemoveProfile(); + } + else + { + Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) ); + myEditedObject->SetGuideLine( aGuideLine ); + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + myEditedObject->SetProfile( aProfile ); + } + + if ( myEditedObject->IsMustBeUpdated() ) + myEditedObject->Update(); + erasePreview(); if( !myIsEdit ) @@ -193,53 +212,42 @@ bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags, return true; } -Handle(HYDROData_Channel) HYDROGUI_ChannelOp::getObjectToEdit() const +Handle(HYDROData_Channel) HYDROGUI_ChannelOp::createNewObject() const +{ + return Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) ); +} + +QColor HYDROGUI_ChannelOp::getDefaultFillingColor() const +{ + return HYDROData_Channel::DefaultFillingColor(); +} + +QColor HYDROGUI_ChannelOp::getDefaultBorderColor() const { - return myIsEdit ? Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ) : - Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) ); + return HYDROData_Channel::DefaultBorderColor(); } -void HYDROGUI_ChannelOp::onCreatePreview( const bool theIsInit ) +void HYDROGUI_ChannelOp::onCreatePreview() { HYDROGUI_ChannelDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel || myEditedObject.IsNull() ) + if ( !aPanel ) return; QString aGuideLineName = aPanel->getGuideLineName(); QString aProfileName = aPanel->getProfileName(); if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() ) { - if ( !theIsInit ) - { - myEditedObject->RemoveGuideLine(); - myEditedObject->RemoveProfile(); - myEditedObject->Update(); - } - erasePreview(); return; } - // Update channel data - if ( !theIsInit ) - { - Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) ); - myEditedObject->SetGuideLine( aGuideLine ); - - Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); - myEditedObject->SetProfile( aProfile ); - - if ( myEditedObject->IsMustBeUpdated() ) - myEditedObject->Update(); - } - LightApp_Application* anApp = module()->getApp(); if ( !getPreviewManager() ) + { setPreviewManager( ::qobject_cast( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); + } OCCViewer_ViewManager* aViewManager = getPreviewManager(); if ( aViewManager && !myPreviewPrs ) @@ -248,14 +256,38 @@ void HYDROGUI_ChannelOp::onCreatePreview( const bool theIsInit ) { Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); if ( !aCtx.IsNull() ) - myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject, getPreviewZLayer() ); + myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); } } if ( !aViewManager || !myPreviewPrs ) return; - myPreviewPrs->update( true ); + Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) ); + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + + HYDROData_Channel::PrsDefinition aPrsDef; + if ( !HYDROData_Channel::CreatePresentaions( aGuideLine, aProfile, aPrsDef ) ) + { + erasePreview(); + return; + } + + QColor aFillingColor = getDefaultFillingColor(); + QColor aBorderColor = getDefaultBorderColor(); + if ( !myEditedObject.IsNull() ) + { + aFillingColor = myEditedObject->GetFillingColor(); + aBorderColor = myEditedObject->GetBorderColor(); + } + + myPreviewPrs->setFillingColor( aFillingColor, false, false ); + myPreviewPrs->setBorderColor( aBorderColor, false, false ); + + myPreviewPrs->setShape( aPrsDef.myPrs2D ); } void HYDROGUI_ChannelOp::erasePreview() diff --git a/src/HYDROGUI/HYDROGUI_ChannelOp.h b/src/HYDROGUI/HYDROGUI_ChannelOp.h index eb15b4e8..798d7a89 100644 --- a/src/HYDROGUI/HYDROGUI_ChannelOp.h +++ b/src/HYDROGUI/HYDROGUI_ChannelOp.h @@ -49,14 +49,18 @@ protected: virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); protected slots: - virtual void onCreatePreview( const bool theIsInit = false ); + virtual void onCreatePreview(); protected: virtual void erasePreview(); - virtual Handle(HYDROData_Channel) getObjectToEdit() const; + virtual Handle(HYDROData_Channel) createNewObject() const; - virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; }; + virtual QColor getDefaultFillingColor() const; + + virtual QColor getDefaultBorderColor() const; + + virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; }; protected: bool myIsEdit; diff --git a/src/HYDROGUI/HYDROGUI_DigueOp.cxx b/src/HYDROGUI/HYDROGUI_DigueOp.cxx index 0d8c6073..f16708f3 100644 --- a/src/HYDROGUI/HYDROGUI_DigueOp.cxx +++ b/src/HYDROGUI/HYDROGUI_DigueOp.cxx @@ -75,8 +75,17 @@ HYDROGUI_InputPanel* HYDROGUI_DigueOp::createInputPanel() const return aPanel; } -Handle(HYDROData_Channel) HYDROGUI_DigueOp::getObjectToEdit() const +Handle(HYDROData_Channel) HYDROGUI_DigueOp::createNewObject() const { - return myIsEdit ? Handle(HYDROData_Digue)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ) : - Handle(HYDROData_Digue)::DownCast( doc()->CreateObject( KIND_DIGUE ) ); + return Handle(HYDROData_Digue)::DownCast( doc()->CreateObject( KIND_DIGUE ) ); +} + +QColor HYDROGUI_DigueOp::getDefaultFillingColor() const +{ + return HYDROData_Digue::DefaultFillingColor(); +} + +QColor HYDROGUI_DigueOp::getDefaultBorderColor() const +{ + return HYDROData_Digue::DefaultBorderColor(); } diff --git a/src/HYDROGUI/HYDROGUI_DigueOp.h b/src/HYDROGUI/HYDROGUI_DigueOp.h index 429baf62..782626a7 100644 --- a/src/HYDROGUI/HYDROGUI_DigueOp.h +++ b/src/HYDROGUI/HYDROGUI_DigueOp.h @@ -43,7 +43,11 @@ protected: protected: - virtual Handle(HYDROData_Channel) getObjectToEdit() const; + virtual Handle(HYDROData_Channel) createNewObject() const; + + virtual QColor getDefaultFillingColor() const; + + virtual QColor getDefaultBorderColor() const; private: