0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / StdStorage / StdStorage_RootData.cxx
CommitLineData
ec964372 1// Copyright (c) 2017 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <StdObjMgt_Persistent.hxx>
15#include <Standard_ErrorHandler.hxx>
ec964372 16#include <StdStorage_RootData.hxx>
17#include <StdStorage_Root.hxx>
18#include <Storage_BaseDriver.hxx>
19#include <Storage_StreamTypeMismatchError.hxx>
ec964372 20#include <TCollection_AsciiString.hxx>
21
25e59720 22IMPLEMENT_STANDARD_RTTIEXT(StdStorage_RootData, Standard_Transient)
ec964372 23
24StdStorage_RootData::StdStorage_RootData()
25 : myErrorStatus(Storage_VSOk)
26{
27}
28
39c8dc70 29Standard_Boolean StdStorage_RootData::Read(const Handle(Storage_BaseDriver)& theDriver)
ec964372 30{
31 // Check driver open mode
39c8dc70 32 if (theDriver->OpenMode() != Storage_VSRead
33 && theDriver->OpenMode() != Storage_VSReadWrite)
ec964372 34 {
35 myErrorStatus = Storage_VSModeError;
36 myErrorStatusExt = "OpenMode";
37 return Standard_False;
38 }
39
40 // Read root section
39c8dc70 41 myErrorStatus = theDriver->BeginReadRootSection();
ec964372 42 if (myErrorStatus != Storage_VSOk)
43 {
44 myErrorStatusExt = "BeginReadRootSection";
45 return Standard_False;
46 }
47
48 TCollection_AsciiString aRootName, aTypeName;
49 Standard_Integer aRef;
50
39c8dc70 51 Standard_Integer len = theDriver->RootSectionSize();
ec964372 52 for (Standard_Integer i = 1; i <= len; i++)
53 {
54 try
55 {
56 OCC_CATCH_SIGNALS
39c8dc70 57 theDriver->ReadRoot(aRootName, aRef, aTypeName);
ec964372 58 }
a738b534 59 catch (Storage_StreamTypeMismatchError const&)
ec964372 60 {
61 myErrorStatus = Storage_VSTypeMismatch;
62 myErrorStatusExt = "ReadRoot";
63 return Standard_False;
64 }
65
66 Handle(StdStorage_Root) aRoot = new StdStorage_Root(aRootName, aRef, aTypeName);
409095ba 67 myObjects.Add(aRootName, aRoot);
ec964372 68 }
69
39c8dc70 70 myErrorStatus = theDriver->EndReadRootSection();
ec964372 71 if (myErrorStatus != Storage_VSOk)
72 {
73 myErrorStatusExt = "EndReadRootSection";
74 return Standard_False;
75 }
76
77 return Standard_True;
78}
79
39c8dc70 80Standard_Boolean StdStorage_RootData::Write(const Handle(Storage_BaseDriver)& theDriver)
ec964372 81{
82 // Check driver open mode
39c8dc70 83 if (theDriver->OpenMode() != Storage_VSWrite
84 && theDriver->OpenMode() != Storage_VSReadWrite)
ec964372 85 {
86 myErrorStatus = Storage_VSModeError;
87 myErrorStatusExt = "OpenMode";
88 return Standard_False;
89 }
90
91 // Write root section
39c8dc70 92 myErrorStatus = theDriver->BeginWriteRootSection();
ec964372 93 if (myErrorStatus != Storage_VSOk)
94 {
95 myErrorStatusExt = "BeginWriteRootSection";
96 return Standard_False;
97 }
98
39c8dc70 99 theDriver->SetRootSectionSize(NumberOfRoots());
ec964372 100 for (StdStorage_MapOfRoots::Iterator anIt(myObjects); anIt.More(); anIt.Next())
101 {
102 const Handle(StdStorage_Root)& aRoot = anIt.Value();
103 try
104 {
105 OCC_CATCH_SIGNALS
39c8dc70 106 theDriver->WriteRoot(aRoot->Name(), aRoot->Reference(), aRoot->Type());
ec964372 107 }
a738b534 108 catch (Storage_StreamTypeMismatchError const&)
ec964372 109 {
110 myErrorStatus = Storage_VSTypeMismatch;
111 myErrorStatusExt = "ReadRoot";
112 return Standard_False;
113 }
114 }
115
39c8dc70 116 myErrorStatus = theDriver->EndWriteRootSection();
ec964372 117 if (myErrorStatus != Storage_VSOk)
118 {
119 myErrorStatusExt = "EndWriteRootSection";
120 return Standard_False;
121 }
122
123 return Standard_True;
124}
125
126Standard_Integer StdStorage_RootData::NumberOfRoots() const
127{
128 return myObjects.Extent();
129}
130
131void StdStorage_RootData::AddRoot(const Handle(StdStorage_Root)& aRoot)
132{
409095ba 133 myObjects.Add(aRoot->Name(), aRoot);
ec964372 134 aRoot->myRef = myObjects.Size();
135}
136
137Handle(StdStorage_HSequenceOfRoots) StdStorage_RootData::Roots() const
138{
139 Handle(StdStorage_HSequenceOfRoots) anObjectsSeq = new StdStorage_HSequenceOfRoots;
140 StdStorage_DataMapIteratorOfMapOfRoots it(myObjects);
141
142 for (; it.More(); it.Next()) {
143 anObjectsSeq->Append(it.Value());
144 }
145
146 return anObjectsSeq;
147}
148
149Handle(StdStorage_Root) StdStorage_RootData::Find(const TCollection_AsciiString& aName) const
150{
151 Handle(StdStorage_Root) p;
409095ba 152 if (myObjects.Contains(aName)) {
153 p = myObjects.FindFromKey(aName);
ec964372 154 }
155
156 return p;
157}
158
159Standard_Boolean StdStorage_RootData::IsRoot(const TCollection_AsciiString& aName) const
160{
409095ba 161 return myObjects.Contains(aName);
ec964372 162}
163
164void StdStorage_RootData::RemoveRoot(const TCollection_AsciiString& aName)
165{
409095ba 166 if (myObjects.Contains(aName)) {
167 myObjects.ChangeFromKey(aName)->myRef = 0;
168 myObjects.RemoveKey(aName);
ec964372 169 Standard_Integer aRef = 1;
170 for (StdStorage_MapOfRoots::Iterator anIt(myObjects); anIt.More(); anIt.Next(), ++aRef)
171 anIt.ChangeValue()->myRef = aRef;
172 }
173}
174
175void StdStorage_RootData::Clear()
176{
177 for (StdStorage_MapOfRoots::Iterator anIt(myObjects); anIt.More(); anIt.Next())
178 anIt.ChangeValue()->myRef = 0;
179
180 myObjects.Clear();
181}
182
183Storage_Error StdStorage_RootData::ErrorStatus() const
184{
185 return myErrorStatus;
186}
187
188void StdStorage_RootData::SetErrorStatus(const Storage_Error anError)
189{
190 myErrorStatus = anError;
191}
192
193void StdStorage_RootData::ClearErrorStatus()
194{
195 myErrorStatus = Storage_VSOk;
196 myErrorStatusExt.Clear();
197}
198
199TCollection_AsciiString StdStorage_RootData::ErrorStatusExtension() const
200{
201 return myErrorStatusExt;
202}
203
204void StdStorage_RootData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
205{
206 myErrorStatusExt = anErrorExt;
207}