⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 figureobj.cpp

📁 参数化车间设备资源绘制程序
💻 CPP
字号:
//FigureObj.cpp 图形元基类实现文档
#include "StdAfx.h"
#include "visdraw.h"

#include "figureobj.h"
#include ".\figureobj.h"

#include "visdrawdoc.h"
#include "visdrawview.h"

#include "ShebeiDlg.h"

#include "GongshiDlg.h"
#include "YunxingDlg.h"


#include <math.h>

//#include "circleobj.h"
//#include "arcobj.h"
#include "cheobj.h"
//#include "textobj.h"
#include "baoobj.h"
#include "xiobj.h"
#include "moobj.h"
#include "tangobj.h"
#include "zuanobj.h"
#include "chongobj.h"
#include "juobj.h"
#include "zhongxinobj.h"
#include "zhewanobj.h"



//#include "selecttool.h"

//初始化静态成员变量
DrawObj CFigureObj::c_drawObj = cheObj;
CPtrList CFigureObj::c_objs;

//static CCircleObj circleToolObj(circleTool);
//static CArcTool tparcToolObj(tparcTool);
//static CArcTool secarcToolObj(secarcTool);
//static CArcTool csearcToolObj(csearcTool);
//static CSelectTool selectToolObj(selectTool);
static CCheObj cheobjObj(cheObj);
//static CTextTool textToolObj(textTool); 
static CBaoObj baoobjObj(baoObj);
static CXiObj xiobjObj(xiObj);
static CMoObj moobjObj(moObj);
static CTangObj tangobjObj(tangObj);
static CZuanObj zuanobjObj(zuanObj);
static CChongObj chongobjObj(chongObj);
static CJuObj juobjObj(juObj);
static CZhongxinObj zhongxinobjObj(zhongxinObj);
static CZhewanObj zhewanobjObj(zhewanObj);
extern CDialogBar m_wndDlgBar;
extern CDialogBar m_wndSBDlgBar;

IMPLEMENT_SERIAL(CFigureObj,CObject,0)
//IMPLEMENT_DYNCREATE(CFigureObj, CObject)
//BEGIN_MESSAGE_MAP(CVisDrawView, CObject)
	// 标准打印命令
	//ON_COMMAND(ID_FILE_PRINT, CObject::OnFilePrint)
	//ON_COMMAND(ID_FILE_PRINT_DIRECT, CObject::OnFilePrint)
	//ON_COMMAND(ID_FILE_PRINT_PREVIEW, CObject::OnFilePrintPreview)
	
	
//END_MESSAGE_MAP()
CFigureObj::CFigureObj(void)
: m_MachineModel(_T("J001"))
{
}


//构造函数
CFigureObj::CFigureObj(const CRect& position)
{
	m_position = position;
	m_pDocument = NULL;

	//m_ClientToWorld = 1.0; 
	m_bPen = TRUE;
	m_logpen.lopnStyle = PS_INSIDEFRAME;
	m_logpen.lopnWidth.x = 1;
	m_logpen.lopnWidth.y = 1;
	m_logpen.lopnColor = RGB(0, 0, 0);

	m_bBrush = FALSE;
	m_logbrush.lbStyle = BS_SOLID;
	m_logbrush.lbColor = RGB(192, 192, 192);
	m_logbrush.lbHatch = HS_HORIZONTAL;
	 m_MachineModel=_T("J001");
	 m_Jcxinghao=_T("CA6140");
}

CFigureObj::CFigureObj(DrawObj drawObj)
{
	//m_LMouseDownStep = 0;
	m_drawObj = drawObj;
	c_objs.AddTail(this);
	c_objs.RemoveAll();
}

CFigureObj::~CFigureObj(void)
{
}

void CFigureObj::Serialize(CArchive& ar)
{
	CObject::Serialize(ar);
	if (ar.IsStoring())
	{
	//	ar << m_position;
		ar << (WORD)m_bPen;
		ar.Write(&m_logpen, sizeof(LOGPEN));
		ar << (WORD)m_bBrush;
		ar.Write(&m_logbrush, sizeof(LOGBRUSH));
	}
	else
	{
		// get the document back pointer from the archive
		m_pDocument = (CVisDrawDoc*)ar.m_pDocument;
		ASSERT_VALID(m_pDocument);
		ASSERT_KINDOF(CVisDrawDoc, m_pDocument);

		WORD wTemp;
	//	ar >> m_position;
		ar >> wTemp; m_bPen = (BOOL)wTemp;
		ar.Read(&m_logpen,sizeof(LOGPEN));
		ar >> wTemp; m_bBrush = (BOOL)wTemp;
		ar.Read(&m_logbrush, sizeof(LOGBRUSH));
	}
}

#ifdef _DEBUG
void CFigureObj::AssertValid()
{
	
}
#endif

void CFigureObj::Draw(CVisDrawView* pView, CDC*)
{
	ASSERT_VALID(this);
}

void CFigureObj::SetLineColor(COLORREF color)
{
	ASSERT_VALID(this);

	m_logpen.lopnColor = color;
	Invalidate();
	m_pDocument->SetModifiedFlag();
}

void CFigureObj::SetFillColor(COLORREF color)
{
	ASSERT_VALID(this);

	m_logbrush.lbColor = color;
	Invalidate();
	m_pDocument->SetModifiedFlag();
}

CRect CFigureObj::CalcBounds(CVisDrawView* pView)
{
	ASSERT_VALID(this);
	return m_position;
	
}

void CFigureObj::Invalidate()
{
	ASSERT_VALID(this);
	m_pDocument->UpdateAllViews(NULL, HINT_UPDATE_DRAWOBJ, this);
}

void CFigureObj::Remove()
{
	delete this;
}

// rect 必须为逻辑坐标
BOOL CFigureObj::Intersects(CVisDrawView* pView, const CRect& rect)
{
	ASSERT_VALID(this);

	int nDistance;

	//获得识别精度,识别精度为逻辑坐标
	nDistance = pView->GetDocument()->GetSetectDistance()/2;

	CRect fixed = m_position;
	fixed.NormalizeRect();

	//用识别精度的半值扩展图元边界矩形
	fixed.top=fixed.top - nDistance;
	fixed.bottom=fixed.bottom + nDistance;
	fixed.left=fixed.left - nDistance;
	fixed.right=fixed.right + nDistance;
	
	CRect rectT = rect;
	rectT.NormalizeRect();
	return !(rectT & fixed).IsRectEmpty();
}

BOOL CFigureObj::IsSelected(CVisDrawView* pView, const CPoint& point)
{
	return false;	
}

double CFigureObj::PointToPoint(CPoint pt1,CPoint pt2)
{
	double distance;
	distance = sqrt((double)((pt2.x - pt1.x)*(pt2.x - pt1.x)+(pt2.y - pt1.y)*(pt2.y - pt1.y)));
	return distance;
}

//返回关键点个数
int CFigureObj::GetHandleCount()
{
	ASSERT_VALID(this);
	return 9;
}

// 返回指定关键点中心逻辑坐标
CPoint CFigureObj::GetHandle(CVisDrawView* pView, int nHandle)
{
	ASSERT_VALID(this);
	int x, y, xCenter, yCenter;

	// 图元边界矩形中心坐标
	xCenter = m_position.left + m_position.Width() / 2;
	yCenter = m_position.top + m_position.Height() / 2;

	//每个关键点坐标
	switch (nHandle)
	{
	default:
		ASSERT(FALSE);

	case 1:
		x = m_position.left;
		y = m_position.top;
		break;

	case 2:
		x = xCenter;
		y = m_position.top;
		break;

	case 3:
		x = m_position.right;
		y = m_position.top;
		break;

	case 4:
		x = m_position.right;
		y = yCenter;
		break;

	case 5:
		x = m_position.right;
		y = m_position.bottom;
		break;

	case 6:
		x = xCenter;
		y = m_position.bottom;
		break;

	case 7:
		x = m_position.left;
		y = m_position.bottom;
		break;

	case 8:
		x = m_position.left;
		y = yCenter;
		break;

	case 9:
		x = xCenter;
		y = yCenter;
		break;
	}

	return CPoint(x, y);
}

// 返回关键点手柄矩形逻辑坐标
CRect CFigureObj::GetHandleRect(int nHandleID, CVisDrawView* pView)
{
	ASSERT_VALID(this);
	ASSERT(pView != NULL);

	//得到识别精度
	int nDistance;
	nDistance = pView->GetDocument()->GetSetectDistance()/2+1;
	CRect rect;

	//得到手柄中心逻辑坐标
	CPoint point = GetHandle(pView, nHandleID);

	//以识别精度半值扩展手柄矩形
	rect.SetRect(point.x - nDistance, point.y - nDistance, point.x + nDistance, point.y + nDistance);

	return rect;
}

//绘制手柄矩形
void CFigureObj::DrawTracker(CVisDrawView* pView, CDC* pDC, TrackerState state)
{
	ASSERT_VALID(this);

	//根据图元的不同状态进行绘制
	switch (state)
	{
	case normal:
		break;

	//图元被拾取
	case selected:
	case active:
		{
			//获得手柄个数
			int nHandleCount = GetHandleCount();

			//遍历所有手柄
			for (int nHandle = 1; nHandle <= nHandleCount; nHandle += 1)
			{
				//手柄中心坐标
			//	CPoint handle = GetHandle(nHandle);
				CRect rect = GetHandleRect(nHandle, pView);

				//扩展手柄矩形,并绘制
		//		pDC->PatBlt(handle.x - 3, handle.y - 3, 7, 7, DSTINVERT);
				pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), DSTINVERT);
			}
		}
		break;
	}
}
// point为逻辑坐标
int CFigureObj::HitTest(CVisDrawView* pView, CPoint point, BOOL bSelected)
{
	ASSERT_VALID(this);
	ASSERT(pView != NULL);

	if (bSelected)
	{
		int nHandleCount = GetHandleCount();
		for (int nHandle = 1; nHandle <= nHandleCount; nHandle += 1)
		{
			// GetHandleRect 返回手柄矩形逻辑坐标
			CRect rc = GetHandleRect(nHandle,pView);
			if (point.x >= rc.left && point.x < rc.right &&
				point.y >= rc.top && point.y < rc.bottom)
				return nHandle;
		}
	}
	else
	{
		if (point.x >= m_position.left && point.x < m_position.right &&
			point.y <= m_position.top && point.y > m_position.bottom)
			return 1;
	}
	return 0;
}

// point 为逻辑坐标
void CFigureObj::MoveHandleTo(int nHandle, CPoint point, CVisDrawView* pView)
{
	ASSERT_VALID(this);
}

// delta为逻辑坐标
void CFigureObj::MoveTo(CPoint delta, CVisDrawView* pView)
{
	ASSERT_VALID(this);	
	
	m_pDocument->SetModifiedFlag();
}
 void CFigureObj::OnEditProperties() 
 {
	 ASSERT_VALID(this);

	CPropertySheet sheet( _T("设备管理信息") );
	CShebeiDlg dlg;
	CGongshiDlg dlg1;
	CYunxingDlg dlg2;
	/*UINT style[] = {PS_INSIDEFRAME,PS_DASHDOT,PS_DASH};
	dlg.m_bNoFill = !m_bBrush;
	dlg.m_penType =0;
	dlg.m_penSize = m_bPen ? m_logpen.lopnWidth.x : 0;*/
	//dlg1.m_IsPic=m_IsPic;
	//dlg1.m_picpath=m_picpath;
	//dlg1.m_note=m_note;
	//dlg2.m_noterun=m_noterun;
//dlg1.m_cheXinghao.AddString(_T("000"));
	//dlg1.SetDlgItemTextA(IDC_COMBO1_XINGHAO,"234");



	//dlg.SetDlgItemTextA(IDC_EDIT1,"CA6140");
	dlg.m_strMachineID=m_MachineModel;
	dlg.m_MachineOperater=_T("王晓明");
	dlg.m_workCurrent=_T("无任务");

	dlg1.m_strXingHao=m_Jcxinghao;

	dlg1.m_strFuHe=_T("工时");
	dlg1.m_workBegine=_T("00:00:00");   
	dlg1.m_workEnd=_T("00:00:00");  


	sheet.AddPage( &dlg );
	sheet.AddPage( &dlg1 );
	sheet.AddPage( &dlg2 );
	//
	if (sheet.DoModal() != IDOK)
		return;
	else
	{
		m_MachineModel=dlg.m_strMachineID;
		m_Jcxinghao=dlg1.m_strXingHao;
	}

	/*m_IsPic=FALSE;
	m_noterun=dlg2.m_noterun;
	m_note=dlg1.m_note;

	m_bBrush = !dlg.m_bNoFill;
	m_bPen = dlg.m_penSize > 0;
	if (m_bPen)
	{
		m_logpen.lopnWidth.x = dlg.m_penSize;
		m_logpen.lopnWidth.y = dlg.m_penSize;
		m_logpen.lopnStyle =style[dlg.m_penType];

	}*/
	m_wndDlgBar.SetDlgItemTextA(IDC_EDIT10,(LPCTSTR)m_MachineModel);
	m_wndSBDlgBar.SetDlgItemTextA(IDC_JCXH,(LPCTSTR)m_Jcxinghao);

	Invalidate();
	m_pDocument->SetModifiedFlag();
 }




 void CFigureObj::OnOpen(CVisDrawView* pView)
 {
	 OnEditProperties();
 }

CFigureObj* CFigureObj::FindObj(DrawObj drawObj)
{
	POSITION pos = c_objs.GetHeadPosition();
	while (pos != NULL)
	{
		CFigureObj* pObj = (CFigureObj*)c_objs.GetNext(pos);
		if (pObj->m_drawObj == drawObj)
			return pObj;
	}

	return NULL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -