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.

355 lines
6.6 KiB
C++

#include "StdAfx.h"
//#include "DrawApp.h"
#include "ItemBase.h"
#include "SectionDoc.h"
#include "SigmaDoc.h"
#include "SigmaView.h"
//#include "DrawDoc.h"
//#include "DrawView.h"
//#include "DrawChildFrame.h"
//#include "DrawMainFrame.h"
namespace NDrawView
{
CItemBase::CItemBase(CSigmaDoc * ppDoc)
: m_bPopupRightMenu(TRUE)
, m_bEnableRButtonCancel(FALSE)
{
m_type=0;
m_pDoc = ppDoc;
m_hdc = 0;
m_pScreenDC = nullptr;
}
CItemBase::~CItemBase(void)
{
m_pDoc=NULL;
m_type=0;
}
void CItemBase::OnLButtonDblClk(UINT nFlags, CPoint point)
{
}
void CItemBase::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk)
{
}
void CItemBase::OnLButtonUp(CDC *pDC, UINT nFlags, CPoint point, int vk)
{
}
int CItemBase::OnMouseMove(CDC *pDC, UINT nFlags, CPoint point)
{
return 1;
}
void CItemBase::OnMouseMoveStatus(CDC *pDC, UINT nFlags, CPoint point, BYTE*& destBuffer, int& destLen)
{
}
void CItemBase::OnRButtonDblClk(UINT nFlags, CPoint point)
{
}
void CItemBase::OnRButtonDown(UINT nFlags, CPoint point)
{
//if(m_bEnableRButtonCancel)
// GetDrawDoc()->EnableDefaultTool();
}
BOOL CItemBase::OnRButtonUp(UINT nFlags, CPoint point)
{
return TRUE;
}
void CItemBase::OnMouseWheel(uint32_t button, int32_t clicks, int32_t x, int32_t y, int32_t delta)
{
}
void CItemBase::DrawAssistant(CDC * pDC, int mouseX, int mouseY)
{
}
int CItemBase::GetSubMenu()
{
return -1;
}
void CItemBase::OnDraw(CXyDC* pDC)
{
}
void CItemBase::OnDraw(CXyDC* pXyDC, CDC* pDC) {
}
BOOL CItemBase::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
return FALSE;
}
BOOL CItemBase::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case VK_ESCAPE:
//GetDrawDoc()->EnableDefaultTool();
return TRUE;
default:
break;
}
return FALSE;
}
long CItemBase::GetType(void)
{
//if(position)
//{
// return GetDrawDoc()->GetDraw()->GetElementType(position);
//}
return m_type;
}
void CItemBase::SetDoc(CSigmaDoc * ppDoc)
{
m_pDoc = ppDoc;
}
CSigmaDoc * CItemBase::GetDrawDoc()
{
return m_pDoc;
}
BOOL CItemBase::IsCaptureState(void)
{
//if(GetDrawView()->GetCapture() != GetDrawView()) return FALSE;
return TRUE;
}
CSigmaView * CItemBase::GetDrawView(void)
{
ASSERT(GetDrawDoc()!=NULL);
if(GetDrawDoc()==NULL) return NULL;
return m_pDoc->GetView();
//return m_pView;
}
CDC* CItemBase::GetScreenDC()
{
//if (m_pDoc == NULL)
// return NULL;
//CSigmaView * pView = (CSigmaView *)m_pDoc->GetView();
//if (pView != 0)
//{
// return pView->GetScreenDC();
//}
return m_pScreenDC;
}
void CItemBase::SetScreenDC(CDC* pScreenDC) {
m_pScreenDC = pScreenDC;
}
CDC* CItemBase::GetImgDC()
{
if (m_pDoc == NULL)
return NULL;
CSigmaView * pView = (CSigmaView *)m_pDoc->GetView();
if (pView != 0)
{
return pView->GetImgDC();
}
return nullptr;
}
CXyDC* CItemBase::GetDC(void) const
{
if (m_pDoc == NULL)
return NULL;
//CSigmaView * pView = (CSigmaView *)m_pDoc->GetView();
//if (pView != 0)
//{
// CDC * cdc = pView->GetDrawDC();
// if (cdc != 0)
// m_pDoc->GetDC().Create(cdc);
//}
return &m_pDoc->GetDC();// m_xyDC;
/*
IDoc * pDoc = GetDrawDoc();
ASSERT(pDoc!=NULL);
if(pDoc==NULL) return NULL;
return &((CSigmaDoc*)(m_pDoc))->m_xyDC;
return nullptr;
*/
}
void CItemBase::SetType(long type)
{
m_type = type;
}
BOOL CItemBase::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
return FALSE;
}
dfPoint CItemBase::GetReal(CPoint point)
{
dfPoint dp;
dp.x0=GetDC()->GetRX(point.x);
dp.y0=GetDC()->GetRY(point.y);
return dp;
}
void CItemBase::SetStatusBarLengthInfo(double x1, double y1, double x2, double y2, BYTE*& destBuffer, int& destLen)
{
CString format;
//format.LoadString(IDS_STRING_LENGTH);//<2F><><EFBFBD><EFBFBD>=%lf
format = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>=%lf";
double dis=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
info.Format(format,dis);
double angle=AfxGetPublicFunction()->GetAngle(x1,y1,x2,y2); if(angle<0) angle+=360;
CString str; str.Format("; Angle=%lf", angle);
info = info + str;
destLen = info.GetLength();
CMemFile mf(destLen);
mf.Write(info, destLen);
destBuffer = mf.Detach();
}
//BOOL CItemBase::InitPropertyGrid(CXTPPropertyGrid& grid)
//{
// return TRUE;
//}
//BOOL CItemBase::OnGridItemChangeValue(CXTPPropertyGridItem* pItem)
//{
// return FALSE;
//}
//
//void CItemBase::OnInplaceButtonDown(CXTPPropertyGridItem* pItem)
//{
//}
CPoint2D CItemBase::CenterPoint(void)
{
CPoint2D pt(0,0);
if (m_pDoc == NULL)
return pt;
CSigmaView* pView =(CSigmaView*)m_pDoc->GetView();
if(pView)
{
//CPoint p= pView->m_client.CenterPoint();
//pt=GetDC()->GetReal(p);
pt = pView->m_client.CenterPoint();
pt = GetDC()->GetReal(pt);
}
return pt;
}
void CItemBase::InvalidateRect(CRect8 rect)
{
CRect rt=GetDC()->GetScreen(rect);
rt.NormalizeRect();
rt.InflateRect(2,2);
//GetDrawDoc()->Invalidate(&rt);
}
CString CItemBase::GetFloatFormatString(BOOL bIsE)
{
CString strFormat;
//strFormat.Format("%%0.%dlf",pf.GetDecimalDigits());
if(!bIsE) strFormat.Format("%%0.%dlf",8);
else strFormat.Format("%%0.%dE",8);
return strFormat;
}
void CItemBase::OnOK(void)
{
}
void CItemBase::OnCancel(void)
{
}
void CItemBase::SetHDC(HDC hdc)
{
m_hdc = hdc;
}
BOOL CItemBase::IsPopupRightMenu(void)
{
return m_bPopupRightMenu;
}
void CItemBase::EnablePopupRightMenu(BOOL bPopup)
{
m_bPopupRightMenu=bPopup;
}
void CItemBase::EnableRButtonCancel(BOOL bEnable)
{
m_bEnableRButtonCancel=bEnable;
}
void CItemBase::DrawCrossPoint(CXyDC* pDC, double x, double y)
{
CPen pen, *pOldPen;
pen.CreatePen(PS_SOLID, 1, RGB(0,0,0));
pOldPen=pDC->GetDC()->SelectObject(&pen);
int od=pDC->GetDC()->SetROP2(R2_NOTXORPEN);
int off=8;
CPoint pt=pDC->GetScreen(x,y);
pDC->GetDC()->MoveTo(pt.x-off, pt.y);
pDC->GetDC()->LineTo(pt.x+off, pt.y);
pDC->GetDC()->MoveTo(pt.x, pt.y-off);
pDC->GetDC()->LineTo(pt.x, pt.y+off);
pDC->GetDC()->SetROP2(od);
pDC->GetDC()->SelectObject(pOldPen);
}
void CItemBase::DrawLineReal(double x1, double y1, double x2, double y2)
{
int od = GetDC()->GetDC()->SetROP2(R2_NOTXORPEN);
GetDC()->MoveTo(x1, y1);
GetDC()->LineTo(x2, y2);
GetDC()->GetDC()->SetROP2(od);
}
void CItemBase::DrawLineScreen(int x1, int y1, int x2, int y2)
{
POINT ptOld;
HDC hdc = m_pScreenDC->m_hDC;
int od= m_pScreenDC->SetROP2(R2_NOTXORPEN);
::MoveToEx(hdc, x1, y1, &ptOld);
::LineTo(hdc, x2,y2);
m_pScreenDC->SetROP2(od);
}
CRect CItemBase::GetNegativeRect(CRect* pRect)
{
CRect rt=*pRect;
rt.bottom=min(pRect->top, pRect->bottom);
rt.top=max(pRect->top, pRect->bottom);
rt.right=min(pRect->left, pRect->right);
rt.left=max(pRect->left, pRect->right);
return rt;
}
//CTreePropertySheet& CItemBase::GetPreferences(void)
//{
// CDrawMainFrame* pmf = (CDrawMainFrame*)GetDrawDoc()->GetMainFrame();
// return pmf->GetDrawFrame().GetPreferences();
//}
}//namesapce