Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 <ModuleBase_IPropertyPanel.h>
10 #include <ModuleBase_ModelWidget.h>
11 #include <ModuleBase_WidgetValueFeature.h>
12
13 #include <SketchPlugin_Feature.h>
14 #include <V3d_View.hxx>
15 #include <AIS_Shape.hxx>
16 #include <AIS_DimensionSelectionMode.hxx>
17
18 #include <QKeyEvent>
19 #include <QMessageBox>
20 #include <QApplication>
21
22 #ifdef _DEBUG
23 #include <QDebug>
24 #endif
25
26 using namespace std;
27
28 PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId, QObject* theParent)
29     : ModuleBase_Operation(theId, theParent)
30 {
31 }
32
33 PartSet_OperationSketchBase::~PartSet_OperationSketchBase()
34 {
35 }
36
37 boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(FeaturePtr theFeature)
38 {
39   boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<
40       SketchPlugin_Feature>(theFeature);
41   if (aFeature) {
42     ResultPtr aRes = aFeature->firstResult();
43     ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
44     if (aBody)
45       return aBody->shape();
46   }
47   return boost::shared_ptr<GeomAPI_Shape>();
48 }
49
50 std::list<FeaturePtr> PartSet_OperationSketchBase::subFeatures() const
51 {
52   return std::list<FeaturePtr>();
53 }
54
55 FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
56 {
57   ModuleBase_Operation::createFeature(theFlushMessage);
58   if (myFeature)
59     emit featureConstructed(myFeature, FM_Activation);
60   return myFeature;
61 }
62
63 void PartSet_OperationSketchBase::mousePressed(
64     QMouseEvent* theEvent, Handle_V3d_View theView,
65     const std::list<ModuleBase_ViewerPrs>& theSelected,
66     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
67 {
68 }
69 void PartSet_OperationSketchBase::mouseReleased(
70     QMouseEvent* theEvent, Handle_V3d_View theView,
71     const std::list<ModuleBase_ViewerPrs>& theSelected,
72     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
73 {
74 }
75 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
76 {
77 }
78 void PartSet_OperationSketchBase::mouseDoubleClick(
79     QMouseEvent* theEvent, Handle_V3d_View theView,
80     const std::list<ModuleBase_ViewerPrs>& theSelected,
81     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
82 {
83 }
84
85 void PartSet_OperationSketchBase::restartOperation(const std::string& theType, ObjectPtr theFeature)
86 {
87   FeaturePtr aFeature = ModelAPI_Feature::feature(theFeature);
88   if (aFeature) {
89     QStringList aNested = this->nestedFeatures();
90     if (!aNested.isEmpty()) {
91       if (!aNested.contains(QString(aFeature->getKind().c_str())))
92         return;
93     }
94   }
95   emit restartRequired(theType, theFeature);
96 }
97
98
99
100 void PartSet_OperationSketchBase::activateByPreselection()
101 {
102   if (!myPropertyPanel)
103     return;
104   ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
105   if ((myPreSelection.size() > 0) && aActiveWgt) {
106     const ModuleBase_ViewerPrs& aPrs = myPreSelection.front();
107     ModuleBase_WidgetValueFeature aValue;
108     aValue.setObject(aPrs.object());
109     if (aActiveWgt->setValue(&aValue)) {
110       myPreSelection.remove(aPrs);
111       if(isValid()) {
112         //myActiveWidget = NULL;
113         commit();
114       } else {
115         myPropertyPanel->activateNextWidget();
116         //emit activateNextWidget(myActiveWidget);
117       }
118     }
119     // If preselection is enough to make a valid feature - apply it immediately
120   }
121 }