+ GeomShapePtr aShape1 = aRef1->value();
+ if (!aShape1.get())
+ aShape1 = aRef1->context()->shape();
+ GeomShapePtr aShape2 = aRef2->value();
+ if (!aShape2.get())
+ aShape2 = aRef2->context()->shape();
+ if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) {
+ std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
+ std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
+ if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
+ }
+ }
+}
+
+
+void ConstructionPlugin_Axis::createAxisByPointAndDirection()
+{
+ AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
+ AttributeDoublePtr aXAttr = data()->real(ConstructionPlugin_Axis::X_DIRECTION());
+ AttributeDoublePtr aYAttr = data()->real(ConstructionPlugin_Axis::Y_DIRECTION());
+ AttributeDoublePtr aZAttr = data()->real(ConstructionPlugin_Axis::Z_DIRECTION());
+ if ((aRef1.get() != NULL) && (aXAttr.get() != NULL) &&
+ (aYAttr.get() != NULL) && (aZAttr.get() != NULL)) {
+ GeomShapePtr aShape1 = aRef1->value();
+ if (!aShape1.get())
+ aShape1 = aRef1->context()->shape();
+
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aXAttr->value(),
+ aYAttr->value(),
+ aZAttr->value()));
+ if (aShape1->isVertex() &&
+ (fabs(aXAttr->value()) > MINIMAL_LENGTH() ||
+ fabs(aYAttr->value()) > MINIMAL_LENGTH() ||
+ fabs(aZAttr->value()) > MINIMAL_LENGTH())) {
+ std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
+ std::shared_ptr<GeomAPI_Pnt> anEnd(new GeomAPI_Pnt(aStart->x() + aXAttr->value(),
+ aStart->y() + aYAttr->value(),
+ aStart->z() + aZAttr->value()));
+
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
+ }
+}
+
+
+void ConstructionPlugin_Axis::createAxisByCylindricalFace()
+{
+ std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
+ // update arguments due to the selection value
+
+ if (!aSelection.get() || aSelection->isNull()) {
+ return;
+ }
+
+ if (aSelection->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aSelection);
+ aSelection = anIt.current();
+ }
+
+ if (aSelection->isFace()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
+}
+
+void ConstructionPlugin_Axis::createAxisByDimensions()
+{
+ // Start by getting these dimensions
+ double aDX = data()->real(DX())->value();
+ double aDY = data()->real(DY())->value();
+ double aDZ = data()->real(DZ())->value();
+
+ if (fabs(aDX) < MINIMAL_LENGTH() && fabs(aDY) < MINIMAL_LENGTH() &&
+ fabs(aDZ) < MINIMAL_LENGTH()) {
+ setError("Axis builder with dimensions :: all dimensions are null", false);
+ return ;
+ }
+
+ // Make the axis, build the ResultConstructionPtr and write it
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aDX, aDY, aDZ);
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+}
+
+void ConstructionPlugin_Axis::createAxisByLine()
+{
+ // Get edge.
+ AttributeSelectionPtr anEdgeSelection = selection(LINE());
+ GeomShapePtr aLineShape = anEdgeSelection->value();
+ if(!aLineShape.get()) {
+ aLineShape = anEdgeSelection->context()->shape();
+ }
+ GeomEdgePtr anEdge;
+ if (aLineShape->isEdge()) {
+ anEdge = aLineShape->edge();
+ }
+ else if (aLineShape->isCompound()) {
+ // create an edge which covers all edges from compounds (they are on the same line)
+ GeomPointPtr aFirst, aLast;
+ GeomXYZPtr aLineVec;
+ for(GeomAPI_ShapeIterator anIt(aLineShape); anIt.more(); anIt.next()) {
+ GeomEdgePtr aSub = anIt.current()->edge();
+ if (aSub.get() && aSub->isLine()) {
+ if (!aLineVec.get()) {
+ aFirst = aSub->firstPoint();
+ aLast = aSub->lastPoint();
+ } else { // set aFirst and aLast by extreme points
+ GeomXYZPtr aFirstVec = aSub->firstPoint()->xyz()->decreased(aFirst->xyz());
+ bool aSameDirection =
+ aSub->lastPoint()->xyz()->decreased(aSub->firstPoint()->xyz())->dot(aLineVec) > 0;
+ if (aLineVec->dot(aFirstVec) < -1.e-7) { // first point is changed
+ aFirst = aSameDirection ? aSub->firstPoint() : aSub->lastPoint();
+ } else { // last point is changed
+ aLast = aSameDirection ? aSub->lastPoint() : aSub->firstPoint();
+ }