mejoras
This commit is contained in:
@@ -4,7 +4,7 @@ from Utils.PVPlantUtils import findObjects
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
from PySide import QtCore, QtGui
|
||||
from PySide import QtCore, QtGui, QtWidgets
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import os
|
||||
@@ -28,10 +28,164 @@ from PVPlantResources import DirIcons as DirIcons
|
||||
field = {"name": "", "width": 0, "heigth": 0}
|
||||
|
||||
|
||||
class LineTypeDelegate(QtWidgets.QStyledItemDelegate):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.line_types = [
|
||||
{"name": "Continuous", "pen": QtCore.Qt.SolidLine},
|
||||
{"name": "Dashed", "pen": QtCore.Qt.DashLine},
|
||||
{"name": "Dotted", "pen": QtCore.Qt.DotLine},
|
||||
{"name": "Dash-Dot", "pen": QtCore.Qt.DashDotLine},
|
||||
{"name": "Dash-Dot-Dot", "pen": QtCore.Qt.DashDotDotLine}
|
||||
]
|
||||
|
||||
def paint(self, painter, option, index):
|
||||
# Dibujar el fondo
|
||||
painter.save()
|
||||
painter.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||
|
||||
# Configuraciones comunes
|
||||
line_color = QtGui.QColor(0, 0, 0) # Color de la línea
|
||||
line_width = 2 # Grosor de línea
|
||||
|
||||
# Dibujar el ítem base
|
||||
super().paint(painter, option, index)
|
||||
|
||||
# Obtener el tipo de línea
|
||||
line_type = self.line_types[index.row()]
|
||||
|
||||
# Configurar el área de dibujo
|
||||
text_rect = option.rect.adjusted(5, 0, -100, 0)
|
||||
line_rect = option.rect.adjusted(option.rect.width() - 90, 2, -5, -2)
|
||||
|
||||
# Dibujar el texto
|
||||
painter.drawText(text_rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, line_type["name"])
|
||||
|
||||
# Dibujar la línea de muestra
|
||||
pen = QtGui.QPen(line_color, line_width, line_type["pen"])
|
||||
painter.setPen(pen)
|
||||
|
||||
start_y = line_rect.center().y()
|
||||
painter.drawLine(line_rect.left(), start_y, line_rect.right(), start_y)
|
||||
|
||||
painter.restore()
|
||||
|
||||
def sizeHint(self, option, index):
|
||||
size = super().sizeHint(option, index)
|
||||
size.setHeight(25) # Altura aumentada para mejor visualización
|
||||
return size
|
||||
|
||||
|
||||
class LineTypePreviewDelegate(QtWidgets.QStyledItemDelegate):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
'''self.line_types = [
|
||||
("Continuous", QtCore.Qt.SolidLine),
|
||||
("Dashed", QtCore.Qt.DashLine),
|
||||
("Dotted", QtCore.Qt.DotLine),
|
||||
("Dash-Dot", QtCore.Qt.DashDotLine),
|
||||
("Dash-Dot-Dot", QtCore.Qt.DashDotDotLine)
|
||||
]'''
|
||||
|
||||
self.line_types = [
|
||||
{"name": "Continuous", "style": QtCore.Qt.SolidLine},
|
||||
{"name": "Dashed", "style": QtCore.Qt.DashLine},
|
||||
{"name": "Dotted", "style": QtCore.Qt.DotLine},
|
||||
{"name": "Custom 1 (--0--0--)",
|
||||
"style": QtCore.Qt.CustomDashLine,
|
||||
"pattern": [8, 4, 2, 4]}, # Patrón personalizado
|
||||
{"name": "Custom 2 (- - -)",
|
||||
"style": QtCore.Qt.CustomDashLine,
|
||||
"pattern": [6, 3]} # Otro patrón
|
||||
]
|
||||
|
||||
def paint(self, painter, option, index):
|
||||
painter.save()
|
||||
painter.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||
|
||||
if index.row() >= len(self.line_types):
|
||||
painter.restore()
|
||||
return
|
||||
|
||||
line_data = self.line_types[index.row()]
|
||||
line_name = line_data["name"]
|
||||
line_style = line_data.get("style", QtCore.Qt.SolidLine)
|
||||
dash_pattern = line_data.get("pattern", [])
|
||||
|
||||
# Fondo para selección
|
||||
if option.state & QtGui.QStyle.State_Selected:
|
||||
painter.fillRect(option.rect, option.palette.highlight())
|
||||
|
||||
# Áreas de dibujo
|
||||
text_rect = option.rect.adjusted(5, 0, -100, 0)
|
||||
preview_rect = option.rect.adjusted(option.rect.width() - 90, 2, -5, -2)
|
||||
|
||||
# Texto
|
||||
painter.setPen(option.palette.color(QtGui.QPalette.Text))
|
||||
painter.drawText(text_rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, line_name)
|
||||
|
||||
# Línea personalizada
|
||||
pen = QtGui.QPen(QtGui.QColor(0, 0, 0), 2)
|
||||
pen.setStyle(line_style)
|
||||
|
||||
if line_style == QtCore.Qt.CustomDashLine and dash_pattern:
|
||||
pen.setDashPattern(dash_pattern)
|
||||
|
||||
painter.setPen(pen)
|
||||
painter.drawLine(preview_rect.left(), preview_rect.center().y(),
|
||||
preview_rect.right(), preview_rect.center().y())
|
||||
|
||||
painter.restore()
|
||||
|
||||
def sizeHint(self, option, index):
|
||||
return QtCore.QSize(200, 25)
|
||||
|
||||
|
||||
class LineTypeComboBox(QtWidgets.QComboBox):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self._delegate = LineTypePreviewDelegate(self)
|
||||
self.setItemDelegate(self._delegate)
|
||||
self.addItems(["Continuous", "Dashed", "Dotted", "Dash-Dot", "Dash-Dot-Dot"])
|
||||
|
||||
def paintEvent(self, event):
|
||||
painter = QtGui.QPainter(self)
|
||||
painter.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||
|
||||
# Dibujar el fondo del combobox
|
||||
option = QtWidgets.QStyleOptionComboBox()
|
||||
self.initStyleOption(option)
|
||||
self.style().drawComplexControl(QtGui.QStyle.CC_ComboBox, option, painter, self)
|
||||
|
||||
# Obtener el texto y estilo actual
|
||||
current_text = self.currentText()
|
||||
line_style = next(
|
||||
(style for name, style in self._delegate.line_types if name == current_text),
|
||||
QtCore.Qt.SolidLine
|
||||
)
|
||||
|
||||
# Área de dibujo
|
||||
text_rect = self.rect().adjusted(5, 0, -30, 0)
|
||||
preview_rect = self.rect().adjusted(self.width() - 70, 2, -5, -2)
|
||||
|
||||
# Dibujar texto
|
||||
painter.setPen(self.palette().color(QtGui.QPalette.Text))
|
||||
painter.drawText(text_rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, current_text)
|
||||
|
||||
# Dibujar línea de previsualización
|
||||
pen = QtGui.QPen(QtGui.QColor(0, 0, 0), 2)
|
||||
pen.setStyle(line_style)
|
||||
painter.setPen(pen)
|
||||
|
||||
center_y = preview_rect.center().y()
|
||||
painter.drawLine(preview_rect.left(), center_y, preview_rect.right(), center_y)
|
||||
|
||||
|
||||
class exportDXF:
|
||||
|
||||
def __init__(self, filename):
|
||||
''' '''
|
||||
|
||||
self.doc = None
|
||||
self.msp = None
|
||||
self.filename = filename
|
||||
@@ -269,11 +423,13 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
QtGui.QWidget.__init__(self)
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
# self.form:
|
||||
self.form = FreeCADGui.PySideUic.loadUi(
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "exportDXF.ui"))
|
||||
# setWindowIcon(QtGui.QIcon(os.path.join(PVPlantResources.DirIcons, "convert.svg")))
|
||||
# self.form.buttonTo.clicked.connect(self.addTo)
|
||||
self.form.tableLayers.setItemDelegateForColumn(3, LineTypeDelegate())
|
||||
|
||||
self.layout = QtGui.QHBoxLayout(self)
|
||||
self.layout.setContentsMargins(4, 4, 4, 4)
|
||||
@@ -281,10 +437,75 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
|
||||
self.form.buttonAcept.clicked.connect(self.onAceptClick)
|
||||
|
||||
self.add_row("Layer 1", QtGui.QColor(255, 0, 0), "Continua", "1")
|
||||
self.add_row("Layer 2", QtGui.QColor(255, 0, 0), "Continua", "1")
|
||||
|
||||
path = os.path.join(os.path.dirname(FreeCAD.ActiveDocument.FileName), "outputs", "autocad")
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
self.filename = os.path.join(path, FreeCAD.ActiveDocument.Name) + ".dxf"
|
||||
name = datetime.now().strftime("%Y%m%d%H%M%S") + "-" + FreeCAD.ActiveDocument.Name
|
||||
self.filename = os.path.join(path, name) + ".dxf"
|
||||
|
||||
def add_row(self, name, color, line_type, thickness):
|
||||
row = self.form.tableLayers.rowCount()
|
||||
self.form.tableLayers.insertRow(row)
|
||||
self.form.tableLayers.setRowHeight(row, 20)
|
||||
|
||||
# Columna 0: Checkbox
|
||||
checkbox = QtWidgets.QCheckBox()
|
||||
cell_widget = QtWidgets.QWidget()
|
||||
layout = QtWidgets.QHBoxLayout(cell_widget)
|
||||
layout.addWidget(checkbox)
|
||||
layout.setAlignment(QtCore.Qt.AlignCenter)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.form.tableLayers.setCellWidget(row, 0, cell_widget)
|
||||
|
||||
# Columna 1: Nombre (editable)
|
||||
item = QtWidgets.QTableWidgetItem(name)
|
||||
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
|
||||
self.form.tableLayers.setItem(row, 1, item)
|
||||
|
||||
# Columna 2: Selector de color
|
||||
color_btn = QtWidgets.QPushButton()
|
||||
color_btn.setFixedSize(20, 20) # Tamaño del cuadrado
|
||||
color_btn.setStyleSheet(f"""
|
||||
QPushButton {{
|
||||
background-color: {color.name()};
|
||||
border: 1px solid #808080;
|
||||
border-radius: 3px;
|
||||
}}
|
||||
QPushButton:hover {{
|
||||
border: 2px solid #606060;
|
||||
}}
|
||||
""")
|
||||
color_btn.color = color # Almacenar el color como atributo
|
||||
color_btn.clicked.connect(lambda: self.change_color(color_btn))
|
||||
|
||||
# Widget contenedor para centrar el botón
|
||||
cell_widget = QtWidgets.QWidget()
|
||||
layout = QtWidgets.QHBoxLayout(cell_widget)
|
||||
layout.addWidget(color_btn)
|
||||
layout.setAlignment(QtCore.Qt.AlignCenter)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.form.tableLayers.setCellWidget(row, 2, cell_widget)
|
||||
|
||||
# Columna 3: Tipo de línea (combobox)
|
||||
line_combo = LineTypeComboBox()
|
||||
line_combo.addItems(["Continua", "Discontinua", "Punteada", "Mixta"])
|
||||
line_combo.setCurrentText(line_type)
|
||||
self.form.tableLayers.setCellWidget(row, 3, line_combo)
|
||||
|
||||
# Columna 4: Grosor de línea (combobox)
|
||||
thickness_combo = QtWidgets.QComboBox()
|
||||
thickness_combo.addItems(["1", "2", "3", "4"])
|
||||
thickness_combo.setCurrentText(thickness)
|
||||
self.form.tableLayers.setCellWidget(row, 4, thickness_combo)
|
||||
|
||||
def change_color(self, button):
|
||||
color = QtWidgets.QColorDialog.getColor(button.color, self, "Seleccionar color")
|
||||
if color.isValid():
|
||||
button.color = color
|
||||
button.setStyleSheet(f"background-color: {color.name()}")
|
||||
|
||||
def createLayers(self):
|
||||
''' '''
|
||||
@@ -297,16 +518,19 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
|
||||
|
||||
def writeArea(self):
|
||||
for area in FreeCAD.ActiveDocument.Boundary.Group:
|
||||
pol = self.exporter.createPolyline(FreeCAD.ActiveDocument.Site.Boundary)
|
||||
pol.dxf.layer = "boundary"
|
||||
|
||||
for area in FreeCAD.ActiveDocument.Boundaries.Group:
|
||||
pol = self.exporter.createPolyline(area)
|
||||
pol.dxf.layer = "Areas_Boundary"
|
||||
|
||||
for area in FreeCAD.ActiveDocument.Exclusion.Group:
|
||||
for area in FreeCAD.ActiveDocument.Exclusions.Group:
|
||||
pol = self.exporter.createPolyline(area)
|
||||
pol.dxf.layer = "Areas_Exclusion"
|
||||
|
||||
for area in FreeCAD.ActiveDocument.Offsets.Group:
|
||||
self.exporter.createPolyline(area)
|
||||
pol = self.exporter.createPolyline(area)
|
||||
pol.dxf.layer = "Areas_Offsets"
|
||||
|
||||
def writeFrameSetups(self):
|
||||
@@ -441,7 +665,7 @@ class _PVPlantExportDXF(QtGui.QWidget):
|
||||
self.close()
|
||||
|
||||
|
||||
class _CommandExportDXF:
|
||||
class CommandExportDXF:
|
||||
def GetResources(self):
|
||||
return {'Pixmap': str(os.path.join(DirIcons, "dxf.svg")),
|
||||
'Accel': "E, A",
|
||||
@@ -462,5 +686,5 @@ class _CommandExportDXF:
|
||||
return False
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('exportDXF', _CommandExportDXF())
|
||||
'''if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('exportDXF', _CommandExportDXF())'''
|
||||
|
||||
@@ -33,13 +33,171 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
<string>Layers</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableLayers">
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="cornerButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Sel</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>LineType</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Lineweight</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
<string>Objetos a exportar</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableObjects">
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>New Row</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>New Row</string>
|
||||
</property>
|
||||
</row>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Sel</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>LineType</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Lineweight</string>
|
||||
</property>
|
||||
</column>
|
||||
<item row="0" column="0">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Planos en papel a crear</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tablePapers">
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>New Row</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>New Row</string>
|
||||
</property>
|
||||
</row>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Sel</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>LineType</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Lineweight</string>
|
||||
</property>
|
||||
</column>
|
||||
<item row="0" column="0">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user