Punto de restauración.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import math
|
||||
import FreeCAD
|
||||
import Part
|
||||
from Utils.PVPlantUtils import findObjects
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
@@ -259,15 +260,60 @@ class exportDXF:
|
||||
'rotation': rotation
|
||||
})
|
||||
|
||||
def createPolyline(self, wire):
|
||||
def createPolyline(self, wire, layer=""):
|
||||
try:
|
||||
data = getWire(wire.Shape)
|
||||
lwp = self.msp.add_lwpolyline(data)
|
||||
if layer:
|
||||
lwp.dxf.layer = layer
|
||||
return lwp
|
||||
except Exception as e:
|
||||
print("Error creating polyline:", e)
|
||||
return None
|
||||
|
||||
def createHatch(self, wire, pattern="SOLID", scale=1.0, angle=0, layer=None):
|
||||
"""Crea un sombreado (hatch) para un área"""
|
||||
try:
|
||||
# Obtener los puntos en metros
|
||||
points = [(x, y) for (x, y, *_) in wire]
|
||||
|
||||
# Crear el hatch
|
||||
hatch = self.msp.add_hatch(color=7, dxfattribs={'layer': layer})
|
||||
|
||||
if pattern == "SOLID":
|
||||
# Sombreado sólido
|
||||
hatch.set_solid_fill()
|
||||
else:
|
||||
# Patrón de sombreado
|
||||
hatch.set_pattern_fill(name=pattern, scale=scale, angle=angle)
|
||||
|
||||
# Añadir el contorno
|
||||
hatch.paths.add_polyline_path(points, is_closed=True)
|
||||
return hatch
|
||||
except Exception as e:
|
||||
print("Error creating hatch:", e)
|
||||
return None
|
||||
|
||||
def export_feature_image(self, feature, layer_name):
|
||||
"""Exporta una imagen del GeoFeature y la añade al DXF"""
|
||||
try:
|
||||
# Añadir la imagen al DXF
|
||||
image_def = self.doc.add_image_def(feature.ImageFile, size_in_pixel=(feature.XSize, feature.YSize))
|
||||
self.msp.add_image(image_def,
|
||||
insert=(0, 0, 0),
|
||||
size_in_units=(feature.XSize,
|
||||
feature.YSize),
|
||||
rotation=0,
|
||||
dxfattribs={'layer': layer_name})
|
||||
|
||||
print(f"Imagen exportada para {feature.Label}")
|
||||
|
||||
# Eliminar el archivo temporal
|
||||
import os
|
||||
os.unlink(temp_img.name)
|
||||
except Exception as e:
|
||||
print(f"Error en exportación de imagen: {e}")
|
||||
|
||||
# =================================================================================
|
||||
# INTERFAZ DE USUARIO
|
||||
# =================================================================================
|
||||
@@ -575,6 +621,58 @@ class LineTypeComboBox(QtWidgets.QComboBox):
|
||||
finally:
|
||||
painter.end() # Asegurar que el painter se cierre correctamente
|
||||
|
||||
layers = [
|
||||
("Available area", QtGui.QColor(0, 204, 153), "Continuous", "1", True),
|
||||
("Available area Names", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
|
||||
("Areas Exclusion", QtGui.QColor(255, 85, 0), "Continuous", "1", True),
|
||||
("Areas Exclusion Name", QtGui.QColor(255, 85, 0), "Continuous", "1", True),
|
||||
("Areas Cadastral Plot", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("Areas Cadastral Plot Name", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("Areas Offset", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
|
||||
("Cable codes LV AC inverter", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("Cable codes LV string", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("Cable codes MV System", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("CABLES LV AC inverter 120 mm2", QtGui.QColor(255, 204, 0), "Continuous", "1", True),
|
||||
("CABLES LV AC inverter 185 mm2", QtGui.QColor(204, 153, 0), "Continuous", "1", True),
|
||||
("CABLES LV string 4 mm2", QtGui.QColor(255, 255, 0), "Continuous", "1", True),
|
||||
("CABLES LV string 10 mm2", QtGui.QColor(255, 255, 102), "Continuous", "1", True),
|
||||
("CABLES MV system 300 mm2", QtGui.QColor(102, 51, 0), "Continuous", "1", True),
|
||||
|
||||
("CIVIL Fence", QtGui.QColor(102, 102, 102), "FENCELINE1", "1", True),
|
||||
("CIVIL External Roads", QtGui.QColor(91, 91, 91), "Continuous", "1", True),
|
||||
("CIVIL External Roads Axis", QtGui.QColor(255, 255, 192), "Dashed", "1", True),
|
||||
("CIVIL External Roads Text", QtGui.QColor(255, 255, 192), "Continuous", "1", True),
|
||||
("CIVIL Internal Roads", QtGui.QColor(153, 95, 76), "Continuous", "1", True),
|
||||
("CIVIL Internal Roads Axis", QtGui.QColor(192, 192, 192), "Dashed", "1", True),
|
||||
("CIVIL External Roads Text", QtGui.QColor(192, 192, 192), "Continuous", "1", True),
|
||||
|
||||
("Contour Line Legend text", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("Major contour line", QtGui.QColor(0, 0, 0), "Continuous", "1", True),
|
||||
("Major contour value", QtGui.QColor(0, 0, 0), "Continuous", "1", True),
|
||||
("Minor contour line", QtGui.QColor(128, 128, 128), "Continuous", "1", True),
|
||||
("Minor contour value", QtGui.QColor(128, 128, 128), "Continuous", "1", True),
|
||||
("Power Stations", QtGui.QColor(255, 0, 0), "Continuous", "1", True),
|
||||
("Power Stations Names", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("ST", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("ST Names", QtGui.QColor(255, 255, 0), "Continuous", "1", True),
|
||||
("String Inv", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("STRUC Structure 1", QtGui.QColor(0, 0, 255), "Continuous", "1", True),
|
||||
("STRUC Structure 2", QtGui.QColor(0, 0, 204), "Continuous", "1", True),
|
||||
("STRUC Structure 3", QtGui.QColor(0, 0, 153), "Continuous", "1", True),
|
||||
("STRUC Structure 4", QtGui.QColor(0, 0, 128), "Continuous", "1", True),
|
||||
("STRUC Structure 5", QtGui.QColor(0, 0, 102), "Continuous", "1", True),
|
||||
("STRUC Structure 6", QtGui.QColor(0, 0, 76), "Continuous", "1", True),
|
||||
("STRUC Structure 7", QtGui.QColor(0, 0, 51), "Continuous", "1", True),
|
||||
("STRUC Structure 8", QtGui.QColor(0, 0, 25), "Continuous", "1", True),
|
||||
("Structure Codes", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("TRENCHES Low voltage 400.0 x 1000.0 m", QtGui.QColor(128, 128, 128), "Continuous", "1", True),
|
||||
("TRENCHES Medium voltage 400.0 x 1000.", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("TRENCHES Medium voltage 800.0 x 1000.", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
("TRENCHES Medium voltage 800.0 x 1500.", QtGui.QColor(255, 255, 255), "Continuous", "1", True),
|
||||
]
|
||||
|
||||
|
||||
class _PVPlantExportDXF(QtGui.QWidget):
|
||||
'''The editmode TaskPanel to select what you want to export'''
|
||||
@@ -610,10 +708,8 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
self.form.tableLayers.removeRow(row)
|
||||
|
||||
# Configuración de las capas por defecto
|
||||
self.add_row("Areas_Boundary", QtGui.QColor(0, 125, 125), "FENCELINE1", "1", True)
|
||||
self.add_row("Areas_Exclusion", QtGui.QColor(255, 0, 0), "CONTINUOUS", "1", True)
|
||||
self.add_row("Internal_Roads", QtGui.QColor(128, 128, 128), "CONTINUOUS", "1", True)
|
||||
self.add_row("Frames", QtGui.QColor(0, 255, 0), "CONTINUOUS", "1", True)
|
||||
for row in layers:
|
||||
self.add_row(*row)
|
||||
|
||||
def save_project_settings(self):
|
||||
"""Guarda la configuración actual en el proyecto de FreeCAD"""
|
||||
@@ -778,25 +874,25 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
)
|
||||
|
||||
def writeArea(self, exporter):
|
||||
exporter.createPolyline(FreeCAD.ActiveDocument.Site.Boundary, "boundary")
|
||||
|
||||
areas_types = ["Boundaries", "Exclusions", "Offsets"]
|
||||
exporter.createPolyline(FreeCAD.ActiveDocument.Site.Boundary, "Available area")
|
||||
areas_types = [("Boundaries", "Available area"),
|
||||
("CadastralPlots", "Areas Cadastral Plot"),
|
||||
("Exclusions", "Areas Exclusion"),
|
||||
("Offsets", "Areas Offset")]
|
||||
for area_type in areas_types:
|
||||
if hasattr(FreeCAD.ActiveDocument, area_type):
|
||||
for area in FreeCAD.ActiveDocument.Boundaries.Group:
|
||||
exporter.createPolyline(area, "Areas_Boundary")
|
||||
|
||||
'''for area in FreeCAD.ActiveDocument.Boundaries.Group:
|
||||
pol = exporter.createPolyline(area)
|
||||
pol.dxf.layer = "Areas_Boundary"
|
||||
|
||||
for area in FreeCAD.ActiveDocument.Exclusions.Group:
|
||||
pol = exporter.createPolyline(area)
|
||||
pol.dxf.layer = "Areas_Exclusion"
|
||||
|
||||
for area in FreeCAD.ActiveDocument.Offsets.Group:
|
||||
pol = exporter.createPolyline(area)
|
||||
pol.dxf.layer = "Areas_Offsets"'''
|
||||
if hasattr(FreeCAD.ActiveDocument, area_type[0]):
|
||||
area_group = FreeCAD.ActiveDocument.getObjectsByLabel(area_type[0])
|
||||
if len(area_group):
|
||||
for area in area_group[0].Group:
|
||||
tmp = exporter.createPolyline(area, area_type[1])
|
||||
if area_type[0] == "Exclusions":
|
||||
exporter.createHatch(
|
||||
tmp,
|
||||
pattern="ANSI37",
|
||||
scale=0.3,
|
||||
angle=0,
|
||||
layer=area_type[1]
|
||||
)
|
||||
|
||||
def writeFrameSetups(self, exporter):
|
||||
if not hasattr(FreeCAD.ActiveDocument, "Site"):
|
||||
@@ -811,11 +907,11 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
w.Placement.Base = w.Placement.Base.sub(center)
|
||||
block.add_lwpolyline(getWire(w))
|
||||
|
||||
block.add_circle((0, 0), 0.2, dxfattribs={'color': 2})
|
||||
block.add_circle((0, 0), 0.2, dxfattribs={'layer': 'Structure Posts'}) #'color': 2,
|
||||
p = math.sin(math.radians(45)) * 0.2
|
||||
|
||||
block.add_line((-p, -p), (p, p), dxfattribs={"layer": "MyLines"})
|
||||
block.add_line((-p, p), (p, -p), dxfattribs={"layer": "MyLines"})
|
||||
block.add_line((-p, -p), (p, p), dxfattribs={'layer': 'Structure Posts'})
|
||||
block.add_line((-p, p), (p, -p), dxfattribs={'layer': 'Structure Posts'})
|
||||
|
||||
# 2. Frames
|
||||
for ts in FreeCAD.ActiveDocument.Site.Frames:
|
||||
@@ -868,10 +964,10 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
|
||||
if FreeCAD.ActiveDocument.Transport:
|
||||
for road in FreeCAD.ActiveDocument.Transport.Group:
|
||||
base = exporter.createPolyline(road, "External_Roads")
|
||||
base = exporter.createPolyline(road, "CIVIL External Roads")
|
||||
base.dxf.const_width = road.Width
|
||||
|
||||
axis = exporter.createPolyline(road.Base, "External_Roads_Axis")
|
||||
axis = exporter.createPolyline(road, "CIVIL External Roads Axis")
|
||||
axis.dxf.const_width = .2
|
||||
|
||||
def writeTrenches(self, exporter):
|
||||
@@ -976,8 +1072,12 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
self.writeTrenches(exporter)
|
||||
|
||||
# Crear espacios de papel
|
||||
self.setup_layout4(exporter.doc)
|
||||
self.createPaperSpaces(exporter)
|
||||
#self.setup_layout4(exporter.doc)
|
||||
#self.createPaperSpaces(exporter)
|
||||
|
||||
if hasattr(FreeCAD.ActiveDocument, "Background"):
|
||||
# Exportar como imagen en lugar de polilínea
|
||||
exporter.export_feature_image(FreeCAD.ActiveDocument.Background, "Site_Image")
|
||||
|
||||
# Guardar archivo
|
||||
exporter.save()
|
||||
|
||||
Reference in New Issue
Block a user