Salome HOME
Copyright update 2021
[modules/shaper.git] / src / SketchPlugin / Test / TestRemainingDoF.py
1 # Copyright (C) 2019-2021  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from salome.shaper import model
21
22 from EventsAPI import *
23 from ModelAPI import *
24
25 class FreeShapesListener(EventsAPI.Events_Listener):
26     def __init__(self):
27         Events_Listener.__init__(self)
28         # register as a listener
29         Events_Loop.loop().registerListener(self, Events_Loop.eventByName("DoFObjects"))
30         self.myEventProcessed = False
31
32     def __del__(self):
33         Events_Loop.loop().removeListener(self)
34
35     def processEvent(self, theMessage):
36         message = messageToUpdatedMessage(theMessage)
37         objs = message.objects()
38         assert(len(objs) == 1)
39         assert(objectToFeature(objs[0]).getKind() == "SketchCircle")
40         self.myEventProcessed = True
41
42
43 if __name__ == "__main__":
44     # create the listener
45     listener = FreeShapesListener()
46
47     model.begin()
48     partSet = model.moduleDocument()
49     Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
50     SketchCircle_1 = Sketch_1.addCircle(-30, 0, 14)
51     SketchLine_1 = Sketch_1.addLine(-30, 0, 0, 0)
52     SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.startPoint())
53     SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "Origin"), False)
54     SketchPoint_1 = SketchProjection_1.createdFeature()
55     SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
56     SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
57     SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30)
58     model.end()
59
60     # send message to find the free shapes in the sketch
61     event = Events_Loop.eventByName("GetDoFObjects")
62     ModelAPI_EventCreator.get().sendUpdated(Sketch_1.feature(), event);
63     Events_Loop.loop().flush(event);
64
65     assert(listener.myEventProcessed)