Пример #1
0
 private bool ImportOsg(string modelName, string filePath)
 {
     try
     {
         IImage       property = null;
         IMatrix      mat      = null;
         IPropertySet images   = null;
         IModel       smodel   = null;
         IModel       fmodel   = null;
         bool         bRes     = this.OpenOsgModel(filePath, out fmodel, out smodel, out images, out mat);
         if (!bRes)
         {
             return(false);
         }
         DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer;
         if (dffc != null)
         {
             IFeatureClass fc = dffc.GetFeatureClass();
             if (fc != null)
             {
                 IResourceManager resManager = fc.FeatureDataSet as IResourceManager;
                 if ((images != null) && (images.Count > 0))
                 {
                     foreach (string str in images.GetAllKeys())
                     {
                         if (!resManager.ImageExist(str))
                         {
                             property = images.GetProperty(str) as IImage;
                             bRes     = resManager.AddImage(str, property);
                             if (!bRes)
                             {
                                 return(false);
                             }
                         }
                     }
                 }
                 bRes = resManager.AddModel(modelName, fmodel, smodel);
                 if (!bRes)
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Пример #2
0
        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)
            {
            }
        }
Пример #3
0
        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)
            {
            }
        }
Пример #4
0
        public void ImportModelXml(IFeatureClass fc, string mdbFile, int groupId, int _nCount)
        {
            try
            {
                //2、获取基本信息
                FileInfo         fInfo       = new FileInfo(mdbFile);
                string           strFilePath = fInfo.DirectoryName;
                IResourceManager rm          = fc.FeatureDataSet as IResourceManager;
                Dictionary <string, IEnvelope> cacheModeInfos = new Dictionary <string, IEnvelope>();
                List <string> cacheImageNames = new List <string>();

                IGeometryFactory geoFactory = new GeometryFactory();
                IResourceFactory symbolFac  = new ResourceFactory();

                IRowBufferCollection fcRows = new RowBufferCollection();
                IRowBuffer           fcRow  = null;

                //4、解析xml
                string      strConn    = "" + mdbFile + "\'";
                int         index      = 0;
                int         totalCount = _nCount;
                IModelPoint modePoint  = null;
                for (int i = 0; i < _nCount; ++i)
                {
                    int    percent = ++index * 100 / totalCount;
                    string toolTip = string.Format("已完成{0}条/总共{1}条 {2}%", index, totalCount, percent);
                    CommonEntity.FormEntity.Text = toolTip;

                    //fc
                    fcRow = fc.CreateRowBuffer();
                    int nPose = fcRow.FieldIndex("name");
                    if (nPose == -1)
                    {
                        continue;
                    }
                    string modelName = _dataTable.Rows[i]["ModelName"].ToString();
                    fcRow.SetValue(nPose, modelName);

                    nPose = fcRow.FieldIndex("groupId");
                    if (nPose == -1)
                    {
                        continue;
                    }
                    fcRow.SetValue(nPose, groupId);

                    modePoint = (IModelPoint)geoFactory.CreateGeometry(
                        gviGeometryType.gviGeometryModelPoint,
                        gviVertexAttribute.gviVertexAttributeZ);
                    modePoint.ModelName = modelName;

                    double dModePointX = double.Parse(_dataTable.Rows[i]["LocationX"].ToString()) + 0;  // CoorX = 0
                    double dModePointY = double.Parse(_dataTable.Rows[i]["LocationY"].ToString()) + 0;  // CoorY = 0
                    double dModePointZ = double.Parse(_dataTable.Rows[i]["LocationZ"].ToString()) + 0;  // CoorZ = 0

                    string  strMatrix = _dataTable.Rows[i]["Matrix3"].ToString();
                    float[] Matrix    = null;
                    if (!string.IsNullOrEmpty(strMatrix))
                    {
                        string[] strArray = strMatrix.Split(',');
                        if (strArray.Length == 9)
                        {
                            Matrix    = new float[9];
                            Matrix[0] = float.Parse(strArray[0]);
                            Matrix[1] = float.Parse(strArray[1]);
                            Matrix[2] = float.Parse(strArray[2]);
                            Matrix[3] = float.Parse(strArray[3]);
                            Matrix[4] = float.Parse(strArray[4]);
                            Matrix[5] = float.Parse(strArray[5]);
                            Matrix[6] = float.Parse(strArray[6]);
                            Matrix[7] = float.Parse(strArray[7]);
                            Matrix[8] = float.Parse(strArray[8]);
                        }
                    }
                    modePoint.X        = dModePointX;
                    modePoint.Y        = dModePointY;
                    modePoint.Z        = dModePointZ;
                    modePoint.Matrix33 = Matrix;


                    //mc
                    IPropertySet Images = null;

                    //如果内存中不包含
                    if (!cacheModeInfos.Keys.Contains(modelName))
                    {
                        //数据库中包含
                        if (rm.ModelExist(modelName))
                        {
                            //重名即跳过
                            IEnvelope ev = rm.GetModel(modelName).Envelope;
                            modePoint.ModelEnvelope = ev;
                        }
                        else
                        {
                            IModel  simpleModel = null;
                            string  osgFilePath = strFilePath + "\\" + modelName + ".osg";
                            IModel  fineModel   = null;
                            IMatrix matrix      = null;
                            symbolFac.CreateModelAndImageFromFileEx(osgFilePath,
                                                                    out Images, out simpleModel, out fineModel, out matrix);
                            if (fineModel == null || fineModel.GroupCount == 0)
                            {
                                continue;
                            }

                            cacheModeInfos[modelName] = modePoint.ModelEnvelope = Clone(fineModel.Envelope);

                            rm.AddModel(modelName, fineModel, simpleModel);
                            //Marshal.ReleaseComObject(simpleModel);
                            //Marshal.ReleaseComObject(fineModel);
                        }
                    }
                    else
                    {
                        modePoint.ModelEnvelope = cacheModeInfos[modelName];
                    }

                    nPose = fcRow.FieldIndex("Geometry");
                    fcRow.SetValue(nPose, modePoint);
                    fcRows.Add(fcRow);

                    //tc
                    int nCount = Images.Count;
                    if (Images != null && nCount > 0)
                    {
                        Hashtable htImages = Images.AsHashtable();
                        foreach (DictionaryEntry item in htImages)
                        {
                            string imgName = item.Key.ToString();
                            IImage img     = item.Value as IImage;
                            if (img == null)
                            {
                                continue;
                            }
                            if (string.IsNullOrEmpty(imgName))
                            {
                                continue;
                            }

                            //如果内存中不包含
                            if (!cacheImageNames.Contains(imgName))
                            {
                                //数据库中包含
                                if (rm.ImageExist(imgName))
                                {
                                    //重名即跳过
                                }
                            }

                            //如果内存中不包含,数据库中也不包含
                            if (!rm.ImageExist(imgName) &&
                                !cacheImageNames.Contains(imgName))
                            {
                                cacheImageNames.Add(imgName);

                                rm.AddImage(imgName, img);
                            }
                        }
                    }
                    //end

                    if (fcRows.Count >= 10)
                    {
                        InsertFeatures(fc as IObjectClass, fcRows);
                        fcRows.Clear();
                    }
                }
                if (fcRows.Count > 0)
                {
                    InsertFeatures(fc as IObjectClass, fcRows);
                    fcRows.Clear();
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #5
0
        public void ImportModelMdb(IFeatureClass fc, string mdbFile, int groupId)
        {
            try
            {
                //2、获取基本信息
                FileInfo fInfo       = new FileInfo(mdbFile);
                string   strFilePath = fInfo.DirectoryName;

                Gvitech.CityMaker.Resource.IResourceFactory rf = new Gvitech.CityMaker.Resource.ResourceFactory();
                IResourceManager rm = fc.FeatureDataSet as IResourceManager;
                Dictionary <string, IEnvelope> cacheModeInfos = new Dictionary <string, IEnvelope>();
                List <string> cacheImageNames = new List <string>();

                IGeometryFactory geoFactory = new GeometryFactory();
                IResourceFactory symbolFac  = new ResourceFactory();

                IRowBufferCollection fcRows = new RowBufferCollection();
                IRowBuffer           fcRow  = null;

                //4、解析mdb
                string strConn    = _ConnStr + mdbFile + "\'";
                int    index      = 0;
                int    totalCount = 0;
                using (OleDbConnection oleConn = new OleDbConnection(strConn))
                {
                    oleConn.Open();
                    string          strSql      = "select count(*)  from Attribute_Table_CityManager";
                    OleDbCommand    countCmd    = new OleDbCommand(strSql, oleConn);
                    OleDbDataReader countReader = countCmd.ExecuteReader();
                    countReader.Read();
                    totalCount = countReader.GetInt32(0);
                    countReader.Close();

                    OleDbCommand    command   = new OleDbCommand(_QueryModelStr, oleConn);
                    OleDbDataReader reader    = command.ExecuteReader();
                    IModelPoint     modePoint = null;
                    while (reader.Read())
                    {
                        int    percent = ++index * 100 / totalCount;
                        string toolTip = string.Format("已完成{0}条/总共{1}条 {2}%", index, totalCount, percent);
                        CommonEntity.FormEntity.Text = toolTip;

                        double dScaleX = 0.0;
                        double dScaleY = 0.0;
                        double dScaleZ = 0.0;

                        double.TryParse(reader.GetString(9), out dScaleX);
                        double.TryParse(reader.GetString(10), out dScaleY);
                        double.TryParse(reader.GetString(11), out dScaleZ);

                        //if (dScaleX < 0 || dScaleY < 0 || dScaleZ < 0)
                        //    continue;

                        //fc
                        fcRow = fc.CreateRowBuffer();
                        int nPose = fcRow.FieldIndex("name");
                        if (nPose == -1)
                        {
                            continue;
                        }
                        string modelName = reader.GetString(0);
                        fcRow.SetValue(nPose, modelName);

                        nPose = fcRow.FieldIndex("groupId");
                        if (nPose == -1)
                        {
                            continue;
                        }
                        fcRow.SetValue(nPose, groupId);

                        modePoint = (IModelPoint)geoFactory.CreateGeometry(
                            gviGeometryType.gviGeometryModelPoint,
                            gviVertexAttribute.gviVertexAttributeZ);
                        modePoint.ModelName = modelName;

                        double dModePointX = double.Parse(reader.GetString(2)) + 0;  // CoorX = 0
                        double dModePointY = double.Parse(reader.GetString(3)) + 0;  // CoorY = 0
                        double dModePointZ = double.Parse(reader.GetString(4)) + 0;  // CoorZ = 0

                        double dRotationAngle = double.Parse(reader.GetString(5));
                        double dAxisX         = double.Parse(reader.GetString(6));
                        double dAxisY         = double.Parse(reader.GetString(7));
                        double dAxisZ         = double.Parse(reader.GetString(8));

                        double dUTransAngel = double.Parse(reader.GetString(12));
                        double dUTransX     = double.Parse(reader.GetString(13));
                        double dUTransY     = double.Parse(reader.GetString(14));
                        double dUTransZ     = double.Parse(reader.GetString(15));

                        modePoint.X = dModePointX;
                        modePoint.Y = dModePointY;
                        modePoint.Z = dModePointZ;

                        IMatrix matrix = new Matrix();

                        IVector3 pointVec = new Vector3();
                        pointVec.X = dModePointX;
                        pointVec.Y = dModePointY;
                        pointVec.Z = dModePointZ;

                        IVector3 Scale = new Vector3();
                        Scale.X = dScaleX;
                        Scale.Y = dScaleY;
                        Scale.Z = dScaleZ;

                        IVector3 Rotation = new Vector3();
                        Rotation.X = dAxisX;
                        Rotation.Y = dAxisY;
                        Rotation.Z = dAxisZ;

                        IVector3 Shear = new Vector3();
                        Shear.X = dUTransX;
                        Shear.Y = dUTransY;
                        Shear.Z = dUTransZ;

                        matrix.Compose2(pointVec, Scale, dRotationAngle, Rotation, dUTransAngel, Shear);
                        modePoint.FromMatrix(matrix);

                        //mc
                        IPropertySet Images = null;

                        //如果内存中不包含
                        if (!cacheModeInfos.Keys.Contains(modelName))
                        {
                            //数据库中包含
                            if (rm.ModelExist(modelName))
                            {
                                //重名即跳过
                                IEnvelope ev = rm.GetModel(modelName).Envelope;
                                modePoint.ModelEnvelope = ev;
                            }
                            else
                            {
                                IModel  simpleModel = null;
                                string  osgFilePath = strFilePath + "\\" + modelName + ".osg";
                                IModel  fineModel   = null;
                                IMatrix m           = null;
                                symbolFac.CreateModelAndImageFromFileEx(osgFilePath,
                                                                        out Images, out simpleModel, out fineModel, out m);
                                if (fineModel == null || fineModel.GroupCount == 0)
                                {
                                    continue;
                                }

                                cacheModeInfos[modelName] = modePoint.ModelEnvelope = Clone(fineModel.Envelope);

                                rm.AddModel(modelName, fineModel, simpleModel);
                            }
                        }
                        else
                        {
                            modePoint.ModelEnvelope = cacheModeInfos[modelName];
                        }

                        nPose = fcRow.FieldIndex("Geometry");
                        fcRow.SetValue(nPose, modePoint);
                        fcRows.Add(fcRow);

                        //tc
                        if (Images != null)
                        {
                            int nCount = Images.Count;
                            if (nCount > 0)
                            {
                                Hashtable htImages = Images.AsHashtable();
                                foreach (DictionaryEntry item in htImages)
                                {
                                    string imgName = item.Key.ToString();
                                    IImage img     = item.Value as IImage;
                                    if (img == null)
                                    {
                                        continue;
                                    }
                                    if (string.IsNullOrEmpty(imgName))
                                    {
                                        continue;
                                    }

                                    //如果内存中不包含
                                    if (!cacheImageNames.Contains(imgName))
                                    {
                                        //数据库中包含
                                        if (rm.ImageExist(imgName))
                                        {
                                            //重名即跳过
                                        }
                                    }

                                    //如果内存中不包含,数据库中也不包含
                                    if (!rm.ImageExist(imgName) &&
                                        !cacheImageNames.Contains(imgName))
                                    {
                                        cacheImageNames.Add(imgName);
                                        rm.AddImage(imgName, img);
                                    }
                                }
                            }
                        }
                        //end

                        if (fcRows.Count >= 10)
                        {
                            InsertFeatures(fc as IObjectClass, fcRows);
                            fcRows.Clear();
                        }
                    }
                    reader.Close();
                    oleConn.Close();
                }

                if (fcRows.Count > 0)
                {
                    InsertFeatures(fc as IObjectClass, fcRows);
                    fcRows.Clear();
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #6
0
        public bool ShowFlowDirection(int flowDir, out IRenderModelPoint rpt)
        {
            rpt = null;
            if (base._rowInfo == null)
            {
                return(false);
            }

            string str = Application.StartupPath + @"\..\Resource\Images\FlowDirection";

            if (!Directory.Exists(str))
            {
                return(false);
            }
            IImage _imgFlowImg = DrawGeometry.resFactory.CreateImageFromFile(str);

            _imgFlowImg.FrameInterval = 50;

            IPolyline        path        = null;
            IPipeSection     pipeSection = null;
            string           name        = "FlowDirection";
            IDrawDynamicFlow flow        = null;
            IModelPoint      mp          = null;

            try
            {
                IModel    model;
                IModel    model2;
                IPoint    pointValue = null;
                IPolyline polyline2  = null;
                polyline2 = base._geoGroup[1] as IPolyline;
                if ((polyline2 == null) || (polyline2.PointCount < 2))
                {
                    return(false);
                }
                path = polyline2.Clone() as IPolyline;
                for (int i = 0; i < path.PointCount; i++)
                {
                    pointValue = path.GetPoint(i);
                    if (pointValue != null)
                    {
                        pointValue.Z += this.OffsetZ;
                        path.UpdatePoint(i, pointValue);
                    }
                }

                pipeSection = new PipeSection(this._dia1, this._dia2, HorizontalPos.Center, VerticalPos.Center, 0.02, 0);

                flow = ParamModelFactory.Instance.CreateGeometryDraw(ModelType.DynamicFlow, Guid.NewGuid().ToString()) as IDrawDynamicFlow;
                flow.SetParameter(pipeSection, path, flowDir);
                flow.SetTextureRender(new string[] { name });
                if (!flow.Draw(out mp, out model, out model2))
                {
                    return(false);
                }

                #region 需要runtime授权
                IFeatureDataSet  iFeatureDataSet = DF3DPipeCreateApp.App.TempLib.OpenFeatureDataset("FeatureDataSet");
                IResourceManager manager         = iFeatureDataSet as IResourceManager;
                if (!manager.ModelExist(mp.ModelName))
                {
                    manager.AddModel(mp.ModelName, model, null);
                }
                if (!manager.ImageExist(name))
                {
                    manager.AddImage(name, _imgFlowImg);
                }
                #endregion

                IModelPointSymbol symbol = new ModelPointSymbolClass();
                symbol.SetResourceDataSet(iFeatureDataSet);
                symbol.Color       = uint.MaxValue;
                symbol.EnableColor = true;
                mp.ModelEnvelope   = model.Envelope;
                rpt = DrawGeometry.Ocx.ObjectManager.CreateRenderModelPoint(mp, symbol, DrawGeometry.Ocx.ProjectTree.RootID);

                return(true);
            }
            catch (Exception exception)
            {
                return(false);
            }
        }
Пример #7
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();
                }
            }
        }
Пример #8
0
        public bool CopyModelAndImage(MyProgressBar bar, IFeatureDataSet srcFds, IFeatureDataSet tarFds)
        {
            bool flag = true;
            int  num  = 1;

            try
            {
                tarFds.DataSource.StartEditing();
                IResourceManager resourceManager  = srcFds as IResourceManager;
                IResourceManager resourceManager2 = tarFds as IResourceManager;
                EnumResName      modelNames       = resourceManager.GetModelNames();
                int modelCount = resourceManager.GetModelCount();
                while (modelNames.MoveNext())
                {
                    if (num % 100 == 0 || num == modelCount)
                    {
                        lock (bar)
                        {
                            if (bar.CallbackCancel)
                            {
                                bar.labelTooltip.Text = StringParser.Parse("${res:View_Cancling}");
                                bool result = false;
                                return(result);
                            }
                        }
                    }
                    string current = modelNames.Current;
                    Gvitech.CityMaker.Resource.IModel model           = resourceManager.GetModel(current);
                    Gvitech.CityMaker.Resource.IModel simplifiedModel = resourceManager.GetSimplifiedModel(current);
                    if (!resourceManager2.ModelExist(current))
                    {
                        resourceManager2.AddModel(current, model, simplifiedModel);
                        LoggingService.Debug(string.Format("Copy model:{0}", current));
                    }
                    num++;
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(modelNames);
                EnumResName imageNames = resourceManager.GetImageNames();
                num = 1;
                resourceManager.GetImageCount();
                while (imageNames.MoveNext())
                {
                    if (num % 100 == 0 || num == modelCount)
                    {
                        lock (bar)
                        {
                            if (bar.CallbackCancel)
                            {
                                bar.labelTooltip.Text = StringParser.Parse("${res:View_Cancling}");
                                bool result = false;
                                return(result);
                            }
                        }
                    }
                    string current2 = imageNames.Current;
                    IImage image    = resourceManager.GetImage(current2);
                    if (image != null && !resourceManager2.ImageExist(current2))
                    {
                        resourceManager2.AddImage(current2, image);
                        LoggingService.Debug(string.Format("Copy model:{0}", current2));
                    }
                    num++;
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(imageNames);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                flag = false;
            }
            catch (System.Exception ex2)
            {
                XtraMessageBox.Show(ex2.Message);
                flag = false;
            }
            finally
            {
                tarFds.DataSource.StopEditing(flag);
            }
            return(flag);
        }
Пример #9
0
        private IEnvelope ImportOsg(IFeatureClass fc, string filePath)
        {
            try
            {
                IEnvelope env = null;

                if (fc == null || !File.Exists(filePath))
                {
                    return(env);
                }

                string           modelName       = Path.GetFileNameWithoutExtension(filePath);
                IResourceManager resourceManager = fc.FeatureDataSet as IResourceManager;
                if (resourceManager == null)
                {
                    return(env);
                }
                if (!resourceManager.CheckResourceName(modelName))
                {
                    return(env);
                }
                IResourceFactory resourceFactory = new ResourceFactory();

                System.Collections.Generic.Dictionary <string, IEnvelope> modelInfos = this.GetModelInfos(resourceManager, modelName);
                fc.FeatureDataSet.DataSource.StartEditing();
                if (modelInfos.Keys.Contains(modelName))
                {
                    if (!sameNameDlg.IsApplicatonAll)//非应用于全部
                    {
                        string tipMessage = string.Format("{0}模型已经存在!", modelName);
                        sameNameDlg.TipMessage = tipMessage;
                        sameNameDlg.ShowDialog();
                    }
                    if (sameNameDlg.IsOverWriter)//如果覆盖就先删除
                    {
                        resourceManager.DeleteModel(modelName);
                        modelInfos.Remove(modelName);
                    }
                    else
                    {
                        env = modelInfos[modelName];
                    }
                }
                if (!modelInfos.Keys.Contains(modelName))
                {
                    Gvitech.CityMaker.Resource.IModel simplifiedModel = null;
                    Gvitech.CityMaker.Resource.IModel model           = null;
                    IMatrix      matrix = null;
                    IPropertySet propertySet;
                    resourceFactory.CreateModelAndImageFromFileEx(filePath, out propertySet, out simplifiedModel, out model, out matrix);
                    if (model == null || model.GroupCount == 0)
                    {
                        return(env);
                    }
                    if (!resourceManager.AddModel(modelName, model, simplifiedModel))
                    {
                        return(env);                                                             //向资源中添加
                    }
                    modelInfos[modelName] = model.Envelope;
                    env = modelInfos[modelName];

                    if (propertySet != null && propertySet.Count > 0)
                    {
                        //获得资源的图片
                        System.Collections.Generic.List <string> imageNames = GetImageNames(resourceManager);
                        string[] allKeys = propertySet.GetAllKeys();
                        string[] array   = allKeys;
                        for (int i = 0; i < array.Length; i++)
                        {
                            string text2 = array[i];
                            if (imageNames.Contains(text2))
                            {
                                if (!sameNameDlg.IsApplicatonAll)//非应用于全部
                                {
                                    string tipMessage2 = string.Format("{0}贴图已存在!", text2);
                                    sameNameDlg.TipMessage = tipMessage2;
                                    sameNameDlg.ShowDialog();
                                }
                                if (sameNameDlg.IsOverWriter)//是否覆盖
                                {
                                    resourceManager.DeleteImage(text2);
                                    imageNames.Remove(text2);
                                }
                            }

                            if (!imageNames.Contains(text2))
                            {
                                if (!resourceManager.CheckResourceName(text2))
                                {
                                }
                                else
                                {
                                    imageNames.Add(text2);
                                    Gvitech.CityMaker.Resource.IImage image = propertySet.GetProperty(text2) as Gvitech.CityMaker.Resource.IImage;
                                    resourceManager.AddImage(text2, image);
                                }
                            }
                        }
                    }
                }
                fc.FeatureDataSet.DataSource.StopEditing(true);
                return(env);
            }
            catch (Exception ex)
            {
                fc.FeatureDataSet.DataSource.StopEditing(false);
                return(null);
            }
        }
Пример #10
0
        public void ImportModelOsg(IFeatureClass fc, string osgFile, int groupId)
        {
            try
            {
                FileInfo         fInfo       = new FileInfo(osgFile);
                string           strFilePath = fInfo.DirectoryName;
                IResourceManager rm          = fc.FeatureDataSet as IResourceManager;
                IGeometryFactory geoFactory  = new GeometryFactory();
                IResourceFactory symbolFac   = new ResourceFactory();
                IRowBuffer       fcRow       = null;

                //fc
                string modelName = fInfo.Name.Split('.')[0];
                fcRow = fc.CreateRowBuffer();
                int nPose = fcRow.FieldIndex("name");
                if (nPose != -1)
                {
                    fcRow.SetValue(nPose, modelName);
                }
                nPose = fcRow.FieldIndex("groupId");
                if (nPose != -1)
                {
                    fcRow.SetValue(nPose, groupId);
                }

                //mc
                IPropertySet Images      = null;
                IModel       simpleModel = null;
                string       osgFilePath = strFilePath + "\\" + modelName + ".osg";
                IModel       fineModel   = null;
                IMatrix      matrix      = null;
                symbolFac.CreateModelAndImageFromFileEx(osgFilePath,
                                                        out Images, out simpleModel, out fineModel, out matrix);
                if (fineModel == null || fineModel.GroupCount == 0)
                {
                    return;
                }
                rm.AddModel(modelName, fineModel, simpleModel);
                //Marshal.ReleaseComObject(simpleModel);
                //Marshal.ReleaseComObject(fineModel);

                //tc
                int nCount = Images.Count;
                if (Images != null && nCount > 0)
                {
                    Hashtable htImages = Images.AsHashtable();
                    foreach (DictionaryEntry item in htImages)
                    {
                        String imgName = item.Key.ToString();
                        IImage img     = item.Value as IImage;
                        rm.AddImage(imgName, img);
                    }
                }

                //modelpoint
                IModelPoint modePoint = null;
                modePoint = (IModelPoint)geoFactory.CreateGeometry(
                    gviGeometryType.gviGeometryModelPoint,
                    gviVertexAttribute.gviVertexAttributeZ);
                modePoint.FromMatrix(matrix);
                modePoint.ModelName = modelName;
                double dModePointX = 0.0;
                double dModePointY = 0.0;
                double dModePointZ = 0.0;
                modePoint.X += dModePointX;
                modePoint.Y += dModePointY;
                modePoint.Z += dModePointZ;
                nPose        = fcRow.FieldIndex("Geometry");
                fcRow.SetValue(nPose, modePoint);

                if (fc.HasTemporal())
                {
                    ITemporalManager mgr = fc.TemporalManager;
                    mgr.Insert(DateTime.Now, fcRow);
                    //Marshal.ReleaseComObject(mgr);
                }
                else
                {
                    IRowBufferCollection fcRows = new RowBufferCollection();
                    fcRows.Add(fcRow);
                    InsertFeatures(fc as IObjectClass, fcRows);
                    fcRows.Clear();
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }