PVPlantTerrain: fix visualización en pantalla — updateData escuchaba Mesh en vez de mesh, añadido publishProperty forzado, más display modes

This commit is contained in:
Javier Braña
2026-05-02 23:49:48 +02:00
parent a515f31726
commit fc4142cfec
+30 -18
View File
@@ -198,6 +198,12 @@ class Terrain(ArchComponent.Component):
if prop == "InitialMesh":
obj.mesh = obj.InitialMesh.copy()
# Forzar actualización visual
obj.publishProperty("Mesh")
if prop == "mesh":
# La propiedad mesh cambió → forzar recompute para que updateData se dispare
pass
if prop == "DEM" or prop == "CuttingBoundary":
from datetime import datetime
@@ -357,7 +363,12 @@ class Terrain(ArchComponent.Component):
mesh.removeDuplicatedPoints()
mesh.removeFoldsOnSurface()
obj.InitialMesh = mesh.copy()
Mesh.show(mesh)
# Limpiar objetos mesh huérfanos previos
for o in FreeCAD.ActiveDocument.Objects:
if o.TypeId == 'Mesh::Feature' and o.Label.startswith('Terrain_mesh_'):
FreeCAD.ActiveDocument.removeObject(o.Name)
mesh_obj = Mesh.show(mesh)
mesh_obj.Label = 'Terrain_mesh_' + obj.Label
print(f'XYZ import: {len(pts_array)} puntos en {datetime.now()-t0}')
@@ -390,6 +401,11 @@ class Terrain(ArchComponent.Component):
if obj.DEM:
obj.DEM = None
obj.mesh = mesh
# Forzar actualización visual llamando a publishProperty
try:
obj.publishProperty("Mesh")
except:
pass
def execute(self, obj):
''''''
@@ -732,31 +748,27 @@ class ViewProviderTerrain:
self.major_coords.geoSystem.setValues(geo_system)
self.minor_coords.geoSystem.setValues(geo_system)
if prop == "Mesh":
if prop == "mesh" or prop == "Mesh":
if obj.mesh:
print("Mostrar mesh")
mesh = obj.mesh
vertices = [tuple(v) for v in mesh.Topology[0]]
faces = []
for face in mesh.Topology[1]:
faces.extend(face)
faces.append(-1)
try:
vertices = [tuple(v) for v in mesh.Topology[0]]
faces = []
for face in mesh.Topology[1]:
faces.extend(face)
faces.append(-1)
# Asignar a los nodos de visualización
self.geo_coords.point.values = vertices # <-- ¡Clave!
self.triangles.coordIndex.values = faces # <-- ¡Clave!
# Asignar a los nodos de visualización
self.geo_coords.point.values = vertices
self.triangles.coordIndex.values = faces
except Exception as e:
FreeCAD.Console.PrintError(f"Error actualizando mesh visual: {e}\n")
def getDisplayModes(self, vobj):
''' Return a list of display modes. '''
modes = ["Surface", "Boundary"]
return modes
return ["Surface", "Boundary", "Flat Lines", "Wireframe"]
def getDefaultDisplayMode(self):
'''
Return the name of the default display mode.
'''
return "Surface"
def claimChildren(self):