From fc4142cfecabc02ecaf745098ee885224af7108b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Bra=C3=B1a?= Date: Sat, 2 May 2026 23:49:48 +0200 Subject: [PATCH] =?UTF-8?q?PVPlantTerrain:=20fix=20visualizaci=C3=B3n=20en?= =?UTF-8?q?=20pantalla=20=E2=80=94=20updateData=20escuchaba=20Mesh=20en=20?= =?UTF-8?q?vez=20de=20mesh,=20a=C3=B1adido=20publishProperty=20forzado,=20?= =?UTF-8?q?m=C3=A1s=20display=20modes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PVPlantTerrain.py | 48 +++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/PVPlantTerrain.py b/PVPlantTerrain.py index 3f2ff50..91e31f7 100644 --- a/PVPlantTerrain.py +++ b/PVPlantTerrain.py @@ -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):