]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
0021708: [CEA 586] Object browser sort only children:
authorakl <akl@opencascade.com>
Tue, 9 Jul 2013 08:22:16 +0000 (08:22 +0000)
committerakl <akl@opencascade.com>
Tue, 9 Jul 2013 08:22:16 +0000 (08:22 +0000)
+ Add Use Case browser data tree management
+ Add "Sort children" contextual menu popup item
+ Update user documentation

doc/salome/gui/GEOM/images/geom_sort.png [new file with mode: 0644]
doc/salome/gui/GEOM/input/arranging_study_objects_page.doc
src/GEOMGUI/GEOMGUI_Selection.cxx
src/GEOMGUI/GEOMGUI_Selection.h
src/GEOMGUI/GEOM_msg_en.ts
src/GEOMGUI/GEOM_msg_fr.ts
src/GEOMGUI/GeometryGUI.cxx
src/GEOMGUI/GeometryGUI_Operations.h
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOMToolsGUI/GEOMToolsGUI.h
src/GEOMToolsGUI/GEOMToolsGUI_1.cxx

diff --git a/doc/salome/gui/GEOM/images/geom_sort.png b/doc/salome/gui/GEOM/images/geom_sort.png
new file mode 100644 (file)
index 0000000..7324f62
Binary files /dev/null and b/doc/salome/gui/GEOM/images/geom_sort.png differ
index 44df8f830e1242b3320fc641a4738f6092abe6b0..aeeec8bb4778d9179d470aff14e04ecc33e0bf0f 100644 (file)
@@ -20,6 +20,10 @@ To create a folder select "Create folder" popup menu item for root "Geometry" ob
 <li> folder(s)
 </ul>
 
+If geometrical object 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 geom_sort.png "Sorting of sub-objects"
+
 Our <b>TUI Scripts</b> provide you with useful examples of 
 \ref tui_arranging_study_objects "Arranging objects in study".
 
index fdf8f84512c9095cef7cd053218f3e1391d7bab9..c090dbbd9061aa782d9cd733aa54af35c4d9ea81 100644 (file)
@@ -161,6 +161,8 @@ QVariant GEOMGUI_Selection::parameter( const int idx, const QString& p ) const
     v = topLevel( idx );
   else if ( p == "hasChildren" )
     v = hasChildren( idx );
+  else if ( p == "nbChildren" )
+    v = nbChildren(idx);
   else if ( p == "hasConcealedChildren" )
     v = hasConcealedChildren( idx );
   else if ( p == "hasDisclosedChildren" )
@@ -399,19 +401,8 @@ bool GEOMGUI_Selection::isVectorsMode( const int index ) const
 
 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
 {
-  bool ok = false;
-  if ( obj ) {
-    _PTR(ChildIterator) it ( obj->GetStudy()->NewChildIterator( obj ) );
-    for ( ; it->More() && !ok; it->Next() ) {
-      _PTR(SObject) child = it->Value();
-      if ( child ) {
-        _PTR(SObject) refObj;
-        if ( child->ReferencedObject( refObj ) ) continue; // omit references
-        if ( child->GetName() != "" ) ok = true;
-      }
-    }
-  }
-  return ok;
+  // as soon as Use Case browser data tree was added
+  return obj->GetStudy()->GetUseCaseBuilder()->HasChildren( obj );
 }
 
 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
@@ -436,6 +427,17 @@ bool GEOMGUI_Selection::isCompoundOfVertices( GEOM::GEOM_Object_ptr obj )
   return ret;
 }
 
+bool GEOMGUI_Selection::isFolder( const _PTR(SObject)& obj )
+{
+  bool ret = false;
+  _PTR(GenericAttribute) anAttr;
+  if ( obj->FindAttribute(anAttr, "AttributeLocalID") ) {
+    _PTR(AttributeLocalID) aLocalID( anAttr );
+    ret = aLocalID->Value() == 999;
+  }
+  return ret;
+}
+
 bool GEOMGUI_Selection::hasChildren( const int index ) const
 {
   bool ok = false;
@@ -452,6 +454,25 @@ bool GEOMGUI_Selection::hasChildren( const int index ) const
   return ok;
 }
 
+int GEOMGUI_Selection::nbChildren( const int index ) const
+{
+  int nb = 0;
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
+
+  if ( appStudy ) {
+    QString anEntry = entry( index );
+    _PTR(Study) study = appStudy->studyDS();
+    if ( study && !anEntry.isEmpty() ) {
+      _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
+      if ( aSO->GetStudy()->GetUseCaseBuilder()->IsUseCaseNode(aSO) ) {
+       _PTR(UseCaseIterator) it = aSO->GetStudy()->GetUseCaseBuilder()->GetUseCaseIterator( aSO ); 
+       for (it->Init(false); it->More(); it->Next()) nb++;
+      }
+    }
+  }
+  return nb;
+}
+
 bool GEOMGUI_Selection::hasConcealedChildren( const int index ) const
 {
   bool OK = false;
@@ -625,6 +646,7 @@ bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const
 
 bool GEOMGUI_Selection::isFolder( const int index ) const
 {
+  bool res = false;
   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
 
   if ( appStudy ) {
@@ -632,15 +654,9 @@ bool GEOMGUI_Selection::isFolder( const int index ) const
     _PTR(Study) study = appStudy->studyDS();
     if ( study && !anEntry.isNull() ) {
       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
-      if ( aSO ) {
-       _PTR(GenericAttribute) anAttr;
-       if ( aSO->FindAttribute(anAttr, "AttributeLocalID") ) {
-         _PTR(AttributeLocalID) aLocalID( anAttr );
-         return aLocalID->Value() == 999;
-       }
-      }
+      if ( aSO ) res = isFolder( aSO );
     }
   }
-  return false;
+  return res;
 }
 
index c8c1230d937a26a117fe0186557e3c6f16abcb0c..fddb4df4ce797a495e8a227ed8de13bdbd740e91 100644 (file)
@@ -52,6 +52,7 @@ public:
   static bool           hasChildren( const _PTR(SObject)& );
   static bool           expandable( const _PTR(SObject)& );
   static bool           isCompoundOfVertices( GEOM::GEOM_Object_ptr );
+  static bool           isFolder( const _PTR(SObject)& );
 
 protected:
   //  virtual QVariant      contextParameter( const QString& ) const;
@@ -67,6 +68,7 @@ private:
   QString               selectionMode() const;
   bool                  isVectorsMode( const int ) const;
   bool                  hasChildren( const int ) const;
+  int                   nbChildren( const int ) const;
   bool                  hasConcealedChildren( const int ) const;
   bool                  hasDisclosedChildren( const int ) const;
   bool                  compoundOfVertices( const int ) const;
index 32cb42f361240e2582bf25b414d6793dfd328263..718477015517e317c7d9840c94f77d7b803b87cf 100644 (file)
@@ -4652,6 +4652,14 @@ Please, select face, shell or solid and try again</translation>
         <source>NEW_FOLDER_NAME</source>
         <translation>NewFolder</translation>
     </message>
+    <message>
+        <source>MEN_POP_SORT_CHILD_ITEMS</source>
+        <translation>Sort children</translation>
+    </message>
+    <message>
+        <source>STB_POP_SORT_CHILD_ITEMS</source>
+        <translation>Sort child items</translation>
+    </message>
     <message>
         <source>GEOM_RESULT_NAME_GRP</source>
         <translation>Result name</translation>
index 065f5fb7b0810cf7bc907f49bae3b12d3fcb4e43..0d165390f657bff31278bd29d22325d239ed8daf 100644 (file)
@@ -4658,6 +4658,14 @@ Choisissez une face, une coque ou un solide et essayez de nouveau</translation>
         <source>NEW_FOLDER_NAME</source>
         <translation type="unfinished">NewFolder</translation>
     </message>
+    <message>
+        <source>MEN_POP_SORT_CHILD_ITEMS</source>
+        <translation type="unfinished">Sort children</translation>
+    </message>
+    <message>
+        <source>STB_POP_SORT_CHILD_ITEMS</source>
+        <translation type="unfinished">Sort child items</translation>
+    </message>
     <message>
         <source>GEOM_RESULT_NAME_GRP</source>
         <translation>Nom du résultat</translation>
index 0d79f320d2af505e6199d0d42ac6ecea9c3a1972..e63309a01b696ee5daf4041227d559261ef3f490 100644 (file)
@@ -391,7 +391,8 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam )
                              << GEOMOp::OpUnpublishObject
                              << GEOMOp::OpPublishObject
                              << GEOMOp::OpPointMarker
-                             << GEOMOp::OpCreateFolder;
+                             << GEOMOp::OpCreateFolder
+                             << GEOMOp::OpSortChildren;
   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommands.contains( id ) )
       return;
 
@@ -444,6 +445,7 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam )
   case GEOMOp::OpBringToFront:       // POPUP MENU - BRING TO FRONT
   case GEOMOp::OpClsBringToFront:    //
   case GEOMOp::OpCreateFolder:       // POPUP MENU - CREATE FOLDER
+  case GEOMOp::OpSortChildren:       // POPUP MENU - SORT CHILD ITEMS
     libName = "GEOMToolsGUI";
     break;
   case GEOMOp::OpDMWireframe:        // MENU VIEW - WIREFRAME
@@ -905,6 +907,7 @@ void GeometryGUI::initialize( CAM_Application* app )
   createGeomAction( GEOMOp::OpMaterialProperties,   "POP_MATERIAL_PROPERTIES" );
   createGeomAction( GEOMOp::OpPredefMaterCustom,    "POP_PREDEF_MATER_CUSTOM" );
   createGeomAction( GEOMOp::OpCreateFolder, "POP_CREATE_FOLDER" );
+  createGeomAction( GEOMOp::OpSortChildren, "POP_SORT_CHILD_ITEMS" );
 
   createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
 
@@ -1407,7 +1410,11 @@ void GeometryGUI::initialize( CAM_Application* app )
 
   mgr->insert( separator(), -1, -1 );     // -----------
   mgr->insert( action(  GEOMOp::OpCreateFolder ), -1, -1 ); // Create Folder
-  mgr->setRule( action( GEOMOp::OpCreateFolder ), QString("client='ObjectBrowser' and (isComponent=true or isFolder=true)"), QtxPopupMgr::VisibleRule );
+  mgr->setRule( action( GEOMOp::OpCreateFolder ), QString("client='ObjectBrowser' and $component={'GEOM'} and (isComponent=true or isFolder=true)"), QtxPopupMgr::VisibleRule );
+
+  mgr->insert( separator(), -1, -1 );     // -----------
+  mgr->insert( action(  GEOMOp::OpSortChildren ), -1, -1 ); // Sort child items
+  mgr->setRule( action( GEOMOp::OpSortChildren ), QString("client='ObjectBrowser' and $component={'GEOM'} and nbChildren>1"), QtxPopupMgr::VisibleRule );
 
   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
 
index 77ca348a3675791e2e52086af0526f91e6e2d23f..38fa6d57fbbc4813d22299b6eb1bfa04e1bd042d 100644 (file)
@@ -60,6 +60,7 @@ namespace GEOMOp {
     OpEdgeWidth           = 1260,   // POPUP MENU - LINE WIDTH - EDGE WIDTH
     OpIsosWidth           = 1261,   // POPUP MENU - LINE WIDTH - ISOS WIDTH
     OpCreateFolder        = 1262,   // POPUP MENU - CREATE FOLDER
+    OpSortChildren        = 1263,   // POPUP MENU - SORT CHILD ITEMS
     // DisplayGUI ------------------//--------------------------------
     OpSwitchVectors       = 2001,   // MENU VIEW  - DISPLAY MODE - SHOW/HIDE EDGE DIRECTION
     OpShowAll             = 2002,   // MENU VIEW  - SHOW ALL
index 0ebb58902519837ad794656a16edac8b6ee12854..23a3576298e9278997ce24785573d5ffc1d61087 100644 (file)
@@ -389,6 +389,9 @@ bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
   case GEOMOp::OpCreateFolder:
     OnCreateFolder();
      break;
+  case GEOMOp::OpSortChildren:
+    OnSortChildren();
+     break;
   default:
     SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
     break;
index b5fe325e37446aa94f612f46ed31c24a63af3b46..408f8c4be295d3fd095b26060679c5b02fdae352 100644 (file)
@@ -89,6 +89,7 @@ private:
   void         OnBringToFront();
   void         OnClsBringToFront();
   void         OnCreateFolder();
+  void         OnSortChildren();
 
   // Shortcut commands
   void         OnChangeTransparency( bool );
index 5d158445fe3051b29e15ddbf0752175257e30fc8..23d89428305195fca577c42222ad911091d96308 100644 (file)
@@ -835,3 +835,30 @@ void GEOMToolsGUI::OnCreateFolder()
                                           _CAST(SObject, aFatherSO)->GetSObject() );
   app->updateObjectBrowser( false );
 }
+
+void GEOMToolsGUI::OnSortChildren()
+{
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  if ( !app ) return;
+
+  SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
+  if ( !appStudy ) return;
+
+  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  if ( !aSelMgr ) return;
+
+  SALOME_ListIO selected;
+  aSelMgr->selectedObjects( selected );
+  if ( selected.IsEmpty() ) return;
+
+  Handle(SALOME_InteractiveObject) anIObject = selected.First();
+
+  _PTR(Study) aStudy = appStudy->studyDS();
+  if( !aStudy ) return;
+  _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
+  if ( !aFatherSO ) return;
+
+  aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
+
+  app->updateObjectBrowser( true );
+}