#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Trsf.h>
#include <GeomAlgoAPI_PointBuilder.h>
}
//Getting axis.
- std::shared_ptr<GeomAPI_Ax1> anAxis;
- std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
- selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
- if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ AttributeSelectionPtr anObjRef = selection(AXIS_OBJECT_ID());
+ GeomShapePtr aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
+ }
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
+ }
+
+ GeomEdgePtr anEdge;
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
}
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
- anEdge->line()->direction()));
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
}
+ std::shared_ptr<GeomAPI_Ax1> anAxis(new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
+
+
// Getting distance.
double aDistance = real(FeaturesPlugin_Translation::DISTANCE_ID())->value();