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 TopoClass GetTopoClassByObjectId(string objectId) { if (dictTopo.ContainsKey(objectId) && dictTopo[objectId] != null) { return(dictTopo[objectId]); } if (DF3DPipeCreateApp.App.TemplateLib == null) { return(null); } IFdeCursor o = null; IRowBuffer row = null; IQueryFilter filter = null; try { IFeatureDataSet fds = DF3DPipeCreateApp.App.TemplateLib.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(null); } IObjectClass oc = fds.OpenObjectClass("OC_TopoManage"); if (oc == null) { return(null); } filter = new QueryFilterClass { WhereClause = string.Format("ObjectId = '{0}'", objectId) }; o = oc.Search(filter, true); row = o.NextRow(); if (row != null) { TopoClass tc = new TopoClass(); if (row.FieldIndex("oid") >= 0) { object obj = row.GetValue(row.FieldIndex("oid")); if (obj != null) { tc.Id = int.Parse(obj.ToString()); } } if (row.FieldIndex("ObjectId") >= 0) { object obj = row.GetValue(row.FieldIndex("ObjectId")); if (obj != null) { tc.ObjectId = obj.ToString(); } } if (row.FieldIndex("TopoLayerName") >= 0) { object obj = row.GetValue(row.FieldIndex("TopoLayerName")); if (obj != null) { tc.Name = obj.ToString(); } } if (row.FieldIndex("Tolerance") >= 0) { object obj = row.GetValue(row.FieldIndex("Tolerance")); if (obj != null) { tc.Tolerance = double.Parse(obj.ToString()); } } if (row.FieldIndex("ToleranceZ") >= 0) { object obj = row.GetValue(row.FieldIndex("ToleranceZ")); if (obj != null) { tc.ToleranceZ = double.Parse(obj.ToString()); } } if (row.FieldIndex("IgnoreZ") >= 0) { object obj = row.GetValue(row.FieldIndex("IgnoreZ")); if (obj != null) { tc.IgnoreZ = obj.ToString() == "1" ? true : false; } } if (row.FieldIndex("TopoTableName") >= 0) { object obj = row.GetValue(row.FieldIndex("TopoTableName")); if (obj != null) { tc.TopoTable = obj.ToString(); } } if (row.FieldIndex("Comment") >= 0) { object obj = row.GetValue(row.FieldIndex("Comment")); if (obj != null) { tc.Comment = obj.ToString(); } } dictTopo[tc.ObjectId] = tc; return(tc); } return(null); } catch (Exception ex) { return(null); } finally { if (o != null) { Marshal.ReleaseComObject(o); o = null; } if (row != null) { 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; } } }