1 # Copyright (C) 2019-2021 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from salome.shaper import model
22 from EventsAPI import *
23 from ModelAPI import *
25 class FreeShapesListener(EventsAPI.Events_Listener):
27 Events_Listener.__init__(self)
28 # register as a listener
29 Events_Loop.loop().registerListener(self, Events_Loop.eventByName("DoFObjects"))
30 self.myEventProcessed = False
33 Events_Loop.loop().removeListener(self)
35 def processEvent(self, theMessage):
36 message = messageToUpdatedMessage(theMessage)
37 objs = message.objects()
38 assert(len(objs) == 3)
39 self.myEventProcessed = True
42 if __name__ == "__main__":
44 listener = FreeShapesListener()
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())
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);
63 assert(listener.myEventProcessed)
64 # explicitly remove the listener to improve code coverage