From: akl Date: Tue, 9 Jul 2013 08:32:08 +0000 (+0000) Subject: 0021708: [CEA 586] Object browser sort only children: X-Git-Tag: V7_3_0a1~288 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7c7b4b0636cbb5fdb2ae67658ec9709be1c58812;p=modules%2Fsmesh.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/SMESH/images/smesh_sort.png b/doc/salome/gui/SMESH/images/smesh_sort.png new file mode 100644 index 000000000..0b00568c3 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 index 000000000..ea655d5f4 --- /dev/null +++ b/doc/salome/gui/SMESH/input/arranging_study_objects_page.doc @@ -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" + +*/ diff --git a/doc/salome/gui/SMESH/input/index.doc b/doc/salome/gui/SMESH/input/index.doc index 798237b4b..917e540bd 100644 --- a/doc/salome/gui/SMESH/input/index.doc +++ b/doc/salome/gui/SMESH/input/index.doc @@ -23,6 +23,9 @@ array of dedicated operations; \subpage using_notebook_mesh_page "Salome notebook". +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 diff --git a/idl/SMESH_Gen.idl b/idl/SMESH_Gen.idl index fbe8a35d6..aadfb1e33 100644 --- a/idl/SMESH_Gen.idl +++ b/idl/SMESH_Gen.idl @@ -36,6 +36,7 @@ module SMESH { + typedef sequence sobject_list; typedef sequence object_array; typedef sequence 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 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 ); }; }; diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 390621247..33de52b4d 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -162,6 +162,7 @@ #include #include #include +#include // OCCT includes #include @@ -1221,6 +1222,25 @@ } } + 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; @@ -3533,6 +3553,10 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) dlg->show(); break; } + case 41: + ::sortChildren(); + break; + } 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( 41, "SORT_CHILD_ITEMS" ); + // ----- 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( 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* ) ) ); diff --git a/src/SMESHGUI/SMESHGUI_Selection.cxx b/src/SMESHGUI/SMESHGUI_Selection.cxx index 4b8c433f9..86a929214 100644 --- a/src/SMESHGUI/SMESHGUI_Selection.cxx +++ b/src/SMESHGUI/SMESHGUI_Selection.cxx @@ -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=="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; @@ -529,6 +532,50 @@ QVariant SMESHGUI_Selection::isVisible( int ind ) const 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 : diff --git a/src/SMESHGUI/SMESHGUI_Selection.h b/src/SMESHGUI/SMESHGUI_Selection.h index 4358bab07..5f2a50bdb 100644 --- a/src/SMESHGUI/SMESHGUI_Selection.h +++ b/src/SMESHGUI/SMESHGUI_Selection.h @@ -63,6 +63,9 @@ public: 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 elemTypes( int ) const; diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index 6fd576050..6a8b6750f 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -4114,6 +4114,14 @@ It can't be deleted SMESH_GIGABYTE %1 GB + + MEN_SORT_CHILD_ITEMS + Sort children + + + STB_SORT_CHILD_ITEMS + Sort child items + SMESHGUI_Dialog diff --git a/src/SMESHGUI/SMESH_msg_fr.ts b/src/SMESHGUI/SMESH_msg_fr.ts index 65e5bb7b5..7423e43ea 100755 --- a/src/SMESHGUI/SMESH_msg_fr.ts +++ b/src/SMESHGUI/SMESH_msg_fr.ts @@ -4114,6 +4114,14 @@ avec le paramètre '%1' des préférences du module Mesh.L'objet sélectionné a été utilisé pour en créer un autre. Il ne peut pas être supprimé. + + MEN_SORT_CHILD_ITEMS + Sort children + + + STB_SORT_CHILD_ITEMS + Sort child items + SMESHGUI_Dialog diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index f710776b6..f393b918c 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -4790,6 +4790,18 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, } 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; } @@ -4997,6 +5009,46 @@ char* SMESH_Gen_i::getVersion() #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 diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index bbd544fab..403fb7ee5 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -585,6 +585,11 @@ public: 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, diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index 4ac7ad8d3..fc50bc409 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -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::UseCaseBuilder_var useCaseBuilder = theStudy->GetUseCaseBuilder(); 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 ); } + // add object to the use case tree + // (to support tree representation customization and drag-n-drop) + useCaseBuilder->AppendTo( SO->GetFather(), SO ); + 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 ); + // 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(); + SALOMEDS::UseCaseBuilder_var useCaseBuilder = theStudy->GetUseCaseBuilder(); 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" ); + // 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();