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