diff --git a/.github/workflows/spdx-check.yml b/.github/workflows/spdx-check-sam-ui.yml similarity index 63% rename from .github/workflows/spdx-check.yml rename to .github/workflows/spdx-check-sam-ui.yml index a3925fae..de33f8eb 100644 --- a/.github/workflows/spdx-check.yml +++ b/.github/workflows/spdx-check-sam-ui.yml @@ -1,7 +1,8 @@ -name: SPDX + Copyright header check +name: SPDX + Copyright header check (SAM_UI special case) on: pull_request: + workflow_dispatch: jobs: spdx: @@ -9,9 +10,11 @@ jobs: permissions: contents: read pull-requests: read + steps: - name: Check SPDX + copyright header in changed .cs files env: + EVENT_NAME: ${{ github.event_name }} GH_TOKEN: ${{ github.token }} PR: ${{ github.event.pull_request.number }} REPO: ${{ github.repository }} @@ -20,14 +23,20 @@ jobs: run: | set -euo pipefail + if [ "$EVENT_NAME" != "pull_request" ]; then + echo "Manual run detected." + echo "This workflow checks files changed in a pull request, so there is nothing to do without PR context." + exit 0 + fi + echo "Repo: $REPO" echo "PR: $PR" echo "Head SHA: $HEAD_SHA" - echo "" + echo mapfile -t files < <( gh api "repos/$REPO/pulls/$PR/files" --paginate \ - --jq '.[] | .filename | select(endswith(".cs"))' + --jq '.[] | select(.status != "removed") | .filename | select(endswith(".cs"))' ) if [ "${#files[@]}" -eq 0 ]; then @@ -37,7 +46,7 @@ jobs: echo "C# files changed in PR:" printf ' - %s\n' "${files[@]}" - echo "" + echo spdx_re='SPDX-License-Identifier:[[:space:]]*LGPL-3\.0-or-later' cr_re='Copyright[[:space:]]*\(c\)[[:space:]]*2020[[:space:]]*[-–—][[:space:]]*2026[[:space:]]*Michal[[:space:]]+Dengusiak[[:space:]]*&[[:space:]]*Jakub[[:space:]]+Ziolkowski[[:space:]]+and[[:space:]]+contributors' @@ -47,50 +56,49 @@ jobs: for f in "${files[@]}"; do echo "Checking: $f" - # Skip entire Properties folders (typically generated / designer-managed code) case "$f" in - */Properties/*) - echo " ⏭️ Skipping Properties/*" + */Properties/*|*.xaml.cs) + echo " Skipping Properties/* and *.xaml.cs" continue ;; esac - content_b64=$(gh api "repos/$REPO/contents/$f?ref=$HEAD_SHA" --jq '.content' 2>/dev/null || true) - if [ -z "$content_b64" ]; then - echo " ❌ Could not fetch file content (deleted? submodule? path issue)" + content=$(gh api \ + -H "Accept: application/vnd.github.raw" \ + "repos/$REPO/contents/$f?ref=$HEAD_SHA" 2>/dev/null || true) + + if [ -z "$content" ]; then + echo " Could not fetch file content" missing+=("$f (unreadable)") continue fi - # Decode fully first (avoids SIGPIPE/broken pipe with pipefail), - # normalize CRLF, then take first 80 lines. - decoded=$(printf '%s' "$content_b64" | base64 -d) - headblock=$(printf '%s' "$decoded" | tr -d '\r' | sed -n '1,80p') + headblock=$(printf '%s' "$content" | sed '1s/^\xEF\xBB\xBF//' | tr -d '\r' | sed -n '1,80p') if ! printf '%s' "$headblock" | grep -Eiq "$spdx_re"; then - echo " ❌ Missing SPDX line in first 80 lines" + echo " Missing SPDX line in first 80 lines" missing+=("$f (SPDX)") continue fi if ! printf '%s' "$headblock" | grep -Eiq "$cr_re"; then - echo " ❌ Missing copyright line in first 80 lines" + echo " Missing copyright line in first 80 lines" missing+=("$f (Copyright)") continue fi - echo " ✅ OK" + echo " OK" done - echo "" + echo if [ "${#missing[@]}" -ne 0 ]; then - echo "❌ Missing required header in:" + echo "Missing required header in:" printf ' - %s\n' "${missing[@]}" - echo "" + echo echo "Expected somewhere in first 80 lines:" echo "// SPDX-License-Identifier: LGPL-3.0-or-later" echo "// Copyright (c) 2020-2026 Michal Dengusiak & Jakub Ziolkowski and contributors" exit 1 fi - echo "✅ SPDX + copyright headers OK." + echo "SPDX + copyright headers OK." \ No newline at end of file diff --git a/Application/SAM Analytical/SAM Analytical.csproj b/Application/SAM Analytical/SAM Analytical.csproj index c01f1bcc..66249e6b 100644 --- a/Application/SAM Analytical/SAM Analytical.csproj +++ b/Application/SAM Analytical/SAM Analytical.csproj @@ -156,6 +156,7 @@ 2.27.0 + 5.5.13.4 diff --git a/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Component/SAMAnalyticalMultitaskerWorkflow.cs b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Component/SAMAnalyticalMultitaskerWorkflow.cs new file mode 100644 index 00000000..b45e7b56 --- /dev/null +++ b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Component/SAMAnalyticalMultitaskerWorkflow.cs @@ -0,0 +1,428 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020-2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using Grasshopper.Kernel; +using Grasshopper.Kernel.Types; +using SAM.Analytical.Grasshopper; +using SAM.Analytical.Tas; +using SAM.Core; +using SAM.Core.Grasshopper; +using SAM.Core.Tas; +using SAM.Weather; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Windows.Forms; + +namespace SAM.Analytical.UI.WPF.Grasshopper +{ + public class SAMAnalyticalMultitaskerWorkflow : GH_SAMVariableOutputParameterComponent + { + /// + /// Gets the unique ID for this component. Do not change this ID after release. + /// + public override Guid ComponentGuid => new Guid("f862c3cd-fdfb-469c-828c-b3e5b3e5d174"); + + /// + /// The latest version of this component + /// + public override string LatestComponentVersion => "1.0.4"; + + /// + /// Provides an Icon for the component. + /// + protected override System.Drawing.Bitmap Icon => Properties.Resources.SAM_Small3; + + + public override GH_Exposure Exposure => GH_Exposure.quarternary; + + /// + /// Initializes a new instance of the SAM_point3D class. + /// + public SAMAnalyticalMultitaskerWorkflow() + : base("SAMAnalytical.MultitaskerWorkflow", "SAMAnalytical.MultitaskerWorkflow", + "MultitaskerWorkflow", + "SAM WIP", "Tas") + { + } + + /// + /// Registers all the input parameters for this component. + /// + protected override GH_SAMParam[] Inputs + { + get + { + List result = new List(); + result.Add(new GH_SAMParam(new GooAnalyticalModelParam { Name = "_analyticalModels", NickName = "_analyticalModels", Description = "AnalyticalModels", Access = GH_ParamAccess.list }, ParamVisibility.Binding)); + result.Add(new GH_SAMParam(new global::Grasshopper.Kernel.Parameters.Param_String() { Name = "_directory", NickName = "_directory", Description = "Directory", Access = GH_ParamAccess.item }, ParamVisibility.Binding)); + + result.Add(new GH_SAMParam(new Weather.Grasshopper.GooWeatherDataParam() { Name = "weatherData_", NickName = "weatherData_", Description = "SAM WeatherData", Access = GH_ParamAccess.item, Optional = true }, ParamVisibility.Binding)); + result.Add(new GH_SAMParam(new GooAnalyticalObjectParam() { Name = "coolingDesignDays_", NickName = "coolingDesignDays_", Description = "The SAM Analytical Design Days for Cooling", Access = GH_ParamAccess.list, Optional = true }, ParamVisibility.Voluntary)); + result.Add(new GH_SAMParam(new GooAnalyticalObjectParam() { Name = "heatingDesignDays_", NickName = "heatingDesignDays_", Description = "The SAM Analytical Design Days for Heating", Access = GH_ParamAccess.list, Optional = true }, ParamVisibility.Voluntary)); + + global::Grasshopper.Kernel.Parameters.Param_Boolean @boolean = null; + + boolean = new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "_addIZAMs_", NickName = "_addIZAMs_", Description = "Add IZAMs", Access = GH_ParamAccess.item }; + @boolean.SetPersistentData(true); + result.Add(new GH_SAMParam(boolean, ParamVisibility.Voluntary)); + + boolean = new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "_sizing_", NickName = "_sizing_", Description = "Sizing", Access = GH_ParamAccess.item }; + @boolean.SetPersistentData(true); + result.Add(new GH_SAMParam(boolean, ParamVisibility.Binding)); + + boolean = new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "_simulate_", NickName = "_simulate_", Description = "Simulates the model from 1 to 365 day.", Access = GH_ParamAccess.item }; + @boolean.SetPersistentData(false); + result.Add(new GH_SAMParam(boolean, ParamVisibility.Binding)); + + boolean = new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "_useBEthickness_", NickName = "_useBEthickness_", Description = "If True Building Element thickness will be applied in T3D. Default False.", Access = GH_ParamAccess.item }; + @boolean.SetPersistentData(false); + result.Add(new GH_SAMParam(boolean, ParamVisibility.Voluntary)); + + global::Grasshopper.Kernel.Parameters.Param_GenericObject genericObject = new global::Grasshopper.Kernel.Parameters.Param_GenericObject() { Name = "surfaceOutputSpec_", NickName = "surfaceOutputSpec_", Description = "Surface Output Spec", Access = GH_ParamAccess.list, Optional = true }; + result.Add(new GH_SAMParam(genericObject, ParamVisibility.Voluntary)); + + global::Grasshopper.Kernel.Parameters.Param_Number number = null; + + number = new global::Grasshopper.Kernel.Parameters.Param_Number() { Name = "_tolerance_", NickName = "_tolerance_", Description = "Tolerance", Access = GH_ParamAccess.item }; + number.SetPersistentData(Core.Tolerance.Distance); + result.Add(new GH_SAMParam(number, ParamVisibility.Voluntary)); + + boolean = new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "_runUnmetHours_", NickName = "_runUnmetHours_", Description = "Calculates the amount of hours that the Zone/Space will be outside of the thermostat setpoint (unmet hours).", Access = GH_ParamAccess.item }; + @boolean.SetPersistentData(false); + result.Add(new GH_SAMParam(boolean, ParamVisibility.Voluntary)); + + @boolean = new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "_removeTBD_", NickName = "_removeTBD_", Description = "If True existing TBD file will be deleted before simulation", Access = GH_ParamAccess.item }; + @boolean.SetPersistentData(false); + result.Add(new GH_SAMParam(@boolean, ParamVisibility.Voluntary)); + + @boolean = new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "_parallel_", NickName = "_parallel_", Description = "Parallel.", Optional = true, Access = GH_ParamAccess.item }; + @boolean.SetPersistentData(true); + result.Add(new GH_SAMParam(@boolean, ParamVisibility.Voluntary)); + + global::Grasshopper.Kernel.Parameters.Param_Integer integer = null; + + integer = new global::Grasshopper.Kernel.Parameters.Param_Integer() { Name = "_cPUs_", NickName = "_cPUs_", Description = "Number of logical processors (as shown in Task Manager) used for the calculation.\r\nIf not specified, defaults to maximum available − 1 (leaving one processor free). If only one logical processor is available, it uses 1.", Optional = true, Access = GH_ParamAccess.item }; + result.Add(new GH_SAMParam(integer, ParamVisibility.Voluntary)); + + @boolean = new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "_run", NickName = "_run", Description = "Connect a boolean toggle to run.", Access = GH_ParamAccess.item }; + @boolean.SetPersistentData(false); + result.Add(new GH_SAMParam(@boolean, ParamVisibility.Binding)); + + return result.ToArray(); + } + } + + /// + /// Registers all the output parameters for this component. + /// + protected override GH_SAMParam[] Outputs + { + get + { + List result = []; + result.Add(new GH_SAMParam(new global::Grasshopper.Kernel.Parameters.Param_String() { Name = "CaseDescriptions", NickName = "CaseDescriptions", Description = "CaseDescriptions", Access = GH_ParamAccess.list }, ParamVisibility.Binding)); + result.Add(new GH_SAMParam(new global::Grasshopper.Kernel.Parameters.Param_String() { Name = "Directories", NickName = "Directories", Description = "Directories", Access = GH_ParamAccess.list }, ParamVisibility.Binding)); + result.Add(new GH_SAMParam(new global::Grasshopper.Kernel.Parameters.Param_Boolean() { Name = "successful", NickName = "successful", Description = "successful", Access = GH_ParamAccess.item }, ParamVisibility.Binding)); + return [.. result]; + } + } + + /// + /// This is the method that actually does the work. + /// + /// The DA object is used to retrieve from inputs and store in outputs. + protected override void SolveInstance(IGH_DataAccess dataAccess) + { + int index_successful = Params.IndexOfOutputParam("successful"); + if (index_successful != -1) + { + dataAccess.SetData(index_successful, false); + } + + int index; + + bool run = false; + index = Params.IndexOfInputParam("_run"); + if (index == -1 || !dataAccess.GetData(index, ref run)) + run = false; + + if (!run) + return; + + string directory = null; + index = Params.IndexOfInputParam("_directory"); + if (index == -1 || !dataAccess.GetData(index, ref directory) || string.IsNullOrWhiteSpace(directory)) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); + return; + } + + WeatherData weatherData = null; + index = Params.IndexOfInputParam("weatherData_"); + if (index != -1) + { + if (!dataAccess.GetData(index, ref weatherData)) + { + weatherData = null; + } + } + + if (weatherData != null) + { + weatherData = new WeatherData(weatherData); + } + + List analyticalModels = []; + index = Params.IndexOfInputParam("_analyticalModels"); + if (index == -1 || !dataAccess.GetDataList(index, analyticalModels) || analyticalModels == null) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); + return; + } + + List heatingDesignDays = []; + index = Params.IndexOfInputParam("heatingDesignDays_"); + if (index == -1 || !dataAccess.GetDataList(index, heatingDesignDays) || heatingDesignDays == null || heatingDesignDays.Count == 0) + { + heatingDesignDays = null; + } + + if (heatingDesignDays != null) + { + heatingDesignDays = heatingDesignDays.ConvertAll(x => x.Clone()); + } + + List coolingDesignDays = []; + index = Params.IndexOfInputParam("coolingDesignDays_"); + if (index == -1 || !dataAccess.GetDataList(index, coolingDesignDays) || coolingDesignDays == null || coolingDesignDays.Count == 0) + { + coolingDesignDays = null; + } + + if (coolingDesignDays != null) + { + coolingDesignDays = coolingDesignDays.ConvertAll(x => x.Clone()); + } + + List surfaceOutputSpecs = null; + + List objectWrappers = []; + index = Params.IndexOfInputParam("surfaceOutputSpec_"); + if (index != -1 && dataAccess.GetDataList(index, objectWrappers) && objectWrappers != null && objectWrappers.Count != 0) + { + surfaceOutputSpecs = []; + foreach (GH_ObjectWrapper objectWrapper in objectWrappers) + { + object value = objectWrapper.Value; + if (value is IGH_Goo) + { + value = (value as dynamic)?.Value; + } + + if (value is bool && ((bool)value)) + { + SurfaceOutputSpec surfaceOutputSpec = new("Tas.Simulate"); + surfaceOutputSpec.SolarGain = true; + surfaceOutputSpec.Conduction = true; + surfaceOutputSpec.ApertureData = false; + surfaceOutputSpec.Condensation = false; + surfaceOutputSpec.Convection = false; + surfaceOutputSpec.LongWave = false; + surfaceOutputSpec.Temperature = false; + + surfaceOutputSpecs.Add(surfaceOutputSpec); + } + else if (Core.Query.IsNumeric(value) && Core.Query.TryConvert(value, out double @double) && @double == 2.0) + { + surfaceOutputSpecs = [new("Tas.Simulate")]; + surfaceOutputSpecs[0].SolarGain = true; + surfaceOutputSpecs[0].Conduction = true; + surfaceOutputSpecs[0].ApertureData = true; + surfaceOutputSpecs[0].Condensation = true; + surfaceOutputSpecs[0].Convection = true; + surfaceOutputSpecs[0].LongWave = true; + surfaceOutputSpecs[0].Temperature = true; + } + else if (value is SurfaceOutputSpec) + { + surfaceOutputSpecs.Add((SurfaceOutputSpec)value); + } + } + } + + bool simulate = false; + index = Params.IndexOfInputParam("_simulate_"); + if (index != -1) + { + if (!dataAccess.GetData(index, ref simulate)) + { + simulate = false; + } + } + + bool useBEWidths = false; + index = Params.IndexOfInputParam("_useBEthickness_"); + if (index != -1) + { + if (!dataAccess.GetData(index, ref useBEWidths)) + { + useBEWidths = false; + } + } + + bool sizing = true; + index = Params.IndexOfInputParam("_sizing_"); + if (index != -1) + { + if (!dataAccess.GetData(index, ref sizing)) + { + sizing = true; + } + } + + bool unmetHours = false; + index = Params.IndexOfInputParam("_runUnmetHours_"); + if (index != -1) + if (!dataAccess.GetData(index, ref unmetHours)) + unmetHours = true; + + bool addIZAMs = true; + index = Params.IndexOfInputParam("_addIZAMs_"); + if (index != -1) + { + if (!dataAccess.GetData(index, ref addIZAMs)) + { + addIZAMs = true; + } + } + + bool removeExistingTBD = false; + index = Params.IndexOfInputParam("_removeTBD_"); + if (index != -1) + { + if (!dataAccess.GetData(index, ref removeExistingTBD)) + { + removeExistingTBD = false; + } + } + + WorkflowSettings workflowSettings = new() + { + Path_TBD = null, + Path_gbXML = null, + WeatherData = weatherData, + DesignDays_Heating = heatingDesignDays, + DesignDays_Cooling = coolingDesignDays, + SurfaceOutputSpecs = surfaceOutputSpecs, + UnmetHours = unmetHours, + Simulate = simulate, + Sizing = sizing, + UpdateZones = true, + UseWidths = useBEWidths, + AddIZAMs = addIZAMs, + SimulateFrom = 1, + SimulateTo = 365, + RemoveExistingTBD = removeExistingTBD, + }; + + bool parallel = true; + index = Params.IndexOfInputParam("_parallel_"); + if (index != -1) + { + if (!dataAccess.GetData(index, ref parallel)) + { + parallel = true; + } + } + + int? maxDegreeOfParallelism = null; + index = Params.IndexOfInputParam("_cPUs_"); + if (index != -1) + { + int maxDegreeOfParallelism_Temp = -1; + if (dataAccess.GetData(index, ref maxDegreeOfParallelism_Temp) && maxDegreeOfParallelism_Temp > 0) + { + maxDegreeOfParallelism = maxDegreeOfParallelism_Temp; + } + } + + Dictionary dictionary = Modify.RunWorkflow(analyticalModels, workflowSettings, directory, parallel, maxDegreeOfParallelism); + + if (analyticalModels.Count != dictionary.Count) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Some of the models could not be calculated."); + } + + index = Params.IndexOfOutputParam("CaseDescriptions"); + if (index != -1) + { + dataAccess.SetDataList(index, dictionary?.Keys); + } + + index = Params.IndexOfOutputParam("Directories"); + if (index != -1) + { + dataAccess.SetDataList(index, dictionary?.Keys); + } + + if (index_successful != -1) + { + dataAccess.SetData(index_successful, true); + } + } + + public override void AppendAdditionalMenuItems(ToolStripDropDown menu) + { + base.AppendAdditionalMenuItems(menu); + + Menu_AppendSeparator(menu); + Menu_AppendItem(menu, "Open Directory", Menu_OpenTBD, Properties.Resources.SAM_Small, true, false); + } + + private void Menu_OpenTBD(object sender, EventArgs e) + { + int index_Path = Params.IndexOfInputParam("_directory"); + if (index_Path == -1) + { + return; + } + + string directory = null; + + object @object = null; + + @object = Params.Input[index_Path].VolatileData.AllData(true)?.OfType()?.ElementAt(0); + if (@object is IGH_Goo) + { + directory = (@object as dynamic).Value?.ToString(); + } + + if (string.IsNullOrWhiteSpace(directory) || !System.IO.Directory.Exists(directory)) + { + return; + } + + if (Directory.Exists(directory)) + { + ProcessStartInfo processStartInfo = new ProcessStartInfo() + { + FileName = directory, + UseShellExecute = true, + Verb = "open" + }; + + try + { + Process.Start(processStartInfo); + } + catch + { + + } + } + } + } +} \ No newline at end of file diff --git a/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Properties/Resources.Designer.cs b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Properties/Resources.Designer.cs new file mode 100644 index 00000000..45f0ac46 --- /dev/null +++ b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Properties/Resources.Designer.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SAM.Analytical.UI.WPF.Grasshopper.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SAM.Analytical.UI.WPF.Grasshopper.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + public static System.Drawing.Bitmap SAM_Small { + get { + object obj = ResourceManager.GetObject("SAM_Small", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + public static System.Drawing.Bitmap SAM_Small3 { + get { + object obj = ResourceManager.GetObject("SAM_Small3", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Properties/Resources.resx b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Properties/Resources.resx new file mode 100644 index 00000000..c1d17bfd --- /dev/null +++ b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Properties/Resources.resx @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\SAM_Small.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\SAM_Small3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Resources/SAM_Small.png b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Resources/SAM_Small.png new file mode 100644 index 00000000..67c295cf Binary files /dev/null and b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Resources/SAM_Small.png differ diff --git a/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Resources/SAM_Small3.png b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Resources/SAM_Small3.png new file mode 100644 index 00000000..1b06e915 Binary files /dev/null and b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/Resources/SAM_Small3.png differ diff --git a/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/SAM.Analytical.UI.WPF.Grasshopper.csproj b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/SAM.Analytical.UI.WPF.Grasshopper.csproj new file mode 100644 index 00000000..bdb117bc --- /dev/null +++ b/Grasshopper/SAM.Analytical.UI.WPF.Grasshopper/SAM.Analytical.UI.WPF.Grasshopper.csproj @@ -0,0 +1,107 @@ + + + net8.0-windows + $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\McNeel\Rhinoceros\8.0\Install', 'Path', null, RegistryView.Registry64)) + $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\Software\McNeel\Rhinoceros\8.0-WIP-Developer-Debug-trunk\Install', 'Path', null, RegistryView.Registry64)) + $([MSBuild]::ValueOrDefault('$(RhinoDebugInstallDir)', '$(RhinoDefaultInstallDir)')) + $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\McNeel\Rhinoceros\8.0\Install', 'Default Plug-ins Folder', null, RegistryView.Registry64)) + $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\Software\McNeel\Rhinoceros\8.0-WIP-Developer-Debug-trunk\Install', 'Default Plug-ins Folder', null, RegistryView.Registry64)) + $([MSBuild]::ValueOrDefault('$(RhinoDebugPluginsDir)', '$(RhinoDefaultPluginsDir)')) + false + true + true + false + false + Debug;Release;net48-windows + ..\..\build\ + + + Library + + + C:\Program Files\Rhino 8\System\Rhino.exe + Program + + + + ..\..\..\SAM\build\SAM.Analytical.dll + + + ..\..\..\SAM\build\SAM.Analytical.Grasshopper.dll + + + ..\..\..\SAM_Mollier\build\SAM.Analytical.Mollier.dll + + + ..\..\..\SAM_Tas\build\SAM.Analytical.Tas.dll + + + ..\..\..\SAM\build\SAM.Core.dll + + + ..\..\..\SAM\build\SAM.Core.Grasshopper.dll + + + ..\..\..\SAM_Mollier\build\SAM.Core.Grasshopper.Mollier.dll + + + ..\..\..\SAM_Mollier\build\SAM.Core.Mollier.dll + + + ..\..\..\SAM_Tas\build\SAM.Core.Tas.dll + + + ..\..\..\SAM\build\SAM.Geometry.dll + + + ..\..\..\SAM\build\SAM.Geometry.Grasshopper.dll + + + ..\..\..\SAM_Mollier\build\SAM.Geometry.Grasshopper.Mollier.dll + + + ..\..\..\SAM\build\SAM.Weather.dll + + + ..\..\..\SAM\build\SAM.Weather.Grasshopper.dll + + + + + + + 8.21.25188.17001 + runtime + + + + + 2.6.0 + + + 13.0.3 + + + + + + + + + + + True + True + Resources.resx + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + + + + + \ No newline at end of file diff --git a/Mollier/SAM.Core.Mollier.UI/Create/Solver2DDatas.cs b/Mollier/SAM.Core.Mollier.UI/Create/Solver2DDatas.cs index 93ffd7d6..8183ca63 100644 --- a/Mollier/SAM.Core.Mollier.UI/Create/Solver2DDatas.cs +++ b/Mollier/SAM.Core.Mollier.UI/Create/Solver2DDatas.cs @@ -374,16 +374,20 @@ private static string getCurveUnitText(ConstantValueCurve curve) { return ""; } + + + double value = Core.Query.Round(curve.Value, Tolerance.MicroDistance); + switch (curve.ChartDataType) { case ChartDataType.RelativeHumidity: - return curve.Value.ToString() + "%"; + return value.ToString() + "%"; case ChartDataType.Enthalpy: - return (curve.Value / 1000).ToString(); + return (value / 1000).ToString(); default: - return curve.Value.ToString(); + return value.ToString(); } } diff --git a/Mollier/SAM.Core.Mollier.UI/SAM.Core.Mollier.UI.csproj b/Mollier/SAM.Core.Mollier.UI/SAM.Core.Mollier.UI.csproj index afc3143a..8699e8cb 100644 --- a/Mollier/SAM.Core.Mollier.UI/SAM.Core.Mollier.UI.csproj +++ b/Mollier/SAM.Core.Mollier.UI/SAM.Core.Mollier.UI.csproj @@ -28,26 +28,22 @@ ..\..\..\SAM_Excel\build\SAM.Core.Excel.dll - - False + ..\..\..\SAM_Mollier\build\SAM.Core.Mollier.dll ..\..\..\SAM_Windows\build\SAM.Core.Windows.dll - - False + ..\..\..\SAM\build\SAM.Geometry.dll ..\..\..\SAM_Mollier\build\SAM.Geometry.Mollier.dll - - False + ..\..\..\SAM\build\SAM.Math.dll - - False + ..\..\..\SAM\build\SAM.Units.dll diff --git a/SAM_UI.sln b/SAM_UI.sln index e870f5fb..8b9441d1 100644 --- a/SAM_UI.sln +++ b/SAM_UI.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 18 -VisualStudioVersion = 18.0.11217.181 d18.0 +VisualStudioVersion = 18.0.11217.181 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{7E74E0F2-AB94-4AFF-8456-EB38F1023D86}" EndProject @@ -59,6 +59,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Grasshopper", "Grasshopper", "{7B25F88D-774F-4F59-9938-216526A2B145}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SAM.Analytical.UI.WPF.Grasshopper", "Grasshopper\SAM.Analytical.UI.WPF.Grasshopper\SAM.Analytical.UI.WPF.Grasshopper.csproj", "{D6AF7994-E58C-1B61-94D5-2891BC4EF5F2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -156,6 +160,12 @@ Global {1218DFB7-B5A1-4C7C-B718-43677B18B7A8}.net48-windows|Any CPU.Build.0 = net48-windows|Any CPU {1218DFB7-B5A1-4C7C-B718-43677B18B7A8}.Release|Any CPU.ActiveCfg = Release|Any CPU {1218DFB7-B5A1-4C7C-B718-43677B18B7A8}.Release|Any CPU.Build.0 = Release|Any CPU + {D6AF7994-E58C-1B61-94D5-2891BC4EF5F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6AF7994-E58C-1B61-94D5-2891BC4EF5F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6AF7994-E58C-1B61-94D5-2891BC4EF5F2}.net48-windows|Any CPU.ActiveCfg = net48-windows|Any CPU + {D6AF7994-E58C-1B61-94D5-2891BC4EF5F2}.net48-windows|Any CPU.Build.0 = net48-windows|Any CPU + {D6AF7994-E58C-1B61-94D5-2891BC4EF5F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6AF7994-E58C-1B61-94D5-2891BC4EF5F2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -181,6 +191,8 @@ Global {C5DAFD38-8F0B-4F8F-AB15-85F3D5475613} = {EDBE2559-B4B9-47CB-ACF9-398089AC149D} {5674B031-9EBC-466E-8B5F-C7973B85438C} = {EDBE2559-B4B9-47CB-ACF9-398089AC149D} {DAC5E6E9-AE63-492F-94DE-55A5E093B61C} = {069D87B3-C914-4360-A465-9E2E3E79B1EE} + {7B25F88D-774F-4F59-9938-216526A2B145} = {069D87B3-C914-4360-A465-9E2E3E79B1EE} + {D6AF7994-E58C-1B61-94D5-2891BC4EF5F2} = {7B25F88D-774F-4F59-9938-216526A2B145} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BDA24D60-F69D-4880-BBD8-4F2C110FF3CD} diff --git a/SAM_UI/SAM.Analytical.UI/Convert/ToSAM/GeometryObjectModel.cs b/SAM_UI/SAM.Analytical.UI/Convert/ToSAM/GeometryObjectModel.cs index 7f2e0fe6..06fa1c53 100644 --- a/SAM_UI/SAM.Analytical.UI/Convert/ToSAM/GeometryObjectModel.cs +++ b/SAM_UI/SAM.Analytical.UI/Convert/ToSAM/GeometryObjectModel.cs @@ -1,4 +1,7 @@ -using SAM.Core; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; using SAM.Core.UI; using SAM.Geometry.Object; using SAM.Geometry.Object.Spatial; @@ -37,6 +40,8 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel Legend legend = threeDimensionalViewSettings.Legend; + Legend legend_Temp = legend is null ? null : new Legend(legend); + List planes = threeDimensionalViewSettings.Planes; //Range range = analyticalModel.GetElevationRange(); @@ -54,13 +59,15 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel Dictionary dictionary_Spaces = new Dictionary(); if (showSpaces) { + Legend legend_Spaces = legend_Temp is null ? null : new Legend(legend_Temp); + List spaces = adjacencyCluster.GetSpaces(); if (spaces != null && spaces.Count != 0) { List legendItemDatas = new List(); foreach (Space space in spaces) { - if (Query.TryGetValue(space, adjacencyCluster, threeDimensionalViewSettings, out object value, out string text)) + if (Query.TryGetValue(space, adjacencyCluster, threeDimensionalViewSettings, out object value, out string text, out _)) { legendItemDatas.Add(new LegendItemData(space, value, text)); } @@ -69,15 +76,15 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel bool editable = Query.Editable(threeDimensionalViewSettings); Dictionary dictionary_LegendItem = Query.LegendItemDictionary(legendItemDatas, editable, Query.UndefinedLegendItem()); - if (legend != null) + if (legend_Spaces != null) { if (dictionary_LegendItem != null && dictionary_LegendItem.Count != 0) { - legend.Refresh(dictionary_LegendItem.Values, true, true); + legend_Spaces.Refresh(dictionary_LegendItem.Values, true, true); } else { - legend = null; + legend_Spaces = null; } } @@ -87,9 +94,9 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel if (dictionary_LegendItem.TryGetValue(space.Guid, out LegendItem legendItem) && legendItem != null) { - if (legend != null) + if (legend_Spaces != null) { - legendItem = legend.Find(legendItem?.Text); + legendItem = legend_Spaces.Find(legendItem?.Text); } color = Color.FromRgb(legendItem.Color.R, legendItem.Color.G, legendItem.Color.B); @@ -139,9 +146,9 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel if (!legendUpdated) { - if (legend != null) + if (legend_Spaces != null) { - threeDimensionalViewSettings.Legend = legend; + threeDimensionalViewSettings.Legend = legend_Spaces; legendUpdated = true; } else @@ -164,13 +171,15 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel Dictionary dictionary_Panels = new Dictionary(); if (showPanels) { + Legend legend_Panels = legend_Temp is null ? null : new Legend(legend_Temp); + List panels = adjacencyCluster.GetPanels(); if (panels != null && panels.Count != 0) { List legendItemDatas = new List(); foreach (Panel panel in panels) { - if (Query.TryGetValue(panel, adjacencyCluster, threeDimensionalViewSettings, out object value, out string text)) + if (Query.TryGetValue(panel, adjacencyCluster, threeDimensionalViewSettings, out object value, out string text, out _)) { legendItemDatas.Add(new LegendItemData(panel, value, text)); } @@ -179,15 +188,15 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel bool editable = Query.Editable(threeDimensionalViewSettings); Dictionary dictionary_LegendItem = Query.LegendItemDictionary(legendItemDatas, editable, Query.UndefinedLegendItem()); - if (legend != null) + if (legend_Panels != null) { if (dictionary_LegendItem != null && dictionary_LegendItem.Count != 0) { - legend.Refresh(dictionary_LegendItem.Values, true, true); + legend_Panels.Refresh(dictionary_LegendItem.Values, true, true); } else { - legend = null; + legend_Panels = null; } } @@ -199,9 +208,9 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel if (dictionary_LegendItem.TryGetValue(panel.Guid, out LegendItem legendItem) && legendItem != null) { - if (legend != null) + if (legend_Panels != null) { - legendItem = legend.Find(legendItem?.Text); + legendItem = legend_Panels.Find(legendItem?.Text); } color = Color.FromRgb(legendItem.Color.R, legendItem.Color.G, legendItem.Color.B); @@ -264,9 +273,9 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel if (!legendUpdated) { - if (legend != null) + if (legend_Panels != null) { - threeDimensionalViewSettings.Legend = legend; + threeDimensionalViewSettings.Legend = legend_Panels; legendUpdated = true; } else @@ -290,13 +299,15 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel Dictionary dictionary_Apertures = new Dictionary(); if (showApertures) { + Legend legend_Apertures = legend_Temp is null ? null : new Legend(legend_Temp); + List apertures = adjacencyCluster.GetApertures(); if (apertures != null && apertures.Count != 0) { List legendItemDatas = new List(); foreach (Aperture aperture in apertures) { - if (Query.TryGetValue(aperture, adjacencyCluster, threeDimensionalViewSettings, out object value, out string text)) + if (Query.TryGetValue(aperture, adjacencyCluster, threeDimensionalViewSettings, out object value, out string text, out _)) { legendItemDatas.Add(new LegendItemData(aperture, value, text)); } @@ -305,15 +316,15 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel bool editable = Query.Editable(threeDimensionalViewSettings); Dictionary dictionary_LegendItem = Query.LegendItemDictionary(legendItemDatas, editable, Query.UndefinedLegendItem()); - if (legend != null) + if (legend_Apertures != null) { if (dictionary_LegendItem != null && dictionary_LegendItem.Count != 0) { - legend.Refresh(dictionary_LegendItem.Values, true, true); + legend_Apertures.Refresh(dictionary_LegendItem.Values, true, true); } else { - legend = null; + legend_Apertures = null; } } @@ -325,9 +336,9 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel if (dictionary_LegendItem.TryGetValue(aperture.Guid, out LegendItem legendItem) && legendItem != null) { - if (legend != null) + if (legend_Apertures != null) { - legendItem = legend.Find(legendItem?.Text); + legendItem = legend_Apertures.Find(legendItem?.Text); } color = Color.FromRgb(legendItem.Color.R, legendItem.Color.G, legendItem.Color.B); @@ -392,9 +403,9 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel if (!legendUpdated) { - if (legend != null) + if (legend_Apertures != null) { - threeDimensionalViewSettings.Legend = legend; + threeDimensionalViewSettings.Legend = legend_Apertures; legendUpdated = true; } else @@ -551,7 +562,7 @@ public static GeometryObjectModel ToSAM_GeometryObjectModel(this AnalyticalModel List legendItemDatas = new List(); foreach (Space space in dictionary_Space.Keys) { - if (Query.TryGetValue(space, adjacencyCluster, twoDimensionalViewSettings, out object value, out string text)) + if (Query.TryGetValue(space, adjacencyCluster, twoDimensionalViewSettings, out object value, out string text, out _)) { legendItemDatas.Add(new LegendItemData(space, value, text)); } diff --git a/SAM_UI/SAM.Analytical.UI/Modify/AssignAnalyticalModel.cs b/SAM_UI/SAM.Analytical.UI/Modify/AssignAnalyticalModel.cs new file mode 100644 index 00000000..258403f6 --- /dev/null +++ b/SAM_UI/SAM.Analytical.UI/Modify/AssignAnalyticalModel.cs @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; +using SAM.Core.UI; + +namespace SAM.Analytical.UI +{ + public static partial class Modify + { + public static void AssignAnalyticalModel(this IFilter filter, AnalyticalModel analyticalModel) + { + if (filter == null) + { + return; + } + + if (filter is IUIFilter) + { + AssignAnalyticalModel((filter as dynamic).Filter, analyticalModel); + } + else if (filter is LogicalFilter) + { + ((LogicalFilter)filter).Filters?.ForEach(x => AssignAnalyticalModel(x, analyticalModel)); + } + else if (filter is IAnalyticalModelFilter) + { + ((IAnalyticalModelFilter)filter).AnalyticalModel = analyticalModel; + if(filter is IUIFilter) + { + AssignAnalyticalModel((filter as dynamic).Filter, analyticalModel); + } + } + + AssignAdjacencyCluster(filter, analyticalModel?.AdjacencyCluster); + } + } +} \ No newline at end of file diff --git a/SAM_UI/SAM.Analytical.UI/Modify/Check.cs b/SAM_UI/SAM.Analytical.UI/Modify/Check.cs index 894c9516..1009e0a3 100644 --- a/SAM_UI/SAM.Analytical.UI/Modify/Check.cs +++ b/SAM_UI/SAM.Analytical.UI/Modify/Check.cs @@ -1,4 +1,7 @@ -using System.Windows.Forms; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using System.Windows.Forms; namespace SAM.Analytical.UI { @@ -14,7 +17,7 @@ public static void Check(this UIAnalyticalModel uIAnalyticalModel, IWin32Window Core.Log log = null; - System.Action action = new System.Action(() => + System.Action action = new (() => { log = analyticalModel.Log(); }); @@ -25,7 +28,9 @@ public static void Check(this UIAnalyticalModel uIAnalyticalModel, IWin32Window return; } - using (Core.Windows.Forms.LogForm logForm = new Core.Windows.Forms.LogForm(log)) + log.Sort(); + + using (Core.Windows.Forms.LogForm logForm = new (log)) { if(logForm.ShowDialog(owner) != DialogResult.OK) { diff --git a/SAM_UI/SAM.Analytical.UI/Modify/Hide.cs b/SAM_UI/SAM.Analytical.UI/Modify/Hide.cs index 667e4837..d1ba89be 100644 --- a/SAM_UI/SAM.Analytical.UI/Modify/Hide.cs +++ b/SAM_UI/SAM.Analytical.UI/Modify/Hide.cs @@ -1,4 +1,7 @@ -using SAM.Core; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; using SAM.Geometry.Object; using SAM.Geometry.UI; using System.Collections.Generic; @@ -8,13 +11,21 @@ namespace SAM.Analytical.UI { public static partial class Modify { - public static void Hide(this UIAnalyticalModel uIAnalyticalModel, System.Guid guid, IEnumerable jSAMObjects) + public static void Hide(this UIAnalyticalModel uIAnalyticalModel, System.Guid guid, IEnumerable jSAMObjects, IEnumerable hide = null) { if(jSAMObjects == null || jSAMObjects.Count() == 0) { return; } + if(hide != null) + { + if(jSAMObjects.Count() != hide.Count()) + { + return; + } + } + AnalyticalModel analyticalModel = uIAnalyticalModel?.JSAMObject; if (analyticalModel == null) { @@ -32,7 +43,7 @@ public static void Hide(this UIAnalyticalModel uIAnalyticalModel, System.Guid gu return; } - Hide(viewSettings, jSAMObjects); + Hide(viewSettings, jSAMObjects, hide); uIGeometrySettings.AddViewSettings(viewSettings); @@ -41,16 +52,26 @@ public static void Hide(this UIAnalyticalModel uIAnalyticalModel, System.Guid gu uIAnalyticalModel.SetJSAMObject(analyticalModel, new ViewSettingsModification(viewSettings, true)); } - public static void Hide(this ViewSettings viewSettings, IEnumerable jSAMObjects) + public static void Hide(this ViewSettings viewSettings, IEnumerable jSAMObjects, IEnumerable hide = null) { if (jSAMObjects == null || jSAMObjects.Count() == 0) { return; } - foreach (IJSAMObject jSAMObject in jSAMObjects) + if (hide != null) + { + if (jSAMObjects.Count() != hide.Count()) + { + return; + } + } + + int count = jSAMObjects.Count(); + + for(int i=0; i < count; i++) { - SAMObject sAMObject = jSAMObject as SAMObject; + SAMObject sAMObject = jSAMObjects.ElementAt(i) as SAMObject; if (sAMObject == null) { continue; @@ -68,11 +89,19 @@ public static void Hide(this ViewSettings viewSettings, IEnumerable } } - surfaceAppearances.ForEach(x => x.Visible = false); + bool visible = false; + if(hide != null) + { + visible = hide.ElementAt(i); + } viewSettings.RemoveAppearances(sAMObject.Guid); - viewSettings.SetAppearances(sAMObject.Guid, surfaceAppearances); + if (!visible) + { + surfaceAppearances.ForEach(x => x.Visible = visible); + viewSettings.SetAppearances(sAMObject.Guid, surfaceAppearances); + } } } } diff --git a/SAM_UI/SAM.Analytical.UI/Modify/Isolate.cs b/SAM_UI/SAM.Analytical.UI/Modify/Isolate.cs new file mode 100644 index 00000000..e5c0052e --- /dev/null +++ b/SAM_UI/SAM.Analytical.UI/Modify/Isolate.cs @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; +using SAM.Geometry.Object; +using SAM.Geometry.UI; +using System.Collections.Generic; +using System.Linq; + +namespace SAM.Analytical.UI +{ + public static partial class Modify + { + public static void Isolate(this UIAnalyticalModel uIAnalyticalModel, System.Guid guid, IEnumerable jSAMObjects) + { + if(jSAMObjects == null || jSAMObjects.Count() == 0) + { + return; + } + + AnalyticalModel analyticalModel = uIAnalyticalModel?.JSAMObject; + if (analyticalModel == null) + { + return; + } + + AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster; + if(adjacencyCluster == null) + { + return; + } + + + if (!analyticalModel.TryGetValue(AnalyticalModelParameter.UIGeometrySettings, out UIGeometrySettings uIGeometrySettings) || uIGeometrySettings == null) + { + return; + } + + ViewSettings viewSettings = uIGeometrySettings.GetViewSettings(guid) as ViewSettings; + if(viewSettings == null) + { + return; + } + + Isolate(viewSettings, adjacencyCluster, jSAMObjects); + + uIGeometrySettings.AddViewSettings(viewSettings); + + analyticalModel.SetValue(AnalyticalModelParameter.UIGeometrySettings, uIGeometrySettings); + + uIAnalyticalModel.SetJSAMObject(analyticalModel, new ViewSettingsModification(viewSettings, true)); + } + + public static void Isolate(this ViewSettings viewSettings, AdjacencyCluster adjacencyCluster, IEnumerable jSAMObjects) + { + if (adjacencyCluster == null || jSAMObjects == null || jSAMObjects.Count() == 0) + { + return; + } + + List sAMObjects = []; + + if(adjacencyCluster.GetObjects() is List panels) + { + foreach(Panel panel in panels) + { + sAMObjects.Add(panel); + + List apertures = panel.Apertures; + if(apertures != null) + { + foreach(Aperture aperture in apertures) + { + sAMObjects.Add(aperture); + } + } + } + } + + adjacencyCluster.GetObjects()?.ForEach(sAMObjects.Add); + + sAMObjects.RemoveAll(x => x == null); + + + HashSet guids = []; + foreach(IJSAMObject jSAMObject in jSAMObjects) + { + if(jSAMObject is not SAMObject sAMObject) + { + continue; + } + + System.Guid guid = sAMObject.Guid; + + guids.Add(guid); + + int index = sAMObjects.FindIndex(x => x.Guid == guid); + if(index == -1) + { + sAMObjects.Add(sAMObject); + } + } + + foreach (SAMObject sAMObject in sAMObjects) + { + List surfaceAppearances = viewSettings.GetAppearances(sAMObject.Guid); + + bool visible = guids.Contains(sAMObject.Guid); + if(visible && (surfaceAppearances == null || surfaceAppearances.Count == 0)) + { + continue; + } + + if (surfaceAppearances == null) + { + SurfaceAppearance surfaceAppearance = new SurfaceAppearance(System.Drawing.Color.FromArgb(0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0), 0); + + surfaceAppearances = new List() { surfaceAppearance }; + if (sAMObject is Aperture) + { + surfaceAppearances.Add(surfaceAppearance.Clone()); + } + } + + surfaceAppearances?.ForEach(x => x.Visible = visible); + + viewSettings.RemoveAppearances(sAMObject.Guid); + + viewSettings.SetAppearances(sAMObject.Guid, surfaceAppearances); + } + + + } + } +} \ No newline at end of file diff --git a/SAM_UI/SAM.Analytical.UI/Modify/ReplaceNameSpecialCharacters.cs b/SAM_UI/SAM.Analytical.UI/Modify/ReplaceNameSpecialCharacters.cs new file mode 100644 index 00000000..6b5a91d9 --- /dev/null +++ b/SAM_UI/SAM.Analytical.UI/Modify/ReplaceNameSpecialCharacters.cs @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; +using SAM.Core.Windows.Forms; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace SAM.Analytical.UI +{ + public static partial class Modify + { + public static void ReplaceNameSpecialCharacters(this UIAnalyticalModel uIAnalyticalModel, IWin32Window owner = null) + { + AnalyticalModel analyticalModel = uIAnalyticalModel?.JSAMObject; + if (analyticalModel == null) + { + return; + } + + AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster; + + List names = ActiveManager.GetSpecialCharacterMapNames(); + if (names == null || names.Count == 0) + { + return; + } + + string name = null; + + using (ComboBoxForm comboBoxForm = new ("Select language", names)) + { + comboBoxForm.SelectedItem = names.Find(x => x == "ISO"); + + if(comboBoxForm.ShowDialog(owner) != DialogResult.OK) + { + return; + } + + name = comboBoxForm.SelectedItem; + } + + if(string.IsNullOrWhiteSpace(name)) + { + return; + } + + adjacencyCluster.ReplaceNameSpecialCharacters(name); + + analyticalModel = new AnalyticalModel(analyticalModel, adjacencyCluster); + + uIAnalyticalModel.JSAMObject = analyticalModel; + } + } +} \ No newline at end of file diff --git a/SAM_UI/SAM.Analytical.UI/Query/IJSAMObjects.cs b/SAM_UI/SAM.Analytical.UI/Query/IJSAMObjects.cs index 4dccd0f4..cbf17a79 100644 --- a/SAM_UI/SAM.Analytical.UI/Query/IJSAMObjects.cs +++ b/SAM_UI/SAM.Analytical.UI/Query/IJSAMObjects.cs @@ -42,7 +42,7 @@ public static List IJSAMObjects(this FilterSelection f filter = uIFilter.Transform(); } - Modify.AssignAdjacencyCluster(filter, adjacencyCluster); + Modify.AssignAnalyticalModel(filter, analyticalModel); return adjacencyCluster.Filter(filter, null); } diff --git a/SAM_UI/SAM.Analytical.UI/Query/IUIFilters.cs b/SAM_UI/SAM.Analytical.UI/Query/IUIFilters.cs index 1ad7bb8c..ef96b2d3 100644 --- a/SAM_UI/SAM.Analytical.UI/Query/IUIFilters.cs +++ b/SAM_UI/SAM.Analytical.UI/Query/IUIFilters.cs @@ -1,4 +1,7 @@ -using SAM.Core; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; using SAM.Core.UI; using System.Collections.Generic; @@ -45,6 +48,12 @@ public static List IUIFilters(this System.Type type, AdjacencyCluster result.Add(new UINumberFilter(string.Format("{0} Area", type.Name), type, new PanelAreaFilter(NumberComparisonType.Equals, 0))); result.Add(new UINumberFilter(string.Format("{0} Min Elevation", type.Name), type, new PanelMinElevationFilter(NumberComparisonType.Equals, 0))); result.Add(new UINumberFilter(string.Format("{0} Max Elevation", type.Name), type, new PanelMaxElevationFilter(NumberComparisonType.Equals, 0))); + result.Add(new UIBooleanFilter(string.Format("{0} Adiabatic", type.Name), type, new PanelAdiabaticFilter(true))); + result.Add(new UIBooleanFilter(string.Format("{0} Has Apertures", type.Name), type, new PanelHasAperturesFilter(true))); + result.Add(new UIBooleanFilter(string.Format("{0} Has Exposed To Sun", type.Name), type, new PanelExposedToSunFilter(true))); + result.Add(new UIBooleanFilter(string.Format("{0} External", type.Name), type, new PanelExternalFilter(true))); + result.Add(new UIBooleanFilter(string.Format("{0} Is Ground", type.Name), type, new PanelGroundFilter(true))); + result.Add(new UIBooleanFilter(string.Format("{0} Transparent", type.Name), type, new PanelTransparentFilter(true))); result.Add(new UINumberFilter(string.Format("Aperture Count", type.Name), type, new PanelApertureCountFilter(NumberComparisonType.Greater, 0))); IUIFilters(typeof(Aperture), adjacencyCluster)?.ForEach(x => result.Add(new UIRelationFilter(x.Name, x.Type, new PanelAperturesFilter(x)))); diff --git a/SAM_UI/SAM.Analytical.UI/Query/IsHidden.cs b/SAM_UI/SAM.Analytical.UI/Query/IsHidden.cs new file mode 100644 index 00000000..943b7c4b --- /dev/null +++ b/SAM_UI/SAM.Analytical.UI/Query/IsHidden.cs @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; +using SAM.Geometry.Object; +using SAM.Geometry.UI; +using System.Collections.Generic; +using System.Linq; + +namespace SAM.Analytical.UI +{ + public static partial class Query + { + public static List IsHidden(this UIAnalyticalModel uIAnalyticalModel, System.Guid guid, IEnumerable jSAMObjects) + { + if(jSAMObjects == null || !jSAMObjects.Any()) + { + return null; + } + + AnalyticalModel analyticalModel = uIAnalyticalModel?.JSAMObject; + if (analyticalModel == null) + { + return null; + } + + if (!analyticalModel.TryGetValue(AnalyticalModelParameter.UIGeometrySettings, out UIGeometrySettings uIGeometrySettings) || uIGeometrySettings == null) + { + return null; + } + + ViewSettings viewSettings = uIGeometrySettings.GetViewSettings(guid) as ViewSettings; + if(viewSettings == null) + { + return null; + } + + int count = jSAMObjects.Count(); + + List result = [.. Enumerable.Repeat(false, count)]; + + for (int i = 0; i < count; i++) + { + result[i] = IsHidden(viewSettings, jSAMObjects.ElementAt(i)); + } + + return result; + } + + public static bool IsHidden(this ViewSettings viewSettings, IJSAMObject jSAMObject) + { + if (jSAMObject is null || viewSettings is null) + { + return false; + } + + SAMObject sAMObject = jSAMObject as SAMObject; + if (sAMObject == null) + { + return false; + } + + List surfaceAppearances = viewSettings.GetAppearances(sAMObject.Guid); + if (surfaceAppearances == null) + { + SurfaceAppearance surfaceAppearance = new SurfaceAppearance(System.Drawing.Color.FromArgb(0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0), 0); + + surfaceAppearances = new List() { surfaceAppearance }; + if (sAMObject is Aperture) + { + surfaceAppearances.Add(surfaceAppearance.Clone()); + } + } + + return surfaceAppearances.Find(x => x.Visible) != null; + } + } +} \ No newline at end of file diff --git a/SAM_UI/SAM.Analytical.UI/Query/LegendItemDictionary.cs b/SAM_UI/SAM.Analytical.UI/Query/LegendItemDictionary.cs index 5d5188de..3255d211 100644 --- a/SAM_UI/SAM.Analytical.UI/Query/LegendItemDictionary.cs +++ b/SAM_UI/SAM.Analytical.UI/Query/LegendItemDictionary.cs @@ -1,4 +1,8 @@ -using SAM.Core.UI; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; +using SAM.Core.UI; using System; using System.Collections.Generic; using System.Drawing; @@ -15,13 +19,13 @@ public static Dictionary LegendItemDictionary(this IEnumerable return null; } - Dictionary dictionary_Values = new Dictionary(); + Dictionary dictionary_Values = []; - Dictionary dictionary_Doubles = new Dictionary(); + Dictionary dictionary_Doubles = []; //HashSet strings = new HashSet(); - Dictionary> dictionary_Strings = new Dictionary>(); + Dictionary> dictionary_Strings = []; Dictionary result = new Dictionary(); foreach (LegendItemData legendItemData in legendItemDatas) @@ -39,7 +43,7 @@ public static Dictionary LegendItemDictionary(this IEnumerable string value = Core.Query.Description((Enum)@object); if(!dictionary_Strings.TryGetValue(value, out List legendItemDatas_Temp)) { - legendItemDatas_Temp = new List(); + legendItemDatas_Temp = []; dictionary_Strings[value] = legendItemDatas_Temp; } legendItemDatas_Temp.Add(legendItemData); @@ -47,15 +51,15 @@ public static Dictionary LegendItemDictionary(this IEnumerable else if (Core.Query.IsNumeric(@object)) { double value = System.Convert.ToDouble(@object); - dictionary_Doubles[value] = Core.Query.Round(value, Core.Tolerance.MacroDistance).ToString(); - dictionary_Values[legendItemData] = value; + dictionary_Doubles[value] = Core.Query.Round(value, Tolerance.MacroDistance).ToString(); + dictionary_Values[legendItemData] = Core.Query.Round(value, Tolerance.MicroDistance); } else if (@object is string) { string value = (string)@object; if (!dictionary_Strings.TryGetValue(value, out List legendItemDatas_Temp)) { - legendItemDatas_Temp = new List(); + legendItemDatas_Temp = []; dictionary_Strings[value] = legendItemDatas_Temp; } legendItemDatas_Temp.Add(legendItemData); @@ -69,7 +73,7 @@ public static Dictionary LegendItemDictionary(this IEnumerable string value = @object?.ToString(); if (!dictionary_Strings.TryGetValue(value, out List legendItemDatas_Temp)) { - legendItemDatas_Temp = new List(); + legendItemDatas_Temp = []; dictionary_Strings[value] = legendItemDatas_Temp; } legendItemDatas_Temp.Add(legendItemData); @@ -81,7 +85,7 @@ public static Dictionary LegendItemDictionary(this IEnumerable double max = double.MaxValue; if (dictionary_Doubles != null && dictionary_Doubles.Count != 0) { - List doubles = new List(dictionary_Doubles.Keys); + List doubles = [.. dictionary_Doubles.Keys]; max = doubles.Max(); min = doubles.Min(); @@ -148,17 +152,68 @@ public static Dictionary LegendItemDictionary(this IEnumerable } } - Random random = new Random(); + //Random random = new Random(); if (dictionary_Strings != null && dictionary_Strings.Count != 0) { + List>> tuples_Strings_Unassigned = []; foreach (KeyValuePair> keyValuePair in dictionary_Strings) { - Color color = System.Drawing.Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + Color color = System.Drawing.Color.Empty; //Core.Create.Color(keyValuePair.Key); //System.Drawing.Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + if(keyValuePair.Value != null && keyValuePair.Value.Count != 0) + { + if (keyValuePair.Value.TrueForAll(x => x.Value is PanelType) && keyValuePair.Value.TrueForAll(x => (PanelType)x.Value == (PanelType)keyValuePair.Value[0].Value)) + { + color = Analytical.Query.Color((PanelType)keyValuePair.Value[0].Value); + } + else if (keyValuePair.Value.TrueForAll(x => x.Value is BoundaryType) && keyValuePair.Value.TrueForAll(x => (BoundaryType)x.Value == (BoundaryType)keyValuePair.Value[0].Value)) + { + color = Analytical.Query.Color((BoundaryType)keyValuePair.Value[0].Value); + } + else if (keyValuePair.Value.TrueForAll(x => x.Value is ApertureType) && keyValuePair.Value.TrueForAll(x => (ApertureType)x.Value == (ApertureType)keyValuePair.Value[0].Value)) + { + color = Analytical.Query.Color(((ApertureType)keyValuePair.Value[0].Value)); + } + } + + if(color == System.Drawing.Color.Empty) + { + tuples_Strings_Unassigned.Add(new Tuple>(keyValuePair.Key, keyValuePair.Value)); + continue; + } + foreach (LegendItemData legendItemData in keyValuePair.Value) { result[legendItemData.Guid] = new LegendItem(color, keyValuePair.Key); } } + + List colors = ColorPaletteGenerator.GetColors(PaletteDefinitions.SamSpacesSoft, tuples_Strings_Unassigned.ConvertAll(x => x.Item1)); + if(colors is null || colors.Count == 0) + { + foreach(Tuple> tuple in tuples_Strings_Unassigned) + { + Color color = Core.Create.Color(tuple.Item1); + + foreach (LegendItemData legendItemData in tuple.Item2) + { + result[legendItemData.Guid] = new LegendItem(color, tuple.Item1); + } + } + } + else + { + for (int i = 0; i < tuples_Strings_Unassigned.Count; i++) + { + Tuple> tuple = tuples_Strings_Unassigned[i]; + + Color color = i < colors.Count ? colors[i] : Core.Create.Color(tuple.Item1); + + foreach (LegendItemData legendItemData in tuple.Item2) + { + result[legendItemData.Guid] = new LegendItem(color, tuple.Item1); + } + } + } } if (undefinedLegendItem != null) diff --git a/SAM_UI/SAM.Analytical.UI/Query/Simulate.cs b/SAM_UI/SAM.Analytical.UI/Query/Simulate.cs deleted file mode 100644 index d911c966..00000000 --- a/SAM_UI/SAM.Analytical.UI/Query/Simulate.cs +++ /dev/null @@ -1,218 +0,0 @@ -using SAM.Analytical.Tas; -using SAM.Core.Tas; -using SAM.Weather; -using System; -using System.Collections.Generic; -using System.Windows.Forms; - -namespace SAM.Analytical.UI -{ - public static partial class Query - { - public static AnalyticalModel Simulate(this AnalyticalModel analyticalModel, string path, IWin32Window owner = null) - { - if(analyticalModel == null) - { - return null; - } - - if(string.IsNullOrWhiteSpace(path)) - { - return null; - } - - if(!analyticalModel.TryGetValue(Analytical.AnalyticalModelParameter.WeatherData, out WeatherData weatherData)) - { - weatherData = null; - } - - string projectName = null; - string outputDirectory = null; - bool unmetHours = false; - bool printRoomDataSheets = false; - - bool fullYearSimulation = false; - int fullYearSimulation_From = -1; - int fullYearSimulation_To = -1; - bool sizing = true; - - SolarCalculationMethod solarCalculationMethod = SolarCalculationMethod.None; - bool updateConstructionLayersByPanelType = false; - - using (Forms.SimulateForm simulateForm = new Forms.SimulateForm(System.IO.Path.GetFileNameWithoutExtension(path), System.IO.Path.GetDirectoryName(path))) - { - simulateForm.WeatherData = weatherData; - if (simulateForm.ShowDialog(owner) != DialogResult.OK) - { - return null; - } - - projectName = simulateForm.ProjectName; - outputDirectory = simulateForm.OutputDirectory; - unmetHours = simulateForm.UnmetHours; - sizing = simulateForm.Sizing; - weatherData = simulateForm.WeatherData; - solarCalculationMethod = simulateForm.SolarCalculationMethod; - updateConstructionLayersByPanelType = simulateForm.UpdateConstructionLayersByPanelType; - printRoomDataSheets = simulateForm.PrintRoomDataSheets; - fullYearSimulation = simulateForm.FullYearSimulation; - if(fullYearSimulation) - { - fullYearSimulation_From = simulateForm.FullYearSimulation_From; - fullYearSimulation_To = simulateForm.FullYearSimulation_To; - } - } - - if (weatherData == null) - { - return null; - } - - string path_TBD = System.IO.Path.Combine(outputDirectory, projectName + ".tbd"); - - bool shadingUpdated = false; - - using (Core.Windows.Forms.ProgressForm progressForm = new Core.Windows.Forms.ProgressForm("Preparing Model", 8)) - { - progressForm.Update("Update Materials"); - - IEnumerable materials = Analytical.Query.Materials(analyticalModel.AdjacencyCluster, Analytical.Query.DefaultMaterialLibrary()); - if (materials != null) - { - foreach (Core.IMaterial material in materials) - { - if (analyticalModel.HasMaterial(material)) - { - continue; - } - - analyticalModel.AddMaterial(material); - } - } - - progressForm.Update("Update ConstructionLayers By PanelTypes"); - - analyticalModel = updateConstructionLayersByPanelType ? analyticalModel.UpdateConstructionLayersByPanelType() : analyticalModel; - - if (System.IO.File.Exists(path_TBD)) - { - System.IO.File.Delete(path_TBD); - } - - List hoursOfYear = Analytical.Query.DefaultHoursOfYear(); - - progressForm.Update("Solar Calculations"); - if (solarCalculationMethod != SolarCalculationMethod.None) - { - SolarCalculator.Modify.Simulate(analyticalModel, hoursOfYear.ConvertAll(x => new DateTime(2018, 1, 1).AddHours(x)), false, Core.Tolerance.MacroDistance, Core.Tolerance.MacroDistance, 0.012, Core.Tolerance.Distance); - } - - using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD)) - { - TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument; - - progressForm.Update("Updating WeatherData"); - Weather.Tas.Modify.UpdateWeatherData(tBDDocument, weatherData, analyticalModel == null ? 0 : analyticalModel.AdjacencyCluster.BuildingHeight()); - - TBD.Calendar calendar = tBDDocument.Building.GetCalendar(); - - List dayTypes = DayTypes(calendar); - if (dayTypes.Find(x => x.name == "HDD") == null) - { - TBD.dayType dayType = calendar.AddDayType(); - dayType.name = "HDD"; - } - - if (dayTypes.Find(x => x.name == "CDD") == null) - { - TBD.dayType dayType = calendar.AddDayType(); - dayType.name = "CDD"; - } - - progressForm.Update("Converting to TBD"); - Tas.Convert.ToTBD(analyticalModel, tBDDocument, true); - - progressForm.Update("Updating Zones"); - Tas.Modify.UpdateZones(tBDDocument.Building, analyticalModel, true); - - progressForm.Update("Updating Shading"); - shadingUpdated = Tas.Modify.UpdateShading(tBDDocument, analyticalModel); - - sAMTBDDocument.Save(); - } - - progressForm.Update("Printing Room Data Sheets"); - if (printRoomDataSheets && analyticalModel != null) - { - if (!System.IO.Directory.Exists(outputDirectory)) - { - System.IO.Directory.CreateDirectory(outputDirectory); - } - - Modify.PrintRoomDataSheets(analyticalModel, outputDirectory); - } - } - - List heatingDesignDays = new List() { Analytical.Query.HeatingDesignDay(weatherData) }; - List coolingDesignDays = new List() { Analytical.Query.CoolingDesignDay(weatherData) }; - - SurfaceOutputSpec surfaceOutputSpec = new SurfaceOutputSpec("Tas.Simulate") - { - SolarGain = true, - Conduction = true, - ApertureData = false, - Condensation = false, - Convection = false, - LongWave = false, - Temperature = false - }; - - List surfaceOutputSpecs = new List() { surfaceOutputSpec }; - - int simulate_From = -1; - int simulate_To = -1; - - bool simulate = fullYearSimulation; - - if (simulate) - { - simulate_From = fullYearSimulation_From; - simulate_To = fullYearSimulation_To; - } - - if (shadingUpdated) - { - if (!simulate) - { - simulate_From = 1; - simulate_To = 1; - simulate = true; - } - } - - WorkflowSettings workflowSettings = new WorkflowSettings() - { - Path_TBD = path_TBD, - Path_gbXML = null, - WeatherData = null, - DesignDays_Heating = heatingDesignDays, - DesignDays_Cooling = coolingDesignDays, - SurfaceOutputSpecs = surfaceOutputSpecs, - UnmetHours = unmetHours, - Simulate = simulate, - Sizing = sizing, - UpdateZones = false, - UseWidths = false, - SimulateFrom = simulate_From, - SimulateTo = simulate_To - }; - - analyticalModel = Tas.Modify.RunWorkflow(analyticalModel, workflowSettings); - - analyticalModel.SetValue(Analytical.AnalyticalModelParameter.WeatherData, weatherData); - - return analyticalModel; - - } - } -} \ No newline at end of file diff --git a/SAM_UI/SAM.Analytical.UI/Query/TryGetValue.cs b/SAM_UI/SAM.Analytical.UI/Query/TryGetValue.cs index 6f78ace5..556d67b7 100644 --- a/SAM_UI/SAM.Analytical.UI/Query/TryGetValue.cs +++ b/SAM_UI/SAM.Analytical.UI/Query/TryGetValue.cs @@ -1,4 +1,7 @@ -using SAM.Core; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; using SAM.Core.UI; using SAM.Geometry.UI; using System.Collections.Generic; @@ -8,10 +11,11 @@ namespace SAM.Analytical.UI { public static partial class Query { - public static bool TryGetValue(this Space space, AdjacencyCluster adjacencyCluster, ViewSettings viewSettings, out object value, out string text) + public static bool TryGetValue(this Space space, AdjacencyCluster adjacencyCluster, ViewSettings viewSettings, out object value, out string text, out string parameterName) { value = null; text = null; + parameterName = null; if(space == null) { @@ -19,6 +23,14 @@ public static bool TryGetValue(this Space space, AdjacencyCluster adjacencyClust } SpaceAppearanceSettings spaceAppearanceSettings = viewSettings?.GetValueAppearanceSettings()?.FirstOrDefault(); + if (spaceAppearanceSettings != null) + { + if (spaceAppearanceSettings.GetValueAppearanceSettings() is ParameterAppearanceSettings parameterAppearanceSettings) + { + parameterName = parameterAppearanceSettings.ParameterName; + } + } + if (spaceAppearanceSettings != null) { IAppearanceSettings appearanceSettings = spaceAppearanceSettings.GetValueAppearanceSettings(); @@ -26,9 +38,11 @@ public static bool TryGetValue(this Space space, AdjacencyCluster adjacencyClust { ParameterAppearanceSettings parameterAppearanceSettings = (ParameterAppearanceSettings)appearanceSettings; - if (Core.Query.TryGetValue(space, parameterAppearanceSettings.ParameterName, out value)) + parameterName = parameterAppearanceSettings.ParameterName; + + if (Core.Query.TryGetValue(space, parameterName, out value)) { - if (parameterAppearanceSettings.ParameterName == "Color") + if (parameterName == "Color") { text = space.Name; } @@ -42,7 +56,7 @@ public static bool TryGetValue(this Space space, AdjacencyCluster adjacencyClust } else if (appearanceSettings is ITypeAppearanceSettings) { - string parameterName = ((ITypeAppearanceSettings)appearanceSettings).GetValueAppearanceSettings()?.ParameterName; + parameterName = ((ITypeAppearanceSettings)appearanceSettings).GetValueAppearanceSettings()?.ParameterName; if (appearanceSettings is InternalConditionAppearanceSettings) { @@ -197,6 +211,11 @@ public static bool TryGetValue(this Space space, AdjacencyCluster adjacencyClust } else if (appearanceSettings is ComplexReferenceAppearanceSettings) { + if(appearanceSettings is ParameterAppearanceSettings parameterAppearanceSettings) + { + parameterName = parameterAppearanceSettings.ParameterName; + } + ComplexReferenceAppearanceSettings complexReferenceAppearanceSettings = (ComplexReferenceAppearanceSettings)appearanceSettings; complexReferenceAppearanceSettings.RelationCluster = new RelationCluster(adjacencyCluster); @@ -221,37 +240,60 @@ public static bool TryGetValue(this Space space, AdjacencyCluster adjacencyClust } - public static bool TryGetValue(this Panel panel, AdjacencyCluster adjacencyCluster, ViewSettings viewSettings, out object value, out string text) + public static bool TryGetValue(this Panel panel, AdjacencyCluster adjacencyCluster, ViewSettings viewSettings, out object value, out string text, out string parameterName) { value = null; text = null; + parameterName = null; if (panel == null) { return false; } + PanelAppearanceSettings panelAppearanceSettings = viewSettings?.GetValueAppearanceSettings()?.FirstOrDefault(); + if (panelAppearanceSettings != null) + { + if(panelAppearanceSettings.GetValueAppearanceSettings() is ParameterAppearanceSettings parameterAppearanceSettings) + { + parameterName = parameterAppearanceSettings.ParameterName; + } + } + ValueAppearanceSettings valueAppearanceSettings = viewSettings?.GetValueAppearanceSettings(panel)?.FirstOrDefault(); if(valueAppearanceSettings != null) { if (valueAppearanceSettings.TryGetValue(panel, out object value_Temp)) { - value = value_Temp; - text = value_Temp?.ToString(); + + if (Core.Query.IsNumeric(value_Temp)) + { + double @double = System.Convert.ToDouble(value_Temp); + value = Core.Query.Round(@double, Tolerance.MacroDistance); + text = Core.Query.Round(@double, Tolerance.MicroDistance).ToString(); + } + else + { + value = value_Temp; + text = value_Temp?.ToString(); + } + return true; } } - PanelAppearanceSettings panelAppearanceSettings = viewSettings?.GetValueAppearanceSettings()?.FirstOrDefault(); if (panelAppearanceSettings != null) { IAppearanceSettings appearanceSettings = panelAppearanceSettings.GetValueAppearanceSettings(); if (appearanceSettings is ParameterAppearanceSettings) { ParameterAppearanceSettings parameterAppearanceSettings = (ParameterAppearanceSettings)appearanceSettings; - if (Core.Query.TryGetValue(panel, parameterAppearanceSettings.ParameterName, out value)) + + parameterName = parameterAppearanceSettings.ParameterName; + + if (Core.Query.TryGetValue(panel, parameterName, out value)) { - if (parameterAppearanceSettings.ParameterName == "Color") + if (parameterName == "Color") { text = panel.Name; } @@ -265,7 +307,7 @@ public static bool TryGetValue(this Panel panel, AdjacencyCluster adjacencyClust } else if (appearanceSettings is ITypeAppearanceSettings) { - string parameterName = ((ITypeAppearanceSettings)appearanceSettings).GetValueAppearanceSettings()?.ParameterName; + parameterName = ((ITypeAppearanceSettings)appearanceSettings).GetValueAppearanceSettings()?.ParameterName; if (appearanceSettings is ConstructionAppearanceSettings) { @@ -320,10 +362,11 @@ public static bool TryGetValue(this Panel panel, AdjacencyCluster adjacencyClust } - public static bool TryGetValue(this Aperture aperture, AdjacencyCluster adjacencyCluster, ViewSettings viewSettings, out object value, out string text) + public static bool TryGetValue(this Aperture aperture, AdjacencyCluster adjacencyCluster, ViewSettings viewSettings, out object value, out string text, out string parameterName) { value = null; text = null; + parameterName = null; if (aperture == null) { @@ -331,15 +374,26 @@ public static bool TryGetValue(this Aperture aperture, AdjacencyCluster adjacenc } ApertureAppearanceSettings apertureAppearanceSettings = viewSettings?.GetValueAppearanceSettings()?.FirstOrDefault(); + if (apertureAppearanceSettings != null) + { + if (apertureAppearanceSettings.GetValueAppearanceSettings() is ParameterAppearanceSettings parameterAppearanceSettings) + { + parameterName = parameterAppearanceSettings.ParameterName; + } + } + if (apertureAppearanceSettings != null) { IAppearanceSettings appearanceSettings = apertureAppearanceSettings.GetValueAppearanceSettings(); if (appearanceSettings is ParameterAppearanceSettings) { ParameterAppearanceSettings parameterAppearanceSettings = (ParameterAppearanceSettings)appearanceSettings; - if (Core.Query.TryGetValue(aperture, parameterAppearanceSettings.ParameterName, out value)) + + parameterName = parameterAppearanceSettings.ParameterName; + + if (Core.Query.TryGetValue(aperture, parameterName, out value)) { - if (parameterAppearanceSettings.ParameterName == "Color") + if (parameterName == "Color") { text = aperture.Name; } @@ -353,7 +407,7 @@ public static bool TryGetValue(this Aperture aperture, AdjacencyCluster adjacenc } else if (appearanceSettings is ITypeAppearanceSettings) { - string parameterName = ((ITypeAppearanceSettings)appearanceSettings).GetValueAppearanceSettings()?.ParameterName; + parameterName = ((ITypeAppearanceSettings)appearanceSettings).GetValueAppearanceSettings()?.ParameterName; if (appearanceSettings is ApertureConstructionAppearanceSettings) { diff --git a/SAM_UI/SAM.Core.UI/Classes/Filter/UIBooleanFilter.cs b/SAM_UI/SAM.Core.UI/Classes/Filter/UIBooleanFilter.cs new file mode 100644 index 00000000..ea49ca83 --- /dev/null +++ b/SAM_UI/SAM.Core.UI/Classes/Filter/UIBooleanFilter.cs @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using Newtonsoft.Json.Linq; +using System; + +namespace SAM.Core.UI +{ + public class UIBooleanFilter : UIFilter + { + public UIBooleanFilter(string name, Type type, IBooleanFilter booleanFilter) + :base(name, type, booleanFilter) + { + + } + + public UIBooleanFilter(UIBooleanFilter uIBooleanFilter) + : base(uIBooleanFilter) + { + + } + + public UIBooleanFilter(JObject jObject) + : base(jObject) + { + + } + } +} diff --git a/SAM_UI/SAM.Core.UI/Classes/LegendItem.cs b/SAM_UI/SAM.Core.UI/Classes/LegendItem.cs index 3808a1f9..d3e0be84 100644 --- a/SAM_UI/SAM.Core.UI/Classes/LegendItem.cs +++ b/SAM_UI/SAM.Core.UI/Classes/LegendItem.cs @@ -1,10 +1,13 @@ -using Newtonsoft.Json.Linq; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using Newtonsoft.Json.Linq; using System; using System.Drawing; namespace SAM.Core.UI { - public class LegendItem : IJSAMObject + public class LegendItem : IJSAMObject { private Color color; private string text; diff --git a/SAM_UI/SAM.Core.UI/Modify/Sort.cs b/SAM_UI/SAM.Core.UI/Modify/Sort.cs new file mode 100644 index 00000000..92088911 --- /dev/null +++ b/SAM_UI/SAM.Core.UI/Modify/Sort.cs @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using System; +using System.Collections.Generic; + +namespace SAM.Core.UI +{ + public static partial class Modify + { + public static void Sort(this List legendItems) + { + if (legendItems == null || legendItems.Count == 0) + { + return; + } + + List> tuples = []; + foreach (LegendItem legendItem in legendItems) + { + if (!Core.Query.TryConvert(legendItem.Text, out double value) || double.IsNaN(value)) + { + tuples = null; + break; + } + + tuples.Add(new Tuple(legendItem, value)); + } + + if (tuples == null || tuples.Count == 0) + { + legendItems.Sort((x, y) => x.Text.CompareTo(y.Text)); + } + else + { + tuples.Sort((x, y) => x.Item2.CompareTo(y.Item2)); + legendItems.Clear(); + legendItems.AddRange(tuples.ConvertAll(x => x.Item1)); + } + } + } +} + + diff --git a/SAM_UI/SAM.Core.UI/Query/IUIFilters.cs b/SAM_UI/SAM.Core.UI/Query/IUIFilters.cs index 05685502..143bb88c 100644 --- a/SAM_UI/SAM.Core.UI/Query/IUIFilters.cs +++ b/SAM_UI/SAM.Core.UI/Query/IUIFilters.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using System.Collections.Generic; namespace SAM.Core.UI { diff --git a/SAM_UI/SAM.Geometry.UI/Classes/Camera.cs b/SAM_UI/SAM.Geometry.UI/Classes/Camera.cs index b18ead01..c5265198 100644 --- a/SAM_UI/SAM.Geometry.UI/Classes/Camera.cs +++ b/SAM_UI/SAM.Geometry.UI/Classes/Camera.cs @@ -1,4 +1,7 @@ -using Newtonsoft.Json.Linq; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using Newtonsoft.Json.Linq; using SAM.Geometry.Spatial; namespace SAM.Geometry.UI @@ -7,6 +10,7 @@ public class Camera : ICamera { private Point3D location; private Vector3D lookDirection; + private Vector3D upDirection; public Camera(Camera camera) { @@ -14,13 +18,15 @@ public Camera(Camera camera) { location = camera.location != null ? new Point3D(camera.location) : null; lookDirection = camera.lookDirection != null ? new Vector3D(camera.lookDirection) : null; + upDirection = camera.upDirection != null ? new Vector3D(camera.upDirection) : null; } } - public Camera(Point3D location, Vector3D lookDirection) + public Camera(Point3D location, Vector3D lookDirection, Vector3D upDirection) { this.location = location; this.lookDirection = lookDirection; + this.upDirection = upDirection; } public Camera(JObject jObject) @@ -54,6 +60,19 @@ public Vector3D LookDirection } } + public Vector3D UpDirection + { + get + { + return upDirection; + } + + set + { + upDirection = value; + } + } + public virtual bool FromJObject(JObject jObject) { if (jObject == null) @@ -71,6 +90,11 @@ public virtual bool FromJObject(JObject jObject) lookDirection = new Vector3D(jObject.Value("LookDirection")); } + if (jObject.ContainsKey("UpDirection")) + { + upDirection = new Vector3D(jObject.Value("UpDirection")); + } + return true; } @@ -89,6 +113,11 @@ public virtual JObject ToJObject() jObject.Add("LookDirection", lookDirection.ToJObject()); } + if (upDirection != null) + { + jObject.Add("UpDirection", upDirection.ToJObject()); + } + return jObject; } } diff --git a/SAM_UI/SAM.Geometry.UI/Classes/Modification/ViewSettingsModification.cs b/SAM_UI/SAM.Geometry.UI/Classes/Modification/ViewSettingsModification.cs index 0dbe8ed0..8d9f2e47 100644 --- a/SAM_UI/SAM.Geometry.UI/Classes/Modification/ViewSettingsModification.cs +++ b/SAM_UI/SAM.Geometry.UI/Classes/Modification/ViewSettingsModification.cs @@ -1,4 +1,7 @@ -using SAM.Core.UI; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020–2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core.UI; using System.Collections.Generic; namespace SAM.Geometry.UI @@ -9,11 +12,13 @@ public class ViewSettingsModification : Modification public bool UpdateGeometry { get; } = false; + public bool UpdateCamera { get; } = false; + public ViewSettingsModification(IViewSettings viewSettings) { if(viewSettings != null) { - ViewSettings = new List() { viewSettings }; + ViewSettings = [viewSettings]; } } @@ -21,20 +26,31 @@ public ViewSettingsModification(IViewSettings viewSettings, bool updateGeometry) { if (viewSettings != null) { - ViewSettings = new List() { viewSettings }; + ViewSettings = [viewSettings]; + } + + UpdateGeometry = updateGeometry; + } + + public ViewSettingsModification(IViewSettings viewSettings, bool updateGeometry, bool updateCamera) + { + if (viewSettings != null) + { + ViewSettings = [viewSettings]; } UpdateGeometry = updateGeometry; + UpdateCamera = updateCamera; } public ViewSettingsModification(IEnumerable viewSettings) { - ViewSettings = viewSettings == null ? null : new List(viewSettings); + ViewSettings = viewSettings == null ? null : [.. viewSettings]; } public ViewSettingsModification(IEnumerable viewSettings, bool updateGeometry) { - ViewSettings = viewSettings == null ? null : new List(viewSettings); + ViewSettings = viewSettings == null ? null : [.. viewSettings]; UpdateGeometry = updateGeometry; } diff --git a/SAM_UI/SAM.Geometry.UI/Classes/Settings/UIGeometrySettings.cs b/SAM_UI/SAM.Geometry.UI/Classes/Settings/UIGeometrySettings.cs index 5ee9c261..17aaf83d 100644 --- a/SAM_UI/SAM.Geometry.UI/Classes/Settings/UIGeometrySettings.cs +++ b/SAM_UI/SAM.Geometry.UI/Classes/Settings/UIGeometrySettings.cs @@ -179,6 +179,11 @@ public Guid ActiveGuid } } + public bool HasAnyViewSettings() + { + return viewSettingsDictionary != null && viewSettingsDictionary.Count > 0; + } + public virtual bool FromJObject(JObject jObject) { if(jObject == null) diff --git a/WPF/SAM.Analytical.UI.WPF/Controls/AnalyticalModelControl.xaml.cs b/WPF/SAM.Analytical.UI.WPF/Controls/AnalyticalModelControl.xaml.cs index f38040b9..85263cea 100644 --- a/WPF/SAM.Analytical.UI.WPF/Controls/AnalyticalModelControl.xaml.cs +++ b/WPF/SAM.Analytical.UI.WPF/Controls/AnalyticalModelControl.xaml.cs @@ -1,4 +1,7 @@ -using SAM.Core; +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (c) 2020-2026 Michal Dengusiak & Jakub Ziolkowski and contributors + +using SAM.Core; using SAM.Core.UI; using SAM.Geometry.UI; using SAM.Geometry.UI.WPF; @@ -16,24 +19,15 @@ namespace SAM.Analytical.UI.WPF /// public partial class AnalyticalModelControl : UserControl { - private Core.Windows.WindowHandle windowHandle; - - private UIAnalyticalModel uIAnalyticalModel; - - private TreeViewDragDropManager treeViewDragDropManager_Views; private TreeViewDragDropManager treeViewDragDropManager_Model; - + private TreeViewDragDropManager treeViewDragDropManager_Views; private TreeViewHighlightManager treeViewHighlightManager_Model; private TreeViewHighlightManager treeViewHighlightManager_Views; - - public event ZoomRequestedEventHandler ZoomRequested; - public event SelectionRequestedEventHandler SelectionRequested; - public event TreeViewItemDroppedEventHandler TreeViewItemDropped; - - + private UIAnalyticalModel uIAnalyticalModel; + private Core.Windows.WindowHandle windowHandle; public AnalyticalModelControl() { - InitializeComponent(); + InitializeComponent(); treeViewDragDropManager_Views = new TreeViewDragDropManager(treeView_Views); treeViewDragDropManager_Views.TreeViewItemDropped += DragDropManager_Views_TreeViewItemDropped; @@ -50,14 +44,87 @@ public AnalyticalModelControl() treeViewHighlightManager_Views.TreeViewItemHighlighted += TreeViewHighlightManager_Views_TreeViewItemHighlighted; ; } - private void TreeViewHighlightManager_Views_TreeViewItemHighlighted(object sender, TreeViewItemHighlightedEventArgs e) + public event SelectionRequestedEventHandler SelectionRequested; + + public event TreeViewItemDroppedEventHandler TreeViewItemDropped; + + public event ZoomRequestedEventHandler ZoomRequested; + public UIAnalyticalModel UIAnalyticalModel { - Modify.AllowTreeViewItemByType(e, typeof(ViewSettings)); + get + { + return uIAnalyticalModel; + } + + set + { + uIAnalyticalModel = value; + if (uIAnalyticalModel != null) + { + uIAnalyticalModel.Modified -= UIAnalyticalModel_Modified; + uIAnalyticalModel.Modified += UIAnalyticalModel_Modified; + + uIAnalyticalModel.Closed -= UIAnalyticalModel_Closed; + uIAnalyticalModel.Closed += UIAnalyticalModel_Closed; + + uIAnalyticalModel.Opened -= UIAnalyticalModel_Opened; + uIAnalyticalModel.Opened += UIAnalyticalModel_Opened; + } + } } - private void TreeViewHighlightManager_Model_TreeViewItemHighlighted(object sender, TreeViewItemHighlightedEventArgs e) + private static List GetSAMObjects(MenuItem menuItem) { - Modify.AllowTreeViewItemByType(e); + if (menuItem == null) + { + return null; + } + + List result = null; + if (menuItem.Tag is IEnumerable) + { + result = new List(); + foreach (object @object in (IEnumerable)menuItem.Tag) + { + if (@object is IJSAMObject) + { + result.Add((IJSAMObject)@object); + } + } + } + else if (menuItem.Tag is IJSAMObject) + { + result = new List() { (IJSAMObject)menuItem.Tag }; + } + + return result; + } + + private static List GetViewSettings(MenuItem menuItem) + { + if (menuItem == null) + { + return null; + } + + List result = new List(); + + IEnumerable enumerable = menuItem.Tag as IEnumerable; + if (enumerable != null) + { + result = enumerable.OfType()?.ToList(); + } + + if (result == null || result.Count() == 0) + { + ViewSettings viewSettings = menuItem.Tag as ViewSettings; + if (viewSettings != null) + { + result = new List() { viewSettings }; + } + } + + return result; } private void DragDropManager_Model_TreeViewItemDropped(object sender, TreeViewItemDroppedEventArgs e) @@ -80,7 +147,7 @@ private void DragDropManager_Model_TreeViewItemDropped(object sender, TreeViewIt { List spaces = new List() { (Space)selectedObject }; List highlightedSpaces = highlightedObjects?.FindAll(x => x is Space).ConvertAll(x => (Space)x); - if(highlightedSpaces != null) + if (highlightedSpaces != null) { spaces.AddRange(highlightedSpaces); } @@ -89,7 +156,7 @@ private void DragDropManager_Model_TreeViewItemDropped(object sender, TreeViewIt e.EventResult = EventResult.Succeeded; } - if(selectedObject is InternalCondition && targetObject is Space) + if (selectedObject is InternalCondition && targetObject is Space) { Modify.AssignSpaceInternalCondition(uIAnalyticalModel, (Space)targetObject, (InternalCondition)selectedObject); e.EventResult = EventResult.Succeeded; @@ -105,11 +172,11 @@ private void DragDropManager_Model_TreeViewItemDropped(object sender, TreeViewIt private void DragDropManager_Views_TreeViewItemDropped(object sender, TreeViewItemDroppedEventArgs e) { ViewSettings viewSettings = e.SelectedTreeViewItem.Tag as ViewSettings; - if(viewSettings == null) + if (viewSettings == null) { return; } - + string group = e.TargetTreeViewItem.Tag as string; List highlightedObjects = treeViewHighlightManager_Views?.HighlightedTreeViewItems?.ConvertAll(x => x.Tag); @@ -122,420 +189,359 @@ private void DragDropManager_Views_TreeViewItemDropped(object sender, TreeViewIt Modify.SetGroup(uIAnalyticalModel, guids, group); } - private void treeView_Model_ContextMenuOpening(object sender, ContextMenuEventArgs e) + private void Edit(IJSAMObject jSAMObject) { - contextMenu_Model.Items.Clear(); - - TreeViewItem treeViewItem = e.Source as TreeViewItem; - if(treeViewItem == null) + if (jSAMObject is Space) { - e.Handled = true; - return; + UI.Modify.EditSpace(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); } - - if (treeViewItem.Tag is Type) + else if (jSAMObject is Panel) { - if(treeViewItem.Tag == typeof(MechanicalSystemType)) - { - MenuItem menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Create"; - menuItem.Header = "Create"; - menuItem.Click += MenuItem_Create_Click; - menuItem.Tag = typeof(MechanicalSystemType); - contextMenu_Model.Items.Add(menuItem); - } + UI.Modify.EditPanel(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); } - - List> tuples = null; - - bool singleSelection = true; - if (treeViewHighlightManager_Model != null && treeViewHighlightManager_Model.Enabled) + else if (jSAMObject is IMaterial) { - List treeViewItems = treeViewHighlightManager_Model.HighlightedTreeViewItems; - if (treeViewItems != null && treeViewItems.Count != 0) - { - tuples = treeViewItems.FindAll(x => x?.Tag is IJSAMObject).ConvertAll(x => new Tuple(x, x.Tag as IJSAMObject)); - singleSelection = tuples != null && tuples.Count == 1; - } + UI.Modify.EditMaterial(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); } - - if(tuples == null || tuples.Count == 0) + else if (jSAMObject is Profile) { - IJSAMObject jSAMObject_Temp = treeViewItem.Tag as IJSAMObject; - if(jSAMObject_Temp != null) - { - tuples = new List>() { new Tuple(treeViewItem, jSAMObject_Temp) }; - } + UI.Modify.EditProfile(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); + } + else if (jSAMObject is Aperture) + { + UI.Modify.EditAperture(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); } + else if (jSAMObject is Zone) + { + Modify.EditZone(uIAnalyticalModel, jSAMObject as dynamic); + } + else if (jSAMObject is InternalCondition) + { + UI.Modify.EditInternalCondition(uIAnalyticalModel, jSAMObject as dynamic); + } + } - if (tuples == null || tuples.Count == 0) + private List GetExpandedTags(ItemCollection itemCollection) + { + if (itemCollection == null) { - TreeViewItem treeViewItem_Parent = treeViewItem.Parent as TreeViewItem; + return null; + } - bool added = false; - if (treeViewItem_Parent.Tag == typeof(Zone)) + List result = new List(); + + foreach (TreeViewItem treeViewItem in itemCollection) + { + if (treeViewItem.IsExpanded) { - if (singleSelection) + result.Add(treeViewItem.Tag); + List expandedTags = GetExpandedTags(treeViewItem.Items); + if (expandedTags != null) { - MenuItem menuItem = new MenuItem(); - menuItem.Name = "MenuItem_EditZone"; - menuItem.Header = "Edit Zone"; - menuItem.Click += MenuItem_EditZone_Click; - menuItem.Tag = treeViewItem.Items == null || treeViewItem.Items.Count == 0 ? null : (treeViewItem.Items[0] as TreeViewItem)?.Tag; - contextMenu_Model.Items.Add(menuItem); - added = true; + result.AddRange(expandedTags); } } + } - if(!added) - { - e.Handled = true; - } + return result; + } + + private void LoadAnalyticalModel(AnalyticalModel analyticalModel, ModifiedEventArgs modifiedEventArgs) + { + LoadModel(analyticalModel); + LoadViews(analyticalModel); + } + private void LoadModel(AnalyticalModel analyticalModel) + { + TreeView treeView_AnalyticalModel = treeView_Model; + if (treeView_AnalyticalModel == null) + { return; } + List expandedTags = GetExpandedTags(treeView_AnalyticalModel.Items); - IJSAMObject jSAMObject = tuples[0].Item2; + treeView_AnalyticalModel.Items.Clear(); + if (analyticalModel == null) + { + return; + } - if (jSAMObject is Space) + string name = analyticalModel.Name; + if (string.IsNullOrWhiteSpace(name)) { - MenuItem menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Zoom"; - menuItem.Header = "Zoom"; - menuItem.Click += MenuItem_Zoom_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); + name = "???"; + } - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Select"; - menuItem.Header = "Select"; - menuItem.Click += MenuItem_Select_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_AnalyticalModel = new TreeViewItem() { Header = name, Tag = analyticalModel, AllowDrop = false }; + treeView_AnalyticalModel.Items.Add(treeViewItem_AnalyticalModel); - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_RenameSpaces"; - menuItem.Header = "Rename"; - menuItem.Click += MenuItem_RenameSpaces_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_Spaces = new TreeViewItem() { Header = "Spaces", Tag = typeof(Space), AllowDrop = false }; + treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Spaces); - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_EditInternalConditions"; - menuItem.Header = "Modify IC"; - menuItem.Click += MenuItem_EditInternalConditions_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_Shades = new TreeViewItem() { Header = "Shades", Tag = typeof(Panel), AllowDrop = false }; + treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Shades); - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_AssignInternalCondition"; - menuItem.Header = "Assign IC"; - menuItem.Click += MenuItem_AssignInternalCondition_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_Profiles = new TreeViewItem() { Header = "Profiles", Tag = typeof(Profile), AllowDrop = false }; + treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Profiles); - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_MapInternalConditions"; - menuItem.Header = "Map IC"; - menuItem.Click += MenuItem_MapInternalConditions_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_Materials = new TreeViewItem() { Header = "Materials", Tag = typeof(IMaterial), AllowDrop = false }; + treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Materials); - if (singleSelection) - { - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Edit"; - menuItem.Header = "Edit Space"; - menuItem.Click += MenuItem_Edit_Click; - menuItem.Tag = jSAMObject; - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_InternalConditions = new TreeViewItem() { Header = "Internal Conditions", Tag = typeof(InternalCondition), AllowDrop = false }; + treeViewItem_AnalyticalModel.Items.Add(treeViewItem_InternalConditions); - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_EditZone"; - menuItem.Header = "Edit Zone"; - menuItem.Click += MenuItem_EditSpaceZone_Click; - menuItem.Tag = tuples[0].Item1; - contextMenu_Model.Items.Add(menuItem); - } + TreeViewItem treeViewItem_MechanicalSystems = new TreeViewItem() { Header = "Mechanical Systems", Tag = typeof(MechanicalSystemType), AllowDrop = false }; + treeViewItem_AnalyticalModel.Items.Add(treeViewItem_MechanicalSystems); - List> tuples_Zone = new List>(); - foreach(Tuple tuple in tuples) + TreeViewItem treeViewItem_Zones = new TreeViewItem() { Header = "Zones", Tag = typeof(Zone), AllowDrop = false }; + treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Zones); + + AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster; + if (adjacencyCluster != null) + { + List spaces = adjacencyCluster.GetSpaces(); + if (spaces != null) { - if(!(tuple.Item2 is Space)) + foreach (Space space in spaces) { - continue; + TreeViewItem treeViewItem_Space = new TreeViewItem() { Header = space.Name, Tag = space, AllowDrop = true }; + treeViewItem_Spaces.Items.Add(treeViewItem_Space); + List panels_Space = adjacencyCluster.GetPanels(space); + if (panels_Space != null) + { + foreach (Panel panel in panels_Space) + { + TreeViewItem treeViewItem_Panel = new TreeViewItem() { Header = panel.Name, Tag = panel, AllowDrop = false }; + treeViewItem_Space.Items.Add(treeViewItem_Panel); + + List apertures = panel.Apertures; + if (apertures != null) + { + foreach (Aperture aperture in apertures) + { + TreeViewItem treeViewItem_Aperture = new TreeViewItem() { Header = aperture.Name, Tag = aperture, AllowDrop = false }; + treeViewItem_Panel.Items.Add(treeViewItem_Aperture); + treeViewItem_Aperture.IsExpanded = expandedTags.Find(x => x is Aperture && ((Aperture)x).Guid == aperture.Guid) != null; + } + } + + treeViewItem_Panel.IsExpanded = expandedTags.Find(x => x is Panel && ((Panel)x).Guid == panel.Guid) != null; + } + } + + treeViewItem_Space.IsExpanded = expandedTags.Find(x => x is Space && ((Space)x).Guid == space.Guid) != null; } + } - TreeViewItem treeViewItem_Zone = treeViewItem.Parent as TreeViewItem; - if (treeViewItem_Zone != null) + List panels = adjacencyCluster.GetPanels(); + if (panels != null) + { + foreach (Panel panel in panels) { - Zone zone = treeViewItem_Zone.Tag as Zone; - if (zone != null) + List spaces_Panel = adjacencyCluster.GetSpaces(panel); + if (spaces_Panel == null || spaces_Panel.Count == 0) { - tuples_Zone.Add(new Tuple(zone, (Space)tuple.Item2)); + TreeViewItem treeViewItem_Shade = new TreeViewItem() { Header = panel.Name, Tag = panel, AllowDrop = false }; + treeViewItem_Shade.Tag = panel; + treeViewItem_Shade.IsExpanded = expandedTags.Find(x => x is Panel && ((Panel)x).Guid == panel.Guid) != null; + + treeViewItem_Shades.Items.Add(treeViewItem_Shade); } } } - if (tuples_Zone != null && tuples_Zone.Count > 0) + IEnumerable internalConditions = adjacencyCluster.GetInternalConditions(false, true); + if (internalConditions != null) { - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_RemoveSpaceZone"; - menuItem.Header = "Remove From Zone"; - menuItem.Click += MenuItem_RemoveSpaceZone_Click; - menuItem.Tag = tuples_Zone; - contextMenu_Model.Items.Add(menuItem); + foreach (InternalCondition internalCondition in internalConditions) + { + TreeViewItem treeViewItem_InternalCondition = new TreeViewItem() { Header = internalCondition.Name, Tag = internalCondition, AllowDrop = false }; + treeViewItem_InternalCondition.MouseDoubleClick += TreeViewItem_MouseDoubleClick; + treeViewItem_InternalConditions.Items.Add(treeViewItem_InternalCondition); + } } - else + + List mechanicalSystemTypes = adjacencyCluster.GetMechanicalSystemTypes(); + if (mechanicalSystemTypes != null) { - foreach (Tuple tuple in tuples) + foreach (MechanicalSystemType mechanicalSystemType in mechanicalSystemTypes) { - if (!(tuple.Item2 is Space)) + TreeViewItem treeViewItem_MechanicalSystemType = new TreeViewItem() { Header = mechanicalSystemType.Name, Tag = mechanicalSystemType, AllowDrop = false }; + treeViewItem_MechanicalSystems.Items.Add(treeViewItem_MechanicalSystemType); + + List mechanicalSystems = adjacencyCluster.GetMechanicalSystems(mechanicalSystemType); + if (mechanicalSystems != null) { - continue; + foreach (MechanicalSystem mechanicalSystem in mechanicalSystems) + { + TreeViewItem treeViewItem_MechanicalSystem = new TreeViewItem() { Header = mechanicalSystem.FullName, Tag = mechanicalSystem, AllowDrop = false }; + treeViewItem_MechanicalSystemType.Items.Add(treeViewItem_MechanicalSystem); + } } - tuples_Zone.Add(new Tuple(null, (Space)tuple.Item2)); + treeViewItem_MechanicalSystemType.IsExpanded = expandedTags.Find(x => x is MechanicalSystemType && ((MechanicalSystemType)x).Guid == mechanicalSystemType.Guid) != null; } } - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_EditZones"; - menuItem.Header = "Edit Zones"; - menuItem.Click += MenuItem_EditZones_Click; - menuItem.Tag = tuples_Zone; - contextMenu_Model.Items.Add(menuItem); } - else if(jSAMObject is Panel) - { - MenuItem menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Zoom"; - menuItem.Header = "Zoom"; - menuItem.Click += MenuItem_Zoom_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Select"; - menuItem.Header = "Select"; - menuItem.Click += MenuItem_Select_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); - if(singleSelection) + List profiles = analyticalModel.ProfileLibrary?.GetProfiles(); + if (profiles != null) + { + foreach (Profile profile in profiles) { - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Edit"; - menuItem.Header = "Edit"; - menuItem.Click += MenuItem_Edit_Click; - menuItem.Tag = jSAMObject; - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_Profile = new TreeViewItem() { Header = profile.Name, Tag = profile, AllowDrop = false }; + treeViewItem_Profile.MouseDoubleClick += TreeViewItem_MouseDoubleClick; + treeViewItem_Profiles.Items.Add(treeViewItem_Profile); } - } - else if (jSAMObject is Aperture) - { - MenuItem menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Zoom"; - menuItem.Header = "Zoom"; - menuItem.Click += MenuItem_Zoom_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Select"; - menuItem.Header = "Select"; - menuItem.Click += MenuItem_Select_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); - if(singleSelection) + List materials = analyticalModel.MaterialLibrary?.GetMaterials(); + if (materials != null) + { + foreach (IMaterial material in materials) { - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Edit"; - menuItem.Header = "Edit"; - menuItem.Click += MenuItem_Edit_Click; - menuItem.Tag = jSAMObject; - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_Material = new TreeViewItem() { Header = material.Name, Tag = material, AllowDrop = false }; + treeViewItem_Materials.Items.Add(treeViewItem_Material); } - } - else if (jSAMObject is IMaterial) - { - MenuItem menuItem = null; - if (singleSelection) + List zones = adjacencyCluster?.GetZones(); + if (zones != null) + { + SortedDictionary> dictionary = new SortedDictionary>(); + foreach (Zone zone in zones) { - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Edit"; - menuItem.Header = "Edit"; - menuItem.Click += MenuItem_Edit_Click; - menuItem.Tag = jSAMObject; - contextMenu_Model.Items.Add(menuItem); - } + if (zone == null) + { + continue; + } - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Remove"; - menuItem.Header = "Remove"; - menuItem.Click += MenuItem_Remove_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); + if (!zone.TryGetValue(ZoneParameter.ZoneCategory, out string zoneCategory) || string.IsNullOrWhiteSpace(zoneCategory)) + { + zoneCategory = "???"; + } - if (singleSelection) - { - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Duplicate"; - menuItem.Header = "Duplicate"; - menuItem.Click += MenuItem_Duplicate_Click; - menuItem.Tag = jSAMObject; - contextMenu_Model.Items.Add(menuItem); - } + if (!dictionary.TryGetValue(zoneCategory, out List zones_Temp)) + { + zones_Temp = new List(); + dictionary[zoneCategory] = zones_Temp; + } - } - else if (jSAMObject is Profile) - { + zones_Temp.Add(zone); + } - if (singleSelection) + foreach (KeyValuePair> keyValuePair in dictionary) { - MenuItem menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Edit"; - menuItem.Header = "Edit"; - menuItem.Click += MenuItem_Edit_Click; - menuItem.Tag = jSAMObject; - contextMenu_Model.Items.Add(menuItem); + TreeViewItem treeViewItem_ZoneCategory = new TreeViewItem() { Header = keyValuePair.Key, Tag = keyValuePair.Key, AllowDrop = false }; + treeViewItem_Zones.Items.Add(treeViewItem_ZoneCategory); + + treeViewItem_ZoneCategory.IsExpanded = expandedTags.Find(x => x is string && (string)x == keyValuePair.Key) != null; + + foreach (Zone zone in keyValuePair.Value) + { + TreeViewItem treeViewItem_Zone = new TreeViewItem() { Header = zone.Name, Tag = zone, AllowDrop = true }; + treeViewItem_ZoneCategory.Items.Add(treeViewItem_Zone); + + treeViewItem_Zone.IsExpanded = expandedTags.Find(x => x is Zone && ((Zone)x).Guid == zone.Guid) != null; + + List spaces = adjacencyCluster.GetRelatedObjects(zone); + if (spaces != null && spaces.Count != 0) + { + foreach (Space space in spaces) + { + TreeViewItem treeViewItem_Space = new TreeViewItem() { Header = space.Name, Tag = space, AllowDrop = true }; + treeViewItem_Zone.Items.Add(treeViewItem_Space); + } + } + } + } } - else if (jSAMObject is Zone) + + treeViewItem_AnalyticalModel.IsExpanded = true; + if (expandedTags != null && expandedTags.Count != 0) { - MenuItem menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Zoom"; - menuItem.Header = "Zoom"; - menuItem.Click += MenuItem_Zoom_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); + treeViewItem_Spaces.IsExpanded = expandedTags.Contains(treeViewItem_Spaces.Tag); + treeViewItem_Shades.IsExpanded = expandedTags.Contains(treeViewItem_Shades.Tag); + treeViewItem_Profiles.IsExpanded = expandedTags.Contains(treeViewItem_Profiles.Tag); + treeViewItem_Materials.IsExpanded = expandedTags.Contains(treeViewItem_Materials.Tag); + treeViewItem_InternalConditions.IsExpanded = expandedTags.Contains(treeViewItem_InternalConditions.Tag); + treeViewItem_MechanicalSystems.IsExpanded = expandedTags.Contains(treeViewItem_MechanicalSystems.Tag); + treeViewItem_Zones.IsExpanded = expandedTags.Contains(treeViewItem_Zones.Tag); + } + } - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Select"; - menuItem.Header = "Select"; - menuItem.Click += MenuItem_Select_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Remove"; - menuItem.Header = "Remove"; - menuItem.Click += MenuItem_Remove_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); - - if (singleSelection) - { - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Edit"; - menuItem.Header = "Edit"; - menuItem.Click += MenuItem_Edit_Click; - menuItem.Tag = jSAMObject; - contextMenu_Model.Items.Add(menuItem); - } - } - else if(jSAMObject is InternalCondition) + private void LoadViews(AnalyticalModel analyticalModel) + { + if (treeView_Views == null) { - if (singleSelection) - { - MenuItem menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Edit"; - menuItem.Header = "Edit"; - menuItem.Click += MenuItem_Edit_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Duplicate"; - menuItem.Header = "Duplicate"; - menuItem.Click += MenuItem_Duplicate_Click; - menuItem.Tag = jSAMObject; - contextMenu_Model.Items.Add(menuItem); - - } + return; } - else if (jSAMObject is MechanicalSystem) - { - MenuItem menuItem = null; - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Remove"; - menuItem.Header = "Remove"; - menuItem.Click += MenuItem_Remove_Click; - menuItem.Tag = tuples.ConvertAll(x => x.Item2); - contextMenu_Model.Items.Add(menuItem); - - if (singleSelection) - { + treeView_Views.Items.Clear(); - } - } - else + if (analyticalModel == null) { - e.Handled = true; return; } - } - private void MenuItem_EditZones_Click(object sender, RoutedEventArgs e) - { - MenuItem menuItem = sender as MenuItem; - if (menuItem == null) + string name = analyticalModel.Name; + if (string.IsNullOrWhiteSpace(name)) { - return; + name = "???"; } - IEnumerable enumerable = menuItem.Tag as IEnumerable; - if (enumerable == null) + TreeViewItem treeViewItem_AnalyticalModel = new TreeViewItem() { Header = name, Tag = analyticalModel, AllowDrop = false }; + treeView_Views.Items.Add(treeViewItem_AnalyticalModel); + + TreeViewItem treeViewItem_Views = new TreeViewItem() { Header = "Views", Tag = typeof(ViewSettings), AllowDrop = true }; + treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Views); + + if (!analyticalModel.TryGetValue(AnalyticalModelParameter.UIGeometrySettings, out UIGeometrySettings uIGeometrySettings) || uIGeometrySettings == null) { return; } + Dictionary dictionary = new Dictionary(); - List spaces = new List(); - string zoneCategory = null; - foreach (object @object in enumerable) + List viewSettingsList = uIGeometrySettings.GetViewSettings(); + foreach (ViewSettings viewSettings in viewSettingsList) { - Tuple tuple = @object as Tuple; - if (tuple == null) + string name_Temp = viewSettings.Name; + if (string.IsNullOrWhiteSpace(name_Temp)) { - continue; + name_Temp = Query.DefaultName(viewSettings); } - if(tuple.Item2 != null) + if (string.IsNullOrWhiteSpace(name_Temp)) { - spaces.Add(tuple.Item2); + name_Temp = "???"; } - if(tuple.Item1 != null) + TreeViewItem treeViewItem_ViewSettings = new TreeViewItem() { Header = name_Temp, Tag = viewSettings, AllowDrop = false }; + treeViewItem_ViewSettings.PreviewMouseDoubleClick += TreeViewItem_ViewSettings_PreviewMouseDoubleClick; + + if (viewSettings.TryGetValue(ViewSettingsParameter.Group, out string group) && !string.IsNullOrWhiteSpace(group)) { - Zone zone = tuple.Item1; - if(zone.TryGetValue(ZoneParameter.ZoneCategory, out string zoneCategory_Temp) && !string.IsNullOrWhiteSpace(zoneCategory_Temp)) + if (!dictionary.TryGetValue(group, out TreeViewItem treeViewItem) || treeViewItem == null) { - zoneCategory = zoneCategory_Temp; + treeViewItem = new TreeViewItem() { Header = group, Tag = group, AllowDrop = true }; + dictionary[group] = treeViewItem; + treeViewItem_Views.Items.Add(treeViewItem); } - } - } - Modify.EditZones(uIAnalyticalModel, spaces, zoneCategory, spaces); - } - - private void MenuItem_MapInternalConditions_Click(object sender, RoutedEventArgs e) - { - List jSAMObjects = GetSAMObjects(sender as MenuItem); - if (jSAMObjects == null || jSAMObjects.Count == 0) - { - return; + treeViewItem.Items.Add(treeViewItem_ViewSettings); + } + else + { + treeViewItem_Views.Items.Add(treeViewItem_ViewSettings); + } } - Modify.MapInternalConditions(uIAnalyticalModel, jSAMObjects.FindAll(x => x is Space).Cast()); + treeViewItem_AnalyticalModel.ExpandSubtree(); } private void MenuItem_AssignInternalCondition_Click(object sender, RoutedEventArgs e) @@ -549,130 +555,63 @@ private void MenuItem_AssignInternalCondition_Click(object sender, RoutedEventAr Modify.AssignSpaceInternalCondition(uIAnalyticalModel, jSAMObjects.FindAll(x => x is Space).Cast()); } - private void MenuItem_RenameSpaces_Click(object sender, RoutedEventArgs e) + private void MenuItem_Close_TabItem_Click(object sender, RoutedEventArgs e) { - List jSAMObjects = GetSAMObjects(sender as MenuItem); - if (jSAMObjects == null || jSAMObjects.Count == 0) + MenuItem menuItem = sender as MenuItem; + if (menuItem == null) { return; } - Modify.RenameSpaces(uIAnalyticalModel, jSAMObjects.FindAll(x => x is Space).Cast()); - } - - private void MenuItem_EditInternalConditions_Click(object sender, RoutedEventArgs e) - { - List jSAMObjects = GetSAMObjects(sender as MenuItem); - if (jSAMObjects == null || jSAMObjects.Count == 0) + List viewSettingsList = GetViewSettings(menuItem); + if (viewSettingsList == null || viewSettingsList.Count() == 0) { return; } - Modify.EditInternalConditions(uIAnalyticalModel, jSAMObjects.FindAll(x => x is Space).Cast()); - } - - private void MenuItem_EditZone_Click(object sender, RoutedEventArgs e) - { - List jSAMObjects = GetSAMObjects(sender as MenuItem); - if(jSAMObjects == null || jSAMObjects.Count == 0) + if (viewSettingsList == null || viewSettingsList.Count() == 0) { return; } - foreach(Zone zone in jSAMObjects.FindAll(x => x is Zone)) - { - Modify.EditSpaceZone(uIAnalyticalModel, zone); - } + Modify.EnableViewSettings(uIAnalyticalModel, viewSettingsList.ConvertAll(x => x.Guid), false); } - private void treeView_Views_ContextMenuOpening(object sender, ContextMenuEventArgs e) + private void MenuItem_Create_Click(object sender, RoutedEventArgs e) { - contextMenu_Views.Items.Clear(); - - TreeViewItem treeViewItem = e.Source as TreeViewItem; - if (treeViewItem == null) + MenuItem menuItem = sender as MenuItem; + if (menuItem == null) { - e.Handled = true; return; } - List jSAMObjects = null; - - if(treeViewItem.Tag is ViewSettings) - { - jSAMObjects = new List() { (ViewSettings)treeViewItem.Tag }; - } - else if(treeViewItem.Tag is string) + if (menuItem.Tag == typeof(MechanicalSystemType)) { - jSAMObjects = new List(); - foreach (object @object in treeViewItem.Items) - { - ViewSettings viewSettings_Temp = (@object as TreeViewItem)?.Tag as ViewSettings; - if(viewSettings_Temp == null) - { - continue; - } - - jSAMObjects.Add(viewSettings_Temp); - } + uIAnalyticalModel.CreateMechanicalSystem(null, windowHandle); + return; } + } + private void MenuItem_Duplicate_Click(object sender, RoutedEventArgs e) + { + List jSAMObjects = GetSAMObjects(sender as MenuItem); if (jSAMObjects == null || jSAMObjects.Count == 0) { - e.Handled = true; return; } - List treeViewItems = treeViewHighlightManager_Views != null && treeViewHighlightManager_Views.Enabled ? treeViewHighlightManager_Views.HighlightedTreeViewItems : null; - if (treeViewItems != null && treeViewItems.Count != 0) + foreach (IMaterial material in jSAMObjects.FindAll(x => x is IMaterial)) { - jSAMObjects = new List(treeViewItems.FindAll(x => x?.Tag is ViewSettings).ConvertAll(x => x.Tag as ViewSettings)); + UI.Modify.DuplicateMaterial(uIAnalyticalModel, material); } - MenuItem menuItem = null; - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Open_TabItem"; - menuItem.Header = "Open"; - menuItem.Click += MenuItem_Open_TabItem_Click; - menuItem.Tag = jSAMObjects; - contextMenu_Views.Items.Add(menuItem); - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Close_TabItem"; - menuItem.Header = "Close"; - menuItem.Click += MenuItem_Close_TabItem_Click; - menuItem.Tag = jSAMObjects; - contextMenu_Views.Items.Add(menuItem); - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Remove_TabItem"; - menuItem.Header = "Remove"; - menuItem.Click += MenuItem_Remove_TabItem_Click; - menuItem.Tag = jSAMObjects; - contextMenu_Views.Items.Add(menuItem); - - if (jSAMObjects.Count == 1) + foreach (InternalCondition internalCondition in jSAMObjects.FindAll(x => x is InternalCondition)) { - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Duplicate_TabItem"; - menuItem.Header = "Duplicate"; - menuItem.Click += MenuItem_Duplicate_TabItem_Click; - menuItem.Tag = jSAMObjects; - contextMenu_Views.Items.Add(menuItem); - - menuItem = new MenuItem(); - menuItem.Name = "MenuItem_Settings_TabItem"; - menuItem.Header = "Settings"; - menuItem.Click += MenuItem_Settings_TabItem_Click; - menuItem.Tag = jSAMObjects; - contextMenu_Views.Items.Add(menuItem); + UI.Modify.DuplicateInternalCondition(uIAnalyticalModel, internalCondition); } - - contextMenu_Views.IsOpen = true; } - private void MenuItem_Remove_TabItem_Click(object sender, RoutedEventArgs e) + private void MenuItem_Duplicate_TabItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) @@ -680,16 +619,16 @@ private void MenuItem_Remove_TabItem_Click(object sender, RoutedEventArgs e) return; } - List viewSettingsList = GetViewSettings(menuItem); - if (viewSettingsList == null || viewSettingsList.Count() == 0) + ViewSettings viewSettings = menuItem.Tag as ViewSettings; + if (viewSettings == null) { return; } - Modify.RemoveViewSettings(uIAnalyticalModel, viewSettingsList.ConvertAll(x => x.Guid)); + Modify.DuplicateViewSettings(uIAnalyticalModel, viewSettings.Guid); } - private void MenuItem_Open_TabItem_Click(object sender, RoutedEventArgs e) + private void MenuItem_Edit_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) @@ -697,51 +636,47 @@ private void MenuItem_Open_TabItem_Click(object sender, RoutedEventArgs e) return; } - List viewSettingsList = GetViewSettings(menuItem); - if (viewSettingsList == null || viewSettingsList.Count() == 0) + if (menuItem.Tag == typeof(IMaterial)) { + uIAnalyticalModel.EditMaterialLibrary(windowHandle); return; } - Modify.EnableViewSettings(uIAnalyticalModel, viewSettingsList.ConvertAll(x => x.Guid), true); - Modify.ActivateViewSettings(uIAnalyticalModel, viewSettingsList.First().Guid); - } + if (menuItem.Tag == typeof(Profile)) + { + uIAnalyticalModel.EditProfileLibrary(windowHandle); + return; + } - private void MenuItem_Settings_TabItem_Click(object sender, RoutedEventArgs e) - { - MenuItem menuItem = sender as MenuItem; - if (menuItem == null) + if (menuItem.Tag == typeof(InternalCondition)) { + uIAnalyticalModel.EditInternalConditions(windowHandle); return; } - List viewSettingsList = GetViewSettings(menuItem); - if (viewSettingsList == null || viewSettingsList.Count() != 1) + List jSAMObjects = GetSAMObjects(menuItem); + if (jSAMObjects == null || jSAMObjects.Count == 0) { return; } - Modify.EditViewSettings(uIAnalyticalModel, viewSettingsList[0].Guid); + Edit(jSAMObjects[0]); + + } - private void MenuItem_Duplicate_TabItem_Click(object sender, RoutedEventArgs e) + private void MenuItem_EditInternalConditions_Click(object sender, RoutedEventArgs e) { - MenuItem menuItem = sender as MenuItem; - if (menuItem == null) - { - return; - } - - ViewSettings viewSettings = menuItem.Tag as ViewSettings; - if (viewSettings == null) + List jSAMObjects = GetSAMObjects(sender as MenuItem); + if (jSAMObjects == null || jSAMObjects.Count == 0) { return; } - Modify.DuplicateViewSettings(uIAnalyticalModel, viewSettings.Guid); + Modify.EditInternalConditions(uIAnalyticalModel, jSAMObjects.FindAll(x => x is Space).Cast()); } - private void MenuItem_Close_TabItem_Click(object sender, RoutedEventArgs e) + private void MenuItem_EditSpaceZone_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) @@ -749,21 +684,22 @@ private void MenuItem_Close_TabItem_Click(object sender, RoutedEventArgs e) return; } - List viewSettingsList = GetViewSettings(menuItem); - if (viewSettingsList == null || viewSettingsList.Count() == 0) + TreeViewItem treeViewItem = menuItem.Tag as TreeViewItem; + if (treeViewItem == null) { return; } - if (viewSettingsList == null || viewSettingsList.Count() == 0) + if (treeViewItem.Tag is Space) { - return; - } + Space space = (Space)treeViewItem.Tag; + string zoneCategory = ((treeViewItem.Parent as TreeViewItem)?.Parent as TreeViewItem)?.Tag?.ToString(); - Modify.EnableViewSettings(uIAnalyticalModel, viewSettingsList.ConvertAll(x => x.Guid), false); + Modify.EditSpaceZone(uIAnalyticalModel, space, zoneCategory); + } } - private void MenuItem_Select_Click(object sender, RoutedEventArgs e) + private void MenuItem_EditZone_Click(object sender, RoutedEventArgs e) { List jSAMObjects = GetSAMObjects(sender as MenuItem); if (jSAMObjects == null || jSAMObjects.Count == 0) @@ -771,21 +707,13 @@ private void MenuItem_Select_Click(object sender, RoutedEventArgs e) return; } - SelectionRequested?.Invoke(this, new SelectionRequestedEventArgs(jSAMObjects?.FindAll(x => x is SAMObject).ConvertAll(x => (SAMObject)x))); - } - - private void MenuItem_Zoom_Click(object sender, RoutedEventArgs e) - { - List jSAMObjects = GetSAMObjects(sender as MenuItem); - if (jSAMObjects == null || jSAMObjects.Count == 0) + foreach (Zone zone in jSAMObjects.FindAll(x => x is Zone)) { - return; + Modify.EditSpaceZone(uIAnalyticalModel, zone); } - - ZoomRequested?.Invoke(this, new ZoomRequestedEventArgs(jSAMObjects?.FindAll(x => x is SAMObject).ConvertAll(x => (SAMObject)x))); } - private void MenuItem_RemoveSpaceZone_Click(object sender, RoutedEventArgs e) + private void MenuItem_EditZones_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) @@ -799,58 +727,62 @@ private void MenuItem_RemoveSpaceZone_Click(object sender, RoutedEventArgs e) return; } - foreach(object @object in enumerable) + + List spaces = new List(); + string zoneCategory = null; + foreach (object @object in enumerable) { Tuple tuple = @object as Tuple; - if(tuple == null) + if (tuple == null) { continue; } - Modify.RemoveSpaceZone(uIAnalyticalModel, tuple.Item2, tuple.Item1); + if (tuple.Item2 != null) + { + spaces.Add(tuple.Item2); + } + + if (tuple.Item1 != null) + { + Zone zone = tuple.Item1; + if (zone.TryGetValue(ZoneParameter.ZoneCategory, out string zoneCategory_Temp) && !string.IsNullOrWhiteSpace(zoneCategory_Temp)) + { + zoneCategory = zoneCategory_Temp; + } + } } + + Modify.EditZones(uIAnalyticalModel, spaces, zoneCategory, spaces); } - private void MenuItem_EditSpaceZone_Click(object sender, RoutedEventArgs e) + private void MenuItem_MapInternalConditions_Click(object sender, RoutedEventArgs e) { - MenuItem menuItem = sender as MenuItem; - if (menuItem == null) - { - return; - } - - TreeViewItem treeViewItem = menuItem.Tag as TreeViewItem; - if (treeViewItem == null) + List jSAMObjects = GetSAMObjects(sender as MenuItem); + if (jSAMObjects == null || jSAMObjects.Count == 0) { return; } - if (treeViewItem.Tag is Space) - { - Space space = (Space)treeViewItem.Tag; - string zoneCategory = ((treeViewItem.Parent as TreeViewItem)?.Parent as TreeViewItem)?.Tag?.ToString(); - - Modify.EditSpaceZone(uIAnalyticalModel, space, zoneCategory); - } + Modify.MapInternalConditions(uIAnalyticalModel, jSAMObjects.FindAll(x => x is Space).Cast()); } - private void MenuItem_Duplicate_Click(object sender, RoutedEventArgs e) + private void MenuItem_Open_TabItem_Click(object sender, RoutedEventArgs e) { - List jSAMObjects = GetSAMObjects(sender as MenuItem); - if(jSAMObjects == null || jSAMObjects.Count == 0) + MenuItem menuItem = sender as MenuItem; + if (menuItem == null) { return; } - foreach(IMaterial material in jSAMObjects.FindAll(x => x is IMaterial)) + List viewSettingsList = GetViewSettings(menuItem); + if (viewSettingsList == null || viewSettingsList.Count() == 0) { - UI.Modify.DuplicateMaterial(uIAnalyticalModel, material); + return; } - foreach (InternalCondition internalCondition in jSAMObjects.FindAll(x => x is InternalCondition)) - { - UI.Modify.DuplicateInternalCondition(uIAnalyticalModel, internalCondition); - } + Modify.EnableViewSettings(uIAnalyticalModel, viewSettingsList.ConvertAll(x => x.Guid), true); + Modify.ActivateViewSettings(uIAnalyticalModel, viewSettingsList.First().Guid); } private void MenuItem_Remove_Click(object sender, RoutedEventArgs e) @@ -868,7 +800,7 @@ private void MenuItem_Remove_Click(object sender, RoutedEventArgs e) } List zones = jSAMObjects?.FindAll(x => x is Zone).ConvertAll(x => (Zone)x); - if(zones != null && zones.Count != 0) + if (zones != null && zones.Count != 0) { Modify.RemoveZones(uIAnalyticalModel, zones); } @@ -880,7 +812,7 @@ private void MenuItem_Remove_Click(object sender, RoutedEventArgs e) } } - private void MenuItem_Create_Click(object sender, RoutedEventArgs e) + private void MenuItem_Remove_TabItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) @@ -888,567 +820,657 @@ private void MenuItem_Create_Click(object sender, RoutedEventArgs e) return; } - if (menuItem.Tag == typeof(MechanicalSystemType)) + List viewSettingsList = GetViewSettings(menuItem); + if (viewSettingsList == null || viewSettingsList.Count() == 0) { - uIAnalyticalModel.CreateMechanicalSystem(null, windowHandle); return; } + + Modify.RemoveViewSettings(uIAnalyticalModel, viewSettingsList.ConvertAll(x => x.Guid)); } - private void MenuItem_Edit_Click(object sender, RoutedEventArgs e) + private void MenuItem_RemoveSpaceZone_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; - if(menuItem == null) + if (menuItem == null) { return; } - if (menuItem.Tag == typeof(IMaterial)) + IEnumerable enumerable = menuItem.Tag as IEnumerable; + if (enumerable == null) { - uIAnalyticalModel.EditMaterialLibrary(windowHandle); return; } - if (menuItem.Tag == typeof(Profile)) + foreach (object @object in enumerable) { - uIAnalyticalModel.EditProfileLibrary(windowHandle); - return; - } + Tuple tuple = @object as Tuple; + if (tuple == null) + { + continue; + } - if (menuItem.Tag == typeof(InternalCondition)) - { - uIAnalyticalModel.EditInternalConditions(windowHandle); - return; + Modify.RemoveSpaceZone(uIAnalyticalModel, tuple.Item2, tuple.Item1); } + } - List jSAMObjects = GetSAMObjects(menuItem); - if(jSAMObjects == null || jSAMObjects.Count == 0) + private void MenuItem_RenameSpaces_Click(object sender, RoutedEventArgs e) + { + List jSAMObjects = GetSAMObjects(sender as MenuItem); + if (jSAMObjects == null || jSAMObjects.Count == 0) { return; } - Edit(jSAMObjects[0]); - - + Modify.RenameSpaces(uIAnalyticalModel, jSAMObjects.FindAll(x => x is Space).Cast()); } - private void Edit(IJSAMObject jSAMObject) + private void MenuItem_Select_Click(object sender, RoutedEventArgs e) { - if (jSAMObject is Space) - { - UI.Modify.EditSpace(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); - } - else if (jSAMObject is Panel) - { - UI.Modify.EditPanel(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); - } - else if (jSAMObject is IMaterial) - { - UI.Modify.EditMaterial(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); - } - else if (jSAMObject is Profile) - { - UI.Modify.EditProfile(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); - } - else if (jSAMObject is Aperture) - { - UI.Modify.EditAperture(uIAnalyticalModel, jSAMObject as dynamic, windowHandle); - } - else if (jSAMObject is Zone) - { - Modify.EditZone(uIAnalyticalModel, jSAMObject as dynamic); - } - else if (jSAMObject is InternalCondition) + List jSAMObjects = GetSAMObjects(sender as MenuItem); + if (jSAMObjects == null || jSAMObjects.Count == 0) { - UI.Modify.EditInternalCondition(uIAnalyticalModel, jSAMObject as dynamic); + return; } + + SelectionRequested?.Invoke(this, new SelectionRequestedEventArgs(jSAMObjects?.FindAll(x => x is SAMObject).ConvertAll(x => (SAMObject)x))); } - public UIAnalyticalModel UIAnalyticalModel + private void MenuItem_Settings_TabItem_Click(object sender, RoutedEventArgs e) { - get + MenuItem menuItem = sender as MenuItem; + if (menuItem == null) { - return uIAnalyticalModel; + return; } - set + List viewSettingsList = GetViewSettings(menuItem); + if (viewSettingsList == null || viewSettingsList.Count() != 1) { - uIAnalyticalModel = value; - if (uIAnalyticalModel != null) - { - uIAnalyticalModel.Modified -= UIAnalyticalModel_Modified; - uIAnalyticalModel.Modified += UIAnalyticalModel_Modified; - - uIAnalyticalModel.Closed -= UIAnalyticalModel_Closed; - uIAnalyticalModel.Closed += UIAnalyticalModel_Closed; - - uIAnalyticalModel.Opened -= UIAnalyticalModel_Opened; - uIAnalyticalModel.Opened += UIAnalyticalModel_Opened; - } + return; } - } - private void UIAnalyticalModel_Modified(object sender, ModifiedEventArgs e) - { - LoadAnalyticalModel(uIAnalyticalModel?.JSAMObject, e); + Modify.EditViewSettings(uIAnalyticalModel, viewSettingsList[0].Guid); } - private void UIAnalyticalModel_Opened(object sender, OpenedEventArgs e) + private void MenuItem_Zoom_Click(object sender, RoutedEventArgs e) { - LoadAnalyticalModel(uIAnalyticalModel?.JSAMObject, e); - } + List jSAMObjects = GetSAMObjects(sender as MenuItem); + if (jSAMObjects == null || jSAMObjects.Count == 0) + { + return; + } - private void UIAnalyticalModel_Closed(object sender, ClosedEventArgs e) - { - LoadAnalyticalModel(uIAnalyticalModel?.JSAMObject, e); + ZoomRequested?.Invoke(this, new ZoomRequestedEventArgs(jSAMObjects?.FindAll(x => x is SAMObject).ConvertAll(x => (SAMObject)x))); } - private void LoadAnalyticalModel(AnalyticalModel analyticalModel, ModifiedEventArgs modifiedEventArgs) + private void treeView_Model_ContextMenuOpening(object sender, ContextMenuEventArgs e) { - LoadModel(analyticalModel); - LoadViews(analyticalModel); - } - + contextMenu_Model.Items.Clear(); - private void LoadModel(AnalyticalModel analyticalModel) - { - TreeView treeView_AnalyticalModel = treeView_Model; - if (treeView_AnalyticalModel == null) + TreeViewItem treeViewItem = e.Source as TreeViewItem; + if (treeViewItem == null) { + e.Handled = true; return; } - List expandedTags = GetExpandedTags(treeView_AnalyticalModel.Items); + if (treeViewItem.Tag is Type) + { + if (treeViewItem.Tag == typeof(MechanicalSystemType)) + { + MenuItem menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Create"; + menuItem.Header = "Create"; + menuItem.Click += MenuItem_Create_Click; + menuItem.Tag = typeof(MechanicalSystemType); + contextMenu_Model.Items.Add(menuItem); + } + } - treeView_AnalyticalModel.Items.Clear(); + List> tuples = null; - if (analyticalModel == null) + bool singleSelection = true; + if (treeViewHighlightManager_Model != null && treeViewHighlightManager_Model.Enabled) { - return; + List treeViewItems = treeViewHighlightManager_Model.HighlightedTreeViewItems; + if (treeViewItems != null && treeViewItems.Count != 0) + { + tuples = treeViewItems.FindAll(x => x?.Tag is IJSAMObject).ConvertAll(x => new Tuple(x, x.Tag as IJSAMObject)); + singleSelection = tuples != null && tuples.Count == 1; + } } - string name = analyticalModel.Name; - if (string.IsNullOrWhiteSpace(name)) + if (tuples == null || tuples.Count == 0) { - name = "???"; + IJSAMObject jSAMObject_Temp = treeViewItem.Tag as IJSAMObject; + if (jSAMObject_Temp != null) + { + tuples = new List>() { new Tuple(treeViewItem, jSAMObject_Temp) }; + } } - TreeViewItem treeViewItem_AnalyticalModel = new TreeViewItem() { Header = name, Tag = analyticalModel, AllowDrop = false }; - treeView_AnalyticalModel.Items.Add(treeViewItem_AnalyticalModel); - - TreeViewItem treeViewItem_Spaces = new TreeViewItem() { Header = "Spaces", Tag = typeof(Space), AllowDrop = false }; - treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Spaces); + if (tuples == null || tuples.Count == 0) + { + TreeViewItem treeViewItem_Parent = treeViewItem.Parent as TreeViewItem; - TreeViewItem treeViewItem_Shades = new TreeViewItem() { Header = "Shades", Tag = typeof(Panel), AllowDrop = false }; - treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Shades); + bool added = false; + if (treeViewItem_Parent.Tag == typeof(Zone)) + { + if (singleSelection) + { + MenuItem menuItem = new MenuItem(); + menuItem.Name = "MenuItem_EditZone"; + menuItem.Header = "Edit Zone"; + menuItem.Click += MenuItem_EditZone_Click; + menuItem.Tag = treeViewItem.Items == null || treeViewItem.Items.Count == 0 ? null : (treeViewItem.Items[0] as TreeViewItem)?.Tag; + contextMenu_Model.Items.Add(menuItem); + added = true; + } + } - TreeViewItem treeViewItem_Profiles = new TreeViewItem() { Header = "Profiles", Tag = typeof(Profile), AllowDrop = false }; - treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Profiles); + if (!added) + { + e.Handled = true; + } - TreeViewItem treeViewItem_Materials = new TreeViewItem() { Header = "Materials", Tag = typeof(IMaterial), AllowDrop = false }; - treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Materials); + return; + } - TreeViewItem treeViewItem_InternalConditions = new TreeViewItem() { Header = "Internal Conditions", Tag = typeof(InternalCondition), AllowDrop = false }; - treeViewItem_AnalyticalModel.Items.Add(treeViewItem_InternalConditions); - TreeViewItem treeViewItem_MechanicalSystems = new TreeViewItem() { Header = "Mechanical Systems", Tag = typeof(MechanicalSystemType), AllowDrop = false }; - treeViewItem_AnalyticalModel.Items.Add(treeViewItem_MechanicalSystems); + IJSAMObject jSAMObject = tuples[0].Item2; - TreeViewItem treeViewItem_Zones = new TreeViewItem() { Header = "Zones", Tag = typeof(Zone), AllowDrop = false }; - treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Zones); - AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster; - if (adjacencyCluster != null) + if (jSAMObject is Space) { - List spaces = adjacencyCluster.GetSpaces(); - if (spaces != null) - { - foreach (Space space in spaces) - { - TreeViewItem treeViewItem_Space = new TreeViewItem() { Header = space.Name, Tag = space, AllowDrop = true }; - treeViewItem_Spaces.Items.Add(treeViewItem_Space); - List panels_Space = adjacencyCluster.GetPanels(space); - if (panels_Space != null) - { - foreach (Panel panel in panels_Space) - { - TreeViewItem treeViewItem_Panel = new TreeViewItem() { Header = panel.Name, Tag = panel, AllowDrop = false}; - treeViewItem_Space.Items.Add(treeViewItem_Panel); + MenuItem menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Zoom"; + menuItem.Header = "Zoom"; + menuItem.Click += MenuItem_Zoom_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); - List apertures = panel.Apertures; - if (apertures != null) - { - foreach (Aperture aperture in apertures) - { - TreeViewItem treeViewItem_Aperture = new TreeViewItem() { Header = aperture.Name, Tag = aperture, AllowDrop = false }; - treeViewItem_Panel.Items.Add(treeViewItem_Aperture); - treeViewItem_Aperture.IsExpanded = expandedTags.Find(x => x is Aperture && ((Aperture)x).Guid == aperture.Guid) != null; - } - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Select"; + menuItem.Header = "Select"; + menuItem.Click += MenuItem_Select_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); - treeViewItem_Panel.IsExpanded = expandedTags.Find(x => x is Panel && ((Panel)x).Guid == panel.Guid) != null; - } - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_RenameSpaces"; + menuItem.Header = "Rename"; + menuItem.Click += MenuItem_RenameSpaces_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); - treeViewItem_Space.IsExpanded = expandedTags.Find(x => x is Space && ((Space)x).Guid == space.Guid) != null; - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_EditInternalConditions"; + menuItem.Header = "Modify IC"; + menuItem.Click += MenuItem_EditInternalConditions_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_AssignInternalCondition"; + menuItem.Header = "Assign IC"; + menuItem.Click += MenuItem_AssignInternalCondition_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_MapInternalConditions"; + menuItem.Header = "Map IC"; + menuItem.Click += MenuItem_MapInternalConditions_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + if (singleSelection) + { + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Edit"; + menuItem.Header = "Edit Space"; + menuItem.Click += MenuItem_Edit_Click; + menuItem.Tag = jSAMObject; + contextMenu_Model.Items.Add(menuItem); + + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_EditZone"; + menuItem.Header = "Edit Zone"; + menuItem.Click += MenuItem_EditSpaceZone_Click; + menuItem.Tag = tuples[0].Item1; + contextMenu_Model.Items.Add(menuItem); } - List panels = adjacencyCluster.GetPanels(); - if (panels != null) + List> tuples_Zone = new List>(); + foreach (Tuple tuple in tuples) { - foreach (Panel panel in panels) + if (!(tuple.Item2 is Space)) { - List spaces_Panel = adjacencyCluster.GetSpaces(panel); - if (spaces_Panel == null || spaces_Panel.Count == 0) - { - TreeViewItem treeViewItem_Shade = new TreeViewItem() { Header = panel.Name, Tag = panel, AllowDrop = false }; - treeViewItem_Shade.Tag = panel; - treeViewItem_Shade.IsExpanded = expandedTags.Find(x => x is Panel && ((Panel)x).Guid == panel.Guid) != null; + continue; + } - treeViewItem_Shades.Items.Add(treeViewItem_Shade); + TreeViewItem treeViewItem_Zone = treeViewItem.Parent as TreeViewItem; + if (treeViewItem_Zone != null) + { + Zone zone = treeViewItem_Zone.Tag as Zone; + if (zone != null) + { + tuples_Zone.Add(new Tuple(zone, (Space)tuple.Item2)); } } } - IEnumerable internalConditions = adjacencyCluster.GetInternalConditions(false, true); - if (internalConditions != null) + if (tuples_Zone != null && tuples_Zone.Count > 0) { - foreach (InternalCondition internalCondition in internalConditions) - { - TreeViewItem treeViewItem_InternalCondition = new TreeViewItem() { Header = internalCondition.Name, Tag = internalCondition, AllowDrop = false }; - treeViewItem_InternalCondition.MouseDoubleClick += TreeViewItem_MouseDoubleClick; - treeViewItem_InternalConditions.Items.Add(treeViewItem_InternalCondition); - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_RemoveSpaceZone"; + menuItem.Header = "Remove From Zone"; + menuItem.Click += MenuItem_RemoveSpaceZone_Click; + menuItem.Tag = tuples_Zone; + contextMenu_Model.Items.Add(menuItem); } - - List mechanicalSystemTypes = adjacencyCluster.GetMechanicalSystemTypes(); - if (mechanicalSystemTypes != null) + else { - foreach (MechanicalSystemType mechanicalSystemType in mechanicalSystemTypes) + foreach (Tuple tuple in tuples) { - TreeViewItem treeViewItem_MechanicalSystemType = new TreeViewItem() { Header = mechanicalSystemType.Name, Tag = mechanicalSystemType, AllowDrop = false}; - treeViewItem_MechanicalSystems.Items.Add(treeViewItem_MechanicalSystemType); - - List mechanicalSystems = adjacencyCluster.GetMechanicalSystems(mechanicalSystemType); - if(mechanicalSystems != null) + if (!(tuple.Item2 is Space)) { - foreach(MechanicalSystem mechanicalSystem in mechanicalSystems) - { - TreeViewItem treeViewItem_MechanicalSystem = new TreeViewItem() { Header = mechanicalSystem.FullName, Tag = mechanicalSystem, AllowDrop = false }; - treeViewItem_MechanicalSystemType.Items.Add(treeViewItem_MechanicalSystem); - } + continue; } - treeViewItem_MechanicalSystemType.IsExpanded = expandedTags.Find(x => x is MechanicalSystemType && ((MechanicalSystemType)x).Guid == mechanicalSystemType.Guid) != null; + tuples_Zone.Add(new Tuple(null, (Space)tuple.Item2)); } } - } - List profiles = analyticalModel.ProfileLibrary?.GetProfiles(); - if (profiles != null) + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_EditZones"; + menuItem.Header = "Edit Zones"; + menuItem.Click += MenuItem_EditZones_Click; + menuItem.Tag = tuples_Zone; + contextMenu_Model.Items.Add(menuItem); + } + else if (jSAMObject is Panel) { - foreach (Profile profile in profiles) + MenuItem menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Zoom"; + menuItem.Header = "Zoom"; + menuItem.Click += MenuItem_Zoom_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Select"; + menuItem.Header = "Select"; + menuItem.Click += MenuItem_Select_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + if (singleSelection) { - TreeViewItem treeViewItem_Profile = new TreeViewItem() { Header = profile.Name, Tag = profile, AllowDrop = false }; - treeViewItem_Profile.MouseDoubleClick += TreeViewItem_MouseDoubleClick; - treeViewItem_Profiles.Items.Add(treeViewItem_Profile); + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Edit"; + menuItem.Header = "Edit"; + menuItem.Click += MenuItem_Edit_Click; + menuItem.Tag = jSAMObject; + contextMenu_Model.Items.Add(menuItem); } - } - List materials = analyticalModel.MaterialLibrary?.GetMaterials(); - if (materials != null) + } + else if (jSAMObject is Aperture) { - foreach (IMaterial material in materials) + MenuItem menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Zoom"; + menuItem.Header = "Zoom"; + menuItem.Click += MenuItem_Zoom_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Select"; + menuItem.Header = "Select"; + menuItem.Click += MenuItem_Select_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + if (singleSelection) { - TreeViewItem treeViewItem_Material = new TreeViewItem() { Header = material.Name, Tag = material, AllowDrop = false }; - treeViewItem_Materials.Items.Add(treeViewItem_Material); + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Edit"; + menuItem.Header = "Edit"; + menuItem.Click += MenuItem_Edit_Click; + menuItem.Tag = jSAMObject; + contextMenu_Model.Items.Add(menuItem); } - } - List zones = adjacencyCluster?.GetZones(); - if(zones != null) + } + else if (jSAMObject is IMaterial) { - SortedDictionary> dictionary = new SortedDictionary>(); - foreach(Zone zone in zones) - { - if(zone == null) - { - continue; - } + MenuItem menuItem = null; - if(!zone.TryGetValue(ZoneParameter.ZoneCategory, out string zoneCategory) || string.IsNullOrWhiteSpace(zoneCategory)) - { - zoneCategory = "???"; - } + if (singleSelection) + { + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Edit"; + menuItem.Header = "Edit"; + menuItem.Click += MenuItem_Edit_Click; + menuItem.Tag = jSAMObject; + contextMenu_Model.Items.Add(menuItem); + } - if(!dictionary.TryGetValue(zoneCategory, out List zones_Temp)) - { - zones_Temp = new List(); - dictionary[zoneCategory] = zones_Temp; - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Remove"; + menuItem.Header = "Remove"; + menuItem.Click += MenuItem_Remove_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); - zones_Temp.Add(zone); + if (singleSelection) + { + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Duplicate"; + menuItem.Header = "Duplicate"; + menuItem.Click += MenuItem_Duplicate_Click; + menuItem.Tag = jSAMObject; + contextMenu_Model.Items.Add(menuItem); } - foreach(KeyValuePair> keyValuePair in dictionary) + } + else if (jSAMObject is Profile) + { + + if (singleSelection) { - TreeViewItem treeViewItem_ZoneCategory = new TreeViewItem() { Header = keyValuePair.Key, Tag = keyValuePair.Key, AllowDrop = false }; - treeViewItem_Zones.Items.Add(treeViewItem_ZoneCategory); + MenuItem menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Edit"; + menuItem.Header = "Edit"; + menuItem.Click += MenuItem_Edit_Click; + menuItem.Tag = jSAMObject; + contextMenu_Model.Items.Add(menuItem); + } + } + else if (jSAMObject is Zone) + { + MenuItem menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Zoom"; + menuItem.Header = "Zoom"; + menuItem.Click += MenuItem_Zoom_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); - treeViewItem_ZoneCategory.IsExpanded = expandedTags.Find(x => x is string && (string)x == keyValuePair.Key) != null; + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Select"; + menuItem.Header = "Select"; + menuItem.Click += MenuItem_Select_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); - foreach (Zone zone in keyValuePair.Value) - { - TreeViewItem treeViewItem_Zone = new TreeViewItem() { Header = zone.Name, Tag = zone, AllowDrop = true }; - treeViewItem_ZoneCategory.Items.Add(treeViewItem_Zone); + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Remove"; + menuItem.Header = "Remove"; + menuItem.Click += MenuItem_Remove_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); - treeViewItem_Zone.IsExpanded = expandedTags.Find(x => x is Zone && ((Zone)x).Guid == zone.Guid) != null; + if (singleSelection) + { + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Edit"; + menuItem.Header = "Edit"; + menuItem.Click += MenuItem_Edit_Click; + menuItem.Tag = jSAMObject; + contextMenu_Model.Items.Add(menuItem); + } + } + else if (jSAMObject is InternalCondition) + { + if (singleSelection) + { + MenuItem menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Edit"; + menuItem.Header = "Edit"; + menuItem.Click += MenuItem_Edit_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Duplicate"; + menuItem.Header = "Duplicate"; + menuItem.Click += MenuItem_Duplicate_Click; + menuItem.Tag = jSAMObject; + contextMenu_Model.Items.Add(menuItem); + + } + } + else if (jSAMObject is MechanicalSystem) + { + MenuItem menuItem = null; + + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Remove"; + menuItem.Header = "Remove"; + menuItem.Click += MenuItem_Remove_Click; + menuItem.Tag = tuples.ConvertAll(x => x.Item2); + contextMenu_Model.Items.Add(menuItem); + + if (singleSelection) + { - List spaces = adjacencyCluster.GetRelatedObjects(zone); - if(spaces != null && spaces.Count != 0) - { - foreach(Space space in spaces) - { - TreeViewItem treeViewItem_Space = new TreeViewItem() { Header = space.Name, Tag = space, AllowDrop = true }; - treeViewItem_Zone.Items.Add(treeViewItem_Space); - } - } - } } } - - treeViewItem_AnalyticalModel.IsExpanded = true; - if (expandedTags != null && expandedTags.Count != 0) + else { - treeViewItem_Spaces.IsExpanded = expandedTags.Contains(treeViewItem_Spaces.Tag); - treeViewItem_Shades.IsExpanded = expandedTags.Contains(treeViewItem_Shades.Tag); - treeViewItem_Profiles.IsExpanded = expandedTags.Contains(treeViewItem_Profiles.Tag); - treeViewItem_Materials.IsExpanded = expandedTags.Contains(treeViewItem_Materials.Tag); - treeViewItem_InternalConditions.IsExpanded = expandedTags.Contains(treeViewItem_InternalConditions.Tag); - treeViewItem_MechanicalSystems.IsExpanded = expandedTags.Contains(treeViewItem_MechanicalSystems.Tag); - treeViewItem_Zones.IsExpanded = expandedTags.Contains(treeViewItem_Zones.Tag); + e.Handled = true; + return; } } - private void TreeViewItem_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) + private void treeView_Model_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { - TreeViewItem treeViewItem = sender as TreeViewItem; - if(treeViewItem == null) + DependencyObject dependencyObject = Core.UI.WPF.Query.DependencyObject(treeView_Model, e.GetPosition(treeView_Model)); + if (dependencyObject == null) { return; } - IAnalyticalObject analyticalObject = treeViewItem.Tag as IAnalyticalObject; - if(analyticalObject == null) + TreeViewItem treeViewItem = Core.UI.WPF.Query.ParentDependencyObject(dependencyObject); + + object @object = treeViewItem?.Tag; + if (@object == null || !(@object is ISAMObject)) { return; } - if(analyticalObject is InternalCondition) - { - UI.Modify.EditInternalCondition(uIAnalyticalModel, (InternalCondition)analyticalObject); - } - else if(analyticalObject is Profile) - { - UI.Modify.EditProfile(uIAnalyticalModel, (Profile)analyticalObject); - } + Edit(@object as ISAMObject); } - private void LoadViews(AnalyticalModel analyticalModel) + private void treeView_Views_ContextMenuOpening(object sender, ContextMenuEventArgs e) { - if (treeView_Views == null) + contextMenu_Views.Items.Clear(); + + TreeViewItem treeViewItem = e.Source as TreeViewItem; + if (treeViewItem == null) { + e.Handled = true; return; } - treeView_Views.Items.Clear(); + List jSAMObjects = null; - if (analyticalModel == null) + if (treeViewItem.Tag is ViewSettings) + { + jSAMObjects = new List() { (ViewSettings)treeViewItem.Tag }; + } + else if (treeViewItem.Tag is string) + { + jSAMObjects = new List(); + foreach (object @object in treeViewItem.Items) + { + ViewSettings viewSettings_Temp = (@object as TreeViewItem)?.Tag as ViewSettings; + if (viewSettings_Temp == null) + { + continue; + } + + jSAMObjects.Add(viewSettings_Temp); + } + } + + if (jSAMObjects == null || jSAMObjects.Count == 0) { + e.Handled = true; return; } - string name = analyticalModel.Name; - if (string.IsNullOrWhiteSpace(name)) + List treeViewItems = treeViewHighlightManager_Views != null && treeViewHighlightManager_Views.Enabled ? treeViewHighlightManager_Views.HighlightedTreeViewItems : null; + if (treeViewItems != null && treeViewItems.Count != 0) { - name = "???"; + jSAMObjects = new List(treeViewItems.FindAll(x => x?.Tag is ViewSettings).ConvertAll(x => x.Tag as ViewSettings)); } - TreeViewItem treeViewItem_AnalyticalModel = new TreeViewItem() { Header = name, Tag = analyticalModel, AllowDrop = false }; - treeView_Views.Items.Add(treeViewItem_AnalyticalModel); + MenuItem menuItem = null; - TreeViewItem treeViewItem_Views = new TreeViewItem() { Header = "Views", Tag = typeof(ViewSettings), AllowDrop = true }; - treeViewItem_AnalyticalModel.Items.Add(treeViewItem_Views); + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Open_TabItem"; + menuItem.Header = "Open"; + menuItem.Click += MenuItem_Open_TabItem_Click; + menuItem.Tag = jSAMObjects; + contextMenu_Views.Items.Add(menuItem); - if (!analyticalModel.TryGetValue(AnalyticalModelParameter.UIGeometrySettings, out UIGeometrySettings uIGeometrySettings) || uIGeometrySettings == null) - { - return; - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Close_TabItem"; + menuItem.Header = "Close"; + menuItem.Click += MenuItem_Close_TabItem_Click; + menuItem.Tag = jSAMObjects; + contextMenu_Views.Items.Add(menuItem); - Dictionary dictionary = new Dictionary(); + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Remove_TabItem"; + menuItem.Header = "Remove"; + menuItem.Click += MenuItem_Remove_TabItem_Click; + menuItem.Tag = jSAMObjects; + contextMenu_Views.Items.Add(menuItem); - List viewSettingsList = uIGeometrySettings.GetViewSettings(); - foreach(ViewSettings viewSettings in viewSettingsList) + if (jSAMObjects.Count == 1) { - string name_Temp = viewSettings.Name; - if(string.IsNullOrWhiteSpace(name_Temp)) - { - name_Temp = Query.DefaultName(viewSettings); - } - - if(string.IsNullOrWhiteSpace(name_Temp)) - { - name_Temp = "???"; - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Duplicate_TabItem"; + menuItem.Header = "Duplicate"; + menuItem.Click += MenuItem_Duplicate_TabItem_Click; + menuItem.Tag = jSAMObjects; + contextMenu_Views.Items.Add(menuItem); - TreeViewItem treeViewItem_ViewSettings = new TreeViewItem() { Header = name_Temp, Tag = viewSettings, AllowDrop = false }; - treeViewItem_ViewSettings.PreviewMouseDoubleClick += TreeViewItem_ViewSettings_PreviewMouseDoubleClick; - - if(viewSettings.TryGetValue(ViewSettingsParameter.Group, out string group) && !string.IsNullOrWhiteSpace(group)) - { - if(!dictionary.TryGetValue(group, out TreeViewItem treeViewItem) || treeViewItem == null) - { - treeViewItem = new TreeViewItem() { Header = group, Tag = group, AllowDrop = true }; - dictionary[group] = treeViewItem; - treeViewItem_Views.Items.Add(treeViewItem); - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_LoadView_TabItem"; + menuItem.Header = "Load view"; + menuItem.Click += MenuItem_LoadView_Click; + menuItem.Tag = jSAMObjects; + contextMenu_Views.Items.Add(menuItem); - treeViewItem.Items.Add(treeViewItem_ViewSettings); - } - else - { - treeViewItem_Views.Items.Add(treeViewItem_ViewSettings); - } + menuItem = new MenuItem(); + menuItem.Name = "MenuItem_Settings_TabItem"; + menuItem.Header = "Settings"; + menuItem.Click += MenuItem_Settings_TabItem_Click; + menuItem.Tag = jSAMObjects; + contextMenu_Views.Items.Add(menuItem); } - treeViewItem_AnalyticalModel.ExpandSubtree(); + contextMenu_Views.IsOpen = true; } - private void TreeViewItem_ViewSettings_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) + private void MenuItem_LoadView_Click(object sender, RoutedEventArgs e) { - TreeViewItem treeViewItem = sender as TreeViewItem; - if (treeViewItem == null) + MenuItem menuItem = sender as MenuItem; + if (menuItem == null) { return; } - ViewSettings viewSettings = treeViewItem.Tag as ViewSettings; + ViewSettings viewSettings = menuItem.Tag as ViewSettings; if (viewSettings == null) { return; } - Modify.EnableViewSettings(uIAnalyticalModel, viewSettings.Guid, true); - Modify.ActivateViewSettings(uIAnalyticalModel, viewSettings.Guid); + Modify.CopyViewSettings(uIAnalyticalModel, viewSettings.Guid); } - private List GetExpandedTags(ItemCollection itemCollection) + private void TreeViewHighlightManager_Model_TreeViewItemHighlighted(object sender, TreeViewItemHighlightedEventArgs e) { - if (itemCollection == null) - { - return null; - } - - List result = new List(); - - foreach (TreeViewItem treeViewItem in itemCollection) - { - if (treeViewItem.IsExpanded) - { - result.Add(treeViewItem.Tag); - List expandedTags = GetExpandedTags(treeViewItem.Items); - if (expandedTags != null) - { - result.AddRange(expandedTags); - } - } - } - - return result; + Modify.AllowTreeViewItemByType(e); } - private void UserControl_Loaded(object sender, RoutedEventArgs e) + private void TreeViewHighlightManager_Views_TreeViewItemHighlighted(object sender, TreeViewItemHighlightedEventArgs e) { - System.Windows.Window window = Geometry.UI.WPF.Query.Window(this); - if(window != null) - { - windowHandle = new Core.Windows.WindowHandle(window); - } + Modify.AllowTreeViewItemByType(e, typeof(ViewSettings)); } - - private static List GetViewSettings(MenuItem menuItem) + + private void TreeViewItem_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if(menuItem == null) + TreeViewItem treeViewItem = sender as TreeViewItem; + if (treeViewItem == null) { - return null; + return; } - List result = new List(); - - IEnumerable enumerable = menuItem.Tag as IEnumerable; - if (enumerable != null) + IAnalyticalObject analyticalObject = treeViewItem.Tag as IAnalyticalObject; + if (analyticalObject == null) { - result = enumerable.OfType()?.ToList(); + return; } - if (result == null || result.Count() == 0) + if (analyticalObject is InternalCondition) { - ViewSettings viewSettings = menuItem.Tag as ViewSettings; - if (viewSettings != null) - { - result = new List() { viewSettings }; - } + UI.Modify.EditInternalCondition(uIAnalyticalModel, (InternalCondition)analyticalObject); + } + else if (analyticalObject is Profile) + { + UI.Modify.EditProfile(uIAnalyticalModel, (Profile)analyticalObject); } - - return result; } - private static List GetSAMObjects(MenuItem menuItem) + private void TreeViewItem_ViewSettings_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if (menuItem == null) + TreeViewItem treeViewItem = sender as TreeViewItem; + if (treeViewItem == null) { - return null; + return; } - List result = null; - if (menuItem.Tag is IEnumerable) - { - result = new List(); - foreach (object @object in (IEnumerable)menuItem.Tag) - { - if (@object is IJSAMObject) - { - result.Add((IJSAMObject)@object); - } - } - } - else if (menuItem.Tag is IJSAMObject) + ViewSettings viewSettings = treeViewItem.Tag as ViewSettings; + if (viewSettings == null) { - result = new List() { (IJSAMObject)menuItem.Tag }; + return; } - return result; + Modify.EnableViewSettings(uIAnalyticalModel, viewSettings.Guid, true); + Modify.ActivateViewSettings(uIAnalyticalModel, viewSettings.Guid); } - private void treeView_Model_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) + private void UIAnalyticalModel_Closed(object sender, ClosedEventArgs e) { - DependencyObject dependencyObject = Core.UI.WPF.Query.DependencyObject(treeView_Model, e.GetPosition(treeView_Model)); - if(dependencyObject == null) - { - return; - } + LoadAnalyticalModel(uIAnalyticalModel?.JSAMObject, e); + } - TreeViewItem treeViewItem = Core.UI.WPF.Query.ParentDependencyObject(dependencyObject); + private void UIAnalyticalModel_Modified(object sender, ModifiedEventArgs e) + { + LoadAnalyticalModel(uIAnalyticalModel?.JSAMObject, e); + } - object @object = treeViewItem?.Tag; - if(@object == null || !(@object is ISAMObject)) + private void UIAnalyticalModel_Opened(object sender, OpenedEventArgs e) + { + LoadAnalyticalModel(uIAnalyticalModel?.JSAMObject, e); + } + + private void UserControl_Loaded(object sender, RoutedEventArgs e) + { + System.Windows.Window window = Geometry.UI.WPF.Query.Window(this); + if(window != null) { - return; + windowHandle = new Core.Windows.WindowHandle(window); } - - Edit(@object as ISAMObject); } } } diff --git a/WPF/SAM.Analytical.UI.WPF/Controls/CreateCaseByApertureConstructionControl.xaml.cs b/WPF/SAM.Analytical.UI.WPF/Controls/CreateCaseByApertureConstructionControl.xaml.cs index 110f5af6..f65b11e0 100644 --- a/WPF/SAM.Analytical.UI.WPF/Controls/CreateCaseByApertureConstructionControl.xaml.cs +++ b/WPF/SAM.Analytical.UI.WPF/Controls/CreateCaseByApertureConstructionControl.xaml.cs @@ -188,7 +188,7 @@ private void button_Selection_Click(object sender, RoutedEventArgs e) List? jSAMObjects = adjacencyCluster?.GetApertures()?.ConvertAll(x => x as IJSAMObject); - FilterWindow filterWindow = new FilterWindow() { Types = [typeof(Aperture)], Type = typeof(Aperture), UIFilter = uIFilter, UIFilters = null, JSAMObjects = jSAMObjects, AdjacencyCluster = adjacencyCluster }; + FilterWindow filterWindow = new FilterWindow() { Types = [typeof(Aperture)], Type = typeof(Aperture), UIFilter = uIFilter, UIFilters = null, JSAMObjects = jSAMObjects, AnalyticalModel = analyticalModel }; filterWindow.FilterAdding += FilterWindow_FilterAdding; bool? result = filterWindow.ShowDialog(); if (result == null || !result.HasValue || !result.Value) diff --git a/WPF/SAM.Analytical.UI.WPF/Controls/CreateCaseByApertureControl.xaml b/WPF/SAM.Analytical.UI.WPF/Controls/CreateCaseByApertureControl.xaml index ee615c63..671d0593 100644 --- a/WPF/SAM.Analytical.UI.WPF/Controls/CreateCaseByApertureControl.xaml +++ b/WPF/SAM.Analytical.UI.WPF/Controls/CreateCaseByApertureControl.xaml @@ -23,7 +23,9 @@ - + + + diff --git a/WPF/SAM.Analytical.UI.WPF/Windows/SelectLevelsWindow.xaml.cs b/WPF/SAM.Analytical.UI.WPF/Windows/SelectLevelsWindow.xaml.cs new file mode 100644 index 00000000..70cf29b3 --- /dev/null +++ b/WPF/SAM.Analytical.UI.WPF/Windows/SelectLevelsWindow.xaml.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using System.Windows; + +namespace SAM.Analytical.UI.WPF +{ + /// + /// Interaction logic for SelectLevelsWindow.xaml + /// + public partial class SelectLevelsWindow : System.Windows.Window + { + public SelectLevelsWindow() + { + InitializeComponent(); + } + + private void button_OK_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + Close(); + } + + private void button_Cancel_Click(object sender, RoutedEventArgs e) + { + DialogResult = false; + Close(); + } + + public void SetLevels(IEnumerable levels) + { + SelectLevelsControl_Main.SetLevels(levels?.ToList(), false); + SelectLevelsControl_Main.SetLevels(levels?.ToList(), true); + } + + public List GetLevels() + { + return SelectLevelsControl_Main.GetLevels(true); + } + } +} diff --git a/WPF/SAM.Analytical.UI.WPF/Windows/SolverWindow.xaml b/WPF/SAM.Analytical.UI.WPF/Windows/SolverWindow.xaml new file mode 100644 index 00000000..dd3134e8 --- /dev/null +++ b/WPF/SAM.Analytical.UI.WPF/Windows/SolverWindow.xaml @@ -0,0 +1,18 @@ + + + + + + + + +