1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSetPlugin_Plugin.h"
4 #include "PartSetPlugin_Part.h"
5 #include "PartSetPlugin_Duplicate.h"
6 #include "PartSetPlugin_Remove.h"
8 #include <Events_Loop.h>
10 #include <ModelAPI_Session.h>
11 #include <ModelAPI_Document.h>
19 // the only created instance of this plugin
20 static PartSetPlugin_Plugin* MY_PARTSET_INSTANCE = new PartSetPlugin_Plugin();
22 PartSetPlugin_Plugin::PartSetPlugin_Plugin()
24 // register this plugin
25 ModelAPI_Session::get()->registerPlugin(this);
28 FeaturePtr PartSetPlugin_Plugin::createFeature(string theFeatureID)
30 if (theFeatureID == PartSetPlugin_Part::ID()) {
31 return FeaturePtr(new PartSetPlugin_Part);
33 if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
34 return FeaturePtr(new PartSetPlugin_Duplicate);
36 if (theFeatureID == PartSetPlugin_Remove::ID()) {
37 return FeaturePtr(new PartSetPlugin_Remove);
39 // feature of such kind is not found
43 void PartSetPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
45 const Events_ID kRequestEvent =
46 Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
47 if (theMessage->eventID() == kRequestEvent) {
48 Events_Loop::loop()->send(getFeaturesState(), false);
49 } else if (theMessage.get()) {
51 std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
52 << theMessage->eventID().eventText() << std::endl;
57 std::shared_ptr<ModelAPI_FeatureStateMessage> PartSetPlugin_Plugin::getFeaturesState()
59 const Events_ID kResponseEvent =
60 Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
61 std::shared_ptr<ModelAPI_FeatureStateMessage> aMsg =
62 std::make_shared<ModelAPI_FeatureStateMessage>(kResponseEvent, this);
63 std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
64 bool aDocIsPart = (aStdDocKind == PartSetPlugin_Part::ID());
65 aMsg->setState(PartSetPlugin_Part::ID(), true);
66 aMsg->setState(PartSetPlugin_Duplicate::ID(), aDocIsPart);
67 aMsg->setState(PartSetPlugin_Remove::ID(), aDocIsPart);