#include "SketchPlugin_ConstraintTangent.h"
#include "SketchPlugin_ConstraintRadius.h"
#include "SketchPlugin_Tools.h"
+#include "SketchPlugin_Validators.h"
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeInteger.h>
#include <GeomDataAPI_Point2D.h>
#include <Events_Loop.h>
+#include <Events_InfoMessage.h>
#include <math.h>
if (!aFilletPoint2D.get())
return false;
- std::set<AttributePoint2DPtr> aCoincidentPoints =
- SketchPlugin_Tools::findPointsCoincidentToPoint(aFilletPoint2D);
- std::set<FeaturePtr> aFilletFeatures;
- for (std::set<AttributePoint2DPtr>::iterator aCPIt = aCoincidentPoints.begin();
- aCPIt != aCoincidentPoints.end(); ++aCPIt) {
- std::shared_ptr<SketchPlugin_Feature> anOwner =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(
- ModelAPI_Feature::feature((*aCPIt)->owner()));
- if (anOwner && !anOwner->isExternal())
- aFilletFeatures.insert(anOwner);
- }
- // remove auxilary entities from set of coincident features
- if (aFilletFeatures.size() > 2) {
- std::set<FeaturePtr>::iterator anIt = aFilletFeatures.begin();
- while (anIt != aFilletFeatures.end()) {
- if ((*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
- std::set<FeaturePtr>::iterator aRemoveIt = anIt++;
- aFilletFeatures.erase(aRemoveIt);
- }
- else
- ++anIt;
- }
- }
- if (aFilletFeatures.size() != 2) {
- setError("Error: Selected point does not have two suitable edges for fillet.");
+ Events_InfoMessage anError;
+ FeaturePtr anEdge1, anEdge2;
+ if (!SketchPlugin_FilletVertexValidator::isValidVertex
+ (aPointRefAttr, anError, anEdge1, anEdge2)) {
+ setError(anError.messageString());
return false;
}
-
- std::set<FeaturePtr>::iterator aFIt = aFilletFeatures.begin();
- myBaseFeatures[0] = *aFIt;
- myBaseFeatures[1] = *(++aFIt);
+ myBaseFeatures[0] = anEdge1;
+ myBaseFeatures[1] = anEdge2;
std::shared_ptr<GeomAPI_Pnt2d> aFilletPnt2d = aFilletPoint2D->pnt();
double aRadius = calculateFilletRadius(myBaseFeatures);
bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
Events_InfoMessage& theError) const
+{
+ FeaturePtr anEdge1, anEdge2;
+ return isValidVertex(theAttribute, theError, anEdge1, anEdge2);
+}
+
+bool SketchPlugin_FilletVertexValidator::isValidVertex(const AttributePtr& theAttribute,
+ Events_InfoMessage& theError,
+ FeaturePtr& theEdge1,
+ FeaturePtr& theEdge2)
{
AttributeRefAttrPtr aPointRefAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
// Get coincides from constraint.
std::set<FeaturePtr> aCoinsides;
SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
- SketchPlugin_ConstraintCoincidence::ENTITY_A(),
- aCoinsides,
- true);
+ SketchPlugin_ConstraintCoincidence::ENTITY_A(),
+ aCoinsides,
+ true);
SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
- SketchPlugin_ConstraintCoincidence::ENTITY_B(),
- aCoinsides,
- true);
+ SketchPlugin_ConstraintCoincidence::ENTITY_B(),
+ aCoinsides,
+ true);
// Remove points and external lines from set of coincides.
std::set<FeaturePtr> aNewSetOfCoincides;
return false;
}
+ // output edges
+ std::set<FeaturePtr>::iterator aFIt = aCoinsides.begin();
+ theEdge1 = *aFIt;
+ theEdge2 = *(++aFIt);
+
// Check that selected edges don't have tangent constraint.
std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
FeaturePtr aFirstFeature = *anIt++;
virtual bool isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
Events_InfoMessage& theError) const;
+
+ //! returns true if attribute is a good point for fillet
+ //! \param theAttribute the checked point attribute
+ //! \param theError error message
+ //! \param theEdge1 adjacent edge feature
+ //! \param theEdge2 adjacent edge feature
+ static bool isValidVertex(const AttributePtr& theAttribute,
+ Events_InfoMessage& theError,
+ FeaturePtr& theEdge1,
+ FeaturePtr& theEdge2);
};