public AssignMaterialDialog( Window owner ) { InitializeComponent(); this.Owner = owner; canvas = (SlopeCanvas) ((Grid) ((TabControl) ((Grid) this.Owner.Content).Children[2]).SelectedContent).Children[2]; canvas.MaterialTypes.ForEach( delegate( MaterialType mt ) { materialList.Items.Add( mt ); } ); materialList.SelectedIndex = 0; switch ( canvas.Units ) { case Units.Metres: cohUnits.Content = emodUnits.Content = "kPa"; gammaUnits.Content = "kN/m^3"; break; case Units.Millimetres: cohUnits.Content = emodUnits.Content = "kPa"; gammaUnits.Content = "kN/m^3"; break; case Units.Feet: cohUnits.Content = emodUnits.Content = "psi"; gammaUnits.Content = "pcf"; break; default: cohUnits.Content = emodUnits.Content = "psi"; gammaUnits.Content = "pcf"; break; } }
public FEAParamsDialog( Window owner ) { InitializeComponent(); this.Owner = owner; canvas = (SlopeCanvas) ((Grid) ((TabControl) ((Grid) this.Owner.Content).Children[2]).SelectedContent).Children[2]; colWidth.Text = canvas.FEAParameters.ColWidth.ToString(); rowHeight.Text = canvas.FEAParameters.RowHeight.ToString(); nStep.Text = canvas.FEAParameters.NStep.ToString(); nIter.Text = canvas.FEAParameters.NIter.ToString(); nPrint.Text = canvas.FEAParameters.NPrint.ToString(); LFact.Text = canvas.FEAParameters.LFact.ToString(); GFact.Text = canvas.FEAParameters.GFact.ToString(); string units; switch ( canvas.Units ) { case Units.Metres: units = "m"; break; case Units.Millimetres: units = "mm"; break; case Units.Feet: units = "ft"; break; default: units = "in"; break; } colWidthUnits.Content = units; rowHeightUnits.Content = units; }
public AddPointLoadDialog( SlopeCanvas canvas , PointLoad load ) { InitializeComponent(); this.canvas = canvas; this.load = load; // get units dependent scaling factor and strings double factor; string coordUnits , loadUnits; switch ( canvas.Units ) { case Units.Metres: factor = 0.0254; coordUnits = "m"; loadUnits = "kN"; break; case Units.Millimetres: factor = 25.4; coordUnits = "mm"; loadUnits = "kN"; break; case Units.Feet: factor = 1.0 / 12.0; coordUnits = "ft"; loadUnits = "lbf"; break; default: factor = 1.0; coordUnits = "in"; loadUnits = "lbf"; break; } // set units labels nodeUnits.Content = coordUnits; xLoadUnits.Content = loadUnits; yLoadUnits.Content = loadUnits; // set node coordinates double xCoord , yCoord; xCoord = (load.Node.Point.X - canvas.OriginOffsetX) / canvas.DpiX * factor * canvas.Scale; yCoord = (canvas.ActualHeight - load.Node.Point.Y - canvas.OriginOffsetY) / canvas.DpiY * factor * canvas.Scale; coords.Content = string.Format( "({0}, {1})" , Math.Round( xCoord , 2 ) , Math.Round( yCoord , 2 ) ); // set existing load values (if present) isLoadedX.IsChecked = xLoad.IsEnabled = load.IsLoadedX; xLoad.Text = string.Format( "{0}" , Math.Round( load.XLoad , 2 ) ); isLoadedY.IsChecked = yLoad.IsEnabled = load.IsLoadedY; yLoad.Text = string.Format( "{0}" , Math.Round( load.YLoad , 2 ) ); }
public GenAlgParamsDialog( Window owner ) { InitializeComponent(); this.Owner = owner; canvas = (SlopeCanvas) ((Grid) ((TabControl) ((Grid) this.Owner.Content).Children[2]).SelectedContent).Children[2]; population.Text = canvas.GeneticAlgorithmParameters.Population.ToString(); generations.Text = canvas.GeneticAlgorithmParameters.Generations.ToString(); fittest.Text = string.Format( "{0}" , Math.Round( canvas.GeneticAlgorithmParameters.FittestProportion , 3 ) ); mating.Text = string.Format( "{0}" , Math.Round( canvas.GeneticAlgorithmParameters.MatingPoolProportion , 3 ) ); crossover.Text = string.Format( "{0}" , Math.Round( canvas.GeneticAlgorithmParameters.CrossoverProbability , 3 ) ); mutation.Text = string.Format( "{0}" , Math.Round( canvas.GeneticAlgorithmParameters.MutationProbability , 3 ) ); slicewidth.Text = string.Format( "{0}" , Math.Round( canvas.GeneticAlgorithmParameters.SliceWidth , 2 ) ); string units; switch ( canvas.Units ) { case Units.Metres: units = "m"; break; case Units.Millimetres: units = "mm"; break; case Units.Feet: units = "ft"; break; default: units = "in"; break; } sliceUnits.Content = units; }
public SetFixityDialog( SlopeCanvas canvas , LineConstraint lc ) { InitializeComponent(); this.canvas = canvas; this.lc = lc; isFixedX.IsChecked = lc.IsFixedX; isFixedY.IsChecked = lc.IsFixedY; }
/// <summary> /// (Constructor) Adds various drawing Polygons. /// </summary> public SlopePlotCanvas( SlopeCanvas source ) { this.source = source; this.analysisType = source.AnalysisType; this.dpiX = source.DpiX; this.dpiY = source.DpiY; this.FilePath = source.FilePath; this.SizeChanged += new SizeChangedEventHandler( SlopePlotCanvas_SizeChanged ); // For zooming to a particular area zoomRect = new ZoomRect(); // Initialize material type list materialTypes = source.MaterialTypes; // Initialize list of FEA parameters feaParams = source.FEAParameters; // Initialize mesh substructs = new List<MaterialBlock>(); nodes = new List<feNode>(); deformedNodes = new List<feNode>(); triElements = new List<fe3NodedTriElement>(); deformedTriMesh = new List<fe3NodedTriElement>(); stressTriMesh = new List<fe3NodedTriElement>(); // Initialize disp vectors disp = new List<List<double>>(); dispVectors = new List<DisplacementVector>(); // Initialize plastic points plasticPoints = new List<PlasticPoint>(); // Initialize stress vectors sxxE = new List<double>(); syyE = new List<double>(); sxyE = new List<double>(); szzE = new List<double>(); fbarE = new List<double>(); sxxN = new List<double>(); syyN = new List<double>(); sxyN = new List<double>(); szzN = new List<double>(); fbarN = new List<double>(); // Intialize analysis phase selectedPhase = source.AnalysisPhases[1]; // Load mesh LoadNodeData(); LoadElementData(); }
/// <summary> /// Initializes the dialog box. /// </summary> public CustomScaleDialog( Window owner ) { InitializeComponent(); this.Owner = owner; if ( this.Owner is MainWindow ) { canvas = (SlopeCanvas) ((Grid) ((TabControl) ((Grid) this.Owner.Content).Children[2]).SelectedContent).Children[2]; scale.Text = string.Format( "{0}" , Math.Round( canvas.Scale , 2 ) ); } else if ( this.Owner is PlotResultsWindow ) { plotCanvas = (SlopePlotCanvas) ((Grid) ((PlotResultsWindow) this.Owner).contentGrid.Children[1]).Children[3]; scale.Text = string.Format( "{0}" , Math.Round( plotCanvas.Scale , 2 ) ); } }
public SetFixityDialog( SlopeCanvas canvas , DrawingPoint p ) { InitializeComponent(); this.canvas = canvas; this.p = p; isFixedX.IsChecked = p.IsFixedX; isFixedY.IsChecked = p.IsFixedY; List<LineConstraint> attachedLCs = new List<LineConstraint>(); canvas.MaterialBlocks.ForEach( delegate( MaterialBlock mb ) { attachedLCs.AddRange( mb.LineConstraints.FindAll( delegate( LineConstraint lc ) { return lc.Nodes.Contains( p ); } ) ); } ); attachedLCs.ForEach( delegate( LineConstraint lc ) { if ( lc.IsFixedX ) isFixedX.IsEnabled = false; if ( lc.IsFixedY ) isFixedY.IsEnabled = false; } ); attachedLCs.Clear(); }
public SlopeBoundary( SlopeCanvas canvas , Point[] pts ) { this.canvas = canvas; meshLines = new List<MeshLine>(); upperSurface = new List<Point>(); Boundary = new Polygon(); boundaryPoints = new List<DrawingPoint>(); Boundary.Stroke = Brushes.Black; Boundary.StrokeThickness = 1.5; Boundary.Fill = Brushes.White; Boundary.Opacity = 0.6; Boundary.MouseLeftButtonDown += new MouseButtonEventHandler( MouseLeftButtonDown ); Boundary.Visibility = Visibility.Visible; canvas.Children.Add( Boundary ); for ( int i = 0 ; i < pts.Length ; i++ ) { Boundary.Points.Add( pts[i] ); boundaryPoints.Add( new DrawingPoint( canvas , this , pts[i] ) ); } SortPoints(); }
public SlopeBoundary( SlopeCanvas canvas ) { this.canvas = canvas; meshLines = new List<MeshLine>(); upperSurface = new List<Point>(); Boundary = new Polygon(); boundaryPoints = new List<DrawingPoint>(); Boundary.Stroke = Brushes.Black; Boundary.StrokeThickness = 1.5; Boundary.Fill = Brushes.White; Boundary.Opacity = 0.6; Boundary.Visibility = Visibility.Visible; canvas.Children.Add( Boundary ); }
/// <summary> /// Constructor /// </summary> /// <param name="canvas">Parent drawing canvas</param> /// <param name="node">Parent node</param> /// <param name="isLoadedX">Is load applied in the horizontal direction?</param> /// <param name="xLoad">Value of horizontal load</param> /// <param name="isLoadedY">Is load applied in the vertical direction?</param> /// <param name="yLoad">Value of vertical load</param> public PointLoad( SlopeCanvas canvas , DrawingPoint node , bool isLoadedX , double xLoad , bool isLoadedY , double yLoad ) { // set parent drawing canvas this.canvas = canvas; // set parent node this.Node = node; // create plotting lines for constraints loadLines = new List<Polyline>(); Polyline newLine; for ( int i = 0 ; i < 6 ; i++ ) { newLine = new Polyline(); newLine.Visibility = Visibility.Hidden; newLine.Fill = Brushes.Blue; newLine.Opacity = 1.0; newLine.StrokeThickness = 1.75; newLine.Stroke = Brushes.Blue; newLine.Points.Add( new Point() ); newLine.Points.Add( new Point() ); loadLines.Add( newLine ); canvas.Children.Add( newLine ); newLine.MouseLeftButtonUp += new MouseButtonEventHandler( MouseLeftButtonUp ); } // set load state this.IsLoadedX = isLoadedX; if ( this.IsLoadedX ) this.XFactor = 1.0; this.XLoad = xLoad; this.IsLoadedY = isLoadedY; if ( this.IsLoadedY ) this.YFactor = 1.0; this.YLoad = yLoad; // Initialize analysis phase lists phaseActiveX = new List<bool>(); phaseActiveY = new List<bool>(); phaseFactorX = new List<double>(); phaseFactorY = new List<double>(); int numAnalysisPhases = canvas.AnalysisPhases.Count - 1; while ( phaseActiveX.Count < numAnalysisPhases ) { phaseActiveX.Add( isLoadedX ); phaseFactorX.Add( isLoadedX ? 1.0 : 0.0 ); phaseActiveY.Add( isLoadedY ); phaseFactorY.Add( isLoadedY ? 1.0 : 0.0 ); } // Add the point load to all blocks that contain its point List<MaterialBlock> parents = canvas.MaterialBlocks.FindAll( delegate( MaterialBlock mb ) { return mb.BoundaryPoints.Contains( node ); } ); foreach ( MaterialBlock pmb in parents ) { if ( !pmb.PointLoads.Contains( this ) ) pmb.PointLoads.Add( this ); } Update(); }
public MeshLine( SlopeCanvas canvas , double x ) { this.canvas = canvas; // initialize and pre-allocate for 10 MeshPoints per MeshLine and 2 per MaterialBlock meshPoints = new List<MeshPoint>( 10 ); List<MeshPoint> blockPoints = new List<MeshPoint>( 2 ); // for intersection finding algorithm double toler = 1e-5; double x1 , y1 , x2 , y2 , m = 0 , y = 0; //bool added; // loop through MaterialBlocks finding boundary intersection points foreach ( MaterialBlock mb in canvas.MaterialBlocks ) { // clear intersection point list (does not de-allocate memory) blockPoints.Clear(); // initialize trailing point to final point in list x1 = mb.Boundary.Points[mb.Boundary.Points.Count - 1].X; y1 = mb.Boundary.Points[mb.Boundary.Points.Count - 1].Y; // loop through MaterialBlock points, finding intersections foreach ( Point p in mb.Boundary.Points ) { x2 = p.X; // update leading point y2 = p.Y; // MeshLine will not intersect segment if ( x < Math.Min( x1 , x2 ) || x > Math.Max( x1 , x2 ) || Math.Abs( x2 - x1 ) < toler ) { x1 = x2; y1 = y2; // skip to next point continue; } // compute slope and y-coord of intersection if ( x2 > x1 ) { m = (y2 - y1) / (x2 - x1); y = y1 + m * (x - x1); } else { m = (y1 - y2) / (x1 - x2); y = y2 + m * (x - x2); } // add the intersection point if found blockPoints.Add( new MeshPoint( new Point( x , y ) , mb.Material ) ); x1 = x2; // update trailing point y1 = y2; } // sort points for labeling blockPoints.Sort( MeshPoint.CompareByY ); // label points as entering or exiting the block depending on order for ( int i = 0 ; i < blockPoints.Count ; i++ ) blockPoints[i].Type = i % 2 == 0 ? MeshPointType.Entrance : MeshPointType.Exit; // insert block points in y-order in MeshLine for ( int i = 0 ; i < meshPoints.Count ; i++ ) { if ( meshPoints[i].Y < blockPoints[0].Y ) { meshPoints.InsertRange( i , blockPoints.GetRange( 0 , 2 ) ); blockPoints.RemoveRange( 0 , 2 ); if ( blockPoints.Count <= 1 ) break; } } // insert remaining block points at end of MeshLine while ( blockPoints.Count > 1 ) { meshPoints.AddRange( blockPoints.GetRange( 0 , 2 ) ); blockPoints.RemoveRange( 0 , 2 ); } } line = new Line(); line.Stroke = Brushes.Black; line.StrokeThickness = 0.75; line.Opacity = 0.9; line.StrokeDashArray.Add( 7.5 ); line.StrokeDashArray.Add( 5 ); line.X1 = x; line.X2 = x; line.Y1 = meshPoints[0].Y; line.Y2 = meshPoints[meshPoints.Count - 1].Y; canvas.Children.Add( line ); for ( int i = 0 ; i < meshPoints.Count ; i++ ) canvas.Children.Add( meshPoints[i].Location ); }
public MaterialBlock( SlopeCanvas canvas , Point[] pts ) { if ( selectFill == null ) { Color selectColour = new Color(); selectColour = new Color(); selectColour.A = 20; selectColour.R = 200; selectColour.G = 0; selectColour.B = 0; selectFill = new SolidColorBrush( selectColour ); } this.canvas = canvas; Boundary = new Polygon(); boundaryPoints = new List<DrawingPoint>(); Boundary.Stroke = Brushes.Black; Boundary.StrokeThickness = 1.1; Boundary.StrokeLineJoin = PenLineJoin.Round; Boundary.StrokeStartLineCap = PenLineCap.Round; Boundary.StrokeEndLineCap = PenLineCap.Round; Boundary.Fill = Brushes.WhiteSmoke; Boundary.Opacity = 0.8; Boundary.MouseLeftButtonDown += new MouseButtonEventHandler( this.MouseLeftButtonDown ); Boundary.Visibility = Visibility.Visible; canvas.Children.Add( Boundary ); for ( int i = 0 ; i < pts.Length ; i++ ) { // check if point is same as existing point bool foundPoint = false; foreach ( MaterialBlock mb in canvas.MaterialBlocks ) { foreach ( DrawingPoint p in mb.BoundaryPoints ) { if ( (pts[i] - p.Point).Length < p.Dot.Width / 2 ) { Boundary.Points.Add( p.Point ); boundaryPoints.Add( p ); p.ParentBlocks.Add( this ); foundPoint = true; break; } } if ( foundPoint ) break; } if ( !foundPoint ) { Boundary.Points.Add( pts[i] ); boundaryPoints.Add( new DrawingPoint( canvas , this , pts[i] ) ); } } Material = new MaterialType(); lineConstraints = new List<LineConstraint>(); lineLoads = new List<LineLoad>(); pointLoads = new List<PointLoad>(); foreach ( MaterialBlock mb in canvas.MaterialBlocks ) { if ( mb == this ) continue; foreach ( LineConstraint lc in mb.LineConstraints ) { if ( this.BoundaryPoints.Contains( lc.Nodes[0] ) && this.BoundaryPoints.Contains( lc.Nodes[1] ) ) { if ( !this.LineConstraints.Contains( lc ) ) this.LineConstraints.Add( lc ); } } } phaseMaterials = new List<MaterialType>(); MaterialType nullMaterial = canvas.MaterialTypes[canvas.MaterialTypes.Count - 1]; int numAnalysisPhases = canvas.AnalysisPhases.Count - 1; while ( phaseMaterials.Count < numAnalysisPhases ) phaseMaterials.Add( nullMaterial ); SortPoints(); }
public void Delete(SlopeCanvas canvas) { AnalysisPhase nextPhase = canvas.AnalysisPhases.Find( delegate( AnalysisPhase ap ) { return ap.BeginPhase == this; } ); while ( nextPhase != null ) { nextPhase.Delete( canvas ); nextPhase = canvas.AnalysisPhases.Find( delegate( AnalysisPhase ap ) { return ap.BeginPhase == this; } ); } int phase = this.Number - 1; foreach ( MaterialBlock mb in canvas.MaterialBlocks ) { mb.PhaseMaterials.RemoveAt( phase ); int numPhases = mb.PhaseMaterials.Count; foreach ( DrawingPoint bp in mb.BoundaryPoints ) { if ( bp.PhaseFixActiveX.Count > numPhases ) { bp.PhaseFixActiveX.RemoveAt( phase ); bp.PhaseFixActiveY.RemoveAt( phase ); } } foreach ( LineConstraint lc in mb.LineConstraints ) { if ( lc.PhaseFixedX.Count > numPhases ) { lc.PhaseFixedX.RemoveAt( phase ); lc.PhaseFixedY.RemoveAt( phase ); } } foreach ( PointLoad pl in mb.PointLoads ) { if ( pl.PhaseActiveX.Count > numPhases ) { pl.PhaseActiveX.RemoveAt( phase ); pl.PhaseFactorX.RemoveAt( phase ); pl.PhaseActiveY.RemoveAt( phase ); pl.PhaseFactorY.RemoveAt( phase ); } } foreach ( LineLoad ll in mb.LineLoads ) { if ( ll.PhaseActiveN.Count >= numPhases ) { ll.PhaseActiveN.RemoveAt( phase ); ll.PhaseFactorN.RemoveAt( phase ); ll.PhaseActiveT.RemoveAt( phase ); ll.PhaseFactorT.RemoveAt( phase ); } } } canvas.AnalysisPhases.Remove( this ); }
public LineConstraint( SlopeCanvas canvas , DrawingPoint p1 , DrawingPoint p2 , bool fixX , bool fixY ) { // set parent drawing canvas this.canvas = canvas; // create list of boundary nodes for the constraint Nodes = new List<DrawingPoint>() { p1 , p2 }; // set constraints on boundary nodes Nodes[0].IsFixedX = fixX || Nodes[0].IsFixedX; Nodes[0].IsFixedY = fixY || Nodes[0].IsFixedY; Nodes[1].IsFixedX = fixX || Nodes[1].IsFixedX; Nodes[1].IsFixedY = fixY || Nodes[1].IsFixedY; // compute the point at which to plot the constraint MidPoint = new Point( 0.5 * (p1.Point.X + p2.Point.X) , 0.5 * (p1.Point.Y + p2.Point.Y) ); // create plotting lines for constraints fixLines = new List<Polyline>(); Polyline newLine; for ( int i = 0 ; i < 4 ; i++ ) { newLine = new Polyline(); newLine.Visibility = Visibility.Hidden; newLine.Fill = Brushes.Blue; newLine.Opacity = 1.0; newLine.StrokeThickness = 1.5; newLine.Stroke = Brushes.Blue; fixLines.Add( newLine ); canvas.Children.Add( newLine ); newLine.MouseLeftButtonUp += new MouseButtonEventHandler( MouseLeftButtonUp ); } fixLines[0].Points.Add( new Point( MidPoint.X - 7 , MidPoint.Y - 3.5 ) ); fixLines[0].Points.Add( new Point( MidPoint.X + 7 , MidPoint.Y - 3.5 ) ); fixLines[1].Points.Add( new Point( MidPoint.X - 7 , MidPoint.Y + 3.5 ) ); fixLines[1].Points.Add( new Point( MidPoint.X + 7 , MidPoint.Y + 3.5 ) ); fixLines[2].Points.Add( new Point( MidPoint.X - 3.5 , MidPoint.Y + 7 ) ); fixLines[2].Points.Add( new Point( MidPoint.X - 3.5 , MidPoint.Y - 7 ) ); fixLines[3].Points.Add( new Point( MidPoint.X + 3.5 , MidPoint.Y + 7 ) ); fixLines[3].Points.Add( new Point( MidPoint.X + 3.5 , MidPoint.Y - 7 ) ); phaseFixedX = new List<bool>(); phaseFixedY = new List<bool>(); int numAnalysisPhases = canvas.AnalysisPhases.Count - 1; while ( phaseFixedX.Count < numAnalysisPhases ) { phaseFixedX.Add( fixX ); phaseFixedY.Add( fixY ); } // Add the constraint to all blocks that contain both of its points List<MaterialBlock> parents = canvas.MaterialBlocks.FindAll( delegate( MaterialBlock mb ) { return mb.BoundaryPoints.Contains( p1 ) && mb.BoundaryPoints.Contains( p2 ); } ); foreach ( MaterialBlock pmb in parents ) { if ( !pmb.LineConstraints.Contains( this ) ) pmb.LineConstraints.Add( this ); } // set visibility of constraints this.IsFixedX = fixX; this.IsFixedY = fixY; }
public DisplayCircularSurface( SlopeCanvas canvas , Point enter , Point exit , double radius ) { this.canvas = canvas; surface = new System.Windows.Shapes.Path(); surface.Stroke = Brushes.Black; surface.StrokeThickness = 1; surface.Fill = Brushes.Transparent; surface.Opacity = 0.8; surface.StrokeDashArray.Add( 5 ); surface.StrokeDashArray.Add( 5 ); PathGeometry surfaceGeom = new PathGeometry(); surfaceGeom.FillRule = FillRule.Nonzero; surface.Data = surfaceGeom; surfaceFigure = new PathFigure(); surfaceFigure.StartPoint = enter; surfaceGeom.Figures.Add( surfaceFigure ); surfaceArc = new ArcSegment(); surfaceArc.Size = new Size( radius , radius ); surfaceArc.Point = exit; surfaceArc.SweepDirection = SweepDirection.Counterclockwise; surfaceArc.IsLargeArc = false; surfaceFigure.Segments.Add( surfaceArc ); canvas.Children.Add( surface ); }
public DefineAnalysisWindow( Window owner , SlopeCanvas canvas ) { InitializeComponent(); this.Owner = owner; this.canvas = canvas; materialTypes = canvas.MaterialTypes; // Create Grid to contain two axes, info block, and plotting canvas Grid inputGrid = new Grid(); inputGrid.HorizontalAlignment = HorizontalAlignment.Stretch; inputGrid.VerticalAlignment = VerticalAlignment.Stretch; inputGrid.Background = Brushes.WhiteSmoke; inputGrid.Margin = new Thickness( 0 , menuPanel.Height , 0 , 0 ); contentGrid.Children.Add( inputGrid ); // Some formatting constants double axisWidth = 55 , inputAreaWidth = 325 , progressBarWidth = 10 , buttonWidth = 60 , buttonOffset = 2.5 * buttonWidth; /* * Create coordinate axes */ // X-axis Grid xAxis = new Grid(); xAxis.ClipToBounds = true; xAxis.Background = Brushes.WhiteSmoke; xAxis.VerticalAlignment = VerticalAlignment.Bottom; xAxis.HorizontalAlignment = HorizontalAlignment.Stretch; xAxis.Margin = new Thickness( axisWidth , 0 , inputAreaWidth , progressBarWidth ); xAxis.Height = axisWidth; inputGrid.Children.Add( xAxis ); // Y-axis Grid yAxis = new Grid(); yAxis.ClipToBounds = true; yAxis.Background = Brushes.WhiteSmoke; yAxis.VerticalAlignment = VerticalAlignment.Stretch; yAxis.HorizontalAlignment = HorizontalAlignment.Left; yAxis.Margin = new Thickness( 0 , 0 , 0 , axisWidth + progressBarWidth ); yAxis.Width = axisWidth; inputGrid.Children.Add( yAxis ); /* * Create input area for analysis phase data */ // Parent = ScrollViewer ScrollViewer inputArea = new ScrollViewer(); inputArea.ClipToBounds = true; inputArea.Background = Brushes.WhiteSmoke; inputArea.VerticalAlignment = VerticalAlignment.Stretch; inputArea.HorizontalAlignment = HorizontalAlignment.Right; inputArea.Margin = new Thickness( 0 , 0 , 0 , progressBarWidth ); inputArea.Width = inputAreaWidth; inputGrid.Children.Add( inputArea ); // Parent.Content = Grid object for input Grid inputBlock = new Grid(); inputBlock.ClipToBounds = true; inputBlock.Background = Brushes.WhiteSmoke; inputBlock.VerticalAlignment = VerticalAlignment.Stretch; inputBlock.HorizontalAlignment = HorizontalAlignment.Stretch; inputBlock.Margin = new Thickness( 0 ); inputArea.Content = inputBlock; // Parent.Content.Children[0] = Border Border inputBlockBorder = new Border(); inputBlockBorder.BorderBrush = Brushes.DimGray; inputBlockBorder.VerticalAlignment = VerticalAlignment.Stretch; inputBlockBorder.HorizontalAlignment = HorizontalAlignment.Stretch; inputBlockBorder.BorderThickness = new Thickness( 1 ); inputBlockBorder.Margin = new Thickness( 0 ); inputBlock.Children.Add( inputBlockBorder ); // Parent.Content.Children[1] = Phase data GroupBox GroupBox phaseBox = new GroupBox(); phaseBox.Header = "Analysis Phase Data"; phaseBox.FontWeight = FontWeights.Bold; phaseBox.VerticalAlignment = VerticalAlignment.Top; phaseBox.HorizontalAlignment = HorizontalAlignment.Stretch; phaseBox.Margin = new Thickness( 15 , 30 , 15 , 0 ); phaseBox.Height = 250; inputBlock.Children.Add( phaseBox ); // Parent.Content.Children[1].Content = Grid for phase data GroupBox elements Grid phaseGrid = new Grid(); phaseGrid.VerticalAlignment = VerticalAlignment.Stretch; phaseGrid.HorizontalAlignment = HorizontalAlignment.Stretch; phaseGrid.Margin = new Thickness( 0 ); phaseBox.Content = phaseGrid; // Label for AnalysisPhase ComboBox Label phaseListLabel = new Label(); phaseListLabel.Content = "Phase:"; phaseListLabel.Height = 28; phaseListLabel.Width = 80; phaseListLabel.HorizontalContentAlignment = HorizontalAlignment.Right; phaseListLabel.HorizontalAlignment = HorizontalAlignment.Center; phaseListLabel.VerticalAlignment = VerticalAlignment.Center; phaseListLabel.Margin = new Thickness( -180 , -170 , 0 , 0 ); phaseListLabel.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( phaseListLabel ); // Name of selected AnalysisPhase phaseList = new ComboBox(); phaseList.Text = "Add new analysis phase..."; phaseList.Height = 23; phaseList.Width = 160; phaseList.HorizontalAlignment = HorizontalAlignment.Center; phaseList.VerticalAlignment = VerticalAlignment.Center; phaseList.Margin = new Thickness( 70 , -170 , 0 , 0 ); phaseList.FontWeight = FontWeights.Normal; phaseList.IsEditable = true; phaseList.SelectionChanged += new SelectionChangedEventHandler( phaseList_SelectionChanged ); phaseGrid.Children.Add( phaseList ); // Label for AnalysisPhase ComboBox Label beginPhaseLabel = new Label(); beginPhaseLabel.Content = "Begin From:"; beginPhaseLabel.Height = 28; beginPhaseLabel.Width = 80; beginPhaseLabel.HorizontalContentAlignment = HorizontalAlignment.Right; beginPhaseLabel.HorizontalAlignment = HorizontalAlignment.Center; beginPhaseLabel.VerticalAlignment = VerticalAlignment.Center; beginPhaseLabel.Margin = new Thickness( -180 , -110 , 0 , 0 ); beginPhaseLabel.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( beginPhaseLabel ); // Name of AnalysisPhase to begin from beginPhaseList = new ComboBox(); beginPhaseList.Height = 23; beginPhaseList.Width = 160; beginPhaseList.HorizontalAlignment = HorizontalAlignment.Center; beginPhaseList.VerticalAlignment = VerticalAlignment.Center; beginPhaseList.Margin = new Thickness( 70 , -110 , 0 , 0 ); beginPhaseList.FontWeight = FontWeights.Normal; beginPhaseList.IsEditable = false; beginPhaseList.SelectionChanged += new SelectionChangedEventHandler( beginPhaseList_SelectionChanged ); phaseGrid.Children.Add( beginPhaseList ); // CheckBox for reset displacements option resetDisplacements = new CheckBox(); resetDisplacements.Content = "Reset displacements to zero?"; resetDisplacements.Height = 23; resetDisplacements.Width = 180; resetDisplacements.HorizontalAlignment = HorizontalAlignment.Center; resetDisplacements.VerticalAlignment = VerticalAlignment.Center; resetDisplacements.HorizontalContentAlignment = HorizontalAlignment.Center; resetDisplacements.Margin = new Thickness( 0 , -50 , 0 , 0 ); resetDisplacements.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( resetDisplacements ); // Label for number of load steps Label loadStepsLabel = new Label(); loadStepsLabel.Content = "# Load Steps"; loadStepsLabel.Height = 28; loadStepsLabel.Width = 150; loadStepsLabel.HorizontalAlignment = HorizontalAlignment.Center; loadStepsLabel.VerticalAlignment = VerticalAlignment.Center; loadStepsLabel.HorizontalContentAlignment = HorizontalAlignment.Right; loadStepsLabel.Margin = new Thickness( -120 , 26 , 0 , 0 ); loadStepsLabel.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( loadStepsLabel ); // TextBox for number of load steps loadSteps = new TextBox(); loadSteps.Height = 23; loadSteps.Width = 90; loadSteps.HorizontalAlignment = HorizontalAlignment.Center; loadSteps.VerticalAlignment = VerticalAlignment.Center; loadSteps.Margin = new Thickness( 140 , 26 , 0 , 0 ); loadSteps.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( loadSteps ); // Label for number of iterations Label iterationsLabel = new Label(); iterationsLabel.Content = "# Iterations"; iterationsLabel.Height = 28; iterationsLabel.Width = 150; iterationsLabel.HorizontalAlignment = HorizontalAlignment.Center; iterationsLabel.VerticalAlignment = VerticalAlignment.Center; iterationsLabel.HorizontalContentAlignment = HorizontalAlignment.Right; iterationsLabel.Margin = new Thickness( -120 , 78 , 0 , 0 ); iterationsLabel.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( iterationsLabel ); // TextBox for number of iterations iterations = new TextBox(); iterations.Height = 23; iterations.Width = 90; iterations.HorizontalAlignment = HorizontalAlignment.Center; iterations.VerticalAlignment = VerticalAlignment.Center; iterations.Margin = new Thickness( 140 , 78 , 0 , 0 ); iterations.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( iterations ); // Label for number of load steps/print line Label printLinesLabel = new Label(); printLinesLabel.Content = "# Load Steps / Print Line"; printLinesLabel.Height = 28; printLinesLabel.Width = 150; printLinesLabel.HorizontalAlignment = HorizontalAlignment.Center; printLinesLabel.VerticalAlignment = VerticalAlignment.Center; printLinesLabel.HorizontalContentAlignment = HorizontalAlignment.Right; printLinesLabel.Margin = new Thickness( -120 , 132 , 0 , 0 ); printLinesLabel.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( printLinesLabel ); // TextBox for number of load steps/print line printLines = new TextBox(); printLines.Height = 23; printLines.Width = 90; printLines.HorizontalAlignment = HorizontalAlignment.Center; printLines.VerticalAlignment = VerticalAlignment.Center; printLines.Margin = new Thickness( 140 , 132 , 0 , 0 ); printLines.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( printLines ); // Label for gravity factor Label gravityLabel = new Label(); gravityLabel.Content = "Gravity Factor"; gravityLabel.Height = 28; gravityLabel.Width = 150; gravityLabel.HorizontalAlignment = HorizontalAlignment.Center; gravityLabel.VerticalAlignment = VerticalAlignment.Center; gravityLabel.HorizontalContentAlignment = HorizontalAlignment.Right; gravityLabel.Margin = new Thickness( -120 , 184 , 0 , 0 ); gravityLabel.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( gravityLabel ); // TextBox for gravity factor gravityFactor = new TextBox(); gravityFactor.Height = 23; gravityFactor.Width = 90; gravityFactor.HorizontalAlignment = HorizontalAlignment.Center; gravityFactor.VerticalAlignment = VerticalAlignment.Center; gravityFactor.Margin = new Thickness( 140 , 184 , 0 , 0 ); gravityFactor.FontWeight = FontWeights.Normal; phaseGrid.Children.Add( gravityFactor ); /* * Initialize analysis phase parameters */ for ( int i = 1 ; i < canvas.AnalysisPhases.Count ; i++ ) { phaseList.Items.Add( canvas.AnalysisPhases[i] ); } for ( int i = 0 ; i < canvas.AnalysisPhases.Count ; i++ ) { beginPhaseList.Items.Add( canvas.AnalysisPhases[i] ); } /* * MaterialType selection data */ // Parent.Content.Children[2] = MaterialType GroupBox GroupBox materialBox = new GroupBox(); materialBox.Header = "Assign Materials"; materialBox.FontWeight = FontWeights.Bold; materialBox.VerticalAlignment = VerticalAlignment.Top; materialBox.HorizontalAlignment = HorizontalAlignment.Stretch; materialBox.Margin = new Thickness( 15 , phaseBox.Margin.Top + phaseBox.Height + 30 , 15 , 0 ); materialBox.Height = 300; inputBlock.Children.Add( materialBox ); // Parent.Content.Children[2].Content = Grid for MaterialType GroupBox elements Grid materialGrid = new Grid(); materialGrid.VerticalAlignment = VerticalAlignment.Stretch; materialGrid.HorizontalAlignment = HorizontalAlignment.Stretch; materialGrid.Margin = new Thickness( 0 ); materialBox.Content = materialGrid; // Fill colour for selected MaterialType materialFill = new Rectangle(); materialFill.Height = 20; materialFill.Width = 30; materialFill.HorizontalAlignment = HorizontalAlignment.Center; materialFill.VerticalAlignment = VerticalAlignment.Center; materialFill.Margin = new Thickness( -180 , -220 , 0 , 0 ); materialFill.Stroke = Brushes.Black; materialFill.StrokeThickness = 1.5; materialFill.Fill = Brushes.Transparent; materialGrid.Children.Add( materialFill ); // Name of selected MaterialType materialList = new ComboBox(); materialList.Height = 23; materialList.Width = 150; materialList.HorizontalAlignment = HorizontalAlignment.Center; materialList.VerticalAlignment = VerticalAlignment.Center; materialList.Margin = new Thickness( 50 , -220 , 0 , 0 ); materialList.FontWeight = FontWeights.Normal; materialList.IsEditable = true; materialList.SelectionChanged += new SelectionChangedEventHandler( materialList_SelectionChanged ); materialGrid.Children.Add( materialList ); // Angle of friction // Property Name Label phiLabel = new Label(); phiLabel.Content = "Angle of Friction"; phiLabel.Height = 28; phiLabel.Width = 100; phiLabel.HorizontalContentAlignment = HorizontalAlignment.Right; phiLabel.HorizontalAlignment = HorizontalAlignment.Center; phiLabel.VerticalAlignment = VerticalAlignment.Center; phiLabel.Margin = new Thickness( -160 , -125 , 0 , 0 ); phiLabel.FontWeight = FontWeights.Normal; materialGrid.Children.Add( phiLabel ); // Property Value phiValue = new TextBlock(); phiValue.Height = 23; phiValue.Width = 90; phiValue.Text = "test........................................................"; phiValue.HorizontalAlignment = HorizontalAlignment.Center; phiValue.VerticalAlignment = VerticalAlignment.Center; phiValue.Margin = new Thickness( 45 , -125 , 0 , 0 ); phiValue.FontWeight = FontWeights.Normal; materialGrid.Children.Add( phiValue ); // Property Units phiUnits = new Label(); phiUnits.Content = "deg"; phiUnits.Height = 28; phiUnits.Width = 55; phiUnits.HorizontalContentAlignment = HorizontalAlignment.Left; phiUnits.HorizontalAlignment = HorizontalAlignment.Center; phiUnits.VerticalAlignment = VerticalAlignment.Center; phiUnits.Margin = new Thickness( 220 , -125 , 0 , 0 ); phiUnits.FontWeight = FontWeights.Normal; materialGrid.Children.Add( phiUnits ); // Cohesion // Property Name Label cohLabel = new Label(); cohLabel.Content = "Cohesion"; cohLabel.Height = 28; cohLabel.Width = 100; cohLabel.HorizontalContentAlignment = HorizontalAlignment.Right; cohLabel.HorizontalAlignment = HorizontalAlignment.Center; cohLabel.VerticalAlignment = VerticalAlignment.Center; cohLabel.Margin = new Thickness( -160 , -75 , 0 , 0 ); cohLabel.FontWeight = FontWeights.Normal; materialGrid.Children.Add( cohLabel ); // Property Value cohValue = new TextBlock(); cohValue.Height = 23; cohValue.Width = 90; cohValue.Text = "test..............................................................................."; cohValue.HorizontalAlignment = HorizontalAlignment.Center; cohValue.VerticalAlignment = VerticalAlignment.Center; cohValue.Margin = new Thickness( 45 , -75 , 0 , 0 ); cohValue.FontWeight = FontWeights.Normal; materialGrid.Children.Add( cohValue ); // Property Units cohUnits = new Label(); cohUnits.Content = "kPa"; cohUnits.Height = 28; cohUnits.Width = 55; cohUnits.HorizontalContentAlignment = HorizontalAlignment.Left; cohUnits.HorizontalAlignment = HorizontalAlignment.Center; cohUnits.VerticalAlignment = VerticalAlignment.Center; cohUnits.Margin = new Thickness( 220 , -75 , 0 , 0 ); cohUnits.FontWeight = FontWeights.Normal; materialGrid.Children.Add( cohUnits ); // Dilatancy angle // Property Name Label psiLabel = new Label(); psiLabel.Content = "Dilatancy Angle"; psiLabel.Height = 28; psiLabel.Width = 100; psiLabel.HorizontalContentAlignment = HorizontalAlignment.Right; psiLabel.HorizontalAlignment = HorizontalAlignment.Center; psiLabel.VerticalAlignment = VerticalAlignment.Center; psiLabel.Margin = new Thickness( -160 , -25 , 0 , 0 ); psiLabel.FontWeight = FontWeights.Normal; materialGrid.Children.Add( psiLabel ); // Property Value psiValue = new TextBlock(); psiValue.Height = 23; psiValue.Width = 90; psiValue.Text = "test..............................................................................."; psiValue.HorizontalAlignment = HorizontalAlignment.Center; psiValue.VerticalAlignment = VerticalAlignment.Center; psiValue.Margin = new Thickness( 45 , -25 , 0 , 0 ); psiValue.FontWeight = FontWeights.Normal; materialGrid.Children.Add( psiValue ); // Property Units psiUnits = new Label(); psiUnits.Content = "deg"; psiUnits.Height = 28; psiUnits.Width = 55; psiUnits.HorizontalContentAlignment = HorizontalAlignment.Left; psiUnits.HorizontalAlignment = HorizontalAlignment.Center; psiUnits.VerticalAlignment = VerticalAlignment.Center; psiUnits.Margin = new Thickness( 220 , -25 , 0 , 0 ); psiUnits.FontWeight = FontWeights.Normal; materialGrid.Children.Add( psiUnits ); // Unit weight // Property Name Label gammaLabel = new Label(); gammaLabel.Content = "Unit Weight"; gammaLabel.Height = 28; gammaLabel.Width = 100; gammaLabel.HorizontalContentAlignment = HorizontalAlignment.Right; gammaLabel.HorizontalAlignment = HorizontalAlignment.Center; gammaLabel.VerticalAlignment = VerticalAlignment.Center; gammaLabel.Margin = new Thickness( -160 , 25 , 0 , 0 ); gammaLabel.FontWeight = FontWeights.Normal; materialGrid.Children.Add( gammaLabel ); // Property Value gammaValue = new TextBlock(); gammaValue.Height = 23; gammaValue.Width = 90; gammaValue.Text = "test..............................................................................."; gammaValue.HorizontalAlignment = HorizontalAlignment.Center; gammaValue.VerticalAlignment = VerticalAlignment.Center; gammaValue.Margin = new Thickness( 45 , 25 , 0 , 0 ); gammaValue.FontWeight = FontWeights.Normal; materialGrid.Children.Add( gammaValue ); // Property Units gammaUnits = new Label(); gammaUnits.Content = "kN/m^3"; gammaUnits.Height = 28; gammaUnits.Width = 55; gammaUnits.HorizontalContentAlignment = HorizontalAlignment.Left; gammaUnits.HorizontalAlignment = HorizontalAlignment.Center; gammaUnits.VerticalAlignment = VerticalAlignment.Center; gammaUnits.Margin = new Thickness( 220 , 25 , 0 , 0 ); gammaUnits.FontWeight = FontWeights.Normal; materialGrid.Children.Add( gammaUnits ); // Elastic modulus // Property Name Label emodLabel = new Label(); emodLabel.Content = "Elastic Modulus"; emodLabel.Height = 28; emodLabel.Width = 100; emodLabel.HorizontalContentAlignment = HorizontalAlignment.Right; emodLabel.HorizontalAlignment = HorizontalAlignment.Center; emodLabel.VerticalAlignment = VerticalAlignment.Center; emodLabel.Margin = new Thickness( -160 , 75 , 0 , 0 ); emodLabel.FontWeight = FontWeights.Normal; materialGrid.Children.Add( emodLabel ); // Property Value emodValue = new TextBlock(); emodValue.Height = 23; emodValue.Width = 90; emodValue.Text = "test..............................................................................."; emodValue.HorizontalAlignment = HorizontalAlignment.Center; emodValue.VerticalAlignment = VerticalAlignment.Center; emodValue.Margin = new Thickness( 45 , 75 , 0 , 0 ); emodValue.FontWeight = FontWeights.Normal; materialGrid.Children.Add( emodValue ); // Property Units emodUnits = new Label(); emodUnits.Content = "kPa"; emodUnits.Height = 28; emodUnits.Width = 55; emodUnits.HorizontalContentAlignment = HorizontalAlignment.Left; emodUnits.HorizontalAlignment = HorizontalAlignment.Center; emodUnits.VerticalAlignment = VerticalAlignment.Center; emodUnits.Margin = new Thickness( 220 , 75 , 0 , 0 ); emodUnits.FontWeight = FontWeights.Normal; materialGrid.Children.Add( emodUnits ); // Poisson's ratio // Property Name Label nuLabel = new Label(); nuLabel.Content = "Poisson's Ratio"; nuLabel.Height = 28; nuLabel.Width = 100; nuLabel.HorizontalContentAlignment = HorizontalAlignment.Right; nuLabel.HorizontalAlignment = HorizontalAlignment.Center; nuLabel.VerticalAlignment = VerticalAlignment.Center; nuLabel.Margin = new Thickness( -160 , 125 , 0 , 0 ); nuLabel.FontWeight = FontWeights.Normal; materialGrid.Children.Add( nuLabel ); // Property Value nuValue = new TextBlock(); nuValue.Height = 23; nuValue.Width = 90; nuValue.Text = "test..............................................................................."; nuValue.HorizontalAlignment = HorizontalAlignment.Center; nuValue.VerticalAlignment = VerticalAlignment.Center; nuValue.Margin = new Thickness( 45 , 125 , 0 , 0 ); nuValue.FontWeight = FontWeights.Normal; materialGrid.Children.Add( nuValue ); // Button for setting selected blocks to selected MaterialType Button setSelectedButton = new Button(); setSelectedButton.Content = "Set Selected"; setSelectedButton.FontWeight = FontWeights.Normal; setSelectedButton.Height = 23; setSelectedButton.Width = 150; setSelectedButton.VerticalAlignment = VerticalAlignment.Center; setSelectedButton.HorizontalAlignment = HorizontalAlignment.Center; setSelectedButton.Margin = new Thickness( 0 , 220 , 0 , 0 ); setSelectedButton.Click += new RoutedEventHandler( setSelectedButton_Click ); materialGrid.Children.Add( setSelectedButton ); /* * Initialize list of MaterialTypes */ canvas.MaterialTypes.ForEach( delegate( MaterialType mt ) { materialList.Items.Add( mt ); } ); materialList.SelectedIndex = 0; switch ( canvas.Units ) { case Units.Metres: cohUnits.Content = emodUnits.Content = "kPa"; gammaUnits.Content = "kN/m^3"; break; case Units.Millimetres: cohUnits.Content = emodUnits.Content = "kPa"; gammaUnits.Content = "kN/m^3"; break; case Units.Feet: cohUnits.Content = emodUnits.Content = "psi"; gammaUnits.Content = "pcf"; break; default: cohUnits.Content = emodUnits.Content = "psi"; gammaUnits.Content = "pcf"; break; } /* * Analysis Phase buttons */ // Parent.Content.Children[3] = Add button add = new Button(); add.Content = "Add"; add.Height = 23; add.Width = buttonWidth; add.VerticalAlignment = VerticalAlignment.Top; add.HorizontalAlignment = HorizontalAlignment.Center; add.Margin = new Thickness( -buttonOffset , materialBox.Margin.Top + materialBox.Height + 30 , 0 , 15 ); add.Click += new RoutedEventHandler( add_Click ); inputBlock.Children.Add( add ); // Parent.Content.Children[4] = Modify button modify = new Button(); modify.Content = "Modify"; modify.Height = 23; modify.Width = buttonWidth; modify.VerticalAlignment = VerticalAlignment.Top; modify.HorizontalAlignment = HorizontalAlignment.Center; modify.Margin = new Thickness( 0 , add.Margin.Top , 0 , 15 ); modify.Click += new RoutedEventHandler( modify_Click ); modify.IsEnabled = false; inputBlock.Children.Add( modify ); // Parent.Content.Children[5] = Delete button delete = new Button(); delete.Content = "Delete"; delete.Height = 23; delete.Width = buttonWidth; delete.VerticalAlignment = VerticalAlignment.Top; delete.HorizontalAlignment = HorizontalAlignment.Center; delete.Margin = new Thickness( buttonOffset , add.Margin.Top , 0 , 15 ); delete.Click += new RoutedEventHandler( delete_Click ); delete.IsEnabled = false; inputBlock.Children.Add( delete ); /* * Create SlopeDefineCanvas object for drawing surface */ inputCanvas = new SlopeDefineCanvas( canvas ); inputCanvas.Background = Brushes.White; inputCanvas.VerticalAlignment = VerticalAlignment.Stretch; inputCanvas.HorizontalAlignment = HorizontalAlignment.Stretch; inputCanvas.Margin = new Thickness( axisWidth , 0 , inputAreaWidth , axisWidth + progressBarWidth ); inputCanvas.InitializeCanvas(); inputGrid.Children.Add( inputCanvas ); }
public PlotResultsWindow( Window owner , SlopeCanvas canvas ) { InitializeComponent(); this.Owner = owner; this.canvas = canvas; // Create Grid to contain two axes, info block, and plotting canvas Grid plottingGrid = new Grid(); plottingGrid.HorizontalAlignment = HorizontalAlignment.Stretch; plottingGrid.VerticalAlignment = VerticalAlignment.Stretch; plottingGrid.Background = Brushes.WhiteSmoke; plottingGrid.Margin = new Thickness( 0 , menuPanel.Height , 0 , 0 ); contentGrid.Children.Add( plottingGrid ); double axisWidth = 55 , infoBlockWidth = 250 , progressBarWidth = 10 , logoSize = 128 , leftAlign = 30 , textBlockWidth = 200 , textBlockHeight = 25 , textAreaTop = 125, fontSize = 12; // Create Grid object for x axis Grid xAxis = new Grid(); xAxis.ClipToBounds = true; xAxis.Background = Brushes.WhiteSmoke; xAxis.VerticalAlignment = VerticalAlignment.Bottom; xAxis.HorizontalAlignment = HorizontalAlignment.Stretch; xAxis.Margin = new Thickness( axisWidth , 0 , infoBlockWidth , progressBarWidth ); xAxis.Height = axisWidth; plottingGrid.Children.Add( xAxis ); // Create Grid object for y axis Grid yAxis = new Grid(); yAxis.ClipToBounds = true; yAxis.Background = Brushes.WhiteSmoke; yAxis.VerticalAlignment = VerticalAlignment.Stretch; yAxis.HorizontalAlignment = HorizontalAlignment.Left; yAxis.Margin = new Thickness( 0 , 0 , 0 , axisWidth + progressBarWidth ); yAxis.Width = axisWidth; plottingGrid.Children.Add( yAxis ); // Create Grid object for plotting info Grid infoBlock = new Grid(); infoBlock.ClipToBounds = true; infoBlock.Background = Brushes.WhiteSmoke; infoBlock.VerticalAlignment = VerticalAlignment.Stretch; infoBlock.HorizontalAlignment = HorizontalAlignment.Right; infoBlock.Margin = new Thickness( 0 , 0 , 0 , progressBarWidth ); infoBlock.Width = infoBlockWidth; plottingGrid.Children.Add( infoBlock ); // Add plotting elements to infoBlock // CHILD 0 = Border Border infoBlockBorder = new Border(); infoBlockBorder.BorderBrush = Brushes.DimGray; infoBlockBorder.VerticalAlignment = VerticalAlignment.Stretch; infoBlockBorder.HorizontalAlignment = HorizontalAlignment.Stretch; infoBlockBorder.BorderThickness = new Thickness( 1 ); infoBlockBorder.Margin = new Thickness( 0 ); infoBlock.Children.Add( infoBlockBorder ); Image infoBlockLogo = new Image(); // CHILD 1 = Logo infoBlockLogo.Height = 128; infoBlockLogo.Width = 128; infoBlockLogo.HorizontalAlignment = HorizontalAlignment.Center; infoBlockLogo.VerticalAlignment = VerticalAlignment.Top; infoBlockLogo.Margin = new Thickness( 0 , Math.Max( (infoBlockWidth - logoSize) / 2 - 10 , 0 ) , 0 , 0 ); BitmapImage logo = new BitmapImage(); logo.BeginInit(); logo.UriSource = new Uri( "/Slope;component/icons/SlopePlotLogo.ico" , UriKind.Relative ); logo.EndInit(); infoBlockLogo.Stretch = Stretch.Fill; infoBlockLogo.Source = logo; infoBlock.Children.Add( infoBlockLogo ); TextBlock infoBlockTitle = new TextBlock(); // CHILD 2 = Program Name infoBlockTitle.Height = textBlockHeight; infoBlockTitle.Width = textBlockWidth; infoBlockTitle.HorizontalAlignment = HorizontalAlignment.Center; infoBlockTitle.VerticalAlignment = VerticalAlignment.Top; infoBlockTitle.Margin = new Thickness( 0 , infoBlockLogo.Margin.Top + logoSize , 0 , 0 ); infoBlockTitle.TextAlignment = TextAlignment.Center; infoBlockTitle.FontSize = 18; infoBlockTitle.FontWeight = FontWeights.DemiBold; infoBlockTitle.FontFamily = new FontFamily( "Consolas, Arial" ); infoBlockTitle.Text = "SlopeFEA 2011"; infoBlock.Children.Add( infoBlockTitle ); TextBlock projectTitle = new TextBlock(); // CHILD 3 = Project Title projectTitle.Height = textBlockHeight; projectTitle.Width = textBlockWidth; projectTitle.HorizontalAlignment = HorizontalAlignment.Left; projectTitle.VerticalAlignment = VerticalAlignment.Bottom; projectTitle.Margin = new Thickness( leftAlign , 0 , 0 , textAreaTop ); projectTitle.TextAlignment = TextAlignment.Left; projectTitle.FontSize = fontSize; projectTitle.FontWeight = FontWeights.Normal; projectTitle.FontFamily = infoBlockTitle.FontFamily; string[] pt = canvas.FilePath.Split( new char[] { '\\' , '.' } , StringSplitOptions.RemoveEmptyEntries ); projectTitle.Text = "Project: " + pt[pt.Length - 2]; infoBlock.Children.Add( projectTitle ); TextBlock projectDate = new TextBlock(); // CHILD 4 = Date projectDate.Height = textBlockHeight; projectDate.Width = textBlockWidth; projectDate.HorizontalAlignment = HorizontalAlignment.Left; projectDate.VerticalAlignment = VerticalAlignment.Bottom; projectDate.Margin = new Thickness( leftAlign , 0 , 0 , projectTitle.Margin.Bottom - textBlockHeight ); projectDate.TextAlignment = TextAlignment.Left; projectDate.FontSize = fontSize; projectDate.FontWeight = FontWeights.Normal; projectDate.FontFamily = infoBlockTitle.FontFamily; DateTime now = DateTime.Now; projectDate.Text = "Date: " + now.Day.ToString() + "\\" + now.Month.ToString() + "\\" + now.Year.ToString(); infoBlock.Children.Add( projectDate ); TextBlock projectAuthor = new TextBlock(); // CHILD 5 = Author projectAuthor.Height = textBlockHeight; projectAuthor.Width = textBlockWidth; projectAuthor.HorizontalAlignment = HorizontalAlignment.Left; projectAuthor.VerticalAlignment = VerticalAlignment.Bottom; projectAuthor.Margin = new Thickness( leftAlign , 0 , 0 , projectDate.Margin.Bottom - textBlockHeight ); projectAuthor.TextAlignment = TextAlignment.Left; projectAuthor.FontSize = fontSize; projectAuthor.FontWeight = FontWeights.Normal; projectAuthor.FontFamily = infoBlockTitle.FontFamily; projectAuthor.Text = "Author:"; infoBlock.Children.Add( projectAuthor ); TextBlock plotScale = new TextBlock(); // CHILD 6 = Scale plotScale.Height = textBlockHeight; plotScale.Width = textBlockWidth; plotScale.HorizontalAlignment = HorizontalAlignment.Left; plotScale.VerticalAlignment = VerticalAlignment.Bottom; plotScale.Margin = new Thickness( leftAlign , 0 , 0 , projectAuthor.Margin.Bottom - textBlockHeight ); plotScale.TextAlignment = TextAlignment.Left; plotScale.FontSize = fontSize; plotScale.FontWeight = FontWeights.Normal; plotScale.FontFamily = infoBlockTitle.FontFamily; plotScale.Text = "Scale:"; infoBlock.Children.Add( plotScale ); TextBlock plotMag = new TextBlock(); // CHILD 7 = Magnification plotMag.Height = textBlockHeight; plotMag.Width = textBlockWidth; plotMag.HorizontalAlignment = HorizontalAlignment.Left; plotMag.VerticalAlignment = VerticalAlignment.Bottom; plotMag.Margin = new Thickness( leftAlign , 0 , 0 , plotScale.Margin.Bottom - textBlockHeight ); plotMag.TextAlignment = TextAlignment.Left; plotMag.FontSize = fontSize; plotMag.FontWeight = FontWeights.Normal; plotMag.FontFamily = infoBlockTitle.FontFamily; plotMag.Text = "Magnification:"; infoBlock.Children.Add( plotMag ); // Create SlopePlotCanvas object for drawing surface SlopePlotCanvas drawingCanvas = new SlopePlotCanvas( canvas ); drawingCanvas.Background = Brushes.White; drawingCanvas.VerticalAlignment = VerticalAlignment.Stretch; drawingCanvas.HorizontalAlignment = HorizontalAlignment.Stretch; drawingCanvas.Margin = new Thickness( axisWidth , 0 , infoBlockWidth , axisWidth + progressBarWidth ); drawingCanvas.InitializeCanvas(); plottingGrid.Children.Add( drawingCanvas ); // Add analysis phase information to menu MenuItem phaseItem; for ( int i = 1 ; i < canvas.AnalysisPhases.Count ; i++ ) { phaseItem = new MenuItem(); phaseItem.Header = canvas.AnalysisPhases[i]; phaseItem.Click += new RoutedEventHandler( phaseItem_Click ); phaseMenu.Items.Add( phaseItem ); } ((MenuItem) phaseMenu.Items[0]).IsChecked = true; }
private static double GenAlg( SlopeCanvas canvas , BackgroundWorker worker , DoWorkEventArgs e ) { // Set the delegate function for evaluating the factor of safety EvaluateSafetyFactor evalSF = null; switch ( canvas.AnalysisType ) { case AnalysisType.Bishop: evalSF += Bishop; break; default: evalSF += RFEM; break; } // Get material data List<MaterialType> materialTypes = new List<MaterialType>(); MaterialType copyMaterial; for ( int i = 0 ; i < canvas.MaterialTypes.Count ; i++ ) { copyMaterial = new MaterialType(); copyMaterial.Phi = canvas.MaterialTypes[i].Phi; copyMaterial.Cohesion = canvas.MaterialTypes[i].Cohesion; copyMaterial.Gamma = canvas.MaterialTypes[i].Gamma; copyMaterial.Emod = canvas.MaterialTypes[i].Emod; copyMaterial.Nu = canvas.MaterialTypes[i].Nu; copyMaterial.Name = canvas.MaterialTypes[i].Name; if ( canvas.AnalysisType == AnalysisType.RFEM ) copyMaterial.ComputeRFEMProperties(); materialTypes.Add( copyMaterial ); } double angleFactor = Math.PI / 180.0; double lengthFactor; double cohFactor = 1.0 , gammaFactor = 1.0; switch ( canvas.Units ) { case Units.Metres: lengthFactor = 0.0254; break; case Units.Millimetres: lengthFactor = 25.4; cohFactor /= Math.Pow( 1000 , 2 ); gammaFactor /= Math.Pow( 1000 , 3 ); break; case Units.Feet: lengthFactor = 1.0 / 12.0; cohFactor *= Math.Pow( 12 , 2 ); break; default: lengthFactor = 1.0; gammaFactor /= Math.Pow( 12 , 3 ); break; } for ( int i = 0 ; i < materialTypes.Count ; i++ ) { materialTypes[i].Phi *= angleFactor; materialTypes[i].Cohesion *= cohFactor; materialTypes[i].Gamma *= gammaFactor; } // Load upper surface and mesh string[] split = canvas.FilePath.Split( '.' ); if ( split[split.Length - 1] != "slp" ) { MessageBox.Show( "Input file format incorrect. Input data must be in a *.slp file." , "Error" ); return 0; } split[split.Length - 1] = "msh"; string path = string.Join( "." , split ); if ( !File.Exists( path ) ) { MessageBox.Show( "Could not find mesh data file." , "Error" ); return 0; } Units meshUnits; List<Point> surface = new List<Point>(); List<List<AnalysisMeshPoint>> mesh = new List<List<AnalysisMeshPoint>>(); List<AnalysisMeshPoint> line; try { using ( TextReader tr = new StreamReader( path ) ) { // Read in actual units string units = tr.ReadLine().Split( new char[] { '=' , ' ' } , StringSplitOptions.RemoveEmptyEntries )[1]; switch ( units ) { case "m": meshUnits = Units.Metres; break; case "mm": meshUnits = Units.Millimetres; break; case "ft": meshUnits = Units.Feet; break; default: meshUnits = Units.Inches; break; } // Check that canvas and mesh files have same units if ( canvas.Units != meshUnits ) { MessageBox.Show( "Units mismatch. Mesh file must have same units as input file." , "Error" ); return 0; } tr.ReadLine(); // Get number of upper surface points int count = int.Parse( tr.ReadLine().Split( '=' )[1] ); tr.ReadLine(); tr.ReadLine(); // Read in units and add to surface point list for ( int i = 0 ; i < count ; i++ ) { split = tr.ReadLine().Split( ',' ); surface.Add( new Point( double.Parse( split[0] ) , double.Parse( split[1] ) ) ); } tr.ReadLine(); // Get number of mesh lines count = int.Parse( tr.ReadLine().Split( '=' )[1] ); tr.ReadLine(); int pointCount; string type , material; MeshPointType mpType; MaterialType matType = null; for ( int i = 0 ; i < count ; i++ ) { // Create new list for points in current mesh line line = new List<AnalysisMeshPoint>(); tr.ReadLine(); // Get number of points in current mesh line pointCount = int.Parse( tr.ReadLine().Split( '=' )[1] ); for ( int j = 0 ; j < pointCount ; j++ ) { // Read data for current point split = tr.ReadLine().Split( ',' ); // Get point type (entrance or exit from material block) type = split[2].Split( new char[] { ' ' } , StringSplitOptions.RemoveEmptyEntries )[0]; switch ( type ) { case "Entrance": mpType = MeshPointType.Entrance; break; default: mpType = MeshPointType.Exit; break; } // Get material type name and find the corresponding material from the list material = split[3].Split( '\"' )[1]; matType = materialTypes.Find( delegate( MaterialType mt ) { return mt.Name == material; } ); // Add this point to the list of points for the current mesh line line.Add( new AnalysisMeshPoint( new Point( double.Parse( split[0] ) , double.Parse( split[1] ) ) , matType , mpType ) ); } mesh.Add( line ); tr.ReadLine(); } } } catch { MessageBox.Show( "Error in reading mesh file. Make sure it is formatted correctly." , "Error" ); return 0; } // Get genetic algorithm parameters int population = canvas.GeneticAlgorithmParameters.Population; int generations = canvas.GeneticAlgorithmParameters.Generations; double fittestProp = canvas.GeneticAlgorithmParameters.FittestProportion; double matingProp = canvas.GeneticAlgorithmParameters.MatingPoolProportion; double crossProb = canvas.GeneticAlgorithmParameters.CrossoverProbability; double mutProb = canvas.GeneticAlgorithmParameters.MutationProbability; // For reporting progress int numberOfEvaluations = population * generations; // Compute additional genetic algorithm parameters int fittest = (int) Math.Ceiling( fittestProp * population ); int parents = population - fittest; fittest += parents % 2; parents = population - fittest; int mating = (int) Math.Ceiling( matingProp * population ); int dof = 3; int mutations = (int) Math.Ceiling( mutProb * (population - fittest) * dof ); List<double> radiusBreaks = FindRadiusBreaks( surface ); double yBoundMin = canvas.Boundary.YMin; yBoundMin = ((canvas.ActualHeight - yBoundMin) - canvas.OriginOffsetY) / canvas.DpiY * lengthFactor * canvas.Scale; SoilMovement soilDirection = canvas.Boundary.SoilDirection; List<CircularSurface> currentSolutions = new List<CircularSurface>(); List<CircularSurface> masterSolutions = new List<CircularSurface>(); List<CircularSurface> matingPool = new List<CircularSurface>(); List<double> parentSelectors = new List<double>(); // Generate initial random population of failure surfaces while ( currentSolutions.Count < population ) { currentSolutions.Insert( 0 , new CircularSurface( surface , yBoundMin , radiusBreaks , soilDirection ) ); currentSolutions[0].GenerateSurface(); } bool foundTwin; double xdiff , ydiff , rdiff; double toler = 1e-5; int progressCount = 1; int percentComplete; double upperSF , totalWeight; for ( int igen = 0 ; igen < generations ; igen++ ) { for ( int isoln = 0 ; isoln < currentSolutions.Count ; isoln++ ) { // Check if analysis has been cancelled if ( worker.CancellationPending ) { e.Cancel = true; return 0; } foundTwin = false; // Check master solution list for existing solution for ( int imaster = 0 ; imaster < masterSolutions.Count ; imaster++ ) { // Determine if (x,y,r) parameters are all within // tolerance of a solution from the master list xdiff = Math.Abs( currentSolutions[isoln].X - masterSolutions[imaster].X ); if ( xdiff > toler ) continue; ydiff = Math.Abs( currentSolutions[isoln].Y - masterSolutions[imaster].Y ); if ( ydiff > toler ) continue; rdiff = Math.Abs( currentSolutions[isoln].R - masterSolutions[imaster].R ); if ( rdiff > toler ) continue; currentSolutions[isoln].SF = masterSolutions[imaster].SF; currentSolutions[isoln].XEnter = masterSolutions[imaster].XEnter; currentSolutions[isoln].XExit = masterSolutions[imaster].XExit; currentSolutions[isoln].YEnter = masterSolutions[imaster].YEnter; currentSolutions[isoln].YExit = masterSolutions[imaster].YExit; foundTwin = true; } // If solution found in master list, do not evaluate if ( foundTwin ) { // Update progress bar percentComplete = (int) ((float) progressCount++ / (float) numberOfEvaluations * (float) 100); worker.ReportProgress( percentComplete ); continue; } // Evaluate safety factor using the appropriate method currentSolutions[isoln].SF = evalSF( currentSolutions[isoln] , surface , mesh ); // Add new surface to master list masterSolutions.Add( new CircularSurface( surface , yBoundMin , radiusBreaks , soilDirection , currentSolutions[isoln].X , currentSolutions[isoln].Y , currentSolutions[isoln].R , currentSolutions[isoln].Limits , currentSolutions[isoln].SF , currentSolutions[isoln].XEnter , currentSolutions[isoln].YEnter , currentSolutions[isoln].XExit , currentSolutions[isoln].YExit ) ); percentComplete = (int) ((float) progressCount++ / (float) numberOfEvaluations * (float) 100); worker.ReportProgress( percentComplete ); } // Sort the master solution list masterSolutions.Sort( SortSolutions ); // Only keep top 20 master solutions while ( masterSolutions.Count > 20 ) masterSolutions.RemoveAt( masterSolutions.Count - 1 ); // Begin mating cycle on all but the last generation if ( igen < generations ) { // Sort the current solution list currentSolutions.Sort( SortSolutions ); // Clear previous mating pool matingPool.Clear(); // Take specified proportion into mating pool while ( matingPool.Count < mating ) { matingPool.Add( currentSolutions[0] ); currentSolutions.RemoveAt( 0 ); } // -------------------------------------- // Reproduction // -------------------------------------- // Get value of SF @ mating+1 // (for producing weighting scheme) upperSF = currentSolutions[0].SF; // Clear current solution list currentSolutions.Clear(); // Reverse SF weighting (minimization) // and sum up SF weights totalWeight = 0; for ( int imate = 0 ; imate < mating ; imate++ ) { totalWeight += matingPool[imate].SFWeight = matingPool[imate].SF - upperSF; } // Divide each SF by sum of SFs to get individual weight, // and add sum of previous weights to obtain // cumulative weighting scheme matingPool[0].SFWeight /= totalWeight; for ( int imate = 1 ; imate < mating - 1 ; imate++ ) { matingPool[imate].SFWeight /= totalWeight; matingPool[imate].SFWeight += matingPool[imate - 1].SFWeight; } matingPool[mating - 1].SFWeight = 1.0; // Generate random numbers for selecting parents parentSelectors.Clear(); while ( parentSelectors.Count < parents ) parentSelectors.Add( random.NextDouble() ); // Add "fittest" solutions to front of solution list for ( int ifit = 0 ; ifit < fittest ; ifit++ ) { currentSolutions.Add( new CircularSurface( surface , yBoundMin , radiusBreaks , soilDirection , matingPool[ifit].X , matingPool[ifit].Y , matingPool[ifit].R , matingPool[ifit].Limits ) ); } // Select random parents based on weighting scheme int iparent = 0; while ( currentSolutions.Count < population ) { for ( int imate = 0 ; imate < mating ; imate++ ) { if ( parentSelectors[iparent] <= matingPool[imate].SFWeight ) { currentSolutions.Add( new CircularSurface( surface , yBoundMin , radiusBreaks , soilDirection , matingPool[imate].X , matingPool[imate].Y , matingPool[imate].R , matingPool[imate].Limits ) ); break; } } iparent++; } int interpt , crosspt; double crosscoeff; double mother , father; // Loop through parents performing crossover // (beginning from one past the fittest) for ( int ichild = fittest ; ichild < population ; ichild += 2 ) { // Check if crossover is to occur if ( random.NextDouble() <= crossProb ) { // Randomly select X, Y, or R for interpolation interpt = (int) (random.NextDouble() * dof); // Randomly select another point for crossover crosspt = (int) (random.NextDouble() * (dof - 1)); // Randomly generate crossover coefficient crosscoeff = random.NextDouble(); switch ( interpt ) { // Interpolation on X case 0: mother = currentSolutions[ichild].X; father = currentSolutions[ichild + 1].X; currentSolutions[ichild].X = mother - crosscoeff * (mother - father); currentSolutions[ichild + 1].X = father + crosscoeff * (mother - father); switch ( crosspt ) { // Crossover on Y case 0: mother = currentSolutions[ichild].Y; father = currentSolutions[ichild + 1].Y; currentSolutions[ichild].Y = father; currentSolutions[ichild + 1].Y = mother; break; // Crossover on R default: mother = currentSolutions[ichild].R; father = currentSolutions[ichild + 1].R; currentSolutions[ichild].R = father; currentSolutions[ichild + 1].R = mother; break; } break; // Interpolation on Y case 1: mother = currentSolutions[ichild].Y; father = currentSolutions[ichild + 1].Y; currentSolutions[ichild].Y = mother - crosscoeff * (mother - father); currentSolutions[ichild + 1].Y = father + crosscoeff * (mother - father); switch ( crosspt ) { // Crossover on X case 0: mother = currentSolutions[ichild].X; father = currentSolutions[ichild + 1].X; currentSolutions[ichild].X = father; currentSolutions[ichild + 1].X = mother; break; // Crossover on R default: mother = currentSolutions[ichild].R; father = currentSolutions[ichild + 1].R; currentSolutions[ichild].R = father; currentSolutions[ichild + 1].R = mother; break; } break; // Interpolation on R default: mother = currentSolutions[ichild].R; father = currentSolutions[ichild + 1].R; currentSolutions[ichild].R = mother - crosscoeff * (mother - father); currentSolutions[ichild + 1].R = father + crosscoeff * (mother - father); switch ( crosspt ) { // Crossover on X case 0: mother = currentSolutions[ichild].X; father = currentSolutions[ichild + 1].X; currentSolutions[ichild].X = father; currentSolutions[ichild + 1].X = mother; break; // Crossover on Y default: mother = currentSolutions[ichild].Y; father = currentSolutions[ichild + 1].Y; currentSolutions[ichild].Y = father; currentSolutions[ichild + 1].Y = mother; break; } break; } } } // Loop through population performing mutations int mutchild , mutpt; for ( int imut = 0 ; imut < mutations ; imut++ ) { // Select child and parameter randomly mutchild = (int) (random.NextDouble() * parents) + fittest; mutpt = (int) (random.NextDouble() * dof); switch ( mutpt ) { case 0: currentSolutions[mutchild].GenerateX(); break; case 1: currentSolutions[mutchild].GenerateY(); break; default: currentSolutions[mutchild].GenerateR(); break; } } } } // Maintain top 10 solutions masterSolutions.Sort( SortSolutions ); while ( masterSolutions.Count > 10 ) masterSolutions.RemoveAt( masterSolutions.Count - 1 ); masterSolutions.Sort( SortSolutions ); // ---------------------------- // OUTPUT FILE GENERATION // ---------------------------- // Read back existing results (if any), print them to output and add this run's output to end. // Save the minimum case thus far immediately after geometry data. // Update the file path split = canvas.FilePath.Split( '.' ); switch ( canvas.AnalysisType ) { case AnalysisType.Bishop: split[split.Length - 1] = "bish"; break; default: split[split.Length - 1] = "rfem"; break; } path = string.Join( "." , split ); // MODIFY THE EXISTING RESULTS FILE if ( File.Exists( path ) ) { // Read in all existing output file contents List<string> contents = new List<string>( File.ReadAllLines( path ) ); // Find line with number of runs, increment run count, and update this line int iruncount = contents.FindIndex( delegate( string s ) { return s.Contains( "Number of Runs = " ); } ); int runs = int.Parse( contents[iruncount].Split( '=' )[1] ); runs++; contents[iruncount] = string.Format( "Number of Runs = {0}" , runs ); // Find region with critical surface information and obtain its Fs int icrit = contents.FindIndex( delegate( string s ) { return s.Contains( "MOST CRITICAL SURFACE" ); } ); double prevSF = double.Parse( contents[icrit + 9].Split( '=' )[1] ); // If min Fs from current run is less than all previous runs, update this section if ( masterSolutions[0].SF < prevSF ) { contents[icrit + 2] = string.Format( "X_centre =\t{0}" , Math.Round( masterSolutions[0].X , 2 ) ); contents[icrit + 3] = string.Format( "Y_centre =\t{0}" , Math.Round( masterSolutions[0].Y , 2 ) ); contents[icrit + 4] = string.Format( "R =\t\t{0}" , Math.Round( masterSolutions[0].R , 2 ) ); contents[icrit + 5] = string.Format( "X_enter =\t{0}" , Math.Round( masterSolutions[0].XEnter , 2 ) ); contents[icrit + 6] = string.Format( "Y_enter =\t{0}" , Math.Round( masterSolutions[0].YEnter , 2 ) ); contents[icrit + 7] = string.Format( "X_exit =\t{0}" , Math.Round( masterSolutions[0].XExit , 2 ) ); contents[icrit + 8] = string.Format( "Y_exit =\t{0}" , Math.Round( masterSolutions[0].YExit , 2 ) ); contents[icrit + 9] = string.Format( "Fs =\t\t{0}" , Math.Round( masterSolutions[0].SF , 3 ) ); contents[icrit + 10] = string.Format( "Run No. =\t{0}" , runs ); } // Write all contents back to file File.WriteAllLines( path , contents ); // Append current run results to end of file using ( TextWriter tw = File.AppendText( path ) ) { tw.WriteLine(); tw.WriteLine( "Run #{0}" , runs ); tw.WriteLine( "{0}" , DateTime.Now ); tw.WriteLine( "X_centre\tY_centre\tR\t\tX_enter\t\tY_enter\t\tX_exit\t\tY_exit\t\tFs" ); for ( int i = 0 ; i < masterSolutions.Count ; i++ ) { tw.WriteLine( "{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}\t\t{5}\t\t{6}\t\t{7}\t\t" , Math.Round( masterSolutions[i].X , 2 ) , Math.Round( masterSolutions[i].Y , 2 ) , Math.Round( masterSolutions[i].R , 2 ) , Math.Round( masterSolutions[i].XEnter , 2 ) , Math.Round( masterSolutions[i].YEnter , 2 ) , Math.Round( masterSolutions[i].XExit , 2 ) , Math.Round( masterSolutions[i].YExit , 2 ) , Math.Round( masterSolutions[i].SF , 3 ) ); } } } // CREATE A NEW RESULTS FILE else { using ( TextWriter tw = new StreamWriter( path ) ) { tw.WriteLine( "*****************************************" ); tw.WriteLine(); tw.WriteLine( " GENETIC ALGORITHM OUTPUT" ); tw.WriteLine(); switch ( canvas.AnalysisType ) { case AnalysisType.Bishop: tw.WriteLine( " ANALYSIS METHOD: Bishop's Method" ); break; default: tw.WriteLine( " ANALYSIS METHOD: RFEM" ); break; } tw.WriteLine(); tw.WriteLine( "*****************************************" ); tw.WriteLine(); string units; switch ( canvas.Units ) { case Units.Metres: units = "m, kPa, kN/m^3"; break; case Units.Millimetres: units = "mm, kPa, kN/m^3"; break; case Units.Feet: units = "ft, psi, pcf"; break; default: units = "in, psi, pcf"; break; } tw.WriteLine( "Units = {0}" , units ); tw.WriteLine(); tw.WriteLine(); tw.WriteLine( "UPPER SURFACE GEOMETRY" ); tw.WriteLine( "--------------------------" ); tw.WriteLine( "Number of Points = {0}" , surface.Count ); tw.WriteLine(); tw.WriteLine( "(X,Y)" ); for ( int i = 0 ; i < surface.Count ; i++ ) tw.WriteLine( "{0}, {1}" , Math.Round( surface[i].X , 2 ) , Math.Round( surface[i].Y , 2 ) ); tw.WriteLine(); tw.WriteLine(); tw.WriteLine( "MATERIAL DATA" ); tw.WriteLine( "--------------------------" ); tw.WriteLine( "Number of Material Types = {0}" , canvas.MaterialTypes.Count ); tw.WriteLine(); for ( int i = 0 ; i < canvas.MaterialTypes.Count ; i++ ) { tw.WriteLine( "Material #{0}" , i + 1 ); tw.WriteLine( "Name = \"{0}\"" , canvas.MaterialTypes[i].Name ); tw.WriteLine( "Phi = {0}" , Math.Round( canvas.MaterialTypes[i].Phi , 2 ) ); tw.WriteLine( "Cohesion = {0}" , Math.Round( canvas.MaterialTypes[i].Cohesion , 2 ) ); tw.WriteLine( "Unit Weight = {0}" , Math.Round( canvas.MaterialTypes[i].Gamma , 2 ) ); tw.WriteLine(); } tw.WriteLine(); tw.WriteLine( "MATERIAL BLOCK GEOMETRY" ); tw.WriteLine( "--------------------------" ); tw.WriteLine( "Number of Material Blocks = {0}" , canvas.MaterialBlocks.Count ); tw.WriteLine(); Point p; double xCoord , yCoord; for ( int i = 0 ; i < canvas.MaterialBlocks.Count ; i++ ) { tw.WriteLine( "MB{0}" , i + 1 ); tw.WriteLine( "Material Type = \"{0}\"" , canvas.MaterialBlocks[i].Material ); tw.WriteLine( "Number of Points = {0}" , canvas.MaterialBlocks[i].BoundaryPoints.Count ); tw.WriteLine( "(X,Y)" ); for ( int j = 0 ; j < canvas.MaterialBlocks[i].BoundaryPoints.Count ; j++ ) { p = canvas.MaterialBlocks[i].BoundaryPoints[j].Point; xCoord = (p.X - canvas.OriginOffsetX) / canvas.DpiX * lengthFactor * canvas.Scale; yCoord = (canvas.ActualHeight - p.Y - canvas.OriginOffsetY) / canvas.DpiY * lengthFactor * canvas.Scale; tw.WriteLine( "{0}, {1}" , Math.Round( xCoord , 2 ) , Math.Round( yCoord , 2 ) ); } tw.WriteLine(); } tw.WriteLine(); tw.WriteLine( "MOST CRITICAL SURFACE" ); tw.WriteLine( "--------------------------" ); tw.WriteLine( "X_centre =\t{0}" , Math.Round( masterSolutions[0].X , 2 ) ); tw.WriteLine( "Y_centre =\t{0}" , Math.Round( masterSolutions[0].Y , 2 ) ); tw.WriteLine( "R =\t\t{0}" , Math.Round( masterSolutions[0].R , 2 ) ); tw.WriteLine( "X_enter =\t{0}" , Math.Round( masterSolutions[0].XEnter , 2 ) ); tw.WriteLine( "Y_enter =\t{0}" , Math.Round( masterSolutions[0].YEnter , 2 ) ); tw.WriteLine( "X_exit =\t{0}" , Math.Round( masterSolutions[0].XExit , 2 ) ); tw.WriteLine( "Y_exit =\t{0}" , Math.Round( masterSolutions[0].YExit , 2 ) ); tw.WriteLine( "Fs =\t\t{0}" , Math.Round( masterSolutions[0].SF , 3 ) ); tw.WriteLine( "Run No. =\t{0}" , 1 ); // this is the first run tw.WriteLine(); tw.WriteLine(); tw.WriteLine( "ADDITIONAL RUN OUTPUT" ); tw.WriteLine( "--------------------------" ); tw.WriteLine( "Number of Runs = {0}" , 1 ); // this is the first run tw.WriteLine(); tw.WriteLine( "Run #{0}" , 1 ); // this is the first run tw.WriteLine( "{0}" , DateTime.Now ); tw.WriteLine( "X_centre\tY_centre\tR\t\tX_enter\t\tY_enter\t\tX_exit\t\tY_exit\t\tFs" ); for ( int i = 0 ; i < masterSolutions.Count ; i++ ) { tw.WriteLine( "{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}\t\t{5}\t\t{6}\t\t{7}\t\t" , Math.Round( masterSolutions[i].X , 2 ) , Math.Round( masterSolutions[i].Y , 2 ) , Math.Round( masterSolutions[i].R , 2 ) , Math.Round( masterSolutions[i].XEnter , 2 ) , Math.Round( masterSolutions[i].YEnter , 2 ) , Math.Round( masterSolutions[i].XExit , 2 ) , Math.Round( masterSolutions[i].YExit , 2 ) , Math.Round( masterSolutions[i].SF , 3 ) ); } } } return masterSolutions[0].SF; }
public DrawingPoint( SlopeCanvas canvas , object parent , Point pt ) { this.canvas = canvas; if ( parent is SlopeBoundary ) this.parentBoundary = parent as SlopeBoundary; else if ( parent is MaterialBlock ) this.parentBlocks = new List<MaterialBlock>() { parent as MaterialBlock }; this.point = pt; fixLines = new List<Polyline>(); Polyline newLine; for ( int i = 0 ; i < 4 ; i++ ) { newLine = new Polyline(); newLine.Visibility = Visibility.Hidden; newLine.Fill = Brushes.Blue; newLine.Opacity = 1.0; newLine.StrokeThickness = 1.5; newLine.Stroke = Brushes.Blue; fixLines.Add( newLine ); canvas.Children.Add( newLine ); newLine.MouseLeftButtonUp += new MouseButtonEventHandler( fixLines_MouseLeftButtonUp ); } fixLines[0].Points.Add( new Point( point.X - 7 , point.Y - 3.5 ) ); fixLines[0].Points.Add( new Point( point.X + 7 , point.Y - 3.5 ) ); fixLines[1].Points.Add( new Point( point.X - 7 , point.Y + 3.5 ) ); fixLines[1].Points.Add( new Point( point.X + 7 , point.Y + 3.5 ) ); fixLines[2].Points.Add( new Point( point.X - 3.5 , point.Y + 7 ) ); fixLines[2].Points.Add( new Point( point.X - 3.5 , point.Y - 7 ) ); fixLines[3].Points.Add( new Point( point.X + 3.5 , point.Y + 7 ) ); fixLines[3].Points.Add( new Point( point.X + 3.5 , point.Y - 7 ) ); dot = new Ellipse(); dot.HorizontalAlignment = HorizontalAlignment.Left; dot.VerticalAlignment = VerticalAlignment.Top; dot.Height = 7; dot.Width = 7; dot.Margin = new Thickness( point.X - 0.5 * dot.Width , point.Y - 0.5 * dot.Height , 0 , 0 ); dot.Stroke = Brushes.Black; dot.Fill = Brushes.Black; dot.Opacity = 0.7; dot.MouseLeftButtonDown += new MouseButtonEventHandler( MouseLeftButtonDown ); phaseFixActiveX = new List<bool>(); phaseFixActiveY = new List<bool>(); if ( parentBlocks != null ) { int numAnalysisPhases = canvas.AnalysisPhases.Count - 1; while ( phaseFixActiveX.Count < numAnalysisPhases ) { phaseFixActiveX.Add( false ); phaseFixActiveY.Add( false ); } } canvas.Children.Add( dot ); }
/// <summary> /// Constructor /// </summary> /// <param name="canvas">Parent drawing canvas</param> /// <param name="p1">Node 1 (assumed to be sorted CCW)</param> /// <param name="p2">Node 2 (assumed to be sorted CCW)</param> /// <param name="isLoadedN">Is load applied in the normal direction?</param> /// <param name="nLoad1">Value of normal load at node 1.</param> /// <param name="nLoad2">Value of normal load at node 2.</param> /// <param name="isLoadedT">Is load applied in the tangential direction?</param> /// <param name="tLoad1">Value of tangential load at node 1.</param> /// <param name="tLoad2">Value of tangential load at node 2.</param> public LineLoad( SlopeCanvas canvas , DrawingPoint p1 , DrawingPoint p2 , bool isLoadedN , double nLoad1 , double nLoad2 , bool isLoadedT , double tLoad1 , double tLoad2 ) { // set parent drawing canvas this.canvas = canvas; // create list of boundary nodes for the load Nodes = new List<DrawingPoint>() { p1 , p2 }; PlotPoints = new List<Point>() { new Point() , new Point() , new Point() }; // create plotting lines for loads loadLines = new List<Polyline>(); Polyline newLine; for ( int i = 0 ; i < 18 ; i++ ) { newLine = new Polyline(); newLine.Visibility = Visibility.Hidden; newLine.Fill = Brushes.Blue; newLine.Opacity = 1.0; newLine.StrokeThickness = 1.25; newLine.Stroke = Brushes.Blue; newLine.Points.Add( new Point() ); newLine.Points.Add( new Point() ); loadLines.Add( newLine ); canvas.Children.Add( newLine ); newLine.MouseLeftButtonUp += new MouseButtonEventHandler( MouseLeftButtonUp ); } // set load state this.IsLoadedN = isLoadedN; if ( this.IsLoadedN ) this.NFactor = 1.0; this.NLoad1 = nLoad1; this.NLoad2 = nLoad2; this.IsLoadedT = isLoadedT; if ( this.IsLoadedT ) this.TFactor = 1.0; this.TLoad1 = tLoad1; this.TLoad2 = tLoad2; // Initialize analysis phase lists phaseActiveN = new List<bool>(); phaseFactorN = new List<double>(); phaseActiveT = new List<bool>(); phaseFactorT = new List<double>(); int numAnalysisPhases = canvas.AnalysisPhases.Count - 1; while ( phaseActiveN.Count < numAnalysisPhases ) { phaseActiveN.Add( isLoadedN ); phaseFactorN.Add( isLoadedN ? 1.0 : 0.0 ); phaseActiveT.Add( isLoadedT ); phaseFactorT.Add( isLoadedT ? 1.0 : 0.0 ); } // Add the constraint to all blocks that contain both of its points List<MaterialBlock> parents = canvas.MaterialBlocks.FindAll( delegate( MaterialBlock mb ) { return mb.BoundaryPoints.Contains( p1 ) && mb.BoundaryPoints.Contains( p2 ); } ); foreach ( MaterialBlock pmb in parents ) { if ( !pmb.LineLoads.Contains( this ) ) pmb.LineLoads.Add( this ); } Update(); }
public ShowResultsDialog( Window owner ) { InitializeComponent(); // intialize canvas information this.Owner = owner; canvas = (SlopeCanvas) ((Grid) ((TabControl) ((Grid) this.Owner.Content).Children[2]).SelectedContent).Children[2]; runSurfaces = canvas.RunSurfaces; analysisType = canvas.AnalysisType; scale = canvas.Scale; dpiX = canvas.DpiX; dpiY = canvas.DpiY; originOffsetX = canvas.OriginOffsetX; originOffsetY = canvas.OriginOffsetY; actualHeight = canvas.ActualHeight; switch ( canvas.Units ) { case Units.Metres: factor = 0.0254; break; case Units.Millimetres: factor = 25.4; break; case Units.Feet: factor = 1.0 / 12.0; break; default: factor = 1.0; break; } // get path to results file resultsPath = canvas.FilePath; resultsPathSplit = resultsPath.Split( '.' ); // check type of analysis and set appropriate file extension switch ( analysisType ) { case AnalysisType.Bishop: resultsPathSplit[resultsPathSplit.Length - 1] = "bish"; break; default: resultsPathSplit[resultsPathSplit.Length - 1] = "rfem"; break; } resultsPath = string.Join( "." , resultsPathSplit ); // error catch to make sure results file exists if ( File.Exists( resultsPath ) ) { // BUILD RESULTS SELECTION LIST // add critical run item to list selectRun.Items.Add( "Critical Run" ); // read in all existing output file contents results = new List<string>( File.ReadAllLines( resultsPath ) ); // find first run in results file int irun = results.FindIndex( delegate( string s ) { return s.Contains( "Run #" ); } ); int run = 1; // loop through results file, adding an item for each run while ( irun != -1 ) { selectRun.Items.Add( string.Format( "Run #{0}" , run++ ) ); irun = results.FindIndex( irun + 1 , delegate( string s ) { return s.Contains( "Run #" ); } ); } // set selected item to critical run selectRun.SelectedIndex = 0; } else { runResults.Text += "Error! No results file found.\n"; } }
/// <summary> /// Constructor /// </summary> public ClosableCanvasTabItem() { // Create the header UserControl ClosableHeader closableTabHeader = new ClosableHeader(); // Assign user control to tab header this.Header = closableTabHeader; // Attach CloseableHeader button events closableTabHeader.tabClose.MouseEnter += new MouseEventHandler( tabClose_MouseEnter ); closableTabHeader.tabClose.MouseLeave += new MouseEventHandler( tabClose_MouseLeave ); closableTabHeader.tabClose.Click += new RoutedEventHandler( tabClose_Click ); closableTabHeader.tabTitle.SizeChanged += new SizeChangedEventHandler( tabTitle_SizeChanged ); // Create Grid to contain two axes and drawing canvas Grid contentGrid = new Grid(); contentGrid.Background = Brushes.WhiteSmoke; contentGrid.Margin = new Thickness( 0 ); this.Content = contentGrid; double axisWidth = 65; // Create Grid object for x axis Grid xAxis = new Grid(); xAxis.ClipToBounds = true; xAxis.Background = Brushes.WhiteSmoke; xAxis.VerticalAlignment = VerticalAlignment.Bottom; xAxis.HorizontalAlignment = HorizontalAlignment.Stretch; xAxis.Margin = new Thickness( axisWidth , 0 , 0 , 10 ); xAxis.Height = axisWidth; contentGrid.Children.Add( xAxis ); // Create Grid object for y axis Grid yAxis = new Grid(); yAxis.ClipToBounds = true; yAxis.Background = Brushes.WhiteSmoke; yAxis.VerticalAlignment = VerticalAlignment.Stretch; yAxis.HorizontalAlignment = HorizontalAlignment.Left; yAxis.Margin = new Thickness( 0 , 0 , 0 , axisWidth + 10 ); yAxis.Width = axisWidth; contentGrid.Children.Add( yAxis ); // Create SlopeCanvas object for drawing surface SlopeCanvas drawingCanvas = new SlopeCanvas(); drawingCanvas.Background = Brushes.White; drawingCanvas.VerticalAlignment = VerticalAlignment.Stretch; drawingCanvas.HorizontalAlignment = HorizontalAlignment.Stretch; drawingCanvas.Margin = new Thickness( axisWidth , 0 , 0 , axisWidth + 10 ); drawingCanvas.InitializeCanvas(); contentGrid.Children.Add( drawingCanvas ); ProgressBar analysisProgress = new ProgressBar(); analysisProgress.Height = 10; analysisProgress.VerticalAlignment = VerticalAlignment.Bottom; analysisProgress.HorizontalAlignment = HorizontalAlignment.Stretch; analysisProgress.Margin = new Thickness( 0 , 0 , 0 , 0 ); analysisProgress.Visibility = Visibility.Hidden; contentGrid.Children.Add( analysisProgress ); Rectangle hideCanvasRect = new Rectangle(); hideCanvasRect.Fill = Brushes.White; hideCanvasRect.Opacity = 0.5; hideCanvasRect.Stroke = Brushes.White; hideCanvasRect.VerticalAlignment = VerticalAlignment.Stretch; hideCanvasRect.HorizontalAlignment = HorizontalAlignment.Stretch; hideCanvasRect.Margin = new Thickness( axisWidth , 0 , 0 , axisWidth + 10 ); hideCanvasRect.Visibility = Visibility.Hidden; contentGrid.Children.Add( hideCanvasRect ); }