|
|
|
|
|
// <copyright file="CalculateZDialog.cs" company="PlaceholderCompany">
|
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace KepGridEditor
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class CalculateZDialog : Form
|
|
|
|
|
|
{
|
|
|
|
|
|
private ToolTip tip;
|
|
|
|
|
|
private TextBox focusedTexbox = null; //现在或最近一次拥有焦点的输入框
|
|
|
|
|
|
private Dictionary<string, string> descriptionMap = new Dictionary<string, string>();
|
|
|
|
|
|
public CalculateZDialog()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
focusedTexbox = zExpressionTextBox;
|
|
|
|
|
|
|
|
|
|
|
|
InitDescriptionMap();
|
|
|
|
|
|
tip = new ToolTip();
|
|
|
|
|
|
tip.AutomaticDelay = 3000;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int GetOperationObjectKind()
|
|
|
|
|
|
{
|
|
|
|
|
|
return operationObjectComboBox.SelectedIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String GetXExpression()
|
|
|
|
|
|
{
|
|
|
|
|
|
return xExpressionTextBox.Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String GetYExpression()
|
|
|
|
|
|
{
|
|
|
|
|
|
return yExpressionTextBox.Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String GetZExpression()
|
|
|
|
|
|
{
|
|
|
|
|
|
return zExpressionTextBox.Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetLExpression()
|
|
|
|
|
|
{
|
|
|
|
|
|
return lExpressionTextBox.Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CalculateZDialog_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
operationObjectComboBox.SelectedIndex = 0;
|
|
|
|
|
|
functionCategoryComboBox.SelectedIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
//这里先清除函数列表 因为程序在调用此函数之前 先调用了
|
|
|
|
|
|
//functionListBox_SelectedIndexChanged函数
|
|
|
|
|
|
//导致重复添加列表项
|
|
|
|
|
|
//所以 在添加前 先清除列表项
|
|
|
|
|
|
functionListBox.Items.Clear();
|
|
|
|
|
|
variationListBox.Items.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
AddOperatorToFunctionCategoryComboBox();
|
|
|
|
|
|
AddFunctionToFunctionCategoryComboxBox();
|
|
|
|
|
|
AddLogicalOperationToFunctionCategoryComboxBox();
|
|
|
|
|
|
FillVariationListBox();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CalculateZDialog_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.KeyCode != Keys.Escape)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InitDescriptionMap()
|
|
|
|
|
|
{
|
|
|
|
|
|
//descriptionMap.Add()
|
|
|
|
|
|
descriptionMap.Add("+", "加号运算符");
|
|
|
|
|
|
descriptionMap.Add("-", "减号运算符");
|
|
|
|
|
|
descriptionMap.Add("*", "乘号运算符");
|
|
|
|
|
|
descriptionMap.Add("/", "除号运算符");
|
|
|
|
|
|
descriptionMap.Add("()","括号运算符");
|
|
|
|
|
|
descriptionMap.Add("^", "幂运算符"); //x^y(x的y次方)
|
|
|
|
|
|
descriptionMap.Add("%", "取余运算符");
|
|
|
|
|
|
|
|
|
|
|
|
descriptionMap.Add("sin()", "sin(表达式)");
|
|
|
|
|
|
descriptionMap.Add("cos()", "cos(表达式)");
|
|
|
|
|
|
descriptionMap.Add("tan()", "tan(表达式)");
|
|
|
|
|
|
descriptionMap.Add("sqrt()", "sqrt(表达式)");
|
|
|
|
|
|
descriptionMap.Add("exp()", "exp(表达式)");
|
|
|
|
|
|
descriptionMap.Add("log()", "log(表达式)");
|
|
|
|
|
|
descriptionMap.Add("asin()", "asin(表达式)");
|
|
|
|
|
|
descriptionMap.Add("acos()", "acos(表达式)");
|
|
|
|
|
|
descriptionMap.Add("atan()", "atan(表达式)");
|
|
|
|
|
|
descriptionMap.Add("abs()", "abs(表达式)");
|
|
|
|
|
|
|
|
|
|
|
|
descriptionMap.Add("<", "x<y(x小于y时返回1,x大于或等于y时返回0)");
|
|
|
|
|
|
descriptionMap.Add(">", "x>y(x大于y时返回1,x小于或等于y时返回0)");
|
|
|
|
|
|
descriptionMap.Add("!", "!x(将x值取非运算,当x为非零值时返回0,x为零时返回1)");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AddOperatorToFunctionCategoryComboBox()
|
|
|
|
|
|
{
|
|
|
|
|
|
functionListBox.Items.Add("+");
|
|
|
|
|
|
functionListBox.Items.Add("-");
|
|
|
|
|
|
functionListBox.Items.Add("*");
|
|
|
|
|
|
functionListBox.Items.Add("/");
|
|
|
|
|
|
functionListBox.Items.Add("()");
|
|
|
|
|
|
functionListBox.Items.Add("^");
|
|
|
|
|
|
functionListBox.Items.Add("%");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AddFunctionToFunctionCategoryComboxBox()
|
|
|
|
|
|
{
|
|
|
|
|
|
functionListBox.Items.Add("sin()");
|
|
|
|
|
|
functionListBox.Items.Add("cos()");
|
|
|
|
|
|
functionListBox.Items.Add("tan()");
|
|
|
|
|
|
functionListBox.Items.Add("sqrt()");
|
|
|
|
|
|
functionListBox.Items.Add("exp()");
|
|
|
|
|
|
functionListBox.Items.Add("log()");
|
|
|
|
|
|
functionListBox.Items.Add("asin()");
|
|
|
|
|
|
functionListBox.Items.Add("acos()");
|
|
|
|
|
|
functionListBox.Items.Add("atan()");
|
|
|
|
|
|
functionListBox.Items.Add("abs()");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AddLogicalOperationToFunctionCategoryComboxBox()
|
|
|
|
|
|
{
|
|
|
|
|
|
functionListBox.Items.Add("<");
|
|
|
|
|
|
functionListBox.Items.Add(">");
|
|
|
|
|
|
functionListBox.Items.Add("!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void FillVariationListBox()
|
|
|
|
|
|
{
|
|
|
|
|
|
//variationListBox.Items.Add("l");
|
|
|
|
|
|
//variationListBox.Items.Add("Pl");
|
|
|
|
|
|
//variationListBox.Items.Add("x");
|
|
|
|
|
|
//variationListBox.Items.Add("y");
|
|
|
|
|
|
variationListBox.Items.Add("z");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void variationListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(variationListBox.SelectedItem == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
string varStr = variationListBox.SelectedItem.ToString();
|
|
|
|
|
|
focusedTexbox.Paste(varStr);
|
|
|
|
|
|
focusedTexbox.Focus();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void functionListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
string functionStr = functionListBox.SelectedItem.ToString();
|
|
|
|
|
|
focusedTexbox.Paste(functionStr);
|
|
|
|
|
|
|
|
|
|
|
|
if (functionStr.Contains("()")) //如果是有括号的表达式 将插入点设置在括号里
|
|
|
|
|
|
{
|
|
|
|
|
|
focusedTexbox.SelectionStart -= 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
focusedTexbox.Focus();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void xExpressionTextBox_Enter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//focusedTexbox = xExpressionTextBox;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void yExpressionTextBox_Enter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//focusedTexbox = yExpressionTextBox;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void zExpressionTextBox_Enter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
focusedTexbox = zExpressionTextBox;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void lExpressionTextBox_Enter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//focusedTexbox = lExpressionTextBox;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void functionListBox_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
focusedTexbox.Focus();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void variationListBox_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
focusedTexbox.Focus();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void functionCategoryComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = functionCategoryComboBox.SelectedIndex;
|
|
|
|
|
|
if (index < 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
functionListBox.Items.Clear();
|
|
|
|
|
|
if (index == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddOperatorToFunctionCategoryComboBox();
|
|
|
|
|
|
AddFunctionToFunctionCategoryComboxBox();
|
|
|
|
|
|
AddLogicalOperationToFunctionCategoryComboxBox();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (index == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddOperatorToFunctionCategoryComboBox();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (index == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddFunctionToFunctionCategoryComboxBox();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (index == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddLogicalOperationToFunctionCategoryComboxBox();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void functionListBox_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
int idx = functionListBox.IndexFromPoint(e.Location);// 获取鼠标所在的项索引
|
|
|
|
|
|
if (idx == -1 || idx >= functionListBox.Items.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string txt = functionListBox.GetItemText(functionListBox.Items[idx]);
|
|
|
|
|
|
if (!descriptionMap.ContainsKey(txt))
|
|
|
|
|
|
return; ;
|
|
|
|
|
|
string helpInfoStr = descriptionMap[txt];
|
|
|
|
|
|
|
|
|
|
|
|
if (tip.GetToolTip(functionListBox) == helpInfoStr)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tip.SetToolTip(functionListBox, helpInfoStr);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|