15,979
社区成员
发帖
与我相关
我的任务
分享
#include "StdAfx.h"
#include "MarkDrawrectanglePlugin.h"
#include "RemoteSensingImageSystem.h"
#include "FrameworkTool/ViewArgs.h"
#include "FrameworkTool/ScrollHelper.h"
#include "FrameworkTool/ViewHelper.h"
#include "resource.h"
#include "afxwin.h"
#include <list>
namespace Plugins
{
CMarkDrawrectanglePlugin::CMarkDrawrectanglePlugin(ImageTool::CImage *&pImg,
FrameworkTool::CHistoryController* &pHistoryCntroller,
FrameworkTool::CViewArgs *pCurViewArgs,
UINT ID,
FrameworkTool::PluginPriority pluginPriority)
:m_pCurImg(pImg),m_pHistoryCntroller(pHistoryCntroller),CPluginInterface(pCurViewArgs,ID,pluginPriority)
{
p_count=1;
p_num=0;
}
void CMarkDrawrectanglePlugin::Execute()
{
//FrameworkTool::CCommandInterface *command = new Command::CCheckerCornerCommand(m_pCurImg,m_pHistoryCntroller);
//command->Execute(); //执行的是BackupFullImgToFileCommand::Execute()
//m_pHistoryCntroller->AddToUndoList(command);
}
void CMarkDrawrectanglePlugin::DoMouseLBtnUp(const CPoint &mousePos)
{
HCURSOR m_HCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);;
::SetCursor(m_HCross);
m_cLatterPoint = mousePos;
CPoint posInImg;
if (p_count)
{
m_bIsRefPointInImg = m_pViewArgs->GetViewHelper()->GetImagePos(mousePos,posInImg,m_pCurImg->GetImageWidth(),m_pCurImg->GetImageHeight());
if (m_bIsRefPointInImg)
{
p_corners[p_count]=posInImg;
switch(p_count)
{
case 2:
//m_pCurImg->RightUp=p_corners[1];
m_pCurImg->RightUp.x=p_corners[1].y;
m_pCurImg->RightUp.y=p_corners[1].x;
RDpoint.push_back(p_corners[1]);
p_count--;
p_num++;
break;
default:
break;
}
}
}
}
void CMarkDrawrectanglePlugin::DoMouseLBtnDown(const CPoint &mousePos )
{
HCURSOR m_HCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);;
::SetCursor(m_HCross);
m_cCurPoint = mousePos;
CPoint posInImg;
if (p_count)
{
m_bIsRefPointInImg = m_pViewArgs->GetViewHelper()->GetImagePos(mousePos,posInImg,m_pCurImg->GetImageWidth(),m_pCurImg->GetImageHeight());
if (m_bIsRefPointInImg)
{
p_corners[p_count]=posInImg;
switch(p_count)
{
case 1:
//m_pCurImg->LeftUp=p_corners[0];
m_pCurImg->LeftUp.x=p_corners[0].y;
m_pCurImg->LeftUp.y=p_corners[0].x;
LUpoint.push_back(p_corners[0]);
p_count++;
default:
break;
}
}
}
}
void CMarkDrawrectanglePlugin::DoMouseMove(const CPoint &mousePos )
{
mousePoint=mousePos;
}
void CMarkDrawrectanglePlugin::DoDraw(CDC *pDC,const CPoint &bltOffset)
{
#define coordinate(i,j) coordinate[m_pCurImg->GetImageWidth()*(j)+(i)]
int scale=m_pViewArgs->GetViewHelper()->GetViewScale();
int i,j,m,n;
CPoint A;
CPoint B;
CPoint scrollPos=m_pViewArgs->GetScrollHelper()->GetScrollPosition();
CPen pPenRed;
pPenRed.CreatePen(PS_SOLID,1,RGB(255,0,0));
pDC->SelectObject(&pPenRed);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
pDC->SelectObject(&pBrush);
if (scale>100) //精确
{
float accurateScale = scale/100;
int offsetX=-scrollPos.x + bltOffset.x;
int offsetY=-scrollPos.y + bltOffset.y;
CPoint A;
CPoint B;
for (int ip=0;ip<p_num;ip++)
{
A=m_cCurPoint;
B=m_cLatterPoint;
i=A.x;
j=A.y;
m=B.x;
n=B.y;
/* if(RDpoint.size()==0||LUpoint.size()==0)break;
B=RDpoint.back();
A=LUpoint.back();
RDpoint.pop_back();
LUpoint.pop_back();
pDC->Rectangle(A.x,A.y,B.x,B.y);*/
/*CPoint leftPosInDC=CPoint(int(i*accurateScale+offsetX-1+0.5f),int(j*accurateScale+offsetY+0.5f));
CPoint rightPosInDC=CPoint(int(i*accurateScale+offsetX+1+0.5f),int(j*accurateScale+offsetY+0.5f));
CPoint topPosInDC=CPoint(int(i*accurateScale+offsetX+0.5f),int(j*accurateScale+offsetY-1+0.5f));
CPoint buttomPosInDC=CPoint(int(i*accurateScale+offsetX+0.5f),int(j*accurateScale+offsetY+1+0.5f));
pDC->MoveTo(leftPosInDC);
pDC->LineTo(rightPosInDC);
pDC->MoveTo(topPosInDC);
pDC->LineTo(buttomPosInDC);*/
pDC->MoveTo(A);
pDC->LineTo(A.x,B.y);
pDC->MoveTo(A.x,B.y);
pDC->LineTo(B.x,B.y);
pDC->MoveTo(B.x,B.y);
pDC->LineTo(B.x,A.y);
pDC->MoveTo(B.x,A.y);
pDC->LineTo(A);
}
}
else
{
float accurateScale=scale/100.0f;
int offsetX=-scrollPos.x + bltOffset.x;
int offsetY=-scrollPos.y + bltOffset.y;
CPoint C,D;
for (int ip=0;ip<p_num;ip++)
{
i=A.x;
j=A.y;
A=m_cCurPoint;
B=m_cLatterPoint;
pDC->MoveTo(A);
pDC->LineTo(A.x,B.y);
pDC->MoveTo(A.x,B.y);
pDC->LineTo(B.x,B.y);
pDC->MoveTo(B.x,B.y);
pDC->LineTo(B.x,A.y);
pDC->MoveTo(B.x,A.y);
pDC->LineTo(A);
}
}
}
}