Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_OperationSketch.cpp
index d96ddc4ac7013029f350eea6f459aee2a2045f0e..e57a113b73ebc39cc1a6cd82a708afc48c8c795d 100644 (file)
@@ -46,21 +46,22 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
   std::list<int> aModes;
   if (!myIsEditMode)
     aModes.push_back(TopAbs_FACE);
-  else {
-    aModes.push_back(TopAbs_VERTEX);
-    aModes.push_back(TopAbs_EDGE);
-  }
+  else
+    aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
   return aModes;
 }
 
-void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                            const std::list<XGUI_ViewerPrs>& theSelected)
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketch::sketch() const
 {
-  if (theSelected.empty())
-    return;
+  return feature();
+}
 
+void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
+                                           const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                           const std::list<XGUI_ViewerPrs>& theHighlighted)
+{
   if (!myIsEditMode) {
-    XGUI_ViewerPrs aPrs = theSelected.front();
+    XGUI_ViewerPrs aPrs = theHighlighted.front();
     const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) {
       setSketchPlane(aShape);
@@ -68,30 +69,31 @@ void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_Vi
     }
   }
   else {
-    if (theSelected.size() == 1) {
-      boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
+    if (theHighlighted.size() == 1) {
+      boost::shared_ptr<ModelAPI_Feature> aFeature = theHighlighted.front().feature();
       if (aFeature)
         emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
     }
+    else
+      myFeatures = theHighlighted;
   }
 }
 
-void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                         const std::list<XGUI_ViewerPrs>& theSelected)
+void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
 {
-  if (!myIsEditMode || !(theEvent->buttons() &  Qt::LeftButton) || theSelected.empty())
+  if (!myIsEditMode || !(theEvent->buttons() &  Qt::LeftButton) || myFeatures.empty())
     return;
 
-  if (theSelected.size() != 1) {
+  if (myFeatures.size() != 1) {
     boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
-                                                                theView, feature(), theSelected);
+                                                                theView, feature(), myFeatures);
     if (aFeature)
       emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
   }
 }
 
 std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
-                                                        PartSet_OperationSketch::preview() const
+                                                        PartSet_OperationSketch::subPreview() const
 {
   std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> > aPreviewMap;
 
@@ -113,6 +115,13 @@ std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
   return aPreviewMap;
 }
 
+void PartSet_OperationSketch::stopOperation()
+{
+  PartSet_OperationSketchBase::stopOperation();
+  emit featureConstructed(feature(), FM_Hide);
+  emit closeLocalContext();
+}
+
 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
 {
   if (theShape.IsNull())
@@ -151,5 +160,10 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
   aDirY->setValue(aC, anA, aB);
   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+
+  flushUpdated();
+
+  emit featureConstructed(feature(), FM_Hide);
+  emit closeLocalContext();
   emit planeSelected(aDir->x(), aDir->y(), aDir->z());
 }