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>
17 // the only created instance of this plugin
18 static PartSetPlugin_Plugin* MY_PARTSET_INSTANCE = new PartSetPlugin_Plugin();
20 PartSetPlugin_Plugin::PartSetPlugin_Plugin()
22 // register this plugin
23 ModelAPI_Session::get()->registerPlugin(this);
26 FeaturePtr PartSetPlugin_Plugin::createFeature(std::string theFeatureID)
28 if (theFeatureID == PartSetPlugin_Part::ID()) {
29 return FeaturePtr(new PartSetPlugin_Part);
31 if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
32 return FeaturePtr(new PartSetPlugin_Duplicate);
34 if (theFeatureID == PartSetPlugin_Remove::ID()) {
35 return FeaturePtr(new PartSetPlugin_Remove);
37 // feature of such kind is not found
41 void PartSetPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
43 const Events_ID kRequestEvent =
44 Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
45 if (theMessage->eventID() == kRequestEvent) {
46 Events_Loop::loop()->send(getFeaturesState(), false);
47 } else if (theMessage.get()) {
49 std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
50 << theMessage->eventID().eventText() << std::endl;
55 std::shared_ptr<ModelAPI_FeatureStateMessage> PartSetPlugin_Plugin::getFeaturesState()
57 const Events_ID kResponseEvent =
58 Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
59 std::shared_ptr<ModelAPI_FeatureStateMessage> aMsg(
60 new ModelAPI_FeatureStateMessage(kResponseEvent, this));
61 std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
62 bool aDocIsPart = (aStdDocKind == PartSetPlugin_Part::ID());
63 aMsg->setState(PartSetPlugin_Part::ID(), true);
64 aMsg->setState(PartSetPlugin_Duplicate::ID(), aDocIsPart);
65 aMsg->setState(PartSetPlugin_Remove::ID(), aDocIsPart);