1 // Copyright (c) 2017-2018 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.
14 #include <XCAFDoc_Note.hxx>
17 #include <Standard_GUID.hxx>
18 #include <TDataXtd_Geometry.hxx>
19 #include <TDataXtd_Plane.hxx>
20 #include <TDataXtd_Point.hxx>
21 #include <TDF_AttributeIterator.hxx>
22 #include <TDF_ChildIterator.hxx>
23 #include <TDF_Label.hxx>
24 #include <TNaming_Builder.hxx>
25 #include <TNaming_NamedShape.hxx>
26 #include <TNaming_Tool.hxx>
27 #include <XCAFDoc.hxx>
28 #include <XCAFDoc_GraphNode.hxx>
30 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Note, TDF_Attribute)
40 // =======================================================================
43 // =======================================================================
45 XCAFDoc_Note::IsMine(const TDF_Label& theLabel)
47 return !Get(theLabel).IsNull();
50 // =======================================================================
51 // function : XCAFDoc_Note
53 // =======================================================================
54 XCAFDoc_Note::XCAFDoc_Note()
58 // =======================================================================
61 // =======================================================================
63 XCAFDoc_Note::Get(const TDF_Label& theLabel)
65 Handle(XCAFDoc_Note) aNote;
66 for (TDF_AttributeIterator anIt(theLabel); anIt.More(); anIt.Next())
68 aNote = Handle(XCAFDoc_Note)::DownCast(anIt.Value());
75 // =======================================================================
78 // =======================================================================
80 XCAFDoc_Note::Set(const TCollection_ExtendedString& theUserName,
81 const TCollection_ExtendedString& theTimeStamp)
85 myUserName = theUserName;
86 myTimeStamp = theTimeStamp;
89 // =======================================================================
90 // function : IsOrphan
92 // =======================================================================
93 Standard_Boolean XCAFDoc_Note::IsOrphan() const
95 Handle(XCAFDoc_GraphNode) aFather;
96 return !Label().FindAttribute(XCAFDoc::NoteRefGUID(), aFather) ||
97 (aFather->NbChildren() == 0);
100 // =======================================================================
101 // function : GetObject
103 // =======================================================================
104 Handle(XCAFNoteObjects_NoteObject) XCAFDoc_Note::GetObject() const
106 Handle(XCAFNoteObjects_NoteObject) anObj = new XCAFNoteObjects_NoteObject();
108 Handle(TDataXtd_Point) aPnt;
109 if (Label().FindChild(ChildLab_Pnt).FindAttribute(TDataXtd_Point::GetID(), aPnt))
112 if (TDataXtd_Geometry::Point(aPnt->Label(), aP))
118 Handle(TDataXtd_Plane) aPln;
119 if (Label().FindChild(ChildLab_Plane).FindAttribute(TDataXtd_Plane::GetID(), aPln))
122 if (TDataXtd_Geometry::Plane(aPln->Label(), aP))
124 anObj->SetPlane(aP.Position().Ax2());
128 Handle(TDataXtd_Point) aPntText;
129 if (Label().FindChild(ChildLab_PntText).FindAttribute(TDataXtd_Point::GetID(), aPntText))
132 if (TDataXtd_Geometry::Point(aPntText->Label(), aP))
134 anObj->SetPointText(aP);
138 Handle(TNaming_NamedShape) aNS;
139 TDF_Label aLPres = Label().FindChild(ChildLab_Presentation);
140 if (aLPres.FindAttribute(TNaming_NamedShape::GetID(), aNS))
142 TopoDS_Shape aPresentation = TNaming_Tool::GetShape(aNS);
143 if (!aPresentation.IsNull())
145 anObj->SetPresentation(aPresentation);
152 // =======================================================================
153 // function : SetObject
155 // =======================================================================
156 void XCAFDoc_Note::SetObject (const Handle(XCAFNoteObjects_NoteObject)& theObject)
160 for (TDF_ChildIterator anIter(Label()); anIter.More(); anIter.Next())
162 anIter.Value().ForgetAllAttributes();
165 if (theObject->HasPoint())
167 gp_Pnt aPnt1 = theObject->GetPoint();
168 TDataXtd_Point::Set (Label().FindChild (ChildLab_Pnt), aPnt1);
171 if (theObject->HasPlane())
173 gp_Ax2 anAx = theObject->GetPlane();
176 TDataXtd_Plane::Set (Label().FindChild (ChildLab_Plane), aP);
179 if (theObject->HasPointText())
181 gp_Pnt aPntText = theObject->GetPointText();
182 TDataXtd_Point::Set (Label().FindChild (ChildLab_PntText), aPntText);
185 TopoDS_Shape aPresentation = theObject->GetPresentation();
186 if (!aPresentation.IsNull())
188 TDF_Label aLPres = Label().FindChild (ChildLab_Presentation);
189 TNaming_Builder aBuilder (aLPres);
190 aBuilder.Generated (aPresentation);
194 // =======================================================================
195 // function : Restore
197 // =======================================================================
199 XCAFDoc_Note::Restore(const Handle(TDF_Attribute)& theAttr)
201 myUserName = Handle(XCAFDoc_Note)::DownCast(theAttr)->myUserName;
202 myTimeStamp = Handle(XCAFDoc_Note)::DownCast(theAttr)->myTimeStamp;
205 // =======================================================================
208 // =======================================================================
210 XCAFDoc_Note::Paste(const Handle(TDF_Attribute)& theAttrInto,
211 const Handle(TDF_RelocationTable)& /*theRT*/) const
213 Handle(XCAFDoc_Note)::DownCast(theAttrInto)->Set(myUserName, myTimeStamp);
216 // =======================================================================
219 // =======================================================================
221 XCAFDoc_Note::Dump(Standard_OStream& theOS) const
223 TDF_Attribute::Dump(theOS);
226 << (myUserName.IsEmpty() ? myUserName : "<anonymous>")
228 << (myTimeStamp.IsEmpty() ? myTimeStamp : "<unknown>")
233 //=======================================================================
234 //function : DumpJson
236 //=======================================================================
237 void XCAFDoc_Note::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
239 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
241 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
243 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myUserName)
244 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myTimeStamp)