#include <ModelAPI_Validator.h>
#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pln.h>
#include <GeomAPI_Vertex.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_PointBuilder.h>
/// Attributes for axis by line.
data()->addAttribute(LINE(), ModelAPI_AttributeSelection::typeId());
+
+ /// Attributes for axis by plane and point.
+ data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
}
void ConstructionPlugin_Axis::createAxisByTwoPoints()
setResult(aConstr);
}
+void ConstructionPlugin_Axis::createAxisByPlaneAndPoint()
+{
+ // Get face.
+ AttributeSelectionPtr aFaceSelection = selection(PLANE());
+ GeomShapePtr aFaceShape = aFaceSelection->value();
+ if(!aFaceShape.get()) {
+ aFaceShape = aFaceSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aFaceShape));
+ std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
+
+ // Get point.
+ AttributeSelectionPtr aPointSelection = selection(POINT());
+ GeomShapePtr aPointShape = aPointSelection->value();
+ if(!aPointShape.get()) {
+ aPointShape = aPointSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+
+ std::shared_ptr<GeomAPI_Pnt> aProjPnt = aPln->project(aPnt);
+
+ if(aProjPnt->isEqual(aPnt)) {
+ aPnt->translate(aPln->direction(), 10);
+ }
+
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aProjPnt, aPnt);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+}
+
void ConstructionPlugin_Axis::execute()
{
AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
createAxisByDimensions();
} else if(aMethodType == CREATION_METHOD_BY_LINE()) {
createAxisByLine();
-
+ } else if(aMethodType == CREATION_METHOD_BY_PLANE_AND_POINT()) {
+ createAxisByPlaneAndPoint();
}
}
return METHOD_ATTR;
}
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_PLANE_AND_POINT()
+ {
+ static const std::string METHOD_ATTR("by_plane_and_point");
+ return METHOD_ATTR;
+ }
+
/// attribute name for first point
inline static const std::string& POINT_FIRST()
{
return ATTR_ID;
}
+ /// Attribute name for plane.
+ inline static const std::string& PLANE()
+ {
+ static const std::string ATTR_ID("plane");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for point.
+ inline static const std::string& POINT()
+ {
+ static const std::string ATTR_ID("point");
+ return ATTR_ID;
+ }
+
/// Returns a minimal length for axis
inline static const double MINIMAL_LENGTH() { return 1.e-5; }
/// Creates a new axis by point and direction
void createAxisByPointAndDirection();
void createAxisByLine();
+ void createAxisByPlaneAndPoint();
};
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
</box>
+ <box id="by_plane_and_point" title="By plane and point" icon="icons/Construction/axis_by_plane_and_point_32x32.png">
+ <shape_selector id="plane"
+ label="Plane"
+ tooltip="Select a planar face."
+ icon="icons/Construction/face.png"
+ shape_types="face">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </shape_selector>
+ <shape_selector id="point"
+ label="Point"
+ tooltip="Select point."
+ icon="icons/Construction/point.png"
+ shape_types="vertex">
+ </shape_selector>
+ </box>
</toolbox>
</source>