Ejemplo n.º 1
0
        public ActivateFixityDialog( SlopeDefineCanvas canvas , DrawingPoint p )
        {
            InitializeComponent();

            this.canvas = canvas;

            this.p = p;

            MaterialBlock parent = canvas.Substructs.Find( delegate( MaterialBlock mb ) { return mb.Material.Name != "NULL" && mb.BoundaryPoints.Contains( p ); } );

            isFixedX.IsEnabled = parent != null && p.IsFixedX;
            isFixedY.IsEnabled = parent != null && p.IsFixedY;
            isFixedX.IsChecked = parent != null && p.IsFixActiveX;
            isFixedY.IsChecked = parent != null && p.IsFixActiveY;

            List<LineConstraint> attachedLCs = new List<LineConstraint>();
            canvas.Substructs.ForEach(
                delegate( MaterialBlock mb )
                {
                    attachedLCs.AddRange( mb.LineConstraints.FindAll( delegate( LineConstraint lc ) { return lc.Nodes.Contains( p ); } ) );
                } );
            attachedLCs.ForEach(
                delegate( LineConstraint lc )
                {
                    if ( lc.IsActiveX ) isFixedX.IsEnabled = false;
                    if ( lc.IsActiveY ) isFixedY.IsEnabled = false;
                } );
            attachedLCs.Clear();
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        public void Merge( DrawingPoint other )
        {
            // merge point fixities
            this.IsFixedX = this.IsFixedX || other.IsFixedX;
            this.IsFixedY = this.IsFixedY || other.IsFixedY;
            for ( int i = 0 ; i < this.PhaseFixActiveX.Count ; i++ )
            {
                this.PhaseFixActiveX[i] = this.PhaseFixActiveX[i] || other.PhaseFixActiveX[i];
                this.PhaseFixActiveY[i] = this.PhaseFixActiveY[i] || other.PhaseFixActiveY[i];
            }

            // obtain all LineConstraints, LineLoads, and PointLoads containing this point
            List<LineConstraint> thisLCs = new List<LineConstraint>();
            List<LineLoad> thisLLs = new List<LineLoad>();
            List<PointLoad> thisPLs = new List<PointLoad>();
            this.ParentBlocks.ForEach(
                delegate( MaterialBlock mb )
                {
                    thisLCs.AddRange( mb.LineConstraints.FindAll( delegate( LineConstraint lc ) { return !thisLCs.Contains( lc ) && lc.Nodes.Contains( this ); } ) );
                    thisLLs.AddRange( mb.LineLoads.FindAll( delegate( LineLoad ll ) { return !thisLLs.Contains( ll ) && ll.Nodes.Contains( this ); } ) );
                    thisPLs.AddRange( mb.PointLoads.FindAll( delegate( PointLoad pl ) { return !thisPLs.Contains( pl ) && pl.Node == this; } ) );
                } );
            // merge multiple point loads at this point
            for ( int i = thisPLs.Count - 1 ; i >= 1 ; i-- )
            {
                thisPLs[0].IsLoadedX = thisPLs[0].IsLoadedX || thisPLs[i].IsLoadedX;
                thisPLs[0].XLoad += thisPLs[i].XLoad;

                thisPLs[0].IsLoadedY = thisPLs[0].IsLoadedY || thisPLs[i].IsLoadedY;
                thisPLs[0].YLoad += thisPLs[i].YLoad;

                for ( int j = 0 ; j < thisPLs[0].PhaseActiveX.Count ; j++ )
                {
                    thisPLs[0].PhaseActiveX[j] = thisPLs[0].PhaseActiveX[j] || thisPLs[i].PhaseActiveX[j];
                    thisPLs[0].PhaseFactorX[j] = thisPLs[0].PhaseActiveX[j] ? 1.0 : 0.0;

                    thisPLs[0].PhaseActiveY[j] = thisPLs[0].PhaseActiveY[j] || thisPLs[i].PhaseActiveY[j];
                    thisPLs[0].PhaseFactorY[j] = thisPLs[0].PhaseActiveY[j] ? 1.0 : 0.0;
                }

                this.ParentBlocks.ForEach(
                    delegate( MaterialBlock mb )
                    { mb.PointLoads.RemoveAll( delegate( PointLoad pl ) { return pl == thisPLs[i]; } ); } );
                thisPLs[i].Delete();
                thisPLs.RemoveAt( i );
            }
            PointLoad thisPL = null;
            if ( thisPLs.Count > 0 ) thisPL = thisPLs[0];

            // obtain all LineConstraints, LineLoads, and PointLoads containing other point
            List<LineConstraint> otherLCs = new List<LineConstraint>();
            List<LineLoad> otherLLs = new List<LineLoad>();
            List<PointLoad> otherPLs = new List<PointLoad>();
            other.ParentBlocks.ForEach(
                delegate( MaterialBlock mb )
                {
                    otherLCs.AddRange( mb.LineConstraints.FindAll( delegate( LineConstraint lc ) { return !otherLCs.Contains( lc ) && lc.Nodes.Contains( other ); } ) );
                    otherLLs.AddRange( mb.LineLoads.FindAll( delegate( LineLoad ll ) { return !otherLLs.Contains( ll ) && ll.Nodes.Contains( other ); } ) );
                    otherPLs.AddRange( mb.PointLoads.FindAll( delegate( PointLoad pl ) { return !otherPLs.Contains( pl ) && pl.Node == other; } ) );
                } );
            // merge multiple point loads at other point
            for ( int i = otherPLs.Count - 1 ; i >= 1 ; i-- )
            {
                otherPLs[0].IsLoadedX = otherPLs[0].IsLoadedX || otherPLs[i].IsLoadedX;
                otherPLs[0].XLoad += otherPLs[i].XLoad;

                otherPLs[0].IsLoadedY = otherPLs[0].IsLoadedY || otherPLs[i].IsLoadedY;
                otherPLs[0].YLoad += otherPLs[i].YLoad;

                for ( int j = 0 ; j < otherPLs[0].PhaseActiveX.Count ; j++ )
                {
                    otherPLs[0].PhaseActiveX[j] = otherPLs[0].PhaseActiveX[j] || otherPLs[i].PhaseActiveX[j];
                    otherPLs[0].PhaseFactorX[j] = otherPLs[0].PhaseActiveX[j] ? 1.0 : 0.0;

                    otherPLs[0].PhaseActiveY[j] = otherPLs[0].PhaseActiveY[j] || otherPLs[i].PhaseActiveY[j];
                    otherPLs[0].PhaseFactorY[j] = otherPLs[0].PhaseActiveY[j] ? 1.0 : 0.0;
                }

                other.ParentBlocks.ForEach(
                    delegate( MaterialBlock mb )
                    { mb.PointLoads.RemoveAll( delegate( PointLoad pl ) { return pl == otherPLs[i]; } ); } );
                otherPLs[i].Delete();
                otherPLs.RemoveAt( i );
            }
            PointLoad otherPL = null;
            if ( otherPLs.Count > 0 ) otherPL = otherPLs[0];

            // set nodes currently containing other node to this node
            otherLCs.ForEach(
                delegate( LineConstraint lc )
                {
                    if ( lc.Nodes[0] == other ) lc.Nodes[0] = this;
                    if ( lc.Nodes[1] == other ) lc.Nodes[1] = this;
                } );
            otherLLs.ForEach(
                delegate( LineLoad ll )
                {
                    if ( ll.Nodes[0] == other ) ll.Nodes[0] = this;
                    if ( ll.Nodes[1] == other ) ll.Nodes[1] = this;
                } );

            // merge any LineContraints on a newly shared edge
            thisLCs.ForEach(
                delegate( LineConstraint lc )
                {
                    // get point that is not this point
                    DrawingPoint otherPt = lc.Nodes.Find( delegate( DrawingPoint p ) { return p != this; } );
                    if ( otherPt != null )
                    {
                        // check for LineConstraints formerly of other node that contain otherPt
                        otherLCs.ForEach(
                            delegate( LineConstraint otherLC )
                            {
                                if ( otherLC.Nodes.Contains( otherPt ) )
                                {
                                    // merge fixities
                                    lc.IsFixedX = lc.IsFixedX || otherLC.IsFixedX;
                                    lc.IsFixedY = lc.IsFixedY || otherLC.IsFixedY;

                                    for ( int i = 0 ; i < lc.PhaseFixedX.Count ; i++ )
                                    {
                                        lc.PhaseFixedX[i] = lc.PhaseFixedX[i] || otherLC.PhaseFixedX[i];
                                        lc.PhaseFixedY[i] = lc.PhaseFixedY[i] || otherLC.PhaseFixedY[i];
                                    }

                                    // replace the LineConstraint in other points parent blocks
                                    other.ParentBlocks.ForEach(
                                        delegate( MaterialBlock mb )
                                        {
                                            int index = mb.LineConstraints.FindIndex( delegate( LineConstraint lc0 ) { return lc0 == otherLC; } );
                                            if ( index >= 0 ) mb.LineConstraints[index] = lc;
                                        } );
                                    otherLC.Delete();
                                }
                            } );
                    }

                    lc.Update();
                } );
            // merge any LineLoads on a newly shared edge
            thisLLs.ForEach(
                delegate( LineLoad ll )
                {
                    // get the point that is not this point
                    DrawingPoint otherPt = ll.Nodes.Find( delegate( DrawingPoint p ) { return p != this; } );
                    if ( otherPt != null )
                    {
                        otherLLs.ForEach(
                            delegate( LineLoad otherLL )
                            {
                                if ( otherLL.Nodes.Contains( otherPt ) )
                                {
                                    // merge loads (NB: adjacent edges will always have reversed node order since both have CCW ordered points
                                    if ( otherLL.IsLoadedN )
                                    {
                                        ll.IsLoadedN = true;
                                        ll.NLoad1 -= otherLL.NLoad2;
                                        ll.NLoad2 -= otherLL.NLoad1;
                                    }
                                    if ( otherLL.IsLoadedT )
                                    {
                                        ll.IsLoadedT = true;
                                        ll.TLoad1 -= otherLL.TLoad2;
                                        ll.TLoad2 -= otherLL.TLoad1;
                                    }

                                    for ( int i = 0 ; i < ll.PhaseActiveN.Count ; i++ )
                                    {
                                        ll.PhaseActiveN[i] = ll.PhaseActiveN[i] || otherLL.PhaseActiveN[i];
                                        ll.PhaseFactorN[i] = ll.PhaseActiveN[i] ? 1.0 : 0.0;

                                        ll.PhaseActiveT[i] = ll.PhaseActiveT[i] || otherLL.PhaseActiveT[i];
                                        ll.PhaseFactorT[i] = ll.PhaseActiveT[i] ? 1.0 : 0.0;
                                    }

                                    // replace the LineLoad in other points parent blocks
                                    other.ParentBlocks.ForEach(
                                        delegate( MaterialBlock mb )
                                        {
                                            int index = mb.LineLoads.FindIndex( delegate( LineLoad ll0 ) { return ll0 == otherLL; } );
                                            if ( index >= 0 ) mb.LineLoads[index] = ll;
                                        } );
                                    //// delete the LineLoad formerly containing other point, leaving only a single summed LineLoad
                                    //other.ParentBlocks.ForEach(
                                    //    delegate( MaterialBlock mb )
                                    //    {
                                    //        mb.LineLoads.RemoveAll( delegate( LineLoad ll0 ) { return ll0 == otherLL; } );
                                    //    } );
                                    otherLL.Delete();
                                }
                            } );
                    }

                    ll.Update();
                } );
            // merge PointLoads if both points contained one
            if ( thisPL != null && otherPL != null )
            {
                if ( otherPL.IsLoadedX )
                {
                    thisPL.IsLoadedX = true;
                    thisPL.XLoad += otherPL.XLoad;
                }
                if ( otherPL.IsLoadedY )
                {
                    thisPL.IsLoadedY = true;
                    thisPL.YLoad += otherPL.YLoad;
                }

                for ( int i = 0 ; i < thisPL.PhaseActiveX.Count ; i++ )
                {
                    thisPL.PhaseActiveX[i] = thisPL.PhaseActiveX[i] || otherPL.PhaseActiveX[i];
                    thisPL.PhaseFactorX[i] = thisPL.PhaseActiveX[i] ? 1.0 : 0.0;

                    thisPL.PhaseActiveY[i] = thisPL.PhaseActiveY[i] || otherPL.PhaseActiveY[i];
                    thisPL.PhaseFactorY[i] = thisPL.PhaseActiveY[i] ? 1.0 : 0.0;
                }

                // replace the PointLoad in other points parent blocks
                other.ParentBlocks.ForEach(
                    delegate( MaterialBlock mb )
                    {
                        int index = mb.PointLoads.FindIndex( delegate( PointLoad pl0 ) { return pl0 == otherPL; } );
                        if ( index >= 0 ) mb.PointLoads[index] = thisPL;
                    } );
                //// delete PointLoad formerly of other point, leaving only a single summed load
                //other.ParentBlocks.ForEach(
                //    delegate( MaterialBlock mb ) { mb.PointLoads.RemoveAll( delegate( PointLoad pl ) { return pl == otherPL; } ); } );
                otherPL.Delete();

                thisPL.Update();
            }

            foreach ( MaterialBlock mb in other.ParentBlocks )
            {
                // merge the actual points
                int index = mb.BoundaryPoints.FindIndex( delegate( DrawingPoint p ) { return p == other; } );
                mb.BoundaryPoints[index] = this;
                mb.Boundary.Points[index] = this.Point;
                if ( !this.ParentBlocks.Contains( mb ) ) this.ParentBlocks.Add( mb );

                if ( thisPL != null && !mb.PointLoads.Contains( thisPL ) ) mb.PointLoads.Add( thisPL );

                // eliminate oddities such as LineLoads and LineConstraints containing duplicate points
                for ( int i = mb.LineLoads.Count - 1 ; i >= 0 ; i-- )
                {
                    if ( (!mb.LineLoads[i].IsLoadedN && !mb.LineLoads[i].IsLoadedT)
                        || (mb.LineLoads[i].Nodes[0] == this && mb.LineLoads[i].Nodes[1] == this) )
                    {
                        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].Nodes[0] == this && mb.LineConstraints[i].Nodes[1] == this) )
                    {
                        mb.LineConstraints[i].Delete();
                        mb.LineConstraints.RemoveAt( i );
                    }
                }
            }

            other.ParentBlocks.Clear();
            other.Delete();
        }
Ejemplo n.º 4
0
        public void AddPoint( DrawingPoint p1 , DrawingPoint p2 )
        {
            int index1 = 0;
            for ( int i = 0 ; i < BoundaryPoints.Count ; i++ )
            {
                if ( BoundaryPoints[i] == p1 )
                {
                    index1 = i;
                    break;
                }
            }

            int index2 = 0;
            for ( int i = 0 ; i < BoundaryPoints.Count ; i++ )
            {
                if ( BoundaryPoints[i] == p2 )
                {
                    index2 = i;
                    break;
                }
            }

            int maxIndex = Math.Max( index1 , index2 );
            int minIndex = Math.Min( index1 , index2 );

            if ( (maxIndex - minIndex) == 1 )
            {
                Point newPoint = new Point( 0.5 * (p1.Point.X + p2.Point.X) , 0.5 * (p1.Point.Y + p2.Point.Y) );
                BoundaryPoints.Insert( maxIndex , new DrawingPoint( canvas , this , newPoint ) );
                Boundary.Points.Insert( maxIndex , newPoint );
                canvas.IsSaved = false;
                canvas.IsVerified = false;
            }
            else if ( minIndex == 0 && maxIndex == BoundaryPoints.Count - 1 )
            {
                Point newPoint = new Point( 0.5 * (p1.Point.X + p2.Point.X) , 0.5 * (p1.Point.Y + p2.Point.Y) );
                BoundaryPoints.Add( new DrawingPoint( canvas , this , newPoint ) );
                Boundary.Points.Add( newPoint );
                canvas.IsSaved = false;
                canvas.IsVerified = false;
            }
            else
            {
                MessageBox.Show( "Points must be different and adjacent." , "Error" );
            }
        }
Ejemplo n.º 5
0
        /// <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( SlopeDefineCanvas canvas , DrawingPoint node ,
                                bool isLoadedX , double xLoad ,
                                bool isLoadedY , double yLoad )
        {
            // set parent drawing canvas
            this.defineCanvas = 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;

            // Add the point load to all blocks that contain its point
            List<MaterialBlock> parents = canvas.Substructs.FindAll( delegate( MaterialBlock mb ) { return mb.BoundaryPoints.Contains( node ); } );
            foreach ( MaterialBlock pmb in parents )
            {
                if ( !pmb.PointLoads.Contains( this ) ) pmb.PointLoads.Add( this );
            }

            Update();
        }
Ejemplo n.º 6
0
        public void ApplyPointLoad( DrawingPoint p )
        {
            // check if a point load has already been defined at this point
            PointLoad load = pointLoads.Find( delegate( PointLoad pl ) { return pl.Node == p; } );

            // if undefined, create a new point load object
            if ( load == null )
            {
                load = new PointLoad( canvas , p , false , 0 , false , 0 );
                //pointLoads.Add( load );
            }

            bool prevLoadedX = load.IsLoadedX , prevLoadedY = load.IsLoadedY;

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

            // if there is no load in horizontal or vertical direction, delete the load ...
            if ( !load.IsLoadedX && !load.IsLoadedY )
            {
                load.Delete();
                //pointLoads.Remove( load );
                canvas.MaterialBlocks.ForEach( delegate( MaterialBlock mb ) { mb.PointLoads.Remove( load ); } );
            }

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

            if ( dlg.DialogResult == true )
            {
                bool newLoadedX = load.IsLoadedX;
                if ( newLoadedX != prevLoadedX )
                {
                    for ( int i = 0 ; i < load.PhaseActiveX.Count ; i++ )
                    {
                        load.PhaseActiveX[i] = newLoadedX;
                        load.PhaseFactorX[i] = newLoadedX ? 1.0 : 0.0;
                    }
                }

                bool newLoadedY = load.IsLoadedY;
                if ( newLoadedY != prevLoadedY )
                {
                    for ( int i = 0 ; i < load.PhaseActiveY.Count ; i++ )
                    {
                        load.PhaseActiveY[i] = newLoadedY;
                        load.PhaseFactorY[i] = newLoadedY ? 1.0 : 0.0;
                    }
                }

                canvas.IsSaved = false;
                canvas.IsVerified = false;
            }
        }
Ejemplo n.º 7
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" );
            }
        }
Ejemplo n.º 8
0
        public bool ApplyFixity( DrawingPoint p1 , DrawingPoint p2 )
        {
            bool added = false;

            // 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." , "Fix X error" );
                return added;
            }

            // 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;
            }

            // if points are the same, fix/unfix the point ...
            if ( index1 == index2 )
            {
                bool prevFixedX = p1.IsFixedX , prevFixedY = p1.IsFixedY;

                SetFixityDialog dlg = new SetFixityDialog( canvas , p1 );
                dlg.ShowDialog();

                if ( dlg.DialogResult == true )
                {
                    bool newFixedX = p1.IsFixedX;
                    if ( newFixedX != prevFixedX )
                    {
                        for ( int i = 0 ; i < p1.PhaseFixActiveX.Count ; i++ )
                        {
                            p1.PhaseFixActiveX[i] = newFixedX;
                        }
                    }

                    bool newFixedY = p1.IsFixedY;
                    if ( newFixedY != prevFixedY )
                    {
                        for ( int i = 0 ; i < p1.PhaseFixActiveY.Count ; i++ )
                        {
                            p1.PhaseFixActiveY[i] = newFixedY;
                        }
                    }

                    canvas.IsSaved = false;
                    canvas.IsVerified = false;
                }
                added = true;
            }

            // ... or if the points are adjacent, create a line constraint ...
            else if ( ((index2 - index1) == 1) || (index2 == 0 && index1 == BoundaryPoints.Count - 1) )
            {
                LineConstraint existingLC = LineConstraints.Find( delegate( LineConstraint lc ) { return lc.Nodes.Contains( p1 ) && lc.Nodes.Contains( p2 ); } );

                if ( existingLC != null )
                {
                    bool prevFixX = existingLC.IsFixedX;
                    bool prevFixY = existingLC.IsFixedY;

                    SetFixityDialog dlg = new SetFixityDialog( canvas , existingLC );
                    dlg.ShowDialog();

                    if ( dlg.DialogResult == true )
                    {
                        bool newFixX = existingLC.IsFixedX;
                        if ( newFixX != prevFixX )
                        {
                            for ( int i = 0 ; i < existingLC.PhaseFixedX.Count ; i++ )
                                existingLC.PhaseFixedX[i] = newFixX;

                            for ( int i = 0 ; i < existingLC.Nodes.Count ; i++ )
                            {
                                for ( int j = 0 ; j < existingLC.Nodes[i].PhaseFixActiveX.Count ; j++ )
                                    existingLC.Nodes[i].PhaseFixActiveX[j] =
                                        existingLC.Nodes[i].PhaseFixActiveX[j] || existingLC.PhaseFixedX[j];
                            }
                        }
                        bool newFixY = existingLC.IsFixedY;
                        if ( newFixY != prevFixY )
                        {
                            for ( int i = 0 ; i < existingLC.PhaseFixedY.Count ; i++ )
                                existingLC.PhaseFixedY[i] = newFixY;

                            for ( int i = 0 ; i < existingLC.Nodes.Count ; i++ )
                            {
                                for ( int j = 0 ; j < existingLC.Nodes.Count ; j++ )
                                    existingLC.Nodes[i].PhaseFixActiveY[j] =
                                        existingLC.Nodes[i].PhaseFixActiveY[j] || existingLC.PhaseFixedY[j];
                            }
                        }

                        canvas.IsSaved = false;
                        canvas.IsVerified = false;
                    }
                    added = true;
                }
                else
                {
                    LineConstraint newLC = new LineConstraint( canvas , p1 , p2 , false , false );
                    SetFixityDialog dlg = new SetFixityDialog( canvas , newLC );
                    dlg.ShowDialog();

                    if ( dlg.DialogResult == true )
                    {
                        bool newFixX = newLC.IsFixedX , newFixY = newLC.IsFixedY;
                        for ( int i = 0 ; i < newLC.PhaseFixedX.Count ; i++ )
                        {
                            newLC.PhaseFixedX[i] = newFixX;
                            newLC.PhaseFixedY[i] = newFixY;
                        }
                        for ( int i = 0 ; i < newLC.Nodes.Count ; i++ )
                        {
                            for ( int j = 0 ; j < newLC.Nodes[i].PhaseFixActiveX.Count ; j++ )
                            {
                                newLC.Nodes[i].PhaseFixActiveX[j] =
                                    newLC.Nodes[i].PhaseFixActiveX[j] || newLC.PhaseFixedX[j];

                                newLC.Nodes[i].PhaseFixActiveY[j] =
                                    newLC.Nodes[i].PhaseFixActiveY[j] || newLC.PhaseFixedY[j];
                            }
                        }

                        //canvas.MaterialBlocks.ForEach(
                        //    delegate( MaterialBlock mb )
                        //    {
                        //        if ( mb.BoundaryPoints.Contains( p1 ) && mb.BoundaryPoints.Contains( p2 ) )
                        //            mb.LineConstraints.Add( newLC );
                        //    } );

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

                    added = true;
                }
            }

            // ... otherwise, indicate that a constraint cannot be applied in this manner
            else
            {
                MessageBox.Show( "Points must be either the same or directly adjacent." , "Error" );
                return added;
            }

            // remove any line constraints that are both unfixed
            canvas.MaterialBlocks.ForEach(
                delegate( MaterialBlock mb )
                {
                    mb.LineConstraints.RemoveAll( delegate( LineConstraint lc ) { return (!lc.IsFixedX && !lc.IsFixedY); } );
                } );

            return added;
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
        /// <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( SlopeDefineCanvas canvas ,
                                DrawingPoint p1 , DrawingPoint p2 ,
                                bool isLoadedN ,
                                double nLoad1 , double nLoad2 ,
                                bool isLoadedT ,
                                double tLoad1 , double tLoad2 )
        {
            // set parent drawing canvas
            this.defineCanvas = 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.TFactor = 1.0;
            this.IsLoadedT = isLoadedT;
            if ( this.IsLoadedT ) this.TFactor = 1.0;
            this.TLoad1 = tLoad1;
            this.TLoad2 = tLoad2;

            // Add the constraint to all blocks that contain both of its points
            List<MaterialBlock> parents = canvas.Substructs.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();
        }
Ejemplo n.º 11
0
        public LineConstraint( SlopeDefineCanvas canvas ,
                                DrawingPoint p1 , DrawingPoint p2 ,
                                bool fixX , bool fixY )
        {
            // set parent drawing canvas
            this.defineCanvas = 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 ) );

            // Add the constraint to all blocks that contain both of its points
            List<MaterialBlock> parents = canvas.Substructs.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;
        }