Skip to content

Commit

Permalink
Fixing print_terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
r-monti14 committed Dec 6, 2024
1 parent a6f4055 commit 57d72d8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 58 deletions.
79 changes: 39 additions & 40 deletions pzero/three_d_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,11 @@ def decimation_quadric_resampling(self):
"Decimation Quadric: resample target surface and reduce number of triangles of the mesh"
)
if self.shown_table != "tabGeology":
self.parent.TextTerminal.appendPlainText(" -- Only geological objects can be resampled -- ")
self.print_terminal(" -- Only geological objects can be resampled -- ")
return
"""Check if some vtkPolyData is selected"""
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText("No input data selected.")
self.print_terminal("No input data selected.")
return
else:
"""Deep copy list of selected uids needed otherwise problems can arise if the main geology table is deseselcted while the dataframe is being built"""
Expand All @@ -1017,7 +1017,7 @@ def decimation_quadric_resampling(self):
if isinstance(self.geol_coll.get_uid_vtk_obj(uid), TriSurf):
pass
else:
self.parent.TextTerminal.appendPlainText(" -- Error input type: only TriSurf type -- ")
self.print_terminal(" -- Error input type: only TriSurf type -- ")
return
"""Create deepcopy of the geological entity dictionary."""
surf_dict = deepcopy(self.geol_coll.entity_dict)
Expand Down Expand Up @@ -1050,7 +1050,7 @@ def decimation_quadric_resampling(self):
if surf_dict["vtk_obj"].points_number > 0:
self.geol_coll.add_entity_from_dict(surf_dict)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object -- ")
self.print_terminal(" -- empty object -- ")


@freeze_gui
Expand All @@ -1060,15 +1060,15 @@ def subdivision_resampling(self, mode=0, type="linear", n_subd=2):
1. vtkLinearSubdivisionFilter (shape preserving)
2. vtkButterflySubdivisionFilter (not shape preserving)
3. vtkLoopSubdivisionFilter (not shape preserving)"""
self.parent.TextTerminal.appendPlainText(
self.print_terminal(
"Subdivision resampling: resample target surface and increase number of triangles of the mesh"
)
if self.shown_table != "tabGeology":
self.parent.TextTerminal.appendPlainText(" -- Only geological objects can be resampled -- ")
self.print_terminal(" -- Only geological objects can be resampled -- ")
return
"""Check if some vtkPolyData is selected"""
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText("No input data selected.")
self.print_terminal("No input data selected.")
return
else:
"""Deep copy list of selected uids needed otherwise problems can arise if the main geology table is
Expand Down Expand Up @@ -1112,23 +1112,22 @@ def subdivision_resampling(self, mode=0, type="linear", n_subd=2):
if surf_dict["vtk_obj"].points_number > 0:
self.geol_coll.add_entity_from_dict(surf_dict)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object -- ")
self.print_terminal(" -- empty object -- ")
else:
self.parent.TextTerminal.appendPlainText(" -- Error input type: only TriSurf type -- ")
self.print_terminal(" -- Error input type: only TriSurf type -- ")
return

@freeze_gui
def intersection_xs(self):
"""vtkCutter is a filter to cut through data using any subclass of vtkImplicitFunction.
HOW TO USE: select one or more Geological objects, DOMs or 3D Meshes (Source data), then function asks for XSection
(input data) for the filter."""
self.parent.TextTerminal.appendPlainText(
"Intersection with XSection: intersect Geological entities, 3D Meshes and DEM & DOMs"
)

self.print_terminal(
"Intersection with XSection: intersect Geological entities, 3D Meshes and DEM & DOMs"
"""Check if some vtkPolyData is selected"""
)
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText("No input data selected.")
self.print_terminal("No input data selected.")
return
else:
"""Deep copy list of selected uids needed otherwise problems can arise if the
Expand Down Expand Up @@ -1195,9 +1194,9 @@ def intersection_xs(self):
obj_dict["vtk_obj"].remove_point_data(data_key)
self.geol_coll.add_entity_from_dict(obj_dict)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object from cutter -- ")
self.print_terminal(" -- empty object from cutter -- ")
else:
self.parent.TextTerminal.appendPlainText(
self.print_terminal(
" -- no intersection of XsPolyLine with its own XSection -- "
)
elif self.geol_coll.get_uid_topology(uid) == "TriSurf":
Expand Down Expand Up @@ -1298,9 +1297,9 @@ def intersection_xs(self):
obj_dict["vtk_obj"].remove_point_data(data_key)
self.geol_coll.add_entity_from_dict(obj_dict)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object from connectivity_clean-- ")
self.print_terminal(" -- empty object from connectivity_clean-- ")
else:
self.parent.TextTerminal.appendPlainText(
self.print_terminal(
" -- empty object from cutter_clean_strips_clean_triangle -- "
)
elif self.shown_table == "tabMeshes3D":
Expand Down Expand Up @@ -1458,9 +1457,9 @@ def intersection_xs(self):
if obj_dict["vtk_obj"].points_number > 0:
self.mesh3d_coll.add_entity_from_dict(obj_dict)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object -- ")
self.print_terminal(" -- empty object -- ")
else:
self.parent.TextTerminal.appendPlainText(" -- empty object -- ")
self.print_terminal(" -- empty object -- ")
elif self.shown_table == "tabDOMs":
for uid in input_uids:
if self.dom_coll.get_uid_topology(uid) == "DEM":
Expand All @@ -1484,19 +1483,19 @@ def intersection_xs(self):
x_section_uid=xsect_uid, parent=self
)
obj_dict["vtk_obj"].DeepCopy(cutter.GetOutput())
self.parent.TextTerminal.appendPlainText("obj_dict['vtk_obj']:\n", obj_dict["vtk_obj"])
self.print_terminal("obj_dict['vtk_obj']:\n", obj_dict["vtk_obj"])
if obj_dict["vtk_obj"].points_number > 0:
for data_key in obj_dict["vtk_obj"].point_data_keys:
if not data_key in obj_dict["properties_names"]:
obj_dict["vtk_obj"].remove_point_data(data_key)
self.dom_coll.add_entity_from_dict(obj_dict)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object -- ")
self.print_terminal(" -- empty object -- ")
else:
print(
self.print_terminal(
" -- Only Geological objects, 3D Meshes and DEM & DOMs can be intersected with XSection -- "
)
self.parent.TextTerminal.appendPlainText



@freeze_gui
Expand All @@ -1505,13 +1504,13 @@ def project_2_dem(self):
HOW TO USE: at the moment, as vtkProjectedTerrainPath takes vtkImageData as input, we need to import
DEM file also as OrthoImage (--> as vtkImageData) and to use this entity as source data for the
projection"""
self.parent.TextTerminal.appendPlainText("Vertical Projection: project target lines onto a terrain image")
#self.print_terminal("Vertical Projection: project target lines onto a terrain image")
if self.shown_table != "tabGeology":
self.parent.TextTerminal.appendPlainText(" -- Only geological objects can be interpolated -- ")
self.print_terminal(" -- Only geological objects can be interpolated -- ")
return
"""Check if some vtkPolyData is selected"""
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText("No input data selected.")
self.print_terminal("No input data selected.")
return
else:
input_uids = deepcopy(self.selected_uids)
Expand Down Expand Up @@ -1617,7 +1616,7 @@ def project_2_dem(self):
if obj_dict["vtk_obj"].points_number > 0:
self.geol_coll.add_entity_from_dict(obj_dict)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object -- ")
self.print_terminal(" -- empty object -- ")
else:
self.geol_coll.replace_vtk(uid=uid, vtk_object=obj_dict["vtk_obj"])
self.geol_coll.set_uid_name(uid=uid, name=obj_dict["name"])
Expand All @@ -1631,14 +1630,14 @@ def project_2_dem(self):
@freeze_gui
def project_2_xs(self):
"""Projection of a copy of point and polyline geological entities to a planar cross section, along an axis specified with plunge/trend."""
self.parent.TextTerminal.appendPlainText("Projection to cross section")
#self.print_terminal("Projection to cross section")
"""Get input objects - points and polylines at the moment."""
if self.shown_table != "tabGeology":
self.parent.TextTerminal.appendPlainText(" -- Only geological objects can be projected -- ")
self.print_terminal(" -- Only geological objects can be projected -- ")
return
"""Check if some vtkPolyData is selected"""
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText("No input data selected.")
self.print_terminal("No input data selected.")
return
else:
"""Deep copy list of selected uids needed otherwise problems can arise if the main geology table is deseselcted while the dataframe is being built"""
Expand Down Expand Up @@ -1687,7 +1686,7 @@ def project_2_xs(self):
abs(self.xsect_coll.get_uid_azimuth(xs_uid) - proj_trend) < 10.0
or abs(self.xsect_coll.get_uid_azimuth(xs_uid) - 180.0 - proj_trend) < 10.0
):
self.parent.TextTerminal.appendPlainText("Plunge too close to being parallel to XSection (angle < 10°)")
self.print_terminal("Plunge too close to being parallel to XSection (angle < 10°)")
return
"""Get cross section start and end points (float64 needed for "t" afterwards)."""
xa = np_float64(self.xsect_coll.get_uid_base_x(xs_uid))
Expand Down Expand Up @@ -1774,7 +1773,7 @@ def project_2_xs(self):
entity_dict=entity_dict
)
else:
self.parent.TextTerminal.appendPlainText(
self.print_terminal(
f'No measure found for group {entity_dict["name"]}, try to extend the maximum distance'
)

Expand Down Expand Up @@ -1826,17 +1825,17 @@ def project_2_xs(self):
entity_dict=entity_dict
)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object -- ")
self.print_terminal(" -- empty object -- ")


@freeze_gui
def split_surf(self):
"""Split two surfaces. This should be integrated with intersection_xs in one function since is the same thing"""
if self.shown_table != "tabGeology":
self.parent.TextTerminal.appendPlainText(" -- Only surface objects can be intersected -- ")
self.print_terminal(" -- Only surface objects can be intersected -- ")
return
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText("No input data selected.")
self.print_terminal("No input data selected.")
return
else:
"""Deep copy list of selected uids needed otherwise problems can arise if the main geology table
Expand Down Expand Up @@ -1978,10 +1977,10 @@ def retopo(self, mode=0, dec_int=0.2, n_iter=40, rel_fac=0.1):
in the future it would be nicer to have an adaptive method (maybe using vtkMeshQuality?)
"""
if self.shown_table != "tabGeology":
self.parent.TextTerminal.appendPlainText(" -- Only geological objects can be retopologized -- ")
self.print_terminal(" -- Only geological objects can be retopologized -- ")
return
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText("No input data selected.")
self.print_terminal("No input data selected.")
return
else:
"""Deep copy list of selected uids needed otherwise problems can arise if the main geology table is deseselcted while the dataframe is being built"""
Expand Down Expand Up @@ -2032,7 +2031,7 @@ def retopo(self, mode=0, dec_int=0.2, n_iter=40, rel_fac=0.1):
if surf_dict["vtk_obj"].points_number > 0:
self.geol_coll.add_entity_from_dict(surf_dict)
else:
self.parent.TextTerminal.appendPlainText(" -- empty object -- ")
self.print_terminal(" -- empty object -- ")
else:
self.parent.TextTerminal.appendPlainText(" -- Error input type: only TriSurf type -- ")
self.print_terminal(" -- Error input type: only TriSurf type -- ")
return
36 changes: 18 additions & 18 deletions pzero/two_d_lines.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""three_d_surfaces.py
"""two_d_lines.py
PZero© Andrea Bistacchi"""

from copy import deepcopy
Expand Down Expand Up @@ -1123,7 +1123,7 @@ def copy_parallel(

"""Check if a line is selected"""
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText(" -- No input data selected -- ")
self.print_terminal(" -- No input data selected -- ")
return
if (
self.parent.geol_coll.get_uid_topology(self.selected_uids[0])
Expand All @@ -1132,7 +1132,7 @@ def copy_parallel(
self.parent.geol_coll.get_uid_topology(self.selected_uids[0])
!= "XsPolyLine"
):
self.parent.TextTerminal.appendPlainText(" -- Selected data is not a line -- ")
self.print_terminal(" -- Selected data is not a line -- ")
return
"""If more than one line is selected, keep the first."""
input_uid = self.selected_uids[0]
Expand Down Expand Up @@ -1199,7 +1199,7 @@ def copy_parallel(
outU = outUV[:, 0]
outV = outUV[:, 1]
else:
self.parent.TextTerminal.appendPlainText("Polyline is not simple, it self-intersects")
self.print_terminal("Polyline is not simple, it self-intersects")
for action in self.findChildren(QAction):
return
if isinstance(self, ViewMap):
Expand All @@ -1213,7 +1213,7 @@ def copy_parallel(
self.this_x_section_uid, outU, outV
)
"""Stack coordinates in two-columns matrix and write to vtk object."""
self.parent.TextTerminal.appendPlainText("outXYZ = np_column_stack((outX, outY, outZ))")
self.print_terminal("outXYZ = np_column_stack((outX, outY, outZ))")
outXYZ = np_column_stack((outX, outY, outZ))

line_dict["vtk_obj"].points = outXYZ
Expand All @@ -1223,7 +1223,7 @@ def copy_parallel(
output_uid = self.parent.geol_coll.add_entity_from_dict(line_dict)
left_right(output_uid)
else:
self.parent.TextTerminal.appendPlainText("Empty object")
self.print_terminal("Empty object")


@freeze_gui
Expand All @@ -1233,11 +1233,11 @@ def copy_kink(
"""Kink folding. Create a line copied and translated from a template line using Shapely.
Since lines are oriented left-to-right and bottom-to-top, and here we copy a line to the left,
a positive distance creates a line shifted upwards and to the left."""
self.parent.TextTerminal.appendPlainText("Copy Kink. Create a line copied and translated.")
self.print_terminal("Copy Kink. Create a line copied and translated.")
"""Terminate running event loops"""
"""Check if a line is selected"""
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText(" -- No input data selected -- ")
self.print_terminal(" -- No input data selected -- ")
return
if (
self.parent.geol_coll.get_uid_topology(self.selected_uids[0])
Expand All @@ -1246,7 +1246,7 @@ def copy_kink(
self.parent.geol_coll.get_uid_topology(self.selected_uids[0])
!= "XsPolyLine"
):
self.parent.TextTerminal.appendPlainText(" -- Selected data is not a line -- ")
self.print_terminal(" -- Selected data is not a line -- ")
return
"""If more than one line is selected, keep the first."""
input_uid = self.selected_uids[0]
Expand Down Expand Up @@ -1310,7 +1310,7 @@ def copy_kink(
outU = outUV[:, 0]
outV = outUV[:, 1]
else:
self.parent.TextTerminal.appendPlainText("Polyline is not simple, it self-intersects")
self.print_terminal("Polyline is not simple, it self-intersects")
return
if isinstance(self, ViewMap):
# if isinstance(self, (ViewMap, ViewMap)):
Expand All @@ -1331,7 +1331,7 @@ def copy_kink(
output_uid = self.parent.geol_coll.add_entity_from_dict(line_dict)
left_right(output_uid)
else:
self.parent.TextTerminal.appendPlainText("Empty object")
self.print_terminal("Empty object")


@freeze_gui
Expand All @@ -1341,12 +1341,12 @@ def copy_similar(
"""Similar folding. Create a line copied and translated from a template line.
Does not need U,V coordinates since the translation vector is already in world coords
"""
self.parent.TextTerminal.appendPlainText("Copy Similar. Create a line copied and translated.")
self.print_terminal("Copy Similar. Create a line copied and translated.")
"""Terminate running event loops"""
# self.stop_event_loops()
"""Check if a line is selected"""
if not self.selected_uids:
self.parent.TextTerminal.appendPlainText(" -- No input data selected -- ")
self.print_terminal(" -- No input data selected -- ")
return
if (
self.parent.geol_coll.get_uid_topology(self.selected_uids[0])
Expand All @@ -1355,7 +1355,7 @@ def copy_similar(
self.parent.geol_coll.get_uid_topology(self.selected_uids[0])
!= "XsPolyLine"
):
self.parent.TextTerminal.appendPlainText(" -- Selected data is not a line -- ")
self.print_terminal(" -- Selected data is not a line -- ")
return
"""If more than one line is selected, keep the first."""
input_uid = self.selected_uids[0]
Expand Down Expand Up @@ -1385,7 +1385,7 @@ def copy_similar(
inZ = self.parent.geol_coll.get_uid_vtk_obj(input_uid).points_Z
"""Get similar folding vector."""
if vector.length == 0:
self.parent.TextTerminal.appendPlainText("Zero-length vector")
self.print_terminal("Zero-length vector")
return

"""Create output line."""
Expand All @@ -1412,13 +1412,13 @@ def copy_similar(
self.clear_selection()
# self.parent.geol_coll.signals.geom_modified.emit([input_uid]) # emit uid as list to force redraw()
else:
self.parent.TextTerminal.appendPlainText("Empty object")
self.print_terminal("Empty object")



def measure_distance(self, vector):
"""Tool to measure distance between two points. Draw a vector_by_mouse and obtain length and azimuth"""
self.parent.TextTerminal.appendPlainText("Measure Distance between two points by drawing a vector by mouse")
self.print_terminal("Measure Distance between two points by drawing a vector by mouse")

def end_measure(event=None):
"""Cleanup function to properly end the measurement tool"""
Expand All @@ -1429,7 +1429,7 @@ def end_measure(event=None):
self.disable_actions()

if vector.length == 0:
self.parent.TextTerminal.appendPlainText("Zero-length vector")
self.print_terminal("Zero-length vector")
end_measure()
return

Expand Down

0 comments on commit 57d72d8

Please sign in to comment.