Beispiel #1
0
        public Complex IntersectWitch(KLine2D l)
        {
            double x = (-C * l.B + B * l.C) / (A * l.B - B * l.A);
            double y = (-A * l.C + C * l.A) / (A * l.B - B * l.A);

            return(new Complex(x, y));
        }
Beispiel #2
0
        public KLine2D(KLine2D l, double delta)
        // |L| - разстоянието от (0,0) до правата
        //delta > 0 = |L| нараства ; delta < 0 = |L| намалявa
        {
            double k = (l.C == 0) ? 1 : (l.C / Math.Abs(l.C));

            C  = Math.Abs(l.C) + delta * Math.Sqrt(l.A * l.A + l.B * l.B);
            C *= k;
            A  = l.A;
            B  = l.B;
        }
Beispiel #3
0
        public static bool IsParalel(KLine2D l1, KLine2D l2)
        {
            bool    rez = false;
            Complex c   = (new Complex(l1.A, l1.B)) / (new Complex(l2.A, l2.B));

            c.x = 0.0;
            if (c.norm() < 0.00000001)
            {
                rez = true;
            }
            return(rez);
        }
Beispiel #4
0
 public KLine2D(KLine2D l)
 {
     A = l.A;
     B = l.B;
     C = l.C;
 }
Beispiel #5
0
        private static double DrawOffset(int N1, int N2, double dist, bool boo)
        {
            double rez = 0;

            using (Transaction transaction = _db.TransactionManager.StartTransaction())
            {
                BlockTable blockTable = transaction.GetObject(_db.BlockTableId, OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord modelSpace = transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                LayerTable layerTable = transaction.GetObject(_db.LayerTableId, OpenMode.ForRead) as LayerTable;

                Polyline bpLine = (Polyline)transaction.GetObject(_polylineId, OpenMode.ForWrite);

                int      off       = -1;
                Polyline firstPoly = new Polyline();
                firstPoly.SetDatabaseDefaults();

                #region make poly
                ArrayList arrayList = new ArrayList();
                for (int j = 1; j <= (bpLine.NumberOfVertices >> 1); j++)
                {
                    if ((N1 + j) > (bpLine.NumberOfVertices - 1))
                    {
                        off++;
                    }
                    int           i   = (off < 0) ? (N1 + j) : off;
                    LineSegment2d seg = bpLine.GetLineSegment2dAt(i);
                    double        bulge;
                    if ((i - 1) < 0)
                    {
                        bulge = bpLine.GetBulgeAt(bpLine.NumberOfVertices - 1);
                    }
                    else
                    {
                        if ((i - 1) > bpLine.NumberOfVertices - 1)
                        {
                            bulge = bpLine.GetBulgeAt(0);
                        }
                        else
                        {
                            bulge = -bpLine.GetBulgeAt(i - 1);
                        }
                    }
                    firstPoly.AddVertexAt(0, new Point2d(seg.StartPoint.X, seg.StartPoint.Y), bulge, 0, 0);
                    arrayList.Add(bpLine.GetBulgeAt(i));
                }

                modelSpace.AppendEntity(firstPoly);
                transaction.AddNewlyCreatedDBObject(firstPoly, true);
                #endregion

                #region coating
                if (boo)
                {
                    LineSegment2d seg1 = firstPoly.GetLineSegment2dAt(0);
                    LineSegment2d seg2 = bpLine.GetLineSegment2dAt(N2);
                    Complex       mid  = new Complex((seg2.StartPoint.X + seg2.EndPoint.X) / 2, (seg2.StartPoint.Y + seg2.EndPoint.Y) / 2);
                    Line2d        l    = new Line2d(new Complex(seg1.StartPoint.X, seg1.StartPoint.Y), new Complex(seg1.EndPoint.X, seg1.EndPoint.Y));

                    int k = l.PositionOfТhePointToLineSign(mid);

                    DBObjectCollection oc = firstPoly.GetOffsetCurves((k < 0) ? dist : -dist);
                    foreach (Entity acEnt in oc)
                    {
                        modelSpace.AppendEntity(acEnt);
                        transaction.AddNewlyCreatedDBObject(acEnt, true);
                        acEnt.TransformBy(_ed.CurrentUserCoordinateSystem);
                        try
                        {
                            acEnt.Layer = _sheetDescriptionForm.GetCoatingLayer();
                        }
                        catch
                        {
                            LayerTableRecord acLyrTblRec = transaction.GetObject(_db.Clayer, OpenMode.ForWrite) as LayerTableRecord;
                            acEnt.Layer = acLyrTblRec.Name;
                        }
                        try
                        {
                            System.Drawing.Color color = _sheetDescriptionForm.GetCoatingColor();
                            if (color.Name == "ByLayer")
                            {
                                throw new ArgumentNullException();
                            }
                            acEnt.Color = Color.FromColor(color);
                        }
                        catch
                        {
                            //LayerTableRecord acLyrTblRec = acTrans.GetObject(Db.Clayer, OpenMode.ForWrite) as LayerTableRecord;
                            LayerTableRecord acLyrTblRec = transaction.GetObject(layerTable[acEnt.Layer], OpenMode.ForWrite) as LayerTableRecord;
                            acEnt.Color = acLyrTblRec.Color;
                        }

                        _entityTemp.Add(acEnt);
                    }
                    Polyline acPoly11 = oc[0] as Polyline;
                }
                #endregion

                #region calculate length
                for (int j = 0; j < firstPoly.NumberOfVertices - 1; j++)
                {
                    if (Math.Abs(firstPoly.GetBulgeAt(j)) != 0.0)
                    {
                        CircularArc2d arc = firstPoly.GetArcSegment2dAt(j);
                        double        rad = arc.Radius;
                        double        ang = Math.Abs(Math.Atan(firstPoly.GetBulgeAt(j)));
                        rez += (4 * ang * rad);
                    }
                    else
                    {
                        LineSegment2d seg = firstPoly.GetLineSegment2dAt(j);
                        Complex       s   = new Complex(seg.StartPoint.X, seg.StartPoint.Y);
                        Complex       e   = new Complex(seg.EndPoint.X, seg.EndPoint.Y);
                        rez += (s - e).abs();
                    }
                }
                #endregion

                firstPoly.Erase();
                transaction.Commit();
            }
            _ed.Regen();
            return(rez);
        }
Beispiel #6
0
        // 2 Points, 2 Heights
        private void DrawInsulationOnTwoPointsTwoHeights(PromptPointResult firstPoint)
        {
            #region input data

            var firstPointResult  = firstPoint;
            var secondPointResult = _editorHelper.PromptForPoint("\nSelect SECOND point.", true, true,
                                                                 firstPointResult.Value);
            if (secondPointResult.Status != PromptStatus.OK)
            {
                return;
            }

            var thicknessAtFirstPointResult = _editorHelper.PromptForDouble("\nThickness at FIRST point : ",
                                                                            Settings.Default
                                                                            .SInsulationThicknessAtFirstPoint);
            if (thicknessAtFirstPointResult.Status != PromptStatus.OK)
            {
                return;
            }
            Settings.Default.SInsulationThicknessAtFirstPoint = thicknessAtFirstPointResult.Value;

            var thicknessAtSecondPointResult = _editorHelper.PromptForDouble("\nThickness at SECOND point : ",
                                                                             Settings.Default
                                                                             .SInsulationThicknessAtSecondPoint);
            if (thicknessAtSecondPointResult.Status != PromptStatus.OK)
            {
                return;
            }
            Settings.Default.SInsulationThicknessAtSecondPoint = thicknessAtSecondPointResult.Value;
            Settings.Default.Save();

            if (Math.Abs(firstPointResult.Value.Z) > 0.00001 || Math.Abs(secondPointResult.Value.Z) > 0.00001)
            {
                _editorHelper.WriteMessage("Soft Insulation should be placed in OXY plane !");
                _logger.Info("User input is invalid.");
                return;
            }
            #endregion

            #region preparation

            var minThickness = (thicknessAtFirstPointResult.Value < thicknessAtSecondPointResult.Value)
                                   ? thicknessAtFirstPointResult.Value
                                   : thicknessAtSecondPointResult.Value;
            var segmentsCount =
                (int)Math.Ceiling((firstPointResult.Value.DistanceTo(secondPointResult.Value) / minThickness) / 0.35);

            var     botLeftPoint = new Complex(0, 0);
            var     botRightPoint = new Complex(firstPointResult.Value.DistanceTo(secondPointResult.Value), 0);
            Complex topLeftPoint, topRightPoint;
            if (thicknessAtFirstPointResult.Value <= thicknessAtSecondPointResult.Value)
            {
                topLeftPoint  = new Complex(0, thicknessAtFirstPointResult.Value);
                topRightPoint = new Complex(firstPointResult.Value.DistanceTo(secondPointResult.Value),
                                            thicknessAtSecondPointResult.Value);
            }
            else
            {
                topLeftPoint  = new Complex(0, thicknessAtSecondPointResult.Value);
                topRightPoint = new Complex(firstPointResult.Value.DistanceTo(secondPointResult.Value),
                                            thicknessAtFirstPointResult.Value);
            }

            var vectorOfBaseLine = new Complex(secondPointResult.Value.X, secondPointResult.Value.Y) -
                                   new Complex(firstPointResult.Value.X, firstPointResult.Value.Y);

            var radiusBotCircle = firstPointResult.Value.DistanceTo(secondPointResult.Value) / (segmentsCount + 0.5);
            radiusBotCircle /= 2.0;

            var vectorTopEdge         = topRightPoint - topLeftPoint;
            var vectorTopEdgeOrt      = vectorTopEdge / vectorTopEdge.abs();
            var vectorNormalOfTopEdge = vectorTopEdgeOrt * (new Complex(0, 1.0));

            #endregion

            #region calculateCenterCircle

            var centersBotCircles = new List <Complex>();
            for (var i = 0; i < segmentsCount + 1; i++)
            {
                centersBotCircles.Add(new Complex(i * 2 * radiusBotCircle, radiusBotCircle));
            }

            var centersTopCircles = new List <KeyValuePair <double, Complex> >();
            var ordinate          = new Line2d(new Complex(radiusBotCircle, 0), new Complex(radiusBotCircle, 100));
            var offsetTopEdge     = new Line2d(topLeftPoint - vectorNormalOfTopEdge * radiusBotCircle,
                                               topRightPoint - vectorNormalOfTopEdge * radiusBotCircle);
            var centerFirstUpperCircle = offsetTopEdge.IntersectWitch(ordinate);
            centersTopCircles.Add(new KeyValuePair <double, Complex>(radiusBotCircle, centerFirstUpperCircle));

            if (((topRightPoint - topLeftPoint).arg()) * 180.0 / Math.PI <= 5)
            {
                for (var i = 1; i < segmentsCount + 1; i++)
                {
                    var rightVerticalEdge = new Line2d(botRightPoint, topRightPoint);
                    var lineParallelToX   = new Line2d(centersTopCircles[i - 1].Value,
                                                       centersTopCircles[i - 1].Value +
                                                       new Complex(rightVerticalEdge.A, rightVerticalEdge.B));
                    var distFromCurrentCircleToRightVertEdge =
                        Math.Abs(
                            (centersTopCircles[i - 1].Value - lineParallelToX.IntersectWitch(rightVerticalEdge)).abs() -
                            centersTopCircles[i - 1].Key);
                    var radiusTopCircle = (distFromCurrentCircleToRightVertEdge / (segmentsCount - i + 0.5)) / 2.0;

                    var rR = centersTopCircles[i - 1].Key + radiusTopCircle;
                    var dR = Math.Abs(radiusTopCircle - centersTopCircles[i - 1].Key);
                    var distBetweenCenters  = Math.Sqrt(rR * rR - dR * dR);
                    var centerNextTopCircle = centersTopCircles[i - 1].Value - vectorNormalOfTopEdge * dR +
                                              vectorTopEdgeOrt * distBetweenCenters;
                    centersTopCircles.Add(new KeyValuePair <double, Complex>(radiusTopCircle, centerNextTopCircle));
                }
            }
            else
            {
                for (var i = 1; i < segmentsCount + 1; i++)
                {
                    var tangentPoints = GetTangentPointsOfCommonExternalTanget(centersBotCircles[i], radiusBotCircle,
                                                                               centersTopCircles[i - 1].Value,
                                                                               centersTopCircles[i - 1].Key, true);
                    var vectorCommonTangent        = tangentPoints.Value - tangentPoints.Key;
                    var vectorCommonTangentOrt     = vectorCommonTangent / vectorCommonTangent.abs();
                    var vectorTranslationTopCircle = vectorCommonTangentOrt * (new Complex(0, 1.0));

                    var dL = new Line2d(tangentPoints.Value, tangentPoints.Value + vectorTranslationTopCircle * 100);
                    var rightVerticalEdge = new Line2d(botRightPoint, topRightPoint);
                    var dist            = (tangentPoints.Value - dL.IntersectWitch(rightVerticalEdge)).abs();
                    var radiusTopCircle = (dist / (segmentsCount - i + 0.5)) / 2.0;

                    var hlpLine = new Line2d(tangentPoints.Key - vectorTranslationTopCircle * radiusTopCircle,
                                             tangentPoints.Value - vectorTranslationTopCircle * radiusTopCircle);
                    var offsetTopEdgeOnRadiusTopCircle = new Line2d(
                        topLeftPoint - vectorNormalOfTopEdge * radiusTopCircle,
                        topRightPoint - vectorNormalOfTopEdge * radiusTopCircle);
                    centersTopCircles.Add(new KeyValuePair <double, Complex>(radiusTopCircle,
                                                                             offsetTopEdgeOnRadiusTopCircle
                                                                             .IntersectWitch(hlpLine)));
                }
            }

            #endregion

            #region calculatePointsForPolylineInsulation
            var insulationPolyline = new Polyline();
            insulationPolyline.SetDatabaseDefaults();
            insulationPolyline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
            var firstPairTangentPoints = GetTangentPointsOfCommonInternalTanget(centersBotCircles[0],
                                                                                radiusBotCircle,
                                                                                centersTopCircles[0].Value,
                                                                                centersTopCircles[0].Key, false);
            var ang = ((firstPairTangentPoints.Key - centersBotCircles[0]) / -centersBotCircles[0]).arg();
            insulationPolyline.AddVertexAt(0,
                                           new Point2d(firstPairTangentPoints.Key.real(),
                                                       firstPairTangentPoints.Key.imag()), -Math.Tan(ang / 4), 0, 0);
            insulationPolyline.AddVertexAt(0,
                                           new Point2d(firstPairTangentPoints.Value.real(),
                                                       firstPairTangentPoints.Value.imag()), 0, 0, 0);
            var secondPairTangentPoints = GetTangentPointsOfCommonInternalTanget(centersBotCircles[1],
                                                                                 radiusBotCircle,
                                                                                 centersTopCircles[0].Value,
                                                                                 centersTopCircles[0].Key, true);
            ang =
                ((centersTopCircles[0].Value - firstPairTangentPoints.Value) /
                 (centersTopCircles[0].Value - secondPairTangentPoints.Value)).arg();
            insulationPolyline.AddVertexAt(0,
                                           new Point2d(secondPairTangentPoints.Value.real(),
                                                       secondPairTangentPoints.Value.imag()), Math.Tan(ang / 4), 0,
                                           0);
            insulationPolyline.AddVertexAt(0,
                                           new Point2d(secondPairTangentPoints.Key.real(),
                                                       secondPairTangentPoints.Key.imag()), 0, 0, 0);
            var oldPair = secondPairTangentPoints;
            for (var i = 1; i < segmentsCount; i++)
            {
                var pairBotRightTopLeft = GetTangentPointsOfCommonInternalTanget(centersBotCircles[i],
                                                                                 radiusBotCircle,
                                                                                 centersTopCircles[i].Value,
                                                                                 centersTopCircles[i].Key,
                                                                                 false);
                var pairTopRightBotLeft = GetTangentPointsOfCommonInternalTanget(centersBotCircles[i + 1],
                                                                                 radiusBotCircle,
                                                                                 centersTopCircles[i].Value,
                                                                                 centersTopCircles[i].Key,
                                                                                 true);
                ang = ((pairBotRightTopLeft.Key - centersBotCircles[i]) / (oldPair.Key - centersBotCircles[i])).arg();
                insulationPolyline.AddVertexAt(0,
                                               new Point2d(pairBotRightTopLeft.Key.real(),
                                                           pairBotRightTopLeft.Key.imag()),
                                               -Math.Tan(ang / 4), 0, 0);
                insulationPolyline.AddVertexAt(0,
                                               new Point2d(pairBotRightTopLeft.Value.real(),
                                                           pairBotRightTopLeft.Value.imag()), 0, 0, 0);

                ang =
                    ((centersTopCircles[i].Value - pairBotRightTopLeft.Value) /
                     (centersTopCircles[i].Value - pairTopRightBotLeft.Value)).arg();
                insulationPolyline.AddVertexAt(0,
                                               new Point2d(pairTopRightBotLeft.Value.real(),
                                                           pairTopRightBotLeft.Value.imag()),
                                               Math.Tan(ang / 4), 0, 0);
                insulationPolyline.AddVertexAt(0,
                                               new Point2d(pairTopRightBotLeft.Key.real(),
                                                           pairTopRightBotLeft.Key.imag()), 0, 0, 0);
                oldPair = pairTopRightBotLeft;
            }
            var lastPairTangentPoints = GetTangentPointsOfCommonInternalTanget(centersBotCircles[segmentsCount],
                                                                               radiusBotCircle,
                                                                               centersTopCircles[segmentsCount]
                                                                               .Value,
                                                                               centersTopCircles[segmentsCount].Key,
                                                                               false);
            ang =
                ((lastPairTangentPoints.Key - centersBotCircles[segmentsCount]) /
                 (oldPair.Key - centersBotCircles[segmentsCount])).arg();
            insulationPolyline.AddVertexAt(0,
                                           new Point2d(lastPairTangentPoints.Key.real(),
                                                       lastPairTangentPoints.Key.imag()), -Math.Tan(ang / 4), 0, 0);
            insulationPolyline.AddVertexAt(0,
                                           new Point2d(lastPairTangentPoints.Value.real(),
                                                       lastPairTangentPoints.Value.imag()), 0, 0, 0);

            var hlpPointForLastBulge = new Complex(centersTopCircles[segmentsCount].Value.real(),
                                                   centersTopCircles[segmentsCount].Value.imag() +
                                                   centersTopCircles[segmentsCount].Key);
            ang =
                ((centersTopCircles[segmentsCount].Value - lastPairTangentPoints.Value) /
                 (centersTopCircles[segmentsCount].Value - hlpPointForLastBulge)).arg();
            insulationPolyline.AddVertexAt(0, new Point2d(hlpPointForLastBulge.real(), hlpPointForLastBulge.imag()),
                                           Math.Tan(ang / 4), 0, 0);

            #endregion

            #region add contur to poly

            insulationPolyline.AddVertexAt(0, new Point2d(topRightPoint.real(), hlpPointForLastBulge.imag()), 0, 0,
                                           0);
            insulationPolyline.AddVertexAt(0, new Point2d(botRightPoint.real(), botRightPoint.imag()), 0, 0, 0);
            insulationPolyline.AddVertexAt(0, new Point2d(botLeftPoint.real(), botLeftPoint.imag()), 0, 0, 0);
            insulationPolyline.AddVertexAt(0, new Point2d(topLeftPoint.real(), topLeftPoint.imag()), 0, 0, 0);
            insulationPolyline.AddVertexAt(0, new Point2d(topRightPoint.real(), topRightPoint.imag()), 0, 0, 0);
            insulationPolyline.AddVertexAt(0, new Point2d(topRightPoint.real(), hlpPointForLastBulge.imag()), 0, 0,
                                           0);

            #endregion

            #region transforms

            if (thicknessAtFirstPointResult.Value > thicknessAtSecondPointResult.Value)
            {
                var acPtFrom = new Point3d(botRightPoint.x / 2, botRightPoint.y / 2, 0);
                var acPtTo   = new Point3d(botRightPoint.x / 2, 100, 0);
                var acLine3d = new Line3d(acPtFrom, acPtTo);
                insulationPolyline.TransformBy(Matrix3d.Mirroring(acLine3d));
            }
            insulationPolyline.TransformBy(Matrix3d.Rotation(vectorOfBaseLine.arg(), new Vector3d(0, 0, 1),
                                                             Point3d.Origin));
            insulationPolyline.TransformBy(Matrix3d.Displacement(Point3d.Origin.GetVectorTo(firstPointResult.Value)));
            insulationPolyline.TransformBy(_editorHelper.CurrentUcs);

            #endregion

            var oldLayer =
                Application.DocumentManager.MdiActiveDocument.Editor.Document
                .Database.Clayer;
            _documentHelper.LayerManipulator.CreateLayer("3-0", System.Drawing.Color.Lime);

            var softInsulationBlock = new BlockTableRecord();
            var nameSalt            = DateTime.Now.GetHashCode().ToString();
            softInsulationBlock.Name   = "SoftInsulation_" + nameSalt;
            softInsulationBlock.Origin = firstPointResult.Value;

            insulationPolyline.Layer = "0";

            #region addObjectsToDataBase
            using (var acTrans = _documentHelper.TransactionManager.StartTransaction())
            {
                var blockTable =
                    acTrans.GetObject(
                        Application.DocumentManager.MdiActiveDocument.Editor
                        .Document.Database.BlockTableId, OpenMode.ForWrite) as BlockTable;

                blockTable.Add(softInsulationBlock);
                acTrans.AddNewlyCreatedDBObject(softInsulationBlock, true);

                softInsulationBlock.AppendEntity(insulationPolyline);
                acTrans.AddNewlyCreatedDBObject(insulationPolyline, true);

                var rigidInsulationRef = new BlockReference(firstPointResult.Value,
                                                            softInsulationBlock.ObjectId)
                {
                    Layer = "3-0"
                };
                var currentSpace =
                    (BlockTableRecord)
                    acTrans.GetObject(
                        Application.DocumentManager.MdiActiveDocument.Editor
                        .Document.Database.CurrentSpaceId, OpenMode.ForWrite);

                currentSpace.AppendEntity(rigidInsulationRef);
                acTrans.AddNewlyCreatedDBObject(rigidInsulationRef, true);
                acTrans.Commit();
            }
            #endregion

            _documentHelper.LayerManipulator.ChangeLayer(oldLayer);
        }