private void InitData() { try { this.cbxFacilityStyle.SelectedIndex = -1; this.listStyles.SelectedIndex = -1; DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer; if (dffc == null) { return; } int count = SelectCollection.Instance().GetCount(false); if (count == 1) { HashMap hm = SelectCollection.Instance().GetSelectGeometrys(); if (hm != null && hm.Count == 1) { IRowBufferCollection rowBufferCollection = hm[dffc] as IRowBufferCollection; if (rowBufferCollection.Count == 1) { IRowBuffer rowBuffer = rowBufferCollection.Get(0); int index = rowBuffer.FieldIndex("StyleId"); if (index != -1 && !rowBuffer.IsNull(index)) { string styleId = rowBuffer.GetValue(index).ToString(); for (int i = 0; i < this.cbxFacilityStyle.Properties.Items.Count; i++) { FacStyleClass fsc = this.cbxFacilityStyle.Properties.Items[i] as FacStyleClass; if (fsc.ObjectId == styleId) { this.cbxFacilityStyle.SelectedIndex = i; this.listStyles.SelectedIndex = i; break; } } } } } } } catch (Exception ex) { } }
private bool UpdateFacStyleClass(FacStyleClass style) { IFdeCursor cursor = null; IRowBuffer row = null; try { IFeatureDataSet fds = this._ds.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(false); } IObjectClass oc = fds.OpenObjectClass("OC_FacilityStyle"); if (oc == null) { return(false); } IQueryFilter filter = new QueryFilter() { WhereClause = string.Format("ObjectId = '{0}'", style.ObjectId) }; cursor = oc.Update(filter); row = cursor.NextRow(); if (row != null) { row.SetValue(row.FieldIndex("Name"), style.Name); row.SetValue(row.FieldIndex("FacClassCode"), style.FacClassCode); row.SetValue(row.FieldIndex("ObjectId"), style.ObjectId); row.SetValue(row.FieldIndex("StyleType"), style.Type.ToString()); row.SetValue(row.FieldIndex("StyleInfo"), style.ObjectToJson()); if (style.Thumbnail != null) { try { IBinaryBuffer bb = new BinaryBufferClass(); MemoryStream stream = new MemoryStream(); style.Thumbnail.Save(stream, ImageFormat.Png); bb.FromByteArray(stream.ToArray()); row.SetValue(row.FieldIndex("Thumbnail"), bb); } catch (Exception exception) { } } cursor.UpdateRow(row); return(true); } else { return(false); } } catch (Exception ex) { return(false); } 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 AddRecord() { try { this.beforeRowBufferMap.Clear(); SelectCollection.Instance().Clear(); if (reg == null || tc == null) { return; } FacStyleClass style = this.cmbStyle.EditValue as FacStyleClass; if (style == null) { return; } SubClass sc = this.cmbClassify.EditValue as SubClass; DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer; if (featureClassInfo == null) { return; } IFeatureClass fc = featureClassInfo.GetFeatureClass(); if (fc == null) { return; } IResourceManager manager = fc.FeatureDataSet as IResourceManager; if (manager == null) { return; } IFeatureLayer fl = featureClassInfo.GetFeatureLayer(); if (fl == null) { return; } IFieldInfoCollection fields = fc.GetFields(); int indexOid = fields.IndexOf(fc.FidFieldName); if (indexOid == -1) { return; } int mpindex = fields.IndexOf(fl.GeometryFieldName); if (mpindex == -1) { return; } int indexShape = fields.IndexOf("Shape"); if (indexShape == -1) { return; } int indexFootPrint = fields.IndexOf("FootPrint"); if (indexFootPrint == -1) { return; } int indexStyleId = fields.IndexOf("StyleId"); if (indexStyleId == -1) { return; } int indexFacilityId = fields.IndexOf("FacilityId"); if (indexFacilityId == -1) { return; } IFieldInfo fiShape = fields.Get(indexShape); if (fiShape == null || fiShape.GeometryDef == null) { return; } IGeometry geo = this._drawTool.GetGeo(); if (geo.GeometryType != gviGeometryType.gviGeometryPoint) { return; } IPoint pt = geo as IPoint; IPoint geoOut = pt.Clone2(fiShape.GeometryDef.VertexAttribute) as IPoint; if (fiShape.GeometryDef.HasZ) { geoOut.SetCoords(pt.X, pt.Y, pt.Z, 0, 0); } else { geoOut.SetCoords(pt.X, pt.Y, 0, 0, 0); } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "1=1"; filter.ResultBeginIndex = 0; filter.ResultLimit = 1; filter.PostfixClause = "ORDER BY " + fc.FidFieldName + " desc"; IFdeCursor cursor = null; cursor = fc.Search(filter, false); IRowBuffer rowtemp = cursor.NextRow(); int oid = 0; if (rowtemp != null) { oid = int.Parse(rowtemp.GetValue(indexOid).ToString()); } if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } IRowBufferFactory fac = new RowBufferFactory(); IRowBuffer row = fac.CreateRowBuffer(fields); row.SetValue(indexOid, oid + 1); row.SetValue(indexShape, geoOut); row.SetValue(indexFootPrint, geoOut.Clone2(gviVertexAttribute.gviVertexAttributeNone)); row.SetValue(indexStyleId, style.ObjectId); row.SetValue(indexFacilityId, BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant()); if (sc != null) { int indexClassify = fields.IndexOf(this._classifyName); int indexGroupId = fields.IndexOf("GroupId"); if (indexClassify != -1 && indexGroupId != -1) { row.SetValue(indexClassify, sc.Name); row.SetValue(indexGroupId, sc.GroupId); } } foreach (DataRow dr in this._dt.Rows) { IFieldInfo fi = dr["F"] as IFieldInfo; if (fi == null) { continue; } string fn = fi.Name; int index = fields.IndexOf(fn); if (index != -1) { if (dr["FV"] == null) { row.SetNull(index); } else { string strobj = dr["FV"].ToString(); bool bRes = false; switch (fi.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldGeometry: case gviFieldType.gviFieldUnknown: break; case gviFieldType.gviFieldFloat: float f; bRes = float.TryParse(strobj, out f); if (bRes) { row.SetValue(index, f); } else { row.SetNull(index); } break; case gviFieldType.gviFieldDouble: double d; bRes = double.TryParse(strobj, out d); if (bRes) { row.SetValue(index, d); } else { row.SetNull(index); } break; case gviFieldType.gviFieldFID: case gviFieldType.gviFieldUUID: case gviFieldType.gviFieldInt16: Int16 i16; bRes = Int16.TryParse(strobj, out i16); if (bRes) { row.SetValue(index, i16); } else { row.SetNull(index); } break; case gviFieldType.gviFieldInt32: Int32 i32; bRes = Int32.TryParse(strobj, out i32); if (bRes) { row.SetValue(index, i32); } else { row.SetNull(index); } break; case gviFieldType.gviFieldInt64: Int64 i64; bRes = Int64.TryParse(strobj, out i64); if (bRes) { row.SetValue(index, i64); } else { row.SetNull(index); } break;; case gviFieldType.gviFieldString: row.SetValue(index, strobj); break; case gviFieldType.gviFieldDate: DateTime dt; bRes = DateTime.TryParse(strobj, out dt); if (bRes) { row.SetValue(index, dt); } else { row.SetNull(index); } break; default: break; } } } } Fac plf = new PipeNodeFac(reg, style, row, tc); IModelPoint mp = null; IModel finemodel = null; IModel simplemodel = null; string name = ""; if (UCAuto3DCreate.RebuildModel(plf, style, out mp, out finemodel, out simplemodel, out name)) { if (finemodel == null || mp == null) { return; } mp.ModelEnvelope = finemodel.Envelope; row.SetValue(mpindex, mp); //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) { return; } IRowBufferCollection rowCol = new RowBufferCollection(); rowCol.Add(row); beforeRowBufferMap[featureClassInfo] = rowCol; UpdateDatabase(); app.Current3DMapControl.FeatureManager.RefreshFeatureClass(fc); } } catch (Exception ex) { } }
public static List <FacStyleClass> GetFacStyleByFacClassCode(string fcCode) { IFdeCursor cursor = null; IRowBuffer row = null; try { IFeatureDataSet fds = DF3DPipeCreateApp.App.TemplateLib.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(null); } IObjectClass oc = fds.OpenObjectClass("OC_FacilityStyle"); if (oc == null) { return(null); } IQueryFilter filter = new QueryFilterClass { WhereClause = string.Format("FacClassCode = '{0}'", fcCode) }; cursor = oc.Search(filter, true); List <FacStyleClass> list = new List <FacStyleClass>(); while ((row = cursor.NextRow()) != null) { StyleType type; FacStyleClass fs = null; if (row.FieldIndex("StyleType") >= 0 && Enum.TryParse <StyleType>(row.GetValue(row.FieldIndex("StyleType")).ToString(), out type)) { Dictionary <string, string> dictionary = null; if (row.FieldIndex("StyleInfo") >= 0) { object obj = row.GetValue(row.FieldIndex("StyleInfo")); if (obj != null) { IBinaryBuffer buffer2 = row.GetValue(row.FieldIndex("StyleInfo")) as IBinaryBuffer; if (buffer2 != null) { dictionary = JsonTool.JsonToObject <Dictionary <string, string> >(Encoding.UTF8.GetString(buffer2.AsByteArray())); } } } switch (type) { case StyleType.PipeNodeStyle: fs = new PipeNodeStyleClass(dictionary); break; case StyleType.PipeLineStyle: fs = new PipeLineStyleClass(dictionary); break; case StyleType.PipeBuildStyle: fs = new PipeBuildStyleClass(dictionary); break; } } if (fs == null) { continue; } if (row.FieldIndex("oid") >= 0) { object obj = row.GetValue(row.FieldIndex("oid")); if (obj != null) { fs.Id = int.Parse(obj.ToString()); } } if (row.FieldIndex("ObjectId") >= 0) { object obj = row.GetValue(row.FieldIndex("ObjectId")); if (obj != null) { fs.ObjectId = obj.ToString(); } } if (row.FieldIndex("FacClassCode") >= 0) { object obj = row.GetValue(row.FieldIndex("FacClassCode")); if (obj != null) { fs.FacClassCode = obj.ToString(); } } if (row.FieldIndex("Name") >= 0) { object obj = row.GetValue(row.FieldIndex("Name")); if (obj != null) { fs.Name = obj.ToString(); } } int index = row.FieldIndex("Thumbnail"); if (index != -1 && !row.IsNull(index)) { IBinaryBuffer b = row.GetValue(index) as IBinaryBuffer; if (row != null) { MemoryStream stream = new MemoryStream(b.AsByteArray()); fs.Thumbnail = Image.FromStream(stream); } } list.Add(fs); } return(list); } catch (Exception exception) { 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 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; } } }