From 826f9e817d671e315b07f6c4265aeadc8628adb5 Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 15 Apr 2010 15:25:33 +0000 Subject: [PATCH] Issue 0020465: [CEA 335] sort tables in visualisation mode --- idl/VISU_Gen.idl | 53 ++++++++++++++- src/VISU_I/VISU_Table_i.cc | 110 +++++++++++++++++++++++++++++++ src/VISU_I/VISU_Table_i.hh | 6 ++ src/VISU_I/VISU_ViewManager_i.cc | 57 +++++++++++++++- 4 files changed, 224 insertions(+), 2 deletions(-) diff --git a/idl/VISU_Gen.idl b/idl/VISU_Gen.idl index 7ed8c91a..965f30fb 100644 --- a/idl/VISU_Gen.idl +++ b/idl/VISU_Gen.idl @@ -74,7 +74,7 @@ module VISU { NODE, /*!< Node corresponds to a geometrical point. */ EDGE, /*!< Edge corresponds to a geometrical line connecting two points. */ FACE, /*!< Face corresponds to a geometrical plane bounded by several lines. */ - CELL, /*!< Cell is a volumic element of a mesh */ + CELL, /*!< Cell is a volumic element of a mesh */ NONE /*!< Indicates undefined entity value */ }; @@ -115,6 +115,25 @@ module VISU { MS_70 }; + /*! + * Tables' sort order + */ + enum SortOrder { + AscendingOrder, /*!< The table items are sorted ascending */ + DescendingOrder /*!< The table items are sorted descending */ + }; + + /*! + * Tables' sort policy (specifies how empty cells are taken into account when sorting) + */ + enum SortPolicy { + EmptyLowest, /*!< Empty cells are considered as lowest values */ + EmptyHighest, /*!< Empty cells are considered as highest values */ + EmptyFirst, /*!< Empty cells are always first */ + EmptyLast, /*!< Empty cells are always last */ + EmptyIgnore /*!< Empty cells are ignored (stay at initial positions) */ + }; + /*! * This enumeration contains a set of elements defining the type of the %VISU object. * This enumeration is used for navigation between a set of %VISU interfaces. @@ -1329,6 +1348,38 @@ module VISU { * \return Long value corresponding to the number of columns of the table */ long GetNbColumns(); + + /*! + * Sorts the specified row of the table. + * \param theRow Index of the row to sort + * \param theSortOrder Sort order (see SortOrder enumeration) + * \param theSortPolicy Sort policy (see SortPolicy enumeration) + */ + void SortRow(in long theRow, in SortOrder theSortOrder, in SortPolicy theSortPolicy); + + /*! + * Sorts the specified column of the table. + * \param theRow Index of the column to sort + * \param theSortOrder Sort order (see SortOrder enumeration) + * \param theSortPolicy Sort policy (see SortPolicy enumeration) + */ + void SortColumn(in long theColumn, in SortOrder theSortOrder, in SortPolicy theSortPolicy); + + /*! + * Sorts the table by the specified row. + * \param theRow Index of the row, by which the table has to be sort + * \param theSortOrder Sort order (see SortOrder enumeration) + * \param theSortPolicy Sort policy (see SortPolicy enumeration) + */ + void SortByRow(in long theRow, in SortOrder theSortOrder, in SortPolicy theSortPolicy); + + /*! + * Sorts the table by the specified column. + * \param theColumn Index of the column, by which the table has to be sort + * \param theSortOrder Sort order (see SortOrder enumeration) + * \param theSortPolicy Sort policy (see SortPolicy enumeration) + */ + void SortByColumn(in long theColumn, in SortOrder theSortOrder, in SortPolicy theSortPolicy); }; //------------------------------------------------------- diff --git a/src/VISU_I/VISU_Table_i.cc b/src/VISU_I/VISU_Table_i.cc index 530704d8..6d6fdf0b 100644 --- a/src/VISU_I/VISU_Table_i.cc +++ b/src/VISU_I/VISU_Table_i.cc @@ -117,6 +117,116 @@ VISU::Table_i return myOrientation; } + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::SortRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy) +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + if ( !SO->_is_nil() ) { + SALOMEDS::GenericAttribute_var anAttr; + if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { + SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); + anInt->SortRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { + SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); + aReal->SortRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + UpdateCurves(); + } +} + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::SortColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy) +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + if ( !SO->_is_nil() ) { + SALOMEDS::GenericAttribute_var anAttr; + if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { + SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); + anInt->SortColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { + SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); + aReal->SortColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + UpdateCurves(); + } +} + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::SortByRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy) +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + if ( !SO->_is_nil() ) { + SALOMEDS::GenericAttribute_var anAttr; + if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { + SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); + anInt->SortByRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { + SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); + aReal->SortByRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + UpdateCurves(); + } +} + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::SortByColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy) +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + if ( !SO->_is_nil() ) { + SALOMEDS::GenericAttribute_var anAttr; + if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { + SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); + anInt->SortByColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { + SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); + aReal->SortByColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + UpdateCurves(); + } +} + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::UpdateCurves() +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( SO ); + for ( CI->InitEx( true ); CI->More(); CI->Next() ) { + CORBA::Object_var anObj = SObjectToObject( CI->Value() ); + VISU::Curve_var aCurve = VISU::Curve::_narrow( anObj ); + if ( !aCurve->_is_nil() ) + if( VISU::Curve_i* pCurve = dynamic_cast( GetServant( aCurve ).in() ) ) + UpdatePlot2d( NULL, eDisplay, pCurve ); // first parameter is null to update curves in all views + } +} + //---------------------------------------------------------------------------- SALOMEDS::SObject_var VISU::Table_i diff --git a/src/VISU_I/VISU_Table_i.hh b/src/VISU_I/VISU_Table_i.hh index ca35887d..33279cf7 100644 --- a/src/VISU_I/VISU_Table_i.hh +++ b/src/VISU_I/VISU_Table_i.hh @@ -54,10 +54,16 @@ namespace VISU{ virtual CORBA::Long GetNbRows(); virtual CORBA::Long GetNbColumns(); + virtual void SortRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy); + virtual void SortColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy); + virtual void SortByRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy); + virtual void SortByColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy); + virtual void RemoveFromStudy(); protected: Storable* Build(int theRestoring); + void UpdateCurves(); protected: VISU::Table::Orientation myOrientation; diff --git a/src/VISU_I/VISU_ViewManager_i.cc b/src/VISU_I/VISU_ViewManager_i.cc index 0bc32345..cde37b44 100644 --- a/src/VISU_I/VISU_ViewManager_i.cc +++ b/src/VISU_I/VISU_ViewManager_i.cc @@ -41,9 +41,11 @@ #include "SVTK_ViewModel.h" #include "VTKViewer_Algorithm.h" #include "SPlot2d_Curve.h" +#include "SPlot2d_ViewModel.h" #include "Plot2d_ViewFrame.h" #include "Plot2d_ViewWindow.h" #include "Plot2d_ViewModel.h" +#include "Plot2d_ViewManager.h" #include "SalomeApp_Study.h" #include "SalomeApp_Application.h" @@ -330,11 +332,64 @@ namespace VISU { return anVISUActor; } + struct TUpdatePlot2dEvent: public SALOME_Event + { + int myDisplaying; + Curve_i* myCurve; + + TUpdatePlot2dEvent (const int theDisplaying, Curve_i* theCurve): + myDisplaying(theDisplaying), + myCurve(theCurve) + {} + + virtual void Execute() + { + SalomeApp_Application* anApp = NULL; + CORBA::String_var studyName = myCurve->GetStudyDocument()->Name(); + std::string aStudyName = studyName.in(); + SUIT_Session* aSession = SUIT_Session::session(); + QList anApplications = aSession->applications(); + QList::Iterator anIter = anApplications.begin(); + while (anIter != anApplications.end()) { + SUIT_Application* aSUITApp = *anIter; + if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + if (aStudyName == aCStudy->Name()) { + anApp = dynamic_cast(aSUITApp); + break; + } + } + } + } + anIter++; + } + if (!anApp) + return; + + ViewManagerList aViewManagerList; + anApp->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList); + SUIT_ViewManager* aViewManager; + foreach( aViewManager, aViewManagerList ) { + if (Plot2d_ViewManager* aManager = dynamic_cast(aViewManager)) { + if (SPlot2d_Viewer* aViewer = dynamic_cast(aManager->getViewModel())) { + if (Plot2d_ViewFrame* aViewFrame = aViewer->getActiveViewFrame()) { + UpdatePlot2d(aViewFrame, myDisplaying, myCurve); + } + } + } + } + } + }; + void UpdatePlot2d (Plot2d_ViewFrame *theView,int theDisplaying, Curve_i* theCurve) { if(MYDEBUG) MESSAGE("UpdatePlot2d - theDisplaying = " << theDisplaying); - if (!theView) + if (!theView) { + // update all views + ProcessVoidEvent(new TUpdatePlot2dEvent(theDisplaying, theCurve)); return; + } QList clist; theView->getCurves(clist); if (theDisplaying == eEraseAll) { -- 2.39.2