From: adv Date: Thu, 19 Sep 2013 07:05:19 +0000 (+0000) Subject: Darwing of zones in OCC viwer (Feature #31). X-Git-Tag: BR_hydro_v_0_1~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c96bf6c78266e6d18db1c065a67308a158e4b53e;p=modules%2Fhydro.git Darwing of zones in OCC viwer (Feature #31). --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 3895c486..c0aee0a0 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -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} ) diff --git a/src/HYDROGUI/HYDROGUI.vcproj b/src/HYDROGUI/HYDROGUI.vcproj index 3a6362ad..15cd7ed8 100644 --- a/src/HYDROGUI/HYDROGUI.vcproj +++ b/src/HYDROGUI/HYDROGUI.vcproj @@ -254,6 +254,10 @@ RelativePath=".\HYDROGUI_PrsZoneDriver.cxx" > + + @@ -633,6 +637,10 @@ RelativePath=".\HYDROGUI_PrsZoneDriver.h" > + + diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx new file mode 100644 index 00000000..107fb743 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -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 + +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +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 index 00000000..4e1ef212 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -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 +#include + +#include +#include + +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 + diff --git a/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx b/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx index 02e6a60b..1806765e 100644 --- a/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx @@ -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 diff --git a/src/HYDROGUI/HYDROGUI_ZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ZoneOp.cxx index 88c54024..e2c95ab1 100644 --- a/src/HYDROGUI/HYDROGUI_ZoneOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ZoneOp.cxx @@ -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 #include -#include -#include -#include +#include +#include #include #include @@ -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( - anApp->createViewManager( GraphicsView_Viewer::Type() ) ); + myPreviewViewManager = ::qobject_cast( + 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; diff --git a/src/HYDROGUI/HYDROGUI_ZoneOp.h b/src/HYDROGUI/HYDROGUI_ZoneOp.h index 9764d0f6..4677e5d6 100644 --- a/src/HYDROGUI/HYDROGUI_ZoneOp.h +++ b/src/HYDROGUI/HYDROGUI_ZoneOp.h @@ -29,11 +29,11 @@ #include -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; }; diff --git a/src/Link/Link_OCC.cxx b/src/Link/Link_OCC.cxx index 0afbb6b8..ebbcdb3f 100644 --- a/src/Link/Link_OCC.cxx +++ b/src/Link/Link_OCC.cxx @@ -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") +