X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OverconstraintListener.cpp;h=640af398ae868f252f563d34e61c89562c30fe6b;hb=ac6c4b849218e6f1a45c0a21e46c5fda401c38f0;hp=fa20c54908f0f3bc9a5404fd4f5a52af9393662d;hpb=0bbc862db48081f4ff407177716e6fb8c16e930f;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index fa20c5490..640af398a 100755 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -1,27 +1,48 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: SketcherPrs_Angle.cpp -// Created: 20 August 2015 -// Author: Vitaly SMETANNIKOV +// 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 "PartSet_OverconstraintListener.h" #include #include +#include +#include "XGUI_CustomPrs.h" +#include "XGUI_Displayer.h" #include "XGUI_ModuleConnector.h" +#include "XGUI_OperationMgr.h" +#include "XGUI_Tools.h" #include "XGUI_Workshop.h" -#include "XGUI_Displayer.h" -#include "XGUI_CustomPrs.h" #include "SketcherPrs_SymbolPrs.h" #include "SketchPlugin_SketchEntity.h" +#include "SketchPlugin_MacroArcReentrantMessage.h" +#include "SketchPlugin_Sketch.h" #include "Events_Loop.h" #include #include +#include #include #include @@ -29,7 +50,7 @@ //#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop) -: myWorkshop(theWorkshop) +: myWorkshop(theWorkshop), myIsActive(false), myIsFullyConstrained(false) { Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED)); @@ -37,41 +58,64 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED)); + + aLoop->registerListener(this, ModelAPI_EventReentrantMessage::eventId()); + aLoop->registerListener(this, SketchPlugin_MacroArcReentrantMessage::eventId()); +} + +void PartSet_OverconstraintListener::setActive(const bool& theActive) +{ + if (myIsActive == theActive) + return; + + myIsActive = theActive; + myIsFullyConstrained = false; /// returned to default state, no custom color for it + + if (myIsActive) { + PartSet_Module* aModule = module(); + CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch(); + if (aSketch.get()) { + std::string aDOFMessage = aSketch->string(SketchPlugin_Sketch::SOLVER_DOF())->value(); + myIsFullyConstrained = QString(aDOFMessage.c_str()).contains("DoF = 0"); + } + } } -bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject, +void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject, std::vector& theColor) { + if (!myIsActive) + return; + + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + std::string aFeatureName = aFeature->data()->name(); + if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) { - Quantity_Color aColor = ModuleBase_Tools::color("Visualization", - "sketch_overconstraint_color"); - theColor.push_back(aColor.Red()*255.); - theColor.push_back(aColor.Green()*255.); - theColor.push_back(aColor.Blue()*255.); - return true; + theColor = Config_PropManager::color("Visualization", "sketch_overconstraint_color"); } if (myIsFullyConstrained) { FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get()) { - PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); - CompositeFeaturePtr aCompositeFeature = aModule->sketchMgr()->activeSketch(); + // only entity features has custom color when sketch is fully constrained + if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind()) && + !PartSet_SketcherMgr::isExternalFeature(aFeature)) { + PartSet_Module* aModule = module(); + CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch(); // the given object is sub feature of the current sketch(created or edited) - if (ModelAPI_Tools::compositeOwner(aFeature) == aCompositeFeature) { - Quantity_Color aColor = ModuleBase_Tools::color("Visualization", - "sketch_fully_constrained_color"); - theColor.push_back(aColor.Red()*255.); - theColor.push_back(aColor.Green()*255.); - theColor.push_back(aColor.Blue()*255.); - return true; - } + if (ModelAPI_Tools::compositeOwner(aFeature) == aSketch) + theColor = Config_PropManager::color("Visualization", "sketch_fully_constrained_color"); } } - return false; } void PartSet_OverconstraintListener::processEvent( const std::shared_ptr& theMessage) { + // #2271 open document: if sketch has confilcting elements, solver sends message with the + // elements by opening the document. Sketch is not active, but an internal container should + // be updated. So, we should not check whether the listener is active here + //if (!myIsActive) + // return; + #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER bool isRepaired = theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED); int aCount = 0; @@ -110,7 +154,61 @@ void PartSet_OverconstraintListener::processEvent( } else if (anEventID == Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED) || anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED)) { + bool aPrevFullyConstrained = myIsFullyConstrained; myIsFullyConstrained = anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED); + + if (aPrevFullyConstrained != myIsFullyConstrained) { + std::set aModifiedObjects; + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch(); + if (aSketch.get()) { + for (int i = 0; i < aSketch->numberOfSubs(); i++) { + FeaturePtr aFeature = aSketch->subFeature(i); + aModifiedObjects.insert(aFeature); // is necessary to redisplay presentations + std::list aResults = aFeature->results(); + for (std::list::const_iterator aIt = aResults.begin(); + aIt != aResults.end(); ++aIt) { + aModifiedObjects.insert(*aIt); + } + } + redisplayObjects(aModifiedObjects); + } + } + } + else if (anEventID == ModelAPI_EventReentrantMessage::eventId() || + anEventID == SketchPlugin_MacroArcReentrantMessage::eventId()) { + // the message is sent to sketcher reentrant manager only if the name of feature + // sender is equal to feature name of the current operation. E.g. Horizontal create operation + // is active. Sketch Line feature is changed, so execute is called, it will send message + // This Line's message should not be processed, as the reentrant operation is not for Line + // It is not enoght of kind, the name should be used, e.g. restarted Lines on auxiliary + // cirlce sometimes causes previous line change, kind the same, but feature line is different + std::string aCurrentFeatureName; + ModuleBase_Operation* anOperation = + XGUI_Tools::workshop(myWorkshop)->operationMgr()->currentOperation(); + if (anOperation) { + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (anOperation); + if (aFOperation) { + FeaturePtr aFeature = aFOperation->feature(); + // data valid is necessary if the feature has been already deleted + // (e.g. Esc of Lenght if lenght value is modified) + if (aFeature.get() && aFeature->data()->isValid()) + aCurrentFeatureName = aFeature->data()->name(); + } + } + if (theMessage->sender()) { + ModelAPI_Object* aSender = static_cast(theMessage->sender()); + if (aSender) { + FeaturePtr aFeatureSender = + std::dynamic_pointer_cast(aSender->data()->owner()); + if (aFeatureSender.get() && aFeatureSender->data()->name() == aCurrentFeatureName) { + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + PartSet_SketcherReentrantMgr* aReentrantMgr = aModule->sketchReentranceMgr(); + aReentrantMgr->setReentrantMessage(theMessage); + } + } + } } #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER @@ -124,8 +222,6 @@ bool PartSet_OverconstraintListener::appendConflictingObjects( const std::set& theConflictingObjects) { std::set aModifiedObjects; - //std::vector aColor; - //getConflictingColor(aColor); // set error state for new objects and append them in the internal map of objects std::set::const_iterator @@ -181,10 +277,9 @@ void PartSet_OverconstraintListener::redisplayObjects( aLoop->flush(EVENT_DISP); } -XGUI_Workshop* PartSet_OverconstraintListener::workshop() const +PartSet_Module* PartSet_OverconstraintListener::module() const { - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - return aConnector->workshop(); + return dynamic_cast(myWorkshop->module()); } #ifdef _DEBUG