Click here to Skip to main content
12,506,293 members (54,878 online)
Click here to Skip to main content

Stats

197.6K views
9.7K downloads
138 bookmarked
Posted

DSGraphEdit: A Reasonable Facsimile of Microsoft's GraphEdit in .NET

, 19 Dec 2007 CPOL
A library for adding DirectShow GraphEdit-like abilities to .NET applications.
WeifenLuo.WinFormsUI.Docking.dll
DaggerLib.dll
DaggerLib.DSGraphEdit.dll
DaggerLib.UI.Windows.dll
DirectShowLib-2005.dll
DSGraphEdit.exe
MediaFoundation.dll
DSGraphEdit
bin
Release
DSIcon.ico
Properties
Referenced Libs
WeifenLuo.WinFormsUI.Docking.dll
RemoteGraphTile.jpg
DaggerLib
bin
Release
Core
Interfaces
Properties
SetGeneric
UI
DaggerLib.DSGraphEdit
DMOParameterControls
DSFilterTreeView
DSGraphEditControls
lib
Properties
ReferencedLibs
DirectShowLib-2005.dll
MediaFoundation.dll
DaggerLib.UI.Windows
AStar
bin
Debug
DaggerPropertyGrid
PropertyGridEx
Properties
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;

using DaggerLib.Interfaces;
using DaggerLib.Core;

namespace DaggerLib.UI.Windows
{
    public partial class DaggerUISubNode : DaggerUINode , IDaggerUISubNode
    {
        //the edit SubNode Caption Button
        internal SimpleImageButton _editSubNodeButton;

        //UIGraph for editing a subnode's graph
        internal DaggerUIGraph _subNodeUIGraph;

        private DaggerSubNode _node;

        public DaggerUISubNode()
        {
            InitializeComponent();
            this.DaggerNodeAttached += new DaggerNodeAttachedHandler(DaggerUISubNode_DaggerNodeAttached);
        }

        public DaggerPinLegend PinLegend
        {
            get
            {
                if (_subNodeUIGraph != null)
                {
                    return _subNodeUIGraph.PinLegend;
                }
                else
                {
                    return null;
                }
            }
            set
            {
                if (_subNodeUIGraph != null)
                {
                    _subNodeUIGraph.PinLegend = value;
                }
            }
        }

        void DaggerUISubNode_DaggerNodeAttached(DaggerNode node)
        {
            // store the sub node so we can make the UIGraph for it later
            _node = (DaggerSubNode)node;
            _node.SubNodeGraph.ImportedPins.PinAdded += new DaggerPinAdded(ImportedPins_PinAdded);
            _node.SubNodeGraph.ExportedPins.PinAdded += new DaggerPinAdded(ExportedPins_PinAdded);
            _editSubNodeButton = new SimpleImageButton();
            _editSubNodeButton.ButtonImage = _subnodeEditButtonImageList.Images[0];
            _editSubNodeButton.ButtonImage2 = _subnodeEditButtonImageList.Images[1];
            _editSubNodeButton.MultiState = true;
            _editSubNodeButton.ToolTipText = "Edit SubNode";
            _editSubNodeButton.ToolTipEnabled = true;
            _editSubNodeButton.StateChanged += new SimpleImageButton.StateChangedEventHandler(_editSubNodeButton_StateChanged);
            CaptionButtons.Add(_editSubNodeButton);
        }

        void ExportedPins_PinAdded(object sender, DaggerBasePin pin)
        {
            if (pin.PinUIElements == null)
            {
                pin.PinUIElements = new PinUI(pin);
            }
        }

        void ImportedPins_PinAdded(object sender, DaggerBasePin pin)
        {
                        if (pin.PinUIElements == null)
            {
                pin.PinUIElements = new PinUI(pin);
            }
        }

        /// <summary>
        /// Event that is raised when the Edit SubNode Caption button is toggled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _editSubNodeButton_StateChanged(object sender, EventArgs e)
        {
            if (_editSubNodeButton.State)
            {
                if (_subNodeUIGraph == null)
                {
                    // create the ui graph for the SubNode
                    _subNodeUIGraph = new DaggerUIGraph(_node.SubNodeGraph, (ParentUIGraph as DaggerUIGraph).PinLegend);
                    _subNodeUIGraph.Visible = true;
                    _subNodeUIGraph.Dock = DockStyle.Fill;
                    _internalControl.Controls.Add(_subNodeUIGraph);

                    // copy the settings of the parent ui graph
                    (ParentUIGraph as DaggerUIGraph).CopySettings(_subNodeUIGraph);
                }

                //expand node for editing
                InternalControl.Visible = true;
                Size = _subNodeUIGraph.OccupiedRegion.Size;
                Resizable = true;
            }
            else
            {
                //collapse node
                InternalControl.Visible = false;
                Resizable = false;
                Size = NodeMinimumSize;
            }
        }

        private void _saveSubNodeToTreeViewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            byte[] subnode = (_node as DaggerSubNode).SubNodeGraph.SerializeSubGraph(-1);

            if (subnode != null)
            {
                if (_parentGraph.DaggerNodeTreeView != null)
                {
                    ValueEditorDialog vue = new ValueEditorDialog("Subnode Name", "Subnode");
                    if (vue.ShowDialog() == DialogResult.OK)
                    {
                        _parentGraph.DaggerNodeTreeView.AddSubNode("User functions", (string)vue.Data, false, subnode);
                    }
                }
                else
                {
                    ValueEditorDialog vue = new ValueEditorDialog("Subnode Name", "Subnode");
                    if (vue.ShowDialog() == DialogResult.OK)
                    {
                        _node.ParentGraph.AddNode(new DaggerSubNode((string)vue.Data, subnode));
                    }
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

JohnnyLocust
Software Developer (Senior) Haivision Network Video
United States United States
AKA Rich Insley.

I have over 25 years experience in programming, and I'm completely self taught. (Except for one year at California State University Fresno where I had to learn the God awful language Miranda (http://miranda.org.uk/). I've spent 10 years as a Paratrooper in the US Army during the Clinton Administration.

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160927.1 | Last Updated 20 Dec 2007
Article Copyright 2007 by JohnnyLocust
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid