Example #1
0
        Stream(ArrayList data, Autodesk.AutoCAD.Colors.Transparency transp)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(Autodesk.AutoCAD.Colors.Transparency)));

            data.Add(new Snoop.Data.Bool("Is ByAlpha", transp.IsByAlpha));
            if (transp.IsByAlpha)
            {
                data.Add(new Snoop.Data.Int("Alpha", transp.Alpha));
                data.Add(new Snoop.Data.Bool("Is clear", transp.IsClear));
                data.Add(new Snoop.Data.Bool("Is solid", transp.IsSolid));
            }
            data.Add(new Snoop.Data.Bool("Is ByBlock", transp.IsByBlock));
            data.Add(new Snoop.Data.Bool("Is ByLayer", transp.IsByLayer));
        }
Example #2
0
        public ObjectId addImage(Document doc, double resulotion, int start_row, int end_row, int start_col, int end_col)
        {
            lockLayerOrNot(_layer_name, false);
            Database database = doc.Database;
            Editor   editor   = doc.Editor;
            ObjectId result;
            //try
            //{
            //    System.Drawing.Image.FromStream(new WebClient().OpenRead(url));
            //}
            //catch
            //{
            //    result = ObjectId.Null;
            //    editor.WriteMessage("Url is invalid!");
            //    return result;
            //}

            ObjectId objectId = ObjectId.Null;

            try
            {
                using (doc.LockDocument(DocumentLockMode.ProtectedAutoWrite, null, null, false))
                {
                    Autodesk.AutoCAD.ApplicationServices.TransactionManager transactionManager = doc.TransactionManager;
                    doc.TransactionManager.EnableGraphicsFlush(true);
                    using (Transaction transaction = transactionManager.StartTransaction())
                    {
                        ObjectId objectId2 = RasterImageDef.GetImageDictionary(database);
                        if (objectId2.IsNull)
                        {
                            objectId2 = RasterImageDef.CreateImageDictionary(database);
                        }
                        //rasterImageDef.ResolutionMMPerPixel = new Vector2d(78217.51696, 78217.51696);
                        DBDictionary dBDictionary = (DBDictionary)transaction.GetObject(objectId2, OpenMode.ForWrite);
                        dBDictionary.Erase();
                        for (int i = start_row; i <= end_row; ++i)
                        {
                            for (int j = start_col; j <= end_col; ++j)
                            {
                                Point2d        left_up        = MapTiles.webMercatorTilesLeftUpLocation(j, i, _level);
                                string         url            = string.Format("http://t3.tianditu.cn/img_c/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=c&TileMatrix={0}&TileRow={1}&TileCol={2}&style=default&format=tiles", _level, i, j);
                                RasterImageDef rasterImageDef = new RasterImageDef();
                                rasterImageDef.SourceFileName = (url);
                                rasterImageDef.Load();
                                bool arg_A4_0 = rasterImageDef.IsLoaded;

                                string text = RasterImageDef.SuggestName(dBDictionary, url);
                                if (dBDictionary.Contains(text))
                                {
                                    result = ObjectId.Null;
                                    return(result);
                                }
                                dBDictionary.SetAt(text, rasterImageDef);
                                transaction.AddNewlyCreatedDBObject(rasterImageDef, true);
                                string   layer_name = _layer_name;
                                ObjectId layer      = GetLayer(database, transaction, ref layer_name);

                                RasterImage rasterImage = new RasterImage();
                                rasterImage.ImageDefId = (rasterImageDef.ObjectId);
                                rasterImage.SetLayerId(layer, false);
                                //byte b = Convert.ToByte(Math.Floor((100.0 - (double)transparency) / 100.0 * 254.0));
                                Transparency transparency2 = new Autodesk.AutoCAD.Colors.Transparency(100);
                                rasterImage.Transparency = transparency2;
                                rasterImage.Orientation  = new CoordinateSystem3d(new Point3d(left_up.X, left_up.Y, 0), new Vector3d(resulotion * 256, 0, 0), new Vector3d(0, resulotion * 256, 0));
                                BlockTable       blockTable       = (BlockTable)transactionManager.GetObject(database.BlockTableId, 0, false);
                                BlockTableRecord blockTableRecord = (BlockTableRecord)transactionManager.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                                rasterImage.ColorIndex = (256);
                                objectId = blockTableRecord.AppendEntity(rasterImage);
                                transactionManager.AddNewlyCreatedDBObject(rasterImage, true);
                                rasterImage.AssociateRasterDef(rasterImageDef);
                                RasterImage.EnableReactors(true);
                                rasterImageDef.UpdateEntities();
                                try
                                {
                                    rasterImageDef.UpdateEntities();
                                }
                                catch (System.Exception ex)
                                {
                                }
                            }
                        }

                        //DrawOrderTable drawOrderTable = (DrawOrderTable)transaction.GetObject(blockTableRecord.DrawOrderTableId, OpenMode.ForWrite);
                        //ObjectIdCollection objectIdCollection = new ObjectIdCollection();
                        //objectIdCollection.Add(objectId);
                        //drawOrderTable.MoveToBottom(objectIdCollection);

                        transaction.Commit();
                    }
                }
                result = objectId;
            }
            catch (System.Exception ex)
            {
                string   message   = ex.Message;
                ObjectId arg_2FE_0 = ObjectId.Null;
                result = ObjectId.Null;
            }
            catch
            {
                //rrorReport.ShowErrorMessage(AfaStrings.UnexpectedErrorInAddingRasterImage);
                result = ObjectId.Null;
            }
            lockLayerOrNot(_layer_name, true);
            return(result);
        }