]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
1) Improved visibility management
authorouv <ouv@opencascade.com>
Mon, 26 Aug 2013 10:25:35 +0000 (10:25 +0000)
committerouv <ouv@opencascade.com>
Mon, 26 Aug 2013 10:25:35 +0000 (10:25 +0000)
2) Save/load visual state

25 files changed:
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_Image.cxx
src/HYDROData/HYDROData_Image.h
src/HYDROData/HYDROData_Iterator.cxx
src/HYDROData/HYDROData_Object.cxx
src/HYDROData/HYDROData_Object.h
src/HYDROData/HYDROData_Polyline.cxx
src/HYDROData/HYDROData_Polyline.h
src/HYDROData/HYDROData_VisualState.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_VisualState.h [new file with mode: 0644]
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_Displayer.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/HYDROGUI_PolylineOp.cxx
src/HYDROGUI/HYDROGUI_ShowHideOp.cxx
src/HYDROGUI/HYDROGUI_Tool.cxx
src/HYDROGUI/HYDROGUI_Tool.h
src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx
src/HYDROGUI/HYDROGUI_VisualStateOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_VisualStateOp.h [new file with mode: 0644]
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index bf28f0d0feb3fbf3f452715436fe4ce496145bab..c53839201c6d534d069659c6a50303613f73fb96 100644 (file)
@@ -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(
index 8fe96f68b8d00d6e1104ca53b691ff9ba1181f85..a41cc26415820521fa13192f7b5471a25bdacd61 100644 (file)
@@ -9,12 +9,6 @@
 #include <TDataStd_UAttribute.hxx>
 #include <TDF_ListIteratorOfLabelList.hxx>
 
-// 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);
index dda1648b3ab7cbdf34f308c852c18357a0a6bd12..e2df2a4e2465363e8de8c381e593452dd282df4b 100644 (file)
@@ -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);
 
index da22e5ebf0d41eb246e0869e667e8432d2caca77..95a70708b9a8c8531b4b3821d771e99fb1581d48 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <HYDROData_Image.h>
 #include <HYDROData_Polyline.h>
+#include <HYDROData_VisualState.h>
 
 #include <TDataStd_Name.hxx>
 #include <NCollection_DataMap.hxx>
@@ -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);
index fe71e385569bfe734eb73ea5afe2c925ca650543..00158bbe4609228dca0620e4dd086df1d8ef3d08 100644 (file)
@@ -3,10 +3,11 @@
 #include <TDataStd_Name.hxx>
 #include <TDataStd_ByteArray.hxx>
 #include <TDataStd_UAttribute.hxx>
+#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_BooleanArray.hxx>
+#include <TDataStd_RealArray.hxx>
 #include <TDF_CopyLabel.hxx>
 
-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++;
+  }
+}
index f4b30d7076e29afafa161007657ad784a910b28d..993297ad76778812ca1343d005e611208f6ef2eb 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <NCollection_Sequence.hxx>
 #include <TDF_Label.hxx>
+#include <QMap>
 #include <QString>
 
 ///! 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
index 294f0e988e0e20b673786b8eea732d591b53825a..34ebfe25c64a5a22658195e83d5c3b5f85e6092d 100755 (executable)
 // 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<PolylineSection>& 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<PolylineSection> HYDROData_Polyline::getPolylineData()
   int aSectCnt;
   QList<PolylineSection> 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<PolylineSection> 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<PolylineSection> 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<PolylineSection> 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<PolylineSection> 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());
index a75650479eb774fbe191740b662314ffb64dd495..73a06a53e06ead800b484a1b04d2e31d54ee4334 100755 (executable)
@@ -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 (file)
index 0000000..e3e0641
--- /dev/null
@@ -0,0 +1,32 @@
+#include <HYDROData_VisualState.h>
+
+#include <TDataStd_AsciiString.hxx>
+
+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 (file)
index 0000000..6a53c44
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef HYDROData_VisualState_HeaderFile
+#define HYDROData_VisualState_HeaderFile
+
+#include <HYDROData_Object.h>
+
+#include <QString>
+
+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
index 5231ebb93b06e6c1857444a13c279b9b75648cc3..6225c6ef9484a113825484de11dc71c93e6e9f71 100644 (file)
@@ -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(
index abcc62743d6b4bc4045b06f76bfa6453acc5ecaa..63a65988236d2b226aae0af598d2a9fc2791bccf 100644 (file)
@@ -30,6 +30,7 @@
 #include <HYDROData_Image.h>
 #include <HYDROData_Iterator.h>
 #include <HYDROData_Polyline.h>
+#include <HYDROData_VisualState.h>
 
 #include <CAM_Application.h>
 #include <CAM_DataObject.h>
@@ -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 );
index 7a254ac8b191a4460bd0881d5ea345486a774703..bb22802118e0abbfb2d39b6e963a3b9fb5cca4bf 100644 (file)
@@ -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 );
     }
   }
index 0baa3d6fd95c36a582be980464013bde95271afb..2b76bdb3af656030b0a2e8386ce1ad5aeda92d99 100644 (file)
@@ -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;
index 9b13d845d165a2d23caab1db3e8ae04ad8be5e86..4dd19fe07a0b966ee57c0da1f70d8b4c73f3c29d 100644 (file)
@@ -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();
index e173c54b1538d7bd9b5070ab6c79191ba21c6b24..a2b8286435eba691739d85c310e00f91eb00ea8a 100644 (file)
@@ -32,6 +32,7 @@
 #include "HYDROGUI_ShowHideOp.h"
 #include "HYDROGUI_TwoImagesOp.h"
 #include "HYDROGUI_UpdateFlags.h"
+#include "HYDROGUI_VisualStateOp.h"
 
 #include <CAM_Application.h>
 
@@ -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<HYDROGUI_Module*>( 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 );
index d8a2b9e8f0e311fd660f217b4992c73420e946d1..7c835e50550b97a484deabf0d5bd678fa21bc240 100644 (file)
@@ -26,6 +26,8 @@
 enum OperationId
 {
   FirstId = 0,
+  SaveVisualStateId,
+  LoadVisualStateId,
   UndoId,
   RedoId,
   ImportImageId,
index 3e9d21a69e74db413b28bcc0a2b0dae200541f9b..636b624965117524174933d866a63df507269fa9 100755 (executable)
@@ -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;
 }
 
index 305af96e234f9eebc50c7951f09e45a2df0bacf5..4fa7c8a30ac2f6cfd99d8ec5a0a6f75c6bff7b1d 100644 (file)
@@ -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 );
     }
   }
 
index 0a942119126c98e14d6a8c02e402cbafd70a6e83..39b6bb97dcbed1f0dbe1a38023ca1a3238b99643 100644 (file)
@@ -29,6 +29,8 @@
 #include <HYDROData_Document.h>
 #include <HYDROData_Iterator.h>
 
+#include <GraphicsView_Viewer.h>
+
 #include <LightApp_Application.h>
 #include <LightApp_DataOwner.h>
 #include <LightApp_SelectionMgr.h>
@@ -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<int> HYDROGUI_Tool::GetGraphicsViewIdList( HYDROGUI_Module* theModule )
+{
+  QList<int> aList;
+  ViewManagerList aViewMgrs;
+  theModule->getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewMgrs );
+  QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
+  while( anIter.hasNext() )
+  {
+    if( SUIT_ViewManager* aViewMgr = anIter.next() )
+    {
+      if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
+        aList.append( (int)aViewer );
+    }
+  }
+  return aList;
+}
index 1af2f5d71912bb47167631692db11fd9fecb81be..e67274fc5dc09200352e7b807aeef3160590381f 100644 (file)
@@ -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<int>               GetGraphicsViewIdList( HYDROGUI_Module* theModule );
 };
 
 #endif
index 38da834fa3d50f83e4e9396c5a3b44969643406d..6a4268c6119f0c7e1c1c1a798978b2ab23c11262 100644 (file)
@@ -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 (file)
index 0000000..326b5ab
--- /dev/null
@@ -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 <HYDROData_Document.h>
+#include <HYDROData_VisualState.h>
+
+#include <GraphicsView_Viewer.h>
+
+#include <LightApp_Application.h>
+
+#include <QtxWorkstack.h>
+
+#include <STD_TabDesktop.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_ViewManager.h>
+#include <SUIT_ViewWindow.h>
+
+#include <QApplication.h>
+
+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<SUIT_ViewManager*> 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<SUIT_ViewWindow*, QString> 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<bool> 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<SUIT_ViewWindow*, QString>::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<QString, int> 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<SUIT_ViewWindow*> 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 (file)
index 0000000..20385ee
--- /dev/null
@@ -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 <STD_Application.h>
+
+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
index 5c935637c493616184f170ca52d32d37d36817ec..75c0e659fb5fc3ab0d1ea0ba8d97539c876adccf 100644 (file)
       <source>DSK_IMPORT_IMAGE</source>
       <translation>Import image</translation>
     </message>
+    <message>
+      <source>DSK_LOAD_VISUAL_STATE</source>
+      <translation>Load visual state</translation>
+    </message>
     <message>
       <source>DSK_OBSERVE_IMAGE</source>
       <translation>Observe image</translation>
       <source>DSK_REDO</source>
       <translation>Redo</translation>
     </message>
+    <message>
+      <source>DSK_SAVE_VISUAL_STATE</source>
+      <translation>Save visual state</translation>
+    </message>
     <message>
       <source>DSK_SHOW</source>
       <translation>Show</translation>
       <source>MEN_IMPORT_IMAGE</source>
       <translation>Import image</translation>
     </message>
+    <message>
+      <source>MEN_LOAD_VISUAL_STATE</source>
+      <translation>Load visual state</translation>
+    </message>
     <message>
       <source>MEN_OBSERVE_IMAGE</source>
       <translation>Observe image</translation>
       <source>MEN_REDO</source>
       <translation>Redo</translation>
     </message>
+    <message>
+      <source>MEN_SAVE_VISUAL_STATE</source>
+      <translation>Save visual state</translation>
+    </message>
     <message>
       <source>MEN_SHOW</source>
       <translation>Show</translation>
       <source>STB_IMPORT_IMAGE</source>
       <translation>Import image</translation>
     </message>
+    <message>
+      <source>STB_LOAD_VISUAL_STATE</source>
+      <translation>Load visual state</translation>
+    </message>
     <message>
       <source>STB_OBSERVE_IMAGE</source>
       <translation>Observe image</translation>
       <source>STB_REDO</source>
       <translation>Redo</translation>
     </message>
+    <message>
+      <source>STB_SAVE_VISUAL_STATE</source>
+      <translation>Save visual state</translation>
+    </message>
     <message>
       <source>STB_SHOW</source>
       <translation>Show</translation>
       <translation>Observe image</translation>
     </message>
   </context>
+  <context>
+    <name>HYDROGUI_PolylineDlg</name>
+    <message>
+      <source>CURVE_NAME_TLT</source>
+      <translation>Name</translation>
+    </message>
+  </context>
   <context>
     <name>HYDROGUI_TwoImagesDlg</name>
     <message>
     </message>
   </context>
   <context>
-    <name>HYDROGUI_PolylineDlg</name>
+    <name>HYDROGUI_VisualStateOp</name>
     <message>
-      <source>CURVE_NAME_TLT</source>
-      <translation>Name</translation>
+      <source>LOAD_VISUAL_STATE</source>
+      <translation>Load visual state</translation>
+    </message>
+    <message>
+      <source>SAVE_VISUAL_STATE</source>
+      <translation>Save visual state</translation>
     </message>
   </context>
 </TS>