1 # Copyright (C) 2019-2022 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) == 1)
39 assert(objectToFeature(objs[0]).getKind() == "SketchCircle")
40 self.myEventProcessed = True
43 if __name__ == "__main__":
45 listener = FreeShapesListener()
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)
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);
65 assert(listener.myEventProcessed)