#include "HYDROGUI_Tool.h"
#include "HYDROGUI_UpdateFlags.h"
#include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_ShapeLandCoverMap.h"
#include <HYDROData_Iterator.h>
#include <HYDROData_StricklerTable.h>
#include <HYDROData_PolylineXY.h>
#include <HYDROData_Object.h>
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewModel.h>
+
+#include <LightApp_Application.h>
+
#include <TopoDS_Face.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <AIS_Shape.hxx>
+
+#include <QApplication>
HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId )
: HYDROGUI_Operation( theModule ),
}
}
aPanel->setObjectName( anObjectName );
-
+
+ closePreview();
+ QStringList aPolylineFaceNames;
+ onCreatePreview( aPolylineFaceNames );
+
aPanel->blockSignals( false );
+
+ module()->update( UF_OCCViewer | UF_FitAll );
}
void HYDROGUI_LandCoverMapOp::abortOperation()
closePreview();
HYDROGUI_Operation::abortOperation();
+
+ module()->update( UF_OCCViewer | UF_FitAll );
}
void HYDROGUI_LandCoverMapOp::commitOperation()
closePreview();
HYDROGUI_Operation::commitOperation();
+
+ module()->update( UF_OCCViewer | UF_FitAll );
}
HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const
this, SLOT( onLandCoverMapChanged( const QString& ) ) );
connect( aPanel, SIGNAL( CreatePreview( const QStringList& ) ),
this, SLOT( onCreatePreview( const QStringList& ) ) );
- /*
- connect( aPanel, SIGNAL( addPolylines() ), SLOT( onAddPolylines() ) );
- connect( aPanel, SIGNAL( removePolylines() ), SLOT( onRemovePolylines() ) );
- */
return aPanel;
}
myOperationId == MergeLandCoverId ||
myOperationId == ChangeLandCoverTypeId )
{
- // TODO:
- //Fill in aFacesSelectedInViewer list
+ if ( myPreviewPrs )
+ {
+ // Fill in aFacesSelectedInViewer list
+ Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
+ if ( !aCtx.IsNull() && aCtx->NbSelected() > 0 )
+ {
+ for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
+ {
+ TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
+ if ( aSelectedShape.IsNull() )
+ continue;
+
+ aFacesSelectedInViewer.Append( aSelectedShape );
+ }
+ }
+ }
}
// Get selected Strickler type
}
}
- /*if ( myOperationId == CreateLandCoverMapId )
- {
- aLandCoverMapObj->SetFillingColor( aLandCoverMapObj->DefaultFillingColor() );
- aLandCoverMapObj->SetBorderColor( aLandCoverMapObj->DefaultBorderColor() );
- }*/
-
// Update land cover map object and close preview
aLandCoverMapObj->Update();
if ( !myEditedObject.IsNull() )
{
// Show preview of the newly selected land cover map
+ closePreview();
QStringList aPolylineFaceNames;
onCreatePreview( aPolylineFaceNames );
}
void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineFaceNames )
{
- /*
- HYDROGUI_LandCoverDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverDlg*>( inputPanel() );
+ HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
if ( !aPanel )
return;
QApplication::setOverrideCursor( Qt::WaitCursor );
- HYDROData_SequenceOfObjects aZonePolylines;
- QStringList::const_iterator anIt = thePolylineNames.begin(), aLast = thePolylineNames.end();
- for( ; anIt!=aLast; anIt++ )
- {
- QString aPolylineName = *anIt;
- Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast(
- HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) );
- if ( !aPolyline.IsNull() )
- aZonePolylines.Append( aPolyline );
- }
-
- TCollection_AsciiString anError;
- TopoDS_Shape aZoneShape = HYDROData_LandCover::buildShape( aZonePolylines, anError );
-
LightApp_Application* anApp = module()->getApp();
if ( !getPreviewManager() )
setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
{
Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
if ( !aCtx.IsNull() )
- myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
+ {
+ connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+ myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
+ }
}
}
if ( aViewManager && myPreviewPrs )
{
- QColor aFillingColor = Qt::magenta;
- QColor aBorderColor = Qt::transparent;
- if ( !myEditedObject.IsNull() ) {
- aFillingColor = myEditedObject->GetFillingColor();
- aBorderColor = myEditedObject->GetBorderColor();
+ TopoDS_Shape aLandCoverMapShape = myEditedObject->GetShape();
+ if( !aLandCoverMapShape.IsNull() )
+ {
+ if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId)
+ myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) );
+ myPreviewPrs->setShape( aLandCoverMapShape );
}
+ }
+
+ module()->update( UF_OCCViewer | UF_FitAll );
- myPreviewPrs->setFillingColor( aFillingColor, false, false );
- myPreviewPrs->setBorderColor( aBorderColor, false, false );
+ QApplication::restoreOverrideCursor();
+}
- if( !aZoneShape.IsNull() )
- myPreviewPrs->setShape( aZoneShape );
- }
+void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
+{
+ HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
- QApplication::restoreOverrideCursor();
- */
+ Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
+ if ( !aCtx.IsNull() )
+ {
+ int aNbSelected = aCtx->NbSelected();
+
+ if ( myOperationId == RemoveLandCoverId )
+ aPanel->setApplyEnabled( aNbSelected > 0 );
+ else if ( myOperationId == MergeLandCoverId )
+ aPanel->setApplyEnabled( aNbSelected > 1 );
+ }
}
void HYDROGUI_LandCoverMapOp::closePreview()
delete myPreviewPrs;
myPreviewPrs = 0;
}
+
+ HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
+
+ if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId )
+ aPanel->setApplyEnabled( false );
+}
+
+Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
+{
+ OCCViewer_ViewManager* aViewManager = getPreviewManager();
+ Handle(AIS_InteractiveContext) aCtx = NULL;
+ if ( aViewManager ) {
+ if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
+ aCtx = aViewer->getAISContext();
+ }
+ }
+ return aCtx;
}
#include <HYDROData_LandCoverMap.h>
+#include <AIS_InteractiveContext.hxx>
+
class HYDROGUI_LandCoverMapOp : public HYDROGUI_Operation
{
Q_OBJECT
virtual ~HYDROGUI_LandCoverMapOp();
protected:
- virtual void startOperation();
- virtual void abortOperation();
- virtual void commitOperation();
+ virtual void startOperation();
+ virtual void abortOperation();
+ virtual void commitOperation();
- virtual HYDROGUI_InputPanel* createInputPanel() const;
+ virtual HYDROGUI_InputPanel* createInputPanel() const;
- virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg,
- QStringList& theBrowseObjectsEntries );
+ virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg,
+ QStringList& theBrowseObjectsEntries );
- virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; };
+ virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; };
protected slots:
- void onLandCoverMapChanged( const QString& theName );
- void onCreatePreview( const QStringList& thePolylineFaceNames );
+ void onLandCoverMapChanged( const QString& theName );
+ void onCreatePreview( const QStringList& thePolylineFaceNames );
+ void onViewerSelectionChanged();
private:
- void closePreview();
+ void closePreview();
+
+ Handle(AIS_InteractiveContext) getInteractiveContext();
private:
int myOperationId;
myHighlightColor( Qt::white ),
myIsToUpdate( false ),
myIsVisible( true ),
- myDisplayMode( AIS_Shaded )
+ myDisplayMode( AIS_Shaded ),
+ mySelectionMode( AIS_Shape::SelectionMode( TopAbs_SHAPE ) )
{
}
if ( myContext.IsNull() || myShape.IsNull() )
return;
- myContext->Erase( myShape, theIsUpdateViewer );
+ eraseShape( theIsUpdateViewer );
}
void HYDROGUI_Shape::update( bool isUpdateViewer,
displayShape( theIsUpdateViewer );
}
else
- myContext->Erase( myShape, theIsUpdateViewer );
+ eraseShape( theIsUpdateViewer );
}
void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
myShape->SetTransparency( 0 );
myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
+ myShape->SetSelectionMode( (Standard_Integer)mySelectionMode );
// Init default params for shape
const Handle(Prs3d_Drawer)& anAttributes = myShape->Attributes();
void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer )
{
- myContext->Display( myShape, Standard_False );
+ if ( myContext->HasOpenedContext() && mySelectionMode > 0 )
+ myContext->CloseLocalContext();
+
+ if ( mySelectionMode > 0 )
+ // Display object in local context with selection
+ myContext->Display( myShape, myDisplayMode, mySelectionMode, Standard_False, Standard_False );
+ else
+ {
+ if ( !myContext->HasOpenedContext() )
+ // Ordinary display of object published in the Object Browser
+ myContext->Display( myShape, Standard_False );
+ else
+ // Display object in local context without selection
+ myContext->Display( myShape, myDisplayMode, -1, Standard_False, Standard_False );
+ }
+
+ if ( mySelectionMode > 0 )
+ {
+ myContext->OpenLocalContext();
+ myContext->Activate( myShape, mySelectionMode, Standard_True );
+ }
if ( myZLayer >= 0 )
myContext->SetZLayer( myShape, myZLayer );
}
}
+void HYDROGUI_Shape::eraseShape( const bool theIsUpdateViewer )
+{
+ if ( myContext->HasOpenedContext() && mySelectionMode > 0 )
+ myContext->CloseLocalContext();
+
+ myContext->Erase( myShape, theIsUpdateViewer );
+}
+
QColor HYDROGUI_Shape::getActiveColor() const
{
return isHighlighted() ? myHighlightColor : myBorderColor;
{
myDisplayMode = theDisplayMode;
}
+
+void HYDROGUI_Shape::setSelectionMode( int theSelectionMode )
+{
+ mySelectionMode = theSelectionMode;
+}
\ No newline at end of file