You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
547 lines
11 KiB
C++
547 lines
11 KiB
C++
//////////////////////////////////////////////////////////////////////////////
|
|
//文件: CItem类扩展
|
|
//主要功能:
|
|
// 操作各类元素或完成一定的功能
|
|
//
|
|
//程序编写: 2006-12-07
|
|
//
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "StdAfx.h"
|
|
#include ".\itemcalibrate.h"
|
|
#include "SigmaDoc.h"
|
|
#include "SigmaView.h"
|
|
//#include "CoordinateDlg.h"
|
|
//#include "DlgCoordinateMode.h"
|
|
#include ".\actionadditem.h"
|
|
#include ".\ActionListItem.h"
|
|
#include ".\actionbackupitem.h"
|
|
|
|
CItemCalibrate::CItemCalibrate(CSigmaDoc* ppDoc)
|
|
: CItemSelectPoint(ppDoc)
|
|
, m_idea(DF_CALIBRATE_FOUR_POINT)
|
|
, m_mode(POINT_INPUT)
|
|
{
|
|
num=4;
|
|
this->SetType(ITEM_CALIBRATE);
|
|
m_nCoorIdea=0;
|
|
m_nBackupID=0;
|
|
}
|
|
|
|
CItemCalibrate::~CItemCalibrate(void)
|
|
{
|
|
}
|
|
|
|
int CItemCalibrate::GetSubMenu()
|
|
{
|
|
return GetSelectSubMenu();
|
|
}
|
|
|
|
bool CItemCalibrate::CalibrateForFourPoint(std::vector<CPoint2D> & pts, COORDINATE_MODE mode)
|
|
{
|
|
if (pts.size() != 8)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (mode == COORDINATE_MODE_DMS)
|
|
{
|
|
ConvertToDMSAndFill(pts, 4);
|
|
}
|
|
else if (mode == COORDINATE_MODE_DEGREE)
|
|
{
|
|
ConvertToDegreeAndFill(pts, 4);
|
|
}
|
|
else
|
|
{
|
|
FillCoordinateInput(pts, 4);
|
|
}
|
|
|
|
SelectList.RemoveAll();
|
|
Select(NULL, pts[4]);
|
|
Select(NULL, pts[5]);
|
|
Select(NULL, pts[6]);
|
|
Select(NULL, pts[7]);
|
|
|
|
//for redo/undo
|
|
//GetDoc()->BeginProgress("Backup Elements...");
|
|
CActionBackupItem *pAction = new CActionBackupItem(GetDoc(), m_nBackupID);
|
|
if (pAction->BackupAllElements() > 0)
|
|
{
|
|
pAction->BackupNew();
|
|
GetDoc()->SetActionItem(pAction);
|
|
GetDoc()->Modified();
|
|
}
|
|
else
|
|
delete pAction;
|
|
//GetDoc()->EndProgress();
|
|
|
|
MetaToImage(FALSE); //校正之前将元文件转换为图像文件
|
|
|
|
//GetDoc()->BeginProgress("Calibrate...");
|
|
num = 4;
|
|
m_idea = DF_CALIBRATE_FOUR_POINT;
|
|
BOOL bInvalidate = CalibrateOther();
|
|
//GetDoc()->EndProgress();
|
|
|
|
if (bInvalidate)
|
|
{
|
|
GetDoc()->Invalidate();
|
|
//GetDoc()->SetModifiedFlag();
|
|
}
|
|
//GetDoc()->EnableDefaultTool();
|
|
return true;
|
|
}
|
|
|
|
bool CItemCalibrate::CalibrateForTwoPoint(std::vector<CPoint2D> & pts, COORDINATE_MODE mode)
|
|
{
|
|
if (pts.size() != 4)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (mode == COORDINATE_MODE_DMS)
|
|
{
|
|
ConvertToDMSAndFill(pts, 2);
|
|
}
|
|
else if (mode == COORDINATE_MODE_DEGREE)
|
|
{
|
|
ConvertToDegreeAndFill(pts, 2);
|
|
}
|
|
else
|
|
{
|
|
FillCoordinateInput(pts, 2);
|
|
}
|
|
|
|
SelectList.RemoveAll();
|
|
Select(NULL, pts[2]);
|
|
Select(NULL, pts[3]);
|
|
|
|
//for redo/undo
|
|
//GetDoc()->BeginProgress("Backup Elements...");
|
|
CActionBackupItem *pAction = new CActionBackupItem(GetDoc(), m_nBackupID);
|
|
if (pAction->BackupAllElements() > 0)
|
|
{
|
|
pAction->BackupNew();
|
|
GetDoc()->SetActionItem(pAction);
|
|
GetDoc()->Modified();
|
|
}
|
|
else
|
|
delete pAction;
|
|
//GetDoc()->EndProgress();
|
|
|
|
MetaToImage(FALSE); //校正之前将元文件转换为图像文件
|
|
|
|
//GetDoc()->BeginProgress("Calibrate...");
|
|
num = 2;
|
|
m_idea = DF_CALIBRATE_TWO_POINT;
|
|
BOOL bInvalidate = CalibrateOther();
|
|
//GetDoc()->EndProgress();
|
|
|
|
if (bInvalidate)
|
|
{
|
|
GetDoc()->Invalidate();
|
|
//GetDoc()->SetModifiedFlag();
|
|
}
|
|
//GetDoc()->EnableDefaultTool();
|
|
return true;
|
|
}
|
|
|
|
void CItemCalibrate::ConvertToDMSAndFill(std::vector<CPoint2D> & pts, int num)
|
|
{
|
|
//度分秒方式
|
|
CExchangeXYZ xyz;
|
|
xyz.SetProjection(&GetDoc()->GetDraw()->m_ExchangeXYZ);
|
|
|
|
if (num == 4)
|
|
{
|
|
CPoint2D pt0 = pts[0];
|
|
CPoint2D pt1 = pts[1];
|
|
CPoint2D pt2 = pts[2];
|
|
CPoint2D pt3 = pts[3];
|
|
|
|
xyz.ToXY_DMS(pt0.x0, pt0.y0);
|
|
xyz.ToXY_DMS(pt1.x0, pt1.y0);
|
|
xyz.ToXY_DMS(pt2.x0, pt2.y0);
|
|
xyz.ToXY_DMS(pt3.x0, pt3.y0);
|
|
|
|
PointList.RemoveAll();
|
|
PointList.AddTail(pt0);
|
|
PointList.AddTail(pt1);
|
|
PointList.AddTail(pt2);
|
|
PointList.AddTail(pt3);
|
|
}
|
|
else if (num == 2)
|
|
{
|
|
CPoint2D pt0 = pts[0];
|
|
CPoint2D pt1 = pts[1];
|
|
|
|
xyz.ToXY_DMS(pt0.x0, pt0.y0);
|
|
xyz.ToXY_DMS(pt1.x0, pt1.y0);
|
|
|
|
PointList.RemoveAll();
|
|
PointList.AddTail(pt0);
|
|
PointList.AddTail(pt1);
|
|
}
|
|
}
|
|
|
|
void CItemCalibrate::ConvertToDegreeAndFill(std::vector<CPoint2D> & pts, int num)
|
|
{
|
|
CExchangeXYZ xyz;
|
|
xyz.SetProjection(&GetDoc()->GetDraw()->m_ExchangeXYZ);
|
|
|
|
if (num == 4)
|
|
{
|
|
CPoint2D pt0 = pts[0];
|
|
CPoint2D pt1 = pts[1];
|
|
CPoint2D pt2 = pts[2];
|
|
CPoint2D pt3 = pts[3];
|
|
|
|
xyz.ToXY_D(pt0.x0, pt0.y0);
|
|
xyz.ToXY_D(pt1.x0, pt1.y0);
|
|
xyz.ToXY_D(pt2.x0, pt2.y0);
|
|
xyz.ToXY_D(pt3.x0, pt3.y0);
|
|
|
|
PointList.RemoveAll();
|
|
PointList.AddTail(pt0);
|
|
PointList.AddTail(pt1);
|
|
PointList.AddTail(pt2);
|
|
PointList.AddTail(pt3);
|
|
}
|
|
else if (num == 2)
|
|
{
|
|
CPoint2D pt0 = pts[0];
|
|
CPoint2D pt1 = pts[1];
|
|
|
|
xyz.ToXY_D(pt0.x0, pt0.y0);
|
|
xyz.ToXY_D(pt1.x0, pt1.y0);
|
|
|
|
PointList.RemoveAll();
|
|
PointList.AddTail(pt0);
|
|
PointList.AddTail(pt1);
|
|
}
|
|
}
|
|
|
|
void CItemCalibrate::FillCoordinateInput(std::vector<CPoint2D> & pts, int num)
|
|
{
|
|
PointList.RemoveAll();
|
|
if (num == 4)
|
|
{
|
|
PointList.AddTail(pts.at(0));
|
|
PointList.AddTail(pts[1]);
|
|
PointList.AddTail(pts[2]);
|
|
PointList.AddTail(pts[3]);
|
|
}
|
|
else
|
|
{
|
|
PointList.AddTail(pts[0]);
|
|
PointList.AddTail(pts[1]);
|
|
}
|
|
}
|
|
|
|
void CItemCalibrate::OnDraw(CXyDC* pDC)
|
|
{
|
|
}
|
|
|
|
void CItemCalibrate::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk)
|
|
{
|
|
CPoint2D dp=GetDC()->GetReal(point);
|
|
switch(m_mode)
|
|
{
|
|
default:
|
|
case POINT_INPUT: //手工输入式
|
|
{
|
|
//CCoordinateDlg dlg;
|
|
//dlg.x=dp.x0;
|
|
//dlg.y=dp.y0;
|
|
//dlg.m_nIndex=(int)(PointList.GetCount())+1;
|
|
//if(dlg.DoModal()!=IDOK) break;
|
|
if(Select(NULL,dp))
|
|
{
|
|
//dp.x0=dlg.x;
|
|
//dp.y0=dlg.y;
|
|
|
|
//将经纬度转换为XY坐标
|
|
if(!GetDoc()->GetDraw()->GetProjection().IsEmpty())
|
|
{
|
|
switch(m_nCoorIdea)
|
|
{
|
|
default:
|
|
case 0: //XY坐标方式
|
|
break;
|
|
case 1: //度分秒方式
|
|
{
|
|
CExchangeXYZ xyz;
|
|
xyz.SetProjection(&GetDoc()->GetDraw()->m_ExchangeXYZ);
|
|
xyz.ToXY_DMS(dp.x0, dp.y0);
|
|
}
|
|
break;
|
|
case 2: //度方式
|
|
{
|
|
CExchangeXYZ xyz;
|
|
xyz.SetProjection(&GetDoc()->GetDraw()->m_ExchangeXYZ);
|
|
xyz.ToXY_D(dp.x0, dp.y0);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
PointList.AddTail(dp);
|
|
}
|
|
if(GetSelectCount()==num)
|
|
{
|
|
DoSelectEnd();
|
|
}
|
|
}
|
|
break;
|
|
case POINT_SELECT: //拾取点式
|
|
case POINT_FILE: //从文件获取坐标式
|
|
break;
|
|
}
|
|
}
|
|
|
|
BOOL CItemCalibrate::DoSelectEnd(void)
|
|
{
|
|
switch(m_idea)
|
|
{
|
|
case DF_CALIBRATE_TO_RECT:
|
|
case DF_CALIBRATE_FOUR_POINT:
|
|
case DF_CALIBRATE_TWO_POINT:
|
|
if(GetSelectCount()==num)break;
|
|
//GetDoc()->EnableDefaultTool();
|
|
return FALSE;
|
|
}
|
|
if(GetSelectCount()==0)
|
|
{
|
|
//GetDoc()->EnableDefaultTool();
|
|
return FALSE;
|
|
}
|
|
//GetDoc()->BeginWaitCursor();
|
|
|
|
//for redo/undo
|
|
//GetDoc()->BeginProgress("Backup Elements...");
|
|
CActionBackupItem *pAction=new CActionBackupItem(GetDoc(), m_nBackupID);
|
|
if (pAction->BackupAllElements() > 0)
|
|
{
|
|
pAction->BackupNew();
|
|
GetDoc()->SetActionItem(pAction);
|
|
}
|
|
else
|
|
{
|
|
delete pAction;
|
|
}
|
|
//GetDoc()->EndProgress();
|
|
|
|
MetaToImage(FALSE); //校正之前将元文件转换为图像文件
|
|
|
|
//GetDoc()->BeginProgress("Calibrate...");
|
|
BOOL bInvalidate=FALSE;
|
|
switch(m_idea)
|
|
{
|
|
case DF_CALIBRATE_ANY_POINT: bInvalidate=CalibrateAny(); break;
|
|
default: bInvalidate=CalibrateOther(); break;
|
|
}
|
|
//GetDoc()->EndProgress();
|
|
|
|
if(bInvalidate)
|
|
{
|
|
GetDoc()->Invalidate();
|
|
//GetDoc()->SetModifiedFlag();
|
|
}
|
|
//GetDoc()->EnableDefaultTool();
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CItemCalibrate::CalibrateAny(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
BOOL CItemCalibrate::CalibrateOther(void)
|
|
{
|
|
if(num<=0) return FALSE;
|
|
|
|
double *m,*n,*x,*y;
|
|
m=new double[num*4];
|
|
n=m+num;
|
|
x=n+num;
|
|
y=x+num;
|
|
SELECT_ITEM item;
|
|
CPoint2D pt;
|
|
POSITION pos=SelectList.GetHeadPosition();
|
|
POSITION pot=PointList.GetHeadPosition();
|
|
for(int i=0;i<num;i++)
|
|
{
|
|
item=SelectList.GetNext(pos);
|
|
pt=PointList.GetNext(pot);
|
|
m[i]=item.point.x0;
|
|
n[i]=item.point.y0;
|
|
x[i]=pt.x0;
|
|
y[i]=pt.y0;
|
|
}
|
|
|
|
BOOL bInvalidate=FALSE;
|
|
switch(m_idea)
|
|
{
|
|
case DF_CALIBRATE_TWO_POINT:
|
|
{
|
|
NCalibrate::CCalibrate2* pc=new NCalibrate::CCalibrate2;
|
|
pc->Create(m,n,x,y);
|
|
GetDoc()->GetDraw()->Calibrate(m_idea,pc);
|
|
delete pc;
|
|
bInvalidate=TRUE;
|
|
}
|
|
break;
|
|
case DF_CALIBRATE_FOUR_POINT:
|
|
{
|
|
NCalibrate::CCalibrate4* pc=new NCalibrate::CCalibrate4;
|
|
pc->Create(m,n,x,y);
|
|
GetDoc()->GetDraw()->Calibrate(m_idea,pc);
|
|
delete pc;
|
|
bInvalidate=TRUE;
|
|
}
|
|
break;
|
|
case DF_CALIBRATE_TO_RECT:
|
|
{
|
|
NCalibrate::CCalibrateToRect* pc=new NCalibrate::CCalibrateToRect;
|
|
pc->Create(m,n,x,y);
|
|
GetDoc()->GetDraw()->Calibrate(m_idea,pc);
|
|
delete pc;
|
|
bInvalidate=TRUE;
|
|
}
|
|
break;
|
|
}
|
|
if(m)delete m;
|
|
return bInvalidate;
|
|
}
|
|
|
|
BOOL CItemCalibrate::Select(POSITION pos, CPoint2D point)
|
|
{
|
|
CItemSelectPoint::Select(pos,point);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CItemCalibrate::Redo(void)
|
|
{
|
|
CItemSelectPoint::Redo();
|
|
CPoint2D pt=RedoPointList.RemoveHead();
|
|
PointList.AddTail(pt);
|
|
}
|
|
|
|
void CItemCalibrate::Undo(void)
|
|
{
|
|
CItemSelectPoint::Undo();
|
|
CPoint2D pt=PointList.RemoveTail();
|
|
RedoPointList.AddHead(pt);
|
|
}
|
|
|
|
BOOL CItemCalibrate::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
|
{
|
|
BOOL br=FALSE;
|
|
switch(m_mode)
|
|
{
|
|
default:
|
|
case POINT_INPUT: //手工输入式
|
|
break;
|
|
case POINT_SELECT: //拾取点式
|
|
case POINT_FILE: //从文件获取坐标式
|
|
br=CItemSelectPoint::OnSetCursor(pWnd,nHitTest,message);
|
|
break;
|
|
}
|
|
return br;
|
|
}
|
|
|
|
void CItemCalibrate::SetIdea(int nIdea)
|
|
{
|
|
m_idea=nIdea;
|
|
switch(m_idea)
|
|
{
|
|
case DF_CALIBRATE_TO_RECT:
|
|
case DF_CALIBRATE_FOUR_POINT:
|
|
num=4;
|
|
break;
|
|
case DF_CALIBRATE_TWO_POINT:
|
|
num=2;
|
|
break;
|
|
case DF_CALIBRATE_ANY_POINT:
|
|
num=-1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void CItemCalibrate::SetMode(int nMode)
|
|
{
|
|
m_mode=nMode;
|
|
}
|
|
|
|
int CItemCalibrate::GetIdea(void)
|
|
{
|
|
return m_idea;
|
|
}
|
|
|
|
int NItem::CItemCalibrate::GetCoordinateMode(void)
|
|
{
|
|
//CDlgCoordinateMode dlg;
|
|
///dlg.m_bEnableLB=!GetDoc()->GetDraw()->GetProjection().IsEmpty();
|
|
//if(dlg.DoModal()!=IDOK) return -1;
|
|
//m_nCoorIdea=dlg.m_nCoorMode;
|
|
return m_nCoorIdea;
|
|
}
|
|
|
|
int NItem::CItemCalibrate::MetaToImage(BOOL bAddAction)
|
|
{
|
|
CPositionList list;
|
|
if(GetDoc()->GetDraw()->GetElement(DOUBLEFOX_WMF, list)==0) return 0;
|
|
|
|
//for undo/redo
|
|
CPositionList plDel, plAdd;
|
|
|
|
POSITION pt, pos;
|
|
COne* pOne;
|
|
pos=list.GetHeadPosition();
|
|
while(pos)
|
|
{
|
|
pt=list.GetNext(pos);
|
|
pOne=GetDoc()->GetDraw()->GetAt(pt);
|
|
|
|
CMetaFile* pMeta=(CMetaFile*)pOne->GetValue();
|
|
if(pMeta)
|
|
{
|
|
CImageInsert* pImage=new CImageInsert();
|
|
if(pMeta->ToImage(*pImage))
|
|
{
|
|
COne* pNewOne=new COne;
|
|
pNewOne->CloneOtherParameter(*pOne);
|
|
pNewOne->SetType(DOUBLEFOX_IMAGE);
|
|
pNewOne->value=pImage;
|
|
POSITION ptNew=GetDoc()->GetDraw()->InsertElementBefore(pt, pNewOne);
|
|
|
|
plAdd.AddTail(ptNew);
|
|
plDel.AddTail(pt);
|
|
}
|
|
else
|
|
delete pImage;
|
|
}
|
|
}
|
|
|
|
if(bAddAction)
|
|
{
|
|
CActionListItem *pAction=new CActionListItem(GetDoc(), ID_META_TO_IMAGE);
|
|
//元素删除操作
|
|
pAction->AddDeleteItem(plDel);
|
|
//元素增加操作
|
|
CActionAddItem* pItem=new CActionAddItem(GetDoc(), 0, plAdd);
|
|
pAction->AddTailItem(pItem);
|
|
GetDoc()->SetActionItem(pAction);
|
|
}
|
|
|
|
return (int)list.GetCount();
|
|
}
|
|
|
|
void NItem::CItemCalibrate::SetBackupID(UINT nID)
|
|
{
|
|
m_nBackupID=nID;
|
|
}
|