b311480e |
1 | // Created on: 2009-04-06 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2009-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <TDataXtd_Shape.ixx> |
17 | #include <TDataStd.hxx> |
18 | #include <TDataXtd.hxx> |
19 | #include <TDF_Label.hxx> |
20 | #include <BRep_Builder.hxx> |
21 | #include <TopoDS_Solid.hxx> |
22 | #include <TNaming_Builder.hxx> |
23 | #include <TNaming_NamedShape.hxx> |
24 | #include <TNaming_Tool.hxx> |
25 | #include <TNaming.hxx> |
26 | |
7fd59977 |
27 | //======================================================================= |
28 | //function : Find |
29 | //purpose : |
30 | //======================================================================= |
31 | |
32 | Standard_Boolean TDataXtd_Shape::Find (const TDF_Label& current, |
33 | Handle(TDataXtd_Shape)& S) |
34 | { |
35 | TDF_Label L = current; |
36 | Handle(TDataXtd_Shape) SA; |
37 | if (L.IsNull()) return Standard_False; |
302f96fb |
38 | for(;;) { |
7fd59977 |
39 | if(L.FindAttribute(TDataXtd_Shape::GetID(), SA)) break; |
40 | L = L.Father(); |
41 | if (L.IsNull()) break; |
42 | } |
43 | |
44 | |
45 | if (!SA.IsNull()) { |
46 | S = SA; |
47 | return Standard_True; |
48 | } |
49 | return Standard_False; |
50 | } |
51 | |
52 | |
53 | //======================================================================= |
54 | //function : New |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | Handle(TDataXtd_Shape) TDataXtd_Shape::New (const TDF_Label& label) |
59 | { |
60 | if (label.HasAttribute()) { |
61 | Standard_DomainError::Raise("TDataXtd_Shape::New : not an empty label"); |
62 | } |
63 | Handle(TDataXtd_Shape) A = new TDataXtd_Shape (); |
64 | label.AddAttribute(A); |
65 | return A; |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : Set |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | Handle(TDataXtd_Shape) TDataXtd_Shape::Set (const TDF_Label& label, const TopoDS_Shape& shape) |
74 | { |
75 | Handle(TDataXtd_Shape) A; |
76 | if (!label.FindAttribute(TDataXtd_Shape::GetID(),A)) { |
77 | A = TDataXtd_Shape::New (label); |
78 | } |
79 | |
7fd59977 |
80 | Handle(TNaming_NamedShape) aNS; |
81 | if(label.FindAttribute(TNaming_NamedShape::GetID(), aNS)) { |
82 | if(!aNS->Get().IsNull()) |
83 | if(aNS->Get() == shape) |
84 | return A; |
85 | } |
7fd59977 |
86 | |
87 | TNaming_Builder B(label); |
88 | B.Generated(shape); |
89 | return A; |
90 | } |
91 | |
92 | //======================================================================= |
93 | //function : Get |
94 | //purpose : |
95 | //======================================================================= |
96 | |
97 | TopoDS_Shape TDataXtd_Shape::Get (const TDF_Label& label) |
98 | { |
99 | TopoDS_Shape shape; |
100 | |
101 | Handle(TNaming_NamedShape) NS; |
102 | if( label.FindAttribute(TNaming_NamedShape::GetID(), NS)) { |
103 | shape = TNaming_Tool::GetShape(NS); |
104 | return shape; |
105 | } |
106 | |
107 | shape.Nullify(); |
108 | return shape; |
109 | } |
110 | |
111 | //======================================================================= |
112 | //function : GetID |
113 | //purpose : |
114 | //======================================================================= |
115 | |
116 | const Standard_GUID& TDataXtd_Shape::GetID() |
117 | { |
118 | static Standard_GUID TDataXtd_ShapeID("2a96b620-ec8b-11d0-bee7-080009dc3333"); |
119 | return TDataXtd_ShapeID; |
120 | } |
121 | |
122 | //======================================================================= |
123 | //function : TDataXtd_Shape |
124 | //purpose : |
125 | //======================================================================= |
126 | |
127 | TDataXtd_Shape::TDataXtd_Shape() |
128 | { |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : ID |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | const Standard_GUID& TDataXtd_Shape::ID() const |
137 | { return GetID(); } |
138 | |
139 | |
140 | //======================================================================= |
141 | //function : NewEmpty |
142 | //purpose : |
143 | //======================================================================= |
144 | |
145 | Handle(TDF_Attribute) TDataXtd_Shape::NewEmpty () const |
146 | { |
147 | return new TDataXtd_Shape(); |
148 | } |
149 | |
150 | //======================================================================= |
151 | //function : Restore |
152 | //purpose : |
153 | //======================================================================= |
154 | |
35e08fe8 |
155 | void TDataXtd_Shape::Restore(const Handle(TDF_Attribute)& ) |
7fd59977 |
156 | { |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : Paste |
161 | //purpose : |
162 | //======================================================================= |
163 | |
35e08fe8 |
164 | void TDataXtd_Shape::Paste (const Handle(TDF_Attribute)&, |
165 | const Handle(TDF_RelocationTable)&) const |
7fd59977 |
166 | { |
167 | } |
168 | |
169 | //======================================================================= |
170 | //function : References |
171 | //purpose : |
172 | //======================================================================= |
173 | |
35e08fe8 |
174 | void TDataXtd_Shape::References (const Handle(TDF_DataSet)&) const |
7fd59977 |
175 | { |
176 | } |
177 | |
178 | //======================================================================= |
179 | //function : Dump |
180 | //purpose : |
181 | //======================================================================= |
182 | |
183 | Standard_OStream& TDataXtd_Shape::Dump (Standard_OStream& anOS) const |
184 | { |
185 | anOS << "Shape"; |
186 | return anOS; |
187 | } |