From: kgv Date: Thu, 23 May 2019 20:47:43 +0000 (+0300) Subject: 0030739: Data Exchange - XCAFDoc_ShapeTool::IsComponent() is too slow X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FCR30739;p=occt-copy.git 0030739: Data Exchange - XCAFDoc_ShapeTool::IsComponent() is too slow --- diff --git a/src/TDF/TDF_AttributeIterator.hxx b/src/TDF/TDF_AttributeIterator.hxx index fa8622c583..dde66abe87 100644 --- a/src/TDF/TDF_AttributeIterator.hxx +++ b/src/TDF/TDF_AttributeIterator.hxx @@ -57,20 +57,16 @@ public: Standard_EXPORT void Initialize (const TDF_Label& aLabel, const Standard_Boolean withoutForgotten = Standard_True) ; - inline Standard_Boolean More() const; - Standard_EXPORT void Next() ; - inline Handle(TDF_Attribute) Value() const; + Standard_Boolean More() const { return myValue != NULL; } -protected: - - // Methods PROTECTED - // + Standard_EXPORT void Next(); + //! Return current value as handle. + Handle(TDF_Attribute) ValueHandle() const { return myValue; } - // Fields PROTECTED - // - + //! Return current value as pointer. + TDF_Attribute* Value() const { return myValue; } private: @@ -85,14 +81,4 @@ private: Standard_Boolean myWithoutForgotten; }; - -// other inline functions and methods (like "C++: function call" methods) -// - -inline Standard_Boolean TDF_AttributeIterator::More() const -{ return (myValue != 0L); } - -inline Handle(TDF_Attribute) TDF_AttributeIterator::Value() const -{ return myValue; } - #endif diff --git a/src/TDF/TDF_Label.cxx b/src/TDF/TDF_Label.cxx index 838a44b347..163e5514bb 100644 --- a/src/TDF/TDF_Label.cxx +++ b/src/TDF/TDF_Label.cxx @@ -53,31 +53,28 @@ void TDF_Label::Imported(const Standard_Boolean aStatus) const //purpose : Finds an attributes according to an ID. //======================================================================= -Standard_Boolean TDF_Label::FindAttribute -(const Standard_GUID& anID, - Handle(TDF_Attribute)& anAttribute) const +TDF_Attribute* TDF_Label::FindAttribute (const Standard_GUID& theID) const { if (IsNull()) throw Standard_NullObject("A null Label has no attribute."); - TDF_AttributeIterator itr (myLabelNode); // Without removed attributes. - for ( ; itr.More(); itr.Next()) { - if (itr.Value()->ID() == anID) { - anAttribute = itr.Value(); - return Standard_True; + // Without removed attributes. + for (TDF_AttributeIterator itr (myLabelNode); itr.More(); itr.Next()) + { + if (itr.Value()->ID() == theID) + { + return itr.Value(); } } - return Standard_False; + return NULL; } - //======================================================================= //function : FindAttribute //purpose : Finds an attributes according to an ID and a Transaction. //======================================================================= -Standard_Boolean TDF_Label::FindAttribute -(const Standard_GUID& anID, - const Standard_Integer aTransaction, - Handle(TDF_Attribute)& anAttribute) const +Standard_Boolean TDF_Label::FindAttribute (const Standard_GUID& anID, + const Standard_Integer aTransaction, + Handle(TDF_Attribute)& anAttribute) const { Handle(TDF_Attribute) locAtt; if (FindAttribute(anID, locAtt)) { diff --git a/src/TDF/TDF_Label.hxx b/src/TDF/TDF_Label.hxx index ab01f019f9..c23756c102 100644 --- a/src/TDF/TDF_Label.hxx +++ b/src/TDF/TDF_Label.hxx @@ -141,23 +141,42 @@ public: //! attribute is not in the structure. Standard_EXPORT void ResumeAttribute (const Handle(TDF_Attribute)& anAttribute) const; - //! Finds an attribute of the current label, according - //! to . - //! If anAttribute is not a valid one, false is returned. - //! + //! Finds an attribute of the current label, according to given ID. //! The method returns True if found, False otherwise. - //! //! A removed attribute cannot be found. - Standard_EXPORT Standard_Boolean FindAttribute (const Standard_GUID& anID, Handle(TDF_Attribute)& anAttribute) const; - + Standard_Boolean FindAttribute (const Standard_GUID& theID, + Handle(TDF_Attribute)& theAttribute) const + { + if (TDF_Attribute* anAttrib = FindAttribute (theID)) + { + theAttribute = anAttrib; + return Standard_True; + } + return Standard_False; + } + + //! Finds an attribute of the current label, according to given ID. + //! The method returns NULL if ID is not found. + //! A removed attribute cannot be found. + Standard_EXPORT TDF_Attribute* FindAttribute (const Standard_GUID& anID) const; + //! Safe variant of FindAttribute() for arbitrary type of argument template Standard_Boolean FindAttribute (const Standard_GUID& theID, Handle(T)& theAttr) const { - Handle(TDF_Attribute) anAttr = theAttr; + Handle(TDF_Attribute) anAttr; return FindAttribute (theID, anAttr) && ! (theAttr = Handle(T)::DownCast(anAttr)).IsNull(); } + //! Safe variant of FindAttribute() for arbitrary type of argument (pointer) + template + Standard_Boolean FindAttribute (const Standard_GUID& theID, T*& theAttr) const + { + TDF_Attribute* anAttr = FindAttribute (theID); + theAttr = dynamic_cast (anAttr); + return theAttr != NULL; + } + //! Finds an attribute of the current label, according //! to and . This attribute //! has/had to be a valid one for the given diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx index 3e15849613..629801ae5c 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -757,8 +757,21 @@ Standard_Boolean XCAFDoc_ShapeTool::IsSimpleShape (const TDF_Label& L) Standard_Boolean XCAFDoc_ShapeTool::IsReference (const TDF_Label& L) { - Handle(TDataStd_TreeNode) Node; - return L.FindAttribute(XCAFDoc::ShapeRefGUID(), Node) && Node->HasFather(); + static const Standard_GUID& aShapeGuid = XCAFDoc::ShapeRefGUID(); + static const Handle(Standard_Type) aDynType = STANDARD_TYPE(TDataStd_TreeNode); + if (TDF_Attribute* anAttrib = L.FindAttribute (aShapeGuid)) + { + if (anAttrib->IsKind (aDynType)) + { + TDataStd_TreeNode* aNode = (TDataStd_TreeNode* )anAttrib; + return aNode->HasFather(); + } + } + return Standard_False; + //return L.FindAttribute (aShapeGuid, aNode) + // && aNode->HasFather(); + //Handle(TDataStd_TreeNode) Node; + //return L.FindAttribute(XCAFDoc::ShapeRefGUID(), Node) && Node->HasFather(); } //=======================================================================