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