From 061386caa71490489a0475540932d9f2e48d77dc Mon Sep 17 00:00:00 2001 From: ouv Date: Mon, 26 Aug 2013 10:25:35 +0000 Subject: [PATCH] 1) Improved visibility management 2) Save/load visual state --- src/HYDROData/CMakeLists.txt | 6 +- src/HYDROData/HYDROData_Image.cxx | 20 +- src/HYDROData/HYDROData_Image.h | 11 + src/HYDROData/HYDROData_Iterator.cxx | 4 + src/HYDROData/HYDROData_Object.cxx | 104 +++++- src/HYDROData/HYDROData_Object.h | 54 ++- src/HYDROData/HYDROData_Polyline.cxx | 28 +- src/HYDROData/HYDROData_Polyline.h | 13 + src/HYDROData/HYDROData_VisualState.cxx | 32 ++ src/HYDROData/HYDROData_VisualState.h | 63 ++++ src/HYDROGUI/CMakeLists.txt | 2 + src/HYDROGUI/HYDROGUI_DataModel.cxx | 18 +- src/HYDROGUI/HYDROGUI_Displayer.cxx | 4 +- src/HYDROGUI/HYDROGUI_ImportImageOp.cxx | 9 +- src/HYDROGUI/HYDROGUI_Module.cxx | 26 +- src/HYDROGUI/HYDROGUI_Operations.cxx | 13 + src/HYDROGUI/HYDROGUI_Operations.h | 2 + src/HYDROGUI/HYDROGUI_PolylineOp.cxx | 2 +- src/HYDROGUI/HYDROGUI_ShowHideOp.cxx | 6 +- src/HYDROGUI/HYDROGUI_Tool.cxx | 42 ++- src/HYDROGUI/HYDROGUI_Tool.h | 16 +- src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx | 7 +- src/HYDROGUI/HYDROGUI_VisualStateOp.cxx | 407 ++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_VisualStateOp.h | 69 ++++ src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 41 ++- 25 files changed, 927 insertions(+), 72 deletions(-) create mode 100644 src/HYDROData/HYDROData_VisualState.cxx create mode 100644 src/HYDROData/HYDROData_VisualState.h create mode 100644 src/HYDROGUI/HYDROGUI_VisualStateOp.cxx create mode 100644 src/HYDROGUI/HYDROGUI_VisualStateOp.h diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index bf28f0d0..c5383920 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -4,19 +4,21 @@ set(PROJECT_HEADERS HYDROData.h HYDROData_Application.h HYDROData_Document.h + HYDROData_Image.h HYDROData_Iterator.h HYDROData_Object.h - HYDROData_Image.h HYDROData_Polyline.h + HYDROData_VisualState.h ) set(PROJECT_SOURCES HYDROData_Application.cxx HYDROData_Document.cxx + HYDROData_Image.cxx HYDROData_Iterator.cxx HYDROData_Object.cxx - HYDROData_Image.cxx HYDROData_Polyline.cxx + HYDROData_VisualState.cxx ) add_definitions( diff --git a/src/HYDROData/HYDROData_Image.cxx b/src/HYDROData/HYDROData_Image.cxx index 8fe96f68..a41cc264 100644 --- a/src/HYDROData/HYDROData_Image.cxx +++ b/src/HYDROData/HYDROData_Image.cxx @@ -9,12 +9,6 @@ #include #include -// tag of the child of my label that contains information about the operator -static const int TAG_OPERATOR = 1; - -// tag of the child of my label that contains information transformation points -static const int TAG_TRSF_POINTS = 2; - static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000"); IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Object) @@ -104,8 +98,8 @@ void HYDROData_Image::SetTrsfPoints(const QPoint& thePointAIn, const QPointF& thePointCOut) { Handle(TDataStd_RealArray) anArray; - if (!myLab.FindChild(TAG_TRSF_POINTS).FindAttribute(TDataStd_RealArray::GetID(), anArray)) { - anArray = TDataStd_RealArray::Set(myLab.FindChild(TAG_TRSF_POINTS), 1, 12); + if (!myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray)) { + anArray = TDataStd_RealArray::Set(myLab.FindChild(DataTag_TrsfPoints), 1, 12); } anArray->SetValue(1, thePointAIn.x()); anArray->SetValue(2, thePointAIn.y()); @@ -129,7 +123,7 @@ void HYDROData_Image::TrsfPoints(QPoint& thePointAIn, QPointF& thePointCOut) { Handle(TDataStd_RealArray) anArray; - if (myLab.FindChild(TAG_TRSF_POINTS).FindAttribute(TDataStd_RealArray::GetID(), anArray)) { + if (myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray)) { thePointAIn = QPointF( anArray->Value(1), anArray->Value(2) ).toPoint(); thePointBIn = QPointF( anArray->Value(3), anArray->Value(4) ).toPoint(); thePointCIn = QPointF( anArray->Value(5), anArray->Value(6) ).toPoint(); @@ -214,14 +208,14 @@ void HYDROData_Image::ClearReferences() void HYDROData_Image::SetOperatorName(const QString theOpName) { - TDataStd_Name::Set(myLab.FindChild(TAG_OPERATOR), + TDataStd_Name::Set(myLab.FindChild(DataTag_Operator), TCollection_ExtendedString(theOpName.toLatin1().constData())); } QString HYDROData_Image::OperatorName() { Handle(TDataStd_Name) aName; - if (myLab.FindChild(TAG_OPERATOR). + if (myLab.FindChild(DataTag_Operator). FindAttribute(TDataStd_Name::GetID(), aName)) { TCollection_AsciiString aStr(aName->Get()); return QString(aStr.ToCString()); @@ -231,13 +225,13 @@ QString HYDROData_Image::OperatorName() void HYDROData_Image::SetArgs(const QByteArray& theArgs) { - SaveByteArray(TAG_OPERATOR, theArgs.constData(), theArgs.length()); + SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length()); } QByteArray HYDROData_Image::Args() { int aLen = 0; - const char* aData = ByteArray(TAG_OPERATOR, aLen); + const char* aData = ByteArray(DataTag_Operator, aLen); if (!aLen) return QByteArray(); return QByteArray(aData, aLen); diff --git a/src/HYDROData/HYDROData_Image.h b/src/HYDROData/HYDROData_Image.h index dda1648b..e2df2a4e 100644 --- a/src/HYDROData/HYDROData_Image.h +++ b/src/HYDROData/HYDROData_Image.h @@ -16,6 +16,17 @@ DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Object) */ class HYDROData_Image : public HYDROData_Object { +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve + DataTag_Operator, ///< name of the operator that must be executed for image update + DataTag_TrsfPoints ///< image transformation points (3 input + 3 output) + }; + public: DEFINE_STANDARD_RTTI(HYDROData_Image); diff --git a/src/HYDROData/HYDROData_Iterator.cxx b/src/HYDROData/HYDROData_Iterator.cxx index da22e5eb..95a70708 100644 --- a/src/HYDROData/HYDROData_Iterator.cxx +++ b/src/HYDROData/HYDROData_Iterator.cxx @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -58,6 +59,9 @@ Handle_HYDROData_Object HYDROData_Iterator::Object(const TDF_Label theLabel) case KIND_POLYLINE: aResult = new HYDROData_Polyline(); break; + case KIND_VISUAL_STATE: + aResult = new HYDROData_VisualState(); + break; } if (!aResult.IsNull()) aResult->SetLabel(theLabel); diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index fe71e385..00158bbe 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -3,10 +3,11 @@ #include #include #include +#include +#include +#include #include -static const Standard_GUID GUID_VISIBILITY("d6a715c5-9c86-4adc-8a6c-13188f3ad94b"); - IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared) @@ -31,18 +32,31 @@ void HYDROData_Object::SetName(const QString& theName) TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); } -bool HYDROData_Object::GetVisibility() const +bool HYDROData_Object::IsVisible( const int theViewId ) const { - return myLab.IsAttribute(GUID_VISIBILITY); + ViewId2VisualStateMap aMap; + GetViewId2VisualStateMap( aMap ); + if( aMap.find( theViewId ) != aMap.end() ) + { + const VisualState& aVisualState = aMap[ theViewId ]; + return aVisualState.Visibility; + } + return false; } -void HYDROData_Object::SetVisibility(bool theState) +void HYDROData_Object::SetVisible( const int theViewId, + const bool theVal ) { - if (theState) { - TDataStd_UAttribute::Set(myLab, GUID_VISIBILITY); - } else { - myLab.ForgetAttribute(GUID_VISIBILITY); - } + if( theViewId == 0 ) + return; + + ViewId2VisualStateMap aMap; + GetViewId2VisualStateMap( aMap ); + + VisualState& aVisualState = aMap[ theViewId ]; + aVisualState.Visibility = theVal; + + SetViewId2VisualStateMap( aMap ); } bool HYDROData_Object::IsRemoved() const @@ -111,3 +125,73 @@ 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 f4b30d70..993297ad 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -5,6 +5,7 @@ #include #include +#include #include ///! Kind of an object in a document @@ -13,6 +14,7 @@ typedef int ObjectKind; const ObjectKind KIND_UNKNOWN = 0; const ObjectKind KIND_IMAGE = 1; const ObjectKind KIND_POLYLINE = 2; +const ObjectKind KIND_VISUAL_STATE = 3; DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared) @@ -25,6 +27,33 @@ DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared) */ class HYDROData_Object : public MMgt_TShared { +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + 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 + }; + +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); @@ -44,16 +73,19 @@ public: HYDRODATA_EXPORT void SetName(const QString& theName); /** - * Returns the object visibility state. + * Returns the object visibility state for the view with specified id. + * \param theViewId view id * \returns visibility state */ - HYDRODATA_EXPORT bool GetVisibility() const; + HYDRODATA_EXPORT bool IsVisible( const int theViewId ) const; /** - * Sets the object visibility state. - * \param theState visibility state + * Sets the object visibility state for the view with specified id. + * \param theViewId view id + * \param theVal visibility state */ - HYDRODATA_EXPORT void SetVisibility(bool theState); + HYDRODATA_EXPORT void SetVisible( const int theViewId, + const bool theVal ); /** * Checks is object exists in the data structure. @@ -121,6 +153,18 @@ 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/HYDROData/HYDROData_Polyline.cxx b/src/HYDROData/HYDROData_Polyline.cxx index 294f0e98..34ebfe25 100755 --- a/src/HYDROData/HYDROData_Polyline.cxx +++ b/src/HYDROData/HYDROData_Polyline.cxx @@ -16,12 +16,6 @@ // tage of the child of my label that contains information about the operator static const Standard_GUID GUID_MUST_BE_UPDATED("6647e1f7-1971-4c5a-86c7-11ff0291452d"); -#define TAG_POINTS 1 -#define TAG_SECTIONS_NAME 2 -#define TAG_SECTIONS_CLOSED 3 -#define TAG_SECTIONS_SIZE 4 -#define TAG_SECTIONS_TYPE 5 - IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline, HYDROData_Object) @@ -78,19 +72,19 @@ void HYDROData_Polyline::setPolylineData( const QList& theSecti int aPointsCnt = 0; - TDF_Label aNameLab = myLab.FindChild(TAG_SECTIONS_NAME); + TDF_Label aNameLab = myLab.FindChild(DataTag_SectionsName); Handle(TDataStd_ExtStringArray) aSectsNameArray; aSectsNameArray = TDataStd_ExtStringArray::Set(aNameLab, 0, aSectionsSize-1, false ); - TDF_Label aSizeLab = myLab.FindChild(TAG_SECTIONS_SIZE); + TDF_Label aSizeLab = myLab.FindChild(DataTag_SectionsSize); Handle(TDataStd_IntegerArray) aSizeArray; aSizeArray = TDataStd_IntegerArray::Set(aSizeLab, 0, aSectionsSize-1, false ); - TDF_Label aClosedLab = myLab.FindChild(TAG_SECTIONS_CLOSED); + TDF_Label aClosedLab = myLab.FindChild(DataTag_SectionsClosed); Handle(TDataStd_BooleanArray) aClosedArray; aClosedArray = TDataStd_BooleanArray::Set(aClosedLab, 0, aSectionsSize-1 ); - TDF_Label aTypeLab = myLab.FindChild(TAG_SECTIONS_TYPE); + TDF_Label aTypeLab = myLab.FindChild(DataTag_SectionsType); Handle(TDataStd_ByteArray) aTypeArray; aTypeArray = TDataStd_ByteArray::Set(aTypeLab, 0, aSectionsSize-1, false ); @@ -128,7 +122,7 @@ QList HYDROData_Polyline::getPolylineData() int aSectCnt; QList aRes; //Get sections size array handle - TDF_Label aLab = myLab.FindChild( TAG_SECTIONS_SIZE ); + TDF_Label aLab = myLab.FindChild( DataTag_SectionsSize ); Handle(TDataStd_IntegerArray) aSizeArray; if (!aLab.FindAttribute(TDataStd_IntegerArray::GetID(), aSizeArray)) return aRes; // return empty if no array @@ -136,7 +130,7 @@ QList HYDROData_Polyline::getPolylineData() if( aSectCnt == 0 ) return aRes; //Get section type array handle - aLab = myLab.FindChild( TAG_SECTIONS_TYPE ); + aLab = myLab.FindChild( DataTag_SectionsType ); Handle(TDataStd_ByteArray) aTypeArray; if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aTypeArray)) return aRes; @@ -144,7 +138,7 @@ QList HYDROData_Polyline::getPolylineData() if( aLen != aSectCnt ) return aRes; //Get section closed array handle - aLab = myLab.FindChild( TAG_SECTIONS_CLOSED ); + aLab = myLab.FindChild( DataTag_SectionsClosed ); Handle(TDataStd_BooleanArray) aClosedArray; if (!aLab.FindAttribute(TDataStd_BooleanArray::GetID(), aClosedArray)) return aRes; @@ -152,7 +146,7 @@ QList HYDROData_Polyline::getPolylineData() if( aLen != aSectCnt ) return aRes; //Get sections names - TDF_Label aNameLab = myLab.FindChild(TAG_SECTIONS_NAME); + TDF_Label aNameLab = myLab.FindChild(DataTag_SectionsName); Handle(TDataStd_ExtStringArray) aSectNamesArray; if(!aNameLab.FindAttribute(TDataStd_ExtStringArray::GetID(), aSectNamesArray)) return aRes; @@ -186,13 +180,13 @@ QList HYDROData_Polyline::getPolylineData() void HYDROData_Polyline::removeAll() { //Remove only section data - TDF_Label aLab = myLab.FindChild( TAG_SECTIONS_SIZE ); + TDF_Label aLab = myLab.FindChild( DataTag_SectionsSize ); aLab.ForgetAllAttributes(); - aLab = myLab.FindChild( TAG_SECTIONS_TYPE ); + aLab = myLab.FindChild( DataTag_SectionsType ); aLab.ForgetAllAttributes(); - aLab = myLab.FindChild( TAG_SECTIONS_CLOSED ); + aLab = myLab.FindChild( DataTag_SectionsClosed ); aLab.ForgetAllAttributes(); myLab.ForgetAttribute(TDataStd_RealArray::GetID()); diff --git a/src/HYDROData/HYDROData_Polyline.h b/src/HYDROData/HYDROData_Polyline.h index a7565047..73a06a53 100755 --- a/src/HYDROData/HYDROData_Polyline.h +++ b/src/HYDROData/HYDROData_Polyline.h @@ -30,6 +30,19 @@ public: */ class HYDROData_Polyline : public HYDROData_Object { +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve + DataTag_SectionsName, + DataTag_SectionsClosed, + DataTag_SectionsSize, + DataTag_SectionsType + }; + public: DEFINE_STANDARD_RTTI(HYDROData_Polyline); diff --git a/src/HYDROData/HYDROData_VisualState.cxx b/src/HYDROData/HYDROData_VisualState.cxx new file mode 100644 index 00000000..e3e06413 --- /dev/null +++ b/src/HYDROData/HYDROData_VisualState.cxx @@ -0,0 +1,32 @@ +#include + +#include + +IMPLEMENT_STANDARD_HANDLE(HYDROData_VisualState, HYDROData_Object) +IMPLEMENT_STANDARD_RTTIEXT(HYDROData_VisualState, HYDROData_Object) + +HYDROData_VisualState::HYDROData_VisualState() +{ +} + +HYDROData_VisualState::~HYDROData_VisualState() +{ +} + +void HYDROData_VisualState::SetState( const QString& theState ) +{ + TCollection_AsciiString aString; + Handle(TDataStd_AsciiString) aState; + if( !myLab.FindAttribute( TDataStd_AsciiString::GetID(), aState ) ) + aState = TDataStd_AsciiString::Set( myLab, aString ); + aString.AssignCat( theState.toLatin1().constData() ); + aState->Set( aString ); +} + +QString HYDROData_VisualState::GetState() const +{ + Handle(TDataStd_AsciiString) aState; + if( !myLab.FindAttribute( TDataStd_AsciiString::GetID(), aState ) ) + return QString(); + return QString( aState->Get().ToCString() ); +} diff --git a/src/HYDROData/HYDROData_VisualState.h b/src/HYDROData/HYDROData_VisualState.h new file mode 100644 index 00000000..6a53c44c --- /dev/null +++ b/src/HYDROData/HYDROData_VisualState.h @@ -0,0 +1,63 @@ +#ifndef HYDROData_VisualState_HeaderFile +#define HYDROData_VisualState_HeaderFile + +#include + +#include + +DEFINE_STANDARD_HANDLE(HYDROData_VisualState, HYDROData_Object) + +/**\class HYDROData_VisualState + * \brief Class that stores/retreives information about the visual state. + * + * Keeps the visual state as encoded text string. + */ +class HYDROData_VisualState : public HYDROData_Object +{ +protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve + DataTag_State ///< encoded visual state + }; + +public: + DEFINE_STANDARD_RTTI(HYDROData_VisualState); + + /** + * Returns the kind of this object. Must be redefined in all objects of known type. + */ + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_VISUAL_STATE; } + + /** + * Stores the encoded visual state + * \param theState new state + */ + HYDRODATA_EXPORT void SetState( const QString& theState ); + + /** + * Returns the encoded visual state + */ + HYDRODATA_EXPORT QString GetState() const; + +protected: + + friend class HYDROData_Iterator; + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDROData_VisualState(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + ~HYDROData_VisualState(); + +}; + +#endif diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 5231ebb9..6225c6ef 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -32,6 +32,7 @@ set(PROJECT_HEADERS HYDROGUI_TwoImagesDlg.h HYDROGUI_TwoImagesOp.h HYDROGUI_UpdateFlags.h + HYDROGUI_VisualStateOp.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -65,6 +66,7 @@ set(PROJECT_SOURCES HYDROGUI_Tool.cxx HYDROGUI_TwoImagesDlg.cxx HYDROGUI_TwoImagesOp.cxx + HYDROGUI_VisualStateOp.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index abcc6274..63a65988 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -197,15 +198,26 @@ void HYDROGUI_DataModel::update( const int theStudyId ) LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, "POLYLINES" ); - HYDROData_Iterator aPolyIterator( aDocument, KIND_POLYLINE ); - for( ; aPolyIterator.More(); aPolyIterator.Next() ) + anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE ); + for( ; anIterator.More(); anIterator.Next() ) { Handle(HYDROData_Polyline) aPolylineObj = - Handle(HYDROData_Polyline)::DownCast( aPolyIterator.Current() ); + Handle(HYDROData_Polyline)::DownCast( anIterator.Current() ); if( !aPolylineObj.IsNull() ) createObject( aPolylineRootObj, aPolylineObj ); } + LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, "VISUAL_STATES" ); + + anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE ); + for( ; anIterator.More(); anIterator.Next() ) + { + Handle(HYDROData_VisualState) aVisualStateObj = + Handle(HYDROData_VisualState)::DownCast( anIterator.Current() ); + if( !aVisualStateObj.IsNull() ) + createObject( aVisualStateRootObj, aVisualStateObj ); + } + if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() ) { anObjectBrowser->setAutoOpenLevel( 3 ); diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index 7a254ac8..bb228021 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -98,7 +98,7 @@ void HYDROGUI_Displayer::DisplayAll( const int theViewerId, const bool theIsForced ) { HYDROData_SequenceOfObjects aSeq; - HYDROGUI_Tool::GetPrsSubObjects( myModule, theViewerId, aSeq ); + HYDROGUI_Tool::GetPrsSubObjects( myModule, aSeq ); Update( aSeq, theViewerId, theIsForced ); } @@ -189,7 +189,7 @@ void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs, if( aPrs ) { - bool anIsVisible = anObj->GetVisibility(); + bool anIsVisible = anObj->IsVisible( (int)aViewer ); aPrs->setVisible( anIsVisible ); } } diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index 0baa3d6f..2b76bdb3 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -144,11 +144,16 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, } } + if( !myPreviewPrs ) + return false; + QImage anImage = myPreviewPrs->getImage(); + closePreview(); + HYDROGUI_ImportImageDlg::TransformationDataMap aMap; bool anIsOk = aPanel->getTransformationDataMap( aMap ); - if( !anIsOk || !myPreviewPrs ) + if( !anIsOk ) return false; QPoint aPointA1 = aMap[ HYDROGUI_PrsImage::PointA ].first; @@ -208,7 +213,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, anImageObj->SetTrsfPoints( aPointA1, aPointB1, aPointC1, aPointA2, aPointB2, aPointC2 ); - anImageObj->SetVisibility( true ); + anImageObj->SetVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), true ); theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced; return true; diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 9b13d845..4dd19fe0 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -139,12 +139,15 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, { HYDROGUI_DataModel* aModel = getDataModel(); + int aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( this ); + bool anIsSelection = false; bool anIsVisibleInSelection = false; bool anIsHiddenInSelection = false; bool anIsImage = false; bool anIsPolyline = false; + bool anIsVisualState = false; HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this ); for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) @@ -154,19 +157,25 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, { anIsSelection = true; - bool aVisibility = anObject->GetVisibility(); + bool aVisibility = anObject->IsVisible( aViewId ); anIsVisibleInSelection |= aVisibility; anIsHiddenInSelection |= !aVisibility; if( anObject->GetKind() == KIND_IMAGE ) anIsImage = true; - - if( anObject->GetKind() == KIND_POLYLINE ) + else if( anObject->GetKind() == KIND_POLYLINE ) anIsPolyline = true; + else if( anObject->GetKind() == KIND_VISUAL_STATE ) + anIsVisualState = true; } } - if( aSeq.Length() == 1 ) + if( aSeq.IsEmpty() ) + { + theMenu->addAction( action( SaveVisualStateId ) ); + theMenu->addSeparator(); + } + else if( anIsSelection && aSeq.Length() == 1 ) { if( anIsImage ) { @@ -180,6 +189,12 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( EditPolylineId ) ); theMenu->addSeparator(); } + else if( anIsVisualState ) + { + theMenu->addAction( action( SaveVisualStateId ) ); + theMenu->addAction( action( LoadVisualStateId ) ); + theMenu->addSeparator(); + } } if( anIsSelection ) @@ -188,7 +203,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addSeparator(); } - if( anIsSelection ) + if( anIsSelection && ( anIsImage || anIsPolyline ) ) { if( anIsHiddenInSelection ) theMenu->addAction( action( ShowId ) ); @@ -197,6 +212,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( HideId ) ); theMenu->addSeparator(); } + theMenu->addAction( action( ShowAllId ) ); theMenu->addAction( action( HideAllId ) ); theMenu->addSeparator(); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index e173c54b..a2b82864 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -32,6 +32,7 @@ #include "HYDROGUI_ShowHideOp.h" #include "HYDROGUI_TwoImagesOp.h" #include "HYDROGUI_UpdateFlags.h" +#include "HYDROGUI_VisualStateOp.h" #include @@ -64,6 +65,9 @@ QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffi void HYDROGUI_Module::createActions() { + createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" ); + createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" ); + createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I ); createAction( EditImageId, "EDIT_IMAGE" ); createAction( ObserveImageId, "OBSERVE_IMAGE" ); @@ -85,6 +89,11 @@ void HYDROGUI_Module::createActions() void HYDROGUI_Module::createMenus() { + int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 ); + int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences" + createMenu( SaveVisualStateId, aFileMenu, aCustomPos ); + createMenu( separator(), aFileMenu, -1, aCustomPos ); + int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 ); createMenu( UndoId, anEditMenu ); createMenu( RedoId, anEditMenu ); @@ -207,6 +216,10 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const HYDROGUI_Module* aModule = const_cast( this ); switch( theId ) { + case SaveVisualStateId: + case LoadVisualStateId: + anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId ); + break; case ImportImageId: case EditImageId: anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImageId ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index d8a2b9e8..7c835e50 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -26,6 +26,8 @@ enum OperationId { FirstId = 0, + SaveVisualStateId, + LoadVisualStateId, UndoId, RedoId, ImportImageId, diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index 3e9d21a6..636b6249 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -94,7 +94,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, aPolylineObj->setPolylineData(aPolylineData); theUpdateFlags = UF_Model; - aPolylineObj->SetVisibility( true ); + aPolylineObj->SetVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), true ); return true; } diff --git a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx index 305af96e..4fa7c8a3 100644 --- a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx @@ -55,6 +55,8 @@ void HYDROGUI_ShowHideOp::startOperation() { HYDROGUI_Operation::startOperation(); + int aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); + // for all objects if( myId == ShowOnlyId || myId == ShowAllId || myId == HideAllId ) { @@ -64,7 +66,7 @@ void HYDROGUI_ShowHideOp::startOperation() { Handle(HYDROData_Object) anObject = anIterator.Current(); if( !anObject.IsNull() ) - anObject->SetVisibility( aVisibility ); + anObject->SetVisible( aViewId, aVisibility ); } } @@ -78,7 +80,7 @@ void HYDROGUI_ShowHideOp::startOperation() { Handle(HYDROData_Object) anObject = aSeq.Value( anIndex ); if( !anObject.IsNull() ) - anObject->SetVisibility( aVisibility ? true : false ); + anObject->SetVisible( aViewId, aVisibility ); } } diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 0a942119..39b6bb97 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -29,6 +29,8 @@ #include #include +#include + #include #include #include @@ -161,14 +163,21 @@ void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule, } void HYDROGUI_Tool::GetPrsSubObjects( HYDROGUI_Module* theModule, - const int theViewerId, // currently unused HYDROData_SequenceOfObjects& theSeq ) { Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); if( aDocument.IsNull() ) return; - HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN ); + HYDROData_Iterator anIterator( aDocument, KIND_IMAGE ); + for( ; anIterator.More(); anIterator.Next() ) + { + Handle(HYDROData_Object) anObject = anIterator.Current(); + if( !anObject.IsNull() ) + theSeq.Append( anObject ); + } + + anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE ); for( ; anIterator.More(); anIterator.Next() ) { Handle(HYDROData_Object) anObject = anIterator.Current(); @@ -278,3 +287,32 @@ QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule, } return aName; } + +int HYDROGUI_Tool::GetActiveGraphicsViewId( HYDROGUI_Module* theModule ) +{ + int aViewId = 0; + SUIT_ViewManager* aViewMgr = theModule->getApp()->activeViewManager(); + if( !aViewMgr || aViewMgr->getType() != GraphicsView_Viewer::Type() ) + return aViewId; + + if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() ) + aViewId = (int)aViewer; + return aViewId; +} + +QList HYDROGUI_Tool::GetGraphicsViewIdList( HYDROGUI_Module* theModule ) +{ + QList aList; + ViewManagerList aViewMgrs; + theModule->getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewMgrs ); + QListIterator anIter( aViewMgrs ); + while( anIter.hasNext() ) + { + if( SUIT_ViewManager* aViewMgr = anIter.next() ) + { + if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() ) + aList.append( (int)aViewer ); + } + } + return aList; +} diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 1af2f5d7..e67274fc 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -113,11 +113,9 @@ public: /** * \brief Get sub-objects to build presentations. * \param theModule module - * \param theViewerId viewer id * \param theSeq sequence of sub-objects */ static void GetPrsSubObjects( HYDROGUI_Module* theModule, - const int theViewerId, HYDROData_SequenceOfObjects& theSeq ); /** @@ -169,6 +167,20 @@ public: */ static QString GenerateObjectName( HYDROGUI_Module* theModule, const QString& thePrefix ); + + /** + * \brief Get id of the active GraphicsView view. + * \param theModule module + * \return view id + */ + static int GetActiveGraphicsViewId( HYDROGUI_Module* theModule ); + + /** + * \brief Get list of ids of existing GraphicsView views. + * \param theModule module + * \return list of view ids + */ + static QList GetGraphicsViewIdList( HYDROGUI_Module* theModule ); }; #endif diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index 38da834f..6a4268c6 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -118,9 +118,10 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, aResult->AppendReference( anImage2 ); aFactory->UpdateImage( doc(), aResult ); - anImage1->SetVisibility( false ); - anImage2->SetVisibility( false ); - aResult->SetVisibility( true ); + int aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); + anImage1->SetVisible( aViewId, false ); + anImage2->SetVisible( aViewId, false ); + aResult->SetVisible( aViewId, true ); theUpdateFlags = UF_Model | UF_Viewer; return true; diff --git a/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx b/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx new file mode 100644 index 00000000..326b5ab8 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VisualStateOp.cxx @@ -0,0 +1,407 @@ +// 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_VisualStateOp.h" + +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" + +#include +#include + +#include + +#include + +#include + +#include + +#include +#include +#include + +#include + +HYDROGUI_VisualStateOp::HYDROGUI_VisualStateOp( HYDROGUI_Module* theModule, + const bool theIsLoad ) +: HYDROGUI_Operation( theModule ), + myIsLoad( theIsLoad ) +{ + setName( theIsLoad ? tr( "LOAD_VISUAL_STATE" ) : tr( "SAVE_VISUAL_STATE" ) ); +} + +HYDROGUI_VisualStateOp::~HYDROGUI_VisualStateOp() +{ +} + +void HYDROGUI_VisualStateOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + bool aResult = false; + if( myIsLoad ) + aResult = loadVisualState(); + else + aResult = saveVisualState(); + + if( aResult ) + commit(); + else + abort(); // do not commit the document command +} + +bool HYDROGUI_VisualStateOp::saveVisualState() +{ + LightApp_Application* anApp = module()->getApp(); + + Handle(HYDROData_VisualState) aVisualState = + Handle(HYDROData_VisualState)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if( aVisualState.IsNull() ) + { + // Create new visual state + aVisualState = Handle(HYDROData_VisualState)::DownCast( doc()->CreateObject( KIND_VISUAL_STATE ) ); + if( aVisualState.IsNull() ) + return false; + + QString aName = HYDROGUI_Tool::GenerateObjectName( module(), "VisualState" ); + aVisualState->SetName( aName ); + } + + // Store parameters. + PropertyMap aPropertyMap; + + // A. Setting unique names for view windows in order to save this view inside + // workstack's structure (see below). On restore the views with the same names will + // be placed to the same place inside the workstack's splitters. + ViewManagerList aViewManagerList; + anApp->viewManagers( aViewManagerList ); + nameViewWindows( aViewManagerList ); + + // B. Store active window. + if( SUIT_ViewWindow* aViewWindow = anApp->desktop()->activeWindow() ) + setVisualProperty( aPropertyMap, "AP_ACTIVE_VIEW", aViewWindow->objectName() ); + + // C. Store view properties. + int aViewerId = 0; + QListIterator anIter( aViewManagerList ); + while( anIter.hasNext() ) + { + if( SUIT_ViewManager* aViewManager = anIter.next() ) + { + int aViewId = (int)aViewManager->getViewModel(); + if( SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView() ) + { + QString aType = aViewManager->getType(); + QString aViewerEntry = QString( "%1_%2" ).arg( aType ).arg( ++aViewerId ); + setVisualProperty( aPropertyMap, "AP_VIEWERS_LIST", aViewerEntry, true ); + + setVisualProperty( aPropertyMap, aViewerEntry, aViewWindow->windowTitle(), true ); + setVisualProperty( aPropertyMap, aViewerEntry, aViewWindow->getVisualParameters(), true ); + + // C1. Store parameters of presentations. + HYDROData_SequenceOfObjects aSeq; + if( aType == GraphicsView_Viewer::Type() ) + HYDROGUI_Tool::GetPrsSubObjects( module(), aSeq ); + + for( int anObjIndex = 1, aLength = aSeq.Length(); anObjIndex <= aLength; anObjIndex++ ) + { + Handle(HYDROData_Object) anObject = aSeq.Value( anObjIndex ); + if( !anObject.IsNull() ) + { + // Format: "Name|Visibility[|CoordX|CoordY]" + QString aParameters = anObject->GetName(); + + int aVisibility = (int)anObject->IsVisible( aViewId ); + aParameters.append( QString( "|%1" ).arg( aVisibility ) ); + + setVisualProperty( aPropertyMap, aViewerEntry, aParameters, true ); + } + } + } + } + } + + // D. Store split areas. + if( anApp->desktop()->inherits( "STD_TabDesktop" ) ) + { + QtxWorkstack* aWorkstack = ( (STD_TabDesktop*)anApp->desktop() )->workstack(); + QByteArray aWorkstackState = aWorkstack->saveState( 0 ); + QString aWorkstackInfo = aWorkstackState.toHex(); + setVisualProperty( aPropertyMap, "AP_WORKSTACK_INFO", aWorkstackInfo ); + } + + // E. Store module preferences. + //ouv: currently, nothing to do + + QString aState = encodePropertyMap( aPropertyMap ); + //printf( "--- SetState -----------\n" ); + //printf( "%s\n", qPrintable( aState ) ); + //printf( "------------------------\n" ); + aVisualState->SetState( aState ); + + module()->update( UF_Model ); + + return true; +} + +bool HYDROGUI_VisualStateOp::loadVisualState() +{ + LightApp_Application* anApp = module()->getApp(); + + Handle(HYDROData_VisualState) aVisualState = + Handle(HYDROData_VisualState)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if( aVisualState.IsNull() ) + return false; + + QString aState = aVisualState->GetState(); + //printf( "--- GetState -----------\n" ); + //printf( "%s\n", qPrintable( aState ) ); + //printf( "------------------------\n" ); + PropertyMap aPropertyMap = decodePropertyMap( aState ); + + // Restore parameters. + + // Preparation. Remove the existing viewers. + anApp->clearViewManagers(); + + // E. Restore module preferences + //ouv: currently, nothing to do + + // C. Restore view properties (step 1). + QMap aViewParameters; + int aNbViewers = nbVisualProperties( aPropertyMap, "AP_VIEWERS_LIST" ); + for( int anIndex = 0; anIndex < aNbViewers; anIndex++ ) + { + QString aViewerEntry = getVisualProperty( aPropertyMap, "AP_VIEWERS_LIST", anIndex ); + QString aType = aViewerEntry.section( '_', 0, -2 ); + QString aViewerId = aViewerEntry.section( '_', -1 ); // unused + if( SUIT_ViewManager* aViewManager = anApp->createViewManager( aType ) ) + { + int aViewId = (int)aViewManager->getViewModel(); + if( SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView() ) + { + // Wait until the window is really shown. This step fixes MANY bugs. + //while( !aViewManager->isVisible() ) + // qApp->processEvents(); + + int aNbViewerProps = nbVisualProperties( aPropertyMap, aViewerEntry ); + + aViewWindow->setWindowTitle( getVisualProperty( aPropertyMap, aViewerEntry, 0 ) ); + + // Parameters of view windows are restoring after the workstack (see below). + aViewParameters[ aViewWindow ] = getVisualProperty( aPropertyMap, aViewerEntry, 1 ); + + // C1. Restore parameters of presentations. + QMap< QString, QStringList > anObject2ParametersMap; + for( int aPropIndex1 = 2; aPropIndex1 < aNbViewerProps; aPropIndex1++ ) + { + QString aProperty = getVisualProperty( aPropertyMap, aViewerEntry, aPropIndex1 ); + QStringList aParameters = aProperty.split( "|" ); + if( aParameters.count() > 1 ) + { + QString aName = aParameters.front(); + aParameters.pop_front(); + anObject2ParametersMap[ aName ] = aParameters; + } + } + + HYDROData_SequenceOfObjects aSeq; + if( aType == GraphicsView_Viewer::Type() ) + HYDROGUI_Tool::GetPrsSubObjects( module(), aSeq ); + + for( int anObjIndex = 1, aLength = aSeq.Length(); anObjIndex <= aLength; anObjIndex++ ) + { + Handle(HYDROData_Object) anObject = aSeq.Value( anObjIndex ); + if( !anObject.IsNull() ) + { + QString aName = anObject->GetName(); + if( anObject2ParametersMap.find( aName ) != anObject2ParametersMap.end() ) + { + QStringList aParameters = anObject2ParametersMap[ aName ]; + int aParamCount = aParameters.count(); + QVector anIsOk( aParamCount, false ); + + int aParamIndex = -1; + if( aParamCount - aParamIndex - 1 >= 1 ) + { + bool anIsVisible = aParameters[ aParamIndex ].toInt( &anIsOk[ ++aParamIndex ] ); + if( anIsOk[ 0 ] ) + anObject->SetVisible( aViewId, anIsVisible ); + } + } + } + } + } + } + } + + // A. Setting unique names for view windows in order to restore positions of view windows inside + // workstack's structure (see below). During save the same naming algorithm was used, + // so the same views will get the same names. + ViewManagerList aViewManagerList; + anApp->viewManagers( aViewManagerList ); + nameViewWindows( aViewManagerList ); + + qApp->processEvents(); + + // D. Restore split areas. + QtxWorkstack* aWorkstack = 0; + if( anApp->desktop()->inherits( "STD_TabDesktop" ) ) + { + if( aWorkstack = ((STD_TabDesktop*)anApp->desktop())->workstack() ) + { + QString aWorkstackInfo = getVisualProperty( aPropertyMap, "AP_WORKSTACK_INFO" ); + QByteArray aWorkstackState = QByteArray::fromHex( aWorkstackInfo.toLatin1() ); + aWorkstack->restoreState( aWorkstackState, 0 ); + } + } + + qApp->processEvents(); + + // C. Restore view properties (step 2). + // B. Restore active window. (currently doesn't work) + QString anActiveViewName = getVisualProperty( aPropertyMap, "AP_ACTIVE_VIEW" ); + QMap::Iterator aMapIter; + for( aMapIter = aViewParameters.begin(); aMapIter != aViewParameters.end(); ++aMapIter ) + { + if( SUIT_ViewWindow* aViewWindow = aMapIter.key() ) + { + aViewWindow->setVisualParameters( aMapIter.value() ); + if( anActiveViewName == aViewWindow->objectName() ) + if( aWorkstack ) + aWorkstack->setActiveWindow( aViewWindow ); + } + } + + module()->update( UF_Viewer ); + + return true; +} + +void HYDROGUI_VisualStateOp::nameViewWindows( const ViewManagerList& theList ) +{ + QMap aViewersCounter; + for( ViewManagerList::const_iterator anIter = theList.begin(); anIter != theList.end(); ++anIter ) + { + SUIT_ViewManager* aViewManager = *anIter; + if( !aViewManager ) + continue; + + int aViewCount = aViewManager->getViewsCount(); + QString aType = aViewManager->getType(); + if( !aViewCount ) + continue; + + if( !aViewersCounter.contains( aType ) ) + aViewersCounter.insert( aType, 0 ); + + int& aViewerId = aViewersCounter[ aType ]; + + QVector aViews = aViewManager->getViews(); + for( int i = 0; i < aViewCount; i++ ) + { + QString aName = QString( "%1_%2_%3" ).arg( aType ).arg( aViewerId ).arg( i ); + aViews[i]->setObjectName( aName ); + } + aViewerId++; + } +} + +QString HYDROGUI_VisualStateOp::encodePropertyMap( const PropertyMap& thePropertyMap ) +{ + QStringList aPropertyDataStringList; + PropertyMapIterator anIter( thePropertyMap ); + while( anIter.hasNext() ) + { + QString aPropertyName = anIter.next().key(); + QStringList aPropertyData = anIter.value(); + + if( !aPropertyData.isEmpty() ) + { + aPropertyData.prepend( aPropertyName ); + QString aPropertyDataString = aPropertyData.join( "||" ); + aPropertyDataStringList.append( aPropertyDataString ); + } + } + + QString aResult = aPropertyDataStringList.join( "|||" ); + return aResult; +} + +HYDROGUI_VisualStateOp::PropertyMap +HYDROGUI_VisualStateOp::decodePropertyMap( const QString& theString ) +{ + PropertyMap aPropertyMap; + QStringList aPropertyDataStringList = theString.split( "|||" ); + QStringListIterator anIter( aPropertyDataStringList ); + while( anIter.hasNext() ) + { + QString aPropertyDataString = anIter.next(); + QStringList aPropertyData = aPropertyDataString.split( "||" ); + if( aPropertyData.count() >= 2 ) + { + QString aPropertyName = aPropertyData.front(); + aPropertyData.pop_front(); + aPropertyMap[ aPropertyName ] = aPropertyData; + } + } + return aPropertyMap; +} + +void HYDROGUI_VisualStateOp::setVisualProperty( PropertyMap& thePropertyMap, + const QString& thePropertyName, + const QString& thePropertyData, + const bool theIsAppend ) +{ + QStringList& aPropertyDataList = thePropertyMap[ thePropertyName ]; + if( !theIsAppend ) + aPropertyDataList.clear(); + aPropertyDataList.append( thePropertyData ); +} + +QString HYDROGUI_VisualStateOp::getVisualProperty( const PropertyMap& thePropertyMap, + const QString& thePropertyName, + int theIndex ) +{ + PropertyMap::const_iterator anIter = thePropertyMap.find( thePropertyName ); + if( anIter != thePropertyMap.end() ) + { + const QStringList aPropertyData = anIter.value(); + if( theIndex >= 0 && theIndex < aPropertyData.count() ) + return aPropertyData[ theIndex ]; + } + return QString(); +} + +int HYDROGUI_VisualStateOp::nbVisualProperties( const PropertyMap& thePropertyMap, + const QString& thePropertyName ) +{ + PropertyMap::const_iterator anIter = thePropertyMap.find( thePropertyName ); + if( anIter != thePropertyMap.end() ) + { + const QStringList aPropertyData = anIter.value(); + return aPropertyData.count(); + } + return 0; +} diff --git a/src/HYDROGUI/HYDROGUI_VisualStateOp.h b/src/HYDROGUI/HYDROGUI_VisualStateOp.h new file mode 100644 index 00000000..20385eea --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VisualStateOp.h @@ -0,0 +1,69 @@ +// 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_VISUALSTATEOP_H +#define HYDROGUI_VISUALSTATEOP_H + +#include "HYDROGUI_Operation.h" + +#include + +class HYDROGUI_VisualStateOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_VisualStateOp( HYDROGUI_Module* theModule, const bool theIsLoad ); + virtual ~HYDROGUI_VisualStateOp(); + +protected: + virtual void startOperation(); + +protected: + bool saveVisualState(); + bool loadVisualState(); + +private: + static void nameViewWindows( const ViewManagerList& lst ); + + typedef QMap < QString, QStringList > PropertyMap; + typedef QMapIterator< QString, QStringList > PropertyMapIterator; + static QString encodePropertyMap( const PropertyMap& thePropertyMap ); + static PropertyMap decodePropertyMap( const QString& theString ); + + static void setVisualProperty( PropertyMap& thePropertyMap, + const QString& thePropertyName, + const QString& thePropertyData, + const bool theIsAppend = false ); + + static QString getVisualProperty( const PropertyMap& thePropertyMap, + const QString& thePropertyName, + int theIndex = 0 ); + + static int nbVisualProperties( const PropertyMap& thePropertyMap, + const QString& thePropertyName ); + +private: + bool myIsLoad; +}; + +#endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 5c935637..75c0e659 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -171,6 +171,10 @@ DSK_IMPORT_IMAGE Import image + + DSK_LOAD_VISUAL_STATE + Load visual state + DSK_OBSERVE_IMAGE Observe image @@ -179,6 +183,10 @@ DSK_REDO Redo + + DSK_SAVE_VISUAL_STATE + Save visual state + DSK_SHOW Show @@ -243,6 +251,10 @@ MEN_IMPORT_IMAGE Import image + + MEN_LOAD_VISUAL_STATE + Load visual state + MEN_OBSERVE_IMAGE Observe image @@ -251,6 +263,10 @@ MEN_REDO Redo + + MEN_SAVE_VISUAL_STATE + Save visual state + MEN_SHOW Show @@ -307,6 +323,10 @@ STB_IMPORT_IMAGE Import image + + STB_LOAD_VISUAL_STATE + Load visual state + STB_OBSERVE_IMAGE Observe image @@ -315,6 +335,10 @@ STB_REDO Redo + + STB_SAVE_VISUAL_STATE + Save visual state + STB_SHOW Show @@ -373,6 +397,13 @@ Observe image + + HYDROGUI_PolylineDlg + + CURVE_NAME_TLT + Name + + HYDROGUI_TwoImagesDlg @@ -420,10 +451,14 @@ - HYDROGUI_PolylineDlg + HYDROGUI_VisualStateOp - CURVE_NAME_TLT - Name + LOAD_VISUAL_STATE + Load visual state + + + SAVE_VISUAL_STATE + Save visual state -- 2.39.2