private void button6_Click(object sender, EventArgs e)
 {
     UsageManager.SendUsageData();
 }
 private void button13_Click(object sender, EventArgs e)
 {
     UsageManager.FinishCollectingData();
 }
        protected override void DoCommandAction()
        {
            // read input
            Queue <Tuple <Location, Location> > fromToTuples = null;

            ReadSearchInput(out fromToTuples);

            // result
            List <List <Location> > paths = new List <List <Location> >();
            List <XDLNet>           nets  = new List <XDLNet>();

            RouteNet routeCmd = new RouteNet();

            routeCmd.Watch = Watch;

            int size  = fromToTuples.Count;
            int count = 0;

            UsageManager usageManager = new UsageManager();

            // upon sink chnmage, block the last nets
            Location lastSink = null;

            while (fromToTuples.Count > 0)
            {
                ProgressInfo.Progress = ProgressStart + (int)((double)count++ / (double)size * ProgressShare);

                Tuple <Location, Location> tuple = fromToTuples.Dequeue();
                Location source = tuple.Item1;
                Location sink   = tuple.Item2;

                bool pathFound = false;

                bool sinkChange = lastSink == null ? false : !lastSink.Equals(sink);
                lastSink = sink;
                if (sinkChange)
                {
                    BlockPips(nets);
                }
                Usage usage = new Usage(source, sink);

                //if (source.Tile.Location.Equals("CLEXL_X22Y16") && source.Pip.Name.Equals("XX_AQ") && sink.Tile.Location.Equals("CLEXM_X23Y18") && sink.Pip.Name.Equals("X_AX"))
                if (source.Tile.Location.Equals("CLEXL_X22Y16") && source.Pip.Name.Equals("XX_AQ") && sink.Tile.Location.Equals("CLEXM_X23Y16") && sink.Pip.Name.Equals("X_AX"))
                {
                }

                List <Location> initialSearchFront = new List <Location>();
                foreach (Location location in usageManager.GetLocationsWithExclusiveUsage(usage).OrderBy(l => Distance(l, sink)))
                {
                    initialSearchFront.Add(location);
                }
                // add default source after the others
                initialSearchFront.Add(source);

                // truncate on first run
                TextWriter tw = new StreamWriter(OutputFile, count > 1);
                tw.Write(PathSearchOnFPGA.GetBanner(source, sink));



                //Console.WriteLine("Running path " + count + " " + usage + (initialSearchFront.Count > 1 ? " with shortcut" : ""));

                if (initialSearchFront.Count > 1)
                {
                }

                Watch.Start("search");
                foreach (List <Location> path in routeCmd.Route("BFS", true, initialSearchFront, sink, 100, MaxDepth, false))
                {
                    if (!PathSearchOnFPGA.PathAlreadyFound(path, paths))
                    {
                        paths.Add(path);

                        XDLNet n = PathToNet(source, sink, path);
                        nets.Add(n);
                        usage.Net = n;

                        tw.Write(PathSearchOnFPGA.PathToString(source, sink, Enumerable.Repeat(path, 1)));
                        pathFound = true;

                        // no blocking on CLEX LOGIC
                        foreach (XDLPip pip in GetPipsToBlock(n))
                        {
                            Location l = new Location(FPGA.FPGA.Instance.GetTile(pip.Location), new Port(pip.From));
                            //Location r = new Location(FPGA.FPGA.Instance.GetTile(pip.Location), new Port(pip.To));
                            usageManager.Add(l, usage, n);
                            //usageManager.Add(r, usage);
                        }
                        break;
                    }
                }
                Watch.Stop("search");

                if (!pathFound)
                {
                    tw.WriteLine("No path found");
                    string trigger = ("if (source.Tile.Location.Equals(\"" + source.Tile.Location + "\") && source.Pip.Name.Equals(\"" + source.Pip.Name + "\") && sink.Tile.Location.Equals(\"" + sink.Tile.Location + "\") && sink.Pip.Name.Equals(\"" + sink.Pip.Name + "\"))");
                    Console.WriteLine(trigger);
                }

                tw.Close();

                if (nets.Count % 20 == 0)
                {
                    //    Console.WriteLine(this.Watch.GetResults());
                }
            }
        }