Salome HOME
Merge branch 'BR_ADVANCED_CURRENT_FEATURE_MANAGEMENT' into Dev_1.5.0
authormpv <mpv@opencascade.com>
Mon, 12 Oct 2015 08:58:19 +0000 (11:58 +0300)
committermpv <mpv@opencascade.com>
Mon, 12 Oct 2015 08:58:19 +0000 (11:58 +0300)
16 files changed:
src/GeomAPI/GeomAPI_Pnt.cpp
src/GeomAPI/GeomAPI_Pnt.h
src/ModuleBase/ModuleBase_ISelection.cpp
src/ModuleBase/ModuleBase_ISelection.h
src/ModuleBase/ModuleBase_IViewer.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/NewGeom/NewGeom_SalomeViewer.cpp
src/NewGeom/NewGeom_SalomeViewer.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_Validators.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_ViewerProxy.h

index 0cf67c2ad7ae7c5b506b685c7fc17d66fac336ee..9138365cc1ec6c0fc5bc1ebe7986794d282a3c3b 100644 (file)
@@ -66,6 +66,11 @@ double GeomAPI_Pnt::distance(const std::shared_ptr<GeomAPI_Pnt>& theOther) const
   return MY_PNT->Distance(theOther->impl<gp_Pnt>());
 }
 
+bool GeomAPI_Pnt::isEqual(const std::shared_ptr<GeomAPI_Pnt>& theOther) const
+{
+  return distance(theOther) < Precision::Confusion();
+}
+
 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
   const std::shared_ptr<GeomAPI_Dir>& theDirX, const std::shared_ptr<GeomAPI_Dir>& theDirY)
 {
index a3016b94315ad794802fee6078735eea8d82de8a..17c2c0db81f000b8f5f4b1f0a4bf6be8aa2dadd7 100644 (file)
@@ -58,6 +58,10 @@ class GeomAPI_Pnt : public GeomAPI_Interface
   GEOMAPI_EXPORT 
   double distance(const std::shared_ptr<GeomAPI_Pnt>& theOther) const;
 
+  /// Returns whether the distance between two points is less then precision confusion
+  GEOMAPI_EXPORT 
+  bool isEqual(const std::shared_ptr<GeomAPI_Pnt>& theOther) const;
+
   /// Projects a point to the plane defined by the origin and 2 axes vectors in this plane
   GEOMAPI_EXPORT 
   std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
index cff9fa134ae48aa270437c0f5992c18fbc3f07b6..9eaf186dc4181b9e8f8a66016250f9fbdf7fef66 100644 (file)
@@ -2,6 +2,12 @@
 
 #include "ModuleBase_ISelection.h"
 
+#include <StdSelect_BRepOwner.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+#include <GeomAPI_Pnt.h>
+
 //********************************************************************
 void ModuleBase_ISelection::appendSelected(const QList<ModuleBase_ViewerPrs> theValues,
                                            QList<ModuleBase_ViewerPrs>& theValuesTo)
@@ -76,3 +82,60 @@ QList<ModuleBase_ViewerPrs> ModuleBase_ISelection::getViewerPrs(const QObjectPtr
   }
   return aSelectedPrs;
 }
+
+//********************************************************************
+void ModuleBase_ISelection::filterPreselectionOnEqualPoints
+                                              (QList<ModuleBase_ViewerPrs>& theSelected)
+{
+  QList<ModuleBase_ViewerPrs> aCandidatesToRemove;
+  QList<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(),
+                                              aLast = theSelected.end();
+  QList<ModuleBase_ViewerPrs>::const_iterator aSubIt;
+  for (; anIt != aLast; anIt++) {
+    aSubIt = anIt;
+    aSubIt++;
+    for (; aSubIt != aLast; aSubIt++) {
+      if (isEqualVertices(*anIt, *aSubIt)) {
+        aCandidatesToRemove.append(*aSubIt);
+        break;
+      }
+    }
+  }
+  QList<ModuleBase_ViewerPrs>::const_iterator aRemIt = aCandidatesToRemove.begin(),
+                                              aRemLast = aCandidatesToRemove.end();
+  for (; aRemIt != aRemLast; aRemIt++) {
+    theSelected.removeAll(*aRemIt);
+  }
+}
+
+bool ModuleBase_ISelection::isEqualVertices(const ModuleBase_ViewerPrs thePrs1,
+                                            const ModuleBase_ViewerPrs thePrs2)
+{
+  bool isEqual = false;
+  Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(thePrs1.owner());
+  Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs2.owner());
+
+  if (!anOwner1.IsNull() && anOwner1->HasShape() &&
+      !anOwner2.IsNull() && anOwner2->HasShape()) {
+    const TopoDS_Shape& aShape1 = anOwner1->Shape();
+    const TopoDS_Shape& aShape2 = anOwner2->Shape();
+    //TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+    if (aShape1.ShapeType() == TopAbs_VERTEX &&
+        aShape2.ShapeType() == TopAbs_VERTEX) {
+      const TopoDS_Vertex& aVertex1 = TopoDS::Vertex(aShape1);
+      const TopoDS_Vertex& aVertex2 = TopoDS::Vertex(aShape2);
+      if (!aVertex1.IsNull() && !aVertex2.IsNull())  {
+        gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1);
+        gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2);
+
+        std::shared_ptr<GeomAPI_Pnt> aPnt1 = std::shared_ptr<GeomAPI_Pnt>
+                        (new GeomAPI_Pnt(aPoint1.X(), aPoint1.Y(), aPoint1.Z()));
+        std::shared_ptr<GeomAPI_Pnt> aPnt2 = std::shared_ptr<GeomAPI_Pnt>
+                        (new GeomAPI_Pnt(aPoint2.X(), aPoint2.Y(), aPoint2.Z()));
+        isEqual = aPnt1->isEqual(aPnt2);
+      }
+    }
+  }
+
+  return isEqual;
+}
index 2c60a76ac05d98038825e48a222649d5ae2948fa..f7289bab76cd4b0306f7cabe14c23fc0110708d5 100644 (file)
@@ -107,6 +107,17 @@ class ModuleBase_ISelection
   //! \return a list of prs, where only object is not empty
   static MODULEBASE_EXPORT QList<ModuleBase_ViewerPrs> getViewerPrs(
                                                        const QObjectPtrList& theObjects);
+
+  /// Removes selection items where owners have equal vertices. The first
+  /// owner with the qual vertex stays in the list.
+  static MODULEBASE_EXPORT void filterPreselectionOnEqualPoints
+                                              (QList<ModuleBase_ViewerPrs>& theSelected);
+private:
+  /// Returns true if the presentations have an owner with a vertex and these vertices are equal.
+  /// \param thePrs1 the first viewer selected presentation
+  /// \param thePrs2 the second viewer selected presentation
+  static bool isEqualVertices(const ModuleBase_ViewerPrs thePrs1,
+                              const ModuleBase_ViewerPrs thePrs2);
 };
 
 #endif
index 7547d6c1f33ddb89ba67c065e9585ba3540af8e2..3c8f67653432a316a5c6534eb9243f81039c6713 100644 (file)
@@ -50,6 +50,9 @@ Q_OBJECT
   //! Returns true if multiselection is enabled
   virtual bool isMultiSelectionEnabled() const = 0;
 
+  //! Enable or disable draw mode in the viewer
+  virtual bool enableDrawMode(bool isEnabled) = 0;
+
   //! Perfroms the fit all for the active view
   virtual void fitAll() = 0;
 
index 97388529154b9daeb80fc0da22bc1e3d7e1b9b62..c6762043e1d8796f78cbf4725c80ee9200dc101f 100755 (executable)
@@ -275,6 +275,8 @@ void ModuleBase_OperationFeature::activateByPreselection()
   if (myPreSelection.empty())
     return;
 
+  ModuleBase_ISelection::filterPreselectionOnEqualPoints(myPreSelection);
+
   ModuleBase_ModelWidget* aFilledWgt = 0;
   ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
   if (aPropertyPanel) {
index 636abd69f2a5638603e1932edcad61801aa6da24..d8415b44788fca61d82fbc521d8d37a4ceee9030 100644 (file)
@@ -257,6 +257,7 @@ bool NewGeom_SalomeViewer::isSelectionEnabled() const
 {
   if (mySelector)
     return mySelector->viewer()->isSelectionEnabled();
+  return false;
 }
 
 //**********************************************
@@ -274,6 +275,15 @@ bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
   return false;
 }
 
+//**********************************************
+bool NewGeom_SalomeViewer::enableDrawMode(bool isEnabled)
+{
+  // TODO: Has to be replaced when SALOME patch become avialable
+  if (mySelector)
+    return mySelector->viewer()->enableDrawMode(isEnabled);
+  return false;
+}
+
 //**********************************************
 void NewGeom_SalomeViewer::fitAll()
 {
index 0635c89894fd9a3c4a0957cf1772f40c75d44eeb..ee250cae0e704739a7c5f8bd15ba22f6b4ae9b13 100644 (file)
@@ -91,6 +91,9 @@ Q_OBJECT
   //! Returns true if multiselection is enabled
   virtual bool isMultiSelectionEnabled() const;
 
+  //! Enable or disable draw mode in the viewer
+  virtual bool enableDrawMode(bool isEnabled);
+
   //! Perfroms the fit all for the active view
   virtual void fitAll();
 
index c1a80e4bdca5a275e0fdcae8e02711d7196da3e9..270877d4bad263c99fd0f089f621ffa5bcdf3961 100644 (file)
@@ -159,7 +159,7 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
 
-  myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
+  myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
 
   connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
           this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
@@ -205,7 +205,9 @@ void PartSet_SketcherMgr::onEnterViewPort()
 
   if (!isNestedCreateOperation(getCurrentOperation()))
     return;
-    operationMgr()->onValidateOperation();
+
+  QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
+  operationMgr()->onValidateOperation();
 
   // we need change displayed state of the current operation feature
   // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
@@ -240,6 +242,9 @@ void PartSet_SketcherMgr::onLeaveViewPort()
 
   if (!isNestedCreateOperation(getCurrentOperation()))
     return;
+
+  QApplication::restoreOverrideCursor();
+
   // the method should be performed if the popup menu is called,
   // the reset of the current widget should not happen
   if (myIsPopupMenuActive)
@@ -336,7 +341,6 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
 
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
-  myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
   if (!aViewer->canDragByMouse())
     return;
 
@@ -397,6 +401,8 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
       myIsDragging = true;
       get2dPoint(theWnd, theEvent, myCurrentPoint);
       myDragDone = false;
+      // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+      myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
       launchEditing();
       if (aFeature.get() != NULL) {
         std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
@@ -416,6 +422,8 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
       myIsDragging = true;
       get2dPoint(theWnd, theEvent, myCurrentPoint);
       myDragDone = false;
+      // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+      myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
 
       // This is necessary in order to finalize previous operation
       QApplication::processEvents();
@@ -453,7 +461,9 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
       }
     }
   }
-  aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
+      // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+  aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
+  //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
   myIsDragging = false;
 }
 
@@ -493,8 +503,10 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     // 2. the enable selection in the viewer should be temporary switched off in order to ignore
     // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
     // deselected). This flag should be restored in the slot, processed the mouse release signal.
-    ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
-    aViewer->enableSelection(false);
+
+    // TODO: Has to be commented out when SALOME patch on draw mode become avialable
+    //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
+    //aViewer->enableSelection(false);
 
     ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
     if (!aCurrentOperation)
@@ -919,7 +931,7 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
 {
   connectToPropertyPanel(true);
-  if (isNestedCreateOperation(theOperation))
+  if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
     QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
 }
 
index 94540d988989d647f1b27dae4973cb400cad7ebf..5e8a09597c69eb1b7fd3246f2c9ea76ad2ad1742 100644 (file)
@@ -294,7 +294,7 @@ private:
 private:
   PartSet_Module* myModule;
 
-  bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
+  bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
   bool myIsDragging;
   bool myDragDone;
   bool myIsResetCurrentValue; /// the state that value in the property panel is reset
index 02683b3554db08b7e313b0fcc5aefe045960ac4d..99468bcf043962bd3b78a489d98eb62eb1579ef1 100755 (executable)
@@ -39,6 +39,8 @@
 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
 {
   QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+  ModuleBase_ISelection::filterPreselectionOnEqualPoints(aList);
+
   int aCount = 0;
   foreach (ModuleBase_ViewerPrs aPrs, aList) {
     const TopoDS_Shape& aShape = aPrs.shape();
index a643ef5a898c71f8b2190d9ffc4e45938aacbe52..8cf826404cc2daf701f87c03f6b84c349c7ed537 100644 (file)
@@ -265,7 +265,7 @@ bool XGUI_OperationMgr::isParentOperationValid() const
 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
 {
   //in case of nested (sketch) operation no confirmation needed
-  if (isGrantedOperation(theOperation))
+  if (isGrantedOperation(theOperation->id()))
     return true;
   if (theOperation && theOperation->isModified()) {
     QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
@@ -293,7 +293,7 @@ void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
   theOperation->resume();
 }
 
-bool XGUI_OperationMgr::isGrantedOperation(ModuleBase_Operation* theOperation)
+bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
 {
   bool isGranted = false;
 
@@ -302,14 +302,14 @@ bool XGUI_OperationMgr::isGrantedOperation(ModuleBase_Operation* theOperation)
   ModuleBase_Operation* aPreviousOperation = 0;
   while (anIt.hasPrevious()) {
     ModuleBase_Operation* anOp = anIt.previous();
-    if (anOp == theOperation) {
+    if (anOp->id() == theId) {
       if (anIt.hasPrevious())
         aPreviousOperation = anIt.previous();
       break;
     }
   }
   if (aPreviousOperation)
-    isGranted = aPreviousOperation->isGranted(theOperation->id());
+    isGranted = aPreviousOperation->isGranted(theId);
 
   return isGranted;
 }
@@ -332,8 +332,20 @@ bool XGUI_OperationMgr::canStartOperation(const QString& theId, const bool isAdd
   ModuleBase_Operation* aCurrentOp = currentOperation();
   if (aCurrentOp) {
     bool aGranted = aCurrentOp->isGranted(theId) || isAdditionallyGranted;
-    if (!aGranted) {
-      if (canStopOperation(aCurrentOp)) {
+    // the started operation is granted for the current one,
+    // e.g. current - Sketch, started - Line
+    if (aGranted) {
+      aCanStart = true;
+    }
+    else {
+      if (!isGrantedOperation(theId)) {
+        // the operation is not granted in the current list of operations
+        // e.g. Edit Parameter when Sketch, Line in Sketch is active.
+        aCanStart = abortAllOperations();
+      }
+      else if (canStopOperation(aCurrentOp)) {
+        // the started operation is granted in the parrent operation,
+        // e.g. current - Line in Sketch, started Circle 
         if (myIsApplyEnabled && aCurrentOp->isModified())
           aCurrentOp->commit();
         else
index 4a9839b9a63865b8ff98e6ff75ede04a60892ee2..052aa86b5c9cd20e968337d7094251f750cdf298 100644 (file)
@@ -171,9 +171,9 @@ protected: // TEMPORARY
   /// Returns whether the parameter operation is granted in relation to the previous operation
   /// in a stack of started operations. It is used in canStopOperation to avoid warning message
   /// when granted operation is aborted, e.g. SketchLine in Sketch
-  /// \param theOperation the started operation
+  /// \param theId id of the operation which is checked
   /// \return boolean result
-  bool isGrantedOperation(ModuleBase_Operation* theOperation);
+  bool isGrantedOperation(const QString& theId);
 
   /// Sets the feature as a current in the document
   /// \param theFeature a feature
index 89b9461f51556a3e303bef2c6d36b7b6013b36ec..ab7695723b537203d7a3f62b8c002fdf9398c5bd 100644 (file)
@@ -166,23 +166,18 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
     activateWidget(NULL);
     return;
   }
-  ModuleBase_ModelWidget* aNextWidget = 0;
   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
   bool isFoundWidget = false;
   activateWindow();
-  for (; anIt != aLast && !aNextWidget; anIt++) {
+  for (; anIt != aLast; anIt++) {
     if (isFoundWidget || !theWidget) {
       if ((*anIt)->focusTo()) {
-        aNextWidget = *anIt;
+        return;
       }
     }
     isFoundWidget = (*anIt) == theWidget;
   }
-  // Normaly focusTo is enough to activate widget
-  // here is a special case on mouse click in the viewer
-  if(aNextWidget == NULL) {
-    activateWidget(aNextWidget);
-  }
+  activateWidget(NULL);
 }
 
 void XGUI_PropertyPanel::activateNextWidget()
index 293b9c0634ac8ee066bda81ecd6d2f9b32f481c2..955813a423b61bf8edfeb398ec3c4cb52bf60f51 100644 (file)
@@ -275,6 +275,16 @@ bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
   }
 }
 
+//***************************************
+bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
+{
+  if (myWorkshop->isSalomeMode()) {
+    return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
+  } else {
+    return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
+  }
+}
+
 //***************************************
 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
 {
index 64bc12fb81a05fc59fb6bf4215a0f373adface70..7362bbfa46a640f43c20be7719d7efa8b029d9f4 100644 (file)
@@ -44,6 +44,9 @@ Q_OBJECT
   //! Returns true if multiselection is enabled
   virtual bool isMultiSelectionEnabled() const;
 
+  //! Enable or disable draw mode in the viewer
+  virtual bool enableDrawMode(bool isEnabled);
+
   //! Sets the view projection
   /// \param theX the X projection value
   /// \param theY the Y projection value