1 // Copyright (c) 2015 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 <StdLPersistent_Data.hxx>
15 #include <StdObjMgt_ReadData.hxx>
17 #include <TDF_Data.hxx>
18 #include <TDF_Attribute.hxx>
21 //! Create a transient label tree from persistent data
22 class StdLPersistent_Data::Parser
25 //! Start parsing a persistent data.
26 Parser (const TColStd_HArray1OfInteger& theLabels,
27 const StdLPersistent_HArray1OfPersistent& theAttributes)
28 : myLabelsIter (theLabels)
29 , myAttribIter (theAttributes) {}
31 //! Fill a transient label with data.
32 void FillLabel (TDF_Label theLabel)
36 // Read attributes count
38 Standard_Integer anAttribCount = myLabelsIter.Value();
40 // Add attributes to the label
41 for (i = 0; i < anAttribCount; i++)
43 // read persistent attribute
44 Handle(StdObjMgt_Persistent)& aPAttrib = myAttribIter.ChangeValue();
47 // create transient attribute and add it to the label
49 theLabel.AddAttribute (aPAttrib->CreateAttribute());
52 // Read child labels count
54 Standard_Integer aSubLabelsCount = myLabelsIter.Value();
56 // Create child labels
57 for (i = 0; i < aSubLabelsCount; i++)
59 // read tag of child label
61 Standard_Integer aSubLabelTag = myLabelsIter.Value();
63 // create and fill child label
64 TDF_Label aSubLabel = theLabel.FindChild (aSubLabelTag, Standard_True);
65 FillLabel (aSubLabel);
70 TColStd_HArray1OfInteger ::Iterator myLabelsIter;
71 StdLPersistent_HArray1OfPersistent::Iterator myAttribIter;
74 //=======================================================================
76 //purpose : Read persistent data from a file
77 //=======================================================================
78 void StdLPersistent_Data::Read (StdObjMgt_ReadData& theReadData)
80 theReadData >> myVersion >> myLabels >> myAttributes;
83 //=======================================================================
85 //purpose : Import transient data from the persistent data
86 //=======================================================================
87 Handle(TDF_Data) StdLPersistent_Data::Import() const
89 if (myLabels.IsNull() || myAttributes.IsNull())
92 // Create tree of labels and add empty transient attributes to them
93 Handle(TDF_Data) aData = new TDF_Data;
94 Parser (*myLabels->Array(), *myAttributes->Array()).FillLabel (aData->Root());
96 // Import transient attribuites from persistent data
97 StdLPersistent_HArray1OfPersistent::Iterator anAttribIter (*myAttributes->Array());
98 for (; anAttribIter.More(); anAttribIter.Next())
100 Handle(StdObjMgt_Persistent)& aPAttrib = anAttribIter.ChangeValue();
102 aPAttrib->ImportAttribute();