0031353: TDocStd_Application does not have api to set progress indicator
[occt.git] / src / PCDM / PCDM_StorageDriver.cxx
CommitLineData
b311480e 1// Created on: 1997-08-07
2// Created by: Jean-Louis Frenkel
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <CDM_Document.hxx>
7fd59977 19#include <FSD_CmpFile.hxx>
42cf5bc1 20#include <PCDM.hxx>
21#include <PCDM_Document.hxx>
22#include <PCDM_DriverError.hxx>
7fd59977 23#include <PCDM_ReadWriter.hxx>
42cf5bc1 24#include <PCDM_SequenceOfDocument.hxx>
25#include <PCDM_StorageDriver.hxx>
7fd59977 26#include <Resource_Manager.hxx>
42cf5bc1 27#include <Standard_ErrorHandler.hxx>
28#include <Standard_NoSuchObject.hxx>
7fd59977 29#include <Standard_NotImplemented.hxx>
42cf5bc1 30#include <Standard_Type.hxx>
31#include <Storage_Data.hxx>
32#include <Storage_OpenMode.hxx>
33#include <Storage_Schema.hxx>
34#include <TCollection_AsciiString.hxx>
35#include <TCollection_ExtendedString.hxx>
36#include <TColStd_SequenceOfExtendedString.hxx>
7fd59977 37
42cf5bc1 38#include <locale.h>
92efcf78 39IMPLEMENT_STANDARD_RTTIEXT(PCDM_StorageDriver,PCDM_Writer)
40
7fd59977 41#define STORAGE_VERSION "STORAGE_VERSION:"
42
43
44
6d8f9f4a 45void PCDM_StorageDriver::Write (const Handle(CDM_Document)& aDocument,
46 const TCollection_ExtendedString& aFileName,
47 const Handle(Message_ProgressIndicator) &/*theProgress*/)
91322f44 48{
7ed7467d 49 Handle(Storage_Schema) theSchema = new Storage_Schema;
7fd59977 50
7fd59977 51 Handle(Storage_Data) theData = new Storage_Data;
52
53 static Standard_Boolean Failure;
54 Failure=Standard_False;
55 Standard_SStream aMsg; aMsg << "error during Make:";
56 PCDM_SequenceOfDocument thePersistentDocuments;
57 {
58 try { OCC_CATCH_SIGNALS Make(aDocument,thePersistentDocuments);}
9775fa61 59 catch (Standard_Failure const& anException) {
60 aMsg << anException<<(char)0;
7fd59977 61 Failure=Standard_True;
62 }
63 }
64
9775fa61 65 if(Failure) throw PCDM_DriverError(aMsg.str().c_str());
7fd59977 66
67 if(thePersistentDocuments.IsEmpty()) {
68 aMsg << "the storage driver: " << DynamicType()->Name() << "returned no documents to store" << (char) 0;
9775fa61 69 throw PCDM_DriverError(aMsg.str().c_str());
7fd59977 70 }
71
72 Standard_Integer i=1;
73 for(; i<=thePersistentDocuments.Length(); i++) {
74 theData->AddRoot(thePersistentDocuments(i));
75 }
76
77 TCollection_AsciiString ligne(STORAGE_VERSION);
78 ligne+=PCDM_ReadWriter::Writer()->Version();
79 theData->AddToUserInfo(ligne);
80
81 PCDM_ReadWriter::WriteFileFormat(theData,aDocument);
82 PCDM_ReadWriter::Writer()->WriteReferenceCounter(theData,aDocument);
83 PCDM_ReadWriter::Writer()->WriteReferences(theData,aDocument,aFileName);
84 PCDM_ReadWriter::Writer()->WriteExtensions(theData,aDocument);
85 PCDM_ReadWriter::Writer()->WriteVersion(theData,aDocument);
86
87 // add document comments
88 TColStd_SequenceOfExtendedString aComments;
89 aDocument->Comments(aComments);
90 Standard_Integer aLen = aComments.Length();
91 for (i = 1; i <= aLen; i++)
92 {
93 theData->AddToComments(aComments(i));
94 }
95
39c8dc70 96 Handle(FSD_CmpFile) theFile = new FSD_CmpFile;
7fd59977 97 PCDM_ReadWriter::Open(theFile,aFileName,Storage_VSWrite);
98 theSchema->Write(theFile,theData);
39c8dc70 99 theFile->Close();
7fd59977 100
7fd59977 101 if ( theData->ErrorStatus() != Storage_VSOk )
9775fa61 102 throw PCDM_DriverError(theData->ErrorStatusExtension().ToCString());
7fd59977 103}
104
4ff92abe 105
106//=======================================================================
107//function : Write
108//purpose :
109//=======================================================================
6d8f9f4a 110void PCDM_StorageDriver::Write (const Handle(CDM_Document)& /*aDocument*/,
111 Standard_OStream& /*theOStream*/,
112 const Handle(Message_ProgressIndicator)& /*theProgress*/)
4ff92abe 113{
114
115}
7fd59977 116
117//Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument) {
118Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& ) {
119 Handle(PCDM_Document) voidDocument;
120 Standard_SStream aMsg;
121 aMsg << "No Make method were implemented in this Driver" << DynamicType()->Name() << (char) 0;
9775fa61 122 throw Standard_NotImplemented(aMsg.str().c_str());
7fd59977 123}
124
125void PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument, PCDM_SequenceOfDocument& Documents) {
126 Documents.Append(Make(aDocument));
127}
128
129//=======================================================================
130//function : SetFormat
131//purpose :
132//=======================================================================
133
134void PCDM_StorageDriver::SetFormat (const TCollection_ExtendedString& aformat)
135{
136 myFormat = aformat;
137}
138
139
140//=======================================================================
141//function : GetFormat
142//purpose :
143//=======================================================================
144
145TCollection_ExtendedString PCDM_StorageDriver::GetFormat () const
146{
147 return myFormat;
148}
15e8b082
M
149
150//=======================================================================
151//function : IsError
152//purpose :
153//=======================================================================
154
155Standard_Boolean PCDM_StorageDriver::IsError () const
156{
157 return myIsError;
158}
159
160//=======================================================================
161//function : SetIsError
162//purpose :
163//=======================================================================
164void PCDM_StorageDriver::SetIsError(const Standard_Boolean theIsError)
165{
166 myIsError = theIsError;
167}
168
169//=======================================================================
170//function : GetStoreStatus
171//purpose :
172//=======================================================================
173
174PCDM_StoreStatus PCDM_StorageDriver::GetStoreStatus () const
175{
176 return myStoreStatus;
177}
178//=======================================================================
179//function : SetStoreStatus
180//purpose :
181//=======================================================================
182void PCDM_StorageDriver::SetStoreStatus(const PCDM_StoreStatus theStoreStatus)
183{
184 myStoreStatus = theStoreStatus;
185}