diff --git a/Code/CSRender/CSRender/CompareTIFF.cs b/Code/CSRender/CSRender/CompareTIFF.cs index d4016bb9b630440aa710814b65bab368fa818f98..4382b31b08fe91736dae9d98a12f879f265a99d9 100644 --- a/Code/CSRender/CSRender/CompareTIFF.cs +++ b/Code/CSRender/CSRender/CompareTIFF.cs @@ -22,19 +22,26 @@ namespace CSRender class CompareTIFF { public static void runPureVerify(string targetDir, string referenceDir, string workPath, - string shiftPixel, string colorMargin, string removePoint, string shadingOff, - bool reportFlag, string reportName, string inDiffPath, string inTargetFileName, DateTime inDateTime) + string shiftPixel, string colorMargin, string removePoint, string shadingOff, bool reportFlag, + string reportName, string inDiffPath, string inTargetFileName, DateTime inDateTime, string inReportInfo) { - //実行用コンソールの呼び出し - ProcessStartInfo processStartInfo = new ProcessStartInfo(); + //exeのpathを取得 string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得 string appDirectory = appPath.Substring(0, appPath.LastIndexOf(@"\") + 1); //モジュールの存在するディレクトリを取得 string exePath = System.IO.Path.Combine("PureVerify.Data", "RipVerify", "bin", "x64"); + + //実行用コンソールの呼び出し + ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = System.IO.Path.Combine(appDirectory, exePath, "PureVerify.exe"); + processStartInfo.WindowStyle = ProcessWindowStyle.Minimized; processStartInfo.CreateNoWindow = true; // コマンドプロンプトを非表示 processStartInfo.UseShellExecute = false; // シェル機能オフ processStartInfo.RedirectStandardOutput = true;//標準出力をリダイレクト + //レポートに書き込む情報を編集 + inTargetFileName = System.IO.Path.GetFileNameWithoutExtension(inTargetFileName); + string reportInfoPath = MainWindow.editEachReport(appDirectory,inTargetFileName, inReportInfo, targetDir, referenceDir); + //引数設定 //指定ファイル processStartInfo.Arguments = "/tar "; @@ -79,14 +86,13 @@ namespace CSRender processStartInfo.Arguments += "\" "; //対象ファイル名を設定 - inTargetFileName = System.IO.Path.GetFileNameWithoutExtension(inTargetFileName); processStartInfo.Arguments += "/inspTiff \""; processStartInfo.Arguments += inTargetFileName + ".pdf"; processStartInfo.Arguments += "\" "; //レポートファイル名を設定 string timeForReport = "【" + inDateTime.ToString("yyMMdd_HHmm") + "】" + ".pdf"; - string TargetName = System.IO.Path.Combine(reportName, "report_" + inTargetFileName + ".pdf" + timeForReport); + string TargetName = System.IO.Path.Combine(reportName, inTargetFileName + ".pdf" + timeForReport); processStartInfo.Arguments += "/inspReport \""; processStartInfo.Arguments += TargetName; processStartInfo.Arguments += "\" "; @@ -110,8 +116,9 @@ namespace CSRender //レポート記述内容の参照先 processStartInfo.Arguments += "/topPageInfo "; - string textPath = System.IO.Path.Combine("PureVerify.Data", "RipVerify", "work", "OUT_INFO", "CSReportInf.txt"); - processStartInfo.Arguments += System.IO.Path.Combine(appDirectory, textPath); + //string textPath = System.IO.Path.Combine("PureVerify.Data", "RipVerify", "work", "OUT_INFO", "CSReportInf.txt"); + //processStartInfo.Arguments += System.IO.Path.Combine(appDirectory, textPath); + processStartInfo.Arguments += reportInfoPath; //CSRender.exeを実行 Process process = Process.Start(processStartInfo); @@ -121,8 +128,7 @@ namespace CSRender //NGの含まれる場合レポート名の頭に【NG】を付与 NGReportName(TargetName, reportName); - - //return workDir; + } //指定先にレポートを移動 @@ -158,16 +164,27 @@ namespace CSRender { //string searchName = "report_" + inTargetName; string searchfile = System.IO.Path.GetFileNameWithoutExtension(inTargetName) + "&*"; - var reportFileName = Directory.GetFiles(inReportPath, searchfile); - if (reportFileName.Length > 0) + var NGreportFileName = Directory.GetFiles(inReportPath, searchfile); + var OKreportFileName = Directory.GetFiles(inReportPath, System.IO.Path.GetFileName(inTargetName)); + int NGCount = NGreportFileName.Length; + if (NGCount > 0) { - foreach (var oldPathName in reportFileName) + foreach (var oldPathName in NGreportFileName) { string oldFile = System.IO.Path.GetFileName(oldPathName); File.Copy(oldPathName, System.IO.Path.Combine(inReportPath, "【NG】" + oldFile), true); File.Delete(oldPathName); } } + else + { + foreach (var beforePathName in OKreportFileName) + { + string oldFile = System.IO.Path.GetFileName(beforePathName); + File.Copy(beforePathName, System.IO.Path.Combine(inReportPath, "【OK】" + oldFile), true); + File.Delete(beforePathName); + } + } } } diff --git a/Code/CSRender/CSRender/MainWindow.xaml.cs b/Code/CSRender/CSRender/MainWindow.xaml.cs index 1d3b9dc14ab9b3fed5da3993a99b46055a6487ea..c108802b224c3d68097def0a06e7b90da9d958d6 100644 --- a/Code/CSRender/CSRender/MainWindow.xaml.cs +++ b/Code/CSRender/CSRender/MainWindow.xaml.cs @@ -105,6 +105,8 @@ namespace CSRender private void CompareButtonClick(object sender, RoutedEventArgs e) { + killButton(); + string workBoxText = workBox.Text; string reportBoxText = reportBox.Text; string targetBoxText = targetBox.Text; @@ -196,7 +198,7 @@ namespace CSRender } //TIFF画像の生成 - ResultConsole.Text += "\r\n"; + ResultConsole.Text += "< TIFF変換開始 >\r\n"; ResultConsole.Text += " 対象ファイルをTIFF画像に変換中\r\n"; ResultConsole.ScrollToEnd(); DoEvents(); @@ -262,14 +264,16 @@ namespace CSRender var allRipTime = $"{timeResult}".Substring(0,8); ResultConsole.Text += " [RIP処理時間 " + allRipTime + "]\r\n"; - ResultConsole.Text += "\r\n"; + ResultConsole.Text += "< TIFF変換完了 >\r\n"; ResultConsole.ScrollToEnd(); DoEvents(); - + + string reportContentsInfo = ""; try { //レポートへの出力内容を編集 - editReport(allRipTime, workBoxText); + //editReport(allRipTime, workBoxText); + reportContentsInfo = getReportInfo(allRipTime, workBoxText); } catch (Exception ex) { @@ -283,22 +287,34 @@ namespace CSRender } string workDir = ""; + int allPDFNum = 0; + int NGPDFNum = 0; try { // 日付取得 DateTime NowTime = DateTime.Now; //検版対象ファイル名の取得 string[] inspectionTargets = GetTargetList(targetBoxText, referenceBoxText); + allPDFNum = inspectionTargets.Length; string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得 string appDirectory = appPath.Substring(0, appPath.LastIndexOf(@"\") + 1); //モジュールの存在するディレクトリを取得 workDir = System.IO.Path.Combine(appDirectory, "PureVerify.Data", "RipVerify"); - - Parallel.ForEach(inspectionTargets, targetPDFName => + + // 並列処理オプションの設定 + ParallelOptions parallelOptions = new ParallelOptions(); + parallelOptions.MaxDegreeOfParallelism = 4;// 並行数(プロセス数) + var logicalProcessNum = Environment.ProcessorCount;//PCの論理CPUの数 + if (logicalProcessNum >= 10) + { + parallelOptions.MaxDegreeOfParallelism = logicalProcessNum - 4; + } + + Parallel.ForEach(inspectionTargets, parallelOptions, targetPDFName => { //PureVerifyの実行 CompareTIFF.runPureVerify(targetTIFFPath, referenceTIFFPath, workBoxText , shiftPixel, colorMargin, removePoint, shadingOff, reportFlag, reportBoxText, - outDiffPath, targetPDFName, NowTime); + outDiffPath, targetPDFName, NowTime, reportContentsInfo); }); } @@ -317,7 +333,9 @@ namespace CSRender try { //レポートを出力 - outputLog(System.IO.Path.Combine(workDir, "report")); + //outputLog(System.IO.Path.Combine(workDir, "report")); + NGPDFNum = getNGNum(System.IO.Path.Combine(workDir, "report")); + outResuletToUI(allPDFNum, NGPDFNum, referenceTIFFPath, targetTIFFPath); } catch (Exception ex) { @@ -367,7 +385,10 @@ namespace CSRender { reportBox.Text = System.IO.Path.Combine(workBoxText, "report", PDFName); } - + + //生成したレポートinf.txtを全削除 + deleteReportTexts(); + //パラメータを次回初期値用に保存 Properties.Settings.Default.resolutionSetting = ResolutionBox.Value; Properties.Settings.Default.formatSetting = FileSelect.Text; @@ -380,6 +401,8 @@ namespace CSRender Properties.Settings.Default.referenceSetting = referenceBoxText; Properties.Settings.Default.reportPathSetting = reportBoxText; Properties.Settings.Default.Save(); + + reviveButton(); } /// @@ -393,6 +416,7 @@ namespace CSRender private void outputLog(string workDir) { //logファイルを読み取り(1行ずつ) + int fileCount = 0; string[] reportFiles = System.IO.Directory.GetFiles(workDir, "*.pdf.log", System.IO.SearchOption.TopDirectoryOnly); foreach (var logfileName in reportFiles) { @@ -401,36 +425,130 @@ namespace CSRender ResultConsole.Text += outputFileName + "\r\n"; StreamReader logString = new StreamReader(logfileName, Encoding.GetEncoding("Shift-JIS"));//Shift-JISでエンコーディング string tranceString = ""; - //int lineCount = 0; - + int lineCount = 0; + //ファイルから読み取った結果をUIに出力 while (logString.EndOfStream == false) { tranceString = logString.ReadLine(); - /* lineCount++; - //logファイルにある処理日時表示を除去 - if (lineCount == 14 || lineCount == 20 || lineCount == 37 || lineCount == 38 || lineCount == 39 || lineCount == 40) - { - tranceString = tranceString.Substring(0, 66); - } - if (lineCount > 13 && lineCount < 41)//必要なところだけをUIに記述 + if(fileCount == 0) { ResultConsole.Text += tranceString + "\r\n"; ResultConsole.ScrollToEnd(); DoEvents(); } - */ - ResultConsole.Text += tranceString + "\r\n"; - ResultConsole.ScrollToEnd(); - DoEvents(); + else + { + if ((lineCount > 13 && lineCount < 27) || lineCount == 6)//必要なところだけをUIに記述 + { + ResultConsole.Text += tranceString + "\r\n"; + ResultConsole.ScrollToEnd(); + DoEvents(); + } + } + //ResultConsole.Text += tranceString + "\r\n"; } logString.Close(); + fileCount++; } + ResultConsole.Text += "< 検版終了 >\r\n"; + ResultConsole.ScrollToEnd(); + DoEvents(); //string logfileName = reportFiles[0]; + + + } + + /// + /// NGな画像の総数を取得 + /// + private int getNGNum(string workDir) + { + int NGFileNum = 0; + //logファイルを読み取り(NG数の記述されている行を抽出) + string[] reportFiles = System.IO.Directory.GetFiles(workDir, "*.pdf.log", System.IO.SearchOption.TopDirectoryOnly); + foreach (var logfileName in reportFiles) + { + string tranceString = File.ReadLines(logfileName, Encoding.GetEncoding("Shift-JIS")).Skip(16).First();//16行目を抽出 + tranceString = tranceString.Replace("NG", "");//不要な部分をカット + tranceString = tranceString.Replace(":", ""); + tranceString = tranceString.Replace(" ", ""); + + int NumOfThisFile = 0; + try + { + NumOfThisFile = Int32.Parse(tranceString); + } + catch (FormatException e) + { + NumOfThisFile = 0; + } + NGFileNum += NumOfThisFile; + } + + return NGFileNum; + } + + /// + /// UIに検版結果を出力する + /// + private void outResuletToUI(int inAllPDFNum, int inNGPDFNum, string refTiffPath, string tarTiffPath) + { + //記述用の情報を取得 + string[] tarTiffNum = System.IO.Directory.GetFiles(tarTiffPath, "*.tiff", System.IO.SearchOption.TopDirectoryOnly);//画像数 + string[] refTiffNum = System.IO.Directory.GetFiles(refTiffPath, "*.tiff", System.IO.SearchOption.TopDirectoryOnly); + int OKPDFNum = inAllPDFNum - inNGPDFNum;//OKの数 + + //検版結果を出力 + ResultConsole.Text += "< 検版結果 >\r\n"; + ResultConsole.Text += " リファレンスPDFパス:"; + ResultConsole.Text += referenceBox.Text; + ResultConsole.Text += "\r\n リファレンス画像ファイル数:"; + ResultConsole.Text += refTiffNum.Length.ToString(); + ResultConsole.ScrollToEnd(); + + ResultConsole.Text += "\r\n 対象PDFパス:"; + ResultConsole.Text += targetBox.Text; + ResultConsole.Text += "\r\n 対象画像ファイル数:"; + ResultConsole.Text += tarTiffNum.Length.ToString(); + ResultConsole.ScrollToEnd(); + + ResultConsole.Text += "\r\n [検版パラメータ]"; + ResultConsole.Text += "\r\n  位置ズレ許容量 :"; + ResultConsole.Text += PositionBox.Text; + ResultConsole.Text += " pixel\r\n  諧調差許容量 :"; + ResultConsole.Text += GradationBox.Text; + ResultConsole.Text += "\r\n  微小差異許容量:"; + ResultConsole.Text += SmallDiffBox.Text; + ResultConsole.Text += "\r\n  視覚的あいまい量:"; + ResultConsole.Text += VisualBox.Text; + ResultConsole.ScrollToEnd(); + + ResultConsole.Text += " pixel\r\n [検版結果]"; + ResultConsole.Text += "\r\n  ALL:"; + ResultConsole.Text += inAllPDFNum.ToString(); + ResultConsole.Text += "\r\n  OK :"; + ResultConsole.Text += OKPDFNum.ToString(); + ResultConsole.Text += "\r\n  NG :"; + ResultConsole.Text += inNGPDFNum.ToString(); + + ResultConsole.Text += "\r\n  OK-バイナリ比較:0"; + ResultConsole.Text += "\r\n  OK-完全一致検版:0"; + ResultConsole.Text += "\r\n  OK-ゆすらせ検版:"; + ResultConsole.Text += OKPDFNum.ToString(); + ResultConsole.Text += "\r\n  NG-完全一致検版:0"; + ResultConsole.Text += "\r\n  NG-ゆすらせ検版:"; + ResultConsole.Text += inNGPDFNum.ToString(); - + + ResultConsole.Text += "\r\n< 検版終了 >\r\n"; + ResultConsole.ScrollToEnd(); + DoEvents(); + //string logfileName = reportFiles[0]; + + } /// @@ -467,6 +585,141 @@ namespace CSRender return allPage; } + /// + /// 検版するPDFに応じたレポートの出力内容を編集する + /// + internal static string editEachReport(string inAppDir, string targetPDF, string textContent, string TarTiffPath, string RefTiffpath) + { + // .txtのパス + string outInfoPath = System.IO.Path.Combine("PureVerify.Data", "RipVerify", "work", "OUT_INFO", "ReportInf"); + outInfoPath = System.IO.Path.Combine(inAppDir, outInfoPath); + if (!Directory.Exists(outInfoPath)) + { + Directory.CreateDirectory(outInfoPath); + } + //ユニークなファイル名(検版するファイル名)でテキストファイルを生成 + string replaceTarName = targetPDF.Replace(" ", "_"); + string reportInfoPath = System.IO.Path.Combine(outInfoPath, replaceTarName + "Inf.txt"); + //if (!File.Exists(reportInfoPath)) + //{ + //File.CreateText(reportInfoPath); + //} + //.txtファイルに記述する内容(ターゲットファイルとリファレンスファイル名) + textContent += "**PDF_REF_NAME: \"" + targetPDF + ".pdf\"\r\n"; + textContent += "**PDF_TAR_NAME: \"" + targetPDF + ".pdf\"\r\n"; + + //ページ数を取得 + string[] referenceTiff = System.IO.Directory.GetFiles(RefTiffpath, targetPDF + ".pdf*.tiff", System.IO.SearchOption.TopDirectoryOnly); + string referenceAllPage = referenceTiff.Length.ToString(); + textContent += "**PDF_REF_PAGE_NUM: \"" + referenceAllPage + "\"\r\n"; + string[] targetTiff = System.IO.Directory.GetFiles(TarTiffPath, targetPDF + ".pdf*.tiff", System.IO.SearchOption.TopDirectoryOnly); + string targetAllPage = targetTiff.Length.ToString(); + textContent += "**PDF_TAR_PAGE_NUM: \"" + targetAllPage + "\"\r\n"; + + // StreamWriterオブジェクトのインスタンスを生成 + using (StreamWriter streamWriter = new StreamWriter(reportInfoPath, false, Encoding.GetEncoding("Shift_JIS"))) + { + // Writeメソッドで文字列データを書き込む + streamWriter.Write(textContent); + // StreamWriterオブジェクトを閉じる + streamWriter.Close(); + } + + return reportInfoPath; + } + + /// + /// 生成したレポート内容参照先txtファイルを全削除(次回に残さない) + /// + private void deleteReportTexts() + { + // .txtのパス + string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得 + string appDirectory = appPath.Substring(0, appPath.LastIndexOf(@"\") + 1); //モジュールの存在するディレクトリを取得 + string outInfoPath = System.IO.Path.Combine("PureVerify.Data", "RipVerify", "work", "OUT_INFO", "ReportInf"); + //ディレクトリ内のファイルを全て取得して全て削除 + DirectoryInfo reportTextDir = new DirectoryInfo(outInfoPath); + FileInfo[] deleteTextFles = reportTextDir.GetFiles(); + foreach (FileInfo deleteTxt in deleteTextFles) + { + deleteTxt.Delete(); + } + } + + /// + /// レポートの出力内容を編集する + /// + private string getReportInfo(string allRipTime, string workBox) + { + // exeのパス + string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得 + //対象フォルダの内容 + string tarTiffDir = System.IO.Path.Combine(workBox, "work", "targetTIFF"); + //PDFの数 + string[] targetPDFs = getPDFName(targetBox.Text); + string targetNum = targetPDFs.Length.ToString(); + //PDFの名前一覧 + /* + string allTargetName = ""; + for (int i = 0; i < targetPDFs.Length; i++) + { + if (i > 0) + { + allTargetName += ","; + } + allTargetName += System.IO.Path.GetFileName(targetPDFs[i]); + } + */ + //PDFのページ数 + string targetAllPage = getPDFPage(targetPDFs, tarTiffDir); + + //リファレンスフォルダの内容 + string refTiffDir = System.IO.Path.Combine(workBox, "work", "referenceTIFF"); + //PDFの数 + string[] referencePDFs = getPDFName(referenceBox.Text); + string referenceNum = referencePDFs.Length.ToString(); + //PDFの名前一覧 + /* + string allReferenceName = ""; + for (int i = 0; i < referencePDFs.Length; i++) + { + if (i > 0) + { + allReferenceName += ","; + } + allReferenceName += System.IO.Path.GetFileName(referencePDFs[i]); + } + */ + //PDFのページ数 + string referenceAllPage = getPDFPage(referencePDFs, refTiffDir); + + //.txtファイルに記述する内容 + string writeText = "**RESULT_RIP_TIME: \"" + allRipTime + "\"\r\n"; + writeText += "**ENV_VERSION: \"CSRender Ver 0.3.0\"\r\n"; + writeText += "**ENV_RIPVERIFY_PATH: \"" + appPath + "\"\r\n"; + writeText += "**ENV_RIP_PROCESSING: \"PDFium\"\r\n"; + writeText += "**ENV_IMAGE_RESO: \"" + ResolutionBox.Text + "\"\r\n"; + if (PageRange.Text == "指定") + { + writeText += "**ENV_INSPECTION_AREA_SPECIFY: \"" + pageBox.Text + "\"\r\n"; + } + else + { + writeText += "**ENV_INSPECTION_AREA_SPECIFY: \"ALL\"\r\n"; + } + writeText += "**PDF_REF_FOLDER: \"" + referenceBox.Text + "\"\r\n"; + writeText += "**PDF_REF_FILE_NUM: \"" + referenceNum + "\"\r\n"; + //writeText += "**PDF_REF_NAME: \"" + allReferenceName + "\"\r\n"; + //writeText += "**PDF_REF_PAGE_NUM: \"" + referenceAllPage + "\"\r\n"; + writeText += "**PDF_TAR_FOLDER: \"" + targetBox.Text + "\"\r\n"; + writeText += "**PDF_TAR_FILE_NUM: \"" + targetNum + "\"\r\n"; + //writeText += "**PDF_TAR_NAME: \"" + allTargetName + "\"\r\n"; + //writeText += "**PDF_TAR_PAGE_NUM: \"" + targetAllPage + "\"\r\n"; + //string eachWriteTxet = writeText; + + return writeText; + } + /// /// レポートの出力内容を編集する /// @@ -539,12 +792,15 @@ namespace CSRender } writeText += "**PDF_REF_FOLDER: \"" + referenceBox.Text + "\"\r\n"; writeText += "**PDF_REF_FILE_NUM: \"" + referenceNum + "\"\r\n"; - writeText += "**PDF_REF_NAME: \"" + allReferenceName + "\"\r\n"; + //writeText += "**PDF_REF_NAME: \"" + allReferenceName + "\"\r\n"; writeText += "**PDF_REF_PAGE_NUM: \"" + referenceAllPage + "\"\r\n"; writeText += "**PDF_TAR_FOLDER: \"" + targetBox.Text + "\"\r\n"; writeText += "**PDF_TAR_FILE_NUM: \"" + targetNum + "\"\r\n"; - writeText += "**PDF_TAR_NAME: \"" + allTargetName + "\"\r\n"; + //writeText += "**PDF_TAR_NAME: \"" + allTargetName + "\"\r\n"; writeText += "**PDF_TAR_PAGE_NUM: \"" + targetAllPage + "\"\r\n"; + string eachWriteTxet = writeText; + writeText += "**PDF_REF_NAME: \"" + allReferenceName + "\"\r\n"; + writeText += "**PDF_TAR_NAME: \"" + allTargetName + "\"\r\n"; // StreamWriterオブジェクトのインスタンスを生成 StreamWriter streamWriter = new StreamWriter(reportInfoPath, false, Encoding.GetEncoding("Shift_JIS")); @@ -664,5 +920,53 @@ namespace CSRender ((DispatcherFrame)obj).Continue = false; return null; } + + //全てのボタンをグレー化 + private void killButton() + { + targetButton.IsEnabled = false; + referenceButton.IsEnabled = false; + workButton.IsEnabled = false; + reportButton.IsEnabled = false; + TIFFButton.IsEnabled = false; + CompareButton.IsEnabled = false; + closeButton.IsEnabled = false; + targetBox.IsEnabled = false; + referenceBox.IsEnabled = false; + reportBox.IsEnabled = false; + workBox.IsEnabled = false; + PageRange.IsEnabled = false; + FileSelect.IsEnabled = false; + ResolutionBox.Enabled = false; + PositionBox.Enabled = false; + GradationBox.Enabled = false; + SmallDiffBox.Enabled = false; + VisualBox.Enabled = false; + pageBox.IsEnabled = false; + } + + //全てのボタンを元にもどす + private void reviveButton() + { + targetButton.IsEnabled = true; + referenceButton.IsEnabled = true; + workButton.IsEnabled = true; + reportButton.IsEnabled = true; + TIFFButton.IsEnabled = true; + CompareButton.IsEnabled = true; + closeButton.IsEnabled = true; + targetBox.IsEnabled = true; + referenceBox.IsEnabled = true; + reportBox.IsEnabled = true; + workBox.IsEnabled = true; + PageRange.IsEnabled = true; + FileSelect.IsEnabled = true; + ResolutionBox.Enabled = true; + PositionBox.Enabled = true; + GradationBox.Enabled = true; + SmallDiffBox.Enabled = true; + VisualBox.Enabled = true; + pageBox.IsEnabled = true; + } } }