From c7fb1d87acef2fe3ea2f79094bf32b91bf262b79 Mon Sep 17 00:00:00 2001 From: mzn Date: Thu, 11 Jun 2015 16:19:50 +0300 Subject: [PATCH] refs #567, 569: build face, coloring. --- src/HYDROData/HYDROData_LandCover.cxx | 113 +++++++++++++++++++++++++- src/HYDROData/HYDROData_LandCover.h | 41 +++++++++- src/HYDROGUI/HYDROGUI_DataModel.cxx | 2 +- src/HYDROGUI/HYDROGUI_LandCoverOp.cxx | 37 +++------ src/HYDROGUI/HYDROGUI_Module.cxx | 2 +- src/HYDROGUI/HYDROGUI_SetColorOp.cxx | 20 ++++- src/HYDROGUI/HYDROGUI_Shape.cxx | 20 ++++- src/HYDROGUI/HYDROGUI_Tool.cxx | 4 +- 8 files changed, 203 insertions(+), 36 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCover.cxx b/src/HYDROData/HYDROData_LandCover.cxx index 180f6404..3680865c 100644 --- a/src/HYDROData/HYDROData_LandCover.cxx +++ b/src/HYDROData/HYDROData_LandCover.cxx @@ -20,10 +20,20 @@ #include "HYDROData_PolylineXY.h" +#include #include #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #include IMPLEMENT_STANDARD_HANDLE( HYDROData_LandCover, HYDROData_Entity ) @@ -124,6 +134,52 @@ HYDROData_SequenceOfObjects HYDROData_LandCover::GetPolylines() const return GetReferenceObjects( DataTag_Polylines ); } +TopoDS_Shape HYDROData_LandCover::GetShape() const +{ + TopoDS_Shape aShape; + + TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false ); + if ( !aLabel.IsNull() ) + { + Handle(TNaming_NamedShape) aNamedShape; + if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) { + aShape = aNamedShape->Get(); + } + } + + return aShape; +} + +void HYDROData_LandCover::SetFillingColor( const QColor& theColor ) +{ + SetColor( theColor, DataTag_FillingColor ); +} + +QColor HYDROData_LandCover::GetFillingColor() const +{ + return GetColor( DefaultFillingColor(), DataTag_FillingColor ); +} + +void HYDROData_LandCover::SetBorderColor( const QColor& theColor ) +{ + SetColor( theColor, DataTag_BorderColor ); +} + +QColor HYDROData_LandCover::GetBorderColor() const +{ + return GetColor( DefaultBorderColor(), DataTag_BorderColor ); +} + +QColor HYDROData_LandCover::DefaultFillingColor() +{ + return QColor( Qt::magenta ); +} + +QColor HYDROData_LandCover::DefaultBorderColor() +{ + return QColor( Qt::transparent ); +} + void HYDROData_LandCover::setShape( const TopoDS_Shape& theShape ) { TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) ); @@ -143,6 +199,9 @@ TopoDS_Shape HYDROData_LandCover::buildShape() const TopoDS_Shape aResShape; ///< \TODO to be reimplemented + TopoDS_Shape anArgShape; + TopTools_ListOfShape aToolShapes; + HYDROData_SequenceOfObjects aRefPolylines = GetPolylines(); for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) { Handle(HYDROData_PolylineXY) aPolyline = @@ -152,10 +211,58 @@ TopoDS_Shape HYDROData_LandCover::buildShape() const continue; } - if ( aPolyline->IsClosed() ) { - aResShape = aPolyline->GetShape(); - break; + if ( !aPolyline->IsClosed() ) { + continue; + } + + TopoDS_Shape aPolyShape = aPolyline->GetShape(); + if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) { + continue; + } + + const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape ); + if ( aPolylineWire.IsNull() ) { + continue; + } + + TopoDS_Face aResultFace = TopoDS_Face(); + BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True ); + aMakeFace.Build(); + if( aMakeFace.IsDone() ) { + aResultFace = aMakeFace.Face(); + } + + if( aResultFace.IsNull() ) { + continue; + } + + if ( anArgShape.IsNull() ) { + anArgShape = aResultFace; + } else { + aToolShapes.Append( aResultFace ); + } + } + + aResShape = anArgShape; + + if ( !anArgShape.IsNull() && aToolShapes.Extent() > 0 ) { + Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator; + BOPAlgo_BOP aBOP(aAL); + + aBOP.AddArgument( anArgShape ); + + TopTools_ListIteratorOfListOfShape anIt(aToolShapes); + for( ; anIt.More(); anIt.Next() ) { + aBOP.AddTool( anIt.Value() ); + } + + aBOP.SetOperation( BOPAlgo_CUT ); + aBOP.Perform(); + + if ( !aBOP.Shape().IsNull() ) { + aResShape = aBOP.Shape(); } } + return aResShape; } \ No newline at end of file diff --git a/src/HYDROData/HYDROData_LandCover.h b/src/HYDROData/HYDROData_LandCover.h index d740e7b4..3bba4a9e 100644 --- a/src/HYDROData/HYDROData_LandCover.h +++ b/src/HYDROData/HYDROData_LandCover.h @@ -35,7 +35,9 @@ protected: DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve DataTag_Shape, ///< the shape presentation of the land cover DataTag_StricklerType, ///< the type corresponding to types in the Strickler tables - DataTag_Polylines ///< the set of reference polylines + DataTag_Polylines, ///< the set of reference polylines + DataTag_FillingColor, ///< filling color of the land cover presentation + DataTag_BorderColor ///< border color of the land cover presentation }; HYDRODATA_EXPORT HYDROData_LandCover(); @@ -89,9 +91,44 @@ public: */ HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetPolylines() const; + /** + * Returns the shape presentation of the land cover. + */ + HYDRODATA_EXPORT virtual TopoDS_Shape GetShape() const; + + /** + * Sets filling color for land cover. + */ + HYDRODATA_EXPORT virtual void SetFillingColor( const QColor& theColor ); + + /** + * Returns filling color of land cover. + */ + HYDRODATA_EXPORT virtual QColor GetFillingColor() const; + + /** + * Sets border color for land cover. + */ + HYDRODATA_EXPORT virtual void SetBorderColor( const QColor& theColor ); + + /** + * Returns border color of land cover. + */ + HYDRODATA_EXPORT virtual QColor GetBorderColor() const; + + /** + * Returns default filling color for new land cover. + */ + HYDRODATA_EXPORT static QColor DefaultFillingColor(); + + /** + * Returns default border color for new land cover. + */ + HYDRODATA_EXPORT static QColor DefaultBorderColor(); + protected: /** - * Sets shape presentation of the land cover. + * Sets the shape presentation of the land cover. */ HYDRODATA_EXPORT virtual void setShape( const TopoDS_Shape& theShape ); diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index 061428ea..06a0ab41 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -720,7 +720,7 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* aKind == KIND_SHAPES_GROUP || aKind == KIND_SPLITTED_GROUP || aKind == KIND_ZONE || aKind == KIND_IMMERSIBLE_ZONE || aKind == KIND_REGION || aKind == KIND_BATHYMETRY || aKind == KIND_OBSTACLE || aKind == KIND_STREAM || aKind == KIND_CHANNEL || - aKind == KIND_DIGUE || aKind == KIND_DUMMY_3D; + aKind == KIND_DIGUE || aKind == KIND_DUMMY_3D || aKind == KIND_LAND_COVER; if ( !visibility ) { Handle(HYDROData_Profile) aProfObj = Handle(HYDROData_Profile)::DownCast( theModelObject ); diff --git a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx index d8b4fdc3..492e871d 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx @@ -80,24 +80,16 @@ void HYDROGUI_LandCoverOp::startOperation() { anObjectName = myEditedObject->GetName(); - // TODO: Temporary commented until getPolylinesCount, GetPolyline and GetStricklerType data model methods will be implemented - /* - int nNoPolylines = myEditedObject->getPolylinesCount(); - for (int i=0; iGetPolyline(i); - if ( !aRefPolyline.IsNull() ) - aSelectedPolylines.append( aRefPolyline->GetName() ); + HYDROData_SequenceOfObjects aRefPolylines = myEditedObject->GetPolylines(); + for ( int i = aRefPolylines.Lower(); i <= aRefPolylines.Upper(); i++ ) { + Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) ); + if ( !aPolyline.IsNull() ) { + aSelectedPolylines.append( aPolyline->GetName() ); + } } - - aSelectedStricklerType = myEditedObject->GetStricklerType(); - */ - - // The code below is a sample of data filling Land cover object - aSelectedPolylines.append( "Lake_1" ); - aSelectedPolylines.append( "Polyline_1" ); - aSelectedStricklerType = "Canaux naturels"; } + + aSelectedStricklerType = myEditedObject->GetStricklerType(); } aPanel->setObjectName( anObjectName ); @@ -184,7 +176,7 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, } } - QList aZonePolylines; + HYDROData_SequenceOfObjects aZonePolylines; QString aStricklerType; QStringList aSelectedPolylineNames = aPanel->getSelectedPolylineNames(); @@ -194,7 +186,7 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, QString aPolylineName = *anIt; if ( !aPolylineName.isEmpty() ) { - aZonePolylines.append( Handle(HYDROData_PolylineXY)::DownCast( + aZonePolylines.Append( Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) ) ); } } @@ -215,19 +207,14 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, aZoneObj->SetName( anObjectName ); - // TODO: Temporary commented until SetFillingColor, DefaultFillingColor, - // SetBorderColor and DefaultBorderColor data model methods will be implemented - /* if ( !myIsEdit ) { aZoneObj->SetFillingColor( HYDROData_LandCover::DefaultFillingColor() ); aZoneObj->SetBorderColor( HYDROData_LandCover::DefaultBorderColor() ); } - */ - // TODO: Temporary commented until SetPolylines and SetStricklerType data model methods will be implemented - //aZoneObj->SetPolylines( aZonePolylines ); - //aZoneObj->SetStricklerType( aSelectedStricklerType ); + aZoneObj->SetPolylines( aZonePolylines ); + aZoneObj->SetStricklerType( aSelectedStricklerType ); aZoneObj->Update(); closePreview(); diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 00094e9f..f84dcebf 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -695,7 +695,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle || anIsStream || anIsChannel || anIsDigue || anIsDummyObject3D || - anIsValidProfile || anIsGroup ) + anIsValidProfile || anIsGroup || anIsLandCover ) { if( anIsHiddenInSelection ) theMenu->addAction( action( ShowId ) ); diff --git a/src/HYDROGUI/HYDROGUI_SetColorOp.cxx b/src/HYDROGUI/HYDROGUI_SetColorOp.cxx index 3dbe5dbe..45b88dee 100644 --- a/src/HYDROGUI/HYDROGUI_SetColorOp.cxx +++ b/src/HYDROGUI/HYDROGUI_SetColorOp.cxx @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -49,7 +50,8 @@ bool HYDROGUI_SetColorOp::CanObjectBeColored( const Handle(HYDROData_Entity)& th return false; return theObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) || - theObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ); + theObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ) || + theObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ); } void HYDROGUI_SetColorOp::startOperation() @@ -95,6 +97,14 @@ void HYDROGUI_SetColorOp::startOperation() anIsOneColor = true; } + else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) ) + { + Handle(HYDROData_LandCover) aLandCover = + Handle(HYDROData_LandCover)::DownCast( myEditedObject ); + + aFirstColor = aLandCover->GetFillingColor(); + aSecondColor = aLandCover->GetBorderColor(); + } // Create color dialog myColorDlg = new HYDROGUI_ColorDlg( module()->getApp()->desktop(), anIsOneColor ); @@ -146,6 +156,14 @@ bool HYDROGUI_SetColorOp::processApply( int& theUpdateFlags, aPolyObject->SetWireColor( aFirstColor ); } + else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) ) + { + Handle(HYDROData_LandCover) aLandCover = + Handle(HYDROData_LandCover)::DownCast( myEditedObject ); + + aLandCover->SetFillingColor( aFirstColor ); + aLandCover->SetBorderColor( aSecondColor ); + } module()->setIsToUpdate( myEditedObject ); diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index c430bb51..339f9453 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -18,6 +18,8 @@ #include #include +#include + #include #include #include @@ -29,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -298,6 +300,22 @@ void HYDROGUI_Shape::update( bool isUpdateViewer, setShape( aCompound, false, false ); } + else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) ) + { + Handle(HYDROData_LandCover) aLandCoverObj = + Handle(HYDROData_LandCover)::DownCast( myObject ); + + TopoDS_Shape aLandCoverShape = aLandCoverObj->GetShape(); + if ( !aLandCoverShape.IsNull() ) { + setShape( aLandCoverShape, false, false ); + } + + QColor aFillingColor = aLandCoverObj->GetFillingColor(); + QColor aBorderColor = aLandCoverObj->GetBorderColor(); + + setFillingColor( aFillingColor, false, false ); + setBorderColor( aBorderColor, false, false ); + } } if ( myShape.IsNull() || !isVisible() ) diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 83cdad60..45e356eb 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -209,7 +209,6 @@ void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule, bool HYDROGUI_Tool::IsObjectHasPresentation( const Handle(HYDROData_Entity)& theObject, const QString& theViewerType ) { - if ( theObject.IsNull() ) return false; @@ -228,7 +227,8 @@ bool HYDROGUI_Tool::IsObjectHasPresentation( const Handle(HYDROData_Entity)& the anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE || anObjectKind == KIND_DUMMY_3D || - anObjectKind == KIND_BATHYMETRY + anObjectKind == KIND_BATHYMETRY || + anObjectKind == KIND_LAND_COVER #ifdef DEB_GROUPS || anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP -- 2.39.2