--- /dev/null
+// 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 );
+ }
+ }
+}
+
+
--- /dev/null
+// 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
+
#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"
#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>
if ( !aPanel )
return;
+ aPanel->blockSignals( true );
+
aPanel->reset();
QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Zone" );
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()
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* ) ),
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 )
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;