Salome HOME
3e16f09155b8a0c03199f5effc8a5f7ef3db1bb8
[modules/shaper.git] / src / PartSetPlugin / PartSetPlugin_Plugin.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "PartSetPlugin_Plugin.h"
21 #include "PartSetPlugin_Part.h"
22 #include "PartSetPlugin_Duplicate.h"
23 #include "PartSetPlugin_Remove.h"
24
25 #include <Events_Loop.h>
26
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Document.h>
29
30 #ifdef _DEBUG
31 #include <iostream>
32 #endif
33
34 // the only created instance of this plugin
35 static PartSetPlugin_Plugin* MY_PARTSET_INSTANCE = new PartSetPlugin_Plugin();
36
37 PartSetPlugin_Plugin::PartSetPlugin_Plugin()
38 {
39   // register this plugin
40   ModelAPI_Session::get()->registerPlugin(this);
41 }
42
43 FeaturePtr PartSetPlugin_Plugin::createFeature(std::string theFeatureID)
44 {
45   if (theFeatureID == PartSetPlugin_Part::ID()) {
46     return FeaturePtr(new PartSetPlugin_Part);
47   }
48   if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
49     return FeaturePtr(new PartSetPlugin_Duplicate);
50   }
51   if (theFeatureID == PartSetPlugin_Remove::ID()) {
52     return FeaturePtr(new PartSetPlugin_Remove);
53   }
54   // feature of such kind is not found
55   return FeaturePtr();
56 }
57 // used only in GUI
58 //LCOV_EXCL_START
59 void PartSetPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
60 {
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()) {
66     #ifdef _DEBUG
67     std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
68               << theMessage->eventID().eventText() << std::endl;
69     #endif
70   }
71 }
72
73 std::shared_ptr<ModelAPI_FeatureStateMessage> PartSetPlugin_Plugin::getFeaturesState()
74 {
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);
84   return aMsg;
85 }
86 //LCOV_EXCL_STOP