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:
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
//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)) {
//! 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
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();
}
//=======================================================================