LinePrimitive and RectanglePrimitive was added

This commit is contained in:
Evgeny Redikultsev
2022-11-19 21:12:55 +05:00
parent 667b91cbfa
commit b566373f16
37 changed files with 544 additions and 69 deletions

View File

@@ -65,7 +65,12 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel>
<Expander Header="Materials" ExpandDirection="Down" MinWidth="20" >
<Expander Header="Materials" ExpandDirection="Down" MinWidth="20">
<Expander.ContextMenu>
<ContextMenu>
<Button Content="Materials" Command="{Binding EditHeadMaterialsCommand}"/>
</ContextMenu>
</Expander.ContextMenu>
<ListBox ItemsSource="{Binding HeadMaterials}">
<ListBox.ItemTemplate>
<DataTemplate>
@@ -86,7 +91,21 @@
</ListBox>
</Expander>
<Expander Header="Geometry" ExpandDirection="Down" MinWidth="20" >
<Expander.ContextMenu>
<ContextMenu>
<MenuItem Header="Add">
<Button Content="Add Rectangle" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Rectangle}"/>
<Button Content="Add Point" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/>
</MenuItem>
</ContextMenu>
</Expander.ContextMenu>
<ListBox ItemsSource="{Binding Primitives}" SelectedItem="{Binding SelectedPrimitive}">
<ListBox.ContextMenu>
<ContextMenu>
<Button Content="Edit" Command="{Binding EditPrimitive}"/>
<Button Content="Delete" Command="{Binding DeletePrimitive}"/>
</ContextMenu>
</ListBox.ContextMenu>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
@@ -122,7 +141,6 @@
</ListBox>
</Expander>
</StackPanel>
<Border BorderBrush="Black" Background="White" BorderThickness="1" Margin="5" Grid.Column="1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown">

View File

@@ -324,6 +324,7 @@ namespace StructureHelper.Windows.MainWindow
MovePrimitiveToGravityCenterCommand = new RelayCommand(o =>
{
if (CheckMaterials() == false) { return;}
IEnumerable<INdm> ndms = Model.GetNdms(calculationProperty);
double[] center = GeometryOperations.GetGravityCenter(ndms);
foreach (var primitive in Model.PrimitiveRepository.Primitives)
@@ -404,6 +405,12 @@ namespace StructureHelper.Windows.MainWindow
}
private bool CheckAnalisysOptions()
{
if (CheckMaterials() == false) { return false; }
return true;
}
private bool CheckMaterials()
{
foreach (var item in PrimitiveRepository.Primitives)
{
@@ -454,16 +461,16 @@ namespace StructureHelper.Windows.MainWindow
wnd.ShowDialog();
if (wnd.DialogResult == true)
{
var rect = template.Shape as StructureHelperCommon.Models.Shapes.Rectangle;
var rect = template.Shape as StructureHelperCommon.Models.Shapes.RectangleShape;
var width = rect.Width;
var height = rect.Height;
var area1 = Math.PI * template.BottomDiameter * template.BottomDiameter / 4d;
var area2 = Math.PI * template.TopDiameter * template.TopDiameter / 4d;
var gap = template.CoverGap;
IHeadMaterial concrete = new HeadMaterial() { Name = "Concrete 40" };
IHeadMaterial concrete = new HeadMaterial() { Name = "Concrete" };
concrete.HelperMaterial = Model.HeadMaterialRepository.LibMaterials.Where(x => (x.MaterialType == MaterialTypes.Concrete & x.Name.Contains("40"))).First();
IHeadMaterial reinforcement = new HeadMaterial() { Name = "Reinforcement 400" };
IHeadMaterial reinforcement = new HeadMaterial() { Name = "Reinforcement" };
reinforcement.HelperMaterial = Model.HeadMaterialRepository.LibMaterials.Where(x => (x.MaterialType == MaterialTypes.Reinforcement & x.Name.Contains("400"))).First();
headMaterials.Add(concrete);
headMaterials.Add(reinforcement);

View File

@@ -7,19 +7,53 @@
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Materials"
d:DataContext="{d:DesignInstance vm:HeadMaterialsViewModel}"
mc:Ignorable="d"
Title="Materials" Height="350" Width="400" WindowStartupLocation="CenterScreen">
Title="Materials" Height="350" Width="680" MinHeight="350" MinWidth="680" WindowStartupLocation="CenterScreen">
<Window.Resources>
<DataTemplate x:Key="LibMaterial">
<StackPanel>
<TextBlock Text="Library material"/>
<ComboBox Grid.Row="2" Height="25" VerticalAlignment="Top" ItemsSource="{Binding LibMaterials}" SelectedItem="{Binding SelectedLibMaterial}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ElasticMaterial">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="180"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
</Grid.RowDefinitions>
<TextBlock Text="Elastic material"/>
<TextBlock Grid.Row="1" Text="Young's modulus"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Modulus, Converter={StaticResource StressConverter}, ValidatesOnDataErrors=True}"/>
<TextBlock Grid.Row="2" Text="Compressive strength"/>
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding CompressiveStrength, Converter={StaticResource StressConverter}, ValidatesOnDataErrors=True}"/>
<TextBlock Grid.Row="3" Text="Tensile strength"/>
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding TensileStrength, Converter={StaticResource StressConverter}, ValidatesOnDataErrors=True}"/>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="280"/>
</Grid.ColumnDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}">
<ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}" SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
@@ -38,21 +72,19 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox Grid.Row="1" Text="{Binding SelectedMaterial.Name}"/>
<ComboBox Grid.Row="2" ItemsSource="{Binding LibMaterials}" SelectedItem="{Binding SelectedLibMaterial}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<StackPanel Grid.Column="1">
<Button Content="New Material" Command="{Binding AddNewMaterialCommand}"/>
<Button Content="New Lib Material" Command="{Binding AddNewMaterialCommand}"/>
<Button Content="New Elastic Material" Command="{Binding AddElasticMaterialCommand}"/>
<Button Content="Edit color" Command="{Binding EditColorCommand}"/>
<Button Content="Copy" Command="{Binding CopyHeadMaterialCommand}"/>
<Button Content="Delete" Command="{Binding DeleteMaterialCommand}"/>
</StackPanel>
<StackPanel Grid.Column="2">
<TextBlock Text="Name"/>
<TextBox Text="{Binding SelectedMaterial.Name}"/>
<StackPanel x:Name="StpMaterialProperties"/>
</StackPanel>
</Grid>
</Window>

View File

@@ -14,6 +14,7 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq;
namespace StructureHelper.Windows.MainWindow.Materials
{
@@ -22,20 +23,47 @@ namespace StructureHelper.Windows.MainWindow.Materials
/// </summary>
public partial class HeadMaterialsView : Window
{
private HeadMaterialsViewModel viewmodel;
private HeadMaterialsViewModel viewModel;
public HeadMaterialsView(IHeadMaterialRepository headMaterialRepository)
{
viewmodel = new HeadMaterialsViewModel(headMaterialRepository);
this.DataContext = viewmodel;
viewModel = new HeadMaterialsViewModel(headMaterialRepository);
this.DataContext = viewModel;
InitializeComponent();
}
public HeadMaterialsView(HeadMaterialsViewModel vm)
{
viewmodel = vm;
this.DataContext = viewmodel;
viewModel = vm;
this.DataContext = viewModel;
InitializeComponent();
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
StpMaterialProperties.Children.Clear();
var selectedMaterial = viewModel.SelectedMaterial;
if (selectedMaterial == null) { return; }
var helperMaterial = selectedMaterial.HelperMaterial;
string dataTemplateName = string.Empty;
Binding binding = new Binding();
if (helperMaterial is ILibMaterial)
{
dataTemplateName = "LibMaterial";
binding.Source = viewModel;
}
if (helperMaterial is IElasticMaterial)
{
dataTemplateName = "ElasticMaterial";
binding.Source = viewModel.SelectedMaterial.HelperMaterial;
}
if (dataTemplateName != string.Empty)
{
ContentControl contentControl = new ContentControl();
contentControl.SetResourceReference(ContentTemplateProperty, dataTemplateName);
contentControl.SetBinding(ContentProperty, binding);
StpMaterialProperties.Children.Add(contentControl);
}
}
}
}

View File

@@ -54,10 +54,9 @@ namespace StructureHelper.Windows.PrimitiveProperiesWindow
foreach (var name in names)
{
ContentControl contentControl = new ContentControl();
contentControl.SetResourceReference(ContentControl.ContentTemplateProperty, name);
Binding binding = new Binding();
binding.Source = viewModel;
contentControl.SetBinding(ContentControl.ContentProperty, binding);
contentControl.SetResourceReference(ContentTemplateProperty, name);
Binding binding = new Binding {Source = viewModel};
contentControl.SetBinding(ContentProperty, binding);
StpProperties.Children.Add(contentControl);
}
}

View File

@@ -27,11 +27,33 @@ namespace StructureHelper.Windows.ViewModels.Materials
ILibMaterial selectedLibMaterial;
public ICommand AddNewMaterialCommand { get; set; }
public ICommand AddElasticMaterialCommand
{
get
{
return addElasticMaterialCommand ??
(
addElasticMaterialCommand = new RelayCommand(o => AddElasticMaterial())
);
}
}
private void AddElasticMaterial()
{
IHeadMaterial material = new HeadMaterial() { Name = "New elastic material" };
material.HelperMaterial = new ElasticMaterial() { Modulus = 2e11d, CompressiveStrength = 4e8d, TensileStrength = 4e8d };
HeadMaterials.Add(material);
materialRepository.HeadMaterials.Add(material);
SelectedMaterial = material;
}
public ICommand CopyHeadMaterialCommand { get; set; }
public ICommand EditColorCommand { get; set; }
public ICommand DeleteMaterialCommand { get; set; }
public ICommand EditHeadMaterial;
private ICommand addElasticMaterialCommand;
public ObservableCollection<IHeadMaterial> HeadMaterials { get; private set; }
public IHeadMaterial SelectedMaterial
{
@@ -104,7 +126,6 @@ namespace StructureHelper.Windows.ViewModels.Materials
HeadMaterials.Add(material);
materialRepository.HeadMaterials.Add(material);
SelectedMaterial = material;
}
private void DeleteMaterial()

View File

@@ -17,7 +17,7 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveTemplates.RCs
{
public IRectangleBeamTemplate Model;
private Rectangle rectangle => (Model.Shape as Rectangle);
private RectangleShape rectangle => (Model.Shape as RectangleShape);
public Window ParentWindow { get; set; }