]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
Salome HOME
Switch Wireframe/Shading with closing of context
[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 #include <GeomAPI_Pnt2d.h>
15
16
17 #define PLANE_SIZE 300
18
19 ConstructionPlugin_Plane::ConstructionPlugin_Plane()
20 {
21 }
22
23 void ConstructionPlugin_Plane::initAttributes()
24 {
25   data()->addAttribute(FACE_ATTR,  ModelAPI_AttributeSelection::type());
26   data()->addAttribute(DISTANCE_ATTR, ModelAPI_AttributeDouble::type());
27 }
28
29 void ConstructionPlugin_Plane::execute()
30 {
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()) {
35
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();
42
43       aOrig->translate(aDir, aDist);
44       std::shared_ptr<GeomAPI_Pln> aNewPln = 
45         std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aOrig, aDir));
46
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);
50
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));
55
56       std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = aPnt1->to2D(aNewPln);
57       std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = aPnt2->to2D(aNewPln);
58
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;
63
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);
69       setResult(aConstr);
70     }
71   }
72 }
73
74 void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
75 {
76   thePrs->setColor(50, 255, 50);
77   thePrs->setTransparensy(0.6);
78 }