Punto de restauración.
This commit is contained in:
@@ -69,6 +69,7 @@ class _Area:
|
||||
''' Initialize the Area object '''
|
||||
self.Type = None
|
||||
self.obj = None
|
||||
self.setProperties(obj)
|
||||
|
||||
def setProperties(self, obj):
|
||||
pl = obj.PropertiesList
|
||||
@@ -101,18 +102,18 @@ class _Area:
|
||||
def __setstate__(self, state):
|
||||
pass
|
||||
|
||||
def execute(self, obj):
|
||||
''' Execute the area object '''
|
||||
pass
|
||||
|
||||
|
||||
class _ViewProviderArea:
|
||||
def __init__(self, vobj):
|
||||
self.Object = vobj.Object
|
||||
vobj.Proxy = self
|
||||
|
||||
def attach(self, vobj):
|
||||
'''
|
||||
Create Object visuals in 3D view.
|
||||
'''
|
||||
self.Object = vobj.Object
|
||||
return
|
||||
''' Create Object visuals in 3D view. '''
|
||||
self.ViewObject = vobj
|
||||
|
||||
def getIcon(self):
|
||||
'''
|
||||
@@ -120,6 +121,7 @@ class _ViewProviderArea:
|
||||
'''
|
||||
|
||||
return str(os.path.join(DirIcons, "area.svg"))
|
||||
|
||||
'''
|
||||
def claimChildren(self):
|
||||
"""
|
||||
@@ -159,17 +161,10 @@ class _ViewProviderArea:
|
||||
pass
|
||||
|
||||
def __getstate__(self):
|
||||
"""
|
||||
Save variables to file.
|
||||
"""
|
||||
return None
|
||||
|
||||
def __setstate__(self, state):
|
||||
"""
|
||||
Get variables from file.
|
||||
"""
|
||||
return None
|
||||
|
||||
pass
|
||||
|
||||
''' Frame Area '''
|
||||
|
||||
@@ -311,17 +306,14 @@ class ViewProviderFrameArea(_ViewProviderArea):
|
||||
|
||||
|
||||
''' offsets '''
|
||||
|
||||
|
||||
def makeOffsetArea(base = None, val=None):
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "OffsetArea")
|
||||
OffsetArea(obj)
|
||||
obj.Base = base
|
||||
ViewProviderOffsetArea(obj.ViewObject)
|
||||
if val:
|
||||
obj.Distance = val
|
||||
obj.OffsetDistance = val
|
||||
|
||||
offsets = None
|
||||
try:
|
||||
offsetsgroup = FreeCAD.ActiveDocument.Offsets
|
||||
except:
|
||||
@@ -334,11 +326,13 @@ def makeOffsetArea(base = None, val=None):
|
||||
|
||||
class OffsetArea(_Area):
|
||||
def __init__(self, obj):
|
||||
_Area.__init__(self, obj)
|
||||
self.setProperties(obj)
|
||||
'''_Area.__init__(self, obj)
|
||||
self.setProperties(obj)'''
|
||||
super().__init__(obj) # Llama al constructor de _Area
|
||||
|
||||
def setProperties(self, obj):
|
||||
_Area.setProperties(self, obj)
|
||||
super().setProperties(obj) # Propiedades de la clase base
|
||||
|
||||
pl = obj.PropertiesList
|
||||
if not ("OffsetDistance" in pl):
|
||||
obj.addProperty("App::PropertyDistance",
|
||||
@@ -354,24 +348,28 @@ class OffsetArea(_Area):
|
||||
self.setProperties(obj)
|
||||
|
||||
def execute(self, obj):
|
||||
import Utils.PVPlantUtils as utils
|
||||
# Comprobar dependencias críticas
|
||||
if not hasattr(obj, "Base") or not obj.Base or not obj.Base.Shape:
|
||||
return
|
||||
if not hasattr(PVPlantSite, "get") or not PVPlantSite.get().Terrain:
|
||||
return
|
||||
|
||||
base = obj.Base.Shape
|
||||
land = PVPlantSite.get().Terrain.Mesh
|
||||
vec = FreeCAD.Vector(0, 0, 1)
|
||||
|
||||
wire = utils.getProjected(base, vec)
|
||||
wire = wire.makeOffset2D(obj.OffsetDistance.Value, 2, False, False, True)
|
||||
tmp = mp.projectShapeOnMesh(wire, land, vec)
|
||||
sections = mp.projectShapeOnMesh(wire, land, vec)
|
||||
pts = []
|
||||
for section in tmp:
|
||||
for section in sections:
|
||||
pts.extend(section)
|
||||
obj.Shape = Part.makePolygon(pts)
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
def __setstate__(self, state):
|
||||
pass
|
||||
# Crear forma solo si hay resultados
|
||||
if sections:
|
||||
obj.Shape = Part.makePolygon(pts)
|
||||
else:
|
||||
obj.Shape = Part.Shape() # Forma vacía si falla
|
||||
|
||||
|
||||
class ViewProviderOffsetArea(_ViewProviderArea):
|
||||
@@ -382,14 +380,12 @@ class ViewProviderOffsetArea(_ViewProviderArea):
|
||||
def claimChildren(self):
|
||||
""" Provides object grouping """
|
||||
children = []
|
||||
if self.Object.Base:
|
||||
children.append(self.Object.Base)
|
||||
if self.ViewObject and self.ViewObject.Object.Base:
|
||||
children.append(self.ViewObject.Object.Base)
|
||||
return children
|
||||
|
||||
|
||||
''' Forbidden Area: '''
|
||||
|
||||
|
||||
def makeProhibitedArea(base = None):
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "ExclusionArea")
|
||||
ProhibitedArea(obj)
|
||||
@@ -416,33 +412,192 @@ class ProhibitedArea(OffsetArea):
|
||||
self.Type = obj.Type = "ProhibitedArea"
|
||||
obj.Proxy = self
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Method run when the document is restored."""
|
||||
self.setProperties(obj)
|
||||
'''# Propiedades de color
|
||||
if not hasattr(obj, "OriginalColor"):
|
||||
obj.addProperty("App::PropertyColor",
|
||||
"OriginalColor",
|
||||
"Display",
|
||||
"Color for original wire")
|
||||
obj.OriginalColor = (1.0, 0.0, 0.0) # Rojo
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
if not hasattr(obj, "OffsetColor"):
|
||||
obj.addProperty("App::PropertyColor",
|
||||
"OffsetColor",
|
||||
"Display",
|
||||
"Color for offset wire")
|
||||
obj.OffsetColor = (1.0, 0.5, 0.0) # Naranja
|
||||
|
||||
def __setstate__(self, state):
|
||||
pass
|
||||
# Propiedades de grosor
|
||||
if not hasattr(obj, "OriginalWidth"):
|
||||
obj.addProperty("App::PropertyFloat",
|
||||
"OriginalWidth",
|
||||
"Display",
|
||||
"Line width for original wire")
|
||||
obj.OriginalWidth = 4.0
|
||||
|
||||
if not hasattr(obj, "OffsetWidth"):
|
||||
obj.addProperty("App::PropertyFloat",
|
||||
"OffsetWidth",
|
||||
"Display",
|
||||
"Line width for offset wire")
|
||||
obj.OffsetWidth = 4.0'''
|
||||
|
||||
def execute(self, obj):
|
||||
# Comprobar dependencias
|
||||
if not hasattr(obj, "Base") or not obj.Base or not obj.Base.Shape:
|
||||
return
|
||||
if not hasattr(PVPlantSite, "get") or not PVPlantSite.get().Terrain:
|
||||
return
|
||||
|
||||
base = obj.Base.Shape
|
||||
land = PVPlantSite.get().Terrain.Mesh
|
||||
vec = FreeCAD.Vector(0, 0, 1)
|
||||
|
||||
# 1. Crear wire original
|
||||
original_wire = utils.getProjected(base, vec)
|
||||
sections_original = mp.projectShapeOnMesh(original_wire, land, vec)
|
||||
|
||||
# 2. Crear wire offset
|
||||
offset_wire = original_wire.makeOffset2D(obj.OffsetDistance.Value, 2, False, False, True)
|
||||
sections_offset = mp.projectShapeOnMesh(offset_wire, land, vec)
|
||||
|
||||
# Crear formas compuestas
|
||||
def make_polygon(sections):
|
||||
if not sections:
|
||||
return Part.Shape()
|
||||
pts = []
|
||||
for section in sections:
|
||||
pts.extend(section)
|
||||
return Part.makePolygon(pts)
|
||||
|
||||
compounds = []
|
||||
if sections_original:
|
||||
compounds.append(make_polygon(sections_original))
|
||||
if sections_offset:
|
||||
compounds.append(make_polygon(sections_offset))
|
||||
|
||||
if compounds:
|
||||
obj.Shape = Part.makeCompound(compounds)
|
||||
else:
|
||||
obj.Shape = Part.Shape()
|
||||
|
||||
# Actualizar colores en la vista
|
||||
if FreeCAD.GuiUp and obj.ViewObject:
|
||||
obj.ViewObject.Proxy.updateVisual()
|
||||
|
||||
|
||||
class ViewProviderForbiddenArea(_ViewProviderArea):
|
||||
def __init__(self, vobj):
|
||||
super().__init__(vobj)
|
||||
# Valores por defecto
|
||||
self.original_color = (1.0, 0.0, 0.0) # Rojo
|
||||
self.offset_color = (1.0, 0.5, 0.0) # Naranja
|
||||
self.original_width = 4.0
|
||||
self.offset_width = 4.0
|
||||
self.line_widths = [] # Almacenará los grosores por arista
|
||||
|
||||
vobj.LineColor = (1.0, 0.0, 0.0)
|
||||
vobj.LineWidth = 4
|
||||
vobj.PointColor = (1.0, 0.0, 0.0)
|
||||
vobj.PointSize = 4
|
||||
|
||||
def getIcon(self):
|
||||
''' Return object treeview icon '''
|
||||
''' Return object treeview icon. '''
|
||||
return str(os.path.join(DirIcons, "area_forbidden.svg"))
|
||||
|
||||
def claimChildren(self):
|
||||
""" Provides object grouping """
|
||||
children = []
|
||||
if self.Object.Base:
|
||||
children.append(self.Object.Base)
|
||||
if self.ViewObject and self.ViewObject.Object.Base:
|
||||
children.append(self.ViewObject.Object.Base)
|
||||
return children
|
||||
|
||||
def attach(self, vobj):
|
||||
super().attach(vobj)
|
||||
# Inicializar visualización
|
||||
self.updateVisual()
|
||||
|
||||
def updateVisual(self):
|
||||
"""Actualiza colores y grosores de línea"""
|
||||
if not hasattr(self, 'ViewObject') or not self.ViewObject or not self.ViewObject.Object:
|
||||
return
|
||||
|
||||
obj = self.ViewObject.Object
|
||||
|
||||
# Obtener propiedades de color y grosor
|
||||
try:
|
||||
self.original_color = obj.OriginalColor
|
||||
self.offset_color = obj.OffsetColor
|
||||
self.original_width = obj.OriginalWidth
|
||||
self.offset_width = obj.OffsetWidth
|
||||
except:
|
||||
pass
|
||||
|
||||
# Actualizar colores si hay forma
|
||||
if hasattr(obj, 'Shape') and obj.Shape and not obj.Shape.isNull():
|
||||
if len(obj.Shape.SubShapes) >= 2:
|
||||
# Asignar colores
|
||||
colors = []
|
||||
colors.append(self.original_color) # Primer wire (original)
|
||||
colors.append(self.offset_color) # Segundo wire (offset)
|
||||
self.ViewObject.DiffuseColor = colors
|
||||
|
||||
# Preparar grosores por arista
|
||||
#self.prepareLineWidths()
|
||||
|
||||
# Asignar grosores usando LineWidthArray
|
||||
'''if self.line_widths:
|
||||
self.ViewObject.LineWidthArray = self.line_widths'''
|
||||
|
||||
# Establecer grosor global como respaldo
|
||||
#self.ViewObject.LineWidth = max(self.original_width, self.offset_width)
|
||||
|
||||
def prepareLineWidths(self):
|
||||
"""Prepara la lista de grosores para cada arista"""
|
||||
self.line_widths = []
|
||||
obj = self.ViewObject.Object
|
||||
|
||||
if hasattr(obj, 'Shape') and obj.Shape and not obj.Shape.isNull():
|
||||
# Contar aristas en cada subforma
|
||||
for i, subshape in enumerate(obj.Shape.SubShapes):
|
||||
edge_count = len(subshape.Edges) if hasattr(subshape, 'Edges') else 1
|
||||
|
||||
# Determinar grosor según tipo de wire
|
||||
width = self.original_width if i == 0 else self.offset_width
|
||||
|
||||
# Asignar el mismo grosor a todas las aristas de este wire
|
||||
self.line_widths.extend([width] * edge_count)
|
||||
|
||||
def onChanged(self, vobj, prop):
|
||||
"""Maneja cambios en propiedades de visualización"""
|
||||
if prop in ["LineColor", "PointColor", "ShapeColor", "LineWidth"]:
|
||||
self.updateVisual()
|
||||
|
||||
def updateData(self, obj, prop):
|
||||
"""Actualiza cuando cambian los datos del objeto"""
|
||||
if prop == "Shape":
|
||||
self.updateVisual()
|
||||
|
||||
'''def __getstate__(self):
|
||||
return {
|
||||
"original_color": self.original_color,
|
||||
"offset_color": self.offset_color,
|
||||
"original_width": self.original_width,
|
||||
"offset_width": self.offset_width
|
||||
}
|
||||
|
||||
def __setstate__(self, state):
|
||||
if "original_color" in state:
|
||||
self.original_color = state["original_color"]
|
||||
if "offset_color" in state:
|
||||
self.offset_color = state["offset_color"]
|
||||
if "original_width" in state:
|
||||
self.original_width = state.get("original_width", 4.0)
|
||||
if "offset_width" in state:
|
||||
self.offset_width = state.get("offset_width", 4.0)'''
|
||||
|
||||
|
||||
''' PV Area: '''
|
||||
|
||||
|
||||
def makePVSubplant():
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "PVSubplant")
|
||||
PVSubplant(obj)
|
||||
|
||||
Reference in New Issue
Block a user