0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / XCAFDoc / XCAFDoc_MaterialTool.cxx
CommitLineData
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//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public version 2.1 as published
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.
b311480e 13
7fd59977 14#include <XCAFDoc_MaterialTool.ixx>
15
16#include <XCAFDoc.hxx>
17#include <XCAFDoc_Material.hxx>
18#include <XCAFDoc_DocumentTool.hxx>
19#include <TDataStd_TreeNode.hxx>
20#include <TDataStd_Name.hxx>
21#include <TDF_ChildIDIterator.hxx>
22
23
24//=======================================================================
25//function : XCAFDoc_MaterialTool
26//purpose :
27//=======================================================================
28
29XCAFDoc_MaterialTool::XCAFDoc_MaterialTool()
30{
31}
32
33
34//=======================================================================
35//function : Set
36//purpose :
37//=======================================================================
38
39Handle(XCAFDoc_MaterialTool) XCAFDoc_MaterialTool::Set(const TDF_Label& L)
40{
41 Handle(XCAFDoc_MaterialTool) A;
42 if (!L.FindAttribute (XCAFDoc_MaterialTool::GetID(), A)) {
43 A = new XCAFDoc_MaterialTool ();
44 L.AddAttribute(A);
45 A->myShapeTool = XCAFDoc_DocumentTool::ShapeTool(L);
46 }
47 return A;
48}
49
50
51//=======================================================================
52//function : GetID
53//purpose :
54//=======================================================================
55
56const Standard_GUID& XCAFDoc_MaterialTool::GetID()
57{
58 static Standard_GUID MatTblID ("efd212f9-6dfd-11d4-b9c8-0060b0ee281b");
59 return MatTblID;
60}
61
62
63//=======================================================================
64//function : BaseLabel
65//purpose :
66//=======================================================================
67
68TDF_Label XCAFDoc_MaterialTool::BaseLabel() const
69{
70 return Label();
71}
72
73
74//=======================================================================
75//function : ShapeTool
76//purpose :
77//=======================================================================
78
79const Handle(XCAFDoc_ShapeTool)& XCAFDoc_MaterialTool::ShapeTool()
80{
81 if(myShapeTool.IsNull())
82 myShapeTool = XCAFDoc_DocumentTool::ShapeTool(Label());
83 return myShapeTool;
84}
85
86
87//=======================================================================
88//function : IsMaterial
89//purpose :
90//=======================================================================
91
92Standard_Boolean XCAFDoc_MaterialTool::IsMaterial(const TDF_Label& lab) const
93{
94 Handle(XCAFDoc_Material) MatAttr;
95 if(lab.FindAttribute(XCAFDoc_Material::GetID(),MatAttr)) {
96 return Standard_True;
97 }
98 return Standard_False;
99}
100
101
102//=======================================================================
103//function : GetMaterialLabels
104//purpose :
105//=======================================================================
106
107void XCAFDoc_MaterialTool::GetMaterialLabels(TDF_LabelSequence& Labels) const
108{
109 Labels.Clear();
110 TDF_ChildIterator ChildIterator( Label() );
111 for (; ChildIterator.More(); ChildIterator.Next()) {
112 TDF_Label L = ChildIterator.Value();
113 if ( IsMaterial(L)) Labels.Append(L);
114 }
115}
116
117
118//=======================================================================
119//function : AddMaterial
120//purpose :
121//=======================================================================
122
123TDF_Label XCAFDoc_MaterialTool::AddMaterial(const Handle(TCollection_HAsciiString)& aName,
124 const Handle(TCollection_HAsciiString)& aDescription,
125 const Standard_Real aDensity,
126 const Handle(TCollection_HAsciiString)& aDensName,
127 const Handle(TCollection_HAsciiString)& aDensValType) const
128{
129 TDF_Label MatL;
130 TDF_TagSource aTag;
131 MatL = aTag.NewChild ( Label() );
132 XCAFDoc_Material::Set(MatL,aName,aDescription,aDensity,aDensName,aDensValType);
133 TDataStd_Name::Set(MatL,TCollection_AsciiString(aName->ToCString()));
134 return MatL;
135}
136
137
138//=======================================================================
139//function : SetMaterial
140//purpose :
141//=======================================================================
142
143void XCAFDoc_MaterialTool::SetMaterial(const TDF_Label& L,const TDF_Label& MatL) const
144{
145 // set reference
146 Handle(TDataStd_TreeNode) refNode, mainNode;
147 mainNode = TDataStd_TreeNode::Set ( MatL, XCAFDoc::MaterialRefGUID() );
148 refNode = TDataStd_TreeNode::Set ( L, XCAFDoc::MaterialRefGUID() );
149 refNode->Remove(); // abv: fix against bug in TreeNode::Append()
150 mainNode->Append(refNode);
151}
152
153
154//=======================================================================
155//function : SetMaterial
156//purpose :
157//=======================================================================
158
159void XCAFDoc_MaterialTool::SetMaterial(const TDF_Label& L,
160 const Handle(TCollection_HAsciiString)& aName,
161 const Handle(TCollection_HAsciiString)& aDescription,
162 const Standard_Real aDensity,
163 const Handle(TCollection_HAsciiString)& aDensName,
164 const Handle(TCollection_HAsciiString)& aDensValType) const
165{
166 TDF_Label MatL = AddMaterial(aName,aDescription,aDensity,aDensName,aDensValType);
167 SetMaterial(L,MatL);
168}
169
170
171//=======================================================================
172//function : GetMaterial
173//purpose :
174//=======================================================================
175
176Standard_Boolean XCAFDoc_MaterialTool::GetMaterial(const TDF_Label& MatL,
177 Handle(TCollection_HAsciiString)& aName,
178 Handle(TCollection_HAsciiString)& aDescription,
179 Standard_Real& aDensity,
180 Handle(TCollection_HAsciiString)& aDensName,
181 Handle(TCollection_HAsciiString)& aDensValType) const
182{
183 Handle(XCAFDoc_Material) MatAttr;
184 if(!MatL.FindAttribute(XCAFDoc_Material::GetID(),MatAttr)) {
185 return Standard_False;
186 }
187 aName = MatAttr->GetName();
188 aDescription = MatAttr->GetDescription();
189 aDensity = MatAttr->GetDensity();
190 aDensName = MatAttr->GetDensName();
191 aDensValType = MatAttr->GetDensValType();
192
193 return Standard_True;
194}
195
196
197//=======================================================================
198//function : GetDensityForShape
199//purpose :
200//=======================================================================
201
202Standard_Real XCAFDoc_MaterialTool::GetDensityForShape(const TDF_Label& ShapeL)
203{
204 Standard_Real Dens=0.0;
205 Handle(TDataStd_TreeNode) Node;
206 if ( ! ShapeL.FindAttribute ( XCAFDoc::MaterialRefGUID(), Node) ||
207 ! Node->HasFather() ) return Dens;
208 TDF_Label MatL = Node->Father()->Label();
209 Handle(XCAFDoc_Material) MatAttr;
210 if(!MatL.FindAttribute(XCAFDoc_Material::GetID(),MatAttr)) {
211 return Dens;
212 }
213 // defaul dimension fo density - gram/sm^3
214 // we transfer "sm" into "mm"
215 Dens = MatAttr->GetDensity()*0.001;
216 return Dens;
217}
218
219
220//=======================================================================
221//function : ID
222//purpose :
223//=======================================================================
224
225const Standard_GUID& XCAFDoc_MaterialTool::ID() const
226{
227 return GetID();
228}
229
230
231//=======================================================================
232//function : Restore
233//purpose :
234//=======================================================================
235
236void XCAFDoc_MaterialTool::Restore(const Handle(TDF_Attribute)& /*with*/)
237{
238}
239
240
241//=======================================================================
242//function : NewEmpty
243//purpose :
244//=======================================================================
245
246Handle(TDF_Attribute) XCAFDoc_MaterialTool::NewEmpty() const
247{
248 return new XCAFDoc_MaterialTool;
249}
250
251
252//=======================================================================
253//function : Paste
254//purpose :
255//=======================================================================
256
257void XCAFDoc_MaterialTool::Paste(const Handle(TDF_Attribute)& /*into*/,
258 const Handle(TDF_RelocationTable)& /*RT*/) const
259{
260}
261