X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FInitializationPlugin%2FInitializationPlugin_Plugin.cpp;h=c71d8f767d143d3cb01995937782b7718d769093;hb=d570a46bdbeb5b2279f04a4746de7da413f0b0a6;hp=fce2a1a2d8df17ee50abaf0649ec92396b485464;hpb=8579a62492b5e8227d9e256cc9754a31442c05ed;p=modules%2Fshaper.git diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp index fce2a1a2d..c71d8f767 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp @@ -1,87 +1,186 @@ - -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-2017 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 +#include #include #include +#include #include #include +#include +#include +#include +#include #include - -#include -#include +#include #include -#ifdef _DEBUG -#include -#endif - // the only created instance of this plugin -static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = new InitializationPlugin_Plugin(); +static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = + new InitializationPlugin_Plugin(); InitializationPlugin_Plugin::InitializationPlugin_Plugin() { - // register this plugin - SessionPtr aSession = ModelAPI_Session::get(); - aSession->registerPlugin(this); - Events_Loop* aLoop = Events_Loop::loop(); const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); aLoop->registerListener(this, kDocCreatedEvent, NULL, true); -} -FeaturePtr InitializationPlugin_Plugin::createFeature(std::string theFeatureID) -{ - return FeaturePtr(); + myEvalListener = + std::shared_ptr(new InitializationPlugin_EvalListener()); } void InitializationPlugin_Plugin::processEvent(const std::shared_ptr& theMessage) { const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); if (theMessage->eventID() == kDocCreatedEvent) { - std::shared_ptr aMessage = - std::dynamic_pointer_cast(theMessage); + std::shared_ptr aMessage = std::dynamic_pointer_cast< + ModelAPI_DocumentCreatedMessage>(theMessage); DocumentPtr aDoc = aMessage->document(); - createPoint(aDoc); - createPlane(aDoc, 1., 0., 0.); - createPlane(aDoc, 0., 1., 0.); - createPlane(aDoc, 0., 0., 1.); - } else if (theMessage.get()) { - #ifdef _DEBUG - std::cout << "InitializationPlugin_Plugin::processEvent: unhandled message caught: " << std::endl - << theMessage->eventID().eventText() << std::endl; - #endif + + /// Issue 431: for the current moment create planes only in the module document, + /// Later if it is needed we may create special initial planes in Parts (may be different) + if (aDoc != ModelAPI_Session::get()->moduleDocument()) + return; + + std::list aFeatures; + + // the viewer update should be blocked in order to avoid the features blinking before they are + // hidden + std::shared_ptr aMsg = std::shared_ptr( + new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED))); + Events_Loop::loop()->send(aMsg); + + FeaturePtr aOrigin = createPoint(aDoc, "Origin", 0., 0., 0.); + aFeatures.push_back(aOrigin); + aFeatures.push_back(createAxis(aDoc, aOrigin, 100., 0., 0.)); + aFeatures.push_back(createAxis(aDoc, aOrigin, 0., 100., 0.)); + aFeatures.push_back(createAxis(aDoc, aOrigin, 0., 0., 100.)); + aFeatures.push_back(createPlane(aDoc, 1., 0., 0.)); + aFeatures.push_back(createPlane(aDoc, 0., -1., 0.)); + aFeatures.push_back(createPlane(aDoc, 0., 0., 1.)); + // for PartSet it is done outside of the transaction, so explicitly flush this creation + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); + + // hides the created features, the precondition is that the feature's results have been + // already built, so the createPlane/Points method calls the execute function for the planes + std::list::const_iterator aFIter = aFeatures.begin(); + for (; aFIter != aFeatures.cend(); aFIter++) { + FeaturePtr aPlane = *aFIter; + const std::list >& aResults = aPlane->results(); + std::list::const_iterator aRIter = aResults.begin(); + for (; aRIter != aResults.cend(); aRIter++) { + (*aRIter)->setDisplayed(false); + } + } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + // the viewer update should be unblocked in order to avoid the features blinking before they are + // hidden + aMsg = std::shared_ptr( + new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED))); + + Events_Loop::loop()->send(aMsg); } } -void InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double theA, double theB, double theC) +FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double theX, double theY, + double theZ) { - std::shared_ptr aPlane = theDoc->addFeature("Plane"); - aPlane->string("CreationMethod")->setValue("PlaneByGeneralEquation"); - aPlane->real("A")->setValue(theA); - aPlane->real("B")->setValue(theB); - aPlane->real("C")->setValue(theC); + FeaturePtr aPlane = theDoc->addFeature("Plane"); + aPlane->string("creation_method")->setValue("by_general_equation"); + aPlane->real("A")->setValue(theX); + aPlane->real("B")->setValue(theY); + aPlane->real("C")->setValue(theZ); aPlane->real("D")->setValue(0.); - if (theA) { - aPlane->data()->setName("Y0Z"); - } else if (theB) { - aPlane->data()->setName("X0Z"); - } else if (theC) { - aPlane->data()->setName("X0Y"); + if (theX) { + aPlane->data()->setName("YOZ"); + } else if (theY) { + aPlane->data()->setName("XOZ"); + } else if (theZ) { + aPlane->data()->setName("XOY"); } + // don't show automatically created feature in the features history + aPlane->setInHistory(aPlane, false); + + // the plane should be executed in order to build the feature result immediatelly + // the results are to be hidden in the plugin + aPlane->execute(); + // this flag is needed here to avoid setting it inside of the next transaction + // (may cause crash on redo of the first transaction in OCAF) + aPlane->data()->execState(ModelAPI_StateDone); + aPlane->firstResult()->data()->execState(ModelAPI_StateDone); + + return aPlane; } -void InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc) +FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const std::string& theName, + double theX, double theY, double theZ) { std::shared_ptr aPoint = theDoc->addFeature("Point"); - aPoint->real("x")->setValue(0.); - aPoint->real("y")->setValue(0.); - aPoint->real("z")->setValue(0.); - aPoint->data()->setName("Origin"); + AttributePointPtr aPointAttr = std::dynamic_pointer_cast + (aPoint->data()->attribute("point3d")); + aPointAttr->setValue(theX, theY, theZ); + aPoint->string("creation_method")->setValue("by_xyz"); + aPoint->data()->setName(theName); + // don't show automatically created feature in the features history + aPoint->setInHistory(aPoint, false); + + // the point should be executed in order to build the feature result immediatelly + // the results are to be hidden in the plugin + aPoint->execute(); + aPoint->data()->execState(ModelAPI_StateDone); + aPoint->firstResult()->data()->execState(ModelAPI_StateDone); + + return aPoint; } +FeaturePtr InitializationPlugin_Plugin::createAxis(DocumentPtr theDoc, FeaturePtr theOrigin, + double theX, double theY, double theZ) +{ + std::shared_ptr aAxis = theDoc->addFeature("Axis"); + aAxis->string("CreationMethod")->setValue("AxisByPointAndDirection"); + + ResultPtr aResult = theOrigin->firstResult(); + aAxis->selection("FirstPoint")->setValue(aResult, aResult->shape()); + + aAxis->real("X_Direction")->setValue(theX); + aAxis->real("Y_Direction")->setValue(theY); + aAxis->real("Z_Direction")->setValue(theZ); + + if (theX != 0) { + aAxis->data()->setName("OX"); + } else if (theY != 0) { + aAxis->data()->setName("OY"); + } else if (theZ != 0) { + aAxis->data()->setName("OZ"); + } + // don't show automatically created feature in the features history + aAxis->setInHistory(aAxis, false); + aAxis->execute(); + aAxis->data()->execState(ModelAPI_StateDone); + aAxis->firstResult()->data()->execState(ModelAPI_StateDone); + + return aAxis; +}