un-revert

This commit is contained in:
2025-07-23 13:50:02 +09:00
parent 24b5ab9686
commit ddb4a1c408
4 changed files with 363 additions and 29 deletions

View File

@@ -54,30 +54,21 @@
<!-- Always show what we're doing -->
<Message Text="Copying fletimageanalysis folder contents..." Importance="normal" />
<Message Text="JSON files to copy: @(FletImageAnalysisJsonFiles->Count())" Importance="normal" />
<Message Text="Other files to copy: @(FletImageAnalysisOtherFiles->Count())" Importance="normal" />
<Message Text="JSON files to copy: @(FletImageAnalysisJsonFiles-&gt;Count())" Importance="normal" />
<Message Text="Other files to copy: @(FletImageAnalysisOtherFiles-&gt;Count())" Importance="normal" />
<!-- Copy JSON files - ALWAYS as new (SkipUnchangedFiles=false) -->
<Copy
SourceFiles="@(FletImageAnalysisJsonFiles)"
DestinationFiles="@(FletImageAnalysisJsonFiles->'$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')"
SkipUnchangedFiles="false"
OverwriteReadOnlyFiles="true" />
<Copy SourceFiles="@(FletImageAnalysisJsonFiles)" DestinationFiles="@(FletImageAnalysisJsonFiles->'$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" OverwriteReadOnlyFiles="true" />
<Message Text="JSON files copied (always as new): @(FletImageAnalysisJsonFiles->Count())" Importance="high" />
<Message Text="JSON files copied (always as new): @(FletImageAnalysisJsonFiles-&gt;Count())" Importance="high" />
<!-- Copy other files - incrementally (SkipUnchangedFiles=true) -->
<Copy
SourceFiles="@(FletImageAnalysisOtherFiles)"
DestinationFiles="@(FletImageAnalysisOtherFiles->'$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="true" />
<Copy SourceFiles="@(FletImageAnalysisOtherFiles)" DestinationFiles="@(FletImageAnalysisOtherFiles->'$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
<Message Text="Other files copied (incremental): @(FletImageAnalysisOtherFiles->Count())" Importance="normal" />
<Message Text="Other files copied (incremental): @(FletImageAnalysisOtherFiles-&gt;Count())" Importance="normal" />
<!-- Verify critical JSON file exists after copy -->
<Error Condition="!Exists('$(OutDir)fletimageanalysis\mapping_table_json.json')"
Text="Critical file missing after copy: mapping_table_json.json" />
<Error Condition="!Exists('$(OutDir)fletimageanalysis\mapping_table_json.json')" Text="Critical file missing after copy: mapping_table_json.json" />
<Message Text="fletimageanalysis folder copy completed successfully." Importance="high" />
</Target>
@@ -87,18 +78,10 @@
<Message Text="Copying fletimageanalysis folder for publish..." Importance="high" />
<!-- Copy JSON files - always as new -->
<Copy
SourceFiles="@(FletImageAnalysisJsonFiles)"
DestinationFiles="@(FletImageAnalysisJsonFiles->'$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')"
SkipUnchangedFiles="false"
OverwriteReadOnlyFiles="true" />
<Copy SourceFiles="@(FletImageAnalysisJsonFiles)" DestinationFiles="@(FletImageAnalysisJsonFiles->'$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" OverwriteReadOnlyFiles="true" />
<!-- Copy other files - always as new for publish -->
<Copy
SourceFiles="@(FletImageAnalysisOtherFiles)"
DestinationFiles="@(FletImageAnalysisOtherFiles->'$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')"
SkipUnchangedFiles="false"
OverwriteReadOnlyFiles="true" />
<Copy SourceFiles="@(FletImageAnalysisOtherFiles)" DestinationFiles="@(FletImageAnalysisOtherFiles->'$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" OverwriteReadOnlyFiles="true" />
<Message Text="fletimageanalysis folder publish copy completed." Importance="high" />
</Target>

View File

@@ -1,7 +1,7 @@
<Window x:Class="DwgExtractorManual.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DWG 정보 추출기" Height="700" Width="900"
Title="DWG 정보 추출기" Height="Auto" Width="900"
WindowStartupLocation="CenterScreen"
MinHeight="600" MinWidth="800">
@@ -12,6 +12,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
@@ -89,6 +90,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 진행률 바 -->
@@ -171,11 +173,32 @@
</Button.Style>
</Button>
</StackPanel>
<!-- Second row of buttons -->
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,0,10">
<Button x:Name="btnDwgOnly"
Content="🔧 DWG추출(폴더별)" Width="150" Height="45"
Margin="5,0"
Click="BtnDwgOnly_Click" FontSize="14" FontWeight="Bold"
Background="#8B4513" Foreground="White"
BorderThickness="0">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="#8B4513"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#A0522D"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
</Grid>
</GroupBox>
<!-- 로그 출력 -->
<GroupBox Grid.Row="5" Header="📋 실시간 로그" Margin="15,5,15,10"
<GroupBox Grid.Row="6" Header="📋 실시간 로그" Margin="15,5,15,10" Height="300"
FontWeight="SemiBold" FontSize="14">
<ScrollViewer Margin="5" VerticalScrollBarVisibility="Auto">
<TextBox x:Name="txtLog"
@@ -188,7 +211,7 @@
</GroupBox>
<!-- 상태바 -->
<StatusBar Grid.Row="6" Background="#3B4252" Foreground="White">
<StatusBar Grid.Row="7" Background="#3B4252" Foreground="White">
<StatusBarItem>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="txtStatusBar" Text="DWG 정보 추출기 v1.0 - 준비됨"/>

View File

@@ -1651,6 +1651,88 @@ namespace DwgExtractorManual
}
}
/// <summary>
/// DWG 전용 폴더별 추출 버튼 클릭 이벤트
/// </summary>
private async void BtnDwgOnly_Click(object sender, RoutedEventArgs e)
{
try
{
// 경로 검증
string sourceFolder = txtSourceFolder.Text;
string resultFolder = txtResultFolder.Text;
if (string.IsNullOrWhiteSpace(sourceFolder) || !Directory.Exists(sourceFolder))
{
ShowMessageBox("올바른 소스 폴더를 선택해주세요.", "경로 오류", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (string.IsNullOrWhiteSpace(resultFolder) || !Directory.Exists(resultFolder))
{
ShowMessageBox("올바른 결과 저장 폴더를 선택해주세요.", "경로 오류", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// 리프 폴더 찾기
var leafFolders = FindLeafFolders(sourceFolder);
if (leafFolders.Count == 0)
{
ShowMessageBox("처리할 리프 폴더가 없습니다.", "정보", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
LogMessage($"🔍 발견된 리프 폴더: {leafFolders.Count}개");
foreach (var folder in leafFolders)
{
LogMessage($" - {folder}");
}
// 사용자 확인
var result = ShowConfirmationDialog(
$"총 {leafFolders.Count}개의 리프 폴더에서 DWG만 추출하시겠습니까?\n\n" +
"각 폴더마다 DWG 추출 작업이 실행되고, 폴더별로 Excel 파일이 생성됩니다.",
"DWG 전용 추출 확인");
if (result != MessageBoxResult.Yes)
{
return;
}
// UI 상태 변경
SetButtonsEnabled(false);
progressBar.Value = 0;
UpdateStatus("🔧 DWG 전용 폴더별 추출 시작...");
// 자동 처리 모드 활성화
isAutoProcessing = true;
await ProcessLeafFoldersDwgOnly(leafFolders, resultFolder);
ShowMessageBox(
$"DWG 전용 추출이 완료되었습니다!\n\n" +
$"처리된 폴더: {leafFolders.Count}개\n" +
$"결과 저장 위치: {resultFolder}",
"완료",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
catch (Exception ex)
{
LogMessage($"❌ DWG 전용 추출 중 오류: {ex.Message}");
ShowMessageBox($"DWG 전용 추출 중 오류가 발생했습니다:\n{ex.Message}", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
SetButtonsEnabled(true);
progressBar.Value = 0;
UpdateStatus("✅ 준비");
// 자동 처리 모드 비활성화
isAutoProcessing = false;
}
}
/// <summary>
/// 폴더에서 리프 폴더들(하위 폴더가 없는 폴더)을 재귀적으로 찾습니다.
/// </summary>
@@ -1803,6 +1885,163 @@ namespace DwgExtractorManual
UpdateStatus("✅ 자동 처리 완료");
}
/// <summary>
/// 리프 폴더들에 대해 DWG 전용 추출을 수행합니다.
/// </summary>
/// <param name="leafFolders">처리할 리프 폴더 목록</param>
/// <param name="resultBaseFolder">결과 파일 저장 기본 폴더</param>
private async Task ProcessLeafFoldersDwgOnly(List<string> leafFolders, string resultBaseFolder)
{
int totalFolders = leafFolders.Count;
int currentFolderIndex = 0;
LogMessage($"🔧 DWG 전용 폴더별 추출 시작: {totalFolders}개 폴더");
foreach (string leafFolder in leafFolders)
{
currentFolderIndex++;
progressBar.Value = (double)currentFolderIndex / totalFolders * 100;
try
{
LogMessage($"📁 [{currentFolderIndex}/{totalFolders}] DWG 추출 시작: {leafFolder}");
// 1. DWG 추출만 수행
await ProcessFilesDwgOnly(leafFolder);
LogMessage($"✅ [{currentFolderIndex}/{totalFolders}] DWG 추출 완료");
// 2초 대기
await Task.Delay(2000);
// 2. DWG 전용 Excel 파일 생성 및 이름 변경
await RenameDwgOnlyExcelFile(resultBaseFolder, leafFolder);
LogMessage($"📋 [{currentFolderIndex}/{totalFolders}] Excel 파일 생성 완료");
// 1초 대기
await Task.Delay(1000);
}
catch (Exception ex)
{
LogMessage($"❌ [{currentFolderIndex}/{totalFolders}] 폴더 처리 실패 ({leafFolder}): {ex.Message}");
LogMessage($"⏭️ [{currentFolderIndex}/{totalFolders}] 다음 폴더로 계속 진행");
// 오류 발생 시 잠시 대기 후 다음 폴더 처리
await Task.Delay(2000);
continue;
}
}
LogMessage($"🎉 DWG 전용 추출 완료! 총 {totalFolders}개 폴더 처리됨");
UpdateStatus("✅ DWG 전용 추출 완료");
}
/// <summary>
/// 지정된 폴더에서 DWG 파일들만 처리합니다.
/// </summary>
/// <param name="sourceFolderPath">처리할 폴더 경로</param>
private async Task ProcessFilesDwgOnly(string sourceFolderPath)
{
try
{
string resultFolder = txtResultFolder.Text;
if (!Directory.Exists(sourceFolderPath))
{
LogMessage($"❌ 소스 폴더가 존재하지 않습니다: {sourceFolderPath}");
return;
}
var dwgFiles = Directory.GetFiles(sourceFolderPath, "*.dwg", SearchOption.TopDirectoryOnly);
if (dwgFiles.Length == 0)
{
LogMessage($"📄 처리할 DWG 파일이 없습니다: {sourceFolderPath}");
return;
}
LogMessage($"📊 처리할 DWG 파일 수: {dwgFiles.Length}개");
LogMessage($"📋 출력 모드: Excel");
LogMessage($"📂 소스 폴더: {sourceFolderPath}");
LogMessage($"💾 결과 폴더: {resultFolder}");
LogMessage("📊 Excel 내보내기 모드로 시작합니다...");
LogMessage("📝 Excel 애플리케이션을 초기화합니다...");
_exportExcel = new ExportExcel();
// UI 응답성을 위한 양보
await Task.Yield();
// 각 DWG 파일 처리
foreach (string dwgFile in dwgFiles)
{
LogMessage($"📄 DWG 파일 처리 중: {Path.GetFileName(dwgFile)}");
_exportExcel.ExportDwgToExcel(dwgFile);
// UI 응답성을 위한 양보
await Task.Yield();
}
// DWG 전용 워크북 저장
LogMessage("💾 DWG 전용 Excel 파일 저장 중...");
_exportExcel.SaveDwgOnlyMappingWorkbook(resultFolder);
LogMessage("✅ DWG 전용 Excel 파일 저장 완료");
}
catch (Exception ex)
{
LogMessage($"❌ DWG 처리 중 치명적 오류: {ex.Message}");
throw;
}
finally
{
_exportExcel?.Dispose();
_exportExcel = null;
}
}
/// <summary>
/// DWG 전용 Excel 파일을 목표 경로로 이름 변경
/// </summary>
/// <param name="resultFolder">결과 폴더</param>
/// <param name="leafFolderPath">리프 폴더 경로</param>
private async Task RenameDwgOnlyExcelFile(string resultFolder, string leafFolderPath)
{
try
{
// 최신 *_DwgOnly_Mapping.xlsx 파일 찾기
var excelFiles = Directory.GetFiles(resultFolder, "*_DwgOnly_Mapping.xlsx")
.Where(f => !Path.GetFileName(f).StartsWith("~$"))
.OrderByDescending(f => File.GetCreationTime(f))
.ToList();
if (excelFiles.Any())
{
string latestFile = excelFiles.First();
// 리프 폴더 경로를 기반으로 파일명 생성
string relativePath = Path.GetRelativePath(txtSourceFolder.Text, leafFolderPath);
string safePath = relativePath.Replace('\\', '_').Replace('/', '_').Replace(':', '_');
string targetFileName = $"{safePath}_DwgMapping.xlsx";
string targetPath = Path.Combine(resultFolder, targetFileName);
// 목표 파일이 이미 존재하면 삭제
if (File.Exists(targetPath))
{
File.Delete(targetPath);
}
// 파일 이름 변경
File.Move(latestFile, targetPath);
LogMessage($"📋 DWG Excel 파일 이름 변경됨: {targetFileName}");
}
}
catch (Exception ex)
{
LogMessage($"⚠️ DWG Excel 파일 이름 변경 실패: {ex.Message}");
}
}
/// <summary>
/// 최신 Excel 파일을 목표 경로로 이름 변경
/// </summary>
@@ -1849,6 +2088,7 @@ namespace DwgExtractorManual
btnPdfExtract.IsEnabled = enabled;
btnMerge.IsEnabled = enabled;
btnAuto.IsEnabled = enabled;
btnDwgOnly.IsEnabled = enabled;
}
protected override void OnClosed(EventArgs e)

View File

@@ -841,6 +841,94 @@ namespace DwgExtractorManual.Models
}
}
/// <summary>
/// DWG 전용 매핑 워크북을 생성하고 저장합니다 (PDF 컬럼 제외).
/// </summary>
/// <param name="resultFolderPath">결과 파일 저장 폴더 경로</param>
public void SaveDwgOnlyMappingWorkbook(string resultFolderPath)
{
try
{
string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
string savePath = Path.Combine(resultFolderPath, $"{timestamp}_DwgOnly_Mapping.xlsx");
Debug.WriteLine($"[DEBUG] DWG 전용 매핑 워크북 생성 시작: {savePath}");
// Excel 애플리케이션 초기화 확인
if (excelApplication == null)
{
excelApplication = new Excel.Application();
excelApplication.Visible = false;
Debug.WriteLine("[DEBUG] 새 Excel 애플리케이션 생성됨 (DWG 전용)");
}
// DWG 전용 워크북 생성
var dwgOnlyWorkbook = excelApplication.Workbooks.Add();
var dwgOnlyWorksheet = (Excel.Worksheet)dwgOnlyWorkbook.Worksheets[1];
dwgOnlyWorksheet.Name = "DWG Mapping Data";
// 헤더 생성 (PDF Value 컬럼 제외)
dwgOnlyWorksheet.Cells[1, 1] = "파일명";
dwgOnlyWorksheet.Cells[1, 2] = "Map Key";
dwgOnlyWorksheet.Cells[1, 3] = "AI Label";
dwgOnlyWorksheet.Cells[1, 4] = "DWG Tag";
dwgOnlyWorksheet.Cells[1, 5] = "DWG Value";
// 헤더 스타일 적용
var headerRange = dwgOnlyWorksheet.Range["A1:E1"];
headerRange.Font.Bold = true;
headerRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGray);
headerRange.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
// 데이터 입력
int row = 2;
foreach (var fileEntry in FileToMapkeyToLabelTagValuePdf)
{
string fileName = fileEntry.Key;
foreach (var mapEntry in fileEntry.Value)
{
string mapKey = mapEntry.Key;
var (aiLabel, dwgTag, dwgValue, pdfValue) = mapEntry.Value;
dwgOnlyWorksheet.Cells[row, 1] = fileName;
dwgOnlyWorksheet.Cells[row, 2] = mapKey;
dwgOnlyWorksheet.Cells[row, 3] = aiLabel;
dwgOnlyWorksheet.Cells[row, 4] = dwgTag;
dwgOnlyWorksheet.Cells[row, 5] = dwgValue;
row++;
}
}
// 컬럼 자동 크기 조정
dwgOnlyWorksheet.Columns.AutoFit();
// 파일 저장
string directory = Path.GetDirectoryName(savePath);
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
dwgOnlyWorkbook.SaveAs(savePath,
FileFormat: Excel.XlFileFormat.xlOpenXMLWorkbook,
AccessMode: Excel.XlSaveAsAccessMode.xlNoChange);
Debug.WriteLine($"✅ DWG 전용 매핑 워크북 저장 완료: {Path.GetFileName(savePath)}");
// 워크북 정리
dwgOnlyWorkbook.Close(false);
System.Runtime.InteropServices.Marshal.ReleaseComObject(dwgOnlyWorksheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(dwgOnlyWorkbook);
}
catch (System.Exception ex)
{
Debug.WriteLine($"❌ DWG 전용 매핑 워크북 저장 중 오류: {ex.Message}");
Debug.WriteLine($" 스택 트레이스: {ex.StackTrace}");
throw;
}
}
/// <summary>
/// 현재 Excel 워크북을 지정된 경로에 저장하고 Excel 애플리케이션을 종료합니다.
/// </summary>