Salome HOME
Make property panel as a GUI of an operation
[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   //TODO: Define position of selection modes definition
54   std::list<int> aModes;
55   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
56   if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
57     aModes.push_back(AIS_DSM_Text);
58     aModes.push_back(AIS_DSM_Line);
59   } else {
60     aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
61     aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
62   }
63   return aModes;
64 }
65 FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
66 {
67   ModuleBase_Operation::createFeature(theFlushMessage);
68   if (myFeature)
69     emit featureConstructed(myFeature, FM_Activation);
70   return myFeature;
71 }
72
73 void PartSet_OperationSketchBase::mousePressed(
74     QMouseEvent* theEvent, Handle_V3d_View theView,
75     const std::list<ModuleBase_ViewerPrs>& theSelected,
76     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
77 {
78 }
79 void PartSet_OperationSketchBase::mouseReleased(
80     QMouseEvent* theEvent, Handle_V3d_View theView,
81     const std::list<ModuleBase_ViewerPrs>& theSelected,
82     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
83 {
84 }
85 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
86 {
87 }
88 void PartSet_OperationSketchBase::mouseDoubleClick(
89     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::restartOperation(const std::string& theType, ObjectPtr theFeature)
96 {
97   FeaturePtr aFeature = ModelAPI_Feature::feature(theFeature);
98   if (aFeature) {
99     QStringList aNested = this->nestedFeatures();
100     if (!aNested.isEmpty()) {
101       if (!aNested.contains(QString(aFeature->getKind().c_str())))
102         return;
103     }
104   }
105   emit restartRequired(theType, theFeature);
106 }