Skip to content

Commit

Permalink
Part: [skip ci] implement editor dialog for tube feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 12, 2020
1 parent ba3106a commit 8121259
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Mod/Part/BasicShapes/CommandShapes.py
Expand Up @@ -48,7 +48,8 @@ def GetResources(self):
'ToolTip': Qt.QT_TRANSLATE_NOOP("Part_Tube","Creates a tube")}

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create tube")
text = FreeCAD.Qt.translate("QObject", "Create tube")
FreeCAD.ActiveDocument.openTransaction(text)
tube = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Tube")
Shapes.TubeFeature(tube)
ViewProviderShapes.ViewProviderTube(tube.ViewObject)
Expand Down
152 changes: 152 additions & 0 deletions src/Mod/Part/BasicShapes/TaskTube.ui
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartGui::TaskTube</class>
<widget class="QWidget" name="PartGui::TaskTube">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>367</width>
<height>223</height>
</rect>
</property>
<property name="windowTitle">
<string>Tube</string>
</property>
<property name="sizeGripEnabled" stdset="0">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Parameter</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="2">
<widget class="Gui::QuantitySpinBox" name="tubeInnerRadius">
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="Gui::QuantitySpinBox" name="tubeHeight">
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="textLabel3">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Outer radius</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Inner radius</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Gui::QuantitySpinBox" name="tubeOuterRadius">
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="value">
<double>4.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>60</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tubeOuterRadius</tabstop>
<tabstop>tubeInnerRadius</tabstop>
<tabstop>tubeHeight</tabstop>
</tabstops>
<resources>
<include location="../Gui/Resources/Part.qrc"/>
</resources>
<connections/>
</ui>
78 changes: 78 additions & 0 deletions src/Mod/Part/BasicShapes/ViewProviderShapes.py
Expand Up @@ -26,6 +26,11 @@
__doc__ = "Basic shapes"


import os
import FreeCAD
import FreeCADGui

from PySide import QtGui

class ViewProviderTube:
def __init__(self, obj):
Expand All @@ -36,6 +41,27 @@ def attach(self, obj):
''' 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"

Expand All @@ -44,3 +70,55 @@ def __getstate__(self):

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
1 change: 1 addition & 0 deletions src/Mod/Part/CMakeLists.txt
Expand Up @@ -35,6 +35,7 @@ if(BUILD_GUI)
list (APPEND BasicShapes_Scripts
BasicShapes/CommandShapes.py
BasicShapes/ViewProviderShapes.py
BasicShapes/TaskTube.ui
)
endif(BUILD_GUI)

Expand Down

0 comments on commit 8121259

Please sign in to comment.