Salome HOME
Copyright update 2022
[modules/shaper.git] / src / SketchPlugin / Test / Test3087_1.py
1 # Copyright (C) 2019-2022  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) == 3)
39         self.myEventProcessed = True
40
41
42 if __name__ == "__main__":
43     # create the listener
44     listener = FreeShapesListener()
45
46     model.begin()
47     partSet = model.moduleDocument()
48     Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
49     SketchLine_1 = Sketch_1.addLine(10, 10, -10, 10)
50     SketchLine_2 = Sketch_1.addLine(-10, 10, -10, -10)
51     SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
52     SketchLine_3 = Sketch_1.addLine(-10, -10, 10, -10)
53     SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
54     SketchConstraintRigid_1 = Sketch_1.setFixed(SketchLine_1.startPoint())
55     SketchConstraintRigid_2 = Sketch_1.setFixed(SketchLine_3.endPoint())
56     model.end()
57
58     # send message to find the free shapes in the sketch
59     event = Events_Loop.eventByName("GetDoFObjects")
60     ModelAPI_EventCreator.get().sendUpdated(Sketch_1.feature(), event);
61     Events_Loop.loop().flush(event);
62
63     assert(listener.myEventProcessed)
64     # explicitly remove the listener to improve code coverage
65     listener.__del__()