Exemplo n.º 1
0
        private void sbtn_Split_Click(object sender, System.EventArgs e)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            if (System.Windows.Forms.DialogResult.No != XtraMessageBox.Show("模型拆分不支持撤销操作,是否继续?", "询问", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation))
            {
                IFeatureClass featureClass = null;
                IFdeCursor    fdeCursor    = null;
                app.Current3DMapControl.PauseRendering(false);
                WaitDialogForm waitDialogForm = null;
                try
                {
                    int count = SelectCollection.Instance().GetCount(true);
                    if (count <= 0)
                    {
                        XtraMessageBox.Show("未选中要拆分的模型!");
                    }
                    else
                    {
                        if (this._renderGeo == null || this._renderGeo.GetFdeGeometry() == null)
                        {
                            XtraMessageBox.Show("请先绘制或选择拆分多边形!");
                        }
                        else
                        {
                            IMultiPolygon multiPolygon = null;
                            if (this.radioGroup1.SelectedIndex == 1)
                            {
                                IGeometryFactory geometryFactory = new GeometryFactoryClass();
                                multiPolygon = (geometryFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon);
                                multiPolygon.AddPolygon(this._renderGeo.GetFdeGeometry() as IPolygon);
                            }
                            else
                            {
                                if (this.radioGroup1.SelectedIndex == 0)
                                {
                                    multiPolygon = (this._renderGeo.GetFdeGeometry() as IMultiPolygon);
                                }
                            }
                            if (multiPolygon == null)
                            {
                                XtraMessageBox.Show("获取裁剪多边形失败!");
                            }
                            else
                            {
                                waitDialogForm = new WaitDialogForm(string.Empty, "正在拆分模型,请稍后...");
                                HashMap featureClassInfoMap            = SelectCollection.Instance().FeatureClassInfoMap;
                                System.Collections.Hashtable hashtable = new System.Collections.Hashtable();
                                foreach (DF3DFeatureClass featureClassInfo in featureClassInfoMap.Keys)
                                {
                                    if (featureClassInfo.GetFeatureLayer().GeometryType == gviGeometryColumnType.gviGeometryColumnModelPoint)
                                    {
                                        System.Collections.Generic.List <int> list  = new System.Collections.Generic.List <int>();
                                        System.Collections.Generic.List <int> list2 = new System.Collections.Generic.List <int>();
                                        IRowBufferCollection rowBufferCollection    = new RowBufferCollectionClass();
                                        IRowBufferCollection rowBufferCollection2   = new RowBufferCollectionClass();
                                        ResultSetInfo        resultSetInfo          = featureClassInfoMap[featureClassInfo] as ResultSetInfo;
                                        DataTable            resultSetTable         = resultSetInfo.ResultSetTable;
                                        if (resultSetTable.Rows.Count >= 1)
                                        {
                                            featureClass = featureClassInfo.GetFeatureClass();
                                            IResourceManager resourceManager = featureClass.FeatureDataSet as IResourceManager;
                                            string           fidFieldName    = featureClass.FidFieldName;
                                            int num = featureClass.GetFields().IndexOf(fidFieldName);
                                            foreach (DataRow dataRow in resultSetTable.Rows)
                                            {
                                                int         num2       = int.Parse(dataRow[fidFieldName].ToString());
                                                IRowBuffer  row        = featureClass.GetRow(num2);
                                                int         position   = row.FieldIndex(featureClassInfo.GetFeatureLayer().GeometryFieldName);
                                                IModelPoint modelPoint = row.GetValue(position) as IModelPoint;
                                                if (modelPoint != null)
                                                {
                                                    Gvitech.CityMaker.Resource.IModel model  = resourceManager.GetModel(modelPoint.ModelName);
                                                    IGeometryConvertor geometryConvertor     = new GeometryConvertorClass();
                                                    Gvitech.CityMaker.Resource.IModel model2 = null;
                                                    Gvitech.CityMaker.Resource.IModel model3 = null;
                                                    IModelPoint modelPoint2 = null;
                                                    IModelPoint modelPoint3 = null;
                                                    bool        flag        = geometryConvertor.SplitModelPointByPolygon2D(multiPolygon, model, modelPoint, out model2, out modelPoint2, out model3, out modelPoint3);
                                                    if (flag && model2 != null && !model2.IsEmpty && modelPoint2 != null && model3 != null && !model3.IsEmpty && modelPoint3 != null)
                                                    {
                                                        System.Guid guid = System.Guid.NewGuid();
                                                        string      text = guid.ToString();
                                                        resourceManager.AddModel(text, model2, null);
                                                        resourceManager.RebuildSimplifiedModel(text);
                                                        guid = System.Guid.NewGuid();
                                                        string text2 = guid.ToString();
                                                        resourceManager.AddModel(text2, model3, null);
                                                        resourceManager.RebuildSimplifiedModel(text2);
                                                        modelPoint3.ModelName = text2;
                                                        row.SetValue(position, modelPoint3);
                                                        rowBufferCollection.Add(row);
                                                        list.Add(num2);
                                                        modelPoint2.ModelName = text;
                                                        IRowBuffer rowBuffer = row.Clone(false);
                                                        rowBuffer.SetNull(num);
                                                        rowBuffer.SetValue(position, modelPoint2);
                                                        fdeCursor = featureClass.Insert();
                                                        fdeCursor.InsertRow(rowBuffer);
                                                        int lastInsertId = fdeCursor.LastInsertId;
                                                        rowBuffer.SetValue(num, lastInsertId);
                                                        rowBufferCollection2.Add(rowBuffer);
                                                        list2.Add(lastInsertId);
                                                        System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor);
                                                        fdeCursor = null;
                                                    }
                                                }
                                            }
                                            featureClass.UpdateRows(rowBufferCollection, false);
                                            app.Current3DMapControl.FeatureManager.EditFeatures(featureClass, rowBufferCollection);
                                            app.Current3DMapControl.FeatureManager.CreateFeatures(featureClass, rowBufferCollection2);
                                            hashtable[featureClassInfo] = list2;
                                            //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                                            featureClass = null;
                                            System.Runtime.InteropServices.Marshal.ReleaseComObject(resourceManager);
                                            resourceManager = null;
                                        }
                                    }
                                }
                                SelectCollection.Instance().UpdateSelection(hashtable);
                                base.Close();
                                base.DialogResult = System.Windows.Forms.DialogResult.OK;
                            }
                        }
                    }
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    XtraMessageBox.Show(ex.Message);
                }
                catch (System.UnauthorizedAccessException var_35_4EC)
                {
                    XtraMessageBox.Show("拒绝访问");
                }
                catch (System.Exception ex2)
                {
                    XtraMessageBox.Show(ex2.Message);
                }
                finally
                {
                    if (waitDialogForm != null)
                    {
                        waitDialogForm.Close();
                    }
                    if (fdeCursor != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor);
                        fdeCursor = null;
                    }
                    //if (featureClass != null && System.Runtime.InteropServices.Marshal.IsComObject(featureClass))
                    //{
                    //    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                    //    featureClass = null;
                    //}
                    app.Current3DMapControl.ResumeRendering();
                }
            }
        }