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.
269 lines
7.7 KiB
C++
269 lines
7.7 KiB
C++
#include "StdAfx.h"
|
|
#include "ObjCircle.h"
|
|
#include "GlobalDrawMgr.h"
|
|
#include "DataPoint.h"
|
|
#include "GlobalFunction.h"
|
|
#include "Propertie.h"
|
|
#include "PropertieMgr.h"
|
|
#include "CommandModifiCircle.h"
|
|
#include "CommandMgr.h"
|
|
#include "WorkFileMgr.h"
|
|
#include "DrawSimpleShape.h"
|
|
#include "WorkDataMgr.h"
|
|
#include "CStringFuc.h"
|
|
|
|
CObjCircle::CObjCircle(void)
|
|
{
|
|
m_bOnlyDrawCenterPt = false;//只绘制圆心十字
|
|
}
|
|
CObjCircle::~CObjCircle(void)
|
|
{
|
|
}
|
|
CString CObjCircle::GetStr()
|
|
{
|
|
CString str = "圆";
|
|
return str;
|
|
}
|
|
CMFCPropertyGridProperty *CObjCircle::CreatSpecialGridProperty(CModule *pModule)
|
|
{
|
|
CString PropertyName;//属性名称
|
|
CString Description;//描述
|
|
CString Name;
|
|
//-------------------------------------------------------------------------------//
|
|
PropertyName = _T("特殊属性");
|
|
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
|
|
//-------------------------------------------------------------------------------//
|
|
{
|
|
//添加属性变量映射
|
|
CPropertie *pPropertie = new CPropertie;
|
|
pPropertie->SetpVal((void*)&m_Radius);
|
|
pPropertie->SetType(_PROP_TYPE_DOUBLE);
|
|
pPropertie->SetpModule(pModule);
|
|
//添加属性显示
|
|
PropertyName = _T("半径");
|
|
Description = _T("圆的半径(单位:mm)");
|
|
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_Radius, Description);
|
|
pGroup->AddSubItem(p1);
|
|
gDrawPropertieMgr.Insert(p1, pPropertie);
|
|
}
|
|
{
|
|
//添加属性变量映射
|
|
CPropertie *pPropertie = new CPropertie;
|
|
pPropertie->SetpVal((void*)&m_Diameter);
|
|
pPropertie->SetType(_PROP_TYPE_DOUBLE);
|
|
pPropertie->SetpModule(pModule);
|
|
//添加属性显示
|
|
PropertyName = _T("直径");
|
|
Description = _T("圆的直径(单位:mm)");
|
|
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_Diameter, Description);
|
|
pGroup->AddSubItem(p1);
|
|
gDrawPropertieMgr.Insert(p1, pPropertie);
|
|
}
|
|
//-------------------------------------------------------------------------------//
|
|
{
|
|
//添加属性变量映射
|
|
CPropertie *pPropertie = new CPropertie;
|
|
pPropertie->SetpVal((void*)&m_EdgeCnt);
|
|
pPropertie->SetType(_PROP_TYPE_INT);
|
|
pPropertie->SetpModule(pModule);
|
|
//添加属性显示
|
|
PropertyName = _T("边数");
|
|
Description = _T("圆的边数(最少3条)(单位:mm)");
|
|
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_EdgeCnt, Description);
|
|
pGroup->AddSubItem(p1);
|
|
gDrawPropertieMgr.Insert(p1, pPropertie);
|
|
}
|
|
return pGroup;
|
|
}
|
|
//相应特殊属性的变化
|
|
void CObjCircle::OnSpecialPropertyChanged()
|
|
{
|
|
//无变化
|
|
if(IsTwoDbEqual(m_OldRadius,m_Radius)&&IsTwoDbEqual(m_OldEdgeCnt,m_EdgeCnt)&&IsTwoDbEqual(m_OldDiameter,m_Diameter))
|
|
return;
|
|
//直径变化了
|
|
if(!IsTwoDbEqual(m_OldDiameter,m_Diameter))
|
|
{
|
|
m_Radius = m_Diameter/2;
|
|
}
|
|
|
|
//撤销指令
|
|
CCommandModifiCircle *pCmd = new CCommandModifiCircle;
|
|
pCmd->SetPar(m_OldRadius,m_OldEdgeCnt,true);//保存旧的参数
|
|
pCmd->SetPar(m_Radius,m_EdgeCnt,false);//保存新的参数
|
|
gCommandMgr.AddUndoCommand(pCmd);
|
|
pCmd->Excute();
|
|
|
|
//重新生成
|
|
ReCreat(m_Radius,m_EdgeCnt);
|
|
}
|
|
void CObjCircle::WriteWorkFileExt(vector<CLab> &LabVec)
|
|
{
|
|
CObjBase::WriteWorkFileExt(LabVec);
|
|
LabVec.push_back(CLab(LAB_CIRCLE_R,m_Radius));
|
|
LabVec.push_back(CLab(LAB_CIRCLE_D,m_Diameter));
|
|
LabVec.push_back(CLab(LAB_CIRCLE_EDGE_CNT,m_EdgeCnt));
|
|
}
|
|
void CObjCircle::ReadWorkFileExt(CLabVecRang &LabVecRang)
|
|
{
|
|
CObjBase::ReadWorkFileExt(LabVecRang);
|
|
|
|
CWorkFileMgr WorkFileMgr;
|
|
//半径
|
|
{
|
|
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_CIRCLE_R);
|
|
if(Lab.m_ValType != _TYPE_NULL)
|
|
{
|
|
m_Radius = Lab.m_Double;
|
|
}
|
|
}
|
|
//直径
|
|
{
|
|
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_CIRCLE_D);
|
|
if(Lab.m_ValType != _TYPE_NULL)
|
|
{
|
|
m_Diameter = Lab.m_Double;
|
|
}
|
|
}
|
|
//边数
|
|
{
|
|
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_CIRCLE_EDGE_CNT);
|
|
if(Lab.m_ValType != _TYPE_NULL)
|
|
{
|
|
m_EdgeCnt = Lab.m_Int;
|
|
}
|
|
}
|
|
}
|
|
//在原来的位置重新生成
|
|
void CObjCircle::ReCreat(double Radius,int DEdgeCnt)
|
|
{
|
|
Dbxy CenterPt = GetRect().GetCenterPt();
|
|
CCirclePar ObjCirclePar;
|
|
ObjCirclePar.CenterPt = CenterPt;
|
|
ObjCirclePar.Radius =Radius;
|
|
ObjCirclePar.DEdgeCnt = DEdgeCnt;
|
|
Creat(ObjCirclePar);
|
|
}
|
|
void CObjCircle::CreatByRadius(double Radius,Dbxy CenterPt,int EdgeCnt)
|
|
{
|
|
CCirclePar ObjCirclePar;
|
|
ObjCirclePar.CenterPt = CenterPt;
|
|
ObjCirclePar.Radius = Radius;
|
|
ObjCirclePar.DEdgeCnt = EdgeCnt;
|
|
Creat(ObjCirclePar);
|
|
}
|
|
//CenterPt 圆心
|
|
//R半径
|
|
//DEdgeCnt 边数
|
|
//bMerge 是否头尾合并
|
|
//StartAng,EndAng 起始角度和结束角度360 度角
|
|
void CObjCircle::Creat(CCirclePar ObjCirclePar)
|
|
{
|
|
Dbxy CenterPt = ObjCirclePar.CenterPt;
|
|
double Radius = ObjCirclePar.Radius;
|
|
int DEdgeCnt = ObjCirclePar.DEdgeCnt;
|
|
bool bMerge = ObjCirclePar.bMerge;
|
|
double StartAng = ObjCirclePar.StartAng;
|
|
double EndAng = ObjCirclePar.EndAng;
|
|
|
|
if(DEdgeCnt == 0)
|
|
{
|
|
DEdgeCnt = gDraw->GetCirclePtCnt(Radius);
|
|
}
|
|
|
|
//删除所有数据点
|
|
DelAllPt();
|
|
|
|
m_OldRadius = m_Radius = Radius;
|
|
m_OldEdgeCnt = m_EdgeCnt = DEdgeCnt;
|
|
m_OldDiameter = m_Diameter = Radius*2;
|
|
|
|
//半径
|
|
double EachAngle = 360/DEdgeCnt;
|
|
bool Flg = true;//第一个点的标志
|
|
double CurrAngle = StartAng;
|
|
|
|
Dbxy pt;
|
|
Dbxy FirstPt;
|
|
while(CurrAngle<EndAng)
|
|
{
|
|
//角度转换为弧度
|
|
double radian = CurrAngle*PI/180;
|
|
if(IsDbEqualZero(Radius))//半径为0 则为点
|
|
{
|
|
pt = CenterPt;
|
|
}
|
|
else
|
|
{
|
|
pt.x = CenterPt.x + Radius*cos(radian);
|
|
pt.y = CenterPt.y + Radius*sin(radian);
|
|
}
|
|
|
|
if(Flg)
|
|
{
|
|
Flg = false;
|
|
FirstPt = pt;
|
|
CDataPoint DataPoint(pt);
|
|
DataPoint.SetIsNode(true);
|
|
AddDataPoint(DataPoint);
|
|
}
|
|
else
|
|
{
|
|
AddDataPoint(pt);
|
|
}
|
|
CurrAngle += EachAngle;
|
|
}
|
|
//最后一条线段
|
|
if(bMerge)
|
|
{
|
|
AddDataPoint(FirstPt);
|
|
}
|
|
//用来捕获的点
|
|
CDataPoint DataPoint(CenterPt);
|
|
DataPoint.SetIsNode(true);
|
|
AddNodePt(DataPoint);
|
|
}
|
|
void CObjCircle::Draw(CDC* pDC,CPen &Pen)
|
|
{
|
|
if(m_bOnlyDrawCenterPt)//只在中心画一个十字
|
|
{
|
|
DbRect Rect(GetRect().GetCenterPt(),gDraw->GetCatchNodeSize()*0.5);
|
|
DrawCrossX(pDC,Pen,Rect);
|
|
}
|
|
else
|
|
{
|
|
CObjBase::Draw(pDC,Pen);
|
|
}
|
|
}
|
|
void CObjCircle::GetPtData(vector<vector<Dbxy>> &vec)
|
|
{
|
|
if(m_bOnlyDrawCenterPt)
|
|
{
|
|
if(m_bMarkPt)//不要收集mark 的数据
|
|
return;
|
|
vector<Dbxy> TempVec;
|
|
TempVec.push_back(GetRect().GetCenterPt());
|
|
vec.push_back(TempVec);
|
|
}
|
|
else
|
|
{
|
|
CObjBase::GetPtData(vec);
|
|
}
|
|
}
|
|
|
|
void CObjCircle::DrawPtCoord(CDC* pDC)
|
|
{
|
|
//圆心
|
|
Dbxy CenterPt = GetCenterPt();
|
|
CString str= "X"+Db2CString(CenterPt.x,3)+"Y"+Db2CString(CenterPt.y,3);
|
|
gDraw->DrawTxt(pDC,str,CenterPt);
|
|
//半径
|
|
Dbxy Pt1(CenterPt.x,CenterPt.y-m_Radius);
|
|
Dbxy Pt2(CenterPt.x,CenterPt.y-m_Radius/2);//半径的中点
|
|
str= "R"+Db2CString(m_Radius,3);
|
|
gDraw->DrawTxt(pDC,str,Pt2);
|
|
|
|
DrawLine(pDC,gDraw->GetScanLine(),Pt1,CenterPt);
|
|
}
|
|
|