コード例 #1
0
        public static void UpdateSpreadPoints(Document document)
        {
            var vm     = new SpreadPointSettingsViewModel();
            var dialog = new SpreadPointSettingsDlg()
            {
                DataContext = vm
            };
            var dlgResult = dialog.ShowDialog();

            if (dlgResult == null || !dlgResult.Value)
            {
                return;
            }

            var mapScale = MapScaleUtils.GetApplicationMapScale();

            if (mapScale == null)
            {
                return;
            }

            var settings = new SpreadPointSettings()
            {
                InsertCode = vm.ShowPointCode,
                InsertId   = vm.ShowPointId,
                Scale      = mapScale.Value / 1000.0
            };

            SpreadPointUtils.UpdateSpreadPoints(document, settings);
        }
コード例 #2
0
        public static IEnumerable <ObjectId> InsertSpreadPoints(Document document, IEnumerable <SpreadPoint> spreadPoints,
                                                                SpreadPointSettings settings)
        {
            var result = new List <ObjectId>();

            // Create text style
            var textStyleId = CreateSpreadPointTextStyle(settings, document.Database);
            // Create layer
            var layerId = CreateSpreadPointLayer(settings, document.Database);

            // Insert points
            using (var transaction = document.Database.TransactionManager.StartTransaction())
            {
                var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(document.Database);
                var modelspace   = (BlockTableRecord)transaction.GetObject(modelspaceId, OpenMode.ForWrite);
                foreach (var spreadPoint in spreadPoints)
                {
                    var ids = InsertSpreadPoint(spreadPoint, modelspace, transaction, layerId, textStyleId, settings);
                    result.AddRange(ids);
                }
                transaction.Commit();
            }

            return(result);
        }
コード例 #3
0
        private static ObjectId CreateSpreadPointTextStyle(SpreadPointSettings settings, Database database)
        {
            ObjectId result = ObjectId.Null;

            using (var transaction = database.TransactionManager.StartTransaction())
            {
                var textStyleTable = (TextStyleTable)transaction.GetObject(database.TextStyleTableId, OpenMode.ForRead);
                if (textStyleTable.Has(settings.TextStyleName))
                {
                    result = textStyleTable[settings.TextStyleName];
                }
                else
                {
                    textStyleTable.UpgradeOpen();
                    var textStyleRecord = new TextStyleTableRecord();
                    textStyleRecord.Name            = settings.TextStyleName;
                    textStyleRecord.FileName        = settings.TextStyleFontFileName;
                    textStyleRecord.BigFontFileName = settings.TextStyleBigFontFileName;
                    result = textStyleTable.Add(textStyleRecord);
                    transaction.AddNewlyCreatedDBObject(textStyleRecord, add: true);
                }
                transaction.Commit();
            }
            return(result);
        }
コード例 #4
0
        private static ObjectId CreateSpreadPointLayer(SpreadPointSettings settings, Database database)
        {
            ObjectId result = ObjectId.Null;

            using (var transaction = database.TransactionManager.StartTransaction())
            {
                var layerTableId = database.LayerTableId;
                var layerTable   = (LayerTable)transaction.GetObject(layerTableId, OpenMode.ForRead);
                if (layerTable.Has(settings.LayerName))
                {
                    result = layerTable[settings.LayerName];
                }
                else
                {
                    layerTable.UpgradeOpen();
                    var layerTableRecord = new LayerTableRecord()
                    {
                        Name  = settings.LayerName,
                        Color = settings.LayerColor.ToAcadColor()
                    };
                    result = layerTable.Add(layerTableRecord);
                    transaction.AddNewlyCreatedDBObject(layerTableRecord, add: true);
                }
                transaction.Commit();
            }
            return(result);
        }
コード例 #5
0
        public static void ImportSpreadPoints(Document document, bool insertId, bool insertCode)
        {
            var mapScale = MapScaleUtils.GetApplicationMapScale();

            if (mapScale == null || mapScale.Value.EqualsWithTolerance(0.0))
            {
                bool success = SetMapScale(document);
                if (!success)
                {
                    return;
                }
                mapScale = MapScaleUtils.GetApplicationMapScale();
            }

            // Open file dialog to select dat file
            // http://through-the-interface.typepad.com/through_the_interface/2007/08/using-autocads-.html
            var fileDialog = new OpenFileDialog("导入展点文件", defaultName: null,
                                                extension: "dat;*", dialogName: "SelectFile",
                                                flags: OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles);
            var dialogResult = fileDialog.ShowDialog();

            if (dialogResult != DialogResult.OK)
            {
                return;
            }

            // Create settings.
            var settings = new SpreadPointSettings()
            {
                InsertId   = insertId,
                InsertCode = insertCode,
                Scale      = mapScale.Value / 1000.0
            };

            var spreadPoints = SpreadPointUtils.ReadSpreadPointsFromFile(fileDialog.Filename);
            var ids          = SpreadPointUtils.InsertSpreadPoints(document, spreadPoints, settings);

            if (!ids.Any())
            {
                return;
            }

            Extents3d extents = GeometryUtils.SafeGetGeometricExtents(ids);

            EditorUtils.ZoomToWin(document.Editor, extents, 1.2);
        }
コード例 #6
0
        public static void UpdateSpreadPoints(Document document, SpreadPointSettings settings)
        {
            // Create text style
            var textStyleId = CreateSpreadPointTextStyle(settings, document.Database);
            // Create layer
            var layerId = CreateSpreadPointLayer(settings, document.Database);

            List <ObjectId> spreadPointIds = new List <ObjectId>();

            // Get all spread point Ids.
            using (var transaction = document.Database.TransactionManager.StartTransaction())
            {
                // Get all spread points
                var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(document.Database);
                var modelspace   = (BlockTableRecord)transaction.GetObject(modelspaceId, OpenMode.ForRead);
                foreach (ObjectId objId in modelspace)
                {
                    var dbPoint = transaction.GetObject(objId, OpenMode.ForRead) as DBPoint;
                    if (dbPoint == null)
                    {
                        continue;
                    }
                    if (IsSpreadPoint(dbPoint))
                    {
                        spreadPointIds.Add(objId);
                    }
                }
                transaction.Commit();
            }

            // Update spread point annotation
            using (var transaction = document.Database.TransactionManager.StartTransaction())
            {
                // Get all spread points
                var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(document.Database);
                var modelspace   = (BlockTableRecord)transaction.GetObject(modelspaceId, OpenMode.ForWrite);

                foreach (var spreadPointId in spreadPointIds)
                {
                    var dbPoint      = (DBPoint)transaction.GetObject(spreadPointId, OpenMode.ForRead);
                    var spreadPoint  = GetSpreadPoint(dbPoint);
                    var annotationId = GetSpreadPointAnnotationId(dbPoint, transaction);

                    // If the point has annotation.
                    if (!annotationId.IsNull)
                    {
                        var dbText = (DBText)transaction.GetObject(annotationId, OpenMode.ForWrite);
                        if (settings.InsertId)
                        {
                            dbText.TextString = spreadPoint.Name;
                        }
                        else if (settings.InsertCode)
                        {
                            dbText.TextString = spreadPoint.Code;
                        }
                        else // No id, no code
                        {
                            dbText.Erase();
                        }
                    }
                    else if (settings.InsertId || settings.InsertCode)
                    {
                        var text   = settings.InsertId ? spreadPoint.Name : spreadPoint.Code;
                        var textId = InsertPointAnnotation(text, spreadPoint.Point, modelspace, transaction,
                                                           layerId, textStyleId, settings);
                        var groupId = GetSpreadPointGroupId(dbPoint, transaction);
                        var group   = (Group)transaction.GetObject(groupId, OpenMode.ForWrite);
                        group.Append(textId);
                    }
                }
                transaction.Commit();
            }
        }
コード例 #7
0
        private static ObjectId InsertPointAnnotation(String text, Point3d basePosition, BlockTableRecord space,
                                                      Transaction transaction, ObjectId layerId, ObjectId textStyleId, SpreadPointSettings settings)
        {
            var dbText = new DBText();

            dbText.TextString     = text;
            dbText.HorizontalMode = TextHorizontalMode.TextLeft;
            dbText.VerticalMode   = TextVerticalMode.TextBase;
            dbText.TextStyleId    = textStyleId;
            dbText.LayerId        = layerId;
            dbText.Color          = settings.Color.ToAcadColor();
            dbText.Height         = settings.FontHeight * settings.Scale;
            dbText.WidthFactor    = 0.8;
            var vector   = new Vector3d(settings.AnnotationXOffset * settings.Scale, settings.AnnotationYOffset * settings.Scale, 0.0);
            var position = basePosition + vector;

            dbText.Position = position;
            // If vertical mode is .TextBase, then the position point is used to determine the text's position.
            // The alignment point is recalculated based on the text string and the position point's value.
            // dbText.AlignmentPoint = position;
            var objectId = space.AppendEntity(dbText);

            transaction.AddNewlyCreatedDBObject(dbText, add: true);
            return(objectId);
        }
コード例 #8
0
        private static IEnumerable <ObjectId> InsertSpreadPoint(SpreadPoint spreadPoint, BlockTableRecord space, Transaction transaction,
                                                                ObjectId layerId, ObjectId textStyleId, SpreadPointSettings settings)
        {
            var result       = new List <ObjectId>();
            var idCollection = new ObjectIdCollection();

            // Add new point
            var dbPoint = new DBPoint(spreadPoint.Point);

            dbPoint.LayerId = layerId;
            dbPoint.Color   = settings.Color.ToAcadColor(); // Color
            var objId = space.AppendEntity(dbPoint);

            // Add xdata
            // Id - compitable with CASS.
            XDataUtils.SetXDataByAppName(layerId.Database, dbPoint, _nameAppName, new object[] { spreadPoint.Name });
            // Code - compitable with CASS
            XDataUtils.SetXDataByAppName(layerId.Database, dbPoint, _codeAppName, new object[] { spreadPoint.Code });

            transaction.AddNewlyCreatedDBObject(dbPoint, add: true);

            idCollection.Add(objId);
            result.Add(objId);

            // Add id text
            if (settings.InsertId)
            {
                var textId = InsertPointAnnotation(spreadPoint.Name, spreadPoint.Point, space, transaction, layerId,
                                                   textStyleId, settings);

                idCollection.Add(textId);
                result.Add(textId);
            }

            // Add code
            if (settings.InsertCode && !String.IsNullOrEmpty(spreadPoint.Code))
            {
                var codeId = InsertPointAnnotation(spreadPoint.Code, spreadPoint.Point, space, transaction, layerId,
                                                   textStyleId, settings);

                idCollection.Add(codeId);
                result.Add(codeId);
            }

            CreateNewGroup(space.Database, "sprdpt", idCollection, transaction);
            return(result);
        }