File size: 8,569 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | # SPDX-License-Identifier: LGPL-2.1-or-later
# ***************************************************************************
# * *
# * Copyright (c) 2020 Yorik van Havre <yorik@uncreated.net> *
# * *
# * This file is part of FreeCAD. *
# * *
# * FreeCAD is free software: you can redistribute it and/or modify it *
# * under the terms of the GNU Lesser General Public License as *
# * published by the Free Software Foundation, either version 2.1 of the *
# * License, or (at your option) any later version. *
# * *
# * FreeCAD 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 *
# * Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Lesser General Public *
# * License along with FreeCAD. If not, see *
# * <https://www.gnu.org/licenses/>. *
# * *
# ***************************************************************************
"""View providers and UI elements for the Ifc classes."""
import FreeCAD
import ArchIFC
if FreeCAD.GuiUp:
from PySide import QtCore, QtGui
import FreeCADGui
from draftutils.translate import translate
else:
def translate(ctxt, txt):
return txt
class IfcContextView:
"""A default view provider for IfcContext objects."""
def attach(self, vobj):
self.Object = vobj.Object
def setEdit(self, vobj, mode):
if mode == 1 or mode == 2:
return None
FreeCADGui.Control.showDialog(IfcContextUI(vobj.Object))
return True
def unsetEdit(self, vobj, mode):
if mode == 1 or mode == 2:
return None
FreeCADGui.Control.closeDialog()
return True
def setupContextMenu(self, vobj, menu):
if FreeCADGui.activeWorkbench().name() != "BIMWorkbench":
return
actionEdit = QtGui.QAction(translate("Arch", "Edit"), menu)
QtCore.QObject.connect(actionEdit, QtCore.SIGNAL("triggered()"), self.edit)
menu.addAction(actionEdit)
# The default Part::FeaturePython context menu contains a `Set colors`
# option. This option does not makes sense here. We therefore
# override this menu and have to add our own `Transform` item.
# To override the default menu this function must return `True`.
actionTransform = QtGui.QAction(
FreeCADGui.getIcon("Std_TransformManip.svg"),
translate("Command", "Transform"), # Context `Command` instead of `Arch`.
menu,
)
QtCore.QObject.connect(actionTransform, QtCore.SIGNAL("triggered()"), self.transform)
menu.addAction(actionTransform)
return True
def edit(self):
FreeCADGui.ActiveDocument.setEdit(self.Object, 0)
def transform(self):
FreeCADGui.ActiveDocument.setEdit(self.Object, 1)
def dumps(self):
return None
def loads(self, state):
return None
class IfcContextUI:
"""A default task panel for editing context objects."""
def __init__(self, object):
self.object = object
self.lineEditObjects = []
self.createBaseLayout()
self.createMapConversionFormLayout()
self.prefillMapConversionForm()
self.form = self.baseWidget
def accept(self):
"""This method runs as a callback when the user selects the ok button.
It writes the data entered into the forms to the object's IfcData
property.
"""
data = {}
for lineEdit in self.lineEditObjects:
data[lineEdit.objectName()] = lineEdit.text()
ArchIFC.IfcRoot.setObjIfcComplexAttributeValue(
self, self.object, "RepresentationContexts", data
)
FreeCADGui.ActiveDocument.resetEdit()
return True
def reject(self):
FreeCADGui.ActiveDocument.resetEdit()
return True
def createBaseLayout(self):
"""Defines the basic layout of the task panel."""
self.baseWidget = QtGui.QWidget()
self.baseLayout = QtGui.QVBoxLayout(self.baseWidget)
def createMapConversionFormLayout(self):
"""Creates form entries for the data being edited.
Creates form entries for each of the data points being edited within
the IFC complex attribute, RepresentationContexts.
"""
self.baseLayout.addWidget(self.createLabel("Target Coordinate Reference System"))
self.baseLayout.addLayout(self.createFormEntry("name", "Name"))
self.baseLayout.addLayout(self.createFormEntry("description", "Description"))
self.baseLayout.addLayout(self.createFormEntry("geodetic_datum", "Geodetic datum"))
self.baseLayout.addLayout(self.createFormEntry("vertical_datum", "Vertical datum"))
self.baseLayout.addLayout(self.createFormEntry("map_projection", "Map projection"))
self.baseLayout.addLayout(self.createFormEntry("map_zone", "Map zone"))
self.baseLayout.addLayout(self.createFormEntry("map_unit", "Map unit"))
self.baseLayout.addWidget(self.createLabel("Map Conversion"))
self.baseLayout.addLayout(self.createFormEntry("eastings", "Eastings"))
self.baseLayout.addLayout(self.createFormEntry("northings", "Northings"))
self.baseLayout.addLayout(self.createFormEntry("orthogonal_height", "Orthogonal height"))
self.baseLayout.addLayout(
self.createFormEntry("true_north", "True north (anti-clockwise from +Y)")
)
self.baseLayout.addLayout(self.createFormEntry("scale", "Scale"))
def prefillMapConversionForm(self):
"""Prefills each of the form entries with the existing value.
Gets the existing value from the object's IfcData, specifically the complex
attribute, RepresentationContexts.
"""
data = ArchIFC.IfcRoot.getObjIfcComplexAttribute(
self, self.object, "RepresentationContexts"
)
for lineEdit in self.lineEditObjects:
if lineEdit.objectName() in data:
lineEdit.setText(data[lineEdit.objectName()])
def createFormEntry(self, name, label):
"""Creates a form entry.
The name corresponds to the data point being edited in the
RepresentationContexts complex attribute. The label is a human readable
version of the name.
Parameters
----------
name: str
The name of the datapoint within the RepresentationContexts
attribute being edited.
label: str
A human readable version of the name.
Returns
-------
<PySide2.QtWidgets.QWidget>
Widget containing the label and form.
"""
layout = QtGui.QHBoxLayout(self.baseWidget)
layout.addWidget(self.createLabel(label))
layout.addWidget(self.createLineEdit(name))
return layout
def createLabel(self, value):
"""Creates a translated label.
Parameters
----------
value: str
The human readable label text.
Returns
-------
<PySide2.QtWidgets.QWidget>
The label Qt widget.
"""
label = QtGui.QLabel(self.baseWidget)
label.setText(QtGui.QApplication.translate("Arch", value, None))
return label
def createLineEdit(self, name):
"""Creates a form with the name specified.
Parameters
----------
name: str
The name of the datapoint within the RepresentationContexts
attribute being edited.
Returns
-------
<PySide2.QtWidgets.QWidget>
The form Qt widget.
"""
lineEdit = QtGui.QLineEdit(self.baseWidget)
lineEdit.setObjectName(name)
self.lineEditObjects.append(lineEdit)
return lineEdit
|