]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSetPlugin/PartSetPlugin_Plugin.cpp
Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[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 using namespace std;
18
19 // the only created instance of this plugin
20 static PartSetPlugin_Plugin* MY_PARTSET_INSTANCE = new PartSetPlugin_Plugin();
21
22 PartSetPlugin_Plugin::PartSetPlugin_Plugin()
23 {
24   // register this plugin
25   ModelAPI_Session::get()->registerPlugin(this);
26 }
27
28 FeaturePtr PartSetPlugin_Plugin::createFeature(string theFeatureID)
29 {
30   if (theFeatureID == PartSetPlugin_Part::ID()) {
31     return FeaturePtr(new PartSetPlugin_Part);
32   }
33   if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
34     return FeaturePtr(new PartSetPlugin_Duplicate);
35   }
36   if (theFeatureID == PartSetPlugin_Remove::ID()) {
37     return FeaturePtr(new PartSetPlugin_Remove);
38   }
39   // feature of such kind is not found
40   return FeaturePtr();
41 }
42
43 void PartSetPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
44 {
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()) {
50     #ifdef _DEBUG
51     std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
52               << theMessage->eventID().eventText() << std::endl;
53     #endif
54   }
55 }
56
57 std::shared_ptr<ModelAPI_FeatureStateMessage> PartSetPlugin_Plugin::getFeaturesState()
58 {
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);
68   return aMsg;
69 }