0024624: Lost word in license statement in source files
[occt.git] / src / TObj / TObj_Application.cxx
CommitLineData
b311480e 1// Created on: 2004-11-23
2// Created by: Pavel TELKOV
973c2be1 3// Copyright (c) 2004-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// The original implementation Copyright: (C) RINA S.p.A
17
18#include <TObj_Application.hxx>
19
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>
26#include <stdio.h>
27
28IMPLEMENT_STANDARD_HANDLE(TObj_Application,TDocStd_Application)
29IMPLEMENT_STANDARD_RTTIEXT(TObj_Application,TDocStd_Application)
30
31//=======================================================================
32//function : GetInstance
33//purpose :
34//=======================================================================
35
36Handle(TObj_Application) TObj_Application::GetInstance()
37{
38 static Handle(TObj_Application) anInstance = new TObj_Application;
39 return anInstance;
40}
41
42//=======================================================================
43//function : TObj_Application
44//purpose :
45//=======================================================================
46
c24d4017 47TObj_Application::TObj_Application () : myIsError(Standard_False)
7fd59977 48{
49 myMessenger = new Message_Messenger;
50 myMessageDriver = new CDM_COutMessageDriver;
51 myIsVerbose = Standard_False;
52}
53
54//=======================================================================
55//function : Formats
56//purpose :
57//=======================================================================
58
59void TObj_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
60{
61 theFormats.Append(TCollection_ExtendedString ("TObjXml"));
62 theFormats.Append(TCollection_ExtendedString ("TObjBin"));
63}
64
65//=======================================================================
66//function : ResourcesName
67//purpose :
68//=======================================================================
69
70Standard_CString TObj_Application::ResourcesName()
71{
72 return Standard_CString("TObj");
73}
74
75//=======================================================================
76//function : SaveDocument
77//purpose : Saving the OCAF document
78//=======================================================================
79
80Standard_Boolean TObj_Application::SaveDocument
81 (const Handle(TDocStd_Document)& theSourceDoc,
82 const char* theTargetFile)
83{
84 myIsError = Standard_False;
85 TCollection_ExtendedString aPath ((const Standard_CString)theTargetFile);
86
15e8b082
M
87 PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, aPath);
88 myIsError = aStatus != PCDM_SS_OK;
7fd59977 89 if (myIsError)
90 {
91 switch (aStatus)
92 {
15e8b082 93 case PCDM_SS_DriverFailure:
7fd59977 94 ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << aPath);
95 break;
15e8b082 96 case PCDM_SS_WriteFailure:
7fd59977 97 ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << aPath);
98 break;
15e8b082
M
99 case PCDM_SS_Failure:
100 ErrorMessage (Message_Msg("TObj_Appl_SFailure") << aPath);
101 break;
15e8b082
M
102 case PCDM_SS_Doc_IsNull:
103 ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << aPath);
104 break;
105 case PCDM_SS_No_Obj:
106 ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << aPath);
107 break;
108 case PCDM_SS_Info_Section_Error:
109 ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << aPath);
110 break;
7fd59977 111 default:
112 ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << aPath);
113 break;
114 }
115 }
116
117 // Release free memory
118 Standard::Purge();
119 return myIsError ? Standard_False : Standard_True;
120}
121
122//=======================================================================
123//function : LoadDocument
124//purpose : Loading the OCAF document
125//=======================================================================
126
127Standard_Boolean TObj_Application::LoadDocument
128 (const char* theSourceFile,
129 Handle(TDocStd_Document)& theTargetDoc)
130{
131 myIsError = Standard_False;
132 TCollection_ExtendedString aPath ((const Standard_CString)theSourceFile);
133
498ce76b 134 PCDM_ReaderStatus aStatus = PCDM_RS_ReaderException;
7fd59977 135 {
136 try
137 {
138 aStatus = Open (aPath, theTargetDoc);
139 }
140 catch (Standard_Failure)
141 {
142#if defined(_DEBUG) || defined(DEB)
143 ErrorMessage (Message_Msg("TObj_Appl_Exception") <<
144 Standard_Failure::Caught()->GetMessageString());
145#endif
146 }
147 }
15e8b082 148 myIsError = aStatus != PCDM_RS_OK;
7fd59977 149 if (myIsError)
150 {
151 switch (aStatus)
152 {
15e8b082 153 case PCDM_RS_UnknownDocument:
7fd59977 154 ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << aPath);
155 break;
15e8b082 156 case PCDM_RS_AlreadyRetrieved:
7fd59977 157 ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << aPath);
158 break;
15e8b082 159 case PCDM_RS_AlreadyRetrievedAndModified:
7fd59977 160 ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << aPath);
161 break;
15e8b082 162 case PCDM_RS_NoDriver:
7fd59977 163 ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath);
164 break;
15e8b082 165 case PCDM_RS_UnknownFileDriver:
7fd59977 166 ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath);
167 break;
15e8b082 168 case PCDM_RS_OpenError:
7fd59977 169 ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << aPath);
170 break;
15e8b082 171 case PCDM_RS_NoVersion:
7fd59977 172 ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << aPath);
173 break;
15e8b082 174 case PCDM_RS_NoModel:
7fd59977 175 ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << aPath);
176 break;
15e8b082 177 case PCDM_RS_NoDocument:
7fd59977 178 ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << aPath);
179 break;
15e8b082 180 case PCDM_RS_FormatFailure:
7fd59977 181 ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << aPath);
182 break;
15e8b082 183 case PCDM_RS_TypeNotFoundInSchema:
7fd59977 184 ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << aPath);
185 break;
15e8b082 186 case PCDM_RS_UnrecognizedFileFormat:
7fd59977 187 ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << aPath);
188 break;
15e8b082 189 case PCDM_RS_MakeFailure:
7fd59977 190 ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << aPath);
191 break;
15e8b082 192 case PCDM_RS_PermissionDenied:
7fd59977 193 ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << aPath);
194 break;
15e8b082 195 case PCDM_RS_DriverFailure:
7fd59977 196 ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << aPath);
197 break;
498ce76b 198 case PCDM_RS_ReaderException:
7fd59977 199 ErrorMessage (Message_Msg("TObj_Appl_RException") << aPath);
200 break;
201 default:
202 ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << aPath);
203 break;
204 }
205 }
206
207 // Release free memory
208 Standard::Purge();
209 return myIsError ? Standard_False : Standard_True;
210}
211
212//=======================================================================
213//function : CreateNewDocument
214//purpose :
215//=======================================================================
216
217Standard_Boolean TObj_Application::CreateNewDocument
218 (Handle(TDocStd_Document)& theDoc,
219 const TCollection_ExtendedString& theFormat)
220{
221 myIsError = Standard_False;
222
223 // Create the Document
224 NewDocument (theFormat, theDoc);
225
226 return myIsError ? Standard_False : Standard_True;
227}
228
229//=======================================================================
230//function : ErrorMessage
231//purpose :
232//=======================================================================
233
234void TObj_Application::ErrorMessage (const TCollection_ExtendedString &theMsg,
235 const Message_Gravity theLevel)
236{
237 myMessenger->Send ( theMsg, theLevel );
238}
239