From 1511dafa934738a6baff1288c95daaa087c21d5f Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Thu, 7 Nov 2024 23:05:19 +0300 Subject: [PATCH] Hide application window on OcrTool press --- RhSolutions.AddIn/Tools/OcrTool.cs | 22 +++++++++++++++++----- RhSolutions.AddIn/Tools/ToolFactory.cs | 3 ++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/RhSolutions.AddIn/Tools/OcrTool.cs b/RhSolutions.AddIn/Tools/OcrTool.cs index 4e0f828..965158b 100644 --- a/RhSolutions.AddIn/Tools/OcrTool.cs +++ b/RhSolutions.AddIn/Tools/OcrTool.cs @@ -2,21 +2,33 @@ using System.Runtime.Versioning; #endif +using System.Threading.Tasks; + namespace RhSolutions.Tools; internal class OcrTool : Tool { - public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory) - { - } + public Application Application { get; set; } + public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory, Application application) : base(readerFactory, writerFactory) + { + Application = application; + } - public override void Execute() - { + public override void Execute() + { + Application.Visible = false; + Task.Run(async delegate + { + await Task.Delay(100); + }).Wait(); + var bmp = SnippingTool.SnippingTool.Snip(); if (bmp != null) { // Do something with the bitmap //... } + + Application.Visible = true; } } \ No newline at end of file diff --git a/RhSolutions.AddIn/Tools/ToolFactory.cs b/RhSolutions.AddIn/Tools/ToolFactory.cs index e65ab0c..045e893 100644 --- a/RhSolutions.AddIn/Tools/ToolFactory.cs +++ b/RhSolutions.AddIn/Tools/ToolFactory.cs @@ -5,6 +5,7 @@ internal class ToolFactory static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService(); static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService(); static FittingsCalculatorFactory fittingsCalculatorFactory = RhSolutionsAddIn.ServiceProvider.GetService(); + static Application application = RhSolutionsAddIn.ServiceProvider.GetService(); public Tool GetTool(string toolName) { @@ -17,7 +18,7 @@ internal class ToolFactory "guess" => new GuessTool(readerFactory, writerFactory), "fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"), "fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"), - "ocr" => new OcrTool(readerFactory, writerFactory), + "ocr" => new OcrTool(readerFactory, writerFactory, application), _ => throw new Exception($"Неизвестный инструмент {toolName}"), }; return tool;