Skip to content

Commit

Permalink
Test: test moving features from one part to another
Browse files Browse the repository at this point in the history
  • Loading branch information
usakhelo authored and wwmayer committed Aug 24, 2016
1 parent 85015ef commit dcd9420
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 15 deletions.
110 changes: 96 additions & 14 deletions src/Mod/PartDesign/TestPartDesignGui.py
@@ -1,4 +1,4 @@
# (c) Juergen Riegel (FreeCAD@juergen-riegel.net) 2011 LGPL *
# (c) Juergen Riegel (FreeCAD@juergen-riegel.net) 2011 LGPL *
# *
# This file is part of the FreeCAD CAx development system. *
# *
Expand All @@ -19,25 +19,107 @@
# USA *
#**************************************************************************

import FreeCAD, FreeCADGui, os, sys, unittest, PartDesign, PartDesignGui
import FreeCAD
import FreeCADGui
import os
import sys
import unittest
import Sketcher
import Part
import PartDesign
import PartDesignGui

from PySide import QtGui, QtCore
from PySide.QtGui import QApplication

#timer runs this class in order to access modal dialog
class Callable:
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):
cbox = diag.findChild(QtGui.QComboBox)
self.test.assertIsNotNone(cbox, "ComboBox widget could not be found")
if (cbox != None):
cbox.setCurrentIndex(1)
QtCore.QTimer.singleShot(0, diag, QtCore.SLOT('accept()'))

App = FreeCAD
Gui = FreeCADGui
#---------------------------------------------------------------------------
# define the test cases to test the FreeCAD PartDesign module
#---------------------------------------------------------------------------
class PartDesignGuiTestCases(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("SketchGuiTest")

def testMoveSingleFeature(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.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch')
self.Sketch.Support = (self.Doc.XY_Plane, [''])
self.Sketch.MapMode = 'FlatFace'
self.BodySource.addFeature(self.Sketch)

geoList = []
geoList.append(Part.Line(App.Vector(-10.000000,10.000000,0),App.Vector(10.000000,10.000000,0)))
geoList.append(Part.Line(App.Vector(10.000000,10.000000,0),App.Vector(10.000000,-10.000000,0)))
geoList.append(Part.Line(App.Vector(10.000000,-10.000000,0),App.Vector(-10.000000,-10.000000,0)))
geoList.append(Part.Line(App.Vector(-10.000000,-10.000000,0),App.Vector(-10.000000,10.000000,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 = Callable(self)
QtCore.QTimer.singleShot(500, cobj)
Gui.runCommand('PartDesign_MoveFeature')
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")

def tearDown(self):
FreeCAD.closeDocument("SketchGuiTest")

#class PartDesignGuiTestCases(unittest.TestCase):
# def setUp(self):
# self.Doc = FreeCAD.newDocument("SketchGuiTest")
# def setUp(self):
# self.Doc = FreeCAD.newDocument("SketchGuiTest")
#
# def testBoxCase(self):
# self.Box = self.Doc.addObject('PartDesign::SketchObject','SketchBox')
# self.Box.addGeometry(Part.Line(App.Vector(-99.230339,36.960674,0),App.Vector(69.432587,36.960674,0)))
# self.Box.addGeometry(Part.Line(App.Vector(69.432587,36.960674,0),App.Vector(69.432587,-53.196629,0)))
# self.Box.addGeometry(Part.Line(App.Vector(69.432587,-53.196629,0),App.Vector(-99.230339,-53.196629,0)))
# self.Box.addGeometry(Part.Line(App.Vector(-99.230339,-53.196629,0),App.Vector(-99.230339,36.960674,0)))
#
# def tearDown(self):
# #closing doc
# FreeCAD.closeDocument("SketchGuiTest")
# def testBoxCase(self):
# self.Box = self.Doc.addObject('PartDesign::SketchObject','SketchBox')
# self.Box.addGeometry(Part.Line(App.Vector(-99.230339,36.960674,0),App.Vector(69.432587,36.960674,0)))
# self.Box.addGeometry(Part.Line(App.Vector(69.432587,36.960674,0),App.Vector(69.432587,-53.196629,0)))
# self.Box.addGeometry(Part.Line(App.Vector(69.432587,-53.196629,0),App.Vector(-99.230339,-53.196629,0)))
# self.Box.addGeometry(Part.Line(App.Vector(-99.230339,-53.196629,0),App.Vector(-99.230339,36.960674,0)))
#
# def tearDown(self):
# #closing doc
# FreeCAD.closeDocument("SketchGuiTest")
3 changes: 2 additions & 1 deletion src/Mod/Test/TestGui.py
@@ -1,4 +1,4 @@
# FreeCAD Part module
# FreeCAD Part module
# (c) 2001 Juergen Riegel
#
# Part design module
Expand Down Expand Up @@ -51,6 +51,7 @@ def Activated(self):
QtUnitGui.addTest("TestSketcherApp")
QtUnitGui.addTest("TestPartApp")
QtUnitGui.addTest("TestPartDesignApp")
QtUnitGui.addTest("TestPartDesignGui")
QtUnitGui.addTest("TestSpreadsheet")
QtUnitGui.addTest("TestDraft")
QtUnitGui.addTest("TestArch")
Expand Down

0 comments on commit dcd9420

Please sign in to comment.