From ee8e304b51d61dd8bf5d25328039aa645f80e4da Mon Sep 17 00:00:00 2001 From: adv Date: Fri, 24 Jan 2014 05:28:18 +0000 Subject: [PATCH] Find object by name were moved to the methods of document. --- src/HYDROData/HYDROData_Document.cxx | 52 ++++++++++++++++++++++++++-- src/HYDROData/HYDROData_Document.h | 23 ++++++++++++ src/HYDROData/HYDROData_Tool.cxx | 50 -------------------------- src/HYDROData/HYDROData_Tool.h | 22 ------------ src/HYDROGUI/HYDROGUI_Tool.cxx | 17 ++++++--- src/HYDROPy/HYDROData_Document.sip | 18 ++++++++++ 6 files changed, 104 insertions(+), 78 deletions(-) diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index c237aa93..c195b9d5 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -360,9 +360,57 @@ void HYDROData_Document::Redo() myTransactionsAfterSave++; } -Handle(HYDROData_Entity) HYDROData_Document::CreateObject(const ObjectKind theKind) +Handle(HYDROData_Entity) HYDROData_Document::CreateObject( const ObjectKind theKind ) { - return HYDROData_Iterator::CreateObject(this, theKind); + return HYDROData_Iterator::CreateObject( this, theKind ); +} + +Handle(HYDROData_Entity) HYDROData_Document::FindObjectByName( + const QString& theName, + const ObjectKind theObjectKind ) const +{ + Handle(HYDROData_Entity) anObject; + if ( theName.isEmpty() ) + return anObject; + + QStringList aNamesList; + aNamesList << theName; + + HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( aNamesList, theObjectKind ); + if( aSeqOfObjs.IsEmpty() ) + return anObject; + + anObject = aSeqOfObjs.First(); + return anObject; +} + +HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames( + const QStringList& theNames, + const ObjectKind theObjectKind ) const +{ + HYDROData_SequenceOfObjects aResSeq; + + QStringList aNamesList = theNames; + + HYDROData_Iterator anIter( this, theObjectKind ); + for( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Entity) anObject = anIter.Current(); + if( anObject.IsNull() ) + continue; + + QString anObjName = anObject->GetName(); + if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) ) + continue; + + aResSeq.Append( anObject ); + + aNamesList.removeAll( anObjName ); + if ( aNamesList.isEmpty() ) + break; + } + + return aResSeq; } HYDROData_Document::HYDROData_Document() diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index 569a588d..1de23428 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -45,6 +45,8 @@ public: HYDRODATA_EXPORT static Handle(HYDROData_Document) Document( const TDF_Label& theObjectLabel ); +public: + //! Returns true if data model contains document for this study HYDRODATA_EXPORT static bool HasDocument(const int theStudyID); @@ -52,6 +54,8 @@ public: HYDRODATA_EXPORT static bool DocumentId( const Handle(HYDROData_Document)& theDocument, int& theDocId ); +public: + //! Loads the OCAF document from the file. //! \param theFileName full name of the file to load //! \param theStudyID identifier of the SALOME study to associate with loaded file @@ -66,6 +70,8 @@ public: //! Removes document data HYDRODATA_EXPORT void Close(); +public: + // Returns name of document instance in python dump script HYDRODATA_EXPORT QString GetDocPyName() const; @@ -77,6 +83,8 @@ public: //! Dump model data to Python script representation. HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; +public: + //! Starts a new operation (opens a tansaction) HYDRODATA_EXPORT void StartOperation(); //! Finishes the previously started operation (closes the transaction) @@ -89,6 +97,8 @@ public: //! Returns true if document was modified (since creation/opening) HYDRODATA_EXPORT bool IsModified(); +public: + //! Returns True if there are available Undos HYDRODATA_EXPORT bool CanUndo(); //! Returns a list of stored undo actions @@ -107,11 +117,24 @@ public: //! Redoes last operation HYDRODATA_EXPORT void Redo(); +public: + //! Creates and locates in the document a new object //! \param theKind kind of the created object, can not be UNKNOWN //! \returns the created object HYDRODATA_EXPORT Handle(HYDROData_Entity) CreateObject(const ObjectKind theKind); + + //! Find the data object with the specified name. + HYDRODATA_EXPORT Handle(HYDROData_Entity) FindObjectByName( + const QString& theName, + const ObjectKind theObjectKind = KIND_UNKNOWN ) const; + + //! Find the data objects with the specified names. + HYDRODATA_EXPORT HYDROData_SequenceOfObjects FindObjectsByNames( + const QStringList& theNames, + const ObjectKind theObjectKind = KIND_UNKNOWN ) const; + protected: friend class HYDROData_Iterator; diff --git a/src/HYDROData/HYDROData_Tool.cxx b/src/HYDROData/HYDROData_Tool.cxx index e5b45109..333205a0 100644 --- a/src/HYDROData/HYDROData_Tool.cxx +++ b/src/HYDROData/HYDROData_Tool.cxx @@ -123,56 +123,6 @@ QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& th return aName; } -Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc, - const QString& theName, - const ObjectKind theObjectKind ) -{ - Handle(HYDROData_Entity) anObject; - if ( theName.isEmpty() || theDoc.IsNull() ) - return anObject; - - QStringList aNamesList; - aNamesList << theName; - - HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind ); - if( aSeqOfObjs.IsEmpty() ) - return anObject; - - anObject = aSeqOfObjs.First(); - return anObject; -} - -HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc, - const QStringList& theNames, - const ObjectKind theObjectKind ) -{ - HYDROData_SequenceOfObjects aResSeq; - if( theDoc.IsNull() ) - return aResSeq; - - QStringList aNamesList = theNames; - - HYDROData_Iterator anIter( theDoc, theObjectKind ); - for( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Entity) anObject = anIter.Current(); - if( anObject.IsNull() ) - continue; - - QString anObjName = anObject->GetName(); - if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) ) - continue; - - aResSeq.Append( anObject ); - - aNamesList.removeAll( anObjName ); - if ( aNamesList.isEmpty() ) - break; - } - - return aResSeq; -} - bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject ) { if ( theObject.IsNull() ) diff --git a/src/HYDROData/HYDROData_Tool.h b/src/HYDROData/HYDROData_Tool.h index d2260e78..bb71d8c4 100644 --- a/src/HYDROData/HYDROData_Tool.h +++ b/src/HYDROData/HYDROData_Tool.h @@ -46,28 +46,6 @@ public: const QStringList& theUsedNames = QStringList(), const bool theIsTryToUsePurePrefix = false ); - /** - * \brief Find the data object with the specified name. - * \param theModule module - * \param theName name - * \param theObjectKind kind of object - * \return data object - */ - static Handle(HYDROData_Entity) FindObjectByName( const Handle(HYDROData_Document)& theDoc, - const QString& theName, - const ObjectKind theObjectKind = KIND_UNKNOWN ); - - /** - * \brief Find the data objects with the specified names. - * \param theModule module - * \param theNames list of names - * \param theObjectKind kind of object - * \return list of data objects - */ - static HYDROData_SequenceOfObjects FindObjectsByNames( const Handle(HYDROData_Document)& theDoc, - const QStringList& theNames, - const ObjectKind theObjectKind = KIND_UNKNOWN ); - /** * \brief Checks the type of object. * \param theObject object to check diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 48bf1989..5c45c8ba 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -438,16 +438,26 @@ Handle(HYDROData_Entity) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theMo const QString& theName, const ObjectKind theObjectKind ) { + Handle(HYDROData_Entity) aResObj; + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); - return HYDROData_Tool::FindObjectByName( aDocument, theName, theObjectKind ); + if ( !aDocument.IsNull() ) + aResObj = aDocument->FindObjectByName( theName, theObjectKind ); + + return aResObj; } HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module* theModule, const QStringList& theNames, const ObjectKind theObjectKind ) { + HYDROData_SequenceOfObjects aResSeq; + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); - return HYDROData_Tool::FindObjectsByNames( aDocument, theNames, theObjectKind ); + if ( !aDocument.IsNull() ) + aResSeq = aDocument->FindObjectsByNames( theNames, theObjectKind ); + + return aResSeq; } QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule, @@ -662,8 +672,7 @@ QColor HYDROGUI_Tool::GenerateFillingColor( const Handle(HYDROData_Document)& th { const QString& aZoneName = aZoneNameIter.next(); Handle(HYDROData_ImmersibleZone) aRefZone = - Handle(HYDROData_ImmersibleZone)::DownCast( - HYDROData_Tool::FindObjectByName( theDoc, aZoneName, KIND_IMMERSIBLE_ZONE ) ); + Handle(HYDROData_ImmersibleZone)::DownCast( theDoc->FindObjectByName( aZoneName, KIND_IMMERSIBLE_ZONE ) ); if( !aRefZone.IsNull() ) { QColor aRefColor = aRefZone->GetFillingColor(); diff --git a/src/HYDROPy/HYDROData_Document.sip b/src/HYDROPy/HYDROData_Document.sip index 5b2e2e19..6aeddf89 100644 --- a/src/HYDROPy/HYDROData_Document.sip +++ b/src/HYDROPy/HYDROData_Document.sip @@ -275,6 +275,24 @@ public: %End + HYDROData_Entity FindObjectByName( const QString& theName, + const ObjectKind theKind = KIND_UNKNOWN ) + [Handle_HYDROData_Entity (const QString&, const ObjectKind)] ; + %MethodCode + + Handle(HYDROData_Entity) anObject; + Py_BEGIN_ALLOW_THREADS + anObject = sipSelfWasArg ? sipCpp->HYDROData_Document::FindObjectByName( *a0, a1 ) : + sipCpp->FindObjectByName( *a0, a1 ); + Py_END_ALLOW_THREADS + + sipRes = createPointer( anObject ); + + %End + + HYDROData_SequenceOfObjects FindObjectsByNames( const QStringList& theNames, + const ObjectKind theKind = KIND_UNKNOWN ); + protected: //! Creates new document: private because "Document" method must be used instead of direct creation. -- 2.39.2