public static SectionData[] ExtractSectionsData(Size searchWindowSize) { var axisPoints = GetListBlocksByPrefix("axisPoint_"); var heightPoints = GetListBlocksByPrefix("heightPoint_"); var redPoints = GetListBlocksByPrefix("redPoint_"); var blackPoints = GetListBlocksByPrefix("blackPoint_"); var data = new SectionData[0]; if (axisPoints.Count == 0) { return(data); } return(axisPoints. Select(axisPoint => { var axisPointPosition = AcadTools.GetBlockPosition(axisPoint); var heightSectionPoints = heightPoints .Where(point => CheckBlockInWindow(point, axisPointPosition, searchWindowSize)); if (heightSectionPoints.Count() == 0) { return null; } var heightSectionPoint = heightSectionPoints .OrderBy(point => (AcadTools.GetBlockPosition(point) - axisPointPosition).Length) .First(); var sectionOrigin = new Point3d( axisPointPosition.X, AcadTools.GetBlockPosition(heightSectionPoint).Y, .0); var redSectionPoints = redPoints .Where(point => CheckBlockInWindow(point, sectionOrigin, searchWindowSize)) .ToList(); if (redSectionPoints.Count < 2) { return null; } var blackSectionPoints = blackPoints .Where(point => CheckBlockInWindow(point, sectionOrigin, searchWindowSize)) .ToList(); return new SectionData() { AxisPoint = axisPoint, HeightPoint = heightSectionPoint, RedPoints = redSectionPoints, BlackPoints = blackSectionPoints }; }) .Where(sectionData => sectionData != null) .ToArray()); }
public static bool CheckBlockInWindow(BlockTableRecord block, Point3d origin, Size windowSize) { var blockLocalPos = AcadTools.GetBlockPosition(block) - origin; var windowWidth = windowSize.Width; var windowHeight = windowSize.Height; return(-windowWidth / 2.0 <= blockLocalPos.X && blockLocalPos.X < windowWidth / 2.0 && -windowHeight / 2.0 <= blockLocalPos.Y && blockLocalPos.Y < windowHeight / 2.0); }
} //button public void GenerateDataXmlFile( string fileName, Func <Vector3d> getFactPositionNoizeAddition = null) { bool factPossEnabled = true; if (getFactPositionNoizeAddition == null) { getFactPositionNoizeAddition = () => new Vector3d(); factPossEnabled = false; } var pluginSettings = PluginSettings.GetInstance(); var sectionMaxSize = pluginSettings.SectionMaxSize; var sectionsData = RoadSectionParametersExtractor .ExtractSectionsData(sectionMaxSize); Func <double, double, string> CoordsToString = (x, y) => String.Format("{0} {1}", AcadTools.DoubleToFormattedString(x), AcadTools.DoubleToFormattedString(y)); Func <Point3d, Point3d, int, XElement> GetPointElement = (projPos, factPos, number) => new XElement( "point", new XElement( "proj_position", CoordsToString(projPos.X, projPos.Y)), new XElement( "fact_position", CoordsToString(factPos.X, factPos.Y)), new XElement("number", number)); var extractedSectionDataDoc = new XDocument( new XElement( "road_sections", new XAttribute("fact_enabled", factPossEnabled), sectionsData .Select(sd => new XElement( "road_section", new XElement( "staEq", AcadTools.DoubleToFormattedString( RoadSectionParametersExtractor.GetStationFromPointBlock(sd.AxisPoint))), new XElement( "origin", CoordsToString( AcadTools.GetBlockPosition(sd.AxisPoint).X, AcadTools.GetBlockPosition(sd.HeightPoint).Y)), new XElement("origin_height", AcadTools.DoubleToFormattedString( RoadSectionParametersExtractor.GetHeightFromPointBlock(sd.HeightPoint))), new XElement( "red_points", sd.RedPoints .Select(redPoint => GetPointElement( AcadTools.GetBlockPosition(redPoint), AcadTools.GetBlockPosition(redPoint) + getFactPositionNoizeAddition(), RoadSectionParametersExtractor.GetPointNumberFromPointBlock(redPoint)))), new XElement( "black_points", sd.BlackPoints .Select(blackPoint => GetPointElement( AcadTools.GetBlockPosition(blackPoint), AcadTools.GetBlockPosition(blackPoint) + getFactPositionNoizeAddition(), RoadSectionParametersExtractor.GetPointNumberFromPointBlock(blackPoint)))) )))); extractedSectionDataDoc.Save(fileName); }