+OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
+{
+ if( myViewManagerMap.contains( theId ) )
+ {
+ ViewManagerInfo anInfo = myViewManagerMap[ theId ];
+ OCCViewer_ViewManager* aViewManager =
+ ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
+ if( aViewManager )
+ return aViewManager->getOCCViewer();
+ }
+ return NULL;
+}
+
+SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
+{
+ if( myViewManagerMap.contains( theId ) )
+ {
+ ViewManagerInfo anInfo = myViewManagerMap[ theId ];
+ SVTK_ViewManager* aViewManager =
+ ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
+ if( aViewManager )
+ return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
+ }
+ return NULL;
+}
+
+int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
+{
+ ViewManagerMapIterator anIter( myViewManagerMap );
+ while( anIter.hasNext() )
+ {
+ int anId = anIter.next().key();
+ const ViewManagerInfo& anInfo = anIter.value();
+ if( anInfo.first == theViewManager )
+ return anId;
+ }
+ return -1;
+}
+
+HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
+{
+ int anId = getViewManagerId( theViewManager );
+ if( anId != -1 )
+ {
+ const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
+ return anInfo.second;
+ }
+ return VMR_Unknown;
+}
+
+void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
+ const ViewManagerRole theRole )
+{
+ int anId = getViewManagerId( theViewManager );
+ if( anId != -1 )
+ {
+ ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
+ anInfo.second = theRole;
+ }
+}
+
+bool HYDROGUI_Module::isObjectVisible( const int theViewId,
+ const Handle(HYDROData_Entity)& theObject ) const
+{
+ if( theObject.IsNull() )
+ return false;
+
+ ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
+ if( anIter1 != myObjectStateMap.end() )
+ {
+ const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
+ QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
+
+ Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
+ if( anIter2 != aEntry2ObjectStateMap.end() )
+ {
+ const ObjectState& anObjectState = anIter2.value();
+ return anObjectState.Visibility;
+ }
+ }
+ return false;
+}
+
+void HYDROGUI_Module::setObjectVisible( const int theViewId,
+ const Handle(HYDROData_Entity)& theObject,
+ const bool theState )
+{
+ if( !theObject.IsNull() )
+ {
+ Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
+ QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
+
+ ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
+ anObjectState.Visibility = theState;
+ }
+}
+
+void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
+ const bool theState )
+{
+ if( !theObject.IsNull() )
+ {
+ // Process OCC shapes
+ ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
+ while( aShapesMapIter != myShapesMap.end() )
+ {
+ const ListOfShapes& aShapesList = aShapesMapIter.value();
+ foreach ( HYDROGUI_Shape* aShape, aShapesList )
+ {
+ if ( aShape && IsEqual( aShape->getObject(), theObject ) )
+ {
+ aShape->setIsToUpdate( theState );
+ }
+ }
+ aShapesMapIter++;
+ }
+ // Process VTK shapes
+ ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
+ while( aVTKPrsMapIter != myVTKPrsMap.end() )
+ {
+ const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
+ foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
+ {
+ if ( aShape && IsEqual( aShape->getObject(), theObject ) )
+ {
+ aShape->setIsToUpdate( theState );
+ }
+ }
+ aVTKPrsMapIter++;
+ }
+ }
+}
+
+/////////////////// OCC SHAPES PROCESSING
+QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
+ ObjectKind theKind ) const
+{
+ QList<HYDROGUI_Shape*> aResult;
+
+ if ( myShapesMap.contains( theViewId ) )
+ {
+ const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
+ foreach ( HYDROGUI_Shape* aShape, aViewShapes )
+ {
+ if( aShape && aShape->getObject()->GetKind()==theKind )
+ aResult.append( aShape );
+ }
+ }
+ return aResult;
+}
+
+HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
+ const Handle(HYDROData_Entity)& theObject ) const
+{
+ HYDROGUI_Shape* aResShape = NULL;
+ if( theObject.IsNull() )
+ return aResShape;
+
+ if ( myShapesMap.contains( theViewId ) )
+ {
+ const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
+ foreach ( HYDROGUI_Shape* aShape, aViewShapes )
+ {
+ if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
+ continue;
+
+ aResShape = aShape;
+ break;
+ }
+ }
+
+ return aResShape;
+}
+
+void HYDROGUI_Module::setObjectShape( const int theViewId,
+ const Handle(HYDROData_Entity)& theObject,
+ HYDROGUI_Shape* theShape )
+{
+ if( theObject.IsNull() )
+ return;
+
+ ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
+ aViewShapes.append( theShape );
+}
+
+void HYDROGUI_Module::removeObjectShape( const int theViewId,
+ const Handle(HYDROData_Entity)& theObject )
+{
+ if ( !myShapesMap.contains( theViewId ) )
+ return;
+
+ ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
+ Handle(HYDROData_Entity) anObject;
+ for ( int i = 0; i < aViewShapes.length(); )
+ {
+ HYDROGUI_Shape* aShape = aViewShapes.at( i );
+ anObject = aShape->getObject();
+ if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
+ {
+ delete aShape;
+ aViewShapes.removeAt( i );
+ continue;
+ }
+
+ ++i;
+ }
+}
+
+void HYDROGUI_Module::removeViewShapes( const int theViewId )
+{
+ if ( !myShapesMap.contains( theViewId ) )
+ return;
+
+ const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
+ for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
+ {
+ HYDROGUI_Shape* aShape = aViewShapes.at( i );
+ if ( aShape )
+ delete aShape;
+ }
+
+ myShapesMap.remove( theViewId );
+}
+/////////////////// END OF OCC SHAPES PROCESSING
+
+/////////////////// VTKPrs PROCESSING
+HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
+ const Handle(HYDROData_Entity)& theObject ) const
+{
+ HYDROGUI_VTKPrs* aResShape = NULL;
+ if( theObject.IsNull() )
+ return aResShape;
+
+ if ( myVTKPrsMap.contains( theViewId ) )
+ {
+ const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
+ foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
+ {
+ if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
+ continue;
+
+ aResShape = aShape;
+ break;
+ }
+ }
+
+ return aResShape;
+}
+
+void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
+ const Handle(HYDROData_Entity)& theObject,
+ HYDROGUI_VTKPrs* theShape )
+{
+ if( theObject.IsNull() )
+ return;
+
+ if( theShape && theShape->needScalarBar() )
+ {
+ // Compute the new global Z range from the added presentation and the old global Z range.
+ double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
+ double* aRange = theShape->getInternalZRange();
+ bool anIsUpdate = false;
+ if ( aRange[0] < aGlobalRange[0] )
+ {
+ aGlobalRange[0] = aRange[0];
+ anIsUpdate = true;
+ }
+ if ( aRange[1] > aGlobalRange[1] )
+ {
+ aGlobalRange[1] = aRange[1];
+ anIsUpdate = true;
+ }
+
+ //if ( anIsUpdate )
+ //{
+ updateVTKZRange( theViewId, aGlobalRange );
+ //}
+ }
+
+ ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
+ aViewShapes.append( theShape );
+}
+
+void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
+ const QString& theEntry )
+{
+ if ( !myVTKPrsMap.contains( theViewId ) )
+ return;
+
+ ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
+ Handle(HYDROData_Entity) anObject;
+ QString anEntryRef;
+ for ( int i = 0; i < aViewShapes.length(); )
+ {
+ HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
+ anObject = aShape->getObject();
+ anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
+ if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
+ {
+ delete aShape;
+ aViewShapes.removeAt( i );
+ continue;
+ }
+
+ ++i;
+ }
+
+ // Invalidate global Z range
+ double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
+ getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
+}
+
+void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
+ const Handle(HYDROData_Entity)& theObject )
+{
+ if ( !myVTKPrsMap.contains( theViewId ) )
+ return;
+
+ ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
+ Handle(HYDROData_Entity) anObject;
+ for ( int i = 0; i < aViewShapes.length(); )
+ {
+ HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
+ anObject = aShape->getObject();
+ if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
+ {
+ delete aShape;
+ aViewShapes.removeAt( i );
+ continue;
+ }
+
+ ++i;
+ }
+
+ // Invalidate global Z range
+ double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
+ getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
+}
+
+void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
+{
+ if ( !myVTKPrsMap.contains( theViewId ) )
+ return;
+
+ const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
+ for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
+ {
+ HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
+ if ( aShape )
+ delete aShape;
+ }
+
+ myVTKPrsMap.remove( theViewId );
+}
+
+void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
+{
+ if ( myVTKPrsMap.contains( theViewId ) )
+ {
+ // For the given viewer id update all VTK presentations ...
+ const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
+ HYDROGUI_VTKPrs* aShape;
+ for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
+ {
+ aShape = aViewShapes.at( i );
+ if ( aShape && aShape->needScalarBar() )
+ {
+ aShape->setZRange( theRange );
+ }
+ }
+ }
+ // ... and update the global color legend scalar bar.
+ getVTKDisplayer()->SetZRange( theViewId, theRange );
+}
+/////////////////// END OF VTKPrs PROCESSING
+