//using DevExpress.XtraEditors;
|
//using DevExpress.XtraEditors.Repository;
|
using Hydro.CommonBase;
|
//using ConfigApp;
|
using Hydro.MapView;
|
//using DevExpress.XtraEditors;
|
//using DevExpress.XtraGrid.Views.Base;
|
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;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
using Colour = Hydro.MapView.Colour;
|
|
namespace Hydro.MapUI
|
{
|
public partial class Form_Colour : Form
|
{
|
public Template Template { get; private set; }
|
|
private List<Colour> Colours = new List<Colour>();
|
private Colour CurrenColour
|
{
|
get {
|
|
return comboBox1.SelectedItem as Colour;
|
}
|
}
|
private List<ColourItem> floors
|
{
|
get
|
{
|
return CurrenColour?.Items;
|
}
|
set
|
{
|
if (Colours.Count == 0) Colours.Add(new Colour()); Colours[0].Items = value;
|
}
|
}
|
private Stack<List<Colour>> undoStack;
|
private Stack<List<Colour>> redoStack;
|
MapViewer map;
|
public Form_Colour(List<Colour> colours,Template template)
|
{
|
InitializeComponent();
|
//comboBox1.DataSource = this.regions;
|
|
|
this.Template = template;
|
this.Colours = colours;
|
//floors = new List<ColourItem>();
|
undoStack = new Stack<List<Colour>>();
|
redoStack = new Stack<List<Colour>>();
|
}
|
|
private void Form_EditFloors_Load(object sender,EventArgs e)
|
{
|
//根据ColourType更新comboBox1的数据集
|
|
int i = 0;
|
foreach (ColourType colour in Enum.GetValues(typeof(ColourType)))
|
{
|
if (i!=0) comboBox3.Items.Add(colour);
|
i++;
|
}
|
comboBox3.Refresh();
|
comboBox3.SelectedIndex = 0;
|
|
|
if (GlobalObject.map == null)
|
{
|
GlobalObject.map = map;
|
|
}
|
UpdateColourList();
|
UpdateColourItemList();
|
|
if (floors == null)
|
{
|
floors = new List<ColourItem>();
|
//为floors添加一系列默认的颜色分级设置
|
|
}
|
|
}
|
private void AddFloorButton_Click(object sender, EventArgs e)
|
{
|
|
|
ColourItem newFloor = new ColourItem();
|
//newFloor.FloorIndex = floors.Count + 1;
|
|
floors.Add(newFloor);
|
|
UpdateColourItemList();
|
FloorsListBox.SelectedItem = newFloor;
|
//foreach (ColourItem f in FloorsListBox.Items)
|
//{
|
// if (newFloor==f)
|
// {
|
// FloorsListBox.SelectedItem = newFloor;
|
// break;
|
// }
|
//}
|
}
|
|
private void DeleteFloorButton_Click(object sender, EventArgs e)
|
{
|
if (FloorsListBox.SelectedIndex != -1)
|
{
|
int selectedIndex = FloorsListBox.SelectedIndex;
|
ColourItem removedFloor = floors[selectedIndex];
|
floors.RemoveAt(selectedIndex);
|
|
// Save the current state for undo
|
undoStack.Push(new List<Colour>(Colours));
|
|
// Clear redo stack since a new operation is performed
|
redoStack.Clear();
|
|
UpdateColourItemList();
|
}
|
}
|
private void UpdateColourList()
|
{
|
comboBox1.Items.Clear();
|
foreach (Colour region in Colours.FindAll(cl=>cl.Type== Current_ColourType))
|
{
|
comboBox1.Items.Add(region);
|
}
|
if (comboBox1.Items.Count>0)
|
comboBox1.SelectedIndex = 0;
|
}
|
private void UpdateColourItemList()
|
{
|
FloorsListBox.Items.Clear();
|
if (floors!=null)
|
FloorsListBox.Items.AddRange(floors.ToArray());
|
|
|
|
}
|
|
private void UndoButton_Click(object sender, EventArgs e)
|
{
|
if (undoStack.Count > 0)
|
{
|
redoStack.Push(new List<Colour>(Colours));
|
Colours = undoStack.Pop();
|
|
UpdateColourItemList();
|
}
|
}
|
|
private void RedoButton_Click(object sender, EventArgs e)
|
{
|
if (redoStack.Count > 0)
|
{
|
undoStack.Push(new List<Colour>(Colours));
|
Colours = redoStack.Pop();
|
|
UpdateColourItemList();
|
}
|
}
|
private ColourItem copiedFloor; // 保存被复制的楼层
|
|
private void CopyFloorButton_Click(object sender, EventArgs e)
|
{
|
if (FloorsListBox.SelectedIndex != -1)
|
{
|
int selectedIndex = FloorsListBox.SelectedIndex;
|
copiedFloor = new ColourItem(floors[selectedIndex]);
|
}
|
}
|
|
private void PasteFloorButton_Click(object sender, EventArgs e)
|
{
|
if (copiedFloor != null)
|
{
|
floors.Add(new ColourItem(copiedFloor));
|
// Save the current state for undo
|
undoStack.Push(new List<Colour>(Colours));
|
|
// Clear redo stack since a new operation is performed
|
redoStack.Clear();
|
UpdateColourItemList();
|
}
|
}
|
|
private void EditFloorButton_Click(object sender, EventArgs e)
|
{
|
if (FloorsListBox.SelectedIndex != -1)
|
{
|
lockEditing();
|
int selectedIndex = FloorsListBox.SelectedIndex;
|
ColourItem selectedFloor = floors[selectedIndex];
|
|
// 显示并允许编辑楼层属性的组件
|
EditProperties(selectedFloor);
|
}
|
}
|
|
private void lockEditing(bool state=true)
|
{
|
simpleButton4.Enabled = !state;
|
FloorsListBox.Enabled = !state;
|
SaveButton.Enabled = state;
|
CancelButton.Enabled = state;
|
//simpleButton1.Enabled = state;
|
tb_Range1.ReadOnly = !state;
|
colorPickEdit1.ReadOnly = !state;
|
//ElevTextBox.ReadOnly = !state;
|
|
}
|
|
private void FloorsListBox_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void EditProperties(ColourItem floor)
|
{
|
tb_Range1.Text = floor.DRange.Min.ToString("0.000");
|
tb_Range2.Text = floor.DRange.Max.ToString("0.000");
|
|
colorPickEdit1.Color = floor.value;
|
//ElevTextBox.Text = floor.Elev.ToString();
|
//MapViewTextBox.Text = floor.MapView?.ToString() ?? "";
|
|
|
|
SaveButton.Visible = true;
|
CancelButton.Visible = true;
|
}
|
|
private void SaveButton_Click(object sender, EventArgs e)
|
{
|
int selectedIndex = FloorsListBox.SelectedIndex;
|
if (selectedIndex == -1 || selectedIndex >= floors.Count) return;
|
|
ColourItem editedFloor = floors[selectedIndex];
|
|
//editedFloor.BackgroundImg = colorPickEdit1.Text;
|
editedFloor.value = colorPickEdit1.Color;
|
|
//editedFloor.MapView = new MapDimensions(MapViewTextBox.Text);
|
|
UpdateColourItemList();
|
|
ClearProperties();
|
// Save the current state for undo
|
undoStack.Push(new List<Colour>(Colours));
|
|
// Clear redo stack since a new operation is performed
|
redoStack.Clear();
|
lockEditing(false);
|
}
|
private void SelectImageButton_Click(object sender, EventArgs e)
|
{
|
//OpenFileDialog openFileDialog = new OpenFileDialog();
|
//openFileDialog.Filter = "Image Files (*.jpg;*.jpeg;*.png;*.gif;*.bmp)|*.jpg;*.jpeg;*.png;*.gif;*.bmp";
|
|
//if (openFileDialog.ShowDialog() == DialogResult.OK)
|
//{
|
// colorPickEdit1.Text = openFileDialog.FileName;
|
//}
|
int selectedIndex = FloorsListBox.SelectedIndex;
|
if (selectedIndex == -1 || selectedIndex >= floors.Count) return;
|
ColourItem editedFloor = floors[selectedIndex];
|
模板管理 fs = new 模板管理(true);
|
if (fs.ShowDialog()==DialogResult.OK)
|
{
|
colorPickEdit1.Text = fs.TemplateID;
|
//editedFloor.TemplateID = fs.TemplateID;
|
map.SetData(TemplateList.GetTemplate(fs.TemplateID));
|
}
|
|
}
|
private void CancelButton_Click(object sender, EventArgs e)
|
{
|
ClearProperties();
|
lockEditing(false);
|
}
|
private void ClearFloorsButton_Click(object sender, EventArgs e)
|
{
|
|
floors.Clear();
|
UpdateColourItemList();
|
// Save the current state for undo
|
undoStack.Push(new List<Colour>(Colours));
|
|
// Clear redo stack since a new operation is performed
|
redoStack.Clear();
|
}
|
|
private void ClearProperties()
|
{
|
tb_Range1.Text = "";
|
colorPickEdit1.Text = "";
|
//ElevTextBox.Text = "";
|
//MapViewTextBox.Text = "";
|
|
tb_Range1.Enabled = true;
|
|
SaveButton.Visible = false;
|
CancelButton.Visible = false;
|
}
|
|
private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
|
private void GenerateFloorsButton_Click(object sender, EventArgs e)
|
{
|
if (CurrenColour==null)
|
{
|
simpleButton9_Click(1,new EventArgs());
|
}
|
// 隐藏错误标签
|
ErrorLabel.Visible = false;
|
|
|
|
float minFloorIndex;
|
float maxFloorIndex;
|
int ColourNum = 0;
|
Color color0 = colorPickEdit2.Color;
|
Color color1 = colorPickEdit3.Color;
|
|
// 尝试解析文本框中的值
|
if (!float.TryParse(tb_minFloorIndex.Text, out minFloorIndex))
|
{
|
ErrorLabel.Text = "最小值必须是数字";
|
ErrorLabel.Visible = true;
|
return;
|
}
|
if (!float.TryParse(tb_maxFloorIndex.Text, out maxFloorIndex))
|
{
|
ErrorLabel.Text = "最大值必须是数字";
|
ErrorLabel.Visible = true;
|
return;
|
}
|
if (!int.TryParse(tb_ColourNum.Text,out ColourNum))
|
{
|
ErrorLabel.Text = "级数必须是数字";
|
ErrorLabel.Visible = true;
|
return;
|
}
|
//if (!float.TryParse(tb_Height.Text, out floorHeight))
|
//{
|
// ErrorLabel.Text = "每层层高必须是数字";
|
// ErrorLabel.Visible = true;
|
// return;
|
//}
|
//if (!float.TryParse(tb_minFloorElev.Text, out minFloorElev))
|
//{
|
// ErrorLabel.Text = "最低层地面高程必须是数字";
|
// ErrorLabel.Visible = true;
|
// return;
|
//}
|
|
|
CurrenColour.color0= color0;
|
CurrenColour.color1 = color1;
|
CurrenColour.maxNum = maxFloorIndex;
|
CurrenColour.minNum = minFloorIndex;
|
CurrenColour.ColourCount = ColourNum;
|
|
|
//string tempID = BackgroundImgTextBox_q.Text;
|
|
// 逐层生成楼层
|
for (int i = 0; i < ColourNum; i++)
|
{
|
DRange currentRange =new DRange(minFloorIndex + i * (maxFloorIndex- minFloorIndex)/ColourNum, minFloorIndex + (i+1) * (maxFloorIndex - minFloorIndex) / ColourNum);
|
Color c;
|
//获取color0和color1,Colour个等分颜色,第一个为color0,最后一个为color1,中间的为等分颜色
|
if (i == 0)
|
{
|
c = color0;
|
}
|
else if (i == ColourNum-1)
|
{
|
c = color1;
|
}
|
else
|
{
|
c = Color.FromArgb(color0.R + (color1.R - color0.R) / (ColourNum - 1) * i, color0.G + (color1.G - color0.G) / (ColourNum - 1) * i, color0.B + (color1.B - color0.B) / (ColourNum-1) * i);
|
|
}
|
|
|
ColourItem newFloor = new ColourItem(currentRange,c);
|
floors.Add(newFloor);
|
}
|
|
// 更新楼层列表
|
UpdateColourItemList();
|
}
|
|
private void SelectImageButton_Click_q(object sender, EventArgs e)
|
{
|
//OpenFileDialog openFileDialog = new OpenFileDialog();
|
//openFileDialog.Filter = "Image Files (*.jpg;*.jpeg;*.png;*.gif;*.bmp)|*.jpg;*.jpeg;*.png;*.gif;*.bmp";
|
|
//if (openFileDialog.ShowDialog() == DialogResult.OK)
|
//{
|
// BackgroundImgTextBox_q.Text = openFileDialog.FileName;
|
//}
|
//int selectedIndex = FloorsListBox.SelectedIndex;
|
//if (selectedIndex == -1 || selectedIndex >= floors.Count) return;
|
//ColourItem editedFloor = floors[selectedIndex];
|
模板管理 fs = new 模板管理(true);
|
if (fs.ShowDialog() == DialogResult.OK)
|
{
|
//BackgroundImgTextBox_q.Text = fs.TemplateID;
|
//editedFloor.TemplateID = fs.TemplateID;
|
//map.SetData(TemplateList.GetTemplate(fs.TemplateID));
|
}
|
|
}
|
|
private void FloorsListBox_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
if (FloorsListBox.SelectedIndex != -1)
|
{
|
int selectedIndex = FloorsListBox.SelectedIndex;
|
ColourItem selectedFloor = floors[selectedIndex];
|
|
// 显示并允许编辑楼层属性的组件
|
EditProperties(selectedFloor);
|
//var template = TemplateList.GetTemplate(selectedFloor.TemplateID);
|
////if (template != null)
|
//// this.map.SetData(template);
|
|
|
}
|
}
|
|
private void simpleButton9_Click(object sender, EventArgs e)
|
{
|
|
int i = 1;
|
string str = (Current_ColourType+"_"+i.ToString()).ToString();
|
while (Colours.FindAll(cl=>cl.Name==str).Count>0)
|
{
|
i++;
|
str = (Current_ColourType + "_" + i.ToString()).ToString();
|
}
|
InputBox inputBox = new InputBox("输入名称",str);
|
string name= inputBox.ShowDialog();
|
|
if (name != null &&name.Trim() !="")
|
{
|
var region = new Colour(Current_ColourType,new List<ColourItem>(),name);
|
if (Colours.Find(r => r.Name == region.Name) != null)
|
{
|
MessageBox.Show($"名称重复[{region.Name}]");
|
return;
|
}
|
Colours.Add(region);
|
UpdateColourList();
|
}
|
|
}
|
|
private void simpleButton10_Click(object sender, EventArgs e)
|
{
|
if (message.show("", "确认删除", MessageBoxButtons.YesNo))
|
{
|
Colours.RemoveAt(comboBox1.SelectedIndex);
|
UpdateColourList();
|
}
|
|
|
}
|
ColourType Current_ColourType
|
{
|
get
|
{
|
if(comboBox3.SelectedItem==null) return ColourType.节点自由压力;
|
return (ColourType)Enum.Parse(typeof(ColourType), comboBox3.SelectedItem.ToString());
|
}
|
}
|
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
UpdateColourList();
|
UpdateColourItemList();
|
}
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
if (CurrenColour == null) return;
|
colorPickEdit2.Color = CurrenColour.color0;
|
colorPickEdit3.Color = CurrenColour.color1;
|
tb_minFloorIndex.Text = CurrenColour.minNum.ToString();
|
tb_maxFloorIndex.Text = CurrenColour.maxNum.ToString();
|
tb_ColourNum.Text = CurrenColour.ColourCount.ToString();
|
|
|
}
|
private void InsertIntoNet_Click(object sender, EventArgs e)
|
{
|
//int step = 1;
|
//int startIndex = 0;
|
//int endIndex = CurrenColour.Items.Count;
|
////if (!CurrenColour.isDirectionUp)
|
////{
|
//// step = -1;
|
//// startIndex = CurrenColour.Floors.Count - 1;
|
//// endIndex = -1;
|
////}
|
//MapViewNetWork net = new MapViewNetWork();
|
//ColourItem lastFloor = null;
|
//NodeViewModel lastPoint = null;
|
//NodeViewModel node1 = null;
|
//for(int i=startIndex; i < endIndex;i+=step)
|
//{
|
// var floor = CurrenColour.Items[i];
|
// if (floor.template.network==null)
|
// {
|
// floor.template.loadInpFile();
|
|
// }
|
// var n= floor.template.network;
|
// var point = n.Nodes.Find(node => node.ID==floor.template.Node1);
|
// if (point == null) point = n.Nodes[0];
|
// PointF3D p = new PointF3D(0- point.X, 0- point.Y, floor.Elev-point.Elev);
|
// n.Nodes.Select(node => (NodeViewModel)node).ToList().ForEach(node => { node.regionName = CurrenColour.Name; });
|
// n.Links.Select(link=>(LinkViewModel)link).ToList().ForEach(link => { link.regionName = CurrenColour.Name; });
|
// var list=net.Add(n, p,true);
|
// NodeViewModel CurrentPoint = (NodeViewModel)list[0];
|
// if (lastPoint!=null)
|
// {
|
// var j=net.AddPipe(lastPoint, CurrentPoint);
|
// j.regionName = CurrenColour.Name;
|
// }
|
// lastPoint = (NodeViewModel)list[0];
|
// if (node1 == null) node1 = lastPoint;
|
|
//}
|
//Template temp=new Template();
|
//temp.network = net;
|
//temp.Node1 = node1.ID;
|
//GlobalObject.map.InsertNet(temp);
|
//this.Close();
|
|
}
|
|
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
//CurrenColour.isDirectionUp = comboBox2.SelectedIndex == 0;
|
}
|
|
private void btn_readNetData_Click(object sender, EventArgs e)
|
{
|
//根据当前选中的ColourType,判断是否有对应的网络数据
|
if (CurrenColour == null) return;
|
double max = 0;
|
double min = 0;
|
|
switch(CurrenColour.Type)
|
{
|
case ColourType.节点自由压力:
|
max=this.Template.network.Nodes.Where(node=>!(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_PRESSURE);
|
min=this.Template.network.Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_PRESSURE);
|
break;
|
case ColourType.节点绝对压力:
|
max = this.Template.network.Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_PRESSURE);
|
min = this.Template.network.Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_PRESSURE);
|
break;
|
case ColourType.节点需水量:
|
max = this.Template.network.Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_DEMAND);
|
min = this.Template.network.Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_DEMAND);
|
break;
|
case ColourType.管线流量:
|
max = this.Template.network.Links.Max(link => link.EN_FLOW);
|
min = this.Template.network.Links.Min(link => link.EN_FLOW);
|
break;
|
case ColourType.管线流速:
|
max = this.Template.network.Links.Max(link => link.EN_VELOCITY);
|
min = this.Template.network.Links.Min(link => link.EN_VELOCITY);
|
break;
|
default:
|
break;
|
|
}
|
tb_minFloorIndex.Text = min.ToString();
|
tb_maxFloorIndex.Text = max.ToString();
|
}
|
|
private void btn_useColour_Click(object sender, EventArgs e)
|
{
|
Colours.ForEach(c => c.isChoosed = false);
|
CurrenColour.isChoosed = true;
|
}
|
|
private void btn_Close_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
|
private void btn_apply_Click(object sender, EventArgs e)
|
{
|
Colours.ForEach(c => c.isChoosed = false);
|
CurrenColour.isChoosed = true;
|
if (CurrenColour.isNode)
|
{
|
GlobalObject.map.cb_Node_Colour.SelectedIndex =(int)CurrenColour.Type ;
|
}
|
else
|
{
|
GlobalObject.map.cb_Link_Colour.SelectedIndex = ((int)CurrenColour.Type - Colour.NodeTypeCount);
|
}
|
TemplateList.SaveToFile();
|
this.Close();
|
|
}
|
|
private void btn_颜色对调_Click(object sender, EventArgs e)
|
{
|
var color=colorPickEdit2.Color;
|
colorPickEdit2.Color = colorPickEdit3.Color;
|
colorPickEdit3.Color = color;
|
|
}
|
}
|
|
|
}
|