+
+void BuildPlugin_Edge::edgeByPoints()
+{
+ // Get base points.
+ AttributeSelectionPtr aFirstPointAttr = selection(FIRST_POINT());
+ AttributeSelectionPtr aSecondPointAttr = selection(SECOND_POINT());
+ if (!aFirstPointAttr.get() || !aSecondPointAttr.get()) {
+ setError("Error: Not enough points selected.");
+ return;
+ }
+
+ std::string aError;
+ GeomShapePtr aFirstShape, aSecondShape;
+ if (!getShape(aFirstPointAttr, aFirstShape, aError) ||
+ !getShape(aSecondPointAttr, aSecondShape, aError)) {
+ setError(aError);
+ return;
+ }
+ if (!aFirstShape.get() || !aSecondShape.get()) {
+ setError("Error: Empty shape selected.");
+ return;
+ }
+
+ if (!aFirstShape->isVertex() || !aSecondShape->isVertex()) {
+ setError("Error: Selected shape has wrong type. Only vertices acceptable.");
+ return;
+ }
+
+ int aResultIndex = 0;
+
+ GeomEdgePtr anEdge = GeomAlgoAPI_EdgeBuilder::line(aFirstShape->vertex()->point(),
+ aSecondShape->vertex()->point());
+ if (!anEdge.get()) {
+ setError("Error: Algorithm failed.");
+ return;
+ }
+
+ // Store result.
+ ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+ aResultBody->store(anEdge);
+ // History of vertices
+ GeomAPI_ShapeExplorer anExp(anEdge, GeomAPI_Shape::VERTEX);
+ GeomShapePtr aStartVertex = anExp.current();
+ anExp.next();
+ GeomShapePtr anEndVertex = anExp.current();
+ aResultBody->modified(aFirstShape, aStartVertex);
+ aResultBody->modified(aSecondShape, anEndVertex);
+
+ setResult(aResultBody, aResultIndex++);
+ removeResults(aResultIndex);
+}