+ GeomShapePtr aShape;
+
+ std::string aCreationMethod = string(CREATION_METHOD())->value();
+ if(aCreationMethod == CREATION_METHOD_BY_GENERAL_EQUATION() ||
+ aCreationMethod == "PlaneByGeneralEquation") {
+ aShape = createByGeneralEquation();
+ } else if(aCreationMethod == CREATION_METHOD_BY_THREE_POINTS()) {
+ aShape = createByThreePoints();
+ } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_POINT()) {
+ aShape = createByLineAndPoint();
+ } else if(aCreationMethod == CREATION_METHOD_BY_OTHER_PLANE()) {
+ std::string aCreationMethodOption = string(CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
+ if(aCreationMethodOption == CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
+ aShape = createByDistanceFromOther();
+ } else if(aCreationMethodOption == CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
+ aShape = createByCoincidentPoint();
+ } else if(aCreationMethodOption == CREATION_METHOD_BY_ROTATION()) {
+ aShape = createByRotation();
+ }
+ } else if(aCreationMethod == CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
+ aShape = createByTwoParallelPlanes();
+ } else {
+ setError("Error: Plane creation method \"" + aCreationMethod + "\" not supported.");
+ return;
+ }
+
+ if(!aShape.get()) {
+ setError("Error: Could not create a plane.");
+ return;
+ }
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(aShape);
+ setResult(aConstr);
+}
+
+//==================================================================================================
+bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+{
+ std::vector<int> aColor;
+ // get color from the attribute of the result
+ if (theResult.get() != NULL &&
+ theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+ AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() && aColorAttr->size()) {
+ aColor.push_back(aColorAttr->value(0));
+ aColor.push_back(aColorAttr->value(1));
+ aColor.push_back(aColorAttr->value(2));
+ }
+ }
+ if (aColor.empty())
+ aColor = Config_PropManager::color("Visualization", "construction_plane_color");
+
+ bool isCustomized = false;
+ if (aColor.size() == 3)
+ isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+ isCustomized = thePrs->setTransparensy(0.6) || isCustomized;
+
+ return isCustomized;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByGeneralEquation()
+{
+ AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A());
+ AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B());
+ AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C());
+ AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D());
+ std::shared_ptr<GeomAPI_Shape> aPlaneFace;
+ if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) &&
+ (anAttrC.get() != NULL) && (anAttrD.get() != NULL) &&
+ anAttrA->isInitialized() && anAttrB->isInitialized() &&
+ anAttrC->isInitialized() && anAttrD->isInitialized() ) {
+ double aA = anAttrA->value(), aB = anAttrB->value(),
+ aC = anAttrC->value(), aD = anAttrD->value();
+ std::shared_ptr<GeomAPI_Pln> aPlane =
+ std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+ double aSize = Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size");
+ aSize *= 4.;
+ aPlaneFace = GeomAlgoAPI_FaceBuilder::squareFace(aPlane, aSize);
+ }
+ return aPlaneFace;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByThreePoints()
+{
+ // Get first point.
+ AttributeSelectionPtr aPointSelection1 = selection(POINT1());
+ GeomShapePtr aPointShape1 = aPointSelection1->value();
+ if(!aPointShape1.get()) {
+ aPointShape1 = aPointSelection1->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
+
+ // Get second point.
+ AttributeSelectionPtr aPointSelection2 = selection(POINT2());
+ GeomShapePtr aPointShape2 = aPointSelection2->value();
+ if(!aPointShape2.get()) {
+ aPointShape2 = aPointSelection2->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
+
+ // Get third point.
+ AttributeSelectionPtr aPointSelection3 = selection(POINT3());
+ GeomShapePtr aPointShape3 = aPointSelection3->value();
+ if(!aPointShape3.get()) {
+ aPointShape3 = aPointSelection3->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
+
+ GeomShapePtr aRes = faceByThreeVertices(aVertex1, aVertex2, aVertex3);
+
+ return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByLineAndPoint()
+{
+ // 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));
+
+ // 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));
+
+ // Get perpendicular flag.
+ bool anIsPerpendicular= boolean(PERPENDICULAR())->value();
+
+ GeomShapePtr aRes;
+ if(anIsPerpendicular) {
+ std::shared_ptr<GeomAPI_Lin> aLin = anEdge->line();
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+ std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(aPnt, aLin->direction()));
+ double aSize = aLin->distance(aPnt) * 2;
+ // point may belong to line, so for the face size use maximum distance between point and line
+ // and the line size (distance between the start and end point)
+ double aDistance = anEdge->firstPoint()->distance(anEdge->lastPoint());
+ aRes = GeomAlgoAPI_FaceBuilder::squareFace(aNewPln, aSize > aDistance ? aSize : aDistance);
+ } else {
+ std::shared_ptr<GeomAPI_Vertex> aV1, aV2;
+ GeomAlgoAPI_ShapeTools::findBounds(anEdge, aV1, aV2);
+ aRes = faceByThreeVertices(aV1, aV2, aVertex);
+ }
+
+ return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByDistanceFromOther()
+{
+ AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::PLANE());