primera subida
This commit is contained in:
333
Electrical/Cable/PVPlantCable.py
Normal file
333
Electrical/Cable/PVPlantCable.py
Normal file
@@ -0,0 +1,333 @@
|
||||
# /**********************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2021 Javier Braña <javier.branagutierrez@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 *
|
||||
# * *
|
||||
# ***********************************************************************
|
||||
|
||||
|
||||
import ArchComponent
|
||||
import FreeCAD
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui, os
|
||||
from PySide import QtCore
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
else:
|
||||
# \cond
|
||||
def translate(ctxt, txt):
|
||||
return txt
|
||||
|
||||
|
||||
def QT_TRANSLATE_NOOP(ctxt, txt):
|
||||
return txt
|
||||
# \endcond
|
||||
|
||||
try:
|
||||
_fromUtf8 = QtCore.QString.fromUtf8
|
||||
except AttributeError:
|
||||
def _fromUtf8(s):
|
||||
return s
|
||||
|
||||
import PVPlantResources
|
||||
|
||||
|
||||
def makeCable(base = None):
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Cable")
|
||||
Cable(obj)
|
||||
ViewProviderCable(obj.ViewObject)
|
||||
if base:
|
||||
obj.Base = base
|
||||
return obj
|
||||
|
||||
class Cable(ArchComponent.Component):
|
||||
"A Base Frame Obcject - Class"
|
||||
|
||||
def __init__(self, obj):
|
||||
ArchComponent.Component.__init__(self, obj)
|
||||
self.setProperties(obj)
|
||||
|
||||
def setProperties(self, obj):
|
||||
pl = obj.PropertiesList
|
||||
|
||||
# General:
|
||||
if not ("Manufacturer" in pl):
|
||||
obj.addProperty("App::PropertyString",
|
||||
"Manufacturer",
|
||||
"General",
|
||||
"Connection")
|
||||
|
||||
if not ("Factory" in pl):
|
||||
obj.addProperty("App::PropertyString",
|
||||
"Factory",
|
||||
"General",
|
||||
"Connection ")
|
||||
|
||||
if not ("DesignStandard" in pl):
|
||||
obj.addProperty("App::PropertyString",
|
||||
"DesignStandard",
|
||||
"General",
|
||||
"Connection ")
|
||||
|
||||
if not ("CableDesignation" in pl):
|
||||
obj.addProperty("App::PropertyString",
|
||||
"CableDesignation",
|
||||
"General",
|
||||
"Connection ").CableDesignation="RH5Z1-OL"
|
||||
|
||||
if not ("MaximumVoltage" in pl):
|
||||
obj.addProperty("App::PropertyElectricPotential",
|
||||
"MaximumVoltage",
|
||||
"General",
|
||||
"Connection ").MaximumVoltage="30kV"
|
||||
|
||||
if not ("MaxTemperatureForContinuousOperation" in pl):
|
||||
obj.addProperty("App::PropertyInteger",
|
||||
"MaxTemperatureForContinuousOperation",
|
||||
"General",
|
||||
"Connection ").MaxTemperatureForContinuousOperation=95
|
||||
|
||||
if not ("MaxTemperatureDuringEmergencyConditions" in pl):
|
||||
obj.addProperty("App::PropertyInteger",
|
||||
"MaxTemperatureDuringEmergencyConditions",
|
||||
"General",
|
||||
"Connection ").MaxTemperatureDuringEmergencyConditions=105
|
||||
|
||||
if not ("MaxTemperatureDuringShortCircuit" in pl):
|
||||
obj.addProperty("App::PropertyInteger",
|
||||
"MaxTemperatureDuringShortCircuit",
|
||||
"General",
|
||||
"Connection ").MaxTemperatureDuringShortCircuit=250
|
||||
|
||||
|
||||
# Conductor:
|
||||
if not ("Material" in pl):
|
||||
obj.addProperty("App::PropertyEnumeration",
|
||||
"Material",
|
||||
"Conductor",
|
||||
"Connection ").Material=["Copper", "Aluminium"]
|
||||
|
||||
if not ("Standard" in pl):
|
||||
obj.addProperty("App::PropertyString",
|
||||
"Standard",
|
||||
"Conductor",
|
||||
"Connection ").Standard = "IEC 60228"
|
||||
|
||||
if not ("CrossSection" in pl):
|
||||
obj.addProperty("App::PropertyArea",
|
||||
"CrossSection",
|
||||
"Conductor",
|
||||
"Connection ").CrossSection = 95
|
||||
|
||||
if not ("MaximumConductorDiameter" in pl):
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"MaximumConductorDiameter",
|
||||
"Conductor",
|
||||
"Connection ")
|
||||
|
||||
if not ("MinimumConductorDiameter" in pl):
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"MinimumConductorDiameter",
|
||||
"Conductor",
|
||||
"Connection ")
|
||||
|
||||
if not ("MaximumResistance" in pl):
|
||||
obj.addProperty("App::PropertyInteger",
|
||||
"MaximumResistance",
|
||||
"Conductor",
|
||||
"Connection ")
|
||||
|
||||
# Insulation:
|
||||
if not ("InsulationMaterial" in pl):
|
||||
obj.addProperty("App::PropertyEnumeration",
|
||||
"InsulationMaterial",
|
||||
"Insulation",
|
||||
"Connection ").InsulationMaterial=["HEPR", "XLPE"]
|
||||
|
||||
if not ("InsulationStandard" in pl):
|
||||
obj.addProperty("App::PropertyString",
|
||||
"InsulationStandard",
|
||||
"Insulation",
|
||||
"Connection ").InsulationStandard = "IEC 60502-2"
|
||||
|
||||
if not ("InsulationNominalThickness" in pl):
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"InsulationNominalThickness",
|
||||
"Insulation",
|
||||
"Sección").InsulationNominalThickness = 7.25
|
||||
|
||||
if not ("InsulationMinimumThickness" in pl):
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"InsulationMinimumThickness",
|
||||
"Insulation",
|
||||
"Sección").InsulationMinimumThickness = 6.43
|
||||
|
||||
if not ("InsulationResistance" in pl):
|
||||
obj.addProperty("App::PropertyInteger",
|
||||
"InsulationResistance",
|
||||
"Insulation",
|
||||
"Sección").InsulationResistance = 3670000
|
||||
|
||||
# Outer semi-conductive layer:
|
||||
if not ("OuterMaterial" in pl):
|
||||
obj.addProperty("App::PropertyString",
|
||||
"OuterMaterial",
|
||||
"OuterLayer",
|
||||
"Connection ").OuterMaterial = "Semicon. compound"
|
||||
|
||||
if not ("OuterNominalThickness" in pl):
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"OuterNominalThickness",
|
||||
"OuterLayer",
|
||||
"Sección").OuterNominalThickness = 0.5
|
||||
|
||||
if not ("OuterMinimumThickness" in pl):
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"OuterMinimumThickness",
|
||||
"OuterLayer",
|
||||
"Sección").OuterMinimumThickness = 0.5
|
||||
|
||||
# algo
|
||||
if not ("ExternalDiameter" in pl):
|
||||
obj.addProperty("App::PropertyDistance",
|
||||
"ExternalDiameter",
|
||||
"Cable",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Diameter")).ExternalDiameter = 6.6
|
||||
|
||||
if not ("Section" in pl):
|
||||
obj.addProperty("App::PropertyArea",
|
||||
"Section",
|
||||
"Cable",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Sección"))
|
||||
|
||||
if not ("Core" in pl):
|
||||
obj.addProperty("App::PropertyEnumeration",
|
||||
"Core",
|
||||
"Cable",
|
||||
"Core").Core = ["1", "2", "3", ]
|
||||
|
||||
if not ("RadiusOfCurvature" in pl):
|
||||
obj.addProperty("App::PropertyDistance",
|
||||
"RadiusOfCurvature",
|
||||
"Cable",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Diameter")).RadiusOfCurvature = 100
|
||||
|
||||
self.Type = "Cable"
|
||||
|
||||
obj.Proxy = self
|
||||
obj.IfcType = "Cable Segment"
|
||||
obj.setEditorMode("IfcType", 1)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Method run when the document is restored.
|
||||
Re-adds the Arch component, and object properties."""
|
||||
|
||||
ArchComponent.Component.onDocumentRestored(self, obj)
|
||||
self.setProperties(obj)
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
''' Do something when a property has changed '''
|
||||
|
||||
def getPoint(self, val):
|
||||
if val.Proxy.Type == 'String':
|
||||
return val.StringPoles[0]
|
||||
elif val.Proxy.Type == 'StringBox':
|
||||
input = val.Shape.SubShapes[2].SubShapes[0]
|
||||
return input.CenterOfMass
|
||||
else:
|
||||
return val.Placement.Base
|
||||
|
||||
def execute(self, obj):
|
||||
import Part, DraftGeomUtils
|
||||
import Draft
|
||||
|
||||
if obj.Base:
|
||||
w = obj.Base.Shape.SubShapes[1].SubShapes[0]
|
||||
w = DraftGeomUtils.filletWire(w, 150)
|
||||
else:
|
||||
return
|
||||
|
||||
"""if obj.Base:
|
||||
# Si tiene ruta, dibujar ruteado
|
||||
import PVPlantTrench as trench
|
||||
if isinstance(obj.Base, trench.Trench):
|
||||
w = obj.Base.Shape.SubShapes[0]
|
||||
else:
|
||||
w = obj.Base.Shape
|
||||
elif obj.From and obj.Name:
|
||||
'''line = Part.LineSegment()
|
||||
line.StartPoint = getPoint(obj.From)
|
||||
line.EndPoint = getPoint(obj.To)
|
||||
w = Part.Wire(line.toShape())'''
|
||||
w = Part.makePolygon([self.getPoint(obj.From), self.getPoint(obj.To)])
|
||||
else:
|
||||
return"""
|
||||
|
||||
r = obj.ExternalDiameter.Value / 2
|
||||
p = Part.Wire([Part.Circle(FreeCAD.Vector(0, 0, 0),
|
||||
FreeCAD.Vector(0, 1, 0),
|
||||
r).toShape()])
|
||||
c = obj.Offset
|
||||
c.x -= r
|
||||
c.z += r
|
||||
v1 = w.Vertexes[1].Point - w.Vertexes[0].Point
|
||||
v2 = DraftGeomUtils.getNormal(p)
|
||||
p.Placement.Base = w.Vertexes[0].Point + c
|
||||
p.Placement.Rotation = FreeCAD.Rotation(v2, v1)
|
||||
|
||||
obj.Shape = w.makePipeShell([p], True, False, 0)
|
||||
obj.Distance = w.Length
|
||||
|
||||
|
||||
class ViewProviderCable(ArchComponent.ViewProviderComponent):
|
||||
def __init__(self, vobj):
|
||||
ArchComponent.ViewProviderComponent.__init__(self, vobj)
|
||||
|
||||
def getIcon(self):
|
||||
return str(os.path.join(PVPlantResources.DirIcons, "cable.svg"))
|
||||
|
||||
|
||||
class CommandCable:
|
||||
def GetResources(self):
|
||||
return {'Pixmap': str(os.path.join(PVPlantResources.DirIcons, "cable.svg")),
|
||||
'Accel': "E, C",
|
||||
'MenuText': QT_TRANSLATE_NOOP("Placement", "Cable"),
|
||||
'ToolTip': QT_TRANSLATE_NOOP("Placement", "Calcular el BOQ de la")}
|
||||
|
||||
def Activated(self):
|
||||
import Draft
|
||||
sel = FreeCADGui.Selection.getSelection()
|
||||
wire = None
|
||||
for obj in sel:
|
||||
if Draft.getType(obj) == "Wire":
|
||||
wire = obj
|
||||
break
|
||||
|
||||
makeCable(wire)
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('PVPlantCable', CommandCable())
|
||||
308
Electrical/Cable/PVPlantElectricalLine.py
Normal file
308
Electrical/Cable/PVPlantElectricalLine.py
Normal file
@@ -0,0 +1,308 @@
|
||||
# /**********************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2021 Javier Braña <javier.branagutierrez@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 *
|
||||
# * *
|
||||
# ***********************************************************************
|
||||
|
||||
|
||||
import ArchComponent
|
||||
import FreeCAD
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui, os
|
||||
from PySide import QtCore
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
else:
|
||||
# \cond
|
||||
def translate(ctxt, txt):
|
||||
return txt
|
||||
|
||||
|
||||
def QT_TRANSLATE_NOOP(ctxt, txt):
|
||||
return txt
|
||||
# \endcond
|
||||
|
||||
try:
|
||||
_fromUtf8 = QtCore.QString.fromUtf8
|
||||
except AttributeError:
|
||||
def _fromUtf8(s):
|
||||
return s
|
||||
|
||||
import PVPlantResources
|
||||
__dir__ = os.path.join(PVPlantResources.__dir__, "Electrical", "Cable")
|
||||
|
||||
|
||||
def makeElectricalLine(base = None):
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "ElectricalLine")
|
||||
ElectricalLine(obj)
|
||||
ViewProviderElectricalLine(obj.ViewObject)
|
||||
if base:
|
||||
obj.Base = base
|
||||
|
||||
'''try:
|
||||
folder = FreeCAD.ActiveDocument.Trenches
|
||||
except:
|
||||
folder = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", 'Trenches')
|
||||
folder.Label = "Trenches"
|
||||
folder.addObject(obj)'''
|
||||
return obj
|
||||
|
||||
|
||||
class ElectricalLine(ArchComponent.Component):
|
||||
|
||||
def __init__(self, obj):
|
||||
ArchComponent.Component.__init__(self, obj)
|
||||
self.setProperties(obj)
|
||||
|
||||
def setProperties(self, obj):
|
||||
pl = obj.PropertiesList
|
||||
|
||||
if not ("Paths" in pl):
|
||||
obj.addProperty("App::PropertyLinkSubList",
|
||||
"Paths",
|
||||
"General",
|
||||
"Connection")
|
||||
|
||||
if not ("offset" in pl):
|
||||
obj.addProperty("App::PropertyVector",
|
||||
"offset",
|
||||
"General",
|
||||
"Connection")
|
||||
|
||||
if not ("From" in pl):
|
||||
obj.addProperty("App::PropertyLink",
|
||||
"From",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Connection "))
|
||||
|
||||
if not ("To" in pl):
|
||||
obj.addProperty("App::PropertyLink",
|
||||
"To",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Connection "))
|
||||
|
||||
if not ("Cable" in pl):
|
||||
obj.addProperty("App::PropertyLink",
|
||||
"Cable",
|
||||
"Line",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Connection "))
|
||||
|
||||
if not ("Phases" in pl):
|
||||
obj.addProperty("App::PropertyEnumeration",
|
||||
"Phases",
|
||||
"Line",
|
||||
"Connection").Phases = ["2", "3"]
|
||||
obj.Phases = "3"
|
||||
|
||||
if not ("LineType" in pl):
|
||||
obj.addProperty("App::PropertyEnumeration",
|
||||
"LineType",
|
||||
"Line",
|
||||
"Connection").LineType = ["AC", "DC"]
|
||||
|
||||
if not ("Setup" in pl):
|
||||
obj.addProperty("App::PropertyEnumeration",
|
||||
"Setup",
|
||||
"Line",
|
||||
"Connection").Setup = ["Trifoil", "Parallel"]
|
||||
|
||||
obj.Proxy = self
|
||||
obj.IfcType = "Cable Segment"
|
||||
obj.setEditorMode("IfcType", 1)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Method run when the document is restored.
|
||||
Re-adds the Arch component, and object properties."""
|
||||
|
||||
ArchComponent.Component.onDocumentRestored(self, obj)
|
||||
self.setProperties(obj)
|
||||
|
||||
def updateOutputProperties(self, obj):
|
||||
''' '''
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
if prop == "Cable":
|
||||
''' '''
|
||||
if hasattr(obj.Cable, "Proxy") and (obj.Cable.Proxy.Type == "Cable"):
|
||||
''' '''
|
||||
else:
|
||||
obj.Cable = None
|
||||
|
||||
if prop == "LineType":
|
||||
obj.Phases = "2" if obj.LineType == "DC" else "3"
|
||||
obj.setEditorMode("Phases", obj.LineType == "DC")
|
||||
self.updateOutputProperties(self, obj)
|
||||
|
||||
def execute(self, obj):
|
||||
import Part, DraftGeomUtils
|
||||
|
||||
w = self.generatePath(obj)
|
||||
if (not w) and (not obj.Cable):
|
||||
return
|
||||
|
||||
r = obj.Cable.ExternalDiameter.Value / 2
|
||||
sh = Part.makeCompound([])
|
||||
cnt = int(obj.Phases)
|
||||
if obj.Phases == "3" and obj.Setup == "Parallel":
|
||||
offsets = [FreeCAD.Vector(-2 * r, 0, r),
|
||||
FreeCAD.Vector(2 * r, 0, r),
|
||||
FreeCAD.Vector(0, 0, r)]
|
||||
else:
|
||||
offsets = [FreeCAD.Vector(-r, 0, r),
|
||||
FreeCAD.Vector(r, 0, r),
|
||||
FreeCAD.Vector(0, 0, r * (1 + 3 ** 0.5))]
|
||||
|
||||
for i in range(cnt):
|
||||
ph = Part.Wire([Part.Circle(offsets[i] + obj.offset,
|
||||
FreeCAD.Vector(0, 1, 0),
|
||||
r).toShape()])
|
||||
v1 = w.Vertexes[1].Point - w.Vertexes[0].Point
|
||||
if v1.y < 0:
|
||||
v1 = -v1
|
||||
v2 = DraftGeomUtils.getNormal(ph)
|
||||
ph.Placement.Base = w.Vertexes[0].Point
|
||||
ph.Placement.Rotation = FreeCAD.Rotation(v2, v1)
|
||||
sh.add(w.makePipeShell([ph, ], True, False, 0))
|
||||
|
||||
obj.Shape = sh
|
||||
|
||||
def generatePath(self, obj):
|
||||
import Utils.PVPlantFillets as fillets
|
||||
|
||||
result = None
|
||||
# 1. sort
|
||||
if not obj.Base:
|
||||
return None
|
||||
|
||||
print(obj.Paths)
|
||||
|
||||
w = obj.Base.Shape.SubShapes[1].SubShapes[0]
|
||||
w = fillets.filletWire(w, obj.Cable.RadiusOfCurvature)
|
||||
return w
|
||||
|
||||
|
||||
class ViewProviderElectricalLine(ArchComponent.ViewProviderComponent):
|
||||
def __init__(self, vobj):
|
||||
ArchComponent.ViewProviderComponent.__init__(self, vobj)
|
||||
self.Object = None
|
||||
vobj.Proxy = self
|
||||
|
||||
def attach(self, vobj):
|
||||
''' Create Object visuals in 3D view. '''
|
||||
self.Object = vobj.Object
|
||||
|
||||
def getIcon(self):
|
||||
return str(os.path.join(PVPlantResources.DirIcons, "electricalline.png"))
|
||||
|
||||
def claimChildren(self):
|
||||
""" Provides object grouping """
|
||||
children = []
|
||||
if self.Object.Cable:
|
||||
children.append(self.Object.Cable)
|
||||
return children
|
||||
|
||||
|
||||
class ElectricalLineTaskPanel:
|
||||
def __init__(self, obj=None):
|
||||
self.new = False
|
||||
self.selection = None
|
||||
self.selectionViewObject = None
|
||||
self.obj = obj
|
||||
|
||||
if obj is None:
|
||||
self.new = True
|
||||
|
||||
self.form = FreeCADGui.PySideUic.loadUi(os.path.join(__dir__, "PVPlantElectricalLine.ui"))
|
||||
'''self.form.buttonAddLayer.clicked.connect(self.addLayer)
|
||||
self.form.buttonDeleteLayer.clicked.connect(self.removeLayer)
|
||||
self.form.buttonUp.clicked.connect(self.moveUp)
|
||||
self.form.buttonDown.clicked.connect(self.moveDown)'''
|
||||
|
||||
|
||||
#self.observer = SelectionObserver.SelObserver()
|
||||
FreeCADGui.Selection.addObserver(self)
|
||||
|
||||
def addSelection(self, document, object, element, position): # Selection
|
||||
''' '''
|
||||
obj = FreeCAD.getDocument(document).getObject(object)
|
||||
if hasattr(obj, "Proxy"):
|
||||
if obj.Proxy.Type == "Trench":
|
||||
self.selection = obj
|
||||
self.selectionViewObject = obj.ViewObject.DisplayMode
|
||||
obj.ViewObject.DisplayMode = "Wireframe"
|
||||
self.TrechDialog = FreeCADGui.PySideUic.loadUi(os.path.join(__dir__, "PVPlantElectricalLineDialog.ui"))
|
||||
self.TrechDialog.labelTitle.setText(obj.Name)
|
||||
self.TrechDialog.spinBox.setMaximum(obj.Cables)
|
||||
self.TrechDialog.buttonAccept.clicked.connect(self.addTrenchRoute)
|
||||
self.TrechDialog.show()
|
||||
|
||||
def clearSelection(self, doc):
|
||||
''' '''
|
||||
if self.selectionViewObject:
|
||||
self.selection.ViewObject.DisplayMode = self.selectionViewObject
|
||||
self.selectionViewObject = None
|
||||
pass
|
||||
|
||||
def addTrenchRoute(self):
|
||||
val = self.TrechDialog.spinBox.value
|
||||
FreeCADGui.Selection.clearSelection()
|
||||
self.TrechDialog.close()
|
||||
|
||||
def accept(self):
|
||||
FreeCAD.ActiveDocument.openTransaction("Create Electrical Line")
|
||||
makeElectricalLine()
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
self.closeForm()
|
||||
return True
|
||||
|
||||
def reject(self):
|
||||
self.closeForm()
|
||||
return False
|
||||
|
||||
def closeForm(self):
|
||||
FreeCADGui.Selection.removeObserver(self)
|
||||
FreeCADGui.Control.closeDialog()
|
||||
|
||||
|
||||
class CommandElectricalLine:
|
||||
def GetResources(self):
|
||||
return {'Pixmap': str(os.path.join(PVPlantResources.DirIcons, "electricalline.png")),
|
||||
'Accel': "E, L",
|
||||
'MenuText': "Línea eléctrica",
|
||||
'ToolTip': "Crea una línea electríca en AC o DC.\n Selecciona la configuración de cable."}
|
||||
|
||||
def Activated(self):
|
||||
TaskPanel = ElectricalLineTaskPanel()
|
||||
FreeCADGui.Control.showDialog(TaskPanel)
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
active = not (FreeCAD.ActiveDocument is None)
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('PVPlanElectricalLine', CommandElectricalLine())
|
||||
|
||||
218
Electrical/Cable/PVPlantElectricalLine.ui
Normal file
218
Electrical/Cable/PVPlantElectricalLine.ui
Normal file
@@ -0,0 +1,218 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>formRack</class>
|
||||
<widget class="QDialog" name="formRack">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>332</width>
|
||||
<height>157</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Fixed Frame:</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Dimensions</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Heigth (m)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="editModuleHeight">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>140</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="editModuleLenght">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>140</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>2000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Anchura (m)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Largura (m)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="editModuleWidth">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>140</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDoubleSpinBox" name="editModuleWidth_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>140</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
71
Electrical/Cable/PVPlantElectricalLineDialog.ui
Normal file
71
Electrical/Cable/PVPlantElectricalLineDialog.ui
Normal file
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>formTrechPathSelector</class>
|
||||
<widget class="QDialog" name="formTrechPathSelector">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>178</width>
|
||||
<height>79</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Fixed Frame:</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Seleccionar ruta</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="labelTitle">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(180, 180, 180);
|
||||
border-color: rgb(129, 129, 129);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="spinBox">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="buttonAccept">
|
||||
<property name="text">
|
||||
<string>Aceptar</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
373
Electrical/CombinerBox/PVPlantStringBox.py
Normal file
373
Electrical/CombinerBox/PVPlantStringBox.py
Normal file
@@ -0,0 +1,373 @@
|
||||
# /**********************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2021 Javier Braña <javier.branagutierrez@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 *
|
||||
# * *
|
||||
# ***********************************************************************
|
||||
|
||||
import ArchComponent
|
||||
import FreeCAD
|
||||
import Part
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui, os
|
||||
from PySide import QtCore
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
from pivy import coin
|
||||
else:
|
||||
# \cond
|
||||
def translate(ctxt, txt):
|
||||
return txt
|
||||
|
||||
def QT_TRANSLATE_NOOP(ctxt, txt):
|
||||
return txt
|
||||
# \endcond
|
||||
|
||||
try:
|
||||
_fromUtf8 = QtCore.QString.fromUtf8
|
||||
except AttributeError:
|
||||
def _fromUtf8(s):
|
||||
return s
|
||||
|
||||
import PVPlantResources
|
||||
|
||||
def makeStringbox():
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "StringBox")
|
||||
_StringBox(obj)
|
||||
_ViewProviderStringBox(obj.ViewObject)
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
#FreeCADGui.ActiveDocument.ActiveView.fitAll()
|
||||
return obj
|
||||
|
||||
class _StringBox(ArchComponent.Component):
|
||||
|
||||
def __init__(self, obj):
|
||||
# Definición de Variables:
|
||||
ArchComponent.Component.__init__(self, obj)
|
||||
self.obj = obj
|
||||
self.setProperties(obj)
|
||||
self.Type = "StringBox"
|
||||
|
||||
# Does a IfcType exist?
|
||||
obj.IfcType = "Electric Distribution Board"
|
||||
obj.setEditorMode("IfcType", 1)
|
||||
# obj.MoveWithHost = False
|
||||
|
||||
def setProperties(self, obj):
|
||||
# Definicion de Propiedades:
|
||||
'''[
|
||||
'App::PropertyBool',
|
||||
'App::PropertyBoolList',
|
||||
'App::PropertyFloat',
|
||||
'App::PropertyFloatList',
|
||||
'App::PropertyFloatConstraint',
|
||||
'App::PropertyPrecision',
|
||||
'App::PropertyQuantity',
|
||||
'App::PropertyQuantityConstraint',
|
||||
'App::PropertyAngle',
|
||||
'App::PropertyDistance',
|
||||
'App::PropertyLength',
|
||||
'App::PropertyArea',
|
||||
'App::PropertyVolume',
|
||||
'App::PropertyFrequency',
|
||||
'App::PropertySpeed',
|
||||
'App::PropertyAcceleration',
|
||||
'App::PropertyForce',
|
||||
'App::PropertyPressure',
|
||||
'App::PropertyVacuumPermittivity',
|
||||
'App::PropertyInteger',
|
||||
'App::PropertyIntegerConstraint',
|
||||
'App::PropertyPercent',
|
||||
'App::PropertyEnumeration',
|
||||
'App::PropertyIntegerList',
|
||||
'App::PropertyIntegerSet',
|
||||
'App::PropertyMap',
|
||||
'App::PropertyString',
|
||||
'App::PropertyPersistentObject',
|
||||
'App::PropertyUUID',
|
||||
'App::PropertyFont',
|
||||
'App::PropertyStringList',
|
||||
'App::PropertyLink',
|
||||
'App::PropertyLinkChild',
|
||||
'App::PropertyLinkGlobal',
|
||||
'App::PropertyLinkHidden',
|
||||
'App::PropertyLinkSub',
|
||||
'App::PropertyLinkSubChild',
|
||||
'App::PropertyLinkSubGlobal',
|
||||
'App::PropertyLinkSubHidden',
|
||||
'App::PropertyLinkList',
|
||||
'App::PropertyLinkListChild',
|
||||
'App::PropertyLinkListGlobal',
|
||||
'App::PropertyLinkListHidden',
|
||||
'App::PropertyLinkSubList',
|
||||
'App::PropertyLinkSubListChild',
|
||||
'App::PropertyLinkSubListGlobal',
|
||||
'App::PropertyLinkSubListHidden',
|
||||
'App::PropertyXLink',
|
||||
'App::PropertyXLinkSub',
|
||||
'App::PropertyXLinkSubList',
|
||||
'App::PropertyXLinkList',
|
||||
'App::PropertyMatrix',
|
||||
'App::PropertyVector',
|
||||
'App::PropertyVectorDistance',
|
||||
'App::PropertyPosition',
|
||||
'App::PropertyDirection',
|
||||
'App::PropertyVectorList',
|
||||
'App::PropertyPlacement',
|
||||
'App::PropertyPlacementList',
|
||||
'App::PropertyPlacementLink',
|
||||
'App::PropertyColor',
|
||||
'App::PropertyColorList',
|
||||
'App::PropertyMaterial',
|
||||
'App::PropertyMaterialList',
|
||||
'App::PropertyPath',
|
||||
'App::PropertyFile',
|
||||
'App::PropertyFileIncluded',
|
||||
'App::PropertyPythonObject',
|
||||
'App::PropertyExpressionEngine',
|
||||
'Part::PropertyPartShape',
|
||||
'Part::PropertyGeometryList',
|
||||
'Part::PropertyShapeHistory',
|
||||
'Part::PropertyFilletEdges',
|
||||
'Mesh::PropertyNormalList',
|
||||
'Mesh::PropertyCurvatureList',
|
||||
'Mesh::PropertyMeshKernel',
|
||||
'Sketcher::PropertyConstraintList'
|
||||
]'''
|
||||
|
||||
pl = obj.PropertiesList
|
||||
if not "InputsFromStrings" in pl:
|
||||
obj.addProperty("App::PropertyQuantity",
|
||||
"InputsFromStrings",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Connection ")).InputsFromStrings = 12
|
||||
|
||||
if not ("PositiveInputs" in pl):
|
||||
obj.addProperty("App::PropertyVectorList",
|
||||
"PositiveInputs",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "The height of this object")
|
||||
).PositiveInputs = []
|
||||
obj.setEditorMode("PositiveInputs", 1)
|
||||
|
||||
if not ("NegativeInputs" in pl):
|
||||
obj.addProperty("App::PropertyVectorList",
|
||||
"NegativeInputs",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "The height of this object")
|
||||
).NegativeInputs = []
|
||||
obj.setEditorMode("NegativeInputs", 1)
|
||||
|
||||
if not "InputCables" in pl:
|
||||
obj.addProperty("App::PropertyLinkList",
|
||||
"InputCables",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "InputCables"))
|
||||
|
||||
# Outputs
|
||||
'''
|
||||
if not "Outputs" in pl:
|
||||
obj.addProperty("App::PropertyQuantity",
|
||||
"Outputs",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Connection ")).Outputs = 1
|
||||
'''
|
||||
|
||||
if not ("PositiveOut" in pl):
|
||||
obj.addProperty("Part::PropertyPartShape",
|
||||
"PositiveOut",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "The height of this object")
|
||||
)
|
||||
obj.setEditorMode("PositiveOut", 1)
|
||||
|
||||
if not ("NegativeOut" in pl):
|
||||
obj.addProperty("Part::PropertyPartShape",
|
||||
"NegativeOut",
|
||||
"Connections",
|
||||
QT_TRANSLATE_NOOP("App::Property", "The height of this object")
|
||||
)
|
||||
obj.setEditorMode("NegativeOut", 1)
|
||||
|
||||
# Size:
|
||||
if not "Width" in pl:
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"Width",
|
||||
"Box",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Connection ")).Width = 330
|
||||
|
||||
if not "Length" in pl:
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"Length",
|
||||
"Box",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Connection ")).Length = 848
|
||||
|
||||
if not "Height" in pl:
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"Height",
|
||||
"Box",
|
||||
QT_TRANSLATE_NOOP("App::Property", "Connection ")).Height = 615
|
||||
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Method run when the document is restored.
|
||||
Re-adds the Arch component, and Arch wall properties."""
|
||||
|
||||
ArchComponent.Component.onDocumentRestored(self, obj)
|
||||
self.setProperties(obj)
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
if prop == "InputsFromStrings":
|
||||
for i in range(int(obj.getPropertyByName(prop).Value)):
|
||||
obj.removeProperty("PositiveInput" + str(i+1))
|
||||
obj.removeProperty("NegativeInput" + str(i + 1))
|
||||
|
||||
|
||||
def execute(self, obj):
|
||||
# obj.Shape: compound
|
||||
# |- body: compound
|
||||
# |-- body: solid
|
||||
# |-- door: solid
|
||||
# |-- inputs: solids
|
||||
# |-- outputs: solids
|
||||
# |- inputs references: compound
|
||||
# |-- positives: compound
|
||||
# |--- positive: point of vertex
|
||||
|
||||
solids = []
|
||||
pts = []
|
||||
|
||||
def getdownFace(object):
|
||||
downface = object.Faces[0]
|
||||
for face in object.Faces:
|
||||
if face.CenterOfMass.z < downface.CenterOfMass.z:
|
||||
downface = face
|
||||
return downface
|
||||
|
||||
def drawInputs(numrows, offsetx, type, cpd):
|
||||
numInputs = int(obj.InputsFromStrings.Value)
|
||||
nperrow = int(round(numInputs / numrows, 0))
|
||||
gap = 45
|
||||
diameter = 20
|
||||
points = []
|
||||
cnt = 0
|
||||
for r in range(numrows):
|
||||
xx = -obj.Length.Value / 2 + offsetx + gap / 2 * (r % 2)
|
||||
yy = -diameter + gap * r
|
||||
for i in range(min(numInputs, nperrow)):
|
||||
cyl = Part.makeCylinder(10, 20, FreeCAD.Vector(xx + gap * i, yy, -20))
|
||||
solids.append(cyl)
|
||||
points.append(getdownFace(cyl).CenterOfMass)
|
||||
cnt += 1
|
||||
inname = ("PositiveIn" if type == 0 else "NegativeIn") + str(cnt)
|
||||
obj.addProperty("Part::PropertyPartShape",
|
||||
inname,
|
||||
"Inputs",
|
||||
QT_TRANSLATE_NOOP("App::Property", "The height of this object")
|
||||
)
|
||||
obj.setEditorMode(inname, 1)
|
||||
setattr(obj, inname, getdownFace(cyl))
|
||||
cpd.add(cyl)
|
||||
numInputs -= nperrow
|
||||
return points
|
||||
|
||||
box = Part.makeBox(obj.Length.Value, obj.Width.Value, obj.Height.Value)
|
||||
box.Placement.Base.x -= obj.Length.Value / 2
|
||||
box.Placement.Base.y -= obj.Width.Value / 2
|
||||
|
||||
# Output:
|
||||
cpd_out = Part.makeCompound([])
|
||||
outp = Part.makeCylinder(65/2, 20, FreeCAD.Vector(0, 0, -20))
|
||||
#out.Placement.Base.x += 50
|
||||
#out.Placement.Base.y += 65/2
|
||||
solids.append(outp)
|
||||
cpd_out.add(outp)
|
||||
obj.PositiveOut = getdownFace(outp)
|
||||
|
||||
outn = outp.copy()
|
||||
outn.Placement.Base.x += 65 + 10
|
||||
solids.append(outn)
|
||||
cpd_out.add(outn)
|
||||
obj.NegativeOut = getdownFace(outn)
|
||||
|
||||
# Inputs:
|
||||
cpd_Pos_Inputs = Part.makeCompound([])
|
||||
cpd_Neg_Inputs = Part.makeCompound([])
|
||||
obj.PositiveInputs = drawInputs(2, 80, 0, cpd_Pos_Inputs).copy()
|
||||
obj.NegativeInputs = drawInputs(4, 650, 1, cpd_Neg_Inputs).copy()
|
||||
|
||||
pts.append(getdownFace(box).CenterOfMass)
|
||||
pts.append(getdownFace(outn).CenterOfMass)
|
||||
pts.append(getdownFace(outp).CenterOfMass)
|
||||
|
||||
obj.Shape = Part.makeCompound([box, cpd_out, cpd_Pos_Inputs, cpd_Neg_Inputs])
|
||||
|
||||
class _ViewProviderStringBox(ArchComponent.ViewProviderComponent):
|
||||
"A View Provider for the Pipe object"
|
||||
|
||||
def __init__(self, vobj):
|
||||
ArchComponent.ViewProviderComponent.__init__(self, vobj)
|
||||
|
||||
def getIcon(self):
|
||||
return str(os.path.join(PVPlantResources.DirIcons, "StringBox.svg"))
|
||||
|
||||
def attach(self, vobj):
|
||||
self.Object = vobj.Object
|
||||
sep = coin.SoSeparator()
|
||||
self.coords = coin.SoCoordinate3()
|
||||
sep.addChild(self.coords)
|
||||
self.coords.point.deleteValues(0)
|
||||
symbol = coin.SoMarkerSet()
|
||||
symbol.markerIndex = FreeCADGui.getMarkerIndex("", 5)
|
||||
sep.addChild(symbol)
|
||||
rn = vobj.RootNode
|
||||
rn.addChild(sep)
|
||||
ArchComponent.ViewProviderComponent.attach(self, vobj)
|
||||
|
||||
def updateData(self, obj, prop):
|
||||
|
||||
if prop == "PositiveInputs":
|
||||
if obj.PositiveInputs:
|
||||
self.coords.point.setNum(len(obj.PositiveInputs))
|
||||
self.coords.point.setValues([[p.x, p.y, p.z] for p in obj.PositiveInputs])
|
||||
else:
|
||||
self.coords.point.deleteValues(0)
|
||||
|
||||
|
||||
class _CommandBoxEnclosure:
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': str(os.path.join(PVPlantResources.DirIcons, "StringBox.svg")),
|
||||
'Accel': "C, E",
|
||||
'MenuText': QT_TRANSLATE_NOOP("Placement", "Movimiento de tierras"),
|
||||
'ToolTip': QT_TRANSLATE_NOOP("Placement", "Calcular el movimiento de tierras")}
|
||||
|
||||
def Activated(self):
|
||||
makeStringbox()
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('PVPlantStringBox', _CommandBoxEnclosure())
|
||||
550
Electrical/Conduit.py
Normal file
550
Electrical/Conduit.py
Normal file
@@ -0,0 +1,550 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#***************************************************************************
|
||||
#* Copyright (c) 2016 Yorik van Havre <yorik@uncreated.net> *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import ArchComponent
|
||||
import FreeCAD
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
from draftutils.translate import translate
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
else:
|
||||
# \cond
|
||||
def translate(ctxt,txt):
|
||||
return txt
|
||||
def QT_TRANSLATE_NOOP(ctxt,txt):
|
||||
return txt
|
||||
# \endcond
|
||||
|
||||
## @package ArchPipe
|
||||
# \ingroup ARCH
|
||||
# \brief The Pipe object and tools
|
||||
#
|
||||
# This module provides tools to build Pipe and Pipe connector objects.
|
||||
# Pipes are tubular objects extruded along a base line.
|
||||
|
||||
__title__ = "Arch Pipe tools"
|
||||
__author__ = "Yorik van Havre"
|
||||
__url__ = "https://www.freecadweb.org"
|
||||
|
||||
|
||||
def makePipe(baseobj=None, diameter=0, length=0, placement=None, name="Pipe"):
|
||||
|
||||
"makePipe([baseobj,diamerter,length,placement,name]): creates an pipe object from the given base object"
|
||||
|
||||
if not FreeCAD.ActiveDocument:
|
||||
FreeCAD.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
obj= FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name)
|
||||
obj.Label = name
|
||||
Pipe(obj)
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
ViewProviderPipe(obj.ViewObject)
|
||||
if baseobj:
|
||||
baseobj.ViewObject.hide()
|
||||
|
||||
if baseobj:
|
||||
obj.Base = baseobj
|
||||
else:
|
||||
if length:
|
||||
obj.Length = length
|
||||
|
||||
if diameter:
|
||||
obj.Diameter = diameter
|
||||
|
||||
if placement:
|
||||
obj.Placement = placement
|
||||
|
||||
return obj
|
||||
|
||||
def makePipeConnector(pipes,radius=0,name="Connector"):
|
||||
|
||||
"makePipeConnector(pipes,[radius,name]): creates a connector between the given pipes"
|
||||
|
||||
if not FreeCAD.ActiveDocument:
|
||||
FreeCAD.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
obj= FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
||||
obj.Label = name
|
||||
_ArchPipeConnector(obj)
|
||||
obj.Pipes = pipes
|
||||
if not radius:
|
||||
radius = pipes[0].Diameter
|
||||
obj.Radius = radius
|
||||
if FreeCAD.GuiUp:
|
||||
_ViewProviderPipe(obj.ViewObject)
|
||||
return obj
|
||||
|
||||
class Pipe(ArchComponent.Component):
|
||||
"the Arch Pipe object"
|
||||
|
||||
def __init__(self,obj):
|
||||
|
||||
ArchComponent.Component.__init__(self,obj)
|
||||
self.setProperties(obj)
|
||||
|
||||
def setProperties(self,obj):
|
||||
|
||||
pl = obj.PropertiesList
|
||||
if not "Diameter" in pl:
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"Diameter",
|
||||
"Conduit",
|
||||
QT_TRANSLATE_NOOP("App::Property","The diameter of this pipe, if not based on a profile")).Diameter = 60
|
||||
|
||||
if not "Length" in pl:
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"Length",
|
||||
"Conduit",
|
||||
QT_TRANSLATE_NOOP("App::Property","The length of this pipe, if not based on an edge"))
|
||||
|
||||
if not "Profile" in pl:
|
||||
obj.addProperty("App::PropertyLink",
|
||||
"Profile",
|
||||
"Conduit",
|
||||
QT_TRANSLATE_NOOP("App::Property","An optional closed profile to base this pipe on"))
|
||||
|
||||
if not "Start" in pl:
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"Start",
|
||||
"Conduit",
|
||||
QT_TRANSLATE_NOOP("App::Property","Offset from the start point"))
|
||||
|
||||
|
||||
if not "Offset" in pl:
|
||||
obj.addProperty("App::PropertyVector",
|
||||
"Offset",
|
||||
"Conduit",
|
||||
QT_TRANSLATE_NOOP("App::Property","Offset from the start point xy"))
|
||||
|
||||
|
||||
if not "WallThickness" in pl:
|
||||
obj.addProperty("App::PropertyLength",
|
||||
"WallThickness",
|
||||
"Conduit",
|
||||
QT_TRANSLATE_NOOP("App::Property","The wall thickness of this pipe, if not based on a profile")).WallThickness = 2
|
||||
|
||||
self.Type = "Conduit"
|
||||
# IfcPipeSegment is new in IFC4
|
||||
from ArchIFC import IfcTypes
|
||||
if "Cable Carrier Segment" in IfcTypes:
|
||||
obj.IfcType = "Cable Carrier Segment"
|
||||
obj.PredefinedType = "CONDUITSEGMENT"
|
||||
obj.setEditorMode("IfcType", 1)
|
||||
obj.setEditorMode("PredefinedType", 1)
|
||||
else:
|
||||
# IFC2x3 does not know a Pipe Segment
|
||||
obj.IfcType = "Undefined"
|
||||
|
||||
def onDocumentRestored(self,obj):
|
||||
ArchComponent.Component.onDocumentRestored(self,obj)
|
||||
self.setProperties(obj)
|
||||
|
||||
def execute(self,obj):
|
||||
import Part, DraftGeomUtils, math
|
||||
pl = obj.Placement
|
||||
|
||||
w = self.getWire(obj)
|
||||
if not w:
|
||||
FreeCAD.Console.PrintError(translate("Arch","Unable to build the base path")+"\n")
|
||||
return
|
||||
|
||||
if obj.Start.Value:
|
||||
# new:
|
||||
d = obj.Start.Value
|
||||
for i, e in enumerate(w.Edges):
|
||||
if e.Length < d:
|
||||
d -= e.Length
|
||||
else:
|
||||
v = e.Vertexes[-1].Point.sub(e.Vertexes[0].Point).normalize()
|
||||
v.multiply(d)
|
||||
p = e.Vertexes[0].Point.add(v)
|
||||
pts = [ver.Point for ver in w.Vertexes]
|
||||
pts = [p] + pts[i + 1:]
|
||||
w = Part.makePolygon(pts)
|
||||
break
|
||||
|
||||
if obj.Length.Value == 0:
|
||||
obj.Length.Value = w.Length
|
||||
elif obj.Length.Value > 0:
|
||||
d = obj.Length.Value
|
||||
for i, e in enumerate(w.Edges):
|
||||
if e.Length < d:
|
||||
d -= e.Length
|
||||
else:
|
||||
v = e.Vertexes[-1].Point.sub(e.Vertexes[0].Point).normalize()
|
||||
v.multiply(d)
|
||||
p = e.Vertexes[0].Point.add(v)
|
||||
pts = [ver.Point for ver in w.Vertexes]
|
||||
pts = pts[:i + 1] + [p]
|
||||
w = Part.makePolygon(pts)
|
||||
break
|
||||
pla = FreeCAD.Vector(w.Vertexes[int(len(w.Vertexes)/2)].Point)
|
||||
w.Placement.Base -= pla
|
||||
p = self.getProfile(obj)
|
||||
if not p:
|
||||
FreeCAD.Console.PrintError(translate("Arch", "Unable to build the profile") + "\n")
|
||||
return
|
||||
|
||||
# move and rotate the profile to the first point
|
||||
if hasattr(p,"CenterOfMass"):
|
||||
c = p.CenterOfMass
|
||||
else:
|
||||
c = p.BoundBox.Center
|
||||
|
||||
delta = w.Vertexes[0].Point - c + FreeCAD.Vector(obj.Offset.y, obj.Offset.x, 0)
|
||||
p.translate(delta)
|
||||
import Draft
|
||||
if Draft.getType(obj.Base) == "BezCurve":
|
||||
v1 = obj.Base.Placement.multVec(obj.Base.Points[1])-w.Vertexes[0].Point
|
||||
else:
|
||||
v1 = w.Vertexes[1].Point-w.Vertexes[0].Point
|
||||
v2 = DraftGeomUtils.getNormal(p)
|
||||
rot = FreeCAD.Rotation(v2,v1)
|
||||
p.rotate(w.Vertexes[0].Point,rot.Axis,math.degrees(rot.Angle))
|
||||
shapes = []
|
||||
try:
|
||||
if p.Faces:
|
||||
for f in p.Faces:
|
||||
sh = w.makePipeShell([f.OuterWire],True,False,2)
|
||||
for shw in f.Wires:
|
||||
if shw.hashCode() != f.OuterWire.hashCode():
|
||||
sh2 = w.makePipeShell([shw],True,False,2)
|
||||
sh = sh.cut(sh2)
|
||||
sh.Placement.Base += pla
|
||||
shapes.append(sh)
|
||||
elif p.Wires:
|
||||
for pw in p.Wires:
|
||||
sh = w.makePipeShell([pw],True,False,2)
|
||||
sh.Placement.Base += pla
|
||||
shapes.append(sh)
|
||||
except Exception:
|
||||
FreeCAD.Console.PrintError(translate("Arch","Unable to build the pipe")+"\n")
|
||||
else:
|
||||
if len(shapes) == 0:
|
||||
return
|
||||
elif len(shapes) == 1:
|
||||
sh = shapes[0]
|
||||
else:
|
||||
sh = Part.makeCompound(shapes)
|
||||
obj.Shape = sh
|
||||
if not obj.Base:
|
||||
obj.Placement = pl
|
||||
|
||||
def getWire(self,obj):
|
||||
import Part
|
||||
if obj.Base:
|
||||
if not hasattr(obj.Base,'Shape'):
|
||||
FreeCAD.Console.PrintError(translate("Arch","The base object is not a Part")+"\n")
|
||||
return
|
||||
if len(obj.Base.Shape.Wires) != 1:
|
||||
FreeCAD.Console.PrintError(translate("Arch","Too many wires in the base shape")+"\n")
|
||||
return
|
||||
if obj.Base.Shape.Wires[0].isClosed():
|
||||
FreeCAD.Console.PrintError(translate("Arch","The base wire is closed")+"\n")
|
||||
return
|
||||
w = obj.Base.Shape.Wires[0]
|
||||
else:
|
||||
if obj.Length.Value == 0:
|
||||
return
|
||||
w = Part.Wire([Part.LineSegment(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,obj.Length.Value)).toShape()])
|
||||
return w
|
||||
|
||||
def getProfile(self,obj):
|
||||
|
||||
import Part
|
||||
if obj.Profile:
|
||||
if not obj.Profile.getLinkedObject().isDerivedFrom("Part::Part2DObject"):
|
||||
FreeCAD.Console.PrintError(translate("Arch","The profile is not a 2D Part")+"\n")
|
||||
return
|
||||
if not obj.Profile.Shape.Wires[0].isClosed():
|
||||
FreeCAD.Console.PrintError(translate("Arch","The profile is not closed")+"\n")
|
||||
return
|
||||
p = obj.Profile.Shape.Wires[0]
|
||||
else:
|
||||
if obj.Diameter.Value == 0:
|
||||
return
|
||||
p = Part.Wire([Part.Circle(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),obj.Diameter.Value/2).toShape()])
|
||||
if obj.WallThickness.Value and (obj.WallThickness.Value < obj.Diameter.Value/2):
|
||||
p2 = Part.Wire([Part.Circle(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),(obj.Diameter.Value/2-obj.WallThickness.Value)).toShape()])
|
||||
p = Part.Face(p)
|
||||
p2 = Part.Face(p2)
|
||||
p = p.cut(p2)
|
||||
return p
|
||||
|
||||
class ViewProviderPipe(ArchComponent.ViewProviderComponent):
|
||||
|
||||
|
||||
"A View Provider for the Pipe object"
|
||||
|
||||
def __init__(self,vobj):
|
||||
|
||||
ArchComponent.ViewProviderComponent.__init__(self,vobj)
|
||||
vobj.ShapeColor = (255, 50, 50)
|
||||
|
||||
def getIcon(self):
|
||||
|
||||
return ":/icons/Arch_Pipe_Tree.svg"
|
||||
|
||||
class CommandConduit:
|
||||
"the Arch Pipe command definition"
|
||||
|
||||
def GetResources(self):
|
||||
|
||||
return {'Pixmap' : 'Arch_Pipe',
|
||||
'MenuText': QT_TRANSLATE_NOOP("Arch_Pipe","Pipe"),
|
||||
'Accel': "P, I",
|
||||
'ToolTip': QT_TRANSLATE_NOOP("Arch_Pipe","Creates a pipe object from a given Wire or Line")}
|
||||
|
||||
def IsActive(self):
|
||||
return not FreeCAD.ActiveDocument is None
|
||||
|
||||
def Activated(self):
|
||||
s = FreeCADGui.Selection.getSelection()
|
||||
if s:
|
||||
for obj in s:
|
||||
if hasattr(obj,'Shape'):
|
||||
if len(obj.Shape.Wires) == 1:
|
||||
FreeCAD.ActiveDocument.openTransaction("Create Conduit")
|
||||
makePipe(obj, name="Conduit")
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
else:
|
||||
FreeCAD.ActiveDocument.openTransaction("Create Conduit")
|
||||
makePipe(name="Conduit")
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
class _CommandPipeConnector:
|
||||
"the Arch Pipe command definition"
|
||||
|
||||
def GetResources(self):
|
||||
|
||||
return {'Pixmap' : 'Arch_PipeConnector',
|
||||
'MenuText': QT_TRANSLATE_NOOP("Arch_PipeConnector","Connector"),
|
||||
'Accel': "P, C",
|
||||
'ToolTip': QT_TRANSLATE_NOOP("Arch_PipeConnector","Creates a connector between 2 or 3 selected pipes")}
|
||||
|
||||
def IsActive(self):
|
||||
|
||||
return not FreeCAD.ActiveDocument is None
|
||||
|
||||
def Activated(self):
|
||||
|
||||
import Draft
|
||||
s = FreeCADGui.Selection.getSelection()
|
||||
if not (len(s) in [2,3]):
|
||||
FreeCAD.Console.PrintError(translate("Arch","Please select exactly 2 or 3 Pipe objects")+"\n")
|
||||
return
|
||||
o = "["
|
||||
for obj in s:
|
||||
if Draft.getType(obj) != "Pipe":
|
||||
FreeCAD.Console.PrintError(translate("Arch","Please select only Pipe objects")+"\n")
|
||||
return
|
||||
o += "FreeCAD.ActiveDocument."+obj.Name+","
|
||||
o += "]"
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Connector"))
|
||||
FreeCADGui.addModule("Arch")
|
||||
FreeCADGui.doCommand("obj = Arch.makePipeConnector("+o+")")
|
||||
FreeCADGui.addModule("Draft")
|
||||
FreeCADGui.doCommand("Draft.autogroup(obj)")
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
class _ArchPipeConnector(ArchComponent.Component):
|
||||
|
||||
|
||||
"the Arch Pipe Connector object"
|
||||
|
||||
def __init__(self,obj):
|
||||
|
||||
ArchComponent.Component.__init__(self,obj)
|
||||
self.setProperties(obj)
|
||||
obj.IfcType = "Pipe Fitting"
|
||||
|
||||
def setProperties(self,obj):
|
||||
|
||||
pl = obj.PropertiesList
|
||||
if not "Radius" in pl:
|
||||
obj.addProperty("App::PropertyLength", "Radius", "PipeConnector", QT_TRANSLATE_NOOP("App::Property","The curvature radius of this connector"))
|
||||
if not "Pipes" in pl:
|
||||
obj.addProperty("App::PropertyLinkList", "Pipes", "PipeConnector", QT_TRANSLATE_NOOP("App::Property","The pipes linked by this connector"))
|
||||
if not "ConnectorType" in pl:
|
||||
obj.addProperty("App::PropertyEnumeration", "ConnectorType", "PipeConnector", QT_TRANSLATE_NOOP("App::Property","The type of this connector"))
|
||||
obj.ConnectorType = ["Corner","Tee"]
|
||||
obj.setEditorMode("ConnectorType",1)
|
||||
self.Type = "PipeConnector"
|
||||
|
||||
def onDocumentRestored(self,obj):
|
||||
|
||||
ArchComponent.Component.onDocumentRestored(self,obj)
|
||||
self.setProperties(obj)
|
||||
|
||||
def execute(self,obj):
|
||||
|
||||
tol = 1 # tolerance for alignment. This is only visual, we can keep it low...
|
||||
ptol = 0.001 # tolerance for coincident points
|
||||
|
||||
import math,Part,DraftGeomUtils,ArchCommands
|
||||
if len(obj.Pipes) < 2:
|
||||
return
|
||||
if len(obj.Pipes) > 3:
|
||||
FreeCAD.Console.PrintWarning(translate("Arch","Only the 3 first wires will be connected")+"\n")
|
||||
if obj.Radius.Value == 0:
|
||||
return
|
||||
wires = []
|
||||
order = []
|
||||
for o in obj.Pipes:
|
||||
wires.append(o.Proxy.getWire(o))
|
||||
if wires[0].Vertexes[0].Point.sub(wires[1].Vertexes[0].Point).Length <= ptol:
|
||||
order = ["start","start"]
|
||||
point = wires[0].Vertexes[0].Point
|
||||
elif wires[0].Vertexes[0].Point.sub(wires[1].Vertexes[-1].Point).Length <= ptol:
|
||||
order = ["start","end"]
|
||||
point = wires[0].Vertexes[0].Point
|
||||
elif wires[0].Vertexes[-1].Point.sub(wires[1].Vertexes[-1].Point).Length <= ptol:
|
||||
order = ["end","end"]
|
||||
point = wires[0].Vertexes[-1].Point
|
||||
elif wires[0].Vertexes[-1].Point.sub(wires[1].Vertexes[0].Point).Length <= ptol:
|
||||
order = ["end","start"]
|
||||
point = wires[0].Vertexes[-1].Point
|
||||
else:
|
||||
FreeCAD.Console.PrintError(translate("Arch","Common vertex not found")+"\n")
|
||||
return
|
||||
if order[0] == "start":
|
||||
v1 = wires[0].Vertexes[1].Point.sub(wires[0].Vertexes[0].Point).normalize()
|
||||
else:
|
||||
v1 = wires[0].Vertexes[-2].Point.sub(wires[0].Vertexes[-1].Point).normalize()
|
||||
if order[1] == "start":
|
||||
v2 = wires[1].Vertexes[1].Point.sub(wires[1].Vertexes[0].Point).normalize()
|
||||
else:
|
||||
v2 = wires[1].Vertexes[-2].Point.sub(wires[1].Vertexes[-1].Point).normalize()
|
||||
p = obj.Pipes[0].Proxy.getProfile(obj.Pipes[0])
|
||||
# If the pipe has a non-zero WallThickness p is a shape instead of a wire:
|
||||
if p.ShapeType != "Wire":
|
||||
p = p.Wires
|
||||
p = Part.Face(p)
|
||||
if len(obj.Pipes) == 2:
|
||||
if obj.ConnectorType != "Corner":
|
||||
obj.ConnectorType = "Corner"
|
||||
if round(v1.getAngle(v2),tol) in [0,round(math.pi,tol)]:
|
||||
FreeCAD.Console.PrintError(translate("Arch","Pipes are already aligned")+"\n")
|
||||
return
|
||||
normal = v2.cross(v1)
|
||||
offset = math.tan(math.pi/2-v1.getAngle(v2)/2)*obj.Radius.Value
|
||||
v1.multiply(offset)
|
||||
v2.multiply(offset)
|
||||
self.setOffset(obj.Pipes[0],order[0],offset)
|
||||
self.setOffset(obj.Pipes[1],order[1],offset)
|
||||
# find center
|
||||
perp = v1.cross(normal).normalize()
|
||||
perp.multiply(obj.Radius.Value)
|
||||
center = point.add(v1).add(perp)
|
||||
# move and rotate the profile to the first point
|
||||
delta = point.add(v1)-p.CenterOfMass
|
||||
p.translate(delta)
|
||||
vp = DraftGeomUtils.getNormal(p)
|
||||
rot = FreeCAD.Rotation(vp,v1)
|
||||
p.rotate(p.CenterOfMass,rot.Axis,math.degrees(rot.Angle))
|
||||
sh = p.revolve(center,normal,math.degrees(math.pi-v1.getAngle(v2)))
|
||||
#sh = Part.makeCompound([sh]+[Part.Vertex(point),Part.Vertex(point.add(v1)),Part.Vertex(center),Part.Vertex(point.add(v2))])
|
||||
else:
|
||||
if obj.ConnectorType != "Tee":
|
||||
obj.ConnectorType = "Tee"
|
||||
if wires[2].Vertexes[0].Point == point:
|
||||
order.append("start")
|
||||
elif wires[0].Vertexes[-1].Point == point:
|
||||
order.append("end")
|
||||
else:
|
||||
FreeCAD.Console.PrintError(translate("Arch","Common vertex not found")+"\n")
|
||||
if order[2] == "start":
|
||||
v3 = wires[2].Vertexes[1].Point.sub(wires[2].Vertexes[0].Point).normalize()
|
||||
else:
|
||||
v3 = wires[2].Vertexes[-2].Point.sub(wires[2].Vertexes[-1].Point).normalize()
|
||||
if round(v1.getAngle(v2),tol) in [0,round(math.pi,tol)]:
|
||||
pair = [v1,v2,v3]
|
||||
elif round(v1.getAngle(v3),tol) in [0,round(math.pi,tol)]:
|
||||
pair = [v1,v3,v2]
|
||||
elif round(v2.getAngle(v3),tol) in [0,round(math.pi,tol)]:
|
||||
pair = [v2,v3,v1]
|
||||
else:
|
||||
FreeCAD.Console.PrintError(translate("Arch","At least 2 pipes must align")+"\n")
|
||||
return
|
||||
offset = obj.Radius.Value
|
||||
v1.multiply(offset)
|
||||
v2.multiply(offset)
|
||||
v3.multiply(offset)
|
||||
self.setOffset(obj.Pipes[0],order[0],offset)
|
||||
self.setOffset(obj.Pipes[1],order[1],offset)
|
||||
self.setOffset(obj.Pipes[2],order[2],offset)
|
||||
normal = pair[0].cross(pair[2])
|
||||
# move and rotate the profile to the first point
|
||||
delta = point.add(pair[0])-p.CenterOfMass
|
||||
p.translate(delta)
|
||||
vp = DraftGeomUtils.getNormal(p)
|
||||
rot = FreeCAD.Rotation(vp,pair[0])
|
||||
p.rotate(p.CenterOfMass,rot.Axis,math.degrees(rot.Angle))
|
||||
t1 = p.extrude(pair[1].multiply(2))
|
||||
# move and rotate the profile to the second point
|
||||
delta = point.add(pair[2])-p.CenterOfMass
|
||||
p.translate(delta)
|
||||
vp = DraftGeomUtils.getNormal(p)
|
||||
rot = FreeCAD.Rotation(vp,pair[2])
|
||||
p.rotate(p.CenterOfMass,rot.Axis,math.degrees(rot.Angle))
|
||||
t2 = p.extrude(pair[2].negative().multiply(2))
|
||||
# create a cut plane
|
||||
cp = Part.makePolygon([point,point.add(pair[0]),point.add(normal),point])
|
||||
cp = Part.Face(cp)
|
||||
if cp.normalAt(0,0).getAngle(pair[2]) < math.pi/2:
|
||||
cp.reverse()
|
||||
cf, cv, invcv = ArchCommands.getCutVolume(cp,t2)
|
||||
t2 = t2.cut(cv)
|
||||
sh = t1.fuse(t2)
|
||||
obj.Shape = sh
|
||||
|
||||
def setOffset(self,pipe,pos,offset):
|
||||
|
||||
if pos == "start":
|
||||
if pipe.OffsetStart != offset:
|
||||
pipe.OffsetStart = offset
|
||||
pipe.Proxy.execute(pipe)
|
||||
else:
|
||||
if pipe.OffsetEnd != offset:
|
||||
pipe.OffsetEnd = offset
|
||||
pipe.Proxy.execute(pipe)
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('Conduit', CommandConduit())
|
||||
FreeCADGui.addCommand('Arch_PipeConnector',_CommandPipeConnector())
|
||||
|
||||
class _ArchPipeGroupCommand:
|
||||
|
||||
def GetCommands(self):
|
||||
return tuple(['Arch_Pipe','Arch_PipeConnector'])
|
||||
def GetResources(self):
|
||||
return { 'MenuText': QT_TRANSLATE_NOOP("Arch_PipeTools",'Pipe tools'),
|
||||
'ToolTip': QT_TRANSLATE_NOOP("Arch_PipeTools",'Pipe tools')
|
||||
}
|
||||
def IsActive(self):
|
||||
return not FreeCAD.ActiveDocument is None
|
||||
|
||||
FreeCADGui.addCommand('Arch_PipeTools', _ArchPipeGroupCommand())
|
||||
398
Electrical/Inverter/PVPlantInverter.py
Normal file
398
Electrical/Inverter/PVPlantInverter.py
Normal file
@@ -0,0 +1,398 @@
|
||||
# /**********************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2021 Javier Braña <javier.branagutierrez@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 *
|
||||
# * *
|
||||
# ***********************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import ArchComponent
|
||||
import os
|
||||
import zipfile
|
||||
import re
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
from DraftTools import translate
|
||||
else:
|
||||
# \cond
|
||||
def translate(ctxt,txt):
|
||||
return txt
|
||||
def QT_TRANSLATE_NOOP(ctxt,txt):
|
||||
return txt
|
||||
# \endcond
|
||||
|
||||
import os
|
||||
from PVPlantResources import DirIcons as DirIcons
|
||||
|
||||
__title__ = "PVPlant Areas"
|
||||
__author__ = "Javier Braña"
|
||||
__url__ = "http://www.sogos-solar.com"
|
||||
|
||||
import PVPlantResources
|
||||
from PVPlantResources import DirIcons as DirIcons
|
||||
Dir3dObjects = os.path.join(PVPlantResources.DirResources, "3dObjects")
|
||||
|
||||
|
||||
def makeStringInverter():
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "StringInverter")
|
||||
InverterBase(obj)
|
||||
ViewProviderStringInverter(obj.ViewObject)
|
||||
|
||||
try:
|
||||
folder = FreeCAD.ActiveDocument.StringInverters
|
||||
except:
|
||||
folder = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", 'StringInverters')
|
||||
folder.Label = "StringInverters"
|
||||
folder.addObject(obj)
|
||||
return obj
|
||||
|
||||
|
||||
class InverterBase(ArchComponent.Component):
|
||||
def __init__(self, obj):
|
||||
''' Initialize the Area object '''
|
||||
ArchComponent.Component.__init__(self, obj)
|
||||
|
||||
self.oldMPPTs = 0
|
||||
|
||||
self.Type = None
|
||||
self.obj = None
|
||||
self.setProperties(obj)
|
||||
|
||||
def setProperties(self, obj):
|
||||
pl = obj.PropertiesList
|
||||
|
||||
if not "File" in pl:
|
||||
obj.addProperty("App::PropertyFile",
|
||||
"File",
|
||||
"Inverter",
|
||||
"The base file this component is built upon")
|
||||
|
||||
if not ("MPPTs" in pl):
|
||||
obj.addProperty("App::PropertyQuantity",
|
||||
"MPPTs",
|
||||
"Inverter",
|
||||
"Points that define the area"
|
||||
).MPPTs = 0
|
||||
|
||||
if not ("Generator" in pl):
|
||||
obj.addProperty("App::PropertyEnumeration",
|
||||
"Generator",
|
||||
"Inverter",
|
||||
"Points that define the area"
|
||||
).Generator = ["Generic", "Library"]
|
||||
obj.Generator = "Generic"
|
||||
|
||||
if not ("Type" in pl):
|
||||
obj.addProperty("App::PropertyString",
|
||||
"Type",
|
||||
"Base",
|
||||
"Points that define the area"
|
||||
).Type = "InverterBase"
|
||||
obj.setEditorMode("Type", 1)
|
||||
|
||||
self.Type = obj.Type
|
||||
obj.Proxy = self
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
""" Method run when the document is restored """
|
||||
self.setProperties(obj)
|
||||
|
||||
def onBeforeChange(self, obj, prop):
|
||||
|
||||
if prop == "MPPTs":
|
||||
self.oldMPPTs = int(obj.MPPTs)
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
''' '''
|
||||
|
||||
if prop == "Generator":
|
||||
if obj.Generator == "Generic":
|
||||
obj.setEditorMode("MPPTs", 0)
|
||||
else:
|
||||
obj.setEditorMode("MPPTs", 1)
|
||||
|
||||
if prop == "MPPTs":
|
||||
''' '''
|
||||
if self.oldMPPTs > obj.MPPTs:
|
||||
''' borrar sobrantes '''
|
||||
obj.removeProperty()
|
||||
|
||||
elif self.oldMPPTs < obj.MPPTs:
|
||||
''' crear los faltantes '''
|
||||
for i in range(self.oldMPPTs, int(obj.MPPTs)):
|
||||
''' '''
|
||||
print(i)
|
||||
else:
|
||||
pass
|
||||
|
||||
if (prop == "File") and obj.File:
|
||||
''' '''
|
||||
|
||||
def execute(self, obj):
|
||||
''' '''
|
||||
# obj.Shape: compound
|
||||
# |- body: compound
|
||||
# |-- inverter: solid
|
||||
# |-- door: solid
|
||||
# |-- holder: solid
|
||||
|
||||
# |- connectors: compound
|
||||
# |-- DC: compound
|
||||
# |--- MPPT 1..x: compound
|
||||
# |---- positive: compound
|
||||
# |----- connector 1..y: ??
|
||||
# |---- negative 1..y: compound
|
||||
# |----- connector 1..y: ??
|
||||
# |-- AC: compound
|
||||
# |--- R,S,T,: ??
|
||||
# |-- Communication
|
||||
|
||||
pl = obj.Placement
|
||||
filename = self.getFile(obj)
|
||||
if filename:
|
||||
parts = self.getPartsList(obj)
|
||||
if parts:
|
||||
zdoc = zipfile.ZipFile(filename)
|
||||
if zdoc:
|
||||
f = zdoc.open(parts[list(parts.keys())[-1]][1])
|
||||
shapedata = f.read()
|
||||
f.close()
|
||||
shapedata = shapedata.decode("utf8")
|
||||
shape = self.cleanShape(shapedata, obj, parts[list(parts.keys())[-1]][2])
|
||||
obj.Shape = shape
|
||||
if not pl.isIdentity():
|
||||
obj.Placement = pl
|
||||
obj.MPPTs = len(shape.SubShapes[1].SubShapes[0].SubShapes)
|
||||
|
||||
def cleanShape(self, shapedata, obj, materials):
|
||||
"cleans the imported shape"
|
||||
|
||||
import Part
|
||||
shape = Part.Shape()
|
||||
shape.importBrepFromString(shapedata)
|
||||
'''if obj.FuseArch and materials:
|
||||
# separate lone edges
|
||||
shapes = []
|
||||
for edge in shape.Edges:
|
||||
found = False
|
||||
for solid in shape.Solids:
|
||||
for soledge in solid.Edges:
|
||||
if edge.hashCode() == soledge.hashCode():
|
||||
found = True
|
||||
break
|
||||
if found:
|
||||
break
|
||||
if found:
|
||||
break
|
||||
else:
|
||||
shapes.append(edge)
|
||||
print("solids:",len(shape.Solids),"mattable:",materials)
|
||||
for key,solindexes in materials.items():
|
||||
if key == "Undefined":
|
||||
# do not join objects with no defined material
|
||||
for solindex in [int(i) for i in solindexes.split(",")]:
|
||||
shapes.append(shape.Solids[solindex])
|
||||
else:
|
||||
fusion = None
|
||||
for solindex in [int(i) for i in solindexes.split(",")]:
|
||||
if not fusion:
|
||||
fusion = shape.Solids[solindex]
|
||||
else:
|
||||
fusion = fusion.fuse(shape.Solids[solindex])
|
||||
if fusion:
|
||||
shapes.append(fusion)
|
||||
shape = Part.makeCompound(shapes)
|
||||
try:
|
||||
shape = shape.removeSplitter()
|
||||
except Exception:
|
||||
print(obj.Label,": error removing splitter")'''
|
||||
return shape
|
||||
|
||||
def getFile(self, obj, filename=None):
|
||||
"gets a valid file, if possible"
|
||||
|
||||
if not filename:
|
||||
filename = obj.File
|
||||
if not filename:
|
||||
return None
|
||||
if not filename.lower().endswith(".fcstd"):
|
||||
return None
|
||||
if not os.path.exists(filename):
|
||||
# search for the file in the current directory if not found
|
||||
basename = os.path.basename(filename)
|
||||
currentdir = os.path.dirname(obj.Document.FileName)
|
||||
altfile = os.path.join(currentdir,basename)
|
||||
if altfile == obj.Document.FileName:
|
||||
return None
|
||||
elif os.path.exists(altfile):
|
||||
return altfile
|
||||
else:
|
||||
# search for subpaths in current folder
|
||||
altfile = None
|
||||
subdirs = self.splitall(os.path.dirname(filename))
|
||||
for i in range(len(subdirs)):
|
||||
subpath = [currentdir]+subdirs[-i:]+[basename]
|
||||
altfile = os.path.join(*subpath)
|
||||
if os.path.exists(altfile):
|
||||
return altfile
|
||||
return None
|
||||
return filename
|
||||
|
||||
def getPartsList(self, obj, filename=None):
|
||||
|
||||
"returns a list of Part-based objects in a FCStd file"
|
||||
|
||||
parts = {}
|
||||
materials = {}
|
||||
filename = self.getFile(obj,filename)
|
||||
if not filename:
|
||||
return parts
|
||||
zdoc = zipfile.ZipFile(filename)
|
||||
with zdoc.open("Document.xml") as docf:
|
||||
name = None
|
||||
label = None
|
||||
part = None
|
||||
materials = {}
|
||||
writemode = False
|
||||
for line in docf:
|
||||
line = line.decode("utf8")
|
||||
if "<Object name=" in line:
|
||||
n = re.findall('name=\"(.*?)\"',line)
|
||||
if n:
|
||||
name = n[0]
|
||||
elif "<Property name=\"Label\"" in line:
|
||||
writemode = True
|
||||
elif writemode and "<String value=" in line:
|
||||
n = re.findall('value=\"(.*?)\"',line)
|
||||
if n:
|
||||
label = n[0]
|
||||
writemode = False
|
||||
elif "<Property name=\"Shape\" type=\"Part::PropertyPartShape\"" in line:
|
||||
writemode = True
|
||||
elif writemode and "<Part file=" in line:
|
||||
n = re.findall('file=\"(.*?)\"',line)
|
||||
if n:
|
||||
part = n[0]
|
||||
writemode = False
|
||||
elif "<Property name=\"MaterialsTable\" type=\"App::PropertyMap\"" in line:
|
||||
writemode = True
|
||||
elif writemode and "<Item key=" in line:
|
||||
n = re.findall('key=\"(.*?)\"',line)
|
||||
v = re.findall('value=\"(.*?)\"',line)
|
||||
if n and v:
|
||||
materials[n[0]] = v[0]
|
||||
elif writemode and "</Map>" in line:
|
||||
writemode = False
|
||||
elif "</Object>" in line:
|
||||
if name and label and part:
|
||||
parts[name] = [label,part,materials]
|
||||
name = None
|
||||
label = None
|
||||
part = None
|
||||
materials = {}
|
||||
writemode = False
|
||||
return parts
|
||||
|
||||
def getColors(self,obj):
|
||||
|
||||
"returns the DiffuseColor of the referenced object"
|
||||
|
||||
filename = self.getFile(obj)
|
||||
if not filename:
|
||||
return None
|
||||
part = obj.Part
|
||||
if not obj.Part:
|
||||
return None
|
||||
zdoc = zipfile.ZipFile(filename)
|
||||
if not "GuiDocument.xml" in zdoc.namelist():
|
||||
return None
|
||||
colorfile = None
|
||||
with zdoc.open("GuiDocument.xml") as docf:
|
||||
writemode1 = False
|
||||
writemode2 = False
|
||||
for line in docf:
|
||||
line = line.decode("utf8")
|
||||
if ("<ViewProvider name=" in line) and (part in line):
|
||||
writemode1 = True
|
||||
elif writemode1 and ("<Property name=\"DiffuseColor\"" in line):
|
||||
writemode1 = False
|
||||
writemode2 = True
|
||||
elif writemode2 and ("<ColorList file=" in line):
|
||||
n = re.findall('file=\"(.*?)\"',line)
|
||||
if n:
|
||||
colorfile = n[0]
|
||||
break
|
||||
if not colorfile:
|
||||
return None
|
||||
if not colorfile in zdoc.namelist():
|
||||
return None
|
||||
colors = []
|
||||
cf = zdoc.open(colorfile)
|
||||
buf = cf.read()
|
||||
cf.close()
|
||||
for i in range(1,int(len(buf)/4)):
|
||||
colors.append((buf[i*4+3]/255.0,buf[i*4+2]/255.0,buf[i*4+1]/255.0,buf[i*4]/255.0))
|
||||
if colors:
|
||||
return colors
|
||||
return None
|
||||
|
||||
def splitall(self,path):
|
||||
|
||||
"splits a path between its components"
|
||||
|
||||
allparts = []
|
||||
while 1:
|
||||
parts = os.path.split(path)
|
||||
if parts[0] == path: # sentinel for absolute paths
|
||||
allparts.insert(0, parts[0])
|
||||
break
|
||||
elif parts[1] == path: # sentinel for relative paths
|
||||
allparts.insert(0, parts[1])
|
||||
break
|
||||
else:
|
||||
path = parts[0]
|
||||
allparts.insert(0, parts[1])
|
||||
return allparts
|
||||
|
||||
class ViewProviderStringInverter(ArchComponent.ViewProviderComponent):
|
||||
def __init__(self, vobj):
|
||||
ArchComponent.ViewProviderComponent.__init__(self, vobj)
|
||||
|
||||
def getIcon(self):
|
||||
return str(os.path.join(PVPlantResources.DirIcons, "Inverter.svg"))
|
||||
|
||||
|
||||
class CommandStringInverter:
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': str(os.path.join(PVPlantResources.DirIcons, "Inverter.svg")),
|
||||
'Accel': "E, I",
|
||||
'MenuText': "String Inverter",
|
||||
'ToolTip': "String Placement",}
|
||||
|
||||
def Activated(self):
|
||||
sinverter = makeStringInverter()
|
||||
|
||||
def IsActive(self):
|
||||
active = not (FreeCAD.ActiveDocument is None)
|
||||
return active
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('StringInverter', CommandStringInverter())
|
||||
|
||||
0
Electrical/Wiring.py
Normal file
0
Electrical/Wiring.py
Normal file
Reference in New Issue
Block a user