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:
+30
-18
@@ -198,6 +198,12 @@ class Terrain(ArchComponent.Component):
|
|||||||
|
|
||||||
if prop == "InitialMesh":
|
if prop == "InitialMesh":
|
||||||
obj.mesh = obj.InitialMesh.copy()
|
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":
|
if prop == "DEM" or prop == "CuttingBoundary":
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -357,7 +363,12 @@ class Terrain(ArchComponent.Component):
|
|||||||
mesh.removeDuplicatedPoints()
|
mesh.removeDuplicatedPoints()
|
||||||
mesh.removeFoldsOnSurface()
|
mesh.removeFoldsOnSurface()
|
||||||
obj.InitialMesh = mesh.copy()
|
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}')
|
print(f'XYZ import: {len(pts_array)} puntos en {datetime.now()-t0}')
|
||||||
|
|
||||||
|
|
||||||
@@ -390,6 +401,11 @@ class Terrain(ArchComponent.Component):
|
|||||||
if obj.DEM:
|
if obj.DEM:
|
||||||
obj.DEM = None
|
obj.DEM = None
|
||||||
obj.mesh = mesh
|
obj.mesh = mesh
|
||||||
|
# Forzar actualización visual llamando a publishProperty
|
||||||
|
try:
|
||||||
|
obj.publishProperty("Mesh")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def execute(self, obj):
|
def execute(self, obj):
|
||||||
''''''
|
''''''
|
||||||
@@ -732,31 +748,27 @@ class ViewProviderTerrain:
|
|||||||
self.major_coords.geoSystem.setValues(geo_system)
|
self.major_coords.geoSystem.setValues(geo_system)
|
||||||
self.minor_coords.geoSystem.setValues(geo_system)
|
self.minor_coords.geoSystem.setValues(geo_system)
|
||||||
|
|
||||||
if prop == "Mesh":
|
if prop == "mesh" or prop == "Mesh":
|
||||||
if obj.mesh:
|
if obj.mesh:
|
||||||
print("Mostrar mesh")
|
|
||||||
|
|
||||||
mesh = obj.mesh
|
mesh = obj.mesh
|
||||||
vertices = [tuple(v) for v in mesh.Topology[0]]
|
try:
|
||||||
faces = []
|
vertices = [tuple(v) for v in mesh.Topology[0]]
|
||||||
for face in mesh.Topology[1]:
|
faces = []
|
||||||
faces.extend(face)
|
for face in mesh.Topology[1]:
|
||||||
faces.append(-1)
|
faces.extend(face)
|
||||||
|
faces.append(-1)
|
||||||
|
|
||||||
# Asignar a los nodos de visualización
|
# Asignar a los nodos de visualización
|
||||||
self.geo_coords.point.values = vertices # <-- ¡Clave!
|
self.geo_coords.point.values = vertices
|
||||||
self.triangles.coordIndex.values = faces # <-- ¡Clave!
|
self.triangles.coordIndex.values = faces
|
||||||
|
except Exception as e:
|
||||||
|
FreeCAD.Console.PrintError(f"Error actualizando mesh visual: {e}\n")
|
||||||
|
|
||||||
def getDisplayModes(self, vobj):
|
def getDisplayModes(self, vobj):
|
||||||
''' Return a list of display modes. '''
|
''' Return a list of display modes. '''
|
||||||
modes = ["Surface", "Boundary"]
|
return ["Surface", "Boundary", "Flat Lines", "Wireframe"]
|
||||||
|
|
||||||
return modes
|
|
||||||
|
|
||||||
def getDefaultDisplayMode(self):
|
def getDefaultDisplayMode(self):
|
||||||
'''
|
|
||||||
Return the name of the default display mode.
|
|
||||||
'''
|
|
||||||
return "Surface"
|
return "Surface"
|
||||||
|
|
||||||
def claimChildren(self):
|
def claimChildren(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user