]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_OperationSketch.cpp
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 <PartSet_OperationEditLine.h>
8
9 #include <SketchPlugin_Sketch.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <GeomAlgoAPI_FaceBuilder.h>
13 #include <GeomDataAPI_Point.h>
14 #include <GeomDataAPI_Dir.h>
15
16 #include <XGUI_ViewerPrs.h>
17
18 #include <AIS_Shape.hxx>
19 #include <AIS_ListOfInteractive.hxx>
20 #include <V3d_View.hxx>
21
22 #ifdef _DEBUG
23 #include <QDebug>
24 #endif
25
26 using namespace std;
27
28 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
29                                                      QObject* theParent)
30 : PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false)
31 {
32 }
33
34 PartSet_OperationSketch::~PartSet_OperationSketch()
35 {
36 }
37
38 std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
39 {
40   std::list<int> aModes;
41   if (!myIsEditMode)
42     aModes.push_back(TopAbs_FACE);
43   else {
44     aModes.push_back(TopAbs_VERTEX);
45     aModes.push_back(TopAbs_EDGE);
46   }
47   return aModes;
48 }
49
50 void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
51                                             const std::list<XGUI_ViewerPrs>& theSelected)
52 {
53   if (theSelected.empty())
54     return;
55   XGUI_ViewerPrs aPrs = theSelected.front();
56
57   if (!myIsEditMode) {
58     const TopoDS_Shape& aShape = aPrs.shape();
59     if (!aShape.IsNull()) {
60       setSketchPlane(aShape);
61       myIsEditMode = true;
62     }
63   }
64   else {
65     if (aPrs.feature())
66       emit launchOperation(PartSet_OperationEditLine::Type(), aPrs.feature());
67   }
68 }
69
70 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
71 {
72   if (theShape.IsNull())
73     return;
74
75   // get selected shape
76   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
77   aGShape->setImpl(new TopoDS_Shape(theShape));
78
79   // get plane parameters
80   boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
81
82   // set plane parameters to feature
83   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
84   double anA, aB, aC, aD;
85   aPlane->coefficients(anA, aB, aC, aD);
86
87   boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
88   /*
89   aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
90   aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
91   aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
92   aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
93   */
94   // temporary solution for main planes only
95   boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
96     boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
97   anOrigin->setValue(0, 0, 0);
98   boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
99     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
100   aNormal->setValue(anA, aB, aC);
101   boost::shared_ptr<GeomDataAPI_Dir> aDirX = 
102     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
103   aDirX->setValue(aB, aC, anA);
104   boost::shared_ptr<GeomDataAPI_Dir> aDirY = 
105     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
106   aDirY->setValue(aC, anA, aB);
107   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
108   emit planeSelected(aDir->x(), aDir->y(), aDir->z());
109 }
110