Commit | Line | Data |
---|---|---|
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> | |
ee5befae | 26 | #include <Message_MsgFile.hxx> |
6fe96f84 | 27 | #include <Resource_Manager.hxx> |
7fd59977 | 28 | |
6fe96f84 | 29 | #include <stdio.h> |
7fd59977 | 30 | |
ee5befae | 31 | #include "TObj_TObj_msg.pxx" |
32 | ||
92efcf78 | 33 | IMPLEMENT_STANDARD_RTTIEXT(TObj_Application,TDocStd_Application) |
34 | ||
7fd59977 | 35 | //======================================================================= |
36 | //function : GetInstance | |
37 | //purpose : | |
38 | //======================================================================= | |
39 | ||
40 | Handle(TObj_Application) TObj_Application::GetInstance() | |
41 | { | |
42 | static Handle(TObj_Application) anInstance = new TObj_Application; | |
43 | return anInstance; | |
44 | } | |
45 | ||
46 | //======================================================================= | |
47 | //function : TObj_Application | |
48 | //purpose : | |
49 | //======================================================================= | |
50 | ||
c24d4017 | 51 | TObj_Application::TObj_Application () : myIsError(Standard_False) |
7fd59977 | 52 | { |
ee5befae | 53 | if (!Message_MsgFile::HasMsg ("TObj_Appl_SUnknownFailure")) |
54 | { | |
55 | // load messages into global map on first instantiation | |
56 | Message_MsgFile::LoadFromString (TObj_TObj_msg, sizeof(TObj_TObj_msg) - 1); | |
57 | if (!Message_MsgFile::HasMsg ("TObj_Appl_SUnknownFailure")) | |
58 | { | |
9775fa61 | 59 | throw Standard_ProgramError("Critical Error - message resources for TObj_Application are invalid or undefined!"); |
ee5befae | 60 | } |
61 | } | |
62 | ||
7fd59977 | 63 | myMessenger = new Message_Messenger; |
7fd59977 | 64 | myIsVerbose = Standard_False; |
65 | } | |
66 | ||
7fd59977 | 67 | //======================================================================= |
68 | //function : ResourcesName | |
69 | //purpose : | |
70 | //======================================================================= | |
71 | ||
72 | Standard_CString TObj_Application::ResourcesName() | |
73 | { | |
74 | return Standard_CString("TObj"); | |
75 | } | |
76 | ||
77 | //======================================================================= | |
78 | //function : SaveDocument | |
79 | //purpose : Saving the OCAF document | |
80 | //======================================================================= | |
81 | ||
82 | Standard_Boolean TObj_Application::SaveDocument | |
be70005c | 83 | (const Handle(TDocStd_Document)& theSourceDoc, |
84 | const TCollection_ExtendedString& theTargetFile) | |
7fd59977 | 85 | { |
86 | myIsError = Standard_False; | |
1f9fb707 | 87 | PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, theTargetFile); |
15e8b082 | 88 | myIsError = aStatus != PCDM_SS_OK; |
7fd59977 | 89 | if (myIsError) |
90 | { | |
91 | switch (aStatus) | |
92 | { | |
15e8b082 | 93 | case PCDM_SS_DriverFailure: |
1f9fb707 | 94 | ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << theTargetFile); |
7fd59977 | 95 | break; |
15e8b082 | 96 | case PCDM_SS_WriteFailure: |
1f9fb707 | 97 | ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << theTargetFile); |
7fd59977 | 98 | break; |
15e8b082 | 99 | case PCDM_SS_Failure: |
1f9fb707 | 100 | ErrorMessage (Message_Msg("TObj_Appl_SFailure") << theTargetFile); |
15e8b082 | 101 | break; |
15e8b082 | 102 | case PCDM_SS_Doc_IsNull: |
1f9fb707 | 103 | ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << theTargetFile); |
15e8b082 M |
104 | break; |
105 | case PCDM_SS_No_Obj: | |
1f9fb707 | 106 | ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << theTargetFile); |
15e8b082 M |
107 | break; |
108 | case PCDM_SS_Info_Section_Error: | |
1f9fb707 | 109 | ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << theTargetFile); |
15e8b082 | 110 | break; |
7fd59977 | 111 | default: |
1f9fb707 | 112 | ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << theTargetFile); |
7fd59977 | 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 | ||
127 | Standard_Boolean TObj_Application::LoadDocument | |
be70005c | 128 | (const TCollection_ExtendedString& theSourceFile, |
129 | Handle(TDocStd_Document)& theTargetDoc) | |
7fd59977 | 130 | { |
131 | myIsError = Standard_False; | |
498ce76b | 132 | PCDM_ReaderStatus aStatus = PCDM_RS_ReaderException; |
7fd59977 | 133 | { |
134 | try | |
135 | { | |
1f9fb707 | 136 | aStatus = Open (theSourceFile, theTargetDoc); |
7fd59977 | 137 | } |
9775fa61 | 138 | catch (Standard_Failure const& anException) { |
0797d9d3 | 139 | #ifdef OCCT_DEBUG |
7fd59977 | 140 | ErrorMessage (Message_Msg("TObj_Appl_Exception") << |
9775fa61 | 141 | anException.GetMessageString()); |
7fd59977 | 142 | #endif |
9775fa61 | 143 | (void)anException; |
7fd59977 | 144 | } |
145 | } | |
15e8b082 | 146 | myIsError = aStatus != PCDM_RS_OK; |
7fd59977 | 147 | if (myIsError) |
148 | { | |
149 | switch (aStatus) | |
150 | { | |
15e8b082 | 151 | case PCDM_RS_UnknownDocument: |
1f9fb707 | 152 | ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << theSourceFile); |
7fd59977 | 153 | break; |
15e8b082 | 154 | case PCDM_RS_AlreadyRetrieved: |
1f9fb707 | 155 | ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << theSourceFile); |
7fd59977 | 156 | break; |
15e8b082 | 157 | case PCDM_RS_AlreadyRetrievedAndModified: |
1f9fb707 | 158 | ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << theSourceFile); |
7fd59977 | 159 | break; |
15e8b082 | 160 | case PCDM_RS_NoDriver: |
1f9fb707 | 161 | ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << theSourceFile); |
7fd59977 | 162 | break; |
15e8b082 | 163 | case PCDM_RS_UnknownFileDriver: |
1f9fb707 | 164 | ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << theSourceFile); |
7fd59977 | 165 | break; |
15e8b082 | 166 | case PCDM_RS_OpenError: |
1f9fb707 | 167 | ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << theSourceFile); |
7fd59977 | 168 | break; |
15e8b082 | 169 | case PCDM_RS_NoVersion: |
1f9fb707 | 170 | ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << theSourceFile); |
7fd59977 | 171 | break; |
15e8b082 | 172 | case PCDM_RS_NoModel: |
1f9fb707 | 173 | ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << theSourceFile); |
7fd59977 | 174 | break; |
15e8b082 | 175 | case PCDM_RS_NoDocument: |
1f9fb707 | 176 | ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << theSourceFile); |
7fd59977 | 177 | break; |
15e8b082 | 178 | case PCDM_RS_FormatFailure: |
1f9fb707 | 179 | ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << theSourceFile); |
7fd59977 | 180 | break; |
15e8b082 | 181 | case PCDM_RS_TypeNotFoundInSchema: |
1f9fb707 | 182 | ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << theSourceFile); |
7fd59977 | 183 | break; |
15e8b082 | 184 | case PCDM_RS_UnrecognizedFileFormat: |
1f9fb707 | 185 | ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << theSourceFile); |
7fd59977 | 186 | break; |
15e8b082 | 187 | case PCDM_RS_MakeFailure: |
1f9fb707 | 188 | ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << theSourceFile); |
7fd59977 | 189 | break; |
15e8b082 | 190 | case PCDM_RS_PermissionDenied: |
1f9fb707 | 191 | ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << theSourceFile); |
7fd59977 | 192 | break; |
15e8b082 | 193 | case PCDM_RS_DriverFailure: |
1f9fb707 | 194 | ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << theSourceFile); |
7fd59977 | 195 | break; |
498ce76b | 196 | case PCDM_RS_ReaderException: |
1f9fb707 | 197 | ErrorMessage (Message_Msg("TObj_Appl_RException") << theSourceFile); |
7fd59977 | 198 | break; |
199 | default: | |
1f9fb707 | 200 | ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << theSourceFile); |
7fd59977 | 201 | break; |
202 | } | |
203 | } | |
204 | ||
205 | // Release free memory | |
206 | Standard::Purge(); | |
207 | return myIsError ? Standard_False : Standard_True; | |
208 | } | |
209 | ||
210 | //======================================================================= | |
211 | //function : CreateNewDocument | |
212 | //purpose : | |
213 | //======================================================================= | |
214 | ||
215 | Standard_Boolean TObj_Application::CreateNewDocument | |
216 | (Handle(TDocStd_Document)& theDoc, | |
217 | const TCollection_ExtendedString& theFormat) | |
218 | { | |
219 | myIsError = Standard_False; | |
220 | ||
221 | // Create the Document | |
222 | NewDocument (theFormat, theDoc); | |
223 | ||
224 | return myIsError ? Standard_False : Standard_True; | |
225 | } | |
226 | ||
227 | //======================================================================= | |
228 | //function : ErrorMessage | |
229 | //purpose : | |
230 | //======================================================================= | |
231 | ||
232 | void TObj_Application::ErrorMessage (const TCollection_ExtendedString &theMsg, | |
233 | const Message_Gravity theLevel) | |
234 | { | |
235 | myMessenger->Send ( theMsg, theLevel ); | |
236 | } | |
237 |