private void DetectPageLanguagesDialog_Load(object sender, EventArgs e)
        {
            string[] supportedLanguages = _ocrEngine.LanguageManager.GetSupportedLanguages();
            if (supportedLanguages == null || supportedLanguages.Length <= 0)
            {
                return;
            }

            Dictionary <string, string> languagesDictionary = new Dictionary <string, string>();

            string[] friendlyNames = new string[supportedLanguages.Length];

            int i = 0;

            foreach (string language in supportedLanguages)
            {
                friendlyNames[i] = MyLanguage.GetLanguageFriendlyName(language);
                languagesDictionary.Add(friendlyNames[i], language);
                i++;
            }

            Array.Sort(friendlyNames, 1, friendlyNames.Length - 1);
            foreach (string friendlyName in friendlyNames)
            {
                MyLanguage ml = new MyLanguage(languagesDictionary[friendlyName], friendlyName, -1);
                _lbSuggestedLanguages.Items.Add(ml);
            }

            UpdateUIState();
        }
Exemplo n.º 2
0
 public static string GetText(int difficulty, MyLanguage language)
 {
     if (language == MyLanguage.Ukrainian)
     {
         return(listUA[MyRand.GetRand(0, 4) + (difficulty - 1) * 5]);
     }
     else
     {
         return(listEN[MyRand.GetRand(0, 4) + (difficulty - 1) * 5]);
     }
 }
        public void Test()
        {
            var context = new MyLanguage();
            Language.Parse(context, "foo");
            Assert.AreEqual(1, context.Scope.SingleLiterArgInvocationCount);
            Assert.AreEqual(1, context.SingleLiterArgInvocationCount);

            Assert.AreEqual(
                "foo-global", context.Result,
                "Global rule-method should be called last and should provide rule result-value");
        }
        public void Test()
        {
            var context = new MyLanguage();

            Language.Parse(context, "foo");
            Assert.AreEqual(1, context.Scope.SingleLiterArgInvocationCount);
            Assert.AreEqual(1, context.SingleLiterArgInvocationCount);

            Assert.AreEqual(
                "foo-global", context.Result,
                "Global rule-method should be called last and should provide rule result-value");
        }
Exemplo n.º 5
0
        private void _btnDetectLanguages_Click(object sender, EventArgs e)
        {
            _lbPageLanguages.Items.Clear();
            string[] suggestedLanguages = new string[_lbSuggestedLanguages.SelectedItems.Count];
            int      index = 0;

            foreach (MyLanguage language in _lbSuggestedLanguages.SelectedItems)
            {
                suggestedLanguages[index] = language.Language;
                index++;
            }

            string[] pageLanguages = _ocrPage.DetectLanguages(suggestedLanguages);
            if (pageLanguages != null && pageLanguages.Length > 0)
            {
                foreach (string lang in pageLanguages)
                {
                    string friendlyName = MyLanguage.GetLanguageFriendlyName(lang);
                    _lbPageLanguages.Items.Add(friendlyName);
                }
            }
        }
Exemplo n.º 6
0
 public void ChangeLanguage(MyLanguage language)
 {
     if (Buttons.Count == smallKeyNameEn.Length)
     {
         if (language == MyLanguage.English)
         {
             for (int i = 0; i < smallKeyNameEn.Length; i++)
             {
                 if (isCapsLock)
                 {
                     Buttons[i].Content = bigKeyNameEn[i];
                 }
                 else
                 {
                     Buttons[i].Content = smallKeyNameEn[i];
                 }
             }
             Language = MyLanguage.English;
         }
         else if (language == MyLanguage.Ukrainian)
         {
             for (int i = 0; i < smallKeyNameEn.Length; i++)
             {
                 if (isCapsLock)
                 {
                     Buttons[i].Content = bigKeyNameUa[i];
                 }
                 else
                 {
                     Buttons[i].Content = smallKeyNameUa[i];
                 }
             }
             Language = MyLanguage.Ukrainian;
         }
     }
 }
Exemplo n.º 7
0
 public KeyBoard()
 {
     Buttons    = new List <Button>();
     Language   = MyLanguage.Ukrainian;
     isCapsLock = false;
 }
Exemplo n.º 8
0
        public void Activate(IOcrEngine ocrEngine, IOcrPage ocrPage, ListBox tvZonesList, IOcrZoneCollection zones)
        {
            _ocrEngine   = ocrEngine;
            _ocrPage     = ocrPage;
            _lbZonesList = tvZonesList;
            _zones       = zones;

            // Initialize the combo boxes
            OcrZoneType[] zoneTypes = ocrEngine.ZoneManager.GetSupportedZoneTypes();
            foreach (OcrZoneType zoneType in zoneTypes)
            {
                _typeComboBox.Items.Add(zoneType);
            }

            // Get the languages supported by this engine and fill the list box
            string[] languages           = ocrEngine.LanguageManager.GetSupportedLanguages();
            string[] additionalLanguages = ocrEngine.LanguageManager.GetAdditionalLanguages();
            Dictionary <string, string> languagesDictionary = new Dictionary <string, string>();

            string[] friendlyNames = new string[languages.Length + additionalLanguages.Length];
            int      i             = 0;

            foreach (string language in languages)
            {
                friendlyNames[i] = MyLanguage.GetLanguageFriendlyName(language);
                languagesDictionary.Add(friendlyNames[i], language);
                i++;
            }
            foreach (string language in additionalLanguages)
            {
                friendlyNames[i] = MyLanguage.GetLanguageFriendlyName(language);
                languagesDictionary.Add(friendlyNames[i], language);
                i++;
            }

            Array.Sort(friendlyNames, 1, friendlyNames.Length - 1);

            MyLanguage ml = new MyLanguage(String.Empty, "None", -1);

            _languageComboBox.Items.Add(ml);
            foreach (string friendlyName in friendlyNames)
            {
                ml = new MyLanguage(languagesDictionary[friendlyName], friendlyName, -1);
                _languageComboBox.Items.Add(ml);
            }

            List <ViewPerspectiveItem> zoneViewPerspectiveValues = new List <ViewPerspectiveItem>();

            zoneViewPerspectiveValues.AddRange(new ViewPerspectiveItem[] {
                new ViewPerspectiveItem(RasterViewPerspective.TopLeft, "TopLeft"),
                new ViewPerspectiveItem(RasterViewPerspective.TopLeft90, "TopLeft90"),
                new ViewPerspectiveItem(RasterViewPerspective.TopLeft180, "TopLeft180"),
                new ViewPerspectiveItem(RasterViewPerspective.TopLeft270, "TopLeft270")
            });
            _zoneViewPerspectiveComboBox.Items.AddRange(zoneViewPerspectiveValues.ToArray());

            List <TextDirectionItem> zoneTextDirectionValues = new List <TextDirectionItem>();

            zoneTextDirectionValues.AddRange(new TextDirectionItem[] {
                new TextDirectionItem(OcrTextDirection.LeftToRight, "LeftToRight"),
                new TextDirectionItem(OcrTextDirection.TopToBottom, "TopToBottom")
            });
            _zoneTextDirectionComboBox.Items.AddRange(zoneTextDirectionValues.ToArray());

            // These events cannot be hooked into from the designer,
            // so we will do them in here
            _leftTextBox.GotFocus   += new EventHandler(_areaTextBox_GotFocus);
            _topTextBox.GotFocus    += new EventHandler(_areaTextBox_GotFocus);
            _widthTextBox.GotFocus  += new EventHandler(_areaTextBox_GotFocus);
            _heightTextBox.GotFocus += new EventHandler(_areaTextBox_GotFocus);

            _leftTextBox.LostFocus   += new EventHandler(_areaTextBox_LostFocus);
            _topTextBox.LostFocus    += new EventHandler(_areaTextBox_LostFocus);
            _widthTextBox.LostFocus  += new EventHandler(_areaTextBox_LostFocus);
            _heightTextBox.LostFocus += new EventHandler(_areaTextBox_LostFocus);

            _nameTextBox.LostFocus += new EventHandler(_textTextBox_LostFocus);

            UpdateUIState();
        }
Exemplo n.º 9
0
        public void ZoneToControls(int index)
        {
            // Fill the controls from the current zone
            if (index != -1)
            {
                OcrZone zone = _zones[index];
                _nameTextBox.Text = zone.Name;

                // Convert the bounds to pixels
                LeadRect bounds = zone.Bounds;
                _leftTextBox.Text   = bounds.X.ToString();
                _topTextBox.Text    = bounds.Y.ToString();
                _widthTextBox.Text  = bounds.Width.ToString();
                _heightTextBox.Text = bounds.Height.ToString();

                // Disable these events when changing the combo boxes selected items once the "UpdateZonesControl" gets activated
                this._typeComboBox.SelectedIndexChanged                -= new System.EventHandler(this._propertiesComboBox_SelectedIndexChanged);
                this._languageComboBox.SelectedIndexChanged            -= new System.EventHandler(this._propertiesComboBox_SelectedIndexChanged);
                this._zoneViewPerspectiveComboBox.SelectedIndexChanged -= new System.EventHandler(this._propertiesComboBox_SelectedIndexChanged);
                this._zoneTextDirectionComboBox.SelectedIndexChanged   -= new System.EventHandler(this._propertiesComboBox_SelectedIndexChanged);

                _typeComboBox.SelectedItem = zone.ZoneType;

                for (int i = 0; i < _languageComboBox.Items.Count; i++)
                {
                    MyLanguage ml = (MyLanguage)_languageComboBox.Items[i];
                    if (zone.Language == null || zone.Language == String.Empty)
                    {
                        if (ml.Language == String.Empty)
                        {
                            _languageComboBox.SelectedItem = ml;
                            break;
                        }
                    }
                    else
                    {
                        if (ml.Language == zone.Language)
                        {
                            _languageComboBox.SelectedItem = ml;
                            break;
                        }
                    }
                }

                _zoneViewPerspectiveComboBox.SelectedIndex = 0;
                foreach (ViewPerspectiveItem item in _zoneViewPerspectiveComboBox.Items)
                {
                    if (item.ViewPerspective == zone.ViewPerspective)
                    {
                        _zoneViewPerspectiveComboBox.SelectedItem = item;
                        break;
                    }
                }

                _zoneTextDirectionComboBox.SelectedIndex = 0;
                foreach (TextDirectionItem item in _zoneTextDirectionComboBox.Items)
                {
                    if (item.TextDirection == zone.TextDirection)
                    {
                        _zoneTextDirectionComboBox.SelectedItem = item;
                        break;
                    }
                }

                this._typeComboBox.SelectedIndexChanged                += new System.EventHandler(this._propertiesComboBox_SelectedIndexChanged);
                this._languageComboBox.SelectedIndexChanged            += new System.EventHandler(this._propertiesComboBox_SelectedIndexChanged);
                this._zoneViewPerspectiveComboBox.SelectedIndexChanged += new System.EventHandler(this._propertiesComboBox_SelectedIndexChanged);
                this._zoneTextDirectionComboBox.SelectedIndexChanged   += new System.EventHandler(this._propertiesComboBox_SelectedIndexChanged);

                if (zone.ZoneType == OcrZoneType.Omr)
                {
                    StringBuilder sb = new StringBuilder();

                    if (!_ocrPage.IsRecognized)
                    {
                        sb.Append("Unfilled (0% certain)");
                    }
                    else
                    {
                        IOcrPageCharacters pageCharacters = _ocrPage.GetRecognizedCharacters();
                        if (pageCharacters == null || pageCharacters.Count == 0 || zone.Id >= pageCharacters.Count)
                        {
                            sb.Append("Unfilled (0% certain)");
                        }
                        else
                        {
                            IOcrZoneCharacters zoneCharacters = pageCharacters[zone.Id];
                            if (zoneCharacters.Count > 0)
                            {
                                OcrCharacter omrCharacter = zoneCharacters[0];
                                char         filledChar   = _ocrEngine.ZoneManager.OmrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Filled);
                                char         unfilledChar = _ocrEngine.ZoneManager.OmrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Unfilled);
                                if (omrCharacter.Code == filledChar)
                                {
                                    sb.Append("Filled");
                                }
                                else
                                {
                                    sb.Append("Unfilled");
                                }

                                sb.AppendFormat(" ({0}% certain)", omrCharacter.Confidence);
                            }
                            else
                            {
                                sb.AppendFormat("Unfilled (0% certain)");
                            }
                        }
                    }

                    _omrStatusLabel.Text = sb.ToString();
                }
                else
                {
                    _omrStatusLabel.Text = string.Empty;
                }

                if ((zone.CharacterFilters & OcrZoneCharacterFilters.Digit) == OcrZoneCharacterFilters.Digit)
                {
                    _digitCheckBox.Checked = true;
                }
                else
                {
                    _digitCheckBox.Checked = false;
                }

                if ((zone.CharacterFilters & OcrZoneCharacterFilters.Plus) == OcrZoneCharacterFilters.Plus)
                {
                    _plusCheckBox.Checked = true;
                }
                else
                {
                    _plusCheckBox.Checked = false;
                }
            }
            else
            {
                _nameTextBox.Text = string.Empty;

                _leftTextBox.Text   = string.Empty;
                _topTextBox.Text    = string.Empty;
                _widthTextBox.Text  = string.Empty;
                _heightTextBox.Text = string.Empty;

                _typeComboBox.SelectedIndex                = 0;
                _languageComboBox.SelectedIndex            = 0;
                _zoneViewPerspectiveComboBox.SelectedIndex = 0;
                _zoneTextDirectionComboBox.SelectedIndex   = 0;
                _omrStatusLabel.Text = string.Empty;

                _digitCheckBox.Checked = false;
                _plusCheckBox.Checked  = false;
            }
        }
Exemplo n.º 10
0
        public static void MainBootstrap(string[] args)
        {
            var rootContentPath = args[0];

            MyLog.Default = new MyLog();
            MyFileSystem.Init(rootContentPath, "./");
            MyLanguage.Init();
            MyRenderProxy.Initialize(new MyNullRender());
            MyLog.Default.Init("converter.log", new StringBuilder());
            Workers.Init(new WorkerConfigurationFactory()
                         .AddGroup(new WorkerConfigurationFactory.Group
            {
                Id       = WorkerGroup.Background,
                Min      = 1,
                Priority = ThreadPriority.BelowNormal,
                Ratio    = .1f
            })
                         .AddGroup(new WorkerConfigurationFactory.Group
            {
                Id       = WorkerGroup.Logic,
                Min      = 1,
                Priority = ThreadPriority.Normal,
                Ratio    = .7f
            })
                         .AddGroup(new WorkerConfigurationFactory.Group
            {
                Id       = WorkerGroup.Render,
                Min      = 1,
                Priority = ThreadPriority.AboveNormal,
                Ratio    = .2f
            })
                         .SetDefault(WorkerGroup.Logic)
                         .Bake(32));

            MyMetadataSystem.LoadAssemblies(new[]
            {
                "VRage",
                "VRage.Game",
                "Sandbox.Graphics",
                "Sandbox.Game",
                "MedievalEngineers.ObjectBuilders",
                "MedievalEngineers.Game"
            }.Select(Assembly.Load));

            var config = (BlockVariantGeneratorConfig) new XmlSerializer(typeof(BlockVariantGeneratorConfig)).Deserialize(File.OpenText(args[1]));

            Console.WriteLine("Loading definitions...");

            MyDefinitionManagerSandbox.Static.LoadData(new ListReader <MyModContext>(new List <MyModContext>(config.ContentRoots.Select(contentPath =>
                                                                                                                                        new MyModContext(Path.GetFileNameWithoutExtension(contentPath), Path.GetFileNameWithoutExtension(contentPath), contentPath)))));
            MyFileSystem.SetAdditionalContentPaths(config.ContentRoots);
            Console.WriteLine("Processing definitions...");
            DefinitionObLoader.LoadObjectBuilders(MyDefinitionManagerSandbox.Static.DefinitionSet);

            Console.WriteLine("Translating definitions...");
            var translatedSet   = new DefinitionObSet();
            var modelTranslator = new ModelAssetTranslator(config.OutputDirectory, config.VariantName);
            Func <string, string> assetTranslator = (asset) =>
            {
                if (string.IsNullOrWhiteSpace(asset))
                {
                    return(asset);
                }
                if (config.AssetTranslations.TryGetValue(asset, out var assetTranslation))
                {
                    return(assetTranslation);
                }
                if (asset.EndsWith(".mwm", StringComparison.OrdinalIgnoreCase) && config.Changes != null)
                {
                    if (asset.Contains("GeneratedStoneEdge"))
                    {
                        Debugger.Break();
                    }
                    var modelMaterials = modelTranslator.GetMaterialsForModel(asset);
                    using (PoolManager.Get(out List <MyObjectBuilder_EquiModifierChangeMaterialDefinition.MaterialModifier> changes))
                    {
                        foreach (var x in config.Changes)
                        {
                            if (modelMaterials.Contains(x.Name))
                            {
                                changes.Add(x);
                            }
                        }
                        if (changes.Count > 0)
                        {
                            Console.WriteLine("Translating model " + asset);
                            using (var builder = MaterialEditsBuilder.Allocate())
                            {
                                foreach (var k in changes)
                                {
                                    var list = new List <MaterialEdit>();
                                    k.GetChanges(list);
                                    builder.Add(k.Name, list);
                                }

                                return(modelTranslator.CreateModel(asset, builder));
                            }
                        }
                    }
                }

                return(asset);
            };
            var translator = new DefinitionObTranslator(
                DefinitionObLoader.Loaded,
                translatedSet,
                assetTranslator,
                (displayName) => $"{displayName} ({config.VariantName})",
                "_" + config.VariantName,
                config.Translations);

            foreach (var id in config.DefinitionsToTranslate)
            {
                if (id.SubtypeName == "**any**")
                {
                    // Find and translate ALL with the given type ID, not forcing
                    foreach (var k in DefinitionObLoader.Loaded.AllDefinitions)
                    {
                        if (k.Id.TypeId == id.TypeId)
                        {
                            translator.Translate(k);
                        }
                    }
                }
                else if (id.SubtypeName == "**any_translated_model**")
                {
                    var ids = new HashSet <MyDefinitionId>();
                    foreach (var k in DefinitionObLoader.Loaded.AllDefinitions)
                    {
                        if (k.Id.TypeId == id.TypeId && k is MyObjectBuilder_PhysicalModelDefinition physModel)
                        {
                            var originalModel   = physModel.Model;
                            var translatedModel = assetTranslator(originalModel);
                            if (!originalModel.Equals(translatedModel))
                            {
                                ids.Add(k.Id);
                            }
                        }
                    }

                    // Include variants that contain the blocks
                    foreach (var k in DefinitionObLoader.Loaded.AllDefinitions.OfType <MyObjectBuilder_BlockVariantsDefinition>())
                    {
                        var good = false;
                        foreach (var e in k.Blocks)
                        {
                            if (ids.Contains(e))
                            {
                                good = true;
                                break;
                            }
                        }

                        if (good)
                        {
                            ids.Add(k.Id);
                        }
                    }

                    foreach (var sid in ids)
                    {
                        foreach (var def in DefinitionObLoader.Loaded.GetDefinitions(sid))
                        {
                            translator.Translate(def, true);
                        }
                    }
                }
                else
                {
                    var list = DefinitionObLoader.Loaded.GetDefinitions(id);
                    if (list.Count == 0)
                    {
                        Console.WriteLine("Couldn't find any definitions with ID " + id);
                    }
                    foreach (var def in list)
                    {
                        translator.Translate(def, true);
                    }
                }
            }

            var definitionSet = new MyObjectBuilder_Definitions
            {
                Definitions = new MySerializableList <MyObjectBuilder_DefinitionBase>(translatedSet.AllDefinitions.OrderBy(x => x.TypeId.ToString())
                                                                                      .ThenBy(x => x.SubtypeName))
            };

            XDocument doc;

            using (var baseWriter = new StringWriter())
            {
                var serializer = new XmlSerializer(typeof(MyObjectBuilder_Definitions));
                using (var writer = new XmlTextWriter(baseWriter))
                    serializer.Serialize(writer, definitionSet);
                doc = XDocument.Load(new StringReader(baseWriter.ToString()));
            }

            NullCleaner.Clean(doc);
            var translatedSbcPath = Path.Combine(config.OutputDirectory, "Data/Translated.sbc");

            Directory.CreateDirectory(Path.GetDirectoryName(translatedSbcPath));
            using (var writer = new XmlTextWriter(translatedSbcPath, Encoding.UTF8)
            {
                Formatting = Formatting.Indented,
                Indentation = 2
            })

                doc.WriteTo(writer);

            MyLog.Default.Dispose();
        }