TestSketcherApp.py

Go to the documentation of this file.
00001 #   (c) Juergen Riegel (FreeCAD@juergen-riegel.net) 2011      LGPL        *
00002 #                                                                         *
00003 #   This file is part of the FreeCAD CAx development system.              *
00004 #                                                                         *
00005 #   This program is free software; you can redistribute it and/or modify  *
00006 #   it under the terms of the GNU Lesser General Public License (LGPL)    *
00007 #   as published by the Free Software Foundation; either version 2 of     *
00008 #   the License, or (at your option) any later version.                   *
00009 #   for detail see the LICENCE text file.                                 *
00010 #                                                                         *
00011 #   FreeCAD is distributed in the hope that it will be useful,            *
00012 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014 #   GNU Library General Public License for more details.                  *
00015 #                                                                         *
00016 #   You should have received a copy of the GNU Library General Public     *
00017 #   License along with FreeCAD; if not, write to the Free Software        *
00018 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00019 #   USA                                                                   *
00020 #**************************************************************************
00021 
00022 
00023 import FreeCAD, os, sys, unittest, Part, Sketcher
00024 App = FreeCAD
00025 
00026 def CreateBoxSketchSet(SketchFeature):
00027         SketchFeature.addGeometry(Part.Line(FreeCAD.Vector(-99.230339,36.960674,0),FreeCAD.Vector(69.432587,36.960674,0)))
00028         SketchFeature.addGeometry(Part.Line(FreeCAD.Vector(69.432587,36.960674,0),FreeCAD.Vector(69.432587,-53.196629,0)))
00029         SketchFeature.addGeometry(Part.Line(FreeCAD.Vector(69.432587,-53.196629,0),FreeCAD.Vector(-99.230339,-53.196629,0)))
00030         SketchFeature.addGeometry(Part.Line(FreeCAD.Vector(-99.230339,-53.196629,0),FreeCAD.Vector(-99.230339,36.960674,0)))
00031         # add the constraints
00032         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1)) 
00033         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1)) 
00034         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1)) 
00035         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',3,2,0,1)) 
00036         SketchFeature.addConstraint(Sketcher.Constraint('Horizontal',0)) 
00037         SketchFeature.addConstraint(Sketcher.Constraint('Horizontal',2)) 
00038         SketchFeature.addConstraint(Sketcher.Constraint('Vertical',1)) 
00039         SketchFeature.addConstraint(Sketcher.Constraint('Vertical',3)) 
00040         # add dimensions
00041         SketchFeature.addConstraint(Sketcher.Constraint('Distance',1,81.370787)) 
00042         SketchFeature.addConstraint(Sketcher.Constraint('Distance',0,187.573036)) 
00043 
00044 def CreateSlotPlateSet(SketchFeature):
00045         SketchFeature.addGeometry(Part.Line(App.Vector(60.029362,-30.279360,0),App.Vector(-120.376335,-30.279360,0)))
00046         SketchFeature.addConstraint(Sketcher.Constraint('Horizontal',0)) 
00047         SketchFeature.addGeometry(Part.Line(App.Vector(-120.376335,-30.279360,0),App.Vector(-70.193062,38.113884,0)))
00048         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1)) 
00049         SketchFeature.addGeometry(Part.Line(App.Vector(-70.193062,38.113884,0),App.Vector(60.241116,37.478645,0)))
00050         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1)) 
00051         SketchFeature.addConstraint(Sketcher.Constraint('Horizontal',2)) 
00052         SketchFeature.addGeometry(Part.ArcOfCircle(Part.Circle(App.Vector(60.039921,3.811391,0),App.Vector(0,0,1),35.127132),-1.403763,1.419522))
00053         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',3,2,2,2)) 
00054         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',3,1,0,1)) 
00055         SketchFeature.addConstraint(Sketcher.Constraint('Tangent',3,2)) 
00056         SketchFeature.addConstraint(Sketcher.Constraint('Tangent',3,0)) 
00057         SketchFeature.addConstraint(Sketcher.Constraint('Angle',0,2,1,1,0.947837)) 
00058         SketchFeature.addConstraint(Sketcher.Constraint('Distance',0,184.127425)) 
00059         SketchFeature.setDatum(9,200.000000)
00060         SketchFeature.addConstraint(Sketcher.Constraint('Radius',3,38.424808)) 
00061         SketchFeature.setDatum(10,40.000000)
00062         SketchFeature.setDatum(8,0.872665)
00063         SketchFeature.addConstraint(Sketcher.Constraint('DistanceX',0,2,0.0)) 
00064         SketchFeature.setDatum(11,0.000000)
00065         SketchFeature.movePoint(0,2,App.Vector(-0.007829,-33.376450,0))
00066         SketchFeature.movePoint(0,2,App.Vector(-0.738149,-10.493386,0))
00067         SketchFeature.movePoint(0,2,App.Vector(-0.007829,2.165328,0))
00068         SketchFeature.addConstraint(Sketcher.Constraint('DistanceY',0,2,2.165328)) 
00069         SketchFeature.setDatum(12,0.000000)
00070 
00071 def CreateSlotPlateInnerSet(SketchFeature):
00072         SketchFeature.addGeometry(Part.Circle(App.Vector(195.055893,39.562252,0),App.Vector(0,0,1),29.846098))
00073         SketchFeature.addGeometry(Part.Line(App.Vector(150.319031,13.449363,0),App.Vector(36.700474,13.139774,0)))
00074         SketchFeature.addConstraint(Sketcher.Constraint('Horizontal',5)) 
00075         SketchFeature.addGeometry(Part.Line(App.Vector(36.700474,13.139774,0),App.Vector(77.566010,63.292927,0)))
00076         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',5,2,6,1)) 
00077         SketchFeature.addGeometry(Part.Line(App.Vector(77.566010,63.292927,0),App.Vector(148.151917,63.602505,0)))
00078         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',6,2,7,1)) 
00079         SketchFeature.addConstraint(Sketcher.Constraint('Horizontal',7)) 
00080         SketchFeature.addConstraint(Sketcher.Constraint('Parallel',1,6)) 
00081         SketchFeature.addGeometry(Part.ArcOfCircle(Part.Circle(App.Vector(192.422913,38.216347,0),App.Vector(0,0,1),45.315174),2.635158,3.602228))
00082         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',7,2,8,1)) 
00083         SketchFeature.addConstraint(Sketcher.Constraint('Coincident',8,2,5,1))
00084         
00085 
00086 
00087 #---------------------------------------------------------------------------
00088 # define the test cases to test the FreeCAD Sketcher module
00089 #---------------------------------------------------------------------------
00090 
00091 
00092 class SketcherSolverTestCases(unittest.TestCase):
00093         def setUp(self):
00094                 self.Doc = FreeCAD.newDocument("SketchSolverTest")
00095 
00096         def testBoxCase(self):
00097                 self.Box = self.Doc.addObject('Sketcher::SketchObject','SketchBox')
00098                 CreateBoxSketchSet(self.Box)
00099                 self.Doc.recompute()
00100                 # moving a point of the sketch
00101                 self.Box.movePoint(0,2,App.Vector(88.342697,28.174158,0))
00102                 # fully constrain
00103                 self.Box.addConstraint(Sketcher.Constraint('DistanceX',1,2,90.0)) 
00104                 self.Box.addConstraint(Sketcher.Constraint('DistanceY',1,2,-50.0)) 
00105                 self.Doc.recompute()
00106                 
00107         def testSlotCase(self):
00108                 self.Slot = self.Doc.addObject('Sketcher::SketchObject','SketchSlot')
00109                 CreateSlotPlateSet(self.Slot)
00110                 self.Doc.recompute()
00111                 # test if all edges created 
00112                 self.failUnless(len(self.Slot.Shape.Edges) == 4)
00113                 CreateSlotPlateInnerSet(self.Slot)
00114                 self.Doc.recompute()
00115                 self.failUnless(len(self.Slot.Shape.Edges) == 9)
00116         
00117         
00118         def tearDown(self):
00119                 #closing doc
00120                 FreeCAD.closeDocument("SketchSolverTest")
00121                 #print ("omit close document for debuging")

Generated on Wed Nov 23 19:00:45 2011 for FreeCAD by  doxygen 1.6.1