/// <summary> /// 绘制线设备 /// </summary> /// <param name="layerId"></param> /// <param name="_esymb"></param> /// <param name="color"> </param> /// <param name="strLineType"></param> /// <param name="lineWidth"></param> /// <param name="xmlDbManager"> </param> public static void AddLineSymbol(ObjectId layerId, ElectronSymbol _esymb, Color color, string strLineType, double lineWidth, XmlDBManager xmlDbManager) { var index = 0; try { AddBasePoint(_esymb); var symbolEventArgs = GetSymbolExecution(_esymb, lineWidth, color, xmlDbManager); var line = DCadApi.SetPolyline(layerId, symbolEventArgs.color, strLineType); foreach (var point in (_esymb.G3E_GEOMETRY as LineString).Points) { line.AddVertexAt(index, new Point2d(point.X, point.Y), 0.0, symbolEventArgs.lineWidth / MapConfig.Instance.earthscale, symbolEventArgs.lineWidth / MapConfig.Instance.earthscale); index++; } DCadApi.AddLabelPinchPoint(line); var objectId = PublicMethod.Instance.ToModelSpace(line); PublicMethod.Instance.dicObjIds.Add(objectId, _esymb); //是否是其他馈线 if (!_esymb.KxType) { PublicMethod.Instance.AddDBSymbolFinder(objectId, _esymb); var extents = line.GeometricExtents; DCadApi.AddDBSymbolLTTIDFinder(_esymb, extents, symbolEventArgs.SBMC, objectId); } } catch (Exception ex) { LogManager.Instance.Error(ex); } }
/// <summary> /// 在cad指定图层上添加多个电力符号 /// </summary> /// <param name="_layerName">图层名称</param> /// <param name="_esymbs">多个电力符号对象</param> /// <param name="color"> </param> /// <param name="strLineType"> </param> /// <param name="lineWidth"> </param> /// <param name="xmlDbManager"> </param> /// <returns></returns> private static void AddElectronSymbol(string _layerName, IEnumerable <ElectronSymbol> _esymbs, CADColor color, string strLineType, double lineWidth, XmlDBManager xmlDbManager) { try { if (!_esymbs.Any()) { return; } //添加图层 var LayerId = DCadApi.addLayer(_layerName, CADColor.FromRgb(255, 255, 255)); if (LayerId != ObjectId.Null) { foreach (var _ee in _esymbs) { //保存原始的FID _ee.OriginalG3e_Fid = _ee.G3E_FID; if (_ee.KxType) { //其他馈线统一在 lock 图层上 var lockcolor = CADColor.FromRgb(51, 51, 51); var lockId = DCadApi.addLayer("lock", lockcolor); AddElectronSymbol(lockId, _ee, lockcolor, strLineType, lineWidth, xmlDbManager); continue; } //加载符号 AddElectronSymbol(LayerId, _ee, color, strLineType, lineWidth, xmlDbManager); } } } catch (Exception exx) { LogManager.Instance.Error(exx); } }
private void AddDX(Dictionary <ObjectId, LateralLineData> dxObjIdList /*,string sbGh*/) { var strObjID = ObjectId.Null; var endObjID = ObjectId.Null; //var dxH = int.Parse(sbGh); foreach (var item in dxObjIdList) { //var dxMc = string.Format("#{0}线", dxH); //GenerateHelper.SetPropertyValue(dxXprops, "SBMC", LateralName + dxMc); //添加导线 DCadApi.InsertSymbol(item.Key, dxXprops, 141, item.Value.lineString); var angle = item.Value.lineAngle; //添加标注 DCadApi.AddSymbolLabel(item.Key, angle); if (!item.Value.startObjID.IsNull) { strObjID = item.Value.startObjID; } if (!item.Value.endObjID.IsNull) { endObjID = item.Value.endObjID; } //dxH++; } //不是连续导线的时候自动添加连接关系 if (!Ck_dllx.Checked) { AutoTopology(strObjID, endObjID); } }
private void AddDG(IEnumerable <ObjectId> dgObjIdList, string dgH) { var ghIndex = 0; var isInteger = int.TryParse(dgH, out ghIndex); //添加杆 foreach (var objId in dgObjIdList) { var gh = string.Empty; if (isInteger) { gh = string.Format("#{0}", ghIndex); } else { gh = string.Format("#{0}", dgH); } string dgSbmc = string.Format("{0}{1}{2}", LateralName, gh, DevStr); GenerateHelper.SetPropertyValue(dgXprops, "Gg_gz_dg_n", "GH", gh); GenerateHelper.SetPropertyValue(dgXprops, "Common_n", "SBMC", dgSbmc); DxCommonToDg(); DCadApi.InsertSymbol(objId, dgXprops, 201, null); DCadApi.AddSymbolLabel(objId, 0); ghIndex++; } //添加包含关系 AutoContain(); }
private void Set_View(ObjectIdList objs) { YxlistView.BeginUpdate(); ObjectId objid; long fno = 0, fid = 0, id = 0; string typeName; YxlistView.Clear(); for (var i = 0; i < objs.Count; i++) { var lvi = new ListViewItem(); objid = objs.ElementAt(i); DBEntityFinder.Instance.GetG3EIds(objid, ref id, ref fid, ref fno); if (FeatureMapping.instance.features.Keys.Contains(fno.ToString())) { typeName = FeatureMapping.instance.features[fno.ToString()]; } else { typeName = "xxxxx"; PublicMethod.Instance.Editor.WriteMessageWithReturn("FeatureMapping字典没有此fno" + fno + "设备"); } var devName = DCadApi.getDevNamebyfidfno(fid, fno); lvi.Tag = objid; lvi.ImageIndex = i; lvi.Text = (i + 1) + @" " + typeName + @" " + devName; YxlistView.Items.Add(lvi); } YxlistView.EndUpdate(); }
/// <summary> /// 获取导线样式 /// </summary> /// <param name="dx"></param> /// <returns></returns> private InsertSymbolEventArgs GetDxStyle(XProps dx) { var lineStyle = DCadApi.InitializeInsertSymbolValue(141, dx, null); lineStyle.lineWidth = lineStyle.lineWidth / MapConfig.Instance.earthscale; return(lineStyle); }
/// <summary> /// 初始化面板view控件 /// </summary> /// <param name="nodeList"></param> public void InitializeList(List <ObjectId> nodeList) { Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen(); //this.ConnlistView.View = View.List; ConnlistView.SmallImageList = imageList1; ConnlistView.BeginUpdate(); ObjectId objid; long fno = 0, fid = 0, id = 0; string typeName; //nodeList.Clear(); ConnlistView.Clear(); for (int i = 0; i < nodeList.Count; i++) //for (int i = nodeList.Count - 1; i >= 0; i--) { var lvi = new ListViewItem(); objid = nodeList.ElementAt(i); DBEntityFinder.Instance.GetG3EIds(objid, ref id, ref fid, ref fno); if (FeatureMapping.instance.features.Keys.Contains(fno.ToString())) { typeName = FeatureMapping.instance.features[fno.ToString()]; } else { typeName = "xxxxx"; PublicMethod.Instance.Editor.WriteMessageWithReturn("FeatureMapping字典没有此fno" + fno + "设备"); } string devName = DCadApi.getDevNamebyfidfno(fid, fno); lvi.Tag = objid; //lvi.ImageIndex = i; lvi.Text = (i + 1) + @" " + typeName + @" " + devName; ConnlistView.Items.Add(lvi); } ConnlistView.EndUpdate(); }
/// <summary> /// 加载标注 /// </summary> /// <param name="xmlDBManager"> </param> /// <param name="layerLableName">层名称</param> /// <param name="className">类型名称</param> /// <param name="index"></param> private void LoadSymbolLabel(XmlDBManager xmlDBManager, string layerLableName, string className, int index) { try { var type = TypeCache.Instance.GetTypeFromCache(typeof(DBEntity), className); if (xmlDBManager.Has(type)) { var lb = xmlDBManager.GetEntities(type).Cast <ElectronSymbol>().ToList(); //大于0,则有多个标注 if (index > 0) { lb.ForEach(o => o.FinderFuncNumber = o.G3E_FNO * 10 + index); } else { lb.ForEach(o => o.FinderFuncNumber = o.G3E_FNO); } var lbs = GetLabel_lb_sdogeom(xmlDBManager, className); DCadApi.addLabelLayer(layerLableName, lb, lbs, CADColor.FromRgb(255, 255, 255), xmlDBManager); } } catch (Exception ex) { LogManager.Instance.Error(ex); } }
private void LoadFixMapToolStripMenuItem_Click(object sender, EventArgs e) { if (!PublicMethod.Instance.IsExecuteSystemCMD("")) { DCadApi.LoadFixMap(); } }
/// <summary> /// 更新选择的同类设备自身属性 /// </summary> public UpdataResult UpdataSelfAttribute(ref List <BulkChangeEnt> Current, XProps objDev) { UpdataResult ur = new UpdataResult(); try { DCadApi.isModifySymbol = true; foreach (var ent in Current) { try { var value = DevEventHandler.GetDevTables(ent.SingleG3EObject.G3E_FNO, ent.SingleG3EObject.G3E_FID); if (value.DevObj != null) { PartialCopy(objDev, value.DevObj); //查找看看该设备是否有符号,有的就要根据属性更新符号 ObjectId objId = DBEntityFinder.Instance.GetObjectIdByFid(ent.SingleG3EObject.G3E_FID); if (objId.IsNull) { UpdateAttribute(value, value.DevObj, false); ur.UpdataSucceedNum++; } else { ObjectId newObjId = ObjectId.Null; bool isUpdate = DCadApi.UpdateSymbol(objId, value.DevObj, out newObjId); if (isUpdate) { UpdateAttribute(value, value.DevObj, false); ur.UpdataSucceedNum++; } else { //存放更新失败的设备 ur.UpdataFailedNum++; ur.UpdataErrorLog.AppendLine("Fid=" + ent.SingleG3EObject.G3E_FID + "的设备更新失败"); } } } PublicMethod.Instance._isSelectedEntityChoice = false; } catch (Exception) { ur.UpdataFailedNum++; ur.UpdataErrorLog.AppendLine("Fid=" + ent.SingleG3EObject.G3E_FID + "的设备更新失败"); } } } catch (Exception ex) { LogManager.Instance.Error(ex); } finally { DCadApi.isModifySymbol = false; } return(ur); }
private static ObjectId AddToModelSpace(BlockReference reference) { //添加夹点 DCadApi.AddPinchPoint(reference); //添加符号-标注标记 DCadApi.AddLabelPinchPoint(reference); //添加到模型空间 return(PublicMethod.Instance.ToModelSpace(reference)); }
/// <summary> /// 加载符号库 /// </summary> private void LoadSymbolicLibrary() { CABLEManager.ParcentHandler -= CABLEManager_ParcentHandler; CABLEManager.ParcentHandler += CABLEManager_ParcentHandler; var symbolLibraryPath = DBEntityFinder.Instance.SymbolLibraryPath; //加载块定义 DCadApi.LoadBolckDefinition(symbolLibraryPath); }
/// <summary> /// 添加标注 /// </summary> /// <param name="g3eObject"></param> /// <param name="labelFlagFno"></param> /// <param name="labelClassName"></param> /// <param name="G3E_CNO"></param> /// <param name="lea"></param> /// <returns></returns> public static bool AddLabel(G3EObject g3eObject, int labelFlagFno, string labelClassName, int G3E_CNO, LabelEventArgs lea) { var result = false; try { var values = SimpleDBSymbolsConfig.Instance.DBSymbol.SingleOrDefault(o => o.G3E_FNO == g3eObject.G3E_FNO); var layerID = DCadApi.addLayer(string.Format("{0}标注", values.OtherProperty.LayerName)); var lbHeight = lea.lbHeight / MapConfig.Instance.earthscale; var mText = AddText(lea.lbText, Point3d.Origin, 0, lbHeight, layerID, lea.color); if (BlockJig.Jig(mText, true)) { DCadApi.AddPinchPoint(mText); DCadApi.AddLabelPinchPoint(mText); var objId = PublicMethod.Instance.ToModelSpace(mText); var mpt = ConvertGeometry.Instance.GetMultipoint(objId); //查询原设备删除的标注 var labelPt = DBEntityFinder.Instance.GetDBEntityByG3efidOrClassName(g3eObject.G3E_FID, labelClassName, EntityState.Delete); //原设备删除 if (labelPt != null) { var labelObject = DBEntityFinder.Instance.GetEraseStateLabel(g3eObject.G3E_FID, labelFlagFno); if (!labelObject.Key.IsNull) { //删除缓存 DBSymbolFinder.Instance.Remove(labelObject.Key); } var pt = labelPt.Clone() as ElectronSymbol; pt.G3E_GEOMETRY = mpt; pt.IsErased = false; pt.EntityState = EntityState.Update; DBManager.Instance.Update(pt); UpdateLabelLB(pt); //新增 PublicMethod.Instance.AddDBSymbolFinder(objId, pt); } else { ErasedCacheLabel(labelClassName, g3eObject.G3E_FID); var pt = CreateLabel(g3eObject, mpt, labelClassName, G3E_CNO, labelFlagFno); PublicMethod.Instance.AddDBSymbolFinder(objId, pt); } result = true; } } catch (Exception ex) { LogManager.Instance.Error(ex); } return(result); }
private static ObjectId AddEntity(Entity entity, ElectronSymbol _esymb) { DCadApi.AddPinchPoint(entity); DCadApi.AddLabelPinchPoint(entity); var objectId = PublicMethod.Instance.ToModelSpace(entity); PublicMethod.Instance.dicObjIds.Add(objectId, _esymb); using (PublicMethod.Instance.acDoc.LockDocument()) { PublicMethod.Instance.AddDBSymbolFinder(objectId, _esymb); } return(objectId); }
private static void AddLabel(ElectronSymbol pt, string layerName, Point3d position, double rotation, LabelEventArgs value) { var layerId = DCadApi.addLayer(layerName); //打开图层再添加标注 PublicMethod.Instance.SetLayerDisplay(layerId, false); //标注高度 var lbHeight = value.lbHeight / MapConfig.Instance.earthscale; var mText = AddText(value.lbText, position, rotation, lbHeight, layerId, value.color, 5); var objectId = AddEntity(mText, pt); PublicMethod.Instance.AddDBSymbolFinder(objectId, pt); }
/// <summary> /// 高亮显示 /// </summary> /// <param name="oc"></param> /// <returns></returns> private static Dictionary <ObjectId, CADColor> Entityhighlight(IEnumerable oc) { var dic = new Dictionary <ObjectId, CADColor>(); foreach (ObjectId objectId in oc) { var oldColor = DCadApi.EditorPointSymbol(objectId, CADColor.FromRgb(0, 255, 0)); if (!dic.ContainsKey(objectId)) { dic.Add(objectId, oldColor); } } return(dic); }
private void btSave_Click(object sender, EventArgs e) { if (MessageBox.Show("确定要新增或修改吗!!!", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK) { btSave.Enabled = true; return; } try { if (isModify) { var value = DevEventHandler.GetDevTables(198, g3eFid); UpdateAttribute((XProps)pgSwitchCabinet.SelectedObject, value.ComObj, value.SelfObj, value.GnwzObj, false); //DBSymbolLTTIDFinder.Instance[g3eFid].SBMC = value.ComObj.SBMC; int idx = dict.SingleOrDefault(o => o.Value == g3eFid).Key; lbSwitchCabinetcol.Items[idx] = string.IsNullOrEmpty(value.ComObj.SBMC)?value.ComObj.G3E_FID.ToString():value.ComObj.SBMC; //lbSwitchCabinetcol.SetSelected(devIndex, true); } if (isBulkModify) { foreach (var item in dict) { var value = DevEventHandler.GetDevTables(198, item.Value); UpdateAttribute((XProps)pgSwitchCabinet.SelectedObject, value.ComObj, value.SelfObj, value.GnwzObj, true); } } if (isAdd) { var kggRes = DCadApi.AddAttribute((XProps)pgSwitchCabinet.SelectedObject, 198, dfG3eFid); var prevCur = kggRes; dict.Add(lbSwitchCabinetcol.Items.Count, long.Parse(prevCur.G3eFid)); lbSwitchCabinetcol.Items.Add(string.IsNullOrEmpty(prevCur.DeviceSbmc)?prevCur.G3eFid.ToString():prevCur.DeviceSbmc); g3eFid = long.Parse(prevCur.G3eFid); lbSwitchCabinetcol.SetSelected(lbSwitchCabinetcol.Items.Count - 1, true); } isModify = false; isAdd = false; } catch (Exception ex) { LogManager.Instance.Error(ex); } finally { ResetSwitch(true); pgSwitchCabinet.Enabled = false; } }
/// <summary> /// 加载图形 /// </summary> /// <param name="_layerName"></param> /// <param name="esymbs"></param> /// <param name="color"></param> /// <param name="strLineType"></param> /// <param name="lineWidth"></param> private void AddElectronSymbol(string _layerName, IEnumerable <ElectronSymbol> esymbs, CADColor color, string strLineType, double lineWidth) { if (esymbs.Any()) { //添加图层 var layerId = DCadApi.addLayer(_layerName, CADColor.FromRgb(255, 255, 255)); if (layerId != ObjectId.Null) { foreach (var _ee in esymbs) { //加载符号 AddElectronSymbol(layerId, _ee, color, strLineType, lineWidth); } } } }
/// <summary> /// 更新点设备图形 /// </summary> /// <param name="objectId"></param> /// <param name="pt"></param> private void UpdatePointGraph(ObjectId objectId, ElectronSymbol pt) { try { var newObjectId = ObjectId.Null; var psd = DCadApi.GetSymbolDataByObjId(objectId); //获取点设备样式 var value = GetPointStyle(psd.color, pt); //根据符号属性获取块定义名称 var blockName = DCadApi.GetBlockDefinitionName(value, pt.G3E_FNO.ToString()); //点符号(点符号是以CAD图块的形式存在的) if (!string.IsNullOrEmpty(blockName) && !string.IsNullOrEmpty(psd.blockName)) { if (blockName != psd.blockName) { psd.blockName = blockName; psd.color = value.color; DCadApi.ReplacePointSymbol(psd, ref newObjectId); } else { //下面是针对点符号,只改变颜色的 if (psd.color != value.color) { DCadApi.EditorPointSymbol(psd.objectId, value.color); psd.color = value.color; } } } //线面符号 else { //这里是针对线改变颜色 if (psd.color != value.color) { DCadApi.EditorPointSymbol(psd.objectId, value.color); psd.color = value.color; } } } catch (Exception ex) { LogManager.Instance.Error(string.Format("更新符号失败!{0}{1}", pt.G3E_FID, ex)); } }
private static void AddZxbzSymbol(XmlDBManager xmlDBManager, ElectronTransferModel.V9_4.Gg_gl_zxbz_n zxbzn) { var zxbzGeom = DBEntityFinder.Instance.GetZxbzGeomByG3e_fid(xmlDBManager, zxbzn.G3E_FID); if (zxbzGeom != null) { //获取坐标 var point = new Point3d((zxbzGeom.G3E_GEOMETRY as Multipoint).Points[0].X, (zxbzGeom.G3E_GEOMETRY as Multipoint).Points[0].Y, 0); //获取角度 var rotateAngle = Math.Atan2((zxbzGeom.G3E_GEOMETRY as Multipoint).Points[1].Y, (zxbzGeom.G3E_GEOMETRY as Multipoint).Points[1].X); //杂项标注图层 var layerID = DCadApi.addLayer("杂项标注"); //标注大小 var lbHeight = 0.35 / MapConfig.Instance.earthscale; //标注颜色 var color = CADColor.FromRgb(0, 0, 0); if (!string.IsNullOrEmpty(zxbzn.MIF_TEXT)) { Entity tEntity; var lb = DBEntityFinder.Instance.GetLabel_LB(zxbzGeom); var alignment = DBEntityFinder.Instance.GetG3eAlignment(lb); if (zxbzn.MIF_TEXT.Contains("\n")) { tEntity = SymbolLabel.Mtext(zxbzn.MIF_TEXT, point, rotateAngle, lbHeight, layerID); } else { tEntity = SymbolLabel.AddText(zxbzn.MIF_TEXT, point, rotateAngle, lbHeight, layerID, color, alignment); } DCadApi.AddPinchPoint(tEntity); DCadApi.AddLabelPinchPoint(tEntity); //添加到当前模型中 var objectId = PublicMethod.Instance.ToModelSpace(tEntity); zxbzGeom.IsErased = false; zxbzGeom.EntityType = EntityType.ZxLabel; PublicMethod.Instance.AddDBSymbolFinder(objectId, zxbzGeom); } } }
/// <summary> /// 绘制点设备 /// </summary> /// <param name="layerId">图层id</param> /// <param name="_esymb">符号对象</param> /// <param name="color">符号颜色</param> public static void AddPointSymbol(ObjectId layerId, ElectronSymbol _esymb, CADColor color, XmlDBManager xmlDbManager) { try { var newBlockName = string.Empty; //获取gis图元样式 var value = GetSymbolExecution(_esymb, color, xmlDbManager); //根据符号属性获取块定义名称 var blockName = DCadApi.GetBlockDefinitionName(value, _esymb.G3E_FNO.ToString()); //获取CAD块定义 DCadApi.InsertBlock(blockName, ref newBlockName); var id = PublicMethod.Instance.GetBlockObjId(newBlockName); if (!id.IsNull) { AddBasePoint(_esymb); _esymb.BlockName = blockName; var reference = GetBlockReference(id, layerId, value.color, _esymb); //添加到模型数据库 var objectId = AddToModelSpace(reference); PublicMethod.Instance.dicObjIds.Add(objectId, _esymb); //保存电杆数据 AdddgList(_esymb); if (!_esymb.KxType) { //记录添加符号信息 PublicMethod.Instance.AddDBSymbolFinder(objectId, _esymb); //保存定位锁定符号信息数据 DCadApi.AddDBSymbolLTTIDFinder(_esymb, objectId, reference.Position, value.SBMC); } } else { PublicMethod.Instance.ShowMessage(string.Format("{0}符号不存在!", _esymb.G3E_FNO)); } } catch (Exception exx) { LogManager.Instance.Error(string.Format("G3E_FID:{0}{1}", _esymb.G3E_FID, exx)); } }
public void RecoverEntityColor() { PublicMethod.Instance.active = true; PublicMethod.Instance.wrapup = false; PublicMethod.Instance.echocmd = false; PublicMethod.Instance.SendCommend("re\n"); if (!IsLoadDataSource()) { return; } try { if (!PublicMethod.Instance.IsExecuteSystemCMD("rec")) { //获取工单范围的实体 var entities = DBEntityFinder.Instance.GetDevInLttID(); foreach (var item in entities) { var psd = DCadApi.GetSymbolDataByObjId(item.Key); if (psd != null) { var rdt = DevEventHandler.GetDevTables(psd.g3eObject.G3E_FNO, psd.g3eObject.G3E_FID); var ise = new InsertSymbolEventArgs { symbolObj = rdt.DevObj, g3e_fno = psd.g3eObject.G3E_FNO }; ExecutionManager.Instance.GetFactory(typeof(InsertSymbolExecutionFactory)) .GetExecution(psd.g3eObject.G3E_FNO) .Execute(null, ise); if (psd.color != ise.symbolColor) { DCadApi.EditorPointSymbol(psd.objectId, ise.symbolColor); } } } } }catch (Exception ex) { LogManager.Instance.Error(ex); } }
/// <summary> /// 复制属性 /// </summary> /// <param name="objectIds"></param> /// <param name="copySymbolObject"> </param> public static int CopyAttribute(ObjectId[] objectIds, CopySymbolObject copySymbolObject) { var copyCount = 0; //获取原设备的样式 var eventArgs = CABLEManager.GetSymbolExecution(copySymbolObject.objectID, copySymbolObject.g3eObject, DBManager.Instance as XmlDBManager); if (eventArgs != null) { //获取原设备的块定义名称 var blockName = DCadApi.GetBlockDefinitionName(eventArgs, copySymbolObject.g3eObject.G3E_FNO.ToString()); foreach (var objectId in objectIds) { G3EObject g3eObject = null; var dbObject = PublicMethod.Instance.GetObject(objectId, OpenMode.ForRead); //排除标注 if (dbObject is BlockReference || dbObject is Polyline) { if (DBEntityFinder.Instance.GetG3EIds(objectId, ref g3eObject)) { //校验工单 if (DBEntityFinder.Instance.VerifyLTTID(objectId)) { //判断类型 if (copySymbolObject.g3eObject.G3E_FNO == g3eObject.G3E_FNO) { foreach (var dbEntity in copySymbolObject.hsDBEntity) { SetBrotherDBEntity(dbEntity, g3eObject); } //更新符号 UpdateSymbol(blockName, objectId, eventArgs); copyCount++; } } } } } } return(copyCount); }
/// <summary> /// 新增符号 /// </summary> /// <param name="symbolPath">符号路径</param> /// <param name="blockName">块名称</param> private void AddSymbol(string symbolPath, string blockName) { try { isInsertSymbol = true; //单个设备新增 if (!IsCustomGroup()) { //特殊符号处理 var sdf = new SpecilaDevField { Ssbyq = GenerateHelper.Unrf.byqFid, Ssgt = GenerateHelper.Unrf.gtFid, Sstj = GenerateHelper.Unrf.tjFid, Sskgg = GenerateHelper.Unrf.kggFid, Ssdf = GenerateHelper.Unrf.dfFid, Sstqhtj = GenerateHelper.Unrf.tqtjFid, SsZx = GenerateHelper.Unrf.zxFid }; //记忆公共属性 AddDevToDict(CurrentFno, CurPropertyObj); //实体存在的点符号 DCadApi.InsertSymbol(File.Exists(symbolPath) ? blockName : symbolPath, CurPropertyObj, sdf); } else { //插入自定义符号 if (File.Exists(symbolPath)) { CustomSymbol.LoadSymbolSetXMl(symbolPath, blockName); } } isInsertSymbol = false; }catch { isInsertSymbol = false; } }
/// <summary> /// 在cad指定图层上添加多个标注 /// </summary> /// <param name="_layerName">图层名称</param> /// <param name="_esymb">多个标注对象</param> /// <param name="lbs"> </param> /// <param name="color"> </param> /// <param name="xmlDbManager"> </param> /// <returns></returns> public static void addLabelLayer(string _layerName, IEnumerable <ElectronSymbol> _esymb, IEnumerable <ElectronBase> lbs, CADColor color, XmlDBManager xmlDbManager) { try { var objId = DCadApi.addLayer(_layerName, CADColor.FromRgb(255, 255, 255)); if (objId != ObjectId.Null) { foreach (var _ee in _esymb) { if (_ee.EntityState == EntityState.Insert) { //var g3e_cno = _ee.GetValue<int>("G3E_CNO"); var lb = DCadApi.GetLabel_LB(lbs, _ee.G3E_FID); DCadApi.addLabelLayer(objId, _ee, lb, color, xmlDbManager); } } } } catch (Exception exx) { LogManager.Instance.Error(exx); } }
/// <summary> /// 坐标定位 /// </summary> /// <param name="X">定位点X坐标</param> /// <param name="Y">定位点Y坐标</param> /// <param name="flag">是否显示标记</param> public void CoordinateFix(double X, double Y, bool flag) { using (Transaction trans = PublicMethod.Instance.acDoc.TransactionManager.StartTransaction()) { using (PublicMethod.Instance.acDoc.LockDocument()) { PublicMethod.Instance.SendCommend("zoom\n" + "c\n" + string.Format("{0},{1} ", X, Y) + "0.4865222729561714810200100517294e-4" + "\n"); if (flag) { DBPoint pt = new DBPoint(); pt.Position = new Point3d(X, Y, 0); pt.ColorIndex = 1; var layerId = DCadApi.addLayer("标记层"); pt.LayerId = layerId; PublicMethod.Instance.DB.AddToModelSpace(pt); coordinateObjId = pt.ObjectId; trans.Commit(); PublicMethod.Instance.wrapup = false; PublicMethod.Instance.SendCommend("PDMODE\n" + "99\n"); } } } }
public void UpdateAttribute(XProps CurPropertyObj, ref ObjectId objId, RequiredDevTables rdt) { if (rdt == null || objId.IsNull || CurPropertyObj == null) { return; } ObjectId newObjId = ObjectId.Null; //只有块才可以更换符号 if (!DCadApi.UpdateSymbol(objId, CurPropertyObj, out newObjId)) { objId = newObjId; } else { FixEntity.Instance.ResetEntityRecord(newObjId, objId); if (objId != newObjId) { objId = newObjId; } } UpdateAttribute(rdt, CurPropertyObj, false); }
/// <summary> /// 更新 /// </summary> /// <param name="sourceBlockName">原设备块定义名称</param> /// <param name="targetObjId">目标对象</param> /// <param name="eventArgs">设备样式</param> private static void UpdateSymbol(string sourceBlockName, ObjectId targetObjId, SymbolEventArgs eventArgs) { try { var targetBlockName = string.Empty; //获取目标设备块定义名称 var entity = PublicMethod.Instance.GetObject(targetObjId, OpenMode.ForRead); if (entity is BlockReference) { targetBlockName = (entity as BlockReference).Name; } var objId = ObjectId.Null; //获取目标设备对象数据 var psd = DCadApi.GetSymbolDataByObjId(targetObjId); if (!string.IsNullOrEmpty(sourceBlockName) && !sourceBlockName.Equals(targetBlockName) && entity is BlockReference) { psd.blockName = sourceBlockName; psd.color = eventArgs.color; //更新设备 DCadApi.ReplacePointSymbol(psd, ref objId); } else { //这里是针对线改变颜色 if (psd.color != eventArgs.color) { //更新颜色 DCadApi.EditorPointSymbol(psd.objectId, eventArgs.color); psd.color = eventArgs.color; } } } catch (Exception ex) { LogManager.Instance.Error(ex); } }
/// <summary> /// 更新公共属性 /// </summary> public UpdataResult UpdataCommonAttribute(ref List <BulkChangeEnt> Current, XProps objDev) { UpdataResult ur = new UpdataResult(); try { DCadApi.isModifySymbol = true; foreach (var ent in Current) { try { //查看是否有没有公共属性表 var simpleEntry = DeviceAttributeConfig.Instance.Attributes.SingleOrDefault(o => o.Fno == ent.SingleG3EObject.G3E_FNO); if (simpleEntry != null) { if (!simpleEntry.Common.PropertiesFromTable.Any()) { ur.UpdataFailedNum++; ur.UpdataErrorLog.AppendLine(ent.SingleG3EObject.G3E_FID.ToString() + "没有公共属性表"); continue; } } } catch (Exception) { ur.UpdataFailedNum++; //ur.UpdataErrorLog.AppendLine("CAD实体查找错误,ObjectID="+ent.SingleG3EObject.G3E_FID); } #region try { var value = DevEventHandler.GetDevTables(ent.SingleG3EObject.G3E_FNO, ent.SingleG3EObject.G3E_FID); if (value.DevObj != null) { PartialCopy(objDev, value.DevObj); //查找看看该设备是否有符号,有的就要根据属性更新符号 ObjectId objId = DBEntityFinder.Instance.GetObjectIdByFid(ent.SingleG3EObject.G3E_FID); if (objId.IsNull) { UpdateAttribute(value, value.DevObj, true); ur.UpdataSucceedNum++; } else { ObjectId newObjId = ObjectId.Null; bool isUpdate = DCadApi.UpdateSymbol(objId, value.DevObj, out newObjId); if (isUpdate) { UpdateAttribute(value, value.DevObj, true); ur.UpdataSucceedNum++; } else { //存放更新失败的设备 ur.UpdataFailedNum++; ur.UpdataErrorLog.AppendLine("Fid=" + ent.SingleG3EObject.G3E_FID + "的设备更新失败 "); } } } } catch (Exception) { ur.UpdataFailedNum++; ur.UpdataErrorLog.AppendLine("Fid=" + ent.SingleG3EObject.G3E_FID + "的设备更新失败 "); } PublicMethod.Instance._isSelectedEntityChoice = false; #endregion } } catch (Exception ex) { LogManager.Instance.Error(ex); } finally { DCadApi.isModifySymbol = false; } return(ur); }
/// <summary> /// 更新指定的实体属性 /// </summary> /// <param name="values"></param> /// <param name="objDev"></param> /// <param name="flag">是否是批量修改公共表</param> private void UpdateAttribute(RequiredDevTables values, XProps objDev, bool flag) { try { DCadApi.isModifySymbol = true; #region if (values.Fno == 148) { var currentAzwz = GenerateHelper.GetPropertyValue(objDev, GenerateHelper.GetGnwzTableNameByFno(148), "GNWZ_FL2"); string oldAzwz = string.Empty; if (values.GnwzObj != null) { oldAzwz = values.GnwzObj.GNWZ_FL2; } //安装位置由非台架变成台架 if (currentAzwz != null && currentAzwz.ToString().Equals("台架")) { //以前是台架只需更新 if (oldAzwz.Equals("台架")) { RefAttribute(objDev, values, 148, flag); //因为都是台架所以更新完148后还要更新199, long tjFid = 0; if (values.GnwzObj != null && long.TryParse(values.GnwzObj.GNWZ_SSTJ, out tjFid)) { var tjTables = DevEventHandler.GetDevTables(199, tjFid); RefAttribute(objDev, tjTables, 199, flag); } } else //以前为空或不是台架 { //先添加一条台架记录 //注意在添加新的台架数据之前先看看有没有对应的原始的台架数据(即被标记为Delete的数据) try { var tj = DBManager.Instance.GetEntity <Gg_gz_tj_n>(o => o.HasAttribute("GNWZ_FID") && o.GNWZ_FID != null && o.GNWZ_FID.Equals(values.Fid.ToString())); if (tj != null) { tj.EntityState = EntityState.Update; tj.IsErased = false; DBManager.Instance.Update(tj); var tjcom = DBManager.Instance.GetEntity <Common_n>(tj.G3E_FID); if (tjcom != null) { tjcom.EntityState = EntityState.Update; tjcom.IsErased = false; DBManager.Instance.Update(tjcom); } var tjGnwz = DBManager.Instance.GetEntity <Gg_pd_gnwzmc_n>(tj.G3E_FID); if (tjGnwz != null) { tjGnwz.EntityState = EntityState.Update; tjGnwz.IsErased = false; DBManager.Instance.Update(tjGnwz); } GenerateHelper.Unrf.tjFid = tj.G3E_FID.ToString(); var tjTables = DevEventHandler.GetDevTables(199, tj.G3E_FID); RefAttribute(objDev, tjTables, 199, flag); } else { var tjRes = DCadApi.AddAttribute(objDev, 199, values.Fid); GenerateHelper.Unrf.tjFid = tjRes.G3eFid; } } catch (NotExistException ex) { var tjRes = DCadApi.AddAttribute(objDev, 199, values.Fid); GenerateHelper.Unrf.tjFid = tjRes.G3eFid; } RefAttribute(objDev, values, 148, flag); } } //安装位置由台架变成非台架 else if (currentAzwz == null || !currentAzwz.ToString().Equals("台架")) { //以前是台架只需删除 if (oldAzwz.Equals("台架")) { //先删除台架数据 DBEntityErased.Instance.ErasedTjDBEntity(values.ComObj.G3E_FID, new List <DBEntity>()); //把变压器的GNWZ_SSTJ变成null GenerateHelper.Unrf.tjFid = null; //GenerateHelper.SetPropertyValue(objDev, "GNWZ_SSTJ", null); if (values.GnwzObj != null) { values.GnwzObj.GNWZ_SSTJ = null; } RefAttribute(objDev, values, 148, flag); } else { RefAttribute(objDev, values, 148, flag); } } } else { RefAttribute(objDev, values, values.Fno, flag); } UpdataShbAdnJlbValue(values.Fno, values.Fid); #endregion } catch (Exception ex) { LogManager.Instance.Error(ex); } finally { DCadApi.isModifySymbol = false; } }