Compare commits
2 Commits
9ad6fd1a4b
...
58bf3b890b
| Author | SHA1 | Date | |
|---|---|---|---|
| 58bf3b890b | |||
| c76f541ba2 |
278
Export/exportKMZ.py
Normal file
278
Export/exportKMZ.py
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import zipfile
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
from PySide2 import QtWidgets, QtCore, QtGui
|
||||||
|
import FreeCAD
|
||||||
|
import Mesh
|
||||||
|
import Part
|
||||||
|
import Import
|
||||||
|
import pyproj
|
||||||
|
import simplekml
|
||||||
|
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
if FreeCAD.GuiUp:
|
||||||
|
import FreeCADGui
|
||||||
|
from PySide import QtCore
|
||||||
|
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||||
|
from DraftTools import translate
|
||||||
|
else:
|
||||||
|
def translate(ctxt, txt):
|
||||||
|
return txt
|
||||||
|
|
||||||
|
try:
|
||||||
|
_fromUtf8 = QtCore.QString.fromUtf8
|
||||||
|
except AttributeError:
|
||||||
|
def _fromUtf8(s):
|
||||||
|
return s
|
||||||
|
|
||||||
|
from PVPlantResources import DirIcons as DirIcons
|
||||||
|
|
||||||
|
|
||||||
|
# Verificación de dependencias
|
||||||
|
try:
|
||||||
|
from pyproj import Transformer
|
||||||
|
except ImportError:
|
||||||
|
QtWidgets.QMessageBox.critical(None, "Error", "pyproj no está instalado.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
import simplekml
|
||||||
|
except ImportError:
|
||||||
|
QtWidgets.QMessageBox.critical(None, "Error", "simplekml no está instalado.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
class ExportKMZDialog(QtWidgets.QDialog):
|
||||||
|
def __init__(self):
|
||||||
|
super(ExportKMZDialog, self).__init__()
|
||||||
|
self.setWindowTitle("Exportar a KMZ")
|
||||||
|
self.layout = QtWidgets.QVBoxLayout(self)
|
||||||
|
|
||||||
|
# Selección de archivo FCStd
|
||||||
|
self.file_layout = QtWidgets.QHBoxLayout()
|
||||||
|
self.fcstd_line = QtWidgets.QLineEdit()
|
||||||
|
self.browse_fcstd_btn = QtWidgets.QPushButton("Examinar...")
|
||||||
|
self.browse_fcstd_btn.clicked.connect(self.browse_fcstd)
|
||||||
|
self.file_layout.addWidget(self.fcstd_line)
|
||||||
|
self.file_layout.addWidget(self.browse_fcstd_btn)
|
||||||
|
self.layout.addLayout(self.file_layout)
|
||||||
|
|
||||||
|
# Sistema de coordenadas
|
||||||
|
self.crs_label = QtWidgets.QLabel("Sistema de coordenadas origen:")
|
||||||
|
self.crs_display = QtWidgets.QLabel("No encontrado")
|
||||||
|
self.layout.addWidget(self.crs_label)
|
||||||
|
self.layout.addWidget(self.crs_display)
|
||||||
|
|
||||||
|
# Archivo de salida KMZ
|
||||||
|
self.output_layout = QtWidgets.QHBoxLayout()
|
||||||
|
self.kmz_line = QtWidgets.QLineEdit()
|
||||||
|
self.browse_kmz_btn = QtWidgets.QPushButton("Examinar...")
|
||||||
|
self.browse_kmz_btn.clicked.connect(self.browse_kmz)
|
||||||
|
self.output_layout.addWidget(self.kmz_line)
|
||||||
|
self.output_layout.addWidget(self.browse_kmz_btn)
|
||||||
|
self.layout.addWidget(QtWidgets.QLabel("Archivo KMZ de salida:"))
|
||||||
|
self.layout.addLayout(self.output_layout)
|
||||||
|
|
||||||
|
# Progreso y logs
|
||||||
|
self.progress = QtWidgets.QProgressBar()
|
||||||
|
self.log = QtWidgets.QTextEdit()
|
||||||
|
self.log.setReadOnly(True)
|
||||||
|
self.layout.addWidget(self.progress)
|
||||||
|
self.layout.addWidget(self.log)
|
||||||
|
|
||||||
|
# Botones
|
||||||
|
self.buttons = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
|
||||||
|
self.buttons.accepted.connect(self.accept)
|
||||||
|
self.buttons.rejected.connect(self.reject)
|
||||||
|
self.layout.addWidget(self.buttons)
|
||||||
|
|
||||||
|
path = os.path.join(os.path.dirname(FreeCAD.ActiveDocument.FileName), "outputs", "kmz")
|
||||||
|
if not os.path.exists(path):
|
||||||
|
os.makedirs(path)
|
||||||
|
name = datetime.now().strftime("%Y%m%d%H%M%S") + "-" + FreeCAD.ActiveDocument.Name
|
||||||
|
self.filename = os.path.join(path, name) + ".kmz"
|
||||||
|
|
||||||
|
def browse_fcstd(self):
|
||||||
|
path, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||||
|
self, "Seleccionar archivo FreeCAD", "", "*.FCStd")
|
||||||
|
if path:
|
||||||
|
self.fcstd_line.setText(path)
|
||||||
|
crs = self.get_crs_from_fcstd(path)
|
||||||
|
self.crs_display.setText(crs if crs else "No encontrado")
|
||||||
|
|
||||||
|
def get_crs_from_fcstd(self, path):
|
||||||
|
try:
|
||||||
|
with zipfile.ZipFile(path, 'r') as z:
|
||||||
|
doc_xml = z.read('Document.xml')
|
||||||
|
root = ET.fromstring(doc_xml)
|
||||||
|
for prop in root.findall('.//Property[@name="CoordinateSystem"]'):
|
||||||
|
if prop.get('type') == 'App::PropertyString':
|
||||||
|
return prop.find('String').get('value')
|
||||||
|
except Exception as e:
|
||||||
|
self.log.append(f"Error leyendo CRS: {str(e)}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def browse_kmz(self):
|
||||||
|
path, _ = QtWidgets.QFileDialog.getSaveFileName(
|
||||||
|
self, "Guardar KMZ", "", "*.kmz")
|
||||||
|
if path:
|
||||||
|
self.kmz_line.setText(path)
|
||||||
|
|
||||||
|
|
||||||
|
class ExportKMZ(QtCore.QObject):
|
||||||
|
progress_updated = QtCore.Signal(int)
|
||||||
|
log_message = QtCore.Signal(str)
|
||||||
|
|
||||||
|
def __init__(self, input_path, output_path, crs):
|
||||||
|
super().__init__()
|
||||||
|
self.input_path = input_path
|
||||||
|
self.output_path = output_path
|
||||||
|
self.crs = crs
|
||||||
|
self.doc = None
|
||||||
|
self.transformer = pyproj.Transformer.from_crs(crs, 'EPSG:4326', always_xy=True)
|
||||||
|
self.temp_dir = tempfile.mkdtemp()
|
||||||
|
self.kml = simplekml.Kml()
|
||||||
|
self.model_folder = self.kml.newfolder(name='Modelos 3D')
|
||||||
|
self.drawing_folder = self.kml.newfolder(name='Dibujos 2D')
|
||||||
|
|
||||||
|
def process(self):
|
||||||
|
try:
|
||||||
|
self.doc = FreeCAD.openDocument(self.input_path)
|
||||||
|
FreeCAD.setActiveDocument(self.doc.Name)
|
||||||
|
self.process_objects()
|
||||||
|
self.save_kmz()
|
||||||
|
self.log_message.emit("Exportación completada exitosamente.")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
self.log_message.emit(f"Error: {str(e)}")
|
||||||
|
return False
|
||||||
|
finally:
|
||||||
|
if self.doc:
|
||||||
|
FreeCAD.closeDocument(self.doc.Name)
|
||||||
|
shutil.rmtree(self.temp_dir, ignore_errors=True)
|
||||||
|
|
||||||
|
def process_objects(self):
|
||||||
|
total = len(self.doc.Objects)
|
||||||
|
for i, obj in enumerate(self.doc.Objects):
|
||||||
|
try:
|
||||||
|
if hasattr(obj, 'Shape') and obj.Shape.Volume > 0:
|
||||||
|
self.process_3d(obj)
|
||||||
|
elif obj.TypeId == 'Sketcher::SketchObject':
|
||||||
|
self.process_2d(obj)
|
||||||
|
except Exception as e:
|
||||||
|
self.log_message.emit(f"Error procesando {obj.Name}: {str(e)}")
|
||||||
|
self.progress_updated.emit(int((i + 1) / total * 100))
|
||||||
|
|
||||||
|
def process_3d(self, obj):
|
||||||
|
placement = obj.getGlobalPlacement()
|
||||||
|
x, y, z = placement.Base.x, placement.Base.y, placement.Base.z
|
||||||
|
lon, lat = self.transformer.transform(x, y)
|
||||||
|
|
||||||
|
temp_doc = FreeCAD.newDocument("TempExport", hidden=True)
|
||||||
|
temp_obj = temp_doc.addObject('Part::Feature', 'TempObj')
|
||||||
|
temp_obj.Shape = obj.Shape.copy()
|
||||||
|
temp_obj.Placement = FreeCAD.Placement()
|
||||||
|
|
||||||
|
model_path = os.path.join(self.temp_dir, f"{obj.Name}.dae")
|
||||||
|
Import.export(temp_obj, model_path)
|
||||||
|
FreeCAD.closeDocument(temp_doc.Name)
|
||||||
|
|
||||||
|
color = obj.ViewObject.ShapeColor
|
||||||
|
kml_color = simplekml.Color.rgb(
|
||||||
|
int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))
|
||||||
|
|
||||||
|
model = self.model_folder.newmodel(name=obj.Name)
|
||||||
|
model.altitudemode = simplekml.AltitudeMode.relativetoground
|
||||||
|
model.longitude = lon
|
||||||
|
model.latitude = lat
|
||||||
|
model.altitude = z
|
||||||
|
model.model = simplekml.Model()
|
||||||
|
model.model.link.href = f"models/{obj.Name}.dae"
|
||||||
|
model.style = simplekml.Style()
|
||||||
|
model.style.polystyle.color = kml_color
|
||||||
|
|
||||||
|
def process_2d(self, obj):
|
||||||
|
coords = []
|
||||||
|
placement = obj.getGlobalPlacement()
|
||||||
|
for geom in obj.Geometry:
|
||||||
|
for point in geom.StartPoint, geom.EndPoint:
|
||||||
|
global_point = placement.multVec(point)
|
||||||
|
lon, lat = self.transformer.transform(global_point.x, global_point.y)
|
||||||
|
coords.append((lon, lat, global_point.z))
|
||||||
|
|
||||||
|
if len(coords) < 3:
|
||||||
|
return
|
||||||
|
|
||||||
|
poly = self.drawing_folder.newpolygon(name=obj.Name)
|
||||||
|
poly.outerboundaryis = coords
|
||||||
|
poly.altitudemode = simplekml.AltitudeMode.relativetoground
|
||||||
|
poly.style.polystyle.color = simplekml.Color.rgb(255, 0, 0, 128)
|
||||||
|
|
||||||
|
def save_kmz(self):
|
||||||
|
kml_path = os.path.join(self.temp_dir, "doc.kml")
|
||||||
|
self.kml.save(kml_path)
|
||||||
|
|
||||||
|
with zipfile.ZipFile(self.output_path, 'w') as zipf:
|
||||||
|
zipf.write(kml_path, arcname='doc.kml')
|
||||||
|
for root, _, files in os.walk(self.temp_dir):
|
||||||
|
for file in files:
|
||||||
|
if file.endswith('.dae'):
|
||||||
|
zipf.write(
|
||||||
|
os.path.join(root, file),
|
||||||
|
arcname=os.path.join('models', file))
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
def main():
|
||||||
|
app = QtWidgets.QApplication([]) if not FreeCAD.GuiUp else QtWidgets.QApplication.instance()
|
||||||
|
dialog = ExportKMZDialog()
|
||||||
|
if dialog.exec_() == QtWidgets.QDialog.Accepted:
|
||||||
|
input_path = dialog.fcstd_line.text()
|
||||||
|
output_path = dialog.kmz_line.text()
|
||||||
|
crs = dialog.crs_display.text()
|
||||||
|
|
||||||
|
if not crs:
|
||||||
|
QtWidgets.QMessageBox.critical(None, "Error", "Sistema de coordenadas no definido.")
|
||||||
|
return
|
||||||
|
|
||||||
|
exporter = ExportKMZ(input_path, output_path, crs)
|
||||||
|
progress_dialog = QtWidgets.QProgressDialog("Exportando...", "Cancelar", 0, 100)
|
||||||
|
exporter.progress_updated.connect(progress_dialog.setValue)
|
||||||
|
exporter.log_message.connect(lambda msg: dialog.log.append(msg))
|
||||||
|
progress_dialog.show()
|
||||||
|
|
||||||
|
QtCore.QTimer.singleShot(100, exporter.process)
|
||||||
|
app.exec_()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
class CommandExportKMZ:
|
||||||
|
def GetResources(self):
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "googleearth.svg")),
|
||||||
|
'Accel': "E, G",
|
||||||
|
'MenuText': "Export to KMZ",
|
||||||
|
'ToolTip': QT_TRANSLATE_NOOP("Placement", "Export choosed layers to kmz file")}
|
||||||
|
|
||||||
|
def Activated(self):
|
||||||
|
taskd = ExportKMZDialog()
|
||||||
|
taskd.setParent(FreeCADGui.getMainWindow())
|
||||||
|
taskd.setWindowFlags(QtCore.Qt.Dialog or QtCore.Qt.Dialog)
|
||||||
|
taskd.setWindowModality(QtCore.Qt.WindowModal)
|
||||||
|
taskd.show()
|
||||||
|
|
||||||
|
def IsActive(self):
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
657
PVPlantTools.py
Normal file
657
PVPlantTools.py
Normal file
@@ -0,0 +1,657 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# ***************************************************************************
|
||||||
|
# * *
|
||||||
|
# * Copyright (c) 2017 - Amritpal Singh <amrit3701@gmail.com> *
|
||||||
|
# * *
|
||||||
|
# * This program is free software; you can redistribute it and/or modify *
|
||||||
|
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||||
|
# * as published by the Free Software Foundation; either version 2 of *
|
||||||
|
# * the License, or (at your option) any later version. *
|
||||||
|
# * for detail see the LICENCE text file. *
|
||||||
|
# * *
|
||||||
|
# * This program is distributed in the hope that it will be useful, *
|
||||||
|
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
# * GNU Library General Public License for more details. *
|
||||||
|
# * *
|
||||||
|
# * You should have received a copy of the GNU Library General Public *
|
||||||
|
# * License along with this program; if not, write to the Free Software *
|
||||||
|
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||||
|
# * USA *
|
||||||
|
# * *
|
||||||
|
# ***************************************************************************
|
||||||
|
|
||||||
|
__title__ = "RebarCommands"
|
||||||
|
__author__ = "Amritpal Singh"
|
||||||
|
__url__ = "https://www.freecadweb.org"
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import FreeCADGui, FreeCAD
|
||||||
|
from PySide import QtGui, QtCore
|
||||||
|
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||||
|
from PVPlantResources import DirIcons as DirIcons
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class CommandPVPlantSite:
|
||||||
|
"the PVPlant Site command definition"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "icon.svg")),
|
||||||
|
'MenuText': QT_TRANSLATE_NOOP("Arch_Site", "Site"),
|
||||||
|
'Accel': "S, I",
|
||||||
|
'ToolTip': QT_TRANSLATE_NOOP("Arch_Site", "Creates a site object including selected objects.")}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return ((not (FreeCAD.ActiveDocument is None)) and
|
||||||
|
(FreeCAD.ActiveDocument.getObject("Site") is None))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantSite
|
||||||
|
PVPlantSite.makePVPlantSite()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class CommandPVPlantGeoreferencing:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "Location.svg")),
|
||||||
|
'Accel': "G, R",
|
||||||
|
'MenuText': QT_TRANSLATE_NOOP("Georeferencing","Georeferencing"),
|
||||||
|
'ToolTip': QT_TRANSLATE_NOOP("Georeferencing","Referenciar el lugar")}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantGeoreferencing
|
||||||
|
form = PVPlantGeoreferencing.MapWindow()
|
||||||
|
form.show()
|
||||||
|
|
||||||
|
|
||||||
|
class CommandProjectSetup:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "flash.svg")),
|
||||||
|
'Accel': "P, S",
|
||||||
|
'MenuText': "Project Setup",
|
||||||
|
'ToolTip': "Setup all the variable for this project"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project import ProjectSetup
|
||||||
|
taskd = ProjectSetup.ProjectSetupDialog()
|
||||||
|
taskd.setParent(FreeCADGui.getMainWindow())
|
||||||
|
taskd.setWindowFlags(QtCore.Qt.Window)
|
||||||
|
taskd.show()
|
||||||
|
|
||||||
|
|
||||||
|
class CommandTerrain:
|
||||||
|
"the PVPlant Terrain command definition"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "terrain.svg")),
|
||||||
|
'MenuText': "Terrain",
|
||||||
|
'Accel': "S, T",
|
||||||
|
'ToolTip': "Creates a Terrain object from setup dialog."}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return (not (FreeCAD.ActiveDocument is None) and
|
||||||
|
not (FreeCAD.ActiveDocument.getObject("Site") is None) and
|
||||||
|
(FreeCAD.ActiveDocument.getObject("Terrain") is None))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantTerrain
|
||||||
|
PVPlantTerrain.makeTerrain()
|
||||||
|
# task = _TerrainTaskPanel()
|
||||||
|
# FreeCADGui.Control.showDialog(task)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class CommandCreateTerrainMesh:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "surface.svg")),
|
||||||
|
'MenuText': QT_TRANSLATE_NOOP("PVPlant", "Create Surface"),
|
||||||
|
'Accel': "C, S",
|
||||||
|
'ToolTip': QT_TRANSLATE_NOOP("PVPlant", "Creates a surface form a cloud of points.")}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return not FreeCAD.ActiveDocument is None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantCreateTerrainMesh
|
||||||
|
TaskPanel = PVPlantCreateTerrainMesh.TaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandDivideArea:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "area.svg")),
|
||||||
|
'Accel': "A, D",
|
||||||
|
'MenuText': "Divide Area",
|
||||||
|
'ToolTip': "Allowed Area"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project.Area import PVPlantArea
|
||||||
|
sel = FreeCADGui.Selection.getSelection()[0]
|
||||||
|
|
||||||
|
|
||||||
|
class CommandBoundary:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "area.svg")),
|
||||||
|
'Accel': "A, B",
|
||||||
|
'MenuText': "Area",
|
||||||
|
'ToolTip': "Allowed Area"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project.Area import PVPlantArea
|
||||||
|
sel = FreeCADGui.Selection.getSelection()[0]
|
||||||
|
obj = PVPlantArea.makeArea([ver.Point for ver in sel.Shape.Vertexes])
|
||||||
|
#taskd = _PVPlantPlacementTaskPanel()
|
||||||
|
#FreeCADGui.Control.showDialog(taskd)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandFrameArea:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "FrameArea.svg")),
|
||||||
|
'Accel': "A, F",
|
||||||
|
'MenuText': "Frame Area",
|
||||||
|
'ToolTip': "Frame Area"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project.Area import PVPlantArea
|
||||||
|
sel = FreeCADGui.Selection.getSelection()
|
||||||
|
makeFramedArea(None, sel)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandProhibitedArea:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "area_forbidden.svg")),
|
||||||
|
'Accel': "A, F",
|
||||||
|
'MenuText': "Prohibited Area",
|
||||||
|
'ToolTip': "Prohibited Area"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project.Area import PVPlantArea
|
||||||
|
sel = FreeCADGui.Selection.getSelection()
|
||||||
|
PVPlantArea.makeProhibitedArea(sel[0])
|
||||||
|
|
||||||
|
|
||||||
|
class CommandPVSubplant:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "subplant.svg")),
|
||||||
|
'Accel': "A, P",
|
||||||
|
'MenuText': "PV Subplant",
|
||||||
|
'ToolTip': "PV Subplant"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project.Area import PVPlantArea
|
||||||
|
area = PVPlantArea.makePVSubplant()
|
||||||
|
sel = FreeCADGui.Selection.getSelection()
|
||||||
|
for obj in sel:
|
||||||
|
if obj.Name[:7] == "Tracker":
|
||||||
|
frame_list = area.Frames
|
||||||
|
frame_list.append(obj)
|
||||||
|
area.Frames = frame_list
|
||||||
|
|
||||||
|
|
||||||
|
class CommandOffsetArea:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "offset.svg")),
|
||||||
|
'Accel': "A, O",
|
||||||
|
'MenuText': "OffsetArea",
|
||||||
|
'ToolTip': "OffsetArea"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project.Area import PVPlantArea
|
||||||
|
sel = FreeCADGui.Selection.getSelection()
|
||||||
|
base = None
|
||||||
|
if sel:
|
||||||
|
base = sel[0]
|
||||||
|
obj = PVPlantArea.makeOffsetArea(base)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandSplitArea:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "split_area.svg")),
|
||||||
|
'Accel': "A, S",
|
||||||
|
'MenuText': "Split Area",
|
||||||
|
'ToolTip': "Split Area"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return (not FreeCAD.ActiveDocument is None and
|
||||||
|
not FreeCAD.ActiveDocument.findObjects(Name="ProhibitedArea") is None and
|
||||||
|
not FreeCAD.ActiveDocument.findObjects(Name="OffsetArea") is None)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project.Area import PVPlantAreaUtils
|
||||||
|
TaskPanel = PVPlantAreaUtils.splitAreaTaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class CommandJoinAreas:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "split_area.svg")),
|
||||||
|
'Accel': "A, J",
|
||||||
|
'MenuText': "Join Areas",
|
||||||
|
'ToolTip': "Join Areas"}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return (not FreeCAD.ActiveDocument is None and
|
||||||
|
not FreeCAD.ActiveDocument.findObjects(Name="ProhibitedArea") is None and
|
||||||
|
not FreeCAD.ActiveDocument.findObjects(Name="OffsetArea") is None)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
from Project.Area import PVPlantAreaUtils
|
||||||
|
TaskPanel = PVPlantAreaUtils.splitAreaTaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class CommandContours:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "TerrainContours.svg")),
|
||||||
|
'Accel': "T, C",
|
||||||
|
'MenuText': 'Curvas de nivel',
|
||||||
|
'ToolTip': 'Curvas de nivel'
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
# return not FreeCAD.ActiveDocument is None
|
||||||
|
if FreeCAD.ActiveDocument is None:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
if FreeCADGui.Selection.getSelection() is not None:
|
||||||
|
selection = FreeCADGui.Selection.getSelection()[-1]
|
||||||
|
if selection.TypeId == 'Mesh::Feature':
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantTerrainAnalisys
|
||||||
|
TaskPanel = PVPlantTerrainAnalisys.ContourTaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandSlopeAnalisys:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "TerrainSlope.svg")),
|
||||||
|
'Accel': "T, S",
|
||||||
|
'MenuText': 'Analisis de Pendiente',
|
||||||
|
'ToolTip': 'Analisis de Pendiente'
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return not FreeCAD.ActiveDocument is None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantTerrainAnalisys
|
||||||
|
TaskPanel = PVPlantTerrainAnalisys.SlopeTaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandHeightAnalisys:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "TerrainHeight.svg")),
|
||||||
|
'Accel': "T, H",
|
||||||
|
'MenuText': 'Analisis de Altura',
|
||||||
|
'ToolTip': 'Analisis de Altura'
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return not FreeCAD.ActiveDocument is None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantTerrainAnalisys
|
||||||
|
TaskPanel = PVPlantTerrainAnalisys.HeightTaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandOrientationAnalisys:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "TerrainOrientation.svg")),
|
||||||
|
'Accel': "T, H",
|
||||||
|
'MenuText': 'Analisis de Orientación',
|
||||||
|
'ToolTip': 'Analisis de Orientación'}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return not FreeCAD.ActiveDocument is None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantTerrainAnalisys
|
||||||
|
TaskPanel = PVPlantTerrainAnalisys.OrientationTaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandTrench: # V1:
|
||||||
|
"""Gui command for the Line tool."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
"""Set icon, menu and tooltip."""
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "trench.svg")),
|
||||||
|
'MenuText': "Trench",
|
||||||
|
'Accel': "C, T",
|
||||||
|
'ToolTip': "Creates a Trench object from setup dialog."}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
active = not (FreeCAD.ActiveDocument is None)
|
||||||
|
terrain = not (FreeCAD.ActiveDocument.getObject("Terrain") is None)
|
||||||
|
active = active and terrain
|
||||||
|
if terrain:
|
||||||
|
active = active and not (FreeCAD.ActiveDocument.getObject("Terrain").Mesh is None)
|
||||||
|
return active
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
"""Execute when the command is called."""
|
||||||
|
import PVPlantTrench
|
||||||
|
sel = FreeCADGui.Selection.getSelection()
|
||||||
|
done = False
|
||||||
|
|
||||||
|
if len(sel) > 0:
|
||||||
|
import Draft
|
||||||
|
for obj in sel:
|
||||||
|
if Draft.getType(obj) == "Wire":
|
||||||
|
FreeCAD.ActiveDocument.openTransaction("Create Trench")
|
||||||
|
PVPlantTrench.makeTrench(obj)
|
||||||
|
FreeCAD.ActiveDocument.commitTransaction()
|
||||||
|
FreeCAD.ActiveDocument.recompute()
|
||||||
|
done = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not done:
|
||||||
|
taskd = PVPlantTrench.TrenchTaskPanel()
|
||||||
|
if taskd:
|
||||||
|
FreeCADGui.Control.showDialog(taskd)
|
||||||
|
else:
|
||||||
|
print(" No ha sido posible crear el formulario")
|
||||||
|
|
||||||
|
|
||||||
|
class CommandSemiAutomaticTrench: # V1:
|
||||||
|
"""Gui command for the Line tool."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
"""Set icon, menu and tooltip."""
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "trench.svg")),
|
||||||
|
'MenuText': "Semi-Automatic Trench Generator",
|
||||||
|
'Accel': "T, S",
|
||||||
|
'ToolTip': "Creates a Trench object from setup dialog."}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
active = not (FreeCAD.ActiveDocument is None)
|
||||||
|
terrain = not (FreeCAD.ActiveDocument.getObject("Terrain") is None)
|
||||||
|
active = active and terrain
|
||||||
|
if terrain:
|
||||||
|
active = active and not (FreeCAD.ActiveDocument.getObject("Terrain").Mesh is None)
|
||||||
|
return active
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
"""Execute when the command is called."""
|
||||||
|
import PVPlantTrench
|
||||||
|
semi = PVPlantTrench.semiAutomaticTrench()
|
||||||
|
|
||||||
|
|
||||||
|
class CommandCalculateEarthworks:
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "pico.svg")),
|
||||||
|
'Accel': "C, E",
|
||||||
|
'MenuText': QT_TRANSLATE_NOOP("Placement", "Movimiento de tierras"),
|
||||||
|
'ToolTip': QT_TRANSLATE_NOOP("Placement", "Calcular el movimiento de tierras")}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
active = not (FreeCAD.ActiveDocument is None)
|
||||||
|
if not (FreeCAD.ActiveDocument.getObject("Terrain") is None):
|
||||||
|
active = active and not (FreeCAD.ActiveDocument.getObject("Terrain").Mesh is None)
|
||||||
|
return active
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantEarthworks
|
||||||
|
TaskPanel = PVPlantEarthworks.EarthWorksTaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandManhole:
|
||||||
|
"the PVPlant Manhole command definition"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'Pixmap': str(os.path.join(DirIcons, "manhole.svg")),
|
||||||
|
'MenuText': "Manhole",
|
||||||
|
'Accel': "C, M",
|
||||||
|
'ToolTip': "Creates a Manhole object from setup dialog."}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return not FreeCAD.ActiveDocument is None
|
||||||
|
if FreeCAD.ActiveDocument is not None:
|
||||||
|
if FreeCADGui.Selection.getCompleteSelection():
|
||||||
|
for ob in FreeCAD.ActiveDocument.Objects:
|
||||||
|
if ob.Name[:4] == "Site":
|
||||||
|
return True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def Activated():
|
||||||
|
import PVPlantManhole
|
||||||
|
TaskPanel = PVPlantManhole._ManholeTaskPanel()
|
||||||
|
FreeCADGui.Control.showDialog(TaskPanel)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if FreeCAD.GuiUp:
|
||||||
|
FreeCADGui.addCommand('PVPlantSite', CommandPVPlantSite())
|
||||||
|
FreeCADGui.addCommand('PVPlantGeoreferencing', CommandPVPlantGeoreferencing())
|
||||||
|
FreeCADGui.addCommand('ProjectSetup', CommandProjectSetup())
|
||||||
|
FreeCADGui.addCommand('Terrain', CommandTerrain())
|
||||||
|
FreeCADGui.addCommand('PVPlantCreateTerrainMesh', CommandCreateTerrainMesh())
|
||||||
|
|
||||||
|
class CommandAreaGroup:
|
||||||
|
@staticmethod
|
||||||
|
def GetCommands():
|
||||||
|
return tuple([#'Area',
|
||||||
|
'FrameArea',
|
||||||
|
'ForbiddenArea',
|
||||||
|
'PVSubplant',
|
||||||
|
'OffsetArea'
|
||||||
|
])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'MenuText': 'Areas',
|
||||||
|
'ToolTip': 'Areas'
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return not FreeCAD.ActiveDocument is None
|
||||||
|
|
||||||
|
#FreeCADGui.addCommand('Area', CommandBoundary())
|
||||||
|
FreeCADGui.addCommand('FrameArea', CommandFrameArea())
|
||||||
|
FreeCADGui.addCommand('ForbiddenArea', CommandProhibitedArea())
|
||||||
|
FreeCADGui.addCommand('PVSubplant', CommandPVSubplant())
|
||||||
|
FreeCADGui.addCommand('OffsetArea', CommandOffsetArea())
|
||||||
|
FreeCADGui.addCommand('PVPlantAreas', CommandAreaGroup())
|
||||||
|
|
||||||
|
FreeCADGui.addCommand('SplitArea', CommandSplitArea())
|
||||||
|
FreeCADGui.addCommand('JoinAreas', CommandJoinAreas())
|
||||||
|
|
||||||
|
class CommandTerrainAnalisysGroup:
|
||||||
|
@staticmethod
|
||||||
|
def GetCommands():
|
||||||
|
return tuple(['Contours',
|
||||||
|
'HeightAnalisys',
|
||||||
|
'SlopeAnalisys',
|
||||||
|
'OrientationAnalisys'
|
||||||
|
])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return { 'MenuText': QT_TRANSLATE_NOOP("",'Terrain Analisys'),
|
||||||
|
'ToolTip': QT_TRANSLATE_NOOP("",'Terrain Analisys')
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
return not FreeCAD.ActiveDocument is None
|
||||||
|
|
||||||
|
FreeCADGui.addCommand('Contours', CommandContours())
|
||||||
|
FreeCADGui.addCommand('SlopeAnalisys', CommandSlopeAnalisys())
|
||||||
|
FreeCADGui.addCommand('HeightAnalisys', CommandHeightAnalisys())
|
||||||
|
FreeCADGui.addCommand('OrientationAnalisys', CommandOrientationAnalisys())
|
||||||
|
FreeCADGui.addCommand('TerrainAnalisys', CommandTerrainAnalisysGroup())
|
||||||
|
|
||||||
|
class CommandTrenchGroup:
|
||||||
|
@staticmethod
|
||||||
|
def GetCommands():
|
||||||
|
return tuple(['PVPlantTrench',
|
||||||
|
'PVPlantSemiAutomaticTrench',
|
||||||
|
])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetResources():
|
||||||
|
return {'MenuText': 'Rack Types',
|
||||||
|
'ToolTip': 'Rack Types'
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def IsActive():
|
||||||
|
active = not (FreeCAD.ActiveDocument is None)
|
||||||
|
terrain = not (FreeCAD.ActiveDocument.getObject("Terrain") is None)
|
||||||
|
active = active and terrain
|
||||||
|
if terrain:
|
||||||
|
active = active and not (FreeCAD.ActiveDocument.getObject("Terrain").Mesh is None)
|
||||||
|
return active
|
||||||
|
|
||||||
|
FreeCADGui.addCommand('PVPlantTrench', CommandTrench())
|
||||||
|
FreeCADGui.addCommand('PVPlantSemiAutomaticTrench', CommandSemiAutomaticTrench())
|
||||||
|
FreeCADGui.addCommand('Trenches', CommandTrenchGroup())
|
||||||
|
FreeCADGui.addCommand('PVPlantEarthworks', CommandCalculateEarthworks())
|
||||||
|
|
||||||
|
FreeCADGui.addCommand('PVPlantManhole', _ommandManhole())
|
||||||
|
|
||||||
|
projectlist = [ #"Reload",
|
||||||
|
"PVPlantSite",
|
||||||
|
"ProjectSetup",
|
||||||
|
"PVPlantGeoreferencing",
|
||||||
|
"Separator",
|
||||||
|
# "ImportGrid",
|
||||||
|
"Terrain",
|
||||||
|
"TerrainAnalisys",
|
||||||
|
"PVPlantCreateTerrainMesh",
|
||||||
|
"Separator",
|
||||||
|
#"PointsGroup",
|
||||||
|
"PVPlantAreas",
|
||||||
|
"SplitArea",
|
||||||
|
"Separator",
|
||||||
|
"Trenches",
|
||||||
|
"PVPlantEarthworks",
|
||||||
|
#"PVPlantPad",
|
||||||
|
#"PVPlantRoad",
|
||||||
|
#"PVPlantManhole",
|
||||||
|
#"PVPlantFoundation"
|
||||||
|
#"GraphTerrainProfile",
|
||||||
|
#"Trace",
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user