1 // Created on: 2004-11-23
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // The original implementation Copyright: (C) RINA S.p.A
18 #include <TObj_Application.hxx>
20 #include <Standard_SStream.hxx>
21 #include <Standard_ErrorHandler.hxx>
22 #include <TCollection_ExtendedString.hxx>
23 #include <TColStd_SequenceOfExtendedString.hxx>
24 #include <CDM_COutMessageDriver.hxx>
25 #include <Message_Msg.hxx>
28 IMPLEMENT_STANDARD_HANDLE(TObj_Application,TDocStd_Application)
29 IMPLEMENT_STANDARD_RTTIEXT(TObj_Application,TDocStd_Application)
31 //=======================================================================
32 //function : GetInstance
34 //=======================================================================
36 Handle(TObj_Application) TObj_Application::GetInstance()
38 static Handle(TObj_Application) anInstance = new TObj_Application;
42 //=======================================================================
43 //function : TObj_Application
45 //=======================================================================
47 TObj_Application::TObj_Application () : myIsError(Standard_False)
49 myMessenger = new Message_Messenger;
50 myMessageDriver = new CDM_COutMessageDriver;
51 myIsVerbose = Standard_False;
54 //=======================================================================
57 //=======================================================================
59 void TObj_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
61 theFormats.Append(TCollection_ExtendedString ("TObjXml"));
62 theFormats.Append(TCollection_ExtendedString ("TObjBin"));
65 //=======================================================================
66 //function : ResourcesName
68 //=======================================================================
70 Standard_CString TObj_Application::ResourcesName()
72 return Standard_CString("TObj");
75 //=======================================================================
76 //function : SaveDocument
77 //purpose : Saving the OCAF document
78 //=======================================================================
80 Standard_Boolean TObj_Application::SaveDocument
81 (const Handle(TDocStd_Document)& theSourceDoc,
82 const char* theTargetFile)
84 myIsError = Standard_False;
85 TCollection_ExtendedString aPath ((const Standard_CString)theTargetFile);
87 PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, aPath);
88 myIsError = aStatus != PCDM_SS_OK;
93 case PCDM_SS_DriverFailure:
94 ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << aPath);
96 case PCDM_SS_WriteFailure:
97 ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << aPath);
100 ErrorMessage (Message_Msg("TObj_Appl_SFailure") << aPath);
102 case PCDM_SS_Doc_IsNull:
103 ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << aPath);
106 ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << aPath);
108 case PCDM_SS_Info_Section_Error:
109 ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << aPath);
112 ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << aPath);
117 // Release free memory
119 return myIsError ? Standard_False : Standard_True;
122 //=======================================================================
123 //function : LoadDocument
124 //purpose : Loading the OCAF document
125 //=======================================================================
127 Standard_Boolean TObj_Application::LoadDocument
128 (const char* theSourceFile,
129 Handle(TDocStd_Document)& theTargetDoc)
131 myIsError = Standard_False;
132 TCollection_ExtendedString aPath ((const Standard_CString)theSourceFile);
134 PCDM_ReaderStatus aStatus = PCDM_RS_ReaderException;
138 aStatus = Open (aPath, theTargetDoc);
140 catch (Standard_Failure)
143 ErrorMessage (Message_Msg("TObj_Appl_Exception") <<
144 Standard_Failure::Caught()->GetMessageString());
148 myIsError = aStatus != PCDM_RS_OK;
153 case PCDM_RS_UnknownDocument:
154 ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << aPath);
156 case PCDM_RS_AlreadyRetrieved:
157 ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << aPath);
159 case PCDM_RS_AlreadyRetrievedAndModified:
160 ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << aPath);
162 case PCDM_RS_NoDriver:
163 ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath);
165 case PCDM_RS_UnknownFileDriver:
166 ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath);
168 case PCDM_RS_OpenError:
169 ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << aPath);
171 case PCDM_RS_NoVersion:
172 ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << aPath);
174 case PCDM_RS_NoModel:
175 ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << aPath);
177 case PCDM_RS_NoDocument:
178 ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << aPath);
180 case PCDM_RS_FormatFailure:
181 ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << aPath);
183 case PCDM_RS_TypeNotFoundInSchema:
184 ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << aPath);
186 case PCDM_RS_UnrecognizedFileFormat:
187 ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << aPath);
189 case PCDM_RS_MakeFailure:
190 ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << aPath);
192 case PCDM_RS_PermissionDenied:
193 ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << aPath);
195 case PCDM_RS_DriverFailure:
196 ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << aPath);
198 case PCDM_RS_ReaderException:
199 ErrorMessage (Message_Msg("TObj_Appl_RException") << aPath);
202 ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << aPath);
207 // Release free memory
209 return myIsError ? Standard_False : Standard_True;
212 //=======================================================================
213 //function : CreateNewDocument
215 //=======================================================================
217 Standard_Boolean TObj_Application::CreateNewDocument
218 (Handle(TDocStd_Document)& theDoc,
219 const TCollection_ExtendedString& theFormat)
221 myIsError = Standard_False;
223 // Create the Document
224 NewDocument (theFormat, theDoc);
226 return myIsError ? Standard_False : Standard_True;
229 //=======================================================================
230 //function : ErrorMessage
232 //=======================================================================
234 void TObj_Application::ErrorMessage (const TCollection_ExtendedString &theMsg,
235 const Message_Gravity theLevel)
237 myMessenger->Send ( theMsg, theLevel );