Salome HOME
0021708: [CEA 586] Object browser sort only children:
authorakl <akl@opencascade.com>
Tue, 9 Jul 2013 08:32:08 +0000 (08:32 +0000)
committerakl <akl@opencascade.com>
Tue, 9 Jul 2013 08:32:08 +0000 (08:32 +0000)
+ Add Use Case browser data tree management
+ Add "Sort children" contextual menu popup item
+ Update user documentation

12 files changed:
doc/salome/gui/SMESH/images/smesh_sort.png [new file with mode: 0644]
doc/salome/gui/SMESH/input/arranging_study_objects_page.doc [new file with mode: 0644]
doc/salome/gui/SMESH/input/index.doc
idl/SMESH_Gen.idl
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI_Selection.cxx
src/SMESHGUI/SMESHGUI_Selection.h
src/SMESHGUI/SMESH_msg_en.ts
src/SMESHGUI/SMESH_msg_fr.ts
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx
src/SMESH_I/SMESH_Gen_i_1.cxx

diff --git a/doc/salome/gui/SMESH/images/smesh_sort.png b/doc/salome/gui/SMESH/images/smesh_sort.png
new file mode 100644 (file)
index 0000000..0b00568
Binary files /dev/null and b/doc/salome/gui/SMESH/images/smesh_sort.png differ
diff --git a/doc/salome/gui/SMESH/input/arranging_study_objects_page.doc b/doc/salome/gui/SMESH/input/arranging_study_objects_page.doc
new file mode 100644 (file)
index 0000000..ea655d5
--- /dev/null
@@ -0,0 +1,11 @@
+/*!
+
+\page arranging_study_objects_page Arranging objects in study
+
+If sub-meshes or groups container item has more than one child sub-object, then there is a possibility to sort these children in ascending order.
+
+To use sort functionality select "Sort children" popup menu item for the parent object.
+
+\image html smesh_sort.png "Sorting of sub-objects"
+
+*/
index 798237b4b2f77c7eb3ac60587c312fb661b027b4..917e540bdc56ed3327bbdcc7024d1ba9d0109ad3 100644 (file)
@@ -23,6 +23,9 @@ array of dedicated operations;</li>
 \subpage using_notebook_mesh_page "Salome notebook".</li>
 </ul>
 
 \subpage using_notebook_mesh_page "Salome notebook".</li>
 </ul>
 
+The possibility to sort the created sub-meshes or groups is detailed on
+\subpage arranging_study_objects_page section.
+
 Mesh module preferences are described in the \subpage mesh_preferences_page section of SALOME Mesh Help.
 
 Almost all mesh module functionalities are accessible via
 Mesh module preferences are described in the \subpage mesh_preferences_page section of SALOME Mesh Help.
 
 Almost all mesh module functionalities are accessible via
index fbe8a35d61517c704f8b6ac198805633aff7a8f7..aadfb1e33a99850be5213ce9da58e2fb8f12eee0 100644 (file)
@@ -36,6 +36,7 @@
 
 module SMESH
 {
 
 module SMESH
 {
+  typedef sequence<SALOMEDS::SObject> sobject_list;
   typedef sequence<GEOM::GEOM_Object> object_array;
   typedef sequence<SMESH_Mesh>        mesh_array;
 
   typedef sequence<GEOM::GEOM_Object> object_array;
   typedef sequence<SMESH_Mesh>        mesh_array;
 
@@ -402,6 +403,19 @@ module SMESH
      * \brief Get names of meshes defined in file with the specified name.
      */
     string_array GetMeshNames(in string theFileName);
      * \brief Get names of meshes defined in file with the specified name.
      */
     string_array GetMeshNames(in string theFileName);
+
+    /*!
+     * \brief Moves objects to the specified position
+     *
+     * This function is used in the drag-n-drop functionality.
+     *
+     * \param what objects being moved
+     * \param where parent object where objects are moved to
+     * \param row position in the parent object's children list at which objects are moved
+     */
+    void Move( in sobject_list what, 
+              in SALOMEDS::SObject where, 
+              in long row );
   };
 
 };
   };
 
 };
index 39062124719b80e8d201ddfb23b71cdfdc98a9dd..33de52b4dd998f5772ee063d60884091bc556595 100644 (file)
 #include <SALOMEDSClient_SComponent.hxx>
 #include <SALOMEDSClient_StudyBuilder.hxx>
 #include <SALOMEDS_Study.hxx>
 #include <SALOMEDSClient_SComponent.hxx>
 #include <SALOMEDSClient_StudyBuilder.hxx>
 #include <SALOMEDS_Study.hxx>
+#include <SALOMEDS_SObject.hxx>
 
 // OCCT includes
 #include <Standard_ErrorHandler.hxx>
 
 // OCCT includes
 #include <Standard_ErrorHandler.hxx>
     }
   }
 
     }
   }
 
+  void sortChildren(){
+    LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+    SALOME_ListIO selected;
+    if( aSel ) {
+      aSel->selectedObjects( selected );
+      
+      if(selected.Extent()){
+       Handle(SALOME_InteractiveObject) anIObject = selected.First();
+       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+       _PTR(SObject) aSObj = aStudy->FindObjectID(anIObject->getEntry());
+       if (aSObj) {
+         if ( aStudy->GetUseCaseBuilder()->SortChildren( aSObj, true/*AscendingOrder*/ ) ) {
+           SMESHGUI::GetSMESHGUI()->updateObjBrowser();
+         }
+       }
+      }
+    }
+  }
+
   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap)
   {
     SALOME_ListIO selected;
   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap)
   {
     SALOME_ListIO selected;
@@ -3533,6 +3553,10 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       dlg->show();
       break;
     }
       dlg->show();
       break;
     }
+  case 41:
+    ::sortChildren();
+    break;
+
   }
 
   anApp->updateActions(); //SRN: To update a Save button in the toolbar
   }
 
   anApp->updateActions(); //SRN: To update a Save button in the toolbar
@@ -3830,6 +3854,8 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( 301, "SHOW" );
   createSMESHAction( 302, "DISPLAY_ONLY" );
 
   createSMESHAction( 301, "SHOW" );
   createSMESHAction( 302, "DISPLAY_ONLY" );
 
+  createSMESHAction( 41, "SORT_CHILD_ITEMS" );
+
   // ----- create menu --------------
   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
   // ----- create menu --------------
   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
@@ -4512,6 +4538,10 @@ void SMESHGUI::initialize( CAM_Application* app )
 
   popupMgr()->insert( separator(), -1, -1 );
 
 
   popupMgr()->insert( separator(), -1, -1 );
 
+  popupMgr()->insert( action( 41 ), -1, -1 );
+  popupMgr()->setRule( action( 41 ), "$component={'SMESH'} and client='ObjectBrowser' and isContainer and nbChildren>1", QtxPopupMgr::VisibleRule );
+  popupMgr()->insert( separator(), -1, -1 );
+
   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
 
   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
 
index 4b8c433f9e70f6ee3d5a13740e6bc9d900b8f324..86a9292141693bf30ae063814bd47c386ffec12d 100644 (file)
@@ -127,6 +127,9 @@ QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
   else if ( p=="groupType" )     val = QVariant( groupType( ind ) );
   else if ( p=="quadratic2DMode") val =  QVariant(quadratic2DMode(ind));
   else if ( p=="isDistributionVisible") val = QVariant(isDistributionVisible(ind));
   else if ( p=="groupType" )     val = QVariant( groupType( ind ) );
   else if ( p=="quadratic2DMode") val =  QVariant(quadratic2DMode(ind));
   else if ( p=="isDistributionVisible") val = QVariant(isDistributionVisible(ind));
+  else if ( p=="hasChildren") val = QVariant(hasChildren(ind));
+  else if ( p=="nbChildren") val = QVariant(nbChildren(ind));
+  else if ( p=="isContainer") val = QVariant(isContainer(ind));
 
   if( val.isValid() )
     return val;
 
   if( val.isValid() )
     return val;
@@ -529,6 +532,50 @@ QVariant SMESHGUI_Selection::isVisible( int ind ) const
   return QVariant( false );
 }
 
   return QVariant( false );
 }
 
+//=======================================================================
+//function : hasChildren
+//purpose  : 
+//=======================================================================
+
+bool SMESHGUI_Selection::hasChildren( int ind ) const
+{
+  if ( ind >= 0 )
+  {
+    _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
+    return SMESH::GetActiveStudyDocument()->GetUseCaseBuilder()->HasChildren( sobj );
+  }
+  return false;
+}
+
+//=======================================================================
+//function : hasChildren
+//purpose  : 
+//=======================================================================
+
+int SMESHGUI_Selection::nbChildren( int ind ) const
+{
+  int nb = 0;
+  if ( ind >= 0 )
+  {
+    _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
+    if ( sobj->GetStudy()->GetUseCaseBuilder()->IsUseCaseNode( sobj ) ) {
+      _PTR(UseCaseIterator) it = sobj->GetStudy()->GetUseCaseBuilder()->GetUseCaseIterator( sobj ); 
+      for (it->Init(false); it->More(); it->Next()) nb++;
+    }
+  }
+  return nb;
+}
+
+//=======================================================================
+//function : isContainer
+//purpose  : 
+//=======================================================================
+
+bool SMESHGUI_Selection::isContainer( int ind ) const
+{
+  return ind >= 0 && ind < myTypes.count() && myTypes[ind] == "Unknown";
+}
+
 //=======================================================================
 //function : type
 //purpose  : 
 //=======================================================================
 //function : type
 //purpose  : 
index 4358bab072531f67bdd4658cf4609952818710a0..5f2a50bdb7f0d94860e0920f730f89ef39606e4d 100644 (file)
@@ -63,6 +63,9 @@ public:
   virtual QString         quadratic2DMode(int ) const;
 
   virtual bool            isDistributionVisible(int ) const;
   virtual QString         quadratic2DMode(int ) const;
 
   virtual bool            isDistributionVisible(int ) const;
+  virtual bool            hasChildren( int ) const;
+  virtual int             nbChildren( int ) const;
+  virtual bool            isContainer( int ) const;
 
   // parameters got from actor return nothing if an actor is not visible
   virtual QList<QVariant> elemTypes( int ) const;
 
   // parameters got from actor return nothing if an actor is not visible
   virtual QList<QVariant> elemTypes( int ) const;
index 6fd576050eaaf007441d1c08b79dec7b652bf8e0..6a8b6750f79bd7df7514a1a40bc7ef83e70b5a23 100644 (file)
@@ -4114,6 +4114,14 @@ It can&apos;t be deleted </translation>
         <source>SMESH_GIGABYTE</source>
         <translation>%1 GB</translation>
     </message>
         <source>SMESH_GIGABYTE</source>
         <translation>%1 GB</translation>
     </message>
+    <message>
+        <source>MEN_SORT_CHILD_ITEMS</source>
+        <translation>Sort children</translation>
+    </message>
+    <message>
+        <source>STB_SORT_CHILD_ITEMS</source>
+        <translation>Sort child items</translation>
+    </message>
 </context>
 <context>
     <name>SMESHGUI_Dialog</name>
 </context>
 <context>
     <name>SMESHGUI_Dialog</name>
index 65e5bb7b576c9cb5c4228d36402de5abccb2f5ed..7423e43ea0dd273b6786a099c2510b34fe630fff 100755 (executable)
@@ -4114,6 +4114,14 @@ avec le paramètre &apos;%1&apos; des préférences du module Mesh.</translation
         <translation>L&apos;objet sélectionné a été utilisé pour en créer un autre.
 Il ne peut pas être supprimé.</translation>
     </message>
         <translation>L&apos;objet sélectionné a été utilisé pour en créer un autre.
 Il ne peut pas être supprimé.</translation>
     </message>
+    <message>
+        <source>MEN_SORT_CHILD_ITEMS</source>
+        <translation type="unfinished">Sort children</translation>
+    </message>
+    <message>
+        <source>STB_SORT_CHILD_ITEMS</source>
+        <translation type="unfinished">Sort child items</translation>
+    </message>
 </context>
 <context>
     <name>SMESHGUI_Dialog</name>
 </context>
 <context>
     <name>SMESHGUI_Dialog</name>
index f710776b60b4284327017e87d4f1287c8094d4b4..f393b918c14440ff20c797f6275de355ede1bd92 100644 (file)
@@ -4790,6 +4790,18 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
   }
   pd << ""; // prevent optimizing pd out
 
   }
   pd << ""; // prevent optimizing pd out
 
+  // creation of tree nodes for all data objects in the study
+  // to support tree representation customization and drag-n-drop:
+  SALOMEDS::UseCaseBuilder_var useCaseBuilder = theComponent->GetStudy()->GetUseCaseBuilder();
+  if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
+    useCaseBuilder->SetRootCurrent();
+    useCaseBuilder->Append( theComponent ); // component object is added as the top level item
+    SALOMEDS::ChildIterator_var it = theComponent->GetStudy()->NewChildIterator( theComponent ); 
+    for (it->InitEx(true); it->More(); it->Next()) {
+      useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
+    }
+  }
+
   INFOS( "SMESH_Gen_i::Load completed" );
   return true;
 }
   INFOS( "SMESH_Gen_i::Load completed" );
   return true;
 }
@@ -4997,6 +5009,46 @@ char* SMESH_Gen_i::getVersion()
 #endif
 }
 
 #endif
 }
 
+//=================================================================================
+// function : Move()
+// purpose  : Moves objects to the specified position. 
+//            Is used in the drag-n-drop functionality.
+//=================================================================================
+void SMESH_Gen_i::Move( const SMESH::sobject_list& what,
+                       SALOMEDS::SObject_ptr where,
+                       CORBA::Long row )
+{
+  if ( CORBA::is_nil( where ) ) return;
+
+  SALOMEDS::Study_var study = where->GetStudy();
+  SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
+  SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
+  SALOMEDS::SComponent_var father = where->GetFatherComponent();
+  std::string dataType = father->ComponentDataType();
+  if ( dataType != "SMESH" ) return; // not a SMESH component
+  
+  SALOMEDS::SObject_var objAfter;
+  if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
+    // insert at given row -> find insertion position
+    SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
+    int i;
+    for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
+    if ( i == row && useCaseIt->More() ) {
+      objAfter = useCaseIt->Value();
+    }
+  }
+  
+  for ( int i = 0; i < what.length(); i++ ) {
+    SALOMEDS::SObject_var sobj = what[i];
+    if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
+    // insert the object to the use case tree
+    if ( !CORBA::is_nil( objAfter ) )
+      useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
+    else
+      useCaseBuilder->AppendTo( where, sobj );        // append to the end of list
+  }
+}
+
 //=============================================================================
 /*!
  *  SMESHEngine_factory
 //=============================================================================
 /*!
  *  SMESHEngine_factory
index bbd544fabf3334b7d708ae85d9d4d0da325050e0..403fb7ee5cc25e12c4bc7f57e01a7066cd7b943f 100644 (file)
@@ -585,6 +585,11 @@ public:
   const std::string &               GetLastObjEntry() const { return myLastObj; }
   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
 
   const std::string &               GetLastObjEntry() const { return myLastObj; }
   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
 
+  // Move objects to the specified position
+  void Move( const SMESH::sobject_list& what,
+            SALOMEDS::SObject_ptr where,
+            CORBA::Long row );
+
 private:
   // Create hypothesis of given type
   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
 private:
   // Create hypothesis of given type
   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
index 4ac7ad8d3e6fe9d878dd5b06091924abf34d47a0..fc50bc409a4e4a2de0110a1ca00be527c6dbab38 100644 (file)
@@ -261,6 +261,7 @@ static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr   theStudy,
 {
   SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
 {
   SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
+  SALOMEDS::UseCaseBuilder_var useCaseBuilder = theStudy->GetUseCaseBuilder();
   if ( SO->_is_nil() ) {
     if ( theTag == 0 )
       SO = aStudyBuilder->NewObject( theFatherObject );
   if ( SO->_is_nil() ) {
     if ( theTag == 0 )
       SO = aStudyBuilder->NewObject( theFatherObject );
@@ -286,6 +287,10 @@ static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr   theStudy,
     selAttr->SetSelectable( false );
   }
 
     selAttr->SetSelectable( false );
   }
 
+  // add object to the use case tree
+  // (to support tree representation customization and drag-n-drop)
+  useCaseBuilder->AppendTo( SO->GetFather(), SO );
+
   return SO._retn();
 }
 
   return SO._retn();
 }
 
@@ -377,6 +382,9 @@ static void addReference (SALOMEDS::Study_ptr   theStudy,
     if ( !theSObject->FindSubObject( theTag, aReferenceSO.inout() ))
       aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
     aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
     if ( !theSObject->FindSubObject( theTag, aReferenceSO.inout() ))
       aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
     aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
+    // add reference to the use case tree
+    // (to support tree representation customization and drag-n-drop)
+    theStudy->GetUseCaseBuilder()->AppendTo( aReferenceSO->GetFather(), aReferenceSO );
   }
 }
 
   }
 }
 
@@ -456,6 +464,7 @@ SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theSt
     return father._retn();
 
   SALOMEDS::StudyBuilder_var      aStudyBuilder = theStudy->NewBuilder(); 
     return father._retn();
 
   SALOMEDS::StudyBuilder_var      aStudyBuilder = theStudy->NewBuilder(); 
+  SALOMEDS::UseCaseBuilder_var    useCaseBuilder = theStudy->GetUseCaseBuilder();
   SALOMEDS::GenericAttribute_wrap anAttr;
   SALOMEDS::AttributePixMap_wrap  aPixmap;
 
   SALOMEDS::GenericAttribute_wrap anAttr;
   SALOMEDS::AttributePixMap_wrap  aPixmap;
 
@@ -466,6 +475,10 @@ SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theSt
   aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
   CORBA::String_var userName = aComp->componentusername();
   SetName( father, userName.in(), "MESH" );
   aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
   CORBA::String_var userName = aComp->componentusername();
   SetName( father, userName.in(), "MESH" );
+  // add component to the use case tree
+  // (to support tree representation customization and drag-n-drop)
+  useCaseBuilder->SetRootCurrent();
+  useCaseBuilder->Append( father ); // component object is added as the top level item
   if(MYDEBUG) MESSAGE("PublishComponent--END");
 
   return father._retn();
   if(MYDEBUG) MESSAGE("PublishComponent--END");
 
   return father._retn();