// RegMark.cpp : implementation file // #include "stdafx.h" #include "leadRaster.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CRGSMRKApp theApp; ///////////////////////////////////////////////////////////////////////////// // CRegMarkDlg dialog CRegMarkDlg::CRegMarkDlg(CWnd* pParent /*=NULL*/) : CDialog(CRegMarkDlg::IDD, pParent) { //{{AFX_DATA_INIT(CRegMarkDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CRegMarkDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRegMarkDlg) DDX_Control(pDX, IDC_ADD_POINTS, m_btnAddPoints); DDX_Control(pDX, IDC_SEARCH_RGN, m_btnSearchRgn); DDX_Control(pDX, IDC_REF_POINTS, m_lstRefPoints); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CRegMarkDlg, CDialog) //{{AFX_MSG_MAP(CRegMarkDlg) ON_BN_CLICKED(IDC_BACK, OnBack) ON_BN_CLICKED(IDC_ADD_POINTS, OnAddPoints) ON_BN_CLICKED(IDC_SEARCH_RGN, OnSearchRgn) ON_LBN_SELCHANGE(IDC_REF_POINTS, OnSelChangeRefPoints) ON_BN_CLICKED(IDC_DELETE, OnDelete) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRegMarkDlg message handlers void CRegMarkDlg::OnBack() { theApp.m_bRefDataDlg = FALSE; theApp.m_bRegMarkDlg = FALSE; CloseDialog(TRUE); EndDialog(TRUE); CRefDataDlg *pRefDataDlg = new CRefDataDlg(); pRefDataDlg->DoModal(); } BOOL CRegMarkDlg::AddData(POINT * pPoint, RECT * pRect) { int nIndex; LPRGSDATA pRgsData; int nCount; CString strStripName; if(m_bArea) { nIndex = m_lstRefPoints.GetCurSel(); if(nIndex < 0) return FALSE; pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(nIndex); pRgsData->rcRect.top = pRect->top; pRgsData->rcRect.bottom = pRect->bottom; pRgsData->rcRect.left = pRect->left; pRgsData->rcRect.right = pRect->right; pRgsData->bFilled = TRUE; strStripName.Format(TEXT("* x = %d y = %d"),pRgsData->ptPoint.x, pRgsData->ptPoint.y); m_lstRefPoints.DeleteString(nIndex); m_lstRefPoints.InsertString(nIndex, strStripName); m_lstRefPoints.SetItemData(nIndex, (long)pRgsData); } else { if(m_bAdd) { pRgsData = (LPRGSDATA) malloc(sizeof(RGSDATA)); memset(pRgsData,0,sizeof(RGSDATA)); pRgsData->ptPoint.x = pPoint->x; pRgsData->ptPoint.y = pPoint->y; pRgsData->rcMarkRect.top = pRect->top; pRgsData->rcMarkRect.bottom = pRect->bottom; pRgsData->rcMarkRect.left = pRect->left; pRgsData->rcMarkRect.right = pRect->right; pRgsData->bFilled = FALSE; strStripName.Format(TEXT(" x = %d y = %d"),pRgsData->ptPoint.x, pRgsData->ptPoint.y); nCount = m_lstRefPoints.GetCount(); m_lstRefPoints.AddString(strStripName); m_lstRefPoints.SetItemData(nCount, (LONG)pRgsData); if(!nCount) { m_btnSearchRgn.EnableWindow(TRUE); m_lstRefPoints.SetCurSel(0); } } } return TRUE; } BOOL CRegMarkDlg::OnInitDialog() { CDialog::OnInitDialog(); LPRGSDATA pRgsData; CString strStripName; CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CRGSMRKView *pView = (CRGSMRKView *) pChild->GetActiveView(); m_btnSearchRgn.EnableWindow(FALSE); m_bArea = FALSE; m_bAdd = FALSE; if(theApp.m_RefDataDlg.nNumber) { for(int i = 0; i < theApp.m_RefDataDlg.nNumber; i++) { if(theApp.m_RefDataDlg.pFilled[i]) strStripName.Format(TEXT("* x = %d y = %d"),theApp.m_RefDataDlg.pPoints[i].x, theApp.m_RefDataDlg.pPoints[i].y); else strStripName.Format(TEXT(" x = %d y = %d"),theApp.m_RefDataDlg.pPoints[i].x, theApp.m_RefDataDlg.pPoints[i].y); pRgsData = (LPRGSDATA) malloc(sizeof(RGSDATA)); m_lstRefPoints.AddString(strStripName); pRgsData->bFilled = theApp.m_RefDataDlg.pFilled[i]; pRgsData->rcRect = theApp.m_RefDataDlg.pRects[i]; pRgsData->rcMarkRect = theApp.m_RefDataDlg.pMarkRects[i]; pRgsData->ptPoint = theApp.m_RefDataDlg.pPoints[i]; m_lstRefPoints.SetItemData(i,(long)pRgsData); } if(!(theApp.m_RefDataDlg.nIndex >= 0 && theApp.m_RefDataDlg.nIndex < theApp.m_RefDataDlg.nNumber)) theApp.m_RefDataDlg.nIndex = 0; m_lstRefPoints.SetCurSel(theApp.m_RefDataDlg.nIndex); if(theApp.m_RefDataDlg.pFilled[theApp.m_RefDataDlg.nIndex]) { float ftop = (float)theApp.m_RefDataDlg.pRects[theApp.m_RefDataDlg.nIndex].top; float fleft= (float)theApp.m_RefDataDlg.pRects[theApp.m_RefDataDlg.nIndex].left; float fwidth = (float)theApp.m_RefDataDlg.pRects[theApp.m_RefDataDlg.nIndex].right ; float fheight = (float)theApp.m_RefDataDlg.pRects[theApp.m_RefDataDlg.nIndex].bottom; pView->m_RasterView.SetRgnFrameType(RGNFRAME_ANIMATED); pView->m_RasterView.GetRaster().SetRgnRect(fleft ,ftop ,fwidth - fleft,fheight - ftop,L_RGN_SET); } else { if(pView->m_RasterView.GetRaster().GetHasRgn()) { pView->m_RasterView.GetRaster().FreeRgn(); } } } if(theApp.m_RefDataDlg.nNumber) m_btnSearchRgn.EnableWindow(TRUE); else m_btnSearchRgn.EnableWindow(FALSE); theApp.m_bRefDataDlg = FALSE; theApp.m_bRegMarkDlg = TRUE; return TRUE; } void CRegMarkDlg::OnAddPoints() { LPRGSDATA pRgsData; int nIndex; CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CRGSMRKView *pView = (CRGSMRKView *) pChild->GetActiveView(); m_bArea = FALSE; theApp.m_bAddingArea = FALSE; nIndex = m_lstRefPoints.GetCurSel(); if(nIndex >= 0) { pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(nIndex); if(pRgsData->bFilled) { float ftop = (float)pRgsData->rcRect.top; float fleft= (float)pRgsData->rcRect.left; float fwidth = pRgsData->rcRect.right - fleft; float fheight = pRgsData->rcRect.bottom - ftop; pView->m_RasterView.SetRgnFrameType(RGNFRAME_ANIMATED); pView->m_RasterView.GetRaster().SetRgnRect(fleft ,ftop ,fwidth ,fheight ,L_RGN_SET); } else { ClearRgn(); if(pView->m_RasterView.GetRaster().GetHasRgn()) { pView->m_RasterView.GetRaster().FreeRgn(); } } } if(m_btnAddPoints.GetCheck() == BST_CHECKED) { m_bAdd = TRUE; theApp.m_bAddingTShape = TRUE; m_btnSearchRgn.SetCheck(BST_UNCHECKED); } else { m_bAdd = FALSE; theApp.m_bAddingTShape = FALSE; } } void CRegMarkDlg::OnSearchRgn() { LPRGSDATA pRgsData; int nIndex; CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CRGSMRKView *pView = (CRGSMRKView *) pChild->GetActiveView(); theApp.m_bAddingTShape = FALSE; m_bAdd = FALSE; nIndex = m_lstRefPoints.GetCurSel(); if(nIndex >= 0) { pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(nIndex); if(pRgsData->bFilled) { float ftop = (float)pRgsData->rcRect.top; float fleft= (float)pRgsData->rcRect.left; float fwidth = pRgsData->rcRect.right - fleft; float fheight = pRgsData->rcRect.bottom - ftop; pView->m_RasterView.SetRgnFrameType(RGNFRAME_ANIMATED); pView->m_RasterView.GetRaster().SetRgnRect(fleft ,ftop ,fwidth ,fheight ,L_RGN_SET); } else { if(pView->m_RasterView.GetRaster().GetHasRgn()) { pView->m_RasterView.GetRaster().FreeRgn(); } } } if(m_btnSearchRgn.GetCheck() == BST_CHECKED) { m_bArea = TRUE; theApp.m_bAddingArea = TRUE; if(m_btnAddPoints.GetCheck() == BST_CHECKED) { m_btnAddPoints.SetCheck(BST_UNCHECKED); } nIndex = m_lstRefPoints.GetCurSel(); if(nIndex < 0) { nIndex = 0; m_lstRefPoints.SetCurSel(nIndex); } pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(nIndex); if(pRgsData->ptPoint.x != -1) { pView->m_RasterView.GetRaster().SetRgnMagicWand((float)pRgsData->ptPoint.x, (float)pRgsData->ptPoint.y, RGB(25, 25, 25), RGB(25, 25, 25), L_RGN_SET); theApp.m_pRasterProcess->Fill(pView->m_RasterView.GetRaster(),theApp.m_clrTShapeColor); } if(pView->m_RasterView.GetRaster().GetHasRgn()) { if(pView->m_RasterView.GetRaster().GetBitmapBits() > 1) { theApp.m_pRasterProcess->Fill(pView->m_RasterView.GetRaster(),RGB(255,0,0)); } else { theApp.m_pRasterProcess->Fill(pView->m_RasterView.GetRaster(),theApp.m_clrTShapeColor); } pView->m_RasterView.GetRaster().FreeRgn(); } if(pRgsData->ptPoint.x != -1) { theApp.m_MarksInfo.ptCenter.x = pRgsData->ptPoint.x; theApp.m_MarksInfo.ptCenter.y = pRgsData->ptPoint.y; theApp.m_MarksInfo.rcMarkRect = pRgsData->rcMarkRect; theApp.m_MarksInfo.rcSearchRect = pRgsData->rcRect; theApp.m_MarksInfo.bFilled = pRgsData->bFilled; } } else { ClearRgn(); m_bArea = FALSE; theApp.m_bAddingArea= FALSE; } } void CRegMarkDlg::OnOK() { if(!CloseDialog(FALSE)) return; theApp.m_bRefDataDlg = FALSE; theApp.m_bRegMarkDlg = FALSE; CDialog::OnOK(); } void CRegMarkDlg::OnSelChangeRefPoints() { int nIndex; LPRGSDATA pRgsData; CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CRGSMRKView *pView = (CRGSMRKView *) pChild->GetActiveView(); nIndex = m_lstRefPoints.GetCurSel(); if(nIndex >= 0) { ClearRgn(); pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(nIndex); if(m_bArea || m_bAdd) { if(pRgsData->ptPoint.x != -1) { pView->m_RasterView.GetRaster().SetRgnMagicWand((float)pRgsData->ptPoint.x, (float)pRgsData->ptPoint.y, RGB(25, 25, 25), RGB(25, 25, 25), L_RGN_SET); theApp.m_pRasterProcess->Fill(pView->m_RasterView.GetRaster(),theApp.m_clrTShapeColor); } if(pView->m_RasterView.GetRaster().GetHasRgn()) { if(pView->m_RasterView.GetRaster().GetBitmapBits() > 1) { theApp.m_pRasterProcess->Fill(pView->m_RasterView.GetRaster(),RGB(255,0,0)); } else { theApp.m_pRasterProcess->Fill(pView->m_RasterView.GetRaster(),theApp.m_clrTShapeColor); } pView->m_RasterView.GetRaster().FreeRgn(); } } if(pRgsData->ptPoint.x != -1) { theApp.m_MarksInfo.ptCenter = pRgsData->ptPoint; theApp.m_MarksInfo.rcMarkRect = pRgsData->rcMarkRect; theApp.m_MarksInfo.rcSearchRect = pRgsData->rcRect; theApp.m_MarksInfo.bFilled = pRgsData->bFilled; } if(pRgsData->bFilled) { float ftop = (float)pRgsData->rcRect.top; float fleft= (float)pRgsData->rcRect.left; float fwidth = pRgsData->rcRect.right - fleft; float fheight = pRgsData->rcRect.bottom - ftop; pView->m_RasterView.SetRgnFrameType(RGNFRAME_ANIMATED); pView->m_RasterView.GetRaster().SetRgnRect(fleft ,ftop ,fwidth ,fheight ,L_RGN_SET); } else { if(pView->m_RasterView.GetRaster().GetHasRgn()) { pView->m_RasterView.GetRaster().FreeRgn(); } } } } void CRegMarkDlg::OnDelete() { int nIndex,nCount; LPRGSDATA pRgsData; CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CRGSMRKView *pView = (CRGSMRKView *) pChild->GetActiveView(); m_bAdd = FALSE; m_bArea = FALSE; theApp.m_bAddingTShape = FALSE; theApp.m_bAddingArea = FALSE; m_btnSearchRgn.SetCheck(BST_UNCHECKED); m_btnAddPoints.SetCheck(BST_UNCHECKED); nIndex = m_lstRefPoints.GetCurSel(); if(nIndex >= 0) { if(pView->m_RasterView.GetRaster().GetHasRgn()) { ClearRgn(); pView->m_RasterView.GetRaster().FreeRgn(); } pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(nIndex); if(pRgsData) { free(pRgsData); } m_lstRefPoints.DeleteString(nIndex); nCount = m_lstRefPoints.GetCount(); if(!nCount) { m_btnSearchRgn.EnableWindow(FALSE); } else { if(nCount == nIndex) { nIndex = nCount - 1; } m_lstRefPoints.SetCurSel(nIndex); pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(nIndex); if(pRgsData->ptPoint.x != -1) { theApp.m_MarksInfo.ptCenter = pRgsData->ptPoint; theApp.m_MarksInfo.rcMarkRect = pRgsData->rcMarkRect; } if(pRgsData->bFilled) { float ftop = (float)pRgsData->rcRect.top; float fleft= (float)pRgsData->rcRect.left; float fwidth = pRgsData->rcRect.right - fleft; float fheight = pRgsData->rcRect.bottom - ftop; pView->m_RasterView.SetRgnFrameType(RGNFRAME_ANIMATED); pView->m_RasterView.GetRaster().SetRgnRect(fleft ,ftop ,fwidth ,fheight ,L_RGN_SET); } else { if(pView->m_RasterView.GetRaster().GetHasRgn()) { pView->m_RasterView.GetRaster().FreeRgn(); } } } } else { if(pView->m_RasterView.GetRaster().GetHasRgn()) { pView->m_RasterView.GetRaster().FreeRgn(); } } } BOOL CRegMarkDlg::CloseDialog(BOOL bBack) { int nCount,i; LPRGSDATA pRgsData; CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CRGSMRKView *pView = (CRGSMRKView *) pChild->GetActiveView(); nCount = m_lstRefPoints.GetCount(); m_bArea = FALSE; m_bAdd = FALSE; theApp.m_bAddingArea = FALSE; theApp.m_bAddingTShape = FALSE; if(!bBack) { if(!CheckData(nCount)) return FALSE; } ClearRgn(); if(pView->m_RasterView.GetRaster().GetHasRgn()) { pView->m_RasterView.GetRaster().FreeRgn(); } theApp.FreeDlgData(); theApp.m_RefDataDlg.nNumber = nCount; theApp.m_RefDataDlg.nIndex = m_lstRefPoints.GetCurSel(); if(bBack) { if(!nCount) { EndDialog(TRUE); return TRUE; } } theApp.m_RefDataDlg.nIndex = m_lstRefPoints.GetCurSel(); theApp.m_RefDataDlg.pFilled = new BOOL[nCount]; theApp.m_RefDataDlg.pRects = new RECT[nCount]; theApp.m_RefDataDlg.pMarkRects = new RECT[nCount]; theApp.m_RefDataDlg.pPoints = new POINT[nCount]; for(i = 0; i < nCount; i++) { pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(i); theApp.m_RefDataDlg.pPoints[i] = pRgsData->ptPoint; theApp.m_RefDataDlg.pMarkRects[i] = pRgsData->rcMarkRect; if(pRgsData->bFilled) { theApp.m_RefDataDlg.pFilled[i] = TRUE; theApp.m_RefDataDlg.pRects[i] = pRgsData->rcRect; } else { theApp.m_RefDataDlg.pFilled[i] = FALSE; theApp.m_RefDataDlg.pRects[i].top = -1; theApp.m_RefDataDlg.pRects[i].left = -1; theApp.m_RefDataDlg.pRects[i].right = -1; theApp.m_RefDataDlg.pRects[i].bottom = -1; } free(pRgsData); } if(!bBack) pView->AddData(); return TRUE; } BOOL CRegMarkDlg::CheckData(int nCount) { LPRGSDATA pRgsData; if(!nCount) { MessageBox(TEXT("No registration mark was selected. You must select 3 registration marks before continuing"), TEXT("ERROR"), MB_OK); return FALSE; } if(nCount < 3) { MessageBox(TEXT("You must select 3 registration marks before continuing"), TEXT("ERROR"), MB_OK); return FALSE; } if(nCount > 3) { MessageBox(TEXT("You must select only 3 registration marks"), TEXT("ERROR"), MB_OK); return FALSE; } for(int i = 0; i < nCount; i++) { pRgsData = (LPRGSDATA)m_lstRefPoints.GetItemData(i); if(!pRgsData->bFilled) { MessageBox(TEXT("Not all search regions were specified"), TEXT("ERROR"), MB_OK); return FALSE; } } return TRUE; } void CRegMarkDlg::OnClose() { OnBack(); } void CRegMarkDlg::OnCancel() { } void CRegMarkDlg::ClearRgn() { LPRGSDATA pRgsData; CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CRGSMRKView *pView = (CRGSMRKView *) pChild->GetActiveView(); for(int i=0;iptPoint.x != -1) { pView->m_RasterView.GetRaster().SetRgnMagicWand((float)pRgsData->ptPoint.x, (float)pRgsData->ptPoint.y, RGB(25, 25, 25), RGB(25, 25, 25), L_RGN_SET); theApp.m_pRasterProcess->Fill(pView->m_RasterView.GetRaster(),theApp.m_clrTShapeColor); } } }