Здесь показаны различия между двумя версиями данной страницы.
Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
developers:tutorial:crsselection [2022/07/28 21:47] proxor |
developers:tutorial:crsselection [2022/08/12 08:51] (текущий) proxor [Расчёт площади контуров конструкции поперечного профиля] |
||
---|---|---|---|
Строка 44: | Строка 44: | ||
* [[developers:references:topomatic.alg|Topomatic.Alg.dll]] - базовые классы подобъектов | * [[developers:references:topomatic.alg|Topomatic.Alg.dll]] - базовые классы подобъектов | ||
+ | * [[developers:references:topomatic.alg.model|Topomatic.Alg.Model.dll]] - возможность использования класса [[developers:references:topomatic.alg.model.alignmentactivitymanager|AlignmentActivityManager]] для получения индекса текущего поперечного профиля | ||
* [[developers:references:topomatic.cad.foundation|Topomatic.Cad.Foundation.dll]] - базовые математические типы и операции | * [[developers:references:topomatic.cad.foundation|Topomatic.Cad.Foundation.dll]] - базовые математические типы и операции | ||
* [[developers:references:topomatic.cad.view|Topomatic.Cad.View.dll]] - элемент управления для отображения слоёв моделей | * [[developers:references:topomatic.cad.view|Topomatic.Cad.View.dll]] - элемент управления для отображения слоёв моделей | ||
Строка 106: | Строка 107: | ||
В этом примере рассчитаем сумму площадей контуров конструкции поперечного с введённым пользователем кодом. | В этом примере рассчитаем сумму площадей контуров конструкции поперечного с введённым пользователем кодом. | ||
- | В отличии от предыдущего примера, доступ к элементам конструкции поперечного профиля мы осуществим не через набор объектов текущего видового экрана, а через контекст конструирования поперечного профиля. Для получения контекста воспользуемся методом [[developers:references:topomatic.alg.crs.corridor.createdesigncontext_system.double|CreateDesignContext()]] класса [[developers:references:topomatic.alg.alignment.corridor|Corridor]]. В качестве аргумента этот метод принимает расстояние от начала пути до створа поперечного профиля. Чтобы получить это значение для текущего поперечника нужно получить наблюдателя ([[developers:references:topomatic.crs.icrsbuilderlistener|ICrsBuilderListener]]) с помощью свойства [[developers:references:topomatic.alg.crs.corridor.listener|Listener]] класса [[developers:references:topomatic.alg.alignment.corridor|Corridor]]. Значение свойства [[developers:references:topomatic.crs.icrsbuilderlistener.station|Station]] у [[developers:references:topomatic.crs.icrsbuilderlistener|ICrsBuilderListener]] вернёт значение расстояния от начала пути то створа текущего поперечного профиля. Получив контекст мы можем найти среди его элементов контуры при помощи метода [[developers:references:topomatic.crs.templates.crscontainer.findcontour_system.int32|FindContour()]], передав указанный код в качестве аргумента. | + | В отличии от предыдущего примера, доступ к элементам конструкции поперечного профиля мы осуществим не через набор объектов текущего видового экрана, а через контекст конструирования поперечного профиля. Для получения контекста воспользуемся свойством [[developers:references:topomatic.alg.crs.corridor.item_system.int32|Item[Int32] ]] класса [[developers:references:topomatic.alg.alignment.corridor|Corridor]]. Индекс текущего поперечного профиля получим через свойство [[developers:references:topomatic.alg.model.alignmentactivitymanager|CurrentSection]] менеджера активности подобъекта ([[developers:references:topomatic.alg.model.alignmentactivitymanager|AlignmentActivityManager]]). [[developers:references:topomatic.alg.model.alignmentactivitymanager|AlignmentActivityManager]] получается с помощью свойства [[developers:references:topomatic.alg.runtime.serviceclasses.activealignmentreciver.manager|Manager ]] класса [[developers:references:topomatic.alg.runtime.serviceclasses.activealignmentreciver|ActiveAlignmentReciver]]. Получив контекст мы можем найти среди его элементов контуры при помощи метода [[developers:references:topomatic.crs.templates.crscontainer.findcontour_system.int32|FindContour()]], передав указанный код в качестве аргумента. |
[[developers:references:topomatic.crs.templates.crscontour|CrsContour]] не содержит информации о занимаемой им площади. Чтобы получить площадь контура следует получить список его векторов и передать этот список в качестве аргумента методу [[developers:references:topomatic.cad.foundation.cadlibrary.polygonarea_system.collections.generic.ienumerable_1|PolygonArea()]] статического класса [[developers:references:topomatic.cad.foundation.cadlibrary|CadLibrary]]. | [[developers:references:topomatic.crs.templates.crscontour|CrsContour]] не содержит информации о занимаемой им площади. Чтобы получить площадь контура следует получить список его векторов и передать этот список в качестве аргумента методу [[developers:references:topomatic.cad.foundation.cadlibrary.polygonarea_system.collections.generic.ienumerable_1|PolygonArea()]] статического класса [[developers:references:topomatic.cad.foundation.cadlibrary|CadLibrary]]. | ||
Строка 141: | Строка 142: | ||
// Получение контуров по коду и расчёт их площади | // Получение контуров по коду и расчёт их площади | ||
var corridor = alignment.Corridor; | var corridor = alignment.Corridor; | ||
- | var station = corridor.Listener.Station; | + | var index = receiver.Manager.CurrentSection; |
- | var context = corridor.CreateDesignContext(station); | + | var context = corridor[index]; |
if (context == null) return; | if (context == null) return; | ||
Строка 186: | Строка 187: | ||
if (alignment == null) | if (alignment == null) | ||
{ | { | ||
- | MessageDlg.Show("Необходимо сделать трассу активной.", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); | + | MessageDlg.Show("Необходимо сделать трассу активной.", MessageBoxButtons.OK, |
+ | MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); | ||
return; | return; | ||
} | } | ||
- | } | ||
- | var cadview = CadView; | + | var cadview = CadView; |
- | if (cadview == null) return; | + | if (cadview == null) return; |
- | //Получаем контуры поверхности земли и проектной линии и указываем тип рассчёта | + | //Получаем контуры поверхности земли и проектной линии и указываем тип рассчёта |
- | var corridor = alignment.Corridor; | + | var corridor = alignment.Corridor; |
- | var station = corridor.Listener.Station; | + | |
- | var context = corridor.CreateDesignContext(station); | + | |
- | if (context == null) return; | + | |
- | var eg = context.GetEgContour().AsVectorList(); | + | var index = receiver.Manager.CurrentSection; |
- | if (eg == null || eg.Count == 0) | + | var context = corridor[index]; |
- | { | + | if (context == null) return; |
- | MessageDlg.Show("Поверхность земли отсутствует.", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); | + | |
- | return; | + | |
- | } | + | |
- | var red = context.GetRedLineContour().AsVectorList(); | + | var eg = context.GetEgContour().AsVectorList(); |
- | if (red == null || red.Count == 0) | + | if (eg == null || eg.Count == 0) |
- | { | + | { |
- | MessageDlg.Show("Проектная линия отсутствует.", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); | + | MessageDlg.Show("Поверхность земли отсутствует.", MessageBoxButtons.OK, MessageBoxIcon.Information, |
- | return; | + | MessageBoxDefaultButton.Button1); |
- | } | + | return; |
+ | } | ||
- | var userSelect = "Насыпи"; | + | var red = context.GetRedLineContour().AsVectorList(); |
- | if (!CadCursors.GetUserSelect(cadview, ref userSelect, null, "Рассчитать площадь: ", "Насыпи", "Выемки")) return; | + | if (red == null || red.Count == 0) |
+ | { | ||
+ | MessageDlg.Show("Проектная линия отсутствует.", MessageBoxButtons.OK, MessageBoxIcon.Information, | ||
+ | MessageBoxDefaultButton.Button1); | ||
+ | return; | ||
+ | } | ||
- | //Рассчитываем площадь пересечения | + | var userSelect = "Насыпи"; |
- | var area = 0.0; | + | if (!CadCursors.GetUserSelect(cadview, ref userSelect, null, "Рассчитать площадь: ", "Насыпи", |
- | if (userSelect.Equals("Насыпи", StringComparison.OrdinalIgnoreCase)) | + | "Выемки")) return; |
- | { | + | |
- | eg.Add(eg[eg.Count - 1] + new Vector2D(0.0, 100.0)); | + | |
- | eg.Add(eg[0] + new Vector2D(0.0, 100.0)); | + | |
- | red.Add(red[red.Count - 1] + new Vector2D(0.0, -100.0)); | + | //Рассчитываем площадь пересечения |
- | red.Add(red[0] + new Vector2D(0.0, -100.0)); | + | var area = 0.0; |
- | } | + | if (userSelect.Equals("Насыпи", StringComparison.OrdinalIgnoreCase)) |
- | else | + | { |
- | { | + | eg.Add(eg[eg.Count - 1] + new Vector2D(0.0, 100.0)); |
- | eg.Add(eg[eg.Count - 1] + new Vector2D(0.0, -100.0)); | + | eg.Add(eg[0] + new Vector2D(0.0, 100.0)); |
- | eg.Add(eg[0] + new Vector2D(0.0, -100.0)); | + | |
- | red.Add(red[red.Count - 1] + new Vector2D(0.0, 100.0)); | + | red.Add(red[red.Count - 1] + new Vector2D(0.0, -100.0)); |
- | red.Add(red[0] + new Vector2D(0.0, 100.0)); | + | red.Add(red[0] + new Vector2D(0.0, -100.0)); |
- | } | + | } |
+ | else | ||
+ | { | ||
+ | eg.Add(eg[eg.Count - 1] + new Vector2D(0.0, -100.0)); | ||
+ | eg.Add(eg[0] + new Vector2D(0.0, -100.0)); | ||
- | var intersections = new PolygonOperation().Intersection(eg, red); | + | red.Add(red[red.Count - 1] + new Vector2D(0.0, 100.0)); |
- | foreach (var intersection in intersections) | + | red.Add(red[0] + new Vector2D(0.0, 100.0)); |
- | area += CadLibrary.PolygonArea(intersection); | + | } |
- | MessageDlg.Show($"Площадь {userSelect.ToLower()}: {ValueConverter.AreaToStr(area)}"); | + | var intersections = new PolygonOperation().Intersection(eg, red); |
+ | foreach (var intersection in intersections) | ||
+ | area += CadLibrary.PolygonArea(intersection); | ||
+ | |||
+ | MessageDlg.Show($"Площадь {userSelect.ToLower()}: {ValueConverter.AreaToStr(area)}"); | ||
+ | } | ||
} | } | ||
... | ... |