Salome HOME
c14ab91896c46f2fc195459b27dbcba8ed299cdc
[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
7 #include <SketchPlugin_Feature.h>
8 #include <ModelAPI_Object.h>
9
10 #include <V3d_View.hxx>
11
12 #include <QKeyEvent>
13
14 #ifdef _DEBUG
15 #include <QDebug>
16 #endif
17
18 using namespace std;
19
20 PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId,
21                                                              QObject* theParent)
22 : ModuleBase_Operation(theId, theParent)
23 {
24 }
25
26 PartSet_OperationSketchBase::~PartSet_OperationSketchBase()
27 {
28 }
29
30 boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
31                                       boost::shared_ptr<ModelAPI_Feature> theFeature)
32 {
33   boost::shared_ptr<SketchPlugin_Feature> aFeature = 
34                               boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
35   if (!aFeature) { // if it is reference to a object feature
36     boost::shared_ptr<ModelAPI_Object> anObj = 
37       boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
38     if (anObj) 
39       aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(anObj->featureRef());
40   }
41   if (!aFeature)
42     return boost::shared_ptr<GeomAPI_Shape>();
43   return aFeature->preview();
44 }
45
46 std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
47                                                      PartSet_OperationSketchBase::subPreview() const
48 {
49   return std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >();
50 }
51
52 std::list<int> PartSet_OperationSketchBase::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
53 {
54   std::list<int> aModes;
55   aModes.push_back(TopAbs_VERTEX);
56   aModes.push_back(TopAbs_EDGE);
57   return aModes;
58 }
59 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
60 {
61   boost::shared_ptr<ModelAPI_Feature> aFeature = ModuleBase_Operation::createFeature(theFlushMessage);
62   if (aFeature)
63     emit featureConstructed(aFeature, FM_Activation);
64   return aFeature;
65 }
66
67
68 void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
69                                                const std::list<XGUI_ViewerPrs>& theSelected,
70                                                const std::list<XGUI_ViewerPrs>& theHighlighted)
71 {
72 }
73 void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
74                                                 const std::list<XGUI_ViewerPrs>& theSelected,
75                                                 const std::list<XGUI_ViewerPrs>& theHighlighted)
76 {
77 }
78 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
79 {
80 }
81
82 void PartSet_OperationSketchBase::keyReleased(const int theKey)
83 {
84   switch (theKey) {
85     case Qt::Key_Escape: {
86       abort();
87     }
88     break;
89     default:
90     break;
91   }
92 }
93
94 void PartSet_OperationSketchBase::keyReleased(std::string theName, QKeyEvent* theEvent)
95 {
96   keyReleased(theEvent->key());
97 }
98
99 void PartSet_OperationSketchBase::restartOperation(const std::string& theType,
100                                                    boost::shared_ptr<ModelAPI_Feature> theFeature)
101 {
102   emit launchOperation(theType, theFeature);
103 }