-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
22,972 additions
and
22,297 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
src/GridCal/Gui/GridEditorWidget/external_grid_graphics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
# GridCal | ||
# Copyright (C) 2022 Santiago Peñate Vera | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 3 of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program; if not, write to the Free Software Foundation, | ||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from PySide6 import QtWidgets, QtGui, QtCore | ||
from GridCal.Engine.Core.Devices.Injections.battery import Battery, DeviceType | ||
from GridCal.Gui.GridEditorWidget.generic_graphics import ACTIVE, DEACTIVATED, OTHER, Square | ||
from GridCal.Gui.GuiFunctions import ObjectsModel | ||
from GridCal.Gui.GridEditorWidget.messages import yes_no_question | ||
|
||
|
||
class ExternalGridGraphicItem(QtWidgets.QGraphicsItemGroup): | ||
""" | ||
ExternalGrid graphic item | ||
""" | ||
def __init__(self, parent, api_obj: Battery, diagramScene): | ||
""" | ||
:param parent: | ||
:param api_obj: | ||
""" | ||
super(ExternalGridGraphicItem, self).__init__(parent) | ||
|
||
self.parent = parent | ||
|
||
self.api_object: Battery = api_obj | ||
|
||
self.diagramScene = diagramScene | ||
|
||
self.w = 40 | ||
self.h = 40 | ||
|
||
# Properties of the container: | ||
self.setFlags(self.GraphicsItemFlag.ItemIsSelectable | self.GraphicsItemFlag.ItemIsMovable) | ||
self.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) | ||
|
||
self.width = 4 | ||
if self.api_object is not None: | ||
if self.api_object.active: | ||
self.style = ACTIVE['style'] | ||
self.color = ACTIVE['color'] | ||
else: | ||
self.style = DEACTIVATED['style'] | ||
self.color = DEACTIVATED['color'] | ||
else: | ||
self.style = OTHER['style'] | ||
self.color = OTHER['color'] | ||
|
||
# line to tie this object with the original bus (the parent) | ||
self.nexus = QtWidgets.QGraphicsLineItem() | ||
self.nexus.setPen(QtGui.QPen(self.color, self.width, self.style)) | ||
parent.scene().addItem(self.nexus) | ||
|
||
pen = QtGui.QPen(self.color, self.width, self.style) | ||
|
||
self.glyph = Square(self) | ||
self.glyph.setRect(0, 0, self.h, self.w) | ||
self.glyph.setPen(pen) | ||
self.addToGroup(self.glyph) | ||
|
||
self.label = QtWidgets.QGraphicsTextItem('E', parent=self.glyph) | ||
self.label.setDefaultTextColor(self.color) | ||
self.label.setPos(self.h / 4, self.w / 5) | ||
|
||
self.setPos(self.parent.x(), self.parent.y() + 100) | ||
self.update_line(self.pos()) | ||
|
||
def recolour_mode(self): | ||
|
||
if self.api_object is not None: | ||
if self.api_object.active: | ||
self.color = ACTIVE['color'] | ||
self.style = ACTIVE['style'] | ||
else: | ||
self.color = DEACTIVATED['color'] | ||
self.style = DEACTIVATED['style'] | ||
else: | ||
self.color = ACTIVE['color'] | ||
self.style = ACTIVE['style'] | ||
|
||
pen = QtGui.QPen(self.color, self.width, self.style) | ||
self.glyph.setPen(pen) | ||
self.nexus.setPen(pen) | ||
self.label.setDefaultTextColor(self.color) | ||
|
||
def update_line(self, pos): | ||
""" | ||
Update the line that joins the parent and this object | ||
:param pos: position of this object | ||
""" | ||
parent = self.parentItem() | ||
rect = parent.rect() | ||
self.nexus.setLine( | ||
pos.x() + self.w / 2, | ||
pos.y() + 0, | ||
parent.x() + rect.width() / 2, | ||
parent.y() + parent.terminal.y + 5, | ||
) | ||
self.setZValue(-1) | ||
self.nexus.setZValue(-1) | ||
|
||
def contextMenuEvent(self, event): | ||
""" | ||
Display context menu | ||
@param event: | ||
@return: | ||
""" | ||
menu = QtWidgets.QMenu() | ||
menu.addSection("External grid") | ||
|
||
pe = menu.addAction('Active') | ||
pe.setCheckable(True) | ||
pe.setChecked(self.api_object.active) | ||
pe.triggered.connect(self.enable_disable_toggle) | ||
|
||
pa = menu.addAction('Plot profiles') | ||
plot_icon = QtGui.QIcon() | ||
plot_icon.addPixmap(QtGui.QPixmap(":/Icons/icons/plot.svg")) | ||
pa.setIcon(plot_icon) | ||
pa.triggered.connect(self.plot) | ||
|
||
da = menu.addAction('Delete') | ||
del_icon = QtGui.QIcon() | ||
del_icon.addPixmap(QtGui.QPixmap(":/Icons/icons/delete3.svg")) | ||
da.setIcon(del_icon) | ||
da.triggered.connect(self.remove) | ||
|
||
menu.exec_(event.screenPos()) | ||
|
||
def remove(self, ask=True): | ||
""" | ||
Remove this element | ||
@return: | ||
""" | ||
if ask: | ||
ok = yes_no_question('Are you sure that you want to remove this external grid', 'Remove external grid') | ||
else: | ||
ok = True | ||
|
||
if ok: | ||
self.diagramScene.removeItem(self.nexus) | ||
self.diagramScene.removeItem(self) | ||
self.api_object.bus.batteries.remove(self.api_object) | ||
|
||
def enable_disable_toggle(self): | ||
""" | ||
@return: | ||
""" | ||
if self.api_object is not None: | ||
if self.api_object.active: | ||
self.set_enable(False) | ||
else: | ||
self.set_enable(True) | ||
|
||
if self.diagramScene.circuit.has_time_series: | ||
ok = yes_no_question('Do you want to update the time series active status accordingly?', | ||
'Update time series active status') | ||
|
||
if ok: | ||
# change the bus state (time series) | ||
self.diagramScene.set_active_status_to_profile(self.api_object, override_question=True) | ||
|
||
def set_enable(self, val=True): | ||
""" | ||
Set the enable value, graphically and in the API | ||
@param val: | ||
@return: | ||
""" | ||
self.api_object.active = val | ||
if self.api_object is not None: | ||
if self.api_object.active: | ||
self.style = ACTIVE['style'] | ||
self.color = ACTIVE['color'] | ||
else: | ||
self.style = DEACTIVATED['style'] | ||
self.color = DEACTIVATED['color'] | ||
else: | ||
self.style = OTHER['style'] | ||
self.color = OTHER['color'] | ||
self.glyph.setPen(QtGui.QPen(self.color, self.width, self.style)) | ||
self.label.setDefaultTextColor(self.color) | ||
|
||
def plot(self): | ||
""" | ||
Plot API objects profiles | ||
""" | ||
# time series object from the last simulation | ||
ts = self.diagramScene.circuit.time_profile | ||
|
||
# plot the profiles | ||
self.api_object.plot_profiles(time=ts) | ||
|
||
def mousePressEvent(self, QGraphicsSceneMouseEvent): | ||
""" | ||
mouse press: display the editor | ||
:param QGraphicsSceneMouseEvent: | ||
:return: | ||
""" | ||
mdl = ObjectsModel([self.api_object], self.api_object.editable_headers, | ||
parent=self.diagramScene.parent().object_editor_table, editable=True, transposed=True, | ||
dictionary_of_lists={DeviceType.Technology.value: self.diagramScene.circuit.technologies, }) | ||
self.diagramScene.parent().object_editor_table.setModel(mdl) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.