Example #1
0
        public bool setImgScale(double _xscale, double _yscale, double _zscale)
        {
            DocumentLock doclock = null;

            try
            {
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                doclock = doc.LockDocument();

                RasterImage pAcDbRasterImage;           // Entity

                Database db = HostApplicationServices.WorkingDatabase;
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

                using (Transaction t = tm.StartTransaction())
                {
                    try
                    {
                        pAcDbRasterImage = (RasterImage)t.GetObject(parEntityId, OpenMode.ForWrite);

                        if (pAcDbRasterImage != null)
                        {
                            double[] ddd = new Autodesk.AutoCAD.Geometry.Matrix3d().ToArray();
                            ddd[0]  = _xscale;
                            ddd[5]  = _yscale;
                            ddd[10] = _zscale;
                            ddd[15] = 1.0;
                            Autodesk.AutoCAD.Geometry.Matrix3d mat = new Autodesk.AutoCAD.Geometry.Matrix3d(ddd);


                            pAcDbRasterImage.TransformBy(mat);

                            // Close object.
                            pAcDbRasterImage.Close();
                        }
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception eex)
                    { }
                    catch (System.Exception ex) { }
                    t.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception eex)
            { return(false); }
            catch (System.Exception ex) { return(false); }
            finally
            {
                doclock.Dispose();
            }


            return(true);
        }
Example #2
0
        public bool setImgPosition(double _x, double _y, double _z)
        {
            DocumentLock doclock = null;

            try
            {
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                doclock = doc.LockDocument();

                RasterImage pAcDbRasterImage;           // Entity

                Database db = HostApplicationServices.WorkingDatabase;
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

                using (Transaction t = tm.StartTransaction())
                {
                    try
                    {
                        pAcDbRasterImage = (RasterImage)t.GetObject(parEntityId, OpenMode.ForWrite);

                        if (pAcDbRasterImage != null)
                        {
                            Autodesk.AutoCAD.Geometry.Vector3d ptag = new Autodesk.AutoCAD.Geometry.Vector3d(_x, _y, _z);

                            Autodesk.AutoCAD.Geometry.Matrix3d mat = new Autodesk.AutoCAD.Geometry.Matrix3d();

                            mat = Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(ptag);



                            pAcDbRasterImage.TransformBy(mat);

                            // Close object.
                            pAcDbRasterImage.Close();
                        }
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception eex)
                    { }
                    catch (System.Exception ex) { }
                    t.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception eex)
            { return(false); }
            catch (System.Exception ex) { return(false); }
            finally
            {
                doclock.Dispose();
            }


            return(true);
        }
Example #3
0
        private List <Edge> genAssistContour(List <Triangle> list, Plane plane, CoordinateSystem userSystem, ObjectId layerId, double assistElevation, int relevantDecimals, int num3)
        {
            Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            int    num5 = 0; int num4 = 0;
            Plane  assistPlane = plane.DeepCopy();

            assistPlane.Point.Z += assistElevation;

            List <Edge> unorderedEdges = this.getInterSection2(list, assistPlane, num3, ref num5, ref num4);

            if (unorderedEdges == null || unorderedEdges.Count <= 0)
            {
                return(null);
            }
            Autodesk.AutoCAD.Geometry.Plane    plane1  = new Autodesk.AutoCAD.Geometry.Plane(new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0), new Autodesk.AutoCAD.Geometry.Vector3d(0, 0, 1));
            Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal);
            TransformUtil.Transform(unorderedEdges, prjMat1);
            List <PLine> pllist = null;
            //pllist = DBManager.WritePlinesInDataBase2(unorderedEdges, userSystem, relevantDecimals, false, layerId, Color.White);

            int num   = 0;
            int num2  = 0;
            int num33 = 0;

            Global.SuspendEpsilon(0.0, 0.0);
            try
            {
                if (userSystem != null)
                {
                    Conversions.ToWCS(userSystem, unorderedEdges);
                }
                //WritePlinesInDataBase2和ConstructFromUnorderedSegments只能调用一个
                if (pllist == null)
                {
                    pllist = PLine.ConstructFromUnorderedSegments(unorderedEdges, relevantDecimals, ref num2, ref num, ref num33, false, false, false);
                }

                cmd.mydb.assistContourDics[cmd.mydb.Resolution].set(assistElevation + ContourLineComputation.spacing / 2, pllist);
                if (unorderedEdges.Count == 0)
                {
                    editor.WriteMessage("\nNo contours at elevation : " + assistElevation.ToString());
                }
            }
            catch (System.Exception ex)
            {
                editor.WriteMessage("genAssistContour error." + ex.Message);
            }
            Global.ResumeEpsilon();
            return(unorderedEdges);
        }
Example #4
0
        public static void GetSheetProfileThickness(/*ObjectId aSheetProfilePolyObjectId , Point3d aPickedPoint*/)
        {
            using (var acTrans = _db.TransactionManager.StartTransaction())
            {
                var tLine = (Line)acTrans.GetObject(_tLineId, OpenMode.ForWrite);
                _basePolyLine = (Polyline)acTrans.GetObject(_polylineId, OpenMode.ForWrite);

                tLine.Erase();
                //        Ed.Regen();

                #region endmost_thickness_segment_search

                var buf = _num1;
                _num1 = _num2;
                _num2 = buf;

                var p1 = _basePolyLine.GetLineSegmentAt(_num1).EndPoint;
                var p2 = _basePolyLine.GetLineSegmentAt(_num1).StartPoint;
                var p3 = new Point3d((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2);
                var p4 = new Point3d(_ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.X + p3.X,
                                     _ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.Y + p3.Y,
                                     _ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.Z + p3.Z);
                var v3D = p3.GetVectorTo(p4);

                tLine = new Line(p1, p2);
                tLine.TransformBy(Matrix3d.Rotation(Math.PI / 4.0, v3D, p3));
                tLine.SetDatabaseDefaults();
                Draw(tLine, 2, acTrans);
                _ed.Regen();
                _tLineId = tLine.ObjectId;
                // thickness = (BasePolyLine.GetLineSegment2dAt(NUM1)).Length;

                #endregion

                acTrans.Commit();
            }
            _ed.Regen();
            //return thickness;
        }
Example #5
0
        public void Unfold2DSheetProfileStart()
        {
            _ed = Application.DocumentManager.MdiActiveDocument.Editor;
            _db = Application.DocumentManager.MdiActiveDocument.Database;

            // Pick a polyline
            var polyOptions = new PromptEntityOptions("Pick a sheet profile :");

            polyOptions.SetRejectMessage(
                "\nThis is not a generated sheet profile.\nSheet Profile is generated from a polyline with SHP command.\nCreate a sheet profile and try again.");
            polyOptions.AddAllowedClass(typeof(Polyline), true);
            var polyResult = _ed.GetEntity(polyOptions);

            if (polyResult.Status != PromptStatus.OK)
            {
                return;
            }

            var pickInsertionPoint = _ed.GetPoint(new PromptPointOptions("Pick insertion point."));

            if (pickInsertionPoint.Status != PromptStatus.OK)
            {
                return;
            }

            _polylineId = polyResult.ObjectId;
            double thickness;

            using (var acTrans = _db.TransactionManager.StartTransaction())
            {
                _basePolyLine = (Polyline)acTrans.GetObject(_polylineId, OpenMode.ForWrite);
                if ((CountOfArcs() + 2 != _basePolyLine.NumberOfVertices >> 1) || (CountOfArcs() % 2 > 0))
                {
                    CommandLineHelper.Command("._copy", _basePolyLine.ObjectId, "0,0", "\033", "0,0", "\033");

                    var acPts2D = new Point3dCollection();
                    for (var nCnt = 0; nCnt < _basePolyLine.NumberOfVertices; nCnt++)
                    {
                        acPts2D.Add(_basePolyLine.GetPoint3dAt(nCnt));
                    }
                    for (var nCnt = 1; nCnt < acPts2D.Count; nCnt++)
                    {
                        var point1 = acPts2D[nCnt];
                        var point2 = acPts2D[nCnt - 1];
                        var dist   = point1.DistanceTo(point2);
                        if (dist < 0.001)
                        {
                            acPts2D.RemoveAt(nCnt);
                            _basePolyLine.RemoveVertexAt(nCnt);
                            nCnt--;
                        }
                    }

                    for (var nCnt = 0; nCnt < acPts2D.Count; nCnt++)
                    {
                        var point1 = acPts2D[nCnt];
                        var point2 = acPts2D[nCnt + 1];
                        var bulge  = _basePolyLine.GetBulgeAt(nCnt);
                        if (bulge != 0)
                        {
                            var arc = _basePolyLine.GetArcSegmentAt(nCnt);
                            var ppp = arc.Center;
                            for (var nCnt1 = 1; nCnt1 < acPts2D.Count - 1; nCnt1++)
                            {
                                if (acPts2D[nCnt1].DistanceTo(ppp) < 0.01)
                                {
                                    var c1 = new Complex(acPts2D[nCnt1].X, acPts2D[nCnt1].Y);
                                    var c2 = new Complex(acPts2D[nCnt1 - 1].X, acPts2D[nCnt1 - 1].Y);
                                    var c3 = new Complex(acPts2D[nCnt1 + 1].X, acPts2D[nCnt1 + 1].Y);

                                    var ml1 = new KLine2D(c1, c2);
                                    var ml2 = new KLine2D(c1, c3);

                                    var c4 = c1 - c2;
                                    c4 /= c4.abs();
                                    c4 *= 0.1;
                                    var c5 = c1 - c3;
                                    c5 /= c5.abs();
                                    c5 *= 0.1;

                                    var c6 = new Complex(point1.X, point1.Y);
                                    var c7 = new Complex(point2.X, point2.Y);

                                    var ml11 = new KLine2D((c1 - c3).real(), (c1 - c3).imag(),
                                                           -(c1 - c3).real() * c6.real() - (c1 - c3).imag() * c6.imag());
                                    var ml22 = new KLine2D((c1 - c2).real(), (c1 - c2).imag(),
                                                           -(c1 - c2).real() * c7.real() - (c1 - c2).imag() * c7.imag());

                                    var c55 = ml11.IntersectWitch(ml2);
                                    var c44 = ml22.IntersectWitch(ml1);

                                    //c6 -= c5; c7 -= c4;
                                    c6 -= c5 - c1 + c55;
                                    c7 -= c4 - c1 + c44;
                                    c4  = c1 - c4;
                                    c5  = c1 - c5;

                                    _basePolyLine.RemoveVertexAt(nCnt);
                                    _basePolyLine.AddVertexAt(nCnt, new Point2d(c6.real(), c6.imag()), bulge, 0, 0);
                                    _basePolyLine.RemoveVertexAt(nCnt + 1);
                                    _basePolyLine.AddVertexAt(nCnt + 1, new Point2d(c7.real(), c7.imag()), 0, 0, 0);

                                    _basePolyLine.RemoveVertexAt(nCnt1);
                                    _basePolyLine.AddVertexAt(nCnt1, new Point2d(c5.real(), c5.imag()), 0, 0, 0);
                                    _basePolyLine.AddVertexAt(nCnt1, new Point2d(c4.real(), c4.imag()), -bulge, 0, 0);

                                    acPts2D.Clear();
                                    for (var nCnt2 = 0; nCnt2 < _basePolyLine.NumberOfVertices; nCnt2++)
                                    {
                                        acPts2D.Add(_basePolyLine.GetPoint3dAt(nCnt2));
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    acTrans.Commit();
                    CommandLineHelper.Command("._u2d", _basePolyLine.ObjectId, pickInsertionPoint.Value);
                    CommandLineHelper.Command("._erase", _basePolyLine.ObjectId, "\033");
                    return;
                    // MessageBox.Show("Must have an even number of ARC segments !" , "ERROR:");
                    // return;
                }
                thickness = GetThickness();
                if (thickness <= 0)
                {
                    MessageBox.Show("PolyLine has only one segment or no ARC segment !", "ERROR:");
                    return;
                }
                if (_basePolyLine.Closed == false)
                {
                    MessageBox.Show("The PolyLline is not closed !", "ERROR:");
                    return;
                }
                if (_basePolyLine.NumberOfVertices % 2 != 0)
                {
                    MessageBox.Show("Must have an even number of segments !", "ERROR:");
                    return;
                }
                _pickPoint  = pickInsertionPoint.Value;
                _cPickPoint = new Complex(_pickPoint.X, _pickPoint.Y);

                #region endmost_thickness_segment_search

                _num1 = -1;
                _num2 = -1;
                for (var i = 0; i < _basePolyLine.NumberOfVertices; i++)
                {
                    var next = i < _basePolyLine.NumberOfVertices - 1 ? i + 1 : 0;
                    var pre  = i > 0 ? i - 1 : _basePolyLine.NumberOfVertices - 1;

                    var seg = _basePolyLine.GetLineSegment2dAt(i);
                    if (seg.Length - thickness < 0.000001)
                    {
                        var segPre  = _basePolyLine.GetLineSegment2dAt(pre);
                        var segNext = _basePolyLine.GetLineSegment2dAt(next);

                        for (var j = next; j < _basePolyLine.NumberOfVertices; j++)
                        {
                            var seg1 = _basePolyLine.GetLineSegment2dAt(j);
                            if (seg1.Length - thickness < 0.000001)
                            {
                                if (Math.Abs(seg.Length - seg1.Length) < 0.000001)
                                {
                                    var cPre = new Complex(segPre.EndPoint.X, segPre.EndPoint.Y) -
                                               new Complex(segPre.StartPoint.X, segPre.StartPoint.Y);
                                    var cNext = new Complex(segNext.EndPoint.X, segNext.EndPoint.Y) -
                                                new Complex(segNext.StartPoint.X, segNext.StartPoint.Y);
                                    var ang = (cNext / cPre).arg();
                                    if (Math.Abs(ang * 180 / Math.PI - 180) < 0.001)
                                    {
                                        if (_num1 == -1)
                                        {
                                            _num1 = i;
                                            _num2 = j;
                                        }
                                        else
                                        {
                                            if (Math.Abs(j - i) == _basePolyLine.NumberOfVertices / 2)
                                            {
                                                _num1 = i;
                                                _num2 = j;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                var p1 = _basePolyLine.GetLineSegmentAt(_num1).EndPoint;
                var p2 = _basePolyLine.GetLineSegmentAt(_num1).StartPoint;
                var p3 = new Point3d((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2);
                var p4 = new Point3d(_ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.X + p3.X,
                                     _ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.Y + p3.Y,
                                     _ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.Z + p3.Z);
                var v3D   = p3.GetVectorTo(p4);
                var tLine = new Line(p1, p2);
                tLine.TransformBy(Matrix3d.Rotation(Math.PI / 4.0, v3D, p3));
                tLine.SetDatabaseDefaults();
                Draw(tLine, 4, acTrans);
                _ed.Regen();
                _tLineId = tLine.ObjectId;
                //thickness = (BasePolyLine.GetLineSegment2dAt(NUM1)).Length;

                #endregion

                acTrans.Commit();
            }

            _unfoldPoints = new ArrayList();
            _entityTemp   = new List <ObjectId>();

            Unfold2DForm = new Unfold2dForm(thickness);
            Unfold2DForm.U2D_PREPARE_REDRAW += PrepareRedraw;
            Unfold2DForm.ShowDialog();
            Logger.Info(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Example #6
0
        internal void genContour2(ObjectId[] objectId_0, CoordinateSystem coordinateSystem_0)
        {
            Editor        editor        = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ProgressMeter progressMeter = new ProgressMeter();
            MessageFilter messageFilter = new MessageFilter();

            System.Windows.Forms.Application.AddMessageFilter(messageFilter);
            CoordinateSystem coordinateSystem = CoordinateSystem.Global();

            try
            {
                if (objectId_0 == null)
                {
                    throw new ArgumentException("No faces selected.");
                }
                string   layerName       = UserCmd.contourLNPrefix + cmd.mydb.Resolution;
                string   assistLayerName = "contour_assist_" + cmd.mydb.Resolution;
                ObjectId layerId         = LayerUtil.CreateLayer(layerName, 127, true, false);
                ObjectId assistLayerId   = LayerUtil.CreateLayer(assistLayerName, 127, true, false);
                int      num             = DBManager.SetEpsilon();
                int      num2            = (int)Convert.ToInt16(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("LUPREC").ToString());
                num = Math.Min(num2 + 2, num);
                List <Triangle> list = Conversions.ToCeometricCADDataTriangleList(objectId_0);
                if (coordinateSystem_0 != coordinateSystem)
                {
                    Triangle.TransformCoordinates(list, coordinateSystem, coordinateSystem_0);
                }
                else
                {
                    coordinateSystem_0 = null;
                }
                int limit = (int)(Math.Abs(ContourLineComputation.endElevation - ContourLineComputation.startElevation) / ContourLineComputation.spacing);
                progressMeter.SetLimit(limit);
                progressMeter.Start("Computing contours");
                int    num3      = 0;
                int    num4      = 0;
                int    num5      = 0;
                int    num6      = 0;
                int    num7      = 0;
                double maxZ      = cmd.mydb.TEDicList[cmd.mydb.Resolution].maxMaxZ;
                double elevation = ContourLineComputation.startElevation;
                Plane  plane     = new Plane(new ngeometry.VectorGeometry.Point(0.0, 0.0, elevation), new Vector3d(0.0, 0.0, 1.0));
                cmd.mydb.assistContourDics[cmd.mydb.Resolution] = new AssistContourDic();
                while (elevation <= ContourLineComputation.endElevation)
                {
                    if (elevation >= maxZ)
                    {
                        break;
                    }
                    progressMeter.MeterProgress();
                    messageFilter.CheckMessageFilter();
                    List <Edge> interEdgeList = this.getInterSection2(list, plane, num3, ref num5, ref num4);
                    if (interEdgeList.Count <= 0)
                    {
                        editor.WriteMessage("\nNo contours at elevation : " + elevation.ToString());
                    }
                    else
                    {
                        Autodesk.AutoCAD.Geometry.Plane    plane1  = new Autodesk.AutoCAD.Geometry.Plane(new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0), new Autodesk.AutoCAD.Geometry.Vector3d(0, 0, 1));
                        Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal);
                        TransformUtil.Transform(interEdgeList, prjMat1);
                        List <Polyline3d> pline3ds = new List <Polyline3d>();
                        List <PLine>      pllist   = DBManager.WritePlinesInDataBase2(interEdgeList, coordinateSystem_0, num, false, layerId, Color.White, pline3ds);
                        cmd.contColorize.addContour(pline3ds, elevation);
                        num6 += pllist.Count;

                        double assistElevation = elevation + spacing / 2;
                        if (assistElevation >= maxZ)
                        {
                            assistElevation = elevation + (maxZ - elevation) / 2;
                        }
                        genAssistContour(list, plane, coordinateSystem_0, assistLayerId, assistElevation, num, num3);
                        num7 += interEdgeList.Count;
                    }

                    elevation    += ContourLineComputation.spacing;
                    plane.Point.Z = elevation;
                    num3++;
                }
                editor.WriteMessage("\nFailed intersections     : " + num5);
                editor.WriteMessage("\nDegenerate intersections : " + num4);
                editor.WriteMessage("\nTotal number of segments : " + num7);
                editor.WriteMessage("\nTotal number of polylines: " + num6);
                progressMeter.Stop();
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                throw;
            }
        }