]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
#662: new presentation for the land cover map
authorasl <asl@opencascade.com>
Mon, 19 Oct 2015 09:17:41 +0000 (12:17 +0300)
committerasl <asl@opencascade.com>
Mon, 19 Oct 2015 09:17:41 +0000 (12:17 +0300)
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDROData/HYDROData_Tool.cxx
src/HYDROData/HYDROData_Tool.h
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h [new file with mode: 0644]
src/HYDRO_tests/TestViewer.cxx

index fad2aceb833121e96279120e91f2c4017aa69d20..e65724dd571bac299d2e691070a665e94575a514 100644 (file)
@@ -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 );
index 210ec410ee8434a29e59973e95a6531c50d91662..def682d94cc6900d6cc1ad2aaccf967460f70edc 100644 (file)
@@ -33,6 +33,7 @@
 #include <ElSLib.hxx>
 #include <Geom_Curve.hxx>
 #include <gp_Pln.hxx>
+#include <Quantity_Color.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
@@ -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;
 }
 
-
index 39fc887b87cb5b1356db19b4589b57b8c3139979..efff055d66a2849944108836fa98461e1e203285 100644 (file)
@@ -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 )
index ae5ef8328f34bfe0d7893607d28bb29c74ad672b..6f477035bd2976358f3e30bcab6f34ee36d850ff 100644 (file)
@@ -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 (file)
index 0000000..0128a7a
--- /dev/null
@@ -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 <HYDROGUI_LandCoverMapPrs.h>
+#include <HYDROData_Iterator.h>
+#include <HYDROData_Tool.h>
+#include <AIS_DisplayMode.hxx>
+#include <Prs3d.hxx>
+#include <Select3D_SensitiveBox.hxx>
+#include <StdPrs_ShadedShape.hxx>
+#include <StdPrs_WFDeflectionShape.hxx>
+#include <StdSelect.hxx>
+#include <StdSelect_BRepOwner.hxx>
+#include <StdSelect_BRepSelectionTool.hxx>
+#include <TopoDS_Face.hxx>
+#include <QColor>
+#include <QString>
+
+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 (file)
index 0000000..50a3f9d
--- /dev/null
@@ -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 <HYDROData_LandCoverMap.h>
+#include <HYDROData_StricklerTable.h>
+#include <AIS_Shape.hxx>
+#include <Aspect_ColorScale.hxx>
+
+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
index 2a2e7f84f483f93f6df14ed4ea8f60c10e47c847..5b5de3d225e930d7a4f1def28d89c9961a8c09df 100644 (file)
@@ -1,5 +1,6 @@
 
 #include <TestViewer.h>
+#include <HYDROData_Tool.h>
 #include <random.h>
 #include <OCCViewer_ViewManager.h>
 #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 )