Salome HOME
Sources formated according to the codeing standards
[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, 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(FeaturePtr theFeature)
34 {
35   boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<
36       SketchPlugin_Feature>(theFeature);
37   if (aFeature) {
38     ResultPtr aRes = aFeature->firstResult();
39     ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
40     if (aBody)
41       return aBody->shape();
42   }
43   return boost::shared_ptr<GeomAPI_Shape>();
44 }
45
46 std::list<FeaturePtr> PartSet_OperationSketchBase::subFeatures() const
47 {
48   return std::list<FeaturePtr>();
49 }
50
51 std::list<int> PartSet_OperationSketchBase::getSelectionModes(ObjectPtr theFeature) const
52 {
53   std::list<int> aModes;
54   //FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
55   //if (aFeature) {
56   //  if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
57   //      aModes.clear();
58   //      aModes.push_back(AIS_DSM_Text);
59   //      aModes.push_back(AIS_DSM_Line);
60   //      return aModes;
61   //  }
62   //}
63   aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
64   aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
65   aModes.push_back(AIS_DSM_Text);
66   aModes.push_back(AIS_DSM_Line);
67   return aModes;
68 }
69 FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
70 {
71   ModuleBase_Operation::createFeature(theFlushMessage);
72   if (myFeature)
73     emit featureConstructed(myFeature, FM_Activation);
74   return myFeature;
75 }
76
77 void PartSet_OperationSketchBase::mousePressed(
78     QMouseEvent* theEvent, Handle_V3d_View theView,
79     const std::list<ModuleBase_ViewerPrs>& theSelected,
80     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
81 {
82 }
83 void PartSet_OperationSketchBase::mouseReleased(
84     QMouseEvent* theEvent, Handle_V3d_View theView,
85     const std::list<ModuleBase_ViewerPrs>& theSelected,
86     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
87 {
88 }
89 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
90 {
91 }
92 void PartSet_OperationSketchBase::mouseDoubleClick(
93     QMouseEvent* theEvent, Handle_V3d_View theView,
94     const std::list<ModuleBase_ViewerPrs>& theSelected,
95     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
96 {
97 }
98
99 void PartSet_OperationSketchBase::keyReleased(const int theKey)
100 {
101   switch (theKey) {
102     case Qt::Key_Escape: {
103       bool toAbort = true;
104       if (isModified()) {
105         int anAnswer = QMessageBox::question(
106             qApp->activeWindow(), tr("Cancel operation"),
107             tr("Operation %1 will be cancelled. Continue?").arg(id()), QMessageBox::Yes,
108             QMessageBox::No);
109         toAbort = (anAnswer == QMessageBox::Yes);
110       }
111       if (toAbort)
112         abort();
113     }
114       break;
115     default:
116       break;
117   }
118 }
119
120 void PartSet_OperationSketchBase::keyReleased(std::string theName, QKeyEvent* theEvent)
121 {
122   keyReleased(theEvent->key());
123 }
124
125 void PartSet_OperationSketchBase::restartOperation(const std::string& theType, ObjectPtr theFeature)
126 {
127   emit launchOperation(theType, theFeature);
128 }