From: akl Date: Tue, 9 Jul 2013 08:02:24 +0000 (+0000) Subject: 0021708: [CEA 586] Object browser sort only children: X-Git-Tag: B4KillOfAutomake~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a9fbe5372ecd9d060f2bd228e9a69d95944f0e1c;p=modules%2Fkernel.git 0021708: [CEA 586] Object browser sort only children: Add sorting function to the UseCaseBuilder CORBA interface to sort child data objects of the specified parent data object according to the specified sort order (ascending or descending). --- diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index e41297a14..69de7bf84 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -1319,6 +1319,10 @@ Activates the %UseCaseIterator. Returns True if the given object theObject of the use case has child objects. */ boolean HasChildren(in SObject theObject); +/*! + Returns True if children of the given object theObject of the use case tree were sorted successfully. +*/ + boolean SortChildren(in SObject theObject, in boolean theAscendingOrder); /*! Gets father object of the given object theObject in the use cases tree. */ diff --git a/src/SALOMEDS/SALOMEDS_UseCaseBuilder.cxx b/src/SALOMEDS/SALOMEDS_UseCaseBuilder.cxx index 79a324850..37dfc1450 100644 --- a/src/SALOMEDS/SALOMEDS_UseCaseBuilder.cxx +++ b/src/SALOMEDS/SALOMEDS_UseCaseBuilder.cxx @@ -139,6 +139,18 @@ bool SALOMEDS_UseCaseBuilder::HasChildren(const _PTR(SObject)& theObject) return ret; } +bool SALOMEDS_UseCaseBuilder::SortChildren(const _PTR(SObject)& theObject, bool theAscendingOrder) +{ + bool ret; + SALOMEDS_SObject* obj = dynamic_cast(theObject.get()); + if (_isLocal) { + SALOMEDS::Locker lock; + ret = _local_impl->SortChildren(*(obj->GetLocalImpl()), theAscendingOrder); + } + else ret = _corba_impl->SortChildren(obj->GetCORBAImpl(), theAscendingOrder); + return ret; +} + _PTR(SObject) SALOMEDS_UseCaseBuilder::GetFather(const _PTR(SObject)& theObject) { SALOMEDS_SObject* father = NULL; diff --git a/src/SALOMEDS/SALOMEDS_UseCaseBuilder.hxx b/src/SALOMEDS/SALOMEDS_UseCaseBuilder.hxx index 055158da6..4162810ec 100644 --- a/src/SALOMEDS/SALOMEDS_UseCaseBuilder.hxx +++ b/src/SALOMEDS/SALOMEDS_UseCaseBuilder.hxx @@ -55,6 +55,7 @@ public: virtual bool SetCurrentObject(const _PTR(SObject)& theObject); virtual bool SetRootCurrent(); virtual bool HasChildren(const _PTR(SObject)& theObject); + virtual bool SortChildren(const _PTR(SObject)& theObject, bool theAscendingOrder); virtual _PTR(SObject) GetFather(const _PTR(SObject)& theObject); virtual bool IsUseCase(const _PTR(SObject)& theObject); virtual bool IsUseCaseNode(const _PTR(SObject)& theObject); diff --git a/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx b/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx index 826a0bcc1..038468386 100644 --- a/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx +++ b/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx @@ -141,6 +141,18 @@ CORBA::Boolean SALOMEDS_UseCaseBuilder_i::HasChildren(SALOMEDS::SObject_ptr theO return _impl->HasChildren(_impl->GetSObject(theObject->GetID())); } +//============================================================================ +/*! Function : SortChildren + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_UseCaseBuilder_i::SortChildren(SALOMEDS::SObject_ptr theObject, CORBA::Boolean theAscendingOrder) +{ + SALOMEDS::Locker lock; + if(!_impl) return 0; + return _impl->SortChildren(_impl->GetSObject(theObject->GetID()), theAscendingOrder); +} + //============================================================================ /*! Function : GetFather * Purpose : diff --git a/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.hxx b/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.hxx index a2caee686..64f34cfb3 100644 --- a/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.hxx +++ b/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.hxx @@ -73,6 +73,8 @@ public: virtual CORBA::Boolean HasChildren(SALOMEDS::SObject_ptr theObject); + virtual CORBA::Boolean SortChildren(SALOMEDS::SObject_ptr theObject, CORBA::Boolean theAscendingOrder); + virtual SALOMEDS::SObject_ptr GetFather(SALOMEDS::SObject_ptr theObject); virtual CORBA::Boolean IsUseCase(SALOMEDS::SObject_ptr theObject); diff --git a/src/SALOMEDS/Test/SALOMEDSTest_UseCase.cxx b/src/SALOMEDS/Test/SALOMEDSTest_UseCase.cxx index 23a07d3a5..079d3dd5c 100755 --- a/src/SALOMEDS/Test/SALOMEDSTest_UseCase.cxx +++ b/src/SALOMEDS/Test/SALOMEDSTest_UseCase.cxx @@ -108,6 +108,10 @@ void SALOMEDSTest::testUseCase() CPPUNIT_ASSERT(builder->HasChildren(so1)); CPPUNIT_ASSERT(!builder->HasChildren(so2)); + //Check method SortChildren + CPPUNIT_ASSERT(builder->SortChildren(so1, true)); + CPPUNIT_ASSERT(!builder->SortChildren(so2, false)); + //Check method Init of UseCaseIterator it->Init(false); //Only the first level CPPUNIT_ASSERT(it->More()); diff --git a/src/SALOMEDSClient/SALOMEDSClient_UseCaseBuilder.hxx b/src/SALOMEDSClient/SALOMEDSClient_UseCaseBuilder.hxx index acc3e0549..6f4f29320 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_UseCaseBuilder.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_UseCaseBuilder.hxx @@ -44,6 +44,7 @@ public: virtual bool SetCurrentObject(const _PTR(SObject)& theObject) = 0; virtual bool SetRootCurrent() = 0; virtual bool HasChildren(const _PTR(SObject)& theObject) = 0; + virtual bool SortChildren(const _PTR(SObject)& theObject, bool theAscendingOrder) = 0; virtual _PTR(SObject) GetFather(const _PTR(SObject)& theObject) = 0; virtual bool IsUseCase(const _PTR(SObject)& theObject) = 0; virtual bool IsUseCaseNode(const _PTR(SObject)& theObject) = 0; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx index 515bc8d07..f3652b682 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx @@ -32,9 +32,42 @@ #include "DF_ChildIterator.hxx" +#include + #define USE_CASE_LABEL_TAG 2 #define USE_CASE_GUID "AA43BB12-D9CD-11d6-945D-0050DA506788" +namespace { + // comparator to sort use case nodes in ascending order + struct AscSortSOs { + bool operator()( SALOMEDSImpl_SObject firstSO, SALOMEDSImpl_SObject secondSO ) const { + std::string firstName, secondName; + SALOMEDSImpl_SObject refSO; + firstSO.ReferencedObject(refSO) ? + firstName = refSO.GetName() : + firstName = firstSO.GetName(); + secondSO.ReferencedObject(refSO) ? + secondName = refSO.GetName() : + secondName = secondSO.GetName(); + return firstName < secondName; + } + }; + + // comparator to sort use case nodes in descending order + struct DescSortSOs { + bool operator()( SALOMEDSImpl_SObject firstSO, SALOMEDSImpl_SObject secondSO ) const { + std::string firstName, secondName; + SALOMEDSImpl_SObject refSO; + firstSO.ReferencedObject(refSO) ? + firstName = refSO.GetName() : + firstName = firstSO.GetName(); + secondSO.ReferencedObject(refSO) ? + secondName = refSO.GetName() : + secondName = secondSO.GetName(); + return firstName > secondName; + } + }; +} //============================================================================ /*! Function : constructor @@ -279,6 +312,44 @@ bool SALOMEDSImpl_UseCaseBuilder::HasChildren(const SALOMEDSImpl_SObject& theObj return (aNode->GetFirst()); } +//============================================================================ +/*! Function : SortChildren + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::SortChildren(const SALOMEDSImpl_SObject& theObject, bool theAscendingOrder) +{ + if(!_root) return false; + + DF_Label aLabel; + if (!theObject) aLabel = _root->Label(); + else + aLabel = theObject.GetLabel(); + if(aLabel.IsNull()) return false; + + SALOMEDSImpl_AttributeTreeNode* aNode = NULL; + if (!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) return false; + + std::list aNodeSOs; + for (SALOMEDSImpl_AttributeTreeNode* aChildNode=aNode->GetFirst(); aChildNode; aChildNode=aChildNode->GetNext() ) { + SALOMEDSImpl_SObject aSO = SALOMEDSImpl_Study::SObject(aChildNode->Label()); + if (aSO) { + aNodeSOs.push_back(aSO); + } + } + if (aNodeSOs.empty()) return false; + + //sort items by names in ascending/descending order + theAscendingOrder ? aNodeSOs.sort( AscSortSOs() ) : aNodeSOs.sort( DescSortSOs() ); + + std::list::iterator it; + for (it=aNodeSOs.begin(); it!=aNodeSOs.end(); ++it) { + AppendTo(aNode->GetSObject(), *it); + } + + return true; +} + //============================================================================ /*! Function : GetFather * Purpose : diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx index 5c190d102..f83363607 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx @@ -65,6 +65,8 @@ public: virtual bool HasChildren(const SALOMEDSImpl_SObject& theObject); + virtual bool SortChildren(const SALOMEDSImpl_SObject& theObject, bool theAscendingOrder); + virtual SALOMEDSImpl_SObject GetFather(const SALOMEDSImpl_SObject& theObject); virtual bool IsUseCase(const SALOMEDSImpl_SObject& theObject);