private void DrawSoilLayer(Graphics g, SortedSet <float> elevations, SocketedShaftSystem sss) { // 转换坐标系 Matrix m = new Matrix(); float sp; float ratio; TransformUtils.GetAxisTransform(_daSoilLayers.Top, _daSoilLayers.Top + _daSoilLayers.Height, elevations.Max, elevations.Min, 0f, out sp, out ratio); m.Translate(_daSoilLayers.Left, sp); m.Scale(1, ratio); g.Transform = m; // 在模型坐标系下绘图 var colors = ColorUtils.ColorExpand(new Color[3] { Color.FromArgb(255, 0, 176, 80), Color.FromArgb(255, 0, 112, 192), Color.FromArgb(255, 0, 32, 96) }, sss.SoilLayers.Count); // colors = ColorUtils.ClassicalExpand(sss.SoilLayers.Count); for (int i = 0; i < sss.SoilLayers.Count; i++) { var s = sss.SoilLayers[i]; g.FillRectangle(new SolidBrush(colors[i]), new RectangleF(0, s.Bottom, _daSoilLayers.Width, s.Top - s.Bottom)); } }
private void buttonImport_Click(object sender, EventArgs e) { string filePath = Utils.ChooseOpenSSS("导入水平受荷嵌岩桩文件"); if (filePath.Length > 0) { try { // XmlReader xr = XmlReader.Create(filePath); // XmlSerializer ss = new XmlSerializer(typeof(SocketedShaftSystem)); SocketedShaftSystem sss = (SocketedShaftSystem)ss.Deserialize(xr); xr.Close(); // 对于是桩截面还是土层参数定义的不同来分别进行导入 StringBuilder sb = new StringBuilder(); string errorMessage; if (typeof(T) == typeof(ShaftSection)) { foreach (ShaftSection s in sss.SectionDefinitions) { if (CheckAddDefinition(_definitions, s, out errorMessage)) { _definitions.Add(s as T); sb.AppendLine((s as T).Name + " : 成功"); } else { sb.AppendLine((s as T).Name + " : " + errorMessage); } } } else if (typeof(T) == typeof(SoilLayer)) { foreach (SoilLayer s in sss.SoilDefinitions) { if (CheckAddDefinition(_definitions, s, out errorMessage)) { _definitions.Add(s as T); sb.AppendLine((s as T).Name + " : 成功"); } else { sb.AppendLine((s as T).Name + " : " + errorMessage); } } } MessageBox.Show("参数导入结束,导入结果: \n\r" + sb.ToString(), "完成", MessageBoxButtons.OK, MessageBoxIcon.Information); // _definitions } catch (Exception ex) { DebugUtils.ShowDebugCatch(ex, "指定的文件不能正常提取其中的定义信息。"); } } #endregion }
private void DrawShaft(Graphics gr, SortedSet <float> elevations, SocketedShaftSystem sss) { // 转换坐标系:对 Y 方向进行变换 float sp; float ratio; TransformUtils.GetAxisTransform( s1: _daShaft.Top, s2: _daShaft.Top + _daShaft.Height, m1: elevations.Max, m2: elevations.Min, mp: 0f, sp: out sp, ratio: out ratio); // 将得到的结果应用到仿射矩阵中 Matrix mY = new Matrix(); mY.Translate(_daShaft.Left, sp); mY.Scale(1, ratio); gr.Transform = mY; // 将变换应用到绘图面板中 // 在模型坐标系下绘图 var colors = ColorUtils.ColorExpand(new Color[3] { Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 255, 192, 0), Color.FromArgb(255, 255, 255, 0) }, sss.SocketedShaft.Sections.Count); for (int i = 0; i < sss.SocketedShaft.Sections.Count; i++) { var s = sss.SocketedShaft.Sections[i]; gr.FillRectangle(new SolidBrush(colors[i]), new RectangleF(0, s.Bottom, _daShaft.Width, s.Top - s.Bottom)); } }
private void DrawOnControl(SocketedShaftSystem sss) { Graphics gr; gr = _pictrueBox.CreateGraphics(); // 清除原有图像 gr.Clear(_pictrueBox.BackColor); DrawSss(gr, sss); gr.Dispose(); }
public void RefreshModel(SocketedShaftSystem sss) { _sss = sss; // // RefreshdataGridViewSoilLayers(sss); RefreshdataGridViewShaft(sss); // _soilLayers.AddingNew += SoilLayersOnAddingNew; _shaftSections.AddingNew += ShaftSectionsOnAddingNew; }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // MainForm mf = new MainForm(); SocketedShaftSystem sss = GetSSS(""); mf.RefreshModel(sss); // Application.Run(mf); // }
private bool ValidateModel(SocketedShaftSystem sss, out string errorMessage) { if (string.IsNullOrEmpty(sss.SocketedShaft.Name)) { errorMessage = "桩未命名"; return(false); } if (!ValidateConnectivity(sss.SoilLayers, out errorMessage)) { errorMessage = "土层连续性不满足: " + errorMessage; return(false); } if (!ValidateConnectivity(sss.SocketedShaft.Sections, out errorMessage)) { errorMessage = "桩段连续性不满足: " + errorMessage; return(false); } // 检查标高位置是否合适 if (sss.SocketedShaft.Sections.First().Top < sss.SoilLayers.First().Top) { errorMessage = "桩顶标高不能低于土层顶部标高 "; return(false); } if (sss.SocketedShaft.Sections.First().Bottom > sss.SoilLayers.First().Top) { errorMessage = "土层顶部以上(水中)最多只能有一种截面(暂时对于水中桩段的计算只设计均匀截面的情况。)"; return(false); } if ((sss.SocketedShaft.Sections.Last().Bottom > sss.SoilLayers.First().Top) || (sss.SocketedShaft.Sections.Last().Bottom < sss.SoilLayers.Last().Bottom)) { errorMessage = "桩底标高必须在土层范围之内 "; return(false); } // var soilTop = sss.SoilLayers.First().Top; if (soilTop < sss.SystemProperty.WaterTop) { //errorMessage = "水面标高低于土层顶部标高"; //return false; sss.SystemProperty.WaterTop = soilTop; } errorMessage = "可以成功导出。"; return(true); }
private void RefreshdataGridViewSoilLayers(SocketedShaftSystem sss) { _soilLayers = new BindingList <SoilLayerEntity>(sss.SoilLayers); // dataGridViewSoilLayers.DataSource = _soilLayers; // 数据列的绑定 ColumnSoilTop.DataPropertyName = "Top"; ColumnSoilBottom.DataPropertyName = "Bottom"; // DataGridViewComboBoxColumn ColumnSoil.DataPropertyName = "Layer"; ColumnSoil.DisplayMember = "Name"; // 土层定义的标识名称 ColumnSoil.ValueMember = "Self"; // 土层定义的标识名称 ColumnSoil.DataSource = _sss.SoilDefinitions; }
private void RefreshdataGridViewShaft(SocketedShaftSystem sss) { _shaftSections = new BindingList <ShaftSectionEntity>(sss.SocketedShaft.Sections); dataGridViewShaft.DataSource = _shaftSections; // // 数据列的绑定 ColumnSegTop.DataPropertyName = "Top"; ColumnSegBottom.DataPropertyName = "Bottom"; ColumnSegment.DataPropertyName = "Section"; // DataGridViewComboBoxColumn ColumnSegment.DataPropertyName = "Section"; ColumnSegment.DisplayMember = "Name"; // 桩截面定义的标识名称 ColumnSegment.ValueMember = "Self"; // 土层定义的标识名称 ColumnSegment.DataSource = _sss.SectionDefinitions; }
private void DrawOnImage(SocketedShaftSystem sss) { Bitmap im = new Bitmap(_pictrueBox.Size.Width, _pictrueBox.Size.Height); Graphics gr; gr = Graphics.FromImage(im); // gr.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; DrawSss(gr, sss); // 刷新并覆盖原有图形 _pictrueBox.Image = im; gr.Dispose(); // 将最后的绘制结果保存下来 // _pictrueBox.Image.Save("4.jpg"); }
public void Save(string filePath, SocketedShaftSystem sss) { // 创建一张空图片 并 获取其画板 Graphics 对象 Bitmap bmp = new Bitmap(220, 220); // 这里的220*220并不能决定最后矢量图的大小 Graphics gr = Graphics.FromImage(bmp); // 由位图的面板生成对应的空白矢量图 并 获取 矢量图的画板 grVector 对象 Metafile _metafile = new Metafile(filePath, gr.GetHdc()); Graphics grVector = Graphics.FromImage(_metafile); // 绘图 DrawSss(grVector, sss); // 保存 grVector.Save(); // grVector.Dispose(); _metafile.Dispose(); }
/// <summary> /// /// </summary> /// <param name="sss"></param> /// <param name="elevations">所有可能的标高线,其第一个元素为最小值</param> private void GetVerticalBounds(SocketedShaftSystem sss, out SortedSet <float> elevations) { elevations = new SortedSet <float>(); // 提取土层信息 foreach (var l in sss.SoilLayers) { elevations.Add(l.Top); elevations.Add(l.Bottom); } // 提取桩截面信息 foreach (var s in sss.SocketedShaft.Sections) { elevations.Add(s.Top); elevations.Add(s.Bottom); } }
/// <param name="filePath">此路径必须为一个有效的路径</param> private void ExportToXml(SocketedShaftSystem sss, string filePath) { try { if (File.Exists(filePath)) { File.Delete(filePath); } FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate); XmlSerializer s = new XmlSerializer(sss.GetType()); s.Serialize(fs, sss); fs.Close(); } catch (Exception ex) { DebugUtils.ShowDebugCatch(ex, ""); } }
/// <summary> 开始进行全局绘制 </summary> /// <param name="g"></param> private void DrawSss(Graphics g, SocketedShaftSystem sss) { // 首先要确保有至少一个土层和桩截面 if (sss.SocketedShaft.Sections.Count <= 0 || sss.SoilLayers.Count <= 0) { // 不需要进行绘制 return; } SortedSet <float> elevations; // 所有可能的标高线,其第一个元素为最小值 GetVerticalBounds(sss, out elevations); // g.ResetTransform(); DrawSoilLayer(g, elevations, sss); g.ResetTransform(); DrawShaft(g, elevations, sss); g.ResetTransform(); DrawNotes(g, elevations, sss); }
/// <summary> 绘制标高与注释 </summary> /// <param name="g"></param> /// <param name="elevations"></param> /// <param name="sss"></param> private void DrawNotes(Graphics g, SortedSet <float> elevations, SocketedShaftSystem sss) { // 转换坐标系 Matrix m = new Matrix(); float sp; float ratio; TransformUtils.GetAxisTransform(_daNotations.Top, _daNotations.Top + _daNotations.Height, elevations.Max, elevations.Min, 0f, out sp, out ratio); m.Translate(_daNotations.Left, sp); m.Scale(1, ratio); // g.Transform = m; // 在模型坐标系下绘图 var c = Color.Black; var modelPoints = elevations.Select(r => new PointF(0, r)).ToArray(); m.TransformPoints(modelPoints); // 增加一定高度以放置字符 float stringHight = 15f; for (int j = 0; j < modelPoints.Length; j++) { modelPoints[j].Y -= stringHight; } // 写字 Pen blackPen = new Pen(Color.Black); Font ft = new Font("Times New Romans", 10, FontStyle.Regular); // "Arial" int i = 0; foreach (var ele in elevations) { g.DrawLine(blackPen, new PointF(0, modelPoints[i].Y + stringHight), new PointF(_daNotations.Width, modelPoints[i].Y + stringHight)); g.DrawString(ele.ToString("0.0"), ft, new SolidBrush(c), modelPoints[i]); i += 1; } }
/// <summary> /// /// </summary> /// <param name="filePath">此路径必须为一个有效的路径</param> private void ImportFromXml(string filePath) { try { // XmlReader xr = XmlReader.Create(filePath); // XmlSerializer ss = new XmlSerializer(typeof(SocketedShaftSystem)); SocketedShaftSystem sss = (SocketedShaftSystem)ss.Deserialize(xr); xr.Close(); // 同步到全局 SocketedShaftSystem.SetUniqueInstance(sss); // this.RefreshModel(sss); // 绘图 RefreshPaintingWithSss(_sss); } catch (Exception ex) { DebugUtils.ShowDebugCatch(ex, "指定的文件不能正常导入为嵌岩桩模型。"); } }
private static SocketedShaftSystem GetSSS(string xmlFile) { SocketedShaftSystem sss = SocketedShaftSystem.GetUniqueInstance(); return(sss); }
// 绘图 private void RefreshPaintingWithSss(SocketedShaftSystem sss) { _drawing.Draw(_sss); }
public void Draw(SocketedShaftSystem sss) { DrawOnImage(sss); }