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 <Message_Msg.hxx>
25 #include <Message_MsgFile.hxx>
26 #include <Resource_Manager.hxx>
30 #include "TObj_TObj_msg.pxx"
32 IMPLEMENT_STANDARD_RTTIEXT(TObj_Application,TDocStd_Application)
34 //=======================================================================
35 //function : GetInstance
37 //=======================================================================
39 Handle(TObj_Application) TObj_Application::GetInstance()
41 static Handle(TObj_Application) anInstance = new TObj_Application;
45 //=======================================================================
46 //function : TObj_Application
48 //=======================================================================
50 TObj_Application::TObj_Application () : myIsError(Standard_False)
52 if (!Message_MsgFile::HasMsg ("TObj_Appl_SUnknownFailure"))
54 // load messages into global map on first instantiation
55 Message_MsgFile::LoadFromString (TObj_TObj_msg, sizeof(TObj_TObj_msg) - 1);
56 if (!Message_MsgFile::HasMsg ("TObj_Appl_SUnknownFailure"))
58 throw Standard_ProgramError("Critical Error - message resources for TObj_Application are invalid or undefined!");
62 myMessenger = new Message_Messenger;
63 myIsVerbose = Standard_False;
66 //=======================================================================
67 //function : ResourcesName
69 //=======================================================================
71 Standard_CString TObj_Application::ResourcesName()
73 return Standard_CString("TObj");
76 //=======================================================================
77 //function : SaveDocument
78 //purpose : Saving the OCAF document
79 //=======================================================================
81 Standard_Boolean TObj_Application::SaveDocument
82 (const Handle(TDocStd_Document)& theSourceDoc,
83 const TCollection_ExtendedString& theTargetFile)
85 myIsError = Standard_False;
86 PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, theTargetFile);
87 myIsError = aStatus != PCDM_SS_OK;
92 case PCDM_SS_DriverFailure:
93 ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << theTargetFile);
95 case PCDM_SS_WriteFailure:
96 ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << theTargetFile);
99 ErrorMessage (Message_Msg("TObj_Appl_SFailure") << theTargetFile);
101 case PCDM_SS_Doc_IsNull:
102 ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << theTargetFile);
105 ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << theTargetFile);
107 case PCDM_SS_Info_Section_Error:
108 ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << theTargetFile);
111 ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << theTargetFile);
116 // Release free memory
118 return myIsError ? Standard_False : Standard_True;
121 //=======================================================================
122 //function : LoadDocument
123 //purpose : Loading the OCAF document
124 //=======================================================================
126 Standard_Boolean TObj_Application::LoadDocument
127 (const TCollection_ExtendedString& theSourceFile,
128 Handle(TDocStd_Document)& theTargetDoc)
130 myIsError = Standard_False;
131 PCDM_ReaderStatus aStatus = PCDM_RS_ReaderException;
135 aStatus = Open (theSourceFile, theTargetDoc);
137 catch (Standard_Failure const& anException) {
139 ErrorMessage (Message_Msg("TObj_Appl_Exception") <<
140 anException.GetMessageString());
145 myIsError = aStatus != PCDM_RS_OK;
150 case PCDM_RS_UnknownDocument:
151 ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << theSourceFile);
153 case PCDM_RS_AlreadyRetrieved:
154 ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << theSourceFile);
156 case PCDM_RS_AlreadyRetrievedAndModified:
157 ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << theSourceFile);
159 case PCDM_RS_NoDriver:
160 ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << theSourceFile);
162 case PCDM_RS_UnknownFileDriver:
163 ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << theSourceFile);
165 case PCDM_RS_OpenError:
166 ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << theSourceFile);
168 case PCDM_RS_NoVersion:
169 ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << theSourceFile);
171 case PCDM_RS_NoModel:
172 ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << theSourceFile);
174 case PCDM_RS_NoDocument:
175 ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << theSourceFile);
177 case PCDM_RS_FormatFailure:
178 ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << theSourceFile);
180 case PCDM_RS_TypeNotFoundInSchema:
181 ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << theSourceFile);
183 case PCDM_RS_UnrecognizedFileFormat:
184 ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << theSourceFile);
186 case PCDM_RS_MakeFailure:
187 ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << theSourceFile);
189 case PCDM_RS_PermissionDenied:
190 ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << theSourceFile);
192 case PCDM_RS_DriverFailure:
193 ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << theSourceFile);
195 case PCDM_RS_ReaderException:
196 ErrorMessage (Message_Msg("TObj_Appl_RException") << theSourceFile);
199 ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << theSourceFile);
204 // Release free memory
206 return myIsError ? Standard_False : Standard_True;
209 //=======================================================================
210 //function : CreateNewDocument
212 //=======================================================================
214 Standard_Boolean TObj_Application::CreateNewDocument
215 (Handle(TDocStd_Document)& theDoc,
216 const TCollection_ExtendedString& theFormat)
218 myIsError = Standard_False;
220 // Create the Document
221 NewDocument (theFormat, theDoc);
223 return myIsError ? Standard_False : Standard_True;
226 //=======================================================================
227 //function : ErrorMessage
229 //=======================================================================
231 void TObj_Application::ErrorMessage (const TCollection_ExtendedString &theMsg,
232 const Message_Gravity theLevel)
234 myMessenger->Send ( theMsg, theLevel );