Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 #include <GeomDataAPI_Point.h>
12 #include <GeomDataAPI_Dir.h>
13
14 #include <AIS_Shape.hxx>
15 #include <AIS_ListOfInteractive.hxx>
16
17 #ifdef _DEBUG
18 #include <QDebug>
19 #endif
20
21 using namespace std;
22
23 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
24                                                      QObject* theParent)
25 : PartSet_OperationSketchBase(theId, theParent)
26 {
27 }
28
29 PartSet_OperationSketch::~PartSet_OperationSketch()
30 {
31 }
32
33 int PartSet_OperationSketch::getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const
34 {
35   int aMode = TopAbs_FACE;
36   if (isEditMode())
37     aMode = TopAbs_VERTEX;
38   return aMode;
39 }
40
41 void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
42 {
43   if (theList.IsEmpty())
44     return;
45
46   if (isEditMode())
47     return;
48
49   // get selected shape
50   const TopoDS_Shape& aShape = theList.First();
51   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
52   aGShape->setImpl(new TopoDS_Shape(aShape));
53
54   // get plane parameters
55   boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
56
57   // set plane parameters to feature
58   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
59   double anA, aB, aC, aD;
60   aPlane->coefficients(anA, aB, aC, aD);
61
62   boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
63   /*
64   aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
65   aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
66   aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
67   aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
68   */
69   // temporary solution for main planes only
70   boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
71     boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
72   anOrigin->setValue(0, 0, 0);
73   boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
74     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
75   aNormal->setValue(anA, aB, aC);
76   boost::shared_ptr<GeomDataAPI_Dir> aDirX = 
77     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
78   aDirX->setValue(aB, aC, anA);
79   boost::shared_ptr<GeomDataAPI_Dir> aDirY = 
80     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
81   aDirY->setValue(aC, anA, aB);
82
83   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
84   emit planeSelected(aDir->x(), aDir->y(), aDir->z());
85
86   //commit();
87   //SketchPlugin_Sketch::setActive(myFeature);
88 }