コード例 #1
0
        /// <summary>
        /// Adds the predefined hatch.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="patternName">Name of the pattern.</param>
        /// <returns></returns>
        public static ObjectId AddPredefinedHatch(Transaction trans, Point2dCollection points, string layername, bool isClosed, string patternName)
        {
            //_logger.Debug("Start AddPredefinedHatch");
            ObjectId id = ObjectId.Null;

            Autodesk.AutoCAD.DatabaseServices.Database           db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Hatch hatch = new Hatch())
            {
                hatch.SetDatabaseDefaults();
                hatch.Layer = layername;

                id = AddToDatabase(db, hatch, trans);

                hatch.UpgradeOpen();
                //hatch.HatchStyle = HatchStyle.Outer;
                hatch.Associative  = true;
                hatch.PatternScale = 100.0;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                double buldge = 0.0;

                HatchLoop loop = new HatchLoop(HatchLoopTypes.Polyline);
                foreach (Point2d pt in points)
                {
                    BulgeVertex bv = new BulgeVertex(pt, buldge);
                    loop.Polyline.Add(bv);
                }
                hatch.AppendLoop(loop);
                hatch.EvaluateHatch(true);
            }
            //_logger.Debug("End AddPredefinedHatch");
            return(id);
        }
コード例 #2
0
        /// <summary>
        ///     Adds the predefined hatch.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="patternName">Name of the pattern.</param>
        /// <returns></returns>
        public static ObjectId AddPredefinedHatch(Transaction trans, Point2dCollection points, string layername,
                                                  bool isClosed, string patternName)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start AddPredefinedHatch");
            var id = ObjectId.Null;
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            var tm = db.TransactionManager;

            using (var hatch = new Hatch())
            {
                hatch.SetDatabaseDefaults();
                hatch.Layer = layername;

                id = AddToDatabase(db, hatch, trans);

                hatch.UpgradeOpen();
                //hatch.HatchStyle = HatchStyle.Outer;
                hatch.Associative  = true;
                hatch.PatternScale = 100.0;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                var buldge = 0.0;

                var loop = new HatchLoop(HatchLoopTypes.Polyline);
                foreach (var pt in points)
                {
                    var bv = new BulgeVertex(pt, buldge);
                    loop.Polyline.Add(bv);
                }
                hatch.AppendLoop(loop);
                hatch.EvaluateHatch(true);
            }
            PGA.MessengerManager.MessengerManager.AddLog("End AddPredefinedHatch");
            return(id);
        }
コード例 #3
0
        private AcadDB.Polyline GetPolylineFromBulgeVertexCollection(BulgeVertexCollection bulges)
        {
            var    polyline   = new AcadDB.Polyline(bulges.Count);
            double totalBulge = 0;

            for (int i = 0; i < bulges.Count; i++)
            {
                BulgeVertex bulgeVertex = bulges[i];
                polyline.AddVertexAt(i, bulgeVertex.Vertex, bulgeVertex.Bulge, 1.0, 1.0);
                totalBulge += bulgeVertex.Bulge;
            }
            polyline.Closed = bulges[0].Vertex.IsEqualTo(bulges[bulges.Count - 1].Vertex) ? true : false;
            return(polyline);
        }
コード例 #4
0
        Coordinate[] GetMPolygonLoopCoordinates(MPolygon multiPolygon, MPolygonLoop multiPolygonLoop)
        {
            var coordinateList = new CoordinateList();
            int num            = multiPolygonLoop.Count - 1;

            for (var i = 0; i <= num; i++)
            {
                BulgeVertex bulgeVertex = multiPolygonLoop[i];
                if (Math.Abs(bulgeVertex.Bulge) < 1e-06)
                {
                    coordinateList.Add(this.ReadCoordinate(bulgeVertex.Vertex), this.AllowRepeatedCoordinates);
                }
                else
                {
                    Point2d vertex;
                    if (i + 1 <= multiPolygonLoop.Count - 1)
                    {
                        vertex = multiPolygonLoop[i + 1].Vertex;
                    }
                    else
                    {
                        vertex = multiPolygonLoop[0].Vertex;
                    }
                    var tessellatedCurveCoordinates = this.GetTessellatedCurveCoordinates(multiPolygon.Ecs, bulgeVertex.Vertex, vertex, bulgeVertex.Bulge);
                    for (var j = 0; j < tessellatedCurveCoordinates.Length; j++)
                    {
                        coordinateList.Add(tessellatedCurveCoordinates[j], this.AllowRepeatedCoordinates);
                    }
                }
            }
            if (!coordinateList[0].Equals2D(coordinateList[coordinateList.Count - 1]))
            {
                coordinateList.Add(coordinateList[0]);
            }
            return(coordinateList.ToCoordinateArray());
        }
コード例 #5
0
        public static HatchModel Hatch2Model(Hatch dbText)
        {
            HatchModel dbModel = new HatchModel();

            int cont = dbText.NumberOfLoops;

            for (int i = 0; i < cont; i++)
            {
                dbModel.loopPoints.Add(i, new ColorAndPointItemModel());
                HatchLoop loop = dbText.GetLoopAt(i);

                ColorAndPointItemModel cpModel = new ColorAndPointItemModel();
                if (i == 0)
                {
                    cpModel.Color = dbText.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(dbText.LayerId) : System.Drawing.ColorTranslator.ToHtml(dbText.Color.ColorValue);
                }
                else
                {
                    cpModel.Color = "#FFFFFF";
                    //  cpModel.ZIndex = "1";
                }

                //if (loop.Polyline.Count == 3)
                //{
                //}

                if (loop.IsPolyline && loop.Polyline.Count > 3)
                {
                    for (int j = 0; j < loop.Polyline.Count - 1; j++)
                    {
                        BulgeVertex vertex  = loop.Polyline[j];
                        BulgeVertex vertex1 = loop.Polyline[j + 1];
                        if (vertex.Bulge != 0)
                        {
                            cpModel.loopPoints.AddRange(MethodCommand.GetArcPointsByBulge(vertex.Vertex, vertex1.Vertex, vertex.Bulge));
                        }
                        else
                        {
                            cpModel.loopPoints.Add(Point2d2Pointf(vertex.Vertex));
                        }
                    }


                    if (dbText.NumberOfHatchLines > 0)
                    {
                        Line2dCollection cl = dbText.GetHatchLinesData();
                    } //foreach (Line2d itemi in )
                      //{

                    //}
                }
                else
                {
                    Curve2dCollection col_cur2d = loop.Curves;
                    foreach (Curve2d item in col_cur2d)
                    {
                        Point2d[] M_point2d = item.GetSamplePoints(20);
                        foreach (Point2d point in M_point2d)
                        {
                            cpModel.loopPoints.Add(Point2d2Pointf(point));
                        }
                    }
                }

                if (cpModel.loopPoints[0] != cpModel.loopPoints[cpModel.loopPoints.Count - 1])
                {
                    cpModel.loopPoints.Add(cpModel.loopPoints[0]);
                }
                dbModel.loopPoints[i] = cpModel;
            }

            for (int i = 0; i < dbModel.loopPoints.Count; i++)
            {
                for (int j = 0; j < dbModel.loopPoints.Count; j++)
                {
                    if (i != j)
                    {
                        if (MethodCommand.PointsAllInPoints(dbModel.loopPoints[j].loopPoints, dbModel.loopPoints[i].loopPoints))
                        {
                            dbModel.loopPoints[j].ZIndex = "2";
                        }
                    }
                }
            }
            try
            {
                dbModel.Area = dbText.Area;
            }
            catch
            { }
            //   dbModel.Color =
            return(dbModel);
        }
コード例 #6
0
        public static HatchModel Hatch2Model(Hatch dbText, AttributeModel atModel)
        {
            HatchModel dbModel = new HatchModel();

            try
            {
                dbModel.Area = dbText.Area;
            }
            catch
            { }

            int    cont  = dbText.NumberOfLoops;
            string color = "";

            for (int i = 0; i < cont; i++)
            {
                dbModel.loopPoints.Add(i, new ColorAndPointItemModel());
                HatchLoop loop = dbText.GetLoopAt(i);

                ColorAndPointItemModel cpModel = new ColorAndPointItemModel();
                if (i == 0)
                {
                    color = cpModel.Color = dbText.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(dbText.LayerId) : System.Drawing.ColorTranslator.ToHtml(dbText.Color.ColorValue);
                }
                else
                {
                    cpModel.Color = "#FFFFFF";
                    //  cpModel.ZIndex = "1";
                }
                if (loop.IsPolyline)
                {
                    for (int j = 0; j < loop.Polyline.Count - 1; j++)
                    {
                        BulgeVertex vertex  = loop.Polyline[j];
                        BulgeVertex vertex1 = loop.Polyline[j + 1];
                        if (vertex.Bulge != 0)
                        {
                            cpModel.loopPoints.AddRange(MethodCommand.GetArcPointsByBulge(vertex.Vertex, vertex1.Vertex, vertex.Bulge));
                        }
                        else
                        {
                            cpModel.loopPoints.Add(Point2d2Pointf(vertex.Vertex));
                        }
                    }


                    if (dbText.NumberOfHatchLines > 0)
                    {
                        Line2dCollection cl = dbText.GetHatchLinesData();
                    } //foreach (Line2d itemi in )
                      //{

                    //}
                }
                else
                {
                    Curve2dCollection col_cur2d = loop.Curves;
                    foreach (Curve2d item in col_cur2d)
                    {
                        Point2d[] M_point2d = item.GetSamplePoints(20);
                        foreach (Point2d point in M_point2d)
                        {
                            cpModel.loopPoints.Add(Point2d2Pointf(point));
                        }
                    }
                }

                if (cpModel.loopPoints[0] != cpModel.loopPoints[cpModel.loopPoints.Count - 1])
                {
                    cpModel.loopPoints.Add(cpModel.loopPoints[0]);
                }
                cpModel.attItemList = new List <AttributeItemModel>();
                foreach (AttributeItemModel item in atModel.attributeItems)
                {
                    string attValue = "";

                    switch (item.AtItemType)
                    {
                    case AttributeItemType.Area:
                        attValue = dbModel.Area.ToString();
                        break;

                    case AttributeItemType.TxtHeight:

                        break;

                    case AttributeItemType.Color:
                        attValue = color;
                        break;

                    case AttributeItemType.Content:

                        break;

                    case AttributeItemType.LayerName:
                        attValue = dbText.Layer;
                        break;

                    case AttributeItemType.LineScale:
                        attValue = dbText.LinetypeScale.ToString();
                        break;

                    case AttributeItemType.LineType:
                        attValue = GetLayerLineTypeByID(dbText);
                        break;

                    case AttributeItemType.Overallwidth:
                        break;

                    case AttributeItemType.TotalArea:
                        attValue = dbModel.Area.ToString();
                        break;
                    }
                    if (!string.IsNullOrEmpty(attValue))
                    {
                        item.AtValue = attValue;
                        cpModel.attItemList.Add(item);
                    }
                    else
                    {
                    }
                }
                dbModel.loopPoints[i] = cpModel;
            }

            for (int i = 0; i < dbModel.loopPoints.Count; i++)
            {
                for (int j = 0; j < dbModel.loopPoints.Count; j++)
                {
                    if (i != j)
                    {
                        if (MethodCommand.PointsAllInPoints(dbModel.loopPoints[j].loopPoints, dbModel.loopPoints[i].loopPoints))
                        {
                            dbModel.loopPoints[j].ZIndex = "2";
                        }
                    }
                }
            }

            //   dbModel.Color =
            return(dbModel);
        }
コード例 #7
0
        void HatchPerimeter(ObjectId entId)
        {
            Document activeDoc = Application.DocumentManager.MdiActiveDocument;

            Database db = activeDoc.Database;

            Editor ed = activeDoc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Hatch hatch = tr.GetObject(entId, OpenMode.ForRead) as Hatch;

                int    nLoops = hatch.NumberOfLoops;
                double totalExternalPerimeter = 0.0;
                double totalInternalPerimeter = 0.0;

                for (int i = 0; i < nLoops; i++)
                {
                    double loopLength = 0.0;

                    HatchLoopTypes hlt = hatch.LoopTypeAt(i);

                    HatchLoop hatchLoop = hatch.GetLoopAt(i);

                    if ((hatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) == HatchLoopTypes.Polyline)
                    {
                        BulgeVertexCollection bulges = hatchLoop.Polyline;
                        int nVertices = bulges.Count;

                        Polyline testPoly = new Polyline(nVertices);

                        for (int vx = 0; vx < bulges.Count; vx++)
                        {
                            BulgeVertex bv = bulges[vx];

                            testPoly.AddVertexAt(vx, bv.Vertex, bv.Bulge, 1.0, 1.0);
                        }

                        LineSegment3d ls = new LineSegment3d();

                        CircularArc3d cs = new CircularArc3d();

                        double d = 0.0, p1 = 0.0, p2 = 1.0;

                        for (int ver = 0; ver < nVertices - 1; ver++)
                        {
                            d = testPoly.GetBulgeAt(ver);

                            if (d <= 1e-5)
                            {
                                ls = testPoly.GetLineSegmentAt(ver);

                                loopLength += ls.Length;
                            }

                            else
                            {
                                Point2d v1 = new Point2d(bulges[ver].Vertex.X, bulges[ver].Vertex.Y);

                                Point2d v2 = new Point2d(bulges[ver + 1].Vertex.X, bulges[ver + 1].Vertex.Y);

                                if (v1.IsEqualTo(v2) == false)
                                {
                                    cs = testPoly.GetArcSegmentAt(ver);

                                    p1 = cs.GetParameterOf(cs.StartPoint);

                                    p2 = cs.GetParameterOf(cs.EndPoint);

                                    loopLength += cs.GetLength
                                                      (p1, p2, Tolerance.Global.EqualPoint);
                                }
                            }
                        }
                    }

                    else
                    {
                        Curve2dCollection curves = hatchLoop.Curves;

                        if (curves != null)
                        {
                            foreach (Curve2d curve in curves)
                            {
                                if (hatchLoop.LoopType == HatchLoopTypes.External)
                                {
                                    totalExternalPerimeter += curve.GetLength(0.0, 1.0);
                                }

                                else
                                {
                                    totalInternalPerimeter += curve.GetLength(0.0, 1.0);
                                }
                            }
                        }
                    }

                    if (nLoops > 1 &&

                        ((hlt & HatchLoopTypes.External) != HatchLoopTypes.External))
                    {
                        totalInternalPerimeter += loopLength;
                    }
                    else
                    {
                        totalExternalPerimeter += loopLength;
                    }
                }
                ed.WriteMessage(string.Format("\nExternal Perimeter : {0}", totalExternalPerimeter));

                ed.WriteMessage(string.Format("\nInternal Perimeter : {0}", totalInternalPerimeter));

                tr.Commit();
            }
        }