Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-esa committed Dec 1, 2023
2 parents ed5d584 + 081f154 commit 7c3bc15
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 19 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ The background pattern was downloaded from www.subtlepatterns.com

Changelog
=========
**4.1.23 (12/2023)**
- Fix interprocess copy-paste issue (could result in duplicate copies)

**4.1.22 (11/2023)**
- Fix export of the statechart into png from the GUI (worked only from command line before)
- Fix navigation in nested states when using partitions

**4.1.21 (11/2023)**
- Critical Fix: saving error (when code generation backend raises an exception model could be lost!)
- Fixed support for array newtypes indexed by an enumerated type

**4.1.20 (11/2023)**
- Fix code generation when combinining a history nextstate trying to go back
to a nested state that contains no inner state (just a start transition ending
Expand Down
1 change: 1 addition & 0 deletions opengeode/AdaGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3610,6 +3610,7 @@ def type_name(a_type, use_prefix=True):
elif a_type.kind == 'EnumeratedType':
return ASN1SCC if use_prefix else ''
else:
LOG.debug(str(traceback.format_exc()))
raise NotImplementedError(f'Type name for {a_type.kind}')


Expand Down
3 changes: 3 additions & 0 deletions opengeode/Clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ def paste(parent, scene):
# LOG.debug("PASTE: " + pr_text)
ast, _, _, _, terminators = \
ogParser.parseSingleElement(common_name, pr_text)
# Clear the local clipboard, there can be only one element
COPY_PASTE.clear()
COPY_PASTE.append(([ast], terminators))
remove_after_paste = True

CLIPBOARD.clear()
if not parent:
new_symbols = paste_floating_objects(scene)
print(new_symbols)
for each in new_symbols:
# Make sure nested scenes are set properly
each.double_click()
Expand Down
1 change: 0 additions & 1 deletion opengeode/Statechart.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ def find_terminators(trans):
# JOIN - Find corresponding label
try:
corr_label, = [lab for lab in
root_ast.content.floating_labels +
root_ast.labels if
lab.inputString.lower() ==
join.inputString.lower()]
Expand Down
4 changes: 2 additions & 2 deletions opengeode/ogParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2945,8 +2945,8 @@ def primary_index(root, context, pos):
check_index = False
node.requires_num = False
try:
index_given_sort = type_name(params[0].exprType)
index_expected_sort = receiver_bty.indexed_by
index_given_sort = type_name(params[0].exprType).lower().replace('-', '_')
index_expected_sort = receiver_bty.indexed_by.lower().replace('-', '_')
if index_given_sort == index_expected_sort:
check_index = True
# Add a flag in the AST for code generators to
Expand Down
52 changes: 43 additions & 9 deletions opengeode/opengeode.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,7 @@ def fix_pos_from_ast(symbol):
process_scene = self # by default, if we are not in a block
for each in self.processes:
process_scene = each.nested_scene
if not process_scene:
continue
else:
if process_scene:
break

for item in process_scene.start:
Expand All @@ -782,8 +780,15 @@ def fix_pos_from_ast(symbol):
else:
# scene already exist, just move the item into it
partition_names[item.ast.partition].addItem(item)
# It can be that no partition was created, if the model was empty
# (nothing inside the process scene). In that case we must still
# set the default partition.
if not partition_names:
partition_names['default'] = process_scene

# set the list of partitions at top-level scene, so that it will be
# picked up when the datadict is set up

self.partitions = partition_names
self.setup_partitions_in_datadict.emit()

Expand Down Expand Up @@ -1250,6 +1255,12 @@ def sdl_to_statechart(self, basic=True, view=None, ast=None):

def export_branch_to_picture(self, symbol, filename, doc_format):
''' Save a symbol and its followers to a file '''
if self.context == 'statechart':
# We can't export just a branch in a statechart:
# export the whole diagram instead
self.export_img(filename=filename, doc_format=doc_format)
return

temp_scene = SDL_Scene(context=self.context)
temp_scene.messages_window = self.messages_window
self.clearSelection()
Expand Down Expand Up @@ -1287,6 +1298,7 @@ def export_img(self, filename=None, doc_format='png', split=False):
self.clearSelection()
self.clear_highlight()
self.clear_focus()
background_brush = self.backgroundBrush()
# Copy in a different scene to get the smallest rectangle
# (except statecharts, they are already optimal)
if self.context != "statechart":
Expand All @@ -1305,7 +1317,7 @@ def export_img(self, filename=None, doc_format='png', split=False):
each.select(False)
rect = other_scene.sceneRect()
else:
# remove the background
# remove the background (it is saved for restoration)
self.setBackgroundBrush(QBrush())
self.scene_refresh()
rect = self.sceneRect()
Expand Down Expand Up @@ -1343,6 +1355,9 @@ def export_img(self, filename=None, doc_format='png', split=False):
if painter.isActive():
painter.end()

# restore the background brush (statecharts only)
self.setBackgroundBrush(background_brush)


def clear_focus(self):
''' Clear focus from any item on the scene '''
Expand Down Expand Up @@ -2117,9 +2132,12 @@ def update_partition_arrows(self):
self.right_button.setEnabled(False)
return
partitions = list(self.top_scene().partitions.keys())
idx = partitions.index(scene.partition_name)
self.left_button.setEnabled(idx > 0)
self.right_button.setEnabled(idx < len(partitions) - 1)
try:
idx = partitions.index(scene.partition_name)
self.left_button.setEnabled(idx > 0)
self.right_button.setEnabled(idx < len(partitions) - 1)
except ValueError:
LOG.debug(f"Partition {scene.partition_name} does not exist")


def go_left(self):
Expand Down Expand Up @@ -2312,7 +2330,16 @@ def save_diagram(self, save_as=False, autosave=False):
# When --edit is combined with --toAda or --toC, generate the
# code at the same time as the model, to save build time in TASTE
process, = scene.ast.processes
generate(process, self.options)
try:
cwd = os.getcwd()
generate(process, self.options)
except Exception as e:
# Code generation failed (can be due to errors in the model)
# pr saving must continue anyway
LOG.info("Code generation failed due to this error" + str(e))
# code generation changes folder. If exception happened,
# we must come back to the original directory
os.chdir(cwd)

# Read the process name for the Makefile
for each in scene.processes:
Expand Down Expand Up @@ -2369,7 +2396,11 @@ def save_png(self):
''' Save the current view as a PNG image '''
filename = QFileDialog.getSaveFileName(
self, "Save picture", ".", "Image (*.png)")[0]
self.scene().export_img(filename, doc_format='png')
if self.statechart_view.hasFocus() and not self.hasFocus():
# check if the currently visible scene is the statechart
self.statechart_view.scene().export_img(filename, doc_format='png')
else:
self.scene().export_img(filename, doc_format='png')

def load_file(self, files):
''' Parse a PR file and render it on the scene '''
Expand Down Expand Up @@ -2853,6 +2884,9 @@ def start(self, options, splash, app):
self.statechart_view = self.findChild(SDL_View, 'statechart_view')
self.statechart_scene = SDL_Scene(context='statechart')
self.statechart_view.setScene(self.statechart_scene)
# give access to the statechart view from the main SDL view, this is
# useful for rendering PNG from the menu item
self.view.statechart_view = self.statechart_view

# Set up the dock area to display the ASN.1 Data model
asn1_dock = self.findChild(QDockWidget, 'datatypes_dock')
Expand Down
15 changes: 9 additions & 6 deletions opengeode/sdlSymbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,12 +1152,15 @@ def nested_scene(self):

def double_click(self):
''' Catch a double click - Set nested scene '''
for each, value in self.scene().composite_states.items():
if str(self).split()[0].lower() == str(each):
self.nested_scene = value
break
else:
self.nested_scene = None
# We have to look in all partitions, not only in the current scene
top_scene = self.scene().views()[0].top_scene()
partitions = top_scene.partitions
for part in partitions.values():
for each, value in part.composite_states.items():
if str(self).split()[0].lower() == str(each):
self.nested_scene = value
return
self.nested_scene = None

@nested_scene.setter
def nested_scene(self, value):
Expand Down
2 changes: 1 addition & 1 deletion opengeode/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
#
# later on we use: version['__version__']
#
__version__ = '4.1.20'
__version__ = '4.1.23'

0 comments on commit 7c3bc15

Please sign in to comment.