// RGSMRKView.cpp : implementation of the CRGSMRKView class // #include "stdafx.h" #include "LeadRaster.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CRGSMRKApp theApp; #define SRC_COPY ((CombineConstants)(CB_DST_0 | CB_SRC_NOP | CB_OP_OR)) ///////////////////////////////////////////////////////////////////////////// // CRGSMRKView IMPLEMENT_DYNCREATE(CRGSMRKView, CFormView) BEGIN_MESSAGE_MAP(CRGSMRKView, CFormView) //{{AFX_MSG_MAP(CRGSMRKView) ON_WM_SIZE() ON_WM_DESTROY() ON_COMMAND(ID_IMAGE_REF_DATA, OnImageNewRefData) ON_COMMAND(IDM_EDIT_CANCELRGN, OnCancelrgn) ON_UPDATE_COMMAND_UI(IDM_EDIT_CANCELRGN, OnUpdateEditCancelrgn) ON_COMMAND(ID_EDIT_COPY, OnEditCopy) ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste) ON_COMMAND(ID_IMAGE_DETC_DATA, OnImageDetcData) ON_UPDATE_COMMAND_UI(ID_IMAGE_DETC_DATA, OnUpdateImageDetcData) ON_COMMAND(ID_IMAGE_COMP_DATA, OnImageCompData) ON_UPDATE_COMMAND_UI(ID_IMAGE_COMP_DATA, OnUpdateImageCompData) ON_COMMAND(ID_IMAGE_APPLY_TRANS, OnImageApplyTrans) ON_UPDATE_COMMAND_UI(ID_IMAGE_APPLY_TRANS, OnUpdateImageApplyTrans) ON_COMMAND(IDM_REFDATA_SAVE, OnRefdataSave) ON_UPDATE_COMMAND_UI(IDM_REFDATA_SAVE, OnUpdateRefdataSave) ON_COMMAND(IDM_REFDATA_LOAD, OnRefdataLoad) ON_UPDATE_COMMAND_UI(IDM_REFDATA_LOAD, OnUpdateRefdataLoad) ON_COMMAND(ID_FILE_SAVE, OnFileSave) ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave) ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE, OnUpdateFileClose) ON_UPDATE_COMMAND_UI(ID_APP_EXIT, OnUpdateAppExit) ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy) ON_UPDATE_COMMAND_UI(ID_IMAGE_REF_DATA, OnUpdateImageRefData) ON_UPDATE_COMMAND_UI(ID_WINDOW_NEW, OnUpdateWindowNew) ON_UPDATE_COMMAND_UI(ID_WINDOW_CASCADE, OnUpdateWindowCascade) ON_UPDATE_COMMAND_UI(ID_WINDOW_TILE_HORZ, OnUpdateWindowTileHorz) ON_UPDATE_COMMAND_UI(ID_WINDOW_ARRANGE, OnUpdateWindowArrange) ON_COMMAND(ID_EDIT_IMAGEINVERSE, OnEditImageInverse) ON_UPDATE_COMMAND_UI(ID_EDIT_IMAGEINVERSE, OnUpdateEditImageinverse) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRGSMRKView construction/destruction CRGSMRKView::CRGSMRKView() : CFormView(CRGSMRKView::IDD) { m_pRegMarkDlg = NULL; theApp.m_bDetected = FALSE; theApp.m_bApplyTrans = FALSE; theApp.m_bHasBeenApplied = FALSE; } CRGSMRKView::~CRGSMRKView() { } void CRGSMRKView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRGSMRKView) DDX_Control(pDX, IDC_LEADRASTERVIEW1, m_RasterView); //}}AFX_DATA_MAP } BOOL CRGSMRKView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } void CRGSMRKView::OnInitialUpdate() { CFormView::OnInitialUpdate(); CRGSMRKDoc *pDoc = (CRGSMRKDoc *)GetDocument(); ILEADRaster *pRaster =pDoc->m_pRaster; pRaster->RefBitmap = TRUE; m_RasterView.GetRaster().SetBitmap(pRaster->Bitmap); int xExt = (int)pRaster->BitmapWidth, yExt = (int)pRaster->BitmapHeight; // Make the CLead control to fit the bitmap and disable CLead's scrolling // Make the form scroll if the window becomes smaller than the bitmap SetScrollSizes(MM_TEXT,CSize(xExt,yExt)); // Make the window fit the image GetParentFrame()->RecalcLayout(); ResizeParentToFit(); // now disable the scroll bars SetScrollSizes(MM_TEXT,CSize(1,1)); m_RasterView.SetBackErase(FALSE); } ///////////////////////////////////////////////////////////////////////////// // CRGSMRKView diagnostics #ifdef _DEBUG void CRGSMRKView::AssertValid() const { CFormView::AssertValid(); } void CRGSMRKView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CRGSMRKDoc* CRGSMRKView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRGSMRKDoc))); return (CRGSMRKDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CRGSMRKView message handlers void CRGSMRKView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); if( IsWindow(m_RasterView.m_hWnd) ) { m_RasterView.SetBackErase(FALSE); m_RasterView.MoveWindow(0, 0, cx, cy); } } void CRGSMRKView::OnDraw(CDC* pDC) { } void CRGSMRKView::OnDestroy() { CFormView::OnDestroy(); theApp.m_pRasterFileDlg->Bitmap = 0; } void CRGSMRKView::OnImageNewRefData() { theApp.FreeDlgData(); if(m_RasterView.GetRaster().GetHasRgn()) m_RasterView.GetRaster().FreeRgn(); CRefDataDlg RefDataDlg; RefDataDlg.DoModal(); } BOOL CRGSMRKView::AddData() { int nNumberOfMarks = theApp.m_RefDataDlg.nNumber; int nRet,i; theApp.m_pRasterProcess->MarksCount = nNumberOfMarks; for(i = 0; i < nNumberOfMarks; i++) { theApp.m_pRasterProcess->GetMark(i)->Type = (MarkTypeConstants)theApp.m_RefDataDlg.nMarkType; theApp.m_pRasterProcess->GetMark(i)->Height = theApp.m_RefDataDlg.nHeight; theApp.m_pRasterProcess->GetMark(i)->Width = theApp.m_RefDataDlg.nWidth; theApp.m_pRasterProcess->GetMark(i)->MaxScale = theApp.m_RefDataDlg.nMaxSizeRatio; theApp.m_pRasterProcess->GetMark(i)->MinScale = theApp.m_RefDataDlg.nMinSizeRatio; theApp.m_pRasterProcess->GetMark(i)->Top = theApp.m_RefDataDlg.pRects[i].top; theApp.m_pRasterProcess->GetMark(i)->Left = theApp.m_RefDataDlg.pRects[i].left; theApp.m_pRasterProcess->GetMark(i)->Bottom = theApp.m_RefDataDlg.pRects[i].bottom; theApp.m_pRasterProcess->GetMark(i)->Right = theApp.m_RefDataDlg.pRects[i].right; theApp.m_pRasterProcess->PutMarkPointX(i,theApp.m_RefDataDlg.pPoints[i].x); theApp.m_pRasterProcess->PutMarkPointY(i,theApp.m_RefDataDlg.pPoints[i].y); theApp.m_pRasterProcess->GetMark(i)->NumberOfExpectedMarks = 1; } nRet = theApp.m_pRasterProcess->GetMarksCenterMass(m_RasterView.GetRaster()); if(nRet == 0) { for(i = 0; i < nNumberOfMarks; i++) { int x,y; x = theApp.m_pRasterProcess->GetMarkCMPointX(i); y = theApp.m_pRasterProcess->GetMarkCMPointY(i); theApp.m_pRasterProcess->PutReferencePointsX(i,x); theApp.m_pRasterProcess->PutReferencePointsY(i,y); } theApp.m_bRefDone = TRUE; theApp.m_bDetected = FALSE; theApp.m_bApplyTrans = FALSE; } return TRUE; } BEGIN_EVENTSINK_MAP(CRGSMRKView, CFormView) //{{AFX_EVENTSINK_MAP(CRGSMRKView) ON_EVENT(CRGSMRKView, IDC_LEADRASTERVIEW1, 4 /* MouseDown */, OnLeadRasterViewMouseDown, VTS_I2 VTS_I2 VTS_R4 VTS_R4) ON_EVENT(CRGSMRKView, IDC_LEADRASTERVIEW1, 5 /* MouseUp */, OnLeadRasterViewMouseUp, VTS_I2 VTS_I2 VTS_R4 VTS_R4) ON_EVENT(CRGSMRKView, IDC_LEADRASTERVIEW1, 3 /* MouseMove */, OnLeadRasterViewMouseMove, VTS_I2 VTS_I2 VTS_R4 VTS_R4) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CRGSMRKView::OnLeadRasterViewMouseDown(short Button, short Shift, float x, float y) { if(theApp.m_bAddingTShape || theApp.m_bAddingArea) { if(theApp.m_bAddingArea) { m_RasterView.SetRgnMarkingMode (RGNMARK_RECT); } m_RasterView.SetRgnFrameType(RGNFRAME_ANIMATED); return; } if( Button != 1 ) return; /* nothing to do! */ } void CRGSMRKView::OnLeadRasterViewMouseUp(short Button, short Shift, float x, float y) { int nRet = 0; RECT rcRef; BOOL bSelected = FALSE; if (Button == 1 && m_RasterView.GetRaster().GetBitmap() != 0) { if(theApp.m_bAddingArea) { m_RasterView.SetRgnMarkingMode (RGNMARK_RECT); rcRef.top = (long)m_RasterView.GetRaster().GetRgnTop(); rcRef.left = (long)m_RasterView.GetRaster().GetRgnLeft(); rcRef.bottom = (long)m_RasterView.GetRaster().GetRgnHeight() + rcRef.top; rcRef.right= (long)m_RasterView.GetRaster().GetRgnWidth() + rcRef.left; if(theApp.m_MarksInfo.rcMarkRect.top > rcRef.top && theApp.m_MarksInfo.rcMarkRect.top < rcRef.bottom && theApp.m_MarksInfo.rcMarkRect.bottom > rcRef.top && theApp.m_MarksInfo.rcMarkRect.bottom < rcRef.bottom && theApp.m_MarksInfo.rcMarkRect.left > rcRef.left && theApp.m_MarksInfo.rcMarkRect.left < rcRef.right && theApp.m_MarksInfo.rcMarkRect.right > rcRef.left && theApp.m_MarksInfo.rcMarkRect.right < rcRef.right && rcRef.left != m_RasterView.GetRaster().GetBitmapWidth() && rcRef.bottom!= m_RasterView.GetRaster().GetBitmapHeight()) { if(GetRegMarkDlg() != NULL) { GetRegMarkDlg()->AddData(0,&rcRef); } } else { MessageBox(TEXT("Mark is outside the search region"),TEXT("Error"), MB_OK); } } if (theApp.m_bAddingTShape == TRUE) { m_RasterView.ClientToBitmap(x,y); m_RasterView.GetRaster().SetRgnMagicWand(m_RasterView.GetConvertX(), m_RasterView.GetConvertY(), RGB(25, 25, 25), RGB(25, 25, 25), L_RGN_SET); nRet = theApp.m_pRasterProcess->IsRegistrationMark(m_RasterView.GetRaster(), theApp.m_RefDataDlg.nMarkType, theApp.m_RefDataDlg.nMinSizeRatio, theApp.m_RefDataDlg.nMaxSizeRatio, theApp.m_RefDataDlg.nWidth, theApp.m_RefDataDlg.nHeight); if(nRet == 0) { POINT ptPoint; ptPoint.x = (long)m_RasterView.GetConvertX(); ptPoint.y = (long)m_RasterView.GetConvertY(); theApp.m_clrTShapeColor = m_RasterView.GetRaster().GetPixel((float)ptPoint.x,(float)ptPoint.y); rcRef.left = (long)m_RasterView.GetRaster().GetRgnLeft(); rcRef.right= (long)m_RasterView.GetRaster().GetRgnWidth() + rcRef.left; rcRef.top = (long)m_RasterView.GetRaster().GetRgnTop(); rcRef.bottom = (long)m_RasterView.GetRaster().GetRgnHeight() + rcRef.top; if(GetRegMarkDlg() != NULL) { // Check if the point is aleady selected or not int nCount = GetRegMarkDlg()->m_lstRefPoints.GetCount(); for(int i =0 ;i < nCount;++i) { LPRGSDATA pRgsData; pRgsData = (LPRGSDATA)GetRegMarkDlg()->m_lstRefPoints.GetItemData(i); if((ptPoint.x >= pRgsData->rcMarkRect.left && ptPoint.x <= pRgsData->rcMarkRect.right) && (ptPoint.y >= pRgsData->rcMarkRect.top && ptPoint.y <= pRgsData->rcMarkRect.bottom)) { MessageBox(TEXT("This point is already selected."),TEXT("ERROR"),MB_OK); bSelected = TRUE; break; } } if(!bSelected) GetRegMarkDlg()->AddData(&ptPoint,&rcRef); } } else { MessageBox(TEXT("Not a registration mark"),TEXT("Error"), MB_OK); if(m_RasterView.GetRaster().GetHasRgn()) { m_RasterView.GetRaster().FreeRgn(); } } } } if (Button != 1) return; /* nothing to do ! */ } void CRGSMRKView::OnLeadRasterViewMouseMove(short Button, short Shift, float x, float y) { } void CRGSMRKView::RestoreBackground() { if (GetDocument()->m_pRasterFloaterBackground->Bitmap != NULL ) { theApp.m_pRasterProcess->Combine( m_RasterView.GetRaster(), m_RasterView.GetRaster().GetRgnLeft(), m_RasterView.GetRaster().GetRgnTop(), m_RasterView.GetRaster().GetRgnWidth(), m_RasterView.GetRaster().GetRgnHeight(), GetDocument()->m_pRasterFloaterBackground, 0.0f, 0.0f, SRC_COPY ); } } void CRGSMRKView::SaveBackground() { if (m_RasterView.GetRaster().GetRgnWidth() <= 0 || m_RasterView.GetRaster().GetRgnHeight() <= 0) return; GetDocument()->m_pRasterFloaterBackground->CreateBitmap( m_RasterView.GetRaster().GetRgnWidth(), m_RasterView.GetRaster().GetRgnHeight(), m_RasterView.GetRaster().GetBitmapBits() ); theApp.m_pRasterProcess->Combine( GetDocument()->m_pRasterFloaterBackground, 0.0f, 0.0f, m_RasterView.GetRaster().GetRgnWidth(), m_RasterView.GetRaster().GetRgnHeight(), m_RasterView.GetRaster(), m_RasterView.GetRaster().GetRgnLeft(), m_RasterView.GetRaster().GetRgnTop(), SRC_COPY); } void CRGSMRKView::OnCancelrgn() { HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT)); RestoreBackground(); m_RasterView.GetRaster().FreeRgn(); /* delete the regions from the master document and all other views */ m_RasterView.SetRgnFrameType(RGNFRAME_NONE); m_RasterView.SetFloater(0); SetCursor(hOldCursor); } void CRGSMRKView::OnUpdateEditCancelrgn(CCmdUI* pCmdUI) { pCmdUI->Enable(m_RasterView.GetRaster().GetHasRgn()); } void CRGSMRKView::OnEditCopy() { BeginWaitCursor(); m_RasterView.GetRaster().Copy(COPY_DIB | COPY_DDB | COPY_PALETTE); EndWaitCursor(); } void CRGSMRKView::OnUpdateEditPaste(CCmdUI* pCmdUI) { BOOL EnablePaste = GetDocument()->m_pRaster->Paste(PASTE_ISREADY); pCmdUI->Enable( EnablePaste); } void CRGSMRKView::OnImageDetcData() { int nRet = 0; int nNumberOfMarks = theApp.m_pRasterProcess->MarksCount; POINT TmpPoints[3] = {0}; theApp.m_pRasterProcess->PutEnableProgressEvent( TRUE ); nRet = theApp.m_pRasterProcess->SearchRegMarks(m_RasterView.GetRaster()); theApp.m_pRasterProcess->PutEnableProgressEvent( FALSE ); if(nRet != 0) { MessageBox(TEXT("Registration marks were not detected"),TEXT("ERROR"), MB_OK); theApp.m_bDetected = FALSE; theApp.m_bApplyTrans = FALSE; theApp.m_bHasBeenApplied = FALSE; return; } nRet = 0; nNumberOfMarks = theApp.m_pRasterProcess->MarksCount; for(int i = 0; i < nNumberOfMarks; i++) { if(theApp.m_pRasterProcess->GetMark(i)->DetectectedMarkCount == 1) nRet += theApp.m_pRasterProcess->GetMark(i)->DetectectedMarkCount; } if(nRet != nNumberOfMarks) { MessageBox(TEXT("Not all registration marks were detected"),TEXT("ERROR"), MB_OK); theApp.m_bDetected = FALSE; theApp.m_bApplyTrans = FALSE; theApp.m_bHasBeenApplied = FALSE; } else { for(i = 0; i < nNumberOfMarks; i++) { TmpPoints[i].x = theApp.m_pRasterProcess->GetMark(i)->GetDetectedMarkPointX(0); TmpPoints[i].y = theApp.m_pRasterProcess->GetMark(i)->GetDetectedMarkPointY(0); theApp.m_pRasterProcess->PutMarkPointX(i,TmpPoints[i].x); theApp.m_pRasterProcess->PutMarkPointY(i,TmpPoints[i].y); m_RasterView.ClientToBitmap((float)TmpPoints[i].x,(float)TmpPoints[i].y); if(i) { m_RasterView.GetRaster().SetRgnMagicWand((float)TmpPoints[i].x, (float)TmpPoints[i].y, RGB(50,50,50), RGB(50,50,50), L_RGN_OR); } else { m_RasterView.GetRaster().SetRgnMagicWand((float)TmpPoints[i].x, (float)TmpPoints[i].y, RGB(50,50,50), RGB(50,50,50), L_RGN_SET); } } MessageBox(TEXT("All registration marks were detected"),TEXT("SUCCESS"), MB_OK); nRet = theApp.m_pRasterProcess->GetMarksCenterMass(m_RasterView.GetRaster()); if(nRet == 0) { theApp.m_bDetected = TRUE; theApp.m_bHasBeenApplied = FALSE; } for(i = 0; i < nNumberOfMarks; i++) { int x,y; x = theApp.m_pRasterProcess->GetMarkCMPointX(i); y = theApp.m_pRasterProcess->GetMarkCMPointY(i); theApp.m_pRasterProcess->PutTransformedPointsX(i,x); theApp.m_pRasterProcess->PutTransformedPointsY(i,y); //////////// TmpPoints[i].x = theApp.m_pRasterProcess->GetMark(i)->GetDetectedMarkPointX(0); TmpPoints[i].y = theApp.m_pRasterProcess->GetMark(i)->GetDetectedMarkPointY(0); m_RasterView.ClientToBitmap((float)TmpPoints[i].x,(float)TmpPoints[i].y); if(i) { m_RasterView.GetRaster().SetRgnMagicWand((float)TmpPoints[i].x, (float)TmpPoints[i].y, RGB(50,50,50), RGB(50,50,50), L_RGN_OR); } else { m_RasterView.GetRaster().SetRgnMagicWand((float)TmpPoints[i].x, (float)TmpPoints[i].y, RGB(50,50,50), RGB(50,50,50), L_RGN_SET); } } } } void CRGSMRKView::OnUpdateImageDetcData(CCmdUI* pCmdUI) { pCmdUI->Enable(theApp.m_bRefDone && !theApp.m_bRegMarkDlg); } void CRGSMRKView::OnImageCompData() { CString strMsg; int nRet = theApp.m_pRasterProcess->GetTransformationParameters(m_RasterView.GetRaster()); if(nRet == 0) { if(theApp.m_bHasBeenApplied) theApp.m_bApplyTrans = FALSE; else theApp.m_bApplyTrans = TRUE; strMsg.Format(TEXT("Rotation Angle = %d \n") TEXT("X Scaling = %d \n") TEXT("Y Scaling = %d \n") TEXT("X Translation = %d \n") TEXT("Y Translation = %d \n"), theApp.m_pRasterProcess->TransformationAngle, theApp.m_pRasterProcess->XScale, theApp.m_pRasterProcess->YScale, theApp.m_pRasterProcess->XTranslation, theApp.m_pRasterProcess->YTranslation); MessageBox(strMsg,TEXT("SUCCESS"),MB_OK); if(m_RasterView.GetRaster().GetHasRgn()) { m_RasterView.GetRaster().FreeRgn(); } } else { MessageBox(TEXT("Can not compute parameters"),TEXT("ERROR"), MB_OK); } } void CRGSMRKView::OnUpdateImageCompData(CCmdUI* pCmdUI) { pCmdUI->Enable(theApp.m_bRefDone && theApp.m_bDetected); } void CRGSMRKView::OnImageApplyTrans() { int nXTranslation,nYTranslation; int nTransformationAngle,nXScale,nYScale; int nRet = 0; nXTranslation = theApp.m_pRasterProcess->XTranslation; nYTranslation = theApp.m_pRasterProcess->YTranslation; nTransformationAngle = theApp.m_pRasterProcess->TransformationAngle; nXScale = theApp.m_pRasterProcess->XScale; nYScale = theApp.m_pRasterProcess->YScale; theApp.m_pRasterProcess->PutEnableProgressEvent( TRUE ); nRet = theApp.m_pRasterProcess->ApplyTransformationParameters(m_RasterView.GetRaster(), nXTranslation, nYTranslation, nTransformationAngle, nXScale, nYScale, RGS_SIZE_NORMAL | RGS_SIZE_FAVORWHITE); if(nRet != 0) { theApp.DisplayLEADError(nRet); } else { theApp.m_bHasBeenApplied = TRUE; theApp.m_bApplyTrans = FALSE; } theApp.m_pRasterProcess->PutEnableProgressEvent( FALSE ); } void CRGSMRKView::OnUpdateImageApplyTrans(CCmdUI* pCmdUI) { pCmdUI->Enable(theApp.m_bApplyTrans); } void CRGSMRKView::OnRefdataSave() { if(theApp.m_bRefDone) { if(MessageBox(TEXT("Are you sure you want to save data?"),TEXT("Save Data"),MB_YESNO) != IDYES) return; } CString strFileName = theApp.GetExePath() + TEXT("RefData.txt"); CFile file(strFileName ,CFile::modeCreate | CFile::modeWrite); char Buffer[MAX_PATH]; int top,left,right,bottom; int nWidth,nHeight; int nType,nMinSizeRatio,nMaxSizeRatio; int nNumberOfMarks,i; int nSearchMarkCount = 0; POINT pt; nNumberOfMarks = theApp.m_pRasterProcess->MarksCount; memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",nNumberOfMarks); file.Write(Buffer,strlen(Buffer)); for(i = 0; i < nNumberOfMarks; i++) { top = theApp.m_pRasterProcess->GetMark(i)->Top; left = theApp.m_pRasterProcess->GetMark(i)->Left; right = theApp.m_pRasterProcess->GetMark(i)->Right; bottom = theApp.m_pRasterProcess->GetMark(i)->Bottom; nWidth = theApp.m_pRasterProcess->GetMark(i)->Width; nHeight = theApp.m_pRasterProcess->GetMark(i)->Height; nType = theApp.m_pRasterProcess->GetMark(i)->Type; nMinSizeRatio = theApp.m_pRasterProcess->GetMark(i)->MinScale; nMaxSizeRatio = theApp.m_pRasterProcess->GetMark(i)->MaxScale; nSearchMarkCount = theApp.m_pRasterProcess->GetMark(i)->NumberOfExpectedMarks; pt.x = theApp.m_pRasterProcess->GetReferencePointsX(i); pt.y = theApp.m_pRasterProcess->GetReferencePointsY(i); //save search rect memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",top); file.Write(Buffer,strlen(Buffer)); memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",left); file.Write(Buffer,strlen(Buffer)); memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",right); file.Write(Buffer,strlen(Buffer)); memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",bottom); file.Write(Buffer,strlen(Buffer)); //save mark width and height memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",nWidth); file.Write(Buffer,strlen(Buffer)); memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",nHeight); file.Write(Buffer,strlen(Buffer)); //save mark type memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",nType); file.Write(Buffer,strlen(Buffer)); //save min and max ratios memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",nMinSizeRatio); file.Write(Buffer,strlen(Buffer)); memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",nMaxSizeRatio); file.Write(Buffer,strlen(Buffer)); //save number of marks inside search region memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",nSearchMarkCount); file.Write(Buffer,strlen(Buffer)); //save mark reference point memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",pt.x); file.Write(Buffer,strlen(Buffer)); memset(Buffer,0,MAX_PATH); sprintf(Buffer,"%d\r\n",pt.y); file.Write(Buffer,strlen(Buffer)); } file.Close(); MessageBox(TEXT("Data Saved"), TEXT("SUCCESS"), MB_OK); } void CRGSMRKView::OnUpdateRefdataSave(CCmdUI* pCmdUI) { pCmdUI->Enable(theApp.m_bRefDone && !theApp.m_bRegMarkDlg); } void CRGSMRKView::OnRefdataLoad() { if(MessageBox(TEXT("Are you sure you want to load data?"),TEXT("Load Data"),MB_YESNO) != IDYES) return; CString strFileName = theApp.GetExePath() + TEXT("RefData.txt"); CFile *file = new CFile(strFileName ,CFile::modeRead); CString str; int nNumberOfMarks,i; nNumberOfMarks = ReadLine(file); theApp.m_pRasterProcess->MarksCount = nNumberOfMarks; for(i =0;iGetMark(i)->Top = ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->Left = ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->Right = ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->Bottom = ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->Width = ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->Height = ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->Type = (MarkTypeConstants)ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->MinScale = ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->MaxScale = ReadLine(file); theApp.m_pRasterProcess->GetMark(i)->NumberOfExpectedMarks = ReadLine(file); theApp.m_pRasterProcess->PutReferencePointsX(i, ReadLine(file)); theApp.m_pRasterProcess->PutReferencePointsY(i, ReadLine(file)); } file->Close(); MessageBox(TEXT("Data Loaded"), TEXT("SUCCESS"), MB_OK); theApp.m_bRefDone = TRUE; theApp.m_bDetected = FALSE; theApp.m_bApplyTrans = FALSE; } void CRGSMRKView::OnUpdateRefdataLoad(CCmdUI* pCmdUI) { CString strFileName = theApp.GetExePath() + TEXT("RefData.txt"); CFile *file = new CFile(); BOOL bLoad = file->Open(strFileName ,CFile::modeRead); pCmdUI->Enable(bLoad && !theApp.m_bRegMarkDlg); if(bLoad) file->Close(); } void CRGSMRKView::OnFileSave() { theApp.m_pRasterFileDlg->PutBitmap (m_RasterView.GetRaster().GetBitmap()); theApp.m_pRasterFileDlg->PutEnableMethodErrors(FALSE); theApp.m_pRasterFileDlg->PutFileDlgFlags(0); theApp.m_pRasterFileDlg->PutUIFlags(SAVE_AUTOPROCESS | SAVE_SHOW_FILEOPTIONS_MULTIPAGE | SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | SAVE_SHOW_FILEOPTIONS_QFACTOR| SAVE_SHOW_FILEOPTIONS_STAMP | SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| SAVE_SHOW_FILEOPTIONS_J2KOPTIONS); theApp.m_pRasterFileDlg->PutDialogTitle("Save File"); int nRet = theApp.m_pRasterFileDlg->ShowSaveDlg((long)this->m_hWnd); if(nRet !=0) { theApp.DisplayLEADError(nRet); } else { if (theApp.m_pRasterFileDlg->GetDialogStatus() != DLG_OK) return; } } long CRGSMRKView::ReadLine(CFile *pFile) { char Buffer[MAX_PATH]; char pByte; int nReadByte = 0; int i = 0; memset(Buffer,0,MAX_PATH); while(TRUE) { nReadByte = pFile->Read(&pByte,1); if(pByte == '\n') break; if(nReadByte == 0) break; Buffer[i] += pByte; i++; } return (long)atol(Buffer); } CRegMarkDlg * CRGSMRKView::GetRegMarkDlg() { return m_pRegMarkDlg; } void CRGSMRKView::SetRegMarkDlg() { m_pRegMarkDlg = new CRegMarkDlg(); } void CRGSMRKView::OnUpdateFileOpen(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateFileSave(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateFileClose(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateAppExit(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateEditCopy(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateImageRefData(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateWindowNew(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateWindowCascade(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateWindowTileHorz(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnUpdateWindowArrange(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); } void CRGSMRKView::OnEditImageInverse() { theApp.m_pRasterProcess->PutEnableProgressEvent( TRUE ); theApp.m_pRasterProcess->Invert(m_RasterView.GetRaster()); theApp.m_pRasterProcess->PutEnableProgressEvent( FALSE ); } void CRGSMRKView::OnUpdateEditImageinverse(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bRegMarkDlg); }