// Author: Vitaly SMETANNIKOV
#include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeString.h>
#include "PartSet_OverconstraintListener.h"
#include <PartSet_Module.h>
#include "SketcherPrs_SymbolPrs.h"
#include "SketchPlugin_SketchEntity.h"
#include "SketchPlugin_MacroArcReentrantMessage.h"
+#include "SketchPlugin_Sketch.h"
#include "Events_Loop.h"
//#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop)
-: myWorkshop(theWorkshop), myIsFullyConstrained(false)
+: myWorkshop(theWorkshop), myIsActive(false), myIsFullyConstrained(false)
{
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED));
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");
+ }
+ }
+}
+
void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
std::vector<int>& theColor)
{
+ if (!myIsActive)
+ return;
+
if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) {
theColor = Config_PropManager::color("Visualization", "sketch_overconstraint_color");
}
FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
// only entity features has custom color when sketch is fully constrained
if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
- PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
- CompositeFeaturePtr aCompositeFeature = aModule->sketchMgr()->activeSketch();
+ 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)
+ if (ModelAPI_Tools::compositeOwner(aFeature) == aSketch)
theColor = Config_PropManager::color("Visualization", "sketch_fully_constrained_color");
}
}
void PartSet_OverconstraintListener::processEvent(
const std::shared_ptr<Events_Message>& theMessage)
{
+ if (!myIsActive)
+ return;
+
#ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
bool isRepaired = theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED);
int aCount = 0;
aLoop->flush(EVENT_DISP);
}
-XGUI_Workshop* PartSet_OverconstraintListener::workshop() const
+PartSet_Module* PartSet_OverconstraintListener::module() const
{
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- return aConnector->workshop();
+ return dynamic_cast<PartSet_Module*>(myWorkshop->module());
}
#ifdef _DEBUG
#include <ModelAPI_Object.h>
class ModuleBase_IWorkshop;
-class XGUI_Workshop;
+class PartSet_Module;
#include <QString>
virtual ~PartSet_OverconstraintListener() {};
- // Set erroneous color for the presentation of object if the object is in the conflicting list
- // \param theObject an object to be settled
- // \param theUpdateViewer a boolean state whether the current viewer should be updated
- //bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);
+ /// If active state is changed, update fully defined state and sketch sub-entities color
+ /// \param theActive a state
+ void setActive(const bool& theActive);
/// Returns true if the object belongs to internal container of conflicting objects
/// \param theObject an object to be checked
void redisplayObjects(const std::set<ObjectPtr>& theObjects);
private:
- /// Returns workshop
- XGUI_Workshop* workshop() const;
+ /// Returns module
+ PartSet_Module* module() const;
#ifdef _DEBUG
/// Unite objects in one string information
#endif
private:
- std::set<ObjectPtr> myConflictingObjects;
ModuleBase_IWorkshop* myWorkshop;
+ bool myIsActive; /// state if sketch is active
+ std::set<ObjectPtr> myConflictingObjects;
bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0
};