X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FInitializationPlugin%2FInitializationPlugin_Plugin.cpp;h=fcd5bd56b19cf11b2c01b2b13704aea950d3c892;hb=06e7f5859095193fc7f498bd89a7d28009794f53;hp=5d4781494052ee0537e05832c291c8482f9b5397;hpb=b3695c3af5289903f1c0fa01bbb7c40203c5e544;p=modules%2Fshaper.git diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp index 5d4781494..fcd5bd56b 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include @@ -30,8 +29,11 @@ #include #include +#include + #include #include +#include #include @@ -39,11 +41,17 @@ static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = new InitializationPlugin_Plugin(); -InitializationPlugin_Plugin::InitializationPlugin_Plugin() +InitializationPlugin_Plugin::InitializationPlugin_Plugin() : + myCreatePartOnStart(false) // by default in TUI mode part is not created on start of PartSet { + char* isUnitTest = getenv("SHAPER_UNIT_TEST_IN_PROGRESS"); + myInitDataModel = (!isUnitTest || isUnitTest[0] != '1'); + Events_Loop* aLoop = Events_Loop::loop(); - const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); + static const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); aLoop->registerListener(this, kDocCreatedEvent, NULL, true); + static const Events_ID kCreatePartEvent = Events_Loop::eventByName(EVENT_CREATE_PART_ON_START); + aLoop->registerListener(this, kCreatePartEvent, NULL, true); myEvalListener = std::shared_ptr(new InitializationPlugin_EvalListener()); @@ -51,7 +59,8 @@ InitializationPlugin_Plugin::InitializationPlugin_Plugin() void InitializationPlugin_Plugin::processEvent(const std::shared_ptr& theMessage) { - const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); + static const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); + static const Events_ID kCreatePartEvent = Events_Loop::eventByName(EVENT_CREATE_PART_ON_START); if (theMessage->eventID() == kDocCreatedEvent) { std::shared_ptr aMessage = std::dynamic_pointer_cast< ModelAPI_DocumentCreatedMessage>(theMessage); @@ -59,10 +68,15 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptrmoduleDocument()) + SessionPtr aMgr = ModelAPI_Session::get(); + if (aDoc != aMgr->moduleDocument() || aMgr->isLoading()) return; + if (myInitDataModel) + myEvalListener->initDataModel(); + std::list aFeatures; + aMgr->startOperation("Initialization"); // the viewer update should be blocked in order to avoid the features blinking before they are // hidden @@ -70,7 +84,7 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptrsend(aMsg); - FeaturePtr aOrigin = createPoint(aDoc, "Origin", 0., 0., 0.); + FeaturePtr aOrigin = createPoint(aDoc, L"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.)); @@ -78,6 +92,8 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptrflush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); @@ -93,13 +109,21 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptrflush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); - // the viewer update should be unblocked in order to avoid the features blinking before they are - // hidden + + aMgr->finishOperation(); // before last message flush to update the title, make it not-modified + aMgr->clearUndoRedo(); // to forbid undo of auxiliary elements and initial part + + // the viewer update should be unblocked 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); } + else if (theMessage->eventID() == kCreatePartEvent) + { + std::shared_ptr aMsg = std::dynamic_pointer_cast(theMessage); + myCreatePartOnStart = aMsg->value(); + } } FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double theX, double theY, @@ -113,11 +137,11 @@ FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double t aPlane->real("D")->setValue(0.); if (theX) { - aPlane->data()->setName("YOZ"); + aPlane->data()->setName(L"YOZ"); } else if (theY) { - aPlane->data()->setName("XOZ"); + aPlane->data()->setName(L"XOZ"); } else if (theZ) { - aPlane->data()->setName("XOY"); + aPlane->data()->setName(L"XOY"); } // don't show automatically created feature in the features history aPlane->setInHistory(aPlane, false); @@ -133,14 +157,13 @@ FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double t return aPlane; } -FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const std::string& theName, +FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const std::wstring& theName, double theX, double theY, double theZ) { std::shared_ptr aPoint = theDoc->addFeature("Point"); - //aPoint->string("creation_method")->setValue("by_xyz"); - aPoint->real("x")->setValue(theX); - aPoint->real("y")->setValue(theY); - aPoint->real("z")->setValue(theZ); + 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 @@ -169,11 +192,11 @@ FeaturePtr InitializationPlugin_Plugin::createAxis(DocumentPtr theDoc, FeaturePt aAxis->real("Z_Direction")->setValue(theZ); if (theX != 0) { - aAxis->data()->setName("OX"); + aAxis->data()->setName(L"OX"); } else if (theY != 0) { - aAxis->data()->setName("OY"); + aAxis->data()->setName(L"OY"); } else if (theZ != 0) { - aAxis->data()->setName("OZ"); + aAxis->data()->setName(L"OZ"); } // don't show automatically created feature in the features history aAxis->setInHistory(aAxis, false); @@ -183,3 +206,10 @@ FeaturePtr InitializationPlugin_Plugin::createAxis(DocumentPtr theDoc, FeaturePt return aAxis; } + +void InitializationPlugin_Plugin::createPart(DocumentPtr thePartSet) +{ + std::shared_ptr aPart = thePartSet->addFeature("Part"); + if (aPart.get()) + aPart->execute(); // to initialize and activate this part document +}