]> OCCT Git - occt-copy.git/commitdiff
0030739: Data Exchange - XCAFDoc_ShapeTool::IsComponent() is too slow CR30739
authorkgv <kgv@opencascade.com>
Thu, 23 May 2019 20:47:43 +0000 (23:47 +0300)
committerkgv <kgv@opencascade.com>
Thu, 23 May 2019 20:54:44 +0000 (23:54 +0300)
src/TDF/TDF_AttributeIterator.hxx
src/TDF/TDF_Label.cxx
src/TDF/TDF_Label.hxx
src/XCAFDoc/XCAFDoc_ShapeTool.cxx

index fa8622c5832eef0b067817e8c741010b696b72f6..dde66abe87b02144141294da137909e49cdd4a0e 100644 (file)
@@ -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
index 838a44b347ab10ce6e2364d2d3a36ce07a1f8edc..163e5514bb783f4d85fee575d9f636538764dd9d 100644 (file)
@@ -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)) {
index ab01f019f9102a2277715f6e04c5fda9cf625094..c23756c102a045c3949873a4352fa082e706222a 100644 (file)
@@ -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 <anID>.
-  //! 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 <class T> 
   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 <class T>
+  Standard_Boolean FindAttribute (const Standard_GUID& theID, T*& theAttr) const
+  {
+    TDF_Attribute* anAttr = FindAttribute (theID);
+    theAttr = dynamic_cast<T*> (anAttr);
+    return theAttr != NULL;
+  }
+
   //! Finds an attribute of the current label, according
   //! to <anID> and <aTransaction>. This attribute
   //! has/had to be a valid one for the given
index 3e15849613f7d7979db66e6fdde0c6bb088a1413..629801ae5c8fe31c45ed47f1555903da72f2280b 100644 (file)
@@ -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();
 }
 
 //=======================================================================