#include "FiltersPlugin_OnPlane.h"
#include <ModelAPI_AttributeSelectionList.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Face.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Curve.h>
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Dir.h>
+
+
+#define LIN_TOLERANCE 1.e-7
bool FiltersPlugin_OnPlane::isSupported(GeomAPI_Shape::ShapeType theType) const
{
return false;
}
-bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape,
- const ModelAPI_FiltersArgs& theArgs) const
+GeomPlanePtr getPlane(AttributeSelectionPtr theAttr)
+{
+ GeomShapePtr aGeom = theAttr->value();
+ if (!aGeom.get()) { // construction plane, #2942
+ aGeom = theAttr->context()->shape();
+ }
+ GeomFacePtr aFace(new GeomAPI_Face(aGeom));
+ return aFace->getPlane();
+}
+
+bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const
{
AttributePtr aAttr = theArgs.argument("OnPlane");
AttributeSelectionListPtr aList =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
if (!aList.get())
return false;
- // ToDo
+ if (theShape->isVertex()) {
+ GeomVertexPtr aVertex(new GeomAPI_Vertex(theShape));
+ GeomPointPtr aPnt = aVertex->point();
+ for (int i = 0; i < aList->size(); i++) {
+ GeomPlanePtr aPlane = getPlane(aList->value(i));
+ if (aPlane->distance(aPnt) < LIN_TOLERANCE)
+ return true;
+ }
+ }
+ else if (theShape->isEdge()) {
+ GeomEdgePtr aEdge(new GeomAPI_Edge(theShape));
+ if (aEdge->isLine()) {
+ GeomPointPtr aPnt1 = aEdge->firstPoint();
+ GeomPointPtr aPnt2 = aEdge->lastPoint();
+ for (int i = 0; i < aList->size(); i++) {
+ GeomPlanePtr aPlane = getPlane(aList->value(i));
+ if ((aPlane->distance(aPnt1) < LIN_TOLERANCE) && (aPlane->distance(aPnt2) < LIN_TOLERANCE))
+ return true;
+ }
+ }
+ else if (aEdge->isPlanar()) {
+ for (int i = 0; i < aList->size(); i++) {
+ GeomPlanePtr aPlane = getPlane(aList->value(i));
+ if (aEdge->isInPlane(aPlane))
+ return true;
+ }
+ }
+ }
+ else if (theShape->isFace()) {
+ GeomFacePtr aFace(new GeomAPI_Face(theShape));
+ if (aFace->isPlanar()) {
+ GeomPlanePtr aPln = aFace->getPlane();
+ for (int i = 0; i < aList->size(); i++) {
+ AttributeSelectionPtr aAttr = aList->value(i);
+ GeomShapePtr aGeom = aAttr->value();
+ GeomPlanePtr aPlane = getPlane(aAttr);
+ if (aPlane->isCoincident(aPln))
+ return true;
+ }
+ }
+ }
return false;
}
-static std::string XMLRepresentation =
-"<filter id = \"OnPlane\">"
-" <multi_selector id=\"OnPlane__OnPlane\""
-" label=\"Planes:\""
-" tooltip=\"Select planes or planar faces.\""
-" type_choice=\"faces\">"
-" <validator id=\"GeomValidators_ShapeType\" parameters=\"plane\"/>"
-" </multi_selector>"
-"</filter>";
-
-
std::string FiltersPlugin_OnPlane::xmlRepresentation() const
{
- return XMLRepresentation;
+ return xmlFromFile("filter-OnPlane.xml");
}
void FiltersPlugin_OnPlane::initAttributes(ModelAPI_FiltersArgs& theArguments)