Soft work twinning project work

Soft work twinning project work

project content
This work belongs courses Spring 2020 Computer Software Engineering Institute (Roger Ren Jian)
Where this requirement in the job Twinning project work
Teaching classes 006
project address https://github.com/Knowden/IntersectionPlus

A, PSP

PSP2.1 Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan
· Estimate • Estimate how much time this task requires 10 10
Development Develop
· Analysis · Needs analysis (including learning new technologies) 180 300
· Design Spec Generate design documents 5 5
· Design Review · Design Review (and his colleagues reviewed the design documents) 10 10
· Coding Standard · Code specifications (development of appropriate norms for the current development) 10 10
· Design · Specific design 120 120
· Coding · Specific coding 240 300
· Code Review · Code Review 60 60
· Test · Test (self-test, modify the code, submit modifications) 60 60
Reporting report
· Test Report · testing report 120 180
· Size Measurement · Computing workload 10 10
· Postmortem & Process Improvement Plan · Hindsight, and propose process improvement plan 10 10
- total 835 1075

Second, information hiding, and loosely coupled interface design

  • Information Hiding

Refers to information hiding in the design and determination module, such that the specific information (data or process) contained within a module, other modules do not need this information, it is inaccessible. We designed the external calculation module provides the results, not the process of calculation of exposure data and calculation process which produced.

  • Interface Design

Our interface to play focused primarily on delivering functional information. That information is input by the UI module via the interface module passes the calculated and then displayed graphically by the UI module through the interface to read the result of the calculation module calculates. UI module only needs to know the data type information transmission, you do not need to know any other information.

  • Loosely coupled

And there is no logical connection between the graphical display and computation logic, only simple transmission of information between the two modules. However, the data type information is set dead, that module must implement the respective type of data received

Third, the calculation of the design and implementation of the interface module

Compared to the previous implementations, the computing module only adds an interface class for front-end calls for

Compared to the previous content, this adds segments and rays, its essence is to do around the boundary line limited, so we use the extension of the original Linemethods of the class to support this extended.

The extension of the Lineclass adds properties around the border

  • Straight line : left and right boundaries are infinite (use INT_MAX representation)
  • Line : left and right boundaries are determined value
  • Ray : single boundary value is determined, the other is infinite boundary

Thus, the original core calculation method can still work, only the calculated specific Pointjudge to its intersection coordinates, i.e., all straight lines are calculated, and then use its own boundaries to filter the results

Furthermore, the addition of exception handling functions

This is partly using c++own exception mechanism to achieve.

We first analyze the meaning of the title for a series of possible abnormal situation, then each code segment abnormalities were possible exception is thrown, and we throw an exception which will be set up in the back-end exception information , so just catch the exception that the front end, and then echoed to the user where the abnormality information to

As for the input process, we use a C++11regular expression to handle, according to the requirements of the subject, we specify a set of regular expressions, for each input graphics are done checking, when the check fails will use the same cast abnormality processing manner

Four, UML diagram

Fifth, the performance improvement calculation module interface section

To achieve than the last, this time to do some floating-point processing optimization

Before adopting a long doubledirect hashand ==operations, not only hashtime consuming, but also there is a problem of accuracy, in order to solve the problems in these areas, the floating-point processing has been optimized

The first data range given subject, we estimate the accuracy of the data generally simply floatcan, we first used floatinstead long doublefor hashthe operation

While this can accelerate the hashspeed of operation, accuracy but the problem still is not resolved, there will be 0.999999999and 1.000000000problems, so in order to solve this problem, we used $ \ epsilon $ is calculated.

I.e., before adding a minimum value for each high-precision floating-point number, and then truncated to float, such as the above mentioned problem is solved.

Through a series of processing above, not only hashtime-consuming calculations to solve the problem, but also solve the accuracy problem, do both.

The above analysis results of the performance of the detector VS

On a personal project, the count_line_with_linemain point in time-consuming compareand hashon, but now in the case of the calculation function content no major changes, get_intersection_withand comparewith hashthe time-consuming essentially flat, revenue shows that brought this optimization is still very large .

Sixth, contract programming

Design by Contract is in accordance with certain provisions of the agreement to make some data, if you exceed the agreed program will no longer run, such as input parameters requirements must be met certain conditions. Such strict requirements of the input and output of programming can be a good program interface specification. Thereby facilitating efficient means to achieve high test coverage to ensure program correctness.

The problem with this approach is that programming requires a lot of energy and time to implement and validate the provisions of the contract and the contract, it is difficult to achieve large coverage in time-critical projects.

Our job in this contract is mainly used in the design module interface, inbound and outbound data type has agreed to ensure the accuracy of the information transfer between modules.

Seven display calculation module of the unit test

For some functions and exception handling of this new project, we also tested the first phase of the project to do a lot complement and extend

The above is not the only test class is a class main is located, because for the corresponding test in the UI and exe, too, because the input of the input file related to unit test would be more influenced by the environment, so there did not carry out the relevant test.

	/*
	两个线段,他们可能只有一个端点相交
	*/
	TEST_METHOD(TestTwoSegmentIntersecInEnd) {
		Line line1("S 0 0 1 1");
		Line line2("S 0 0 1 -1");

		std::vector<Point> result = line1.get_intersection_with(line2);
		Assert::AreEqual(1, (int)result.size());
	}

	/*
	两线段共线,且有一个公共交点(端点)
	*/
	TEST_METHOD(TestTwoSegmentInSameLineHaveOneIntersection) {
		Line line1("S 0 0 1 1");
		Line line2("S 1 1 2 2");

		std::vector<Point> result = line1.get_intersection_with(line2);
		Assert::AreEqual(1, (int)result.size());
	}

	/*
	两线段共线,且无交点
	*/
	TEST_METHOD(TestTwoSegmentInSameLineHaveNoIntersection) {
		Line line1("S 0 0 1 1");
		Line line2("S 2 2 3 3");

		std::vector<Point> result = line1.get_intersection_with(line2);
		Assert::AreEqual(0, (int)result.size());
	}

The above is part of the test code, you can see that we have a more comprehensive test for some marginal cases, covering every combination of circumstances, at the same time, in order to facilitate bug fixes when an error occurs, we have more important tests were interpreted comments to facilitate post-maintenance.

Eight, the calculation module portion exception handling instructions

The exception handling we mainly consider the following categories

  • Parameter format is not correct (wrong characters, multiple spaces)
  • Radius r <= 0
  • Coordinate overrun
  • Input points coincide
  • There are an infinite number of intersection (graphics overlap)

For these types of anomalies above, we will be packaged in an appropriate error message exception thrown, so do significant UI back

	/*
	圆半径异常
	*/
	TEST_METHOD(IllegalCircleRedix1) {
		auto func = [] {
			Solution s;
			s.add_component("C 0 0 0");
		};

		Assert::ExpectException<std::exception>(func);
	}
	/*
	非法字符输入(小写字母,特殊符号)
	*/
	TEST_METHOD(IllegalCharacterInput1) {
		auto func = [] {
			Solution s;
			s.add_component("l 0 0 1 1");
		};

		Assert::ExpectException<std::exception>(func);
	}
	/*
	输入点重合
	*/
	TEST_METHOD(PointCollision1) {
		auto func = [] {
			Solution s;
			s.add_component("L 0 0 0 0");
		};

		Assert::ExpectException<std::exception>(func);
	}
	/*
	两线段共线,且有多个交点(部分重合),期望抛出异常
	*/
	TEST_METHOD(TestTwoSegmentCoverPart) {
		auto func = [] {
			Line line1("S 0 0 3 3");
			Line line2("S 1 1 5 5");
			line1.get_intersection_with(line2);
		};

		Assert::ExpectException<std::exception>(func);
	}
	/*
	各种坐标超限
	*/
	TEST_METHOD(ArgumentOutOfBound1) {
		auto func = [] {
			Solution s;
			s.add_component("C 100001 0 1");
		};

		Assert::ExpectException<std::exception>(func);
	}

Nine, interface module detailed design process

The UI design using VS comes with MFC, MFC have to say it is a bit old, a lot of things and hard to use and not easy to use, learning cost is very high but the price is relatively low.

The general idea is to UI design the read data directly to the calculation module, and the data plotted functions required intersection is read out from the computing module.

  • Importing data from a file

Import data related to click function is present in the IMPORT button

void CUIDlg::OnBnClickedImport()
{
	// TODO: 在此添加控件通知处理程序代码
	m_strHistoryPath = "";//文件选择清空
	CFileDialog dlg(TRUE, _T("txt"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("文本文件|*.txt||"));
	if (dlg.DoModal() == IDOK)
	{
		m_strHistoryPath = dlg.GetPathName();
		if (m_strHistoryPath == "")
		{
			MessageBox(_T("未选择文件!"));
			return;
		}
	}
	else		//取消文件导入
	{
		return;
	}
	CStdioFile file;
	CString szLine;
	int i = 0;
	file.Open(m_strHistoryPath, CFile::modeRead);
    //处理文本第一行
	file.ReadString(szLine);
    //处理文本输入数据
	while (file.ReadString(szLine))
	{
		std::string str(CW2A(szLine.GetString()));
        //向计算模块中传递数据并捕获输入相关的异常
		try {
			core.add_component(str);
		}
		catch(std::exception e){
			CString cstr;
			std::string str;
			str = e.what();
			cstr = CA2W(str.c_str());
			MessageBox(cstr);
		}
	}
	//关闭文件
	file.Close();
    //更新图形列表
	getList(m_list);
}

In addition abnormality occurs when a file is imported, select a file such documents related anomalies identified by the UI module and the input malformed input such anomaly is identified by the calculation module, the UI module captures treatment of these anomalies. UI module imported data will be passed on by the computing module to the calculation module finishes processing without treatment.

  • Manually add data

Data input by the user click the Add button in the ADD function is implemented

void CUIDlg::OnBnClickedAdd()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(true);
	std::string str(CW2A(m_input.GetString()));
    //向计算模块中传递数据并捕获输入相关的异常
	try {
		core.add_component(str);
	}
	catch (std::exception e) {
		CString cstr;
		std::string str;
		str = e.what();
		cstr = CA2W(str.c_str());
		MessageBox(cstr);
	}
    //更新图形列表
	m_list.DeleteAllItems();
	line_count = 0;
	getList(m_list);
}
  • Maintain a list of graphics

In the UI module, the action pattern is a list of all the information used in rendering the graphics, and provides the selected object is deleted deleted implementing functions. That is, after clicking graphics functions in the list, press the Delete button to delete realization of graphics.

Maintains a list of graphical implementation choices by the click function list by getList()updating the list of functions to achieve

void CUIDlg::OnNMClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;

	NMLISTVIEW* pNMListView = (NMLISTVIEW*)pNMHDR;
	if (pNMListView->iItem != -1)        // 如果iItem不是-1,就说明有列表项被选择
	{
		m_selected = m_list.GetItemText(pNMListView->iItem, 0);
		m_id = m_list.GetItemText(pNMListView->iItem, 1);
        //将选中的图形信息更新到选中的图形文本框中
		UpdateData(false);
	}
}
void CUIDlg::getList(CListCtrl &m_list)
{
	std::vector<Line>::iterator line_iter;
	std::vector<Circle>::iterator circle_iter;
	line_list = core.get_all_line();
	circle_list = core.get_all_circle();
    //处理直线类型的数据的信息
	for (line_iter = line_list.begin(); line_iter != line_list.end(); line_iter++) 
	{
		std::string str;
		if (line_iter->k == INT_MAX)
		{
			str = "x=" + std::to_string(line_iter->b);
		}
		else if (line_iter->k == 0)
		{
			str = "y=" + std::to_string(line_iter->b);
		}
		else
		{
			str = "y=" + std::to_string(line_iter->k) + "x+" + std::to_string(line_iter->b);
		}
		CString id;
		id.Format(_T("L%d"), line_iter->id);
		m_list.InsertItem(line_count, CA2W(str.c_str()));
		m_list.SetItemText(line_count++, 1, id);
	}
    //处理圆的数据的信息
	for (circle_iter = circle_list.begin(); circle_iter != circle_list.end(); circle_iter++)
	{
		std::string str;
		str = "(x-" + std::to_string(circle_iter->center->x) + ")^2 + (y-" 
			  + std::to_string(circle_iter->center->y) + ")^2 = " + std::to_string(circle_iter->r);
		CString id;
		id.Format(_T("C%d"), circle_iter->id);
		m_list.InsertItem(line_count, CA2W(str.c_str()));
		m_list.SetItemText(line_count++, 1, id);
	}
}
  • Delete function

Click Delete function is implemented in the function DELETE button, delete the object selected by the user in the list of graphics.

void CUIDlg::OnBnClickedDelete()
{
	// TODO: 在此添加控件通知处理程序代码
	CString t;
	CString id;
	int id_int;
	t = m_id.Left(1);
	id = m_id.Right(1);
	if (t == _T("L"))
	{
		id_int = _ttoi(id);
		core.delete_line_component(id_int);
	}
	else if (t == _T("C"))
	{
		id_int = _ttoi(id);
		core.delete_circle_component(id_int);
	}
	else return;
    //更新图形列表
	m_list.DeleteAllItems();
	line_count = 0;
	getList(m_list);
}
  • Draw function

Draw the button is pressed, a list of all the graphical UI module pattern will be drawn on the drawing board. Draw function is implemented in the button's click function PAINT

void CUIDlg::OnBnClickedPaint()
{
	std::vector<Line>::iterator line_iter;
	std::vector<Circle>::iterator circle_iter;
	//获取画板信息
	CRect rect;
	CWnd* pWin = GetDlgItem(IDC_DRAW);
	pWin->GetClientRect(rect);
	CDC* pDc = pWin->GetDC();
	pDc->Rectangle(rect);
	CBrush myBrush;
	CBrush blueBrush;
	CPen blackPen;
	CPen redPen;
	CPen bluePen;
	myBrush.CreateSolidBrush(RGB(192, 250, 233));
	blueBrush.CreateSolidBrush(RGB(0, 0, 255));
	blackPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
	redPen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
	bluePen.CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
	//将画板重置
	pDc->FillRect(rect, &myBrush);
	//绘制坐标轴
	pDc->SelectObject(&blackPen);
	pDc->MoveTo(rect.left, rect.bottom / 2);
	pDc->LineTo(rect.right, rect.bottom / 2);
	pDc->MoveTo(rect.right, rect.bottom / 2);
	pDc->LineTo(rect.right - 20, rect.bottom / 2 + 10);
	pDc->MoveTo(rect.right, rect.bottom / 2);
	pDc->LineTo(rect.right - 20, rect.bottom / 2 - 10);
	pDc->MoveTo(rect.right / 2, rect.bottom);
	pDc->LineTo(rect.right / 2, rect.top);
	pDc->MoveTo(rect.right / 2, rect.top);
	pDc->LineTo(rect.right / 2 + 10, rect.top + 20);
	pDc->MoveTo(rect.right / 2, rect.top);
	pDc->LineTo(rect.right / 2 - 10, rect.top + 20);
	int R_MAX = rect.right / 2/ ratio;
	//将原点设为坐标轴心
	pDc->SetViewportOrg(rect.right / 2, rect.bottom / 2);
	// TODO: 在此添加控件通知处理程序代码
	line_list = core.get_all_line();
	//画线类型的图形
	pDc->SelectObject(&redPen);
	for (line_iter = line_list.begin(); line_iter != line_list.end(); line_iter++)
	{
		float k = line_iter->k;
		float b = line_iter->b;
		float left_limit = line_iter->leftLimit < -10000 ? -10000 : line_iter->leftLimit;
		float right_limit = line_iter->rightLimit > 10000 ? 10000 : line_iter->rightLimit;
		if (k == INT_MAX)
		{
			if (b > R_MAX)b = 10000;
			pDc->MoveTo(b*ratio, -(int)left_limit*ratio);
			pDc->LineTo(b*ratio, -(int)right_limit*ratio);
		}
		else
		{
			if (right_limit > R_MAX) right_limit = R_MAX;
			pDc->MoveTo((int)left_limit*ratio, -(int)calY(left_limit, k, b)*ratio);
			pDc->LineTo((int)right_limit*ratio, -(int)calY(right_limit, k, b)*ratio);
		}
	}
	//画圆的图形
	for (circle_iter = circle_list.begin(); circle_iter != circle_list.end(); circle_iter++)
	{
		float x = circle_iter->center->x*ratio;
		float y = circle_iter->center->y*ratio;
		float r = circle_iter->r*ratio;
		CPoint pLeftUp((int)(x - r), (int)(-y - r));
		CPoint pRightDown((int)(x + r), (int)(-y + r));
		if (pLeftUp.x > R_MAX*ratio) continue;
		CRect circle(pLeftUp.x, pLeftUp.y, pRightDown.x, pRightDown.y);
		pDc->SelectStockObject(NULL_BRUSH);
		pDc->Ellipse(&circle);
	}

	std::unordered_set<Point> points;
	std::unordered_set<Point>::iterator point_iter;
	try {
		points = core.get_all_intersection(true);
	}
	catch (std::exception e) {
		CString cstr;
		std::string str;
		str = e.what();
		cstr = CA2W(str.c_str());
		MessageBox(cstr);
	}
    //画交点
	pDc->SelectObject(&bluePen);	//蓝笔标点,点实际是一个实心方块
	for (point_iter = points.begin(); point_iter != points.end(); point_iter++)
	{
		float x = point_iter->x * ratio;
		float y = point_iter->y * ratio;
		if (x > R_MAX*ratio) continue;
		CRect point(x - ratio/4, -y - ratio/4, x + ratio/4, -y + ratio/4);
		pDc->FillRect(point, &blueBrush);
	}
    //在交点个数文本框中更新交点的个数
	m_result = points.size();
	UpdateData(false);
}

Because MFC does not provide any easy way to draw coordinate system, and therefore this method will start to draw the axes (similar to the principle and draw a straight line). On the other hand, it does not provide the MFC drawing method and straight rays, rays, and thus to achieve a predetermined straight line using the right and left sections achieved (i.e., draw a line beyond the drawing board) to a fixed value method. For pattern beyond the drawing board, the method of detecting coordinates and beyond the truncated portion of its drawing board.

For the display of the intersection, the user is able to clearly see the intersection of location, we use a certain solid side length of the blue square to represent.

Since the calculation of the coordinates do not support MFC decimal (i.e. MFC smallest integer drawing units), so we use the coordinate calculation module given a certain coordinate transformation method which the UI module in the middle-scaled drawing to reduce errors.

X. docking module and the computing module interface

class _declspec(dllexport) core {
private:
	Solution s;

public:
	void add_component(std::string component);
    void delete_line_component(int id);
	void delete_circle_component(int id);
    
	std::unordered_set<Point> get_all_intersection(bool force);
	std::vector<Line> get_all_line();
	std::vector<Circle> get_all_circle();
};
  • input interface

UI module add_component(std::string component)transmitting user input data to the computing module

UI module delete_line_component(int id)impart linear type of graphic to be deleted to the calculation module id

UI module delete_circle_component(int id)transfer type id circle pattern to be deleted to the computing module

  • Output Interface

UI module through std::unordered_set<Point> get_all_intersection(bool force)information received from the computing module intersection

UI module std::vector<Line> get_all_line()receives information from the line style pattern calculation module

UI module through std::vector<Circle> get_all_circle()information received from the circular type pattern calculation module

XI describe the process of twinning

The pair programming using the VS live share QQ and screen sharing. live share very powerful, we can achieve two people together to modify the code, but often Caton, and invitees can not freely access the file, there will be a lot of inconvenience on the exchange.

QQ-definition screen sharing features, while low but relatively smooth, easy to exchange. However, limited functionality, naturally can not do common editing code.

XII pair programming advantages and disadvantages

  • Pair programming advantages

You can do a man a man to write code review, correct rate of output code, reliability

The ability to be able to do complementary, pair both sides play to their strengths

During the school can tie knot on each other's strengths, gain experience

  • Junction disadvantage of programming

When the difference between the two styles is large there will be friction, but lower efficiency

Some people prefer a person programming, but programming with more than distracting

If the two levels will be quite different circumstances a person who has been writing a look, 1 + 1 <2

  • My Strengths

Better learning ability, quick start tool can not come into contact with

Logical, structured analysis can be performed

Strong communication skills, be able to adapt to a very good teammate, and his teammates running

  • My weakness

Weak programming, code style a little feces

The ability to independently solve problems of the poor, often can not quickly solve the bug

  • Partner benefits

Strong programming skills, can quickly write beautiful code

Emphasis on testing, testing to do very detailed

Good communication, we are often able to discuss some issues with voice

  • Partner shortcomings

Details not in place

Thirteen, loosely coupled modules

Since the other group did not discuss in advance with a good interface, so the need for adaptability in the UI module after the exchange dll change more.

  • Switching Module Changes
class GeometryFactory{
public:
	GeometryFactory();
	/* Modification */
	int addLine(int type, long long x1, long long x2, long long y1, long long y2);		// 添加直线,传入四个参数,其中type详见constant.h, 返回值为id,会抛出各种异常
	int addCircle(long long x, long long y, long long r);							    // 添加圆, 返回值为id,会抛出各种异常
	void remove(int id);										                        // 删除几何对象,传入参数为id
	/* Query */
	Line getLine(int id);										                        // 获取已经添加的直线,传入参数为id
	Circle getCircle(int id);									                        // 获取已添加的原,传入参数为id
	vector<Point> getPoints();									                        // 获取所有的交点
	int getPointsCount();										                        // 获取交点总数
	int addObjectFromFile(string & message);							                // 解析文件内的一行输入,如“L 0 0 1 1”或“C 0 0 3”,会抛出各种异常
};

This is the other side of the interface. You can see, we have the main difference between the two groups:

  • Storage line

Our group uses oblique point storage methods, i.e., k and b are represented by straight lines; and the other groups using the general linear formula way to store, i.e. the use of a, b, c to represent a straight line. This difference affects the graphic drawing method and display method of a function of the UI module in the list

  • Graphic data acquisition methods

We can group all of the graphic data directly, while the other group need to pass in order to spread graphics id corresponding graphic data, which affects the graphics update the list.

  • Graphic data storage method

We set the circles and straight lines are divided into two categories, unique id to determine a unique pattern in each of the major categories. While the other group although the circles and straight lines are divided into two categories, but id did not classify unique id to determine a unique pattern in all graphics

In summary, the UI module changes mainly in getList()function and drawing functions

Changing the getList()function:

void CUIDlg::getList(CListCtrl &m_list)
{
	std::map<int, string>::iterator id_iter;
	std::vector<Line>::iterator line_iter;
	std::vector<Circle>::iterator circle_iter;
	for (id_iter = id_list.begin(); id_iter != id_list.end(); id_iter++)
	{
		if (id_iter->second == "L")
		{
			Line line;
			line = core.getLine(id_iter->first);
			line_list.push_back(line);
			std::string str;
			if (line_iter->b == 0)
			{
				str = std::to_string(line_iter->a) + "x+" + std::to_string(line_iter->c) + " = 0";
			}
			else if (line_iter->a == 0)
			{
				str = std::to_string(line_iter->b) + "y+" + std::to_string(line_iter->c) + " = 0";
			}
			else
			{
				str = std::to_string(line_iter->a) + "x+" + std::to_string(line_iter->b) + "y+" + std::to_string(line_iter->c) + " = 0";
			}
			CString id;
			id.Format(_T("%d"), id_iter->first);
			m_list.InsertItem(line_count, CA2W(str.c_str()));
			m_list.SetItemText(line_count++, 1, id);
		}
		else
		{
			Circle circle;

			CString id;
			id.Format(_T("%d"), id_iter->first);
			MessageBox(id);

			circle = core.getCircle(id_iter->first);
			circle_list.push_back(circle);
			std::string str;
			str = "(x-" + std::to_string(circle_iter->a) + ")^2 + (y-"
				+ std::to_string(circle_iter->b) + ")^2 = " + std::to_string(circle_iter->r);
			//CString id;
			id.Format(_T("%d"), id_iter->first);
			m_list.InsertItem(line_count, CA2W(str.c_str()));
			m_list.SetItemText(line_count++, 1, id);
		}
	}
}

Because regardless of category id, so UI part is a map<int, string>container to store the id, the id value for the Key, value for the category (linear or circular) corresponding graphic id belongs, in order to each other by the dll Line getLine(int id)and Circle getCircle(int id) read graphic data.

The main function is to change the drawing method for drawing a straight line, i.e. the point oblique to the general formula, it is therefore not described herein. Also delete and add methods have done little to change the main purpose is to meet each other dll's id storage.

  • Problems arise exchange module

Since we set UI module for reading data is processed without any direct throw computing module, so after exchanging dll our UI module can not use the other modules int addLine(int type, long long x1, long long x2, long long y1, long long y2)and int addCircle(long long x, long long y, long long r)interfaces can only be used int addObjectFromFile(string & message)for input processing. But the other side of this interface seems there are certain problems, not correctly handling strings, as shown also reported the correct string format error exception, and therefore can not achieve the correct intersection of computing and drawing functions

Tested int addLine(int type, long long x1, long long x2, long long y1, long long y2)and int addCircle(long long x, long long y, long long r)interfaces is no problem, so we added a string handling interface UI to fit these two interfaces, in order to solve this problem.

Increased following string input handler

void CUIDlg::addStr(std::string str)
{
	vector<string> strs = testSplit11(str, " ");
	int id;
	if (strs.at(0) == "L")
	{
		id = core.addLine(1, atoi(strs.at(1).c_str()), atoi(strs.at(3).c_str()), atoi(strs.at(2).c_str()), atoi(strs.at(4).c_str()));
		id_list.insert(pair<int, string>(id, "L"));
	}
	else if (strs.at(0) == "R")
	{
		id = core.addLine(2, atoi(strs.at(1).c_str()), atoi(strs.at(3).c_str()), atoi(strs.at(2).c_str()), atoi(strs.at(4).c_str()));
		id_list.insert(pair<int, string>(id, "L"));
	}
	else if (strs.at(0) == "S")
	{
		id = core.addLine(3, atoi(strs.at(1).c_str()), atoi(strs.at(3).c_str()), atoi(strs.at(2).c_str()), atoi(strs.at(4).c_str()));
		id_list.insert(pair<int, string>(id, "L"));
	}
	else if (strs.at(0) == "C")
	{
		id = core.addCircle(atoi(strs.at(1).c_str()), atoi(strs.at(2).c_str()), atoi(strs.at(3).c_str()));
		id_list.insert(pair<int, string>(id, "C"));
	}
}
vector<string> CUIDlg::testSplit11(const string& in, const string& delim)
{
	vector<string> ret;
	regex re{delim};
	return vector<string>{
		sregex_token_iterator(in.begin(), in.end(), re, -1),
			sregex_token_iterator()
	};
	return ret;
}

After the increase in display graphics and a list of additions and deletions can be run properly

Guess you like

Origin www.cnblogs.com/huangxianhao/p/12556734.html