public AddLineLoadDialog( SlopeCanvas canvas , LineLoad 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/m"; break;
                case Units.Millimetres: factor = 25.4; coordUnits = "mm"; loadUnits = "kN/m"; break;
                case Units.Feet: factor = 1.0 / 12.0; coordUnits = "ft"; loadUnits = "lbf/ft"; break;
                default: factor = 1.0; coordUnits = "in"; loadUnits = "lbf/ft"; break;
            }

            // set units labels
            node1Units.Content = coordUnits;
            node2Units.Content = coordUnits;
            nLoad1Units.Content = loadUnits;
            nLoad2Units.Content = loadUnits;
            tLoad1Units.Content = loadUnits;
            tLoad2Units.Content = loadUnits;

            // set node coordinates
            double xCoord , yCoord;
            xCoord = (load.Nodes[0].Point.X - canvas.OriginOffsetX) / canvas.DpiX * factor * canvas.Scale;
            yCoord = (canvas.ActualHeight - load.Nodes[0].Point.Y - canvas.OriginOffsetY) / canvas.DpiY * factor * canvas.Scale;
            coords1.Content = string.Format( "({0}, {1})" , Math.Round( xCoord , 2 ) , Math.Round( yCoord , 2 ) );
            xCoord = (load.Nodes[1].Point.X - canvas.OriginOffsetX) / canvas.DpiX * factor * canvas.Scale;
            yCoord = (canvas.ActualHeight - load.Nodes[1].Point.Y - canvas.OriginOffsetY) / canvas.DpiY * factor * canvas.Scale;
            coords2.Content = string.Format( "({0}, {1})" , Math.Round( xCoord , 2 ) , Math.Round( yCoord , 2 ) );

            // set existing load values (if present)
            isLoadedN.IsChecked = nLoad1.IsEnabled = nLoad2.IsEnabled = load.IsLoadedN;
            nLoad1.Text = string.Format( "{0}" , Math.Round( load.NLoad1 , 2 ) );
            nLoad2.Text = string.Format( "{0}" , Math.Round( load.NLoad2 , 2 ) );
            isLoadedT.IsChecked = tLoad1.IsEnabled = tLoad2.IsEnabled = load.IsLoadedT;
            tLoad1.Text = string.Format( "{0}" , Math.Round( load.TLoad1 , 2 ) );
            tLoad2.Text = string.Format( "{0}" , Math.Round( load.TLoad2 , 2 ) );
        }
示例#2
0
        public void ApplyLineLoad( DrawingPoint p1 , DrawingPoint p2 )
        {
            // find point indices in list
            int index1 = BoundaryPoints.FindIndex( delegate( DrawingPoint p ) { return p == p1; } );
            int index2 = BoundaryPoints.FindIndex( delegate( DrawingPoint p ) { return p == p2; } );

            // if points were not successfully found
            if ( index1 == -1 || index2 == -1 )
            {
                MessageBox.Show( "Points not found on block." , "Line Load Error" );
                return;
            }

            // ensure max and min as appropriate
            if ( ((index1 > index2) && !(index2 == 0 && index1 == BoundaryPoints.Count - 1))
                || (index1 == 0 && index2 == BoundaryPoints.Count - 1) )
            {
                int tmp = index1;
                index1 = index2;
                index2 = tmp;

                DrawingPoint tmpPt = p1;
                p1 = p2;
                p2 = tmpPt;
            }

            // points must be adjacent and different
            if ( (index2 - index1) == 1 || (index2 == 0 && index1 == BoundaryPoints.Count - 1) )
            {
                // check if a line load has already been defined between these two objects
                LineLoad load = lineLoads.Find( delegate( LineLoad l ) { return l.Nodes[0] == p1 && l.Nodes[1] == p2; } );

                // if undefined, create a new line load object
                if ( load == null )
                {
                    load = new LineLoad( canvas , p1 , p2 , false , 0 , 0 , false , 0 , 0 );
                    //lineLoads.Add( load );
                }

                bool prevLoadedN = load.IsLoadedN , prevLoadedT = load.IsLoadedT;

                // start dialog for user input
                AddLineLoadDialog dlg = new AddLineLoadDialog( canvas , load );
                dlg.ShowDialog();

                // if there is no load in normal or tangential direction, delete the load ...
                if ( !load.IsLoadedN && !load.IsLoadedT )
                {
                    load.Delete();
                    //lineLoads.Remove( load );
                    canvas.MaterialBlocks.ForEach( delegate( MaterialBlock mb ) { mb.LineLoads.Remove( load ); } );
                }

                // ... otherwise update its visibility and plotting location
                else
                {
                    load.Update();
                }

                if ( dlg.DialogResult == true )
                {
                    bool newLoadedN = load.IsLoadedN;
                    if ( newLoadedN != prevLoadedN )
                    {
                        for ( int i = 0 ; i < load.PhaseActiveN.Count ; i++ )
                        {
                            load.PhaseActiveN[i] = newLoadedN;
                            load.PhaseFactorN[i] = newLoadedN ? 1.0 : 0.0;
                        }
                    }

                    bool newLoadedT = load.IsLoadedT;
                    if ( newLoadedT != prevLoadedT )
                    {
                        for ( int i = 0 ; i < load.PhaseActiveT.Count ; i++ )
                        {
                            load.PhaseActiveT[i] = newLoadedT;
                            load.PhaseFactorT[i] = newLoadedT ? 1.0 : 0.0;
                        }
                    }

                    canvas.IsSaved = false;
                    canvas.IsVerified = false;
                }
            }
            else
            {
                MessageBox.Show( "Points must be different and adjacent." , "Line Load Error" );
            }
        }
示例#3
0
        public DrawingPoint AddPoint( DrawingPoint p1 , DrawingPoint p2, DrawingPoint pNew )
        {
            // find point indices in list
            int index1 = BoundaryPoints.FindIndex( delegate( DrawingPoint p ) { return p == p1; } );
            int index2 = BoundaryPoints.FindIndex( delegate( DrawingPoint p ) { return p == p2; } );

            // if points were not successfully found
            if ( index1 == -1 || index2 == -1 )
            {
                MessageBox.Show( "Points not found on block." , "Error" );
                return null;
            }

            // ensure max and min as appropriate
            if ( ((index1 > index2) && !(index2 == 0 && index1 == BoundaryPoints.Count - 1))
                || (index1 == 0 && index2 == BoundaryPoints.Count - 1) )
            {
                int tmp = index1;
                index1 = index2;
                index2 = tmp;

                DrawingPoint tmpPt = p1;
                p1 = p2;
                p2 = tmpPt;
            }

            DrawingPoint newNode;
            Point newPoint;
            if ( (index2 - index1) == 1 )
            {
                if ( pNew == null )
                {
                    newPoint = new Point( 0.5 * (p1.Point.X + p2.Point.X) , 0.5 * (p1.Point.Y + p2.Point.Y) );
                    newNode = new DrawingPoint( canvas , this , newPoint );
                }
                else
                {
                    newNode = pNew;
                    newNode.ParentBlocks.Add( this );
                    newPoint = pNew.Point;
                }
                BoundaryPoints.Insert( index2 , newNode );
                Boundary.Points.Insert( index2 , newPoint );
            }
            else if ( index2 == 0 && index1 == BoundaryPoints.Count - 1 )
            {
                if ( pNew == null )
                {
                    newPoint = new Point( 0.5 * (p1.Point.X + p2.Point.X) , 0.5 * (p1.Point.Y + p2.Point.Y) );
                    newNode = new DrawingPoint( canvas , this , newPoint );
                }
                else
                {
                    newNode = pNew;
                    newNode.ParentBlocks.Add( this );
                    newPoint = pNew.Point;
                }
                BoundaryPoints.Add( newNode );
                Boundary.Points.Add( newPoint );
            }
            else
            {
                MessageBox.Show( "Points must be different and adjacent." , "Error" );
                return null;
            }

            // if a line constraint exists between these two points, remove it and create two in its place
            List<LineConstraint> existingLCs = new List<LineConstraint>();
            List<MaterialBlock> existingParents = new List<MaterialBlock>();
            canvas.MaterialBlocks.ForEach(
                delegate( MaterialBlock mb )
                {
                    existingLCs.AddRange( mb.LineConstraints.FindAll(
                        delegate( LineConstraint lc )
                        {
                            if ( lc.Nodes.Contains( p1 ) && lc.Nodes.Contains( p2 ) )
                            {
                                existingParents.Add( mb );
                                return true;
                            }
                            else return false;
                        } ) );
                } );
            // create the two new line constraints
            LineConstraint newLC1 = new LineConstraint( canvas , p1 , newNode , false , false );
            LineConstraint newLC2 = new LineConstraint( canvas , newNode , p2 , false , false );
            existingLCs.ForEach(
                delegate( LineConstraint lc )
                {
                    // match the new node fixity to the line constraint
                    newNode.IsFixedX = newNode.IsFixedX || lc.IsFixedX;
                    newNode.IsFixedY = newNode.IsFixedY || lc.IsFixedY;
                    newLC1.IsFixedX = newLC1.IsFixedX || lc.IsFixedX;
                    newLC1.IsFixedY = newLC1.IsFixedY || lc.IsFixedY;
                    newLC2.IsFixedX = newLC2.IsFixedX || lc.IsFixedX;
                    newLC2.IsFixedY = newLC2.IsFixedY || lc.IsFixedY;

                    // clear the existing plotting lines, remove the existing constraint, and add the new constraints
                    existingParents.ForEach( delegate( MaterialBlock mb ) { mb.LineConstraints.Remove( lc ); } );
                    lc.Delete();
                } );
            existingParents.ForEach( delegate( MaterialBlock mb ) { mb.LineConstraints.Add( newLC1 ); mb.LineConstraints.Add( newLC2 ); } );
            existingLCs.Clear(); existingParents.Clear();

            // if a line load exists between these two points, remove it and create two in its place
            List<LineLoad> existingLLs = new List<LineLoad>();
            canvas.MaterialBlocks.ForEach(
                delegate( MaterialBlock mb )
                {
                    existingLLs.AddRange( mb.LineLoads.FindAll(
                        delegate( LineLoad ll )
                        {
                            if ( ll.Nodes.Contains( p1 ) && ll.Nodes.Contains( p2 ) )
                            {
                                existingParents.Add( mb );
                                return true;
                            }
                            else return false;
                        } ) );
                } );
            LineLoad newLL1 = new LineLoad( canvas , p1 , newNode , false , 0 , 0 , false , 0 , 0 );
            LineLoad newLL2 = new LineLoad( canvas , newNode , p2 , false , 0 , 0 , false , 0 , 0 );
            existingLLs.ForEach(
                delegate( LineLoad ll )
                {
                    newLL1.IsLoadedN = newLL1.IsLoadedN || ll.IsLoadedN;
                    if ( newLL1.IsLoadedN )
                    {
                        newLL1.NLoad1 += ll.NLoad1;
                        newLL1.NLoad2 += 0.5 * (ll.NLoad1 + ll.NLoad2);
                    }
                    newLL1.IsLoadedT = newLL1.IsLoadedT || ll.IsLoadedT;
                    if ( newLL1.IsLoadedT )
                    {
                        newLL1.TLoad1 += ll.TLoad1;
                        newLL1.TLoad2 += 0.5 * (ll.TLoad1 + ll.TLoad2);
                    }

                    newLL2.IsLoadedN = newLL2.IsLoadedN || ll.IsLoadedN;
                    if ( newLL2.IsLoadedN )
                    {
                        newLL2.NLoad1 += 0.5 * (ll.NLoad1 + ll.NLoad2);
                        newLL2.NLoad2 += ll.NLoad2;
                    }
                    newLL2.IsLoadedT = newLL2.IsLoadedT || ll.IsLoadedT;
                    if ( newLL2.IsLoadedT )
                    {
                        newLL2.TLoad1 += 0.5 * (ll.TLoad1 + ll.TLoad2);
                        newLL2.TLoad2 += ll.TLoad2;
                    }

                    // clear the existing plotting lines, remove the existing line load, and add the new line loads
                    existingParents.ForEach( delegate( MaterialBlock mb ) { mb.LineLoads.Remove( ll ); } );
                    ll.Delete();
                } );
            LineLoads.Add( newLL1 ); LineLoads.Add( newLL2 );
            existingLLs.Clear(); existingParents.Clear();

            foreach ( MaterialBlock mb in canvas.MaterialBlocks )
            {
                for ( int i = mb.LineLoads.Count - 1 ; i >= 0 ; i-- )
                {
                    if ( !mb.LineLoads[i].IsLoadedN && !mb.LineLoads[i].IsLoadedT )
                    {
                        mb.LineLoads[i].Delete();
                        mb.LineLoads.RemoveAt( i );
                    }
                }

                for ( int i = mb.LineConstraints.Count - 1 ; i >= 0 ; i-- )
                {
                    if ( !mb.LineConstraints[i].IsFixedX && !mb.LineConstraints[i].IsFixedY )
                    {
                        mb.LineConstraints[i].Delete();
                        mb.LineConstraints.RemoveAt( i );
                    }
                }
            }

            canvas.IsSaved = false;
            canvas.IsVerified = false;

            return newNode;
        }