973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
7fd59977 |
13 | |
bc73b006 |
14 | #include <XCAFDoc_ShapeMapTool.hxx> |
42cf5bc1 |
15 | |
16 | #include <Standard_GUID.hxx> |
17 | #include <Standard_Type.hxx> |
18 | #include <TDF_Attribute.hxx> |
19 | #include <TDF_Label.hxx> |
20 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
21 | #include <TopoDS_Iterator.hxx> |
42cf5bc1 |
22 | #include <TopoDS_Shape.hxx> |
7fd59977 |
23 | |
92efcf78 |
24 | IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_ShapeMapTool,TDF_Attribute) |
25 | |
7fd59977 |
26 | #define AUTONAMING // automatically set names for labels |
27 | |
28 | // attribute methods ////////////////////////////////////////////////// |
29 | |
30 | //======================================================================= |
31 | //function : GetID |
32 | //purpose : |
33 | //======================================================================= |
34 | |
35 | const Standard_GUID& XCAFDoc_ShapeMapTool::GetID() |
36 | { |
37 | static Standard_GUID ShapeToolID ("3B913F4D-4A82-44ef-A0BF-9E01E9FF317A"); |
38 | return ShapeToolID; |
39 | } |
40 | |
41 | //======================================================================= |
42 | //function : Set |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | Handle(XCAFDoc_ShapeMapTool) XCAFDoc_ShapeMapTool::Set(const TDF_Label& L) |
47 | { |
48 | Handle(XCAFDoc_ShapeMapTool) A; |
49 | if (!L.FindAttribute (XCAFDoc_ShapeMapTool::GetID(), A)) { |
50 | A = new XCAFDoc_ShapeMapTool (); |
51 | L.AddAttribute(A); |
52 | } |
53 | return A; |
54 | } |
55 | |
56 | //======================================================================= |
57 | //function : ID |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | const Standard_GUID& XCAFDoc_ShapeMapTool::ID() const |
62 | { |
63 | return GetID(); |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : Restore |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | void XCAFDoc_ShapeMapTool::Restore(const Handle(TDF_Attribute)& /*with*/) |
72 | { |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : NewEmpty |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | Handle(TDF_Attribute) XCAFDoc_ShapeMapTool::NewEmpty() const |
81 | { |
82 | return new XCAFDoc_ShapeMapTool; |
83 | } |
84 | |
85 | //======================================================================= |
86 | //function : Paste |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | void XCAFDoc_ShapeMapTool::Paste (const Handle(TDF_Attribute)& /*into*/, |
91 | const Handle(TDF_RelocationTable)& /*RT*/) const |
92 | { |
93 | } |
94 | |
95 | //======================================================================= |
96 | //function : Constructor |
97 | //purpose : |
98 | //======================================================================= |
99 | |
100 | XCAFDoc_ShapeMapTool::XCAFDoc_ShapeMapTool() |
101 | { |
102 | } |
103 | |
104 | |
105 | //======================================================================= |
106 | //function : IsSubShape |
107 | //purpose : |
108 | //======================================================================= |
109 | |
110 | Standard_Boolean XCAFDoc_ShapeMapTool::IsSubShape(const TopoDS_Shape& sub) const |
111 | { |
112 | return myMap.Contains(sub); |
113 | } |
114 | |
115 | |
116 | //======================================================================= |
117 | //function : SetShape |
118 | //purpose : auxilary |
119 | //======================================================================= |
120 | static void AddSubShape(const TopoDS_Shape& S, |
121 | TopTools_IndexedMapOfShape& myMap) |
122 | { |
123 | myMap.Add(S); |
124 | for ( TopoDS_Iterator it(S); it.More(); it.Next() ) |
125 | AddSubShape(it.Value(),myMap); |
126 | } |
127 | |
128 | |
129 | //======================================================================= |
130 | //function : SetShape |
131 | //purpose : |
132 | //======================================================================= |
133 | |
134 | void XCAFDoc_ShapeMapTool::SetShape(const TopoDS_Shape& S) |
135 | { |
136 | myMap.Clear(); |
137 | for ( TopoDS_Iterator it(S); it.More(); it.Next() ) |
138 | AddSubShape(it.Value(),myMap); |
139 | |
140 | } |
141 | |
142 | |
143 | //======================================================================= |
144 | //function : GetMap |
145 | //purpose : |
146 | //======================================================================= |
147 | |
148 | const TopTools_IndexedMapOfShape& XCAFDoc_ShapeMapTool::GetMap() const |
149 | { |
150 | return myMap; |
151 | } |
bc73b006 |
152 | |
153 | //======================================================================= |
154 | //function : DumpJson |
155 | //purpose : |
156 | //======================================================================= |
157 | void XCAFDoc_ShapeMapTool::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
158 | { |
159 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
160 | |
161 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute) |
162 | |
163 | for (TopTools_IndexedMapOfShape::Iterator aMapIt (myMap); aMapIt.More(); aMapIt.Next()) |
164 | { |
165 | const TopoDS_Shape& aShape = aMapIt.Value(); |
166 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &aShape) |
167 | } |
168 | } |