using DevExpress.Utils.Extensions;
|
using Hydro;
|
using System.Data;
|
|
namespace PBS.WinFrmUI.Hydro
|
{
|
public partial class EditFloors : DevExpress.XtraEditors.XtraForm
|
{
|
public EditFloors()
|
{
|
InitializeComponent();
|
}
|
|
private List<FloorTemplateViewModel> floorTemplateViewModels = new List<FloorTemplateViewModel>();
|
private Template _selectTemp { get; set; }
|
|
private void EditFloors_Load(object sender, EventArgs e)
|
{
|
if (map == null)
|
{
|
map = new MapViewer();
|
map.Lock2DView = true;
|
map.Location = new System.Drawing.Point(0, 0);
|
map.Dock = DockStyle.Fill;
|
|
panelControl1.AddControl(map);
|
|
this.floorTemplateViewModelBindingSource.DataSource = floorTemplateViewModels;
|
this.gridView1.RefreshData();
|
}
|
}
|
|
private MapViewer map = null;
|
|
//模选择
|
private void textEditChoice_Click(object sender, EventArgs e)
|
{
|
var dlg = new TemplateChoice();
|
if (dlg.ShowDialog() == DialogResult.OK)
|
{
|
template = ModelConvertToTemplate(dlg.modelTemplate);
|
SetMapData(template);
|
textEditChoice.Text = template.Name;
|
}
|
}
|
|
|
|
private void textEditTemplate_Click(object sender, EventArgs e)
|
{
|
var dlg = new TemplateChoice();
|
if (dlg.ShowDialog() == DialogResult.OK)
|
{
|
floorTemplate = ModelConvertToTemplate(dlg.modelTemplate);
|
SetMapData(floorTemplate);
|
textEditTemplate.Text = floorTemplate.Name;
|
}
|
}
|
|
private void SetMapData(Template _template)
|
{
|
// 获取当前选中的模板
|
_selectTemp = _template;
|
|
if (_selectTemp != null)
|
{
|
var temp = _selectTemp;
|
string filePath = temp.FullPath;
|
temp.network = new MapViewNetWork();
|
temp.network.BuildFromInp(Path.Combine(Directory.GetCurrentDirectory(), filePath));
|
map.SetData(temp);
|
}
|
}
|
|
|
private Template ModelConvertToTemplate(Vmo.ModelTemplateVmo model)
|
{
|
return Yw.JsonHelper.Json2Object<Template>(model.ModelInfo);
|
}
|
|
|
|
private Template template;
|
private Template floorTemplate;
|
public List<Floor> floors = new List<Floor>();
|
|
private void simpleButton3_Click(object sender, EventArgs e)
|
{
|
//清空楼层
|
if (floorTemplateViewModels.Any())
|
{
|
floorTemplateViewModels.Clear();
|
|
floors.Clear();
|
ClearControl();
|
this.gridView1.RefreshData();
|
}
|
}
|
|
private void ClearControl()
|
{
|
textEditlowerlayers.Text = textEditHightlayers.Text = textEditLevel.Text = textEditFloor.Text = textEdit7.Text = textEditChoice.Text = "";
|
}
|
|
private void ClearPropControl()
|
{
|
textEdit2.Text = textEditTemplate.Text = textEdit10.Text = "";
|
}
|
|
/// <summary>
|
/// 插入管网
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void simpleBtnFinish_Click(object sender, EventArgs e)
|
{
|
var temp = GetNet();
|
GlobalObject.map.InsertNet(temp);
|
this.Hide();
|
}
|
|
private Template GetNet()
|
{
|
int step = 1;
|
int startIndex = 0;
|
int endIndex = floors.Count;
|
var isDirectionUp = textEdit7.SelectedItem as string == "向上" ? true : false;
|
if (!isDirectionUp)
|
{
|
step = -1;
|
startIndex = floors.Count - 1;
|
endIndex = -1;
|
}
|
MapViewNetWork net = new MapViewNetWork();
|
NodeViewModel lastPoint = null;
|
NodeViewModel node1 = null;
|
for (int i = startIndex; isDirectionUp ? i < endIndex : i > endIndex; i += step)
|
{
|
var floor = floors[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 = PBS.eWaterSupply.Low.ToString(); node.Floor = i.ToString(); });
|
n.Links.Select(link => (LinkViewModel)link).ToList().ForEach(link => { link.regionName = PBS.eWaterSupply.Low.ToString(); link.Floor = i.ToString(); });
|
var list = net.Add(n, p, true);
|
NodeViewModel CurrentPoint = (NodeViewModel)list[0];
|
if (lastPoint != null)
|
{
|
var j = net.AddPipe(lastPoint, CurrentPoint);
|
j.regionName = PBS.eWaterSupply.Low.ToString();
|
}
|
lastPoint = (NodeViewModel)list[0];
|
if (node1 == null) node1 = lastPoint;
|
}
|
Template temp = new Template();
|
temp.network = net;
|
temp.Node1 = node1.ID;
|
return temp;
|
}
|
|
private void simpleButton2_Click(object sender, EventArgs e)
|
{
|
ClearPropControl();
|
simpleButton1.Enabled = false;
|
}
|
|
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
{
|
var curr = this.gridView1.GetFocusedRow() as FloorTemplateViewModel;
|
textEdit2.Text = curr.FloorIndex;
|
textEdit10.Text = curr.FloorHeight.ToString();
|
textEditTemplate.Text = curr.TemplateName;
|
simpleButton1.Enabled = true;
|
floorTemplate = curr.floorTemplate;
|
SetMapData(floorTemplate);
|
}
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
{
|
|
floorTemplateViewModels.ForEach(c =>
|
{
|
if (c.FloorIndex == textEdit2.Text)
|
{
|
c.FloorHeight = float.Parse(textEdit10.Text);
|
c.TemplateID = long.Parse(floorTemplate.ID);
|
c.TemplateName = floorTemplate.Name;
|
c.floorTemplate = floorTemplate;
|
}
|
});
|
|
floors.ForEach(c =>
|
{
|
if (c.FloorIndex == int.Parse(textEdit2.Text.Replace("楼", "")))
|
{
|
c.TemplateID = floorTemplate.ID;
|
}
|
});
|
this.gridView1.RefreshData();
|
}
|
|
|
|
//生成
|
private void simpleButton4_Click_1(object sender, EventArgs e)
|
{
|
int minFloorIndex;
|
int maxFloorIndex;
|
float floorHeight;
|
float minFloorElev;
|
if (!Verify())
|
return;
|
minFloorIndex = int.Parse(textEditlowerlayers.Text);
|
maxFloorIndex = int.Parse(textEditHightlayers.Text);
|
floorHeight = float.Parse(textEditFloor.Text);
|
minFloorElev = float.Parse(textEditLevel.Text);
|
for (int i = minFloorIndex; i <= maxFloorIndex; i++)
|
{
|
var floorName = i + "楼";
|
if (!floorTemplateViewModels.Any(c => c.FloorIndex == floorName))
|
{
|
float floorElev = minFloorElev + (i - minFloorIndex) * floorHeight;
|
Floor newFloor = new Floor(i, template.ID, floorElev, null);
|
floors.Add(newFloor);
|
|
floorTemplateViewModels.Add(new FloorTemplateViewModel()
|
{
|
FloorIndex = floorName,
|
FloorHeight = floorHeight,
|
TemplateID = long.Parse(template.ID),
|
TemplateName = template.Name,
|
floorTemplate = template
|
});
|
}
|
}
|
|
this.floorTemplateViewModelBindingSource.DataSource = floorTemplateViewModels;
|
this.gridView1.RefreshData();
|
}
|
|
//数据验证
|
private bool Verify()
|
{
|
dxErrorProvider1.ClearErrors();
|
//最低层
|
if (string.IsNullOrEmpty(textEditlowerlayers.Text))
|
{
|
dxErrorProvider1.SetError(textEditlowerlayers, "必填项");
|
return false;
|
}
|
if (!int.TryParse(textEditlowerlayers.Text, out int low) || low <= 0)
|
{
|
dxErrorProvider1.SetError(textEditlowerlayers, "必须大于0");
|
return false;
|
}
|
//最高层
|
if (string.IsNullOrEmpty(textEditHightlayers.Text))
|
{
|
dxErrorProvider1.SetError(textEditHightlayers, "必填项");
|
return false;
|
}
|
if (!int.TryParse(textEditHightlayers.Text, out int hight) || hight <= 0)
|
{
|
dxErrorProvider1.SetError(textEditHightlayers, "必须大于0");
|
return false;
|
}
|
//底层标高
|
if (string.IsNullOrEmpty(textEditLevel.Text))
|
{
|
dxErrorProvider1.SetError(textEditLevel, "必填项");
|
return false;
|
}
|
if (!int.TryParse(textEditLevel.Text, out int level) || level <= 0)
|
{
|
dxErrorProvider1.SetError(textEditLevel, "必须大于0");
|
return false;
|
}
|
|
//楼层高
|
if (string.IsNullOrEmpty(textEditFloor.Text))
|
{
|
dxErrorProvider1.SetError(textEditFloor, "必填项");
|
return false;
|
}
|
if (!float.TryParse(textEditFloor.Text, out float floor) || floor <= 1)
|
{
|
dxErrorProvider1.SetError(textEditFloor, "必须大于1");
|
return false;
|
}
|
if (hight <= low)
|
{
|
dxErrorProvider1.SetError(textEditHightlayers, "最高层需大于最低层");
|
return false;
|
}
|
if (template == null)
|
{
|
dxErrorProvider1.SetError(textEditChoice, "必选项");
|
return false;
|
}
|
// 如果以上条件都不满足,则返回true
|
return true;
|
}
|
}
|
|
public class FloorTemplateViewModel
|
{
|
public string FloorIndex { get; set; }
|
|
public long TemplateID { get; set; }
|
|
public string TemplateName { get; set; }
|
|
public float FloorHeight { get; set; }
|
|
public Template floorTemplate { get; set; }
|
}
|
}
|