Ejemplo n.º 1
0
 /// <summary>
 /// Create instance of <see cref="SoundedData"/>.
 /// </summary>
 /// <param name="data">Sounded data.</param>
 /// <param name="channelType"><see cref="Frame.ChannelType"/>.</param>
 /// <param name="upperLimit"><see cref="UpperLimit"/>.</param>
 /// <param name="lowerLimit"><see cref="LowerLimit"/>.</param>
 public SoundedData(byte[] data, ChannelType channelType, LinearDimension upperLimit, LinearDimension lowerLimit)
 {
     Data        = data;
     ChannelType = channelType;
     UpperLimit  = upperLimit;
     LowerLimit  = lowerLimit;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置拖拉预览
        /// </summary>
        /// <param name="ld"></param>
        private void SetDimFeatuer(LinearDimension ld, int row, ref double[] offset)
        {
            double temp = UMathUtils.GetDis(ld.HandleOrigin, superBox.CenterPt);     //判断拖拉是否超过边界

            if (Math.Abs(ld.Value) >= 2 * temp && ld.Value < 0)
            {
                return;
            }
            if (boolOffset.Value)
            {
                SetDimSame(ld.Value, ref offset);
                dimOffset.Value = ld.Value;
                negativeX.Value = ld.Value;
                negativeY.Value = ld.Value;
                negativeZ.Value = ld.Value;

                positiveX.Value = ld.Value;
                positiveX.Value = ld.Value;
                positiveZ.Value = ld.Value;
            }
            else
            {
                offset[row] = ld.Value;
            }
            superBox.Update(matr, offset);
        }
 public override void SetDimForFace(ref LinearDimension ld, Vector3d vec)
 {
     foreach (Face face in this.ToolingBox.GetBodies()[0].GetFaces())
     {
         if (face.SolidFaceType == Face.FaceType.Cylindrical)
         {
             Point3d  originPt = new Point3d(0, 0, 0);
             Vector3d normal   = new Vector3d(0, 0, 0);
             FaceUtils.AskFaceOriginAndNormal(face, out originPt, out normal);
             double angle1 = UMathUtils.Angle(vec, new Vector3d(1, 1, 1));
             if (UMathUtils.IsEqual(angle1, 0))
             {
                 ld.HandleOrientation = normal;
                 ld.HandleOrigin      = originPt;
             }
         }
         else
         {
             FaceData fd   = FaceUtils.AskFaceData(face);
             Vector3d temp = fd.Dir;
             this.Matr.ApplyVec(ref temp);
             double angle = UMathUtils.Angle(vec, temp);
             if (UMathUtils.IsEqual(angle, 0))
             {
                 ld.HandleOrientation = fd.Dir;
                 ld.HandleOrigin      = fd.Point;
             }
         }
     }
 }
Ejemplo n.º 4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var style = doc.DimStyles.Current;
            var plane = Plane.WorldXY;

            var p1 = new Point3d(1.0, 1.0, 0.0);
            var p2 = new Point3d(5.0, 2.0, 0.0);
            var pl = new Point3d(5.0, 4.0, 0.0);

            var xaxis = p2 - p1;
            var yaxis = pl - p1;

            if (xaxis.Unitize() && yaxis.Unitize())
            {
                var zaxis = Vector3d.CrossProduct(xaxis, yaxis);
                if (zaxis.Unitize())
                {
                    plane = new Plane(p1, xaxis, yaxis);
                }
            }

            var dim = LinearDimension.Create(AnnotationType.Aligned, style, plane, Plane.WorldXY.XAxis, p1, p2, pl, 0.0);

            //string displaytext = dim.GetDistanceDisplayText(doc.ModelUnitSystem, style);

            doc.Objects.Add(dim);

            doc.Views.Redraw();
            return(Result.Success);
        }
    public static Rhino.Commands.Result AddLinearDimension2(Rhino.RhinoDoc doc)
    {
        Point3d origin = new Point3d(1, 1, 0);
        Point3d offset = new Point3d(11, 1, 0);
        Point3d pt     = new Point3d((offset.X - origin.X) / 2, 3, 0);

        Plane plane = Plane.WorldXY;

        plane.Origin = origin;

        double u, v;

        plane.ClosestParameter(origin, out u, out v);
        Point2d ext1 = new Point2d(u, v);

        plane.ClosestParameter(offset, out u, out v);
        Point2d ext2 = new Point2d(u, v);

        plane.ClosestParameter(pt, out u, out v);
        Point2d linePt = new Point2d(u, v);

        LinearDimension dimension = new LinearDimension(plane, ext1, ext2, linePt);

        if (doc.Objects.AddLinearDimension(dimension) != Guid.Empty)
        {
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
Ejemplo n.º 6
0
        internal override void UpdateAnnotations()
        {
            Annotations = new AnnotationBase[3];

            var lengthDim = new LinearDimension();

            lengthDim.Plane              = Plane;
            lengthDim.Prefix             = "Length ";
            lengthDim.DimensionLinePoint = new Point2d(0, -Settings.AnnotationOffset);
            lengthDim.ExtensionLine1End  = new Point2d(0, 0);
            lengthDim.ExtensionLine2End  = new Point2d(Length, 0);
            Annotations[0] = lengthDim;

            var widthDim = new LinearDimension();

            widthDim.Plane              = new Plane(Plane.Origin, Plane.YAxis, -Plane.XAxis);
            widthDim.Prefix             = "Width ";
            widthDim.DimensionLinePoint = new Point2d(0, Settings.AnnotationOffset);
            widthDim.ExtensionLine1End  = new Point2d(0, 0);
            widthDim.ExtensionLine2End  = new Point2d(Width, 0);
            Annotations[1]              = widthDim;

            var heightDim = new LinearDimension();

            heightDim.Plane              = new Plane(Plane.Origin, Vector3d.CrossProduct(Plane.XAxis, Plane.YAxis), Plane.XAxis);
            heightDim.Prefix             = "Height ";
            heightDim.DimensionLinePoint = new Point2d(0, Settings.AnnotationOffset);
            heightDim.ExtensionLine1End  = new Point2d(0, 0);
            heightDim.ExtensionLine2End  = new Point2d(Height, 0);
            Annotations[2] = heightDim;
        }
Ejemplo n.º 7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            UsefulFunctions.XSelectCurves("Select curves for linear dimensioning", out CurveList curves);

            //var lines = new RhinoList<Line>();

            //for (var i = 0; i < curves.Count; i++)
            //{
            //    lines.Add(new Line(curves[i].PointAtStart, curves[i].PointAtEnd));
            //}



            //get the user to select a point

            var gp = new GetPoint();

            string prompt;

            prompt = "Pick a point";

            gp.SetCommandPrompt(prompt);


            gp.Get();

            Point3d pt = gp.Point();

            foreach (var curve in curves)
            {
                Point3d origin = curve.PointAtStart;
                Point3d offset = curve.PointAtEnd;

                //Vector3d linevec = new Vector3d(offset - origin);

                // you can rotate vector so its perp. with the line...


                Plane plane = Plane.WorldXY;

                plane.Origin = origin;

                double u, v;
                plane.ClosestParameter(origin, out u, out v);
                Point2d ext1 = new Point2d(u, v);

                plane.ClosestParameter(offset, out u, out v);
                Point2d ext2 = new Point2d(u, v);

                plane.ClosestParameter(pt, out u, out v);
                Point2d linePt = new Point2d(u, v);

                LinearDimension lindim = new LinearDimension(plane, ext1, ext2, linePt);

                doc.Objects.AddLinearDimension(lindim);
            }

            return(Result.Success);
        }
Ejemplo n.º 8
0
        public void LinearDimensionEqualTest()
        {
            var depth1 = new LinearDimension(43.81234123, LinearDimensionUnit.Foot);
            var depth2 = new LinearDimension(depth1.GetMeters(), LinearDimensionUnit.Meter);

            Assert.AreEqual(depth1, depth2);
            Assert.IsTrue(depth1 == depth2);
        }
Ejemplo n.º 9
0
        public void LinearDimensionOperationsTest()
        {
            var depth1 = new LinearDimension(43.81, LinearDimensionUnit.Foot);
            var depth2 = new LinearDimension(12.34, LinearDimensionUnit.Meter);
            var depth3 = new LinearDimension(depth1.GetMeters() + depth2.GetMeters(), LinearDimensionUnit.Meter);

            Assert.IsTrue(depth1 > depth2);
            Assert.IsTrue(depth2 < depth1);
            Assert.IsTrue(depth3 == depth1 + depth2);
        }
Ejemplo n.º 10
0
        public void LinearDimensionCreationTest()
        {
            //45 foots == 13.716 meters
            var depth1 = new LinearDimension(45, LinearDimensionUnit.Foot);

            Assert.AreEqual(13.716, depth1.GetMeters(), 0.001);

            //20 meters == 65.61679 meters
            var depth2 = new LinearDimension(20, LinearDimensionUnit.Meter);

            Assert.AreEqual(65.61679, depth2.GetFoots(), 0.001);
        }
Ejemplo n.º 11
0
 public override void SetDimForFace(ref LinearDimension ld, Vector3d vec)
 {
     foreach (Face face in this.ToolingBox.GetBodies()[0].GetFaces())
     {
         FaceData fd   = FaceUtils.AskFaceData(face);
         Vector3d temp = fd.Dir;
         this.Matr.ApplyVec(ref temp);
         double angle = UMathUtils.Angle(vec, temp);
         if (UMathUtils.IsEqual(angle, 0))
         {
             ld.HandleOrientation = fd.Dir;
             ld.HandleOrigin      = fd.Point;
         }
     }
 }
Ejemplo n.º 12
0
        public void CreateDimss(BoxCulvertSection bs)
        {
            var p1 = Shopdrawing.Core.Utilities.PointsHelper.Offset(bs.BasePoint.Coordinates, 0, bs.H / 2);
            var p2 = Shopdrawing.Core.Utilities.PointsHelper.Offset(p1, bs.B, 0);

            d1 = new LinearDimension(Drawing, p1, p2, p1);
            //Dims.Add(dim);
            d1.Dimpost  = "B=";
            d1.Dimscale = this.DimScale;
            this.Children.Add(d1);
            this.Dependencies.Add(d1);
            d1.OnAddingToCanvas(Drawing.Canvas);
            d1.UpdateVisual();
            Dims.Add(d1);
        }
Ejemplo n.º 13
0
        internal override void UpdateAnnotations()
        {
            if (Annotations is null)
            {
                Annotations = new AnnotationBase[1];
            }

            var dim = new LinearDimension();

            dim.Plane              = Plane;
            dim.Prefix             = "Radius ";
            dim.DimensionLinePoint = new Point2d(0, 0);
            dim.ExtensionLine1End  = new Point2d(0, 0);
            dim.ExtensionLine2End  = new Point2d(Radius, 0);

            Annotations[0] = dim;
        }
Ejemplo n.º 14
0
        public static List <Guid> drawDimension(Plane plane, Point3d pt, Point3d offset, Point3d origin, List <Guid> guidList, RhinoDoc doc)
        {
            double u, v;

            plane.ClosestParameter(origin, out u, out v);
            Point2d ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            Point2d ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            Point2d linePt = new Point2d(u, v);

            LinearDimension dimension = new LinearDimension(plane, ext1, ext2, linePt);
            Guid            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);
            return(guidList);
        }
Ejemplo n.º 15
0
        public DxfDocument DrawEnd()
        {
            Vector2[] points =
            {
                new Vector2(-50,                                             -this._SupportHeight),
                new Vector2(-50,                              Beam.I.Height + this._SupportHeight),
                new Vector2(-50,                              Beam.I.Height),
                new Vector2(-50 - this.RightSupportWidth / 2, Beam.I.Height),
                new Vector2(-50 - this.RightSupportWidth,                                       0),
                new Vector2(-50,                                                                0),
            };

            if (this.RightSupportType == "A")
            {
                Beam.I.Dxf.AddEntity(new Line(
                                         points[0],
                                         points[1]));
            }
            else if (this.RightSupportType == "B")
            {
                Beam.I.Dxf.AddEntity(new Line(
                                         points[0],
                                         points[2]));
                Beam.I.Dxf.AddEntity(new Line(
                                         points[2],
                                         points[3]));
            }

            if (this.RightSupportType != "C")
            {
                LinearDimension dim45 = new LinearDimension(
                    points[4],
                    points[5],
                    -20,
                    0,
                    Beam.I.DimensionStyles.General);
                dim45.UserText = "<>";
                Beam.I.Dxf.AddEntity(dim45);
            }
            return(Beam.I.Dxf);
        }
Ejemplo n.º 16
0
        internal override void UpdateAnnotations()
        {
            Annotations = new AnnotationBase[2];

            var widthDim = new LinearDimension();

            widthDim.Plane              = Plane;
            widthDim.Prefix             = "Width ";
            widthDim.DimensionLinePoint = new Point2d(0, -Settings.AnnotationOffset);
            widthDim.ExtensionLine1End  = new Point2d(0, 0);
            widthDim.ExtensionLine2End  = new Point2d(Width, 0);
            Annotations[0]              = widthDim;

            var heightDim = new LinearDimension();

            heightDim.Plane              = new Plane(Plane.Origin, Plane.YAxis, -Plane.XAxis);
            heightDim.Prefix             = "Height ";
            heightDim.DimensionLinePoint = new Point2d(0, -Width - Settings.AnnotationOffset);
            heightDim.ExtensionLine1End  = new Point2d(0, -Width);
            heightDim.ExtensionLine2End  = new Point2d(Height, -Width);
            Annotations[1] = heightDim;
        }
Ejemplo n.º 17
0
        private static byte[] GetArrayForNoiseAndBottomSurfaces(short packetSize, LinearDimension depth,
                                                                LinearDimension upperLimit, LinearDimension lowerLimit)
        {
            //calc packet size for all the water column (from water surface to lower limit)
            var allTheWaterColumnPacketSize = (uint)Math.Ceiling(lowerLimit * packetSize / (lowerLimit - upperLimit));

            //create byte array for all the column
            var allTheWaterColumnBytesArray = new byte[allTheWaterColumnPacketSize];

            //and fill it with patterns for water surface noises and bottom surface
            // lets water surface noises always has 0.5 meter depth. then one meter packet size is
            var oneMeterPacketSize = (uint)(allTheWaterColumnPacketSize / lowerLimit.GetMeters());

            //then noise array is
            var noiseArray = GetDecreasingByteSurface(oneMeterPacketSize);

            //copy noise array to begin of allTheWaterColumnBytesArray
            noiseArray.CopyTo(allTheWaterColumnBytesArray, 0);

            //lets fill by bottom surface all the place beyond depth and lower limit
            if (depth < lowerLimit)
            {
                //calc bottom surface packet size
                var bottomSurfacePacketSize = (uint)((lowerLimit - depth) * allTheWaterColumnPacketSize / lowerLimit);

                //then bottom array is
                var bottomArray = GetDecreasingByteSurface(bottomSurfacePacketSize);

                //and copy bottom array to the end of allTheWaterColumnBytesArray
                bottomArray.CopyTo(allTheWaterColumnBytesArray, allTheWaterColumnPacketSize - bottomSurfacePacketSize);
            }

            //finally cut allTheWaterColumnBytesArray to array from upper to lower limit and return SoundedData
            var arrayForSoundedData = new byte[packetSize];

            allTheWaterColumnBytesArray.CopyTo(arrayForSoundedData, allTheWaterColumnPacketSize - packetSize);
            return(arrayForSoundedData);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Create instance of <see cref="CsvLogEntry" /> object from objects of <see cref="CoordinatePoint" /> add <see cref="LinearDimension" /> double value
 /// </summary>
 /// <param name="point"><see cref="CoordinatePoint" /> object.</param>
 /// <param name="depth">Depth double value</param>
 public CsvLogEntry(CoordinatePoint point, LinearDimension depth)
 {
     Point = point;
     Depth = depth;
 }
Ejemplo n.º 19
0
        public DxfDocument DrawSideView()
        {
            //alter left support
            double x0, y0;
            double x4, y4;

            if (this.LeftSupportType == "A")
            {
                x0 = this._Translation + this.LeftSupportWidth;
                y0 = -_SupportHeight;
                x4 = x0;
                y4 = Beam.I.Height + _SupportHeight;
            }
            else if (this.LeftSupportType == "B")
            {
                x0 = this._Translation + this.LeftSupportWidth;
                y0 = -_SupportHeight;
                x4 = this._Translation + this.LeftSupportWidth / 2;
                y4 = Beam.I.Height;
            }
            else
            {
                x0 = this._Translation + this.LeftSupportWidth;
                y0 = Beam.I.Height / 2;
                x4 = x0;
                y4 = Beam.I.Height / 2;
            }
            //alter right support
            double x3, y3;
            double x7, y7;

            if (this.RightSupportType == "A")
            {
                x3 = this._Translation + this.SpanLength + this.LeftSupportWidth;
                y3 = -_SupportHeight;
                x7 = x3;
                y7 = Beam.I.Height + _SupportHeight;
            }
            else if (this.RightSupportType == "B")
            {
                x3 = this._Translation + this.SpanLength + this.LeftSupportWidth;
                y3 = -_SupportHeight;
                x7 = x3 + this.RightSupportWidth / 2;
                y7 = Beam.I.Height;
            }
            else
            {
                x3 = this._Translation + this.SpanLength + this.LeftSupportWidth;
                y3 = Beam.I.Height / 2;
                x7 = x3 + this.RightSupportWidth / 2;
                y7 = Beam.I.Height / 2;
            }

            Vector2[] points =
            {
                new Vector2(x0,                                                          y0),
                new Vector2(this._Translation + this.LeftSupportWidth,                               0),
                new Vector2(this._Translation + this.LeftSupportWidth + this.SpanLength,             0),
                new Vector2(x3,                                                          y3),
                new Vector2(x4,                                                          y4),
                new Vector2(this._Translation + this.LeftSupportWidth,                   Beam.I.Height),
                new Vector2(this._Translation + this.LeftSupportWidth + this.SpanLength, Beam.I.Height),
                new Vector2(x7,                                                          y7),
                //to dimension
                new Vector2(this._Translation,                                                       0),
            };

            Beam.I.Dxf.AddEntity(new Line(
                                     points[0],
                                     points[1]));
            Beam.I.Dxf.AddEntity(new Line(
                                     points[1],
                                     points[2]));
            Beam.I.Dxf.AddEntity(new Line(
                                     points[2],
                                     points[3]));
            Beam.I.Dxf.AddEntity(new Line(
                                     points[4],
                                     points[5]));
            Beam.I.Dxf.AddEntity(new Line(
                                     points[5],
                                     points[6]));
            Beam.I.Dxf.AddEntity(new Line(
                                     points[6],
                                     points[7]));


            if (this.LeftSupportType != "C")
            {
                LinearDimension dim81 = new LinearDimension(
                    points[8],
                    points[1],
                    -20,
                    0,
                    Beam.I.DimensionStyles.General);
                dim81.UserText = "<>";
                Beam.I.Dxf.AddEntity(dim81);
            }

            LinearDimension dim12 = new LinearDimension(
                points[1],
                points[2],
                -20,
                0,
                Beam.I.DimensionStyles.General);

            dim12.UserText = "<>";
            Beam.I.Dxf.AddEntity(dim12);
            return(Beam.I.Dxf);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Create instance of <see cref="CsvLogEntry" /> object from objects of <see cref="Latitude" />, <see cref="Longitude" /> add <see cref="LinearDimension" /> double value
 /// </summary>
 /// <param name="latitude">Latitude</param>
 /// <param name="longitude">Longitude</param>
 /// <param name="depth">Depth double value</param>
 public CsvLogEntry(Latitude latitude, Longitude longitude, LinearDimension depth)
 {
     Point = new CoordinatePoint(latitude, longitude);
     Depth = depth;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 关联线性向量到体面上
 /// </summary>
 /// <param name="ld">控件</param
 /// <param name="vec">向量</param>
 public abstract void SetDimForFace(ref LinearDimension ld, Vector3d vec);
Ejemplo n.º 22
0
 public Guid AddLinearDimension(LinearDimension dimension, ObjectAttributes attributes)
 {
     throw NotSupportedExceptionHelp();
 }
Ejemplo n.º 23
0
 public Guid __InternalAdd(LinearDimension dimension)
 {
     return(AddLinearDimension(dimension));
 }
Ejemplo n.º 24
0
        /// <summary>
        /// TryParse CSV log string, consists of Latitude, Longitude, Depth(and may be other values), separated by comma
        /// </summary>
        /// <param name="cvsLogEntryString">String to parse</param>
        /// <param name="charForSplit">Char for sting split</param>
        /// <param name="depthUnit">Depth unit</param>
        /// <param name="valuesOrder">Represent order of CvsLogEntry properties in string</param>
        /// <param name="result">CvsLogEntry</param>
        /// <returns>Conversion succeeded or failed</returns>
        public static bool TryParse(string cvsLogEntryString, char charForSplit, LinearDimensionUnit depthUnit, IDictionary <int, string> valuesOrder, out CsvLogEntry result)
        {
            result = new CsvLogEntry {
                UnexpectedValues = new List <string>()
            };

            Latitude        lat    = null;
            Longitude       lon    = null;
            LinearDimension dpt    = null;
            var             values = cvsLogEntryString.Split(charForSplit);

            // if string doesn't contains values or values count less then expect return false
            if (values.Length == 0 || values.Length < valuesOrder.Count)
            {
                return(false);
            }

            for (var i = 0; i < values.Length; i++)
            {
                if (valuesOrder.ContainsKey(i))
                {
                    if (CultureInfo.InvariantCulture.CompareInfo.IndexOf(valuesOrder[i],
                                                                         "Latitude", CompareOptions.IgnoreCase) >= 0)
                    {
                        var parceresult = Latitude.TryParse(values[i], out lat);

                        if (parceresult)
                        {
                            continue;
                        }
                        return(false);
                    }

                    if (CultureInfo.InvariantCulture.CompareInfo.IndexOf(valuesOrder[i],
                                                                         "Longitude", CompareOptions.IgnoreCase) >= 0)
                    {
                        var parceresult = Longitude.TryParse(values[i], out lon);

                        if (parceresult)
                        {
                            continue;
                        }
                        return(false);
                    }

                    if (CultureInfo.InvariantCulture.CompareInfo.IndexOf(valuesOrder[i],
                                                                         "Depth", CompareOptions.IgnoreCase) >= 0)
                    {
                        var parceresult = LinearDimension.TryParse(values[i], depthUnit, out dpt);

                        if (parceresult)
                        {
                            continue;
                        }
                        return(false);
                    }
                }
                else
                {
                    result.UnexpectedValues.Add(values[i]);
                }
            }

            if (lat != null && lon != null && dpt != null)
            {
                result.Point = new CoordinatePoint(lat, lon);
                result.Depth = dpt;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 25
0
 public Guid AddLinearDimension(LinearDimension dimension)
 {
     return(AddLinearDimension(dimension, null));
 }
Ejemplo n.º 26
0
        public DxfDocument DrawRbar(int id, bool inside, double offset)
        {
            //decides where to put the rbar to avoid overlaping
            double factor, shift = Math.Max(Math.Abs(this.Y1 - this.Y0), Math.Abs(this.Y3 - this.Y2)) + 10;

            if (inside == true)
            {
                factor = 0;
            }
            else
            {
                factor = -Convert.ToInt32(id) % 2;
            }

            //checks if there are any hooks
            double shiftLeft = 0, bulgeLeft = 0, shiftRight = 0, bulgeRight = 0,
                   flipLeft = 1, flipRight = 1;

            if (this.Y1 - this.Y0 != 0)
            {
                shiftLeft = 2 * this.Diameter / 10;
                bulgeLeft = 0.4;
            }
            if (this.Y3 - this.Y2 != 0)
            {
                shiftRight = 2 * this.Diameter / 10;
                bulgeRight = 0.4;
            }
            if (this.Y0 < this.Y1)
            {
                flipLeft = -1;
            }
            if (this.Y3 < this.Y2)
            {
                flipRight = -1;
            }

            //find rbar boundary to draw
            List <netDxf.Entities.LwPolylineVertex> vertexes = new List <netDxf.Entities.LwPolylineVertex>()
            {
                new netDxf.Entities.LwPolylineVertex(this.X0, this.Y0 + offset - shift * factor),
                new netDxf.Entities.LwPolylineVertex(this.X1, this.Y1 + offset + flipLeft * shiftLeft - shift * factor, flipLeft * bulgeLeft),
                new netDxf.Entities.LwPolylineVertex(this.X1 + shiftLeft, this.Y1 + offset - shift * factor),
                new netDxf.Entities.LwPolylineVertex(this.X2 - shiftRight, this.Y2 + offset - shift * factor, flipRight * bulgeRight),
                new netDxf.Entities.LwPolylineVertex(this.X2, this.Y2 + offset + flipRight * shiftRight - shift * factor),
                new netDxf.Entities.LwPolylineVertex(this.X3, this.Y3 + offset - shift * factor),
            };

            //draw rbar
            LwPolyline rbar = new LwPolyline(vertexes.GetRange(0, 6));

            rbar.SetConstantWidth(this.Diameter / 10);
            Beam.I.Dxf.AddEntity(rbar);

            //if inside of the beam, return
            if (inside)
            {
                return(Beam.I.Dxf);
            }

            //find rbar points to annotate
            Vector2[] points =
            {
                new Vector2(this.X0, this.Y0 + offset - shift * factor),
                new Vector2(this.X1, this.Y1 + offset - shift * factor),
                new Vector2(this.X2, this.Y2 + offset - shift * factor),
                new Vector2(this.X3, this.Y3 + offset - shift * factor),
            };

            //generate description text
            string descriptionText = "(" + id + ") " + this.NumberOfRbars.ToString() + "#" + this.Diameter.ToString() + " L=";

            descriptionText += (Math.Abs(this.Y0 - this.Y1) + Math.Abs(this.X0 - this.X2) + Math.Abs(this.Y3 - this.Y2)).ToString();

            //add description of a rbar
            LinearDimension dim = new LinearDimension(
                points[1],
                points[2],
                1.8,
                0,
                Beam.I.DimensionStyles.Annotation);

            dim.UserText = descriptionText;
            Beam.I.Dxf.AddEntity(dim);

            //check if there's a left hook and dim
            if (this.Y0 != this.Y1)
            {
                LinearDimension leftHookDim = new LinearDimension(
                    points[0],
                    points[1],
                    -5.4,
                    90,
                    Beam.I.DimensionStyles.Rbars);
                Beam.I.Dxf.AddEntity(leftHookDim);
            }

            //draw dimension of the main part of a rbar
            LinearDimension rbarDim = new LinearDimension(
                points[1],
                points[2],
                -5.4,
                0,
                Beam.I.DimensionStyles.Rbars);

            Beam.I.Dxf.AddEntity(rbarDim);

            //check if there's a right hook and dim
            if (this.Y2 != this.Y3)
            {
                LinearDimension rightHookDim = new LinearDimension(
                    points[2],
                    points[3],
                    -5.4,
                    90,
                    Beam.I.DimensionStyles.Rbars);
                Beam.I.Dxf.AddEntity(rightHookDim);
            }
            return(Beam.I.Dxf);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Adjust depth at sequence of points.
 /// </summary>
 /// <param name="inputSequence">Sequence of points to adjust depth.</param>
 /// <param name="ajustValue">Value to add to depth.</param>
 /// <returns>Sequence of points after depth adjust.</returns>
 private static IEnumerable <IDepthPointSource> AdjustDepth(IEnumerable <IDepthPointSource> inputSequence, LinearDimension ajustValue)
 {
     foreach (var inputPoint in inputSequence)
     {
         inputPoint.Depth += ajustValue;
         yield return(inputPoint);
     }
 }
        /// <summary>
        /// Draws the panel.
        /// </summary>
        /// <param name="xLowerBound">The x lower bound.</param>
        /// <param name="xUpperBound">The x upper bound.</param>
        /// <param name="yLowerBound">The y lower bound.</param>
        /// <param name="yUpperBound">The y upper bound.</param>
        /// <param name="panel">The panel.</param>
        /// <param name="para">The para.</param>
        public static void drawPanel(double xLowerBound, double xUpperBound, double yLowerBound, double yUpperBound, PerforationPanel panel, bool fixingHolesManipulated, bool enablePerf)
        {
            RhinoDoc    doc        = RhinoDoc.ActiveDoc;
            List <Guid> guidList   = new List <Guid>();
            string      layerName  = null;                       //name of layers
            int         layerIndex = 0;                          //index of layers

            Rhino.DocObjects.Layer parent_layer_Approval = null; //create variable to hold approval layer
            Rhino.DocObjects.Layer parent_layer_Nesting  = null; //create variable to hold nesting layer
                                                                 //Rhino.DocObjects.Layer childlayer = null; //Create a variable to hold child layers
            string       text   = "";
            double       height = panel.labelHeight / 3;
            const string font   = "Arial";
            Guid         burrLeader;
            RhinoObject  labelText;

            Rhino.Geometry.Point3d pt    = new Rhino.Geometry.Point3d(0, 0, 0);
            Rhino.Geometry.Plane   plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

            //start
            //Creating layer called "Layers for Approval Drawings" to make it a parent layer
            layerName = "LAYERS FOR APPROVAL DRAWINGS";
            // Does a layer with the same name already exist?
            layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex            = doc.Layers.Add(layerName, System.Drawing.Color.Black);
                parent_layer_Approval = doc.Layers[layerIndex]; //set the layer as parent layer
            }
            else
            {
                parent_layer_Approval = doc.Layers[layerIndex];
            }

            layerName = "LAYERS FOR NESTING";

            // Does a layer with the same name already exist?
            layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex           = doc.Layers.Add(layerName, System.Drawing.Color.Black);
                parent_layer_Nesting = doc.Layers[layerIndex];
            }
            else
            {
                parent_layer_Nesting = doc.Layers[layerIndex];
            }


            // Create a new layer called Perimeter
            layerName = "PANEL PERIMETER";

            layerIndex = createSubLayers.createSubLayer(layerName,
                                                        System.Drawing.Color.Black, parent_layer_Nesting); //make Nesting layer the parent layer

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            //Bottom and left justified the panels in the grid (panel x0,x1,y0,y1 - refers to the folds edg (folds layer)
            double panelX0 = xLowerBound;
            double panelX1 = panelX0 + panel.X;
            double panelY0 = yUpperBound;
            double panelY1 = panelY0 + panel.Y;

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

            panel.Perimeter = doc.Objects.AddLine(new Point3d(panelX0, panelY1, 0), new Point3d(panelX1, panelY1, 0));
            guidList.Add(panel.Perimeter);

            panel.Perimeter = doc.Objects.AddLine(new Point3d(panelX0, panelY0, 0), new Point3d(panelX0, panelY1, 0));
            guidList.Add(panel.Perimeter);

            panel.Perimeter = doc.Objects.AddLine(new Point3d(panelX0, panelY0, 0), new Point3d(panelX1, panelY0, 0));
            guidList.Add(panel.Perimeter);

            panel.Perimeter = doc.Objects.AddLine(new Point3d(panelX1, panelY0, 0), new Point3d(panelX1, panelY1, 0));
            guidList.Add(panel.Perimeter);

            //MetrixUtilities.joinCurves(doc.Layers.Find("PANEL PERIMETER", true)); //join the closed curves using the method


            //Calculating the borders
            double borderX0 = panelX0 + panel.LeftBorder;  //refers to the borders corners
            double borderY0 = panelY0 + panel.BottomBorder;
            double borderX1 = panelX1 - panel.RightBorder;
            double borderY1 = panelY1 - panel.TopBorder;

            BoundingBox    panelBox          = new BoundingBox(borderX0, borderY0, 0, borderX1, borderY1, 0);
            List <Point3d> rectangle_corners = panelBox.GetCorners().Distinct().ToList();

            // add 1st point at last to close the loop
            rectangle_corners.Add(rectangle_corners[0]);
            // Create a new layer called Border

            layerName  = "BORDERS";
            layerIndex = createSubLayers.createSubLayer(layerName,
                                                        System.Drawing.Color.Purple, parent_layer_Approval); //pass to the method, make Approval layer the parent layer

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);
            //Add the borders only if the panel is not solid
            if (panel.DrawPerf != 3)
            {
                //Create a bounding box for the borders
                panel.Border = doc.Objects.AddPolyline(rectangle_corners);
                guidList.Add(panel.Border);
            }

            // Create a new layer called LABELS
            layerName  = "LABELS";
            layerIndex = createSubLayers.createSubLayer(layerName,
                                                        System.Drawing.Color.Red, parent_layer_Nesting); //pass to the method, make Nesting layer the parent layer

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);
            text         = panel.PartName;
            height       = panel.labelHeight;
            pt           = new Rhino.Geometry.Point3d(borderX0, borderY0 + 4 + height, 0);
            plane        = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
            plane.Origin = pt;
            panel.Label  = doc.Objects.AddText(text, plane, height, font, false, false);
            guidList.Add(panel.Label);

            RhinoApp.RunScript("SelNone", true);
            labelText = doc.Objects.Find(panel.Label);
            labelText.Select(true);
            BoundingBox bbox = labelText.Geometry.GetBoundingBox(true);
            double      minX = bbox.Corner(true, true, true).X;
            double      maxX = bbox.Corner(false, true, true).X;
            double      minY = bbox.Corner(true, true, true).Y;
            double      maxY = bbox.Corner(true, false, true).Y;

            if (maxX - minX >= panel.X - panel.LeftBorder - panel.RightBorder)
            {
                double ratio = 1;
                labelText.Select(true);
                if (panel.Y > panel.X)
                {
                    RhinoApp.RunScript("_-rotate " + bbox.Center.X + "," + bbox.Center.Y + " " + "90", true);
                }

                if (maxY - minY + 4 >= panel.X - panel.LeftBorder - panel.RightBorder)
                {
                    ratio = (panel.X - panel.LeftBorder - panel.RightBorder) / (2 * (maxY - minY));
                    if (ratio * (maxX - minX) >= (panel.Y - panel.TopBorder - panel.BottomBorder))
                    {
                        ratio = ratio * (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * ratio * (maxX - minX));
                    }
                }
                else if (maxX - minX >= panel.Y - panel.TopBorder - panel.BottomBorder)
                {
                    ratio = (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * (maxX - minX));
                }
                RhinoApp.RunScript("_-Scale " + bbox.Center.X + "," + bbox.Center.Y + " " + ratio, true);
                BoundingBox bbox3     = labelText.Geometry.GetBoundingBox(true);
                double      distance1 = borderX0 + ratio * (bbox3.Max.X - bbox3.Min.X) / 2;
                double      distance2 = borderY0 + ratio * (bbox3.Max.Y - bbox3.Min.Y) / 2;
                if (panel.Y > panel.X)
                {
                    distance1 = borderX0 + ratio * (bbox3.Max.Y - bbox3.Min.Y) / 2;
                    distance2 = borderY0 + ratio * (bbox3.Max.X - bbox3.Min.X) / 2;
                }

                RhinoApp.WriteLine(bbox3.Center.ToString());
                RhinoApp.RunScript("_-Move " + bbox3.Center.X + "," + bbox3.Center.Y + ",0 " + distance1 + "," + distance2 + ",0", true);
            }
            else if (maxY - minY >= panel.Y - panel.TopBorder - panel.BottomBorder)
            {
                double ratio = (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * (maxY - minY));
                labelText.Select(true);
                RhinoApp.RunScript("_-Scale " + bbox.Center.X + "," + bbox.Center.Y + " " + ratio, true);
                BoundingBox bbox2     = labelText.Geometry.GetBoundingBox(true);
                double      distanceX = borderX0 + ratio * (bbox2.Center.X - bbox2.Min.X) / 2;
                double      distanceY = panelBox.Min.Y + ratio * (bbox2.Center.Y - bbox.Min.Y) / 2;

                RhinoApp.WriteLine(bbox2.Center.ToString());
                RhinoApp.RunScript("_-Move " + bbox2.Center.X + "," + bbox2.Center.Y + ",0 " + distanceX + "," + distanceY + ",0", true);
            }
            labelText.Select(false);

            // If dotFontLabel is more than 0 draw the dot font text on the panel, else skip
            // if (para.DotFont == 1)
            if (panel.DotFontLabel > 0)
            {
                // Create a new layer called DOT SCRIBE LABEL
                layerName = "DOT SCRIBE LABEL";

                layerIndex = createSubLayers.createSubLayer(layerName,
                                                            System.Drawing.Color.Black, parent_layer_Nesting); //make Nesting layer the parent layer


                doc.Layers.SetCurrentLayerIndex(layerIndex, true);

                // Put in the Dot Matrix Label
                // Draw at the right side of the border aand 10mm from the bottom and 100mm from the left edge
                double panelOffset = 0;
                if (panel.BottomBorder - 8.7 <= 6)
                {
                    panelOffset = (panel.BottomBorder - 8.7) / 2;
                }
                else
                {
                    panelOffset = 3.1;
                }
                if (panel.X < 160)
                {
                    pt = new Point3d(1 * (panelX0 + panelX1) / 2, panelY0 + panelOffset + 8.7, 0);
                }
                else
                {
                    pt = new Point3d(panelX1 - 100, panelY0 + panelOffset + 8.7, 0);
                }
                if (panel.DotFontLabellerSide.Equals("Rear"))
                {
                    DotMatrixLabellerCommand.Instance.drawDotMatrix(pt, panel.PartName, 8.7, panel.X); //set the size of dotfont
                }
                else //If not revered use front labeller
                {
                    DotMatrixFrontLabellerCommand.Instance.drawDotMatrix(pt, panel.PartName, 8.7);
                }
            }
            //checks whether the perforation layers exists, if not create layer and make Approval layer the parent layer
            //If exists, make Approval layer the parent layer
            layerName  = "PERFORATION";
            layerIndex = createSubLayers.createSubLayer(layerName,
                                                        System.Drawing.Color.Green, parent_layer_Approval);

            // doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            //Create Temporary Layer

            if (panel.DrawPerf == 1)
            {
                RhinoUtilities.SetActiveLayer("TemporaryPerfLayer", System.Drawing.Color.Green);
                doc.Views.Redraw();

                RhinoApp.RunScript("SelAll", true);
                RhinoApp.RunScript("-_Rotate 0,0,0 -" + panel.patternDirection, true);
                PerforationForm perforationForm = new PerforationForm(new Rhino.DocObjects.ObjRef(panel.Border).Curve());
                perforationForm.enablePerforation = enablePerf;
                perforationForm.drawPerforationDesign(panel.PatternName, true, enablePerf);
                RhinoApp.RunScript("SelAll", true);
                RhinoApp.RunScript("-_Rotate 0,0,0 " + panel.patternDirection, true);
                RhinoApp.RunScript("SelNone", true);

                var rhinoObjects        = doc.Objects.FindByLayer("TemporaryPerfLayer");
                var toolHitObjects      = doc.Objects.FindByLayer("TemporaryToolHit");
                var temporaryTool2Layer = doc.Objects.FindByLayer("TemporaryTool2Layer");

                //Perf objects
                if (rhinoObjects != null && rhinoObjects.Length > 1)
                {
                    foreach (var rhinObj in rhinoObjects)
                    {
                        rhinObj.Select(true);
                    }
                    if (panel.patternDirection == 1)
                    {
                        RhinoApp.RunScript("-_Rotate 0,0,0 -90", true);
                        RhinoApp.RunScript("-_Rotate 0,0,0 90", true);
                    }

                    RhinoUtilities.SetActiveLayer(Properties.Settings.Default.PerforationLayerName, System.Drawing.Color.Green);
                    RhinoApp.RunScript("-_ChangeLayer PERFORATION", true);
                    int index = doc.Layers.Find("TemporaryPerfLayer", true);
                    doc.Layers.Delete(index, true);
                }

                //tool hit objects
                if (toolHitObjects != null && toolHitObjects.Length > 1)
                {
                    foreach (var toolhitObj in toolHitObjects)
                    {
                        toolhitObj.Select(true);
                    }

                    if (panel.patternDirection == 1)
                    {
                        RhinoApp.RunScript("-_Rotate 0,0,0 -90", true);
                        RhinoApp.RunScript("-_Rotate 0,0,0 90", true);
                    }
                    RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black);
                    RhinoApp.RunScript("-_ChangeLayer TOOL HIT", true);
                    int index = doc.Layers.Find("TemporaryToolHit", true);
                    doc.Layers.Delete(index, true);
                }

                //Tool 2 objects
                if (temporaryTool2Layer != null && temporaryTool2Layer.Length > 1)
                {
                    foreach (var tool2Objs in temporaryTool2Layer)
                    {
                        tool2Objs.Select(true);
                    }
                    if (panel.patternDirection == 1)
                    {
                        RhinoApp.RunScript("-_Rotate 0,0,0 -90", true);
                        RhinoApp.RunScript("-_Rotate 0,0,0 90", true);
                    }

                    RhinoUtilities.SetActiveLayer("Tool 2 Layer", System.Drawing.Color.Yellow);
                    RhinoApp.RunScript("-_ChangeLayer Tool 2 Layer", true);
                    int index = doc.Layers.Find("TemporaryTool2Layer", true);
                    doc.Layers.Delete(index, true);
                }
                doc.Views.Redraw();
            }


            DimensionStyle dimStyle = MetrixUtilities.createMetrixRealDimension(); //sets the metrix real dimension

            Point3d         origin = new Point3d(0, 0, 0);
            Point3d         offset = new Point3d(0, 0, 0);
            Point2d         ext1;
            Point2d         ext2;
            Point2d         linePt;
            LinearDimension dimension;
            Guid            dimGuid = new Guid();
            double          u, v;


            // Create a new layer called DIMENSIONS BLACK
            layerName  = "DIMENSIONS BLACK";
            layerIndex = createSubLayers.createSubLayer(layerName,
                                                        System.Drawing.Color.Black, parent_layer_Approval); //pass to the method, make Approval layer the parent layer

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            // Add the word perforated area to the panel
            if (panel.DrawPerf != 3) //Add the text only if the panel is not a solid panel
            {
                //pt = new Rhino.Geometry.Point3d(((borderX1 + borderX0) / 2) - 117.5, ((borderY1 + borderY0) / 2) + 33, 0);
                text         = System.Text.RegularExpressions.Regex.Unescape(panel.PerfText);
                height       = panel.labelHeight / 2;
                pt           = new Rhino.Geometry.Point3d(((borderX1 + borderX0) / 2) - 117.5, ((borderY1 + borderY0) / 2) + 10 + height, 0);
                plane.Origin = pt;
                Guid perforatedAreaLabel = doc.Objects.AddText(text, plane, height, font, false, false);
                guidList.Add(perforatedAreaLabel);

                double ratio = 1;

                if (panel.X - panel.LeftBorder - panel.RightBorder < 230)
                {
                    RhinoApp.RunScript("SelNone", true);
                    labelText = doc.Objects.Find(perforatedAreaLabel);
                    labelText.Select(true);
                    bbox = labelText.Geometry.GetBoundingBox(true);
                    if (panel.Y > panel.X)
                    {
                        RhinoApp.RunScript("_-rotate " + bbox.Center.X + "," + bbox.Center.Y + " " + "90", true);
                    }

                    minX = bbox.Corner(true, true, true).X;
                    maxX = bbox.Corner(false, true, true).X;
                    minY = bbox.Corner(true, true, true).Y;
                    maxY = bbox.Corner(true, false, true).Y;

                    if (maxY - minY > panel.X - panel.LeftBorder - panel.RightBorder)
                    {
                        ratio = (panel.X - panel.LeftBorder - panel.RightBorder) / (2 * (maxY - minY));
                        if (ratio * (maxX - minX) > (panel.Y - panel.TopBorder - panel.BottomBorder))
                        {
                            ratio = ratio * (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * ratio * (maxX - minX));
                        }
                    }
                    else if (maxX - minX >= panel.Y - panel.TopBorder - panel.BottomBorder)
                    {
                        ratio = (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * (maxX - minX));
                    }
                    labelText.Select(true);
                    RhinoApp.RunScript("_-Scale " + bbox.Center.X + "," + bbox.Center.Y + " " + ratio, true);
                    BoundingBox bbox2     = labelText.Geometry.GetBoundingBox(true);
                    double      distanceX = (borderX0 + borderX1) / 2;
                    double      distanceY = (borderY0 + borderY1) / 2;

                    RhinoApp.WriteLine(bbox2.Center.ToString());
                    RhinoApp.RunScript("_-Move " + bbox2.Center.X + "," + bbox2.Center.Y + ",0 " + distanceX + "," + distanceY + ",0", true);
                }
                else
                {
                    RhinoApp.RunScript("SelNone", true);
                    labelText = doc.Objects.Find(perforatedAreaLabel);
                    labelText.Select(true);
                    bbox = labelText.Geometry.GetBoundingBox(true);
                    minX = bbox.Corner(true, true, true).X;
                    maxX = bbox.Corner(false, true, true).X;
                    minY = bbox.Corner(true, true, true).Y;
                    maxY = bbox.Corner(true, false, true).Y;

                    if (maxX - minX > panel.Y - panel.TopBorder - panel.BottomBorder)
                    {
                        ratio = (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * (maxY - minY));
                        labelText.Select(true);
                        RhinoApp.RunScript("_-Scale " + bbox.Center.X + "," + bbox.Center.Y + " " + ratio, true);
                    }
                    BoundingBox bbox2     = labelText.Geometry.GetBoundingBox(true);
                    double      distanceX = (borderX0 + borderX1) / 2;
                    double      distanceY = (borderY0 + borderY1) / 2;

                    RhinoApp.WriteLine(bbox2.Center.ToString());
                    RhinoApp.RunScript("_-Move " + bbox2.Center.X + "," + bbox2.Center.Y + ",0 " + distanceX + "," + distanceY + ",0", true);
                }
            }

            // Add horizontal dimension
            origin = new Point3d(panelX1, panelY0 - 50, 0);
            offset = new Point3d(panelX0, panelY0 - 50, 0);
            pt     = new Point3d((offset.X - origin.X) / 2, panelY0 - 100, 0);

            plane        = Plane.WorldXY;
            plane.Origin = origin;

            //double u, v;
            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);


            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);       //add the bottom dimension(vertical line)
            guidList.Add(dimGuid);

            // Add vertical dimension for panel

            origin = new Point3d(panelX0 - 20, panelY0, 0);
            offset = new Point3d(panelX0 - 20, panelY1, 0);
            pt     = new Point3d(panelX0 - 100, (offset.Y - origin.Y) / 2, 0);

            plane        = Plane.WorldXY;
            plane.XAxis  = new Vector3d(0, -1, 0);
            plane.YAxis  = new Vector3d(-1, 0, 0);
            plane.ZAxis  = new Vector3d(0, 0, -1);
            plane.Origin = origin;

            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension); //adds the left dimension

            guidList.Add(dimGuid);


            MetrixUtilities.createMetrixBordersDimension(); //sets the dimension style for borders

            // Draw Border dimension on BORDERS layer
            if (panel.DrawPerf != 3) ///Add only if the panel is not a solid panel
            {
                layerName  = "BORDERS";
                layerIndex = doc.Layers.Find(layerName, true);
                doc.Layers.SetCurrentLayerIndex(layerIndex, true);

                // Add horizontal borders dimension
                origin = new Point3d(panelX1, (panelY0 + panelY1) / 2, 0);
                offset = new Point3d(borderX1, (panelY0 + panelY1) / 2, 0);
                pt     = new Point3d((offset.X - origin.X) / 2, (borderY0 + borderY1) / 2, 0);

                plane        = Plane.WorldXY;
                plane.Origin = origin;

                plane.ClosestParameter(origin, out u, out v);
                ext1 = new Point2d(u, v);

                plane.ClosestParameter(offset, out u, out v);
                ext2 = new Point2d(u, v);

                plane.ClosestParameter(pt, out u, out v);
                linePt = new Point2d(u, v);

                dimension = new LinearDimension(plane, ext1, ext2, linePt);
                dimGuid   = doc.Objects.AddLinearDimension(dimension);

                guidList.Add(dimGuid);

                // Add horizontal borders dimension
                origin = new Point3d(panelX0, (panelY0 + panelY1) / 2, 0);
                offset = new Point3d(borderX0, (panelY0 + panelY1) / 2, 0);
                pt     = new Point3d((offset.X - origin.X) / 2, (borderY0 + borderY1) / 2, 0);


                plane.ClosestParameter(origin, out u, out v);
                ext1 = new Point2d(u, v);

                plane.ClosestParameter(offset, out u, out v);
                ext2 = new Point2d(u, v);

                plane.ClosestParameter(pt, out u, out v);
                linePt = new Point2d(u, v);

                dimension = new LinearDimension(plane, ext1, ext2, linePt);
                dimGuid   = doc.Objects.AddLinearDimension(dimension);

                guidList.Add(dimGuid);

                // Add vertical border dimension for panel

                origin = new Point3d((panelX0 + panelX1) / 2, panelY0, 0);
                offset = new Point3d((panelX0 + panelX1) / 2, borderY0, 0);
                pt     = new Point3d((borderX0 + borderX1) / 2, (offset.Y - origin.Y) / 2, 0);

                plane        = Plane.WorldXY;
                plane.XAxis  = new Vector3d(0, -1, 0);
                plane.YAxis  = new Vector3d(-1, 0, 0);
                plane.ZAxis  = new Vector3d(0, 0, -1);
                plane.Origin = origin;

                plane.ClosestParameter(origin, out u, out v);
                ext1 = new Point2d(u, v);

                plane.ClosestParameter(offset, out u, out v);
                ext2 = new Point2d(u, v);

                plane.ClosestParameter(pt, out u, out v);
                linePt = new Point2d(u, v);

                dimension = new LinearDimension(plane, ext1, ext2, linePt);
                dimGuid   = doc.Objects.AddLinearDimension(dimension);

                guidList.Add(dimGuid);

                origin = new Point3d((panelX0 + panelX1) / 2, panelY1, 0);
                offset = new Point3d((panelX0 + panelX1) / 2, borderY1, 0);
                pt     = new Point3d((borderX0 + borderX1) / 2, (offset.Y - origin.Y) / 2, 0);

                plane.ClosestParameter(origin, out u, out v);
                ext1 = new Point2d(u, v);

                plane.ClosestParameter(offset, out u, out v);
                ext2 = new Point2d(u, v);

                plane.ClosestParameter(pt, out u, out v);
                linePt = new Point2d(u, v);

                dimension = new LinearDimension(plane, ext1, ext2, linePt);
                dimGuid   = doc.Objects.AddLinearDimension(dimension);

                guidList.Add(dimGuid);
            }

            MetrixUtilities.createMetrixRealDimension(); //sets the default dimension style
            layerName  = "VIEWPORT";
            layerIndex = createSubLayers.createSubLayer(layerName,
                                                        System.Drawing.Color.Black, parent_layer_Approval); //pass to the method, make Approval layer the parent layer

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);



            Rhino.DocObjects.RhinoObject label = doc.Objects.Find(panel.Label);
            string exportFileName = "1";

            if (label != null)
            {
                label.Select(true);
                Rhino.Geometry.TextEntity textentity = label.Geometry as Rhino.Geometry.TextEntity;
                exportFileName = textentity.Text + ".dxf";
            }


            /**
             * Checks if the dxf files are required by the user, if yes check whether the panel is perforated
             * using the drawPerf property in the panel. If it is a perforated panel then check if the directory
             * for perforated panels dxf files already exists, if does not exist create directory and run command.
             * If panel is not perforated, create directory to save not perforated panels dxf files if the directory
             * does not exist. Then run the dxf file create command.
             * */
            if (panel.DXFFilesRequired.Equals("Yes"))
            {
                String path;
                String immediateFolderName = Path.GetFileName(Path.GetDirectoryName(doc.Path)); //get the immediate foldername which the file is located in
                                                                                                //split the path to get the parent folder.
                String[] newPath = MetrixUtilities.splitString(Path.GetDirectoryName(doc.Path), immediateFolderName);
                if (panel.DrawPerf == 1)                                                        //checks if panel is perforated
                {
                    path = newPath[0] + ("5TRUMPF") + ("\\WITH PERF");                          //merge path for perforated files
                    if (!Directory.Exists(path))                                                //check if directory already exists
                    {
                        System.IO.Directory.CreateDirectory(path);                              //create directory if not exist
                    }
                }
                else
                {
                    path = newPath[0] + ("5TRUMPF") + ("\\NO PERF"); //merge path for not perforated files
                    if (!Directory.Exists(path))                     //check if directory already exists
                    {
                        System.IO.Directory.CreateDirectory(path);   //create directory if not exist
                    }
                }
                string command = string.Format("-_Export \"" + path + @"\" + exportFileName + "\"  Scheme \"R12 Lines & Arcs\" Enter");
                // Export the selected curves
                RhinoApp.RunScript(command, true);
            }
            // Unselect all objects
            doc.Objects.UnselectAll();

            // Default layer index
            int defaultLayerIndex = doc.Layers.Find("Default", true);

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            ////if draw perf is false, turnoff the toolhit layer
            //if (Convert.ToBoolean(panel.DrawPerf) != true)
            //{
            //   layerName = "Tool Hit";
            //   layerIndex = doc.Layers.Find(layerName, true);
            //   doc.Layers[layerIndex].IsVisible = false;
            //}



            MetrixUtilities.joinCurves(doc.Layers.Find("PANEL PERIMETER", true));
            if (panel.FixingHoles == "1")
            {
                //if fixing holes are not manipulated, recalculate distances
                if (!fixingHolesManipulated)
                {
                    //panel = reCalculateDistances(panel);

                    //Below method is if fixing holes are automated
                    guidList = FixingHoles.drawFixingFoles(panel, null, false, 0, 0, panelY0, panelY1, dimStyle, guidList, panelX0, panelX1, 0, 0, 0, 0, 0); //add fixing holes
                }
                else
                {
                    //Below method is if fixing holes  have been manipulated
                    guidList = CustomFixingHoles.drawFixingFoles(panel, null, false, 0, 0, panelY0, panelY1, dimStyle, guidList, panelX0, panelX1, 0, 0, 0, 0, 0); //add fixing holes
                }
            }
            layerName  = "VIEWPORT";
            layerIndex = createSubLayers.createSubLayer(layerName,
                                                        System.Drawing.Color.Black, parent_layer_Approval); //pass to the method, make Approval layer the parent layer

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            foreach (Guid g in guidList)
            {
                int idx = RhinoDoc.ActiveDoc.Groups.Find(panel.PartName, false);

                if (idx < 0)
                {
                    idx = RhinoDoc.ActiveDoc.Groups.Add(panel.PartName);
                }

                RhinoDoc.ActiveDoc.Groups.AddToGroup(idx, g);
            }

            //end
        }
Ejemplo n.º 29
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp      = commandData.Application;
            UIDocument    uidoc      = uiapp.ActiveUIDocument;
            Application   app        = uiapp.Application;
            Document      doc        = uidoc.Document;
            View          activeView = doc.ActiveView;

            //duplicated in the helper file! remember to change both
            double scale = 304.8;

            //string path = @"C:\Users\gbrog\Desktop\test.3dm";

            string path = @"C:\Users\giovanni.brogiolo\Desktop\ST00-0221.3dm";

            File3dm rhinoModel = File3dm.Read(path);

            List <Rhino.DocObjects.Layer> m_layers = rhinoModel.AllLayers.ToList();

            List <string> layers = Get_RhinoLayerNames(rhinoModel);

            File3dmObject[] rhinoObjects = Get_RhinoObjects(rhinoModel);

            List <Rhino.Geometry.LineCurve> rh_lines = new List <Rhino.Geometry.LineCurve>();

            List <Rhino.Geometry.ArcCurve> rh_arc = new List <Rhino.Geometry.ArcCurve>();

            List <Rhino.Geometry.TextEntity> rh_text = new List <TextEntity>();

            List <Rhino.Geometry.Leader> rh_textLeader = new List <Rhino.Geometry.Leader>();

            List <Rhino.Geometry.LinearDimension> rh_linearDimension = new List <LinearDimension>();

            List <List <Rhino.Geometry.Point3d> > rh_polylineCurvePoints = new List <List <Point3d> >();

            List <Tuple <string, XYZ> > rh_Blocks = new List <Tuple <string, XYZ> >();

            foreach (var item in rhinoObjects)
            {
                GeometryBase geo = item.Geometry;

                // check if geometry is a curve
                if (geo is Rhino.Geometry.LineCurve)
                {
                    // add curve to list
                    Rhino.Geometry.LineCurve ln = geo as Rhino.Geometry.LineCurve;
                    rh_lines.Add(ln);
                }

                if (geo is Rhino.Geometry.ArcCurve)
                {
                    // add curve to list
                    Rhino.Geometry.ArcCurve arc = geo as Rhino.Geometry.ArcCurve;
                    rh_arc.Add(arc);
                }


                if (!item.Attributes.IsInstanceDefinitionObject && geo is Rhino.Geometry.PolylineCurve)
                {
                    PolylineCurve pc = geo as PolylineCurve;

                    Polyline pl = pc.ToPolyline();

                    rh_polylineCurvePoints.Add(pl.ToList());
                }

                if (geo is Rhino.Geometry.TextEntity)
                {
                    TextEntity te = geo as Rhino.Geometry.TextEntity;
                    rh_text.Add(te);
                }

                if (geo is Rhino.Geometry.Leader)
                {
                    rh_textLeader.Add(geo as Rhino.Geometry.Leader);

                    //var text = geo as Rhino.Geometry.Leader;

                    //TaskDialog.Show("r", text.PlainText);
                }

                if (geo is Rhino.Geometry.AnnotationBase)
                {
                    var text = geo as Rhino.Geometry.AnnotationBase;

                    //TaskDialog.Show("r", text.PlainText);
                }

                if (geo is Rhino.Geometry.LinearDimension)
                {
                    LinearDimension ld = geo as Rhino.Geometry.LinearDimension;
                    rh_linearDimension.Add(ld);
                }

                if (geo is Rhino.Geometry.InstanceReferenceGeometry)
                {
                    InstanceReferenceGeometry refGeo = (InstanceReferenceGeometry)geo;

                    // Lookup the parent block definition
                    System.Guid blockDefId         = refGeo.ParentIdefId;
                    InstanceDefinitionGeometry def = rhinoModel.AllInstanceDefinitions.FindId(blockDefId);

                    // block definition name
                    string defname = def.Name;

                    //TaskDialog.Show("R", defname);

                    // transform data for block instance
                    Rhino.Geometry.Transform xform = refGeo.Xform;

                    double x = refGeo.Xform.M03 / scale;
                    double y = refGeo.Xform.M13 / scale;

                    XYZ placementPt = new XYZ(x, y, 0);

                    rh_Blocks.Add(new Tuple <string, XYZ>(defname, placementPt));
                }
            }

            //TaskDialog.Show("r", rh_linearDimension.Count.ToString());

            Rhynamo.clsGeometryConversionUtils rh_ds = new Rhynamo.clsGeometryConversionUtils();

            using (Transaction t = new Transaction(doc, "Convert lines"))
            {
                t.Start();

                rh_ds.Convert_rhLinesToRevitDetailCurve(doc, rh_lines, "3 Arup Continuous Line");

                rh_ds.Convert_PolycurveToLines(doc, rh_polylineCurvePoints, "1 Arup Continuous Line");

                rh_ds.Convert_ArcsToDS(doc, rh_arc);

                rh_ds.RhinoTextToRevitNote(doc, rh_text);

                rh_ds.RhinoLeaderToRevitNote(doc, rh_textLeader);

                rh_ds.RhinoToRevitDimension(doc, rh_linearDimension);

                rh_ds.Convert_rhBlocks(doc, rh_Blocks);

                t.Commit();
            }

            TaskDialog.Show("r", "Done");

            return(Result.Succeeded);
        }
        /// <summary>
        /// Draws the panel.
        /// </summary>
        /// <param name="xLowerBound">The x lower bound.</param>
        /// <param name="xUpperBound">The x upper bound.</param>
        /// <param name="yLowerBound">The y lower bound.</param>
        /// <param name="yUpperBound">The y upper bound.</param>
        /// <param name="panel">The panel.</param>
        /// <param name="para">The para.</param>
        public static void drawPanel(double xLowerBound, double xUpperBound, double yLowerBound, double yUpperBound, PerforationPanel panel, PanelParameters para)
        {
            RhinoDoc    doc      = RhinoDoc.ActiveDoc;
            List <Guid> guidList = new List <Guid>();

            // Create a new layer called Panel Perimeter
            string layerName = "PANEL PERIMETER";

            // Does a layer with the same name already exist?
            int layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            // Bottom and left justified the panels in the grid
            double panelX0 = xLowerBound;
            double panelX1 = panelX0 + panel.X;
            double panelY0 = yUpperBound;
            double panelY1 = panelY0 + panel.Y;

            // Position the panel to be in the middle of the grid
            //double panelX0 = xLowerBound + ((xUpperBound - xLowerBound) - panel.X) /2 ;
            //double panelX1 = panelX0 + panel.X;
            //double panelY1 = yLowerBound  - ((yLowerBound - yUpperBound) - panel.Y) / 2;
            //double panelY0 = panelY1 - panel.Y;

            BoundingBox    panelBox          = new BoundingBox(panelX0, panelY0, 0, panelX1, panelY1, 0);
            List <Point3d> rectangle_corners = panelBox.GetCorners().Distinct().ToList();

            // add 1st point at last to close the loop
            rectangle_corners.Add(rectangle_corners[0]);
            panel.Perimeter = doc.Objects.AddPolyline(rectangle_corners);

            guidList.Add(panel.Perimeter);

            // Create a new layer called Border
            layerName = "BORDERS";

            // Does a layer with the same name already exist?
            layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Purple);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            double borderX0 = panelX0 + panel.LeftBorder;
            double borderY0 = panelY0 + panel.BottomBorder;
            double borderX1 = panelX1 - panel.RightBorder;
            double borderY1 = panelY1 - panel.TopBorder;

            panelBox          = new BoundingBox(borderX0, borderY0, 0, borderX1, borderY1, 0);
            rectangle_corners = panelBox.GetCorners().Distinct().ToList();
            // add 1st point at last to close the loop
            rectangle_corners.Add(rectangle_corners[0]);
            panel.Border = doc.Objects.AddPolyline(rectangle_corners);

            guidList.Add(panel.Border);

            // Create a new layer called LABELS
            layerName = "LABELS";

            // Does a layer with the same name already exist?
            layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Red);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(borderX0, borderY0, 0);
            string       text         = panel.PartName;
            double       height       = para.LabelHeight;
            const string font         = "Arial";

            Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
            plane.Origin = pt;
            panel.Label  = doc.Objects.AddText(text, plane, height, font, false, false);
            guidList.Add(panel.Label);

            // If Dot font needs to be drawn
            if (para.DotFont == 1)
            {
                // Create a new layer called DOTS
                layerName = "DOTS";

                // Does a layer with the same name already exist?
                layerIndex = doc.Layers.Find(layerName, true);

                // If layer does not exist
                if (layerIndex == -1)
                {
                    // Add a new layer to the document
                    layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black);
                }

                doc.Layers.SetCurrentLayerIndex(layerIndex, true);

                // Put in the Dot Matrix Label
                // Draw at the right side of the border aand 10mm from the bottom and 100mm from the left edge
                pt = new Point3d(panelX1 - 100, panelY0 + 5, 0);
                DotMatrixLabellerCommand.Instance.drawDotMatrix(pt, panel.PartName, Properties.Settings.Default.DotMatrixHeight, panel.X);
            }

            if (para.PatternDirection == 1)
            {
                // Export the selected curves
                RhinoApp.RunScript("SelAll", true);
                RhinoApp.RunScript("-_Rotate 0,0,0 90", true);
            }

            PerforationForm perforationForm = new PerforationForm(new Rhino.DocObjects.ObjRef(panel.Border).Curve());

            perforationForm.drawPerforationDesign(panel.PatternName, true);

            if (para.PatternDirection == 1)
            {
                // Export the selected curves
                RhinoApp.RunScript("SelAll", true);
                RhinoApp.RunScript("-_Rotate 0,0,0 -90", true);
            }

            // Draw Dimension
            // Find the Dimension Style

            // Create a new layer called DIMENSION
            layerName = "DIMENSION";

            // Does a layer with the same name already exist?
            layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            // Add the word perforated area to the panel
            pt           = new Rhino.Geometry.Point3d(((borderX1 + borderX0) / 2) - 117.5, ((borderY1 + borderY0) / 2) + 33, 0);
            text         = "PERFORATED \nAREA";
            height       = para.LabelHeight / 2;
            plane.Origin = pt;
            Guid perforatedAreaLabel = doc.Objects.AddText(text, plane, height, font, false, false);

            guidList.Add(perforatedAreaLabel);

            DimensionStyle dimStyle      = doc.DimStyles.Find("Metrix Real", true);
            int            dimStyleIndex = 0;

            if (dimStyle == null)
            {
                dimStyleIndex = doc.DimStyles.Add("Metrix Real");
                dimStyle      = doc.DimStyles.Find("Metrix Real", true);
            }
            else
            {
                dimStyleIndex = dimStyle.Index;
            }

            dimStyle.TextHeight             = 40;
            dimStyle.TextGap                = 25;
            dimStyle.ExtensionLineExtension = 25;
            dimStyle.ExtensionLineOffset    = 25;
            dimStyle.LengthResolution       = 0;
            dimStyle.AngleResolution        = 0;

            dimStyle.ArrowLength           = 25;
            dimStyle.LeaderArrowLength     = 25;
            dimStyle.FitText               = DimensionStyle.TextFit.TextInside;
            dimStyle.FixedExtensionLength  = 25;
            dimStyle.FixedExtensionOn      = true;
            dimStyle.DimRadialTextLocation = DimensionStyle.TextLocation.AboveDimLine;
            doc.DimStyles.Modify(dimStyle, dimStyleIndex, false);
            dimStyle.LeaderTextVerticalAlignment = TextVerticalAlignment.Middle;
            doc.DimStyles.SetCurrent(dimStyleIndex, false);

            // Add horizontal dimension
            Point3d origin = new Point3d(panelX1, panelY0, 0);
            Point3d offset = new Point3d(panelX0, panelY0, 0);

            pt = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 4), 0);

            plane        = Plane.WorldXY;
            plane.Origin = origin;

            double u, v;

            plane.ClosestParameter(origin, out u, out v);
            Point2d ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            Point2d ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            Point2d linePt = new Point2d(u, v);

            LinearDimension dimension = new LinearDimension(plane, ext1, ext2, linePt);
            Guid            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            // Add horizontal borders dimension
            origin = new Point3d(panelX0, panelY0, 0);
            offset = new Point3d(borderX0, panelY0, 0);
            pt     = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 2), 0);


            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            // Add horizontal borders dimension
            origin = new Point3d(panelX1, panelY0, 0);
            offset = new Point3d(borderX1, panelY0, 0);
            pt     = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 2), 0);


            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            // Add vertical dimension for panel

            origin = new Point3d(panelX0, panelY0, 0);
            offset = new Point3d(panelX0, panelY1, 0);
            pt     = new Point3d(panelX0 - (dimStyle.TextHeight * 4), (offset.Y - origin.Y) / 2, 0);

            plane        = Plane.WorldXY;
            plane.XAxis  = new Vector3d(0, -1, 0);
            plane.YAxis  = new Vector3d(-1, 0, 0);
            plane.ZAxis  = new Vector3d(0, 0, -1);
            plane.Origin = origin;

            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            // Add vertical dimension for panel

            origin = new Point3d(panelX0, panelY0, 0);
            offset = new Point3d(panelX0, borderY0, 0);
            pt     = new Point3d(panelX0 - (dimStyle.TextHeight * 2), (offset.Y - origin.Y) / 2, 0);

            plane        = Plane.WorldXY;
            plane.XAxis  = new Vector3d(0, -1, 0);
            plane.YAxis  = new Vector3d(-1, 0, 0);
            plane.ZAxis  = new Vector3d(0, 0, -1);
            plane.Origin = origin;

            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            origin = new Point3d(panelX0, panelY1, 0);
            offset = new Point3d(panelX0, borderY1, 0);
            pt     = new Point3d(panelX0 - (dimStyle.TextHeight * 2), (offset.Y - origin.Y) / 2, 0);

            plane        = Plane.WorldXY;
            plane.XAxis  = new Vector3d(0, -1, 0);
            plane.YAxis  = new Vector3d(-1, 0, 0);
            plane.ZAxis  = new Vector3d(0, 0, -1);
            plane.Origin = origin;

            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            doc.Views.Redraw();

            RhinoObject panelPerimeterObj = doc.Objects.Find(panel.Perimeter);

            // Select all objects on Perforation Layer
            Rhino.DocObjects.RhinoObject[] rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.PerforationLayerName);

            double tolerance = Properties.Settings.Default.Tolerance;

            Rhino.Geometry.Curve panelPerimeterCurve = panelPerimeterObj.Geometry as Rhino.Geometry.Curve;

            // If tool perforation layer is missing
            if (rhinoObjs == null)
            {
                // Select all objects on Perforation Layer
                rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.ToolHitLayerName);
            }

            if (Convert.ToBoolean(panel.DrawPerf) == true && rhinoObjs != null)
            {
                foreach (RhinoObject rhinoObj in rhinoObjs)
                {
                    Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve;

                    if (testCurve != null)
                    {
                        if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA)
                        {
                            guidList.Add(rhinoObj.Id);
                        }
                    }
                }
            }

            // Export the panel

            doc.Objects.UnselectAll();


            doc.Objects.Select(panel.Perimeter);

            // Get all of the objects on the layer. If layername is bogus, you will
            // just get an empty list back

            Rhino.DocObjects.RhinoObject label = doc.Objects.Find(panel.Label);
            string exportFileName = "1";

            if (label != null)
            {
                label.Select(true);
                Rhino.Geometry.TextEntity textentity = label.Geometry as Rhino.Geometry.TextEntity;
                exportFileName = textentity.Text + ".dxf";
            }

            // Select all objects on DOTS Layer
            rhinoObjs = doc.Objects.FindByLayer("DOTS");

            tolerance           = Properties.Settings.Default.Tolerance;
            panelPerimeterCurve = panelPerimeterObj.Geometry as Rhino.Geometry.Curve;

            if (rhinoObjs != null)
            {
                foreach (RhinoObject rhinoObj in rhinoObjs)
                {
                    Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve;

                    if (testCurve != null)
                    {
                        if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA)
                        {
                            rhinoObj.Select(true);
                        }
                    }
                }
            }

            // Select all objects on Tool Hit
            rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.ToolHitLayerName);

            if (rhinoObjs == null)
            {
                rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.PerforationLayerName);
            }

            if (rhinoObjs != null)
            {
                foreach (RhinoObject rhinoObj in rhinoObjs)
                {
                    Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve;

                    if (testCurve != null)
                    {
                        if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA)
                        {
                            rhinoObj.Select(true);
                        }
                    }
                }
            }

            string command = string.Format("-_Export \"" + Path.GetDirectoryName(doc.Path) + @"\" + exportFileName + "\"  Scheme \"R12 Lines & Arcs\" Enter");

            // Export the selected curves
            RhinoApp.RunScript(command, true);

            // Unselect all objects
            doc.Objects.UnselectAll();

            // Default layer index
            int defaultLayerIndex = doc.Layers.Find("Default", true);

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            if (Convert.ToBoolean(panel.DrawPerf) != true)
            {
                // Delete the Perforation layer as it consumes too much memory
                // Create a new layer called DIMENSION
                layerName = "PERFORATION";

                // Does a layer with the same name already exist?
                layerIndex = doc.Layers.Find(layerName, true);

                // Get all of the objects on the layer. If layername is bogus, you will
                // just get an empty list back
                Rhino.DocObjects.RhinoObject[] rhobjs = doc.Objects.FindByLayer(layerName);

                if (rhobjs != null)
                {
                    if (rhobjs.Length > 0)
                    {
                        for (int i = 0; i < rhobjs.Length; i++)
                        {
                            doc.Objects.Delete(rhobjs[i], true);
                        }
                    }
                }

                doc.Layers.Delete(layerIndex, true);
            }

            foreach (Guid g in guidList)
            {
                int idx = RhinoDoc.ActiveDoc.Groups.Find(panel.PartName, false);

                if (idx < 0)
                {
                    idx = RhinoDoc.ActiveDoc.Groups.Add(panel.PartName);
                }

                RhinoDoc.ActiveDoc.Groups.AddToGroup(idx, g);
            }
        }