Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_OperationSketchBase.cpp
1 // File:        PartSet_OperationSketchBase.cpp
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_OperationSketchBase.h>
6 #include <PartSet_Tools.h>
7
8 #include <SketchPlugin_Feature.h>
9 #include <V3d_View.hxx>
10 #include <AIS_Shape.hxx>
11 #include <AIS_DimensionSelectionMode.hxx>
12
13 #include <QKeyEvent>
14
15 #ifdef _DEBUG
16 #include <QDebug>
17 #endif
18
19 using namespace std;
20
21 PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId,
22                                                              QObject* theParent)
23 : ModuleBase_Operation(theId, theParent)
24 {
25 }
26
27 PartSet_OperationSketchBase::~PartSet_OperationSketchBase()
28 {
29 }
30
31 boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
32                                       FeaturePtr theFeature)
33 {
34   boost::shared_ptr<SketchPlugin_Feature> aFeature = 
35                               boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
36   if (!aFeature)
37     return boost::shared_ptr<GeomAPI_Shape>();
38   return aFeature->preview();
39 }
40
41 std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >
42                                                      PartSet_OperationSketchBase::subPreview() const
43 {
44   return std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >();
45 }
46
47 std::list<int> PartSet_OperationSketchBase::getSelectionModes(FeaturePtr theFeature) const
48 {
49   std::list<int> aModes;
50   if (PartSet_Tools::isConstraintFeature(theFeature->getKind())) {
51       aModes.clear();
52       aModes.push_back(AIS_DSM_Text);
53       aModes.push_back(AIS_DSM_Line);
54   }
55   else {
56     aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)TopAbs_VERTEX));
57     aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)TopAbs_EDGE));
58   }
59   return aModes;
60 }
61 FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
62 {
63   FeaturePtr aFeature = ModuleBase_Operation::createFeature(theFlushMessage);
64   if (aFeature)
65     emit featureConstructed(aFeature, FM_Activation);
66   return aFeature;
67 }
68
69
70 void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
71                                                const std::list<XGUI_ViewerPrs>& theSelected,
72                                                const std::list<XGUI_ViewerPrs>& theHighlighted)
73 {
74 }
75 void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
76                                                 const std::list<XGUI_ViewerPrs>& theSelected,
77                                                 const std::list<XGUI_ViewerPrs>& theHighlighted)
78 {
79 }
80 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
81 {
82 }
83 void PartSet_OperationSketchBase::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
84                                                    const std::list<XGUI_ViewerPrs>& theSelected,
85                                                    const std::list<XGUI_ViewerPrs>& theHighlighted)
86 {
87 }
88
89 void PartSet_OperationSketchBase::keyReleased(const int theKey)
90 {
91   switch (theKey) {
92     case Qt::Key_Escape: {
93       abort();
94     }
95     break;
96     default:
97     break;
98   }
99 }
100
101 void PartSet_OperationSketchBase::keyReleased(std::string theName, QKeyEvent* theEvent)
102 {
103   keyReleased(theEvent->key());
104 }
105
106 void PartSet_OperationSketchBase::restartOperation(const std::string& theType,
107                                                    FeaturePtr theFeature)
108 {
109   emit launchOperation(theType, theFeature);
110 }