#include "stdafx.h"
#include "MdispMFC.h"
#include "MdispMFCDoc.h"
#include "MdispMFCView.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const MIL_INT CMdispMFCView::s_CompressionType[] =
{M_NULL, M_JPEG_LOSSY, M_JPEG_LOSSLESS};
const MIL_INT CMdispMFCView::s_AsynchronousMaxUpdateRate[] =
{M_DISABLE, 1, 5, 10, 15, 30, M_INFINITE};
const MIL_INT CMdispMFCView::s_QFactor[] =
{60, 70, 75, 80, 82, 85, 87, 90, 92, 95, 99};
const UINT CMdispMFCView::s_FirstCompressionTypeControlInRange = ID_COMPRESSION_NONE;
const UINT CMdispMFCView::s_FirstAsynchronousMaxUpdateRateControlInRange
= ID_ASYNCHRONOUSMODE_DISABLED;
const UINT CMdispMFCView::s_FirstQFactorControlInRange = ID_QFACTOR_60;
MIL_INT MFTYPE MouseFct(MIL_INT HookType, MIL_ID EventID, void* UserDataPtr)
{
CMdispMFCView* pCurrentView = (CMdispMFCView*)UserDataPtr;
if(pCurrentView)
{
MOUSEPOSITION MousePosition;
MdispGetHookInfo(EventID, M_MOUSE_POSITION_X, &MousePosition.m_DisplayPositionX);
MdispGetHookInfo(EventID, M_MOUSE_POSITION_Y, &MousePosition.m_DisplayPositionY);
MdispGetHookInfo(EventID, M_MOUSE_POSITION_BUFFER_X, &MousePosition.m_BufferPositionX);
MdispGetHookInfo(EventID, M_MOUSE_POSITION_BUFFER_Y, &MousePosition.m_BufferPositionY);
pCurrentView->SetMousePosition(MousePosition);
pCurrentView->SendMessage(WM_COMMAND, ID_MOUSE_UPDATE_TEXT);
}
return 0;
}
MIL_INT MFTYPE GraphicListModifiedHookFct(MIL_INT HookType, MIL_ID EventID, void* UserDataPtr)
{
CMdispMFCView* pCurrentView = (CMdispMFCView*)UserDataPtr;
if(pCurrentView)
{
MIL_INT State = M_NULL;
MgraGetHookInfo(EventID, M_INTERACTIVE_GRAPHIC_STATE, &State);
if((State != M_STATE_WAITING_FOR_CREATION) && (State != M_STATE_BEING_CREATED))
{
pCurrentView->ResetPrimitiveCreation();
}
}
return 0;
}
IMPLEMENT_DYNCREATE(CMdispMFCView, CView)
BEGIN_MESSAGE_MAP(CMdispMFCView, CView)
ON_COMMAND(ID_GRAB_START, OnGrabStart)
ON_UPDATE_COMMAND_UI(ID_GRAB_START, OnUpdateGrabStart)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateSave)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateSaveAs)
ON_COMMAND(ID_GRAB_STOP, OnGrabStop)
ON_COMMAND(ID_MOUSE_UPDATE_TEXT, OnMouseUpdateText)
ON_UPDATE_COMMAND_UI(ID_GRAB_STOP, OnUpdateGrabStop)
ON_WM_DESTROY()
ON_COMMAND(ID_OVERLAY, OnOverlay)
ON_UPDATE_COMMAND_UI(ID_OVERLAY, OnUpdateOverlay)
ON_WM_SIZE()
ON_WM_KEYDOWN()
ON_WM_TIMER()
ON_COMMAND(ID_ZOOMIN, OnZoomin)
ON_UPDATE_COMMAND_UI(ID_ZOOMIN, OnUpdateZoomin)
ON_COMMAND(ID_ZOOMOUT, OnZoomout)
ON_UPDATE_COMMAND_UI(ID_ZOOMOUT, OnUpdateZoomout)
ON_COMMAND(ID_NOZOOM, OnNoZoom)
ON_UPDATE_COMMAND_UI(ID_NOZOOM, OnUpdateNoZoom)
ON_COMMAND(ID_SCALEDISPLAY, OnScaleDisplay)
ON_UPDATE_COMMAND_UI(ID_SCALEDISPLAY, OnUpdateScaleDisplay)
ON_COMMAND(ID_GDIANNOTATIONS, OnGDIAnnotations)
ON_UPDATE_COMMAND_UI(ID_GDIANNOTATIONS, OnUpdateGDIAnnotations)
ON_CONTROL(CBN_SELCHANGE, IDC_CB_VIEW_MODE, OnViewModeChange)
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_WM_SIZING()
ON_COMMAND_RANGE(ID_COMPRESSION_NONE, ID_COMPRESSION_LOSSLESS, &CMdispMFCView::OnCompression)
ON_UPDATE_COMMAND_UI_RANGE(ID_COMPRESSION_NONE, ID_COMPRESSION_LOSSLESS, &CMdispMFCView::OnUpdateCompression)
ON_COMMAND_RANGE(ID_ASYNCHRONOUSMODE_DISABLED, ID_ASYNCHRONOUSMODE_MAXIMUMRATE, &CMdispMFCView::OnAsynchronousMode)
ON_UPDATE_COMMAND_UI_RANGE(ID_ASYNCHRONOUSMODE_DISABLED, ID_ASYNCHRONOUSMODE_MAXIMUMRATE, &CMdispMFCView::OnUpdateAsynchronousMode)
ON_COMMAND_RANGE(ID_QFACTOR_DEFAULT, ID_QFACTOR_99, &CMdispMFCView::OnQFactor)
ON_UPDATE_COMMAND_UI_RANGE(ID_QFACTOR_DEFAULT, ID_QFACTOR_99, &CMdispMFCView::OnUpdateQFactor)
ON_COMMAND(ID_RESTRICTCURSOR, &CMdispMFCView::OnRestrictCursor)
ON_UPDATE_COMMAND_UI(ID_RESTRICTCURSOR, &CMdispMFCView::OnUpdateRestrictCursor)
ON_COMMAND(ID_DISPLAY_GRAPHICSANNOTATIONS, &CMdispMFCView::OnGraphicsAnnotations)
ON_UPDATE_COMMAND_UI(ID_DISPLAY_GRAPHICSANNOTATIONS, &CMdispMFCView::OnUpdateGraphicsAnnotations)
ON_COMMAND(ID_GRA_RECTANGLE, &CMdispMFCView::OnGraRectangle)
ON_UPDATE_COMMAND_UI(ID_GRA_RECTANGLE, &CMdispMFCView::OnUpdateGraRectangle)
ON_COMMAND(ID_GRA_CIRCLE, &CMdispMFCView::OnGraCircle)
ON_UPDATE_COMMAND_UI(ID_GRA_CIRCLE, &CMdispMFCView::OnUpdateGraCircle)
ON_COMMAND(ID_GRA_POLYGON, &CMdispMFCView::OnGraPolygon)
ON_UPDATE_COMMAND_UI(ID_GRA_POLYGON, &CMdispMFCView::OnUpdateGraPolygon)
ON_COMMAND(ID_GRA_COLOR, &CMdispMFCView::OnGraChooseColor)
ON_UPDATE_COMMAND_UI(ID_GRA_COLOR, &CMdispMFCView::OnUpdateGraChooseColor)
ON_COMMAND(ID_GRA_FILL, &CMdispMFCView::OnGraFill)
ON_UPDATE_COMMAND_UI(ID_GRA_FILL, &CMdispMFCView::OnUpdateGraFill)
END_MESSAGE_MAP()
CMdispMFCView::CMdispMFCView()
{
m_MilOverlayImage = M_NULL;
m_MilDisplay = M_NULL;
m_MilGraphContext = M_NULL;
m_MilGraphList = M_NULL;
m_isWindowed = true;
m_isExclusive = false;
m_isOverlayEnabled = false;
m_isOverlayInitialized = false;
m_isScaleDisplayEnabled = false;
m_isGDIAnnotationsEnabled = false;
m_currentViewMode = M_TRANSPARENT;
m_currentShiftValue = M_NULL;
m_isInAsynchronousMode = false;
m_currentCompressionType = M_NULL;
m_currentAsynchronousFrameRate = M_INFINITE;
m_currentQFactor = M_DEFAULT;
m_currentRestrictCursor = M_ENABLE;
m_bGraphicsAnnotations = false;
m_PrimitiveInCreation = M_NULL;
}
CMdispMFCView::~CMdispMFCView()
{
}
BOOL CMdispMFCView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
#ifdef _DEBUG
void CMdispMFCView::AssertValid() const
{
CView::AssertValid();
}
void CMdispMFCView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMdispMFCDoc* CMdispMFCView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMdispMFCDoc)));
return (CMdispMFCDoc*)m_pDocument;
}
#endif
void CMdispMFCView::OnGrabStart()
{
if(((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted)
((CMdispMFCApp*)AfxGetApp())->m_pGrabView->SendMessage(WM_COMMAND, ID_GRAB_STOP, 0);
MdigGrabContinuous(((CMdispMFCApp*)AfxGetApp())->m_MilDigitizer,
((CMdispMFCDoc*)GetDocument())->m_MilImage);
((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted = TRUE;
((CMdispMFCApp*)AfxGetApp())->m_pGrabView = this;
((CMdispMFCDoc*)GetDocument())->SetModifiedFlag(TRUE);
}
void CMdispMFCView::OnUpdateGrabStart(CCmdUI* pCmdUI)
{
CView *GrabOwnerViewPtr = ((CMdispMFCApp*)AfxGetApp())->m_pGrabView;
if( 0 == ((CMdispMFCApp*)AfxGetApp())->m_numberOfDigitizer )
{
pCmdUI->Enable(0);
}
else
{
pCmdUI->Enable(!(GrabOwnerViewPtr &&
(GetDocument() == GrabOwnerViewPtr->GetDocument()) &&
(((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted == TRUE) &&
((CMdispMFCApp*)AfxGetApp())->m_numberOfDigitizer));
}
}
void CMdispMFCView::OnUpdateSave(CCmdUI* pCmdUI)
{
pCmdUI->Enable(((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted == FALSE);
}
void CMdispMFCView::OnUpdateSaveAs(CCmdUI* pCmdUI)
{
pCmdUI->Enable(((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted == FALSE);
}
void CMdispMFCView::OnMouseUpdateText()
{
((CChildFrame*)GetParentFrame())->UpdateStatusBarWithMouse(m_LastMousePosition.m_DisplayPositionX, m_LastMousePosition.m_DisplayPositionY,
m_LastMousePosition.m_BufferPositionX, m_LastMousePosition.m_BufferPositionY);
m_LastMousePosition.Set(M_INVALID, M_INVALID, M_INVALID, M_INVALID);
}
void CMdispMFCView::OnGrabStop()
{
MdigHalt(((CMdispMFCApp*)AfxGetApp())->m_MilDigitizer);
((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted = FALSE;
}
void CMdispMFCView::OnUpdateGrabStop(CCmdUI* pCmdUI)
{
CView *GrabOwnerViewPtr = ((CMdispMFCApp*)AfxGetApp())->m_pGrabView;
pCmdUI->Enable(GrabOwnerViewPtr &&
(GetDocument() == GrabOwnerViewPtr->GetDocument()) &&
(((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted == TRUE) &&
((CMdispMFCApp*)AfxGetApp())->m_numberOfDigitizer);
}
void CMdispMFCView::OnOverlay()
{
if (!m_isOverlayEnabled)
{
MdispControl(m_MilDisplay, M_OVERLAY, M_ENABLE);
if(!m_isOverlayInitialized)
InitializeOverlay();
m_isOverlayEnabled = true;
}
else
{
MdispControl(m_MilDisplay, M_OVERLAY, M_DISABLE);
m_isOverlayInitialized = false;
m_isOverlayEnabled = false;
}
}
void CMdispMFCView::OnUpdateOverlay(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_isOverlayEnabled);
}
void CMdispMFCView::OnInitialUpdate()
{
SetTimer(TIMER_FRAMERATE,500,M_NULL);
CSize statusBarSize = ((CChildFrame*)GetParentFrame())->GetStatusBarSize();
if (((CMdispMFCDoc*)GetDocument())->m_MilImage)
{
MdispAlloc(((CMdispMFCApp*)AfxGetApp())->m_MilSystem, M_DEFAULT,
MIL_TEXT("M_DEFAULT"), M_DEFAULT, &m_MilDisplay);
if(m_MilDisplay)
{
MIL_INT DisplayType = MdispInquire(m_MilDisplay, M_DISPLAY_TYPE, M_NULL);
if((DisplayType&(M_WINDOWED|M_EXCLUSIVE)) != M_WINDOWED)
m_isWindowed = false;
if(DisplayType&(M_EXCLUSIVE))
m_isExclusive = true;
ChangeViewMode(M_DEFAULT);
if(IsNetworkedSystem())
{
MdispInquire(m_MilDisplay, M_COMPRESSION_TYPE, &m_currentCompressionType);
m_isInAsynchronousMode = (MdispInquire(m_MilDisplay,
M_ASYNC_UPDATE, M_NULL) == M_ENABLE);
MdispInquire(m_MilDisplay, M_UPDATE_RATE_MAX, &m_currentAsynchronousFrameRate);
MdispInquire(m_MilDisplay, M_Q_FACTOR, &m_currentQFactor);
}
if(m_isExclusive)
{
MdispInquire(m_MilDisplay, M_RESTRICT_CURSOR, &m_currentRestrictCursor);
}
MdispSelectWindow(m_MilDisplay,
((CMdispMFCDoc*)GetDocument())->m_MilImage, m_isWindowed?m_hWnd:0);
MdispControl(m_MilDisplay, M_MOUSE_USE, M_ENABLE);
MdispControl(m_MilDisplay, M_MOUSE_CURSOR_CHANGE, M_ENABLE);
}
CView::OnInitialUpdate();
if(!GetParent()->IsZoomed()&& !m_isExclusive)
ResizeDisplayWindow();
if(m_isWindowed)
{
GetParentFrame()->RecalcLayout();
}
MdispHookFunction(m_MilDisplay, M_MOUSE_MOVE, MouseFct, (void*)this);
}
}
void CMdispMFCView::OnDestroy()
{
KillTimer(TIMER_FRAMERATE);
RemoveFromDisplay();
CView::OnDestroy();
}
void CMdispMFCView::RemoveFromDisplay()
{
if ((((CMdispMFCApp*)AfxGetApp())->m_pGrabView == this) &&
((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted)
{
MdigHalt(((CMdispMFCApp*)AfxGetApp())->m_MilDigitizer);
((CMdispMFCApp*)AfxGetApp())->m_isGrabStarted = FALSE;
}
if (((CMdispMFCDoc*)GetDocument())->m_MilImage && m_MilDisplay)
{
MdispDeselect(m_MilDisplay,((CMdispMFCDoc*)GetDocument())->m_MilImage);
MdispHookFunction(m_MilDisplay, M_MOUSE_MOVE+M_UNHOOK, MouseFct, (void*)this);
if(m_MilGraphList)
{
MgraFree(m_MilGraphList);
m_MilGraphList = M_NULL;
}
if(m_MilGraphContext)
{
MgraFree(m_MilGraphContext);
m_MilGraphContext = M_NULL;
}
MdispFree(m_MilDisplay);
m_MilDisplay = M_NULL;
}
}
void CMdispMFCView::OnDraw(CDC* pDC)
{
RECT clientRECT;
if(!m_MilDisplay)
{
GetClientRect(&clientRECT);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,0,0));
pDC->DrawText("Display Allocation Failed!", &clientRECT,DT_LEFT);
}
else if(m_isWindowed)
{
if(m_isGDIAnnotationsEnabled )
{
GetClientRect(&clientRECT);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,0,255));
clientRECT.top += 50;
pDC->DrawText("Window Annotations", &clientRECT,DT_CENTER);
}
}
else
{
GetClientRect(&clientRECT);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
pDC->DrawText("Image displayed on external screen", &clientRECT,DT_LEFT);
}
}
void CMdispMFCView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if(m_MilDisplay)
{
MIL_DOUBLE ZoomX = 1, ZoomY = 1;
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_X, &ZoomX);
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_Y, &ZoomY);
((CChildFrame*)GetParentFrame())->UpdateStatusBarWithScale(ZoomX, ZoomY);
}
}
void CMdispMFCView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(m_bGraphicsAnnotations)
{
if (nChar == VK_ESCAPE)
{
MIL_INT CurrentInteractiveState = M_NULL;
MgraInquireList(m_MilGraphList, M_LIST, M_DEFAULT, M_INTERACTIVE_GRAPHIC_STATE, &CurrentInteractiveState);
switch(CurrentInteractiveState)
{
case M_STATE_IDLE :
case M_STATE_GRAPHIC_HOVERED :
case M_STATE_HANDLE_HOVERED :
MgraControlList(m_MilGraphList, M_ALL, M_DEFAULT, M_GRAPHIC_SELECTED, M_FALSE);
break;
case M_STATE_GRAPHIC_DRAGGED :
case M_STATE_HANDLE_DRAGGED :
case M_STATE_WAITING_FOR_CREATION:
case M_STATE_BEING_CREATED :
MgraInteractive(M_NULL, m_MilGraphList, M_CANCEL, M_DEFAULT, M_DEFAULT);
break;
default:
break;
}
}
if (nChar == VK_DELETE)
{
MgraControlList(m_MilGraphList, M_ALL_SELECTED, M_DEFAULT, M_DELETE, M_DEFAULT);
}
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CMdispMFCView::OnTimer(UINT_PTR nIDEvent)
{
if (m_MilDisplay && (nIDEvent == TIMER_FRAMERATE))
{
MIL_DOUBLE CurrentFrameRate = M_NULL;
MdispInquire(m_MilDisplay, M_UPDATE_RATE, &CurrentFrameRate);
((CChildFrame*)GetParentFrame())->UpdateStatusBarWithFrameRate(CurrentFrameRate);
MIL_DOUBLE ZoomX =1, ZoomY = 1;
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_X, &ZoomX);
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_Y, &ZoomY);
((CChildFrame*)GetParentFrame())->UpdateStatusBarWithScale(ZoomX, ZoomY);
}
CView::OnTimer(nIDEvent);
}
void CMdispMFCView::OnZoomin()
{
if(m_MilDisplay)
{
MIL_DOUBLE ZoomX = 1, ZoomY = 1;
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_X, &ZoomX);
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_Y, &ZoomY);
if((ZoomX < 64) && (ZoomY < 64))
{
ZoomX *= 2;
ZoomY *= 2;
}
Zoom(ZoomX, ZoomY);
}
}
void CMdispMFCView::OnUpdateZoomin(CCmdUI* pCmdUI)
{
if(m_isScaleDisplayEnabled)
pCmdUI->Enable(0);
else
pCmdUI->Enable(1);
}
void CMdispMFCView::OnZoomout()
{
if(m_MilDisplay)
{
MIL_DOUBLE ZoomX = 1, ZoomY = 1;
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_X, &ZoomX);
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_Y, &ZoomY);
if((ZoomX > 0.015625) && (ZoomY > 0.015625))
{
ZoomX /= 2;
ZoomY /= 2;
}
Zoom(ZoomX, ZoomY);
}
}
void CMdispMFCView::OnUpdateZoomout(CCmdUI* pCmdUI)
{
if(m_isScaleDisplayEnabled)
pCmdUI->Enable(0);
else
pCmdUI->Enable(1);
}
void CMdispMFCView::OnNoZoom()
{
if(m_MilDisplay)
{
Zoom(1, 1);
MdispPan(m_MilDisplay, M_NULL, M_NULL);
}
}
void CMdispMFCView::OnUpdateNoZoom(CCmdUI* pCmdUI)
{
if(m_isScaleDisplayEnabled)
pCmdUI->Enable(0);
else
pCmdUI->Enable(1);
}
void CMdispMFCView::OnScaleDisplay()
{
if(m_MilDisplay)
{
if(!m_isScaleDisplayEnabled)
{
MdispControl(m_MilDisplay, M_SCALE_DISPLAY, M_ENABLE);
m_isScaleDisplayEnabled = true;
}
else
{
MdispControl(m_MilDisplay, M_SCALE_DISPLAY, M_DISABLE);
m_isScaleDisplayEnabled = false;
}
if(m_isWindowed)
InvalidateRect(M_NULL);
}
}
void CMdispMFCView::OnUpdateScaleDisplay(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_isScaleDisplayEnabled);
pCmdUI->Enable(1);
}
void CMdispMFCView::ResizeDisplayWindow()
{
CRect parentRECT;
GetParent()->GetParent()->GetClientRect(&parentRECT);
CSize statusBarSize = ((CChildFrame*)GetParentFrame())->GetStatusBarSize();
CRect MMRect;
MIL_DOUBLE ZoomX, ZoomY = 0;
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_X, &ZoomX);
MdispInquire(m_MilDisplay, M_ZOOM_FACTOR_Y, &ZoomY);
int dispX = (int)(GetDocument()->m_imageSizeX * ZoomX);
int dispY = (int)(GetDocument()->m_imageSizeY * ZoomY);
if(!m_isWindowed)
{
dispX = (int)MdispInquire(m_MilDisplay, M_SIZE_X, M_NULL);
dispY = (int)MdispInquire(m_MilDisplay, M_SIZE_Y, M_NULL);
}
long PosOffset = 4;
MMRect.SetRect(0, 0, dispX, dispY);
GetParent()->CalcWindowRect(&MMRect, CWnd::adjustBorder);
MMRect.OffsetRect(-MMRect.left,-MMRect.top);
if(MMRect.Width() > parentRECT.Width())
MMRect.right = parentRECT.right;
if(MMRect.Height() > parentRECT.Height())
MMRect.bottom = parentRECT.bottom;
else
MMRect.bottom = MMRect.bottom + statusBarSize.cy;
GetParent()->SetWindowPos( NULL,
0,
0,
MMRect.right + PosOffset,
MMRect.bottom + PosOffset,
SWP_NOACTIVATE|SWP_NOZORDER);
GetParent()->InvalidateRect(NULL,FALSE);
}
void CMdispMFCView::OnGDIAnnotations()
{
if(!m_isGDIAnnotationsEnabled)
{
MdispControl(m_MilDisplay, M_WINDOW_ANNOTATIONS, M_ENABLE);
if (MdispInquire(m_MilDisplay,M_WINDOW_ANNOTATIONS,M_NULL) == M_ENABLE)
m_isGDIAnnotationsEnabled = true;
}
else
{
MdispControl(m_MilDisplay, M_WINDOW_ANNOTATIONS, M_DISABLE);
m_isGDIAnnotationsEnabled = false;
}
InvalidateRect(NULL);
UpdateWindow();
}
void CMdispMFCView::OnUpdateGDIAnnotations(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_isWindowed);
pCmdUI->SetCheck(m_isGDIAnnotationsEnabled);
}
void CMdispMFCView::OnViewModeChange()
{
if(m_MilDisplay)
{
CComboBox* pViewModeComboBox =
((CMainFrame*)AfxGetMainWnd())->GetToolbarViewModeCombo() ;
if (pViewModeComboBox)
{
int index = pViewModeComboBox->GetCurSel();
if(index!=CB_ERR)
{
switch(index)
{
case 0:
ChangeViewMode(M_DEFAULT);
break;
case 1:
ChangeViewMode(M_TRANSPARENT);
break;
case 2:
ChangeViewMode(M_AUTO_SCALE);
break;
case 3:
ChangeViewMode(M_MULTI_BYTES);
break;
case 4:
ChangeViewMode(M_BIT_SHIFT,2);
break;
case 5:
ChangeViewMode(M_BIT_SHIFT,4);
break;
case 6:
ChangeViewMode(M_BIT_SHIFT,8);
break;
default:
ChangeViewMode(M_DEFAULT);
}
}
}
}
}
void CMdispMFCView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
UpdateComboBoxWithCurrentViewMode();
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CMdispMFCView::UpdateComboBoxWithCurrentViewMode()
{
CComboBox *ViewModeComboBox = ((CMainFrame*)AfxGetMainWnd())->GetToolbarViewModeCombo();
if(ViewModeComboBox)
{
if(m_currentViewMode == M_DEFAULT)
ViewModeComboBox->SelectString(0,MIL_TEXT("M_DEFAULT"));
else if(m_currentViewMode == M_TRANSPARENT)
ViewModeComboBox->SelectString(0,MIL_TEXT("M_TRANSPARENT"));
else if(m_currentViewMode==M_AUTO_SCALE)
ViewModeComboBox->SelectString(0,MIL_TEXT("M_AUTO_SCALE"));
else if(m_currentViewMode==M_MULTI_BYTES)
ViewModeComboBox->SelectString(0,MIL_TEXT("M_MULTI_BYTES"));
else if(m_currentViewMode==M_BIT_SHIFT)
{
if(m_currentShiftValue == 2)
ViewModeComboBox->SelectString(0,MIL_TEXT("M_BIT_SHIFT:2"));
else if(m_currentShiftValue == 4)
ViewModeComboBox->SelectString(0,MIL_TEXT("M_BIT_SHIFT:4"));
else if(m_currentShiftValue == 8)
ViewModeComboBox->SelectString(0,MIL_TEXT("M_BIT_SHIFT:8"));
}
ViewModeComboBox->UpdateData(FALSE);
}
}
void CMdispMFCView::Zoom(MIL_DOUBLE ZoomFactorToApplyX, MIL_DOUBLE ZoomFactorToApplyY)
{
MdispZoom(m_MilDisplay, ZoomFactorToApplyX, ZoomFactorToApplyY);
}
void CMdispMFCView::ChangeViewMode(MIL_INT ViewMode, MIL_INT ShiftValue)
{
if(m_MilDisplay)
{
MdispControl(m_MilDisplay, M_VIEW_MODE, ViewMode);
if(ViewMode == M_BIT_SHIFT)
MdispControl(m_MilDisplay, M_VIEW_BIT_SHIFT, ShiftValue);
if(MdispInquire(m_MilDisplay, M_VIEW_MODE,M_NULL)==ViewMode)
{
m_currentViewMode = ViewMode;
m_currentShiftValue = ShiftValue;
UpdateComboBoxWithCurrentViewMode();
}
}
}
void CMdispMFCView::InitializeOverlay()
{
if ((!m_isOverlayInitialized) && (m_MilDisplay))
{
if ((((CMdispMFCDoc*)GetDocument())->m_MilImage) && (m_MilDisplay) )
{
MdispControl(m_MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(m_MilDisplay, M_OVERLAY_ID, &m_MilOverlayImage);
MdispControl(m_MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MdispControl(m_MilDisplay, M_OVERLAY_SHOW, M_DISABLE);
long imageWidth = (long)MbufInquire(m_MilOverlayImage,M_SIZE_X,M_NULL);
long imageHeight = (long)MbufInquire(m_MilOverlayImage,M_SIZE_Y,M_NULL);
MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);
MgraColor(M_DEFAULT, M_COLOR_WHITE);
MgraText(M_DEFAULT, m_MilOverlayImage, (imageWidth/9), (imageHeight/5),
MIL_TEXT(" -------------------- "));
MgraText(M_DEFAULT, m_MilOverlayImage, (imageWidth/9), ((imageHeight/5)+25),
MIL_TEXT(" - MIL Overlay Text - "));
MgraText(M_DEFAULT, m_MilOverlayImage, (imageWidth/9), ((imageHeight/5)+50),
MIL_TEXT(" -------------------- "));
MgraColor(M_DEFAULT, M_COLOR_GREEN);
MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, (imageHeight/5),
MIL_TEXT(" -------------------- "));
MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, ((imageHeight/5)+25),
MIL_TEXT(" - MIL Overlay Text - "));
MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, ((imageHeight/5)+50),
MIL_TEXT(" -------------------- "));
MappControl(M_DEFAULT, M_ERROR_HOOKS, M_DISABLE);
MbufControl(m_MilOverlayImage, M_DC_ALLOC, M_DEFAULT);
MappControl(M_DEFAULT, M_ERROR_HOOKS, M_ENABLE);
HDC OverlayDC = (HDC)MbufInquire(m_MilOverlayImage, M_DC_HANDLE, M_NULL);
if(OverlayDC != M_NULL)
{
CDC NewDC;
NewDC.Attach(OverlayDC);
NewDC.SetBkMode(TRANSPARENT);
m_pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
m_penOld = NewDC.SelectObject(&m_pen);
NewDC.MoveTo(0,(imageHeight/2));
NewDC.LineTo(imageWidth,(imageHeight/2));
NewDC.MoveTo((imageWidth/2),0);
NewDC.LineTo((imageWidth/2),imageHeight);
MosStrcpy(m_chText, 80, MIL_TEXT("GDI Overlay Text "));
NewDC.SetTextColor(RGB(255, 0, 0));
NewDC.TextOut((imageWidth*3/18),(imageHeight*17/24), m_chText,
(MIL_INT32)MosStrlen(m_chText));
NewDC.SetTextColor(RGB(255, 255, 0));
NewDC.TextOut((imageWidth*12/18),(imageHeight*17/24), m_chText,
(MIL_INT32)MosStrlen(m_chText));
NewDC.SelectObject(m_penOld);
m_pen.DeleteObject();
NewDC.Detach();
MbufControl(m_MilOverlayImage, M_DC_FREE, M_DEFAULT);
MbufControl(m_MilOverlayImage, M_MODIFIED, M_DEFAULT);
}
MdispControl(m_MilDisplay, M_OVERLAY_SHOW, M_ENABLE);
m_isOverlayInitialized = true;
}
}
}
void CMdispMFCView::OnSizing(UINT fwSide, LPRECT pRect)
{
if(m_MilDisplay && !m_isWindowed)
CView::OnSizing(fwSide, pRect);
}
void CMdispMFCView::OnCompression(UINT nID)
{
UINT CompressionTypeIndex = nID - s_FirstCompressionTypeControlInRange;
ASSERT(CompressionTypeIndex < (sizeof(s_CompressionType) / sizeof(MIL_INT)));
ChangeCompressionType(s_CompressionType[CompressionTypeIndex]);
}
void CMdispMFCView::OnUpdateCompression(CCmdUI *pCmdUI)
{
pCmdUI->Enable(IsNetworkedSystem());
UINT CompressionTypeIndex = pCmdUI->m_nID - s_FirstCompressionTypeControlInRange;
ASSERT(CompressionTypeIndex < (sizeof(s_CompressionType) / sizeof(MIL_INT)));
pCmdUI->SetRadio(m_currentCompressionType == s_CompressionType[CompressionTypeIndex]);
}
void CMdispMFCView::OnAsynchronousMode(UINT nID)
{
UINT AsynchronousModeIndex = nID - s_FirstAsynchronousMaxUpdateRateControlInRange;
ASSERT(AsynchronousModeIndex < (sizeof(s_AsynchronousMaxUpdateRate) / sizeof(MIL_INT)));
ChangeAsynchronousMode(s_AsynchronousMaxUpdateRate[AsynchronousModeIndex] != M_DISABLE,
s_AsynchronousMaxUpdateRate[AsynchronousModeIndex]);
}
void CMdispMFCView::OnUpdateAsynchronousMode(CCmdUI *pCmdUI)
{
pCmdUI->Enable(IsNetworkedSystem());
UINT AsynchronousModeIndex = pCmdUI->m_nID - s_FirstAsynchronousMaxUpdateRateControlInRange;
ASSERT(AsynchronousModeIndex < (sizeof(s_AsynchronousMaxUpdateRate) / sizeof(MIL_INT)));
bool SetRadio = m_isInAsynchronousMode ||
(s_AsynchronousMaxUpdateRate[AsynchronousModeIndex] == M_DISABLE);
if(m_isInAsynchronousMode)
SetRadio = (s_AsynchronousMaxUpdateRate[AsynchronousModeIndex] ==
m_currentAsynchronousFrameRate);
pCmdUI->SetRadio(SetRadio);
}
void CMdispMFCView::OnQFactor(UINT nID)
{
UINT QFactorIndex = nID - s_FirstQFactorControlInRange;
ASSERT(QFactorIndex < (sizeof(s_QFactor) / sizeof(MIL_INT)));
ChangeQFactor(s_QFactor[QFactorIndex]);
}
void CMdispMFCView::OnUpdateQFactor(CCmdUI *pCmdUI)
{
pCmdUI->Enable(IsNetworkedSystem());
UINT QFactorIndex = pCmdUI->m_nID - s_FirstQFactorControlInRange;
ASSERT(QFactorIndex < (sizeof(s_QFactor) / sizeof(MIL_INT)));
pCmdUI->SetRadio(s_QFactor[QFactorIndex] == m_currentQFactor);
}
void CMdispMFCView::ChangeCompressionType(MIL_INT CompressionType)
{
if(m_MilDisplay)
{
MdispControl(m_MilDisplay, M_COMPRESSION_TYPE, CompressionType);
if(MdispInquire(m_MilDisplay, M_COMPRESSION_TYPE, M_NULL) == CompressionType)
{
m_currentCompressionType = CompressionType;
}
}
}
void CMdispMFCView::ChangeAsynchronousMode(bool Enabled, MIL_INT FrameRate)
{
if(Enabled && (FrameRate != m_currentAsynchronousFrameRate))
{
if(m_MilDisplay)
{
MdispControl(m_MilDisplay, M_UPDATE_RATE_MAX, FrameRate);
if(MdispInquire(m_MilDisplay, M_UPDATE_RATE_MAX, M_NULL) == FrameRate)
{
m_currentAsynchronousFrameRate = FrameRate;
}
}
}
if((Enabled && !m_isInAsynchronousMode) ||
(!Enabled && m_isInAsynchronousMode))
{
if(m_MilDisplay)
{
MdispControl(m_MilDisplay, M_ASYNC_UPDATE, (Enabled ? M_ENABLE : M_DISABLE));
if(MdispInquire(m_MilDisplay, M_ASYNC_UPDATE, M_NULL) ==
(Enabled ? M_ENABLE : M_DISABLE))
{
m_isInAsynchronousMode = Enabled;
}
}
}
}
void CMdispMFCView::ChangeQFactor(MIL_INT QFactor)
{
if(m_MilDisplay)
{
MdispControl(m_MilDisplay, M_Q_FACTOR, QFactor);
if(MdispInquire(m_MilDisplay, M_Q_FACTOR, M_NULL) == QFactor)
{
m_currentQFactor = QFactor;
}
}
}
bool CMdispMFCView::IsNetworkedSystem()
{
bool NetworkedSystem = false;
MIL_ID SystemId = ((CMdispMFCApp*)AfxGetApp())->m_MilSystem;
if(SystemId)
NetworkedSystem = (MsysInquire(SystemId, M_LOCATION, M_NULL) == M_REMOTE);
return NetworkedSystem;
}
void CMdispMFCView::OnRestrictCursor()
{
if(m_MilDisplay)
{
if(m_currentRestrictCursor == M_DISABLE)
{
MdispControl(m_MilDisplay, M_RESTRICT_CURSOR, M_ENABLE);
}
else
{
MdispControl(m_MilDisplay, M_RESTRICT_CURSOR, M_DISABLE);
}
MdispInquire(m_MilDisplay, M_RESTRICT_CURSOR, &m_currentRestrictCursor);
}
}
void CMdispMFCView::OnUpdateRestrictCursor(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_isExclusive);
pCmdUI->SetCheck(m_currentRestrictCursor == M_ENABLE);
}
void CMdispMFCView::OnGraphicsAnnotations()
{
m_bGraphicsAnnotations = !m_bGraphicsAnnotations;
if(m_MilDisplay)
{
if(m_bGraphicsAnnotations)
{
if(!m_MilGraphContext && !m_MilGraphList)
{
MIL_INT BufSizeX = 0, BufSizeY = 0;
MIL_INT Offset = 15;
MgraAlloc(((CMdispMFCApp*)AfxGetApp())->m_MilSystem, &m_MilGraphContext);
MgraAllocList(((CMdispMFCApp*)AfxGetApp())->m_MilSystem, M_DEFAULT, &m_MilGraphList);
MdispControl(m_MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, m_MilGraphList);
MdispControl(m_MilDisplay, M_UPDATE_GRAPHIC_LIST, M_DISABLE);
MbufInquire(((CMdispMFCDoc*)GetDocument())->m_MilImage, M_SIZE_X, &BufSizeX);
MbufInquire(((CMdispMFCDoc*)GetDocument())->m_MilImage, M_SIZE_Y, &BufSizeY);
MgraClear(m_MilGraphContext, m_MilGraphList);
MgraColor(m_MilGraphContext, M_COLOR_LIGHT_BLUE);
MgraRect(m_MilGraphContext, m_MilGraphList, Offset, Offset, BufSizeX - Offset, BufSizeY - Offset);
MgraColor(m_MilGraphContext, M_COLOR_GREEN);
MgraControl(m_MilGraphContext, M_BACKGROUND_MODE, M_TRANSPARENT);
MgraControl(m_MilGraphContext, M_TEXT_ALIGN_HORIZONTAL, M_CENTER);
MgraControl(m_MilGraphContext, M_TEXT_ALIGN_VERTICAL, M_CENTER);
MgraControl(m_MilGraphContext, M_FONT_SIZE, 12);
MgraFont(m_MilGraphContext, MIL_FONT_NAME(MIL_TEXT("Arial:Bold")));
MgraText(m_MilGraphContext, m_MilGraphList, BufSizeX/2, Offset, MIL_TEXT("Interactive Graphic Annotations"));
MdispControl(m_MilDisplay, M_UPDATE_GRAPHIC_LIST, M_ENABLE);
MdispControl(m_MilDisplay, M_GRAPHIC_LIST_INTERACTIVE, M_ENABLE);
MgraHookFunction(m_MilGraphList, M_INTERACTIVE_GRAPHIC_STATE_MODIFIED, GraphicListModifiedHookFct, (void*)this);
}
}
else
{
MgraHookFunction(m_MilGraphList, M_INTERACTIVE_GRAPHIC_STATE_MODIFIED+M_UNHOOK, GraphicListModifiedHookFct, (void*)this);
MdispControl(m_MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, M_NULL);
if(m_MilGraphList)
{
MgraFree(m_MilGraphList);
m_MilGraphList = M_NULL;
}
if(m_MilGraphContext)
{
MgraFree(m_MilGraphContext);
m_MilGraphContext = M_NULL;
}
}
}
}
void CMdispMFCView::OnUpdateGraphicsAnnotations(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(m_bGraphicsAnnotations);
}
void CMdispMFCView::OnGraRectangle()
{
if(m_bGraphicsAnnotations)
{
MgraColor(m_MilGraphContext, M_COLOR_WHITE);
MgraInteractive(m_MilGraphContext, m_MilGraphList, M_GRAPHIC_TYPE_RECT, M_DEFAULT, M_DEFAULT);
m_PrimitiveInCreation = M_GRAPHIC_TYPE_RECT;
}
}
void CMdispMFCView::OnGraCircle()
{
if(m_bGraphicsAnnotations)
{
MgraColor(m_MilGraphContext, M_COLOR_YELLOW);
MgraInteractive(m_MilGraphContext, m_MilGraphList, M_GRAPHIC_TYPE_ARC, M_DEFAULT, M_DEFAULT);
m_PrimitiveInCreation = M_GRAPHIC_TYPE_ARC;
}
}
void CMdispMFCView::OnGraPolygon()
{
if(m_bGraphicsAnnotations)
{
MgraColor(m_MilGraphContext, M_COLOR_MAGENTA);
MgraInteractive(m_MilGraphContext, m_MilGraphList, M_GRAPHIC_TYPE_POLYGON, M_DEFAULT, M_DEFAULT);
m_PrimitiveInCreation = M_GRAPHIC_TYPE_POLYGON;
}
}
void CMdispMFCView::OnUpdateGraRectangle(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bGraphicsAnnotations);
pCmdUI->SetCheck(m_PrimitiveInCreation == M_GRAPHIC_TYPE_RECT);
}
void CMdispMFCView::OnUpdateGraCircle(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bGraphicsAnnotations);
pCmdUI->SetCheck(m_PrimitiveInCreation == M_GRAPHIC_TYPE_ARC);
}
void CMdispMFCView::OnUpdateGraPolygon(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bGraphicsAnnotations);
pCmdUI->SetCheck(m_PrimitiveInCreation == M_GRAPHIC_TYPE_POLYGON);
}
void CMdispMFCView::OnGraChooseColor()
{
COLORREF NewColor = M_NULL;
if(ShowColorChooser(NewColor))
{
NewColor = M_RGB888(GetRValue(NewColor), GetGValue(NewColor), GetBValue(NewColor));
MgraControlList(m_MilGraphList, M_ALL_SELECTED, M_DEFAULT, M_COLOR, (MIL_INT)NewColor);
MgraControlList(m_MilGraphList, M_ALL, M_DEFAULT, M_GRAPHIC_SELECTED, M_FALSE);
}
}
void CMdispMFCView::OnUpdateGraChooseColor(CCmdUI *pCmdUI)
{
if(m_bGraphicsAnnotations)
{
pCmdUI->Enable(true);
}
else
{
pCmdUI->Enable(false);
}
}
void CMdispMFCView::OnGraFill()
{
MgraControlList(m_MilGraphList, M_ALL_SELECTED, M_DEFAULT, M_FILLED, M_TRUE);
MgraControlList(m_MilGraphList, M_ALL, M_DEFAULT, M_GRAPHIC_SELECTED, M_FALSE);
}
void CMdispMFCView::OnUpdateGraFill(CCmdUI *pCmdUI)
{
if(m_bGraphicsAnnotations)
{
pCmdUI->Enable(true);
}
else
{
pCmdUI->Enable(false);
}
}
bool CMdispMFCView::ShowColorChooser(COLORREF& NewColor)
{
bool Success = false;
CColorDialog ColorDlg(NewColor, CC_FULLOPEN);
if(ColorDlg.DoModal() == IDOK)
{
Success = true;
NewColor = ColorDlg.GetColor();
}
return Success;
}