diff --git a/Modify_Part3-ch09/SectionCalculation.exe b/Modify_Part3-ch09/SectionCalculation.exe new file mode 100644 index 0000000..1e84c01 Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation.exe differ diff --git a/Modify_Part3-ch09/SectionCalculation/.vs/SectionCalculation/v14/.suo b/Modify_Part3-ch09/SectionCalculation/.vs/SectionCalculation/v14/.suo new file mode 100644 index 0000000..601aa29 Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/.vs/SectionCalculation/v14/.suo differ diff --git a/Modify_Part3-ch09/SectionCalculation/Debug/SectionCalculation.exe b/Modify_Part3-ch09/SectionCalculation/Debug/SectionCalculation.exe new file mode 100644 index 0000000..b817017 Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/Debug/SectionCalculation.exe differ diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation.sln b/Modify_Part3-ch09/SectionCalculation/SectionCalculation.sln new file mode 100644 index 0000000..8bc5569 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SectionCalculation", "SectionCalculation\SectionCalculation.vcxproj", "{7B25400A-51C5-449B-87A6-88A0D9B0DC25}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7B25400A-51C5-449B-87A6-88A0D9B0DC25}.Debug|x64.ActiveCfg = Debug|x64 + {7B25400A-51C5-449B-87A6-88A0D9B0DC25}.Debug|x64.Build.0 = Debug|x64 + {7B25400A-51C5-449B-87A6-88A0D9B0DC25}.Debug|x86.ActiveCfg = Debug|Win32 + {7B25400A-51C5-449B-87A6-88A0D9B0DC25}.Debug|x86.Build.0 = Debug|Win32 + {7B25400A-51C5-449B-87A6-88A0D9B0DC25}.Release|x64.ActiveCfg = Release|x64 + {7B25400A-51C5-449B-87A6-88A0D9B0DC25}.Release|x64.Build.0 = Release|x64 + {7B25400A-51C5-449B-87A6-88A0D9B0DC25}.Release|x86.ActiveCfg = Release|Win32 + {7B25400A-51C5-449B-87A6-88A0D9B0DC25}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/BasicCalc.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/BasicCalc.cpp new file mode 100644 index 0000000..c575e0c --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/BasicCalc.cpp @@ -0,0 +1,81 @@ +#include "stdafx.h" +#include "BasicCalc.h" + + +CBasicCalc::CBasicCalc() +{ +} + + +CBasicCalc::~CBasicCalc() +{ +} + +double CBasicCalc::Azimuth(double x1, double y1, double x2, double y2)//rad +{ + double a = 0; + double x = x2 - x1; + double y = y2 - y1; + if (fabs(x) < EPCLONG) + { + if (y > 0) + a = PI * 0.5; + if (y < 0) + a = PI * 1.5; + } + a = atan(y / x); + if (x < 0) + a += PI; + if (a > 2.0 * PI) + a -= 2.0 * PI; + if (a < 0) + a += 2.0 * PI; + return a; +} + +double CBasicCalc::Distance(double x1, double y1, double x2, double y2) +{ + double x = x2 - x1; + double y = y2 - y1; + double dis = sqrt(x * x + y * y); + return dis; +} + +void CBasicCalc::SortDis(std::vector& p) +{ + CPointInfo temp; + for (int i = 0; i < p.size() - 1; ++i) + { + for (int j = 0; j < p.size() - 1 - i; ++j) + { + if (p[j].Dis() > p[j + 1].Dis()) + { + temp = p[j]; + p[j] = p[j + 1]; + p[j + 1] = temp; + } + } + } +} + +void CBasicCalc::CalcHeight(std::vector& oripoint, std::vector& insertpoint) +{ + double addNumerator = 0, addDenominator = 0, dis = 0; + for (int i = 0; i < 11; ++i) + { + for (int j = 0; j < oripoint.size(); ++j) + { + dis = Distance(oripoint[j].X(), oripoint[j].Y(), insertpoint[i].X(), insertpoint[i].Y()); + oripoint[j].SetDis(dis); + } + SortDis(oripoint); + for (int k = 0; k < 20; ++k) + { + addNumerator += oripoint[k].H() / oripoint[k].Dis(); + addDenominator += 1.0 / oripoint[k].Dis(); + } + insertpoint[i].SetH(addNumerator / addDenominator); + addNumerator = 0; + addDenominator = 0; + } +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/BasicCalc.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/BasicCalc.h new file mode 100644 index 0000000..a95f77c --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/BasicCalc.h @@ -0,0 +1,39 @@ +/****************************************************************************** + +Ȩ (C), 2018-2020, + +****************************************************************************** + : BasicCalc.h + : + : + : 20181026 +޸ : + : ĺ +б : +* +* + +޸ʷ : +1. : 20181026 + : +޸ : ļ + +******************************************************************************/ +#pragma once +#include "PointInfo.h" +#include + +const double PI = 3.1415926535897932; +const double EPCLONG = 1.0e-10; +class CBasicCalc +{ +public: + CBasicCalc(); + ~CBasicCalc(); + + double Azimuth(double x1, double y1, double x2, double y2); + double Distance(double x1, double y1, double x2, double y2); + void SortDis(std::vector &p); //ð򣬰С + void CalcHeight(std::vector& oripoint, std::vector& insertpoint); //߳ +}; + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DrawDlg.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DrawDlg.cpp new file mode 100644 index 0000000..fc93878 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DrawDlg.cpp @@ -0,0 +1,95 @@ +// DrawDlg.cpp : ʵļ +// + +#include "stdafx.h" +#include "SectionCalculation.h" +#include "DrawDlg.h" +#include "afxdialogex.h" + + +// CDrawDlg Ի + +IMPLEMENT_DYNAMIC(CDrawDlg, CDialogEx) + +CDrawDlg::CDrawDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(IDD_DLG_DRAW, pParent) +{ + +} + +CDrawDlg::~CDrawDlg() +{ +} + +void CDrawDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + + +BEGIN_MESSAGE_MAP(CDrawDlg, CDialogEx) + ON_WM_SIZE() + ON_WM_MOUSEWHEEL() + ON_WM_MOUSEMOVE() + ON_WM_PAINT() +END_MESSAGE_MAP() + + +// CDrawDlg Ϣ + + +BOOL CDrawDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // TODO: ڴӶijʼ + CRect rect; + this->GetParent()->GetClientRect(&rect); + rect.top += 2; + rect.left += 2; + rect.right -= 10; + rect.bottom -= 2; + this->MoveWindow(rect); + + return TRUE; // return TRUE unless you set the focus to a control + // 쳣: OCX ҳӦ FALSE +} + + +void CDrawDlg::OnSize(UINT nType, int cx, int cy) +{ + CDialogEx::OnSize(nType, cx, cy); + if (::IsWindow(m_hWnd)) + { + CZoomView::SetScreenPoint(cx, cy); + Invalidate(); + } +} + + +BOOL CDrawDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) +{ + // TODO: ڴϢ/Ĭֵ + CZoomView::WheelScale(zDelta); + Invalidate(); + return CDialogEx::OnMouseWheel(nFlags, zDelta, pt); +} + + +void CDrawDlg::OnMouseMove(UINT nFlags, CPoint point) +{ + // TODO: ڴϢ/Ĭֵ + CZoomView::CoorMove(point.x, point.y, nFlags); + if (nFlags == 1) + Invalidate(); + CDialogEx::OnMouseMove(nFlags, point); +} + + +void CDrawDlg::OnPaint() +{ + CPaintDC dc(this); // device context for painting + // TODO: ڴ˴Ϣ + // ΪͼϢ CDialogEx::OnPaint() + CZoomView::Draw(dc); +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DrawDlg.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DrawDlg.h new file mode 100644 index 0000000..0b8d1de --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DrawDlg.h @@ -0,0 +1,29 @@ +#pragma once +#include "ZoomView.h" + +// CDrawDlg Ի + +class CDrawDlg : public CDialogEx +{ + DECLARE_DYNAMIC(CDrawDlg) + +public: + CDrawDlg(CWnd* pParent = NULL); // ׼캯 + virtual ~CDrawDlg(); + +// Ի +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_DLG_DRAW }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧ + + DECLARE_MESSAGE_MAP() +public: + virtual BOOL OnInitDialog(); + afx_msg void OnSize(UINT nType, int cx, int cy); + afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); + afx_msg void OnMouseMove(UINT nFlags, CPoint point); + afx_msg void OnPaint(); +}; diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DxfFile.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DxfFile.cpp new file mode 100644 index 0000000..f9077a2 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DxfFile.cpp @@ -0,0 +1,104 @@ +#include "stdafx.h" +#include "DxfFile.h" + + +CDxfFile::CDxfFile() +{ +} + + +CDxfFile::~CDxfFile() +{ +} + +bool CDxfFile::Begin() +{ + CFileDialog dlg(false, _T("dxf"), _T("resultDXF"), 6UL, _T("DXFļ(*.dxf)|*.dxf||")); + if (IDCANCEL == dlg.DoModal()) + return false; + + CString filename = dlg.GetPathName(); + if (!file.Open(filename, CFile::modeCreate | CFile::modeWrite)) + return false; + + file.WriteString(_T("0\n")); + file.WriteString(_T("SECTION\n")); + file.WriteString(_T("2\n")); + file.WriteString(_T("ENTITIES\n")); + return true; +} + +void CDxfFile::Line(double x1, double y1, double x2, double y2) +{ + file.WriteString(_T("0\n")); + file.WriteString(_T("LINE\n")); + file.WriteString(_T("8\n")); + file.WriteString(_T("0\n")); + file.WriteString(_T("10\n")); + str.Format(_T("%lf\n"), x1); + file.WriteString(str); + file.WriteString(_T("20\n")); + str.Format(_T("%lf\n"), y1); + file.WriteString(str); + file.WriteString(_T("30\n")); + file.WriteString(_T("0.0\n")); + + file.WriteString(_T("11\n")); + str.Format(_T("%lf\n"), x2); + file.WriteString(str); + file.WriteString(_T("21\n")); + str.Format(_T("%lf\n"), y2); + file.WriteString(str); + file.WriteString(_T("31\n")); + file.WriteString(_T("0.0\n")); +} + +void CDxfFile::Point(double x1, double y1) +{ + file.WriteString(_T("0\n")); + file.WriteString(_T("POINT\n")); + file.WriteString(_T("8\n")); + file.WriteString(_T("0\n")); + file.WriteString(_T("10\n")); + str.Format(_T("%lf\n"), x1); + file.WriteString(str); + file.WriteString(_T("20\n")); + str.Format(_T("%lf\n"), y1); + file.WriteString(str); + file.WriteString(_T("30\n")); + file.WriteString(_T("0.0\n")); +} + +void CDxfFile::Text(double x1, double y1, CString strID) +{ + file.WriteString(_T("0\n")); + file.WriteString(_T("TEXT\n")); + file.WriteString(_T("8\n")); + file.WriteString(_T("0\n")); + file.WriteString(_T("10\n")); + str.Format(_T("%lf\n"), x1); + file.WriteString(str); + file.WriteString(_T("20\n")); + str.Format(_T("%lf\n"), y1); + file.WriteString(str); + file.WriteString(_T("30\n")); + file.WriteString(_T("0.0\n")); + file.WriteString(_T("40\n")); + file.WriteString(_T("10\n")); + + file.WriteString(_T("1\n")); + str.Format(_T("%s\n"), strID); + file.WriteString(str); +} + +void CDxfFile::End() +{ + file.WriteString(_T("0\n")); + file.WriteString(_T("ENDSEC\n")); + file.WriteString(_T("0\n")); + file.WriteString(_T("EOF\n")); + + file.Close(); + AfxMessageBox(_T("dxfϣ")); +} + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DxfFile.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DxfFile.h new file mode 100644 index 0000000..1a3aaef --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/DxfFile.h @@ -0,0 +1,39 @@ +/****************************************************************************** + +Ȩ (C), 2018-2020, + +****************************************************************************** + : DxfFile.h + : + : + : 20181026 +޸ : + : дDXFļ +б : +* +* + +޸ʷ : +1. : 20181026 + : +޸ : ļ + +******************************************************************************/ +#pragma once +class CDxfFile +{ +public: + CDxfFile(); + ~CDxfFile(); + + bool Begin(); //dxfļͷ + void Line(double x1, double y1, double x2, double y2); // + void Point(double x1, double y1); // + void Text(double x1, double y1, CString strID); //д + void End(); //dxfļβ + +private: + CString str; + CStdioFile file; +}; + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/FileOperation.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/FileOperation.cpp new file mode 100644 index 0000000..1ed441e --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/FileOperation.cpp @@ -0,0 +1,145 @@ +#include "stdafx.h" +#include "FileOperation.h" + +CString CFileOperation::s_horizonSectionContent = _T(""); +CString CFileOperation::s_verticalSectionContent = _T(""); +CFileOperation::CFileOperation() +{ + m_h0 = 0; +} + + +CFileOperation::~CFileOperation() +{ +} + +bool CFileOperation::ReadData() +{ + CFileDialog dlg(true, _T("txt"), 0, 6UL, _T("ıļ(*.txt)|*.txt||")); + if (IDCANCEL == dlg.DoModal()) + return false; + CString filename = dlg.GetPathName(); + CStdioFile file; + if (!file.Open(filename, CFile::modeRead)) + return false; + + CString strline, strbuf; + std::vector data; + m_pOriPoint.clear(); + m_pKnowPoint.clear(); + + file.ReadString(strline); + data.clear(); + strline.Remove(' '); + while (strline.GetLength()) + { + strbuf = strline.SpanExcluding(_T(",")); + data.push_back(strbuf); + strline.Delete(0, strbuf.GetLength() + 1); + } + if (data.size() == 2) + { + m_h0 = _tstof(data[1]); + } + else + { + AfxMessageBox(_T("ļ򿪴")); + return false; + } + + CString str1, str2, str3; + file.ReadString(strline); + data.clear(); + strline.Remove(' '); + while (strline.GetLength()) + { + strbuf = strline.SpanExcluding(_T(",")); + data.push_back(strbuf); + strline.Delete(0, strbuf.GetLength() + 1); + } + if (data.size() == 3) + { + str1 = data[0]; + str2 = data[1]; + str3 = data[2]; + } + else + { + AfxMessageBox(_T("ļ򿪴")); + return false; + } + + while (file.ReadString(strline)) + { + data.clear(); + strline.Remove(' '); + if (strline.GetLength() > 0) + { + while (strline.GetLength()) + { + strbuf = strline.SpanExcluding(_T(",")); + data.push_back(strbuf); + strline.Delete(0, strbuf.GetLength() + 1); + } + if (data.size() == 4) + { + if (data[0] == str1 || data[0] == str2 || data[0] == str3) + { + m_pKnowPoint.push_back(CPointInfo(data[0], _tstof(data[1]), _tstof(data[2]), _tstof(data[3]))); + } + m_pOriPoint.push_back(CPointInfo(data[0], _tstof(data[1]), _tstof(data[2]), _tstof(data[3]))); + } + else + { + AfxMessageBox(_T("ļ򿪴")); + return false; + } + } + } + file.Close(); + return true; +} + +void CFileOperation::WriteTXT() +{ + CFileDialog dlg(false, _T("txt"), 0, 6UL, _T("ıļ(*.txt)|*.txt||")); + if (IDCANCEL == dlg.DoModal()) + return; + CString filename = dlg.GetPathName(); + + CStdioFile file; + if (!file.Open(filename, CFile::modeCreate | CFile::modeWrite)) + return; + + CString strbuf; + CString data = s_verticalSectionContent; + while (data.GetLength()) + { + strbuf = data.SpanExcluding(_T("\r\n")); + file.WriteString(strbuf + _T("\n")); + data.Delete(0, strbuf.GetLength() + 2); + } + data = s_horizonSectionContent; + while (data.GetLength()) + { + strbuf = data.SpanExcluding(_T("\r\n")); + file.WriteString(strbuf + _T("\n")); + data.Delete(0, strbuf.GetLength() + 2); + } + file.Close(); +} + +std::vector CFileOperation::OriPoint() const +{ + return m_pOriPoint; +} + +std::vector CFileOperation::KnowPoint() const +{ + return m_pKnowPoint; +} + +double CFileOperation::H0() const +{ + return m_h0; +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/FileOperation.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/FileOperation.h new file mode 100644 index 0000000..19e3c37 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/FileOperation.h @@ -0,0 +1,48 @@ +/****************************************************************************** + +Ȩ (C), 2018-2020, + +****************************************************************************** + : FileOperation.h + : + : + : 20181026 +޸ : + : ļزȡд롣 +б : +* +* + +޸ʷ : +1. : 20181026 + : +޸ : ļ + +******************************************************************************/ +#pragma once +#include "BasicCalc.h" +#include + +class CFileOperation +{ +public: + CFileOperation(); + ~CFileOperation(); +public: + bool ReadData(); //ļȡ + void WriteTXT(); //TXTļ +public: + std::vector OriPoint() const; + std::vector KnowPoint() const; + double H0() const; + +public: + CBasicCalc m_basicCalc; + static CString s_horizonSectionContent; //ڴ洢rrַ + static CString s_verticalSectionContent; //ڴ洢rrַ +private: + std::vector m_pOriPoint; //ԭʼ + std::vector m_pKnowPoint; //֪ + double m_h0; +}; + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/HorizonSectionCalc.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/HorizonSectionCalc.cpp new file mode 100644 index 0000000..34a6e54 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/HorizonSectionCalc.cpp @@ -0,0 +1,144 @@ +#include "stdafx.h" +#include "HorizonSectionCalc.h" + + +CHorizonSectionCalc::CHorizonSectionCalc() +{ + detta = 5; + //IJ + am = 0; + an = 0; //λ + mX = 0; + mY = 0; + nX = 0; + nY = 0; + m_mTotalArea = 0; //M + m_nTotalArea = 0;//N +} + + +CHorizonSectionCalc::~CHorizonSectionCalc() +{ +} + +void CHorizonSectionCalc::CalcHorizonSection(CFileOperation fileOper) +{ + m_fileOper = fileOper; + m_pOripoint.clear(); + m_pOripoint = m_fileOper.OriPoint(); + m_pKnowpoint.clear(); + m_pKnowpoint = m_fileOper.KnowPoint(); + + double a1 = m_fileOper.m_basicCalc.Azimuth(m_pKnowpoint[0].X(), m_pKnowpoint[0].Y(), m_pKnowpoint[1].X(), m_pKnowpoint[1].Y()); + double a2 = m_fileOper.m_basicCalc.Azimuth(m_pKnowpoint[1].X(), m_pKnowpoint[1].Y(), m_pKnowpoint[2].X(), m_pKnowpoint[2].Y()); + am = a1 - PI / 2.0; + an = a2 - PI / 2.0; + mX = (m_pKnowpoint[0].X() + m_pKnowpoint[1].X()) / 2.0; + mY = (m_pKnowpoint[0].Y() + m_pKnowpoint[1].Y()) / 2.0; + nX = (m_pKnowpoint[1].X() + m_pKnowpoint[2].X()) / 2.0; + nY = (m_pKnowpoint[1].Y() + m_pKnowpoint[2].Y()) / 2.0; + + CalcInsertPointPosition(); + CalcHeight(); + CalcArea(m_pMHInsertPoint, m_mTotalArea); + CalcArea(m_pNHInsertPoint, m_nTotalArea); + AfxMessageBox(_T(" ɣ")); + + WriteData(m_fileOper.s_horizonSectionContent); +} + +void CHorizonSectionCalc::CalcInsertPointPosition() +{ + m_pMHInsertPoint.clear(); + m_pNHInsertPoint.clear(); + + double dX, dY, dK; + CString str; + for (int i = 0; i < 11; ++i) + { + str.Format(_T("C%d"), i - 5); + dX = mX + (i - 5) * detta * cos(am); + dY = mY + (i - 5) * detta * sin(am); + dK = i * detta; + m_pMHInsertPoint.push_back(CPointInfo(str, dX, dY, 0, dK)); + } + str.Format(_T("M")); + m_pMHInsertPoint[5].SetPointName(str); + + for (int i = 0; i < 11; ++i) + { + str.Format(_T("C%d"), i - 5); + dX = nX + (i - 5) * detta * cos(an); + dY = nY + (i - 5) * detta * sin(an); + dK = i * detta; + m_pNHInsertPoint.push_back(CPointInfo(str, dX, dY, 0, dK)); + } + str.Format(_T("N")); + m_pNHInsertPoint[5].SetPointName(str); +} + +void CHorizonSectionCalc::CalcHeight() +{ + m_fileOper.m_basicCalc.CalcHeight(m_pOripoint, m_pMHInsertPoint); + m_fileOper.m_basicCalc.CalcHeight(m_pOripoint, m_pNHInsertPoint); +} + +void CHorizonSectionCalc::CalcArea(std::vector& insertpoint, double& totalArea) +{ + totalArea = 0; + double H0 = m_fileOper.H0(); + for (int i = 0; i < insertpoint.size() - 1; ++i) + { + totalArea += (insertpoint[i].H() + insertpoint[i + 1].H() - 2.0 * H0) / 2.0 * detta; + } +} + +void CHorizonSectionCalc::WriteData(CString & content) +{ + content = _T(""); + setlocale(LC_ALL, ""); + CString str; + content += _T("\r\n M Ϣ\r\n"); + content += _T("------------------------------------------------------------------------------------\r\n"); + if (m_pMHInsertPoint.size() > 0) + { + str.Format(_T(":%.3lf\r\n"), m_mTotalArea); + content += str; + str.Format(_T("ȫ:50\r\n")); + content += str; + content += _T("·\r\n"); + content += _T("\tK(m) X(m)\tY(m)\tH(m)\r\n"); + for (int i = 0; i < m_pMHInsertPoint.size(); ++i) + { + str.Format(_T("%s\t%.3lf\t%.3lf\t%.3lf\t%.3lf\r\n"), m_pMHInsertPoint[i].PointName(), m_pMHInsertPoint[i].K(), m_pMHInsertPoint[i].X(), m_pMHInsertPoint[i].Y(), m_pMHInsertPoint[i].H()); + content += str; + } + } + + content += _T("\r\n N Ϣ\r\n"); + content += _T("------------------------------------------------------------------------------------\r\n"); + if (m_pNHInsertPoint.size() > 0) + { + str.Format(_T(":%.3lf\r\n"), m_nTotalArea); + content += str; + str.Format(_T("ȫ:50\r\n")); + content += str; + content += _T("·\r\n"); + content += _T("\tK(m) X(m)\tY(m)\tH(m)\r\n"); + for (int i = 0; i < m_pNHInsertPoint.size(); ++i) + { + str.Format(_T("%s\t%.3lf\t%.3lf\t%.3lf\t%.3lf\r\n"), m_pNHInsertPoint[i].PointName(), m_pNHInsertPoint[i].K(), m_pNHInsertPoint[i].X(), m_pNHInsertPoint[i].Y(), m_pNHInsertPoint[i].H()); + content += str; + } + } +} + +std::vector CHorizonSectionCalc::MHInsertPoint() const +{ + return m_pMHInsertPoint; +} + +std::vector CHorizonSectionCalc::NHInsertPoint() const +{ + return m_pNHInsertPoint; +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/HorizonSectionCalc.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/HorizonSectionCalc.h new file mode 100644 index 0000000..55199c2 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/HorizonSectionCalc.h @@ -0,0 +1,58 @@ +/****************************************************************************** + +Ȩ (C), 2018-2020, + +****************************************************************************** + : HorizonSectionCalc.h + : + : + : 20181026 +޸ : + : ļ㡣MK0 K1ĵ㣬NK1K2ĵ㣬ֱMNƺ档 +б : +* +* + +޸ʷ : +1. : 20181026 + : +޸ : ļ + +******************************************************************************/ +#pragma once +#include "FileOperation.h" +class CHorizonSectionCalc +{ +public: + CHorizonSectionCalc(); + ~CHorizonSectionCalc(); + +public: + void CalcHorizonSection(CFileOperation fileOper); //Ϣ + +private: + void CalcInsertPointPosition(); //Ϣ + void CalcHeight(); //߳ + void CalcArea(std::vector& insertpoint, double& totalArea); // + void WriteData(CString &content); + +public: + std::vector MHInsertPoint() const; + std::vector NHInsertPoint() const; + +private: + std::vector m_pMHInsertPoint; //IJֵ + std::vector m_pNHInsertPoint; //IJֵ + CFileOperation m_fileOper; + std::vector m_pOripoint; + std::vector m_pKnowpoint; + + double detta; //ֵļ + + //IJ + double am, an; //λ + double mX, mY; + double nX, nY; + double m_mTotalArea, m_nTotalArea; //M , N +}; + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ListDlg.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ListDlg.cpp new file mode 100644 index 0000000..fa9b4ab --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ListDlg.cpp @@ -0,0 +1,60 @@ +// ListDlg.cpp : ʵļ +// + +#include "stdafx.h" +#include "SectionCalculation.h" +#include "ListDlg.h" +#include "afxdialogex.h" + + +// CListDlg Ի + +IMPLEMENT_DYNAMIC(CListDlg, CDialogEx) + +CListDlg::CListDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(IDD_DLG_LIST, pParent) +{ + +} + +CListDlg::~CListDlg() +{ +} + +void CListDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list); +} + + +BEGIN_MESSAGE_MAP(CListDlg, CDialogEx) +END_MESSAGE_MAP() + + +// CListDlg Ϣ + + +BOOL CListDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // TODO: ڴӶijʼ + CRect rect; + this->GetParent()->GetClientRect(&rect); + rect.top += 2; + rect.left += 2; + rect.right -= 10; + rect.bottom -= 2; + m_list.MoveWindow(rect); + + m_list.ModifyStyle(0, LVS_REPORT); + m_list.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); + m_list.InsertColumn(0, _T(""), LVCFMT_LEFT, 150); + m_list.InsertColumn(1, _T("X"), LVCFMT_LEFT, 150); + m_list.InsertColumn(2, _T("Y"), LVCFMT_LEFT, 150); + m_list.InsertColumn(3, _T("H"), LVCFMT_LEFT, 150); + + return TRUE; // return TRUE unless you set the focus to a control + // 쳣: OCX ҳӦ FALSE +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ListDlg.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ListDlg.h new file mode 100644 index 0000000..e6b34aa --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ListDlg.h @@ -0,0 +1,27 @@ +#pragma once +#include "afxcmn.h" + + +// CListDlg Ի + +class CListDlg : public CDialogEx +{ + DECLARE_DYNAMIC(CListDlg) + +public: + CListDlg(CWnd* pParent = NULL); // ׼캯 + virtual ~CListDlg(); + +// Ի +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_DLG_LIST }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧ + + DECLARE_MESSAGE_MAP() +public: + CListCtrl m_list; + virtual BOOL OnInitDialog(); +}; diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/PointInfo.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/PointInfo.cpp new file mode 100644 index 0000000..0d09d8a --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/PointInfo.cpp @@ -0,0 +1,73 @@ +#include "stdafx.h" +#include "PointInfo.h" + + +CPointInfo::CPointInfo() +{ + m_pointName = _T(""); + m_x = 0; + m_y = 0; + m_h = 0; + m_k = 0; + m_dis = 0; +} + +CPointInfo::CPointInfo(CString pointName, double x, double y, double h, double k, double dis) +{ + m_pointName = pointName; + m_x = x; + m_y = y; + m_h = h; + m_k = k; + m_dis = dis; +} + + +CPointInfo::~CPointInfo() +{ +} + +CString CPointInfo::PointName() const +{ + return m_pointName; +} + +double CPointInfo::X() const +{ + return m_x; +} + +double CPointInfo::Y() const +{ + return m_y; +} + +double CPointInfo::H() const +{ + return m_h; +} + +double CPointInfo::K() const +{ + return m_k; +} + +double CPointInfo::Dis() const +{ + return m_dis; +} + +void CPointInfo::SetPointName(CString str) +{ + m_pointName = str; +} + +void CPointInfo::SetH(double h) +{ + m_h = h; +} + +void CPointInfo::SetDis(double dis) +{ + m_dis = dis; +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/PointInfo.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/PointInfo.h new file mode 100644 index 0000000..72d2b35 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/PointInfo.h @@ -0,0 +1,48 @@ +/****************************************************************************** + +Ȩ (C), 2018-2020, + +****************************************************************************** + : PointInfo.h + : + : + : 20181026 +޸ : + : 洢λϢ +б : +* +* + +޸ʷ : +1. : 20181026 + : +޸ : ļ + +******************************************************************************/ +#pragma once +class CPointInfo +{ +public: + CPointInfo(); + CPointInfo(CString pointName, double x, double y, double h, double k = 0, double dis = 0); + ~CPointInfo(); +public: + CString PointName() const; + double X() const; + double Y() const; + double H() const; + double K() const; + double Dis() const; + void SetPointName(CString str); + void SetH(double h); + void SetDis(double dis); + +private: + CString m_pointName; // + double m_x; //x + double m_y; //y + double m_h; //h + double m_k; // + double m_dis; // +}; + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReadMe.txt b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReadMe.txt new file mode 100644 index 0000000..457d50c --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReadMe.txt @@ -0,0 +1,70 @@ +================================================================================ + MICROSOFT 基础类库 : SectionCalculation 项目概述 +=============================================================================== + +应用程序向导已为您创建了此 SectionCalculation 应用程序。此应用程序不仅演示 Microsoft 基础类的基本使用方法,还可作为您编写应用程序的起点。 + +本文件概要介绍组成 SectionCalculation 应用程序的每个文件的内容。 + +SectionCalculation.vcxproj + 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 + +SectionCalculation.vcxproj.filters + 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 + +SectionCalculation.h + 这是应用程序的主头文件。 + 其中包括其他项目特定的标头(包括 Resource.h),并声明 CSectionCalculationApp 应用程序类。 + +SectionCalculation.cpp + 这是包含应用程序类 CSectionCalculationApp 的主应用程序源文件。 + +SectionCalculation.rc + 这是程序使用的所有 Microsoft Windows 资源的列表。它包括 RES 子目录中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ 中进行编辑。项目资源包含在 2052 中。 + +res\SectionCalculation.ico + 这是用作应用程序图标的图标文件。此图标包括在主资源文件 SectionCalculation.rc 中。 + +res\SectionCalculation.rc2 + 此文件包含不在 Microsoft Visual C++ 中进行编辑的资源。您应该将不可由资源编辑器编辑的所有资源放在此文件中。 + + +///////////////////////////////////////////////////////////////////////////// + +应用程序向导创建一个对话框类: + +SectionCalculationDlg.h、SectionCalculationDlg.cpp - 对话框 + 这些文件包含 CSectionCalculationDlg 类。此类定义应用程序的主对话框的行为。对话框模板包含在 SectionCalculation.rc 中,该文件可以在 Microsoft Visual C++ 中编辑。 + +///////////////////////////////////////////////////////////////////////////// + +其他功能: + +ActiveX 控件 + 该应用程序包含对使用 ActiveX 控件的支持。 + +打印和打印预览支持 + 应用程序向导通过从 MFC 库调用 CView 类中的成员函数生成代码,来处理打印、打印设置和打印预览命令。 + +///////////////////////////////////////////////////////////////////////////// + +其他标准文件: + +StdAfx.h, StdAfx.cpp + 这些文件用于生成名为 SectionCalculation.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 + +Resource.h + 这是标准头文件,可用于定义新的资源 ID。Microsoft Visual C++ 将读取并更新此文件。 + +SectionCalculation.manifest + Windows XP 使用应用程序清单文件来描述特定版本的并行程序集的应用程序依赖项。加载程序使用这些信息来从程序集缓存中加载相应的程序集,并保护其不被应用程序访问。应用程序清单可能会包含在内,以作为与应用程序可执行文件安装在同一文件夹中的外部 .manifest 文件进行重新分发,它还可能以资源的形式包含在可执行文件中。 +///////////////////////////////////////////////////////////////////////////// + +其他注释: + +应用程序向导使用“TODO:”来指示应添加或自定义的源代码部分。 + +如果应用程序使用共享 DLL 中的 MFC,您将需要重新分发 MFC DLL。如果应用程序所使用的语言与操作系统的区域设置不同,则还需要重新分发相应的本地化资源 mfc110XXX.DLL。 +有关上述话题的更多信息,请参见 MSDN 文档中有关重新分发 Visual C++ 应用程序的部分。 + +///////////////////////////////////////////////////////////////////////////// diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReportDlg.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReportDlg.cpp new file mode 100644 index 0000000..04893c0 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReportDlg.cpp @@ -0,0 +1,53 @@ +// ReportDlg.cpp : ʵļ +// + +#include "stdafx.h" +#include "SectionCalculation.h" +#include "ReportDlg.h" +#include "afxdialogex.h" + + +// CReportDlg Ի + +IMPLEMENT_DYNAMIC(CReportDlg, CDialogEx) + +CReportDlg::CReportDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(IDD_DLG_REPORT, pParent) +{ + +} + +CReportDlg::~CReportDlg() +{ +} + +void CReportDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_EDIT1, m_edit); +} + + +BEGIN_MESSAGE_MAP(CReportDlg, CDialogEx) +END_MESSAGE_MAP() + + +// CReportDlg Ϣ + + +BOOL CReportDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // TODO: ڴӶijʼ + CRect rect; + this->GetParent()->GetClientRect(&rect); + rect.top += 2; + rect.left += 2; + rect.right -= 10; + rect.bottom -= 2; + m_edit.MoveWindow(rect); + + return TRUE; // return TRUE unless you set the focus to a control + // 쳣: OCX ҳӦ FALSE +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReportDlg.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReportDlg.h new file mode 100644 index 0000000..44cba40 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ReportDlg.h @@ -0,0 +1,27 @@ +#pragma once +#include "afxwin.h" + + +// CReportDlg Ի + +class CReportDlg : public CDialogEx +{ + DECLARE_DYNAMIC(CReportDlg) + +public: + CReportDlg(CWnd* pParent = NULL); // ׼캯 + virtual ~CReportDlg(); + +// Ի +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_DLG_REPORT }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧ + + DECLARE_MESSAGE_MAP() +public: + CEdit m_edit; + virtual BOOL OnInitDialog(); +}; diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.aps b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.aps new file mode 100644 index 0000000..bfc9142 Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.aps differ diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.cpp new file mode 100644 index 0000000..7ffa350 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.cpp @@ -0,0 +1,102 @@ + +// SectionCalculation.cpp : ӦóΪ +// + +#include "stdafx.h" +#include "SectionCalculation.h" +#include "SectionCalculationDlg.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// CSectionCalculationApp + +BEGIN_MESSAGE_MAP(CSectionCalculationApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CSectionCalculationApp + +CSectionCalculationApp::CSectionCalculationApp() +{ + // ֧ + m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; + + // TODO: ڴ˴ӹ룬 + // Ҫijʼ InitInstance +} + + +// Ψһһ CSectionCalculationApp + +CSectionCalculationApp theApp; + + +// CSectionCalculationApp ʼ + +BOOL CSectionCalculationApp::InitInstance() +{ + // һ Windows XP ϵӦó嵥ָҪ + // ʹ ComCtl32.dll 汾 6 ߰汾ÿӻʽ + //Ҫ InitCommonControlsEx() 򣬽޷ڡ + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // ΪҪӦóʹõ + // ؼࡣ + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // shell ԷԻ + // κ shell ͼؼ shell бͼؼ + CShellManager *pShellManager = new CShellManager; + + // Windows NativeӾԱ MFC ؼ + CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); + + // ׼ʼ + // δʹЩܲϣС + // տִļĴСӦƳ + // Ҫضʼ + // ڴ洢õע + // TODO: Ӧʵ޸ĸַ + // ޸Ϊ˾֯ + SetRegistryKey(_T("ӦóɵıӦó")); + + CSectionCalculationDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: ڴ˷ôʱ + // ȷرնԻĴ + } + else if (nResponse == IDCANCEL) + { + // TODO: ڴ˷ôʱ + // ȡرնԻĴ + } + else if (nResponse == -1) + { + TRACE(traceAppMsg, 0, ": Ի򴴽ʧܣӦóֹ\n"); + TRACE(traceAppMsg, 0, ": ڶԻʹ MFC ؼ޷ #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS\n"); + } + + // ɾ洴 shell + if (pShellManager != NULL) + { + delete pShellManager; + } + + // ڶԻѹرգԽ FALSE Ա˳Ӧó + // ӦóϢá + return FALSE; +} + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.h new file mode 100644 index 0000000..387500a --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.h @@ -0,0 +1,32 @@ + +// SectionCalculation.h : PROJECT_NAME Ӧóͷļ +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "ڰļ֮ǰstdafx.h PCH ļ" +#endif + +#include "resource.h" // + + +// CSectionCalculationApp: +// йشʵ֣ SectionCalculation.cpp +// + +class CSectionCalculationApp : public CWinApp +{ +public: + CSectionCalculationApp(); + +// д +public: + virtual BOOL InitInstance(); + +// ʵ + + DECLARE_MESSAGE_MAP() +}; + +extern CSectionCalculationApp theApp; \ No newline at end of file diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.rc b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.rc new file mode 100644 index 0000000..65b2caf Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.rc differ diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.vcxproj b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.vcxproj new file mode 100644 index 0000000..b379767 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.vcxproj @@ -0,0 +1,243 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {7B25400A-51C5-449B-87A6-88A0D9B0DC25} + SectionCalculation + 8.1 + MFCProj + + + + Application + true + v140 + Unicode + Dynamic + + + Application + false + v140 + true + Unicode + Dynamic + + + Application + true + v140 + Unicode + Dynamic + + + Application + false + v140 + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0804 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + _WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0804 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0804 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0804 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.vcxproj.filters b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.vcxproj.filters new file mode 100644 index 0000000..fa77db8 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculation.vcxproj.filters @@ -0,0 +1,129 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 资源文件 + + + + + 资源文件 + + + + + 资源文件 + + + 资源文件 + + + 资源文件 + + + \ No newline at end of file diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculationDlg.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculationDlg.cpp new file mode 100644 index 0000000..15e5bdd --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculationDlg.cpp @@ -0,0 +1,718 @@ + +// SectionCalculationDlg.cpp : ʵļ +// + +#include "stdafx.h" +#include "SectionCalculation.h" +#include "SectionCalculationDlg.h" +#include "afxdialogex.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// Ӧó򡰹ڡ˵ CAboutDlg Ի + +class CAboutDlg : public CDialogEx +{ +public: + CAboutDlg(); + +// Ի +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_ABOUTBOX }; +#endif + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧ + +// ʵ +protected: + DECLARE_MESSAGE_MAP() +}; + +CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) +{ +} + +void CAboutDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) +END_MESSAGE_MAP() + + +// CSectionCalculationDlg Ի + + + +CSectionCalculationDlg::CSectionCalculationDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(IDD_SECTIONCALCULATION_DIALOG, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + ia = 0; + ib = 0; + ic = 0; + idd = 0; + ie = 0; +} + +void CSectionCalculationDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_TAB1, m_tab); +} + +BEGIN_MESSAGE_MAP(CSectionCalculationDlg, CDialogEx) + ON_WM_SYSCOMMAND() + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CSectionCalculationDlg::OnSelchangeTab1) + ON_COMMAND(IDM_OPEN, &CSectionCalculationDlg::OnOpen) + ON_COMMAND(IDM_TXT, &CSectionCalculationDlg::OnTxt) + ON_COMMAND(IDM_DXF, &CSectionCalculationDlg::OnDxf) + ON_COMMAND(IDM_VCALC, &CSectionCalculationDlg::OnVcalc) + ON_COMMAND(IDM_HCALC, &CSectionCalculationDlg::OnHcalc) + ON_COMMAND(IDM_LIST, &CSectionCalculationDlg::OnList) + ON_COMMAND(IDM_DRAW, &CSectionCalculationDlg::OnDraw) + ON_COMMAND(IDM_REPORT, &CSectionCalculationDlg::OnReport) + ON_UPDATE_COMMAND_UI(IDM_TXT, &CSectionCalculationDlg::OnUpdateTxt) + ON_UPDATE_COMMAND_UI(IDM_DXF, &CSectionCalculationDlg::OnUpdateDxf) + ON_UPDATE_COMMAND_UI(IDM_VCALC, &CSectionCalculationDlg::OnUpdateVcalc) + ON_UPDATE_COMMAND_UI(IDM_HCALC, &CSectionCalculationDlg::OnUpdateHcalc) + ON_UPDATE_COMMAND_UI(IDM_DRAW, &CSectionCalculationDlg::OnUpdateDraw) + ON_UPDATE_COMMAND_UI(IDM_REPORT, &CSectionCalculationDlg::OnUpdateReport) + ON_WM_INITMENUPOPUP() + ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipNotify) + ON_COMMAND(IDM_ZOOM_IN, &CSectionCalculationDlg::OnZoomIn) + ON_UPDATE_COMMAND_UI(IDM_ZOOM_IN, &CSectionCalculationDlg::OnUpdateZoomIn) + ON_COMMAND(IDM_ZOOM_OUT, &CSectionCalculationDlg::OnZoomOut) + ON_UPDATE_COMMAND_UI(IDM_ZOOM_OUT, &CSectionCalculationDlg::OnUpdateZoomOut) +END_MESSAGE_MAP() + + +// CSectionCalculationDlg Ϣ + +BOOL CSectionCalculationDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // ...˵ӵϵͳ˵С + m_toolbar.CreateEx(this); + m_toolbar.LoadToolBar(IDR_TOOLBAR1); + CRect rect1; + GetClientRect(&rect1); + m_toolbar.MoveWindow(0, 0, rect1.Width(), 50); + m_toolbar.EnableToolTips(TRUE); + + // IDM_ABOUTBOX ϵͳΧڡ + ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); + ASSERT(IDM_ABOUTBOX < 0xF000); + + CMenu* pSysMenu = GetSystemMenu(FALSE); + if (pSysMenu != NULL) + { + BOOL bNameValid; + CString strAboutMenu; + bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); + ASSERT(bNameValid); + if (!strAboutMenu.IsEmpty()) + { + pSysMenu->AppendMenu(MF_SEPARATOR); + pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); + } + } + + // ô˶Իͼꡣ ӦóڲǶԻʱܽԶ + // ִд˲ + SetIcon(m_hIcon, TRUE); // ôͼ + SetIcon(m_hIcon, FALSE); // Сͼ + + // TODO: ڴӶijʼ + m_tab.InsertItem(0, _T("")); + m_tab.InsertItem(1, _T("ͼ")); + m_tab.InsertItem(2, _T("")); + + m_listDlg.Create(IDD_DLG_LIST, &m_tab); + m_drawDlg.Create(IDD_DLG_DRAW, &m_tab); + m_reportDlg.Create(IDD_DLG_REPORT, &m_tab); + + m_listDlg.ShowWindow(SW_SHOW); + m_drawDlg.ShowWindow(SW_HIDE); + m_reportDlg.ShowWindow(SW_HIDE); + + //ȡtabؼĴС + CRect rect; + m_tab.GetClientRect(&rect); + rect.top += 2; + rect.left += 1; + rect.right -= 2; + rect.bottom -= 22; + m_listDlg.MoveWindow(rect); + m_drawDlg.MoveWindow(rect); + m_reportDlg.MoveWindow(rect); + + return TRUE; // ǽõؼ򷵻 TRUE +} + +void CSectionCalculationDlg::OnSysCommand(UINT nID, LPARAM lParam) +{ + if ((nID & 0xFFF0) == IDM_ABOUTBOX) + { + CAboutDlg dlgAbout; + dlgAbout.DoModal(); + } + else + { + CDialogEx::OnSysCommand(nID, lParam); + } +} + +// ԻСťҪĴ +// Ƹͼꡣ ʹĵ/ͼģ͵ MFC Ӧó +// ⽫ɿԶɡ + +void CSectionCalculationDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // ڻƵ豸 + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // ʹͼڹо + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // ͼ + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +//û϶Сʱϵͳô˺ȡù +//ʾ +HCURSOR CSectionCalculationDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + + + +void CSectionCalculationDlg::OnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult) +{ + int nSelect = m_tab.GetCurSel(); + if (nSelect == 0) + { + m_listDlg.ShowWindow(SW_SHOW); + m_drawDlg.ShowWindow(SW_HIDE); + m_reportDlg.ShowWindow(SW_HIDE); + } + if (nSelect == 1 && idd == 1) + { + m_listDlg.ShowWindow(SW_HIDE); + m_drawDlg.ShowWindow(SW_SHOW); + m_reportDlg.ShowWindow(SW_HIDE); + } + if (nSelect == 2 && ie == 1) + { + m_listDlg.ShowWindow(SW_HIDE); + m_drawDlg.ShowWindow(SW_HIDE); + m_reportDlg.ShowWindow(SW_SHOW); + } + *pResult = 0; +} + + +void CSectionCalculationDlg::OnOpen() +{ + if (false == m_fileOper.ReadData()) + { + ia = 0; + ib = 0; + ic = 0; + idd = 0; + ie = 0; + return; + } + m_listDlg.m_list.DeleteAllItems(); + CString str; + for (int i = 0; i < m_fileOper.OriPoint().size(); ++i) + { + m_listDlg.m_list.InsertItem(i, _T("")); + m_listDlg.m_list.SetItemText(i, 0, m_fileOper.OriPoint()[i].PointName()); + str.Format(_T("%lf"), m_fileOper.OriPoint()[i].X()); + m_listDlg.m_list.SetItemText(i, 1, str); + + str.Format(_T("%lf"), m_fileOper.OriPoint()[i].Y()); + m_listDlg.m_list.SetItemText(i, 2, str); + + str.Format(_T("%lf"), m_fileOper.OriPoint()[i].H()); + m_listDlg.m_list.SetItemText(i, 3, str); + } + ia = 1; + ib = 0; + ic = 0; + idd = 0; + m_listDlg.ShowWindow(SW_SHOW); + m_drawDlg.ShowWindow(SW_HIDE); + m_reportDlg.ShowWindow(SW_HIDE); + m_tab.SetCurSel(0); +} + + +void CSectionCalculationDlg::OnTxt() +{ + m_fileOper.WriteTXT(); +} + + +void CSectionCalculationDlg::OnDxf() +{ + DrawDxf(); +} + + +void CSectionCalculationDlg::OnVcalc() +{ + m_calcV.CalcVerticalSection(m_fileOper); + ia = 0; + ib = 1; + ic = 0; + idd = 0; + ie = 0; +} + + +void CSectionCalculationDlg::OnHcalc() +{ + m_calcH.CalcHorizonSection(m_fileOper); + ia = 0; + ib = 0; + ic = 1; + idd = 0; + ie = 0; +} + + +void CSectionCalculationDlg::OnList() +{ + m_listDlg.ShowWindow(SW_SHOW); + m_drawDlg.ShowWindow(SW_HIDE); + m_reportDlg.ShowWindow(SW_HIDE); + m_tab.SetCurSel(0); +} + + +void CSectionCalculationDlg::OnDraw() +{ + CZoomView::SetPoint(CZoomView::m_tempOriPoint, m_fileOper.OriPoint()); + CZoomView::SetPoint(CZoomView::m_tempKnowPoint, m_fileOper.KnowPoint()); + CZoomView::SetPoint(CZoomView::m_tempVInsertPoint, m_calcV.VInsertPoint()); + CZoomView::SetPoint(CZoomView::m_tempMInsertPoint, m_calcH.MHInsertPoint()); + CZoomView::SetPoint(CZoomView::m_tempNInsertPoint, m_calcH.NHInsertPoint()); + CZoomView::SetData(CZoomView::m_tempOriPoint); + m_listDlg.ShowWindow(SW_HIDE); + m_drawDlg.ShowWindow(SW_SHOW); + m_reportDlg.ShowWindow(SW_HIDE); + m_tab.SetCurSel(1); + idd = 1; +} + + +void CSectionCalculationDlg::OnReport() +{ + CString content = m_fileOper.s_verticalSectionContent + m_fileOper.s_horizonSectionContent; + m_reportDlg.m_edit.SetWindowTextW(content); + m_listDlg.ShowWindow(SW_HIDE); + m_drawDlg.ShowWindow(SW_HIDE); + m_reportDlg.ShowWindow(SW_SHOW); + m_tab.SetCurSel(2); + ie = 1; +} + + +void CSectionCalculationDlg::OnUpdateTxt(CCmdUI *pCmdUI) +{ + if (ic == 1) + pCmdUI->Enable(1); + else + pCmdUI->Enable(0); +} + + +void CSectionCalculationDlg::OnUpdateDxf(CCmdUI *pCmdUI) +{ + if (ic == 1) + pCmdUI->Enable(1); + else + pCmdUI->Enable(0); +} + + +void CSectionCalculationDlg::OnUpdateVcalc(CCmdUI *pCmdUI) +{ + if (ia == 1) + pCmdUI->Enable(1); + else + pCmdUI->Enable(0); +} + + +void CSectionCalculationDlg::OnUpdateHcalc(CCmdUI *pCmdUI) +{ + if (ib == 1) + pCmdUI->Enable(1); + else + pCmdUI->Enable(0); +} + + +void CSectionCalculationDlg::OnUpdateDraw(CCmdUI *pCmdUI) +{ + if (ic == 1) + pCmdUI->Enable(1); + else + pCmdUI->Enable(0); +} + + +void CSectionCalculationDlg::OnUpdateReport(CCmdUI *pCmdUI) +{ + if (ic == 1) + pCmdUI->Enable(1); + else + pCmdUI->Enable(0); +} + +void CSectionCalculationDlg::DrawDxf() +{ + if (false == m_dxf.Begin()) + return; + + //᣺ ᶼΪ1500 Ϊ1500 Ϊ500 + m_dxf.Line(0, 1500, 1500, 1500);//h + m_dxf.Line(0, 1500, 0, 2000);//v + //ƿ̶ + double dv = 500.0 / 3.0; + double dh = 1500.0 / 4.0; + double dX, dY; + CString str; + for (int i = 0; i < 4; ++i) + { + dX = dh * i; + dY = dv * i + 1500; + m_dxf.Line(0, dY, -10, dY);//v + m_dxf.Line(dX, 1500, dX, 1490);//h + str.Format(_T("%d"), 3350 + 20 * i); + m_dxf.Text(-80, dY, str); + str.Format(_T("%d"), 4490 + 20 * i); + m_dxf.Text(dX, 1470, str); + } + str.Format(_T("%d"), 4570); + m_dxf.Text(1500, 1470, str); + + //ڶ 700z -- 1200 + m_dxf.Line(0, 700, 1500, 700); //h + m_dxf.Line(0, 700, 0, 1200); //z + dv = 500.0 / 5.0; + dh = 1500.0 / 5.0; + for (int i = 0; i < 6; ++i) + { + dY = dv * i + 700; + dX = dh * i; + m_dxf.Line(0, dY, -10, dY); //v + m_dxf.Line(dX, 700, dX, 690); //h + str.Format(_T("%d"), 10 + 2 * i); + m_dxf.Text(-80, dY, str); + str.Format(_T("%d"), 2 * i); + m_dxf.Text(dX, 670, str); + } + + // 0-500 + m_dxf.Line(0, 0, 1500, 0); //h + m_dxf.Line(0, 0, 0, 500); //z + dv = 500.0 / 5.0; + dh = 1500.0 / 5.0; + for (int i = 0; i < 6; ++i) + { + dY = dv * i; + dX = dh * i; + m_dxf.Line(0, dY, -10, dY); //z + m_dxf.Line(dX, 0, dX, -10); //h + str.Format(_T("%d"), 10 + 2 * i); + m_dxf.Text(-80, dY, str); + str.Format(_T("%d"), 2 * i); + m_dxf.Text(dX, -30, str); + } + + //ڵһϵչ + for (int i = 0; i < m_fileOper.OriPoint().size(); ++i) + { + dX = (m_fileOper.OriPoint()[i].X() - 4490) * 1500 / (4570 - 4490); + dY = 1500 + (m_fileOper.OriPoint()[i].Y() - 3350) * 500 / (3410 - 3350); + m_dxf.Point(dX, dY); + } + for (int i = 0; i < 3; ++i) + { + dX = (m_fileOper.KnowPoint()[i].X() - 4490) * 1500 / (4570 - 4490); + dY = 1500 + (m_fileOper.KnowPoint()[i].Y() - 3350) * 500 / (3410 - 3350); + m_dxf.Point(dX, dY); + dY += 20; + m_dxf.Text(dX, dY, m_fileOper.KnowPoint()[i].PointName()); + } + dX = (m_fileOper.KnowPoint()[2].X() - 4490) * 1500 / (4570 - 4490); + dY = 1500 + (m_fileOper.KnowPoint()[2].Y() - 3350) * 500 / (3410 - 3350); + double dX1, dY1; + dX1 = (m_fileOper.KnowPoint()[0].X() - 4490) * 1500 / (4570 - 4490); + dY1 = 1500 + (m_fileOper.KnowPoint()[0].Y() - 3350) * 500 / (3410 - 3350); + m_dxf.Line(dX, dY, dX1, dY1); + + //M + dX = (m_calcH.MHInsertPoint()[5].X() - 4490) * 1500 / (4570 - 4490); + dY = 1500 + (m_calcH.MHInsertPoint()[5].Y() - 3350) * 500 / (3410 - 3350) + 20; + m_dxf.Text(dX, dY, m_calcH.MHInsertPoint()[5].PointName()); + + //N + dX = (m_calcH.NHInsertPoint()[5].X() - 4490) * 1500.0 / (4570 - 4490); + dY = 1500 + (m_calcH.NHInsertPoint()[5].Y() - 3350) * 500.0 / (3410 - 3350) + 20; + m_dxf.Text(dX, dY, m_calcH.NHInsertPoint()[5].PointName()); + + //M + dX = (m_calcH.MHInsertPoint()[10].X() - 4490) * 1500.0 / (4570 - 4490); + dY = 1500 + (m_calcH.MHInsertPoint()[10].Y() - 3350) * 500.0 / (3410 - 3350); + dX1 = (m_calcH.MHInsertPoint()[0].X() - 4490) * 1500.0 / (4570 - 4490); + dY1 = 1500 + (m_calcH.MHInsertPoint()[0].Y() - 3350) * 500.0 / (3410 - 3350); + m_dxf.Line(dX, dY, dX1, dY1); + + //N + dX = (m_calcH.NHInsertPoint()[10].X() - 4490) * 1500.0 / (4570 - 4490); + dY = 1500 + (m_calcH.NHInsertPoint()[10].Y() - 3350) * 500.0 / (3410 - 3350); + dX1 = (m_calcH.NHInsertPoint()[0].X() - 4490) * 1500.0 / (4570 - 4490); + dY1 = 1500 + (m_calcH.NHInsertPoint()[0].Y() - 3350) * 500.0 / (3410 - 3350); + m_dxf.Line(dX, dY, dX1, dY1); + + //ݶ + for (int i = 0; i < m_calcV.VInsertPoint().size() - 1; ++i) + { + dX = i * 1500.0 / 10.0; + dY = 700 + (m_calcV.VInsertPoint()[i].H() - 10) * 500.0 / 10.0; + dX1 = (i + 1) * 1500 / 10.0; + dY1 = 700 + (m_calcV.VInsertPoint()[i + 1].H() - 10) * 500.0 / 10.0; + m_dxf.Point(dX, dY); + m_dxf.Line(dX, dY, dX1, dY1); + } + + //M + for (int i = 0; i < 10; ++i) + { + dX = i * 1500.0 / 10.0; + dY = (m_calcH.MHInsertPoint()[i].H() - 10) * 500.0 / 10.0; + dX1 = (i + 1) * 1500.0 / 10.0; + dY1 = (m_calcH.MHInsertPoint()[i + 1].H() - 10) * 500.0 / 10.0; + m_dxf.Point(dX, dY); + m_dxf.Line(dX, dY, dX1, dY1); + } + + //N + for (int i = 0; i < 10; ++i) + { + dX = i * 1500.0 / 10.0; + dY = (m_calcH.NHInsertPoint()[i].H() - 10) * 500.0 / 10.0; + dX1 = (i + 1) * 1500.0 / 10.0; + dY1 = (m_calcH.NHInsertPoint()[i + 1].H() - 10) * 500.0 / 10.0; + m_dxf.Point(dX, dY); + m_dxf.Line(dX, dY, dX1, dY1); + } + m_dxf.End(); +} + + +void CSectionCalculationDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) +{ + CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); + + // TODO: Add your message handler code here + + + ASSERT(pPopupMenu != NULL); + // Check the enabled state of various menu items. + CCmdUI state; + state.m_pMenu = pPopupMenu; + ASSERT(state.m_pOther == NULL); + ASSERT(state.m_pParentMenu == NULL); + // Determine if menu is popup in top-level menu and set m_pOther to + // it if so (m_pParentMenu == NULL indicates that it is secondary popup). + HMENU hParentMenu; + if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu) + state.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup. + else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL) + { + CWnd* pParent = this; + // Child windows don't have menus--need to go to the top! + if (pParent != NULL && + (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL) + { + int nIndexMax = ::GetMenuItemCount(hParentMenu); + for (int nIndex = 0; nIndex < nIndexMax; nIndex++) + { + if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu) + { + // When popup is found, m_pParentMenu is containing menu. + state.m_pParentMenu = CMenu::FromHandle(hParentMenu); + break; + } + } + } + } + state.m_nIndexMax = pPopupMenu->GetMenuItemCount(); + for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax; + state.m_nIndex++) + { + state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex); + if (state.m_nID == 0) + continue; // Menu separator or invalid cmd - ignore it. + ASSERT(state.m_pOther == NULL); + ASSERT(state.m_pMenu != NULL); + if (state.m_nID == (UINT)-1) + { + // Possibly a popup menu, route to first item of that popup. + state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex); + if (state.m_pSubMenu == NULL || + (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 || + state.m_nID == (UINT)-1) + { + continue; // First item of popup can't be routed to. + } + state.DoUpdate(this, TRUE); // Popups are never auto disabled. + } + else + { + // Normal menu item. + // Auto enable/disable if frame window has m_bAutoMenuEnable + // set and command is _not_ a system command. + state.m_pSubMenu = NULL; + state.DoUpdate(this, FALSE); + } + // Adjust for menu deletions and additions. + UINT nCount = pPopupMenu->GetMenuItemCount(); + if (nCount < state.m_nIndexMax) + { + state.m_nIndex -= (state.m_nIndexMax - nCount); + while (state.m_nIndex < nCount && + pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID) + { + state.m_nIndex++; + } + } + state.m_nIndexMax = nCount; + } +} + + +BOOL CSectionCalculationDlg::OnToolTipNotify(UINT id, NMHDR * pNMHDR, LRESULT * pResult) +{ + TOOLTIPTEXT* pT = (TOOLTIPTEXT*)pNMHDR; //pNMHDRתTOOLTIPTEXTָ + + UINT nID = pNMHDR->idFrom; //ȡϰťID + + if (nID == IDM_OPEN) //nIDϣȡID,ôӦʾϢTOOLTIPTEXTṹlpszTextС + { + pT->lpszText = _T("ļ"); + pT->hinst = AfxGetResourceHandle(); + return(TRUE); + } + if (nID == IDM_VCALC) + { + pT->lpszText = _T("ݶϢ"); + pT->hinst = AfxGetResourceHandle(); + return(TRUE); + } + if (nID == IDM_HCALC) + { + pT->lpszText = _T("ݶϢ"); + pT->hinst = AfxGetResourceHandle(); + return(TRUE); + } + if (nID == IDM_DRAW) + { + pT->lpszText = _T("ͼν"); + pT->hinst = AfxGetResourceHandle(); + return(TRUE); + } + if (nID == IDM_REPORT) + { + pT->lpszText = _T(""); + pT->hinst = AfxGetResourceHandle(); + return(TRUE); + } + return FALSE; +} + +void CSectionCalculationDlg::OnZoomIn() +{ + CZoomView::WheelScale(120); + Invalidate(); +} + + +void CSectionCalculationDlg::OnUpdateZoomIn(CCmdUI *pCmdUI) +{ + if (idd == 1) + pCmdUI->Enable(1); + else + pCmdUI->Enable(0); +} + + +void CSectionCalculationDlg::OnZoomOut() +{ + CZoomView::WheelScale(-120); + Invalidate(); +} + + +void CSectionCalculationDlg::OnUpdateZoomOut(CCmdUI *pCmdUI) +{ + if (idd == 1) + pCmdUI->Enable(1); + else + pCmdUI->Enable(0); +} + + +BOOL CSectionCalculationDlg::ContinueModal() +{ + if (m_toolbar.IsWindowVisible()) // Իй,m_ToolBarΪ + { + CFrameWnd* pParent = (CFrameWnd*)m_toolbar.GetParent(); + if (pParent) + m_toolbar.OnUpdateCmdUI(pParent, (WPARAM)TRUE); + } + + CMenu* pMainMenu = GetMenu(); // Իڲ˵,²˵ + CCmdUI cmdUI; + for (UINT n = 0; n < pMainMenu->GetMenuItemCount(); ++n) + { + CMenu* pSubMenu = pMainMenu->GetSubMenu(n); + cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount(); + for (UINT i = 0; i < cmdUI.m_nIndexMax; ++i) + { + cmdUI.m_nIndex = i; + cmdUI.m_nID = pSubMenu->GetMenuItemID(i); + cmdUI.m_pMenu = pSubMenu; + cmdUI.DoUpdate(this, FALSE); + } + } + return CDialog::ContinueModal(); +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculationDlg.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculationDlg.h new file mode 100644 index 0000000..306c5e5 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/SectionCalculationDlg.h @@ -0,0 +1,80 @@ + +// SectionCalculationDlg.h : ͷļ +// + +#pragma once +#include "afxcmn.h" +#include "ListDlg.h" +#include "DrawDlg.h" +#include "ReportDlg.h" +#include "HorizonSectionCalc.h" +#include "VerticalSectionCalc.h" +#include "DxfFile.h" + +// CSectionCalculationDlg Ի +class CSectionCalculationDlg : public CDialogEx +{ +// +public: + CSectionCalculationDlg(CWnd* pParent = NULL); // ׼캯 + +// Ի +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_SECTIONCALCULATION_DIALOG }; +#endif + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧ + + +// ʵ +protected: + HICON m_hIcon; + + // ɵϢӳ亯 + virtual BOOL OnInitDialog(); + afx_msg void OnSysCommand(UINT nID, LPARAM lParam); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult); + afx_msg void OnOpen(); + afx_msg void OnTxt(); + afx_msg void OnDxf(); + afx_msg void OnVcalc(); + afx_msg void OnHcalc(); + afx_msg void OnList(); + afx_msg void OnDraw(); + afx_msg void OnReport(); + afx_msg void OnUpdateTxt(CCmdUI *pCmdUI); + afx_msg void OnUpdateDxf(CCmdUI *pCmdUI); + afx_msg void OnUpdateVcalc(CCmdUI *pCmdUI); + afx_msg void OnUpdateHcalc(CCmdUI *pCmdUI); + afx_msg void OnUpdateDraw(CCmdUI *pCmdUI); + afx_msg void OnUpdateReport(CCmdUI *pCmdUI); + afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu); + afx_msg BOOL OnToolTipNotify(UINT id, NMHDR * pNMHDR, LRESULT * pResult); + afx_msg void OnZoomIn(); + afx_msg void OnUpdateZoomIn(CCmdUI *pCmdUI); + afx_msg void OnZoomOut(); + afx_msg void OnUpdateZoomOut(CCmdUI *pCmdUI); + virtual BOOL ContinueModal(); + +private: + void DrawDxf(); +public: + CTabCtrl m_tab; + CToolBar m_toolbar; + CListDlg m_listDlg; + CDrawDlg m_drawDlg; + CReportDlg m_reportDlg; + + CFileOperation m_fileOper; + CHorizonSectionCalc m_calcH; + CVerticalSectionCalc m_calcV; + CDxfFile m_dxf; + +private: + int ia, ib, ic, idd, ie; // +}; diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/VerticalSectionCalc.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/VerticalSectionCalc.cpp new file mode 100644 index 0000000..441eeca --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/VerticalSectionCalc.cpp @@ -0,0 +1,119 @@ +#include "stdafx.h" +#include "VerticalSectionCalc.h" + + +CVerticalSectionCalc::CVerticalSectionCalc() +{ + detta = 10; + a1 = 0; + a2 = 0; //λ + m_vTotalLength = 0; //ݶȫ + m_vTotalLength1 = 0; //ݶĵһεij + m_vCount1 = 0; //ݶһβֵĸ + m_vCount = 0; //ݶֵĸټ.3֪ܸ + m_vTotalArea = 0; //ݶ +} + + +CVerticalSectionCalc::~CVerticalSectionCalc() +{ +} + +void CVerticalSectionCalc::CalcVerticalSection(CFileOperation fileOper) +{ + m_fileOper = fileOper; + m_pOripoint.clear(); + m_pOripoint = m_fileOper.OriPoint(); + m_pKnowpoint.clear(); + m_pKnowpoint = m_fileOper.KnowPoint(); + + m_pVInsertPoint.clear(); + + a1 = m_fileOper.m_basicCalc.Azimuth(m_pKnowpoint[0].X(), m_pKnowpoint[0].Y(), m_pKnowpoint[1].X(), m_pKnowpoint[1].Y()); + a2 = m_fileOper.m_basicCalc.Azimuth(m_pKnowpoint[1].X(), m_pKnowpoint[1].Y(), m_pKnowpoint[2].X(), m_pKnowpoint[2].Y()); + m_vTotalLength1 = m_fileOper.m_basicCalc.Distance(m_pKnowpoint[0].X(), m_pKnowpoint[0].Y(), m_pKnowpoint[1].X(), m_pKnowpoint[1].Y()); + m_vTotalLength = m_vTotalLength1 + m_fileOper.m_basicCalc.Distance(m_pKnowpoint[1].X(), m_pKnowpoint[1].Y(), m_pKnowpoint[2].X(), m_pKnowpoint[2].Y()); + m_vCount1 = (int)(m_vTotalLength1 / detta); + m_vCount = (int)(m_vTotalLength / detta) + 3; // ֪ + + CalcInsertPointPosition(); + CalcHeight(); + CalcArea(); + AfxMessageBox(_T("ݶ ɣ")); + + WriteData(m_fileOper.s_verticalSectionContent); +} + +void CVerticalSectionCalc::CalcInsertPointPosition() +{ + m_pVInsertPoint.push_back(CPointInfo(m_pKnowpoint[0].PointName(), m_pKnowpoint[0].X(), m_pKnowpoint[0].Y(), m_pKnowpoint[0].H())); + double dX, dY, dK; + CString str; + for (int i = 0; i < m_vCount1; ++i) + { + str.Format(_T("V-%d"), i + 1); + dX = m_pKnowpoint[0].X() + detta * (i + 1) * cos(a1); + dY = m_pKnowpoint[0].Y() + detta * (i + 1) * sin(a1); + dK = (i + 1) * detta; + m_pVInsertPoint.push_back(CPointInfo(str, dX, dY, 0, dK)); + } + m_pVInsertPoint.push_back(CPointInfo(m_pKnowpoint[1].PointName(), m_pKnowpoint[1].X(), m_pKnowpoint[1].Y(), m_pKnowpoint[1].H(), m_vTotalLength1)); + + double dis = m_fileOper.m_basicCalc.Distance(m_pVInsertPoint[m_vCount1].X(), m_pVInsertPoint[m_vCount1].Y(), m_pKnowpoint[1].X(), m_pKnowpoint[1].Y()); + for (int i = m_vCount1; i < m_vCount - 3; ++i) + { + str.Format(_T("V-%d"), i + 1); + dX = m_pKnowpoint[1].X() + (detta - dis + detta * (i - m_vCount1)) * cos(a2); + dY = m_pKnowpoint[1].Y() + (detta - dis + detta * (i - m_vCount1)) * sin(a2); + dK = (i + 1) * detta; + m_pVInsertPoint.push_back(CPointInfo(str, dX, dY, 0, dK)); + } + m_pVInsertPoint.push_back(CPointInfo(m_pKnowpoint[2].PointName(), m_pKnowpoint[2].X(), m_pKnowpoint[2].Y(), m_pKnowpoint[2].H(), m_vTotalLength)); +} + +void CVerticalSectionCalc::CalcHeight() +{ + m_fileOper.m_basicCalc.CalcHeight(m_pOripoint, m_pVInsertPoint); + m_pVInsertPoint[0].SetH(m_pKnowpoint[0].H()); + m_pVInsertPoint[m_vCount1 + 1].SetH(m_pKnowpoint[1].H()); + m_pVInsertPoint[m_vCount - 1].SetH(m_pKnowpoint[2].H()); +} + +void CVerticalSectionCalc::CalcArea() +{ + m_vTotalArea = 0; + double H0 = m_fileOper.H0(); + for (int i = 0; i < m_pVInsertPoint.size() - 1; ++i) + { + m_vTotalArea += (m_pVInsertPoint[i].H() + m_pVInsertPoint[i + 1].H() - 2.0 * H0) + / 2.0 * m_fileOper.m_basicCalc.Distance(m_pVInsertPoint[i].X(), m_pVInsertPoint[i].Y(), m_pVInsertPoint[i + 1].X(), m_pVInsertPoint[i + 1].Y()); + } +} + +void CVerticalSectionCalc::WriteData(CString &content) +{ + content = _T(""); + setlocale(LC_ALL, ""); + CString str; + content += _T("ݶϢ\r\n"); + content += _T("------------------------------------------------------------------------------------\r\n"); + if (m_pVInsertPoint.size() > 0) + { + str.Format(_T("ݶ:%.3lf\r\n"), m_vTotalArea); + content += str; + str.Format(_T("ݶȫ:%.3lf\r\n"), m_vTotalLength); + content += str; + content += _T("·\r\n"); + content += _T("\tK(m) X(m)\tY(m)\tH(m)\r\n"); + for (int i = 0; i < m_pVInsertPoint.size(); ++i) + { + str.Format(_T("%s\t%.3lf\t%.3lf\t%.3lf\t%.3lf\r\n"), m_pVInsertPoint[i].PointName(), m_pVInsertPoint[i].K(), m_pVInsertPoint[i].X(), m_pVInsertPoint[i].Y(), m_pVInsertPoint[i].H()); + content += str; + } + } +} + +std::vector CVerticalSectionCalc::VInsertPoint() const +{ + return m_pVInsertPoint; +} diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/VerticalSectionCalc.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/VerticalSectionCalc.h new file mode 100644 index 0000000..76e8071 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/VerticalSectionCalc.h @@ -0,0 +1,56 @@ +/****************************************************************************** + +Ȩ (C), 2018-2020, + +****************************************************************************** + : VerticalSectionCalc.h + : + : + : 20181026 +޸ : + : ݶļ㡣K0 K1K2ǵ·ϵ3ؼ㣬3㹹ݶ档 +б : +* +* + +޸ʷ : +1. : 20181026 + : +޸ : ļ + +******************************************************************************/ +#pragma once +#include "FileOperation.h" + +class CVerticalSectionCalc +{ +public: + CVerticalSectionCalc(); + ~CVerticalSectionCalc(); + + void CalcVerticalSection(CFileOperation fileOper); //ݶϢ +private: + void CalcInsertPointPosition(); //ݶϢ + void CalcHeight(); //߳ + void CalcArea(); // + void WriteData(CString &content); + +public: + std::vector VInsertPoint() const; + +private: + std::vector m_pVInsertPoint; //ݶIJֵ + CFileOperation m_fileOper; + std::vector m_pOripoint; + std::vector m_pKnowpoint; + +private: + double detta; //ֵļ + double a1, a2; //λ + double m_vTotalLength; //ݶȫ + double m_vTotalLength1; //ݶĵһεij + int m_vCount1; //ݶһβֵĸ + int m_vCount; //ݶֵĸټ.3֪ܸ + double m_vTotalArea; //ݶ +}; + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ZoomView.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ZoomView.cpp new file mode 100644 index 0000000..1d1bf7c --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ZoomView.cpp @@ -0,0 +1,319 @@ +#include "stdafx.h" +#include "ZoomView.h" + +std::vector CZoomView::m_tempOriPoint; +std::vector CZoomView::m_tempKnowPoint; +std::vector CZoomView::m_tempVInsertPoint; +std::vector CZoomView::m_tempMInsertPoint; +std::vector CZoomView::m_tempNInsertPoint; + +CCoorPoint CZoomView::m_dataCenterPoint; +CCoorPoint CZoomView::m_screenCenterPoint; +CCoorPoint CZoomView::m_mousePosition; +double CZoomView::m_dataHeight = 1; +double CZoomView::m_dataWidth = 1; +double CZoomView::m_dataScale = 1; +double CZoomView::m_scrollScale = 1; + +CCoorPoint::CCoorPoint() +{ + m_x = 0; + m_y = 0; + m_h = 0; + m_name = _T(""); +} + +CCoorPoint::~CCoorPoint() +{ +} + +void CCoorPoint::Move(double x, double y) +{ + m_x += x; + m_y += y; +} + +void CCoorPoint::SetPoint(double x, double y) +{ + m_x = x; + m_y = y; +} + + +CZoomView::CZoomView() +{ +} + + +CZoomView::~CZoomView() +{ +} + +void CZoomView::SetData(std::vector data) +{ + double minX, minY, maxX, maxY; + minX = data[0].m_x; + minY = data[0].m_y; + maxX = data[0].m_x; + maxY = data[0].m_y; + + for (int i = 0; i < data.size(); ++i) + { + if (minX > data[i].m_x) + minX = data[i].m_x; + if (minY > data[i].m_y) + minY = data[i].m_y; + if (maxX < data[i].m_x) + maxX = data[i].m_x; + if (maxY < data[i].m_y) + maxY = data[i].m_y; + } + m_dataWidth = maxX - minX; + m_dataHeight = maxY - minY; + m_dataCenterPoint.SetPoint((minX + maxX) / 2.0, (minY + maxY) / 2.0); +} + +void CZoomView::SetScreenPoint(double height, double width) +{ + m_screenCenterPoint.SetPoint(height / 2.0, width / 2.0); + double x_scale, y_scale; + x_scale = m_dataWidth / width; + y_scale = m_dataHeight / height; + if (x_scale > y_scale) + m_dataScale = x_scale; + else + m_dataScale = y_scale; + m_dataScale *= 100; +} + +void CZoomView::WheelScale(int zDelta) +{ + m_scrollScale *= (1.0 - 0.2 * zDelta / 120.0); +} + +void CZoomView::CoorMove(int x, int y, int nflags) +{ + double deltaX, deltaY; + if (nflags == 1) + { + deltaX = m_mousePosition.m_x - x; + deltaY = y - m_mousePosition.m_y; + m_dataCenterPoint.Move(deltaX * m_scrollScale * m_dataScale, deltaY * m_scrollScale * m_dataScale); + } + m_mousePosition.SetPoint(x, y); +} + +double CZoomView::SetX(double x) +{ + double dx = (x - m_dataCenterPoint.m_x) / (m_scrollScale * m_dataScale) + m_screenCenterPoint.m_x; + return dx; +} + +double CZoomView::SetY(double y) +{ + double dy = (m_dataCenterPoint.m_y - y) / (m_scrollScale * m_dataScale) + m_screenCenterPoint.m_y; + return dy; +} + +void CZoomView::Draw(CDC & dc) +{ + DrawFirstChart(dc); + DrawSection(dc, m_tempVInsertPoint, 0); + DrawSection(dc, m_tempMInsertPoint, 50); + DrawSection(dc, m_tempNInsertPoint, 50); +} + +void CZoomView::SetPoint(std::vector& m_tempOriPoint, std::vector data) +{ + m_tempOriPoint.clear(); + CCoorPoint temp; + for (int i = 0; i < data.size(); ++i) + { + temp.m_name = data[i].PointName(); + temp.m_x = data[i].X(); + temp.m_y = data[i].Y(); + temp.m_h = data[i].H(); + m_tempOriPoint.push_back(temp); + } +} + +void CZoomView::DrawFirstChart(CDC &dc) +{ + // + double x1, y1, x2, y2; + x1 = SetX(4490); + y1 = SetY(3350) * 0.5; + dc.MoveTo(x1, y1); + x2 = SetX(4580); + y2 = SetY(3420) * 0.5; + dc.LineTo(x1, y2); + dc.MoveTo(x1, y1); + dc.LineTo(x2, y1); + //̶ + for (int i = 0; i < 5; ++i) + { + x1 = SetX(i * 20 + 4490); + y2 = y1 + 5; + dc.MoveTo(x1, y1); + dc.LineTo(x1, y2); + } + for (int i = 0; i < 4; ++i) + { + x1 = SetX(4490); + x2 = x1 - 5; + y1 = SetY(3350 + i * 20) * 0.5; + dc.MoveTo(x1, y1); + dc.LineTo(x2, y1); + } + //չ + CBrush brush; + brush.CreateSolidBrush(RGB(0, 0, 0)); + dc.SelectObject(&brush); + for (int i = 0; i < m_tempOriPoint.size(); ++i) + { + x1 = SetX(m_tempOriPoint[i].m_x); + y1 = SetY(m_tempOriPoint[i].m_y) * 0.5; + dc.Ellipse(x1 - 3, y1 - 3, x1 + 3, y1 + 3); + } + for (int i = 0; i < m_tempKnowPoint.size(); ++i) + { + x1 = SetX(m_tempKnowPoint[i].m_x); + y1 = SetY(m_tempKnowPoint[i].m_y) * 0.5; + dc.Rectangle(x1 - 5, y1 - 5, x1 + 5, y1 + 5); + } + x1 = SetX(m_tempMInsertPoint[5].m_x); + y1 = SetY(m_tempMInsertPoint[5].m_y) * 0.5; + dc.Rectangle(x1 - 5, y1 - 5, x1 + 5, y1 + 5); + x1 = SetX(m_tempNInsertPoint[5].m_x); + y1 = SetY(m_tempNInsertPoint[5].m_y) * 0.5; + dc.Rectangle(x1 - 5, y1 - 5, x1 + 5, y1 + 5); + // + CPen pen; + dc.SelectObject(&pen); + for (int i = 0; i < m_tempKnowPoint.size() - 1; ++i) + { + x1 = SetX(m_tempKnowPoint[i].m_x); + y1 = SetY(m_tempKnowPoint[i].m_y) * 0.5; + x2 = SetX(m_tempKnowPoint[i + 1].m_x); + y2 = SetY(m_tempKnowPoint[i + 1].m_y) * 0.5; + dc.MoveTo(x1, y1); + dc.LineTo(x2, y2); + } + x1 = SetX(m_tempMInsertPoint[0].m_x); + y1 = SetY(m_tempMInsertPoint[0].m_y) * 0.5; + x2 = SetX(m_tempMInsertPoint[10].m_x); + y2 = SetY(m_tempMInsertPoint[10].m_y) * 0.5; + dc.MoveTo(x1, y1); + dc.LineTo(x2, y2); + x1 = SetX(m_tempNInsertPoint[0].m_x); + y1 = SetY(m_tempNInsertPoint[0].m_y) * 0.5; + x2 = SetX(m_tempNInsertPoint[10].m_x); + y2 = SetY(m_tempNInsertPoint[10].m_y) * 0.5; + dc.MoveTo(x1, y1); + dc.LineTo(x2, y2); + + //д̶ȣд + CFont font; + font.CreatePointFont(70, _T("")); + dc.SelectObject(&font); + for (int i = 0; i < m_tempKnowPoint.size(); ++i) + { + x1 = SetX(m_tempKnowPoint[i].m_x); + y1 = SetY(m_tempKnowPoint[i].m_y) * 0.5; + dc.TextOut(x1, y1 - 15, m_tempKnowPoint[i].m_name); + } + x1 = SetX(m_tempMInsertPoint[5].m_x); + y1 = SetY(m_tempMInsertPoint[5].m_y) * 0.5; + dc.TextOut(x1, y1 - 15, m_tempMInsertPoint[5].m_name); + x1 = SetX(m_tempNInsertPoint[5].m_x); + y1 = SetY(m_tempNInsertPoint[5].m_y) * 0.5; + dc.TextOut(x1, y1 - 15, m_tempNInsertPoint[5].m_name); + CString str; + for (int i = 0; i < 5; ++i) + { + x1 = SetX(i * 20 + 4490); + y1 = SetY(3350) * 0.5; + str.Format(_T("%d"), 4490 + i * 20); + dc.TextOut(x1, y1 + 15, str); + } + for (int i = 0; i < 4; ++i) + { + x1 = SetX(4490); + y1 = SetY(3350 + i * 20) * 0.5; + str.Format(_T("%d"), 3350 + i * 20); + dc.TextOut(x1 - 30, y1, str); + } + x1 = SetX(4530); + y1 = SetY(3415) * 0.5; + str.Format(_T("·ͼ")); + dc.TextOut(x1, y1, str); + + y1 = SetY(3330) * 0.5; + str.Format(_T("ݶʾͼ")); + dc.TextOut(x1, y1, str); + + y1 = SetY(3280) * 0.5; + str.Format(_T("ʾͼ")); + dc.TextOut(x1, y1, str); +} + +void CZoomView::DrawSection(CDC &dc, std::vector pt, double delta) +{ + // + double x1, y1, x2, y2; + x1 = SetX(4490); + y1 = SetY(3300 - delta) * 0.5; + dc.MoveTo(x1, y1); + x2 = SetX(4580); + y2 = SetY(3330 - delta) * 0.5; + dc.LineTo(x1, y2); + dc.MoveTo(x1, y1); + dc.LineTo(x2, y1); + //̶ + for (int i = 0; i < 5; ++i) + { + x1 = SetX(i * 20 + 4490); + y2 = y1 + 5; + dc.MoveTo(x1, y1); + dc.LineTo(x1, y2); + } + for (int i = 0; i < 6; ++i) + { + x1 = SetX(4490); + x2 = x1 - 5; + y1 = SetY(3300 - delta + i * 6) * 0.5; + dc.MoveTo(x1, y1); + dc.LineTo(x2, y1); + } + double d; + for (int i = 0; i < pt.size() - 1; ++i) + { + d = (4570.0 - 4490.0) / 10.0; + x1 = SetX(i * d + 4490); + y1 = SetY((pt[i].m_h - 10.0) * 3 + 3300 - delta) * 0.5; + x2 = SetX((i + 1) * d + 4490); + y2 = SetY((pt[i + 1].m_h - 10.0) * 3 + 3300 - delta) * 0.5; + dc.MoveTo(x1, y1); + dc.LineTo(x2, y2); + } + //д̶ + CFont font; + font.CreatePointFont(70, _T("")); + dc.SelectObject(&font); + CString str; + for (int i = 0; i < 5; ++i) + { + x1 = SetX(i * 20 + 4490); + y1 = SetY(3300 - delta) * 0.5; + str.Format(_T("%d"), i * 2); + dc.TextOut(x1, y1 + 8, str); + } + for (int i = 0; i < 6; ++i) + { + x1 = SetX(4490); + y1 = SetY(3300 - delta + i * 6) * 0.5; + str.Format(_T("%d"), 10 + i * 2); + dc.TextOut(x1 - 15, y1, str); + } +} + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ZoomView.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ZoomView.h new file mode 100644 index 0000000..4f153fd --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/ZoomView.h @@ -0,0 +1,75 @@ +/****************************************************************************** + +Ȩ (C), 2018-2020, + +****************************************************************************** + : ZoomView.h + : + : + : 20181026 +޸ : + : ʵͼķŴСȹ +б : +* +* + +޸ʷ : +1. : 20181026 + : +޸ : ļ + +******************************************************************************/ +#pragma once +#include "HorizonSectionCalc.h" +#include "VerticalSectionCalc.h" +#include + +class CCoorPoint +{ +public: + CCoorPoint(); + ~CCoorPoint(); +public: + void Move(double x, double y); //ƶ + void SetPoint(double x, double y); //õֵ + double m_x, m_y, m_h; + CString m_name; +}; + +class CZoomView +{ +public: + CZoomView(); + ~CZoomView(); +public: + static void SetData(std::vector data); //ȡĻϵķֲ + static void SetScreenPoint(double height, double width); //Ļ + static void WheelScale(int zDelta); //ű + static void CoorMove(int x, int y, int nflags); //λƶ + static double SetX(double x); //õڵǰµX + static double SetY(double y); //õڵǰµY + + static void Draw(CDC &dc); + static void SetPoint(std::vector &m_tempOriPoint, std::vector data); + +private: + static void DrawFirstChart(CDC &dc); + static void DrawSection(CDC &dc, std::vector pt, double delta); + +public: + static std::vector m_tempOriPoint; + static std::vector m_tempKnowPoint; + static std::vector m_tempVInsertPoint; + static std::vector m_tempMInsertPoint; + static std::vector m_tempNInsertPoint; + + static CCoorPoint m_dataCenterPoint; + static CCoorPoint m_screenCenterPoint; + static CCoorPoint m_mousePosition; + + static double m_dataHeight; + static double m_dataWidth; + static double m_dataScale; + static double m_scrollScale; +}; + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/SectionCalculation.ico b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/SectionCalculation.ico new file mode 100644 index 0000000..d56fbcd Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/SectionCalculation.ico differ diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/SectionCalculation.rc2 b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/SectionCalculation.rc2 new file mode 100644 index 0000000..68f1002 Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/SectionCalculation.rc2 differ diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/icon1.ico b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/icon1.ico new file mode 100644 index 0000000..481add2 Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/icon1.ico differ diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/toolbar1.bmp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/toolbar1.bmp new file mode 100644 index 0000000..0ba7fa2 Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/res/toolbar1.bmp differ diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/resource.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/resource.h new file mode 100644 index 0000000..31feea6 Binary files /dev/null and b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/resource.h differ diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/stdafx.cpp b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/stdafx.cpp new file mode 100644 index 0000000..cb7cb65 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : ֻ׼ļԴļ +// SectionCalculation.pch ΪԤͷ +// stdafx.obj ԤϢ + +#include "stdafx.h" + + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/stdafx.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/stdafx.h new file mode 100644 index 0000000..a2e5acf --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/stdafx.h @@ -0,0 +1,54 @@ + +// stdafx.h : ׼ϵͳļİļ +// Ǿʹõĵ +// ضĿİļ + +#pragma once + +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN // Windows ͷųʹõ +#endif + +#include "targetver.h" + +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // ijЩ CString 캯ʽ + +// ر MFC ijЩɷĺԵľϢ +#define _AFX_ALL_WARNINGS + +#include // MFC ͱ׼ +#include // MFC չ + + +#include // MFC Զ + + + +#ifndef _AFX_NO_OLE_SUPPORT +#include // MFC Internet Explorer 4 ؼ֧ +#endif +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC Windows ؼ֧ +#endif // _AFX_NO_AFXCMN_SUPPORT + +#include // Ϳؼ MFC ֧ + + + + + + + + + +#ifdef _UNICODE +#if defined _M_IX86 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_X64 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif +#endif + + diff --git a/Modify_Part3-ch09/SectionCalculation/SectionCalculation/targetver.h b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/targetver.h new file mode 100644 index 0000000..9518d24 --- /dev/null +++ b/Modify_Part3-ch09/SectionCalculation/SectionCalculation/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// SDKDDKVer.h õ߰汾 Windows ƽ̨ + +// ҪΪǰ Windows ƽ̨Ӧó WinSDKVer.h +// _WIN32_WINNT ΪҪֵ֧ƽ̨Ȼٰ SDKDDKVer.h + +#include diff --git "a/Modify_Part3-ch09/\346\226\255\351\235\242\346\225\260\346\215\256.txt" "b/Modify_Part3-ch09/\346\226\255\351\235\242\346\225\260\346\215\256.txt" new file mode 100644 index 0000000..463aa6a --- /dev/null +++ "b/Modify_Part3-ch09/\346\226\255\351\235\242\346\225\260\346\215\256.txt" @@ -0,0 +1,47 @@ +H0,10.000 +K0,K1,K2 + +K0,4574.012 ,3358.300 ,12.922 +P01,4570.355 ,3382.210 ,10.558 +P02,4571.827 ,3372.090 ,10.619 +P03,4570.907 ,3362.574 ,10.771 +P04,4569.494 ,3355.660 ,14.233 +P05,4556.682 ,3361.789 ,16.660 +P06,4547.554 ,3364.421 ,17.352 +P07,4534.086 ,3370.041 ,17.158 +P08,4517.549 ,3376.080 ,17.345 +P09,4505.572 ,3383.182 ,15.637 +P10,4498.562 ,3390.196 ,13.033 +P11,4494.457 ,3390.748 ,10.963 +P12,4500.501 ,3391.959 ,13.085 +P13,4510.753 ,3382.485 ,14.083 +P14,4522.092 ,3378.296 ,14.356 +P15,4531.567 ,3373.371 ,15.047 +P16,4546.386 ,3367.159 ,15.794 +P17,4556.219 ,3362.776 ,16.082 +P18,4559.558 ,3362.461 ,15.678 +P19,4554.746 ,3366.571 ,17.609 +P20,4545.254 ,3372.596 ,19.024 +P21,4540.860 ,3376.395 ,19.223 +P22,4536.141 ,3378.766 ,19.502 +K1,4534.227 ,3380.195 ,19.925 +P23,4525.945 ,3383.019 ,18.152 +P24,4519.592 ,3385.587 ,18.060 +P25,4513.249 ,3391.514 ,18.302 +P26,4523.724 ,3389.414 ,18.811 +P27,4537.846 ,3387.734 ,18.239 +P28,4540.773 ,3379.044 ,18.344 +P29,4549.894 ,3382.932 ,16.482 +P30,4543.390 ,3387.292 ,16.594 +P31,4546.992 ,3381.416 ,16.637 +P32,4558.964 ,3370.594 ,16.666 +P33,4565.741 ,3367.802 ,13.835 +P34,4561.203 ,3375.941 ,13.732 +P35,4561.762 ,3385.330 ,13.068 +P36,4569.250 ,3376.133 ,12.032 +P37,4572.318 ,3372.975 ,10.908 +P38,4568.279 ,3386.945 ,11.014 +P39,4550.913 ,3394.728 ,10.462 +P40,4537.754 ,3400.079 ,10.427 +P41,4509.525 ,3411.290 ,10.478 +K2,4497.844 ,3403.422 ,10.836