displaydlg.cpp

来自「winsail v2.0是用于DOS下的图形界面空间系统」· C++ 代码 · 共 1,590 行 · 第 1/3 页

CPP
1,590
字号
// DisplayDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Display.h"
#include "DisplayDlg.h"
#include <math.h>

#include <conio.h>


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDisplayDlg dialog

CDisplayDlg::CDisplayDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDisplayDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDisplayDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDisplayDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDisplayDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDisplayDlg, CDialog)
	//{{AFX_MSG_MAP(CDisplayDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDisplayDlg message handlers

BOOL CDisplayDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDisplayDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CDisplayDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDisplayDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

#define MAX_TEST_ITEM_COUNT            128
#define MAX2_TEST_ITEM_COUNT           128
#define TEST_ITEM_COUNT                 48
#define  MAX_ARMATURE_SUPPORT_COUNT     40



typedef struct _tagENVIRONMENTALEX
{
	//ARMATURE_TEST
	char  strModelName[24];
	char  strFile[24];

	int   nBar;
	DWORD dwStyle;
	int   nMachineDot;

	DWORD dwCodePoint;
	DWORD dwCodeStart;
	DWORD dwCodeEnd;

	float fHipotVol;
	float fHipotTime;
	float fHipotCur[3][2];
	float fInsulationVol;
	float fInsulationRes;

	float fsResistance[MAX_ARMATURE_SUPPORT_COUNT][2];
	float fWeldRes;
	float fSurgePercent;

	float fSurgeVol;
	int   nSurgeInternal;
	float fSurgeSampleFreq;

	int   nResistanceRange;
	int   nInsulation;

	BOOL  bsHipot[3];
	BOOL  bInsulation;
	BOOL  bBar;
	BOOL  bWeld;
	BOOL  bSurge;

	BOOL  bsSurge[MAX_ARMATURE_SUPPORT_COUNT];

	//STATOR
	float fStartupCapacitance;
	BOOL  bThreePhase;
	BOOL  bTStyle;
	BOOL  bThreeStyle;

	//VBTION_710

	float fsAmp[2];
	float fsStartAmp[2];
	float fsVol[2];
	float fsSpeed[2];
	float fsVbtionA[2];
	float fsVbtionV[2];
	float fsVbtionS[2];
	float fsFilter[2];
	float fRunningTime;
	int   nDivide;
	int   nFreqResolution;

	BOOL bAutoRange;
	int  nAmpRange;
	int  nStartAmpRange;
	BOOL  bsMask[TEST_ITEM_COUNT];

	//NORMAL
	float fsTest[TEST_ITEM_COUNT][2];
	BOOL  bsTest[TEST_ITEM_COUNT];
}ENVIRONMENTALEX;


#define MAX_TREE_DEGREE 30



#define TRAVERSING_BINARYTREE_FIRST  0 
#define TRAVERSING_BINARYTREE_MIDDLE 1 
#define TRAVERSING_BINARYTREE_LAST   2 

struct CTreeNode
{
	//指向用户信息
	void* pUser;
	//父结点
	CTreeNode* pParent;

	union
	{
		//二叉种结构
		struct
		{
			//若wFlagL = 0, pChildL表左孩子
			//若wFlagL = 1, pChildL表前驱
			WORD wFlagL; 

			//左结点
			CTreeNode* pChildL;

			//若wFlagR = 0, pChildL表右孩子
			//若wFlagR = 1, pChildL表后续
			WORD wFlagR;

			//右结点
			CTreeNode* pChildR;
		}BinaryTree;

		//树结构
		struct
		{
			//若wFlagL = 0, pChild表第一个孩子
			//若wFlagL = 1, pChild表前驱
			WORD wFlagL; 

			//第一个孩子
			CTreeNode* pChild;

			//若wFlagR = 0, pSibling表兄弟
			//若wFlagR = 1, pSibling表后续
			WORD wFlagR; 

			//兄弟
			CTreeNode* pSibling;
		}Tree;
	}Node;
};

//递归的结构体
struct BINARYTREE_RECURSION//recursion
{
	DWORD dwP0; //返回语句标号
	CTreeNode* pTreeNode; //结点指针
};

class CTree
{
protected:
	//度
	int m_nDegree;
	//最大度
	int m_nMaxDegree;
	//列指针
	int* m_pnCol;
	//根结点
	CTreeNode* m_pRoot;
	//遍历类型
	int m_nVisitStyle;
	//遍历参数
	void* m_pVisitUser;
	//析离参数	
	void* m_pMoveUser;
	//删除参数
	void* m_pDeleteUser;
	//遍历筛选函数
	CTreeNode* (*m_pVisitFc)(CTree*, CTreeNode*, void*, int, int);
	//析离结点操作
	CTreeNode* (*m_pMoveFc)(CTreeNode*, void*);
	//删除函数
	CTreeNode* (*m_pDeleteFc)(CTreeNode*, void*);

public:
	//树初始化
	void InitiateTree();
	//树清空
	BOOL ClearTree();
	//求树的根结点
	CTreeNode* GetRoot();
	//求结点所在树的根结点
	static CTreeNode* GetRoot(CTreeNode *pTreeNode);
	//求双亲
	CTreeNode* GetParent(CTreeNode *pTreeNode);
	//求孩子
	CTreeNode* GetChild(CTreeNode* pTreeNode, DWORD dwIndex);
	//求右兄弟
	CTreeNode* GetRightSibling(CTreeNode* pTreeNode, DWORD dwIndex);
	//求第一个兄弟
	CTreeNode* GetRightSibling_First(CTreeNode* pTreeNode)
	{
		return(this->GetRightSibling(pTreeNode, 0));
	}
	//求最后一个兄弟
	CTreeNode* GetRightSibling_Last(CTreeNode* pTreeNode)
	{
		return(this->GetRightSibling(pTreeNode, 0xFFFFFFFFlu));
	}

	//建立一棵以指定结点为根的树
	CTree* BuildTree(CTreeNode* pTreeNode);
	//插入子树
	BOOL InsertChild(CTreeNode* pTarget, DWORD dwIndex, CTreeNode* pSource);
	//删除子树
	BOOL DeleteChild(CTreeNode* pTreeNode, DWORD dwIndex);
	//删除指定结点为根结点的树
	BOOL DeleteChild(CTreeNode* pTreeNode);
	//遍历操作
	BOOL TraverseTree(CTreeNode* pTreeNode, int nStyle, void* pUser);

public:
	//设置遍历类型
	void SetVisitStyle(int nStyle) {m_nVisitStyle = nStyle;}
	//设置遍历函数
	void SetVisitFc(CTreeNode* (*pFc)(CTree*, CTreeNode*, void*, int, int)) {m_pVisitFc = pFc;}
	//设置遍历参数
	void SetVisitUser(void* pUser) {m_pVisitUser = pUser;}

	//设置析离函数
	void SetMoveFc(CTreeNode* (*pFc)(CTreeNode*, void*)) {m_pMoveFc = pFc;}
	//设置析离参数
	void SetMoveUser(void* pUser) {m_pMoveUser = pUser;}

	//设置删除函数
	void SetDeleteFc(CTreeNode* (*pFc)(CTreeNode*, void*)) {m_pDeleteFc = pFc;}
	//设置删除参数
	void SetDeleteUser(void* pUser) {m_pDeleteUser = pUser;}
public:
	int GetDegree(){return(m_nDegree);}
	int GetMaxDegree(){return(m_nMaxDegree);}	
protected:
	//计算度用的访问函数
	static CTreeNode* CalcDegreeFc(CTree* pTree, CTreeNode* pTreeNode, 
		void* pUser, int nDegree, int nCol);
	//访问结点操作
	CTreeNode* VisitTree(CTreeNode* pTreeNode, void* pUser, int nCol);
	//析离结点操作
	CTreeNode* MoveTree(CTreeNode* pTreeNode, void* pUser);
	//删除结点操作
	CTreeNode* DeleteTree(CTreeNode* pTreeNode, void* pUser);

	//初始化成员变量
	void CoTree();
public:
	//构造函数
	CTree();
	//析构函数
	~CTree();
};


class CBinaryTree:public CTree
{	
public:
	//求左边孩子
	CTreeNode* GetChildL(CTreeNode* pTreeNode) 
	{
		return (pTreeNode->Node.BinaryTree.pChildL);
	}
	//求右边孩子
	CTreeNode* GetChildR(CTreeNode* pTreeNode)
	{
		return (pTreeNode->Node.BinaryTree.pChildR);
	}
	//求左兄弟
	CTreeNode* GetSiblingL(CTreeNode* pTreeNode);
	//求右兄弟
	CTreeNode* GetSiblingR(CTreeNode* pTreeNode);
	//建立一棵以指定结点为根的树
	BOOL BuildBinaryTree(CTreeNode* pRoot,
		CTreeNode* pChildL, CTreeNode* pChildR);
	//插入左子树
	BOOL InsertChildL(CTreeNode* pNode, CTreeNode* pChildL);
	//插入右子树
	BOOL InsertChildR(CTreeNode* pNode, CTreeNode* pChildR);
	//删除左子树
	BOOL DeleteChildL(CTreeNode* pNode);
	//删除右子树
	BOOL DeleteChildR(CTreeNode* pNode);
	//遍历树操作
	CTreeNode* TraverseBinaryTree(
		CTreeNode* (*pFc)(CTree* pTree, CTreeNode*, void*, int, int), void* pUser, int nStyle);
	//二叉种的线索化
	BOOL Thread();
public:
	int CalcMaxDegree();
	static void CBinaryTree::CalcCoordinate(RECT* pRc, int nMaxDegree, int nDegree,
		int nCol, int* pnLeft, int* pnTop);
private:
	//指定结点作为根的遍历树操作
	CTreeNode* TraverseBinaryTree(CTreeNode* pTreeNode);
};


//函数功能:初始化成员变量
void CTree::CoTree()
{
	//度
	m_nDegree = 1;
	//树的度数
	m_nMaxDegree = 1;	
	//列
	m_pnCol = NULL;
	//根结点
	m_pRoot = NULL;
	//遍历类型
	m_nVisitStyle = TRAVERSING_BINARYTREE_MIDDLE;
	//遍历参数
	m_pVisitUser = NULL;
	//析离参数	
	m_pMoveUser = NULL;
	//删除参数
	m_pDeleteUser = NULL;
	//遍历筛选函数
	m_pVisitFc = NULL;
	//析离结点操作
	m_pMoveFc = NULL;
	//删除函数
	m_pDeleteFc = NULL;
}

//函数功能:构造函数
CTree::CTree()
{
	//初始化成员变量
	this->CoTree();

	//初始化树
	this->InitiateTree();
}

//函数功能:析构函数
CTree::~CTree()
{
	this->ClearTree();
}

//函数功能:初始化树
void CTree::InitiateTree()
{
	this->ClearTree();

	//初始化成员变量
	this->CoTree();

}

//函数功能:清除树
BOOL CTree::ClearTree()
{
	m_pRoot = NULL;

	if (m_pnCol != NULL)
	{
		delete m_pnCol;
		m_pnCol = NULL;
	}
	return (TRUE);
}

//函数功能:求树的根结点
CTreeNode* CTree::GetRoot()  
{

⌨️ 快捷键说明

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