Updated validators for arc.
return true;
}
+//==================================================================================================
+bool GeomAlgoAPI_ShapeTools::isShapesIntersects(
+ const std::shared_ptr<GeomAPI_Shape> theShape1,
+ const std::shared_ptr<GeomAPI_Shape> theShape2)
+{
+ if(!theShape1.get() || !theShape2.get()) {
+ return false;
+ }
+
+ const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
+
+ BRepExtrema_DistShapeShape aDist(aShape1, aShape2);
+ aDist.Perform();
+ if(aDist.IsDone() && aDist.Value() < Precision::Confusion()) {
+ return true;
+ }
+
+ return false;
+}
+
//==================================================================================================
bool GeomAlgoAPI_ShapeTools::isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape)
{
const std::shared_ptr<GeomAPI_Shape> theSubShape,
const std::shared_ptr<GeomAPI_Shape> theBaseShape);
+ /// \brief Checks that shapes intersects.
+ /// \param[in] theShape1 first shape.
+ /// \param[in] theShape2 second shape.
+ /// \return true if shapes intersects.
+ GEOMALGOAPI_EXPORT static bool GeomAlgoAPI_ShapeTools::isShapesIntersects(
+ const std::shared_ptr<GeomAPI_Shape> theShape1,
+ const std::shared_ptr<GeomAPI_Shape> theShape2);
+
/// \return true if theShape is valid.
GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
data()->blockSendAttributeUpdated(aWasBlocked, false);
}
-AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
+GeomShapePtr SketchPlugin_MacroArc::getArcShape()
{
if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
- return AISObjectPtr();
+ return GeomShapePtr();
}
SketchPlugin_Sketch* aSketch = sketch();
if(!aSketch) {
- return AISObjectPtr();
+ return GeomShapePtr();
}
- std::shared_ptr<GeomAPI_Pnt> aStart = aSketch->to3D(myStart->x(), myStart->y());
- std::shared_ptr<GeomAPI_Pnt> anEnd = aSketch->to3D(myEnd->x(), myEnd->y());
- std::shared_ptr<GeomAPI_Pnt> aCenter = aSketch->to3D(myCenter->x(), myCenter->y());;
-
+ std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(myCenter->x(), myCenter->y()));
+ std::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(myStart->x(), myStart->y()));
+ std::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(myEnd->x(), myEnd->y()));
std::shared_ptr<GeomDataAPI_Dir> aNDir =
- std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+ std::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->attribute(SketchPlugin_Sketch::NORM_ID()));
+ std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
+
GeomShapePtr anArcShape = boolean(REVERSED_ID())->value() ?
GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal)
: GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal);
+
+ return anArcShape;
+}
+
+AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
+{
+ if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
+ return AISObjectPtr();
+ }
+
+ SketchPlugin_Sketch* aSketch = sketch();
+ if(!aSketch) {
+ return AISObjectPtr();
+ }
+
+ GeomShapePtr anArcShape = getArcShape();
+ std::shared_ptr<GeomAPI_Pnt> aCenter = aSketch->to3D(myCenter->x(), myCenter->y());;
GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
if(!anArcShape.get() || !aCenterPointShape.get()) {
/// Use plugin manager for features creation.
SketchPlugin_MacroArc();
+ /// Returns shape of arc.
+ GeomShapePtr getArcShape();
+
private:
/// Set fields for center, start and end points
void fillByCenterAndTwoPassed();
new SketchPlugin_CirclePassedPointValidator);
aFactory->registerValidator("SketchPlugin_ThirdPointValidator",
new SketchPlugin_ThirdPointValidator);
+ aFactory->registerValidator("SketchPlugin_ArcEndPointValidator",
+ new SketchPlugin_ArcEndPointValidator);
+ aFactory->registerValidator("SketchPlugin_ArcEndPointIntersectionValidator",
+ new SketchPlugin_ArcEndPointIntersectionValidator);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
#include <ModelGeomAlgo_Point2D.h>
#include <ModelGeomAlgo_Shape.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
#include <GeomAPI_Circ.h>
#include <GeomAPI_Dir2d.h>
#include <GeomAPI_Lin.h>
theError = aErrorPointsApart;
return isOk;
}
+
+bool SketchPlugin_ArcEndPointValidator::isValid(
+ const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ AttributeRefAttrPtr anEndPointRef = aFeature->refattr(theArguments.front());
+
+ if(!anEndPointRef.get()) {
+ return true;
+ }
+
+ if(!anEndPointRef->isInitialized()) {
+ return true;
+ }
+
+ if(anEndPointRef->attr().get()) {
+ return false;
+ }
+
+ ObjectPtr anObject = anEndPointRef->object();
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if(aResult.get()) {
+ GeomShapePtr aShape = aResult->shape();
+ if(aShape.get() && aShape->isVertex()) {
+ return false;
+ }
+ }
+
+ aFeature = ModelAPI_Feature::feature(anObject);
+ if(aFeature.get()) {
+ if(aFeature->getKind() == SketchPlugin_Point::ID()) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
+ const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ std::shared_ptr<SketchPlugin_MacroArc> anArcFeature =
+ std::dynamic_pointer_cast<SketchPlugin_MacroArc>(theAttribute->owner());
+ AttributeRefAttrPtr anEndPointRef = anArcFeature->refattr(theArguments.front());
+
+ if(!anEndPointRef.get()) {
+ return true;
+ }
+
+ if(!anEndPointRef->isInitialized()) {
+ return true;
+ }
+
+ GeomShapePtr anArcShape = anArcFeature->getArcShape();
+
+ if(!anArcShape.get() || anArcShape->isNull()) {
+ return true;
+ }
+
+ ObjectPtr anObject = anEndPointRef->object();
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if(aResult.get()) {
+ GeomShapePtr aShape = aResult->shape();
+ if(aShape.get() && !aShape->isNull()) {
+ return GeomAlgoAPI_ShapeTools::isShapesIntersects(anArcShape, aShape);
+ }
+ }
+
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(anObject);
+ if(aSelectedFeature.get()) {
+ std::list<ResultPtr> aResults = aSelectedFeature->results();
+ for(std::list<ResultPtr>::const_iterator anIt = aResults.cbegin();
+ anIt != aResults.cend();
+ ++anIt)
+ {
+ GeomShapePtr aShape = (*anIt)->shape();
+ if(aShape.get() && !aShape->isNull()) {
+ if(GeomAlgoAPI_ShapeTools::isShapesIntersects(anArcShape, aShape)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+}
Events_InfoMessage& theError) const;
};
+/**\class SketchPlugin_ArcEndPointValidator
+ * \ingroup Validators
+ * \brief Validator for the end point of MacroArc feature.
+ *
+ * Checks that third point does not lie on a point.
+ */
+class SketchPlugin_ArcEndPointValidator: public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ //! \param theError error message
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
+/**\class SketchPlugin_ArcEndPointIntersectionValidator
+ * \ingroup Validators
+ * \brief Validator for the end point of MacroArc feature.
+ *
+ * Checks that third point does lie on edge which intersects arc.
+ */
+class SketchPlugin_ArcEndPointIntersectionValidator: public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ //! \param theError error message
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
#endif
title="End point"
tooltip="End point"
accept_expressions="0"
- enable_value="enable_by_preferences"/>
+ enable_value="enable_by_preferences">
+ <validator id="SketchPlugin_ArcEndPointValidator" parameters="end_point_ref"/>
+ <validator id="SketchPlugin_ArcEndPointIntersectionValidator" parameters="end_point_ref"/>
+ </sketch-2dpoint_selector>
<validator id="GeomValidators_Different" parameters="center_point,start_point_1,end_point_1"/>
</box>
<box id="by_three_points"
accept_expressions="0"
enable_value="enable_by_preferences">
<validator id="SketchPlugin_DifferentReference" parameters="start_point_ref,end_point_ref"/>
+ <validator id="SketchPlugin_ArcEndPointValidator" parameters="end_point_ref"/>
</sketch-2dpoint_selector>
<sketch-2dpoint_selector id="passed_point"
reference_attribute="passed_point_ref"
title="End point"
tooltip="End point"
accept_expressions="0"
- enable_value="enable_by_preferences"/>
+ enable_value="enable_by_preferences">
+ <validator id="SketchPlugin_ArcEndPointValidator" parameters="end_point_ref"/>
+ </sketch-2dpoint_selector>
</box>
</toolbox>
<labelvalue id="radius"