using Hydro;
|
|
namespace PBS.WinFrmUI.Hydro
|
{
|
public partial class SelectModelTemplateDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public SelectModelTemplateDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
this.layoutControl1.SetupLayoutControl();
|
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
|
this.modelTemplateTreeListCtrl1.SelectModelTemplateEvent += ModelTemplateTreeListCtrl1_SelectModelTemplateEvent;
|
}
|
|
|
|
/// <summary>
|
/// 重载数据
|
/// </summary>
|
public event Action<Template> ReloadDataEvent;
|
|
public Vmo.ModelTemplateVmo _modelTemplate;
|
private Template _template = null;
|
private MapViewer _mapView = null;
|
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public async void SetBindingData()
|
{
|
|
_mapView = new MapViewer();
|
_mapView.Lock2DView = true;
|
_mapView.ShowPropertyForm = false;
|
_mapView.ShowStatusBar = false;
|
_mapView.Location = new System.Drawing.Point(0, 0);
|
_mapView.Dock = DockStyle.Fill;
|
|
this.panelControl1.Controls.Add(_mapView);
|
|
var modelTemplateList = await BLLFactory<BLL.ModelTemplate>.Instance.GetAll();
|
this.modelTemplateTreeListCtrl1.SetBindingData(modelTemplateList);
|
this.modelTemplateTreeListCtrl1.MenuBarVisible = false;
|
|
this.txtLowerLevel.EditValue = 1;
|
this.txtHighestLevel.EditValue = 3;
|
this.txtBottomElevation.EditValue = 3;
|
this.txtFloorHeight.EditValue = 3;
|
|
}
|
|
//选择模型模板
|
private void ModelTemplateTreeListCtrl1_SelectModelTemplateEvent(ModelTemplateVmo obj)
|
{
|
if (obj == null)
|
{
|
_modelTemplate = null;
|
_template = null;
|
_mapView.Clear();
|
return;
|
}
|
|
_modelTemplate = obj;
|
_template = Yw.JsonHelper.Json2Object<Template>(obj.ModelInfo);
|
|
|
var template = _template;
|
template.network = new MapViewNetWork();
|
template.network.BuildFromInp(Path.Combine(Directory.GetCurrentDirectory(), _template.filePath));
|
_mapView.SetData(template);
|
}
|
|
//生成
|
private Template CreateTemplate()
|
{
|
if (!Verify())
|
return null;
|
|
int minFloorIndex = Convert.ToInt32(this.txtLowerLevel.EditValue);
|
int maxFloorIndex = Convert.ToInt32(this.txtHighestLevel.EditValue);
|
double floorHeight = Convert.ToDouble(this.txtFloorHeight.EditValue);
|
double minFloorElev = Convert.ToDouble(this.txtBottomElevation.EditValue);
|
|
var floorList = new List<(int FloorIndex, double Elevation)>();
|
for (int i = minFloorIndex; i <= maxFloorIndex; i++)
|
{
|
var floorElevation = minFloorElev + (i - minFloorIndex) * floorHeight;
|
floorList.Add((i, floorElevation));
|
}
|
|
int step = 1;
|
int startIndex = 0;
|
int endIndex = floorList.Count;
|
var isDirectionUp = this.cmbDirection.SelectedItem as string == "向上" ? true : false;
|
if (!isDirectionUp)
|
{
|
step = -1;
|
startIndex = floorList.Count - 1;
|
endIndex = -1;
|
}
|
|
var template = _template;
|
var newNetWork = new MapViewNetWork();
|
NodeViewModel lastNode = null;
|
NodeViewModel newStartNode = null;
|
for (int i = startIndex; isDirectionUp ? i < endIndex : i > endIndex; i += step)
|
{
|
var (FloorIndex, Elevation) = floorList[i];
|
|
var templateNetWork = template.network;
|
var startNode = templateNetWork.Nodes.Find(node => node.ID == template.Node1);
|
if (startNode == null)
|
startNode = templateNetWork.Nodes[0];
|
var newNode = new PointF3D(0 - startNode.X, 0 - startNode.Y, (float)Elevation - startNode.Elev);
|
|
templateNetWork.Nodes
|
.Select(node => (NodeViewModel)node)
|
.ToList()
|
.ForEach(node =>
|
{
|
node.regionName = PBS.eWaterSupply.Low.ToString(); node.Floor = i.ToString();
|
});
|
|
templateNetWork
|
.Links
|
.Select(link => (LinkViewModel)link)
|
.ToList()
|
.ForEach(link =>
|
{
|
link.regionName = PBS.eWaterSupply.Low.ToString(); link.Floor = i.ToString();
|
});
|
|
var list = newNetWork.Add(templateNetWork, newNode, true);
|
NodeViewModel CurrentPoint = (NodeViewModel)list[0];
|
if (lastNode != null)
|
{
|
var j = newNetWork.AddPipe(lastNode, CurrentPoint);
|
j.regionName = PBS.eWaterSupply.Low.ToString();
|
}
|
lastNode = (NodeViewModel)list[0];
|
if (newStartNode == null)
|
newStartNode = lastNode;
|
}
|
|
Template newTemplate = new Template();
|
newTemplate.network = newNetWork;
|
newTemplate.Node1 = newStartNode.ID;
|
return newTemplate;
|
}
|
|
|
//数据验证
|
private bool Verify()
|
{
|
var notError = true;
|
this.dxErrorProvider1.ClearErrors();
|
if (string.IsNullOrEmpty(this.txtLowerLevel.Text))
|
{
|
notError = true;
|
this.dxErrorProvider1.SetError(this.txtLowerLevel, "必填项");
|
}
|
if (string.IsNullOrEmpty(this.txtHighestLevel.Text))
|
{
|
notError = true;
|
this.dxErrorProvider1.SetError(this.txtHighestLevel, "必填项");
|
}
|
if (string.IsNullOrEmpty(this.txtBottomElevation.Text))
|
{
|
notError = true;
|
this.dxErrorProvider1.SetError(this.txtBottomElevation, "必填项");
|
}
|
if (string.IsNullOrEmpty(this.txtFloorHeight.Text))
|
{
|
notError = true;
|
this.dxErrorProvider1.SetError(this.txtFloorHeight, "必填项");
|
}
|
|
return notError;
|
}
|
|
|
|
//确定
|
private void GeneralOkAndCancelCtrl1_OkEvent()
|
{
|
if (!Verify())
|
{
|
return;
|
}
|
|
var template=CreateTemplate();
|
if (template==null)
|
{
|
return;
|
}
|
|
this.ReloadDataEvent?.Invoke(template);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
|
}
|
|
}
|
}
|