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