diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml index a1a6dce..1cac55f 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml @@ -200,6 +200,7 @@ + - - + + + + + + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs index d13f6d8..eb3b87f 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs @@ -1,7 +1,14 @@ -using EPLAN.Harness.Common.Extensions; +using EPLAN.Harness.Common; +using EPLAN.Harness.Common.Extensions; +using EPLAN.Harness.Core.Common; using EPLAN.Harness.Core.Controls; +using EPLAN.Harness.Core.Events; +using EPLAN.Harness.Core.Lampy; using EPLAN.Harness.Core.Settings; using EPLAN.Harness.IO; +using EPLAN.Harness.ProjectCore; +using EPLAN.Harness.ProjectCore.Occurrences; +using EPLAN.Harness.ProjectCore.Occurrences.Designer; using EPLAN.Harness.ProjectCore.Report; using Microsoft.Win32; using Sinvo.EplanHpD.Plugin.WPFUI.Models; @@ -28,11 +35,15 @@ public partial class MainWindow : Window public delegate void UpdateDataGridColumns(List columns, DataGridType type); private IEnumerable datas; private List reportColumns; - public MainWindow(IEnumerable datas, List columns) + private FlexReport _report; + public MainWindow(FlexReport report) { InitializeComponent(); + _report = report; this.DataContext = ViewModel = new MainViewModel(); ViewModel.UpdateDataGridColumns = UpdateDataGridColumnsByType; + var columns = report.Reporter.Formater.RepColumns; + var datas = report.GetAllReportEntries(); this.datas = datas; this.reportColumns = columns; ViewModel.DataColumns = []; @@ -281,4 +292,138 @@ public partial class MainWindow : Window } } } + + private void GoToSource() + { + var selectItems = ModelGenDataGrid.SelectedItems; + if (selectItems != null && selectItems.Count > 0) + //if (selectItems is List reportItems) + { + //foreach (ReportModel item in selectItems) + StuffedDataModel item = (StuffedDataModel)selectItems[0]; + if (item != null) + { + var repoetEntry = datas.FirstOrDefault(it => it.Properties["WireName"].ValueString() == item.WireName); + _report.DataSources.GetSources(); + if (repoetEntry.OrigDocIDs == null || repoetEntry.OrigDocIDs.Count == 0) + { + repoetEntry.OrigDocIDs = new List(); + foreach (IDataSource dataSource in _report.DataSources.GetSources()) + { + IFlexStudioDocument documentByID = FlexProject.CurrentProject.GetDocumentByID(dataSource.ParentID); + FlexDesigner designer; + if ((designer = (documentByID as FlexDesigner)) != null) + { + FlexProject.CurrentProject.LoadDesignerMetadata(designer); + } + if (repoetEntry.OrigID != null && SelfControler.FindInstance(repoetEntry.OrigID) != null) + { + repoetEntry.OrigDocIDs.Add(documentByID.ID); + } + FlexProject.CurrentProject.CloseAllUsedDocuments(); + } + } + foreach (string text in repoetEntry.OrigDocIDs.Distinct()) + + { + FlexDesigner flexDesigner; + if (text != string.Empty && (flexDesigner = (SelfControler.FindInstance(text) as FlexDesigner)) != null && (!(flexDesigner is FlexWorkdesk) || Lamparna.Instance.IsWorkdeskAvailable()) && (!(flexDesigner is FlexWorkspace) || Lamparna.Instance.IsWorkspaceAvailable())) + { + Singleton.Instance.Invoke(NamedEvents.Open_Studio_Document, this._report, new object[] + { + flexDesigner + }); + if (flexDesigner.ReaderStatus != DataReaderStatus.Full) + { + break; + } + flexDesigner.SelectSet.Clear(); + string origID = repoetEntry.OrigID; + List list = new List(); + BaseOccurrence baseOccurrence = SelfControler.FindInstance(origID); + if (baseOccurrence != null && flexDesigner.IsOccRegistered(baseOccurrence)) + { + Singleton.Instance.Invoke(NamedEvents.TreeView_BeginUpdate, this, Array.Empty()); + if (_report.Reporter is AggregatedBOMReporter) + { + using (List.Enumerator enumerator3 = flexDesigner.GetOccurrencesWithSameLibID(new GUIDVerClass(baseOccurrence.LibID, baseOccurrence.LibVersion), false).GetEnumerator()) + { + while (enumerator3.MoveNext()) + { + string objID = enumerator3.Current; + list.Add(SelfControler.FindInstance(objID)); + } + } + this.AddToDesignerSelectSet(flexDesigner, list); + Singleton.Instance.Invoke(NamedEvents.TreeView_EndUpdate, this, Array.Empty()); + flexDesigner.FitToSelectSet(); + continue; + } + if (baseOccurrence is OccSurfaceProtectionBase) + { + using (IEnumerator enumerator4 = (baseOccurrence as OccSurfaceProtectionBase).GetParentBundles().GetEnumerator()) + { + while (enumerator4.MoveNext()) + { + IOccBundle occBundle = enumerator4.Current; + list.Add(occBundle as BaseOccurrence); + } + } + this.AddToDesignerSelectSet(flexDesigner, list); + Singleton.Instance.Invoke(NamedEvents.TreeView_EndUpdate, this, Array.Empty()); + flexDesigner.FitToSelectSet(); + continue; + } + //if (_report.Reporter is AccessoryReporter && (baseOccurrence is OccAttachedPart || baseOccurrence is OccAttachedPartEC || baseOccurrence is BaseEncapsulatedOcc)) + //{ + // this.GoToSourceAttachedPart(baseOccurrence); + // Singleton.Instance.Invoke(NamedEvents.TreeView_EndUpdate, this, Array.Empty()); + // break; + //} + list.Add(baseOccurrence); + this.AddToDesignerSelectSet(flexDesigner, list); + Singleton.Instance.Invoke(NamedEvents.TreeView_EndUpdate, this, Array.Empty()); + flexDesigner.FitToSelectSet(); + //flexDesigner. + flexDesigner.SelectSet.OnSelectionChanged(); + } + + } + } + } + } + + } + + + private void AddToDesignerSelectSet(FlexDesigner designerDoc, List occurrences) + { + List list = new List(); + foreach (BaseOccurrence baseOccurrence in occurrences) + { + bool? flag; + if (baseOccurrence == null) + { + flag = null; + } + else + { + FlexBaseOrganizer parentOrganizer = baseOccurrence.GetParentOrganizer(); + flag = ((parentOrganizer != null) ? new bool?(parentOrganizer.IsOccRegistered(baseOccurrence)) : null); + } + if (flag ?? false) + { + baseOccurrence.SetVisibility(true, null); + list.Add(baseOccurrence); + } + } + designerDoc.SelectSet.Add(list); + + //designerDoc. + } + + private void GoToSource_Click(object sender, RoutedEventArgs e) + { + GoToSource(); + } } \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj index 79a639d..1b4a08e 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj @@ -74,9 +74,15 @@ ..\Sinvo.EplanHpD.Plugin\RefDLL\EPLAN.Harness.Core.dll + + ..\Sinvo.EplanHpD.Plugin\RefDLL\EPLAN.Harness.Graphics.dll + ..\Sinvo.EplanHpD.Plugin\RefDLL\EPLAN.Harness.IO.dll + + ..\Sinvo.EplanHpD.Plugin\RefDLL\EPLAN.Harness.PlatformCore.dll + ..\Sinvo.EplanHpD.Plugin\RefDLL\EPLAN.Harness.Primitives.dll diff --git a/Sinvo.EplanHpD.Plugin/PluginEntry.cs b/Sinvo.EplanHpD.Plugin/PluginEntry.cs index 9eec20b..3058b6d 100644 --- a/Sinvo.EplanHpD.Plugin/PluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/PluginEntry.cs @@ -49,9 +49,10 @@ namespace Sinvo.EplanHpD.Plugin public HpDModule Module => HpDModule.Report; - + private MainWindow window; public void Execute(HpdApi api) { + bool isUpdated = false; try { var doc = api.CurrentProject.GetActiveDocument(); @@ -73,15 +74,50 @@ namespace Sinvo.EplanHpD.Plugin "报表数据不是最新的,是否更新?", false) == DialogResult.OK) { flexReport.UpdateReport(); + isUpdated = true; } } // 取可见的列 - var columns = flexReport.Reporter.Formater.RepColumns; - var datas = flexReport.GetAllReportEntries(); - var window = new MainWindow(datas, columns); + //var columns = flexReport.Reporter.Formater.RepColumns; + //var datas = flexReport.GetAllReportEntries(); + //var window = new MainWindow(datas, columns); + try + { + + if (window == null) + { + + window = new MainWindow(flexReport); + ElementHost.EnableModelessKeyboardInterop(window); + window.Show(); + } + else + { + if (isUpdated) + { + window.Close(); + window = new MainWindow(flexReport); + ElementHost.EnableModelessKeyboardInterop(window); + window.Show(); + } + window.ShowActivated = true; + if (window.WindowState == System.Windows.WindowState.Minimized) + { + window.WindowState = System.Windows.WindowState.Normal; + } + window.Show(); + window.Activate(); + } + + } + catch (Exception) + { + window = new MainWindow(flexReport); + ElementHost.EnableModelessKeyboardInterop(window); + window.Show(); + } // 解决WPF窗体在WinForm中无法输入的问题 - ElementHost.EnableModelessKeyboardInterop(window); - window.Show(); + } } else diff --git a/Sinvo.EplanHpD.Plugin/RefDLL/EPLAN.Harness.Graphics.dll b/Sinvo.EplanHpD.Plugin/RefDLL/EPLAN.Harness.Graphics.dll new file mode 100644 index 0000000..15fe32a Binary files /dev/null and b/Sinvo.EplanHpD.Plugin/RefDLL/EPLAN.Harness.Graphics.dll differ diff --git a/Sinvo.EplanHpD.Plugin/RefDLL/EPLAN.Harness.PlatformCore.dll b/Sinvo.EplanHpD.Plugin/RefDLL/EPLAN.Harness.PlatformCore.dll new file mode 100644 index 0000000..3b2c7e4 Binary files /dev/null and b/Sinvo.EplanHpD.Plugin/RefDLL/EPLAN.Harness.PlatformCore.dll differ