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) { } }
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) { } }