]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSetPlugin/PartSetPlugin_Plugin.cpp
Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[modules/shaper.git] / src / PartSetPlugin / PartSetPlugin_Plugin.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "PartSetPlugin_Plugin.h"
22 #include "PartSetPlugin_Part.h"
23 #include "PartSetPlugin_Duplicate.h"
24 #include "PartSetPlugin_Remove.h"
25
26 #include <Events_Loop.h>
27
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Document.h>
30
31 #ifdef _DEBUG
32 #include <iostream>
33 #endif
34
35 // the only created instance of this plugin
36 static PartSetPlugin_Plugin* MY_PARTSET_INSTANCE = new PartSetPlugin_Plugin();
37
38 PartSetPlugin_Plugin::PartSetPlugin_Plugin()
39 {
40   // register this plugin
41   ModelAPI_Session::get()->registerPlugin(this);
42 }
43
44 FeaturePtr PartSetPlugin_Plugin::createFeature(std::string theFeatureID)
45 {
46   if (theFeatureID == PartSetPlugin_Part::ID()) {
47     return FeaturePtr(new PartSetPlugin_Part);
48   }
49   if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
50     return FeaturePtr(new PartSetPlugin_Duplicate);
51   }
52   if (theFeatureID == PartSetPlugin_Remove::ID()) {
53     return FeaturePtr(new PartSetPlugin_Remove);
54   }
55   // feature of such kind is not found
56   return FeaturePtr();
57 }
58 // used only in GUI
59 //LCOV_EXCL_START
60 void PartSetPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
61 {
62   const Events_ID kRequestEvent =
63       Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
64   if (theMessage->eventID() == kRequestEvent) {
65     Events_Loop::loop()->send(getFeaturesState(), false);
66   } else if (theMessage.get()) {
67     #ifdef _DEBUG
68     std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
69               << theMessage->eventID().eventText() << std::endl;
70     #endif
71   }
72 }
73
74 std::shared_ptr<ModelAPI_FeatureStateMessage> PartSetPlugin_Plugin::getFeaturesState()
75 {
76   const Events_ID kResponseEvent =
77         Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
78   std::shared_ptr<ModelAPI_FeatureStateMessage> aMsg(
79       new ModelAPI_FeatureStateMessage(kResponseEvent, this));
80   std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
81   bool aDocIsPart = (aStdDocKind == PartSetPlugin_Part::ID());
82   aMsg->setState(PartSetPlugin_Part::ID(), true);
83   aMsg->setState(PartSetPlugin_Duplicate::ID(), aDocIsPart);
84   aMsg->setState(PartSetPlugin_Remove::ID(), aDocIsPart);
85   return aMsg;
86 }
87 //LCOV_EXCL_STOP