X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSetPlugin%2FPartSetPlugin_Plugin.cpp;h=9527146ef5e2e979333fd05807aa2c582ff20778;hb=a211165b993cec59888b300199b44b525c0daf69;hp=76ea7b441c0f6ae5375b48bdb1ed5c4bc498ddcc;hpb=04e52dd31f27fb0004f97fa8ef4e275d4c1b962b;p=modules%2Fshaper.git diff --git a/src/PartSetPlugin/PartSetPlugin_Plugin.cpp b/src/PartSetPlugin/PartSetPlugin_Plugin.cpp index 76ea7b441..9527146ef 100644 --- a/src/PartSetPlugin/PartSetPlugin_Plugin.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Plugin.cpp @@ -1,32 +1,86 @@ +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + #include "PartSetPlugin_Plugin.h" #include "PartSetPlugin_Part.h" #include "PartSetPlugin_Duplicate.h" #include "PartSetPlugin_Remove.h" -#include + +#include + +#include #include -using namespace std; +#ifdef _DEBUG +#include +#endif // the only created instance of this plugin -static PartSetPlugin_Plugin* MY_INSTANCE = new PartSetPlugin_Plugin(); +static PartSetPlugin_Plugin* MY_PARTSET_INSTANCE = new PartSetPlugin_Plugin(); -PartSetPlugin_Plugin::PartSetPlugin_Plugin() +PartSetPlugin_Plugin::PartSetPlugin_Plugin() { // register this plugin - ModelAPI_PluginManager::get()->registerPlugin(this); + ModelAPI_Session::get()->registerPlugin(this); } -boost::shared_ptr PartSetPlugin_Plugin::createFeature(string theFeatureID) +FeaturePtr PartSetPlugin_Plugin::createFeature(std::string theFeatureID) { - if (theFeatureID == "Part") { - return boost::shared_ptr(new PartSetPlugin_Part); + if (theFeatureID == PartSetPlugin_Part::ID()) { + return FeaturePtr(new PartSetPlugin_Part); } - if (theFeatureID == "duplicate") { - return boost::shared_ptr(new PartSetPlugin_Duplicate); + if (theFeatureID == PartSetPlugin_Duplicate::ID()) { + return FeaturePtr(new PartSetPlugin_Duplicate); } - if (theFeatureID == "remove") { - return boost::shared_ptr(new PartSetPlugin_Remove); + if (theFeatureID == PartSetPlugin_Remove::ID()) { + return FeaturePtr(new PartSetPlugin_Remove); } - // feature of such kind is not found - return boost::shared_ptr(); + // feature of such kind is not found + return FeaturePtr(); +} +// used only in GUI +//LCOV_EXCL_START +void PartSetPlugin_Plugin::processEvent(const std::shared_ptr& theMessage) +{ + const Events_ID kRequestEvent = + Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST); + if (theMessage->eventID() == kRequestEvent) { + Events_Loop::loop()->send(getFeaturesState(), false); + } else if (theMessage.get()) { + #ifdef _DEBUG + std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl + << theMessage->eventID().eventText() << std::endl; + #endif + } +} + +std::shared_ptr PartSetPlugin_Plugin::getFeaturesState() +{ + const Events_ID kResponseEvent = + Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE); + std::shared_ptr aMsg( + new ModelAPI_FeatureStateMessage(kResponseEvent, this)); + std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind(); + bool aDocIsPart = (aStdDocKind == PartSetPlugin_Part::ID()); + aMsg->setState(PartSetPlugin_Part::ID(), true); + aMsg->setState(PartSetPlugin_Duplicate::ID(), aDocIsPart); + aMsg->setState(PartSetPlugin_Remove::ID(), aDocIsPart); + return aMsg; } +//LCOV_EXCL_STOP