Salome HOME
refs #567, 569: build face, coloring.
authormzn <mzn@opencascade.com>
Thu, 11 Jun 2015 13:19:50 +0000 (16:19 +0300)
committermzn <mzn@opencascade.com>
Thu, 11 Jun 2015 13:19:50 +0000 (16:19 +0300)
src/HYDROData/HYDROData_LandCover.cxx
src/HYDROData/HYDROData_LandCover.h
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_LandCoverOp.cxx
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_SetColorOp.cxx
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_Tool.cxx

index 180f640481f2297b78088bdf50be42e764296068..3680865ca4a39b611265412e37f81b1c11311233 100644 (file)
 
 #include "HYDROData_PolylineXY.h"
 
+#include <BRepBuilderAPI_MakeFace.hxx>
 #include <TDataStd_AsciiString.hxx>
 #include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <NCollection_IncAllocator.hxx>
+#include <BOPAlgo_BOP.hxx>
 
+#include <QColor>
 #include <QStringList>
 
 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
index d740e7b4d765351c61289447aeb1c5d4a8db55a8..3bba4a9e7e895d07d7a049b06ad2c843d5fab3cf 100644 (file)
@@ -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 );
 
index 061428eaa17ca8c4e9fdfe24d817f9c62476b0b3..06a0ab41c2da1dcd98b9dd276a91b111a720b5c9 100644 (file)
@@ -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 );
index d8b4fdc36811221377d778809512b54583fd8076..492e871d1512400d072cc0c42061df009d02c98e 100644 (file)
@@ -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; i<nNoPolylines; i++)
-      {
-        Handle(HYDROData_PolylineXY) aRefPolyline = myEditedObject->GetPolyline(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<Handle(HYDROData_PolylineXY)> 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();
index 00094e9ff40961c3a83329fe70e59aa27a6352fc..f84dcebf8d79af10b4d97c896f4ad2ec7b0e8421 100644 (file)
@@ -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 ) );
index 3dbe5dbe9d5be75ae93468b76d7770b66b333751..45b88dee547714b95df652013d88289608f6d0db 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <HYDROData_Object.h>
 #include <HYDROData_IPolyline.h>
+#include <HYDROData_LandCover.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_UpdateFlags.h>
@@ -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 );
 
index c430bb5163bfcc962ed867f22361ca8b43c155b8..339f9453e054787e8a4f54925a84b2563de992f3 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <HYDROGUI_Shape.h>
 #include <HYDROGUI_Tool.h>
+#include <HYDROGUI_Polyline.h>
+
 #include <HYDROData_Channel.h>
 #include <HYDROData_Document.h>
 #include <HYDROData_DummyObject3D.h>
@@ -29,7 +31,7 @@
 #include <HYDROData_ShapesGroup.h>
 #include <HYDROData_Stream.h>
 #include <HYDROData_Zone.h>
-#include <HYDROGUI_Polyline.h>
+#include <HYDROData_LandCover.h>
 
 #include <AIS_Shape.hxx>
 #include <BRep_Builder.hxx>
@@ -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() )
index 83cdad6035e229bfa2e2dbfe417dba2a5b28cd8f..45e356eba33aecb89808930ffa822a9753b8dbb1 100644 (file)
@@ -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