Salome HOME
Issue #251. Append Export/Import NewGeom commands in the SALOME desktop.
[modules/shaper.git] / src / PartSet / PartSet_OperationSketch.cpp
index 7f5dcd7583b840119ee2a7abf7344209e56e3178..c3ca9d922d802d974e962a87ac41eddf62f6983c 100644 (file)
@@ -5,7 +5,6 @@
 #include <PartSet_OperationSketch.h>
 
 #include <PartSet_OperationFeatureEdit.h>
-#include <PartSet_OperationFeatureEditMulti.h>
 #include <PartSet_Tools.h>
 
 #include <SketchPlugin_Sketch.h>
@@ -63,30 +62,33 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, ModuleBase_IVi
     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
     QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
     QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
+    // commented: the next code is commented because the nearestFeature check the highlighting
+    // and selection inside
     //if (aHasShift && (aSelected.size() > 0)) {
-      foreach(ModuleBase_ViewerPrs aPrs, aHighlighted)
-        aSelected.append(aPrs);
+    //  foreach(ModuleBase_ViewerPrs aPrs, aHighlighted)
+    //    aSelected.append(aPrs);
     //}
     //if (aHasShift && aSelected.size() > 0)
     //  return;
 
     // there should be a start of operation, which uses the pre-highlighted objects,
     // the selected ones are collected here and are processed by a mouse move
-    if (aHighlighted.size() == 1) {
+    //if (aHighlighted.size() == 1) {
     //if (aSelected.size() > 0) {
-      ObjectPtr aFeature = aSelected.first().object();
-      if (aFeature) {
-        std::string anOperationType =
-            (aSelected.size() > 1) ?
-                PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type();
-        restartOperation(anOperationType, aFeature);
-      }
-    }
-    else
-      myFeatures = aHighlighted;
+    //  ObjectPtr aFeature = aSelected.first().object();
+    //  if (aFeature) {
+    // commented: end
+        Handle(V3d_View) aView = theViewer->activeView();
+        ObjectPtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(),
+                                                           aSelected, aHighlighted);
+        if (aFeature)
+          restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
+      //}
+    //}
+    //else
+    //  myFeatures = aHighlighted;
     //else
     //myFeatures = aSelected;
-
   } 
 }
 
@@ -102,13 +104,15 @@ void PartSet_OperationSketch::selectionChanged(ModuleBase_ISelection* theSelecti
     // We have to select a plane before any operation
     TopoDS_Shape aShape = aPrs.shape();
     if (!aShape.IsNull()) {
-      setSketchPlane(aShape);
+      boost::shared_ptr<GeomAPI_Dir> aDir = setSketchPlane(aShape);
+      flushUpdated();
+      emit featureConstructed(feature(), FM_Hide);
       // If selection is not a sketcher presentation then it has to be stored as 
       // External shape
       if (feature() != aPrs.object()) {
-        boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
-          boost::dynamic_pointer_cast<SketchPlugin_Sketch>(feature());
-        DataPtr aData = aSketch->data();
+        //boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
+        //  boost::dynamic_pointer_cast<SketchPlugin_Sketch>(feature());
+        DataPtr aData = feature()->data();
         AttributeSelectionPtr aSelAttr = 
           boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>
           (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
@@ -120,7 +124,12 @@ void PartSet_OperationSketch::selectionChanged(ModuleBase_ISelection* theSelecti
             aSelAttr->setValue(aRes, aShapePtr);
           }
         }
+      } else {
+        // Turn viewer to the plane
+        emit planeSelected(aDir->x(), aDir->y(), aDir->z());
       }
+      emit updatePropPanel();
+      emit launchSketch();
     }
   }
 }
@@ -149,13 +158,15 @@ void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, ModuleBase_IView
   if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty())
     return;
 
-  if (myFeatures.size() != 1) {
+  // myFeatures are not filled in the previous realization, so, this code is just commented
+  // because has no effect
+  /*if (myFeatures.size() != 1) {
     Handle(V3d_View) aView = theViewer->activeView();
-    FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(),
-                                                        myFeatures);
+    ObjectPtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(),
+                                                       myFeatures);
     if (aFeature)
-      restartOperation(PartSet_OperationFeatureEditMulti::Type(), aFeature);
-  }
+      restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
+  }*/
 }
 
 std::list<FeaturePtr> PartSet_OperationSketch::subFeatures() const
@@ -225,10 +236,10 @@ bool PartSet_OperationSketch::hasSketchPlane() const
   return aHasPlane;
 }
 
-void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
+boost::shared_ptr<GeomAPI_Dir> PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
 {
   if (theShape.IsNull())
-    return;
+    return boost::shared_ptr<GeomAPI_Dir>();
 
   // get selected shape
   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
@@ -269,11 +280,7 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
       aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
   aDirY->setValue(aYDir);
   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
-
-  flushUpdated();
-
-  emit featureConstructed(feature(), FM_Hide);
-  emit planeSelected(aDir->x(), aDir->y(), aDir->z());
+  return aDir;
 }