Platform: FeaturePython completo. Objeto Platform con SourceFrames, SlopeTolerance, Shape. EarthWorks acepta Platform o frames. ViewProvider verde semitransparente.
This commit is contained in:
+28
-12
@@ -31,30 +31,40 @@ else:
|
||||
|
||||
import PVPlantResources
|
||||
from PVPlantResources import DirIcons as DirIcons
|
||||
from .PVPlantPlatform import build_platform
|
||||
from .PVPlantPlatform import build_platform, get_platform_shape, make_platform
|
||||
|
||||
VOLUME_TYPES = ["Fill", "Cut"]
|
||||
|
||||
|
||||
def compute_earthworks(frames, terrain_mesh, slope_tolerance=10.0):
|
||||
def compute_earthworks(platform_or_frames, terrain_mesh, slope_tolerance=10.0):
|
||||
"""
|
||||
Calcula el movimiento de tierras para una lista de frames/trackers.
|
||||
Calcula el movimiento de tierras.
|
||||
|
||||
Args:
|
||||
frames: lista de objetos tracker
|
||||
platform_or_frames: Objeto Platform o lista de frames/trackers
|
||||
Si es Platform, usa su Shape directamente.
|
||||
Si es lista de frames, genera la plataforma primero.
|
||||
terrain_mesh: Mesh del terreno natural
|
||||
slope_tolerance: pendiente máxima E-W (grados)
|
||||
|
||||
Returns:
|
||||
tuple: (mesh_cut, mesh_fill, volume_cut_mm3, volume_fill_mm3)
|
||||
mesh_cut/mesh_fill pueden ser None si no hay volumen en esa categoría
|
||||
"""
|
||||
import MeshPart
|
||||
|
||||
# 1. Construir la plataforma (superficie diseñada) desde los trackers
|
||||
platform = build_platform(frames, slope_tolerance)
|
||||
if platform is None:
|
||||
return None, None, 0, 0
|
||||
# 1. Obtener la plataforma
|
||||
if hasattr(platform_or_frames, 'Proxy') and hasattr(platform_or_frames.Proxy, '__class__'):
|
||||
cls_name = platform_or_frames.Proxy.__class__.__name__
|
||||
if cls_name == 'Platform':
|
||||
# Ya es un objeto Platform → usar su Shape
|
||||
platform = get_platform_shape(platform_or_frames)
|
||||
else:
|
||||
platform = build_platform([platform_or_frames], slope_tolerance)
|
||||
elif hasattr(platform_or_frames, '__iter__'):
|
||||
# Es una lista de frames
|
||||
platform = build_platform(platform_or_frames, slope_tolerance)
|
||||
else:
|
||||
platform = None
|
||||
|
||||
# 2. Convertir plataforma a mesh para booleanos
|
||||
try:
|
||||
@@ -321,9 +331,14 @@ class EarthWorksTaskPanel:
|
||||
def accept(self):
|
||||
land = FreeCAD.ActiveDocument.Terrain.Mesh.copy()
|
||||
|
||||
# Detectar si hay un Platform seleccionado o trackers sueltos
|
||||
platform_obj = None
|
||||
frames = []
|
||||
|
||||
for obj in FreeCADGui.Selection.getSelection():
|
||||
if hasattr(obj, "Proxy"):
|
||||
if obj.Proxy.__class__.__name__ == 'Platform':
|
||||
platform_obj = obj
|
||||
t = getattr(obj.Proxy, "Type", None)
|
||||
if t == "Tracker" and obj not in frames:
|
||||
frames.append(obj)
|
||||
@@ -332,9 +347,9 @@ class EarthWorksTaskPanel:
|
||||
if fr not in frames:
|
||||
frames.append(fr)
|
||||
|
||||
if not frames:
|
||||
if not frames and not platform_obj:
|
||||
FreeCAD.Console.PrintWarning(
|
||||
"Selecciona trackers o un FrameArea\n")
|
||||
"Selecciona trackers, un FrameArea o un Platform\n")
|
||||
return False
|
||||
|
||||
slope = getattr(FreeCAD.ActiveDocument,
|
||||
@@ -342,8 +357,9 @@ class EarthWorksTaskPanel:
|
||||
|
||||
FreeCAD.ActiveDocument.openTransaction("Movimiento de tierras")
|
||||
try:
|
||||
input_data = platform_obj if platform_obj else frames
|
||||
cut_mesh, fill_mesh, vol_cut, vol_fill = compute_earthworks(
|
||||
frames, land, slope)
|
||||
input_data, land, slope)
|
||||
|
||||
if cut_mesh and cut_mesh.countPoints() > 3:
|
||||
v = makeEarthWorksVolume(1) # Cut
|
||||
|
||||
Reference in New Issue
Block a user