Exemple #1
0
        private static Extents3d GetExtents3DPoly(ObjectId selectedObjectId)
        {
            Document    doc = Application.DocumentManager.MdiActiveDocument;
            Editor      ed  = doc.Editor;
            Database    db  = CivilApplicationManager.WorkingDatabase;
            Transaction tr  = db.TransactionManager.StartTransaction();

            // Get the current UCS

            CoordinateSystem3d ucs =
                ed.CurrentUserCoordinateSystem.CoordinateSystem3d;

            using (tr)
            {
                DBObject obj =
                    tr.GetObject(selectedObjectId, OpenMode.ForRead);


                // If a "lightweight" (or optimized) polyline

                Polyline lwp = obj as Polyline;

                if (lwp != null)
                {
                    // Is Polyline Closed
                    if (lwp.Closed)
                    {
                        return(lwp.GeometricExtents);
                    }
                    // Use a for loop to get each vertex, one by one

                    int vn = lwp.NumberOfVertices;

                    for (int i = 0; i < vn; i++)
                    {
                        // Could also get the 3D point here

                        Point2d pt = lwp.GetPoint2dAt(i);

                        ed.WriteMessage("\n" + pt.ToString());
                    }
                }

                else
                {
                    // If an old-style, 2D polyline

                    Polyline2d p2d = obj as Polyline2d;

                    if (p2d != null)
                    {
                        // Use foreach to get each contained vertex

                        foreach (ObjectId vId in p2d)
                        {
                            Vertex2d v2d =
                                (Vertex2d)tr.GetObject(
                                    vId,
                                    OpenMode.ForRead
                                    );

                            ed.WriteMessage(
                                "\n" + v2d.Position.ToString()
                                );
                        }
                    }

                    else
                    {
                        // If an old-style, 3D polyline

                        Polyline3d p3d = obj as Polyline3d;

                        if (p3d != null)
                        {
                            // Use foreach to get each contained vertex

                            foreach (ObjectId vId in p3d)
                            {
                                PolylineVertex3d v3d =
                                    (PolylineVertex3d)tr.GetObject(
                                        vId,
                                        OpenMode.ForRead
                                        );

                                ed.WriteMessage(
                                    "\n" + v3d.Position.ToString()
                                    );
                            }
                        }
                    }
                }

                // Committing is cheaper than aborting

                tr.Commit();
            }
            return(new Extents3d(new Point3d(0, 0, 0), new Point3d(0, 0, 0)));
        }
Exemple #2
0
        public static void ObjectsByLayer()
        {
            Document    doc = Application.DocumentManager.MdiActiveDocument;
            Database    db  = doc.Database;
            Transaction tr  = db.TransactionManager.StartTransaction();


            string output = Path.ChangeExtension(doc.Name, "dat");

            if (doc == null)
            {
                return;
            }
            var ed = doc.Editor;
            // Select the objects to sort
            // Setups the keyword options
            PromptSelectionOptions Opts = new PromptSelectionOptions();

            Opts.MessageForAdding = "\n请选择断面图";
            var psr = ed.GetSelection(Opts);

            if (psr.Status != PromptStatus.OK)
            {
                return;
            }
            // We'll sort them based on a string value (the layer name)
            var map = new Dictionary <ObjectId, string>();

            foreach (dynamic id in psr.Value.GetObjectIds())
            {
                if (id.ObjectClass.Name == "AcDbText")
                {
                    if (id.TextString.Contains("K"))
                    {
                        map.Add(id, id.TextString);
                        WriteMessage(output, id.TextString);
                    }
                    else if (id.TextString.Contains("Wy"))
                    {
                        WriteMessage(output, "#------------------------------------------------------#");
                        map.Add(id, id.TextString);
                        WriteMessage(output, id.TextString);
                    }
                    if (id.Layer == "右标高1")
                    {
                        map.Add(id, id.TextString);
                        WriteMessage(output, "H0=" + id.TextString);
                    }
                    else if (id.Layer == "左标高")
                    {
                        map.Add(id, id.TextString);
                        WriteMessage(output, "H1=" + id.TextString);
                    }
                    else if (id.Layer == "左标高1")
                    {
                        map.Add(id, id.TextString);
                        WriteMessage(output, "H2=" + id.TextString);
                    }
                }
                else if (id.ObjectClass.Name == "AcDb2dPolyline")
                {
                    Polyline2d tmp = (Polyline2d)tr.GetObject(id, OpenMode.ForRead);
                    // tmp.
                    if (tmp.Layer == "dmx")
                    {
                        WriteMessage(output, "dmx");
                        IEnumerator vertices = tmp.GetEnumerator();
                        while (vertices.MoveNext())
                        {
                            ObjectId vetxid = (ObjectId)vertices.Current;
                            Vertex2d vtx    = (Vertex2d)vetxid.GetObject(OpenMode.ForRead);
                            string   loc    = string.Format("{0},{1},0", vtx.Position.X, vtx.Position.Y);
                            WriteMessage(output, loc);
                        }
                    }
                    else if (tmp.Layer == "sjx")
                    {
                        WriteMessage(output, "sjx");
                        IEnumerator vertices = tmp.GetEnumerator();
                        while (vertices.MoveNext())
                        {
                            ObjectId vetxid = (ObjectId)vertices.Current;
                            Vertex2d vtx    = (Vertex2d)vetxid.GetObject(OpenMode.ForRead);
                            string   loc    = string.Format("{0},{1},0", vtx.Position.X, vtx.Position.Y);
                            WriteMessage(output, loc);
                        }
                    }
                }
                else if (id.ObjectClass.Name == "AcDbLine")
                {
                    Line zx = (Line)tr.GetObject(id, OpenMode.ForRead);
                    if (zx.Layer == "zhix")
                    {
                        WriteMessage(output, "X=" + zx.StartPoint.X.ToString());
                    }
                }
            }
            var sorted = map.OrderBy(kv => kv.Value);

            // Print them in order to the command-line
            foreach (var item in sorted)
            {
                ed.WriteMessage("\nObject {0} on layer {1}", item.Key, item.Value);
            }
            tr.Commit();
            tr.Dispose();
        }
 void IShaderUniformContainer.SetUniform(GraphicsContext ctx, string uniformName, Vertex2d v)
 {
     throw new NotImplementedException();
 }
Exemple #4
0
        void CreateBorder(VertexStore vxs, Vertex2d prev, Vertex2d now, Vertex2d next0, Vertex2d next1)
        {
            //now we are on now
            using (Tools.BorrowVxs(out var vxs1))
            {
                vxs.AddMoveTo(now.x, now.y);

                //create outer line-join
                _strokeMath.CreateJoin(vxs1, prev, now, next0);
                vxs.AppendVertexStore(vxs1);
                //create inner line join

                //next outer line join
                vxs1.Clear();//reuse
                _strokeMath.CreateJoin(vxs1, now, next0, next1);
                vxs.AppendVertexStore(vxs1);

                vxs.AddLineTo(next0.x, next0.y);
                vxs.AddCloseFigure();
            }
        }
 /// <summary>
 /// Set uniform state variable (variant type variable).
 /// </summary>
 /// <param name="ctx">
 /// A <see cref="GraphicsContext"/> used for operations.
 /// </param>
 /// <param name="uniformName">
 /// A <see cref="String"/> that specify the variable name in the shader source.
 /// </param>
 /// <param name="v">
 /// A <see cref="Vertex2d"/> holding the uniform variabile data.
 /// </param>
 public void SetVariantUniform(GraphicsContext ctx, string uniformName, Vertex2d v)
 {
     SetVariantUniform(ctx, uniformName, v.x, v.y);
 }
		/// <summary>
		/// Set uniform state variable (variant type variable).
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> used for operations.
		/// </param>
		/// <param name="uniformName">
		/// A <see cref="String"/> that specify the variable name in the shader source.
		/// </param>
		/// <param name="v">
		/// A <see cref="Vertex2d"/> holding the uniform variabile data.
		/// </param>
		public void SetVariantUniform(GraphicsContext ctx, string uniformName, Vertex2d v)
		{
			SetVariantUniform(ctx, uniformName, v.x, v.y);
		}
        public void PrintEntityCoordinates()
        {
            if (!CheckLicense.Check())
            {
                return;
            }

            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Autodesk.AutoCAD.DatabaseServices.Database    db  = doc.Database;
            Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs;
            Matrix3d wcs2ucs = AcadUtility.AcadGraphics.WcsToUcs;

            using (PrintEntitiesForm form = new PrintEntitiesForm())
            {
                // Read settings
                form.SelectPoint    = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectPoint;
                form.SelectCircle   = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectCircle;
                form.SelectLine     = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectLine;
                form.SelectPolyline = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectPolyline;
                form.Select3DFace   = Properties.Settings.Default.Command_PRINTENTCOORDS_Select3DFace;
                form.SelectText     = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectText;
                form.SelectBlock    = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectBlock;

                form.UseUCS = Properties.Settings.Default.Command_PRINTENTCOORDS_UCS;

                form.SetLineFormats(Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.Cast <string>());
                form.Precision = Properties.Settings.Default.Command_PRINTENTCOORDS_Precision;

                if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form) == System.Windows.Forms.DialogResult.OK)
                {
                    // Save changes
                    Properties.Settings.Default.Command_PRINTENTCOORDS_SelectPoint    = form.SelectPoint;
                    Properties.Settings.Default.Command_PRINTENTCOORDS_SelectCircle   = form.SelectCircle;
                    Properties.Settings.Default.Command_PRINTENTCOORDS_SelectLine     = form.SelectLine;
                    Properties.Settings.Default.Command_PRINTENTCOORDS_SelectPolyline = form.SelectPolyline;
                    Properties.Settings.Default.Command_PRINTENTCOORDS_Select3DFace   = form.Select3DFace;
                    Properties.Settings.Default.Command_PRINTENTCOORDS_SelectText     = form.SelectText;
                    Properties.Settings.Default.Command_PRINTENTCOORDS_SelectBlock    = form.SelectBlock;

                    Properties.Settings.Default.Command_PRINTENTCOORDS_UCS = form.UseUCS;

                    string selectedFormat = form.LineFormat;
                    bool   found          = false;
                    foreach (string format in Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat)
                    {
                        if (string.Compare(format, selectedFormat) == 0)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.Insert(0, selectedFormat);
                    }
                    while (Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.Count > 40)
                    {
                        Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.RemoveAt(Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.Count - 1);
                    }
                    Properties.Settings.Default.Command_PRINTENTCOORDS_Precision = form.Precision;

                    Properties.Settings.Default.Save();

                    // Select objects
                    List <TypedValue> tvs = new List <TypedValue>();
                    tvs.Add(new TypedValue((int)DxfCode.Operator, "<OR"));
                    if (form.SelectPoint)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "POINT"));
                    }

                    if (form.SelectCircle)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "CIRCLE"));
                    }

                    if (form.SelectLine)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "LINE"));
                    }

                    if (form.SelectPolyline)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "POLYLINE"));
                    }

                    if (form.SelectPolyline)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"));
                    }

                    if (form.Select3DFace)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "3DFACE"));
                    }

                    if (form.SelectText)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "TEXT"));
                    }

                    if (form.SelectText)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "MTEXT"));
                    }

                    if (form.SelectBlock)
                    {
                        tvs.Add(new TypedValue((int)DxfCode.Start, "INSERT"));
                    }
                    tvs.Add(new TypedValue((int)DxfCode.Operator, "OR>"));
                    SelectionFilter filter = new SelectionFilter(tvs.ToArray());

                    PromptSelectionResult selRes = doc.Editor.GetSelection(filter);
                    if (selRes.Status == PromptStatus.OK)
                    {
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            try
                            {
                                var listPoints    = new List <Point3d>();
                                var listCircles   = new List <Point3d>();
                                var listTexts     = new List <Point3d>();
                                var listBlocks    = new List <Point3d>();
                                var listLines     = new List <Tuple <Point3d, Point3d> >();
                                var listPolylines = new List <Point3dCollection>();
                                var list3DFaces   = new List <Tuple <Point3d, Point3d, Point3d, Point3d> >();

                                Point3d GetPoint(Point3d pt) =>
                                form.UseUCS ? pt : pt.TransformBy(wcs2ucs);

                                // Read objects
                                foreach (ObjectId id in selRes.Value.GetObjectIds())
                                {
                                    if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBPoint)).UnmanagedObject)
                                    {
                                        DBPoint obj = tr.GetObject(id, OpenMode.ForRead) as DBPoint;
                                        listPoints.Add(GetPoint(obj.Position));
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Circle)).UnmanagedObject)
                                    {
                                        Circle obj = tr.GetObject(id, OpenMode.ForRead) as Circle;
                                        listCircles.Add(GetPoint(obj.Center));
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject)
                                    {
                                        DBText obj = tr.GetObject(id, OpenMode.ForRead) as DBText;
                                        listTexts.Add(GetPoint(obj.Position));
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(MText)).UnmanagedObject)
                                    {
                                        MText obj = tr.GetObject(id, OpenMode.ForRead) as MText;
                                        listTexts.Add(GetPoint(obj.Location));
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(BlockReference)).UnmanagedObject)
                                    {
                                        BlockReference obj = tr.GetObject(id, OpenMode.ForRead) as BlockReference;
                                        listBlocks.Add(GetPoint(obj.Position));
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Line)).UnmanagedObject)
                                    {
                                        Line obj = tr.GetObject(id, OpenMode.ForRead) as Line;
                                        listLines.Add(new Tuple <Point3d, Point3d>(GetPoint(obj.StartPoint), GetPoint(obj.EndPoint)));
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Face)).UnmanagedObject)
                                    {
                                        Face obj = tr.GetObject(id, OpenMode.ForRead) as Face;
                                        list3DFaces.Add(new Tuple <Point3d, Point3d, Point3d, Point3d>(
                                                            GetPoint(obj.GetVertexAt(0)), GetPoint(obj.GetVertexAt(1)),
                                                            GetPoint(obj.GetVertexAt(2)), GetPoint(obj.GetVertexAt(3))));
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline)).UnmanagedObject)
                                    {
                                        Polyline          obj    = tr.GetObject(id, OpenMode.ForRead) as Polyline;
                                        Point3dCollection points = new Point3dCollection();
                                        for (int i = 0; i < obj.NumberOfVertices; i++)
                                        {
                                            points.Add(GetPoint(obj.GetPoint3dAt(i)));
                                        }
                                        listPolylines.Add(points);
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline2d)).UnmanagedObject)
                                    {
                                        Polyline2d        obj    = tr.GetObject(id, OpenMode.ForRead) as Polyline2d;
                                        Point3dCollection points = new Point3dCollection();
                                        foreach (ObjectId vId in obj)
                                        {
                                            Vertex2d vertex = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead);
                                            points.Add(GetPoint(vertex.Position));
                                        }
                                        listPolylines.Add(points);
                                    }
                                    else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline3d)).UnmanagedObject)
                                    {
                                        Polyline3d        obj    = tr.GetObject(id, OpenMode.ForRead) as Polyline3d;
                                        Point3dCollection points = new Point3dCollection();
                                        foreach (ObjectId vId in obj)
                                        {
                                            PolylineVertex3d vertex = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
                                            points.Add(GetPoint(vertex.Position));
                                        }
                                        listPolylines.Add(points);
                                    }
                                }

                                // Write text
                                using (System.IO.StreamWriter file = new System.IO.StreamWriter(form.OutputFilename))
                                {
                                    string PrintCoord(double coord) =>
                                    coord.ToString(form.Precision == 0 ? "0" : "0." + new string('0', form.Precision));

                                    string ClearLine(string line) =>
                                    line.Replace("[X]", "").Replace("[Y]", "").Replace("[Z]", "")
                                    .Replace("[X1]", "").Replace("[Y1]", "").Replace("[Z1]", "")
                                    .Replace("[X2]", "").Replace("[Y2]", "").Replace("[Z2]", "")
                                    .Replace("[X3]", "").Replace("[Y3]", "").Replace("[Z3]", "")
                                    .Replace("[X4]", "").Replace("[Y4]", "").Replace("[Z4]", "");

                                    var headerStr = form.LineFormat.Replace("[", "").Replace("]", "");

                                    void PrintPointList(List <Point3d> points)
                                    {
                                        file.WriteLine(headerStr);
                                        int i = 1;

                                        foreach (var pt in points)
                                        {
                                            var str = form.LineFormat;
                                            str = str.Replace("[#]", i.ToString());
                                            str = str.Replace("[X]", PrintCoord(pt.X));
                                            str = str.Replace("[Y]", PrintCoord(pt.Y));
                                            str = str.Replace("[Z]", PrintCoord(pt.Z));
                                            str = str.Replace("[X1]", PrintCoord(pt.X));
                                            str = str.Replace("[Y1]", PrintCoord(pt.Y));
                                            str = str.Replace("[Z1]", PrintCoord(pt.Z));
                                            str = ClearLine(str);
                                            file.WriteLine(str);
                                            i++;
                                        }
                                    }

                                    // Point
                                    if (listPoints.Count > 0)
                                    {
                                        file.WriteLine("POINT({0})", listPoints.Count);
                                        PrintPointList(listPoints);
                                    }
                                    // Circle
                                    if (listCircles.Count > 0)
                                    {
                                        file.WriteLine("CIRCLE({0})", listCircles.Count);
                                        PrintPointList(listCircles);
                                    }
                                    // Line
                                    if (listLines.Count > 0)
                                    {
                                        file.WriteLine("LINE({0})", listLines.Count);
                                        file.WriteLine(headerStr);
                                        int i = 1;
                                        foreach (var points in listLines)
                                        {
                                            var pt1 = points.Item1;
                                            var pt2 = points.Item2;

                                            var str = form.LineFormat;
                                            str = str.Replace("[#]", i.ToString());
                                            str = str.Replace("[X1]", PrintCoord(pt1.X));
                                            str = str.Replace("[Y1]", PrintCoord(pt1.Y));
                                            str = str.Replace("[Z1]", PrintCoord(pt1.Z));
                                            str = str.Replace("[X2]", PrintCoord(pt2.X));
                                            str = str.Replace("[Y2]", PrintCoord(pt2.Y));
                                            str = str.Replace("[Z2]", PrintCoord(pt2.Z));
                                            str = ClearLine(str);
                                            file.WriteLine(str);
                                            i++;
                                        }
                                    }
                                    // Polyline
                                    if (listPolylines.Count > 0)
                                    {
                                        file.WriteLine("POLYLINE({0})", listPolylines.Count);
                                        int i = 1;
                                        foreach (var polyline in listPolylines)
                                        {
                                            file.WriteLine("POLYLINE-{0}", i);
                                            file.WriteLine(headerStr);

                                            for (int j = 0; j < polyline.Count; j++)
                                            {
                                                var str = form.LineFormat;
                                                str = str.Replace("[#]", (j + 1).ToString());
                                                str = str.Replace("[X]", PrintCoord(polyline[j].X));
                                                str = str.Replace("[Y]", PrintCoord(polyline[j].Y));
                                                str = str.Replace("[Z]", PrintCoord(polyline[j].Z));
                                                str = str.Replace("[X1]", PrintCoord(polyline[j].X));
                                                str = str.Replace("[Y1]", PrintCoord(polyline[j].Y));
                                                str = str.Replace("[Z1]", PrintCoord(polyline[j].Z));
                                                str = ClearLine(str);
                                                file.WriteLine(str);
                                            }

                                            i++;
                                        }
                                    }
                                    // 3DFace
                                    if (list3DFaces.Count > 0)
                                    {
                                        file.WriteLine("3DFACE({0})", list3DFaces.Count);
                                        file.WriteLine(headerStr);
                                        int i = 1;
                                        foreach (var points in list3DFaces)
                                        {
                                            var pt1 = points.Item1;
                                            var pt2 = points.Item2;
                                            var pt3 = points.Item3;
                                            var pt4 = points.Item4;

                                            var str = form.LineFormat;
                                            str = str.Replace("[#]", i.ToString());
                                            str = str.Replace("[X1]", PrintCoord(pt1.X));
                                            str = str.Replace("[Y1]", PrintCoord(pt1.Y));
                                            str = str.Replace("[Z1]", PrintCoord(pt1.Z));
                                            str = str.Replace("[X2]", PrintCoord(pt2.X));
                                            str = str.Replace("[Y2]", PrintCoord(pt2.Y));
                                            str = str.Replace("[Z2]", PrintCoord(pt2.Z));
                                            str = str.Replace("[X3]", PrintCoord(pt3.X));
                                            str = str.Replace("[Y3]", PrintCoord(pt3.Y));
                                            str = str.Replace("[Z3]", PrintCoord(pt3.Z));
                                            str = str.Replace("[X4]", PrintCoord(pt4.X));
                                            str = str.Replace("[Y4]", PrintCoord(pt4.Y));
                                            str = str.Replace("[Z4]", PrintCoord(pt4.Z));
                                            str = ClearLine(str);
                                            file.WriteLine(str);
                                            i++;
                                        }
                                    }
                                    // Text
                                    if (listTexts.Count > 0)
                                    {
                                        file.WriteLine("TEXT({0})", listTexts.Count);
                                        PrintPointList(listTexts);
                                    }
                                    // Block
                                    if (listBlocks.Count > 0)
                                    {
                                        file.WriteLine("BLOCK({0})", listBlocks.Count);
                                        PrintPointList(listBlocks);
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            tr.Commit();
                        }
                    }
                }
            }
        }
		/// <summary>
		/// Accumulate a translation on this ModelMatrixDouble.
		/// </summary>
		/// <param name="p">
		/// A <see cref="Vertex2d"/> that specifies the translation.
		/// </param>
		public void Translate(Vertex2d p)
		{
			ModelMatrixDouble translationMatrix = new ModelMatrixDouble();

			translationMatrix[3, 0] = p.x;
			translationMatrix[3, 1] = p.y;

			Set(this * translationMatrix);
		}
		/// <summary>
		/// Accumulate a scaling to this model matrix.
		/// </summary>
		/// <param name="s">
		/// A <see cref="Vertex2d"/> holding the scaling factors on three dimensions.
		/// </param>
		public void Scale(Vertex2d s)
		{
			ModelMatrixDouble scaleModel = new ModelMatrixDouble();

			scaleModel[0, 0] = s.x;
			scaleModel[1, 1] = s.y;

			Set(this * scaleModel);
		}
Exemple #10
0
        public static void TranslateCoordinates()
        {
            // 获取当前文档和数据库,启动事务
            var acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var acCurDb = acDoc.Database;

            using (var acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 以读模式打开块表
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // 以写模式打开块表记录模型空间
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                // 创建2D多段线
                var acPoly2d = new Polyline2d();

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acPoly2d);
                acTrans.AddNewlyCreatedDBObject(acPoly2d, true);

                // 先将多段线添加到块表记录,然后才能给它添加顶点
                var acPts2dPoly = new Point3dCollection();
                acPts2dPoly.Add(new Point3d(1, 1, 0));
                acPts2dPoly.Add(new Point3d(1, 2, 0));
                acPts2dPoly.Add(new Point3d(2, 2, 0));
                acPts2dPoly.Add(new Point3d(3, 2, 0));
                acPts2dPoly.Add(new Point3d(4, 4, 0));

                foreach (Point3d acPt3d in acPts2dPoly)
                {
                    var acVer2d = new Vertex2d(acPt3d, 0, 0, 0, 0);
                    acPoly2d.AppendVertex(acVer2d);
                    acTrans.AddNewlyCreatedDBObject(acVer2d, true);
                }

                // Set the normal of the 2D polyline
                acPoly2d.Normal = new Vector3d(0, 1, 2);

                // Get the first coordinate of the 2D polyline
                var      acPts3d    = new Point3dCollection();
                Vertex2d acFirstVer = null;
                foreach (ObjectId acObjIdVert in acPoly2d)
                {
                    acFirstVer = acTrans.GetObject(acObjIdVert,
                                                   OpenMode.ForRead) as Vertex2d;

                    acPts3d.Add(acFirstVer.Position);

                    break;
                }

                // Get the first point of the polyline and
                // use the elevation for the Z value
                var pFirstVer = new Point3d(acFirstVer.Position.X,
                                            acFirstVer.Position.Y,
                                            acPoly2d.Elevation);

                // Translate the OCS to WCS
                var mWPlane = Matrix3d.WorldToPlane(acPoly2d.Normal);
                var pWCSPt  = pFirstVer.TransformBy(mWPlane);

                Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog(
                    "The first vertex has the following " +
                    "coordinates:" +
                    "\nOCS: " + pFirstVer +
                    "\nWCS: " + pWCSPt);

                // 提交事务
                acTrans.Commit();
            }
        }
        Point3dCollection ReadPoints(IEnumerable <ObjectId> items, double maxSpacing)
        {
            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            HashSet <Point3d> points = new HashSet <Point3d>(new Point3dComparer(new Tolerance(maxSpacing, maxSpacing)));

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    foreach (ObjectId id in items)
                    {
                        // Point
                        if (SelectPoints && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBPoint)).UnmanagedObject)
                        {
                            DBPoint item = (DBPoint)tr.GetObject(id, OpenMode.ForRead);
                            points.Add(item.Position);
                        }
                        // Line
                        else if (SelectLines && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Line)).UnmanagedObject)
                        {
                            Line item = (Line)tr.GetObject(id, OpenMode.ForRead);
                            points.Add(item.StartPoint);
                            points.Add(item.EndPoint);
                        }
                        // LW Polyline
                        else if (SelectPolylines && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline)).UnmanagedObject)
                        {
                            Polyline item = (Polyline)tr.GetObject(id, OpenMode.ForRead);
                            for (int i = 0; i < item.NumberOfVertices; i++)
                            {
                                points.Add(item.GetPoint3dAt(i));
                            }
                        }
                        // 2D Polyline
                        else if (SelectPolylines && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline2d)).UnmanagedObject)
                        {
                            Polyline2d item = (Polyline2d)tr.GetObject(id, OpenMode.ForRead);
                            foreach (ObjectId vId in item)
                            {
                                Vertex2d vertex = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead);
                                points.Add(vertex.Position);
                            }
                        }
                        // 3D Polyline
                        else if (SelectPolylines && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline3d)).UnmanagedObject)
                        {
                            Polyline3d item = (Polyline3d)tr.GetObject(id, OpenMode.ForRead);
                            foreach (ObjectId vId in item)
                            {
                                PolylineVertex3d vertex = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
                                points.Add(vertex.Position);
                            }
                        }
                        // Text
                        else if (SelectTexts && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject)
                        {
                            DBText item = (DBText)tr.GetObject(id, OpenMode.ForRead);
                            points.Add(item.Position);
                        }
                        // Text with Z
                        else if (SelectTextsWithZ && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject)
                        {
                            DBText item = (DBText)tr.GetObject(id, OpenMode.ForRead);
                            if (double.TryParse(item.TextString, out double z))
                            {
                                Point3d pt = item.Position;
                                points.Add(new Point3d(pt.X, pt.Y, z));
                            }
                        }
                        // Blocks
                        else if (SelectBlocks && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(BlockReference)).UnmanagedObject)
                        {
                            BlockReference item = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                            points.Add(item.Position);
                        }
                        // 3DFace
                        else if (Select3DFace && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Face)).UnmanagedObject)
                        {
                            Face item = (Face)tr.GetObject(id, OpenMode.ForRead);
                            points.Add(item.GetVertexAt(0));
                            points.Add(item.GetVertexAt(1));
                            points.Add(item.GetVertexAt(2));
                            points.Add(item.GetVertexAt(3));
                        }
                        // PolyFaceMesh
                        else if (SelectPolyfaceMesh && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(PolyFaceMesh)).UnmanagedObject)
                        {
                            PolyFaceMesh item = (PolyFaceMesh)tr.GetObject(id, OpenMode.ForRead);
                            foreach (ObjectId faceId in item)
                            {
                                DBObject obj = tr.GetObject(faceId, OpenMode.ForRead);
                                if (obj is PolyFaceMeshVertex vertex)
                                {
                                    points.Add(vertex.Position);
                                }
                            }
                        }
                        // Solid (2D)
                        else if (SelectSolid && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Solid)).UnmanagedObject)
                        {
                            Solid item = (Solid)tr.GetObject(id, OpenMode.ForRead);
                            points.Add(item.GetPointAt(0));
                            points.Add(item.GetPointAt(1));
                            points.Add(item.GetPointAt(3));
                            points.Add(item.GetPointAt(2));
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                tr.Commit();
            }

            if (points.Count == 0)
            {
                return(new Point3dCollection());
            }
            else
            {
                return(new Point3dCollection(points.ToArray()));
            }
        }
Exemple #12
0
        public static void StartFunction()
        {
#if !DEBUG
            Statistic.SendCommandStarting(ModPlusConnector.Instance);
#endif
            try
            {
                var doc = Application.DocumentManager.MdiActiveDocument;
                var db  = doc.Database;
                var ed  = doc.Editor;

                var pso = new PromptSelectionOptions
                {
                    AllowDuplicates  = false,
                    MessageForAdding = $"\n{Language.GetItem(PlinesEditFunction.LangItem, "k2")}:"
                };
                var filList = new[] { new TypedValue((int)DxfCode.Start, "*POLYLINE") };
                var sf      = new SelectionFilter(filList);
                var psr     = ed.GetSelection(pso, sf);
                if (psr.Status != PromptStatus.OK)
                {
                    return;
                }
                var ids     = psr.Value.GetObjectIds();
                var plCount = psr.Value.Count;

                using (doc.LockDocument())
                {
                    using (var tr = db.TransactionManager.StartTransaction())
                    {
                        foreach (var objectId in ids)
                        {
                            var dbObj   = tr.GetObject(objectId, OpenMode.ForRead);
                            var deleted = 0;

                            // Если простая полилиния
                            if (dbObj is Polyline polyline)
                            {
                                var listOfDuplicateVertex = new List <int>();
                                for (var i = 0; i < polyline.NumberOfVertices - 1; i++)
                                {
                                    if (polyline.GetPoint2dAt(i).Equals(polyline.GetPoint2dAt(i + 1)))
                                    {
                                        listOfDuplicateVertex.Add(i + 1);
                                    }
                                }

                                if (listOfDuplicateVertex.Count > 0)
                                {
                                    /*
                                     * при каждом удалении вершины количество вершин меняется
                                     * значит после каждого удаления нужно нужно значение i уменьшать
                                     * на переменную, в которую будет записано кол-во проходов
                                     */
                                    polyline.UpgradeOpen();
                                    var j = 0;
                                    foreach (var i in listOfDuplicateVertex)
                                    {
                                        if (j == 0)
                                        {
                                            var bulge = polyline.GetBulgeAt(i);
                                            if (!bulge.Equals(0.0))
                                            {
                                                polyline.SetBulgeAt(i - 1, bulge);
                                            }
                                            polyline.RemoveVertexAt(i);
                                        }
                                        else
                                        {
                                            var bulge = polyline.GetBulgeAt(i - j);
                                            if (!bulge.Equals(0.0))
                                            {
                                                polyline.SetBulgeAt(i - j - 1, bulge);
                                            }
                                            polyline.RemoveVertexAt(i - j);
                                        }

                                        j++;
                                    }

                                    deleted = listOfDuplicateVertex.Count;
                                }
                            }
                            else if (dbObj is Polyline2d polyline2d)
                            {
                                // Будем запоминать предыдущую и сравнивать с текущей
                                var      i        = 0;
                                Vertex2d vrBefore = null;
                                foreach (ObjectId vId in polyline2d)
                                {
                                    var v2D = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead);
                                    if (vrBefore == null)
                                    {
                                        vrBefore = v2D;
                                    }
                                    else
                                    {
                                        if (vrBefore.Position.Equals(v2D.Position))
                                        {
                                            v2D.UpgradeOpen();
                                            if (!v2D.Bulge.Equals(0.0))
                                            {
                                                vrBefore.Bulge = v2D.Bulge;
                                            }
                                            v2D.Erase(true);
                                            i++;
                                        }
                                    }

                                    vrBefore = v2D;
                                }

                                if (i > 0)
                                {
                                    polyline2d.UpgradeOpen();
                                    polyline2d.RecordGraphicsModified(true);
                                    deleted = i;
                                }
                            }
                            else if (dbObj is Polyline3d polyline3d)
                            {
                                // Будем запоминать предыдущую и сравнивать с текущей
                                var i = 0;
                                PolylineVertex3d vrBefore = null;
                                foreach (ObjectId vId in polyline3d)
                                {
                                    var v3D = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
                                    if (vrBefore == null)
                                    {
                                        vrBefore = v3D;
                                    }
                                    else
                                    {
                                        if (vrBefore.Position.Equals(v3D.Position))
                                        {
                                            v3D.UpgradeOpen();
                                            v3D.Erase(true);
                                            i++;
                                        }
                                    }

                                    vrBefore = v3D;
                                }

                                if (i > 0)
                                {
                                    polyline3d.UpgradeOpen();
                                    polyline3d.RecordGraphicsModified(true);
                                    deleted = i;
                                }
                            }

                            // Вывод результата
                            if (deleted > 0)
                            {
                                if (plCount == 1)
                                {
                                    MessageBox.Show($"{Language.GetItem(PlinesEditFunction.LangItem, "k3")}:{deleted}");
                                }
                                else
                                {
                                    ed.WriteMessage(
                                        $"\n{Language.GetItem(PlinesEditFunction.LangItem, "k4")}:{objectId} {Language.GetItem(PlinesEditFunction.LangItem, "k3").ToLower()}:{deleted}");
                                }
                            }
                            else
                            {
                                if (plCount == 1)
                                {
                                    MessageBox.Show(
                                        $"{Language.GetItem(PlinesEditFunction.LangItem, "k4")} {Language.GetItem(PlinesEditFunction.LangItem, "k5")}");
                                }
                                else
                                {
                                    ed.WriteMessage(
                                        $"\n{Language.GetItem(PlinesEditFunction.LangItem, "k4")} {objectId} {Language.GetItem(PlinesEditFunction.LangItem, "k5")}");
                                }
                            }
                        }

                        tr.Commit();
                    }
                }
            }
            catch (System.Exception exception)
            {
                ExceptionBox.Show(exception);
            }
        }
Exemple #13
0
        /// <summary>
        /// Inverse solution: compute the point given distance and bearing from a point.
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <param name="rng"></param>
        /// <param name="brg"></param>
        public static void Inverse(Vertex2d v1, Vertex2d v2, out double rng, out double brg)
        {
            const int    MaxIterations = 200;
            const double Precision     = 1e-12;

            const double a = 6378137.0;                         // Major axis
            const double b = 6356752.3142;                      // Minor axis
            const double f = (a - b) / a;                       // Flattening

            double φ1 = Angle.ToRadians(v1.y), λ1 = Angle.ToRadians(v1.x);
            double φ2 = Angle.ToRadians(v2.y), λ2 = Angle.ToRadians(v2.x);

            double L = λ2 - λ1;
            double tanU1 = (1.0 - f) * Math.Tan(φ1), cosU1 = 1.0 / Math.Sqrt((1.0 + tanU1 * tanU1)), sinU1 = tanU1 * cosU1;
            double tanU2 = (1.0 - f) * Math.Tan(φ2), cosU2 = 1.0 / Math.Sqrt((1.0 + tanU2 * tanU2)), sinU2 = tanU2 * cosU2;

            double sinλ, cosλ, sinSqσ, sinσ, cosσ, σ, sinα, cosSqα, cos2σM, C;

            rng = brg = 0.0;             // Suppose coincident points

            double λ          = L;
            int    iterations = 0;

            do
            {
                sinλ   = Math.Sin(λ);
                cosλ   = Math.Cos(λ);
                sinSqσ = (cosU2 * sinλ) * (cosU2 * sinλ) + (cosU1 * sinU2 - sinU1 * cosU2 * cosλ) * (cosU1 * sinU2 - sinU1 * cosU2 * cosλ);
                sinσ   = Math.Sqrt(sinSqσ);
                if (Math.Abs(sinσ) < Double.Epsilon)
                {
                    return;                                                         // co-incident points
                }
                cosσ   = sinU1 * sinU2 + cosU1 * cosU2 * cosλ;
                σ      = Math.Atan2(sinσ, cosσ);
                sinα   = cosU1 * cosU2 * sinλ / sinσ;
                cosSqα = 1.0 - sinα * sinα;
                cos2σM = cosσ - 2.0 * sinU1 * sinU2 / cosSqα;
                if (Double.IsNaN(cos2σM))
                {
                    cos2σM = 0;                                                     // equatorial line: cosSqα=0 (§6)
                }
                C  = f / 16.0 * cosSqα * (4.0 + f * (4.0 - 3.0 * cosSqα));
                λ1 = λ;
                λ  = L + (1.0 - C) * f * sinα * (σ + C * sinσ * (cos2σM + C * cosσ * (-1.0 + 2.0 * cos2σM * cos2σM)));
            } while (Math.Abs(λ - λ1) > Precision && ++iterations < MaxIterations);

            if (iterations >= MaxIterations)
            {
                throw new Exception("failed to converge");
            }

            double uSq = cosSqα * (a * a - b * b) / (b * b);
            double A   = 1.0 + uSq / 16384.0 * (4096.0 + uSq * (-768.0 + uSq * (320.0 - 175.0 * uSq)));
            double B   = uSq / 1024.0 * (256.0 + uSq * (-128.0 + uSq * (74.0 - 47.0 * uSq)));
            double Δσ  = B * sinσ * (cos2σM + B / 4.0 * (cosσ * (-1.0 + 2.0 * cos2σM * cos2σM) - B / 6.0 * cos2σM * (-3.0 + 4.0 * sinσ * sinσ) * (-3.0 + 4.0 * cos2σM * cos2σM)));

            double s = b * A * (σ - Δσ);

            double α1 = Math.Atan2(cosU2 * sinλ, cosU1 * sinU2 - sinU1 * cosU2 * cosλ);
            double α2 = Math.Atan2(cosU1 * sinλ, -sinU1 * cosU2 + cosU1 * sinU2 * cosλ);

            α1 = (α1 + 2.0 * Math.PI) % (2.0 * Math.PI);             // normalise to 0..360
            α2 = (α2 + 2.0 * Math.PI) % (2.0 * Math.PI);             // normalise to 0..360

            rng = s;
            brg = Angle.ToDegrees(α1);                  // Otherwise Angle.ToDegrees(α2)
        }
Exemple #14
0
 public Point2D ConvertAcadVertex2DToPoint2D(Vertex2d Acadvertex, int number)
 {
     return(new Point2D(Math.Round(Acadvertex.Position.X, 2), Math.Round(Acadvertex.Position.Y, 2), number));
 }
Exemple #15
0
		/// <summary>
		/// Accumulate a scaling to this model matrix.
		/// </summary>
		/// <param name="s">
		/// A <see cref="Vertex2d"/> holding the scaling factors on three dimensions.
		/// </param>
		public void Scale(Vertex2d s)
		{
			Scale((float)s.x, (float)s.y);
		}
Exemple #16
0
        public void convertTo3d()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager myTm = db.TransactionManager;
            Transaction myT = db.TransactionManager.StartTransaction();

            //alle Blöcke wählen
            myAutoCAD.Blöcke.Instance.init();
            myAutoCAD.Blöcke.Instance.selectAll();
            Messpunkt[] vMP = Blöcke.Instance.getMP;

            //Linien

            using (DocumentLock dl = Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                foreach (KeyValuePair <ObjectId, Line> valPair in m_LineCollection)
                {
                    ObjectId id      = valPair.Key;
                    Line     objLine = valPair.Value;

                    Messpunkt MP      = new Messpunkt();
                    Point2d   startPt = new Point2d(objLine.StartPoint.X, objLine.StartPoint.Y);
                    Point2d   endPt   = new Point2d(objLine.EndPoint.X, objLine.EndPoint.Y);

                    Line line = (Line)myT.GetObject(id, OpenMode.ForWrite);
                    if (Blöcke.Instance.findPos(ref MP, startPt, 0.001) == ErrorStatus.OK)
                    {
                        line.StartPoint = MP.Position;
                    }
                    else
                    {
                        m_lsMP_Error.Add(new Messpunkt("", startPt.X, startPt.Y, null, null, 0));
                    }

                    if (Blöcke.Instance.findPos(ref MP, endPt, 0.001) == ErrorStatus.OK)
                    {
                        line.EndPoint = MP.Position;
                    }
                    else
                    {
                        m_lsMP_Error.Add(new Messpunkt("", endPt.X, endPt.Y, null, null, 0));
                    }
                }
            }

            //Polylinien
            using (DocumentLock dl = Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                foreach (KeyValuePair <ObjectId, Polyline> valPair in m_PolylineCollection)
                {
                    ObjectId id    = valPair.Key;
                    Polyline objPL = valPair.Value;

                    List <Point3d> lsPt3d = new List <Point3d>();

                    //Vertices iterieren
                    for (int i = 0; i < objPL.NumberOfVertices; i++)
                    {
                        Point2d   pt = objPL.GetPoint2dAt(i);
                        Messpunkt MP = new Messpunkt();

                        if (Blöcke.Instance.findPos(ref MP, pt, 0.001) == ErrorStatus.OK)
                        {
                            lsPt3d.Add(MP.Position);
                        }
                        else
                        {
                            Point3d pt3d = new Point3d(pt.X, pt.Y, 0);
                            MP.Position = pt3d;
                            m_lsMP_Error.Add(MP);
                            lsPt3d.Add(pt3d);
                        }
                    }

                    //3dPolylinie erstellen
                    //Punktliste erzeugen
                    Point3d[] vPT3d = new Point3d[lsPt3d.Count];
                    for (int i = 0; i < lsPt3d.Count; i++)
                    {
                        vPT3d[i] = lsPt3d[i];
                    }

                    //3d Polylinie erzeugen
                    Point3dCollection pt3dCol = new Point3dCollection(vPT3d);
                    Polyline3d        objPL3d = new Polyline3d(Poly3dType.SimplePoly, pt3dCol, objPL.Closed);
                    objPL3d.Layer = objPL.Layer;

                    //2d Polylinie löschen
                    Polyline pl = (Polyline)myT.GetObject(id, OpenMode.ForWrite);
                    pl.Erase(true);

                    //Polylinie in DB einfügen
                    try
                    {
                        BlockTable       bt  = (BlockTable)myT.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                        BlockTableRecord btr = (BlockTableRecord)myT.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                        ObjectId idPL3d = btr.AppendEntity(objPL3d);
                        myT.AddNewlyCreatedDBObject(objPL3d, true);
                        objPL3d.Draw();
                    }
                    catch { }
                }
            }

            //Polyline2d
            using (DocumentLock dl = Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                foreach (KeyValuePair <ObjectId, Polyline2d> valPair in m_Polyline2dCollection)
                {
                    ObjectId       id      = valPair.Key;
                    Polyline2d     objPL2d = valPair.Value;
                    List <Point3d> lsPt3d  = new List <Point3d>();

                    //Vertices iterieren
                    foreach (ObjectId idVertex in objPL2d)
                    {
                        Vertex2d  vertex2d = (Vertex2d)myT.GetObject(idVertex, OpenMode.ForRead);
                        Point2d   pt       = new Point2d(vertex2d.Position.X, vertex2d.Position.Y);
                        Messpunkt MP       = new Messpunkt();

                        if (Blöcke.Instance.findPos(ref MP, pt, 0.001) == ErrorStatus.OK)
                        {
                            lsPt3d.Add(MP.Position);
                        }
                        else
                        {
                            Point3d pt3d = new Point3d(pt.X, pt.Y, 0);
                            MP.Position = pt3d;
                            m_lsMP_Error.Add(MP);
                            lsPt3d.Add(pt3d);
                        }
                    }

                    //3dPolylinie erstellen
                    //Punktliste erzeugen
                    Point3d[] vPT3d = new Point3d[lsPt3d.Count];
                    for (int i = 0; i < lsPt3d.Count; i++)
                    {
                        vPT3d[i] = lsPt3d[i];
                    }

                    //3d Polylinie erzeugen
                    Point3dCollection pt3dCol = new Point3dCollection(vPT3d);
                    Polyline3d        objPL3d = new Polyline3d(Poly3dType.SimplePoly, pt3dCol, objPL2d.Closed);
                    objPL3d.Layer = objPL2d.Layer;

                    //2d Polylinie löschen
                    Polyline2d pl2d = (Polyline2d)myT.GetObject(id, OpenMode.ForWrite);
                    pl2d.Erase(true);

                    //Polylinie in DB einfügen
                    try
                    {
                        BlockTable       bt  = (BlockTable)myT.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                        BlockTableRecord btr = (BlockTableRecord)myT.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                        ObjectId idPL3d = btr.AppendEntity(objPL3d);
                        myT.AddNewlyCreatedDBObject(objPL3d, true);
                        objPL3d.Draw();
                    }
                    catch { }
                }
            }

            //Fehler anzeigen
            if (m_lsMP_Error.Count > 0)
            {
                foreach (Messpunkt MP in m_lsMP_Error)
                {
                    MP.mark(0.2);
                }

                System.Windows.Forms.MessageBox.Show(m_lsMP_Error.Count.ToString() + " Fehler gefunden!");
            }

            else
            {
                System.Windows.Forms.MessageBox.Show("3d Konvertierung fehlerfrei durchgeführt!");
            }

            myT.Commit();
        }
Exemple #17
0
		/// <summary>
		/// Accumulate a translation on this model matrix.
		/// </summary>
		/// <param name="p">
		/// A <see cref="Vertex2d"/> that specifies the translation.
		/// </param>
		public void Translate(Vertex2d p)
		{
			Translate((float)p.x, (float)p.y);
		}
Exemple #18
0
        public static PointSet SubdividePolyline2d(Autodesk.AutoCAD.DatabaseServices.Polyline2d p2d, Transaction trans, double d)
        {
            PointSet result;

            try
            {
                PointSet pointSet = new PointSet();
                if (d <= 0.0)
                {
                    //using (System.Collections.IEnumerator enumerator = p2d.GetEnumerator())
                    {
                        System.Collections.IEnumerator enumerator = p2d.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            ObjectId objectId = (ObjectId)enumerator.Current;
                            Vertex2d vertex2d = (Vertex2d)trans.GetObject(objectId, (OpenMode)0);
                            Point    point    = new Point(vertex2d.Position.X, vertex2d.Position.Y, p2d.Elevation);
                            if (pointSet.Count > 1)
                            {
                                if (pointSet[pointSet.Count - 1] != point)
                                {
                                    pointSet.Add(point);
                                }
                            }
                            else
                            {
                                pointSet.Add(point);
                            }
                        }
                        goto IL_21D;
                    }
                }
                List <Point> list = new List <Point>();
                foreach (ObjectId objectId2 in p2d)
                {
                    Vertex2d vertex2d2 = (Vertex2d)trans.GetObject(objectId2, (OpenMode)0);
                    list.Add(new Point(vertex2d2.Position.X, vertex2d2.Position.Y, p2d.Elevation));
                }
                if (p2d.Closed)
                {
                    list.Add(list[0]);
                }
                for (int i = 0; i < list.Count - 1; i++)
                {
                    Point point2 = list[i];
                    Point point3 = list[i + 1];
                    ngeometry.VectorGeometry.Vector3d vector3d = new ngeometry.VectorGeometry.Vector3d(point3 - point2);
                    double num  = point2.DistanceTo(point3);
                    double num2 = (double)((int)Math.Max(Math.Ceiling(num / d), 1.0));
                    double norm = num / num2;
                    vector3d.Norm = norm;
                    int num3 = 0;
                    while ((double)num3 < num2)
                    {
                        pointSet.Add(point2 + (double)num3 * vector3d.ToPoint());
                        num3++;
                    }
                }
                if (!p2d.Closed)
                {
                    pointSet.Add(list[list.Count - 1]);
                }
IL_21D:
                result = pointSet;
            }
            catch (System.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Can not subdivide polyline2d (handle: " + p2d.Handle.ToString() + ")\n");
                result = null;
            }
            return(result);
        }