public RoomImage(RoomImage image, Wall wall) { if(!image.ImageWalls.Contains(wall)) throw new ArgumentException("Room elements are non-existent"); Parent = image; ImageWalls = new Wall[image.ImageWalls.Length]; ImageWalls[0] = wall; int i = 1; foreach (Wall roomWall in image.ImageWalls) { if (roomWall == wall) continue; Point startVector = Geometry.ParallelProjection(wall, roomWall.Start, true); startVector.X -= roomWall.Start.X; startVector.Y -= roomWall.Start.Y; Point endVector = Geometry.ParallelProjection(wall, roomWall.End, true); endVector.X -= roomWall.End.X; endVector.Y -= roomWall.End.Y; Point newStart = new Point(roomWall.Start.X + 2 * startVector.X, roomWall.Start.Y + 2 * startVector.Y); Point newEnd = new Point(roomWall.End.X + 2 * endVector.X, roomWall.End.Y + 2 * endVector.Y); ImageWalls[i] = new Wall(newStart, newEnd, roomWall.WallMaterial); i++; } Point sourceVector = Geometry.ParallelProjection(wall, image.Source, true); sourceVector.X -= image.Source.X; sourceVector.Y -= image.Source.Y; Source = new Point(image.Source.X + 2 * sourceVector.X, image.Source.Y + 2 * sourceVector.Y); }
private void UpdateWallProps(Wall wall) { PropsPanel.Children.Clear(); TextBlock name = new TextBlock { FontSize = 20, Text = "WALL", TextAlignment = TextAlignment.Center, Width = rightPanelWidth }; PropsPanel.Children.Add(name); TextBlock material = new TextBlock { FontSize = 14, Text = "Material", Width = rightPanelWidth, TextAlignment = TextAlignment.Center }; PropsPanel.Children.Add(material); ComboBox materialBox = new ComboBox {Width = 180}; //materialBox.Items.Add(Wall.MaterialPreset.Brick); //materialBox.Items.Add(Wall.MaterialPreset.Glass); //materialBox.Items.Add(Wall.MaterialPreset.Granite); //materialBox.Items.Add(Wall.MaterialPreset.OakWood); //materialBox.Items.Add(Wall.MaterialPreset.Rubber); //materialBox.Items.Add(Wall.MaterialPreset.None); materialBox.ItemsSource = Enum.GetValues(typeof (Wall.MaterialPreset)); materialBox.SelectedItem = wall.MatPreset; PropsPanel.Children.Add(materialBox); TextBlock matParams = new TextBlock { FontSize = 14, Text = "Material paramaters", Width = rightPanelWidth, TextAlignment = TextAlignment.Center }; PropsPanel.Children.Add(matParams); TextBlock density = new TextBlock { FontSize = 10, Text = "Density", Width = rightPanelWidth, TextAlignment = TextAlignment.Left }; PropsPanel.Children.Add(density); TextBox densityBox = new TextBox { FontSize = 10, Text = wall.WallMaterial.Density + "", Width = rightPanelWidth, TextAlignment = TextAlignment.Left }; PropsPanel.Children.Add(densityBox); TextBlock soundspeed = new TextBlock { FontSize = 10, Text = "Speed of sound", Width = rightPanelWidth, TextAlignment = TextAlignment.Left }; PropsPanel.Children.Add(soundspeed); TextBox soundspeedBox = new TextBox { FontSize = 10, Text = wall.WallMaterial.SoundSpeed + "", Width = rightPanelWidth, TextAlignment = TextAlignment.Left }; PropsPanel.Children.Add(soundspeedBox); TextBlock location = new TextBlock { FontSize = 14, Text = "Location", Width = rightPanelWidth, TextAlignment = TextAlignment.Center }; PropsPanel.Children.Add(location); TextBlock beginning = new TextBlock { FontSize = 10, Text = "First point", Width = rightPanelWidth, TextAlignment = TextAlignment.Left }; PropsPanel.Children.Add(beginning); StackPanel firstPanel = new StackPanel{Orientation = Orientation.Horizontal, Width = rightPanelWidth}; TextBlock xbegblock = new TextBlock{FontSize = 10, Text = "X: ",Margin = new Thickness(5,5,5,0)}; firstPanel.Children.Add(xbegblock); TextBox xbegbox = new TextBox{ FontSize = 10, Text = wall.Start.X+"",Width=numFieldWidth,TextAlignment = TextAlignment.Left}; firstPanel.Children.Add(xbegbox); TextBlock ybegblock = new TextBlock { FontSize = 10, Text = "Y: ", Margin = new Thickness(5, 5, 5, 0) }; firstPanel.Children.Add(ybegblock); TextBox ybegbox = new TextBox { FontSize = 10, Text = wall.Start.Y + "", Width = numFieldWidth, TextAlignment = TextAlignment.Left }; firstPanel.Children.Add(ybegbox); PropsPanel.Children.Add(firstPanel); TextBlock ending = new TextBlock { FontSize = 10, Text = "Second point", Width = rightPanelWidth, TextAlignment = TextAlignment.Left }; PropsPanel.Children.Add(ending); StackPanel secondPanel = new StackPanel { Orientation = Orientation.Horizontal, Width = rightPanelWidth }; TextBlock xendblock = new TextBlock { FontSize = 10, Text = "X: ", Margin = new Thickness(5, 5, 5, 0) }; secondPanel.Children.Add(xendblock); TextBox xendbox = new TextBox { FontSize = 10, Text = wall.End.X + "", Width = numFieldWidth, TextAlignment = TextAlignment.Left }; secondPanel.Children.Add(xendbox); TextBlock yendblock = new TextBlock { FontSize = 10, Text = "Y: ", Margin = new Thickness(5, 5, 5, 0) }; secondPanel.Children.Add(yendblock); TextBox yendbox = new TextBox{ FontSize = 10, Text = wall.End.Y + "", Width = numFieldWidth, TextAlignment = TextAlignment.Left }; secondPanel.Children.Add(yendbox); PropsPanel.Children.Add(secondPanel); TextBlock filtering = new TextBlock { FontSize = 14, Text = "Level of filtering by frequency", Width = rightPanelWidth, TextAlignment = TextAlignment.Center }; PropsPanel.Children.Add(filtering); StackPanel freqPanel = new StackPanel{Orientation = Orientation.Horizontal,Width = rightPanelWidth}; TextBlock lowBlock = new TextBlock {FontSize = 10, Text = "LOW: ", Margin = new Thickness(5, 5, 5, 0)}; TextBox lowBox = new TextBox{FontSize = 10,Text = wall.WallMaterial.Low+"",Width = numFieldWidth,TextAlignment = TextAlignment.Left}; freqPanel.Children.Add(lowBlock); freqPanel.Children.Add(lowBox); TextBlock medBlock = new TextBlock { FontSize = 10, Text = "MED: ", Margin = new Thickness(5, 5, 5, 0) }; TextBox medBox = new TextBox { FontSize = 10, Text = wall.WallMaterial.Medium + "", Width = numFieldWidth, TextAlignment = TextAlignment.Left }; freqPanel.Children.Add(medBlock); freqPanel.Children.Add(medBox); TextBlock highBlock = new TextBlock { FontSize = 10, Text = "HIGH: ", Margin = new Thickness(5, 5, 5, 0) }; TextBox highBox = new TextBox { FontSize = 10, Text = wall.WallMaterial.High + "", Width = numFieldWidth, TextAlignment = TextAlignment.Left }; freqPanel.Children.Add(highBlock); freqPanel.Children.Add(highBox); PropsPanel.Children.Add(freqPanel); Button deleteButton = new Button{Content = "Delete wall", HorizontalAlignment = HorizontalAlignment.Center,Margin = new Thickness(10,10,10,10)}; PropsPanel.Children.Add(deleteButton); deleteButton.Click += delegate { ((TextBlock) PropsPanel.Children[0]).Text = "Properties"; PropsPanel.Children.RemoveRange(1, PropsPanel.Children.Count - 1); mRoom.RemoveWall(mSelectedRoomObject as Wall); mSelectedRoomObject = null; DrawRoom(); }; materialBox.SelectionChanged += delegate { for (int i = 0; i < mRoom.Walls.Count; i++) { if (mRoom.Walls[i] == wall) { if ((Wall.MaterialPreset) materialBox.SelectedItem == Wall.MaterialPreset.None) { mRoom.Walls[i].MatPreset = Wall.MaterialPreset.None; return; } mRoom.Walls[i] = new Wall(wall.Start, wall.End, (Wall.MaterialPreset) materialBox.Items[materialBox.SelectedIndex]); mSelectedRoomObject = mRoom.Walls[i]; UpdateWallProps(mSelectedRoomObject as Wall); } } }; densityBox.TextChanged += delegate { double newValue; if (!double.TryParse(densityBox.Text, out newValue) || newValue<0) return; wall.WallMaterial.Density = newValue; wall.MatPreset = Wall.MaterialPreset.None; materialBox.SelectedItem = Wall.MaterialPreset.None; }; densityBox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) densityBox.Text = wall1.WallMaterial.Density+""; }; soundspeedBox.TextChanged += delegate { double newValue; if (!double.TryParse(soundspeedBox.Text, out newValue) || newValue<0) return; wall.WallMaterial.SoundSpeed = newValue; wall.MatPreset = Wall.MaterialPreset.None; materialBox.SelectedItem = Wall.MaterialPreset.None; }; soundspeedBox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) soundspeedBox.Text = wall1.WallMaterial.SoundSpeed + ""; }; lowBox.TextChanged += delegate { double newValue; if (!double.TryParse(lowBox.Text, out newValue) || newValue > 1 || newValue < 0) return; wall.WallMaterial.Low = newValue; wall.MatPreset = Wall.MaterialPreset.None; materialBox.SelectedItem = Wall.MaterialPreset.None; }; lowBox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) lowBox.Text = wall1.WallMaterial.Low + ""; }; medBox.TextChanged += delegate { double newValue; if (!double.TryParse(medBox.Text, out newValue) || newValue > 1 || newValue < 0) return; wall.WallMaterial.Medium = newValue; wall.MatPreset = Wall.MaterialPreset.None; materialBox.SelectedItem = Wall.MaterialPreset.None; }; medBox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) medBox.Text = wall1.WallMaterial.Medium + ""; }; highBox.TextChanged += delegate { double newValue; if (!double.TryParse(highBox.Text, out newValue) || newValue > 1 || newValue < 0) return; wall.WallMaterial.High = newValue; wall.MatPreset = Wall.MaterialPreset.None; materialBox.SelectedItem = Wall.MaterialPreset.None; }; highBox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) highBox.Text = wall1.WallMaterial.High + ""; }; xbegbox.TextChanged += delegate { double newValue; if (!double.TryParse(xbegbox.Text, out newValue)) return; ((Wall) mSelectedRoomObject).Start.X = newValue; DrawRoom(); }; xbegbox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) xbegbox.Text = wall1.Start.X+""; }; ybegbox.TextChanged += delegate { double newValue; if (!double.TryParse(ybegbox.Text, out newValue)) return; ((Wall) mSelectedRoomObject).Start.Y = newValue; DrawRoom(); }; ybegbox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) ybegbox.Text = wall1.Start.Y + ""; }; xendbox.TextChanged += delegate { double newValue; if (!double.TryParse(xendbox.Text, out newValue)) return; ((Wall) mSelectedRoomObject).End.X = newValue; DrawRoom(); }; xendbox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) xendbox.Text = wall1.End.X + ""; }; yendbox.TextChanged += delegate { double newValue; if (!double.TryParse(yendbox.Text, out newValue)) return; ((Wall) mSelectedRoomObject).End.Y = newValue; DrawRoom(); }; yendbox.LostFocus += delegate { var wall1 = mSelectedRoomObject as Wall; if (wall1 != null) yendbox.Text = wall1.End.Y + ""; }; }