1 // Copyright (C) 2014-2021 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PartSetPlugin_Plugin.h"
21 #include "PartSetPlugin_Part.h"
22 #include "PartSetPlugin_Duplicate.h"
23 #include "PartSetPlugin_Remove.h"
25 #include <Events_Loop.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Document.h>
34 // the only created instance of this plugin
35 static PartSetPlugin_Plugin* MY_PARTSET_INSTANCE = new PartSetPlugin_Plugin();
37 PartSetPlugin_Plugin::PartSetPlugin_Plugin()
39 // register this plugin
40 ModelAPI_Session::get()->registerPlugin(this);
43 FeaturePtr PartSetPlugin_Plugin::createFeature(std::string theFeatureID)
45 if (theFeatureID == PartSetPlugin_Part::ID()) {
46 return FeaturePtr(new PartSetPlugin_Part);
48 if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
49 return FeaturePtr(new PartSetPlugin_Duplicate);
51 if (theFeatureID == PartSetPlugin_Remove::ID()) {
52 return FeaturePtr(new PartSetPlugin_Remove);
54 // feature of such kind is not found
59 void PartSetPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
61 const Events_ID kRequestEvent =
62 Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
63 if (theMessage->eventID() == kRequestEvent) {
64 Events_Loop::loop()->send(getFeaturesState(), false);
65 } else if (theMessage.get()) {
67 std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
68 << theMessage->eventID().eventText() << std::endl;
73 std::shared_ptr<ModelAPI_FeatureStateMessage> PartSetPlugin_Plugin::getFeaturesState()
75 const Events_ID kResponseEvent =
76 Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
77 std::shared_ptr<ModelAPI_FeatureStateMessage> aMsg(
78 new ModelAPI_FeatureStateMessage(kResponseEvent, this));
79 std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
80 bool aDocIsPart = (aStdDocKind == PartSetPlugin_Part::ID());
81 aMsg->setState(PartSetPlugin_Part::ID(), true);
82 aMsg->setState(PartSetPlugin_Duplicate::ID(), aDocIsPart);
83 aMsg->setState(PartSetPlugin_Remove::ID(), aDocIsPart);