From: ouv Date: Wed, 4 Sep 2013 09:32:43 +0000 (+0000) Subject: Visibility management is improved. Methods SetVisible/IsVisible of HYDROData_Object... X-Git-Tag: BR_hydro_v_0_1~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=efb4364f3d91fb7106136328dec46c9e376d2144;p=modules%2Fhydro.git Visibility management is improved. Methods SetVisible/IsVisible of HYDROData_Object class have been replaced by setObjectVisible/isObjectVisible in HYDROGUI_Module. --- diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index 00158bbe..23f9038c 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -32,33 +32,6 @@ void HYDROData_Object::SetName(const QString& theName) TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); } -bool HYDROData_Object::IsVisible( const int theViewId ) const -{ - ViewId2VisualStateMap aMap; - GetViewId2VisualStateMap( aMap ); - if( aMap.find( theViewId ) != aMap.end() ) - { - const VisualState& aVisualState = aMap[ theViewId ]; - return aVisualState.Visibility; - } - return false; -} - -void HYDROData_Object::SetVisible( const int theViewId, - const bool theVal ) -{ - if( theViewId == 0 ) - return; - - ViewId2VisualStateMap aMap; - GetViewId2VisualStateMap( aMap ); - - VisualState& aVisualState = aMap[ theViewId ]; - aVisualState.Visibility = theVal; - - SetViewId2VisualStateMap( aMap ); -} - bool HYDROData_Object::IsRemoved() const { return !myLab.HasAttribute(); @@ -125,73 +98,3 @@ const char* HYDROData_Object::ByteArray(const int theTag, int& theLen) return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1))); return NULL; } - -void HYDROData_Object::GetViewId2VisualStateMap( ViewId2VisualStateMap& theMap ) const -{ - theMap.clear(); - - TDF_Label aViewIdLab = myLab.FindChild( DataTag_ViewId ); - TDF_Label aVisibilityLab = myLab.FindChild( DataTag_Visibility ); - TDF_Label aTransparencyLab = myLab.FindChild( DataTag_Transparency ); - TDF_Label aZValueLab = myLab.FindChild( DataTag_ZValue ); - - Handle(TDataStd_IntegerArray) aViewIdArray; - Handle(TDataStd_BooleanArray) aVisibilityArray; - Handle(TDataStd_RealArray) aTransparencyArray; - Handle(TDataStd_RealArray) aZValueArray; - - if( !aViewIdLab.FindAttribute( TDataStd_IntegerArray::GetID(), aViewIdArray ) || - !aVisibilityLab.FindAttribute( TDataStd_BooleanArray::GetID(), aVisibilityArray ) || - !aTransparencyLab.FindAttribute( TDataStd_RealArray::GetID(), aTransparencyArray ) || - !aZValueLab.FindAttribute( TDataStd_RealArray::GetID(), aZValueArray ) ) - return; - - int aSize = qMin( qMin( aViewIdArray->Length(), aVisibilityArray->Length() ), - qMin( aTransparencyArray->Length(), aZValueArray->Length() ) ); - for( int anIndex = 0; anIndex < aSize; anIndex++ ) - { - int aViewId = aViewIdArray->Value( anIndex ); - VisualState aVisualState; - aVisualState.Visibility = aVisibilityArray->Value( anIndex ); - aVisualState.Transparency = aTransparencyArray->Value( anIndex ); - aVisualState.ZValue = aZValueArray->Value( anIndex ); - theMap[ aViewId ] = aVisualState; - } -} - -void HYDROData_Object::SetViewId2VisualStateMap( const ViewId2VisualStateMap& theMap ) -{ - TDF_Label aViewIdLab = myLab.FindChild( DataTag_ViewId ); - TDF_Label aVisibilityLab = myLab.FindChild( DataTag_Visibility ); - TDF_Label aTransparencyLab = myLab.FindChild( DataTag_Transparency ); - TDF_Label aZValueLab = myLab.FindChild( DataTag_ZValue ); - - aViewIdLab.ForgetAllAttributes(); - aVisibilityLab.ForgetAllAttributes(); - aTransparencyLab.ForgetAllAttributes(); - aZValueLab.ForgetAllAttributes(); - - int aSize = theMap.size(); - - Handle(TDataStd_IntegerArray) aViewIdArray = - TDataStd_IntegerArray::Set( aViewIdLab, 0, aSize-1 ); - Handle(TDataStd_BooleanArray) aVisibilityArray = - TDataStd_BooleanArray::Set( aVisibilityLab, 0, aSize-1 ); - Handle(TDataStd_RealArray) aTransparencyArray = - TDataStd_RealArray::Set( aTransparencyLab, 0, aSize-1 ); - Handle(TDataStd_RealArray) aZValueArray = - TDataStd_RealArray::Set( aZValueLab, 0, aSize-1 ); - - int anIndex = 0; - ViewId2VisualStateMapIterator anIter( theMap ); - while( anIter.hasNext() ) - { - int aViewId = anIter.next().key(); - const VisualState& aVisualState = anIter.value(); - aViewIdArray->SetValue( anIndex, aViewId ); - aVisibilityArray->SetValue( anIndex, aVisualState.Visibility ); - aTransparencyArray->SetValue( anIndex, aVisualState.Transparency ); - aZValueArray->SetValue( anIndex, aVisualState.ZValue ); - anIndex++; - } -} diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index a8f999f2..e5bfa5fb 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -34,27 +34,10 @@ protected: */ enum DataTag { - DataTag_First = 0, ///< first tag, to reserve - DataTag_ViewId, ///< visual state, array of view ids - DataTag_Visibility, ///< visual state, array of visibility states - DataTag_Transparency, ///< visual state, array of transparency values - DataTag_ZValue ///< visual state, array of z-values + DataTag_First = 0 ///< first tag, to reserve + // ... }; -public: - /** - * Visual state data. - */ - struct VisualState - { - bool Visibility; - double Transparency; - double ZValue; - VisualState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {} - }; - typedef QMap < int, VisualState > ViewId2VisualStateMap; - typedef QMapIterator< int, VisualState > ViewId2VisualStateMapIterator; - public: DEFINE_STANDARD_RTTI(HYDROData_Object); @@ -73,21 +56,6 @@ public: */ HYDRODATA_EXPORT void SetName(const QString& theName); - /** - * Returns the object visibility state for the view with specified id. - * \param theViewId view id - * \returns visibility state - */ - HYDRODATA_EXPORT bool IsVisible( const int theViewId ) const; - - /** - * Sets the object visibility state for the view with specified id. - * \param theViewId view id - * \param theVal visibility state - */ - HYDRODATA_EXPORT void SetVisible( const int theViewId, - const bool theVal ); - /** * Checks is object exists in the data structure. * \returns true is object is not exists in the data model @@ -154,18 +122,6 @@ protected: */ const char* ByteArray(const int theTag, int& theLen); - /** - * Returns the map containing the visual states for the specified views. - * \param theMap map of visual states - */ - void GetViewId2VisualStateMap( ViewId2VisualStateMap& theMap ) const; - - /** - * Sets the map containing the visual states for the specified views. - * \param theMap map of visual states - */ - void SetViewId2VisualStateMap( const ViewId2VisualStateMap& theMap ); - protected: /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty. TDF_Label myLab; ///< label of this object diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index d6fc5f61..d979bfbe 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -189,7 +189,7 @@ void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs, if( aPrs ) { - bool anIsVisible = anObj->IsVisible( (size_t)aViewer ); + bool anIsVisible = myModule->isObjectVisible( (size_t)aViewer, anObj ); aPrs->setVisible( anIsVisible ); } } diff --git a/src/HYDROGUI/HYDROGUI_ExportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ExportImageOp.cxx index d4b3fccf..cedcb441 100644 --- a/src/HYDROGUI/HYDROGUI_ExportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportImageOp.cxx @@ -62,5 +62,5 @@ void HYDROGUI_ExportImageOp::startOperation() anImage.save( aFileName ); } - abort(); // do not commit the document command + commit(); } diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index d2da0a5c..f2835a47 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -304,7 +304,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, closePreview(); if( !myIsEdit ) - anImageObj->SetVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), true ); + module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true ); if( myIsEdit ) if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() ) diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index cf2220ba..c436594d 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -117,6 +117,8 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy ) getApp()->removeViewManager( aViewManager ); myViewManagerMap.clear(); + myObjectStateMap.clear(); + setMenuShown( false ); setToolShown( false ); @@ -161,7 +163,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, { anIsSelection = true; - bool aVisibility = anObject->IsVisible( aViewId ); + bool aVisibility = isObjectVisible( aViewId, anObject ); anIsVisibleInSelection |= aVisibility; anIsHiddenInSelection |= !aVisibility; @@ -248,13 +250,19 @@ void HYDROGUI_Module::update( const int flags ) // from one of the methods called below setUpdateEnabled( false ); + if( ( flags & UF_Viewer ) ) + updateGV( flags & UF_GV_Init, + flags & UF_GV_Forced ); + if( ( flags & UF_Model ) && getDataModel() && getApp() ) { getDataModel()->update( getStudyId() ); // Temporary workaround to prevent breaking - // the selection in the object browser - qApp->processEvents(); + // the selection in the object browser. + // Note: processEvents() should be called after updateGV(), + // otherwise the application crashes from time to time. + qApp->processEvents(); getApp()->updateObjectBrowser( true ); } @@ -262,10 +270,6 @@ void HYDROGUI_Module::update( const int flags ) //if( ( flags & UF_ObjBrowser ) && getApp() ) // getApp()->updateObjectBrowser( true ); - if( ( flags & UF_Viewer ) ) - updateGV( flags & UF_GV_Init, - flags & UF_GV_Forced ); - if( ( flags & UF_Controls ) && getApp() ) getApp()->updateActions(); @@ -342,6 +346,38 @@ void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager, } } +bool HYDROGUI_Module::isObjectVisible( const int theViewId, + const Handle(HYDROData_Object)& theObject ) +{ + if( theObject.IsNull() ) + return false; + + ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId ); + if( anIter1 != myObjectStateMap.end() ) + { + const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value(); + Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName()); + if( anIter2 != aName2ObjectStateMap.end() ) + { + const ObjectState& anObjectState = anIter2.value(); + return anObjectState.Visibility; + } + } + return false; +} + +void HYDROGUI_Module::setObjectVisible( const int theViewId, + const Handle(HYDROData_Object)& theObject, + const bool theState ) +{ + if( !theObject.IsNull() ) + { + Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ]; + ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ]; + anObjectState.Visibility = theState; + } +} + CAM_DataModel* HYDROGUI_Module::createDataModel() { return new HYDROGUI_DataModel( this ); @@ -357,13 +393,6 @@ void HYDROGUI_Module::customEvent( QEvent* e ) { if( GraphicsView_Viewer* aViewer = dynamic_cast( aViewFrame->getViewer() ) ) { - SUIT_ViewManager* aViewManager = aViewer->getViewManager(); - ViewManagerRole aRole = getViewManagerRole( aViewManager ); - if( aRole == VMR_General ) - update( UF_Viewer ); - - aViewer->activateTransform( GraphicsView_Viewer::FitAll ); - if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() ) { aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect ); @@ -373,6 +402,13 @@ void HYDROGUI_Module::customEvent( QEvent* e ) //ouv: temporarily commented //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true ); } + + SUIT_ViewManager* aViewManager = aViewer->getViewManager(); + ViewManagerRole aRole = getViewManagerRole( aViewManager ); + if( aRole != VMR_TransformImage ) + update( UF_Viewer ); + + aViewer->activateTransform( GraphicsView_Viewer::FitAll ); } } } diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 8db2c13b..9593a529 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -23,6 +23,8 @@ #ifndef HYDROGUI_MODULE_H #define HYDROGUI_MODULE_H +#include + #include #include @@ -52,6 +54,16 @@ public: typedef QMap < int, ViewManagerInfo > ViewManagerMap; typedef QMapIterator< int, ViewManagerInfo > ViewManagerMapIterator; + struct ObjectState + { + bool Visibility; + double Transparency; + double ZValue; + ObjectState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {} + }; + typedef QMap< QString, ObjectState > Name2ObjectStateMap; + typedef QMap< int, Name2ObjectStateMap > ViewId2Name2ObjectStateMap; + public: HYDROGUI_Module(); virtual ~HYDROGUI_Module(); @@ -80,6 +92,12 @@ public: void setViewManagerRole( SUIT_ViewManager* theViewManager, const ViewManagerRole theRole ); + bool isObjectVisible( const int theViewId, + const Handle(HYDROData_Object)& theObject ); + void setObjectVisible( const int theViewId, + const Handle(HYDROData_Object)& theObject, + const bool theState ); + protected: CAM_DataModel* createDataModel(); @@ -133,6 +151,7 @@ private: HYDROGUI_Displayer* myDisplayer; ViewManagerMap myViewManagerMap; + ViewId2Name2ObjectStateMap myObjectStateMap; bool myIsUpdateEnabled; }; diff --git a/src/HYDROGUI/HYDROGUI_ObserveImageOp.cxx b/src/HYDROGUI/HYDROGUI_ObserveImageOp.cxx index b559dbc1..9171df39 100644 --- a/src/HYDROGUI/HYDROGUI_ObserveImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ObserveImageOp.cxx @@ -25,6 +25,7 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_PrsImage.h" #include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" #include @@ -67,15 +68,10 @@ void HYDROGUI_ObserveImageOp::startOperation() module()->setViewManagerRole( aViewManager, HYDROGUI_Module::VMR_ObserveImage ); aViewManager->setTitle( anImageObj->GetName() ); if( GraphicsView_Viewer* aViewer = aViewManager->getViewer() ) - { - if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() ) - { - aViewPort->addItem( aPrs ); - aViewPort->fitAll(); - } - } + module()->setObjectVisible( (size_t)aViewer, anImageObj, true ); } } - abort(); // do not commit the document command + module()->update( UF_Viewer ); + commit(); } diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index 52c1509b..45383c5c 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -106,7 +106,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, aPolylineObj->setPolylineData(aPolylineData); theUpdateFlags = UF_Model; - aPolylineObj->SetVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), true ); + module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true ); return true; } diff --git a/src/HYDROGUI/HYDROGUI_PrsImageDriver.cxx b/src/HYDROGUI/HYDROGUI_PrsImageDriver.cxx index cac25c91..79b812f2 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImageDriver.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsImageDriver.cxx @@ -38,6 +38,7 @@ HYDROGUI_PrsImageDriver::~HYDROGUI_PrsImageDriver() bool HYDROGUI_PrsImageDriver::Update( const Handle(HYDROData_Object)& theObj, HYDROGUI_Prs*& thePrs ) { + printf( "Update( %s )\n", qPrintable( theObj->GetName() ) ); HYDROGUI_PrsDriver::Update( theObj, thePrs ); if( theObj.IsNull() ) @@ -56,6 +57,9 @@ bool HYDROGUI_PrsImageDriver::Update( const Handle(HYDROData_Object)& theObj, aPrsImage->setImage( anImage->Image() ); aPrsImage->setTransform( anImage->Trsf() ); + QImage i = anImage->Image(); + printf( "w = %d, h = %d\n", i.width(), i.height() ); + aPrsImage->compute(); return true; diff --git a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx index 8d91cde4..a2d46be4 100644 --- a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx @@ -55,8 +55,6 @@ void HYDROGUI_ShowHideOp::startOperation() { HYDROGUI_Operation::startOperation(); - startDocOperation(); - size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); // for all objects @@ -68,7 +66,7 @@ void HYDROGUI_ShowHideOp::startOperation() { Handle(HYDROData_Object) anObject = anIterator.Current(); if( !anObject.IsNull() ) - anObject->SetVisible( aViewId, aVisibility ); + module()->setObjectVisible( aViewId, anObject, aVisibility ); } } @@ -82,12 +80,10 @@ void HYDROGUI_ShowHideOp::startOperation() { Handle(HYDROData_Object) anObject = aSeq.Value( anIndex ); if( !anObject.IsNull() ) - anObject->SetVisible( aViewId, aVisibility ); + module()->setObjectVisible( aViewId, anObject, aVisibility ); } } - commitDocOperation(); - module()->update( UF_Viewer ); commit(); } diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index 3422f245..8754c305 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -180,9 +180,10 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, if( !myIsEdit ) { size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); - anImage1->SetVisible( aViewId, false ); - anImage2->SetVisible( aViewId, false ); - aResult->SetVisible( aViewId, true ); + module()->setObjectVisible( aViewId, anImage1, false ); + module()->setObjectVisible( aViewId, anImage2, false ); + module()->setObjectVisible( aViewId, aResult, true ); + } theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced; diff --git a/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx b/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx index 37f9c27f..90a79828 100644 --- a/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx +++ b/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx @@ -59,7 +59,8 @@ void HYDROGUI_VisualStateOp::startOperation() { HYDROGUI_Operation::startOperation(); - startDocOperation(); + if( !myIsLoad ) + startDocOperation(); bool aResult = false; if( myIsLoad ) @@ -69,13 +70,15 @@ void HYDROGUI_VisualStateOp::startOperation() if( aResult ) { - commitDocOperation(); + if( !myIsLoad ) + commitDocOperation(); commit(); } else { - abortDocOperation(); - abort(); // do not commit the document command + if( !myIsLoad ) + abortDocOperation(); + abort(); } } @@ -140,7 +143,7 @@ bool HYDROGUI_VisualStateOp::saveVisualState() // Format: "Name|Visibility[|CoordX|CoordY]" QString aParameters = anObject->GetName(); - int aVisibility = (int)anObject->IsVisible( aViewId ); + int aVisibility = (int)( module()->isObjectVisible( aViewId, anObject ) ); aParameters.append( QString( "|%1" ).arg( aVisibility ) ); setVisualProperty( aPropertyMap, aViewerEntry, aParameters, true ); @@ -255,7 +258,7 @@ bool HYDROGUI_VisualStateOp::loadVisualState() { bool anIsVisible = aParameters[ aParamIndex ].toInt( &anIsOk[ ++aParamIndex ] ); if( anIsOk[ 0 ] ) - anObject->SetVisible( aViewId, anIsVisible ); + module()->setObjectVisible( aViewId, anObject, anIsVisible ); } } }