Salome HOME
Put groups to the separated plugin: Collection
[modules/shaper.git] / src / PartSetPlugin / PartSetPlugin_Plugin.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "PartSetPlugin_Plugin.h"
4 #include "PartSetPlugin_Part.h"
5 #include "PartSetPlugin_Duplicate.h"
6 #include "PartSetPlugin_Remove.h"
7
8 #include <Events_Loop.h>
9
10 #include <ModelAPI_Session.h>
11 #include <ModelAPI_Document.h>
12
13 #ifdef _DEBUG
14 #include <iostream>
15 #endif
16
17 // the only created instance of this plugin
18 static PartSetPlugin_Plugin* MY_PARTSET_INSTANCE = new PartSetPlugin_Plugin();
19
20 PartSetPlugin_Plugin::PartSetPlugin_Plugin()
21 {
22   // register this plugin
23   ModelAPI_Session::get()->registerPlugin(this);
24 }
25
26 FeaturePtr PartSetPlugin_Plugin::createFeature(std::string theFeatureID)
27 {
28   if (theFeatureID == PartSetPlugin_Part::ID()) {
29     return FeaturePtr(new PartSetPlugin_Part);
30   }
31   if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
32     return FeaturePtr(new PartSetPlugin_Duplicate);
33   }
34   if (theFeatureID == PartSetPlugin_Remove::ID()) {
35     return FeaturePtr(new PartSetPlugin_Remove);
36   }
37   // feature of such kind is not found
38   return FeaturePtr();
39 }
40
41 void PartSetPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
42 {
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()) {
48     #ifdef _DEBUG
49     std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
50               << theMessage->eventID().eventText() << std::endl;
51     #endif
52   }
53 }
54
55 std::shared_ptr<ModelAPI_FeatureStateMessage> PartSetPlugin_Plugin::getFeaturesState()
56 {
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);
66   return aMsg;
67 }