Exemple #1
0
        /// <summary>
        /// rotate all entries in a structure around bounding box center point. Changes coordinates of them
        /// </summary>
        /// <param name="in_deg"></param>
        public void performRotationOfDxfStruct(double in_deg)
        {
            //obtain center of rotation
            double horizontalMidPoint = (this.currentBoundingBox.XLowerLeft + this.currentBoundingBox.XUpperRight) / 2.0;
            double verticalMidPoint   = (this.currentBoundingBox.YLowerLeft + this.currentBoundingBox.YUpperRight) / 2.0;

            //obtain rotation matrix
            double[,] currentRotationMatrix = MathHelperForTransformations.getRotationMatrixAroundPoint(horizontalMidPoint, verticalMidPoint, MathHelperForTransformations.ConvertDegreesToRadians(in_deg));
            //iterate over all entries in dxf structure altering them
            for (int iii = 0; iii < AllDXFdrawingEntries.Count; iii++)
            {
                DXFdrawingEntry item = AllDXFdrawingEntries[iii];
                if (item is MyDxfLine)
                {
                    Tuple <double, double> coord1 = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (item as MyDxfLine).XStart, (item as MyDxfLine).YStart);
                    (item as MyDxfLine).XStart = coord1.Item1;
                    (item as MyDxfLine).YStart = coord1.Item2;
                    Tuple <double, double> coord2 = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (item as MyDxfLine).XEnd, (item as MyDxfLine).YEnd);
                    (item as MyDxfLine).XEnd = coord2.Item1;
                    (item as MyDxfLine).YEnd = coord2.Item2;
                }
                else if (item is MyDxfArc)
                {
                    //center coordinates
                    Tuple <double, double> coordCenter = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (item as MyDxfArc).XCenter, (item as MyDxfArc).YCenter);
                    // Rotate start and stop angles. They are pointed by vectors, coming from Center and by magnitube of Radius
                    // https://www.youtube.com/watch?v=g9lgL6f3h90

                    /*
                     * double startAngleCoordinateX = (item as MyDxfArc).XCenter + (item as MyDxfArc).Radius * Math.Cos((item as MyDxfArc).StartAngleRad);
                     * double startAngleCoordinateY = (item as MyDxfArc).YCenter + (item as MyDxfArc).Radius * Math.Sin((item as MyDxfArc).StartAngleRad);
                     * double endAngleCoordinateX = (item as MyDxfArc).XCenter + (item as MyDxfArc).Radius * Math.Cos((item as MyDxfArc).EndAngleRad);
                     * double endAngleCoordinateY = (item as MyDxfArc).YCenter + (item as MyDxfArc).Radius * Math.Sin((item as MyDxfArc).EndAngleRad);
                     * //rotate vector which corresponds to start angle
                     * Tuple<double, double> startAnglePointNew = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (startAngleCoordinateX ), (startAngleCoordinateY ));
                     * double theta1Start = Math.Asin(Math.Abs(startAnglePointNew.Item2 - coordCenter.Item2) / (item as MyDxfArc).Radius);
                     * double startAngleDegree = MathHelperForTransformations.ConvertRadiansToDegrees(theta1Start);
                     * //rotate vector which corresponds to end angle
                     * Tuple<double, double> endAnglePointNew = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (endAngleCoordinateX ), (endAngleCoordinateY ));
                     * double theta2End = Math.Asin(Math.Abs(endAnglePointNew.Item2 - coordCenter.Item2) / (item as MyDxfArc).Radius);
                     * double endAngleDegree = MathHelperForTransformations.ConvertRadiansToDegrees(theta2End);
                     */
                    double startAngleDegree = (item as MyDxfArc).StartAngleDegree + in_deg;
                    double endAngleDegree   = (item as MyDxfArc).EndAngleDegree + in_deg;
                    AllDXFdrawingEntries[iii] = new MyDxfArc(coordCenter.Item1, coordCenter.Item2, startAngleDegree, endAngleDegree, (item as MyDxfArc).Radius);
                }
            }
            //bounding box should be changed too. rotate ALL the coordinates of bounding rectangle and select the new appropriate values

            recalculateBoundingBoxFromScratch();
        }
Exemple #2
0
        public completeDxfStruct processDxfFile(string in_obtainedFileName)
        {
            completeDxfStruct valueToReturn = new completeDxfStruct();
            DxfFile           dxfFile;

            using (System.IO.FileStream fs = new System.IO.FileStream(in_obtainedFileName, System.IO.FileMode.Open))
            {
                dxfFile = DxfFile.Load(fs);
                IList <DxfBlock>  allBlocks = dxfFile.Blocks;
                IList <DxfEntity> usedEntities;
                if ((allBlocks.Count == 0) || (allBlocks[0].Name.ToUpper().Contains("MODEL") == false))
                {
                    usedEntities = dxfFile.Entities;
                }
                else
                {
                    usedEntities = allBlocks[0].Entities;
                }

                foreach (DxfEntity entity in dxfFile.Entities)
                {
                    switch (entity.EntityType)
                    {
                    case DxfEntityType.Line:
                    {
                        DxfLine   line       = (DxfLine)entity;
                        MyDxfLine TransfLine = new MyDxfLine(line.P1.X, line.P1.Y, line.P2.X, line.P2.Y);
                        valueToReturn.addDxfDrawingEntry(TransfLine);
                        break;
                    }

                    case DxfEntityType.Arc:
                    {
                        DxfArc   arc       = (DxfArc)entity;
                        MyDxfArc TransfArc = new MyDxfArc(arc.Center.X, arc.Center.Y, arc.StartAngle, arc.EndAngle, arc.Radius);
                        valueToReturn.addDxfDrawingEntry(TransfArc);
                        break;
                    }

                    case DxfEntityType.LwPolyline: {    //polyline. It has vertices.
                        DxfLwPolyline polylineS             = entity as DxfLwPolyline;
                        int           totalnumberOfVertices = polylineS.Vertices.Count;
                        for (int i = 0; i < totalnumberOfVertices - 1; i++)
                        {         //iterate through vertices, taking them by 2. A figure is between these two
                            DxfLwPolylineVertex point1 = polylineS.Vertices[i];
                            DxfLwPolylineVertex point2 = polylineS.Vertices[i + 1];
                            if (point1.Bulge == 0)
                            {
                                MyDxfLine TransfLine = new MyDxfLine(point1.X, point1.Y, point2.X, point2.Y);
                                valueToReturn.addDxfDrawingEntry(TransfLine);
                            }
                            else             //it is arc
                            // The bulge is the tangent of one fourth the included angle for an arc segment,
                            // made negative if the arc goes clockwise from the start point to the endpoint.
                            // A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle
                            {
                                double angleOfArc = System.Math.Atan(point1.Bulge) * 180.0 / Math.PI * 4;
                                double startAngle = Math.Atan(point1.Y / point1.X) * 180.0 / Math.PI;
                                //double endAngle =
                            }
                        }

                        break;
                    }

                    case DxfEntityType.Polyline:  {
                        //https://github.com/IxMilia/Dxf/issues/90
                        DxfPolyline polyline = entity as DxfPolyline;

                        break;
                    }
                    }
                }
            }
            return(valueToReturn);
        }