private void LoadStyle() { try { this.cmbStyle.Properties.Items.Clear(); DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer; if (dffc != null) { IFeatureClass fc = dffc.GetFeatureClass(); if (fc != null) { reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString()); if (reg != null) { tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); List <FacStyleClass> list1 = FacilityInfoService.GetFacStyleByFacClassCode(reg.FacClassCode); if (list1 != null) { foreach (FacStyleClass fsc in list1) { int imageIndex = this.imageCollection1.Images.Add(fsc.Thumbnail); ImageComboBoxItem item = new ImageComboBoxItem(); item.Value = fsc; item.Description = fsc.ToString(); item.ImageIndex = imageIndex; this.cmbStyle.Properties.Items.Add(item); } for (int i = 0; i < this.cmbStyle.Properties.Items.Count; i++) { this.cmbStyle.Properties.Items[i].ImageIndex = i; } if (this.cmbStyle.Properties.Items.Count > 0) { this.cmbStyle.SelectedIndex = 0; } else { this.cmbStyle.SelectedIndex = -1; } } } } } } catch (Exception ex) { } }
private void CmdEditFacilityStyle_FacStyleClassChangedEvent(DF3DPipeCreateTool.Class.FacStyleClass style) { try { this.beforeRowBufferMap.Clear(); if (style == null) { return; } DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer; if (dffc == null) { return; } IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { return; } FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.GuidString); if (reg == null) { return; } TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); if (tc == null) { return; } FacilityClass facc = reg.FacilityType; if (facc == null) { return; } IResourceManager manager = fc.FeatureDataSet as IResourceManager; if (manager == null) { return; } IFieldInfoCollection fields = fc.GetFields(); //int indexGroupid = -1; //int indexClassify = -1; //SubClass sc = null; //MajorClass mc = LogicDataStructureManage3D.Instance.GetMajorClassByDFFeatureClassID(fc.GuidString); //if (mc != null) //{ // indexClassify = fields.IndexOf(mc.ClassifyField); // indexGroupid = fields.IndexOf("GroupId"); //} int index = fields.IndexOf("StyleId"); if (index == -1) { return; } int mnindex = fields.IndexOf("ModelName"); int mpindex = fields.IndexOf("Geometry"); if (mpindex == -1) { return; } HashMap hm = SelectCollection.Instance().GetSelectGeometrys(); if (hm != null && hm.Count == 1) { IRowBufferCollection res = new RowBufferCollection(); IRowBufferCollection rowBufferCollection = hm[dffc] as IRowBufferCollection; if (rowBufferCollection != null) { for (int i = 0; i < rowBufferCollection.Count; i++) { IRowBuffer rowBuffer = rowBufferCollection.Get(i); Fac fac = null; IModelPoint mp = null; IModel finemodel = null; IModel simplemodel = null; string name = ""; switch (facc.Name) { case "PipeNode": fac = new PipeNodeFac(reg, style, rowBuffer, tc); break; case "PipeLine": fac = new PipeLineFac(reg, style, rowBuffer, tc, false, false); break; case "PipeBuild": case "PipeBuild1": fac = new PipeBuildFac(reg, style, rowBuffer); break; } if (UCAuto3DCreate.RebuildModel(fac, style, out mp, out finemodel, out simplemodel, out name)) { if (finemodel == null || mp == null) { continue; } mp.ModelEnvelope = finemodel.Envelope; rowBuffer.SetValue(mpindex, mp); rowBuffer.SetValue(index, style.ObjectId); //if (mc != null) //{ // if (indexClassify != -1 && indexGroupid != -1) // { // } //} bool bRes = false; if (!string.IsNullOrEmpty(mp.ModelName)) { if (!manager.ModelExist(mp.ModelName)) { if (manager.AddModel(mp.ModelName, finemodel, simplemodel)) { bRes = true; } } else { if (manager.UpdateModel(mp.ModelName, finemodel) && manager.UpdateSimplifiedModel(mp.ModelName, simplemodel)) { bRes = true; } } } if (bRes) { res.Add(rowBuffer); } } } } beforeRowBufferMap[dffc] = res; //SelectCollection.Instance().Clear(); UpdateDatabase(); DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } app.Current3DMapControl.FeatureManager.RefreshFeatureClass(fc); } } catch (Exception ex) { } }
public static List <FacClassReg> GetFacClassRegsByFacilityType(string str) { IFdeCursor cursor = null; IRowBuffer row = null; try { IFeatureDataSet fds = DF3DPipeCreateApp.App.PipeLib.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(null); } IObjectClass oc = fds.OpenObjectClass("OC_FacilityClass"); if (oc == null) { return(null); } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "FacilityType='" + str + "'"; cursor = oc.Search(filter, false); List <FacClassReg> list = new List <FacClassReg>(); while ((row = cursor.NextRow()) != null) { FacClassReg fc = new FacClassReg(); if (row.FieldIndex("oid") >= 0) { object obj = row.GetValue(row.FieldIndex("oid")); if (obj != null) { fc.Id = int.Parse(obj.ToString()); } } if (row.FieldIndex("Name") >= 0) { object obj = row.GetValue(row.FieldIndex("Name")); if (obj != null) { fc.Name = obj.ToString(); } } if (row.FieldIndex("FacClassCode") >= 0) { object obj = row.GetValue(row.FieldIndex("FacClassCode")); if (obj != null) { fc.FacClassCode = obj.ToString(); } } if (row.FieldIndex("DataSetName") >= 0) { object obj = row.GetValue(row.FieldIndex("DataSetName")); if (obj != null) { fc.DataSetName = obj.ToString(); } } if (row.FieldIndex("FeatureClassId") >= 0) { object obj = row.GetValue(row.FieldIndex("FeatureClassId")); if (obj != null) { fc.FeatureClassId = obj.ToString(); } } if (row.FieldIndex("FcName") >= 0) { object obj = row.GetValue(row.FieldIndex("FcName")); if (obj != null) { fc.FcName = obj.ToString(); } } if (row.FieldIndex("DataType") >= 0) { object obj = row.GetValue(row.FieldIndex("DataType")); if (obj != null) { DataLifeCyle ts = 0; if (Enum.TryParse <DataLifeCyle>(obj.ToString(), out ts)) { fc.DataType = ts; } else { fc.DataType = 0; } } } if (row.FieldIndex("Comment") >= 0) { object obj = row.GetValue(row.FieldIndex("Comment")); if (obj != null) { fc.Comment = obj.ToString(); } } if (row.FieldIndex("TurnerStyle") >= 0) { object obj = row.GetValue(row.FieldIndex("TurnerStyle")); if (obj != null) { TurnerStyle ts = 0; if (Enum.TryParse <TurnerStyle>(obj.ToString(), out ts)) { fc.TurnerStyle = ts; } else { fc.TurnerStyle = 0; } } } if (row.FieldIndex("FacilityType") >= 0) { object obj = row.GetValue(row.FieldIndex("FacilityType")); if (obj != null) { fc.FacilityType = FacilityClassManager.Instance.GetFacilityClassByName(obj.ToString()); } } if (row.FieldIndex("LocationType") >= 0) { object obj = row.GetValue(row.FieldIndex("LocationType")); if (obj != null) { LocationType lt = 0; if (Enum.TryParse <LocationType>(obj.ToString(), out lt)) { fc.LocationType = lt; } else { fc.LocationType = 0; } } } list.Add(fc); } return(list); } catch (Exception ex) { return(null); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
private void ClickQuery() { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } try { IFeatureLayer fl = this._drawTool.GetSelectFeatureLayerPickResult().FeatureLayer; if (fl == null) { return; } int featureId = this._drawTool.GetSelectFeatureLayerPickResult().FeatureId; FacilityClass facc = Dictionary3DTable.Instance.GetFacilityClassByDFFeatureClassID(fl.FeatureClassId.ToString()); if (facc == null || facc.Name != "PipeNode") { XtraMessageBox.Show("您选中的不是管点设施,请选择管点设施。", "提示"); return; } DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fl.FeatureClassId.ToString()); if (dffc == null || dffc.GetFeatureClass() == null) { return; } IFeatureClass fc = dffc.GetFeatureClass(); if (this._bFinished) { Clear(); this._startFCGuid = fc.Guid.ToString(); this._startOid = featureId; this._bFinished = false; ILabel label = app.Current3DMapControl.ObjectManager.CreateLabel(app.Current3DMapControl.ProjectTree.RootID); label.Text = "起点"; ITextSymbol ts = new TextSymbol(); ts.TextAttribute.TextSize = SystemInfo.Instance.TextSize; ts.TextAttribute.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16); label.TextSymbol = ts; label.Position = this._drawTool.GetSelectPoint(); this._listRGuid.Add(label.Guid); } else { if (this._startFCGuid == fc.Guid.ToString() && this._startOid == featureId) { XtraMessageBox.Show("您选中的是同一个管点设施。", "提示"); return; } this._bFinished = true; ILabel label = app.Current3DMapControl.ObjectManager.CreateLabel(app.Current3DMapControl.ProjectTree.RootID); label.Text = "终点"; ITextSymbol ts = new TextSymbol(); ts.TextAttribute.TextSize = SystemInfo.Instance.TextSize; ts.TextAttribute.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16); label.TextSymbol = ts; label.Position = this._drawTool.GetSelectPoint(); this._listRGuid.Add(label.Guid); if (this._startFCGuid != fc.Guid.ToString()) { XtraMessageBox.Show("您选中的不是同一类管点设施。", "提示"); return; } else { WaitForm.Start("正在分析...", "请稍后"); FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString()); if (reg == null) { return; } TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); if (tc == null) { return; } TopoNetwork net = tc.GetNetwork(); if (net == null) { XtraMessageBox.Show("构建拓扑网络失败!", "提示"); return; } else { string startId = this._startFCGuid + "_" + this._startOid.ToString(); string endId = fc.Guid.ToString() + "_" + featureId.ToString(); List <string> path; double shortestLength = net.SPFA(startId, endId, out path); if ((shortestLength > 0.0 && shortestLength != double.MaxValue) || (path != null && path.Count > 0)) { List <IPoint> listPt = new List <IPoint>(); foreach (string nodeId in path) { int index = nodeId.LastIndexOf("_"); string fcguid = nodeId.Substring(0, index); string oid = nodeId.Substring(index + 1, nodeId.Length - index - 1); DF3DFeatureClass dffcTemp = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fcguid); if (dffcTemp == null || dffcTemp.GetFeatureClass() == null) { continue; } if (dffcTemp.GetFacilityClassName() != "PipeNode") { continue; } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "oid = " + oid; filter.SubFields = "oid,Shape"; IRowBuffer row = null; IFdeCursor cursor = null; try { cursor = dffcTemp.GetFeatureClass().Search(filter, false); while ((row = cursor.NextRow()) != null) { if (!row.IsNull(1) && (row.GetValue(1) is IGeometry)) { IGeometry geo = row.GetValue(1) as IGeometry; switch (geo.GeometryType) { case gviGeometryType.gviGeometryPoint: IPoint pt = geo as IPoint; pt.Z = pt.Z + 1; listPt.Add(pt); break; } } } } catch (Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } } IPolyline polyline = (new GeometryFactory()).CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; foreach (IPoint pt in listPt) { ISimplePointSymbol ps = new SimplePointSymbol(); ps.Size = 5; ps.Style = gviSimplePointStyle.gviSimplePointCircle; ps.FillColor = Convert.ToUInt32(SystemInfo.Instance.FillColor, 16); IRenderPoint rp = app.Current3DMapControl.ObjectManager.CreateRenderPoint(pt, ps, app.Current3DMapControl.ProjectTree.RootID); rp.Glow(5000); polyline.AppendPoint(pt); this._listRGuid.Add(rp.Guid); } ICurveSymbol cs = new CurveSymbol(); cs.Color = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16); cs.Width = -5; IRenderPolyline rpl = app.Current3DMapControl.ObjectManager.CreateRenderPolyline(polyline, cs, app.Current3DMapControl.ProjectTree.RootID); rpl.Glow(5000); this._listRGuid.Add(rpl.Guid); } else { XtraMessageBox.Show("两点不连通!", "提示"); } } } } } catch (Exception ex) { XtraMessageBox.Show("分析出错!", "提示"); } finally { WaitForm.Stop(); } }
private void ShowFlowDirect(IFeatureLayerPickResult pr) { if (pr == null) { return; } IRowBuffer row = null; IFdeCursor cursor = null; try { int fid = pr.FeatureId; DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(pr.FeatureLayer.FeatureClassId.ToString()); if (dffc == null) { return; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass fac = dffc.GetFacilityClass(); if (fc == null || fac == null || fac.Name != "PipeLine") { return; } DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("FlowDirect"); if (fi == null) { return; } IFieldInfoCollection fiCol = fc.GetFields(); int index = fiCol.IndexOf(fi.Name); if (index == -1) { return; } int indexShape = fiCol.IndexOf("Shape"); IQueryFilter filter = new QueryFilter(); filter.WhereClause = "oid=" + fid; cursor = fc.Search(filter, false); row = cursor.NextRow(); if (row == null) { return; } IPolyline line = null; if (indexShape != -1 && !row.IsNull(indexShape)) { object obj = row.GetValue(indexShape); if (obj != null && obj is IPolyline) { line = obj as IPolyline; } } string flowDirectValue = "0"; int type = 1;// 1表示具有流向字段;2表示从高到低 if (!row.IsNull(index)) { flowDirectValue = row.GetValue(index).ToString(); if (flowDirectValue != "0" && flowDirectValue != "1") { flowDirectValue = "0"; } type = 1; } else if (line != null) { if (line.StartPoint.Z > line.EndPoint.Z) { flowDirectValue = "0"; } else { flowDirectValue = "1"; } type = 2; } if (line == null) { return; } if (this._isAuth) { #region 流向渲染1 FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString()); if (reg == null) { return; } TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); if (tc == null) { return; } FacStyleClass style = null; List <FacStyleClass> facilityStyles = FacilityInfoService.GetFacStyleByFacClassCode(reg.FacClassCode); if ((facilityStyles != null) && (facilityStyles.Count > 0)) { style = facilityStyles[0]; } PipeLineFac plfac = new PipeLineFac(reg, style, row, tc); IRenderModelPoint rmp = null; DrawGeometry.Ocx = DF3DApplication.Application.Current3DMapControl; plfac.ShowFlowDirection(int.Parse(flowDirectValue), out rmp); if (rmp != null) { this._listRender.Add(rmp.Guid); } #endregion } else { #region 流向渲染2 IEulerAngle angle = DF3DApplication.Application.Current3DMapControl.Camera.GetAimingAngles2(line.StartPoint, line.EndPoint); double dia = 0.0; string diaField = fac.GetFieldInfoNameBySystemName("Diameter"); int indexDia = fiCol.IndexOf(diaField); if (indexDia != -1 && !row.IsNull(indexDia)) { string diaStr = row.GetValue(indexDia).ToString(); int indexDia1 = diaStr.ToString().IndexOf('*'); if (indexDia1 != -1) { var dia1 = int.Parse(diaStr.ToString().Substring(0, indexDia1)); var dia2 = int.Parse(diaStr.ToString().Substring(indexDia1 + 1, diaStr.ToString().Length)); dia = ((dia1 > dia2) ? dia1 : dia2) * 0.001; } else { dia = int.Parse(diaStr) * 0.001; } } List <IPoint> points = new List <IPoint>(); if (flowDirectValue == "0") { for (int i = 0; i < line.PointCount; i++) { IPoint pt = line.GetPoint(i); pt.Z += dia / 2; points.Add(pt); } } else if (flowDirectValue == "1") { for (int i = line.PointCount - 1; i >= 0; i--) { IPoint pt = line.GetPoint(i); pt.Z += dia / 2; points.Add(pt); } } for (int i = 0; i < points.Count - 1; i++) { IPoint pt1 = points[i]; var pt2 = points[i + 1]; double delt = 0; double _rate, _distance; if (!(Math.Abs(dia) < 0.0000001)) { delt = 2.0 * dia; if (dia <= 0.5 && dia >= 0.3) { _rate = 7 * dia; _distance = 3 * dia / 0.4; } else if (dia < 0.3 && dia > 0.1) { _rate = 12 * dia; _distance = 6 * dia / 0.4; } else if (dia <= 0.1) { _rate = 22 * dia; _distance = 9 * dia / 0.4; } else { _rate = 3.5 * dia; _distance = 1.5 * dia / 0.4; } } else { _rate = 2.0; _distance = 3.0; //z = maxZ + 0.2; delt = 0.2; } List <IPoint> list = DisPerseLine(pt1, pt2, _distance); if (list.Count < 2) { return; } List <IPoint> list1 = new List <IPoint>(); IGeometryFactory geoFact = new GeometryFactoryClass(); for (int j = 0; j < list.Count - 1; j++) { IPoint p = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); p.X = (list[j].X + list[j + 1].X) / 2; p.Y = (list[j].Y + list[j + 1].Y) / 2; p.Z = (list[j].Z + list[j + 1].Z) / 2; list1.Add(p); } for (var m = 0; m < list1.Count; m++) { IPosition pos = new PositionClass(); pos.X = list1[m].X; pos.Y = list1[m].Y; pos.Altitude = list1[m].Z + delt; pos.AltitudeType = gviAltitudeType.gviAltitudeTerrainAbsolute; pos.Heading = angle.Heading; pos.Tilt = angle.Tilt; pos.Roll = angle.Roll; UInt32 color; if (type == 1) { color = 0xFFFFFF00; } else { color = 0xFF00FFFF; } ITerrainArrow rArrow = DF3DApplication.Application.Current3DMapControl.ObjectManager.CreateArrow(pos, 0.8 * _rate, 3, color, color, DF3DApplication.Application.Current3DMapControl.ProjectTree.RootID); this._listRender.Add(rArrow.Guid); } } #endregion } } catch (Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }