// Find coincident in these coordinates
ObjectPtr aObj = aPrsList.first().object();
FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
- const std::set<AttributePtr>& aRefsList = aFeature->data()->refsToMe();
- std::set<AttributePtr>::const_iterator aIt;
- FeaturePtr aCoincident;
- for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
- if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- std::shared_ptr<GeomAPI_Pnt2d> a2dPnt =
- PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
- if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) {
- aCoincident = aConstrFeature;
- break;
- } else {
- a2dPnt = PartSet_Tools::getPoint(aConstrFeature,
- SketchPlugin_ConstraintCoincidence::ENTITY_B());
- if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) {
- aCoincident = aConstrFeature;
- break;
- }
- }
- }
- }
+ FeaturePtr aCoincident = PartSet_Tools::findFirstCoincidence(aFeature, aSelPnt);
// If we have coincidence then add Detach menu
if (aCoincident.get() != NULL) {
mySelectedFeature = aCoincident;
return std::shared_ptr<GeomAPI_Pnt2d>();
}
+FeaturePtr PartSet_Tools::findFirstCoincidence(const FeaturePtr& theFeature,
+ std::shared_ptr<GeomAPI_Pnt2d> thePoint)
+{
+ FeaturePtr aCoincident;
+
+ const std::set<AttributePtr>& aRefsList = theFeature->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aIt;
+ for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+ std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+ FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+ std::shared_ptr<GeomAPI_Pnt2d> a2dPnt =
+ PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ if (a2dPnt.get() && thePoint->isEqual(a2dPnt)) {
+ aCoincident = aConstrFeature;
+ break;
+ } else {
+ a2dPnt = PartSet_Tools::getPoint(aConstrFeature,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ if (a2dPnt.get() && thePoint->isEqual(a2dPnt)) {
+ aCoincident = aConstrFeature;
+ break;
+ }
+ }
+ }
+ }
+ return aCoincident;
+}
+
void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
std::string theAttr)
{
static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::string& theAttribute);
+ /**
+ * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
+ * and compare the point value to be equal with the given. Returns the first feature, which has
+ * equal points.
+ * \return the coincidence feature or null
+ */
+ static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
+ std::shared_ptr<GeomAPI_Pnt2d> thePoint);
+
/**
* Returns list of features connected in a councedence feature point
* \param theStartCoin the coincidence feature
else {
if (getPoint2d(aView, aShape, aX, aY))
setPoint(aX, aY);
+ bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch);
setConstraintWith(aObject);
- emit vertexSelected();
+ if (!anOrphanPoint)
+ emit vertexSelected();
emit focusOutWidget(this);
}
}
setPoint(aX, aY);
}
else {
+ bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch);
// do not set a coincidence constraint in the attribute if the feature contains a point
// with the same coordinates. It is important for line creation in order to do not set
// the same constraints for the same points, oterwise the result line has zero length.
// points of the line becomes less than the tolerance. Validator of the line returns
// false, the line will be aborted, but sketch stays valid.
updateObject(feature());
- emit vertexSelected();
+ if (!anOrphanPoint)
+ emit vertexSelected();
emit focusOutWidget(this);
}
}
}
return isModified;
}
+
+bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
+ const CompositeFeaturePtr& theSketch)
+{
+ bool anOrphanPoint = false;
+ if (theFeature.get()) {
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+ std::string aFeatureKind = theFeature->getKind();
+ if (aFeatureKind == SketchPlugin_Point::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(SketchPlugin_Point::COORD_ID()));
+ else if (aFeatureKind == SketchPlugin_Circle::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
+
+ else if (aFeatureKind == SketchPlugin_Arc::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
+
+ if (aPointAttr.get()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
+ FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint);
+ anOrphanPoint = true;
+ // if there is at least one concident line to the point, the point is not an orphant
+ if (aCoincidence.get()) {
+ QList<FeaturePtr> aCoinsideLines;
+ PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
+ SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
+ aLast = aCoinsideLines.end();
+ for (; anIt != aLast && anOrphanPoint; anIt++) {
+ anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
+ }
+ }
+ }
+ }
+ return anOrphanPoint;
+}
/// \theObject a result object
void setConstraintWith(const ObjectPtr& theObject);
+ /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
+ /// has no a coincident to other lines. In Circle and arc only center points are processed.
+ /// \param theFeature a checked feature
+ /// \param theSketch a sketch
+ /// \return boolean result
+ static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch);
+
protected:
ModuleBase_IWorkshop* myWorkshop; ///< workshop