From: asl Date: Tue, 20 Oct 2015 07:25:29 +0000 (+0300) Subject: #662: test for land cover map presentation X-Git-Tag: v1.5~78^2~1^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=609358898761f9c6633d52e364dcee5f91b8ae86;p=modules%2Fhydro.git #662: test for land cover map presentation --- diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx index 0128a7a3..f74fb1a5 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx @@ -21,9 +21,13 @@ #include #include #include +#include +#include +#include +#include #include #include -#include +#include #include #include #include @@ -31,6 +35,19 @@ #include #include +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; diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h index 50a3f9d1..1900f2ab 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h @@ -24,9 +24,16 @@ #include #include +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)& ); diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 4e4a4114..45e7f12b 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -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} ) diff --git a/src/HYDRO_tests/ExternalFiles.cmake b/src/HYDRO_tests/ExternalFiles.cmake index f98517a0..663cd087 100644 --- a/src/HYDRO_tests/ExternalFiles.cmake +++ b/src/HYDRO_tests/ExternalFiles.cmake @@ -55,4 +55,5 @@ set( EXTERNAL_FILES ../HYDROGUI/HYDROGUI_ListModel.cxx ../HYDROGUI/HYDROGUI_DataObject.cxx + ../HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx ) diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index 5b5de3d2..02516f51 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -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 ); diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index 9768982a..a27a8c7d 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -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 ); diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index d9923b80..fa0952cf 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -39,6 +41,7 @@ #include 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& 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() << 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() << 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() << 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(); +} diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h index a891c39c..bf28ae68 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h @@ -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 );