1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Standard_GUID.hxx>
16 #include <Standard_Type.hxx>
17 #include <TCollection_HAsciiString.hxx>
18 #include <TDF_Attribute.hxx>
19 #include <TDF_Label.hxx>
20 #include <TDF_RelocationTable.hxx>
21 #include <XCAFDoc_Datum.hxx>
22 #include <TDataStd_AsciiString.hxx>
23 #include <TDataStd_IntegerArray.hxx>
24 #include <TDataStd_Integer.hxx>
25 #include <TDataStd_Real.hxx>
26 #include <TNaming_NamedShape.hxx>
27 #include <TNaming_Builder.hxx>
30 #include <XCAFDimTolObjects_DatumObject.hxx>
36 ChildLab_ModifierWithValue,
40 //=======================================================================
41 //function : XCAFDoc_Datum
43 //=======================================================================
44 XCAFDoc_Datum::XCAFDoc_Datum()
49 //=======================================================================
52 //=======================================================================
54 const Standard_GUID& XCAFDoc_Datum::GetID()
56 static Standard_GUID DID("58ed092e-44de-11d8-8776-001083004c77");
57 //static Standard_GUID ID("efd212e2-6dfd-11d4-b9c8-0060b0ee281b");
63 //=======================================================================
66 //=======================================================================
68 Handle(XCAFDoc_Datum) XCAFDoc_Datum::Set(const TDF_Label& theLabel,
69 const Handle(TCollection_HAsciiString)& theName,
70 const Handle(TCollection_HAsciiString)& theDescription,
71 const Handle(TCollection_HAsciiString)& theIdentification)
73 Handle(XCAFDoc_Datum) aDatum;
74 if (!theLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) {
75 aDatum = new XCAFDoc_Datum();
76 theLabel.AddAttribute(aDatum);
78 aDatum->Set(theName,theDescription,theIdentification);
82 //=======================================================================
85 //=======================================================================
87 Handle(XCAFDoc_Datum) XCAFDoc_Datum::Set(const TDF_Label& theLabel)
89 Handle(XCAFDoc_Datum) aDatum;
90 if (!theLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) {
91 aDatum = new XCAFDoc_Datum();
92 theLabel.AddAttribute(aDatum);
98 //=======================================================================
101 //=======================================================================
103 void XCAFDoc_Datum::Set(const Handle(TCollection_HAsciiString)& theName,
104 const Handle(TCollection_HAsciiString)& theDescription,
105 const Handle(TCollection_HAsciiString)& theIdentification)
109 myDescription = theDescription;
110 myIdentification = theIdentification;
114 //=======================================================================
117 //=======================================================================
119 Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetName() const
122 return new TCollection_HAsciiString();
126 //=======================================================================
127 //function : GetDescriptio7n
129 //=======================================================================
131 Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetDescription() const
133 return myDescription;
137 //=======================================================================
138 //function : GetIdentification
140 //=======================================================================
142 Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetIdentification() const
144 return myIdentification;
147 //=======================================================================
148 //function : SetObject
150 //=======================================================================
152 void XCAFDoc_Datum::SetObject(const Handle(XCAFDimTolObjects_DatumObject)& theObject)
155 if (!theObject->GetName().IsNull())
157 Handle(TDataStd_AsciiString) anAttName;
158 if(!Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), anAttName))
160 anAttName = new TDataStd_AsciiString();
161 Label().FindChild(ChildLab_Name).AddAttribute(anAttName);
163 anAttName->Set(theObject->GetName()->String());
167 Label().FindChild(ChildLab_Name).ForgetAllAttributes();
170 if(theObject->GetModifiers().Length() == 0)
172 Label().FindChild(ChildLab_Modifiers).ForgetAllAttributes();
176 Handle(TDataStd_IntegerArray) aModifiers;
177 if(!Label().FindChild(ChildLab_Modifiers).FindAttribute(TDataStd_IntegerArray::GetID(), aModifiers))
179 aModifiers = new TDataStd_IntegerArray();
180 Label().FindChild(ChildLab_Modifiers).AddAttribute(aModifiers);
182 Handle(TColStd_HArray1OfInteger) anArr = new TColStd_HArray1OfInteger(1,theObject->GetModifiers().Length());
183 for(Standard_Integer i = 1; i <= theObject->GetModifiers().Length(); i++)
184 anArr->SetValue(i,theObject->GetModifiers().Value(i));
185 aModifiers->ChangeArray(anArr);
188 XCAFDimTolObjects_DatumModifWithValue aM;
190 theObject->GetModifierWithValue(aM, aV);
191 if(aM != XCAFDimTolObjects_DatumModifWithValue_None)
193 Handle(TDataStd_Integer) aModifierWithValueM;
194 if(!Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Integer::GetID(), aModifierWithValueM))
196 aModifierWithValueM = new TDataStd_Integer();
197 Label().FindChild(ChildLab_ModifierWithValue).AddAttribute(aModifierWithValueM);
199 Handle(TDataStd_Real) aModifierWithValueV;
200 if(!Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Real::GetID(), aModifierWithValueV))
202 aModifierWithValueV = new TDataStd_Real();
203 Label().FindChild(ChildLab_ModifierWithValue).AddAttribute(aModifierWithValueV);
205 aModifierWithValueM->Set(aM);
206 aModifierWithValueV->Set(aV);
210 Label().FindChild(ChildLab_ModifierWithValue).ForgetAllAttributes();
213 if(!theObject->GetDatumTarget().IsNull())
215 TNaming_Builder tnBuild(Label().FindChild(ChildLab_DatumTarget));
216 tnBuild.Generated(theObject->GetDatumTarget());
220 Label().FindChild(ChildLab_DatumTarget).ForgetAllAttributes();
224 //=======================================================================
225 //function : GetObject
227 //=======================================================================
229 Handle(XCAFDimTolObjects_DatumObject) XCAFDoc_Datum::GetObject() const
231 Handle(XCAFDimTolObjects_DatumObject) anObj = new XCAFDimTolObjects_DatumObject();
233 Handle(TDataStd_AsciiString) anAttName;
234 if(Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), anAttName))
236 Handle(TCollection_HAsciiString) aStr = new TCollection_HAsciiString(anAttName->Get());
237 anObj->SetName(aStr);
240 Handle(TDataStd_IntegerArray) anArr;
241 if(Label().FindChild(ChildLab_Modifiers).FindAttribute(TDataStd_IntegerArray::GetID(), anArr)
242 && !anArr->Array().IsNull())
244 XCAFDimTolObjects_DatumModifiersSequence aModifiers;
245 for(Standard_Integer i = 1; i <= anArr->Length(); i++)
246 aModifiers.Append((XCAFDimTolObjects_DatumSingleModif)anArr->Value(i));
247 anObj->SetModifiers(aModifiers);
250 Handle(TDataStd_Integer) aModifierWithValueM;
251 if(Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Integer::GetID(), aModifierWithValueM))
253 Handle(TDataStd_Real) aModifierWithValueV;
254 if(Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Real::GetID(), aModifierWithValueV))
256 anObj->SetModifierWithValue((XCAFDimTolObjects_DatumModifWithValue)aModifierWithValueM->Get(),aModifierWithValueV->Get());
260 Handle(TNaming_NamedShape) aDatumTarget;
261 if(Label().FindChild(ChildLab_DatumTarget).FindAttribute(TNaming_NamedShape::GetID(), aDatumTarget))
263 anObj->SetDatumTarget(aDatumTarget->Get());
269 //=======================================================================
272 //=======================================================================
274 const Standard_GUID& XCAFDoc_Datum::ID() const
280 //=======================================================================
283 //=======================================================================
285 void XCAFDoc_Datum::Restore(const Handle(TDF_Attribute)& theWith)
287 myName = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetName();
288 myDescription = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetDescription();
289 myIdentification = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetIdentification();
293 //=======================================================================
294 //function : NewEmpty
296 //=======================================================================
298 Handle(TDF_Attribute) XCAFDoc_Datum::NewEmpty() const
300 return new XCAFDoc_Datum();
304 //=======================================================================
307 //=======================================================================
309 void XCAFDoc_Datum::Paste(const Handle(TDF_Attribute)& theInto,
310 const Handle(TDF_RelocationTable)& /*RT*/) const
312 Handle(XCAFDoc_Datum)::DownCast(theInto)->Set(myName,myDescription,myIdentification);