tdf#144694 In direct SQL dialog, activate options 'Run SQL command
[LibreOffice.git] / solenv / gdb / libreoffice / basegfx.py
blobb2e4db94536c761efc09951d520e8d2330160f51
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import gdb
11 import six
13 from libreoffice.util import printing
15 class B2DRangePrinter(object):
16 '''Prints a B2DRange object.'''
18 def __init__(self, typename, value):
19 self.typename = typename
20 self.value = value
21 # inject children() func dynamically
22 if not self._isEmpty():
23 self.children = self._children
25 def to_string(self):
26 if self._isEmpty():
27 return "empty %s" % (self.typename)
28 else:
29 return "%s" % (self.typename)
31 def _isEmpty(self):
32 return (self.value['maRangeX']['mnMinimum'] > self.value['maRangeX']['mnMaximum']
33 or self.value['maRangeY']['mnMinimum'] > self.value['maRangeY']['mnMaximum'])
35 def _children(self):
36 left = self.value['maRangeX']['mnMinimum']
37 top = self.value['maRangeY']['mnMinimum']
38 right = self.value['maRangeX']['mnMaximum']
39 bottom = self.value['maRangeY']['mnMaximum']
40 children = [('left', left), ('top', top), ('right', right), ('bottom', bottom)]
41 return children.__iter__()
43 class B2DPolygonPrinter(object):
44 '''Prints a B2DPolygon object.'''
46 def __init__(self, typename, value):
47 self.typename = typename
48 self.value = value
49 # inject children() func dynamically
50 if not self._isEmpty():
51 self.children = self._children
53 def to_string(self):
54 if self._isEmpty():
55 return "empty %s" % (self.typename)
56 else:
57 return "%s %s" % ('bezier curve' if self._hasCurves() else 'straight line',
58 self.typename)
60 def _count(self):
61 # It's a call into the inferior (being debugged) process.
62 # Will not work with core dumps and can cause a deadlock.
63 if self.exists():
64 return int(gdb.parse_and_eval(
65 "(('basegfx::B2DPolygon' *) {})->count()".format(self.value.address)))
67 def _isEmpty(self):
68 return self._count() == 0
70 def _hasCurves(self):
71 # It's a call into the inferior (being debugged) process.
72 # Will not work with core dumps and can cause a deadlock.
73 if self.exists():
74 return int(gdb.parse_and_eval(
75 "(('basegfx::B2DPolygon' *) {})->areControlPointsUsed()".format(self.value.address))) != 0
77 def _children(self):
78 if self._hasCurves():
79 return self._bezierIterator(self._count(), self.value)
80 else:
81 return self._plainIterator(self._count(), self.value)
83 class _plainIterator(six.Iterator):
84 def __init__(self, count, value):
85 self.count = count
86 self.value = value
87 self.index = 0
89 def __iter__(self):
90 return self
92 def __next__(self):
93 if self.index >= self.count:
94 raise StopIteration()
95 points = self.value['mpPolygon']['m_pimpl'].dereference()['m_value']['maPoints']['maVector']
96 currPoint = (points['_M_impl']['_M_start'] + self.index).dereference()
97 # doesn't work?
98 #currPoint = gdb.parse_and_eval(
99 # '((basegfx::B2DPolygon*)%d)->getB2DPoint(%d)' % (
100 # self.value.address, self.index))
101 self.index += 1
102 return ('point %d' % (self.index-1),
103 '(%15f, %15f)' % (currPoint['mnX'], currPoint['mnY']))
105 class _bezierIterator(six.Iterator):
106 def __init__(self, count, value):
107 self.count = count
108 self.value = value
109 self.index = 0
111 def __iter__(self):
112 return self
114 def __next__(self):
115 if self.index >= self.count:
116 raise StopIteration()
117 points = self.value['mpPolygon']['m_pimpl'].dereference()['m_value']['maPoints']['maVector']
118 currPoint = (points['_M_impl']['_M_start'] + self.index).dereference()
119 #currPoint = gdb.parse_and_eval(
120 # '((basegfx::B2DPolygon*)%d)->getB2DPoint(%d)' % (
121 # self.value.address, self.index))
123 # It's a call into the inferior (being debugged) process.
124 # Will not work with core dumps and can cause a deadlock.
125 prevControl = gdb.parse_and_eval(
126 "(('basegfx::B2DPolygon' *) {})->getPrevControlPoint({:d})".format(self.value.address, self.index))
127 # It's a call into the inferior (being debugged) process.
128 # Will not work with core dumps and can cause a deadlock.
129 nextControl = gdb.parse_and_eval(
130 "(('basegfx::B2DPolygon' *) {})->getNextControlPoint({:d})".format(self.value.address, self.index))
131 self.index += 1
132 return ('point %d' % (self.index-1),
133 'p: (%15f, %15f) c-1: (%15f, %15f) c1: (%15f, %15f)' %
134 (currPoint['mnX'], currPoint['mnY'],
135 prevControl['mnX'], prevControl['mnY'],
136 nextControl['mnX'], nextControl['mnY']))
138 class B2DPolyPolygonPrinter(object):
139 '''Prints a B2DPolyPolygon object.'''
141 def __init__(self, typename, value):
142 self.typename = typename
143 self.value = value
145 def to_string(self):
146 if self._isEmpty():
147 return "empty %s" % (self.typename)
148 else:
149 return "%s %s with %d sub-polygon(s)" % ('closed' if self._isClosed() else 'open',
150 self.typename,
151 self._count())
153 def _count(self):
154 # It's a call into the inferior (being debugged) process.
155 # Will not work with core dumps and can cause a deadlock.
156 if self.exists():
157 return int(gdb.parse_and_eval(
158 "(('basegfx::B2DPolyPolygon' *) {})->count()".format(self.value.address)))
160 def _isClosed(self):
161 # It's a call into the inferior (being debugged) process.
162 # Will not work with core dumps and can cause a deadlock.
163 if self.exists():
164 return int(gdb.parse_and_eval(
165 "(('basegfx::B2DPolyPolygon' *) {})->isClosed()".format(self.value.address))) != 0
167 def _isEmpty(self):
168 return self._count() == 0
170 def children(self):
171 if self.value['mpPolyPolygon']['m_pimpl'].type.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_MEMBERPTR):
172 if self.value['mpPolyPolygon']['m_pimpl']:
173 try:
174 vector = self.value['mpPolyPolygon']['m_pimpl'].dereference()['m_value']['maPolygons']
175 import libstdcxx.v6.printers as std
176 return std.StdVectorPrinter("std::vector", vector).children()
177 except RuntimeError:
178 gdb.write("Cannot access memory at address " + str(self.value['mpPolyPolygon']['m_pimpl'].address))
180 return None
182 printer = None
184 def build_pretty_printers():
185 global printer
187 printer = printing.Printer('libreoffice/basegfx')
189 # basic types
190 printer.add('basegfx::B2DRange', B2DRangePrinter)
191 printer.add('basegfx::B2DPolygon', B2DPolygonPrinter)
192 printer.add('basegfx::B2DPolyPolygon', B2DPolyPolygonPrinter)
194 def register_pretty_printers(obj):
195 printing.register_pretty_printer(printer, obj)
197 build_pretty_printers()
199 # vim:set shiftwidth=4 softtabstop=4 expandtab: