diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index eca0856bc..57c812370 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -28,12 +28,14 @@
-
+
-
-
-
-
+
+
+
+
+
+
@@ -74,7 +76,7 @@
@@ -185,14 +187,14 @@
+
-
-
+
@@ -668,8 +670,8 @@
-
+
@@ -1381,6 +1383,7 @@
+
1656059954202
@@ -1725,7 +1728,7 @@
1698766404661
-
+
@@ -1759,8 +1762,6 @@
-
-
@@ -1784,7 +1785,9 @@
-
+
+
+
@@ -2296,11 +2299,11 @@
-
+
-
+
@@ -2336,13 +2339,13 @@
-
+
-
+
@@ -2374,23 +2377,23 @@
-
-
+
+
-
+
-
+
@@ -2403,8 +2406,8 @@
-
+
@@ -2431,8 +2434,8 @@
-
+
@@ -2648,7 +2651,7 @@
-
+
@@ -2718,7 +2721,7 @@
-
+
diff --git a/src/GridCal/Gui/Main/SubClasses/Results/results.py b/src/GridCal/Gui/Main/SubClasses/Results/results.py
index c021be698..6e056ecaf 100644
--- a/src/GridCal/Gui/Main/SubClasses/Results/results.py
+++ b/src/GridCal/Gui/Main/SubClasses/Results/results.py
@@ -22,7 +22,7 @@
import GridCal.Gui.gui_functions as gf
from GridCal.Gui.messages import error_msg, warning_msg
from GridCal.Gui.Main.SubClasses.simulations import SimulationsMain
-from GridCal.Session.results_model import ResultsModel
+from GridCal.Gui.results_model import ResultsModel
from GridCal.Gui.general_dialogues import fill_tree_from_logs
import GridCalEngine.Utils.Filtering as flt
from GridCalEngine.basic_structures import Logger
diff --git a/src/GridCal/Gui/SigmaAnalysis/sigma_analysis_dialogue.py b/src/GridCal/Gui/SigmaAnalysis/sigma_analysis_dialogue.py
index 22d828d7f..347fd9ed7 100644
--- a/src/GridCal/Gui/SigmaAnalysis/sigma_analysis_dialogue.py
+++ b/src/GridCal/Gui/SigmaAnalysis/sigma_analysis_dialogue.py
@@ -19,7 +19,7 @@
from PySide6 import QtWidgets
from GridCal.Gui.SigmaAnalysis.gui import Ui_MainWindow
-from GridCal.Session.results_model import ResultsModel
+from GridCal.Gui.results_model import ResultsModel
from GridCalEngine.enumerations import ResultTypes
from GridCalEngine.Simulations.SigmaAnalysis.sigma_analysis_driver import SigmaAnalysisResults
diff --git a/src/GridCal/Session/results_model.py b/src/GridCal/Gui/results_model.py
similarity index 100%
rename from src/GridCal/Session/results_model.py
rename to src/GridCal/Gui/results_model.py
diff --git a/src/GridCal/Session/session.py b/src/GridCal/Session/session.py
index 8154b0608..8e17348d4 100644
--- a/src/GridCal/Session/session.py
+++ b/src/GridCal/Session/session.py
@@ -60,7 +60,7 @@
from GridCalEngine.enumerations import ResultTypes, SimulationTypes
from GridCalEngine.Simulations.types import DRIVER_OBJECTS, RESULTS_OBJECTS
from GridCalEngine.basic_structures import Logger
-from GridCal.Session.results_model import ResultsModel
+from GridCal.Gui.results_model import ResultsModel
class GcThread(QThread):
diff --git a/src/GridCalEngine/Devices/assets.py b/src/GridCalEngine/Devices/assets.py
index f60dfad40..fc1b32618 100644
--- a/src/GridCalEngine/Devices/assets.py
+++ b/src/GridCalEngine/Devices/assets.py
@@ -4305,6 +4305,16 @@ def get_injection_devices(self) -> List[INJECTION_DEVICE_TYPES]:
elms += lst
return elms
+ def injection_items(self) -> Generator[INJECTION_DEVICE_TYPES, None, None]:
+ """
+ Get a list of all devices that can inject or subtract power from a node
+ :return: List of EditableDevice
+ """
+ for lst in self.get_injection_devices_lists():
+ for elm in lst:
+ yield elm
+
+
# ------------------------------------------------------------------------------------------------------------------
# Load-like devices
# ------------------------------------------------------------------------------------------------------------------
diff --git a/src/GridCalEngine/Devices/multi_circuit.py b/src/GridCalEngine/Devices/multi_circuit.py
index 40f7a1538..4cdff5dae 100644
--- a/src/GridCalEngine/Devices/multi_circuit.py
+++ b/src/GridCalEngine/Devices/multi_circuit.py
@@ -1395,41 +1395,76 @@ def get_injection_devices_grouped_by_group_type(
devices_by_type = dict()
- for lst in self.get_injection_devices_lists():
+ for elm in self.injection_items():
- for elm in lst:
-
- if group_type == DeviceType.AreaDevice:
+ if group_type == DeviceType.AreaDevice:
+ if elm.bus.area is not None:
matches = elm.bus.area == group_device
+ else:
+ matches = False
- elif group_type == DeviceType.ZoneDevice:
+ elif group_type == DeviceType.ZoneDevice:
+ if elm.bus.zone is not None:
matches = elm.bus.zone == group_device
+ else:
+ matches = False
- elif group_type == DeviceType.SubstationDevice:
+ elif group_type == DeviceType.SubstationDevice:
+ if elm.bus.substation is not None:
matches = elm.bus.substation == group_device
+ else:
+ matches = False
- elif group_type == DeviceType.CountryDevice:
- matches = ((elm.bus.country == group_device) or
- (elm.bus.substation.country == group_device))
-
- elif group_type == DeviceType.CommunityDevice:
- matches = (elm.bus.substation.community == group_device)
+ elif group_type == DeviceType.CountryDevice:
+ if elm.bus.substation is not None:
+ matches = elm.bus.substation.country == group_device
- elif group_type == DeviceType.RegionDevice:
- matches = elm.bus.substation.region == group_device
+ if elm.bus.country is not None:
+ if elm.bus.substation.country != elm.bus.country:
+ print(f"Bus <{elm.bus.name}> country is different from its substation country :/")
+ else:
+ if elm.bus.country is not None:
+ matches = elm.bus.country == group_device
+ else:
+ matches = False
- elif group_type == DeviceType.MunicipalityDevice:
- matches = elm.bus.substation.municipality == group_device
+ elif group_type == DeviceType.CommunityDevice:
+ if elm.bus.substation is not None:
+ if elm.bus.substation.community is not None:
+ matches = elm.bus.substation.community == group_device
+ else:
+ matches = False
+ else:
+ matches = False
+ elif group_type == DeviceType.RegionDevice:
+ if elm.bus.substation is not None:
+ if elm.bus.substation.region is not None:
+ matches = elm.bus.substation.region == group_device
+ else:
+ matches = False
else:
matches = False
- if matches:
- lst = devices_by_type.get(elm.device_type, None)
- if lst is None:
- devices_by_type[elm.device_type] = [elm]
+ elif group_type == DeviceType.MunicipalityDevice:
+ if elm.bus.substation is not None:
+ if elm.bus.substation.municipality is not None:
+ matches = elm.bus.substation.municipality == group_device
else:
- devices_by_type[elm.device_type].append(elm)
+ matches = False
+ else:
+ matches = False
+
+ else:
+ matches = False
+
+ # if we found a match ...
+ if matches:
+ lst = devices_by_type.get(elm.device_type, None)
+ if lst is None:
+ devices_by_type[elm.device_type] = [elm]
+ else:
+ devices_by_type[elm.device_type].append(elm)
result.append(devices_by_type)