1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ConstructionPlugin_Plane.cpp
4 // Created: 12 Dec 2014
5 // Author: Vitaly Smetannikov
7 #include "ConstructionPlugin_Plane.h"
9 #include <Config_PropManager.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeDouble.h>
13 #include <ModelAPI_ResultConstruction.h>
14 #include <GeomAlgoAPI_FaceBuilder.h>
16 #include <GeomAPI_Pnt2d.h>
19 #define PLANE_SIZE 300
21 ConstructionPlugin_Plane::ConstructionPlugin_Plane()
25 void ConstructionPlugin_Plane::initAttributes()
27 data()->addAttribute(ConstructionPlugin_Plane::FACE(), ModelAPI_AttributeSelection::type());
28 data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::type());
31 void ConstructionPlugin_Plane::execute()
33 AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::FACE());
34 AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE());
35 if ((aFaceAttr.get() != NULL) && (aDistAttr.get() != NULL) &&
36 aFaceAttr->isInitialized() && aDistAttr->isInitialized()) {
38 double aDist = aDistAttr->value();
39 GeomShapePtr aShape = aFaceAttr->value();
40 if (aShape.get() != NULL) {
41 std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aShape);
42 std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
43 std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
45 aOrig->translate(aDir, aDist);
46 std::shared_ptr<GeomAPI_Pln> aNewPln =
47 std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aOrig, aDir));
49 // Create rectangular face close to the selected
50 double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
51 aShape->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
53 std::shared_ptr<GeomAPI_Pnt> aPnt1 =
54 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aXmin, aYmin, Zmin));
55 std::shared_ptr<GeomAPI_Pnt> aPnt2 =
56 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aXmax, aYmax, Zmax));
58 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = aPnt1->to2D(aNewPln);
59 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = aPnt2->to2D(aNewPln);
61 double aWidth = aPnt2d2->x() - aPnt2d1->x();
62 double aHeight = aPnt2d2->y() - aPnt2d1->y();
63 double aWgap = aWidth * 0.1;
64 double aHgap = aHeight * 0.1;
66 std::shared_ptr<GeomAPI_Shape> aPlane =
67 GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, aPnt2d1->x() - aWgap, aPnt2d1->y() - aHgap,
68 aWidth + 2 * aWgap, aHeight + 2 * aHgap);
69 ResultConstructionPtr aConstr = document()->createConstruction(data());
70 aConstr->setShape(aPlane);
76 void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
78 std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_plane_color",
79 ConstructionPlugin_Plane::DEFAULT_COLOR());
80 thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
81 thePrs->setTransparensy(0.6);