+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();
+ }
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ 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(), defaultAxisSize);
+ }
+
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aPnt, aProjPnt);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+}
+
+void ConstructionPlugin_Axis::createAxisByTwoPlanes()
+{
+ // Get face 1.
+ AttributeSelectionPtr aFaceSelection1 = selection(PLANE1());
+ GeomShapePtr aFaceShape1 = aFaceSelection1->value();
+ if(!aFaceShape1.get()) {
+ aFaceShape1 = aFaceSelection1->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace1(new GeomAPI_Face(aFaceShape1));
+ std::shared_ptr<GeomAPI_Pln> aPln1 = aFace1->getPlane();
+
+ std::string useOffset1 = string(USE_OFFSET1())->value();
+ if(!useOffset1.empty()) {
+ double anOffset1 = real(OFFSET1())->value();
+ bool reverseOffset1 = boolean(REVERSE_OFFSET1())->value();
+ if(reverseOffset1) {
+ anOffset1 = -anOffset1;
+ }
+ aPln1->translate(aPln1->direction(), anOffset1);
+ }
+
+ // Get face 2.
+ AttributeSelectionPtr aFaceSelection2 = selection(PLANE2());
+ GeomShapePtr aFaceShape2 = aFaceSelection2->value();
+ if(!aFaceShape2.get()) {
+ aFaceShape2 = aFaceSelection2->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace2(new GeomAPI_Face(aFaceShape2));
+ std::shared_ptr<GeomAPI_Pln> aPln2 = aFace2->getPlane();
+
+ std::string useOffset2 = string(USE_OFFSET2())->value();
+ if(!useOffset2.empty()) {
+ double anOffset2 = real(OFFSET2())->value();
+ bool reverseOffset2 = boolean(REVERSE_OFFSET2())->value();
+ if(reverseOffset2) {
+ anOffset2 = -anOffset2;
+ }
+ aPln2->translate(aPln2->direction(), anOffset2);
+ }
+
+ std::shared_ptr<GeomAPI_Lin> aLin = aPln1->intersect(aPln2);
+ std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLin->location();
+ std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLin->location();
+ aPnt2->translate(aLin->direction(), defaultAxisSize);
+
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aPnt1, aPnt2);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+}
+