Part: [skip ci] implement editor dialog for tube feature
This commit is contained in:
@@ -26,6 +26,11 @@ __url__ = "http://www.freecadweb.org"
|
||||
__doc__ = "Basic shapes"
|
||||
|
||||
|
||||
import os
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
class ViewProviderTube:
|
||||
def __init__(self, obj):
|
||||
@@ -36,6 +41,27 @@ class ViewProviderTube:
|
||||
''' Setup the scene sub-graph of the view provider, this method is mandatory '''
|
||||
return
|
||||
|
||||
def setupContextMenu(self, viewObject, menu):
|
||||
action = menu.addAction(FreeCAD.Qt.translate("QObject", "Edit %1").replace("%1", viewObject.Object.Label))
|
||||
action.triggered.connect(lambda: self.startDefaultEditMode(viewObject))
|
||||
return False
|
||||
|
||||
def startDefaultEditMode(self, viewObject):
|
||||
text = FreeCAD.Qt.translate("QObject", "Edit %1").replace("%1", viewObject.Object.Label)
|
||||
document = viewObject.Document.Document
|
||||
document.openTransaction(text)
|
||||
viewObject.Document.setEdit(viewObject.Object, 0)
|
||||
|
||||
def setEdit(self, viewObject, mode):
|
||||
if mode == 0:
|
||||
FreeCADGui.Control.showDialog(TaskTubeUI(viewObject))
|
||||
return True
|
||||
|
||||
def unsetEdit(self, viewObject, mode):
|
||||
if mode == 0:
|
||||
FreeCADGui.Control.closeDialog()
|
||||
return True
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/parametric/Part_Tube_Parametric.svg"
|
||||
|
||||
@@ -44,3 +70,55 @@ class ViewProviderTube:
|
||||
|
||||
def __setstate__(self,state):
|
||||
return None
|
||||
|
||||
|
||||
class TaskTubeUI:
|
||||
"""A default task panel for editing tube objects."""
|
||||
|
||||
def __init__(self, viewObject):
|
||||
self.viewObject = viewObject
|
||||
ui_file = os.path.join(os.path.dirname(__file__), "TaskTube.ui")
|
||||
ui = FreeCADGui.UiLoader()
|
||||
self.form = ui.load(ui_file)
|
||||
|
||||
object = self.viewObject.Object
|
||||
self.form.tubeOuterRadius.setProperty("rawValue", object.OuterRadius.Value)
|
||||
self.form.tubeInnerRadius.setProperty("rawValue", object.InnerRadius.Value)
|
||||
self.form.tubeHeight.setProperty("rawValue", object.Height.Value)
|
||||
|
||||
self.form.tubeOuterRadius.valueChanged.connect(lambda x: self.onChangeOuterRadius(x))
|
||||
self.form.tubeInnerRadius.valueChanged.connect(lambda x: self.onChangeInnerRadius(x))
|
||||
self.form.tubeHeight.valueChanged.connect(lambda x: self.onChangeHeight(x))
|
||||
|
||||
def onChangeOuterRadius(self, radius):
|
||||
object = self.viewObject.Object
|
||||
object.OuterRadius = radius
|
||||
object.recompute()
|
||||
|
||||
def onChangeInnerRadius(self, radius):
|
||||
object = self.viewObject.Object
|
||||
object.InnerRadius = radius
|
||||
object.recompute()
|
||||
|
||||
def onChangeHeight(self, height):
|
||||
object = self.viewObject.Object
|
||||
object.Height = height
|
||||
object.recompute()
|
||||
|
||||
def accept(self):
|
||||
object = self.viewObject.Object
|
||||
if not object.isValid():
|
||||
QtGui.QMessageBox.warning(None, "Error", object.getStatusString())
|
||||
return False
|
||||
document = self.viewObject.Document.Document
|
||||
document.commitTransaction()
|
||||
document.recompute()
|
||||
self.viewObject.Document.resetEdit()
|
||||
return True
|
||||
|
||||
def reject(self):
|
||||
document = self.viewObject.Document.Document
|
||||
document.abortTransaction()
|
||||
document.recompute()
|
||||
self.viewObject.Document.resetEdit()
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user