]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
#662: test for land cover map presentation
authorasl <asl@opencascade.com>
Tue, 20 Oct 2015 07:25:29 +0000 (10:25 +0300)
committerasl <asl@opencascade.com>
Tue, 20 Oct 2015 07:25:29 +0000 (10:25 +0300)
src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx
src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h
src/HYDRO_tests/CMakeLists.txt
src/HYDRO_tests/ExternalFiles.cmake
src/HYDRO_tests/TestViewer.cxx
src/HYDRO_tests/TestViewer.h
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx
src/HYDRO_tests/test_HYDROData_LandCoverMap.h

index 0128a7a311d846db9a83011603ebd4ec165a0ab5..f74fb1a556cd0d349dc7d53e009cf50ebcfc6af6 100644 (file)
 #include <HYDROData_Tool.h>
 #include <AIS_DisplayMode.hxx>
 #include <Prs3d.hxx>
+#include <Prs3d_IsoAspect.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Prs3d_ShadingAspect.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
 #include <Select3D_SensitiveBox.hxx>
 #include <StdPrs_ShadedShape.hxx>
-#include <StdPrs_WFDeflectionShape.hxx>
+#include <StdPrs_WFShape.hxx>
 #include <StdSelect.hxx>
 #include <StdSelect_BRepOwner.hxx>
 #include <StdSelect_BRepSelectionTool.hxx>
 #include <QColor>
 #include <QString>
 
+IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_Shape )
+IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_Shape )
+
+HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
+  : AIS_Shape( TopoDS_Shape() )
+{
+  SetLandCoverMap( theMap );
+}
+
+HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
+{
+}
+
 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
 {
   return myLCMap;
@@ -39,6 +56,7 @@ Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
 {
   myLCMap = theMap;
+  Set( theMap->GetShape() );
 }
 
 Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
@@ -102,6 +120,16 @@ void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3
   if( myLCMap.IsNull() )
     return;
 
+  thePresentation->Clear();
+  SetMaterial( Graphic3d_NOM_PLASTIC );
+
+  Quantity_Color anEdgeColor = Quantity_NOC_WHITE;
+  myDrawer->LineAspect()->SetColor( anEdgeColor );
+  myDrawer->FaceBoundaryAspect()->SetColor( anEdgeColor );
+  myDrawer->FreeBoundaryAspect()->SetColor( anEdgeColor );
+  myDrawer->UIsoAspect()->SetNumber( 0 );
+  myDrawer->VIsoAspect()->SetNumber( 0 );
+
   switch( theMode )
   {
   case AIS_WireFrame:
@@ -112,14 +140,27 @@ void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3
       for( ; anIt.More(); anIt.Next() )
       {
         TopoDS_Face aFace = anIt.Face();
-        QString aStricklerType = anIt.StricklerType();
-        Quantity_Color aColor = GetColor( aStricklerType );
-        SetColor( aColor );
-
         if( isShaded )
+        {
+          QString aStricklerType = anIt.StricklerType();
+          Quantity_Color aColor = GetColor( aStricklerType );
+          Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
+          Graphic3d_MaterialAspect aMaterialAspect( Graphic3d_NOM_PLASTIC );
+          aMaterialAspect.SetColor( aColor );
+          anAspect->SetFrontMaterial( aMaterialAspect );
+          anAspect->SetBackMaterial( aMaterialAspect );
+
+          Handle(Graphic3d_AspectFillArea3d) aGlobalAspect = myDrawer->ShadingAspect()->Aspect();
+          myDrawer->ShadingAspect()->SetAspect( anAspect );
           StdPrs_ShadedShape::Add( thePresentation, aFace, myDrawer );
+          myDrawer->ShadingAspect()->SetAspect( aGlobalAspect );
+
+          StdPrs_WFShape::Add( thePresentation, aFace, myDrawer );
+        }
         else
-          StdPrs_WFDeflectionShape::Add( thePresentation, aFace, myDrawer );
+        {
+          StdPrs_WFShape::Add( thePresentation, aFace, myDrawer );
+        }
       }
     }
     break;
index 50a3f9d1888dba0e9af657ddee20156d713ed482..1900f2ab1d376d158be1c73220d750f48f0c9959 100644 (file)
 #include <AIS_Shape.hxx>
 #include <Aspect_ColorScale.hxx>
 
+DEFINE_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_Shape )
+
 class HYDROGUI_LandCoverMapPrs : public AIS_Shape
 {
 public:
+  DEFINE_STANDARD_RTTI( HYDROGUI_LandCoverMapPrs );
+
+  HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& );
+  virtual ~HYDROGUI_LandCoverMapPrs();
+
   Handle(HYDROData_LandCoverMap) GetLandCoverMap() const;
   void SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& );
 
index 4e4a41149c152c4fd2f6ee1b92d3eaf3626442f0..45e7f12b9e2160f3382138cf30d0ea1817ed0b9e 100644 (file)
@@ -61,7 +61,7 @@ IF( ${WIN32} )
 ELSE()
   link_directories( $ENV{CAS_ROOT_DIR}/lib )
 ENDIF()
-SET( CAS_LIBRARIES TKernel TKLCAF TKCAF TKCDF TKMath TKG2d TKG3d TKBRep TKGeomBase TKTopAlgo TKGeomAlgo TKBool TKShHealing TKXSBase TKOffset TKHLR TKBO TKV3d )
+SET( CAS_LIBRARIES TKernel TKLCAF TKCAF TKCDF TKMath TKG2d TKG3d TKBRep TKGeomBase TKTopAlgo TKGeomAlgo TKBool TKShHealing TKXSBase TKOffset TKHLR TKBO TKV3d TKService )
 
 link_directories( $ENV{QT4_ROOT_DIR}/lib )
 IF( ${WIN32} )
index f98517a018a5c1d130e48c09cb490e852a269c1f..663cd087710813dcf6c8417bff76ea16a1aae3c9 100644 (file)
@@ -55,4 +55,5 @@ set( EXTERNAL_FILES
 
   ../HYDROGUI/HYDROGUI_ListModel.cxx
   ../HYDROGUI/HYDROGUI_DataObject.cxx
+  ../HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx
 )
index 5b5de3d225e930d7a4f1def28d89c9961a8c09df..02516f517c1749ba779745ee138043a457f16c47 100644 (file)
@@ -75,6 +75,19 @@ QColor randomColor()
   return aColor;
 }
 
+void TestViewer::show( const Handle(AIS_InteractiveObject)& theObject,
+                       int theMode, int theSelectionMode, bool isFitAll )
+{
+  context()->EraseAll( Standard_False );
+  context()->Display( theObject, theMode, theSelectionMode );
+
+  if( isFitAll )
+  {
+    viewWindow()->onTopView();
+    viewWindow()->onFitAll();
+  }
+}
+
 void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor )
 {
   Handle(AIS_Shape) aShape = new AIS_Shape( theShape );
@@ -91,7 +104,7 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll,
 
 void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey )
 {
-  context()->EraseAll();
+  context()->EraseAll( Standard_False );
   
   myKey = theKey;
   test_srand( 0 );
index 9768982a2c603f3d0453520f7530ea78dbea07ef..a27a8c7de5d1735ffd3e858d7318004d27b14ac0 100644 (file)
@@ -7,6 +7,7 @@ class OCCViewer_ViewWindow;
 class TopoDS_Shape;
 class QString;
 class QColor;
+class Handle_AIS_InteractiveObject;
 
 class TestViewer
 {
@@ -15,6 +16,8 @@ public:
   static OCCViewer_Viewer* viewer();
   static OCCViewer_ViewWindow* viewWindow();
 
+  static void show( const Handle_AIS_InteractiveObject& theObject,
+                    int theMode, int theSelelctionMode, bool isFitAll );
   static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor );
   static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey );
   static bool AssertImages( QString& theMessage );
index d9923b80919f992f0715220c8a7e90c4b7c7620c..fa0952cf4544f3af53dc4af86ce0144e3b85679e 100644 (file)
@@ -20,7 +20,9 @@
 #include <HYDROData_Document.h>
 #include <HYDROData_LandCoverMap.h>
 #include <HYDROData_PolylineXY.h>
+#include <HYDROData_StricklerTable.h>
 #include <HYDROData_Tool.h>
+#include <HYDROGUI_LandCoverMapPrs.h>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
@@ -39,6 +41,7 @@
 #include <BRep_Builder.hxx>
 
 const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" );
+const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt";
 
 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
 {
@@ -444,5 +447,35 @@ void test_HYDROData_LandCoverMap::test_merge_faces_circles()
     CPPUNIT_ASSERT_IMAGES
     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
   }
+}
+
+void test_HYDROData_LandCoverMap::test_land_cover_prs()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_StricklerTable) aTable =
+    Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+  CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
 
-}
\ No newline at end of file
+  Handle(HYDROData_LandCoverMap) aMap =
+    Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+
+  TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
+
+  TopoDS_Face aLC2 = LandCover( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
+                                                   44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
+                                                  128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
+                                                  31 << 114 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
+
+  TopoDS_Face aLC3 = LandCover( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
+                                                 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
+
+  Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
+  aPrs->SetTable( aTable );
+  TestViewer::show( aPrs, AIS_Shaded, 1, true );
+
+  aDoc->Close();
+}
index a891c39c04680cf1211b840b1154926ad3817ca6..bf28ae68231e79a51dfcfc28c153b27d5d82bb77 100644 (file)
@@ -32,6 +32,7 @@ class test_HYDROData_LandCoverMap : public CppUnit::TestFixture
   CPPUNIT_TEST( test_remove );
   CPPUNIT_TEST( test_merge_faces_boxes );
   CPPUNIT_TEST( test_merge_faces_circles );
+  CPPUNIT_TEST( test_land_cover_prs );
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -42,6 +43,7 @@ public:
   void test_remove();
   void test_merge_faces_boxes();
   void test_merge_faces_circles();
+  void test_land_cover_prs();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap );