1 // Created on: 1997-08-07
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <CDM_Document.hxx>
19 #include <FSD_CmpFile.hxx>
21 #include <PCDM_Document.hxx>
22 #include <PCDM_DriverError.hxx>
23 #include <PCDM_ReadWriter.hxx>
24 #include <PCDM_SequenceOfDocument.hxx>
25 #include <PCDM_StorageDriver.hxx>
26 #include <Resource_Manager.hxx>
27 #include <Standard_ErrorHandler.hxx>
28 #include <Standard_NoSuchObject.hxx>
29 #include <Standard_NotImplemented.hxx>
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>
39 IMPLEMENT_STANDARD_RTTIEXT(PCDM_StorageDriver,PCDM_Writer)
41 #define STORAGE_VERSION "STORAGE_VERSION:"
45 void PCDM_StorageDriver::Write(const Handle(CDM_Document)& aDocument, const TCollection_ExtendedString& aFileName)
47 Handle(Storage_Schema) theSchema = new Storage_Schema;
49 Handle(Storage_Data) theData = new Storage_Data;
51 static Standard_Boolean Failure;
52 Failure=Standard_False;
53 Standard_SStream aMsg; aMsg << "error during Make:";
54 PCDM_SequenceOfDocument thePersistentDocuments;
56 try { OCC_CATCH_SIGNALS Make(aDocument,thePersistentDocuments);}
57 catch (Standard_Failure const& anException) {
58 aMsg << anException<<(char)0;
59 Failure=Standard_True;
63 if(Failure) throw PCDM_DriverError(aMsg.str().c_str());
65 if(thePersistentDocuments.IsEmpty()) {
66 aMsg << "the storage driver: " << DynamicType()->Name() << "returned no documents to store" << (char) 0;
67 throw PCDM_DriverError(aMsg.str().c_str());
71 for(; i<=thePersistentDocuments.Length(); i++) {
72 theData->AddRoot(thePersistentDocuments(i));
75 TCollection_AsciiString ligne(STORAGE_VERSION);
76 ligne+=PCDM_ReadWriter::Writer()->Version();
77 theData->AddToUserInfo(ligne);
79 PCDM_ReadWriter::WriteFileFormat(theData,aDocument);
80 PCDM_ReadWriter::Writer()->WriteReferenceCounter(theData,aDocument);
81 PCDM_ReadWriter::Writer()->WriteReferences(theData,aDocument,aFileName);
82 PCDM_ReadWriter::Writer()->WriteExtensions(theData,aDocument);
83 PCDM_ReadWriter::Writer()->WriteVersion(theData,aDocument);
85 // add document comments
86 TColStd_SequenceOfExtendedString aComments;
87 aDocument->Comments(aComments);
88 Standard_Integer aLen = aComments.Length();
89 for (i = 1; i <= aLen; i++)
91 theData->AddToComments(aComments(i));
95 PCDM_ReadWriter::Open(theFile,aFileName,Storage_VSWrite);
96 theSchema->Write(theFile,theData);
99 if ( theData->ErrorStatus() != Storage_VSOk )
100 throw PCDM_DriverError(theData->ErrorStatusExtension().ToCString());
104 //=======================================================================
107 //=======================================================================
108 void PCDM_StorageDriver::Write (const Handle(CDM_Document)& /*aDocument*/, Standard_OStream& /*theOStream*/)
113 //Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument) {
114 Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& ) {
115 Handle(PCDM_Document) voidDocument;
116 Standard_SStream aMsg;
117 aMsg << "No Make method were implemented in this Driver" << DynamicType()->Name() << (char) 0;
118 throw Standard_NotImplemented(aMsg.str().c_str());
121 void PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument, PCDM_SequenceOfDocument& Documents) {
122 Documents.Append(Make(aDocument));
125 //=======================================================================
126 //function : SetFormat
128 //=======================================================================
130 void PCDM_StorageDriver::SetFormat (const TCollection_ExtendedString& aformat)
136 //=======================================================================
137 //function : GetFormat
139 //=======================================================================
141 TCollection_ExtendedString PCDM_StorageDriver::GetFormat () const
146 //=======================================================================
149 //=======================================================================
151 Standard_Boolean PCDM_StorageDriver::IsError () const
156 //=======================================================================
157 //function : SetIsError
159 //=======================================================================
160 void PCDM_StorageDriver::SetIsError(const Standard_Boolean theIsError)
162 myIsError = theIsError;
165 //=======================================================================
166 //function : GetStoreStatus
168 //=======================================================================
170 PCDM_StoreStatus PCDM_StorageDriver::GetStoreStatus () const
172 return myStoreStatus;
174 //=======================================================================
175 //function : SetStoreStatus
177 //=======================================================================
178 void PCDM_StorageDriver::SetStoreStatus(const PCDM_StoreStatus theStoreStatus)
180 myStoreStatus = theStoreStatus;