void PartSet_Module::enableCustomModes() {
myCustomPrs->enableCustomModes();
}
+
+//******************************************************
+void PartSet_Module::onConflictingConstraints()
+{
+ const std::set<ObjectPtr>& aConstraints = myOverconstraintListener->conflictingObjects();
+ if (aConstraints.size() == 1) {
+ QObjectPtrList aObjectsList;
+ std::set<ObjectPtr>::const_iterator aIt;
+ for (aIt = aConstraints.cbegin(); aIt != aConstraints.cend(); aIt++) {
+ if (mySketchReentrantMgr->isLastAutoConstraint(*aIt))
+ aObjectsList.append(*aIt);
+ }
+ if (aObjectsList.size() > 0) {
+ XGUI_Workshop* aWorkshop = getWorkshop();
+ QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
+ ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription);
+ XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
+
+ anOpMgr->startOperation(anOpAction);
+ aWorkshop->deleteFeatures(aObjectsList);
+ anOpMgr->commitOperation();
+ ModuleBase_Tools::flushUpdated(sketchMgr()->activeSketch());
+ }
+ }
+}
/// \param theTrsfType type of tranformation
virtual void onViewTransformed(int theTrsfType = 2);
+ void onConflictingConstraints();
+
protected slots:
/// Called when previous operation is finished
virtual void onSelectionChanged();
#include "SketchPlugin_SketchEntity.h"
#include "SketchPlugin_MacroArcReentrantMessage.h"
#include "SketchPlugin_Sketch.h"
+#include "SketchPlugin_ConstraintHorizontal.h"
+#include "SketchPlugin_ConstraintVertical.h"
#include "Events_Loop.h"
#include <ModuleBase_Tools.h>
#include <QString>
+#include <QTimer>
//#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
if (isUpdated)
redisplayObjects(aModifiedObjects);
+ if (myConflictingObjects.size() == 1) {
+ // If the conflicting object is an automatic constraint caused the conflict
+ // then it has to be deleted
+ ObjectPtr aObj = *theConflictingObjects.cbegin();
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature) {
+ std::string aType = aFeature->getKind();
+ if ((aType == SketchPlugin_ConstraintHorizontal::ID()) ||
+ (aType == SketchPlugin_ConstraintVertical::ID())) {
+ PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+ QTimer::singleShot(5, aModule, SLOT(onConflictingConstraints()));
+ }
+ }
+ }
+
return isUpdated;
}
ObjectPtr anObject = *anIt;
if (theConflictingObjects.find(anObject) != theConflictingObjects.end()) { // it is found
myConflictingObjects.erase(anObject);
-
aModifiedObjects.insert(anObject);
}
}
return (myConflictingObjects.find(theObject) != myConflictingObjects.end());
}
+ const std::set<ObjectPtr>& conflictingObjects() const
+ {
+ return myConflictingObjects;
+ }
+
bool isFullyConstrained() const { return myIsFullyConstrained; }
protected:
myIsFlagsBlocked(false),
myIsInternalEditOperation(false),
myNoMoreWidgetsAttribute(""),
- myIsAutoConstraints(true)
+ myIsAutoConstraints(true),
+ myLastAutoConstraint(0)
{
}
double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
FeaturePtr aFeature;
- if (aHorAngle < aTolerance)
+ if (aHorAngle < aTolerance) {
// Add horizontal constraint
aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
- else if (aVertAngle < aTolerance)
+ }
+ else if (aVertAngle < aTolerance) {
// Add vertical constraint
aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID());
-
+ }
if (aFeature.get()) {
aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(
theFeature->firstResult());
+ myLastAutoConstraint = aFeature.get();
}
}
}
+
+
+bool PartSet_SketcherReentrantMgr::isLastAutoConstraint(const ObjectPtr& theObj) const
+{
+ return theObj.get() == myLastAutoConstraint;
+}
bool isAutoConstraints() const { return myIsAutoConstraints; }
+ bool isLastAutoConstraint(const ObjectPtr& theObj) const;
+
public slots:
/// The slot is called when user checks "Automatic constraints" button
/// \param isOn a state of the check box
std::shared_ptr<GeomAPI_Pnt2d> myClickedSketchPoint; /// cashed clicked point
bool myIsAutoConstraints;
+ void* myLastAutoConstraint; //< Stores address of last automatic constraint. Connot be used as a pointer!!!
};
#endif