Esempio n. 1
0
        private void GraphForm_MouseMove(object sender, MouseEventArgs e)
        {
            mousepos = e.Location;
            mousepos.X += hScrollBar.Value;
            mousepos.Y += vScrollBar.Value - toolStripHeight;

            if (movingFilter != null)
            {
                int dx = (mousepos.X - movingStart.X) / graph.cellsize;
                int dy = (mousepos.Y - movingStart.Y) / graph.cellsize;
                if (dx != 0 || dy != 0)
                {
                    Point c = movingFilter.movingStartCoords;
                    c.X += dx;
                    c.Y += dy;
                    c.X = Math.Max(c.X, 1);
                    c.Y = Math.Max(c.Y, 0);
                    if (c != movingFilter.Coords)
                    {
                        foreach(Filter f in graph.SelectedFilters)
                            graph.PlaceFilter(f, false);
                        bool canplace = true;
                        foreach (Filter f in graph.SelectedFilters)
                        {
                            c = f.movingStartCoords;
                            c.X += dx;
                            c.Y += dy;
                            c.X = Math.Max(c.X, 1);
                            c.Y = Math.Max(c.Y, 0);
                            if (!graph.CanPlaceFilter(c, f))
                            {
                                canplace = false;
                                break;
                            }
                        }

                        if (canplace)
                        {
                            foreach (Filter f in graph.SelectedFilters)
                            {
                                c = f.movingStartCoords;
                                c.X += dx;
                                c.Y += dy;
                                c.X = Math.Max(c.X, 1);
                                c.Y = Math.Max(c.Y, 0);
                                f.Coords = c;
                                graph.PlaceFilter(f, true);
                            }
                            graph.RecalcPaths();
                            RecalcScrolls();
                            Invalidate();
                        }
                        else
                            foreach (Filter f in graph.SelectedFilters)
                                graph.PlaceFilter(f, true);
                    }
                }
            }
            if (connectingPin != null && connectingPin.Connection==null)
            {
                otherPin = null;
                Filter f = graph.FilterInPoint(mousepos);
                if (f != null)
                {
                    Pin p = f.PinInPoint(mousepos);
                    if (p != null && p.Direction != connectingPin.Direction && p.Connection==null)
                        otherPin = p;                        
                }
                Invalidate();
            }
            if (selecting)
            {
                Invalidate();
            }
            DescribeActions();
        }
Esempio n. 2
0
        private void OnLButtonUp()
        {
            if (movingFilter != null)
                foreach (Filter f in graph.SelectedFilters)
                    f.movingStartCoords = f.Coords;
            movingFilter = null;

            if (connectingPin != null)
            {
                if (mousepos == movingStart) //just click on pin
                {
                    if (connectingPin.Connection != null)
                    {
                        AMMediaType mt = new AMMediaType();
                        connectingPin.IPin.ConnectionMediaType(mt);
                        MediaTypeProps mtp = MediaTypeProps.CreateMTProps(mt); //new MediaTypeProps(mt);
                        Program.mainform.propform.SetObject(mtp);
                    }
                    else
                    {
                        IEnumMediaTypes mtenum;
                        if (connectingPin.IPin.EnumMediaTypes(out mtenum) >= 0)
                        {
                            AMMediaType[] mts = new AMMediaType[1];
                            List<MediaTypeProps> mtypes = new List<MediaTypeProps>();
                            IntPtr fetched = Marshal.AllocHGlobal(4);
                            while (mtenum.Next(1, mts, fetched) == 0)
                                mtypes.Add(MediaTypeProps.CreateMTProps(mts[0]));
                            Marshal.FreeHGlobal(fetched);
                            Program.mainform.propform.SetObject(mtypes.ToArray());
                        }
                    }
                }
                else
                {
                    if (otherPin != null)
                    {
                        Pin inpin, outpin;
                        if (connectingPin.Direction == PinDirection.Input)
                        {
                            inpin = connectingPin;
                            outpin = otherPin;
                        }
                        else
                        {
                            inpin = otherPin;
                            outpin = connectingPin;
                        }
                        graph.Connect(outpin, inpin, true);
                    }
                }
                Invalidate();
            }

            if (selecting)
            {
                Rectangle rc = new Rectangle(Math.Min(mousepos.X, movingStart.X), Math.Min(mousepos.Y, movingStart.Y),
                    Math.Abs(mousepos.X - movingStart.X), Math.Abs(mousepos.Y - movingStart.Y));
                if (ModifierKeys != Keys.Shift)
                    graph.ClearFiltersSelection();
                graph.SelectSeveralFilters(rc);
                selecting = false;
                Invalidate();
            }
            connectingPin = null;
            otherPin = null;
        }
Esempio n. 3
0
        private void OnRButtonDown(Point eLocation)
        {
            Filter filter = graph.FilterInPoint(mousepos);
            if (filter != null)
            {
                Pin pin = filter.PinInPoint(mousepos);
                if (pin != null)
                {                    
                        movingStart = mousepos;
                        connectingPin = pin;                       
                }
                else //filter right click
                {
                    rightClickedFilter = filter;
                    ContextMenu menu = new ContextMenu();
                    if (FilterGraphTools.HasPropertyPages(filter.BaseFilter))
                        menu.MenuItems.Add("Property page", ShowPropertyPage);

                    IAMVfwCompressDialogs vfw = filter.BaseFilter as IAMVfwCompressDialogs;
                    if (vfw != null)
                    {
                        if (vfw.ShowDialog(VfwCompressDialogs.QueryConfig, Handle) == 0)
                            menu.MenuItems.Add("VfW compressor: Config", VfWConfig);
                        if (vfw.ShowDialog(VfwCompressDialogs.QueryAbout, Handle) == 0)
                            menu.MenuItems.Add("VfW compressor: About", VfWAbout);
                    }

                    if ((filter.BaseFilter as ISampleGrabber) != null)
                    {
                        menu.MenuItems.Add("Set media type", SetSGMediaType);
                        menu.MenuItems.Add("Watch grabbed samples", WatchSampleGrabber);
                    }

                    menu.MenuItems.Add("Scan interfaces", ScanInterfaces);
                    if (filter.filterProps.DisplayName.Length > 0)
                    {
                        menu.MenuItems.Add("Add to favorites", AddToFavorites);
                        menu.MenuItems.Add("Find this filter in the list", FindFilterInList);
                    }

                    if ((filter.BaseFilter as IPersistStream) != null)
                    {
                        menu.MenuItems.Add("Save state to C++ code", SaveFilterStateToCode);
                        menu.MenuItems.Add("Save state to C# code", SaveFilterStateToCodeCS);
                    }

                    menu.Show(this, eLocation);
                }
            }
            else //out of filter right click
            {
                ContextMenu menu = new ContextMenu();
                menu.MenuItems.Add("Render file...", RenderFile);
                menu.MenuItems.Add("Add source filter...", AddSourceFilter);
                menu.MenuItems.Add("Load graph...", LoadGraph);
                if (savedFileName != null)
                    menu.MenuItems.Add("Save graph", SaveGraph);
                menu.MenuItems.Add("Save graph as...", SaveGraphAs);
                menu.MenuItems.Add("See event log...", ShowEventLog);
                menu.MenuItems.Add("Arrange filters", delegate
                {
                    graph.LayoutFilters();
                    graph.RecalcPaths();
                    Invalidate();
                });
                menu.MenuItems.Add("Refresh graph", delegate { graph.ReloadGraph(); Invalidate(); });
                menu.Show(this, eLocation);
            }
        }
Esempio n. 4
0
        public void ReloadFilters()
        {
            log("reload filters..");
            IEnumFilters ef;

            ClearFiltersSelection();
            ClearConnections();

            filter_positions.Clear();
            foreach (Filter f in filters)
            {
                filter_positions.Add(f.Name, f.Coords);
            }
            filters.Clear();
            log("reload_filters 1");
            try
            {
                int hr = graphBuilder.EnumFilters(out ef);
                DsError.ThrowExceptionForHR(hr);
                IBaseFilter[] fs      = new IBaseFilter[1];
                IntPtr        fetched = Marshal.AllocHGlobal(4);
                while ((hr = ef.Next(1, fs, fetched)) == 0)
                {
                    log("reload_filters 2");
                    FilterInfo fi;
                    fs[0].QueryFilterInfo(out fi);
                    log("reload_filters: " + fi.achName);
                    Filter ff = FindFilterByName(fi.achName);
                    if (ff == null) //not found
                    {
                        ff = new Filter(fs[0]);
                        AddFilterHere(ff, false, null);
                        history.AddFilterIfNew(ff.filterProps, ff.Name, ff.srcFileName, ff.dstFileName, ff);
                    }
                    else
                    {
                        ff.ReloadPins();
                    }
                    log("reload_filters 3");
                    foreach (Pin pin in ff.Pins)
                    {
                        log("reload_filters 4: " + pin.Name);
                        IPin ip = pin.IPin, connected_ipin;
                        hr = ip.ConnectedTo(out connected_ipin);
                        if (hr != 0)
                        {
                            continue;
                        }
                        PinInfo cpi;
                        connected_ipin.QueryPinInfo(out cpi);
                        FilterInfo cfi;
                        cpi.filter.QueryFilterInfo(out cfi);
                        Filter connected_filter = FindFilterByName(cfi.achName);
                        if (connected_filter != null)
                        {
                            Pin cp = connected_filter.FindPinByName(connected_filter.Name + "." + cpi.name);
                            if (cp != null)
                            {
                                string con_uniqname = (pin.Direction == PinDirection.Input) ?
                                                      cp.UniqName + "-" + pin.UniqName : pin.UniqName + "-" + cp.UniqName;
                                PinConnection con = FindConnectionByName(con_uniqname);
                                if (con == null)
                                {
                                    if (pin.Direction == PinDirection.Input)
                                    {
                                        Connect(cp, pin);
                                    }
                                    else
                                    {
                                        Connect(pin, cp);
                                    }
                                }
                            }
                        }
                        DsUtils.FreePinInfo(cpi);
                    }
                }
                Marshal.FreeHGlobal(fetched);
                if (hr < 0)
                {
                    DsError.ThrowExceptionForHR(hr);
                }
            }
            catch (COMException e)
            {
                ShowCOMException(e, "Error while enumerating filters in the graph");
                return;
            }

            /*catch (Exception e)
             * {
             *  MessageBox.Show(e.Message, "Error while enumerating filters in the graph");
             *  return;
             * }*/
            log("reload_filters: almost done");
            history.CommitAdded();
            log("reload_filters: done");
        }
Esempio n. 5
0
        public List <ConStep> CalcPath(Pin outpin, Pin inpin, int con_id)
        {
            Point gsz = GetGraphSize();
            int   mx = gsz.X, my = gsz.Y;

            //calc graph field size
            cost = new int[mx, my];
            dirs = new int[mx, my];

            //get pins coords
            Point psrc = new Point(outpin.Filter.Coords.X + outpin.Filter.boxsize.X,
                                   outpin.Filter.Coords.Y + outpin.Rect.Top / cellsize);

            pdst = new Point(inpin.Filter.Coords.X - 1,
                             inpin.Filter.Coords.Y + inpin.Rect.Top / cellsize);

            //make path field
            changed = new PriorityQueue <Point>();//Queue<Point>();
            cost[psrc.X, psrc.Y] = 1;
            dirs[psrc.X, psrc.Y] = 2;
            changed.Enqueue(psrc, 1);
            Point p;

            while (changed.Count > 0)
            {
                p = changed.Dequeue().Value;
                if (p == pdst)
                {
                    break;
                }
                int x = p.X, y = p.Y;
                int c = cost[x, y];
                if (p.X > 0)
                {
                    CheckPath(p.X - 1, p.Y, c, 0);
                }
                if (p.X < mx - 1)
                {
                    CheckPath(p.X + 1, p.Y, c, 2);
                }
                if (p.Y > 0)
                {
                    CheckPath(p.X, p.Y - 1, c + 1, 3);
                }
                if (p.Y < my - 1)
                {
                    CheckPath(p.X, p.Y + 1, c + 1, 1);
                }
            }

            //make path
            p = pdst;
            List <ConStep> path = new List <ConStep>();
            int            cd   = 2;

            //  43
            //  56
            while (true)
            {
                int nd = dirs[p.X, p.Y], d = 0;
                if (cd == 0 && nd == 0)
                {
                    d = 2;
                }
                if (cd == 0 && nd == 1)
                {
                    d = 4;
                }
                if (cd == 0 && nd == 2)
                {
                    d = 0;
                }
                if (cd == 0 && nd == 3)
                {
                    d = 5;
                }
                if (cd == 1 && nd == 0)
                {
                    d = 6;
                }
                if (cd == 1 && nd == 1)
                {
                    d = 1;
                }
                if (cd == 1 && nd == 2)
                {
                    d = 5;
                }
                if (cd == 1 && nd == 3)
                {
                    d = 0;
                }
                if (cd == 2 && nd == 0)
                {
                    d = 0;
                }
                if (cd == 2 && nd == 1)
                {
                    d = 3;
                }
                if (cd == 2 && nd == 2)
                {
                    d = 2;
                }
                if (cd == 2 && nd == 3)
                {
                    d = 6;
                }
                if (cd == 3 && nd == 0)
                {
                    d = 3;
                }
                if (cd == 3 && nd == 1)
                {
                    d = 0;
                }
                if (cd == 3 && nd == 2)
                {
                    d = 4;
                }
                if (cd == 3 && nd == 3)
                {
                    d = 1;
                }

                if (d == 0)
                {
                    break;
                }
                ConStep cs = new ConStep();
                cs.x = p.X; cs.y = p.Y; cs.dir = d;
                path.Add(cs);
                field[p.X, p.Y]    += 100;
                ownersmap[p.X, p.Y] = con_id;
                if (p == psrc)
                {
                    break;
                }

                if (nd == 0)
                {
                    p.X++;
                }
                if (nd == 2)
                {
                    p.X--;
                }
                if (nd == 3)
                {
                    p.Y++;
                }
                if (nd == 1)
                {
                    p.Y--;
                }
                cd = nd;
            }

            changed = null; cost = null; //dirs = null;
            return(path);
        }
Esempio n. 6
0
 public void PinSetFormat(Pin pin, AMMediaType mt)
 {
     history.SetFormat(pin, mt);
 }