Exemple #1
0
        // --- function --
        public static double AngleBetweenZaxes(UCS ucs1, UCS ucs2)
        {
            double     ang = 0;
            Quaternion q1  = new Quaternion(ucs1.ToACS(new Quaternion(0, 0, 0, 100)) - ucs1.ToACS(new Quaternion(0, 0, 0, 0)));
            Quaternion q2  = new Quaternion(ucs2.ToACS(new Quaternion(0, 0, 0, 100)) - ucs2.ToACS(new Quaternion(0, 0, 0, 0)));

            ang = q1.angTo(q2);

            return(ang);
        }
Exemple #2
0
        public static void DrawSolidDescription(ObjectIdCollection OuterContours, Point3d origin, Point3d Xaxe, Point3d Yaxe, PromptPointResult target, bool bds)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;  

            Vector3d vX, vY, vZ;
            ObjectId ID = OuterContours[OuterContours.Count - 1];
            Point3d centroid = new Point3d();
            string layer;
            ObjectId[] solids = { ID, ID, ID, ID, ID, ID, ID };
            using (Transaction acTrans = db.TransactionManager.StartTransaction())
            {
                BlockTable acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Entity ent = acTrans.GetObject(ID, OpenMode.ForRead) as Entity;

                #region check selection
                String[] str = ent.GetType().ToString().Split('.');
                if (str[str.Length - 1] != "Solid3d")//check for solid
                {
                    MessageBox.Show("No selected Solid !");
                    return;
                }

                Quaternion q1 = new Quaternion(Xaxe.X - origin.X, Xaxe.Y - origin.Y, Xaxe.Z - origin.Z, 0);
                Quaternion q2 = new Quaternion(Yaxe.X - origin.X, Yaxe.Y - origin.Y, Yaxe.Z - origin.Z, 0);

                if (q1.abs() < 10E-11)
                {
                    MessageBox.Show("origin = Xaxe !");
                    return;
                }

                if (q2.abs() < 10E-11)
                {
                    MessageBox.Show("origin = Xaxe !");
                    return;
                }


                q1 /= q1.abs();
                q2 /= q2.abs();

                Quaternion q = q2 / q1;
                q = new Quaternion(0, q.GetX(), q.GetY(), q.GetZ());
                if (q.norm() < 10E-14)
                {
                    MessageBox.Show("three points in one line !");
                    return;
                }
                #endregion

                Solid3d solid = acTrans.GetObject(ID, OpenMode.ForWrite) as Solid3d;
                layer = solid.Layer;
                solids[0] = solid.ObjectId;

                centroid = solid.MassProperties.Centroid;

                UCS UCS = new UCS(new Quaternion(0, origin.X, origin.Y, origin.Z), new Quaternion(0, Xaxe.X, Xaxe.Y, Xaxe.Z), new Quaternion(0, Yaxe.X, Yaxe.Y, Yaxe.Z));
                Quaternion ucsX = UCS.ToACS(new Quaternion(0, 1, 0, 0));
                Quaternion ucsY = UCS.ToACS(new Quaternion(0, 0, 1, 0));
                Quaternion ucsZ = UCS.ToACS(new Quaternion(0, 0, 0, 1));
                vX = origin.GetVectorTo(new Point3d(ucsX.GetX(), ucsX.GetY(), ucsX.GetZ()));
                vY = origin.GetVectorTo(new Point3d(ucsY.GetX(), ucsY.GetY(), ucsY.GetZ()));
                vZ = origin.GetVectorTo(new Point3d(ucsZ.GetX(), ucsZ.GetY(), ucsZ.GetZ()));

                _centroid = centroid;
                vO[0] = vX; vO[1] = vY; vO[2] = vZ;
                _target = target.Value;

                Matrix3d newMatrix = new Matrix3d();
                newMatrix = Matrix3d.AlignCoordinateSystem(centroid, vX, vY, vZ, centroid, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis);
                solid.TransformBy(newMatrix);


                Point3d MIN = new Point3d(solid.GeometricExtents.MinPoint.X - centroid.X, solid.GeometricExtents.MinPoint.Y - centroid.Y, solid.GeometricExtents.MinPoint.Z - centroid.Z);
                Point3d MAX = new Point3d(solid.GeometricExtents.MaxPoint.X - centroid.X, solid.GeometricExtents.MaxPoint.Y - centroid.Y, solid.GeometricExtents.MaxPoint.Z - centroid.Z);

                double MaxX = (Math.Abs(MIN.X) > Math.Abs(MAX.X)) ? Math.Abs(MIN.X) : Math.Abs(MAX.X);
                double MaxY = (Math.Abs(MIN.Y) > Math.Abs(MAX.Y)) ? Math.Abs(MIN.Y) : Math.Abs(MAX.Y);
                double MaxZ = (Math.Abs(MIN.Z) > Math.Abs(MAX.Z)) ? Math.Abs(MIN.Z) : Math.Abs(MAX.Z);


                Solid3d[] solidARR = { solid.Clone() as Solid3d, solid.Clone() as Solid3d, solid.Clone() as Solid3d, solid.Clone() as Solid3d, solid.Clone() as Solid3d };

                for (int i = 0; i < 5; i++)
                {
                    modelSpace.AppendEntity(solidARR[i]);
                    acTrans.AddNewlyCreatedDBObject(solidARR[i], true);
                }

                Vector3d vRot1 = centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y + 2.5 * Math.Abs(MAX.X), centroid.Z));
                Vector3d vRot2 = centroid.GetVectorTo(new Point3d(centroid.X + 2.5 * Math.Abs(MAX.X), centroid.Y, centroid.Z));
                Vector3d vRot3 = centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y, centroid.Z + 2.5 * Math.Abs(MAX.Z)));


                if (bds)
                {
                    solidARR[0].TransformBy(Matrix3d.Rotation(-Math.PI / 2.0, vRot1, centroid));
                    solidARR[0].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X - MaxZ - 1.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[1] = solidARR[0].ObjectId;
                    solidARR[1].TransformBy(Matrix3d.Rotation(Math.PI / 2.0, vRot1, centroid));
                    solidARR[1].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + MaxZ + 1.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[2] = solidARR[1].ObjectId;
                    solidARR[2].TransformBy(Matrix3d.Rotation(Math.PI, vRot1, centroid));
                    solidARR[2].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + 3 * MaxZ + 2.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[3] = solidARR[2].ObjectId;
                    solidARR[3].TransformBy(Matrix3d.Rotation(Math.PI / 2, vRot2, centroid));
                    solidARR[3].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y - MaxZ - 1.5 * MaxY, centroid.Z))));
                    solids[4] = solidARR[3].ObjectId;
                    solidARR[4].TransformBy(Matrix3d.Rotation(-Math.PI / 2, vRot2, centroid));
                    solidARR[4].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y + MaxZ + 1.5 * MaxY, centroid.Z))));
                    solids[5] = solidARR[4].ObjectId;
                }
                else
                {
                    solidARR[0].TransformBy(Matrix3d.Rotation(-Math.PI / 2.0, vRot1, centroid));
                    solidARR[0].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + MaxZ + 1.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[1] = solidARR[0].ObjectId;

                    solidARR[1].TransformBy(Matrix3d.Rotation(Math.PI / 2.0, vRot1, centroid));
                    solidARR[1].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X - MaxZ - 1.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[2] = solidARR[1].ObjectId;

                    solidARR[2].TransformBy(Matrix3d.Rotation(Math.PI, vRot1, centroid));
                    solidARR[2].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + 3 * MaxZ + 2.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[3] = solidARR[2].ObjectId;
                    solidARR[3].TransformBy(Matrix3d.Rotation(Math.PI / 2, vRot2, centroid));
                    solidARR[3].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y + MaxZ + 1.5 * MaxY, centroid.Z))));
                    solids[4] = solidARR[3].ObjectId;
                    solidARR[4].TransformBy(Matrix3d.Rotation(-Math.PI / 2, vRot2, centroid));
                    solidARR[4].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y - MaxZ - 1.5 * MaxY, centroid.Z))));
                    solids[5] = solidARR[4].ObjectId;
                }

                Solid3d solid1 = solid.Clone() as Solid3d;
                modelSpace.AppendEntity(solid1);
                acTrans.AddNewlyCreatedDBObject(solid1, true);

                solids[6] = solid1.ObjectId;

                solid1.TransformBy(Matrix3d.Rotation(Math.PI / 4, vRot3, centroid));
                solid1.TransformBy(Matrix3d.Rotation(-Math.PI / 3.28854, vRot2, centroid));

                double dX = Math.Abs(solid1.GeometricExtents.MinPoint.X - centroid.X) + Math.Abs(solid.GeometricExtents.MaxPoint.X - centroid.X);
                double dY = Math.Abs(solid1.GeometricExtents.MinPoint.Y - centroid.Y) + Math.Abs(solid.GeometricExtents.MaxPoint.Y - centroid.Y);
                solid1.TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + dX + 1.5 * MaxX, centroid.Y + dY + 1.5 * MaxY, 0))));

                acTrans.Commit();
            }

            for (int i = 0; i < 7; i++)
            {
                solids_buff[i] = solids[i];
            }


            doc.SendStringToExecute("-view\rO\rT\r", false, false, false);
            doc.SendStringToExecute("TILEMODE\r0\r", false, false, false);
            // Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", 0);
            // Doc.Editor.SwitchToPaperSpace();
            doc.SendStringToExecute("MSPACE\r", false, false, false);
            doc.SendStringToExecute("SOLPROF\rall\r\rY\rY\rY\r", false, false, false);
            doc.SendStringToExecute("PSPACE\r", false, false, false);
            doc.SendStringToExecute("TILEMODE\r1\r", false, false, false);
            //Doc.SendStringToExecute("ZOOM\rE\r" , false , false , false);
            doc.SendStringToExecute("hideflat\r", false, false, false);

            if (target.Status == PromptStatus.OK)
            {
                string bs = centroid.X.ToString() + "," + centroid.Y.ToString();
                string ts = target.Value.X.ToString() + "," + target.Value.Y.ToString();

                doc.SendStringToExecute("move\rlast\r\r" + bs + "\r" + ts + "\r", false, false, false);
                doc.SendStringToExecute("ZOOM\rE\r", false, false, false);

            }

            doc.SendStringToExecute("eraseflat\r", false, false, false);
            doc.SendStringToExecute("finalflat\r", false, false, false);
            doc.SendStringToExecute("ZOOM\rE\r", false, false, false);
        }
Exemple #3
0
        private void CreateInsulationPolylineAndAppendToModelSpace(Point3d[] inputPoints, int rk,
                                                                   bool drawPerimeterOfInsulation)
        {
            var inputQPoints = new Quaternion[4]; // completed after sorting

            #region sorting

            var longestDistance = 0.0;
            var indexFirstPoint = 0;
            for (var i = 1; i < 4; i++)
            {
                var currentDistance = inputPoints[i - 1].DistanceTo(inputPoints[i]);
                if (currentDistance > longestDistance)
                {
                    longestDistance = currentDistance;
                    indexFirstPoint = i - 1;
                }
            }
            if (inputPoints[3].DistanceTo(inputPoints[0]) > longestDistance)
            {
                indexFirstPoint = 3;
            }

            var tempPoints = new Point3d[4];
            for (var i = indexFirstPoint; i < 4 + indexFirstPoint; i++)
            {
                if (i < 4)
                {
                    tempPoints[i - indexFirstPoint] = inputPoints[i];
                }
                else
                {
                    tempPoints[i - indexFirstPoint] = inputPoints[i - 4];
                }
            }

            for (var i = 0; i < 4; i++)
            {
                inputPoints[i]  = tempPoints[i];
                inputQPoints[i] = new Quaternion(0.0, inputPoints[i].X, inputPoints[i].Y, inputPoints[i].Z);
            }

            #endregion

            var uCSOfInputPoints = new UCS(inputQPoints[0], inputQPoints[1], inputQPoints[2]);

            if (Math.Abs((uCSOfInputPoints.FromACS(inputQPoints[3])).GetZ()) > 0.00000254)
            {
                _editorHelper.WriteMessage("Four Points are not in the same Plane !");
                _logger.Info("User input is invalid.");
                return;
            }

            #region counterclockwise selection test

            var centerUcsOfInputPoints  = new Quaternion(0, 0, 0, 0);
            var zAxisInUscOfInputPoints = new Quaternion(0, 0, 0, 1000);
            var zAxisInAcs = uCSOfInputPoints.ToACS(zAxisInUscOfInputPoints) -
                             uCSOfInputPoints.ToACS(centerUcsOfInputPoints);
            if (zAxisInAcs.GetZ() < 0)
            {
                var tempPoint      = new Point3d();
                var tempQuaternion = new Quaternion();

                tempPoint      = inputPoints[0];
                inputPoints[0] = inputPoints[1];
                inputPoints[1] = tempPoint;

                tempQuaternion  = inputQPoints[0];
                inputQPoints[0] = inputQPoints[1];
                inputQPoints[1] = tempQuaternion;

                tempPoint      = inputPoints[2];
                inputPoints[2] = inputPoints[3];
                inputPoints[3] = tempPoint;

                tempQuaternion  = inputQPoints[2];
                inputQPoints[2] = inputQPoints[3];
                inputQPoints[3] = tempQuaternion;

                uCSOfInputPoints = new UCS(inputQPoints[0], inputQPoints[1], inputQPoints[2]);
            }

            #endregion

            var ucsPoints = new Point3d[4];
            //are coordinates in a 0.0 WCS to draw (drawing only in oXY 0,0 per WCS and transform when it is ready polyline transform)
            var ucsQPoints = new Quaternion[4];
            //are coordinates in a 0.0 WCS to draw (drawing only in oXY 0,0 per WCS and when it is ready polyline transform)

            var complexPoints   = new Complex[4];
            var sidesOffPolygon = new Complex[4];

            #region 2d prepare

            for (int i = 0; i < 4; i++)
            {
                Quaternion q = uCSOfInputPoints.FromACS(inputQPoints[i]);
                ucsQPoints[i] = new Quaternion(0, (Math.Abs(q.GetX()) > 0.00000254) ? q.GetX() : 0.0,
                                               (Math.Abs(q.GetY()) > 0.00000254) ? q.GetY() : 0.0,
                                               (Math.Abs(q.GetZ()) > 0.00000254) ? q.GetZ() : 0.0);
                ucsPoints[i]     = new Point3d(ucsQPoints[i].GetX(), ucsQPoints[i].GetY(), ucsQPoints[i].GetZ());
                complexPoints[i] = new Complex(ucsQPoints[i].GetX(), ucsQPoints[i].GetY());
                if (i > 0)
                {
                    sidesOffPolygon[i - 1] = complexPoints[i] - complexPoints[i - 1];
                }
            }
            sidesOffPolygon[3] = complexPoints[0] - complexPoints[3];

            #endregion

            #region convex check

            for (var i = 0; i < 4; i++)
            {
                if (Math.Abs(GetAngleInPointIndex(i, complexPoints)) >= Math.PI)
                {
                    break;
                }
            }

            #endregion

            var minThickness = (complexPoints[2].imag() < complexPoints[3].imag())
                                   ? complexPoints[2].imag()
                                   : complexPoints[3].imag();
            var segmentsCount = (int)Math.Ceiling((sidesOffPolygon[0].abs() / minThickness) / 0.35);

            var radius = sidesOffPolygon[0].abs() * 2 / (segmentsCount * 2);
            radius /= rk;

            var lowerLine = new List <Complex>();
            var upperLine = new List <Complex>();


            var insulationPerimeter = new Polyline();
            insulationPerimeter.SetDatabaseDefaults();
            insulationPerimeter.AddVertexAt(0, new Point2d(complexPoints[0].real(), complexPoints[0].imag()), 0, 0,
                                            0);
            insulationPerimeter.AddVertexAt(1, new Point2d(complexPoints[1].real(), complexPoints[1].imag()), 0, 0,
                                            0);
            insulationPerimeter.AddVertexAt(2, new Point2d(complexPoints[2].real(), complexPoints[2].imag()), 0, 0,
                                            0);
            insulationPerimeter.AddVertexAt(3, new Point2d(complexPoints[3].real(), complexPoints[3].imag()), 0, 0,
                                            0);
            insulationPerimeter.AddVertexAt(4, new Point2d(complexPoints[0].real(), complexPoints[0].imag()), 0, 0,
                                            0);

            var objectsCollection = insulationPerimeter.GetOffsetCurves(-radius);
            var acPolyOffset      = objectsCollection[0] as Polyline;

            var pointsFromOffset = new Complex[4];
            for (var i = 0; i < 4; i++)
            {
                var point = acPolyOffset.GetPoint3dAt(i);
                pointsFromOffset[i] = new Complex(point.X, point.Y);
            }

            var variant = 0;
            if (pointsFromOffset[3].real() < pointsFromOffset[0].real() &&
                (pointsFromOffset[3] - pointsFromOffset[0]).abs() / (radius * 2) > 1 &&
                Math.Abs(pointsFromOffset[2].real() - pointsFromOffset[1].real()) > radius * 2)
            {
                variant = 1;
                lowerLine.Add(pointsFromOffset[0]);
                var xPos = pointsFromOffset[0].real();
                do
                {
                    xPos += radius * 2.0;
                    if (xPos <= pointsFromOffset[1].real() + radius * 2 / 3)
                    {
                        lowerLine.Add(new Complex(xPos, radius));
                    }
                } while (xPos < (pointsFromOffset[0] - pointsFromOffset[1]).abs() + radius * 2 / 3);

                xPos = 0;
                var ort = (pointsFromOffset[3] - pointsFromOffset[0]) /
                          (pointsFromOffset[3] - pointsFromOffset[0]).abs();
                var k = Math.Abs(Math.Cos(ort.arg()));
                k -= 0.01;
                do
                {
                    xPos += 2 * radius / Math.Abs(k);
                    if (xPos < (pointsFromOffset[3] - pointsFromOffset[0]).abs() + radius * 2 / 3)
                    {
                        lowerLine.Insert(0, ort * xPos + pointsFromOffset[0]);
                    }
                } while (xPos < (pointsFromOffset[3] - pointsFromOffset[0]).abs() + radius * 2 / 3);
                lowerLine.RemoveAt(0);
            }

            if (pointsFromOffset[1].real() < pointsFromOffset[2].real() &&
                (pointsFromOffset[2] - pointsFromOffset[1]).abs() / (radius * 2) > 1 &&
                Math.Abs(pointsFromOffset[2].real() - pointsFromOffset[1].real()) > radius * 2)
            {
                variant = 2;
                lowerLine.Add(pointsFromOffset[1]);
                var xPos = pointsFromOffset[1].real();
                do
                {
                    xPos -= radius * 2.0;
                    if (xPos >= pointsFromOffset[0].real() - radius * 2.0 / 3.0)
                    {
                        lowerLine.Insert(0, new Complex(xPos, radius));
                    }
                } while (xPos > pointsFromOffset[0].real() - radius * 2.0 / 3.0);


                xPos = 0;
                var ort = (pointsFromOffset[2] - pointsFromOffset[1]) /
                          (pointsFromOffset[2] - pointsFromOffset[1]).abs();
                var k = Math.Abs(Math.Cos(ort.arg()));
                k -= 0.01;
                do
                {
                    xPos += 2 * radius / Math.Abs(k);
                    if (xPos < (pointsFromOffset[2] - pointsFromOffset[1]).abs() + radius * 2.0 / 3.0)
                    {
                        lowerLine.Add(ort * xPos + pointsFromOffset[1]);
                    }
                } while (xPos < (pointsFromOffset[2] - pointsFromOffset[1]).abs() + radius * 2.0 / 3.0);
            }
            if (variant == 0)
            {
                lowerLine.Add(pointsFromOffset[0]);
                var xPos = pointsFromOffset[0].real();
                do
                {
                    xPos += radius * 2.0;
                    if (xPos <= pointsFromOffset[1].real() + radius * 2.0)
                    {
                        lowerLine.Add(new Complex(xPos, radius));
                    }
                } while (xPos < (pointsFromOffset[0] - pointsFromOffset[1]).abs() + radius * 2.0);
            }

            var insulationPolyline = new Polyline();
            insulationPolyline.SetDatabaseDefaults();
            var old = new KeyValuePair <Complex, Complex>();
            for (var i = 1; i < lowerLine.Count; i++)
            {
                var hlpPoint = (lowerLine[i] + lowerLine[i - 1]) / 2.0;

                var verticalLine = new Line(new Point3d(hlpPoint.real(), hlpPoint.imag(), 0),
                                            new Point3d(hlpPoint.real(), hlpPoint.imag() + 0.01, 0));

                var pts = new Point3dCollection();
                try
                {
                    acPolyOffset.IntersectWith(verticalLine, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                }
                catch (Exception aCadRuntimeException)
                {
                    _logger.Error("Unable to Intersect 2 entities", aCadRuntimeException);
                }
                if (pts.Count != 2)
                {
                    continue;
                }
                var p  = (pts[0].Y > pts[1].Y) ? pts[0] : pts[1];
                var cc = new Complex(p.X, p.Y);
                if ((cc - hlpPoint).abs() > 2 * radius)
                {
                    upperLine.Add(new Complex(p.X, p.Y));

                    var tangentPointsTopLeftBotRight = GetTangentPointsOfCommonInternalTanget(cc, radius,
                                                                                              lowerLine[i], radius,
                                                                                              true);
                    var tangentPointsBotRightTopLeft = GetTangentPointsOfCommonInternalTanget(lowerLine[i - 1],
                                                                                              radius, cc, radius,
                                                                                              false);

                    if (i > 1)
                    {
                        double ang1 = 0;

                        ang1 =
                            ((lowerLine[i - 1] - tangentPointsBotRightTopLeft.Key) / (lowerLine[i - 1] - old.Value))
                            .arg();
                        insulationPolyline.AddVertexAt(0,
                                                       new Point2d(tangentPointsBotRightTopLeft.Key.real(),
                                                                   tangentPointsBotRightTopLeft.Key.imag()),
                                                       -Math.Tan(ang1 / 4), 0, 0);
                    }
                    else
                    {
                        insulationPolyline.AddVertexAt(0,
                                                       new Point2d(tangentPointsBotRightTopLeft.Key.real(),
                                                                   tangentPointsBotRightTopLeft.Key.imag()), 0, 0, 0);
                    }
                    double ang =
                        ((cc - tangentPointsBotRightTopLeft.Value) / (cc - tangentPointsTopLeftBotRight.Key)).arg();
                    insulationPolyline.AddVertexAt(0,
                                                   new Point2d(tangentPointsBotRightTopLeft.Value.real(),
                                                               tangentPointsBotRightTopLeft.Value.imag()), 0, 0, 0);

                    insulationPolyline.AddVertexAt(0,
                                                   new Point2d(tangentPointsTopLeftBotRight.Key.real(),
                                                               tangentPointsTopLeftBotRight.Key.imag()),
                                                   Math.Tan(ang / 4), 0, 0);
                    insulationPolyline.AddVertexAt(0,
                                                   new Point2d(tangentPointsTopLeftBotRight.Value.real(),
                                                               tangentPointsTopLeftBotRight.Value.imag()), 0, 0, 0);

                    old = tangentPointsTopLeftBotRight;
                }
                else
                {
                    if (i < lowerLine.Count / 2)
                    {
                        lowerLine.RemoveAt(i - 1);
                    }
                    else
                    {
                        lowerLine.RemoveAt(i);
                    }
                    i--;
                }
            }

            var vectorBaseLine = new Complex(inputPoints[1].X, inputPoints[1].Y) -
                                 new Complex(inputPoints[0].X, inputPoints[0].Y);

            #region transforms

            insulationPolyline.TransformBy(Matrix3d.Rotation(vectorBaseLine.arg(), new Vector3d(0, 0, 1),
                                                             Point3d.Origin));
            insulationPerimeter.TransformBy(Matrix3d.Rotation(vectorBaseLine.arg(), new Vector3d(0, 0, 1),
                                                              Point3d.Origin));

            insulationPolyline.TransformBy(Matrix3d.Displacement(Point3d.Origin.GetVectorTo(inputPoints[0])));
            insulationPerimeter.TransformBy(Matrix3d.Displacement(Point3d.Origin.GetVectorTo(inputPoints[0])));

            insulationPolyline.TransformBy(_editorHelper.CurrentUcs);
            insulationPerimeter.TransformBy(_editorHelper.CurrentUcs);

            #endregion

            var oldLayer = _documentHelper.Database.Clayer;

            _documentHelper.LayerManipulator.CreateLayer("3-0", System.Drawing.Color.Lime);
            insulationPolyline.Layer = "0";
            var softInsulationBlock = new BlockTableRecord();
            var nameSalt            = DateTime.Now.GetHashCode().ToString();
            softInsulationBlock.Name   = "SoftInsulation_" + nameSalt;
            softInsulationBlock.Origin = inputPoints[0];

            using (var acTrans = _documentHelper.TransactionManager.StartTransaction())
            {
                var acBlkTbl = acTrans.GetObject(_documentHelper.Database.BlockTableId, OpenMode.ForWrite) as BlockTable;
                acBlkTbl.Add(softInsulationBlock);
                acTrans.AddNewlyCreatedDBObject(softInsulationBlock, true);
                softInsulationBlock.AppendEntity(insulationPolyline);
                acTrans.AddNewlyCreatedDBObject(insulationPolyline, true);
                if (drawPerimeterOfInsulation)
                {
                    insulationPerimeter.Layer = "0";
                    softInsulationBlock.AppendEntity(insulationPerimeter);
                    acTrans.AddNewlyCreatedDBObject(insulationPerimeter, true);
                }
                var rigidInsulationRef = new BlockReference(inputPoints[0],
                                                            softInsulationBlock.ObjectId)
                {
                    Layer = "3-0"
                };
                var currentSpace =
                    (BlockTableRecord)acTrans.GetObject(_documentHelper.Database.CurrentSpaceId, OpenMode.ForWrite);
                currentSpace.AppendEntity(rigidInsulationRef);
                acTrans.AddNewlyCreatedDBObject(rigidInsulationRef, true);
                acTrans.Commit();
            }
            _documentHelper.LayerManipulator.ChangeLayer(oldLayer);
        }
Exemple #4
0
        public void ArrowMarkStart()
        {
            var basePointResult = _editorHelper.PromptForPoint("Pick arrow point : ");

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

            var directionPointResult = _editorHelper.PromptForPoint("Pick direction point : ", true, true, basePointResult.Value);

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

            if (directionPointResult.Value == basePointResult.Value)
            {
                _editorHelper.WriteMessage("\nBase point and direction point can not be the same or be less then 8 units closer. Try again and place the direction point further from the base point.");
                return;
            }

            Vector3d xAxis = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Xaxis;
            Vector3d yAxis = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Yaxis;

            xAxis = (xAxis + yAxis) / 2.0;

            Matrix3d ucs = _editorHelper.CurrentUcs;

            basePointResult.Value.TransformBy(GeometryUtility.GetTransforMatrixToWcs());
            directionPointResult.Value.TransformBy(GeometryUtility.GetTransforMatrixToWcs());



            _editorHelper.CurrentUcs = Matrix3d.Identity;
            Point3d    endPoint = directionPointResult.Value;
            Vector3d   vx       = new Vector3d(endPoint.X - basePointResult.Value.X, endPoint.Y - basePointResult.Value.Y, endPoint.Z - basePointResult.Value.Z);
            Quaternion qx       = new Quaternion(0, vx.X, vx.Y, vx.Z);
            Quaternion qy       = new Quaternion(0, xAxis.X, xAxis.Y, xAxis.Z);
            UCS        UCS      = new UCS(new Quaternion(0, 0, 0, 0), qx, qy);

            qx = UCS.ToACS(new Quaternion(0, 1, 0, 0));
            qy = UCS.ToACS(new Quaternion(0, 0, 1, 0));
            Quaternion qz = UCS.ToACS(new Quaternion(0, 0, 0, 1));

            vx    = new Vector3d(qx.GetX(), qx.GetY(), qx.GetZ());
            yAxis = new Vector3d(qy.GetX(), qy.GetY(), qy.GetZ());
            Vector3d vZ = new Vector3d(qz.GetX(), qz.GetY(), qz.GetZ());

            Matrix3d newUcs = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, basePointResult.Value, vx, yAxis, vZ);

            double dist = basePointResult.Value.DistanceTo(endPoint);

            endPoint = new Point3d(dist, 0, 0);

            Hashtable dynamicBlockProperties = new Hashtable();
            Hashtable dynamicBlockAttributes = new Hashtable();

            dynamicBlockProperties.Add("Base Point", basePointResult);
            dynamicBlockProperties.Add("Arrow Direction", (Int16)0); // always to the right
            double rotationAngle = GeometryUtility.GetAngleFromXAxis(new Point3d(), endPoint);

            dynamicBlockProperties.Add("Arrow Rotation", rotationAngle);

            ObjectId refO = new ObjectId();
            string   dynamicBlockFullName = _blockDrawingProvider.GetBlockFile(MethodBase.GetCurrentMethod().DeclaringType.Name);

            if (dynamicBlockFullName == null)
            {
                _editorHelper.WriteMessage("Dynamic block ArrowMark.dwg does not exist.");
                return;
            }

            try
            {
                refO = _drawingHelper.ImportDynamicBlockAndFillItsProperties(dynamicBlockFullName, new Point3d(), dynamicBlockProperties, dynamicBlockAttributes);
            }
            catch (Exception exception)
            {
                _logger.Error("Error importing Arrow mark.", exception);
                _editorHelper.WriteMessage("Error importing Arrow mark.");
                return;
            }


            using (Transaction startTransaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
            {
                var entity = (Entity)startTransaction.GetObject(refO, OpenMode.ForWrite);
                entity.TransformBy(newUcs);
                startTransaction.Commit();
            }

            _editorHelper.CurrentUcs = ucs;
            _logger.Info(MethodBase.GetCurrentMethod().Name);
        }
Exemple #5
0
        public void LevelHeightSignStart()
        {
            var insertionPointResult = _editorHelper.PromptForPoint("Pick insertion point : ");

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

            var dynamicBlockProperties = new Hashtable();
            var dynamicBlockAttributes = new Hashtable();

            dynamicBlockProperties.Add("Base Point", insertionPointResult.Value);
            var dynamicBlockPath = _blockDrawingProvider.GetBlockFile(MethodBase.GetCurrentMethod().DeclaringType.Name);

            if (dynamicBlockPath == null)
            {
                _editorHelper.WriteMessage("Dynamic block LevelHeightSign.dwg does not exist.");
                return;
            }
            var brefId = _drawingHelper.ImportDynamicBlockAndFillItsProperties(
                dynamicBlockPath, insertionPointResult.Value, dynamicBlockProperties, dynamicBlockAttributes);

            using (var transaction = _doc.TransactionManager.StartTransaction())
            {
                var blockReference = (BlockReference)transaction.GetObject(brefId, OpenMode.ForWrite);

                var zAxis  = _doc.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis;
                var xAxis  = _doc.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Xaxis;
                var yAxis  = _doc.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Yaxis;
                var origin = _doc.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Origin;

                var mat = Matrix3d.AlignCoordinateSystem(
                    Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, origin, xAxis, yAxis, zAxis);

                blockReference.TransformBy(mat);

                var ORIGIN = new Quaternion(0, origin.X, origin.Y, origin.Z);
                var axeX   = new Quaternion(0, xAxis.X, xAxis.Y, xAxis.Z);
                var axeY   = new Quaternion(0, yAxis.X, yAxis.Y, yAxis.Z);

                var ucs       = new UCS(ORIGIN, ORIGIN + axeX, ORIGIN + axeY);
                var basePoint = new Quaternion(
                    0, insertionPointResult.Value.X, insertionPointResult.Value.Y, insertionPointResult.Value.Z);
                basePoint = ucs.ToACS(basePoint);
                ucs       = new UCS(ORIGIN, ORIGIN + axeX, basePoint);

                var y = ucs.FromACS(basePoint).GetY();
                if (double.IsNaN(y))
                {
                    y = 0.0;
                }

                foreach (ObjectId attId in blockReference.AttributeCollection)
                {
                    var attributeReference = (AttributeReference)transaction.GetObject(attId, OpenMode.ForWrite);
                    if (attributeReference.Tag == "LEVEL")
                    {
                        var mess = y.ToString("0.#####");
                        attributeReference.TextString = (mess.Length > 0) ? mess : "0.0";
                    }
                }
                transaction.Commit();
            }
            _logger.Info(MethodBase.GetCurrentMethod().Name);
        }