Salome HOME
Create selection validator and selection object
[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 #include <QMessageBox>
15 #include <QApplication>
16
17 #ifdef _DEBUG
18 #include <QDebug>
19 #endif
20
21 using namespace std;
22
23 PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId,
24                                                              QObject* theParent)
25 : ModuleBase_Operation(theId, theParent)
26 {
27 }
28
29 PartSet_OperationSketchBase::~PartSet_OperationSketchBase()
30 {
31 }
32
33 boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
34                                       FeaturePtr theFeature)
35 {
36   boost::shared_ptr<SketchPlugin_Feature> aFeature = 
37                               boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
38   if (!aFeature)
39     return boost::shared_ptr<GeomAPI_Shape>();
40   return aFeature->preview();
41 }
42
43 std::list<FeaturePtr> PartSet_OperationSketchBase::subFeatures() const
44 {
45   return std::list<FeaturePtr>();
46 }
47
48 std::list<int> PartSet_OperationSketchBase::getSelectionModes(FeaturePtr theFeature) const
49 {
50   std::list<int> aModes;
51   if (PartSet_Tools::isConstraintFeature(theFeature->getKind())) {
52       aModes.clear();
53       aModes.push_back(AIS_DSM_Text);
54       aModes.push_back(AIS_DSM_Line);
55   }
56   else {
57     aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)TopAbs_VERTEX));
58     aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)TopAbs_EDGE));
59   }
60   return aModes;
61 }
62 FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
63 {
64   FeaturePtr aFeature = ModuleBase_Operation::createFeature(theFlushMessage);
65   if (aFeature)
66     emit featureConstructed(aFeature, FM_Activation);
67   return aFeature;
68 }
69
70
71 void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
72                                                const std::list<ModuleBase_ViewerPrs>& theSelected,
73                                                const std::list<ModuleBase_ViewerPrs>& theHighlighted)
74 {
75 }
76 void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
77                                                 const std::list<ModuleBase_ViewerPrs>& theSelected,
78                                                 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
79 {
80 }
81 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
82 {
83 }
84 void PartSet_OperationSketchBase::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
85                                                    const std::list<ModuleBase_ViewerPrs>& theSelected,
86                                                    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
87 {
88 }
89
90 void PartSet_OperationSketchBase::keyReleased(const int theKey)
91 {
92   switch (theKey) {
93     case Qt::Key_Escape: {
94       bool toAbort = true;
95       if (isModified()) {
96         int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Cancel operation"),
97                                   tr("Operation %1 will be cancelled. Continue?").arg(id()),
98                                   QMessageBox::Yes, QMessageBox::No);
99         toAbort = (anAnswer == QMessageBox::Yes);
100       }
101       if (toAbort)
102         abort();
103     }
104     break;
105     default:
106     break;
107   }
108 }
109
110 void PartSet_OperationSketchBase::keyReleased(std::string theName, QKeyEvent* theEvent)
111 {
112   keyReleased(theEvent->key());
113 }
114
115 void PartSet_OperationSketchBase::restartOperation(const std::string& theType,
116                                                    FeaturePtr theFeature)
117 {
118   emit launchOperation(theType, theFeature);
119 }