]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[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 <Config_PropManager.h>
10
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeDouble.h>
13 #include <ModelAPI_ResultConstruction.h>
14 #include <GeomAlgoAPI_FaceBuilder.h>
15
16 #include <GeomAPI_Pnt2d.h>
17
18
19 #define PLANE_SIZE 300
20
21 ConstructionPlugin_Plane::ConstructionPlugin_Plane()
22 {
23 }
24
25 void ConstructionPlugin_Plane::initAttributes()
26 {
27   data()->addAttribute(ConstructionPlugin_Plane::FACE(),  ModelAPI_AttributeSelection::type());
28   data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::type());
29 }
30
31 void ConstructionPlugin_Plane::execute()
32 {
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()) {
37
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();
44
45       aOrig->translate(aDir, aDist);
46       std::shared_ptr<GeomAPI_Pln> aNewPln = 
47         std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aOrig, aDir));
48
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);
52
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));
57
58       std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = aPnt1->to2D(aNewPln);
59       std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = aPnt2->to2D(aNewPln);
60
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;
65
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);
71       setResult(aConstr);
72     }
73   }
74 }
75
76 void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
77 {
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);
82 }