Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/workspace.xml
#	src/GridCal/__version__.py
#	src/GridCalEngine/__version__.py
#	src/GridCalServer/__version__.py
  • Loading branch information
SanPen committed Oct 1, 2024
2 parents 1e270fb + a0c30f3 commit 3a42737
Show file tree
Hide file tree
Showing 22 changed files with 371 additions and 214 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ networkx>=2.1
pandas>=1.1
xlwt>=1.3.0
xlrd>=1.1.0
ortools>=9.8.0, <=9.9.3963
ortools>=9.10.0,
matplotlib>=2.1.1
qtconsole>=4.3.1
openpyxl>=2.4.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def add_segment(self, segment: MapLineSegment):
"""
self.segments_list.append(segment)

def set_colour(self, color: QColor, w, style: Qt.PenStyle, tool_tip: str = '') -> None:
def set_colour(self, color: QColor, style: Qt.PenStyle, tool_tip: str = '') -> None:
"""
Set color and style
:param color: QColor instance
Expand All @@ -133,7 +133,7 @@ def set_colour(self, color: QColor, w, style: Qt.PenStyle, tool_tip: str = '') -
"""
for segment in self.segments_list:
segment.setToolTip(tool_tip)
segment.set_colour(color=color, w=w, style=style)
segment.set_colour(color=color, style=style)

def update_connectors(self) -> None:
"""
Expand Down
17 changes: 8 additions & 9 deletions src/GridCal/Gui/Diagrams/MapWidget/Branches/map_line_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, first: NodeGraphicItem, second: NodeGraphicItem, container: M
self.first.add_position_change_callback(self.set_from_side_coordinates)
self.second.add_position_change_callback(self.set_to_side_coordinates)

self.set_colour(self.color, self.width, self.style)
self.set_colour(self.color, self.style)
self.update_endings()
self.needsUpdate = True
self.setZValue(0)
Expand Down Expand Up @@ -115,7 +115,7 @@ def set_width(self, width: float):
self.arrow_p_to.label.setScale(width)
self.arrow_q_to.label.setScale(width)

def set_colour(self, color: QColor, w: float, style: Qt.PenStyle):
def set_colour(self, color: QColor, style: Qt.PenStyle):
"""
Set color and style
:param color: QColor instance
Expand All @@ -124,14 +124,13 @@ def set_colour(self, color: QColor, w: float, style: Qt.PenStyle):
:return:
"""

pen = QPen(color, w, style, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin)
pen.setWidthF(w)
pen = QPen(color, self.width, style, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin)

self.setPen(pen)
self.arrow_p_from.set_colour(color, w, style)
self.arrow_q_from.set_colour(color, w, style)
self.arrow_p_to.set_colour(color, w, style)
self.arrow_q_to.set_colour(color, w, style)
self.arrow_p_from.set_colour(color, self.arrow_p_from.w, style)
self.arrow_q_from.set_colour(color, self.arrow_q_from.w, style)
self.arrow_p_to.set_colour(color, self.arrow_p_to.w, style)
self.arrow_q_to.set_colour(color, self.arrow_q_to.w, style)

def set_from_side_coordinates(self, x: float, y: float):
"""
Expand Down Expand Up @@ -286,7 +285,7 @@ def set_enable(self, val=True):
self.color = OTHER['color']

# Set pen for everyone
self.set_colour(self.color, self.width, self.style)
self.set_colour(self.color, self.style)

def enable_disable_label_drawing(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def __init__(self,
self.setAcceptHoverEvents(True)

# Allow selecting the node
self.setFlag(self.GraphicsItemFlag.ItemIsSelectable | QGraphicsRectItem.ItemIsMovable)
self.setFlag(self.GraphicsItemFlag.ItemIsSelectable | self.GraphicsItemFlag.ItemIsMovable)

self.setCursor(QCursor(Qt.PointingHandCursor))
self.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))

# Create a pen with reduced line width
self.change_pen_width(0.5)
Expand All @@ -113,6 +113,7 @@ def set_size(self, r: float):
rect = self.rect()
rect.setWidth(r)
rect.setHeight(r)
self.radius = r

# change the width and height while keeping the same center
r2 = r / 2
Expand All @@ -121,16 +122,30 @@ def set_size(self, r: float):

# Set the new rectangle with the updated dimensions
self.setRect(new_x, new_y, r, r)
self.radius = r

# update the callbacks position for the lines to move accordingly
self.set_callabacks(new_x + r2, new_y + r2)

for vl_graphics in self.voltage_level_graphics:
vl_graphics.center_on_substation()

self.update_diagram()

def set_api_object_color(self):
def resize_voltage_levels(self):
"""
:return:
"""
max_vl = 1.0 # 1 KV
for vl_graphics in self.voltage_level_graphics:
max_vl = max(max_vl, vl_graphics.api_object.Vnom)

for vl_graphics in self.voltage_level_graphics:
# radius here is the width, therefore we need to send W/2
scale = vl_graphics.api_object.Vnom / max_vl * 0.5
vl_graphics.set_size(r=self.radius * scale)

def set_api_object_color(self) -> None:
"""
Gather the API object color and update this objects
"""
Expand Down Expand Up @@ -169,12 +184,20 @@ def sort_voltage_levels(self) -> None:
"""
Set the Zorder based on the voltage level voltage
"""
# TODO: Check this
sorted_objects = sorted(self.voltage_level_graphics, key=lambda x: x.api_object.Vnom)
max_vl = 1.0 # 1 KV
for vl_graphics in self.voltage_level_graphics:
max_vl = max(max_vl, vl_graphics.api_object.Vnom)

for vl_graphics in self.voltage_level_graphics:
scale = vl_graphics.api_object.Vnom / max_vl * 0.8
vl_graphics.set_size(r=self.radius * scale)
vl_graphics.center_on_substation()

sorted_objects = sorted(self.voltage_level_graphics, key=lambda x: -x.api_object.Vnom)
for i, vl_graphics in enumerate(sorted_objects):
vl_graphics.setZValue(i)

def update_diagram(self):
def update_diagram(self) -> None:
"""
Updates the element position in the diagram (to save)
:return:
Expand Down Expand Up @@ -246,7 +269,7 @@ def hoverEnterEvent(self, event: QtWidgets.QGraphicsSceneHoverEvent) -> None:
# self.editor.map.view.in_item = True
self.set_color(self.hoover_color, self.color)
self.hovered = True
QApplication.instance().setOverrideCursor(Qt.PointingHandCursor)
QApplication.instance().setOverrideCursor(Qt.CursorShape.PointingHandCursor)

def hoverLeaveEvent(self, event: QtWidgets.QGraphicsSceneHoverEvent) -> None:
"""
Expand All @@ -266,34 +289,39 @@ def contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent):

add_menu_entry(menu=menu,
text="Add voltage level",
icon_path="",
icon_path=":/Icons/icons/plus.svg",
function_ptr=self.add_voltage_level)

add_menu_entry(menu=menu,
text="Create line from here",
icon_path="",
icon_path=":/Icons/icons/plus.svg",
function_ptr=self.create_new_line)

add_menu_entry(menu=menu,
text="Move to API coordinates",
icon_path="",
text="Set coordinates to DB",
icon_path=":/Icons/icons/down.svg",
function_ptr=self.move_to_api_coordinates)

add_menu_entry(menu=menu,
text="Remove",
icon_path="",
text="Remove from schematic",
icon_path=":/Icons/icons/delete_schematic.svg",
function_ptr=self.remove_function)

add_menu_entry(menu=menu,
text="ADD node",
icon_path=":/Icons/icons/divide.svg",
function_ptr=self.add_function)
# add_menu_entry(menu=menu,
# text="ADD node",
# icon_path=":/Icons/icons/plus.svg",
# function_ptr=self.add_function)

add_menu_entry(menu=menu,
text="Show diagram",
icon_path="",
icon_path=":/Icons/icons/grid_icon.svg",
function_ptr=self.new_substation_diagram)

add_menu_entry(menu=menu,
text="Plot",
icon_path=":/Icons/icons/plot.svg",
function_ptr=self.plot)

menu.exec_(event.screenPos())

def create_new_line(self):
Expand Down Expand Up @@ -343,7 +371,7 @@ def remove_function(self) -> None:
"Remove substation graphics")

if ok:
self.editor.removeSubstation(self)
self.editor.removeSubstation(substation=self)

def move_to_api_coordinates(self):
"""
Expand All @@ -364,6 +392,13 @@ def new_substation_diagram(self):
"""
self.editor.new_substation_diagram(substation=self.api_object)

def plot(self):
"""
Plot the substations data
"""
i = self.editor.circuit.get_substations().index(self.api_object)
self.editor.plot_substation(i, self.api_object)

def add_voltage_level(self) -> None:
"""
Add Voltage Level
Expand Down Expand Up @@ -392,9 +427,8 @@ def add_voltage_level(self) -> None:

self.editor.circuit.add_voltage_level(vl)
self.editor.circuit.add_bus(obj=bus)

self.editor.add_api_voltage_level(substation_graphics=self,
api_object=vl)
self.editor.add_api_voltage_level(substation_graphics=self, api_object=vl)
self.sort_voltage_levels()

def set_color(self, inner_color: QColor = None, border_color: QColor = None) -> None:
"""
Expand Down Expand Up @@ -433,14 +467,6 @@ def getPos(self) -> QPointF:

return center_point

# def resize(self, new_radius: float) -> None:
# """
# Resize the node.
# :param new_radius: New radius for the node.
# """
# self.radius = new_radius
# self.setRect(self.x - new_radius, self.y - new_radius, new_radius * 2, new_radius * 2)

def change_pen_width(self, width: float) -> None:
"""
Change the pen width for the node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from GridCalEngine.Devices.Substation.voltage_level import VoltageLevel
from GridCalEngine.Devices.Substation.bus import Bus
from GridCalEngine.enumerations import DeviceType

if TYPE_CHECKING: # Only imports the below statements during type checking
from GridCal.Gui.Diagrams.MapWidget.grid_map_widget import GridMapWidget
Expand Down Expand Up @@ -64,21 +63,25 @@ def __init__(self,
api_object=api_object,
editor=editor,
draw_labels=draw_labels)
QGraphicsEllipseItem.__init__(self, parent_center.x(), parent_center.y(), r * api_object.Vnom * 0.01,
r * api_object.Vnom * 0.01, parent)
QGraphicsEllipseItem.__init__(self,
parent_center.x(),
parent_center.y(),
r * api_object.Vnom * 0.01,
r * api_object.Vnom * 0.01,
parent)

parent.register_voltage_level(vl=self)

self.editor: GridMapWidget = editor # to reinforce the type

self.api_object: VoltageLevel = api_object # to reinforce the type

self.radius = r * api_object.Vnom * 0.01
# print(f"VL created at x:{parent_center.x()}, y:{parent_center.y()}")

self.setAcceptHoverEvents(True) # Enable hover events for the item
# self.setFlag(QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemIsMovable) # Allow moving the node
self.setFlag(
self.GraphicsItemFlag.ItemIsSelectable | self.GraphicsItemFlag.ItemIsMovable) # Allow selecting the node

# Allow moving the node
self.setFlag(self.GraphicsItemFlag.ItemIsSelectable | self.GraphicsItemFlag.ItemIsMovable)

# Create a pen with reduced line width
self.change_pen_width(0.5)
Expand Down Expand Up @@ -114,6 +117,26 @@ def move_to_xy(self, x: float, y: float):
self.setRect(x, y, self.rect().width(), self.rect().height())
return x, y

def set_size(self, r: float):
"""
:param r: radius in pixels
:return:
"""
# if r != self.radius:
rect = self.rect()
rect.setWidth(r)
rect.setHeight(r)
self.radius = r

# change the width and height while keeping the same center
r2 = r / 2
new_x = rect.x() - r2
new_y = rect.y() - r2

# Set the new rectangle with the updated dimensions
self.setRect(new_x, new_y, r, r)

def updateDiagram(self) -> None:
"""
Expand All @@ -124,8 +147,6 @@ def updateDiagram(self) -> None:
lat, long = self.editor.to_lat_lon(x=center_point.x() + real_position.x(),
y=center_point.y() + real_position.y())

print(f'Updating VL position id:{self.api_object.idtag}, lat:{lat}, lon:{long}')

self.editor.update_diagram_element(device=self.api_object,
latitude=lat,
longitude=long,
Expand Down
Loading

0 comments on commit 3a42737

Please sign in to comment.