+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
// File: SketchSolver_ConstraintManager.cpp
// Created: 08 May 2014
// Author: Artem ZHIDKOV
#include "SketchSolver_ConstraintManager.h"
+#include <SketchSolver_ConstraintGroup.h>
#include <Events_Loop.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Attribute.h>
#include <SketchPlugin_Constraint.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Feature.h>
#include <list>
+#include <set>
+#include <memory>
// Initialization of constraint manager self pointer
SketchSolver_ConstraintManager* SketchSolver_ConstraintManager::_self = 0;
std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
if (!aFeature)
continue;
- changeConstraintOrEntity(aFeature);
+ changeConstraintOrEntity(aFeature);
}
}
// Solve the set of constraints
- resolveConstraints();
+ resolveConstraints(isMovedEvt); // send update for movement in any case
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleteMsg =
std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
if (!isUpdated) {
SketchSolver_ConstraintGroup* aNewGroup = new SketchSolver_ConstraintGroup(theSketch);
// Verify that the group is created successfully
- if (!aNewGroup->isBaseWorkplane(theSketch)) {
+ if (!aNewGroup->isBaseWorkplane(theSketch) || !aNewGroup->isWorkplaneValid()) {
delete aNewGroup;
return false;
}
if ((*aGroupIter)->getId() == aGroupId) {
// If the group is empty, the feature is not added (the constraint only)
if (!aConstraint && !(*aGroupIter)->isEmpty())
- return (*aGroupIter)->changeEntity(theFeature) != SLVS_E_UNKNOWN;
+ return (*aGroupIter)->changeEntityFeature(theFeature) != SLVS_E_UNKNOWN;
return (*aGroupIter)->changeConstraint(aConstraint);
}
} else if (aGroups.size() > 1) { // Several groups applicable for this feature => need to merge them
if (aConstraint)
return (*aFirstGroupIter)->changeConstraint(aConstraint);
- return (*aFirstGroupIter)->changeEntity(theFeature) != SLVS_E_UNKNOWN;
+ return (*aFirstGroupIter)->changeEntityFeature(theFeature) != SLVS_E_UNKNOWN;
}
// Something goes wrong
std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter;
for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
if (!(*aGroupIter)->isEmpty())
- (*aGroupIter)->updateRelatedConstraints(theFeature);
+ (*aGroupIter)->updateRelatedConstraintsFeature(theFeature);
}
// ============================================================================
// Class: SketchSolver_Session
// Purpose: search workplane containing given feature
// ============================================================================
-std::shared_ptr<ModelAPI_CompositeFeature> SketchSolver_ConstraintManager::findWorkplane(
- std::shared_ptr<SketchPlugin_Feature> theFeature) const
+std::shared_ptr<ModelAPI_CompositeFeature> SketchSolver_ConstraintManager
+::findWorkplane(std::shared_ptr<SketchPlugin_Feature> theFeature) const
{
// Already verified workplanes
std::set<std::shared_ptr<ModelAPI_CompositeFeature> > aVerified;
// Class: SketchSolver_Session
// Purpose: change entities according to available constraints
// ============================================================================
-void SketchSolver_ConstraintManager::resolveConstraints()
+void SketchSolver_ConstraintManager::resolveConstraints(const bool theForceUpdate)
{
myIsComputed = true;
bool needToUpdate = false;
+ static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ // to avoid redisplay of each segment on update by solver one by one in the viewer
+ bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
+ if (isUpdateFlushed) {
+ Events_Loop::loop()->setFlushed(anUpdateEvent, false);
+ }
+
std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter;
for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
if ((*aGroupIter)->resolveConstraints())
needToUpdate = true;
- // Features may be updated => send events
- if (needToUpdate)
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ // Features may be updated => now send events, but for all changed at once
+ if (isUpdateFlushed) {
+ Events_Loop::loop()->setFlushed(anUpdateEvent, true);
+ }
+ // Must be before flush because on "Updated" flush the results may be produced
+ // and the creation event is appeared with many new objects. If myIsComputed these
+ // events are missed in processEvents and some elements are not added.
myIsComputed = false;
+ if (needToUpdate || theForceUpdate)
+ Events_Loop::loop()->flush(anUpdateEvent);
}