- Geometry Editor: fixed the selected shapes width issue; now the selected shapes are thicker

- Geometry Editor: no longer matter the order (top-bottom or bottom-top) of selection, now the last selected shape has the data updated in the UI
- Geometry Editor: fixed the simplification tool to work on a selection of shapes
This commit is contained in:
Marius Stanciu
2023-06-12 15:57:25 +03:00
parent 473470bf03
commit dd49b21176
3 changed files with 245 additions and 99 deletions

View File

@@ -7,6 +7,12 @@ CHANGELOG for FlatCAM Evo beta
================================================= =================================================
12.06.2023
- Geometry Editor: fixed the selected shapes width issue; now the selected shapes are thicker
- Geometry Editor: no longer matter the order (top-bottom or bottom-top) of selection, now the last selected shape has the data updated in the UI
- Geometry Editor: fixed the simplification tool to work on a selection of shapes
10.06.2023 10.06.2023
- Isolation Plugin and Isolate Tcl Command: optimized the isolation method - Isolation Plugin and Isolate Tcl Command: optimized the isolation method

View File

@@ -1892,14 +1892,10 @@ class FCSelect(DrawTool):
except Exception as e: except Exception as e:
log.error("[ERROR] AppGeoEditor.FCSelect.click_release() -> Something went bad. %s" % str(e)) log.error("[ERROR] AppGeoEditor.FCSelect.click_release() -> Something went bad. %s" % str(e))
# if selection is done on canvas update the Tree in Properties Tab with the selection self.draw_app.ui.tw.blockSignals(True)
try:
self.draw_app.ui.tw.itemPressed.disconnect(self.draw_app.on_tree_geo_click)
except (AttributeError, TypeError):
pass
self.draw_app.ui.tw.selectionModel().clearSelection() self.draw_app.ui.tw.selectionModel().clearSelection()
for sel_shape in self.draw_app.selected: for sel_shape in self.draw_app.get_selected():
iterator = QtWidgets.QTreeWidgetItemIterator(self.draw_app.ui.tw) iterator = QtWidgets.QTreeWidgetItemIterator(self.draw_app.ui.tw)
while iterator.value(): while iterator.value():
item = iterator.value() item = iterator.value()
@@ -1908,10 +1904,9 @@ class FCSelect(DrawTool):
item.setSelected(True) item.setSelected(True)
except ValueError: except ValueError:
pass pass
iterator += 1 iterator += 1
self.draw_app.ui.tw.itemPressed.connect(self.draw_app.on_tree_geo_click) self.draw_app.ui.tw.blockSignals(False)
# self.draw_app.ui.tw.itemClicked.emit(self.draw_app.ui.tw.currentItem(), 0) # self.draw_app.ui.tw.itemClicked.emit(self.draw_app.ui.tw.currentItem(), 0)
self.draw_app.update_ui() self.draw_app.update_ui()
@@ -3301,21 +3296,24 @@ class AppGeoEditor(QtCore.QObject):
# # ## Data # # ## Data
self.active_tool = None self.active_tool = None
self.storage = AppGeoEditor.make_storage() self.storage = self.make_storage()
self.utility = [] self.utility = []
# VisPy visuals # VisPy visuals
self.fcgeometry = None self.fcgeometry = None
if self.app.use_3d_engine: if self.app.use_3d_engine:
self.shapes = self.app.plotcanvas.new_shape_collection(layers=1) self.shapes = self.app.plotcanvas.new_shape_collection(layers=1)
self.sel_shapes = self.app.plotcanvas.new_shape_collection(layers=1)
self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1) self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1)
else: else:
from appGUI.PlotCanvasLegacy import ShapeCollectionLegacy from appGUI.PlotCanvasLegacy import ShapeCollectionLegacy
self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_geo_editor') self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_geo_editor')
self.sel_shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='sel_shapes_geo_editor')
self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_geo_editor') self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_geo_editor')
# Remove from scene # Remove from scene
self.shapes.enabled = False self.shapes.enabled = False
self.sel_shapes.enabled = False
self.tool_shape.enabled = False self.tool_shape.enabled = False
# List of selected shapes. # List of selected shapes.
@@ -3478,6 +3476,7 @@ class AppGeoEditor(QtCore.QObject):
def pool_recreated(self, pool): def pool_recreated(self, pool):
self.shapes.pool = pool self.shapes.pool = pool
self.sel_shapes.pool = pool
self.tool_shape.pool = pool self.tool_shape.pool = pool
def on_transform_complete(self): def on_transform_complete(self):
@@ -3605,17 +3604,27 @@ class AppGeoEditor(QtCore.QObject):
def on_geo_elem_selected(self): def on_geo_elem_selected(self):
pass pass
def update_ui(self): def update_ui(self, current_item: QtWidgets.QTreeWidgetItem = None):
self.selected = [] self.selected = []
last_obj_shape = None last_obj_shape = None
last_id = None last_id = None
if current_item:
last_id = current_item.text(0)
for obj_shape in self.storage.get_objects():
try:
if id(obj_shape) == int(last_id):
# self.selected.append(obj_shape)
last_obj_shape = obj_shape
except ValueError:
pass
else:
selected_tree_items = self.ui.tw.selectedItems() selected_tree_items = self.ui.tw.selectedItems()
for sel in selected_tree_items: for sel in selected_tree_items:
for obj_shape in self.storage.get_objects(): for obj_shape in self.storage.get_objects():
try: try:
if id(obj_shape) == int(sel.text(0)): if id(obj_shape) == int(sel.text(0)):
self.selected.append(obj_shape) # self.selected.append(obj_shape)
last_obj_shape = obj_shape last_obj_shape = obj_shape
last_id = sel.text(0) last_id = sel.text(0)
except ValueError: except ValueError:
@@ -3693,6 +3702,9 @@ class AppGeoEditor(QtCore.QObject):
assert isinstance(self.shapes, ShapeCollection) assert isinstance(self.shapes, ShapeCollection)
self.shapes.lock_updates() self.shapes.lock_updates()
assert isinstance(self.sel_shapes, ShapeCollection)
self.sel_shapes.lock_updates()
# adjust the view camera to be slightly bigger than the bounds so the shape collection can be # adjust the view camera to be slightly bigger than the bounds so the shape collection can be
# seen clearly otherwise the shape collection boundary will have no border # seen clearly otherwise the shape collection boundary will have no border
dx = rect.right - rect.left dx = rect.right - rect.left
@@ -3707,6 +3719,7 @@ class AppGeoEditor(QtCore.QObject):
self.app.plotcanvas.view.camera.rect = rect self.app.plotcanvas.view.camera.rect = rect
self.shapes.unlock_updates() self.shapes.unlock_updates()
self.sel_shapes.unlock_updates()
else: else:
width = xmax - xmin width = xmax - xmin
height = ymax - ymin height = ymax - ymin
@@ -3722,13 +3735,49 @@ class AppGeoEditor(QtCore.QObject):
self.app.inform.emit('%s: %s' % (_("Last selected shape ID"), str(last_id))) self.app.inform.emit('%s: %s' % (_("Last selected shape ID"), str(last_id)))
def on_tree_geo_click(self): def on_tree_geo_click(self, current_item, prev_item):
try: try:
self.update_ui() self.update_ui(current_item=current_item)
self.plot_all() # self.plot_all()
except Exception as e: except Exception as e:
self.app.log.error("APpGeoEditor.on_tree_selection_change() -> %s" % str(e)) self.app.log.error("APpGeoEditor.on_tree_selection_change() -> %s" % str(e))
def on_tree_selection(self):
selected_items = self.ui.tw.selectedItems()
if len(selected_items) == 0:
self.ui.is_valid_entry.set_value("None")
self.ui.is_empty_entry.set_value("None")
self.ui.is_simple_entry.set_value("None")
self.ui.is_ring_entry.set_value("None")
self.ui.is_ccw_entry.set_value("None")
self.ui.geo_len_entry.set_value("None")
self.ui.geo_coords_entry.setText("None")
self.ui.geo_vertex_entry.set_value("")
if len(selected_items) >= 1:
total_selected_shapes = []
for sel in selected_items:
for obj_shape in self.storage.get_objects():
try:
if id(obj_shape) == int(sel.text(0)):
total_selected_shapes.append(obj_shape)
except ValueError:
pass
self.selected = total_selected_shapes
self.plot_all()
total_geos = flatten_shapely_geometry([s.geo for s in total_selected_shapes])
total_vtx = 0
for geo in total_geos:
try:
total_vtx += len(geo.coords)
except AttributeError:
pass
self.ui.geo_all_vertex_entry.set_value(str(total_vtx))
def on_change_orientation(self): def on_change_orientation(self):
self.app.log.debug("AppGeoEditor.on_change_orientation()") self.app.log.debug("AppGeoEditor.on_change_orientation()")
@@ -3758,8 +3807,7 @@ class AppGeoEditor(QtCore.QObject):
except ValueError: except ValueError:
pass pass
for shape in processed_shapes: self.delete_shape(processed_shapes)
self.delete_shape(shape=shape)
for geo in new_shapes: for geo in new_shapes:
self.add_shape(DrawToolShape(geo), build_ui=False) self.add_shape(DrawToolShape(geo), build_ui=False)
@@ -3798,11 +3846,12 @@ class AppGeoEditor(QtCore.QObject):
self.connect_canvas_event_handlers() self.connect_canvas_event_handlers()
# initialize working objects # initialize working objects
self.storage = AppGeoEditor.make_storage() self.storage = self.make_storage()
self.utility = [] self.utility = []
self.selected = [] self.selected = []
self.shapes.enabled = True self.shapes.enabled = True
self.sel_shapes.enabled = True
self.tool_shape.enabled = True self.tool_shape.enabled = True
self.app.app_cursor.enabled = True self.app.app_cursor.enabled = True
@@ -3838,7 +3887,9 @@ class AppGeoEditor(QtCore.QObject):
self.item_selected.connect(self.on_geo_elem_selected) self.item_selected.connect(self.on_geo_elem_selected)
# ## appGUI Events # ## appGUI Events
self.ui.tw.itemPressed.connect(self.on_tree_geo_click) self.ui.tw.currentItemChanged.connect(self.on_tree_geo_click)
self.ui.tw.itemSelectionChanged.connect(self.on_tree_selection)
# self.ui.tw.keyPressed.connect(self.app.ui.keyPressEvent) # self.ui.tw.keyPressed.connect(self.app.ui.keyPressEvent)
# self.ui.tw.customContextMenuRequested.connect(self.on_menu_request) # self.ui.tw.customContextMenuRequested.connect(self.on_menu_request)
@@ -3873,6 +3924,7 @@ class AppGeoEditor(QtCore.QObject):
# Disable visuals # Disable visuals
self.shapes.enabled = False self.shapes.enabled = False
self.sel_shapes.enabled = False
self.tool_shape.enabled = False self.tool_shape.enabled = False
# disable text cursor (for FCPath) # disable text cursor (for FCPath)
@@ -3902,15 +3954,20 @@ class AppGeoEditor(QtCore.QObject):
try: try:
self.item_selected.disconnect() self.item_selected.disconnect()
except (AttributeError, TypeError): except (AttributeError, TypeError, RuntimeError):
pass pass
try: try:
# ## appGUI Events # ## appGUI Events
self.ui.tw.itemPressed.disconnect(self.on_tree_geo_click) self.ui.tw.currentItemChanged.disconnect(self.on_tree_geo_click)
# self.ui.tw.keyPressed.connect(self.app.ui.keyPressEvent) # self.ui.tw.keyPressed.connect(self.app.ui.keyPressEvent)
# self.ui.tw.customContextMenuRequested.connect(self.on_menu_request) # self.ui.tw.customContextMenuRequested.connect(self.on_menu_request)
except (AttributeError, TypeError): except (AttributeError, TypeError, RuntimeError):
pass
try:
self.ui.tw.itemSelectionChanged.disconnect(self.on_tree_selection)
except (AttributeError, TypeError, RuntimeError):
pass pass
# try: # try:
@@ -4218,6 +4275,7 @@ class AppGeoEditor(QtCore.QObject):
# self.shape_buffer = [] # self.shape_buffer = []
self.selected = [] self.selected = []
self.shapes.clear(update=True) self.shapes.clear(update=True)
self.sel_shapes.clear(update=True)
self.tool_shape.clear(update=True) self.tool_shape.clear(update=True)
# self.storage = AppGeoEditor.make_storage() # self.storage = AppGeoEditor.make_storage()
@@ -4554,7 +4612,7 @@ class AppGeoEditor(QtCore.QObject):
# ######### if selection is done on canvas update the Tree in Selected Tab with the selection ############### # ######### if selection is done on canvas update the Tree in Selected Tab with the selection ###############
# ############################################################################################################# # #############################################################################################################
try: try:
self.ui.tw.itemPressed.disconnect(self.on_tree_geo_click) self.ui.tw.currentItemChanged.disconnect(self.on_tree_geo_click)
except (AttributeError, TypeError): except (AttributeError, TypeError):
pass pass
@@ -4588,7 +4646,7 @@ class AppGeoEditor(QtCore.QObject):
self.ui.geo_vertex_entry.set_value(vertex_nr) self.ui.geo_vertex_entry.set_value(vertex_nr)
self.ui.tw.itemPressed.connect(self.on_tree_geo_click) self.ui.tw.currentItemChanged.connect(self.on_tree_geo_click)
self.plot_all() self.plot_all()
@@ -4663,13 +4721,22 @@ class AppGeoEditor(QtCore.QObject):
self.build_ui() self.build_ui()
self.plot_all() self.plot_all()
def delete_shape(self, shape): def delete_shape(self, shapes):
"""
Deletes shape(shapes) from the storage, selection and utility
"""
w_shapes = [shapes] if not isinstance(shapes, list) else shapes
for shape in w_shapes:
# remove from Storage
self.storage.remove(shape)
# remove from Utility
if shape in self.utility: if shape in self.utility:
self.utility.remove(shape) self.utility.remove(shape)
return return
self.storage.remove(shape) # remove from Selection
if shape in self.selected: if shape in self.selected:
self.selected.remove(shape) self.selected.remove(shape)
@@ -4711,7 +4778,7 @@ class AppGeoEditor(QtCore.QObject):
# return [shape for shape in self.shape_buffer if shape["selected"]] # return [shape for shape in self.shape_buffer if shape["selected"]]
return self.selected return self.selected
def plot_shape(self, geometry=None, color='#000000FF', linewidth=1): def plot_shape(self, storage, geometry=None, color='#000000FF', linewidth=1, layer=0):
""" """
Plots a geometric object or list of objects without rendering. Plotted objects Plots a geometric object or list of objects without rendering. Plotted objects
are returned as a list. This allows for efficient/animated rendering. are returned as a list. This allows for efficient/animated rendering.
@@ -4742,13 +4809,12 @@ class AppGeoEditor(QtCore.QObject):
# plot_elements += self.plot_shape(geometry=geometry.interiors, color=color, linewidth=linewidth) # plot_elements += self.plot_shape(geometry=geometry.interiors, color=color, linewidth=linewidth)
if isinstance(geometry, Polygon): if isinstance(geometry, Polygon):
plot_elements.append(self.shapes.add(shape=geometry, color=color, face_color=color[:-2] + '50', layer=0, plot_elements.append(storage.add(shape=geometry, color=color, face_color=color[:-2] + '50',
tolerance=self.fcgeometry.drawing_tolerance, layer=layer, tolerance=self.fcgeometry.drawing_tolerance,
linewidth=linewidth)) linewidth=linewidth))
if isinstance(geometry, (LineString, LinearRing)): if isinstance(geometry, (LineString, LinearRing)):
plot_elements.append(self.shapes.add(shape=geometry, color=color, layer=0, plot_elements.append(storage.add(shape=geometry, color=color, layer=layer,
tolerance=self.fcgeometry.drawing_tolerance, tolerance=self.fcgeometry.drawing_tolerance, linewidth=linewidth))
linewidth=linewidth))
if type(geometry) == Point: if type(geometry) == Point:
pass pass
@@ -4764,25 +4830,38 @@ class AppGeoEditor(QtCore.QObject):
""" """
# self.app.log.debug(str(inspect.stack()[1][3]) + " --> AppGeoEditor.plot_all()") # self.app.log.debug(str(inspect.stack()[1][3]) + " --> AppGeoEditor.plot_all()")
self.shapes.clear(update=True)
orig_draw_color = self.get_draw_color() orig_draw_color = self.get_draw_color()
draw_color = orig_draw_color[:-2] + "FF" draw_color = orig_draw_color[:-2] + "FF"
orig_sel_color = self.get_sel_color() orig_sel_color = self.get_sel_color()
sel_color = orig_sel_color[:-2] + 'FF' sel_color = orig_sel_color[:-2] + 'FF'
geo_drawn = []
geos_selected = []
for shape in self.storage.get_objects(): for shape in self.storage.get_objects():
if shape.geo and not shape.geo.is_empty and shape.geo.is_valid: if shape.geo and not shape.geo.is_empty and shape.geo.is_valid:
if shape in self.selected: if shape in self.get_selected():
self.plot_shape(geometry=shape.geo, color=sel_color) geos_selected.append(shape.geo)
else: else:
self.plot_shape(geometry=shape.geo, color=draw_color) geo_drawn.append(shape.geo)
if geo_drawn:
self.shapes.clear(update=True)
for geo in geo_drawn:
self.plot_shape(storage=self.shapes, geometry=geo, color=draw_color, linewidth=1)
for shape in self.utility: for shape in self.utility:
self.plot_shape(geometry=shape.geo, linewidth=1) self.plot_shape(storage=self.shapes, geometry=shape.geo, linewidth=1)
self.shapes.redraw() self.shapes.redraw()
if geos_selected:
self.sel_shapes.clear(update=True)
for geo in geos_selected:
self.plot_shape(storage=self.sel_shapes, geometry=geo, color=sel_color, linewidth=3)
self.sel_shapes.redraw()
def on_shape_complete(self): def on_shape_complete(self):
self.app.log.debug("on_shape_complete()") self.app.log.debug("on_shape_complete()")
@@ -5601,9 +5680,9 @@ class AppGeoEditorUI:
self.tools_box.addLayout(v_grid) self.tools_box.addLayout(v_grid)
# Vertex Points Number # Vertex Points Number
vertex_lbl = FCLabel('%s' % _("Vertex Points"), bold=True) vertex_lbl = FCLabel('%s' % _("Last Vertexes"), bold=True)
vertex_lbl.setToolTip( vertex_lbl.setToolTip(
_("The number of vertex points in the selected geometry element.") _("The number of vertex points in the last selected geometry element.")
) )
self.geo_vertex_entry = FCEntry(decimals=self.decimals) self.geo_vertex_entry = FCEntry(decimals=self.decimals)
self.geo_vertex_entry.setReadOnly(True) self.geo_vertex_entry.setReadOnly(True)
@@ -5611,6 +5690,17 @@ class AppGeoEditorUI:
v_grid.addWidget(vertex_lbl, 0, 0) v_grid.addWidget(vertex_lbl, 0, 0)
v_grid.addWidget(self.geo_vertex_entry, 0, 1) v_grid.addWidget(self.geo_vertex_entry, 0, 1)
# All selected Vertex Points Number
vertex_all_lbl = FCLabel('%s' % _("Selected Vertexes"), bold=True)
vertex_all_lbl.setToolTip(
_("The number of vertex points in all selected geometry elements.")
)
self.geo_all_vertex_entry = FCEntry(decimals=self.decimals)
self.geo_all_vertex_entry.setReadOnly(True)
v_grid.addWidget(vertex_all_lbl, 2, 0)
v_grid.addWidget(self.geo_all_vertex_entry, 2, 1)
GLay.set_common_column_size([grid0, v_grid, tw_grid, coords_grid, dia_grid, par_grid], 0) GLay.set_common_column_size([grid0, v_grid, tw_grid, coords_grid, dia_grid, par_grid], 0)
layout.addStretch(1) layout.addStretch(1)

View File

@@ -4,6 +4,9 @@ from appTool import AppToolEditor
from appGUI.GUIElements import VerticalScrollArea, GLay, FCLabel, FCButton, FCFrame, FCTextEdit, FCEntry, \ from appGUI.GUIElements import VerticalScrollArea, GLay, FCLabel, FCButton, FCFrame, FCTextEdit, FCEntry, \
FCDoubleSpinner FCDoubleSpinner
# from camlib import flatten_shapely_geometry
from copy import deepcopy
import gettext import gettext
import appTranslation as fcTranslate import appTranslation as fcTranslate
import builtins import builtins
@@ -23,9 +26,9 @@ class SimplificationTool(AppToolEditor):
def __init__(self, app, draw_app): def __init__(self, app, draw_app):
AppToolEditor.__init__(self, app) AppToolEditor.__init__(self, app)
self.draw_app = draw_app self.geo_editor = draw_app
self.decimals = app.decimals self.decimals = app.decimals
self.app = self.draw_app.app self.app = self.geo_editor.app
self.ui = SimplificationEditorUI(layout=self.layout, simp_class=self) self.ui = SimplificationEditorUI(layout=self.layout, simp_class=self)
self.plugin_name = self.ui.pluginName self.plugin_name = self.ui.pluginName
@@ -75,89 +78,136 @@ class SimplificationTool(AppToolEditor):
def set_tool_ui(self): def set_tool_ui(self):
# Init appGUI # Init appGUI
self.ui.geo_tol_entry.set_value(0.01 if self.draw_app.units == 'MM' else 0.0004) self.ui.geo_tol_entry.set_value(0.01 if self.geo_editor.units == 'MM' else 0.0004)
selected_shapes_geos = [] selected_shapes_geos = []
selected_tree_items = self.draw_app.ui.tw.selectedItems() selected_tree_items = self.geo_editor.ui.tw.selectedItems()
for sel in selected_tree_items: for sel in selected_tree_items:
for obj_shape in self.draw_app.storage.get_objects(): for obj_shape in self.geo_editor.storage.get_objects():
try: try:
if id(obj_shape) == int(sel.text(0)): if id(obj_shape) == int(sel.text(0)):
selected_shapes_geos.append(obj_shape.geo) selected_shapes_geos.append(obj_shape.geo)
except ValueError: except (ValueError, AttributeError):
pass pass
if selected_shapes_geos: if selected_shapes_geos:
# those are displayed by triggering the signal self.update_ui # those are displayed by triggering the signal self.update_ui
self.calculate_coords_vertex(selected_shapes_geos[-1]) self.calculate_coords_vertex(selected_shapes_geos)
def on_tab_close(self): def on_tab_close(self):
self.draw_app.select_tool("select") self.geo_editor.select_tool("select")
self.app.ui.notebook.callback_on_close = lambda: None self.app.ui.notebook.callback_on_close = lambda: None
def on_simplification_click(self): def on_simplification_click(self):
self.app.log.debug("FCSimplification.on_simplification_click()") self.app.log.debug("FCSimplification.on_simplification_click()")
selected_shapes_geos = []
tol = self.ui.geo_tol_entry.get_value() tol = self.ui.geo_tol_entry.get_value()
def task_job(self_class): def task_job(geo_editor):
with self_class.app.proc_container.new('%s...' % _("Simplify")): with self.app.proc_container.new('%s...' % _("Simplifying")):
selected_shapes = self_class.draw_app.get_selected() geo_editor.interdict_selection = True
self_class.draw_app.interdict_selection = True
for obj_shape in selected_shapes:
selected_shapes_geos.append(obj_shape.geo.simplify(tolerance=tol))
if not selected_shapes: # Simplification
self_class.app.inform.emit('%s' % _("Failed.")) selected_shapes = geo_editor.selected
selected_shapes_geos = [
deepcopy(obj_shape.geo.simplify(tolerance=tol)) for obj_shape in selected_shapes
]
not_selected_geos = [
obj_shape for obj_shape in geo_editor.storage.get_objects() if obj_shape not in selected_shapes
]
if not selected_shapes or not selected_shapes_geos:
self.app.inform.emit('%s' % _("Failed."))
return return
for shape in selected_shapes: # reset the old storage
self_class.draw_app.delete_shape(shape=shape) geo_editor.storage = geo_editor.make_storage()
geo_editor.ui.tw.blockSignals(True)
# add again the shapes (modified and non-modified
for geo in not_selected_geos + selected_shapes_geos:
geo_editor.add_shape(geo, build_ui=False)
geo_editor.ui.tw.blockSignals(False)
for geo in selected_shapes_geos: # # -----------------------------------------------------
self_class.draw_app.add_shape(geo, build_ui=False) # # Shape Deletion -> Shape Adding
# # geo_editor.ui.tw.blockSignals(True)
# geo_editor.delete_shape(selected_shapes)
#
# # while adding the shape also add it to selected
# for geo in selected_shapes_geos:
# geo_editor.add_shape(geo, build_ui=False)
# # geo_editor.ui.tw.blockSignals(False)
# # -----------------------------------------------------
self_class.draw_app.selected = [] self.calculate_coords_vertex(selected_shapes_geos)
geo_editor.plot_all()
last_sel_geo = selected_shapes_geos[-1] geo_editor.interdict_selection = False
self_class.calculate_coords_vertex(last_sel_geo) geo_editor.build_ui_sig.emit()
self.app.inform.emit('%s' % _("Done."))
self_class.app.inform.emit('%s' % _("Done.")) self.app.worker_task.emit({'fcn': task_job, 'params': [self.geo_editor]})
self_class.draw_app.plot_all() def calculate_coords_vertex(self, selected_geos):
self_class.draw_app.interdict_selection = False
self_class.draw_app.build_ui_sig.emit()
self.app.worker_task.emit({'fcn': task_job, 'params': [self]})
def calculate_coords_vertex(self, last_sel_geo):
if last_sel_geo:
if last_sel_geo.geom_type == 'MultiLineString':
coords = ''
vertex_nr = 0 vertex_nr = 0
for idx, line in enumerate(last_sel_geo.geoms): coords = ''
for c_geo in selected_geos:
if c_geo.geom_type == 'MultiLineString':
for idx, line in enumerate(c_geo.geoms):
line_coords = list(line.coords) line_coords = list(line.coords)
vertex_nr += len(line_coords) vertex_nr += len(line_coords)
coords += 'Line %s\n' % str(idx) coords += 'Line %s\n' % str(idx)
coords += str(line_coords) + '\n' coords += str(line_coords) + '\n'
elif last_sel_geo.geom_type == 'MultiPolygon': elif c_geo.geom_type == 'MultiPolygon':
coords = '' for idx, poly in enumerate(c_geo.geoms):
vertex_nr = 0
for idx, poly in enumerate(last_sel_geo.geoms):
poly_coords = list(poly.exterior.coords) + [list(i.coords) for i in poly.interiors] poly_coords = list(poly.exterior.coords) + [list(i.coords) for i in poly.interiors]
vertex_nr += len(poly_coords) vertex_nr += len(poly_coords)
coords += 'Polygon %s\n' % str(idx) coords += 'Polygon %s\n' % str(idx)
coords += str(poly_coords) + '\n' coords += str(poly_coords) + '\n'
elif last_sel_geo.geom_type in ['LinearRing', 'LineString']: elif c_geo.geom_type in ['LinearRing', 'LineString']:
coords = list(last_sel_geo.coords) line_coords = list(c_geo.coords)
vertex_nr = len(coords) coords += 'Line \n'
elif last_sel_geo.geom_type == 'Polygon': coords += str(line_coords) + '\n'
coords = list(last_sel_geo.exterior.coords)
vertex_nr = len(coords) vertex_nr += len(line_coords)
elif c_geo.geom_type == 'Polygon':
line_coords = list(c_geo.exterior.coords)
coords += 'Line \n'
coords += str(line_coords) + '\n'
vertex_nr += len(line_coords)
else: else:
coords = 'None' coords += 'None\n'
vertex_nr = 0
# if last_sel_geo:
# if last_sel_geo.geom_type == 'MultiLineString':
# coords = ''
# vertex_nr = 0
# for idx, line in enumerate(last_sel_geo.geoms):
# line_coords = list(line.coords)
# vertex_nr += len(line_coords)
# coords += 'Line %s\n' % str(idx)
# coords += str(line_coords) + '\n'
# elif last_sel_geo.geom_type == 'MultiPolygon':
# coords = ''
# vertex_nr = 0
# for idx, poly in enumerate(last_sel_geo.geoms):
# poly_coords = list(poly.exterior.coords) + [list(i.coords) for i in poly.interiors]
# vertex_nr += len(poly_coords)
#
# coords += 'Polygon %s\n' % str(idx)
# coords += str(poly_coords) + '\n'
# elif last_sel_geo.geom_type in ['LinearRing', 'LineString']:
# coords = list(last_sel_geo.coords)
# vertex_nr = len(coords)
# elif last_sel_geo.geom_type == 'Polygon':
# coords = list(last_sel_geo.exterior.coords)
# vertex_nr = len(coords)
# else:
# coords = 'None'
# vertex_nr = 0
self.update_ui.emit(coords, vertex_nr) self.update_ui.emit(coords, vertex_nr)