00001
00002
00003
00004
00005 #include "MFCBase.h"
00006 #include "RwGRDoc.h"
00007
00008 #include "MessageBoxDLG.h"
00009 #include "ReadFilesDLG.h"
00010 #include "ProgressBarDLG.h"
00011
00012
00013 #ifdef _DEBUG
00014 #define new DEBUG_NEW
00015 #undef THIS_FILE
00016 static char THIS_FILE[] = __FILE__;
00017 #endif
00018
00019
00020 using namespace jbxwl;
00021
00022
00024
00025
00026 IMPLEMENT_DYNCREATE(CRwGRDoc, CExDocument)
00027
00028 CRwGRDoc::CRwGRDoc()
00029 {
00030
00031
00032 }
00033
00034
00035
00036 CRwGRDoc::~CRwGRDoc()
00037 {
00038 }
00039
00040
00041
00042 BEGIN_MESSAGE_MAP(CRwGRDoc, CExDocument)
00043
00044
00045
00046 END_MESSAGE_MAP()
00047
00048
00049
00050
00052
00053
00054 #ifdef _DEBUG
00055 void CRwGRDoc::AssertValid() const
00056 {
00057 CExDocument::AssertValid();
00058 }
00059
00060
00061
00062 void CRwGRDoc::Dump(CDumpContext& dc) const
00063 {
00064 CExDocument::Dump(dc);
00065 }
00066 #endif //_DEBUG
00067
00068
00069
00070
00072
00073
00074 void CRwGRDoc::Serialize(CArchive& ar)
00075 {
00076 if (ar.IsStoring())
00077 {
00078
00079 }
00080 else
00081 {
00082
00083 }
00084 }
00085
00086
00087
00088
00090
00091
00092 BOOL CRwGRDoc::ReadDataFile(LPCTSTR fname)
00093 {
00094 CString message = _T("");
00095 CString fnm = get_file_name_t(fname);
00096 CString err_fname = _T("");
00097 CmnHead hd;
00098
00099
00100 CProgressBarDLG* counter = NULL;
00101 counter = new CProgressBarDLG(IDD_PROGBAR, NULL, TRUE);
00102 if (counter!=NULL) {
00103 SetGlobalCounter(counter);
00104 }
00105
00106 init_CmnHead(&hd);
00107
00108
00109 if (multiSliceData) {
00110
00111 CReadFilesDLG* rsdlg = new CReadFilesDLG(fnm);
00112 if (rsdlg==NULL) return FALSE;
00113 if (rsdlg->DoModal()!=IDOK) {
00114 pFrame->cancelOperation = TRUE;
00115 pFrame->doneErrorMessage = TRUE;
00116 delete (rsdlg);
00117 return FALSE;
00118 }
00119 startNo = rsdlg->fromNum;
00120 endNo = rsdlg->toNum;
00121 CString mfname = rsdlg->fName;
00122 delete (rsdlg);
00123
00124 if (counter!=NULL) {
00125 CString mesg;
00126 mesg.LoadString(IDS_STR_RDNG_FILE);
00127 char* mbstr = ts2mbs(mesg);
00128 counter->Start(0, mbstr);
00129 ::free(mbstr);
00130 }
00131
00132 Title = mfname;
00133 char* fname_str = ts2mbs(mfname);
00134
00135
00136 hd = SetHeaderDLG.getCmnHead();
00137
00138 DEBUG_INFO("CRwGRDoc::ReadDataFile(): Multi Slice: file = %s, start = %d, end = %d\n", fname_str, startNo, endNo);
00139 msGraph = readGraphicSlices<sWord>(fname_str, startNo, endNo, &hd, true);
00140
00141 if (msGraph.state>=0 && msGraph.state!=Xabs(endNo-startNo)+1) {
00142 char* numf = numbering_name(fname_str, startNo+msGraph.state-1+Sign(endNo-startNo));
00143 err_fname = mbs2ts(numf);
00144 ::free(numf);
00145
00146 CString mesg, noti;
00147 noti.LoadString(IDS_STR_CNFRM_CNTNUE);
00148 mesg.LoadString(IDS_STR_ERR_OPEN_FILE);
00149 message = _T("CRwGRDoc::ReadDataFile():\n\n") + mesg + _T(" ") + err_fname;
00150 MessageBox(pFrame->m_hWnd, message, noti, MB_OK);
00151 }
00152 if (msGraph.state>0) msGraph.state = 0;
00153
00154 if (msGraph.isNull() && msGraph.state==JBXL_GRAPH_HEADER_ERROR) {
00155 err_fname = numbering_name_t(mfname, msGraph.zs);
00156 }
00157
00158 ::free(fname_str);
00159 }
00160
00161
00162 else {
00163 CString mesg;
00164 mesg.LoadString(IDS_STR_RDNG_FILE);
00165 char* mbstr = ts2mbs(mesg);
00166 if (counter!=NULL) counter->Start(0, mbstr);
00167 ::free(mbstr);
00168 Title = fnm;
00169 hd = SetHeaderDLG.getCmnHead();
00170
00171 char* fname_str = ts2mbs(fname);
00172 msGraph = readGraphicFile<sWord>(fname_str, &hd, true);
00173 ::free(fname_str);
00174 }
00175
00176
00177 this->infHead = getinfo_CmnHead(hd);
00178 this->colorMode = msGraph.color;
00179 free_CmnHead(&hd);
00180
00181
00182 if (counter!=NULL) {
00183 counter->Stop();
00184 ClearGlobalCounter();
00185 delete counter;
00186 }
00187
00188
00189 if (msGraph.isNull()) {
00190 CString mesg, noti;
00191
00192 if (msGraph.state==JBXL_GRAPH_OPFILE_ERROR) {
00193 mesg.LoadString(IDS_STR_ERR_OPEN_FILE);
00194 noti.LoadString(IDS_STR_ERROR);
00195 if (multiSliceData) {
00196 message = _T("CRwGRDoc::ReadDataFile():\n\n") + mesg + _T(" ") + err_fname;
00197 MessageBox(pFrame->m_hWnd, message, noti, MB_OK);
00198 }
00199 else {
00200 MessageBox(pFrame->m_hWnd, _T("CRwGRDoc::ReadDataFile():\n\n") + mesg, noti, MB_OK);
00201 }
00202 }
00203 else if (msGraph.state==JBXL_GRAPH_MEMORY_ERROR) {
00204 mesg.LoadString(IDS_STR_ERR_MEMORY);
00205 noti.LoadString(IDS_STR_ERROR);
00206 MessageBox(pFrame->m_hWnd, _T("CRwGRDoc::ReadDataFile():\n\n") + mesg, noti, MB_OK);
00207 }
00208 else if (msGraph.state==JBXL_GRAPH_CANCEL) {
00209 mesg.LoadString(IDS_STR_CANCEL_OPNFILE);
00210 noti.LoadString(IDS_STR_CANCEL);
00211 MessageBox(pFrame->m_hWnd, _T("CRwGRDoc::ReadDataFile():\n\n") + mesg, noti, MB_OK);
00212 pFrame->cancelOperation = TRUE;
00213 }
00214 else {
00215 mesg.LoadString(IDS_STR_ERR_UNKWN);
00216 noti.LoadString(IDS_STR_ERROR);
00217 MessageBox(pFrame->m_hWnd, _T("CRwGRDoc::ReadDataFile():\n\n") + mesg, noti, MB_OK);
00218 }
00219 pFrame->doneErrorMessage = TRUE;
00220
00221 return FALSE;
00222 }
00223
00224 return TRUE;
00225 }
00226
00227
00228
00229
00230
00231
00232 BOOL CRwGRDoc::MakeViewData()
00233 {
00234 CString mesg, noti;
00235
00236
00237 CProgressBarDLG* counter = NULL;
00238 if (msGraph.zs > 10) {
00239
00240 counter = new CProgressBarDLG(IDD_PROGBAR, NULL, TRUE);
00241 if (counter!=NULL) {
00242 mesg.LoadString(IDS_STR_TRNS_DISPDATA);
00243 SetGlobalCounter(counter);
00244 char* mbstr = ts2mbs(mesg);
00245 counter->Start(0, mbstr);
00246 ::free(mbstr);
00247 }
00248 }
00249
00250
00251 cmnHead = TranslateData();
00252
00253
00254 if (counter!=NULL) {
00255 counter->Stop();
00256 ClearGlobalCounter();
00257 delete counter;
00258 }
00259
00260
00261 if (cmnHead.kind==HEADER_NONE) {
00262 if (cmnHead.xsize==JBXL_GRAPH_MEMORY_ERROR) {
00263 mesg.LoadString(IDS_STR_ERR_MEMORY);
00264 noti.LoadString(IDS_STR_ERROR);
00265 MessageBox(pFrame->m_hWnd, _T("CRwGRDoc::MakeViewData():\n\n") + mesg, noti, MB_OK);
00266 }
00267 else if (cmnHead.xsize==JBXL_GRAPH_CANCEL) {
00268 mesg.LoadString(IDS_STR_CANCEL_TRNS_DATA);
00269 noti.LoadString(IDS_STR_CANCEL);
00270 MessageBox(pFrame->m_hWnd, _T("CRwGRDoc::MakeViewData():\n\n") + mesg, noti, MB_OK);
00271 pFrame->cancelOperation = TRUE;
00272 }
00273 else {
00274 mesg.LoadString(IDS_STR_ERR_UNKWN);
00275 noti.LoadString(IDS_STR_ERROR);
00276 MessageBox(pFrame->m_hWnd, _T("CRwGRDoc::MakeViewData():\n\n") + mesg, noti, MB_OK);
00277 }
00278 pFrame->doneErrorMessage = TRUE;
00279 return FALSE;
00280 }
00281
00282 return TRUE;
00283 }
00284
00285
00286
00287 CmnHead CRwGRDoc::TranslateData()
00288 {
00289 CmnHead chd;
00290
00291 int mode = 0;
00292 if (msGraph.color==GRAPH_COLOR_MONO || msGraph.color==GRAPH_COLOR_MONO16 ||
00293 msGraph.color==GRAPH_COLOR_RGB || msGraph.color==GRAPH_COLOR_BGR ||
00294 msGraph.color==GRAPH_COLOR_XRGB || msGraph.color==GRAPH_COLOR_ARGB || msGraph.color==GRAPH_COLOR_RGBA ||
00295 msGraph.color==GRAPH_COLOR_XBGR || msGraph.color==GRAPH_COLOR_ABGR || msGraph.color==GRAPH_COLOR_BGRA) {
00296
00297 mode = MG2CH_OCTET;
00298 }
00299 if (ctrlCntrst || msGraph.color==GRAPH_COLOR_MONO16) {
00300 mode |= MG2CH_CONTRAST;
00301 }
00302
00303 chd = copyMSGraph2CmnHead(msGraph, mode, true);
00304
00305 cMax = vMax = msGraph.max;
00306 cMin = vMin = msGraph.min;
00307
00308 if (msGraph.color==GRAPH_COLOR_RGB16 || msGraph.color==GRAPH_COLOR_ARGB16
00309 || msGraph.color==GRAPH_COLOR_RGBA16) {
00310
00311
00312
00313 }
00314 else if (!ctrlCntrst && cMin>=0 && cMax<=VIEW_8_MAX) {
00315 vMax = cMax = VIEW_8_MAX;
00316 vMin = cMin = 0;
00317 }
00318
00319 base = msGraph.base;
00320
00321 return chd;
00322 }
00323
00324