Example #1
0
        public void WriteDxfDocument()
        {
            string file = "bin3.dxf";

            // by default it will create an AutoCad2000 DXF version
            DxfDocument dxf = new DxfDocument();

            // a rectangular wipeout defined by its bottom-left corner and its width and height
            Wipeout wipeout = new Wipeout(0, 0, Bin.Width, Bin.Height);

            dxf.AddEntity(wipeout);

            if (Bin.NestedItems.Count >= 1)
            {
                foreach (Item nestedItem in Bin.NestedItems)
                {
                    wipeout = new Wipeout(nestedItem.BLpPosition, nestedItem.BLqPosition, nestedItem.Width, nestedItem.Height);
                    dxf.AddEntity(wipeout);
                }

                // save to file
                dxf.Save(file);
            }

            // this check is optional but recommended before loading a DXF file
            DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file);

            // netDxf is only compatible with AutoCad2000 and higher DXF version
            if (dxfVersion < DxfVersion.AutoCad2000)
            {
                return;
            }
            // load file
            DxfDocument loaded = DxfDocument.Load(file);
        }
Example #2
0
        /// <summary>
        /// Возвращает маскировку, созданную по контуру с указанным отступом
        /// </summary>
        /// <param name="extents3d">Крайние границы</param>
        /// <param name="offset">Отступ</param>
        private static Wipeout GetBackgroundMask(Extents3d extents3d, double offset)
        {
            try
            {
                var minPoint         = extents3d.MinPoint;
                var maxPoint         = extents3d.MaxPoint;
                var bottomLeftPoint  = new Point2d(minPoint.X - offset, minPoint.Y - offset);
                var topLeftPoint     = new Point2d(minPoint.X - offset, maxPoint.Y + offset);
                var topRightPoint    = new Point2d(maxPoint.X + offset, maxPoint.Y + offset);
                var bottomRightPoint = new Point2d(maxPoint.X + offset, minPoint.Y - offset);

                var wipeout = new Wipeout();
                wipeout.SetFrom(
                    new Point2dCollection
                {
                    bottomLeftPoint, topLeftPoint, topRightPoint, bottomRightPoint, bottomLeftPoint
                }, Vector3d.ZAxis);
                return(wipeout);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                if (ex.Message == "eNullExtents")
                {
                    return(null);
                }

                throw;
            }
        }
Example #3
0
		/*Draw Wipeout*/
		public static void DrawWipeout(Wipeout xPoly, Canvas mainCanvas)
		{
			System.Windows.Shapes.Polygon wPoly = new System.Windows.Shapes.Polygon();

			foreach (netDxf.Vector2 xVertex in xPoly.ClippingBoundary.Vertexes) {
				System.Windows.Point myPt = TypeConverter.Vertex2ToPoint(xVertex);
				getMaxPt(myPt);
				myPt.Y = mainCanvas.Height - myPt.Y;
				wPoly.Points.Add(myPt);
			}
			TypeConverter.Entity2Shape(xPoly, wPoly);
			wPoly.Fill = new SolidColorBrush(DXF2WPF.Window_bgColor);
			mainCanvas.Children.Add(wPoly);
		}
Example #4
0
        /// <summary>
        /// metodo per scrivere un file dxf a partire
        /// dalle sequenze di bin generate da hsolve
        /// </summary>
        /// <param name="sequences"></param>
        /// <param name="fileName"></param>
        public void WriteAllData(IList <Sequence> sequences, string fileName)
        {
            string      file          = fileName + ".dxf";
            DxfDocument dxf           = new DxfDocument();
            TextStyle   style         = new TextStyle("MyStyle", "Helvetica", FontStyle.Italic | FontStyle.Bold);
            int         offsetX       = 0;
            int         sequenceIndex = 1;

            foreach (var sequence in sequences)
            {
                MText title = new MText("ITERAZIONE N° " + sequenceIndex)
                {
                    Position = new Vector3(0 + offsetX, 1800, 0.0),
                    Height   = 70,
                    Style    = style
                };
                dxf.AddEntity(title);
                foreach (var bin in sequence.Bins)
                {
                    if (bin.PricedItems != null)
                    {
                        //un wipeout rettangolare che contiene tutte le altre forme


                        Wipeout wipeout = new Wipeout(0 + offsetX, 0, sequence.Bins.ElementAt(0).Width, sequence.Bins.ElementAt(0).Height);
                        dxf.AddEntity(wipeout);
                        foreach (var pricedItem in bin.PricedItems)
                        {
                            //un wipeout rettangolare che rappresenta una forma
                            wipeout = new Wipeout(pricedItem.BLpPosition + offsetX, pricedItem.BLqPosition, pricedItem.Width, pricedItem.Height);

                            //un id progressivo per il wipeout rettangolare
                            MText text = new MText(pricedItem.Id.ToString())
                            {
                                Position = new Vector3(pricedItem.BLpPosition + 30 + offsetX, pricedItem.BLqPosition + 45, 0.0),
                                Height   = 30,
                                Style    = style
                            };
                            dxf.AddEntity(wipeout);
                            dxf.AddEntity(text);
                        }
                        offsetX += 4000;
                    }
                }
                offsetX       += 3000;
                sequenceIndex += 99;
            }
            dxf.Save(file);
        }
Example #5
0
        public void WriteDxfDocument()
        {
            string file = "binRectangularItems.dxf";

            //// by default it will create an AutoCad2000 DXF version
            DxfDocument dxf = new DxfDocument();

            //un wipeout rettangolare che contiene tutte le altre forme
            Wipeout wipeout = new Wipeout(0, 0, Bin.Width, Bin.Height);

            dxf.AddEntity(wipeout);

            TextStyle style = new TextStyle("MyStyle", "Helvetica", FontStyle.Italic | FontStyle.Bold);

            if (Bin.NestedItems.Count >= 1)
            {
                foreach (var nestedItem in Bin.NestedItems)
                {
                    //un wipeout rettangolare che rapprsenta una forma
                    wipeout = new Wipeout(nestedItem.BLpPosition, nestedItem.BLqPosition, nestedItem.Width, nestedItem.Height);
                    //un id progressivo per il wipeout rettangolare
                    MText text = new MText(nestedItem.Id.ToString())
                    {
                        Position = new Vector3(nestedItem.BLpPosition + 0.3, nestedItem.BLqPosition + 0.5, 0.0),
                        Height   = 0.2,
                        Style    = style
                    };
                    dxf.AddEntity(wipeout);
                    dxf.AddEntity(text);
                }

                // save to file
                dxf.Save(file);
            }

            //// this check is optional but recommended before loading a DXF file
            DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file);

            //// netDxf is only compatible with AutoCad2000 and higher DXF version
            if (dxfVersion < DxfVersion.AutoCad2000)
            {
                return;
            }
            //// load file
            DxfDocument loaded = DxfDocument.Load(file);
        }
Example #6
0
        /// <summary>
        /// metodo per scrivere un file dxf a partire
        /// dalle sequenze di bin generate da hsolve
        /// </summary>
        /// <param name="sequences"></param>
        /// <param name="fileName"></param>
        public void WriteAllData(IList <Sequence> sequences, string fileName)
        {
            string      file    = fileName + ".dxf";
            DxfDocument dxf     = new DxfDocument();
            TextStyle   style   = new TextStyle("MyStyle", "Helvetica", FontStyle.Italic | FontStyle.Bold);
            int         offsetX = 0;
            int         offsetY = 0;

            foreach (var sequence in sequences)
            {
                foreach (var bin in sequence.Bins)
                {
                    if (bin.NestedItems != null)
                    {
                        //un wipeout rettangolare che contiene tutte le altre forme
                        Wipeout wipeout = new Wipeout(0 + offsetX, 0 + offsetY, sequence.Bins.ElementAt(0).Width, sequence.Bins.ElementAt(0).Height);
                        dxf.AddEntity(wipeout);

                        foreach (var nestedItem in bin.NestedItems)
                        {
                            //un wipeout rettangolare che rappresenta una forma
                            wipeout = new Wipeout(nestedItem.BLpPosition + offsetX, nestedItem.BLqPosition + offsetY, nestedItem.Width, nestedItem.Height);
                            //un id progressivo per il wipeout rettangolare
                            MText text = new MText(nestedItem.Id.ToString())
                            {
                                Position = new Vector3(nestedItem.BLpPosition + 0.3 + offsetX, nestedItem.BLqPosition + 0.5 + offsetY, 0.0),
                                Height   = 0.2,
                                Style    = style
                            };
                            dxf.AddEntity(wipeout);
                            dxf.AddEntity(text);
                        }
                    }
                    offsetX += 20;
                }
                //dato che ricomincio a disegnare i bin di una nuova iterazione, riporto offsetX = 0
                offsetX = 0;
                //inoltre mi sposto in basso di 25, così ho i bin del container i+1 sotto i bin del container i
                offsetY = -25;
            }

            dxf.Save(file);
        }
Example #7
0
 Wipeout CloneWipeout(Wipeout oldEnt)
 {
     try
     {
         Wipeout newEnt = new Wipeout()
         {
             Orientation       = oldEnt.Orientation,
             Brightness        = oldEnt.Brightness,
             ImageTransparency = oldEnt.ImageTransparency,
             Rotation          = oldEnt.Rotation,
             ShowImage         = oldEnt.ShowImage
                                 //HasFrame = oldEnt.HasFrame;,
                                 //Name = oldEnt.Name,
         };
         return(newEnt);
     }
     catch (Exception ex)
     {
         Logger.log("CloneWipeout", ex.Message);
     }
     return(null);
 }
Example #8
0
        private void CreateEntities(
            Point3d insertionPoint,
            Point3d leaderPoint,
            double scale)
        {
            var secantThickness = SecantThickness * scale;
            var secantLength    = SecantLength * scale;
            var v = (leaderPoint - insertionPoint).GetNormal();

            var secantEnd = insertionPoint + (v * secantLength);

            _secantPolyline = new Polyline(2);
            _secantPolyline.AddVertexAt(0, insertionPoint.ToPoint2d(), 0.0, secantThickness, secantThickness);
            _secantPolyline.AddVertexAt(1, secantEnd.ToPoint2d(), 0.0, secantThickness, secantThickness);

            if (secantEnd.DistanceTo(leaderPoint) > 0.0)
            {
                _leaderLine = new Line(secantEnd, leaderPoint);
            }

            //// Дальше код идентичен коду в NodalLeader! Учесть при внесении изменений

            SetNodeNumberOnCreation();

            var mainTextHeight     = MainTextHeight * scale;
            var secondTextHeight   = SecondTextHeight * scale;
            var textIndent         = TextIndent * scale;
            var textVerticalOffset = TextVerticalOffset * scale;
            var shelfLedge         = ShelfLedge * scale;
            var isRight            = ShelfPosition == ShelfPosition.Right;

            var topFirstTextLength  = 0.0;
            var topSecondTextLength = 0.0;
            var bottomTextLength    = 0.0;
            var bottomTextHeight    = 0.0;

            if (!string.IsNullOrEmpty(NodeNumber))
            {
                _topFirstDbText = new DBText {
                    TextString = NodeNumber
                };
                _topFirstDbText.SetProperties(TextStyle, mainTextHeight);
                topFirstTextLength = _topFirstDbText.GetLength();
            }

            if (!string.IsNullOrEmpty(SheetNumber))
            {
                _topSecondDbText = new DBText {
                    TextString = $"({SheetNumber})"
                };
                _topSecondDbText.SetProperties(TextStyle, secondTextHeight);
                topSecondTextLength = _topSecondDbText.GetLength();
            }

            if (!string.IsNullOrEmpty(NodeAddress))
            {
                _bottomDbText = new DBText {
                    TextString = NodeAddress
                };
                _bottomDbText.SetProperties(TextStyle, secondTextHeight);
                bottomTextLength = _bottomDbText.GetLength();
                bottomTextHeight = _bottomDbText.GetHeight();
            }

            var topTextLength     = topFirstTextLength + topSecondTextLength;
            var largestTextLength = Math.Max(topTextLength, bottomTextLength);
            var shelfLength       = textIndent + largestTextLength + shelfLedge;

            if (isRight)
            {
                var nodeNumberPosition =
                    leaderPoint +
                    (Vector3d.XAxis * (shelfLength - topTextLength) / 2) +
                    (Vector3d.YAxis * textVerticalOffset);

                if (_topFirstDbText != null)
                {
                    _topFirstDbText.Position = nodeNumberPosition;
                }

                if (_topSecondDbText != null)
                {
                    _topSecondDbText.Position = nodeNumberPosition + (Vector3d.XAxis * topFirstTextLength);
                }

                if (_bottomDbText != null)
                {
                    _bottomDbText.Position = leaderPoint +
                                             (Vector3d.XAxis * (shelfLength - bottomTextLength) / 2) -
                                             (Vector3d.YAxis * (textVerticalOffset + bottomTextHeight));
                }
            }
            else
            {
                var sheetNumberEndPoint =
                    leaderPoint -
                    (Vector3d.XAxis * (shelfLength - topTextLength) / 2) +
                    (Vector3d.YAxis * textVerticalOffset);

                if (_topFirstDbText != null)
                {
                    _topFirstDbText.Position = sheetNumberEndPoint -
                                               (Vector3d.XAxis * (topSecondTextLength + topFirstTextLength));
                }

                if (_topSecondDbText != null)
                {
                    _topSecondDbText.Position = sheetNumberEndPoint -
                                                (Vector3d.XAxis * topSecondTextLength);
                }

                if (_bottomDbText != null)
                {
                    _bottomDbText.Position = leaderPoint -
                                             (Vector3d.XAxis * shelfLength) +
                                             (Vector3d.XAxis * (shelfLength - bottomTextLength) / 2) -
                                             (Vector3d.YAxis * (textVerticalOffset + bottomTextHeight));
                }
            }

            var shelfEndPoint = ShelfPosition == ShelfPosition.Right
                ? leaderPoint + (Vector3d.XAxis * shelfLength)
                : leaderPoint - (Vector3d.XAxis * shelfLength);

            if (HideTextBackground)
            {
                var offset = TextMaskOffset * scale;
                _topFirstTextMask  = _topFirstDbText.GetBackgroundMask(offset);
                _topSecondTextMask = _topSecondDbText.GetBackgroundMask(offset);
                _bottomTextMask    = _bottomDbText.GetBackgroundMask(offset);
            }

            if (IsTextAlwaysHorizontal && IsRotated)
            {
                var backRotationMatrix = GetBackRotationMatrix(leaderPoint);
                shelfEndPoint = shelfEndPoint.TransformBy(backRotationMatrix);
                _topFirstDbText?.TransformBy(backRotationMatrix);
                _topFirstTextMask?.TransformBy(backRotationMatrix);
                _topSecondDbText?.TransformBy(backRotationMatrix);
                _topSecondTextMask?.TransformBy(backRotationMatrix);
                _bottomDbText?.TransformBy(backRotationMatrix);
                _bottomTextMask?.TransformBy(backRotationMatrix);
            }

            _shelfLine = new Line(leaderPoint, shelfEndPoint);
        }
Example #9
0
        /// <summary>
        /// metodo per scrivere un file dxf a partire
        /// dalle sequenze di bin generate da hsolve
        /// </summary>
        /// <param name="sequences"></param>
        /// <param name="fileName"></param>
        public void WriteAllData(IList <Sequence> sequences, string fileName)
        {
            string      file           = fileName + ".dxf";
            DxfDocument dxf            = new DxfDocument();
            TextStyle   style          = new TextStyle("MyStyle", "Helvetica", FontStyle.Italic | FontStyle.Bold);
            int         offsetX        = 0;
            int         offsetY        = 0;
            int         offsetCriteria = 0;

            foreach (Sequence sequence in sequences)
            {
                MText criteria = null;

                foreach (string c in sequence.Criterias)
                {
                    criteria = new MText(c)
                    {
                        Position = new Vector3(-900 + offsetX + offsetCriteria, 700 + offsetY, 0.0),
                        Height   = 70,
                        Style    = style
                    };
                    dxf.AddEntity(criteria);
                    offsetCriteria += 250;
                }
                offsetCriteria = 0;


                MText title = new MText("ITERAZIONE N° " + sequence.IteratioNumber)
                {
                    Position = new Vector3(0 + offsetX, 1800 + offsetY, 0.0),
                    Height   = 70,
                    Style    = style
                };
                dxf.AddEntity(title);
                foreach (Bin <Tuple> bin in sequence.Bins)
                {
                    if (bin.NestedItems != null)
                    {
                        //un wipeout rettangolare che contiene tutte le altre forme
                        Wipeout wipeout = new Wipeout(0 + offsetX, 0 + offsetY, sequence.Bins.ElementAt(0).Width, sequence.Bins.ElementAt(0).Height);
                        dxf.AddEntity(wipeout);
                        foreach (Item pricedItem in bin.NestedItems)
                        {
                            //un wipeout rettangolare che rappresenta una forma
                            wipeout = new Wipeout(pricedItem.BLpPosition + offsetX, pricedItem.BLqPosition + offsetY, pricedItem.Width, pricedItem.Height);

                            //un id progressivo per il wipeout rettangolare
                            MText text = new MText(pricedItem.Id.ToString())
                            {
                                Position = new Vector3(pricedItem.BLpPosition + 10 + offsetX, pricedItem.BLqPosition + 45 + offsetY, 0.0),
                                Height   = 30,
                                Style    = style
                            };
                            dxf.AddEntity(wipeout);
                            dxf.AddEntity(text);
                        }
                        offsetX += 4000;
                    }
                }
                offsetY += -6000;
                offsetX  = 0;
            }
            dxf.Save(file);
        }
Example #10
0
        private void CreateEntities(
            Point3d insertionPoint,
            Point3d framePoint,
            Point3d leaderPoint,
            double scale,
            bool drawLeader)
        {
            if (FrameType == FrameType.Round)
            {
                _framePolyline = null;

                try
                {
                    var radius = framePoint.DistanceTo(insertionPoint);
                    if (double.IsNaN(radius) || double.IsInfinity(radius) || radius < 0.0)
                    {
                        radius = 5 * scale;
                    }

                    _frameCircle = new Circle
                    {
                        Center = insertionPoint,
                        Radius = radius
                    };

                    if (!drawLeader)
                    {
                        return;
                    }

                    var leaderLine = new Line(insertionPoint, leaderPoint);
                    var pts        = new Point3dCollection();
                    _frameCircle.IntersectWith(leaderLine, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero);
                    _leaderLine = pts.Count > 0 ? new Line(pts[0], leaderPoint) : leaderLine;
                }
                catch
                {
                    _frameCircle = null;
                }
            }
            else
            {
                _frameCircle = null;

                var width        = Math.Abs(framePoint.X - insertionPoint.X);
                var height       = Math.Abs(framePoint.Y - insertionPoint.Y);
                var cornerRadius = CornerRadius * scale;

                if (((width * 2) - (cornerRadius * 2)) < (1 * scale) ||
                    ((height * 2) - (cornerRadius * 2)) < (1 * scale))
                {
                    var minSize = Math.Min(width * 2, height * 2);
                    cornerRadius = (int)((minSize - (1 * scale)) / 2);
                }

                var points = new[]
                {
                    new Point2d(insertionPoint.X - width + cornerRadius, insertionPoint.Y - height),
                    new Point2d(insertionPoint.X - width, insertionPoint.Y - height + cornerRadius),
                    new Point2d(insertionPoint.X - width, insertionPoint.Y + height - cornerRadius),
                    new Point2d(insertionPoint.X - width + cornerRadius, insertionPoint.Y + height),
                    new Point2d(insertionPoint.X + width - cornerRadius, insertionPoint.Y + height),
                    new Point2d(insertionPoint.X + width, insertionPoint.Y + height - cornerRadius),
                    new Point2d(insertionPoint.X + width, insertionPoint.Y - height + cornerRadius),
                    new Point2d(insertionPoint.X + width - cornerRadius, insertionPoint.Y - height)
                };

                var bevelBulge = Math.Tan((90 / 4).DegreeToRadian());
                var bulges     = new[]
                {
                    -bevelBulge,
                    0.0,
                    -bevelBulge,
                    0.0,
                    -bevelBulge,
                    0.0,
                    -bevelBulge,
                    0.0
                };

                _framePolyline = new Polyline(points.Length);

                for (var i = 0; i < points.Length; i++)
                {
                    _framePolyline.AddVertexAt(i, points[i], bulges[i], 0.0, 0.0);
                }

                _framePolyline.Closed = true;

                if (!drawLeader)
                {
                    return;
                }

                var leaderLine = new Line(insertionPoint, leaderPoint);
                var pts        = new Point3dCollection();
                _framePolyline.IntersectWith(leaderLine, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero);
                _leaderLine = pts.Count > 0 ? new Line(pts[0], leaderPoint) : leaderLine;
            }

            // Если drawLeader == false, то дальше код не выполнится

            //// Дальше код идентичен коду в SecantNodalLeader! Учесть при внесении изменений

            SetNodeNumberOnCreation();

            var mainTextHeight     = MainTextHeight * scale;
            var secondTextHeight   = SecondTextHeight * scale;
            var textIndent         = TextIndent * scale;
            var textVerticalOffset = TextVerticalOffset * scale;
            var shelfLedge         = ShelfLedge * scale;
            var isRight            = ShelfPosition == ShelfPosition.Right;

            var topFirstTextLength  = 0.0;
            var topSecondTextLength = 0.0;
            var bottomTextLength    = 0.0;
            var bottomTextHeight    = 0.0;

            if (!string.IsNullOrEmpty(NodeNumber))
            {
                _topFirstDbText = new DBText {
                    TextString = NodeNumber
                };
                _topFirstDbText.SetProperties(TextStyle, mainTextHeight);
                topFirstTextLength = _topFirstDbText.GetLength();
            }

            if (!string.IsNullOrEmpty(SheetNumber))
            {
                _topSecondDbText = new DBText {
                    TextString = $"({SheetNumber})"
                };
                _topSecondDbText.SetProperties(TextStyle, secondTextHeight);
                topSecondTextLength = _topSecondDbText.GetLength();
            }

            if (!string.IsNullOrEmpty(NodeAddress))
            {
                _bottomDbText = new DBText {
                    TextString = NodeAddress
                };
                _bottomDbText.SetProperties(TextStyle, secondTextHeight);
                bottomTextLength = _bottomDbText.GetLength();
                bottomTextHeight = _bottomDbText.GetHeight();
            }

            var topTextLength     = topFirstTextLength + topSecondTextLength;
            var largestTextLength = Math.Max(topTextLength, bottomTextLength);
            var shelfLength       = textIndent + largestTextLength + shelfLedge;

            if (isRight)
            {
                var nodeNumberPosition =
                    leaderPoint +
                    (Vector3d.XAxis * (shelfLength - topTextLength) / 2) +
                    (Vector3d.YAxis * textVerticalOffset);

                if (_topFirstDbText != null)
                {
                    _topFirstDbText.Position = nodeNumberPosition;
                }

                if (_topSecondDbText != null)
                {
                    _topSecondDbText.Position = nodeNumberPosition + (Vector3d.XAxis * topFirstTextLength);
                }

                if (_bottomDbText != null)
                {
                    _bottomDbText.Position = leaderPoint +
                                             (Vector3d.XAxis * (shelfLength - bottomTextLength) / 2) -
                                             (Vector3d.YAxis * (textVerticalOffset + bottomTextHeight));
                }
            }
            else
            {
                var sheetNumberEndPoint =
                    leaderPoint -
                    (Vector3d.XAxis * (shelfLength - topTextLength) / 2) +
                    (Vector3d.YAxis * textVerticalOffset);

                if (_topFirstDbText != null)
                {
                    _topFirstDbText.Position = sheetNumberEndPoint -
                                               (Vector3d.XAxis * (topSecondTextLength + topFirstTextLength));
                }

                if (_topSecondDbText != null)
                {
                    _topSecondDbText.Position = sheetNumberEndPoint -
                                                (Vector3d.XAxis * topSecondTextLength);
                }

                if (_bottomDbText != null)
                {
                    _bottomDbText.Position = leaderPoint -
                                             (Vector3d.XAxis * shelfLength) +
                                             (Vector3d.XAxis * (shelfLength - bottomTextLength) / 2) -
                                             (Vector3d.YAxis * (textVerticalOffset + bottomTextHeight));
                }
            }

            var shelfEndPoint = ShelfPosition == ShelfPosition.Right
                ? leaderPoint + (Vector3d.XAxis * shelfLength)
                : leaderPoint - (Vector3d.XAxis * shelfLength);

            if (HideTextBackground)
            {
                var offset = TextMaskOffset * scale;
                _topFirstTextMask  = _topFirstDbText.GetBackgroundMask(offset);
                _topSecondTextMask = _topSecondDbText.GetBackgroundMask(offset);
                _bottomTextMask    = _bottomDbText.GetBackgroundMask(offset);
            }

            if (IsTextAlwaysHorizontal && IsRotated)
            {
                var backRotationMatrix = GetBackRotationMatrix(leaderPoint);
                shelfEndPoint = shelfEndPoint.TransformBy(backRotationMatrix);
                _topFirstDbText?.TransformBy(backRotationMatrix);
                _topFirstTextMask?.TransformBy(backRotationMatrix);
                _topSecondDbText?.TransformBy(backRotationMatrix);
                _topSecondTextMask?.TransformBy(backRotationMatrix);
                _bottomDbText?.TransformBy(backRotationMatrix);
                _bottomTextMask?.TransformBy(backRotationMatrix);
            }

            _shelfLine = new Line(leaderPoint, shelfEndPoint);
        }
Example #11
0
        addSymbolAndWipeout(Point3d pnt3d, double angleView, out ObjectId idWO, double radius, int numSides, bool addWipeOut = false)
        {
            ObjectId idSYM = ObjectId.Null;

            double            pi         = System.Math.PI;
            double            pi2        = pi * 2.0;
            double            angleBase  = 0;
            double            length     = 0;
            double            delta      = 0;
            double            scale      = Misc.getCurrAnnoScale();
            double            deltaBegin = 0;
            Point2d           pnt2dBase  = Point2d.Origin;
            Point2dCollection pnts2d     = new Point2dCollection();
            Point2d           pnt2dCen   = new Point2d(pnt3d.X, pnt3d.Y);

            delta = 2 * pi / numSides;
            idWO  = ObjectId.Null;

            switch (numSides)
            {
            case 3:
                length    = 1.33 * scale * 2 * radius;
                pnt2dBase = pnt2dCen.traverse(angleView - pi / 2, length / 4);
                pnt2dBase = pnt2dBase.traverse(angleView, length / 2);
                pnts2d.Add(pnt2dBase);
                deltaBegin = delta + angleView;
                break;

            case 4:
                angleBase = angleView + 7.0 / 8.0 * pi2;
                length    = 0.5 * 1.68 * scale * radius * System.Math.Sqrt(2);
                pnt2dBase = pnt2dCen.traverse(angleBase, length);
                pnts2d.Add(pnt2dBase);
                length     = scale * 1.68 * radius;
                deltaBegin = delta + angleView;
                break;

            case 6:
                angleBase = angleView + 10.0 / 12.0 * pi2;
                //angleBase = angleView;
                length    = 1.03 * scale * radius / System.Math.Cos(delta / 3);
                pnt2dBase = pnt2dCen.traverse(angleBase, length);
                pnts2d.Add(pnt2dBase);     //pnt0
                deltaBegin = angleBase + 2 * delta;
                break;

            case 1024:
                //angleBase = angleView + 3.0 / 2.0 * pi;
                angleBase = angleView;
                length    = scale * 2.0 * radius * System.Math.Sin(delta / 2);
                pnt2dBase = pnt2dCen.traverse(angleBase, scale * radius);
                pnts2d.Add(pnt2dBase);
                deltaBegin = angleBase + delta + pi / 2;
                break;

            default:
                break;
            }

            //adjust first segment to account for viewtwist
            pnt2dBase = pnt2dBase.traverse(deltaBegin, length);
            pnts2d.Add(pnt2dBase); //pnt1
            //pnt2dBase.addPointNode(34, 0.01);

            double deltaTotal = deltaBegin;

            //from then on it is
            for (int i = 1; i < numSides; i++)
            {
                deltaTotal = deltaTotal + delta;
                pnt2dBase  = pnt2dBase.traverse(deltaTotal, length);
                pnts2d.Add(pnt2dBase); //pnts 2-6
                //pnt2dBase.addPointNode(34, 0.01);
            }

            if (numSides < 1024)
            {
                idSYM = addPoly(pnts2d, "BUBBLE", 5);
            }
            else
            {
                idSYM = Draw.addCircle(pnt3d, scale * radius, "BUBBLE", 5);
            }

            if (addWipeOut)
            {
                Wipeout wo = new Wipeout();
                try
                {
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        BlockTableRecord ms = Blocks.getBlockTableRecordMS();
                        wo.SetFrom(pnts2d, Vector3d.ZAxis);
                        wo.Layer = "BUBBLE";
                        wo.Color = Color.FromColorIndex(ColorMethod.ByBlock, 8);
                        ms.AppendEntity(wo);
                        tr.AddNewlyCreatedDBObject(wo, true);
                        idWO = wo.ObjectId;
                        tr.Commit();
                    }
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(ex.Message + " Draw.cs: line: 804");
                }
            }

            return(idSYM);
        }
Example #12
0
        private void CreateEntities(Point3d insertionPoint, List <Point3d> middlePoints, Point3d endPoint, double scale)
        {
            var strokesWidth = StrokeWidth * scale;

            // top and bottom strokes
            var topStrokeEndPoint    = GetTopStrokeEndPoint(insertionPoint, endPoint, middlePoints, scale);
            var bottomStrokeEndPoint = GetBottomStrokeEndPoint(insertionPoint, endPoint, middlePoints, scale);

            _topStroke = new Polyline(2);
            _topStroke.AddVertexAt(0, topStrokeEndPoint.ToPoint2d(), 0.0, strokesWidth, strokesWidth);
            _topStroke.AddVertexAt(1, insertionPoint.ToPoint2d(), 0.0, strokesWidth, strokesWidth);

            _bottomStroke = new Polyline(2);
            _bottomStroke.AddVertexAt(0, endPoint.ToPoint2d(), 0.0, strokesWidth, strokesWidth);
            _bottomStroke.AddVertexAt(1, bottomStrokeEndPoint.ToPoint2d(), 0.0, strokesWidth, strokesWidth);

            var topStrokeNormalVector    = (topStrokeEndPoint - insertionPoint).GetNormal();
            var bottomStrokeNormalVector = (bottomStrokeEndPoint - endPoint).GetNormal();

            // shelf lines
            var topShelfStartPoint = insertionPoint + (topStrokeNormalVector * GetShelfOffset() * scale);
            var topShelfEndPoint   = topShelfStartPoint + (topStrokeNormalVector.GetPerpendicularVector() * ShelfLength * scale);

            TopShelfEndPoint = topShelfEndPoint.TransformBy(BlockTransform);
            _topShelfLine    = new Line
            {
                StartPoint = topShelfStartPoint,
                EndPoint   = topShelfEndPoint
            };

            var bottomShelfStartPoint = endPoint + (bottomStrokeNormalVector * GetShelfOffset() * scale);
            var bottomShelfEndPoint   = bottomShelfStartPoint + (bottomStrokeNormalVector.GetPerpendicularVector().Negate() * ShelfLength * scale);

            BottomShelfEndPoint = bottomShelfEndPoint.TransformBy(BlockTransform);
            _bottomShelfLine    = new Line
            {
                StartPoint = bottomShelfStartPoint,
                EndPoint   = bottomShelfEndPoint
            };

            // shelf arrows
            var topShelfArrowStartPoint = topShelfStartPoint + (topStrokeNormalVector.GetPerpendicularVector() * ShelfArrowLength * scale);

            _topShelfArrow = new Polyline(2);
            _topShelfArrow.AddVertexAt(0, topShelfArrowStartPoint.ToPoint2d(), 0.0, ShelfArrowWidth * scale, 0.0);
            _topShelfArrow.AddVertexAt(1, topShelfStartPoint.ToPoint2d(), 0.0, 0.0, 0.0);

            var bottomShelfArrowStartPoint =
                bottomShelfStartPoint + (bottomStrokeNormalVector.GetPerpendicularVector().Negate() * ShelfArrowLength * scale);

            _bottomShelfArrow = new Polyline(2);
            _bottomShelfArrow.AddVertexAt(0, bottomShelfArrowStartPoint.ToPoint2d(), 0.0, ShelfArrowWidth * scale, 0.0);
            _bottomShelfArrow.AddVertexAt(1, bottomShelfStartPoint.ToPoint2d(), 0.0, 0.0, 0.0);

            // text
            var textContentsForTopText    = GetTextContents(true);
            var textContentsForBottomText = GetTextContents(false);

            if (!string.IsNullOrEmpty(textContentsForTopText) && !string.IsNullOrEmpty(textContentsForBottomText))
            {
                var textStyleId = AcadUtils.GetTextStyleIdByName(TextStyle);
                var textHeight  = MainTextHeight * scale;
                _topMText = new MText
                {
                    TextStyleId = textStyleId,
                    Contents    = textContentsForTopText,
                    TextHeight  = textHeight,
                    Attachment  = AttachmentPoint.MiddleCenter
                };

                _bottomMText = new MText
                {
                    TextStyleId = textStyleId,
                    Contents    = textContentsForBottomText,
                    TextHeight  = textHeight,
                    Attachment  = AttachmentPoint.MiddleCenter
                };

                // TextActualHeight = _topMText.ActualHeight;
                // TextActualWidth = _topMText.ActualWidth;

                var check = 1 / Math.Sqrt(2);

                // top
                var alongShelfTextOffset  = _topMText.ActualWidth / 2;
                var acrossShelfTextOffset = _topMText.ActualHeight / 2;
                if (double.IsNaN(AlongTopShelfTextOffset) && double.IsNaN(AcrossTopShelfTextOffset))
                {
                    if ((topStrokeNormalVector.X > check || topStrokeNormalVector.X < -check) &&
                        (topStrokeNormalVector.Y < check || topStrokeNormalVector.Y > -check))
                    {
                        alongShelfTextOffset  = _topMText.ActualHeight / 2;
                        acrossShelfTextOffset = _topMText.ActualWidth / 2;
                    }

                    var tempPoint          = topShelfEndPoint + ((topShelfStartPoint - topShelfEndPoint).GetNormal() * alongShelfTextOffset);
                    var topTextCenterPoint = tempPoint + (topStrokeNormalVector * ((2 * scale) + acrossShelfTextOffset));
                    _topMText.Location = topTextCenterPoint;
                }
                else
                {
                    var tempPoint = topShelfEndPoint +
                                    ((topShelfStartPoint - topShelfEndPoint).GetNormal() * (AlongTopShelfTextOffset + (_topMText.ActualWidth / 2)));
                    var topTextCenterPoint = tempPoint + (topStrokeNormalVector * ((2 * scale) + (AcrossTopShelfTextOffset + (_topMText.ActualHeight / 2))));
                    _topMText.Location = topTextCenterPoint;
                }

                TopDesignationPoint = _topMText.GeometricExtents.MinPoint.TransformBy(BlockTransform);

                // bottom
                alongShelfTextOffset  = _bottomMText.ActualWidth / 2;
                acrossShelfTextOffset = _bottomMText.ActualHeight / 2;
                if (double.IsNaN(AlongBottomShelfTextOffset) && double.IsNaN(AcrossBottomShelfTextOffset))
                {
                    if ((bottomStrokeNormalVector.X > check || bottomStrokeNormalVector.X < -check) &&
                        (bottomStrokeNormalVector.Y < check || bottomStrokeNormalVector.Y > -check))
                    {
                        alongShelfTextOffset  = _topMText.ActualHeight / 2;
                        acrossShelfTextOffset = _topMText.ActualWidth / 2;
                    }

                    var tempPoint             = bottomShelfEndPoint + ((bottomShelfStartPoint - bottomShelfEndPoint).GetNormal() * alongShelfTextOffset);
                    var bottomTextCenterPoint = tempPoint + (bottomStrokeNormalVector * ((2 * scale) + acrossShelfTextOffset));
                    _bottomMText.Location = bottomTextCenterPoint;
                }
                else
                {
                    var tempPoint = bottomShelfEndPoint + ((bottomShelfStartPoint - bottomShelfEndPoint).GetNormal() *
                                                           (AlongBottomShelfTextOffset + (_bottomMText.ActualWidth / 2)));
                    var bottomTextCenterPoint =
                        tempPoint + (bottomStrokeNormalVector * ((2 * scale) + (AcrossBottomShelfTextOffset + (_bottomMText.ActualHeight / 2))));
                    _bottomMText.Location = bottomTextCenterPoint;
                }

                BottomDesignationPoint = _bottomMText.GeometricExtents.MinPoint.TransformBy(BlockTransform);

                if (HideTextBackground)
                {
                    var maskOffset = TextMaskOffset * scale;
                    _topTextMask    = _topMText.GetBackgroundMask(maskOffset);
                    _bottomTextMask = _bottomMText.GetBackgroundMask(maskOffset);
                }
            }

            _middleStrokes.Clear();

            // middle strokes
            if (MiddlePoints.Any())
            {
                var middleStrokeLength = MiddleStrokeLength * scale;

                var points = new List <Point3d> {
                    insertionPoint
                };
                points.AddRange(middlePoints);
                points.Add(endPoint);

                for (var i = 1; i < points.Count - 1; i++)
                {
                    var previousPoint = points[i - 1];
                    var currentPoint  = points[i];
                    var nextPoint     = points[i + 1];

                    var middleStrokePolyline = new Polyline(3);
                    middleStrokePolyline.AddVertexAt(
                        0,
                        (currentPoint + ((previousPoint - currentPoint).GetNormal() * middleStrokeLength)).ToPoint2d(),
                        0, strokesWidth, strokesWidth);
                    middleStrokePolyline.AddVertexAt(1, currentPoint.ToPoint2d(), 0, strokesWidth, strokesWidth);
                    middleStrokePolyline.AddVertexAt(
                        2,
                        (currentPoint + ((nextPoint - currentPoint).GetNormal() * middleStrokeLength)).ToPoint2d(),
                        0, strokesWidth, strokesWidth);

                    _middleStrokes.Add(middleStrokePolyline);
                }
            }
        }