From: akl Date: Tue, 9 Jul 2013 08:22:16 +0000 (+0000) Subject: 0021708: [CEA 586] Object browser sort only children: X-Git-Tag: BR_hydro_v_0_3_1~161 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1dd8f0e9e65764777d1200cc6c61c7ac8a6c651c;p=modules%2Fgeom.git 0021708: [CEA 586] Object browser sort only children: + Add Use Case browser data tree management + Add "Sort children" contextual menu popup item + Update user documentation --- diff --git a/doc/salome/gui/GEOM/images/geom_sort.png b/doc/salome/gui/GEOM/images/geom_sort.png new file mode 100644 index 000000000..7324f62dd Binary files /dev/null and b/doc/salome/gui/GEOM/images/geom_sort.png differ diff --git a/doc/salome/gui/GEOM/input/arranging_study_objects_page.doc b/doc/salome/gui/GEOM/input/arranging_study_objects_page.doc index 44df8f830..aeeec8bb4 100644 --- a/doc/salome/gui/GEOM/input/arranging_study_objects_page.doc +++ b/doc/salome/gui/GEOM/input/arranging_study_objects_page.doc @@ -20,6 +20,10 @@ To create a folder select "Create folder" popup menu item for root "Geometry" ob
  • folder(s) +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 TUI Scripts provide you with useful examples of \ref tui_arranging_study_objects "Arranging objects in study". diff --git a/src/GEOMGUI/GEOMGUI_Selection.cxx b/src/GEOMGUI/GEOMGUI_Selection.cxx index fdf8f8451..c090dbbd9 100644 --- a/src/GEOMGUI/GEOMGUI_Selection.cxx +++ b/src/GEOMGUI/GEOMGUI_Selection.cxx @@ -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( 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( 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; } diff --git a/src/GEOMGUI/GEOMGUI_Selection.h b/src/GEOMGUI/GEOMGUI_Selection.h index c8c1230d9..fddb4df4c 100644 --- a/src/GEOMGUI/GEOMGUI_Selection.h +++ b/src/GEOMGUI/GEOMGUI_Selection.h @@ -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; diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 32cb42f36..718477015 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -4652,6 +4652,14 @@ Please, select face, shell or solid and try again NEW_FOLDER_NAME NewFolder + + MEN_POP_SORT_CHILD_ITEMS + Sort children + + + STB_POP_SORT_CHILD_ITEMS + Sort child items + GEOM_RESULT_NAME_GRP Result name diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index 065f5fb7b..0d165390f 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -4658,6 +4658,14 @@ Choisissez une face, une coque ou un solide et essayez de nouveau NEW_FOLDER_NAME NewFolder + + MEN_POP_SORT_CHILD_ITEMS + Sort children + + + STB_POP_SORT_CHILD_ITEMS + Sort child items + GEOM_RESULT_NAME_GRP Nom du résultat diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 0d79f320d..e63309a01 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -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 ) ) ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 77ca348a3..38fa6d57f 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -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 diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index 0ebb58902..23a357629 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -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; diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.h b/src/GEOMToolsGUI/GEOMToolsGUI.h index b5fe325e3..408f8c4be 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI.h @@ -89,6 +89,7 @@ private: void OnBringToFront(); void OnClsBringToFront(); void OnCreateFolder(); + void OnSortChildren(); // Shortcut commands void OnChangeTransparency( bool ); diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index 5d158445f..23d894283 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -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 ); +}