]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_OperationSketch.cpp
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / PartSet / PartSet_OperationSketch.cpp
1 // File:        PartSet_OperationSketch.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_OperationSketch.h>
6
7 #include <SketchPlugin_Sketch.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_AttributeDouble.h>
10 #include <GeomAlgoAPI_FaceBuilder.h>
11
12 #include <AIS_Shape.hxx>
13 #include <AIS_ListOfInteractive.hxx>
14
15 #ifdef _DEBUG
16 #include <QDebug>
17 #endif
18
19 using namespace std;
20
21 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
22                                                      QObject* theParent)
23 : PartSet_OperationSketchBase(theId, theParent)
24 {
25 }
26
27 PartSet_OperationSketch::~PartSet_OperationSketch()
28 {
29 }
30
31 bool PartSet_OperationSketch::isPerformedImmediately() const
32 {
33   return false;
34 }
35
36 int PartSet_OperationSketch::getSelectionMode() const
37 {
38   return TopAbs_FACE;
39 }
40
41 void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
42 {
43   if (theList.IsEmpty())
44     return;
45
46   // get selected shape
47   const TopoDS_Shape& aShape = theList.First();
48   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
49   aGShape->setImpl(new TopoDS_Shape(aShape));
50
51   // get plane parameters
52   boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
53
54   // set plane parameters to feature
55   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
56   double anA, aB, aC, aD;
57   aPlane->coefficients(anA, aB, aC, aD);
58
59   boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
60
61   aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
62   aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
63   aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
64   aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
65
66   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
67   emit viewerProjectionChange(aDir->x(), aDir->y(), aDir->z());
68
69   commit();
70 }