Salome HOME
A fix for a bug: clear content in the shape selector by deselection it in the viewer.
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
index e404a2f4126c6cd75a3b800fa8dc73c6969e85fd..f3d5bfa320deb4f71dcd88151bbf8852f2f34089 100644 (file)
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintFillet.h>
 #include <SketchPlugin_ConstraintMirror.h>
+#include <SketchPlugin_MultiRotation.h>
+#include <SketchPlugin_MultiTranslation.h>
+
+#include <SketcherPrs_Tools.h>
 
 #include <SelectMgr_IndexedMapOfOwner.hxx>
 #include <StdSelect_BRepOwner.hxx>
 
 //#include <AIS_DimensionSelectionMode.hxx>
-//#include <AIS_Shape.hxx>
+#include <AIS_Shape.hxx>
 
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
@@ -69,6 +73,7 @@
 #include <QMouseEvent>
 #include <QApplication>
 
+//#define DEBUG_DO_NOT_BY_ENTER
 
 /// Returns list of unique objects by sum of objects from List1 and List2
 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
@@ -164,8 +169,11 @@ void PartSet_SketcherMgr::onEnterViewPort()
   myIsMouseOverWindow = true;
   myIsPropertyPanelValueChanged = false;
 
-  if (!isNestedCreateOperation(getCurrentOperation()))
-    return;
+  #ifdef DEBUG_DO_NOT_BY_ENTER
+  return;
+  #endif
+  //if (!isNestedCreateOperation(getCurrentOperation()))
+  //  return;
 }
 
 void PartSet_SketcherMgr::onLeaveViewPort()
@@ -174,6 +182,10 @@ void PartSet_SketcherMgr::onLeaveViewPort()
   myIsMouseOverWindow = false;
   myIsPropertyPanelValueChanged = false;
 
+  #ifdef DEBUG_DO_NOT_BY_ENTER
+  return;
+  #endif
+
   if (!isNestedCreateOperation(getCurrentOperation()))
     return;
   // the method should be performed if the popup menu is called,
@@ -308,13 +320,25 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
           aOperation->abort();
       return;
     }
+    // Init flyout point for radius rotation
+    FeaturePtr aFeature = myCurrentSelection.begin().key();
 
     if (isSketcher) {
       myIsDragging = true;
       get2dPoint(theWnd, theEvent, myCurrentPoint);
       myDragDone = false;
       launchEditing();
-
+      if (aFeature.get() != NULL) {
+        std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+                  std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+      if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
+          DataPtr aData = aSPFeature->data();
+          AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
+          std::shared_ptr<GeomDataAPI_Point2D> aFPAttr = 
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
+          aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
+        }
+      }
     } else if (isSketchOpe && isEditing) {
       // If selected another object commit current result
       aOperation->commit();
@@ -552,18 +576,9 @@ void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent
 
 void PartSet_SketcherMgr::launchEditing()
 {
-  // there should be activate the vertex selection mode because the edit can happens by the selected
-  // point
-  QIntList aModes;
-  aModes << TopAbs_VERTEX << TopAbs_EDGE;
-  // TODO: #391 - to be uncommented
-  /*aModes.append(AIS_DSM_Text);
-  aModes.append(AIS_DSM_Line);
-  aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
-  aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));*/
-
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
-  aConnector->activateSubShapesSelection(aModes);
+  // there should be activate the sketch selection mode because the edit can happens
+  // by any sketch entity or consttant selected
+  activateObjectsInSketchMode(true);
 
   if (!myCurrentSelection.empty()) {
     FeaturePtr aFeature = myCurrentSelection.begin().key();
@@ -585,19 +600,8 @@ const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
     aIds << SketchPlugin_Point::ID().c_str();
     aIds << SketchPlugin_Arc::ID().c_str();
     aIds << SketchPlugin_Circle::ID().c_str();
-    aIds << SketchPlugin_ConstraintLength::ID().c_str();
-    aIds << SketchPlugin_ConstraintDistance::ID().c_str();
-    aIds << SketchPlugin_ConstraintRigid::ID().c_str();
-    aIds << SketchPlugin_ConstraintRadius::ID().c_str();
-    aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
-    aIds << SketchPlugin_ConstraintParallel::ID().c_str();
-    aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
-    aIds << SketchPlugin_ConstraintVertical::ID().c_str();
-    aIds << SketchPlugin_ConstraintEqual::ID().c_str();
-    aIds << SketchPlugin_ConstraintTangent::ID().c_str();
-    aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
     aIds << SketchPlugin_ConstraintFillet::ID().c_str();
-    aIds << SketchPlugin_ConstraintMirror::ID().c_str();
+    aIds.append(constraintsIdList());
   }
   return aIds;
 }
@@ -618,10 +622,22 @@ const QStringList& PartSet_SketcherMgr::constraintsIdList()
     aIds << SketchPlugin_ConstraintTangent::ID().c_str();
     aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
     aIds << SketchPlugin_ConstraintMirror::ID().c_str();
+    aIds << SketchPlugin_MultiRotation::ID().c_str();
+    aIds << SketchPlugin_MultiTranslation::ID().c_str();
   }
   return aIds;
 }
 
+void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
+{
+  theModes.clear();
+
+  theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
+  theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
+  theModes.append(SketcherPrs_Tools::Sel_Constraint);
+  theModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
+  theModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+}
 
 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
 {
@@ -639,14 +655,12 @@ bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOpera
   return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
 }
 
-bool PartSet_SketcherMgr::isEntityOperation(ModuleBase_Operation* theOperation)
+bool PartSet_SketcherMgr::isEntity(const std::string& theId)
 {
-  std::string aId = theOperation ? theOperation->id().toStdString() : "";
-
-  return (aId == SketchPlugin_Line::ID()) ||
-         (aId == SketchPlugin_Point::ID()) ||
-         (aId == SketchPlugin_Arc::ID()) ||
-         (aId == SketchPlugin_Circle::ID());
+  return (theId == SketchPlugin_Line::ID()) ||
+         (theId == SketchPlugin_Point::ID()) ||
+         (theId == SketchPlugin_Arc::ID()) ||
+         (theId == SketchPlugin_Circle::ID());
 }
 
 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
@@ -694,11 +708,18 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
     myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
   }
   aDisplayer->updateViewer();
+  // all sketch objects should be activated in the sketch selection modes by edit operation start
+  if (theOperation->isEditOperation())
+    activateObjectsInSketchMode(true);
 }
 
 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
 {
   myIsMouseOverWindow = false;
+  myIsConstraintsShown = true;
+  // the objects activated in the sketch should be deactivated in order to do not have the specific
+  // sketch selection mode activated on objects in neutral point of the application(no started operation)
+  activateObjectsInSketchMode(false);
 
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
@@ -742,8 +763,12 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
   aDisplayer->updateViewer();
 }
 
-void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* )
+void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
 {
+  if (constraintsIdList().contains(theOperation->id())) {
+    // Show constraints if a constraint was created
+    onShowConstraintsToggle(true);
+  }
   connectToPropertyPanel(true);
 }
 
@@ -752,6 +777,10 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
   connectToPropertyPanel(false);
   myIsPropertyPanelValueChanged = false;
   myIsMouseOverViewProcessed = true;
+
+  // the sketch objects selection should be activated in order to select any sketch
+  // object
+  activateObjectsInSketchMode(true);
 }
 
 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
@@ -759,10 +788,6 @@ void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
   if (isNestedCreateOperation(theOperation))
     visualizeFeature(theOperation, true);
 
-  if (constraintsIdList().contains(theOperation->id())) {
-    // Show constraints if a constraint was created
-    onShowConstraintsToggle(true);
-  }
 }
 
 bool PartSet_SketcherMgr::canUndo() const
@@ -789,7 +814,7 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
       aCanDisplay = false;
   }
   else { // there are no an active sketch
-    // 2. sketch sub-features should not visualized if the sketch operatio is not active
+    // 2. sketch sub-features should not be visualized if the sketch operation is not active
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
     if (aFeature.get() != NULL) {
       std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
@@ -799,12 +824,34 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
     }
   }
 
-  // 3. For created nested feature operation do not display the created feature if
+  // 3. the method should not filter the objects, which are not related to the current operation.
+  // The object is filtered just if it is a current operation feature or this feature result
+  bool isObjectFound = false;
+  ModuleBase_Operation* anOperation = getCurrentOperation();
+  if (anOperation) {
+    FeaturePtr aFeature = anOperation->feature();
+    if (aFeature.get()) {
+      std::list<ResultPtr> aResults = aFeature->results();
+      if (theObject == aFeature)
+        isObjectFound = true;
+      else {
+        std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
+        for (; anIt != aLast; anIt++) {
+          isObjectFound = *anIt == theObject;
+        }
+      }
+    }
+  }
+  if (!isObjectFound)
+    return aCanDisplay;
+
+  // 4. For created nested feature operation do not display the created feature if
   // the mouse curstor leaves the OCC window.
   // The correction cases, which ignores this condition:
   // a. the property panel values modification
   // b. the popup menu activated
   // c. widget editor control
+  #ifndef DEBUG_DO_NOT_BY_ENTER
   if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
     ModuleBase_Operation* aOperation = getCurrentOperation();
     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
@@ -818,13 +865,33 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
       aCanDisplay = myIsPropertyPanelValueChanged || myIsMouseOverWindow;
     }
   }
+  #endif
   return aCanDisplay;
 }
 
+bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
+{
+  bool isFoundObject = false;
+
+  FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
+  if (anObjectFeature.get()) {
+    int aSize = myCurrentSketch->numberOfSubs();
+    for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
+      FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
+      isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
+    }
+  }
+  return isFoundObject;
+}
 
 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
 {
   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
+
+  // after the plane is selected in the sketch, the sketch selection should be activated
+  // it can not be performed in the sketch label widget because, we don't need to switch off
+  // the selection by any label deactivation, but need to switch it off by stop the sketch
+  activateObjectsInSketchMode(true);
 }
 
 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
@@ -985,6 +1052,10 @@ ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
                                            const bool isToDisplay)
 {
+  #ifdef DEBUG_DO_NOT_BY_ENTER
+  return;
+  #endif
+
   if (!theOperation || theOperation->isEditOperation())
     return;
 
@@ -1014,6 +1085,18 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
   aDisplayer->updateViewer();
 }
 
+void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive)
+{
+  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+  QIntList aModes;
+  if (isActive)
+    sketchSelectionModes(aModes);
+  aDisplayer->activateObjects(aModes);
+}
+
 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
 {
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();