-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020 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
#include <cmath>
-#define DEBUG_TRIM
#ifdef DEBUG_TRIM
#include <iostream>
#endif
static const double PI = 3.141592653589793238463;
-static const std::string OPERATION_HIGHLIGHT_COLOR() { return "128, 0, 0"; }
-static const std::string OPERATION_REMOVE_FEATURE_COLOR() { return "255, 174, 201"; }
-
SketchPlugin_Trim::SketchPlugin_Trim()
{
}
{
if (aRefIt->first->isEqual(aPoint)) {
anInfo = aRefIt->second;
- break;
+ // prefer a segment instead of a point, because further coincidence with a segment
+ // decreases only 1 DoF (instead of 2 for point) and prevents an overconstraint situation.
+ bool isEdge = false;
+ for (std::list<ObjectPtr>::const_iterator anIt = anInfo.second.begin();
+ anIt != anInfo.second.end() && !isEdge; ++anIt) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(*anIt);
+ if (aResult) {
+ GeomShapePtr aShape = aResult->shape();
+ isEdge = aShape && aShape->isEdge();
+ }
+ }
+ if (isEdge)
+ break;
}
}
const std::list<ObjectPtr>& anObjects = anInfo.second;
const std::set<AttributePtr>& aRefs = aBaseFeature->data()->refsToMe();
std::list<AttributePtr> aRefsToParent;
for (std::set<AttributePtr>::const_iterator aRef = aRefs.begin(); aRef != aRefs.end(); ++aRef) {
- if ((*aRef)->id() == SketchPlugin_Line::PARENT_ID() ||
- (*aRef)->id() == SketchPlugin_Point::PARENT_ID())
+ if ((*aRef)->id() == SketchPlugin_SketchEntity::PARENT_ID())
aRefsToParent.push_back(*aRef);
}
for (std::list<AttributePtr>::iterator aRef = aRefsToParent.begin();
- aRef != aRefsToParent.end(); ++aRef)
+ aRef != aRefsToParent.end(); ++aRef) {
std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*aRef)->setValue(anNewFeature);
+
+ FeaturePtr anOwner = ModelAPI_Feature::feature((*aRef)->owner());
+ SketchPlugin_Tools::replaceInName(anOwner, aBaseFeature->name(), anNewFeature->name());
+ SketchPlugin_Tools::replaceInName(anOwner->lastResult(),
+ aBaseFeature->name(), anNewFeature->name());
+ }
}
const std::string& aStartAttrName = anNewFeature->getKind() == SketchPlugin_Arc::ID() ?