Exemple #1
0
        /// <summary>
        /// 插入标注
        /// </summary>
        /// <param name="_esymb"></param>
        /// <param name="position"></param>
        /// <param name="rotateAngle"></param>
        /// <param name="layerId"></param>
        /// <param name="alignment"></param>
        /// <param name="xmlDbManager"></param>
        public static void InsertLabel(ElectronSymbol _esymb, Point3d position, double rotateAngle, ObjectId layerId, int alignment, XmlDBManager xmlDbManager)
        {
            if (_esymb.EntityState != EntityState.Delete)
            {
                _esymb.EntityType = EntityType.Label;
                var value = new LabelEventArgs {
                    xmlDB = xmlDbManager, color = CADColor.FromRgb(0, 0, 0)
                };
                value = GetLabelTextStyle(_esymb, value);

                if (string.IsNullOrEmpty(value.lbText))
                {
                    value.lbText = "";
                }
                //打开图层再添加标注
                PublicMethod.Instance.SetLayerDisplay(layerId, false);
                //标注高度
                var lbHeight = value.lbHeight / MapConfig.Instance.earthscale;

                if (value.lbText.Contains("\n"))
                {
                    var mText = Mtext(value.lbText, position, rotateAngle, lbHeight, layerId);
                    AddEntity(mText, _esymb);
                }
                else
                {
                    var mText = AddText(value.lbText, position, rotateAngle, lbHeight, layerId, value.color, alignment);
                    AddEntity(mText, _esymb);
                }
            }
        }
 /// <summary>
 /// 加载标注
 /// </summary>
 /// <param name="xmlDBManager"> </param>
 /// <param name="layerLableName">层名称</param>
 /// <param name="className">类型名称</param>
 /// <param name="index"></param>
 private void LoadSymbolLabel(XmlDBManager xmlDBManager, string layerLableName, string className, int index)
 {
     try
     {
         var type = TypeCache.Instance.GetTypeFromCache(typeof(DBEntity), className);
         if (xmlDBManager.Has(type))
         {
             var lb = xmlDBManager.GetEntities(type).Cast <ElectronSymbol>().ToList();
             //大于0,则有多个标注
             if (index > 0)
             {
                 lb.ForEach(o => o.FinderFuncNumber = o.G3E_FNO * 10 + index);
             }
             else
             {
                 lb.ForEach(o => o.FinderFuncNumber = o.G3E_FNO);
             }
             var lbs = GetLabel_lb_sdogeom(xmlDBManager, className);
             DCadApi.addLabelLayer(layerLableName, lb, lbs, CADColor.FromRgb(255, 255, 255), xmlDBManager);
         }
     }
     catch (Exception ex)
     {
         LogManager.Instance.Error(ex);
     }
 }
Exemple #3
0
        /// <summary>
        /// 获取标注样式
        /// </summary>
        /// <param name="g3e_UserName"></param>
        /// <param name="e"></param>
        private static void GetG3e_textstyle(string g3e_UserName, LabelEventArgs e)
        {
            const double increment = 0.05;

            try
            {
                var textstyle = CDDBManager.Instance.GetEntity <G3e_textstyle>(o => o.G3E_USERNAME.ToUpper() == g3e_UserName.ToUpper());
                if (textstyle != null)
                {
                    if (textstyle.G3E_COLOR != null)
                    {
                        e.color = CADColor.FromColor(Color.FromArgb((int)textstyle.G3E_COLOR));
                    }
                    if (textstyle.G3E_SIZE != null)
                    {
                        e.lbHeight = (double)textstyle.G3E_SIZE + increment;
                    }
                }
                else
                {
                    e.lbHeight = 0.2 + increment;
                    e.color    = CADColor.FromRgb(0, 0, 0);
                    LogManager.Instance.Error(string.Format("获取样式失败!{0}", g3e_UserName));
                }
            }
            catch
            {
                e.lbHeight = 0.2 + increment;
                e.color    = CADColor.FromRgb(0, 0, 0);
                LogManager.Instance.Error(string.Format("获取样式失败!{0}", g3e_UserName));
            }
        }
Exemple #4
0
        private void ShowTransientErrorMark(CheckResult checkResult)
        {
            var markshape = ErrorMarkSettings.CurrentSettings.MarkShapes[checkResult.ActionType];
            var color     = ErrorMarkSettings.CurrentSettings.MarkColors[checkResult.ActionType];
            var acadColor = AcadColor.FromRgb(color.R, color.G, color.B);

            _transientGraphicsMgr.CreateTransientErrorMarks(markshape, checkResult.MarkPoints, acadColor, checkResult.TransientDrawables);
        }
Exemple #5
0
        /// <summary>
        /// 获取标注值
        /// </summary>
        /// <param name="g3e_cno"></param>
        /// <param name="g3e_fno"> </param>
        /// <param name="g3e_fid"> </param>
        /// <returns></returns>
        public static LabelEventArgs GetLabelText(string g3e_cno, long g3e_fid, long g3e_fno)
        {
            var labelEventArgs = new LabelEventArgs {
                xmlDB = DBManager.Instance as XmlDBManager, color = CADColor.FromRgb(0, 0, 0)
            };

            labelEventArgs = GetLabelTextStyle(g3e_cno, g3e_fid, g3e_fno, labelEventArgs);
            return(labelEventArgs);
        }
Exemple #6
0
        /// <summary>
        /// 获取标注值
        /// </summary>
        /// <param name="g3e_cno"></param>
        /// <param name="g3eObject"> </param>
        /// <returns></returns>
        public static LabelEventArgs GetLabelText(string g3e_cno, G3EObject g3eObject)
        {
            var labelEventArgs = new LabelEventArgs {
                xmlDB = DBManager.Instance as XmlDBManager, color = CADColor.FromRgb(0, 0, 0)
            };

            labelEventArgs = GetLabelTextStyle(g3e_cno, g3eObject.G3E_FID, g3eObject.G3E_FNO, labelEventArgs);
            return(labelEventArgs);
        }
Exemple #7
0
        /// <summary>
        /// 获取标注值
        /// </summary>
        /// <param name="electronSymbol">标注的坐标表</param>
        /// <returns></returns>
        public static LabelEventArgs GetLabelText(ElectronSymbol electronSymbol)
        {
            var labelEventArgs = new LabelEventArgs {
                xmlDB = DBManager.Instance as XmlDBManager, color = CADColor.FromRgb(0, 0, 0)
            };

            labelEventArgs = GetLabelTextStyle(electronSymbol, labelEventArgs);
            return(labelEventArgs);
        }
Exemple #8
0
        public void Execute(string layerName)
        {
            // Get the current document and database
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            // Lock the new document
            using (DocumentLock acLckDoc = acDoc.LockDocument())
            {
                // Start a transaction
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    // Open the Layer table for read
                    LayerTable acLyrTbl;
                    acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                                 OpenMode.ForRead) as LayerTable;

                    LayerTableRecord acLyrTblRec;

                    if (!acLyrTbl.Has(layerName))
                    {
                        acLyrTblRec = new LayerTableRecord();

                        // Assign the layer a name
                        acLyrTblRec.Name = layerName;

                        // Upgrade the Layer table for write
                        if (acLyrTbl.IsWriteEnabled == false)
                        {
                            acLyrTbl.UpgradeOpen();
                        }

                        // Append the new layer to the Layer table and the transaction
                        acLyrTbl.Add(acLyrTblRec);
                        acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);

                        Color acadColor;
                        // Define an array of colors for the layers
                        using (var hashAlgorithm = new SHA1Managed())
                        {
                            byte[] rgb = hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(layerName)).Take(3).ToArray();
                            acadColor = Color.FromRgb(rgb[0], rgb[1], rgb[2]);
                        }

                        // Set the color of the layer
                        acLyrTblRec.Color      = acadColor;
                        acLyrTblRec.LineWeight = LineWeight.LineWeight030;
                    }

                    // Save the changes and dispose of the transaction
                    acTrans.Commit();
                }
            }
        }
        /// <summary>
        /// 高亮显示
        /// </summary>
        /// <param name="oc"></param>
        /// <returns></returns>
        private static Dictionary <ObjectId, CADColor> Entityhighlight(IEnumerable oc)
        {
            var dic = new Dictionary <ObjectId, CADColor>();

            foreach (ObjectId objectId in oc)
            {
                var oldColor = DCadApi.EditorPointSymbol(objectId, CADColor.FromRgb(0, 255, 0));
                if (!dic.ContainsKey(objectId))
                {
                    dic.Add(objectId, oldColor);
                }
            }
            return(dic);
        }
Exemple #10
0
        ///  <summary>
        ///  由插入点、文字内容、文字样式、文字高度、文字宽度创建多行文字
        ///  </summary>
        ///  <param name="textString">文字内容</param>
        ///  <param name="location"> 基点</param>
        ///  <param name="lbHeight"> 文字高度</param>
        ///  <param name="rot">文字转角</param>
        /// <param name="layerId">层ID</param>
        /// <param name="alginment"> </param>
        /// <returns></returns>
        public static MText Mtext(string textString, Point3d location, double lbHeight, double rot, ObjectId layerId, int alginment)
        {
            var txt = new MText
            {
                Location    = location,
                Rotation    = rot,
                Contents    = textString,
                LayerId     = layerId,
                TextHeight  = lbHeight,
                Color       = CADColor.FromRgb(0, 0, 0),
                TextStyleId = PublicMethod.Instance.MultTextStyleId
            };

            return(txt);
        }
 /// <summary>
 /// 加载图形
 /// </summary>
 /// <param name="_layerName"></param>
 /// <param name="esymbs"></param>
 /// <param name="color"></param>
 /// <param name="strLineType"></param>
 /// <param name="lineWidth"></param>
 private void AddElectronSymbol(string _layerName, IEnumerable <ElectronSymbol> esymbs, CADColor color, string strLineType, double lineWidth)
 {
     if (esymbs.Any())
     {
         //添加图层
         var layerId = DCadApi.addLayer(_layerName, CADColor.FromRgb(255, 255, 255));
         if (layerId != ObjectId.Null)
         {
             foreach (var _ee in esymbs)
             {
                 //加载符号
                 AddElectronSymbol(layerId, _ee, color, strLineType, lineWidth);
             }
         }
     }
 }
        /// <summary>
        /// The form has been submitted. We now need to check and see if
        /// everything validates and then we can send off our data to the
        /// ConcentricCircles class to actually do the creating of the
        /// circles.
        ///
        /// If we find some invalid data, then we need to let the user know
        /// (via the validationLabel in the form) and keep the form window
        /// open.
        ///
        /// <seealso cref="ConcentricCirclesForm.validationLabel"/>
        /// <seealso cref="ConcentricCircles"/>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createButton_Click(object sender, EventArgs e)
        {
            // check validity (halt processing if necessary)
            var valid = ValidateTextAsNumber("Position X", positionX.Text);

            valid = valid && ValidateTextAsNumber("Position Y", positionY.Text);
            valid = valid && ValidateTextAsNumber("Position Z", positionZ.Text);

            if (!valid)
            {
                return;
            }

            // collect input
            var centerPoint = new Point3d(Double.Parse(positionX.Text),
                                          Double.Parse(positionY.Text),
                                          Double.Parse(positionZ.Text));
            var outerCircleColor = AcColor.FromRgb((byte)outerCircleRed.Value,
                                                   (byte)outerCircleGreen.Value,
                                                   (byte)outerCircleGreen.Value);
            var middleCircleColor = AcColor.FromRgb((byte)middleCircleRed.Value,
                                                    (byte)middleCircleGreen.Value,
                                                    (byte)middleCircleBlue.Value);
            var innerCircleColor = AcColor.FromRgb((byte)innerCircleRed.Value,
                                                   (byte)innerCircleGreen.Value,
                                                   (byte)innerCircleBlue.Value);


            // draw the circles
            ConcentricCircles.DrawConcentricCircles(centerPoint,
                                                    new AcColor[] {
                outerCircleColor,
                middleCircleColor,
                innerCircleColor
            });

            // close the form
            this.Close();
        }
 /// <summary>
 /// 在cad指定图层上添加多个标注
 /// </summary>
 /// <param name="_layerName">图层名称</param>
 /// <param name="_esymb">多个标注对象</param>
 /// <param name="lbs"> </param>
 /// <param name="color"> </param>
 /// <param name="xmlDbManager"> </param>
 /// <returns></returns>
 public static void addLabelLayer(string _layerName, IEnumerable <ElectronSymbol> _esymb, IEnumerable <ElectronBase> lbs, CADColor color, XmlDBManager xmlDbManager)
 {
     try
     {
         var objId = DCadApi.addLayer(_layerName, CADColor.FromRgb(255, 255, 255));
         if (objId != ObjectId.Null)
         {
             foreach (var _ee in _esymb)
             {
                 if (_ee.EntityState == EntityState.Insert)
                 {
                     //var g3e_cno = _ee.GetValue<int>("G3E_CNO");
                     var lb = DCadApi.GetLabel_LB(lbs, _ee.G3E_FID);
                     DCadApi.addLabelLayer(objId, _ee, lb, color, xmlDbManager);
                 }
             }
         }
     }
     catch (Exception exx)
     {
         LogManager.Instance.Error(exx);
     }
 }