2 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include <InitializationPlugin_Plugin.h>
6 #include <ModelAPI_Session.h>
7 #include <ModelAPI_Document.h>
8 #include <ModelAPI_AttributeDouble.h>
9 #include <ModelAPI_AttributeString.h>
12 #include <Events_Message.h>
14 #include <ModelAPI_Events.h>
15 #include <ModelAPI_Session.h>
23 // the only created instance of this plugin
24 static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = new InitializationPlugin_Plugin();
26 InitializationPlugin_Plugin::InitializationPlugin_Plugin()
28 // register this plugin
29 SessionPtr aSession = ModelAPI_Session::get();
30 aSession->registerPlugin(this);
32 Events_Loop* aLoop = Events_Loop::loop();
33 const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
34 aLoop->registerListener(this, kDocCreatedEvent, NULL, true);
37 FeaturePtr InitializationPlugin_Plugin::createFeature(std::string theFeatureID)
42 void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
44 const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
45 if (theMessage->eventID() == kDocCreatedEvent) {
46 std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage =
47 std::dynamic_pointer_cast<ModelAPI_DocumentCreatedMessage>(theMessage);
48 DocumentPtr aDoc = aMessage->document();
50 createPlane(aDoc, 1., 0., 0.);
51 createPlane(aDoc, 0., 1., 0.);
52 createPlane(aDoc, 0., 0., 1.);
53 } else if (theMessage.get()) {
55 std::cout << "InitializationPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
56 << theMessage->eventID().eventText() << std::endl;
61 void InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double theA, double theB, double theC)
63 std::shared_ptr<ModelAPI_Feature> aPlane = theDoc->addFeature("Plane");
64 aPlane->string("CreationMethod")->setValue("PlaneByGeneralEquation");
65 aPlane->real("A")->setValue(theA);
66 aPlane->real("B")->setValue(theB);
67 aPlane->real("C")->setValue(theC);
68 aPlane->real("D")->setValue(0.);
71 aPlane->data()->setName("Y0Z");
73 aPlane->data()->setName("X0Z");
75 aPlane->data()->setName("X0Y");
79 void InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc)
81 std::shared_ptr<ModelAPI_Feature> aPoint = theDoc->addFeature("Point");
82 aPoint->real("x")->setValue(0.);
83 aPoint->real("y")->setValue(0.);
84 aPoint->real("z")->setValue(0.);
85 aPoint->data()->setName("Origin");