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.
kev/Drawer/Module/GeoSigmaDraw/ItemProportion.cpp

486 lines
12 KiB
C++

#include "StdAfx.h"
#include ".\itemproportion.h"
#include "SigmaDoc.h"
#include "SigmaView.h"
//#include "ScaleSelectPage.h"
//#include "ScaleUnitPage.h"
int CItemProportion::m_bAlone=0;
CItemProportion::CItemProportion(CSigmaDoc* ppDoc)
: CItem(ppDoc)
, m_bLButtonDown(FALSE)
, m_nAlignsH(1)
, m_nProportionMode(1)
, m_color(0)
{
this->SetType(ITEM_PROPORTION);
m_pProportion=new CProportion;
m_pBakProportion=new CProportion;
//m_pDlg=NULL;
}
CItemProportion::~CItemProportion(void)
{
//if(m_pDlg)//为了焦点不在m_pDlg上时按ESC键可以正常删除的问题
//{
// m_pDlg->OnCancel();
// CRect8 rect=m_pProportion->GetRect();
// InvalidateRect(rect);
//}
//m_pDlg=NULL;
if(m_pProportion && !IsEditState())
delete m_pProportion;
m_pProportion=NULL;
if(m_pBakProportion)
delete m_pBakProportion;
m_pBakProportion=NULL;
}
BOOL CItemProportion::DoSelectEnd(void)
{
if(IsEditState())
{
m_pProportion=NULL;
}
else
{
POSITION pos=AddElement(m_pProportion,DOUBLEFOX_PROPORTION,false);
CItem::SetPos(pos);
GetDoc()->GetDraw()->SetElementColor(pos, m_color);
}
return TRUE;
}
void CItemProportion::SetPos(POSITION pos)
{
if(pos==NULL)
SetProportion(NULL);
else
SetProportion((CProportion*)GetDoc()->GetDraw()->GetAtValue(pos));
CItem::SetPos(pos);
}
void CItemProportion::SetProportion(CProportion* pProportion)
{
if(m_pProportion)
{
if(!IsEditState())
delete m_pProportion;
m_pProportion=NULL;
}
if(pProportion==NULL) return;
m_pProportion=pProportion;
if(m_pBakProportion==NULL)
m_pBakProportion=new CProportion;
*m_pBakProportion=*pProportion;
}
void CItemProportion::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk)
{
SetScreenDC(pDC);
if(m_pProportion)
{
CRect8 rect=m_pProportion->GetRect();
CPoint2D rp=GetDC()->GetReal(point);
//if(m_bLButtonDown)
//{
InvalideOne();// rect
//}
//InvalidateRect(rect);
m_pProportion->x0=rp.x0;
m_pProportion->y0=rp.y0;
//m_bLButtonDown=TRUE;
*m_pBakProportion=*m_pProportion;
//rect=m_pProportion->GetRect();
//InvalideOne(rect);
InvalideOne();
}
}
void CItemProportion::InvalideOne()
{
CRect rect = m_client;
CDC* pDC = m_pScreenDC;
//DCHelp::ClearDC(pDC);
pDC->BitBlt(0, 0, rect.Width(), rect.Height(), m_pBackGroundDC, 0, 0, SRCCOPY);
GetDC()->Create(pDC);
GetDC()->Draw(*m_pProportion, m_color);
//COne* pOne = m_pDoc->GetDraw()->CreateOne(m_pProportion, DOUBLEFOX_PROPORTION);
//pOne->Draw(*GetDC());
//m_pDoc->GetDraw()->RemoveAt(pOne);
//if (pOne != nullptr) {
// delete pOne;
// pOne = nullptr;
//}
}
void CItemProportion::OnDraw(CXyDC* pDC)
{
if(m_pProportion)
pDC->Draw(*m_pProportion, m_color);
}
void CItemProportion::DrawAssistant(CDC * pDC, int mouseX, int mouseY)
{
if (m_pProportion)
{
GetDC()->Create(pDC);
GetDC()->Draw(*m_pProportion, m_color);
}
}
/*
BOOL CItemProportion::InitPropertyGrid(CXTPPropertyGrid& grid)
{
ASSERT(m_pProportion);
CPropertyGridItemAdd ItemAdd(NULL);
CString strFormat=GetFloatFormatString();
CXTPPropertyGridItem* pItem=grid.AddCategory(IDS_STRING_Proportion);
ItemAdd.SetItem(pItem); pItem->Expand();
m_point.SetPoint(m_pProportion->x0,m_pProportion->y0);
ItemAdd.AddItemPoint(IDS_GI_COORDINATE,m_point,&m_point);
pItem=ItemAdd.AddItemString(IDS_STRING_SCALE,GetScaleString(m_pProportion->m_dScaleLength));pItem->SetReadOnly(TRUE);
//"普通式|现代式|流行式";
switch(m_pProportion->GetViewMode())
{
case CProportion::styleSimple: m_nProportionMode=0; break;
case CProportion::styleContemporaneity: m_nProportionMode=1; break;
case CProportion::stylePopular: m_nProportionMode=2; break;
}
ItemAdd.AddItemCombo(IDS_GI_PROPORTION_MODE, IDS_GI_PROPORTION_MODE_TYPE, m_nProportionMode, &m_nProportionMode);
pItem=ItemAdd.AddItem(new CCustomItemScaleWizard(IDS_GI_PROPORTION_SCALE,m_pProportion->m_dScaleLength,
strFormat, NULL));
((CCustomItemScaleWizard*)pItem)->SetUnit(GetDoc()->GetDraw()->GetUnit());
ItemAdd.AddItemLong(IDS_GI_PROPORTION_NUMBER, m_pProportion->num, NULL);
//ItemAdd.AddItemDouble(IDS_GI_PROPORTION_COEFFICIENT, m_pProportion->m_dCoefficient, strFormat, NULL);
pItem=ItemAdd.AddItemCombo(IDS_PROPORTION_UNIT, IDS_PROPORTION_UNIT_TYPE, m_pProportion->m_strUnit, &m_pProportion->m_strUnit);
pItem->SetFlags(xtpGridItemHasComboButton|xtpGridItemHasEdit);
if(this->IsEditState())
color=GetDoc()->GetDraw()->GetAt(GetPos())->color;
ItemAdd.AddItemColor(IDS_GI_COLOR, color,&color);
pItem=grid.AddCategory(IDS_STRING_Text);
ItemAdd.SetItem(pItem); pItem->Expand();
ItemAdd.AddItemDouble(IDS_GI_PROPORTION_TEXTSCALE, m_pProportion->m_dTextScale, strFormat, NULL);
DWORD md=m_pProportion->GetAlignsH();
if(md&CTextFlags::alignLeft) m_nAlignsH=0;
else if(md&CTextFlags::alignCenterH) m_nAlignsH=1;
else if(md&CTextFlags::alignRight) m_nAlignsH=2;
ItemAdd.AddItemCombo(IDS_GI_TEXT_ALIGNS_H, IDS_GI_TEXT_ALIGNS_H_IDEA, m_nAlignsH, &m_nAlignsH);
m_size = GetUnitMode().toPrintUnit(m_pProportion->m_size);
ItemAdd.AddItemUnitDouble(IDS_STRING_TEXT_HEIGHT, GetUnit(), m_size.cy, strFormat, &m_size.cy);
ItemAdd.AddItemUnitDouble(IDS_STRING_TEXT_WIDTH, GetUnit(), m_size.cx, strFormat, &m_size.cx);
ItemAdd.AddItemBool(IDS_GI_TEXT_HEIGHT_AND_WIDTH, m_bAlone, &m_bAlone);
CItem::InitPropertyGrid(grid);
return TRUE;
}
*/
void NItem::CItemProportion::InsertProportion(void)
{
/*
//根据比例值获得比例长度
if(GetDoc()->GetDraw()->m_dScaleFactor > 1.0)
{
CUnit cu;
double h = cu.Millimetres(GetDoc()->GetDraw()->m_unit.cx); //根据1个实际单位的毫米长度
//1毫米代表的实际长度
m_pProportion->m_dScaleLength = GetDoc()->GetDraw()->m_dScaleFactor / h;
//转换为1厘米代表的实际长度
m_pProportion->m_dScaleLength *= 10;
}
*/
m_pProportion->m_dScaleLength = 2000;
CPoint2D pt=CenterPoint();
//OnLButtonDown(0,GetDC()->GetScreen(pt));
}
int CItemProportion::ChangeScale(double scale)
{
//TODO:根据单位 将scale转换为scale length
m_pProportion->m_dScaleLength = scale;// / 100;
return 1;
}
int NItem::CItemProportion::ChangeScaleHeight(double height)
{
m_pProportion->m_dScaleHeight = height;
return 1;
}
int CItemProportion::GetScale()
{
//TODO:根据单位 转换scale length成scale
/*
double height = m_pProportion->m_dScaleLength;
CSize unit = GetDoc()->GetDraw()->GetUnit();
height *= 0.1; //转换为1毫米代表的实际长度
///< 转换为1毫米代表实际多少毫米
CUnit ut;
height *= ut.Millimetres(unit.cx);
return (int)height;
*/
return m_pProportion->m_dScaleLength;// * 100;
}
int CItemProportion::ChangeNumber(int number)
{
if (number < 1)
return -1;
m_pProportion->num = number;
return 1;
}
int CItemProportion::ChangeShowMode(int mode)
{
switch (mode)
{
case 0: m_pProportion->SetViewMode(CProportion::styleSimple);
return 1; //普通式
case 1: m_pProportion->SetViewMode(CProportion::styleContemporaneity);
return 1; //现代式
case 2: m_pProportion->SetViewMode(CProportion::stylePopular);
return 1; //流行式
}
return -1;
}
int CItemProportion::ChangeUnit(int unit)
{
//m_pProportion->m_strUnit
return -1;
}
int CItemProportion::ChangeColor(int r, int g, int b)
{
if (IsEditState())
{
GetDoc()->GetDraw()->GetAt(GetPos())->color = RGB(r, g, b);
}
m_color = RGB(r, g, b);
return 1;
}
int CItemProportion::ChangeTextScale(double scale)
{
m_pProportion->m_dTextScale = scale;
return 1;
}
int CItemProportion::ChangeAlign(int align)
{
switch (align)
{
case 0:
m_pProportion->SetAlignsH(CTextFlags::alignLeft);
return 1;
case 1:
m_pProportion->SetAlignsH(CTextFlags::alignCenterH);
return 1;
case 2:
m_pProportion->SetAlignsH(CTextFlags::alignRight);
return 1;
}
return -1;
}
int CItemProportion::ChangeTextHeight(int height)
{
m_pProportion->m_size.cy = GetUnitMode().toRealUnit(height);
if (!m_bAlone)
m_pProportion->m_size.cx = height * 0.4;
return 1;
}
int CItemProportion::ChangeTextWidth(int width)
{
m_pProportion->m_size.cx = GetUnitMode().toRealUnit(width);
if (!m_bAlone)
m_pProportion->m_size.cy = width / 0.4;
return 1;
}
int CItemProportion::ChangeTextHeightAlone(int alone)
{
m_bAlone = alone;
return 1;
}
int CItemProportion::ChangeCoordinate(double x, double y)
{
m_pProportion->x0 = x;
m_pProportion->y0 = y;
return 1;
}
int CItemProportion::Add()
{
POSITION pos = AddElement(m_pProportion, DOUBLEFOX_PROPORTION, false);
CItem::SetPos(pos);
GetDoc()->GetDraw()->SetElementColor(pos, m_color);
return 1;
}
int GetUnitIndex(LPCTSTR name) {
CStringArray units;
units.Add(" ");
units.Add("公里");
units.Add("千米");
units.Add("");
units.Add("km");
units.Add("m");
units.Add(" (公里)");
units.Add(" (千米)");
units.Add(" (米)");
units.Add(" (km)");
units.Add(" (m)");
int nSize = units.GetSize();
for (int i = 0; i < nSize; i++) {
if (units.GetAt(i).Compare(name)==0) {
return i;
}
}
return -1;
}
bool GetUnitString(int index, CString& str) {
if (index < 0) {
return "";
}
CStringArray units;
units.Add(" ");
units.Add("公里");
units.Add("千米");
units.Add("");
units.Add("km");
units.Add("m");
units.Add(" (公里)");
units.Add(" (千米)");
units.Add(" (米)");
units.Add(" (km)");
units.Add(" (m)");
str = units.GetAt(index);
return true;
}
int CItemProportion::GetData(ProportionData * data)
{
if (m_pProportion == NULL)
return -1;
data->x = m_pProportion->x0;
data->y = m_pProportion->y0;
data->ScaleLength = GetScale();
data->ScaleHeight = data->ScaleLength * m_pProportion->m_dCoefficient * 0.4;
DWORD nViewMode = m_pProportion->GetViewMode();
int nViewModeUI = 0;
if (nViewMode == CProportion::styleSimple) {
nViewModeUI = 0;
}
else if (nViewMode == CProportion::styleContemporaneity)
{
nViewModeUI = 1;
}
else if(nViewMode == CProportion::stylePopular)
{
nViewModeUI = 2;
}
data->ViewMode = nViewModeUI;
data->num = m_pProportion->num;
data->Unit = GetUnitIndex(m_pProportion->m_strUnit);
data->ColorR = GetRValue(m_pProportion->color);
data->ColorG = GetGValue(m_pProportion->color);
data->ColorB = GetBValue(m_pProportion->color);
data->TextScale = m_pProportion->m_dTextScale;
data->TextSpace = m_pProportion->m_dSpace;
DWORD nTextAlign = m_pProportion->GetAlignsH();
int nUIAlign = 1;
if (CTextFlags::alignLeft == nTextAlign) {
nUIAlign = 0;
}
else if (CTextFlags::alignCenterH == nTextAlign)
{
nUIAlign = 1;
}
else if (CTextFlags::alignRight == nTextAlign) {
nUIAlign = 2;
}
data->TextAlign = nUIAlign;
//double dx = m_pProportion->m_dScaleLength*m_pProportion->m_dCoefficient;
//m_pProportion->m_size.cx = dx * 0.1;
//m_pProportion->m_size.cy = m_pProportion->m_size.cx*0.4;
data->TextWidth = m_pProportion->m_size.cx;
data->TextHeight = m_pProportion->m_size.cy;
return 1;
}
void CItemProportion::SetParameter(ProportionData * data) {
if (m_pProportion == NULL)
return;
m_pProportion->x0 = data->x;
m_pProportion->y0 = data->y;
m_pProportion->m_dScaleLength = data->ScaleLength;// / 100;
m_pProportion->m_dScaleHeight = data->ScaleHeight;
ChangeShowMode(data->ViewMode);
m_pProportion->num = data->num;
GetUnitString(data->Unit, m_pProportion->m_strUnit);
//m_pProportion->m_strUnit = CString(strUnit);
m_pProportion->color = RGB(data->ColorR, data->ColorG, data->ColorB);
m_color = m_pProportion->color;
m_pProportion->m_dTextScale = data->TextScale;
m_pProportion->m_dSpace = data->TextSpace;
ChangeAlign(data->TextAlign);
m_pProportion->m_size.cx = data->TextWidth;
m_pProportion->m_size.cy = data->TextHeight;
}
void CItemProportion::OnOK(void)
{
DoSelectEnd();
//m_pDlg=NULL;
//GetDoc()->EnableDefaultTool();
}
void CItemProportion::OnCancel(void)
{
CRect8 rect=m_pProportion->GetRect();
InvalidateRect(rect);
//m_pDlg=NULL;
//GetDoc()->EnableDefaultTool();
}