Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Plane.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ConstructionPlugin_Plane.cpp
4 // Created:     12 Dec 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "ConstructionPlugin_Plane.h"
8
9 #include <ModelAPI_AttributeSelection.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_ResultConstruction.h>
12 #include <GeomAlgoAPI_FaceBuilder.h>
13
14
15 #define PLANE_SIZE 300
16
17 ConstructionPlugin_Plane::ConstructionPlugin_Plane()
18 {
19 }
20
21 void ConstructionPlugin_Plane::initAttributes()
22 {
23   data()->addAttribute(FACE_ATTR,  ModelAPI_AttributeSelection::type());
24   data()->addAttribute(DISTANCE_ATTR, ModelAPI_AttributeDouble::type());
25 }
26
27 void ConstructionPlugin_Plane::execute()
28 {
29   AttributeSelectionPtr aFaceAttr = data()->selection(FACE_ATTR);
30   AttributeDoublePtr aDistAttr = data()->real(DISTANCE_ATTR);
31   if ((aFaceAttr.get() != NULL) && (aDistAttr.get() != NULL) && 
32     aFaceAttr->isInitialized() && aDistAttr->isInitialized()) {
33
34     double aDist = aDistAttr->value();
35     GeomShapePtr aShape = aFaceAttr->value();
36     if (aShape.get() != NULL) {
37       std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aShape);
38       std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
39       std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
40
41       aOrig->translate(aDir, aDist);
42       std::shared_ptr<GeomAPI_Shape> aPlane = 
43         GeomAlgoAPI_FaceBuilder::square(aOrig, aDir, PLANE_SIZE);
44       ResultConstructionPtr aConstr = document()->createConstruction(data());
45       aConstr->setShape(aPlane);
46       setResult(aConstr);
47     }
48   }
49 }
50
51 void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
52 {
53   thePrs->setColor(50, 255, 50);
54   thePrs->setTransparensy(0.6);
55 }