public override void Execute()
        {
            // if is already executing do nothing
            if (mExecuting)
            {
                return;
            }

            mExecuting = true;

            try
            {
                AxDrawingControl _activeCtrl = null;

                //get drawing for which the core connections diagram should be generated
                DrawingControlWindow _wnd = diagApp.GetCurrentDrawingControl();
                if (_wnd != null)
                {
                    _activeCtrl = _wnd.mVisioDrawingControl.ActiveXDrawingControl;
                }

                ArrayList _cableList = new ArrayList();

                // if drawing is found
                if (_activeCtrl != null)
                {
                    // get active window
                    Visio.Window _actWindow = _activeCtrl.Document.Application.ActiveWindow;
                    // get selection
                    Visio.Selection _selection = _actWindow.Selection;
                    _selection.IterationMode &= ~(int)Visio.VisSelectMode.visSelModeSkipSub;

                    // get cables from selection or from all document (if nothing is selected)
                    if (_selection.Count > 0)
                    {
                        foreach (Visio.Shape _shape in _selection)
                        {
                            CheckAddShape(_shape, _cableList);
                        }
                    }
                    else
                    {
                        foreach (Visio.Page _page in ((AxDrawingControl)_activeCtrl).Document.Pages)
                        {
                            foreach (Visio.Shape _shape in _page.Shapes)
                            {
                                CheckAddShape(_shape, _cableList);
                            }
                        }
                    }
                }

                if (_cableList.Count == 0)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot get cables for Core Connections Diagram!", "Core Connections Diagram");
                    return;
                }

                //create new empty diagram
                DrawingControlWindow _dwgInstance = new DrawingControlWindow();
                AxDrawingControl     _newDwgCtrl  = null;

                if (_dwgInstance != null)
                {
                    _newDwgCtrl = _dwgInstance.NewDiagram();
                }

                if (_newDwgCtrl != null)
                {
                    CoreConnectionsDiagram _diag = new CoreConnectionsDiagram(_newDwgCtrl);
                    _diag.DrawSchema(_cableList);
                    DrawingManager.SaveNewDrawingToDb(_dwgInstance);
                }
            }
            catch (Exception _ex)
            {
                Console.WriteLine(_ex.ToString());
            }
            finally
            {
                mExecuting = false;
            }
        }
Esempio n. 2
0
        public override void Execute()
        {
            // if is already executing do nothing
            if( mExecuting )
                return;

            mExecuting = true;

            try
            {
                AxDrawingControl _activeCtrl = null;

                //get drawing for which the core connections diagram should be generated
                DrawingControlWindow _wnd = diagApp.GetCurrentDrawingControl();
                if( _wnd != null )
                    _activeCtrl = _wnd.mVisioDrawingControl.ActiveXDrawingControl;

                ArrayList _cableList = new ArrayList();

                // if drawing is found
                if( _activeCtrl != null )
                {
                    // get active window
                    Visio.Window _actWindow = _activeCtrl.Document.Application.ActiveWindow;
                    // get selection
                    Visio.Selection _selection = _actWindow.Selection;
                    _selection.IterationMode &= ~(int)Visio.VisSelectMode.visSelModeSkipSub;

                    // get cables from selection or from all document (if nothing is selected)
                    if( _selection.Count > 0 )
                    {
                        foreach( Visio.Shape _shape in _selection )
                            CheckAddShape( _shape, _cableList );
                    }
                    else
                    {
                        foreach( Visio.Page _page in ( (AxDrawingControl)_activeCtrl ).Document.Pages )
                            foreach( Visio.Shape _shape in _page.Shapes )
                                CheckAddShape( _shape, _cableList );
                    }
                }

                if( _cableList.Count == 0 )
                {
                    System.Windows.Forms.MessageBox.Show( "Cannot get cables for Core Connections Diagram!", "Core Connections Diagram" );
                    return;
                }

                //create new empty diagram
                DrawingControlWindow _dwgInstance = new DrawingControlWindow();
                AxDrawingControl _newDwgCtrl = null;

                if( _dwgInstance != null )
                    _newDwgCtrl = _dwgInstance.NewDiagram();

                if( _newDwgCtrl != null )
                {
                    CoreConnectionsDiagram _diag = new CoreConnectionsDiagram( _newDwgCtrl );
                    _diag.DrawSchema( _cableList );
                    DrawingManager.SaveNewDrawingToDb( _dwgInstance );
                }
            }
            catch( Exception _ex )
            {
                Console.WriteLine( _ex.ToString() );
            }
            finally
            {
                mExecuting = false;
            }
        }