+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByCoincidentPoint()
+{
+ // Get face.
+ AttributeSelectionPtr aFaceSelection = selection(PLANE());
+ GeomShapePtr aFaceShape = aFaceSelection->value();
+ if(!aFaceShape.get()) {
+ aFaceShape = aFaceSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace;
+ if (aFaceShape->isFace()) {
+ aFace = aFaceShape->face();
+ }
+ else if (aFaceShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape);
+ aFace = anIt.current()->face();
+ }
+
+ // Get point.
+ AttributeSelectionPtr aPointSelection = selection(COINCIDENT_POINT());
+ GeomShapePtr aPointShape = aPointSelection->value();
+ if(!aPointShape.get()) {
+ aPointShape = aPointSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex = aPointShape->vertex();
+ if (!aVertex)
+ return GeomShapePtr();
+
+ std::shared_ptr<GeomAPI_Pnt> anOrig = aVertex->point();
+ std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
+ std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
+
+ std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(anOrig, aDir));
+
+ return makeRectangularFace(aFace, aNewPln);
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByRotation()
+{
+ // Get face.
+ AttributeSelectionPtr aFaceSelection = selection(PLANE());
+ GeomShapePtr aFaceShape = aFaceSelection->value();
+ if(!aFaceShape.get()) {
+ aFaceShape = aFaceSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace;
+ if (aFaceShape->isFace()) {
+ aFace = aFaceShape->face();
+ }
+ else if (aFaceShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape);
+ aFace = anIt.current()->face();
+ }
+ if (!aFace)
+ return GeomShapePtr();
+ aFace = makeRectangularFace(aFace, aFace->getPlane());
+
+ // Get axis.
+ AttributeSelectionPtr anAxisSelection = selection(AXIS());
+ GeomShapePtr anAxisShape = anAxisSelection->value();
+ if(!anAxisShape.get()) {
+ anAxisShape = anAxisSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Edge> anEdge;
+ if (anAxisShape->isEdge()) {
+ anEdge = anAxisShape->edge();
+ }
+ else if (anAxisShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(anAxisShape);
+ anEdge = anIt.current()->edge();
+ }
+ if (!anEdge)
+ return GeomShapePtr();
+
+ std::shared_ptr<GeomAPI_Ax1> anAxis =
+ std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
+
+ // Getting angle.
+ double anAngle = real(ANGLE())->value();
+
+ std::shared_ptr<GeomAlgoAPI_Rotation> aRotationAlgo(
+ new GeomAlgoAPI_Rotation(aFace, anAxis, anAngle));
+ // Checking that the algorithm worked properly.
+ std::string anError;
+ if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationAlgo, getKind(), anError)) {
+ setError("Error: Failed to rotate plane");
+ return GeomShapePtr();
+ }
+
+ std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face(aRotationAlgo->shape()));
+ return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByTwoParallelPlanes()
+{
+ // Get plane 1.
+ AttributeSelectionPtr aFaceSelection1 = selection(PLANE1());
+ GeomShapePtr aFaceShape1 = aFaceSelection1->value();
+ if(!aFaceShape1.get()) {
+ aFaceShape1 = aFaceSelection1->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace1;
+ if (aFaceShape1->isFace()) {
+ aFace1 = aFaceShape1->face();
+ }
+ else if (aFaceShape1->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape1);
+ aFace1 = anIt.current()->face();
+ }
+ if (!aFace1)
+ return GeomShapePtr();
+ std::shared_ptr<GeomAPI_Pln> aPln1 = aFace1->getPlane();
+
+ // Get plane 2.
+ AttributeSelectionPtr aFaceSelection2 = selection(PLANE2());
+ GeomShapePtr aFaceShape2 = aFaceSelection2->value();
+ if(!aFaceShape2.get()) {
+ aFaceShape2 = aFaceSelection2->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace2;
+ if (aFaceShape2->isFace()) {
+ aFace2 = aFaceShape2->face();
+ }
+ else if (aFaceShape2->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape2);
+ aFace2 = anIt.current()->face();
+ }
+ if (!aFace2)
+ return GeomShapePtr();
+ std::shared_ptr<GeomAPI_Pln> aPln2 = aFace2->getPlane();
+
+ std::shared_ptr<GeomAPI_Pnt> anOrig1 = aPln1->location();
+ std::shared_ptr<GeomAPI_Pnt> aPntOnPln2 = aPln2->project(anOrig1);
+
+ std::shared_ptr<GeomAPI_Pnt> aNewOrig(new GeomAPI_Pnt(anOrig1->xyz()->added(
+ aPntOnPln2->xyz())->multiplied(0.5)));
+
+ std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(aNewOrig, aPln1->direction()));
+
+ std::shared_ptr<GeomAPI_Face> aRes = makeRectangularFace(aFace1, aNewPln);
+
+ return aRes;
+}
+