From 0d00ea2638c11dff054bb93c5d446104663b31b3 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sun, 2 Apr 2023 16:46:23 +0200 Subject: [PATCH] export drawings to agr --- src/gui_qt/graphs/graphwindow.py | 4 ++ src/gui_qt/io/exporters.py | 4 ++ src/nmreval/io/graceeditor.py | 89 +++++++++++++++++++++++++++++++- 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/gui_qt/graphs/graphwindow.py b/src/gui_qt/graphs/graphwindow.py index 2f44954..c213bd0 100644 --- a/src/gui_qt/graphs/graphwindow.py +++ b/src/gui_qt/graphs/graphwindow.py @@ -637,6 +637,10 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow): dic['in_legend'] = in_legend + dic['drawings'] = [] + for d in self.drawings: + dic['drawings'].append(d.get_value()) + return dic def get_state(self) -> dict: diff --git a/src/gui_qt/io/exporters.py b/src/gui_qt/io/exporters.py index e089991..5023e32 100644 --- a/src/gui_qt/io/exporters.py +++ b/src/gui_qt/io/exporters.py @@ -91,6 +91,10 @@ class GraceExporter: else: data.data = c_[item['x'], item['y']] + for item in self.__opts['drawings']: + print(item) + draw = self.__agr.new_drawing() + for c in new_colors: self.__agr.set_color(c[1], c[2], idx=c[0]) diff --git a/src/nmreval/io/graceeditor.py b/src/nmreval/io/graceeditor.py index 61c27db..59efe9b 100644 --- a/src/nmreval/io/graceeditor.py +++ b/src/nmreval/io/graceeditor.py @@ -80,6 +80,12 @@ class GraceEditor: return self.graphs[-1] + def new_drawing(self, dtype: str = 'line'): + obj = GraceDrawing(dtype) + self.drawing_objects.append(obj) + return self.drawing_objects[-1] + + def new_set(self, graph): s = None g_idx = -1 @@ -193,6 +199,8 @@ class GraceEditor: self.graphs[-1].append(line) + print(self.drawing_objects) + def _make_graph(self, line: str): m = self._RE_GRAPH_START.match(line) g_idx = int(m.group(1)) @@ -324,6 +332,86 @@ class GraceEditor: class GraceDrawing(list): + type_map = {'text': 'string', 'rectangle': 'box'} + + def __init__(self, draw_type: str): + super().__init__() + + + if draw_type not in ['rectangle', 'line', 'ellipse', 'multipts', 'text']: + raise ValueError(f'Unknown drawing object {draw_type}') + + draw_type = GraceDrawing.type_map.get(draw_type, draw_type) + self._type = draw_type + + def _create_box(self): + text = """\ +@with box +@ box on +@ box loctype world +@ box 0.0, 0.0, 1.0, 1.0 +@ box linestyle 1 +@ box linewidth 1.0 +@ box color 1 +@ box fill color 1 +@ box fill pattern 0' +@box def +""" + for line in text.split('\n'): + self.append(line + '\n') + + def _create_ellipse(self): + text = """\ +@with ellipse +@ ellipse on +@ ellipse loctype world +@ ellipse 0.0, 0.0, 1.0, 1.0 +@ ellipse linestyle 1 +@ ellipse linewidth 1.0 +@ ellipse color 1 +@ ellipse fill color 1 +@ ellipse fill pattern 0 +@ellipse def +""" + for line in text.split('\n'): + self.append(line + '\n') + + def _create_line(self): + text = """\ +@with string +@ string on +@ string loctype world +@ string 0.0, 0.0 +@ string color 1 +@ string rot 0 +@ string font 0 +@ string just 0 +@ string char size 1.000000 +@ string def "" +""" + + + def _create_line(self): + text = """\ +@with line +@ line on +@ line loctype world +@ line g0 +@ line 0.0, 0.0, 1.0, 1.0 +@ line linewidth 1.0 +@ line linestyle 1 +@ line color 1 +@ line arrow 0 +@ line arrow type 0 +@ line arrow length 1.000000 +@ line arrow layout 1.000000, 1.000000 +@line def +""" + for line in text.split('\n'): + self.append(line + '\n') + + + def __str__(self): return ''.join(self) @@ -605,7 +693,6 @@ class GraceSetProps(GraceProperties): self.set_property(**_kwargs) def set_symbol(self, **kwargs): - _kwargs = {'symbol '+k: v for k, v in kwargs.items()} if 'symbol' in kwargs: _kwargs['symbol'] = kwargs['symbol']