0029902: Data Exchange, XCAF - provide extended Material definition for visualization...
[occt.git] / src / XCAFDoc / XCAFDoc_AssemblyItemRef.hxx
1 // Created on: 2017-02-16
2 // Created by: Sergey NIKONOV
3 // Copyright (c) 2000-2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _XCAFDoc_AssemblyItemRef_HeaderFile
17 #define _XCAFDoc_AssemblyItemRef_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21 #include <Standard_GUID.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <XCAFDoc_AssemblyItemId.hxx>
24
25 class TDF_Data;
26 class TDF_RelocationTable;
27
28 class XCAFDoc_AssemblyItemRef;
29 DEFINE_STANDARD_HANDLE(XCAFDoc_AssemblyItemRef, TDF_Attribute)
30
31 //! An attribute that describes a weak reference to an assembly item
32 //! or to a subshape or to an assembly label attribute.
33 class XCAFDoc_AssemblyItemRef : public TDF_Attribute
34 {
35
36 public:
37
38   DEFINE_STANDARD_RTTIEXT(XCAFDoc_AssemblyItemRef, TDF_Attribute);
39
40   Standard_EXPORT static const Standard_GUID& GetID();
41
42   //! Finds a reference attribute on the given label and returns it, if it is found
43   Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Get(const TDF_Label& theLabel);
44
45   //! @name Set reference attribute functions.
46   //! @{
47
48   //! Create (if not exist) a reference to an assembly item.
49   //! \param [in] theLabel  - label to add the attribute.
50   //! \param [in] theItemId - assembly item ID.
51   //! \return A handle to the attribute instance.
52   Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Set(const TDF_Label&              theLabel,
53                                                              const XCAFDoc_AssemblyItemId& theItemId);
54
55   //! Create (if not exist) a reference to an assembly item's label attribute.
56   //! \param [in] theLabel  - label to add the attribute.
57   //! \param [in] theItemId - assembly item ID.
58   //! \param [in] theGUID   - assembly item's label attribute ID.
59   //! \return A handle to the attribute instance.
60   Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Set(const TDF_Label&              theLabel,
61                                                              const XCAFDoc_AssemblyItemId& theItemId,
62                                                              const Standard_GUID&          theGUID);
63
64   //! Create (if not exist) a reference to an assembly item's subshape.
65   //! \param [in] theLabel      - label to add the attribute.
66   //! \param [in] theItemId     - assembly item ID.
67   //! \param [in] theShapeIndex - assembly item's subshape index.
68   //! \return A handle to the attribute instance.
69   Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Set(const TDF_Label&              theLabel,
70                                                              const XCAFDoc_AssemblyItemId& theItemId,
71                                                              const Standard_Integer        theShapeIndex);
72
73   //! @}
74
75   //! Creates an empty reference attribute.
76   Standard_EXPORT XCAFDoc_AssemblyItemRef();
77
78   //! Checks if the reference points to a really existing item in XDE document.
79   Standard_EXPORT Standard_Boolean IsOrphan() const;
80
81   //! @name Extra reference functions.
82   //! @{
83
84   //! Checks if the reference points on an item's shapeindex or attribute.
85   Standard_EXPORT Standard_Boolean HasExtraRef() const;
86
87   //! Checks is the reference points to an item's attribute.
88   Standard_EXPORT Standard_Boolean IsGUID() const;
89
90   //! Checks is the reference points to an item's subshape.
91   Standard_EXPORT Standard_Boolean IsSubshapeIndex() const;
92
93   //! Returns the assembly item's attribute that the reference points to.
94   //! If the reference doesn't point to an attribute, returns an empty GUID.
95   Standard_EXPORT Standard_GUID GetGUID() const;
96
97   //! Returns the assembly item's subshape that the reference points to.
98   //! If the reference doesn't point to a subshape, returns 0.
99   Standard_EXPORT Standard_Integer GetSubshapeIndex() const;
100
101   //! @}
102
103   //! Returns the assembly item ID that the reference points to.
104   Standard_EXPORT const XCAFDoc_AssemblyItemId& GetItem() const;
105   
106   //! @name Set reference data functions.
107   //! @{
108
109   //! Sets the assembly item ID that the reference points to.
110   //! Extra reference data (if any) will be cleared.
111   Standard_EXPORT void SetItem(const XCAFDoc_AssemblyItemId& theItemId);
112
113   //! Sets the assembly item ID from a list of label entries 
114   //! that the reference points to.
115   //! Extra reference data (if any) will be cleared.
116   Standard_EXPORT void SetItem(const TColStd_ListOfAsciiString& thePath);
117
118   //! Sets the assembly item ID from a formatted path 
119   //! that the reference points to.
120   //! Extra reference data (if any) will be cleared.
121   Standard_EXPORT void SetItem(const TCollection_AsciiString& theString);
122
123   //! Sets the assembly item's label attribute that the reference points to.
124   //! The base assembly item will not change.
125   Standard_EXPORT void SetGUID(const Standard_GUID& theAttrGUID);
126
127   //! Sets the assembly item's subshape that the reference points to.
128   //! The base assembly item will not change.
129   Standard_EXPORT void SetSubshapeIndex(Standard_Integer theShapeIndex);
130
131   //! @}
132
133   //! Reverts the reference to empty state.
134   Standard_EXPORT void ClearExtraRef();
135
136 public:
137
138   // Overrides TDF_Attribute pure virtuals
139   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
140   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
141   Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theAttrFrom) Standard_OVERRIDE;
142   Standard_EXPORT void Paste(const Handle(TDF_Attribute)&       theAttrInto,
143                              const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE;
144   Standard_EXPORT Standard_OStream& Dump(Standard_OStream& theOS) const Standard_OVERRIDE;
145
146 private:
147
148   XCAFDoc_AssemblyItemId  myItemId;   ///< Assembly item ID
149   Standard_Integer        myExtraRef; ///< Type of extra reference: subshape or attribute
150   TCollection_AsciiString myExtraId;  ///< Extra reference data
151
152 };
153
154 #endif // _XCAFDoc_AssemblyItemRef_HeaderFile