From: asl Date: Mon, 19 Oct 2015 09:17:41 +0000 (+0300) Subject: #662: new presentation for the land cover map X-Git-Tag: v1.5~78^2~1^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=08590dec007aeb0f695b969f057ad04e1d4bd35d;p=modules%2Fhydro.git #662: new presentation for the land cover map --- diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index fad2aceb..e65724dd 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -86,8 +86,9 @@ public: TopoDS_Face FindByPoint( const gp_Pnt2d&, QString& theType ) const; -protected: TopoDS_Shape GetShape() const; + +protected: void SetShape( const TopoDS_Shape& ); bool LocalPartition( const TopoDS_Shape&, const QString& theNewType ); diff --git a/src/HYDROData/HYDROData_Tool.cxx b/src/HYDROData/HYDROData_Tool.cxx index 210ec410..def682d9 100644 --- a/src/HYDROData/HYDROData_Tool.cxx +++ b/src/HYDROData/HYDROData_Tool.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -272,6 +273,15 @@ QString HYDROData_Tool::toQString( const TCollection_ExtendedString& theStr ) return QString( (QChar*)theStr.ToExtString(), theStr.Length() ); } +Quantity_Color HYDROData_Tool::toOccColor( const QColor& theColor ) +{ + double r = theColor.red() / 255.0; + double g = theColor.green() / 255.0; + double b = theColor.blue() / 255.0; + + return Quantity_Color( r, g, b, Quantity_TOC_RGB ); +} + std::ostream& operator<<( std::ostream& theStream, const QString& theText ) { theStream << theText.toStdString(); @@ -296,4 +306,3 @@ std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace ) return theStream; } - diff --git a/src/HYDROData/HYDROData_Tool.h b/src/HYDROData/HYDROData_Tool.h index 39fc887b..efff055d 100644 --- a/src/HYDROData/HYDROData_Tool.h +++ b/src/HYDROData/HYDROData_Tool.h @@ -41,6 +41,7 @@ class TopoDS_Face; class TopoDS_Shape; class TopoDS_Wire; class TopTools_SequenceOfShape; +class Quantity_Color; class HYDRODATA_EXPORT HYDROData_Tool { @@ -117,6 +118,8 @@ public: static TCollection_ExtendedString toExtString( const QString& ); static QString toQString( const TCollection_ExtendedString& ); + + static Quantity_Color toOccColor( const QColor& ); }; inline bool ValuesEquals( const double& theFirst, const double& theSecond ) diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index ae5ef832..6f477035 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -43,6 +43,7 @@ set(PROJECT_HEADERS HYDROGUI_ExportSinusXOp.h HYDROGUI_ExportSinusXDlg.h HYDROGUI_InputPanel.h + HYDROGUI_LandCoverMapPrs.h HYDROGUI_LocalCSDlg.h HYDROGUI_LocalCSOp.h HYDROGUI_MergePolylinesDlg.h @@ -180,6 +181,7 @@ set(PROJECT_SOURCES HYDROGUI_ExportSinusXOp.cxx HYDROGUI_ExportSinusXDlg.cxx HYDROGUI_InputPanel.cxx + HYDROGUI_LandCoverMapPrs.cxx HYDROGUI_LocalCSDlg.cxx HYDROGUI_LocalCSOp.cxx HYDROGUI_MergePolylinesDlg.cxx diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx new file mode 100644 index 00000000..0128a7a3 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx @@ -0,0 +1,161 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const +{ + return myLCMap; +} + +void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap ) +{ + myLCMap = theMap; +} + +Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const +{ + return myColorScale; +} + +void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale ) +{ + myColorScale = theColorScale; +} + +Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const +{ + return myTable; +} + +void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable ) +{ + myTable = theTable; +} + +Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const +{ + Quantity_Color aResult; + + if( !myColorScale.IsNull() && !myTable.IsNull() ) + { + double aCoeff = myTable->Get( theStricklerType, 0.0 ); + Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult ); + if( isOK ) + return aResult; + else + return Quantity_Color(); + } + + if( !myTable.IsNull() && myTable->HasType( theStricklerType ) ) + { + QColor aColor = myTable->GetColor( theStricklerType ); + return HYDROData_Tool::toOccColor( aColor ); + } + + HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE ); + for( ; anIt.More(); anIt.Next() ) + { + Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() ); + if( aTable->HasType( theStricklerType ) ) + { + QColor aColor = myTable->GetColor( theStricklerType ); + return HYDROData_Tool::toOccColor( aColor ); + } + } + + return Quantity_Color(); +} + +void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode ) +{ + if( myLCMap.IsNull() ) + return; + + switch( theMode ) + { + case AIS_WireFrame: + case AIS_Shaded: + { + bool isShaded = theMode==AIS_Shaded; + HYDROData_LandCoverMap::Iterator anIt( myLCMap ); + for( ; anIt.More(); anIt.Next() ) + { + TopoDS_Face aFace = anIt.Face(); + QString aStricklerType = anIt.StricklerType(); + Quantity_Color aColor = GetColor( aStricklerType ); + SetColor( aColor ); + + if( isShaded ) + StdPrs_ShadedShape::Add( thePresentation, aFace, myDrawer ); + else + StdPrs_WFDeflectionShape::Add( thePresentation, aFace, myDrawer ); + } + } + break; + default: + break; + } +} + +void HYDROGUI_LandCoverMapPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, + const Standard_Integer theMode ) +{ + if( myLCMap.IsNull() ) + return; + + if( theMode==0 ) + { + theSelection->Clear(); + Bnd_Box B = BoundingBox(); + Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner( myLCMap->GetShape(), this ); + Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, B ); + theSelection->Add( aSensitiveBox ); + } + else + { + Standard_Real aDeflection = Prs3d::GetDeflection( myLCMap->GetShape(), myDrawer ); + HYDROData_LandCoverMap::Iterator anIt( myLCMap ); + for( ; anIt.More(); anIt.Next() ) + { + StdSelect_BRepSelectionTool::Load( theSelection, + this, + anIt.Face(), + TopAbs_FACE, + aDeflection, + myDrawer->HLRAngle(), + myDrawer->IsAutoTriangulation()); + } + StdSelect::SetDrawerForBRepOwner( theSelection, myDrawer ); + } +} diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h new file mode 100644 index 00000000..50a3f9d1 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h @@ -0,0 +1,54 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_LANDCOVERMAP_PRS_H +#define HYDROGUI_LANDCOVERMAP_PRS_H + +#include +#include +#include +#include + +class HYDROGUI_LandCoverMapPrs : public AIS_Shape +{ +public: + Handle(HYDROData_LandCoverMap) GetLandCoverMap() const; + void SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& ); + + Handle(Aspect_ColorScale) GetColorScale() const; + void SetColorScale( const Handle(Aspect_ColorScale)& ); + + Handle(HYDROData_StricklerTable) GetTable() const; + void SetTable( const Handle(HYDROData_StricklerTable)& ); + + virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode ); + + virtual void ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, + const Standard_Integer theMode ); + + Quantity_Color GetColor( const QString& theStricklerType ) const; + +private: + Handle(HYDROData_LandCoverMap) myLCMap; + Handle(Aspect_ColorScale) myColorScale; + Handle(HYDROData_StricklerTable) myTable; +}; + +#endif diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index 2a2e7f84..5b5de3d2 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -1,5 +1,6 @@ #include +#include #include #include #ifdef WIN32 @@ -76,13 +77,9 @@ QColor randomColor() void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor ) { - double r = theColor.red() / 255.0; - double g = theColor.green() / 255.0; - double b = theColor.blue() / 255.0; - Handle(AIS_Shape) aShape = new AIS_Shape( theShape ); aShape->SetMaterial( Graphic3d_NOM_PLASTIC ); - aShape->SetColor( Quantity_Color( r, g, b, Quantity_TOC_RGB ) ); + aShape->SetColor( HYDROData_Tool::toOccColor( theColor ) ); context()->Display( aShape, theMode, 0, Standard_False ); if( isFitAll )