//2.定义张拉方式改变时的处理函数 //通过将两列CheckBox设置为ReadOnly=true状态,通过程序实现点击后的变化,并添加对应的事件 //事件主要包括两方面:一是不允许两侧均不张拉;二是更新伸长量数据 private void dataGridViewTendons_CellContentClick(object sender, DataGridViewCellEventArgs e) { #region 当修改左侧张拉方式 if (dataGridViewTendons.CurrentCell.ColumnIndex == 4) { Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { ObjectId tdId = tdIdsInTable[dataGridViewTendons.CurrentRow.Cells[10].Value.ToString()]; //获取本行钢束线的ObjectId Polyline td = tdId.GetObject(OpenMode.ForRead) as Polyline; //获取本行钢束线 if ((bool)dataGridViewTendons.CurrentRow.Cells[4].Value == true) //如果左侧目前为张拉状态 { dataGridViewTendons.CurrentRow.Cells[4].Value = false; //点击后变为不张拉状态 dataGridViewTendons.CurrentRow.Cells[5].Value = true; //右侧则必须为张拉状态 //左侧引伸量 dataGridViewTendons.CurrentRow.Cells[6].Value = "0"; //右侧引伸量 dataGridViewTendons.CurrentRow.Cells[7].Value = td.SingleDrawAmount(ctrlStress, kii, miu, 1, Ep).ToString("F0"); } else if ((bool)dataGridViewTendons.CurrentRow.Cells[4].Value == false) //左侧目前为不张拉状态 { dataGridViewTendons.CurrentRow.Cells[4].Value = true; //左侧点击后变为张拉状态 //左侧引伸量 dataGridViewTendons.CurrentRow.Cells[6].Value = td.BothDrawAmount(ctrlStress, kii, miu, Ep)[0].ToString("F0"); //右侧引伸量 dataGridViewTendons.CurrentRow.Cells[7].Value = td.BothDrawAmount(ctrlStress, kii, miu, Ep)[1].ToString("F0"); } trans.Commit(); } } #endregion #region 当修改右侧张拉方式 if (dataGridViewTendons.CurrentCell.ColumnIndex == 5) { Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { ObjectId tdId = tdIdsInTable[dataGridViewTendons.CurrentRow.Cells[10].Value.ToString()]; //获取本行钢束线的ObjectId Polyline td = tdId.GetObject(OpenMode.ForRead) as Polyline; //获取本行钢束线 if ((bool)dataGridViewTendons.CurrentRow.Cells[5].Value == true) //如果右侧目前为张拉状态 { dataGridViewTendons.CurrentRow.Cells[5].Value = false; //点击后变为不张拉状态 dataGridViewTendons.CurrentRow.Cells[4].Value = true; //左侧则必须为张拉状态 //左侧引伸量 dataGridViewTendons.CurrentRow.Cells[6].Value = td.SingleDrawAmount(ctrlStress, kii, miu, -1, Ep).ToString("F0"); //右侧引伸量 dataGridViewTendons.CurrentRow.Cells[7].Value = "0"; } else if ((bool)dataGridViewTendons.CurrentRow.Cells[5].Value == false) //右侧目前为不张拉状态 { dataGridViewTendons.CurrentRow.Cells[5].Value = true; //右侧点击后变为张拉状态 //左侧引伸量 dataGridViewTendons.CurrentRow.Cells[6].Value = td.BothDrawAmount(ctrlStress, kii, miu, Ep)[0].ToString("F0"); //右侧引伸量 dataGridViewTendons.CurrentRow.Cells[7].Value = td.BothDrawAmount(ctrlStress, kii, miu, Ep)[1].ToString("F0"); } trans.Commit(); } } #endregion }
/// <summary> /// 将多段线钢束中的Xrecord信息读入到表格中 /// 没有Xrecord则按默认值输入 /// </summary> /// <param name="tdInfo">窗体</param> /// <param name="td">钢束多段线</param> /// <param name="kii">管道偏差系数(1/m)</param> /// <param name="miu">摩阻系数</param> /// <param name="Ep">钢束弹模(MPa)</param> /// <param name="ctrlStress">张拉控制应力(MPa)</param> /// <param name="workLen">工作长度(mm)</param> /// <returns>新加行的行号</returns> public static int?ReadXRecordToRow(TendonInfo tdInfo, Polyline td, double kii, double miu, double Ep, double ctrlStress, double workLen) { int index = tdInfo.dataGridViewTendons.Rows.Add(); //添加新行 int tdDrawStyle = 0; //张拉方式 #region 1.钢束名称 if (td.ExtensionDictionary.IsNull || td.ObjectId.GetXrecord("tdName") == null) { TypedValueList values = new TypedValueList(); values.Add(DxfCode.Text, $"F{1 + index}"); td.ObjectId.AddXrecord("tdName", values); tdInfo.dataGridViewTendons.Rows[index].Cells[0].Value = $"F{1 + index}"; } else//如果存在该键值,采用Xrecord中记录的信息 { string tdName = (string)td.ObjectId.GetXrecord("tdName")[0].Value; tdInfo.dataGridViewTendons.Rows[index].Cells[0].Value = tdName; } #endregion #region 2.钢束规格 if (td.ExtensionDictionary.IsNull || td.ObjectId.GetXrecord("tdStyle") == null) { TypedValueList values = new TypedValueList(); values.Add(DxfCode.Text, "Φ15-12"); td.ObjectId.AddXrecord("tdStyle", values); tdInfo.dataGridViewTendons.Rows[index].Cells[1].Value = "Φ15-12"; } else//如果存在该键值,采用Xrecord中记录的信息 { string tdStyle = (string)td.ObjectId.GetXrecord("tdStyle")[0].Value; tdInfo.dataGridViewTendons.Rows[index].Cells[1].Value = tdStyle; } #endregion #region 3.钢束根数 if (td.ExtensionDictionary.IsNull || td.ObjectId.GetXrecord("tdNum") == null) { TypedValueList values = new TypedValueList(); values.Add(DxfCode.Int16, 1); td.ObjectId.AddXrecord("tdNum", values); tdInfo.dataGridViewTendons.Rows[index].Cells[2].Value = "1"; } else//如果存在该键值,采用Xrecord中记录的信息 { Int16 tdNum = (Int16)td.ObjectId.GetXrecord("tdNum")[0].Value; tdInfo.dataGridViewTendons.Rows[index].Cells[2].Value = tdNum.ToString(); } #endregion #region 4.管道直径 if (td.ExtensionDictionary.IsNull || td.ObjectId.GetXrecord("tdPipeDia") == null) { TypedValueList values = new TypedValueList(); values.Add(DxfCode.Real, 90); td.ObjectId.AddXrecord("tdPipeDia", values); tdInfo.dataGridViewTendons.Rows[index].Cells[3].Value = "90"; } else//如果存在该键值,采用Xrecord中记录的信息 { double tdPipeDia = (double)td.ObjectId.GetXrecord("tdPipeDia")[0].Value; tdInfo.dataGridViewTendons.Rows[index].Cells[3].Value = tdPipeDia.ToString("F0"); } #endregion #region 5.张拉方式 if (td.ExtensionDictionary.IsNull || td.ObjectId.GetXrecord("tdDrawStyle") == null) { TypedValueList values = new TypedValueList(); values.Add(DxfCode.Int16, 0); td.ObjectId.AddXrecord("tdDrawStyle", values); tdInfo.dataGridViewTendons.Rows[index].Cells[4].Value = true; tdInfo.dataGridViewTendons.Rows[index].Cells[5].Value = true; } else//如果存在该键值,采用Xrecord中记录的信息 { tdDrawStyle = (Int16)td.ObjectId.GetXrecord("tdDrawStyle")[0].Value; switch (tdDrawStyle) { case -1: //左侧张拉 tdInfo.dataGridViewTendons.Rows[index].Cells[4].Value = true; tdInfo.dataGridViewTendons.Rows[index].Cells[5].Value = false; break; case 0: //两侧张拉 tdInfo.dataGridViewTendons.Rows[index].Cells[4].Value = true; tdInfo.dataGridViewTendons.Rows[index].Cells[5].Value = true; break; case 1: //右侧张拉 tdInfo.dataGridViewTendons.Rows[index].Cells[4].Value = false; tdInfo.dataGridViewTendons.Rows[index].Cells[5].Value = true; break; } } #endregion #region 6.引伸量 switch (tdDrawStyle) { case -1: //左侧引伸量 tdInfo.dataGridViewTendons.Rows[index].Cells[6].Value = td.SingleDrawAmount(ctrlStress, kii, miu, -1, Ep).ToString("F0"); //右侧引伸量 tdInfo.dataGridViewTendons.Rows[index].Cells[7].Value = "0"; break; case 0: //左侧引伸量 tdInfo.dataGridViewTendons.Rows[index].Cells[6].Value = td.BothDrawAmount(ctrlStress, kii, miu, Ep)[0].ToString("F0"); //右侧引伸量 tdInfo.dataGridViewTendons.Rows[index].Cells[7].Value = td.BothDrawAmount(ctrlStress, kii, miu, Ep)[1].ToString("F0"); break; case 1: //左侧引伸量 tdInfo.dataGridViewTendons.Rows[index].Cells[6].Value = "0"; //右侧引伸量 tdInfo.dataGridViewTendons.Rows[index].Cells[7].Value = td.SingleDrawAmount(ctrlStress, kii, miu, 1, Ep).ToString("F0"); break; } #endregion #region 7.钢束长度 //钢束净长 tdInfo.dataGridViewTendons.Rows[index].Cells[8].Value = td.Length.ToString("F0"); //钢束总长 tdInfo.dataGridViewTendons.Rows[index].Cells[9].Value = (td.Length + (2 - Math.Abs(tdDrawStyle)) * workLen).ToString("F0"); #endregion return(index); }
public void DrawingAmounts() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; int drwStyle = 0;//张拉方式,0为两端张拉,-1为左端张拉,1为右端张拉 //钢束总体参数 double kii = TendonGeneralParameters.Kii; double miu = TendonGeneralParameters.Miu; double Ep = TendonGeneralParameters.Ep; double ctrlStress = TendonGeneralParameters.CtrlStress; using (Transaction trans = db.TransactionManager.StartTransaction())//开始事务处理 { //1.选择钢束线 PromptEntityOptions tdLineOpt = new PromptEntityOptions("\n选择钢束或[张拉方式(D)/管道偏差系数(K)/摩阻系数(U)/张拉控制应力(C)]"); tdLineOpt.SetRejectMessage("\n钢束应为多段线"); tdLineOpt.AddAllowedClass(typeof(Polyline), true);//仅能选择多段线 tdLineOpt.Keywords.Add("D"); tdLineOpt.Keywords.Add("K"); tdLineOpt.Keywords.Add("U"); tdLineOpt.Keywords.Add("C"); tdLineOpt.AppendKeywordsToMessage = false; //提示信息中不显示关键字 for (;;) //无限循环,直到选中钢束线为止 { PromptEntityResult tdLineRes = ed.GetEntity(tdLineOpt); //2.各关键字下分别设置钢束张拉参数 if (tdLineRes.Status == PromptStatus.Keyword) { switch (tdLineRes.StringResult) { case "D": PromptIntegerOptions drwOpt = new PromptIntegerOptions($"\n输入张拉方式[两端张拉(0)/左端张拉(-1)/右端张拉(1)<{drwStyle}>"); drwOpt.AllowNone = true; PromptIntegerResult drwRes = ed.GetInteger(drwOpt); if (drwRes.Value == 0) { drwStyle = 0; } else if (drwRes.Value == -1) { drwStyle = -1; } else if (drwRes.Value == 1) { drwStyle = 1; } break; case "K": PromptDoubleOptions kiiOpt = new PromptDoubleOptions($"\n设置管道偏差系数(1/m)<{kii}>"); kiiOpt.AllowNone = true; kiiOpt.AllowNegative = false; kiiOpt.AllowZero = false; PromptDoubleResult kiiRes = ed.GetDouble(kiiOpt); if (kiiRes.Status == PromptStatus.OK) { kii = kiiRes.Value; } break; case "U": PromptDoubleOptions miuOpt = new PromptDoubleOptions($"\n设置摩阻系数<{miu}>"); miuOpt.AllowNone = true; miuOpt.AllowNegative = false; miuOpt.AllowZero = false; PromptDoubleResult miuRes = ed.GetDouble(miuOpt); if (miuRes.Status == PromptStatus.OK) { miu = miuRes.Value; } break; case "C": PromptDoubleOptions ctrOpt = new PromptDoubleOptions($"\n设置张拉控制应力(MPa)<{ctrlStress}>"); ctrOpt.AllowNone = true; PromptDoubleResult ctrRes = ed.GetDouble(ctrOpt); if (ctrRes.Status == PromptStatus.OK) { ctrlStress = ctrRes.Value; } break; } } //3.输出引伸量 else if (tdLineRes.Status == PromptStatus.OK) { ObjectId tdLineId = tdLineRes.ObjectId; Polyline tdLine = trans.GetObject(tdLineId, OpenMode.ForRead) as Polyline; if (drwStyle == 0)//两端张拉 { double[] drawAmounts = tdLine.BothDrawAmount(ctrlStress, kii, miu, Ep); ed.WriteMessage("\n左侧引伸量:" + drawAmounts[0].ToString("F0") + "; " + "右侧引伸量:" + drawAmounts[1].ToString("F0") + "。"); } else if (drwStyle == -1)//左侧张拉 { double drawAmount = tdLine.SingleDrawAmount(ctrlStress, kii, miu, -1, Ep); ed.WriteMessage("\n左侧引伸量:" + drawAmount.ToString("F0") + "。"); } else if (drwStyle == 1)//右侧张拉 { double drawAmount = tdLine.SingleDrawAmount(ctrlStress, kii, miu, 1, Ep); ed.WriteMessage("\n右侧引伸量:" + drawAmount.ToString("F0") + "。"); } break; } else { ed.WriteMessage("输入有误!"); return; } } trans.Commit();//执行事务处理 } }