- in Geometry Editor - fixed the Explode tool to work on the result of adding Text geometry
- all the Geometry Editor plugins are moved inside another folder and the UI's are moved into their own class
This commit is contained in:
@@ -11,82 +11,22 @@ class BufferSelectionTool(AppTool):
|
||||
Simple input for buffer distance.
|
||||
"""
|
||||
|
||||
pluginName = _("Buffer Selection")
|
||||
|
||||
def __init__(self, app, draw_app):
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
self.draw_app = draw_app
|
||||
self.decimals = app.decimals
|
||||
|
||||
# Title
|
||||
title_label = FCLabel("%s" % ('Editor ' + self.pluginName))
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(title_label)
|
||||
self.ui = BufferEditorUI(layout=self.layout, buffer_class=self)
|
||||
|
||||
# this way I can hide/show the frame
|
||||
self.buffer_tool_frame = QtWidgets.QFrame()
|
||||
self.buffer_tool_frame.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout.addWidget(self.buffer_tool_frame)
|
||||
self.buffer_tools_box = QtWidgets.QVBoxLayout()
|
||||
self.buffer_tools_box.setContentsMargins(0, 0, 0, 0)
|
||||
self.buffer_tool_frame.setLayout(self.buffer_tools_box)
|
||||
|
||||
# Grid Layout
|
||||
grid_buffer = GLay(v_spacing=5, h_spacing=3)
|
||||
self.buffer_tools_box.addLayout(grid_buffer)
|
||||
|
||||
# Buffer distance
|
||||
self.buffer_distance_entry = FCDoubleSpinner()
|
||||
self.buffer_distance_entry.set_precision(self.decimals)
|
||||
self.buffer_distance_entry.set_range(0.0000, 9910000.0000)
|
||||
grid_buffer.addWidget(FCLabel('%s:' % _("Buffer distance")), 0, 0)
|
||||
grid_buffer.addWidget(self.buffer_distance_entry, 0, 1)
|
||||
|
||||
self.buffer_corner_lbl = FCLabel('%s:' % _("Buffer corner"))
|
||||
self.buffer_corner_lbl.setToolTip(
|
||||
_("There are 3 types of corners:\n"
|
||||
" - 'Round': the corner is rounded for exterior buffer.\n"
|
||||
" - 'Square': the corner is met in a sharp angle for exterior buffer.\n"
|
||||
" - 'Beveled': the corner is a line that directly connects the features meeting in the corner")
|
||||
)
|
||||
self.buffer_corner_cb = FCComboBox()
|
||||
self.buffer_corner_cb.addItem(_("Round"))
|
||||
self.buffer_corner_cb.addItem(_("Square"))
|
||||
self.buffer_corner_cb.addItem(_("Beveled"))
|
||||
grid_buffer.addWidget(self.buffer_corner_lbl, 2, 0)
|
||||
grid_buffer.addWidget(self.buffer_corner_cb, 2, 1)
|
||||
|
||||
# Buttons
|
||||
hlay = QtWidgets.QHBoxLayout()
|
||||
grid_buffer.addLayout(hlay, 4, 0, 1, 2)
|
||||
|
||||
self.buffer_int_button = FCButton(_("Buffer Interior"))
|
||||
hlay.addWidget(self.buffer_int_button)
|
||||
self.buffer_ext_button = FCButton(_("Buffer Exterior"))
|
||||
hlay.addWidget(self.buffer_ext_button)
|
||||
|
||||
hlay1 = QtWidgets.QHBoxLayout()
|
||||
grid_buffer.addLayout(hlay1, 6, 0, 1, 2)
|
||||
|
||||
self.buffer_button = FCButton(_("Full Buffer"))
|
||||
hlay1.addWidget(self.buffer_button)
|
||||
|
||||
self.layout.addStretch(1)
|
||||
self.connect_signals_at_init()
|
||||
self.set_tool_ui()
|
||||
|
||||
def connect_signals_at_init(self):
|
||||
# Signals
|
||||
self.buffer_button.clicked.connect(self.on_buffer)
|
||||
self.buffer_int_button.clicked.connect(self.on_buffer_int)
|
||||
self.buffer_ext_button.clicked.connect(self.on_buffer_ext)
|
||||
|
||||
# Init appGUI
|
||||
self.buffer_distance_entry.set_value(0.01)
|
||||
self.ui.buffer_button.clicked.connect(self.on_buffer)
|
||||
self.ui.buffer_int_button.clicked.connect(self.on_buffer_int)
|
||||
self.ui.buffer_ext_button.clicked.connect(self.on_buffer_ext)
|
||||
|
||||
def run(self):
|
||||
self.app.defaults.report_usage("Geo Editor ToolBuffer()")
|
||||
@@ -123,59 +63,63 @@ class BufferSelectionTool(AppTool):
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Buffer Tool"))
|
||||
|
||||
def set_tool_ui(self):
|
||||
# Init appGUI
|
||||
self.ui.buffer_distance_entry.set_value(0.01)
|
||||
|
||||
def on_tab_close(self):
|
||||
self.draw_app.select_tool("select")
|
||||
self.app.ui.notebook.callback_on_close = lambda: None
|
||||
|
||||
def on_buffer(self):
|
||||
try:
|
||||
buffer_distance = float(self.buffer_distance_entry.get_value())
|
||||
buffer_distance = float(self.ui.buffer_distance_entry.get_value())
|
||||
except ValueError:
|
||||
# try to convert comma to decimal point. if it's still not working error message and return
|
||||
try:
|
||||
buffer_distance = float(self.buffer_distance_entry.get_value().replace(',', '.'))
|
||||
self.buffer_distance_entry.set_value(buffer_distance)
|
||||
buffer_distance = float(self.ui.buffer_distance_entry.get_value().replace(',', '.'))
|
||||
self.ui.buffer_distance_entry.set_value(buffer_distance)
|
||||
except ValueError:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' %
|
||||
_("Buffer distance value is missing or wrong format. Add it and retry."))
|
||||
return
|
||||
# the cb index start from 0 but the join styles for the buffer start from 1 therefore the adjustment
|
||||
# I populated the combobox such that the index coincide with the join styles value (which is really an INT)
|
||||
join_style = self.buffer_corner_cb.currentIndex() + 1
|
||||
join_style = self.ui.buffer_corner_cb.currentIndex() + 1
|
||||
self.buffer(buffer_distance, join_style)
|
||||
|
||||
def on_buffer_int(self):
|
||||
try:
|
||||
buffer_distance = float(self.buffer_distance_entry.get_value())
|
||||
buffer_distance = float(self.ui.buffer_distance_entry.get_value())
|
||||
except ValueError:
|
||||
# try to convert comma to decimal point. if it's still not working error message and return
|
||||
try:
|
||||
buffer_distance = float(self.buffer_distance_entry.get_value().replace(',', '.'))
|
||||
self.buffer_distance_entry.set_value(buffer_distance)
|
||||
buffer_distance = float(self.ui.buffer_distance_entry.get_value().replace(',', '.'))
|
||||
self.ui.buffer_distance_entry.set_value(buffer_distance)
|
||||
except ValueError:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' %
|
||||
_("Buffer distance value is missing or wrong format. Add it and retry."))
|
||||
return
|
||||
# the cb index start from 0 but the join styles for the buffer start from 1 therefore the adjustment
|
||||
# I populated the combobox such that the index coincide with the join styles value (which is really an INT)
|
||||
join_style = self.buffer_corner_cb.currentIndex() + 1
|
||||
join_style = self.ui.buffer_corner_cb.currentIndex() + 1
|
||||
self.buffer_int(buffer_distance, join_style)
|
||||
|
||||
def on_buffer_ext(self):
|
||||
try:
|
||||
buffer_distance = float(self.buffer_distance_entry.get_value())
|
||||
buffer_distance = float(self.ui.buffer_distance_entry.get_value())
|
||||
except ValueError:
|
||||
# try to convert comma to decimal point. if it's still not working error message and return
|
||||
try:
|
||||
buffer_distance = float(self.buffer_distance_entry.get_value().replace(',', '.'))
|
||||
self.buffer_distance_entry.set_value(buffer_distance)
|
||||
buffer_distance = float(self.ui.buffer_distance_entry.get_value().replace(',', '.'))
|
||||
self.ui.buffer_distance_entry.set_value(buffer_distance)
|
||||
except ValueError:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' %
|
||||
_("Buffer distance value is missing or wrong format. Add it and retry."))
|
||||
return
|
||||
# the cb index start from 0 but the join styles for the buffer start from 1 therefore the adjustment
|
||||
# I populated the combobox such that the index coincide with the join styles value (which is really an INT)
|
||||
join_style = self.buffer_corner_cb.currentIndex() + 1
|
||||
join_style = self.ui.buffer_corner_cb.currentIndex() + 1
|
||||
self.buffer_ext(buffer_distance, join_style)
|
||||
|
||||
def buffer(self, buf_distance, join_style):
|
||||
@@ -393,5 +337,75 @@ class BufferSelectionTool(AppTool):
|
||||
self.app.worker_task.emit({'fcn': work_task, 'params': [self]})
|
||||
|
||||
def hide_tool(self):
|
||||
self.buffer_tool_frame.hide()
|
||||
self.ui.buffer_tool_frame.hide()
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
|
||||
|
||||
|
||||
class BufferEditorUI:
|
||||
pluginName = _("Buffer")
|
||||
|
||||
def __init__(self, layout, buffer_class):
|
||||
self.buffer_class = buffer_class
|
||||
self.decimals = self.buffer_class.app.decimals
|
||||
self.layout = layout
|
||||
|
||||
# Title
|
||||
title_label = FCLabel("%s" % ('Editor ' + self.pluginName))
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(title_label)
|
||||
|
||||
# this way I can hide/show the frame
|
||||
self.buffer_tool_frame = QtWidgets.QFrame()
|
||||
self.buffer_tool_frame.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout.addWidget(self.buffer_tool_frame)
|
||||
self.buffer_tools_box = QtWidgets.QVBoxLayout()
|
||||
self.buffer_tools_box.setContentsMargins(0, 0, 0, 0)
|
||||
self.buffer_tool_frame.setLayout(self.buffer_tools_box)
|
||||
|
||||
# Grid Layout
|
||||
grid_buffer = GLay(v_spacing=5, h_spacing=3)
|
||||
self.buffer_tools_box.addLayout(grid_buffer)
|
||||
|
||||
# Buffer distance
|
||||
self.buffer_distance_entry = FCDoubleSpinner()
|
||||
self.buffer_distance_entry.set_precision(self.decimals)
|
||||
self.buffer_distance_entry.set_range(0.0000, 9910000.0000)
|
||||
grid_buffer.addWidget(FCLabel('%s:' % _("Buffer distance")), 0, 0)
|
||||
grid_buffer.addWidget(self.buffer_distance_entry, 0, 1)
|
||||
|
||||
self.buffer_corner_lbl = FCLabel('%s:' % _("Buffer corner"))
|
||||
self.buffer_corner_lbl.setToolTip(
|
||||
_("There are 3 types of corners:\n"
|
||||
" - 'Round': the corner is rounded for exterior buffer.\n"
|
||||
" - 'Square': the corner is met in a sharp angle for exterior buffer.\n"
|
||||
" - 'Beveled': the corner is a line that directly connects the features meeting in the corner")
|
||||
)
|
||||
self.buffer_corner_cb = FCComboBox()
|
||||
self.buffer_corner_cb.addItem(_("Round"))
|
||||
self.buffer_corner_cb.addItem(_("Square"))
|
||||
self.buffer_corner_cb.addItem(_("Beveled"))
|
||||
grid_buffer.addWidget(self.buffer_corner_lbl, 2, 0)
|
||||
grid_buffer.addWidget(self.buffer_corner_cb, 2, 1)
|
||||
|
||||
# Buttons
|
||||
hlay = QtWidgets.QHBoxLayout()
|
||||
grid_buffer.addLayout(hlay, 4, 0, 1, 2)
|
||||
|
||||
self.buffer_int_button = FCButton(_("Buffer Interior"))
|
||||
hlay.addWidget(self.buffer_int_button)
|
||||
self.buffer_ext_button = FCButton(_("Buffer Exterior"))
|
||||
hlay.addWidget(self.buffer_ext_button)
|
||||
|
||||
hlay1 = QtWidgets.QHBoxLayout()
|
||||
grid_buffer.addLayout(hlay1, 6, 0, 1, 2)
|
||||
|
||||
self.buffer_button = FCButton(_("Full Buffer"))
|
||||
hlay1.addWidget(self.buffer_button)
|
||||
|
||||
self.layout.addStretch(1)
|
||||
|
||||
@@ -12,8 +12,6 @@ class PaintOptionsTool(AppTool):
|
||||
Inputs to specify how to paint the selected polygons.
|
||||
"""
|
||||
|
||||
pluginName = _("Paint Tool")
|
||||
|
||||
def __init__(self, app, fcdraw):
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
@@ -21,6 +19,211 @@ class PaintOptionsTool(AppTool):
|
||||
self.fcdraw = fcdraw
|
||||
self.decimals = self.app.decimals
|
||||
|
||||
self.ui = PaintEditorUI(layout=self.layout, paint_class=self)
|
||||
|
||||
self.connect_signals_at_init()
|
||||
self.set_tool_ui()
|
||||
|
||||
def run(self):
|
||||
self.app.defaults.report_usage("Geo Editor ToolPaint()")
|
||||
AppTool.run(self)
|
||||
|
||||
# if the splitter us hidden, display it
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
|
||||
# if the Tool Tab is hidden display it, else hide it but only if the objectName is the same
|
||||
found_idx = None
|
||||
for idx in range(self.app.ui.notebook.count()):
|
||||
if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab":
|
||||
found_idx = idx
|
||||
break
|
||||
# show the Tab
|
||||
if not found_idx:
|
||||
try:
|
||||
self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin"))
|
||||
except RuntimeError:
|
||||
self.app.ui.plugin_tab = QtWidgets.QWidget()
|
||||
self.app.ui.plugin_tab.setObjectName("plugin_tab")
|
||||
self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab)
|
||||
self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2)
|
||||
|
||||
self.app.ui.plugin_scroll_area = VerticalScrollArea()
|
||||
self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area)
|
||||
self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin"))
|
||||
# focus on Tool Tab
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab)
|
||||
|
||||
# self.app.ui.notebook.callback_on_close = self.on_tab_close
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Paint Tool"))
|
||||
|
||||
def connect_signals_at_init(self):
|
||||
# Signals
|
||||
self.ui.paint_button.clicked.connect(self.on_paint)
|
||||
|
||||
def on_tab_close(self):
|
||||
self.fcdraw.select_tool("select")
|
||||
self.app.ui.notebook.callback_on_close = lambda: None
|
||||
|
||||
def set_tool_ui(self):
|
||||
# Init appGUI
|
||||
if self.app.options["tools_paint_tooldia"]:
|
||||
self.ui.painttooldia_entry.set_value(self.app.options["tools_paint_tooldia"])
|
||||
else:
|
||||
self.ui.painttooldia_entry.set_value(0.0)
|
||||
|
||||
if self.app.options["tools_paint_overlap"]:
|
||||
self.ui.paintoverlap_entry.set_value(self.app.options["tools_paint_overlap"])
|
||||
else:
|
||||
self.ui.paintoverlap_entry.set_value(0.0)
|
||||
|
||||
if self.app.options["tools_paint_offset"]:
|
||||
self.ui.paintmargin_entry.set_value(self.app.options["tools_paint_offset"])
|
||||
else:
|
||||
self.ui.paintmargin_entry.set_value(0.0)
|
||||
|
||||
if self.app.options["tools_paint_method"]:
|
||||
self.ui.paintmethod_combo.set_value(self.app.options["tools_paint_method"])
|
||||
else:
|
||||
self.ui.paintmethod_combo.set_value(_("Seed"))
|
||||
|
||||
if self.app.options["tools_paint_connect"]:
|
||||
self.ui.pathconnect_cb.set_value(self.app.options["tools_paint_connect"])
|
||||
else:
|
||||
self.ui.pathconnect_cb.set_value(False)
|
||||
|
||||
if self.app.options["tools_paint_contour"]:
|
||||
self.ui.paintcontour_cb.set_value(self.app.options["tools_paint_contour"])
|
||||
else:
|
||||
self.ui.paintcontour_cb.set_value(False)
|
||||
|
||||
def on_paint(self):
|
||||
if not self.fcdraw.selected:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' % (_("Cancelled."), _("No shape selected.")))
|
||||
return
|
||||
|
||||
tooldia = self.ui.painttooldia_entry.get_value()
|
||||
overlap = self.ui.paintoverlap_entry.get_value() / 100.0
|
||||
margin = self.ui.paintmargin_entry.get_value()
|
||||
|
||||
method = self.ui.paintmethod_combo.get_value()
|
||||
contour = self.ui.paintcontour_cb.get_value()
|
||||
connect = self.ui.pathconnect_cb.get_value()
|
||||
|
||||
self.paint(tooldia, overlap, margin, connect=connect, contour=contour, method=method)
|
||||
self.fcdraw.select_tool("select")
|
||||
# self.app.ui.notebook.setTabText(2, _("Tools"))
|
||||
# self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
|
||||
#
|
||||
# self.app.ui.splitter.setSizes([0, 1])
|
||||
|
||||
def paint(self, tooldia, overlap, margin, connect, contour, method):
|
||||
def work_task(geo_editor):
|
||||
with geo_editor.app.proc_container.new(_("Working...")):
|
||||
if overlap >= 100:
|
||||
geo_editor.app.inform.emit('[ERROR_NOTCL] %s' %
|
||||
_("Could not do Paint. Overlap value has to be less than 100%%."))
|
||||
return
|
||||
|
||||
geo_editor.paint_tooldia = tooldia
|
||||
selected = geo_editor.get_selected()
|
||||
|
||||
if len(selected) == 0:
|
||||
geo_editor.app.inform.emit('[WARNING_NOTCL] %s' % _("Nothing selected."))
|
||||
return
|
||||
|
||||
for param in [tooldia, overlap, margin]:
|
||||
if not isinstance(param, float):
|
||||
param_name = [k for k, v in locals().items() if v is param][0]
|
||||
geo_editor.app.inform.emit('[WARNING] %s: %s' % (_("Invalid value for"), str(param)))
|
||||
|
||||
results = []
|
||||
|
||||
def recurse(geometry, reset=True):
|
||||
"""
|
||||
Creates a list of non-iterable linear geometry objects.
|
||||
Results are placed in self.flat_geometry
|
||||
|
||||
:param geometry: Shapely type or list or list of list of such.
|
||||
:param reset: Clears the contents of self.flat_geometry.
|
||||
"""
|
||||
|
||||
if geometry is None:
|
||||
return
|
||||
|
||||
if reset:
|
||||
self.flat_geo = []
|
||||
|
||||
# If iterable, expand recursively.
|
||||
try:
|
||||
for geo_el in geometry:
|
||||
if geo_el is not None:
|
||||
recurse(geometry=geo_el, reset=False)
|
||||
|
||||
# Not iterable, do the actual indexing and add.
|
||||
except TypeError:
|
||||
self.flat_geo.append(geometry)
|
||||
|
||||
return self.flat_geo
|
||||
|
||||
for geo in selected:
|
||||
|
||||
local_results = []
|
||||
for geo_obj in recurse(geo.geo):
|
||||
try:
|
||||
if type(geo_obj) == Polygon:
|
||||
poly_buf = geo_obj.buffer(-margin)
|
||||
else:
|
||||
poly_buf = Polygon(geo_obj).buffer(-margin)
|
||||
|
||||
if method == _("Seed"):
|
||||
cp = Geometry.clear_polygon2(
|
||||
geo_editor, polygon_to_clear=poly_buf, tooldia=tooldia,
|
||||
steps_per_circle=geo_editor.app.options["geometry_circle_steps"],
|
||||
overlap=overlap, contour=contour, connect=connect)
|
||||
elif method == _("Lines"):
|
||||
cp = Geometry.clear_polygon3(
|
||||
geo_editor, polygon=poly_buf, tooldia=tooldia,
|
||||
steps_per_circle=geo_editor.app.options["geometry_circle_steps"],
|
||||
overlap=overlap, contour=contour, connect=connect)
|
||||
else:
|
||||
cp = Geometry.clear_polygon(
|
||||
geo_editor, polygon=poly_buf, tooldia=tooldia,
|
||||
steps_per_circle=geo_editor.app.options["geometry_circle_steps"],
|
||||
overlap=overlap, contour=contour, connect=connect)
|
||||
|
||||
if cp is not None:
|
||||
local_results += list(cp.get_objects())
|
||||
except Exception as e:
|
||||
geo_editor.app.log.error("Could not Paint the polygons. %s" % str(e))
|
||||
geo_editor.app.inform.emit(
|
||||
'[ERROR] %s\n%s' % (_("Could not do Paint. Try a different combination of parameters. "
|
||||
"Or a different method of Paint"), str(e))
|
||||
)
|
||||
return
|
||||
|
||||
# add the result to the results list
|
||||
results.append(unary_union(local_results))
|
||||
|
||||
# This is a dirty patch:
|
||||
for r in results:
|
||||
geo_editor.add_shape(r)
|
||||
geo_editor.plot_all()
|
||||
geo_editor.build_ui_sig.emit()
|
||||
geo_editor.app.inform.emit('[success] %s' % _("Done."))
|
||||
|
||||
self.app.worker_task.emit({'fcn': work_task, 'params': [self.fcdraw]})
|
||||
|
||||
|
||||
class PaintEditorUI:
|
||||
pluginName = _("Paint")
|
||||
|
||||
def __init__(self, layout, paint_class):
|
||||
self.paint_class = paint_class
|
||||
self.decimals = self.paint_class.app.decimals
|
||||
self.layout = layout
|
||||
|
||||
# Title
|
||||
title_label = FCLabel("%s" % self.pluginName)
|
||||
title_label.setStyleSheet("""
|
||||
@@ -129,196 +332,4 @@ class PaintOptionsTool(AppTool):
|
||||
self.paint_button = FCButton(_("Paint"))
|
||||
hlay.addWidget(self.paint_button)
|
||||
|
||||
self.layout.addStretch()
|
||||
|
||||
# Signals
|
||||
self.paint_button.clicked.connect(self.on_paint)
|
||||
|
||||
self.set_tool_ui()
|
||||
|
||||
def run(self):
|
||||
self.app.defaults.report_usage("Geo Editor ToolPaint()")
|
||||
AppTool.run(self)
|
||||
|
||||
# if the splitter us hidden, display it
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
|
||||
# if the Tool Tab is hidden display it, else hide it but only if the objectName is the same
|
||||
found_idx = None
|
||||
for idx in range(self.app.ui.notebook.count()):
|
||||
if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab":
|
||||
found_idx = idx
|
||||
break
|
||||
# show the Tab
|
||||
if not found_idx:
|
||||
try:
|
||||
self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin"))
|
||||
except RuntimeError:
|
||||
self.app.ui.plugin_tab = QtWidgets.QWidget()
|
||||
self.app.ui.plugin_tab.setObjectName("plugin_tab")
|
||||
self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab)
|
||||
self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2)
|
||||
|
||||
self.app.ui.plugin_scroll_area = VerticalScrollArea()
|
||||
self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area)
|
||||
self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin"))
|
||||
# focus on Tool Tab
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab)
|
||||
|
||||
# self.app.ui.notebook.callback_on_close = self.on_tab_close
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Paint Tool"))
|
||||
|
||||
def on_tab_close(self):
|
||||
self.fcdraw.select_tool("select")
|
||||
self.app.ui.notebook.callback_on_close = lambda: None
|
||||
|
||||
def set_tool_ui(self):
|
||||
# Init appGUI
|
||||
if self.app.options["tools_paint_tooldia"]:
|
||||
self.painttooldia_entry.set_value(self.app.options["tools_paint_tooldia"])
|
||||
else:
|
||||
self.painttooldia_entry.set_value(0.0)
|
||||
|
||||
if self.app.options["tools_paint_overlap"]:
|
||||
self.paintoverlap_entry.set_value(self.app.options["tools_paint_overlap"])
|
||||
else:
|
||||
self.paintoverlap_entry.set_value(0.0)
|
||||
|
||||
if self.app.options["tools_paint_offset"]:
|
||||
self.paintmargin_entry.set_value(self.app.options["tools_paint_offset"])
|
||||
else:
|
||||
self.paintmargin_entry.set_value(0.0)
|
||||
|
||||
if self.app.options["tools_paint_method"]:
|
||||
self.paintmethod_combo.set_value(self.app.options["tools_paint_method"])
|
||||
else:
|
||||
self.paintmethod_combo.set_value(_("Seed"))
|
||||
|
||||
if self.app.options["tools_paint_connect"]:
|
||||
self.pathconnect_cb.set_value(self.app.options["tools_paint_connect"])
|
||||
else:
|
||||
self.pathconnect_cb.set_value(False)
|
||||
|
||||
if self.app.options["tools_paint_contour"]:
|
||||
self.paintcontour_cb.set_value(self.app.options["tools_paint_contour"])
|
||||
else:
|
||||
self.paintcontour_cb.set_value(False)
|
||||
|
||||
def on_paint(self):
|
||||
if not self.fcdraw.selected:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' % (_("Cancelled."), _("No shape selected.")))
|
||||
return
|
||||
|
||||
tooldia = self.painttooldia_entry.get_value()
|
||||
overlap = self.paintoverlap_entry.get_value() / 100.0
|
||||
margin = self.paintmargin_entry.get_value()
|
||||
|
||||
method = self.paintmethod_combo.get_value()
|
||||
contour = self.paintcontour_cb.get_value()
|
||||
connect = self.pathconnect_cb.get_value()
|
||||
|
||||
self.paint(tooldia, overlap, margin, connect=connect, contour=contour, method=method)
|
||||
self.fcdraw.select_tool("select")
|
||||
# self.app.ui.notebook.setTabText(2, _("Tools"))
|
||||
# self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
|
||||
#
|
||||
# self.app.ui.splitter.setSizes([0, 1])
|
||||
|
||||
def paint(self, tooldia, overlap, margin, connect, contour, method):
|
||||
def work_task(geo_editor):
|
||||
with geo_editor.app.proc_container.new(_("Working...")):
|
||||
if overlap >= 100:
|
||||
geo_editor.app.inform.emit('[ERROR_NOTCL] %s' %
|
||||
_("Could not do Paint. Overlap value has to be less than 100%%."))
|
||||
return
|
||||
|
||||
geo_editor.paint_tooldia = tooldia
|
||||
selected = geo_editor.get_selected()
|
||||
|
||||
if len(selected) == 0:
|
||||
geo_editor.app.inform.emit('[WARNING_NOTCL] %s' % _("Nothing selected."))
|
||||
return
|
||||
|
||||
for param in [tooldia, overlap, margin]:
|
||||
if not isinstance(param, float):
|
||||
param_name = [k for k, v in locals().items() if v is param][0]
|
||||
geo_editor.app.inform.emit('[WARNING] %s: %s' % (_("Invalid value for"), str(param)))
|
||||
|
||||
results = []
|
||||
|
||||
def recurse(geometry, reset=True):
|
||||
"""
|
||||
Creates a list of non-iterable linear geometry objects.
|
||||
Results are placed in self.flat_geometry
|
||||
|
||||
:param geometry: Shapely type or list or list of list of such.
|
||||
:param reset: Clears the contents of self.flat_geometry.
|
||||
"""
|
||||
|
||||
if geometry is None:
|
||||
return
|
||||
|
||||
if reset:
|
||||
self.flat_geo = []
|
||||
|
||||
# If iterable, expand recursively.
|
||||
try:
|
||||
for geo_el in geometry:
|
||||
if geo_el is not None:
|
||||
recurse(geometry=geo_el, reset=False)
|
||||
|
||||
# Not iterable, do the actual indexing and add.
|
||||
except TypeError:
|
||||
self.flat_geo.append(geometry)
|
||||
|
||||
return self.flat_geo
|
||||
|
||||
for geo in selected:
|
||||
|
||||
local_results = []
|
||||
for geo_obj in recurse(geo.geo):
|
||||
try:
|
||||
if type(geo_obj) == Polygon:
|
||||
poly_buf = geo_obj.buffer(-margin)
|
||||
else:
|
||||
poly_buf = Polygon(geo_obj).buffer(-margin)
|
||||
|
||||
if method == _("Seed"):
|
||||
cp = Geometry.clear_polygon2(
|
||||
geo_editor, polygon_to_clear=poly_buf, tooldia=tooldia,
|
||||
steps_per_circle=geo_editor.app.options["geometry_circle_steps"],
|
||||
overlap=overlap, contour=contour, connect=connect)
|
||||
elif method == _("Lines"):
|
||||
cp = Geometry.clear_polygon3(
|
||||
geo_editor, polygon=poly_buf, tooldia=tooldia,
|
||||
steps_per_circle=geo_editor.app.options["geometry_circle_steps"],
|
||||
overlap=overlap, contour=contour, connect=connect)
|
||||
else:
|
||||
cp = Geometry.clear_polygon(
|
||||
geo_editor, polygon=poly_buf, tooldia=tooldia,
|
||||
steps_per_circle=geo_editor.app.options["geometry_circle_steps"],
|
||||
overlap=overlap, contour=contour, connect=connect)
|
||||
|
||||
if cp is not None:
|
||||
local_results += list(cp.get_objects())
|
||||
except Exception as e:
|
||||
geo_editor.app.log.error("Could not Paint the polygons. %s" % str(e))
|
||||
geo_editor.app.inform.emit(
|
||||
'[ERROR] %s\n%s' % (_("Could not do Paint. Try a different combination of parameters. "
|
||||
"Or a different method of Paint"), str(e))
|
||||
)
|
||||
return
|
||||
|
||||
# add the result to the results list
|
||||
results.append(unary_union(local_results))
|
||||
|
||||
# This is a dirty patch:
|
||||
for r in results:
|
||||
geo_editor.add_shape(r)
|
||||
geo_editor.plot_all()
|
||||
geo_editor.build_ui_sig.emit()
|
||||
geo_editor.app.inform.emit('[success] %s' % _("Done."))
|
||||
|
||||
self.app.worker_task.emit({'fcn': work_task, 'params': [self.fcdraw]})
|
||||
self.layout.addStretch(1)
|
||||
|
||||
@@ -12,8 +12,6 @@ class TextInputTool(AppTool):
|
||||
Simple input for buffer distance.
|
||||
"""
|
||||
|
||||
pluginName = _("Text Input Tool")
|
||||
|
||||
def __init__(self, app, draw_app):
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
@@ -24,30 +22,58 @@ class TextInputTool(AppTool):
|
||||
|
||||
self.f_parse = ParseFont(self.app)
|
||||
self.f_parse.get_fonts_by_types()
|
||||
self.font_name = None
|
||||
self.font_bold = False
|
||||
self.font_italic = False
|
||||
|
||||
# this way I can hide/show the frame
|
||||
self.text_tool_frame = QtWidgets.QFrame()
|
||||
self.text_tool_frame.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout.addWidget(self.text_tool_frame)
|
||||
self.text_tools_box = QtWidgets.QVBoxLayout()
|
||||
self.text_tools_box.setContentsMargins(0, 0, 0, 0)
|
||||
self.text_tool_frame.setLayout(self.text_tools_box)
|
||||
self.ui = TextEditorUI(layout=self.layout, text_class=self)
|
||||
|
||||
# Title
|
||||
title_label = FCLabel("%s" % self.pluginName)
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.text_tools_box.addWidget(title_label)
|
||||
self.connect_signals_at_init()
|
||||
self.set_tool_ui()
|
||||
|
||||
# Grid Layout
|
||||
self.grid_text = GLay(v_spacing=5, h_spacing=3)
|
||||
self.text_tools_box.addLayout(self.grid_text)
|
||||
def run(self):
|
||||
self.app.defaults.report_usage("Geo Editor TextInputTool()")
|
||||
AppTool.run(self)
|
||||
|
||||
# if the splitter us hidden, display it
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
|
||||
# if the Tool Tab is hidden display it, else hide it but only if the objectName is the same
|
||||
found_idx = None
|
||||
for idx in range(self.app.ui.notebook.count()):
|
||||
if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab":
|
||||
found_idx = idx
|
||||
break
|
||||
# show the Tab
|
||||
if not found_idx:
|
||||
try:
|
||||
self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin"))
|
||||
except RuntimeError:
|
||||
self.app.ui.plugin_tab = QtWidgets.QWidget()
|
||||
self.app.ui.plugin_tab.setObjectName("plugin_tab")
|
||||
self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab)
|
||||
self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2)
|
||||
|
||||
self.app.ui.plugin_scroll_area = VerticalScrollArea()
|
||||
self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area)
|
||||
self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin"))
|
||||
# focus on Tool Tab
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab)
|
||||
|
||||
# self.app.ui.notebook.callback_on_close = self.on_tab_close
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Text Tool"))
|
||||
|
||||
def connect_signals_at_init(self):
|
||||
# Signals
|
||||
self.ui.apply_button.clicked.connect(self.on_apply_button)
|
||||
self.ui.font_type_cb.currentFontChanged.connect(self.font_family)
|
||||
self.ui.font_size_cb.activated.connect(self.font_size)
|
||||
self.ui.font_bold_tb.clicked.connect(self.on_bold_button)
|
||||
self.ui.font_italic_tb.clicked.connect(self.on_italic_button)
|
||||
|
||||
def set_tool_ui(self):
|
||||
# Font type
|
||||
if sys.platform == "win32":
|
||||
f_current = QtGui.QFont("Arial")
|
||||
@@ -57,16 +83,15 @@ class TextInputTool(AppTool):
|
||||
f_current = QtGui.QFont("Helvetica Neue")
|
||||
|
||||
self.font_name = f_current.family()
|
||||
|
||||
self.font_type_cb = QtWidgets.QFontComboBox(self)
|
||||
self.font_type_cb.setCurrentFont(f_current)
|
||||
self.grid_text.addWidget(FCLabel('%s:' % _("Font")), 0, 0)
|
||||
self.grid_text.addWidget(self.font_type_cb, 0, 1)
|
||||
self.ui.font_type_cb.setCurrentFont(f_current)
|
||||
|
||||
# Flag variables to show if font is bold, italic, both or none (regular)
|
||||
self.font_bold = False
|
||||
self.font_italic = False
|
||||
|
||||
self.ui.text_input_entry.setCurrentFont(f_current)
|
||||
self.ui.text_input_entry.setFontPointSize(10)
|
||||
|
||||
# # Create dictionaries with the filenames of the fonts
|
||||
# # Key: Fontname
|
||||
# # Value: Font File Name.ttf
|
||||
@@ -104,8 +129,105 @@ class TextInputTool(AppTool):
|
||||
# except WindowsError:
|
||||
# pass
|
||||
|
||||
# Font size
|
||||
def on_tab_close(self):
|
||||
self.draw_app.select_tool("select")
|
||||
self.app.ui.notebook.callback_on_close = lambda: None
|
||||
|
||||
def on_apply_button(self):
|
||||
font_to_geo_type = ""
|
||||
|
||||
if self.font_bold is True:
|
||||
font_to_geo_type = 'bold'
|
||||
elif self.font_italic is True:
|
||||
font_to_geo_type = 'italic'
|
||||
elif self.font_bold is True and self.font_italic is True:
|
||||
font_to_geo_type = 'bi'
|
||||
elif self.font_bold is False and self.font_italic is False:
|
||||
font_to_geo_type = 'regular'
|
||||
|
||||
string_to_geo = self.ui.text_input_entry.get_value()
|
||||
font_to_geo_size = self.ui.font_size_cb.get_value()
|
||||
|
||||
self.text_path = self.f_parse.font_to_geometry(char_string=string_to_geo, font_name=self.font_name,
|
||||
font_size=font_to_geo_size,
|
||||
font_type=font_to_geo_type,
|
||||
units=self.app.app_units.upper())
|
||||
|
||||
def font_family(self, font):
|
||||
self.ui.text_input_entry.selectAll()
|
||||
font.setPointSize(int(self.ui.font_size_cb.get_value()))
|
||||
self.ui.text_input_entry.setCurrentFont(font)
|
||||
self.font_name = self.ui.font_type_cb.currentFont().family()
|
||||
|
||||
def font_size(self):
|
||||
self.ui.text_input_entry.selectAll()
|
||||
self.ui.text_input_entry.setFontPointSize(float(self.ui.font_size_cb.get_value()))
|
||||
|
||||
def on_bold_button(self):
|
||||
if self.ui.font_bold_tb.isChecked():
|
||||
self.ui.text_input_entry.selectAll()
|
||||
self.ui.text_input_entry.setFontWeight(QtGui.QFont.Weight.Bold)
|
||||
self.font_bold = True
|
||||
else:
|
||||
self.ui.text_input_entry.selectAll()
|
||||
self.ui.text_input_entry.setFontWeight(QtGui.QFont.Weight.Normal)
|
||||
self.font_bold = False
|
||||
|
||||
def on_italic_button(self):
|
||||
if self.ui.font_italic_tb.isChecked():
|
||||
self.ui.text_input_entry.selectAll()
|
||||
self.ui.text_input_entry.setFontItalic(True)
|
||||
self.font_italic = True
|
||||
else:
|
||||
self.ui.text_input_entry.selectAll()
|
||||
self.ui.text_input_entry.setFontItalic(False)
|
||||
self.font_italic = False
|
||||
|
||||
def hide_tool(self):
|
||||
self.ui.text_tool_frame.hide()
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab)
|
||||
# self.app.ui.splitter.setSizes([0, 1])
|
||||
# self.app.ui.notebook.setTabText(2, _("Tool"))
|
||||
self.app.ui.notebook.removeTab(2)
|
||||
|
||||
|
||||
class TextEditorUI:
|
||||
pluginName = _("Text")
|
||||
|
||||
def __init__(self, layout, text_class):
|
||||
self.text_class = text_class
|
||||
self.decimals = self.text_class.app.decimals
|
||||
self.layout = layout
|
||||
self.app = self.text_class.app
|
||||
|
||||
# this way I can hide/show the frame
|
||||
self.text_tool_frame = QtWidgets.QFrame()
|
||||
self.text_tool_frame.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout.addWidget(self.text_tool_frame)
|
||||
self.text_tools_box = QtWidgets.QVBoxLayout()
|
||||
self.text_tools_box.setContentsMargins(0, 0, 0, 0)
|
||||
self.text_tool_frame.setLayout(self.text_tools_box)
|
||||
|
||||
# Title
|
||||
title_label = FCLabel("%s" % self.pluginName)
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.text_tools_box.addWidget(title_label)
|
||||
|
||||
# Grid Layout
|
||||
self.grid_text = GLay(v_spacing=5, h_spacing=3)
|
||||
self.text_tools_box.addLayout(self.grid_text)
|
||||
|
||||
self.font_type_cb = QtWidgets.QFontComboBox()
|
||||
self.grid_text.addWidget(FCLabel('%s:' % _("Font")), 0, 0)
|
||||
self.grid_text.addWidget(self.font_type_cb, 0, 1)
|
||||
|
||||
# Font size
|
||||
hlay = QtWidgets.QHBoxLayout()
|
||||
|
||||
self.font_size_cb = FCComboBox(policy=False)
|
||||
@@ -144,8 +266,7 @@ class TextInputTool(AppTool):
|
||||
self.text_input_entry.setTabStopDistance(12)
|
||||
self.text_input_entry.setMinimumHeight(200)
|
||||
# self.text_input_entry.setMaximumHeight(150)
|
||||
self.text_input_entry.setCurrentFont(f_current)
|
||||
self.text_input_entry.setFontPointSize(10)
|
||||
|
||||
self.grid_text.addWidget(self.text_input_entry, 6, 0, 1, 2)
|
||||
|
||||
# Buttons
|
||||
@@ -153,104 +274,3 @@ class TextInputTool(AppTool):
|
||||
self.grid_text.addWidget(self.apply_button, 8, 0, 1, 2)
|
||||
|
||||
# self.layout.addStretch()
|
||||
|
||||
# Signals
|
||||
self.apply_button.clicked.connect(self.on_apply_button)
|
||||
self.font_type_cb.currentFontChanged.connect(self.font_family)
|
||||
self.font_size_cb.activated.connect(self.font_size)
|
||||
self.font_bold_tb.clicked.connect(self.on_bold_button)
|
||||
self.font_italic_tb.clicked.connect(self.on_italic_button)
|
||||
|
||||
def run(self):
|
||||
self.app.defaults.report_usage("Geo Editor TextInputTool()")
|
||||
AppTool.run(self)
|
||||
|
||||
# if the splitter us hidden, display it
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
|
||||
# if the Tool Tab is hidden display it, else hide it but only if the objectName is the same
|
||||
found_idx = None
|
||||
for idx in range(self.app.ui.notebook.count()):
|
||||
if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab":
|
||||
found_idx = idx
|
||||
break
|
||||
# show the Tab
|
||||
if not found_idx:
|
||||
try:
|
||||
self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin"))
|
||||
except RuntimeError:
|
||||
self.app.ui.plugin_tab = QtWidgets.QWidget()
|
||||
self.app.ui.plugin_tab.setObjectName("plugin_tab")
|
||||
self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab)
|
||||
self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2)
|
||||
|
||||
self.app.ui.plugin_scroll_area = VerticalScrollArea()
|
||||
self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area)
|
||||
self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin"))
|
||||
# focus on Tool Tab
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab)
|
||||
|
||||
# self.app.ui.notebook.callback_on_close = self.on_tab_close
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Text Tool"))
|
||||
|
||||
def on_tab_close(self):
|
||||
self.draw_app.select_tool("select")
|
||||
self.app.ui.notebook.callback_on_close = lambda: None
|
||||
|
||||
def on_apply_button(self):
|
||||
font_to_geo_type = ""
|
||||
|
||||
if self.font_bold is True:
|
||||
font_to_geo_type = 'bold'
|
||||
elif self.font_italic is True:
|
||||
font_to_geo_type = 'italic'
|
||||
elif self.font_bold is True and self.font_italic is True:
|
||||
font_to_geo_type = 'bi'
|
||||
elif self.font_bold is False and self.font_italic is False:
|
||||
font_to_geo_type = 'regular'
|
||||
|
||||
string_to_geo = self.text_input_entry.get_value()
|
||||
font_to_geo_size = self.font_size_cb.get_value()
|
||||
|
||||
self.text_path = self.f_parse.font_to_geometry(char_string=string_to_geo, font_name=self.font_name,
|
||||
font_size=font_to_geo_size,
|
||||
font_type=font_to_geo_type,
|
||||
units=self.app.app_units.upper())
|
||||
|
||||
def font_family(self, font):
|
||||
self.text_input_entry.selectAll()
|
||||
font.setPointSize(float(self.font_size_cb.get_value()))
|
||||
self.text_input_entry.setCurrentFont(font)
|
||||
self.font_name = self.font_type_cb.currentFont().family()
|
||||
|
||||
def font_size(self):
|
||||
self.text_input_entry.selectAll()
|
||||
self.text_input_entry.setFontPointSize(float(self.font_size_cb.get_value()))
|
||||
|
||||
def on_bold_button(self):
|
||||
if self.font_bold_tb.isChecked():
|
||||
self.text_input_entry.selectAll()
|
||||
self.text_input_entry.setFontWeight(QtGui.QFont.Weight.Bold)
|
||||
self.font_bold = True
|
||||
else:
|
||||
self.text_input_entry.selectAll()
|
||||
self.text_input_entry.setFontWeight(QtGui.QFont.Weight.Normal)
|
||||
self.font_bold = False
|
||||
|
||||
def on_italic_button(self):
|
||||
if self.font_italic_tb.isChecked():
|
||||
self.text_input_entry.selectAll()
|
||||
self.text_input_entry.setFontItalic(True)
|
||||
self.font_italic = True
|
||||
else:
|
||||
self.text_input_entry.selectAll()
|
||||
self.text_input_entry.setFontItalic(False)
|
||||
self.font_italic = False
|
||||
|
||||
def hide_tool(self):
|
||||
self.text_tool_frame.hide()
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab)
|
||||
# self.app.ui.splitter.setSizes([0, 1])
|
||||
self.app.ui.notebook.setTabText(2, _("Tool"))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user