Skip to content

Commit

Permalink
Test: Add case to test attempt when feature is not movable
Browse files Browse the repository at this point in the history
  • Loading branch information
usakhelo authored and wwmayer committed Aug 24, 2016
1 parent f49ddae commit 8750ac5
Showing 1 changed file with 78 additions and 2 deletions.
80 changes: 78 additions & 2 deletions src/Mod/PartDesign/TestPartDesignGui.py
Expand Up @@ -33,12 +33,21 @@
from PySide.QtGui import QApplication

#timer runs this class in order to access modal dialog
class Callable:
class CallableCheckWarning:
def __init__(self, test):
self.test = test
def __call__(self):
diag = QApplication.activeModalWidget()
self.test.assertIsNotNone(diag, "Input dialog box could not be found")
if (diag != None):
QtCore.QTimer.singleShot(0, diag, QtCore.SLOT('accept()'))

class CallableComboBox:
def __init__(self, test):
self.test = test
def __call__(self):
diag = QApplication.activeModalWidget()
self.test.assertIsNotNone(diag, "Warning dialog box could not be found")
if (diag != None):
cbox = diag.findChild(QtGui.QComboBox)
self.test.assertIsNotNone(cbox, "ComboBox widget could not be found")
Expand All @@ -55,6 +64,70 @@ class PartDesignGuiTestCases(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("SketchGuiTest")

def testRefuseToMoveSingleFeature(self):
FreeCAD.Console.PrintMessage('Testing moving one feature from one body to another\n')
self.BodySource = self.Doc.addObject('PartDesign::Body','Body')
Gui.activeView().setActiveObject('pdbody', self.BodySource)

self.BoxObj = self.Doc.addObject('PartDesign::AdditiveBox','Box')
self.BoxObj.Length=10.0
self.BoxObj.Width=10.0
self.BoxObj.Height=10.0
self.BodySource.addFeature(self.BoxObj)

self.BoxCoords = self.Doc.addObject('PartDesign::CoordinateSystem','CoordinateSystem')
self.BodySource.addFeature(self.BoxCoords)
self.BoxObj.CoordinateSystem=(self.BoxCoords)
App.ActiveDocument.recompute()
Gui.activeDocument().hide('CoordinateSystem')

self.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch')
self.Sketch.Support = (self.BoxObj, ('Face3',))
self.Sketch.MapMode = 'FlatFace'
self.BodySource.addFeature(self.Sketch)

geoList = []
geoList.append(Part.Line(App.Vector(2.0,8.0,0),App.Vector(8.0,8.0,0)))
geoList.append(Part.Line(App.Vector(8.0,8.0,0),App.Vector(8.0,2.0,0)))
geoList.append(Part.Line(App.Vector(8.0,2.0,0),App.Vector(2.0,2.0,0)))
geoList.append(Part.Line(App.Vector(2.0,2.0,0),App.Vector(2.0,8.0,0)))
self.Sketch.addGeometry(geoList,False)
conList = []
conList.append(Sketcher.Constraint('Coincident',0,2,1,1))
conList.append(Sketcher.Constraint('Coincident',1,2,2,1))
conList.append(Sketcher.Constraint('Coincident',2,2,3,1))
conList.append(Sketcher.Constraint('Coincident',3,2,0,1))
conList.append(Sketcher.Constraint('Horizontal',0))
conList.append(Sketcher.Constraint('Horizontal',2))
conList.append(Sketcher.Constraint('Vertical',1))
conList.append(Sketcher.Constraint('Vertical',3))
self.Sketch.addConstraint(conList)

self.Pad = self.Doc.addObject("PartDesign::Pad","Pad")
self.Pad.Profile = self.Sketch
self.Pad.Length = 10.000000
self.Pad.Length2 = 100.000000
self.Pad.Type = 0
self.Pad.UpToFace = None
self.Pad.Reversed = 0
self.Pad.Midplane = 0
self.Pad.Offset = 0.000000

self.BodySource.addFeature(self.Pad)

self.Doc.recompute()
Gui.SendMsgToActiveView("ViewFit")

self.BodyTarget = self.Doc.addObject('PartDesign::Body','Body')

Gui.Selection.addSelection(App.ActiveDocument.Pad)
cobj = CallableCheckWarning(self)
QtCore.QTimer.singleShot(500, cobj)
Gui.runCommand('PartDesign_MoveFeature')
#assert depenedencies of the Sketch
self.assertEqual(len(self.BodySource.Model), 4, "Source body feature count is wrong")
self.assertEqual(len(self.BodyTarget.Model), 0, "Target body feature count is wrong")

def testMoveSingleFeature(self):
FreeCAD.Console.PrintMessage('Testing moving one feature from one body to another\n')
self.BodySource = self.Doc.addObject('PartDesign::Body','Body')
Expand Down Expand Up @@ -100,9 +173,12 @@ def testMoveSingleFeature(self):
self.BodyTarget = self.Doc.addObject('PartDesign::Body','Body')

Gui.Selection.addSelection(App.ActiveDocument.Pad)
cobj = Callable(self)
cobj = CallableComboBox(self)
QtCore.QTimer.singleShot(500, cobj)
Gui.runCommand('PartDesign_MoveFeature')
#assert depenedencies of the Sketch
self.assertFalse(self.Sketch.Support[0][0] in self.BodySource.Origin.OriginFeatures)
self.assertTrue(self.Sketch.Support[0][0] in self.BodyTarget.Origin.OriginFeatures)
self.assertEqual(len(self.BodySource.Model), 0, "Source body feature count is wrong")
self.assertEqual(len(self.BodyTarget.Model), 2, "Target body feature count is wrong")

Expand Down

0 comments on commit 8750ac5

Please sign in to comment.