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 <ModelAPI_AttributeSelection.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_ResultConstruction.h>
12 #include <GeomAlgoAPI_FaceBuilder.h>
14 #include <GeomAPI_Pnt2d.h>
17 #define PLANE_SIZE 300
19 ConstructionPlugin_Plane::ConstructionPlugin_Plane()
23 void ConstructionPlugin_Plane::initAttributes()
25 data()->addAttribute(FACE_ATTR, ModelAPI_AttributeSelection::type());
26 data()->addAttribute(DISTANCE_ATTR, ModelAPI_AttributeDouble::type());
29 void ConstructionPlugin_Plane::execute()
31 AttributeSelectionPtr aFaceAttr = data()->selection(FACE_ATTR);
32 AttributeDoublePtr aDistAttr = data()->real(DISTANCE_ATTR);
33 if ((aFaceAttr.get() != NULL) && (aDistAttr.get() != NULL) &&
34 aFaceAttr->isInitialized() && aDistAttr->isInitialized()) {
36 double aDist = aDistAttr->value();
37 GeomShapePtr aShape = aFaceAttr->value();
38 if (aShape.get() != NULL) {
39 std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aShape);
40 std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
41 std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
43 aOrig->translate(aDir, aDist);
44 std::shared_ptr<GeomAPI_Pln> aNewPln =
45 std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aOrig, aDir));
47 // Create rectangular face close to the selected
48 double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
49 aShape->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
51 std::shared_ptr<GeomAPI_Pnt> aPnt1 =
52 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aXmin, aYmin, Zmin));
53 std::shared_ptr<GeomAPI_Pnt> aPnt2 =
54 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aXmax, aYmax, Zmax));
56 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = aPnt1->to2D(aNewPln);
57 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = aPnt2->to2D(aNewPln);
59 double aWidth = aPnt2d2->x() - aPnt2d1->x();
60 double aHeight = aPnt2d2->y() - aPnt2d1->y();
61 double aWgap = aWidth * 0.1;
62 double aHgap = aHeight * 0.1;
64 std::shared_ptr<GeomAPI_Shape> aPlane =
65 GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, aPnt2d1->x() - aWgap, aPnt2d1->y() - aHgap,
66 aWidth + 2 * aWgap, aHeight + 2 * aHgap);
67 ResultConstructionPtr aConstr = document()->createConstruction(data());
68 aConstr->setShape(aPlane);
74 void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
76 thePrs->setColor(50, 255, 50);
77 thePrs->setTransparensy(0.6);