]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_OperationSketchBase.cpp
Salome HOME
2ce61d8efc8250d67e8182a00f91f7dcc1ad34c0
[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 std::list<int> PartSet_OperationSketchBase::getSelectionModes(ObjectPtr theFeature) const
56 {
57   //TODO: Define position of selection modes definition
58   std::list<int> aModes;
59   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
60   if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
61     aModes.push_back(AIS_DSM_Text);
62     aModes.push_back(AIS_DSM_Line);
63   } else {
64     aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
65     aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
66   }
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::restartOperation(const std::string& theType, ObjectPtr theFeature)
100 {
101   FeaturePtr aFeature = ModelAPI_Feature::feature(theFeature);
102   if (aFeature) {
103     QStringList aNested = this->nestedFeatures();
104     if (!aNested.isEmpty()) {
105       if (!aNested.contains(QString(aFeature->getKind().c_str())))
106         return;
107     }
108   }
109   emit restartRequired(theType, theFeature);
110 }
111
112
113
114 void PartSet_OperationSketchBase::activateByPreselection()
115 {
116   if (!myPropertyPanel)
117     return;
118   ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
119   if ((myPreSelection.size() > 0) && aActiveWgt) {
120     const ModuleBase_ViewerPrs& aPrs = myPreSelection.front();
121     ModuleBase_WidgetValueFeature aValue;
122     aValue.setObject(aPrs.object());
123     if (aActiveWgt->setValue(&aValue)) {
124       myPreSelection.remove(aPrs);
125       if(isValid()) {
126         //myActiveWidget = NULL;
127         commit();
128       } else {
129         myPropertyPanel->activateNextWidget();
130         //emit activateNextWidget(myActiveWidget);
131       }
132     }
133     // If preselection is enough to make a valid feature - apply it immediately
134   }
135 }