Salome HOME
Within Issue #143 small corrections in sketch label's margins
[modules/shaper.git] / src / PartSet / PartSet_OperationSketchBase.cpp
index 46b9a05411bad19924e4420dea5a8c7eedfbbe39..9dd3141eb50135b8836616dde205871b20884857 100644 (file)
@@ -3,13 +3,17 @@
 // Author:      Natalia ERMOLAEVA
 
 #include <PartSet_OperationSketchBase.h>
+#include <PartSet_Tools.h>
+#include <ModelAPI_ResultBody.h>
 
 #include <SketchPlugin_Feature.h>
-#include <ModelAPI_Object.h>
-
 #include <V3d_View.hxx>
+#include <AIS_Shape.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
 
 #include <QKeyEvent>
+#include <QMessageBox>
+#include <QApplication>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -17,9 +21,8 @@
 
 using namespace std;
 
-PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId,
-                                                            QObject* theParent)
-: ModuleBase_Operation(theId, theParent)
+PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId, QObject* theParent)
+    : ModuleBase_Operation(theId, theParent)
 {
 }
 
@@ -27,71 +30,79 @@ PartSet_OperationSketchBase::~PartSet_OperationSketchBase()
 {
 }
 
-boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
-                                      boost::shared_ptr<ModelAPI_Feature> theFeature)
+boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(FeaturePtr theFeature)
 {
-  boost::shared_ptr<SketchPlugin_Feature> aFeature = 
-                              boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
-  if (!aFeature) { // if it is reference to a object feature
-    boost::shared_ptr<ModelAPI_Object> anObj = 
-      boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
-    if (anObj) 
-      aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(anObj->featureRef());
+  boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<
+      SketchPlugin_Feature>(theFeature);
+  if (aFeature) {
+    ResultPtr aRes = aFeature->firstResult();
+    ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
+    if (aBody)
+      return aBody->shape();
   }
-  if (!aFeature)
-    return boost::shared_ptr<GeomAPI_Shape>();
-  return aFeature->preview();
+  return boost::shared_ptr<GeomAPI_Shape>();
 }
 
-std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
-                                                     PartSet_OperationSketchBase::subPreview() const
+std::list<FeaturePtr> PartSet_OperationSketchBase::subFeatures() const
 {
-  return std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >();
+  return std::list<FeaturePtr>();
 }
 
-std::list<int> PartSet_OperationSketchBase::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
+std::list<int> PartSet_OperationSketchBase::getSelectionModes(ObjectPtr theFeature) const
 {
+  //TODO: Define position of selection modes definition
   std::list<int> aModes;
-  aModes.push_back(TopAbs_VERTEX);
-  aModes.push_back(TopAbs_EDGE);
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
+  if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
+    aModes.push_back(AIS_DSM_Text);
+    aModes.push_back(AIS_DSM_Line);
+  } else {
+    aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
+    aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+  }
   return aModes;
 }
-boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
+FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
 {
-  boost::shared_ptr<ModelAPI_Feature> aFeature = ModuleBase_Operation::createFeature(theFlushMessage);
-  if (aFeature)
-    emit featureConstructed(aFeature, FM_Activation);
-  return aFeature;
+  ModuleBase_Operation::createFeature(theFlushMessage);
+  if (myFeature)
+    emit featureConstructed(myFeature, FM_Activation);
+  return myFeature;
 }
 
-
-void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                               const std::list<XGUI_ViewerPrs>& theSelected,
-                                               const std::list<XGUI_ViewerPrs>& theHighlighted)
+void PartSet_OperationSketchBase::mousePressed(
+    QMouseEvent* theEvent, Handle_V3d_View theView,
+    const std::list<ModuleBase_ViewerPrs>& theSelected,
+    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
 }
-void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                                const std::list<XGUI_ViewerPrs>& theSelected,
-                                                const std::list<XGUI_ViewerPrs>& theHighlighted)
+void PartSet_OperationSketchBase::mouseReleased(
+    QMouseEvent* theEvent, Handle_V3d_View theView,
+    const std::list<ModuleBase_ViewerPrs>& theSelected,
+    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
 }
 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
 {
 }
-
-void PartSet_OperationSketchBase::keyReleased(const int theKey)
+void PartSet_OperationSketchBase::mouseDoubleClick(
+    QMouseEvent* theEvent, Handle_V3d_View theView,
+    const std::list<ModuleBase_ViewerPrs>& theSelected,
+    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
-  switch (theKey) {
-    case Qt::Key_Escape: {
-      abort();
-    }
-    break;
-    default:
-    break;
-  }
 }
 
-void PartSet_OperationSketchBase::keyReleased(std::string theName, QKeyEvent* theEvent)
+void PartSet_OperationSketchBase::restartOperation(const std::string& theType, ObjectPtr theFeature)
 {
-  keyReleased(theEvent->key());
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theFeature);
+  if (aFeature) {
+    QStringList aNested = this->nestedFeatures();
+    if (!aNested.isEmpty()) {
+      if (aNested.contains(QString(aFeature->getKind().c_str()))) 
+        emit restartRequired(theType, theFeature);
+      else
+        return;
+    }
+  }
+  emit restartRequired(theType, theFeature);
 }