1
0
forked from IPKM/nmreval

export drawings to agr

This commit is contained in:
Dominik Demuth 2023-04-02 16:46:23 +02:00
parent 8d2bfacaca
commit 0d00ea2638
3 changed files with 96 additions and 1 deletions

View File

@ -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:

View File

@ -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])

View File

@ -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']