summaryrefslogtreecommitdiff
path: root/src/TObj/TObj_Application.cxx
blob: 52cbdcdef036a6c89394b31b59930ae901e42864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// File:        TObj_Application.cxx
// Created:     Tue Nov 23 11:08:43 2004
// Author:      Pavel TELKOV
// Copyright:   Open CASCADE  2007
// The original implementation Copyright: (C) RINA S.p.A

#include <TObj_Application.hxx>

#include <Standard_SStream.hxx>
#include <Standard_ErrorHandler.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
#include <CDM_COutMessageDriver.hxx>
#include <Message_Msg.hxx>
#include <stdio.h>

IMPLEMENT_STANDARD_HANDLE(TObj_Application,TDocStd_Application)
IMPLEMENT_STANDARD_RTTIEXT(TObj_Application,TDocStd_Application)

//=======================================================================
//function : GetInstance
//purpose  :
//=======================================================================

Handle(TObj_Application) TObj_Application::GetInstance()
{
  static Handle(TObj_Application) anInstance = new TObj_Application;
  return anInstance;
}

//=======================================================================
//function : TObj_Application
//purpose  : 
//=======================================================================

TObj_Application::TObj_Application ()
{
  myMessenger = new Message_Messenger;
  myMessageDriver = new CDM_COutMessageDriver;
  myIsVerbose = Standard_False;
}

//=======================================================================
//function : Formats
//purpose  : 
//=======================================================================

void TObj_Application::Formats(TColStd_SequenceOfExtendedString& theFormats) 
{
  theFormats.Append(TCollection_ExtendedString ("TObjXml"));
  theFormats.Append(TCollection_ExtendedString ("TObjBin"));
}

//=======================================================================
//function : ResourcesName
//purpose  : 
//=======================================================================

Standard_CString TObj_Application::ResourcesName()
{
  return Standard_CString("TObj");
}

//=======================================================================
//function : SaveDocument
//purpose  : Saving the OCAF document
//=======================================================================

Standard_Boolean TObj_Application::SaveDocument
                        (const Handle(TDocStd_Document)&   theSourceDoc,
                         const char*                       theTargetFile)
{
  myIsError = Standard_False;
  TCollection_ExtendedString aPath ((const Standard_CString)theTargetFile);

  PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, aPath);
  myIsError = aStatus != PCDM_SS_OK;
  if (myIsError)
  {
    switch (aStatus)
    {
    case PCDM_SS_DriverFailure:
      ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << aPath);
      break;
    case PCDM_SS_WriteFailure:
      ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << aPath);
      break;
    case PCDM_SS_Failure:
      ErrorMessage (Message_Msg("TObj_Appl_SFailure") << aPath);
      break;
    case PCDM_SS_DiskWritingFailure:
      ErrorMessage (Message_Msg("TObj_Appl_SDiskWritingFailure") << aPath);
      break;
    case PCDM_SS_Doc_IsNull:
      ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << aPath);
      break;
    case PCDM_SS_No_Obj:
      ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << aPath);
      break;
    case PCDM_SS_Info_Section_Error:
      ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << aPath);
      break;
    default:
      ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << aPath);
      break;
    }
  }

  // Release free memory
  Standard::Purge();
  return myIsError ? Standard_False : Standard_True;
}

//=======================================================================
//function : LoadDocument
//purpose  : Loading the OCAF document
//=======================================================================

Standard_Boolean TObj_Application::LoadDocument
                        (const char*                       theSourceFile,
                         Handle(TDocStd_Document)&         theTargetDoc)
{
  myIsError = Standard_False;
  TCollection_ExtendedString aPath ((const Standard_CString)theSourceFile);

  PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
  {
    try
    {
      aStatus = Open (aPath, theTargetDoc);
    }
    catch (Standard_Failure)
    {
#if defined(_DEBUG) || defined(DEB)
      ErrorMessage (Message_Msg("TObj_Appl_Exception") << 
                    Standard_Failure::Caught()->GetMessageString());
#endif
    }
  }
  myIsError = aStatus != PCDM_RS_OK;
  if (myIsError)
  {
    switch ((int)aStatus)
    {
    case PCDM_RS_UnknownDocument:
      ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << aPath);
      break;
    case PCDM_RS_AlreadyRetrieved:
      ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << aPath);
      break;
    case PCDM_RS_AlreadyRetrievedAndModified:
      ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << aPath);
      break;
    case PCDM_RS_NoDriver:
      ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath);
      break;
    case PCDM_RS_UnknownFileDriver:
      ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath);
      break;
    case PCDM_RS_OpenError:
      ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << aPath);
      break;
    case PCDM_RS_NoVersion:
      ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << aPath);
      break;
    case PCDM_RS_NoModel:
      ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << aPath);
      break;
    case PCDM_RS_NoDocument:
      ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << aPath);
      break;
    case PCDM_RS_FormatFailure:
      ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << aPath);
      break;
    case PCDM_RS_TypeNotFoundInSchema:
      ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << aPath);
      break;
    case PCDM_RS_UnrecognizedFileFormat:
      ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << aPath);
      break;
    case PCDM_RS_MakeFailure:
      ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << aPath);
      break;
    case PCDM_RS_PermissionDenied:
      ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << aPath);
      break;
    case PCDM_RS_DriverFailure:
      ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << aPath);
      break;
    case -1:
      ErrorMessage (Message_Msg("TObj_Appl_RException") << aPath);
      break;
    default:
      ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << aPath);
      break;
    }
  }

  // Release free memory
  Standard::Purge();
  return myIsError ? Standard_False : Standard_True;
}

//=======================================================================
//function : CreateNewDocument
//purpose  : 
//=======================================================================

Standard_Boolean TObj_Application::CreateNewDocument
                        (Handle(TDocStd_Document)&         theDoc,
                         const TCollection_ExtendedString& theFormat)
{
  myIsError = Standard_False;

  // Create the Document
  NewDocument (theFormat, theDoc);

  return myIsError ? Standard_False : Standard_True;
}

//=======================================================================
//function : ErrorMessage
//purpose  : 
//=======================================================================

void TObj_Application::ErrorMessage (const TCollection_ExtendedString &theMsg,
					 const Message_Gravity theLevel)
{
  myMessenger->Send ( theMsg, theLevel );
}