Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_OperationSketch.cpp
index 5bd17a0f9cb9a09295be05ea82c8080efc02c4c7..e57a113b73ebc39cc1a6cd82a708afc48c8c795d 100644 (file)
@@ -4,20 +4,31 @@
 
 #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 <ModelAPI_AttributeRefList.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,
@@ -35,22 +46,87 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
   std::list<int> aModes;
   if (!myIsEditMode)
     aModes.push_back(TopAbs_FACE);
+  else
+    aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
   return aModes;
 }
 
-void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                          const TopoDS_Shape& theShape)
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketch::sketch() const
+{
+  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) {
-    setSketchPlane(theShape);
-    myIsEditMode = true;
+    XGUI_ViewerPrs aPrs = theHighlighted.front();
+    const TopoDS_Shape& aShape = aPrs.shape();
+    if (!aShape.IsNull()) {
+      setSketchPlane(aShape);
+      myIsEditMode = true;
+    }
+  }
+  else {
+    if (theHighlighted.size() == 1) {
+      boost::shared_ptr<ModelAPI_Feature> aFeature = theHighlighted.front().feature();
+      if (aFeature)
+        emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+    }
+    else
+      myFeatures = theHighlighted;
   }
-  else if (theFeature)
-    emit launchOperation("EditLine", theFeature);
+}
+
+void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+{
+  if (!myIsEditMode || !(theEvent->buttons() &  Qt::LeftButton) || myFeatures.empty())
+    return;
+
+  if (myFeatures.size() != 1) {
+    boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
+                                                                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::subPreview() const
+{
+  std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> > aPreviewMap;
+
+  boost::shared_ptr<SketchPlugin_Feature> aFeature;
+
+  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+  boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
+
+  std::list<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aRefList->list();
+  std::list<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
+                                                                  aLast = aFeatures.end();
+  for (; anIt != aLast; anIt++) {
+    aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
+    boost::shared_ptr<GeomAPI_Shape> aPreview = aFeature->preview();
+    if (aPreview)
+      aPreviewMap[aFeature] = aPreview;
+  }
+  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())
+    return;
+
   // get selected shape
   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
   aGShape->setImpl(new TopoDS_Shape(theShape));
@@ -84,6 +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());
 }
-