- AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
- AttributePtr aAR = aRAttr->attr();
- if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc
- aCoinList.insert(aConstrFeature);
- }
- }
- // if there is no coincidence then it is not valid
- if (aCoinList.size() == 0)
- return false;
-
- // find that coincedence is the same
- const std::set<std::shared_ptr<ModelAPI_Attribute>>& aOtherList = aOtherFea->data()->refsToMe();
- std::set<FeaturePtr>::const_iterator aCoinsIt;
- for (aIt = aOtherList.cbegin(); aIt != aOtherList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
- aCoinsIt = aCoinList.find(aConstrFeature);
- if (aCoinsIt != aCoinList.end()) {
- AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
- AttributePtr aAR = aRAttr->attr();
- if (aAR->id() != SketchPlugin_Arc::CENTER_ID())
+ AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
+ AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
+ if(anAttrRefA.get() && !anAttrRefA->isObject()) {
+ AttributePtr anAttrA = anAttrRefA->attr();
+ if(aPointAttribute == anAttrA) {
+ aConstraintCoincidence = aConstrFeature;
+ break;
+ }
+ }
+ if(anAttrRefB.get() && !anAttrRefB->isObject()) {
+ AttributePtr anAttrB = anAttrRefB->attr();
+ if(aPointAttribute == anAttrB) {
+ aConstraintCoincidence = aConstrFeature;
+ break;
+ }
+ }
+ }
+ }
+
+ if(!aConstraintCoincidence.get()) {
+ theError = "Error: one of the selected point does not have coicidence.";
+ return false;
+ }
+
+ // Get coincides from constraint.
+ std::set<FeaturePtr> aCoinsides;
+ SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
+ SketchPlugin_ConstraintCoincidence::ENTITY_A(),
+ aCoinsides);
+ SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B(),
+ aCoinsides);
+
+ // Remove points from set of coincides.
+ std::set<FeaturePtr> aNewSetOfCoincides;
+ for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
+ if((*anIt)->getKind() != SketchPlugin_Line::ID() &&
+ (*anIt)->getKind() != SketchPlugin_Arc::ID()) {
+ continue;
+ }
+ if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
+ AttributePtr anArcCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
+ std::shared_ptr<GeomAPI_Pnt2d> anArcCenterPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcCenter)->pnt();
+ double aDistSelectedArcCenter = aSelectedPnt->distance(anArcCenterPnt);
+ if(aDistSelectedArcCenter < tolerance) {
+ continue;
+ }
+ }
+ aNewSetOfCoincides.insert(*anIt);
+ }
+ aCoinsides = aNewSetOfCoincides;
+
+ // If we still have more than two coincides remove auxilary entities from set of coincides.
+ if(aCoinsides.size() > 2) {
+ aNewSetOfCoincides.clear();
+ for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
+ if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
+ aNewSetOfCoincides.insert(*anIt);
+ }
+ }
+ aCoinsides = aNewSetOfCoincides;
+ }
+
+ if(aCoinsides.size() != 2) {
+ theError = "Error: One of the selected points does not have two suitable edges for fillet.";
+ return false;
+ }
+
+ // Check that selected edges don't have tangent constraint.
+ std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
+ FeaturePtr aFirstFeature = *anIt++;
+ FeaturePtr aSecondFeature = *anIt;
+ const std::set<AttributePtr>& aFirstFeatureRefsList = aFirstFeature->data()->refsToMe();
+ if(hasSameTangentFeature(aFirstFeatureRefsList, aSecondFeature)) {
+ theError = "Error: Edges in selected point has tangent constraint.";
+ return false;
+ }
+
+ std::list<ResultPtr> aFirstResults = aFirstFeature->results();
+ for(std::list<ResultPtr>::iterator aResIt = aFirstResults.begin(); aResIt != aFirstResults.end(); ++aResIt) {
+ ResultPtr aRes = *aResIt;
+ const std::set<AttributePtr>& aResRefsList = aRes->data()->refsToMe();
+ if(hasSameTangentFeature(aResRefsList, aSecondFeature)) {
+ theError = "Error: Edges in selected point has tangent constraint.";
+ return false;
+ }
+ }
+
+ // Check that lines not collinear
+ if(aFirstFeature->getKind() == SketchPlugin_Line::ID() && aSecondFeature->getKind() == SketchPlugin_Line::ID()) {
+ std::string aStartAttr = SketchPlugin_Line::START_ID();
+ std::string anEndAttr = SketchPlugin_Line::END_ID();
+ std::shared_ptr<GeomAPI_Pnt2d> aFirstStartPnt, aFirstEndPnt, aSecondStartPnt, aSecondEndPnt;
+ aFirstStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(aStartAttr))->pnt();
+ aFirstEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(anEndAttr))->pnt();
+ aSecondStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(aStartAttr))->pnt();
+ aSecondEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(anEndAttr))->pnt();
+ double aCheck1 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
+ (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
+ double aCheck2 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
+ (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
+ if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+ theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+ return false;
+ }
+
+ // there is a check whether the feature contains a point and a linear edge or two point values
+ std::string aParamA = theArguments.front();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+ FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ AttributeRefAttrPtr anOtherAttr = anAttributeFeature->data()->refattr(aParamA);
+
+ AttributeRefAttrPtr aRefAttrs[2] = {aRefAttr, anOtherAttr};
+ int aNbPoints = 0;
+ int aNbLines = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (!aRefAttrs[i]->isObject())
+ ++aNbPoints;
+ else {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrs[i]->object());
+ if (!aFeature) {
+ if (aNbPoints + aNbLines != 0)