Пример #1
0
        public static void KtaneFriendshipUpDownButtons()
        {
            if (Program.Settings.SelectedVertices.Count != 12)
            {
                DlgMessage.ShowInfo("Need 12 vertices for this tool.");
                return;
            }

            var outerDn = Program.Settings.SelectedVertices.Skip(0).Take(3).Select(pt => Program.Settings.Faces.SelectMany(fc => fc.Vertices).Where(v => v.Location == pt).ToArray()).ToArray();
            var innerDn = Program.Settings.SelectedVertices.Skip(3).Take(3).Select(pt => Program.Settings.Faces.SelectMany(fc => fc.Vertices).Where(v => v.Location == pt).ToArray()).ToArray();
            var outerUp = Program.Settings.SelectedVertices.Skip(6).Take(3).Select(pt => Program.Settings.Faces.SelectMany(fc => fc.Vertices).Where(v => v.Location == pt).ToArray()).ToArray();
            var innerUp = Program.Settings.SelectedVertices.Skip(9).Take(3).Select(pt => Program.Settings.Faces.SelectMany(fc => fc.Vertices).Where(v => v.Location == pt).ToArray()).ToArray();

            var undo = new List <Tuple <VertexInfo, Pt, Pt, Pt?, Pt?> >();

            const double f      = .8 * .1;
            const double innerY = .13;
            const double outerY = .150511;

            for (int k = 0; k < 3; k++)
            {
                // Down
                var innerDnX = (.12 * f * cs(360 * k / 3 + 90) - .052) * 10;
                var innerDnZ = (.12 * f * sn(360 * k / 3 + 90) + .06) * 10;

                var outerDnX = (.16 * f * cs(360 * k / 3 + 90) - .052) * 10;
                var outerDnZ = (.16 * f * sn(360 * k / 3 + 90) + .06) * 10;

                // Up
                var innerUpX = (-.12 * f * cs(360 * k / 3 + 90) - .07) * 10;
                var innerUpZ = (-.12 * f * sn(360 * k / 3 + 90) + .0648) * 10;

                var outerUpX = (-.16 * f * cs(360 * k / 3 + 90) - .07) * 10;
                var outerUpZ = (-.16 * f * sn(360 * k / 3 + 90) + .0648) * 10;

                foreach (var v in outerDn[k])
                {
                    undo.Add(Tuple.Create(v, v.Location, new Pt(outerDnX, outerY, outerDnZ), v.Normal, new Pt(0, 1, 0).Nullable()));
                }
                foreach (var v in innerDn[k])
                {
                    undo.Add(Tuple.Create(v, v.Location, new Pt(innerDnX, innerY, innerDnZ), v.Normal, v.Normal));
                }
                foreach (var v in outerUp[k])
                {
                    undo.Add(Tuple.Create(v, v.Location, new Pt(outerUpX, outerY, outerUpZ), v.Normal, new Pt(0, 1, 0).Nullable()));
                }
                foreach (var v in innerUp[k])
                {
                    undo.Add(Tuple.Create(v, v.Location, new Pt(innerUpX, innerY, innerUpZ), v.Normal, v.Normal));
                }
            }

            Program.Settings.Execute(new MoveVertices(undo.ToArray()));
        }
Пример #2
0
 private void miOpenInBrowser_Click(object sender, EventArgs e)
 {
     if (Program.Interface.ServerRunning)
     {
         ProcessStartInfo si = new ProcessStartInfo("http://localhost:{0}".Fmt(Program.Interface.ServerPort));
         si.UseShellExecute = true;
         Process.Start(si);
     }
     else
     {
         DlgMessage.ShowInfo(Program.Tr.Warning_CannotOpenInBrowser);
     }
 }
Пример #3
0
        public static void KtaneFriendshipSubmitButton()
        {
            if (!Program.Settings.IsFaceSelected || Program.Settings.SelectedFaces.Count != 1)
            {
                DlgMessage.ShowInfo("Need exactly one selected face for this tool.");
                return;
            }
            var face = Program.Settings.SelectedFaces[0];

            const double centerX     = -0.64;
            const double centerZ     = 0.3;
            const double innerRadius = .16; // .2 × .8
            const double outerRadius = .18;
            const double innerY      = .13;
            const double outerY      = .150511;
            const int    steps       = 72;

            var newFaces = new List <Face>();

            foreach (var inf in Enumerable.Range(0, steps).Select(k => 360.0 * k / steps).Select(angle => new
            {
                Inner = new Pt(innerRadius * cs(angle) + centerX, innerY, innerRadius * sn(angle) + centerZ),
                Outer = new Pt(outerRadius * cs(angle) + centerX, outerY, outerRadius * sn(angle) + centerZ)
            }).ConsecutivePairs(true))
            {
                var i1 = inf.Item1;
                var i2 = inf.Item2;

                // Bevel
                newFaces.Add(new Face(Ut.NewArray(
                                          new VertexInfo(i2.Inner, null, new Pt(centerX, innerY, centerZ) - i2.Inner),
                                          new VertexInfo(i2.Outer, null, new Pt(0, 1, 0)),
                                          new VertexInfo(i1.Outer, null, new Pt(0, 1, 0)),
                                          new VertexInfo(i1.Inner, null, new Pt(centerX, innerY, centerZ) - i1.Inner))));

                // Rim
                var closest1 = face.Vertices.MinElement(v => v.Location.Distance(i1.Outer));
                var closest2 = face.Vertices.MinElement(v => v.Location.Distance(i2.Outer));
                newFaces.Add(new Face(
                                 (closest1 == closest2 ? new[] { i1.Outer, i2.Outer, closest1.Location } : new[] { i1.Outer, i2.Outer, closest2.Location, closest1.Location })
                                 .Select(v => new VertexInfo(v, null, new Pt(0, 1, 0)))
                                 .ToArray()));
            }

            Program.Settings.Execute(new AddRemoveFaces(new[] { face }, newFaces.ToArray()));
        }
Пример #4
0
        static void Main(string[] args)
        {
            //CodecTests.TestRandom();
            PatternHashTable.SelfTest();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            int worker, dummy;

            ThreadPool.SetMinThreads(Environment.ProcessorCount, 10);
            ThreadPool.SetMaxThreads(Environment.ProcessorCount, 10);
            ThreadPool.GetAvailableThreads(out worker, out dummy);
            System.Diagnostics.Debug.Assert(worker == Environment.ProcessorCount);


            if (args.Length == 0)
            {
                SettingsUtil.LoadSettings(out Settings);
                MainForm form = new MainForm();
                Application.Run(form);
                Settings.Save();
            }
            else if (args[0] == "?")
            {
                DlgMessage.ShowInfo("Usage:\n  i4c.exe - run interactive GUI.\n  i4c.exe <algorithm> <filename> [<arg1> <arg2> ...] - compress/decompress single file.\n  i4c.exe benchmark <algorithm> [<arg1> <arg2> ...] - benchmark on all files in cur dir.\n\nAvailable algorithms:\n\n" + Compressors.Keys.Select(compr => "* " + compr + "\n").JoinString());
            }
            else if (args[0] == "benchmark")
            {
                if (args.Length == 1)
                {
                    DlgMessage.ShowError("Must also specify the name of the algorithm to benchmark");
                    return;
                }
                command_Benchmark(args[1], args.Skip(2).Select(val => (RVariant)val).ToArray());
            }
            else
            {
                if (args.Length < 2)
                {
                    DlgMessage.ShowError("Must specify at least the algorithm name and the file name");
                    return;
                }
                command_Single(args[1], args[0], args.Skip(2).Select(val => (RVariant)val).ToArray());
            }
        }
Пример #5
0
        public void ApplyChanges()
        {
            Repository repo;

            try
            {
                repo = new Repository(RepoPath);
            }
            catch
            {
                DlgMessage.ShowWarning("It looks like there is no valid Git repository at this path anymore. Please use “Browse” to load from another path.");
                return;
            }

            var knownCommits  = Commits.ToDictionary(c => c.Hash);
            var loadedCommits = new HashSet <string>(repo.Commits.Select(c => c.Id.Sha));

            if (knownCommits.Count != loadedCommits.Count || knownCommits.Keys.Any(c => !loadedCommits.Contains(c)) || loadedCommits.Any(c => !knownCommits.ContainsKey(c)) ||
                repo.Commits.Any(cl => !knownCommits[cl.Id.Sha].MatchesOriginal(cl)))
            {
                DlgMessage.ShowWarning("The repository at this path has changed since it was last loaded. Please use Reload before applying changes.");
                return;
            }

            foreach (var rf in repo.Refs.Where(rf => rf.CanonicalName.StartsWith("refs/original/")).ToList())
            {
                repo.Refs.Remove(rf);
            }

            repo.Refs.RewriteHistory(new RewriteHistoryOptions
            {
                CommitHeaderRewriter = arg =>
                {
                    var ours = knownCommits[arg.Id.Sha];
                    return(new CommitRewriteInfo
                    {
                        Author = new Signature(ours.AuthorName, ours.AuthorEmail, ours.AuthorDate),
                        Committer = new Signature(ours.CommitterName, ours.CommitterEmail, ours.CommitterDate),
                        Message = ours.Message
                    });
                }
            }, repo.Commits);
            InitialLoadRepo(RepoPath);
            DlgMessage.ShowInfo("Changes applied successfully.");
        }
Пример #6
0
        public static void GenerateInset(
            [ToolDouble("Bevel radius?")] double radius,
            [ToolBool("Open or closed curve?", "&Closed", "&Open")] bool open,
            [ToolDouble("Extra wall depth?")] double extraWallDepth,
            [ToolBool("Miter join calculation?", "&Normalized", "N&on-normalized")] bool nonNormalizedMiter,
            [ToolInt("Number of steps of revolution?")] int revSteps)
        {
            if (Program.Settings.SelectedVertices.Count < (open ? 2 : 3))
            {
                DlgMessage.ShowInfo(@"Need at least {0} vertices for {1} curve.".Fmt(open ? 2 : 3, open ? "an open" : "a closed"));
                return;
            }

            var pts = Program.Settings.SelectedVertices;

            Pt mn(Pt p) => nonNormalizedMiter ? p : p.Normalize();

            var nPts = pts
                       .Select((p, ix) => new
            {
                AxisStart = !open || ix != pts.Count - 1 ? p.Add(y: -radius) : pts[pts.Count - 2].Add(y: -radius),
                AxisEnd   = !open || (ix != 0 && ix != pts.Count - 1) ? p.Add(y: -radius) + mn(pts[(ix + 1) % pts.Count] - p) + mn(p - pts[(ix - 1 + pts.Count) % pts.Count]) :
                            ix == 0 ? pts[1].Add(y: -radius) : pts[pts.Count - 1].Add(y: -radius),
                Perpendicular = pts[ix],
                Center        = pts[ix].Add(y: -radius)
            })
                       .Select(inf => Enumerable.Range(0, revSteps)
                               .Select(i => - 90 * i / (revSteps - 1))
                               .Select(angle => new { inf.Center, Angle = angle, Rotated = inf.Perpendicular.Rotate(inf.AxisStart, inf.AxisEnd, angle) })
                               .Apply(x => x.Concat(new { Center = inf.Center.Add(y: -extraWallDepth), Angle = -90, Rotated = inf.Perpendicular.Rotate(inf.AxisStart, inf.AxisEnd, -90).Add(y: -extraWallDepth) }))
                               .ToArray())
                       .ToArray();

            var faces = Enumerable.Range(0, nPts.Length)
                        .SelectConsecutivePairs(!open, (i1, i2) => Enumerable.Range(0, nPts[0].Length)
                                                .SelectConsecutivePairs(false, (j1, j2) => new[] { nPts[i1][j1], nPts[i2][j1], nPts[i2][j2], nPts[i1][j2] }
                                                                        .Select(inf => new VertexInfo(inf.Rotated, null, pts[i2].Rotate(pts[i1].Add(y: -radius), pts[i2].Add(y: -radius), inf.Angle) - pts[i2].Add(y: -radius))).ToArray()))
                        .SelectMany(x => x);

            Program.Settings.Execute(new AddRemoveFaces(null, faces.Select(f => new Face(f, false)).ToArray()));
        }
Пример #7
0
        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            if (!_model.AnyChanges)
            {
                DlgMessage.ShowInfo("There are no pending changes to apply.");
                return;
            }
            var btn = DlgMessage.ShowQuestion("Apply pending changes to this repository?\nRemember that changing history has consequences that need to be understood.\n\nWARNING: MAKE A BACKUP OF YOUR REPOSITORY.\nThis program modifies the repository in-place using LibGit2Sharp. This program has not been through extensive testing, and could well damage or destroy your repository. Seriously, do not skip the backup.",
                                              "&Continue at my own risk", "More &about rewriting history", "Cancel");

            if (btn == 2)
            {
                return;
            }
            if (btn == 1)
            {
                Process.Start("http://stackoverflow.com/a/1491022/33080");
                return;
            }
            _model.ApplyChanges();
        }
Пример #8
0
        public static void GenerateCircle([ToolDouble("Center X?")] double centerX, [ToolDouble("Center Z?")] double centerZ, [ToolDouble("Radius of the circle?")] double radius, [ToolInt("Number of points?")] int steps)
        {
            if (!Program.Settings.IsFaceSelected || Program.Settings.SelectedFaces.Count != 1)
            {
                DlgMessage.ShowInfo("Need exactly one selected face for this tool.");
                return;
            }
            var face = Program.Settings.SelectedFaces[0];

            double centerY = face.Vertices.Aggregate(0d, (prev, next) => prev + next.Location.Y) / face.Vertices.Length;

            var newFaces = Enumerable.Range(0, steps)
                           .Select(k => 360.0 * k / steps)
                           .Select(angle => new Pt(radius * cs(angle) + centerX, centerY, radius * sn(angle) + centerZ))
                           .Select(pt => new { Point = pt, Closest = face.Vertices.MinElement(v => v.Location.Distance(pt)) })
                           .SelectConsecutivePairs(true, (i1, i2) => new Face(
                                                       (i1.Closest == i2.Closest ? new[] { i1.Point, i2.Point, i1.Closest.Location } : new[] { i1.Point, i2.Point, i2.Closest.Location, i1.Closest.Location })
                                                       .Select(v => new VertexInfo(v, null, new Pt(0, 1, 0)))
                                                       .ToArray()));

            Program.Settings.Execute(new AddRemoveFaces(new[] { face }, newFaces.ToArray()));
        }
Пример #9
0
        public static void TriangulateFace()
        {
            if (!Program.Settings.IsFaceSelected || Program.Settings.SelectedFaces.Count != 1)
            {
                DlgMessage.ShowInfo("Need exactly one selected face to triangulate.");
                return;
            }
            var face = Program.Settings.SelectedFaces[0];

            if (face.Vertices.Any(v => v.Location.Y != face.Vertices[0].Location.Y))
            {
                DlgMessage.ShowInfo("Not all vertices have the same Y coordinate.");
                return;
            }
            var y = face.Vertices[0].Location.Y;

            var result = Triangulate.DelaunayConstrained(
                face.Vertices.Select(v => new PointD(v.Location.X, v.Location.Z)),
                face.Vertices.Select(v => new PointD(v.Location.X, v.Location.Z)).SelectConsecutivePairs(closed: true, selector: (p1, p2) => new EdgeD(p1, p2)));

            var newFaces = result.Select(triangle => new Face(triangle.Vertices.Select(v => new Pt(v.X, y, v.Y)).ToArray())).ToArray();

            Program.Settings.Execute(new AddRemoveFaces(new[] { face }, newFaces));
        }
Пример #10
0
        static int Main(string[] args)
        {
            // Configure Classify. This goes before the post-build check because it depends on it
            Classify.DefaultOptions = new ClassifyOptions()
                                      .AddTypeOptions(typeof(W.Color), new colorTypeOptions())
                                      .AddTypeOptions(typeof(D.Color), new colorTypeOptions())
                                      .AddTypeOptions(typeof(Filename), new filenameTypeOptions())
                                      .AddTypeOptions(typeof(ObservableCollection <LayerBase>), new listLayerBaseOptions())
                                      .AddTypeOptions(typeof(ObservableCollection <EffectBase>), new listEffectBaseOptions());

            if (args.Length == 2 && args[0] == "--post-build-check")
            {
                return(RT.Util.Ut.RunPostBuildChecks(args[1], Assembly.GetExecutingAssembly()));
            }

            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

#if DEBUG
            CompositePath.Tests();
#endif

            Thread.CurrentThread.Name = "Main";
#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += (_, ea) =>
            {
                bool copy = DlgMessage.ShowError(App.Translation.Error.ExceptionGlobal,
                                                 App.Translation.Error.ErrorToClipboard_Copy, App.Translation.Error.ErrorToClipboard_OK) == 0;
                if (copy)
                {
                    if (Ut.ClipboardSet(Ut.ExceptionToDebugString(ea.ExceptionObject)))
                    {
                        DlgMessage.ShowInfo(App.Translation.Error.ErrorToClipboard_Copied);
                    }
                }
            };
#else
            var dummy  = App.Translation.Error.ExceptionGlobal; // to keep Lingo happy that the string is used
            var dummy2 = new StringBuilder();                   // to keep the "using" clause used
#endif

            // Find all the layer and effect types in the assembly (required before settings are loaded)
            App.LayerTypes  = findTypes <LayerBase>("layer");
            App.EffectTypes = findTypes <EffectBase>("effect");

            // Load all settings
            SettingsUtil.LoadSettings(out App.Settings);
            UpdateSettingsIfNecessary();

            // Guess the language if the OS language has changed (or this is the first run)
            var osLingo = Ut.GetOsLanguage();
            if (App.Settings.OsLingo != osLingo)
            {
                App.Settings.OsLingo = App.Settings.Lingo = osLingo;
            }
            // Load translation
            App.Translation = Lingo.LoadTranslationOrDefault <Translation>("TankIconMaker", ref App.Settings.Lingo);

            // Run the UI
            var app = new App();
            app.InitializeComponent();
            app.Run();

            // Save settings upon exit, even though they should be saved on every change anyway
            App.Settings.SaveQuiet();

            return(0);
        }
Пример #11
0
            /// <summary>Generates the file.</summary>
            public void Dispose()
            {
                if (!Directory.Exists(Path.GetDirectoryName(_filename)))
                {
                    // silently ignore this error because we might be running the Debug build in some other environment
                    return;
                }

                var f = new StringBuilder();

                f.AppendLine("using RT.Lingo;");
                f.AppendLine("");
                bool first = true;

                foreach (var kvp in _codeSoFar)
                {
                    if (!first)
                    {
                        f.AppendLine();
                    }
                    first = false;
                    f.AppendLine("namespace " + kvp.Key);
                    f.AppendLine("{");
                    bool first2 = true;
                    foreach (var val in kvp.Value)
                    {
                        if (!first2)
                        {
                            f.AppendLine();
                        }
                        first2 = false;
                        f.Append(val);
                    }
                    f.AppendLine("}");
                }

                var    newOutput         = f.ToString();
                var    prevOutput        = File.Exists(_filename) ? File.ReadAllText(_filename) : string.Empty;
                string filenameGenerated = null;

                if (newOutput != prevOutput)
                {
                    // Replace the destination file with the newly generated stuff, but only if there are any differences.
                    int choice;
                    while ((choice = DlgMessage.ShowWarning("The file \"{0}\" will be modified by Lingo.".Fmt(Path.GetFullPath(_filename)), "&OK", "&Diff", "&Break")) != 0)
                    {
                        if (choice == 1)
                        {
                            if (Environment.GetEnvironmentVariable("LINGO_DIFF") == null)
                            {
                                DlgMessage.ShowInfo("The \"LINGO_DIFF\" environment variable is not defined. To enable diffing, set it to a full path to your preferred diff program.");
                            }
                            else
                            {
                                filenameGenerated = Path.GetTempFileName();
                                File.WriteAllText(filenameGenerated, newOutput);
                                Process.Start(Environment.GetEnvironmentVariable("LINGO_DIFF"), @"""{0}"" ""{1}""".Fmt(_filename, filenameGenerated));
                            }
                        }
                        else if (choice == 2)
                        {
                            Debugger.Break();
                        }
                    }
                    if (File.Exists(_filename))
                    {
                        File.SetAttributes(_filename, File.GetAttributes(_filename) & ~FileAttributes.ReadOnly);
                    }
                    File.WriteAllText(_filename, newOutput);
                    if (filenameGenerated != null)
                    {
                        File.Delete(filenameGenerated);
                    }
                    // Warn the user that some things may not behave properly until rebuild (e.g. newly generated strings won't show in translation UI yet).
                    DlgMessage.ShowWarning("The file \"{0}\" has been modified by Lingo.\n\nPlease rebuild the application to avoid unexpected behaviour, or click \"OK\" at your own risk.".Fmt(Path.GetFullPath(_filename)));
                }
            }
Пример #12
0
 private void HelpToolStripMenuItem1Click(object sender, EventArgs e)
 {
     DlgMessage.ShowInfo(_helpMessage);
 }
Пример #13
0
 private void Reload_Click(object sender, RoutedEventArgs e)
 {
     _model.ReloadRepo();
     DlgMessage.ShowInfo("Repository has been reloaded.");
 }