예제 #1
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" );
            }
        }
예제 #2
0
        /// <summary>
        /// Override for left-click selection
        /// </summary>
        /// <param name="sender">Reference to sending object.</param>
        /// <param name="e">Mouse event arguments.</param>
        private void MouseLeftButtonUp( object sender , MouseEventArgs e )
        {
            if ( canvas != null )
            {
                if ( canvas.DrawMode == DrawModes.Select
                    || canvas.DrawMode == DrawModes.LineLoad )
                {
                    // start dialog for user input
                    AddLineLoadDialog dlg = new AddLineLoadDialog( canvas , this );
                    dlg.ShowDialog();

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

                        //MaterialBlock parent = null;
                        //foreach ( MaterialBlock mb in canvas.MaterialBlocks )
                        //{
                        //    if ( mb.LineLoads.Contains( this ) )
                        //    {
                        //        parent = mb;
                        //        break;
                        //    }
                        //}
                        //if ( parent != null ) parent.LineLoads.Remove( this );
                    }

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

                    if ( dlg.DialogResult == true )
                    {
                        canvas.IsSaved = false;
                        canvas.IsVerified = false;
                    }
                }
            }
            else if ( defineCanvas != null )
            {
                FactorLineLoadDialog dlg = new FactorLineLoadDialog( defineCanvas , this );
                dlg.ShowDialog();

                this.Update();
            }
        }