Esempio n. 1
0
        /// <summary>
        /// The form is closed.  Clean up.
        /// </summary>
        private void _formClosed(object sender, System.Windows.Forms.FormClosedEventArgs args)
        {
            try
            {
                if (false == this.InvokeRequired)
                {
                    if (this == CadKit.Documents.Manager.Instance.ActiveView)
                    {
                        CadKit.Documents.Manager.Instance.ActiveView = null;
                    }

                    CadKit.Interfaces.IDocument document = this.Document;
                    CadKit.Viewer.Panel         panel    = this.Panel;

                    // Call this first because it circles back around and expects the panel to exist.
                    if (null != document)
                    {
                        document.remove(this);
                        this.Document = null;
                    }

                    // Now clear the panel.
                    if (null != panel)
                    {
                        panel.clear();
                        this.Panel = null;
                    }
                }
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("Error 6554359560: {0}", e.Message);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Determine if the button should be enabled.
 /// </summary>
 protected override bool _shouldBeEnabled()
 {
     CadKit.Interfaces.IDocument       idoc     = CadKit.Documents.Manager.Instance.ActiveDocument;
     CadKit.Documents.Document         doc      = idoc as CadKit.Documents.Document;
     CadKit.Interfaces.ICommandHistory commands = (null == doc) ? null : doc.CommandHistory;
     return((null == commands) ? false : commands.CanRedo);
 }
Esempio n. 3
0
        /// <summary>
        /// Called when the label is clicked.
        /// </summary>
        void _labelClick(object sender, System.EventArgs args)
        {
            try
            {
                int index = _flowLayoutPanel.Controls.IndexOf(sender as System.Windows.Forms.Control);

                if (index >= 0 && index < _documentNew.Length)
                {
                    // Create the document.
                    CadKit.Documents.Document   doc  = _documentNew[index].create(_caller) as CadKit.Documents.Document;
                    CadKit.Interfaces.IDocument idoc = doc as CadKit.Interfaces.IDocument;
                    CadKit.Documents.Manager.Instance.addDocument(idoc);

                    // Give the document a command history. Assigning this avoids a dependency.
                    if (null != doc)
                    {
                        doc.CommandHistory = new CadKit.Commands.History();
                    }

                    // Set the delegate.
                    CadKit.Documents.Manager.Instance.setGuiDelegate(idoc, this.Caller);

                    // Create the default user-interface.
                    if (false == this._createDefaultGui(idoc))
                    {
                        idoc.close();
                        CadKit.Documents.Manager.Instance.remove(idoc);
                    }
                }
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("Error 96335236: trying to create new document: {0}", e.Message);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Open the document. Either returns a document or throws.
        /// </summary>
        public CadKit.Interfaces.IDocument open(string name, ChooseBestOpenerDelegate del, object caller)
        {
            // Re-entrant! Do not lock the mutex!

            // Look for existing document with this name.
            CadKit.Interfaces.IDocument document = this.findDocument(name);
            if (null != document)
            {
                this.windowsForward(document, caller);
                return(document);
            }

            // Determine the opener that handles this extension.
            CadKit.Interfaces.IDocumentOpen opener = this._findBestOpener(name, del, caller);
            if (null == opener)
            {
                System.IO.FileInfo info = new System.IO.FileInfo(name);
                throw new System.Exception("Error 4027629339: Failed to find plugin that opens files with extension '" + info.Extension + "'");
            }

            // Open the document. This may throw.
            document = (CadKit.Interfaces.IDocument)(opener.open(name, caller));

            // If we get to here then add the new document.
            this.addDocument(document);

            // Return new document.
            return(document);
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        public override void execute()
        {
            try
            {
                CadKit.Interfaces.IDocument document = CadKit.Documents.Manager.Instance.ActiveDocument;
                if (null != document)
                {
                    // Only save if the document is modified.
                    // This function should never get called if this is false, but it can't hurt to have the check.
                    if (document.Modified)
                    {
                        // If the document has a name.
                        if (false == document.HasDefaultName)
                        {
                            CadKit.Interfaces.IFileSave save = document as CadKit.Interfaces.IFileSave;
                            if (null != save)
                            {
                                save.save(_caller);
                            }
                        }

                        // We need to have the user choose a name.
                        else
                        {
                            CadKit.Helios.Commands.SaveAsDocumentCommand saveAs = new SaveAsDocumentCommand(_caller);
                            saveAs.execute();
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("Error 1903003532: {0}", e.Message);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Create the default user-interface.
        /// </summary>
        private bool _createDefaultGui(CadKit.Interfaces.IDocument idoc)
        {
            bool result = false;

            try
            {
                System.Windows.Forms.Form form = CadKit.Helios.Application.Instance.MainForm;
                if (true == form.InvokeRequired)
                {
                    CreateDefaultGuiDelegate function = new CreateDefaultGuiDelegate(this._createDefaultGui);
                    result = (bool)(form.Invoke(function, new object[] { idoc }));
                }
                else
                {
                    CadKit.Interfaces.IGuiCreate gui = idoc as CadKit.Interfaces.IGuiCreate;
                    if (null != gui)
                    {
                        gui.create(this.Caller);
                        result = true;
                    }
                }
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("Error 2697332471: Failed to create default user interface: {0}", e.Message);
            }
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Remove the document.
        /// </summary>
        public void remove(CadKit.Interfaces.IDocument document)
        {
            if (null != document)
            {
                if (document == this.ActiveDocument)
                {
                    // This also sets active document to null.
                    this.ActiveView = null;
                }
                using (this.Lock.write())
                {
                    while (true == _documents.Remove(document))
                    {
                    }

                    // Clear the GUI delegate.
                    //document.GuiDelegate.Document = null;
                    //document.GuiDelegate = null;
                    document.close();

                    // Wait for cleanup.
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Bring the windows forward.
 /// </summary>
 void CadKit.Interfaces.IWindowsForward.windowsForward(object caller)
 {
     CadKit.Interfaces.IDocument       document = this.Document;
     CadKit.Interfaces.IDocumentView[] views    = this.Document.views();
     foreach (CadKit.Interfaces.IDocumentView view in views)
     {
         this._activateView(view);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Execute the command.
 /// </summary>
 public override void execute()
 {
     CadKit.Interfaces.IDocument       idoc     = CadKit.Documents.Manager.Instance.ActiveDocument;
     CadKit.Documents.Document         doc      = idoc as CadKit.Documents.Document;
     CadKit.Interfaces.ICommandHistory commands = (null == doc) ? null : doc.CommandHistory;
     if (null != commands && true == commands.CanRedo)
     {
         commands.redo();
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Add the document.
 /// </summary>
 public void addDocument(CadKit.Interfaces.IDocument document)
 {
     if (null != document)
     {
         using (this.Lock.write())
         {
             _documents.Add(document);
         }
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Construct a view.
        /// </summary>
        public Viewer(object caller, CadKit.Interfaces.IDocument document) : base()
        {
            this.Icon      = System.Windows.Forms.Application.OpenForms[0].Icon;
            this.MdiParent = caller as System.Windows.Forms.Form;

            _document = document;
            this.Text = (null == _document) ? this.ToString() : _document.Name;

            this.Load += this._load;
        }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        protected override bool _shouldBeEnabled()
        {
            CadKit.Interfaces.IDocument document = CadKit.Documents.Manager.Instance.ActiveDocument;
            if (null != document)
            {
                return(document is CadKit.Interfaces.IFileExport);
            }

            return(false);
        }
Esempio n. 13
0
        /// <summary>
        /// Bring this document's windows to the front.
        /// </summary>
        public void windowsForward(CadKit.Interfaces.IDocument doc, object caller)
        {
            // Re-entrant! Do not lock the mutex! This is a convenience function
            // that does not alter any members.

            CadKit.Interfaces.IWindowsForward forward = doc as CadKit.Interfaces.IWindowsForward;
            if (null != forward)
            {
                forward.windowsForward(caller);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Called when the parent is shown.
        /// </summary>
        void _parentShown(object sender, System.EventArgs e)
        {
            try
            {
                _documentNew = CadKit.Plugins.Manager.Instance.getAll <CadKit.Interfaces.IDocumentNew>();

                for (uint i = 0; i < _documentNew.Length; ++i)
                {
                    CadKit.Documents.Document   doc  = this._createDocument(i);
                    CadKit.Interfaces.IDocument iDoc = doc as CadKit.Interfaces.IDocument;

                    if (null != doc && null != iDoc)
                    {
                        System.Windows.Forms.LinkLabel label = new System.Windows.Forms.LinkLabel();
                        label.Name   = iDoc.TypeName;
                        label.Text   = iDoc.TypeName;
                        label.Click += new System.EventHandler(_labelClick);

                        CadKit.Interfaces.IDocumentIcon docIcon = iDoc as CadKit.Interfaces.IDocumentIcon;
                        if (docIcon == null || docIcon.Icon == null)
                        {
                            label.Image = CadKit.Images.Image.load(CadKit.Helios.Application.Instance.IconDir + "/new_document.png");
                        }
                        else
                        {
                            label.Image = docIcon.Icon as System.Drawing.Image;
                        }

                        label.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                        label.TextAlign  = System.Drawing.ContentAlignment.MiddleRight;
                        _flowLayoutPanel.Controls.Add(label);
                    }

                    doc = null;
                }

                System.Windows.Forms.Form parent = sender as System.Windows.Forms.Form;
                CadKit.Tools.ToolWindow.configure(this, parent, "New Document", false);

                _configureDockWindow(sender, this);

                CadKit.Interfaces.IWindowMenu windowMenu = sender as CadKit.Interfaces.IWindowMenu;
                if (null != windowMenu)
                {
                    windowMenu.addFormWindowMenu(this.Text, this);
                }

                parent.Activate();
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine("Error 3980677532: building new document form: {0}", ex.Message);
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Hook up document with appropriate delegate.
 /// </summary>
 public void setGuiDelegate(CadKit.Interfaces.IDocument doc, object caller)
 {
     if (null != doc)
     {
         // Look for delegate.
         CadKit.Interfaces.IGuiDelegateCreate[] creators = CadKit.Plugins.Manager.Instance.getAll <CadKit.Interfaces.IGuiDelegateCreate>();
         foreach (CadKit.Interfaces.IGuiDelegateCreate creator in creators)
         {
             CadKit.Interfaces.IGuiDelegate gui = ((null != creator) ? (creator.create(caller) as CadKit.Interfaces.IGuiDelegate) : null);
             if (null != gui && true == gui.doesHandle(doc.TypeName))
             {
                 doc.GuiDelegate = gui;
                 gui.Document    = doc;
             }
         }
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Set the active document.
        /// </summary>
        private void _setActiveDocument()
        {
            CadKit.Interfaces.IDocumentView activeView = this.ActiveView;
            CadKit.Interfaces.IDocument     oldDoc     = this.ActiveDocument;

            using (this.Lock.write())
            {
                _activeDoc = (null == activeView) ? null : activeView.Document;
            }

            //if (oldDoc != this.ActiveDocument)
            {
                if (null != this.ActiveDocumentChanged)
                {
                    this.ActiveDocumentChanged(oldDoc, this.ActiveDocument);
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        ///
        /// </summary>
        void _activeDocumentChanged(CadKit.Interfaces.IDocument oldDoc, CadKit.Interfaces.IDocument newDoc)
        {
            if (oldDoc == newDoc)
            {
                return;
            }

            if (null != oldDoc)
            {
                oldDoc.remove(this);
            }

            _document = newDoc;

            if (null != _document)
            {
                _document.add(this);
            }

            this.addLayers();

            _treeView.Invalidate();
        }
Esempio n. 18
0
        /// <summary>
        /// Called when the thread starts.
        /// </summary>
        protected override void _startJob(CadKit.Threads.Jobs.Job job)
        {
            // Should be true.
            System.Diagnostics.Debug.Assert(false == CadKit.Threads.Tools.MainThread.Instance.IsMainThread);

            // If it exists then bring it forward.
            CadKit.Interfaces.IDocument idoc = CadKit.Documents.Manager.Instance.findDocument(this.File);
            if (null != idoc)
            {
                CadKit.Documents.Manager.Instance.windowsForward(idoc, this.Caller);
                return;
            }

            // Feedback.
            System.Console.WriteLine(System.String.Format("Opening file: {0}", this.File));

            // Open the document.
            idoc = CadKit.Documents.Manager.Instance.open(this.File, null, this);

            // Give the document a command history. Assigning this avoids a dependency.
            CadKit.Documents.Document doc = idoc as CadKit.Documents.Document;
            if (null != doc)
            {
                doc.CommandHistory = new CadKit.Commands.History();
                doc.CommandHistory.add(this.Command);
            }

            // Set the delegate.
            CadKit.Documents.Manager.Instance.setGuiDelegate(idoc, this.Caller);

            // Create the default user-interface.
            if (false == this._createDefaultGui(idoc))
            {
                idoc.close();
                CadKit.Documents.Manager.Instance.remove(idoc);
            }
        }
Esempio n. 19
0
 /// <summary>
 ///
 /// </summary>
 private void _activeDocumentChanged(CadKit.Interfaces.IDocument oldDoc, CadKit.Interfaces.IDocument newDoc)
 {
     CadKit.Interfaces.IImageLayer imageLayer = newDoc as CadKit.Interfaces.IImageLayer;
     _listView.Enabled = (imageLayer != null);
 }