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++

#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;//ֻ<><D6BB><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>ʮ<EFBFBD><CAAE>
}
CObjCircle::~CObjCircle(void)
{
}
CString CObjCircle::GetStr()
{
CString str = "Բ";
return str;
}
CMFCPropertyGridProperty *CObjCircle::CreatSpecialGridProperty(CModule *pModule)
{
CString PropertyName;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString Description;//<2F><><EFBFBD><EFBFBD>
CString Name;
//-------------------------------------------------------------------------------//
PropertyName = _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
//-------------------------------------------------------------------------------//
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_Radius);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(pModule);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
PropertyName = _T("<EFBFBD>");
Description = _T("Բ<EFBFBD>İ뾶(<28><>λ:mm)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_Radius, Description);
pGroup->AddSubItem(p1);
gDrawPropertieMgr.Insert(p1, pPropertie);
}
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_Diameter);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(pModule);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
PropertyName = _T("ֱ<EFBFBD><EFBFBD>");
Description = _T("Բ<EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>(<28><>λ:mm)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_Diameter, Description);
pGroup->AddSubItem(p1);
gDrawPropertieMgr.Insert(p1, pPropertie);
}
//-------------------------------------------------------------------------------//
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_EdgeCnt);
pPropertie->SetType(_PROP_TYPE_INT);
pPropertie->SetpModule(pModule);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
PropertyName = _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
Description = _T("Բ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>3<EFBFBD><33>)(<28><>λ:mm)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_EdgeCnt, Description);
pGroup->AddSubItem(p1);
gDrawPropertieMgr.Insert(p1, pPropertie);
}
return pGroup;
}
//<2F><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Եı
void CObjCircle::OnSpecialPropertyChanged()
{
//<2F>ޱ仯
if(IsTwoDbEqual(m_OldRadius,m_Radius)&&IsTwoDbEqual(m_OldEdgeCnt,m_EdgeCnt)&&IsTwoDbEqual(m_OldDiameter,m_Diameter))
return;
//ֱ<><D6B1><EFBFBD><EFBFBD><E4BBAF>
if(!IsTwoDbEqual(m_OldDiameter,m_Diameter))
{
m_Radius = m_Diameter/2;
}
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
CCommandModifiCircle *pCmd = new CCommandModifiCircle;
pCmd->SetPar(m_OldRadius,m_OldEdgeCnt,true);//<2F><><EFBFBD><EFBFBD><EFBFBD>ɵIJ<C9B5><C4B2><EFBFBD>
pCmd->SetPar(m_Radius,m_EdgeCnt,false);//<2F><><EFBFBD><EFBFBD><EFBFBD>µIJ<C2B5><C4B2><EFBFBD>
gCommandMgr.AddUndoCommand(pCmd);
pCmd->Excute();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
//<2F>
{
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_CIRCLE_R);
if(Lab.m_ValType != _TYPE_NULL)
{
m_Radius = Lab.m_Double;
}
}
//ֱ<><D6B1>
{
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_CIRCLE_D);
if(Lab.m_ValType != _TYPE_NULL)
{
m_Diameter = Lab.m_Double;
}
}
//<2F><><EFBFBD><EFBFBD>
{
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_CIRCLE_EDGE_CNT);
if(Lab.m_ValType != _TYPE_NULL)
{
m_EdgeCnt = Lab.m_Int;
}
}
}
//<2F><>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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 Բ<><D4B2>
//R<>
//DEdgeCnt <20><><EFBFBD><EFBFBD>
//bMerge <20>Ƿ<EFBFBD>ͷβ<CDB7>ϲ<EFBFBD>
//StartAng,EndAng <20><>ʼ<EFBFBD>ǶȺͽ<C8BA><CDBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>360 <20>Ƚ<EFBFBD>
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);
}
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>
DelAllPt();
m_OldRadius = m_Radius = Radius;
m_OldEdgeCnt = m_EdgeCnt = DEdgeCnt;
m_OldDiameter = m_Diameter = Radius*2;
//<2F>
double EachAngle = 360/DEdgeCnt;
bool Flg = true;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>־
double CurrAngle = StartAng;
Dbxy pt;
Dbxy FirstPt;
while(CurrAngle<EndAng)
{
//<2F>Ƕ<EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
double radian = CurrAngle*PI/180;
if(IsDbEqualZero(Radius))//<2F>뾶Ϊ0 <20><>Ϊ<EFBFBD><CEAA>
{
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;
}
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>߶<EFBFBD>
if(bMerge)
{
AddDataPoint(FirstPt);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
CDataPoint DataPoint(CenterPt);
DataPoint.SetIsNode(true);
AddNodePt(DataPoint);
}
void CObjCircle::Draw(CDC* pDC,CPen &Pen)
{
if(m_bOnlyDrawCenterPt)//ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>һ<EFBFBD><D2BB>ʮ<EFBFBD><CAAE>
{
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)//<2F><>Ҫ<EFBFBD>ռ<EFBFBD>mark <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return;
vector<Dbxy> TempVec;
TempVec.push_back(GetRect().GetCenterPt());
vec.push_back(TempVec);
}
else
{
CObjBase::GetPtData(vec);
}
}
void CObjCircle::DrawPtCoord(CDC* pDC)
{
//Բ<><D4B2>
Dbxy CenterPt = GetCenterPt();
CString str= "X"+Db2CString(CenterPt.x,3)+"Y"+Db2CString(CenterPt.y,3);
gDraw->DrawTxt(pDC,str,CenterPt);
//<2F>
Dbxy Pt1(CenterPt.x,CenterPt.y-m_Radius);
Dbxy Pt2(CenterPt.x,CenterPt.y-m_Radius/2);//<2F><EFBFBD><EBBEB6><EFBFBD>е<EFBFBD>
str= "R"+Db2CString(m_Radius,3);
gDraw->DrawTxt(pDC,str,Pt2);
DrawLine(pDC,gDraw->GetScanLine(),Pt1,CenterPt);
}