You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/UCDraw/KepGridEditor/ExpressionZDialog.cs

182 lines
6.6 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// <copyright file="ExpressionZDialog.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 ExpressionZDialog : Form
{
private Dictionary<string, string> descriptionMap = new Dictionary<string, string>();
public ExpressionZDialog()
{
InitializeComponent();
InitDescriptionMap();
}
public string GetExpression()
{
return expresstionTextBox.Text;
}
private void InitDescriptionMap()
{
//descriptionMap.Add()
descriptionMap.Add("+", "加号运算符");
descriptionMap.Add("-", "减号运算符");
descriptionMap.Add("*", "乘号运算符");
descriptionMap.Add("/", "除号运算符");
descriptionMap.Add("()", "括号运算符");
descriptionMap.Add("^", "^;\r\n格式x^y(x的y次方)");
descriptionMap.Add("sin()", "sin();\r\n格式sin(表达式)");
descriptionMap.Add("cos()", "cos()\r\n格式cos(表达式)");
descriptionMap.Add("int()", "int();\r\n格式int(表达式)");
descriptionMap.Add("tan()", "tan();\r\n格式tan(表达式)");
descriptionMap.Add("ctan()", "ctan();\r\n格式ctan(表达式)");
descriptionMap.Add("sqrt()", "sqrt()\r\n格式sqrt(表达式)");
descriptionMap.Add("exp()", "exp();\r\n格式exp(表达式)");
descriptionMap.Add("log()", "log();\r\n格式log(表达式)");
descriptionMap.Add("asin()", "asin();\r\n格式asin(表达式)");
descriptionMap.Add("acos()", "acos();\r\n格式acos(表达式)");
descriptionMap.Add("atan()", "atan();\r\n格式atan(表达式)");
descriptionMap.Add("fabs()", "fabs();\r\n格式fabs(表达式)");
descriptionMap.Add("<", "<;\r\n格式x<yx小于y时返回1x大于或等于y时返回0");
descriptionMap.Add(">", ">;\r\n格式x>yx大于y时返回1x小于或等于y时返回0");
descriptionMap.Add("!", "!;\r\n格式!x将x值取非运算当x为非零值时返回0x为零时返回1");
}
private void ExpressionZDialog_Load(object sender, EventArgs e)
{
functionCategoryComboBox.SelectedIndex = 0;
AddOperatorToFunctionCategoryComboBox();
AddFunctionToFunctionCategoryComboxBox();
AddLogicalOperationToFunctionCategoryComboxBox();
FillVariationListBox();
}
private void AddOperatorToFunctionCategoryComboBox()
{
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("int()");
functionListBox.Items.Add("tan()");
functionListBox.Items.Add("ctan()");
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("fabs()");
}
private void AddLogicalOperationToFunctionCategoryComboxBox()
{
functionListBox.Items.Add("<");
functionListBox.Items.Add(">");
functionListBox.Items.Add("!");
}
private void functionListBox_SelectedValueChanged(object sender, EventArgs e)
{
string functionStr = functionListBox.SelectedItem.ToString();
if (functionStr.Length == 0)
return;
if (descriptionMap.ContainsKey(functionStr) == false)
return;
notationTextBox.Text = descriptionMap[functionStr];
}
public void InsertFunctionToExpresstionTextBox(string funcStr)
{
int start = expresstionTextBox.SelectionStart; //插入点位置
expresstionTextBox.Paste(funcStr);
//ScrollToCaret();
//expresstionTextBox.ScrollToCaret();
//expresstionTextBox.cu
}
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 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_DoubleClick(object sender, EventArgs e)
{
string functionStr = functionListBox.SelectedItem.ToString();
expresstionTextBox.Paste(functionStr);
if (functionStr.Contains("()")) //如果是有括号的表达式 将插入点设置在括号里
{
expresstionTextBox.SelectionStart -= 1;
}
expresstionTextBox.Focus();
}
private void variationListBox_DoubleClick(object sender, EventArgs e)
{
string varStr = variationListBox.SelectedItem.ToString();
expresstionTextBox.Paste(varStr);
expresstionTextBox.Focus();
}
}
}