]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Darwing of zones in OCC viwer (Feature #31).
authoradv <adv@opencascade.com>
Thu, 19 Sep 2013 07:05:19 +0000 (07:05 +0000)
committeradv <adv@opencascade.com>
Thu, 19 Sep 2013 07:05:19 +0000 (07:05 +0000)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI.vcproj
src/HYDROGUI/HYDROGUI_Shape.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_Shape.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ZoneDlg.cxx
src/HYDROGUI/HYDROGUI_ZoneOp.cxx
src/HYDROGUI/HYDROGUI_ZoneOp.h
src/Link/Link_OCC.cxx

index 3895c48694a43416ac32df6bb697de344f01b422..c0aee0a01664dd225bde9e72d073f71763b1913d 100644 (file)
@@ -35,6 +35,7 @@ set(PROJECT_HEADERS
     HYDROGUI_PrsPolylineDriver.h
     HYDROGUI_PrsZone.h
     HYDROGUI_PrsZoneDriver.h
+    HYDROGUI_Shape.h
     HYDROGUI_ShowHideOp.h
     HYDROGUI_Tool.h
     HYDROGUI_TwoImagesDlg.h
@@ -81,6 +82,7 @@ set(PROJECT_SOURCES
     HYDROGUI_PrsPolylineDriver.cxx
     HYDROGUI_PrsZone.cxx
     HYDROGUI_PrsZoneDriver.cxx
+    HYDROGUI_Shape.cxx
     HYDROGUI_ShowHideOp.cxx
     HYDROGUI_Tool.cxx
     HYDROGUI_TwoImagesDlg.cxx
@@ -110,7 +112,7 @@ include_directories(
 
 add_library(HYDROGUI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${PROJECT_HEADERS_MOC})
 target_link_libraries(HYDROGUI HYDROData 
-    ${CAS_TKV3d}
+    ${CAS_TKV3d} ${CAS_TKTopAlgo}
     ${LightApp} ${CAM} ${suit} ${qtx} ${ObjBrowser} ${GraphicsView} ${std} ${Event} ${OCCViewer}
     ${CurveCreator}
     )
index 3a6362ad3d6fb187e1e186f8aaa6f1c90749d1db..15cd7ed8dac956caba027cc050dded8da85ecf79 100644 (file)
                                RelativePath=".\HYDROGUI_PrsZoneDriver.cxx"
                                >
                        </File>
+                       <File
+                               RelativePath=".\HYDROGUI_Shape.cxx"
+                               >
+                       </File>
                        <File
                                RelativePath=".\HYDROGUI_ShowHideOp.cxx"
                                >
                                RelativePath=".\HYDROGUI_PrsZoneDriver.h"
                                >
                        </File>
+                       <File
+                               RelativePath=".\HYDROGUI_Shape.h"
+                               >
+                       </File>
                        <File
                                RelativePath=".\HYDROGUI_ShowHideOp.h"
                                >
diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx
new file mode 100644 (file)
index 0000000..107fb74
--- /dev/null
@@ -0,0 +1,315 @@
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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.
+//
+// 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_Shape.h"
+
+#include <AIS_Drawer.hxx>
+
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+
+#include <gp_Pnt.hxx>
+
+#include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_MaterialAspect.hxx>
+
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Face.hxx>
+
+#include <Prs3d_ShadingAspect.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Prs3d_IsoAspect.hxx>
+
+#include <QColor>
+
+HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext )
+: myContext( theContext ),
+  myIsHighlight( false ),
+  myZIndex( 0.0 ),
+  myFillingColor( Qt::green ),
+  myBorderColor( Qt::black ),
+  myHighlightColor( Qt::white )
+{
+}
+
+HYDROGUI_Shape::~HYDROGUI_Shape()
+{
+  erase();
+
+  if ( !myShape.IsNull() )
+    myShape.Nullify();
+}
+
+void HYDROGUI_Shape::display()
+{
+  if ( !myContext || myShape.IsNull() )
+    return;
+
+  myContext->Display( myShape );
+}
+
+void HYDROGUI_Shape::erase()
+{
+  if ( !myContext || myShape.IsNull() )
+    return;
+
+  myContext->Erase( myShape );
+}
+
+void HYDROGUI_Shape::highlight( bool theIsHighlight )
+{
+  if ( myIsHighlight == theIsHighlight )
+    return;
+
+  myIsHighlight = theIsHighlight;
+
+  if ( !myContext || myShape.IsNull() )
+    return;
+
+  colorShapeBorder( getActiveColor() );
+  myContext->Display( myShape );
+}
+
+bool HYDROGUI_Shape::isHighlighted() const
+{
+  return myIsHighlight;
+}
+
+void HYDROGUI_Shape::setPath( const QPainterPath& thePath,
+                              const bool          theToDisplay )
+{
+  myPath = thePath;
+  buildShape();
+  updateShape( theToDisplay );
+}
+
+QPainterPath HYDROGUI_Shape::getPath() const
+{
+  return myPath;
+}
+
+void HYDROGUI_Shape::setZIndex( const double theZIndex,
+                                const bool   theToDisplay )
+{
+  myZIndex = theZIndex;
+  buildShape();
+  updateShape( theToDisplay );
+}
+
+double HYDROGUI_Shape::getZIndex() const
+{
+  return myZIndex;
+}
+
+void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
+                                      const bool    theToDisplay )
+{
+  myFillingColor = theColor;
+  updateShape( theToDisplay );
+}
+
+QColor HYDROGUI_Shape::getFillingColor() const
+{
+  return myFillingColor;
+}
+
+void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
+                                     const bool    theToDisplay )
+{
+  myBorderColor = theColor;
+  updateShape( theToDisplay );
+}
+
+QColor HYDROGUI_Shape::getBorderColor() const
+{
+  return myBorderColor;
+}
+
+void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
+{
+  myHighlightColor = theColor;
+}
+
+QColor HYDROGUI_Shape::getHighlightColor() const
+{
+  return myHighlightColor;
+}
+
+void HYDROGUI_Shape::buildShape()
+{
+  // Erase previously created shape
+  erase();
+
+  if ( myPath.isEmpty() )
+    return;
+
+  BRepBuilderAPI_MakeWire aMakeWire;
+
+  // Build new shape from path
+  gp_Pnt aPrevPoint( 0, 0, myZIndex );
+  for ( int i = 0; i < myPath.elementCount(); ++i )
+  {
+    const QPainterPath::Element& aPathElem = myPath.elementAt( i );
+
+    gp_Pnt aCurPoint( aPathElem.x, aPathElem.y, myZIndex );
+    switch ( aPathElem.type )
+    {
+      case QPainterPath::LineToElement:
+      {
+        BRepBuilderAPI_MakeEdge aMakeEdge( aPrevPoint, aCurPoint );
+        aMakeEdge.Build();
+        if ( aMakeEdge.IsDone() )
+        {
+          TopoDS_Edge anEdge = aMakeEdge;
+          aMakeWire.Add( anEdge );
+        }
+        break;
+      }
+      case QPainterPath::CurveToElement:
+      {
+        // TODO
+        break;
+      }
+      case QPainterPath::MoveToElement:
+      default:
+        break;
+    }
+
+    aPrevPoint = aCurPoint;
+  }
+
+  TopoDS_Face aResShape;
+
+  aMakeWire.Build();
+  if ( aMakeWire.IsDone() )
+  {
+    TopoDS_Wire aCommonWire = aMakeWire;
+
+    BRepBuilderAPI_MakeFace aMakeFace( aCommonWire, true );
+    aMakeFace.Build();
+    if ( aMakeFace.IsDone() )
+       aResShape = aMakeFace;
+  }
+
+  myShape = new AIS_Shape( aResShape );
+
+  myShape->SetTransparency( 0 );
+  myShape->SetDisplayMode( AIS_Shaded );
+
+  // Init default params for shape
+  const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
+  if ( !anAttributes.IsNull() )
+  {
+    Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
+    if ( !anIsoAspect.IsNull() )
+      anIsoAspect->SetNumber( 0 );
+    
+    anIsoAspect = anAttributes->VIsoAspect();
+    if ( !anIsoAspect.IsNull() )
+      anIsoAspect->SetNumber( 0 );
+
+    Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
+    if ( !aShadingAspect.IsNull() )
+    {
+      Graphic3d_MaterialAspect aMatAspect;
+         aMatAspect.SetAmbient( 1 );
+         aMatAspect.SetDiffuse( 0 );
+       
+         aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
+         aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
+    }
+  }
+}
+
+void HYDROGUI_Shape::updateShape( const bool theIsForce )
+{
+  if ( myShape.IsNull() )
+    return;
+
+  const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
+  if ( !anAttributes.IsNull() )
+  {
+    // Coloring face filling
+    Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
+    if ( !aShadingAspect.IsNull() )
+    {
+      Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ), 
+                                    getQuantityColorVal( myFillingColor.green() ),
+                                    getQuantityColorVal( myFillingColor.blue() ),
+                                    Quantity_TOC_RGB );
+
+      aShadingAspect->SetColor( aFillingColor );
+      aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
+    }
+
+    // Coloring borders
+    colorShapeBorder( getActiveColor() );
+  }
+
+  if ( !theIsForce || !myContext )
+    return;
+  
+  myContext->Display( myShape );
+}
+
+QColor HYDROGUI_Shape::getActiveColor() const
+{
+  return isHighlighted() ? myHighlightColor : myBorderColor;
+}
+
+double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
+{
+  return theColorVal == 0 ? 0 : (double)( theColorVal / 255 );
+}
+
+void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
+{
+  if ( myShape.IsNull() )
+    return;
+
+  const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
+  if ( anAttributes.IsNull() )
+    return;
+
+  if ( theColor.alpha() == 0 )
+  {
+    anAttributes->SetFaceBoundaryDraw( false );
+  }
+  else
+  {
+    Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ), 
+                                 getQuantityColorVal( theColor.green() ),
+                                 getQuantityColorVal( theColor.blue() ),
+                                 Quantity_TOC_RGB );
+
+    anAttributes->SetFaceBoundaryDraw( true );
+
+    Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
+    if ( !aBoundaryAspect.IsNull() )
+    {
+      aBoundaryAspect->SetColor( aBorderColor );
+    }
+  }
+}
+
+
diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h
new file mode 100644 (file)
index 0000000..4e1ef21
--- /dev/null
@@ -0,0 +1,87 @@
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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.
+//
+// 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_SHAPE_H
+#define HYDROGUI_SHAPE_H
+
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_Shape.hxx>
+
+#include <QColor>
+#include <QPainterPath>
+
+class HYDROGUI_Shape
+{
+public:
+  HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext );
+  ~HYDROGUI_Shape();
+
+public:
+  virtual void               display();
+  virtual void               erase();
+
+  virtual void               highlight( bool theIsHighlight );
+  virtual bool               isHighlighted() const;
+
+  virtual void               setPath( const QPainterPath& thePath,
+                                      const bool          theToDisplay = true );
+  virtual QPainterPath       getPath() const;
+
+  virtual void               setZIndex( const double theZIndex,
+                                        const bool   theToDisplay = true );
+  virtual double             getZIndex() const;
+
+  virtual void               setFillingColor( const QColor& theColor,
+                                              const bool    theToDisplay = true );
+  virtual QColor             getFillingColor() const;
+
+  virtual void               setBorderColor( const QColor& theColor,
+                                             const bool    theToDisplay = true );
+  virtual QColor             getBorderColor() const;
+
+  virtual void               setHighlightColor( const QColor& theColor );
+  virtual QColor             getHighlightColor() const;
+
+protected:
+  virtual void               buildShape();
+  virtual void               updateShape( const bool theIsForce = true );
+  virtual QColor             getActiveColor() const;
+
+private:
+  static double              getQuantityColorVal( const int theColorVal );
+  void                       colorShapeBorder( const QColor& theColor );
+
+private:
+  Handle(AIS_InteractiveContext) myContext;
+  Handle(AIS_Shape)              myShape;
+
+  bool                           myIsHighlight;
+  QPainterPath                   myPath;
+  
+  double                         myZIndex;
+  QColor                         myFillingColor;
+  QColor                         myBorderColor;
+  QColor                         myHighlightColor;
+};
+
+#endif
+
index 02e6a60b5f28348abecc0b6ceabf10b5f9f12187..1806765edfdefd14ec3bd4481cab800081378345 100644 (file)
@@ -174,7 +174,15 @@ void HYDROGUI_ZoneDlg::setPolylineNames( const QStringList& thePolylines )
 
 void HYDROGUI_ZoneDlg::setPolylineName( const QString& theName )
 {
-  myPolylines->setCurrentIndex( myPolylines->findText( theName ) );
+  int aNewIdx = myPolylines->findText( theName );
+  if ( aNewIdx != myPolylines->currentIndex() )
+  {
+    myPolylines->setCurrentIndex( aNewIdx );
+  }
+  else
+  {
+    onZoneDefChanged();
+  }
 }
 
 QString HYDROGUI_ZoneDlg::getPolylineName() const
index 88c540243313b5662c5fab92ed9f8111ef52167d..e2c95ab1bedc99abe686135e2a647d037f31889b 100644 (file)
@@ -25,7 +25,7 @@
 #include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_ZoneDlg.h"
 #include "HYDROGUI_Module.h"
-#include "HYDROGUI_PrsZone.h"
+#include "HYDROGUI_Shape.h"
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 
@@ -33,9 +33,8 @@
 #include <HYDROData_Iterator.h>
 #include <HYDROData_Polyline.h>
 
-#include <GraphicsView_ViewManager.h>
-#include <GraphicsView_ViewPort.h>
-#include <GraphicsView_Viewer.h>
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewModel.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_UpdateFlags.h>
@@ -64,6 +63,8 @@ void HYDROGUI_ZoneOp::startOperation()
   if ( !aPanel )
     return;
 
+  aPanel->blockSignals( true );
+
   aPanel->reset();
 
   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Zone" );
@@ -147,11 +148,14 @@ void HYDROGUI_ZoneOp::startOperation()
   aPanel->setBorderColor( aBorderColor );
 
   aPanel->setPolylineNames( aPolylines );
-  aPanel->setPolylineName( aSelectedPolyline );
 
   aPanel->setBathymetries( aBathymetries );
   aPanel->setSelectedBathymetries( aSelectedBathymetries );
 
+  aPanel->blockSignals( false );
+
+  aPanel->setPolylineName( aSelectedPolyline );
+
 }
 
 void HYDROGUI_ZoneOp::abortOperation()
@@ -268,20 +272,10 @@ void HYDROGUI_ZoneOp::onCreatePreview( const QString& thePolylineName )
     myActiveViewManager = anApp->activeViewManager();
   }
 
-  if ( !myPreviewPrs )
-  {
-    myPreviewPrs = new HYDROGUI_PrsZone( myIsEdit ? myEditedObject : 0 );
-  }
-
-  myPreviewPrs->setPath( aPath );
-  myPreviewPrs->setFillingColor( aPanel->getFillingColor() );
-  myPreviewPrs->setBorderColor( aPanel->getBorderColor() );
-  myPreviewPrs->compute();
-
   if ( !myPreviewViewManager )
   {
-    myPreviewViewManager = ::qobject_cast<GraphicsView_ViewManager*>( 
-      anApp->createViewManager( GraphicsView_Viewer::Type() ) );
+    myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>( 
+      anApp->createViewManager( OCCViewer_Viewer::Type() ) );
     if ( myPreviewViewManager )
     {
       connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
@@ -289,27 +283,24 @@ void HYDROGUI_ZoneOp::onCreatePreview( const QString& thePolylineName )
 
       module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewZone );
       myPreviewViewManager->setTitle( tr( "PREVIEW_ZONE" ) );
-      if ( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
+
+      if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
       {
-        if ( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
+        Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+        if ( !aCtx.IsNull() )
         {
-          aViewPort->addItem( myPreviewPrs );
+          myPreviewPrs = new HYDROGUI_Shape( aCtx );
         }
       }
     }
   }
 
-  if ( myPreviewViewManager )
-  {
-    if ( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
-    {
-      if ( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
-      {
-        aViewPort->update();
-        aViewPort->fitAll();
-      }
-    }
-  }
+  if ( !myPreviewViewManager || !myPreviewPrs )
+    return;
+
+  myPreviewPrs->setFillingColor( aPanel->getFillingColor(), false );
+  myPreviewPrs->setBorderColor( aPanel->getBorderColor(), false );
+  myPreviewPrs->setPath( aPath, true );
 }
 
 void HYDROGUI_ZoneOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
@@ -319,14 +310,6 @@ void HYDROGUI_ZoneOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
 
 void HYDROGUI_ZoneOp::closePreview()
 {
-  // It's very strange, but without calling this method (it's quite safe) a crash is stably reproduced.
-  // Scenario: create any non-Graphics view, activate import op, click apply.
-  // Result: a few SIGSEGVs coming from processEvents(), then crash.
-  if( myPreviewViewManager )
-    if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
-      if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
-        aViewPort->onBoundingRectChanged();
-
   if( myPreviewPrs )
   {
     delete myPreviewPrs;
index 9764d0f691f2f7e7ec8e1f5182ba36ffcea10db2..4677e5d6af98a232cded00485c34cafc53799d88 100644 (file)
 
 #include <QPainterPath>
 
-class GraphicsView_ViewManager;
+class OCCViewer_ViewManager;
 
 class SUIT_ViewManager;
 
-class HYDROGUI_PrsZone;
+class HYDROGUI_Shape;
 
 class HYDROGUI_ZoneOp : public HYDROGUI_Operation
 {
@@ -66,8 +66,8 @@ private:
 
   SUIT_ViewManager*          myActiveViewManager;
 
-  GraphicsView_ViewManager*  myPreviewViewManager;
-  HYDROGUI_PrsZone*          myPreviewPrs;
+  OCCViewer_ViewManager*     myPreviewViewManager;
+  HYDROGUI_Shape*            myPreviewPrs;
 
   QPainterPath               myZonePath;
 };
index 0afbb6b8658b348161f4660a289ab0762a23a661..ebbcdb3f0e6d0349fbabe4e846a6709fb094a219 100644 (file)
@@ -16,3 +16,6 @@
 #pragma comment (lib , "TKGeomBase.lib")
 #pragma comment (lib , "TKLCAF.lib") 
 #pragma comment (lib , "TKV3d.lib") 
+#pragma comment (lib , "TKBrep.lib") 
+#pragma comment (lib , "TKTopAlgo.lib") 
+