Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / PartSet / PartSet_OperationSketch.cpp
index 46b0c4ca2a70d4da3dd3389c596dbea623b2762e..e5290aa77eb9bc3cbd86ec285cb4b6afdf623019 100644 (file)
@@ -5,21 +5,28 @@
 #include <PartSet_OperationSketch.h>
 
 #include <PartSet_OperationEditLine.h>
+#include <PartSet_Tools.h>
 
 #include <SketchPlugin_Sketch.h>
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
 
+#include <XGUI_ViewerPrs.h>
+
 #include <AIS_Shape.hxx>
 #include <AIS_ListOfInteractive.hxx>
+#include <V3d_View.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
 #endif
 
+#include <QMouseEvent>
+
 using namespace std;
 
 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
@@ -44,22 +51,39 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
   return aModes;
 }
 
-void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                          const TopoDS_Shape& theShape)
+void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                                            const std::list<XGUI_ViewerPrs>& theSelected)
 {
-  if (theShape.IsNull())
+  if (theSelected.empty())
     return;
 
   if (!myIsEditMode) {
-    setSketchPlane(theShape);
-    myIsEditMode = true;
+    XGUI_ViewerPrs aPrs = theSelected.front();
+    const TopoDS_Shape& aShape = aPrs.shape();
+    if (!aShape.IsNull()) {
+      setSketchPlane(aShape);
+      myIsEditMode = true;
+    }
   }
-  else if (theFeature)
-    emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
+}
+
+void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
+                                         const std::list<XGUI_ViewerPrs>& theSelected)
+{
+  if (!myIsEditMode || !(theEvent->buttons() &  Qt::LeftButton) || theSelected.empty())
+    return;
+
+  boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
+                                                              theView, feature(), theSelected);
+  if (aFeature)
+    emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
 }
 
 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
 {
+  if (theShape.IsNull())
+    return;
+
   // get selected shape
   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
   aGShape->setImpl(new TopoDS_Shape(theShape));
@@ -95,4 +119,3 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
   emit planeSelected(aDir->x(), aDir->y(), aDir->z());
 }
-