]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Publishing the reference objects.
authorouv <ouv@opencascade.com>
Mon, 2 Sep 2013 12:21:39 +0000 (12:21 +0000)
committerouv <ouv@opencascade.com>
Mon, 2 Sep 2013 12:21:39 +0000 (12:21 +0000)
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_DataModel.h
src/HYDROGUI/HYDROGUI_DataObject.cxx
src/HYDROGUI/HYDROGUI_DataObject.h
src/HYDROGUI/HYDROGUI_Tool.cxx

index 1c8368ffaf5d37f99c03aeb4cd531f6065a0d6b2..798cf88ed181a2ca635233e75e260fc7e699509d 100644 (file)
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
 
+#include <HYDROData_Bathymetry.h>
 #include <HYDROData_Document.h>
 #include <HYDROData_Image.h>
 #include <HYDROData_Iterator.h>
 #include <HYDROData_Polyline.h>
 #include <HYDROData_VisualState.h>
-#include <HYDROData_Bathymetry.h>
 
 #include <CAM_Application.h>
 #include <CAM_DataObject.h>
@@ -194,7 +194,17 @@ void HYDROGUI_DataModel::update( const int theStudyId )
     Handle(HYDROData_Image) anImageObj =
       Handle(HYDROData_Image)::DownCast( anIterator.Current() );
     if( !anImageObj.IsNull() )
-      createObject( anImageRootObj, anImageObj );
+    {
+      if( LightApp_DataObject* anImageDataObj = createObject( anImageRootObj, anImageObj ) )
+      {
+        for( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
+        {
+          Handle(HYDROData_Image) aRefImageObj = anImageObj->Reference( anIndex );
+          if( !aRefImageObj.IsNull() && !aRefImageObj->IsRemoved() )
+            createObject( anImageDataObj, aRefImageObj, anImageDataObj->entry() );
+        }
+      }
+    }
   }
 
   LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, "BATHYMETRIES" );
@@ -279,6 +289,10 @@ void HYDROGUI_DataModel::updateModel()
 Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
                                                             const ObjectKind theObjectKind )
 {
+  QString anEntry = theEntry;
+  if( anEntry.indexOf( "_" ) != -1 ) // reference object
+    anEntry = anEntry.section( "_", -1 );
+
   Handle(HYDROData_Document) aDocument = getDocument();
   if( !aDocument.IsNull() )
   {
@@ -288,8 +302,8 @@ Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEn
       Handle(HYDROData_Object) anObject = anIterator.Current();
       if( !anObject.IsNull() )
       {
-        QString anEntry = HYDROGUI_DataObject::dataObjectEntry( anObject );
-        if( anEntry == theEntry )
+        QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
+        if( anEntryRef == anEntry )
           return anObject;
       }
     }
@@ -366,9 +380,10 @@ Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
 }
 
 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
-                                                       Handle(HYDROData_Object) theModelObject )
+                                                       Handle(HYDROData_Object) theModelObject,
+                                                       const QString& theParentEntry )
 {
-  return new HYDROGUI_DataObject( theParent, theModelObject );
+  return new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
 }
 
 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
index eb6f374f65b4757967af4953fc84425aadb55d01..a0e597647d9a4d902bb3a16932f669e6c6e069d9 100644 (file)
@@ -194,7 +194,8 @@ protected:
    * \param theObject model object
    */
   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
-                                     Handle(HYDROData_Object) theModelObject );
+                                     Handle(HYDROData_Object) theModelObject,
+                                     const QString& theParentEntry = QString() );
 
   /**
    * Creates the GUI data object without corresponding model object: just by name
index fd4638a92a5a364fa12600ce21f4d510ced88fa6..c760d195a9ef14140f5e264844d2631dcc1a953d 100644 (file)
 #include <TDF_Tool.hxx>
 
 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, 
-                                          Handle(HYDROData_Object) theData )
+                                          Handle(HYDROData_Object) theData,
+                                          const QString& theParentEntry )
 : CAM_DataObject( theParent ),
   LightApp_DataObject( theParent ),
-  myData( theData )
+  myData( theData ),
+  myParentEntry( theParentEntry )
 {
 }
 
 QString HYDROGUI_DataObject::entry() const
 {
-  return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
+  QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
+  if( isReference() )
+    anEntry.prepend( myParentEntry + "_" );
+  return anEntry;
+}
+
+QString HYDROGUI_DataObject::refEntry() const
+{
+  if( !myParentEntry.isEmpty() )
+    return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
+  return QString();
 }
 
 QString HYDROGUI_DataObject::name() const
index cad33c21f52db026d1538411557e3b06322a3c23..33b53a36a8914b97a74ee413828d788b9ea1afb8 100644 (file)
@@ -47,15 +47,22 @@ public:
    * Constructor.
    * \param theParent parent data object
    * \param theData reference to the corresponding object from data structure
+   * \param theParentEntry entry of the parent data object (for reference objects)
    */
   HYDROGUI_DataObject( SUIT_DataObject* theParent,
-                       Handle(HYDROData_Object) theData );
+                       Handle(HYDROData_Object) theData,
+                       const QString& theParentEntry );
     
   /**
    * Returns the unique object identifier string.
    */
   virtual QString entry() const;
 
+  /**
+   * Returns the entry of the referenced object.
+   */
+  virtual QString refEntry() const;
+
   /**
    * Returns the name of object.
    */
@@ -74,7 +81,7 @@ public:
   /**
    * Returns the entry prefix for all HYDRO data objects.
    */
-  static QString entryPrefix() { return QString( "HYDRO_" ); }
+  static QString entryPrefix() { return QString( "HYDRO:" ); }
 
   /**
    * Returns the full entry for the specified data object.
@@ -83,6 +90,7 @@ public:
 
 protected:
   Handle(HYDROData_Object) myData; ///< object from data model
+  QString myParentEntry;
 };
 
 /**
index b30f5ec8372fe6bc91e4fbfde74ee7ac99246193..5aeadb6178fd74df3e50021d8317ca55c17379f8 100644 (file)
@@ -236,13 +236,21 @@ HYDROData_SequenceOfObjects HYDROGUI_Tool::GetSelectedObjects( HYDROGUI_Module*
   SUIT_DataOwnerPtrList anOwners;
   aSelectionMgr->selected( anOwners );
 
+  QStringList aCollectedNameList; // to avoid duplication
   foreach( SUIT_DataOwner* aSUITOwner, anOwners )
   {
     if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
     {
-      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry(), KIND_UNKNOWN );
+      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() );
       if( !anObject.IsNull() )
-        aSeq.Append( anObject );
+      {
+        QString aName = anObject->GetName();
+        if( !aCollectedNameList.contains( aName ) )
+        {
+          aSeq.Append( anObject );
+          aCollectedNameList.append( aName );
+        }
+      }
     }
   }
   return aSeq;