Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Fri, 16 May 2014 14:09:02 +0000 (18:09 +0400)
committernds <natalia.donis@opencascade.com>
Fri, 16 May 2014 14:09:02 +0000 (18:09 +0400)
Edit for multi selection.

12 files changed:
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationEditLine.cpp
src/PartSet/PartSet_OperationEditLine.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h

index 17998703c234ef06343493c59074509beaaf792f..b68326fce668d0472901811ab5851c8841161ca6 100644 (file)
@@ -138,13 +138,7 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
                                        myWorkshop->operationMgr()->currentOperation());
   if (aPreviewOp)
   {
-    XGUI_SelectionMgr* aSelector = myWorkshop->selector();
-    std::list<XGUI_ViewerPrs> aPresentations;
-    if (aSelector) {
-      NCollection_List<TopoDS_Shape> aList;
-      aSelector->selectedShapes(aList);
-      aPresentations = myWorkshop->displayer()->GetViewerPrs(aList);
-    }
+    std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
     aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
   }
 }
@@ -155,13 +149,7 @@ void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
                                        myWorkshop->operationMgr()->currentOperation());
   if (aPreviewOp)
   {
-    XGUI_SelectionMgr* aSelector = myWorkshop->selector();
-    std::list<XGUI_ViewerPrs> aPresentations;
-    if (aSelector) {
-      NCollection_List<TopoDS_Shape> aList;
-      aSelector->selectedShapes(aList);
-      aPresentations = myWorkshop->displayer()->GetViewerPrs(aList);
-    }
+    std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
     aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
   }
 }
@@ -196,7 +184,8 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<Mo
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp)
   {
-    aPreviewOp->init(theFeature);
+    std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
+    aPreviewOp->init(theFeature, aPresentations);
   }
   myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true);
   sendOperation(anOperation);
@@ -208,12 +197,6 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
   aViewer->enableMultiselection(theEnabled);
 }
 
-void PartSet_Module::onSelectionEnabled(bool theEnabled)
-{
-  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
-  aViewer->enableSelection(theEnabled);
-}
-
 void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
                                           int theMode)
 {
@@ -264,8 +247,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
             this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
     connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
             this, SLOT(onMultiSelectionEnabled(bool)));
-    connect(aPreviewOp, SIGNAL(selectionEnabled(bool)),
-            this, SLOT(onSelectionEnabled(bool)));
 
     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
     if (aSketchOp) {
index 14a418d01435fbb58e037a7af0e375118edf6265..86c2d95f6b38ed99599461e1907e740b96b9813f 100644 (file)
@@ -83,10 +83,6 @@ public slots:
   /// \param theEnabled the enabled state
   void onMultiSelectionEnabled(bool theEnabled);
 
-  /// SLOT, to switch on/off the selection in the viewer
-  /// \param theEnabled the enabled state
-  void onSelectionEnabled(bool theEnabled);
-
   /// SLOT, to visualize the feature in another local context mode
   /// \param theFeature the feature to be put in another local context mode
   /// \param theMode the mode appeared on the feature
index f0049b007d46a956a908173655af8fda6266e2f6..ee98295b559a7ecd20acfae51997448bf5174143 100644 (file)
@@ -48,9 +48,11 @@ std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<Mo
   return aModes;
 }
 
-void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                     const std::list<XGUI_ViewerPrs>& thePresentations)
 {
   setFeature(theFeature);
+  myFeatures = thePresentations;
 }
 
 void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
@@ -66,6 +68,7 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie
 {
   if (!(theEvent->buttons() &  Qt::LeftButton))
     return;
+
   gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
 
   if (myCurPoint.myIsInitialized) {
@@ -81,14 +84,14 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie
     moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START);
     moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END);
 
-    /*std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
+    std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
     for (; anIt != aLast; anIt++) {
       boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
-      if (!aFeature)
+      if (!aFeature || aFeature == feature())
         continue;
       moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
       moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END);
-    }*/
+    }
   }
   myCurPoint.setPoint(aPoint);
 }
@@ -96,28 +99,41 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie
 void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
                                               const std::list<XGUI_ViewerPrs>& theSelected)
 {
-  boost::shared_ptr<ModelAPI_Feature> aFeature;
-  if (!theSelected.empty())
-    aFeature = theSelected.front().feature();
-  
-  if (aFeature == feature())
-    return;
+  std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
+  if (myFeatures.size() == 1) {
+    boost::shared_ptr<ModelAPI_Feature> aFeature;
+    if (!theSelected.empty())
+      aFeature = theSelected.front().feature();
+
+    if (aFeature == feature())
+      return;
   
-  commit();
-  if (aFeature)
-    emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+   commit();
+   if (aFeature)
+     emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+  }
+  else {
+    commit();
+    std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+    for (; anIt != aLast; anIt++) {
+      boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
+      if (aFeature)
+        emit featureConstructed(aFeature, FM_Deactivation);
+    }
+  }
 }
 
 void PartSet_OperationEditLine::startOperation()
 {
   // do nothing in order to do not create a new feature
-  emit selectionEnabled(false);
+  emit multiSelectionEnabled(false);
   myCurPoint.clear();
 }
 
 void PartSet_OperationEditLine::stopOperation()
 {
-  emit selectionEnabled(true);
+  emit multiSelectionEnabled(true);
+  myFeatures.clear();
 }
 
 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
index 826a5f9aedf77a4132e8dcf6fc3d94db16e2a0fc..58b911b261e0663b0dbe67c48b8b2de456edd1e5 100644 (file)
@@ -71,7 +71,9 @@ public:
 
   /// Initializes some fields accorging to the feature
   /// \param theFeature the feature
-  virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
+  /// \param thePresentations the list of additional presentations
+  virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                    const std::list<XGUI_ViewerPrs>& thePresentations);
 
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
@@ -116,6 +118,7 @@ protected:
 
 private:
   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+  std::list<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
   Point myCurPoint; ///< the current 3D point clicked or moved
   gp_Pnt myCurPressed; ///< the current 3D point clicked or moved
 };
index bcbbf15719214015b0d593b40ac521c71b0f665e..d96ddc4ac7013029f350eea6f459aee2a2045f0e 100644 (file)
@@ -67,6 +67,13 @@ void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_Vi
       myIsEditMode = true;
     }
   }
+  else {
+    if (theSelected.size() == 1) {
+      boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
+      if (aFeature)
+        emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+    }
+  }
 }
 
 void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
@@ -75,10 +82,12 @@ void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View)
   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);
+  if (theSelected.size() != 1) {
+    boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
+                                                                theView, feature(), theSelected);
+    if (aFeature)
+      emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+  }
 }
 
 std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
index cce1c55113f1b99362c47e0bce2efdc500d42f18..ad6886c330a9e951974e860d7814240797429d39 100644 (file)
@@ -56,7 +56,9 @@ public:
 
   /// Initializes some fields accorging to the feature
   /// \param theFeature the feature
-  virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature) {}
+  /// \param thePresentations the list of additional presentations
+  virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                    const std::list<XGUI_ViewerPrs>& thePresentations) {}
 
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
@@ -95,10 +97,6 @@ signals:
   /// \param theEnabled the boolean state
   void multiSelectionEnabled(bool theEnabled);
 
-  /// signal to enable/disable usual selection in the viewer
-  /// \param theEnabled the boolean state
-  void selectionEnabled(bool theEnabled);
-
 protected:
   /// Creates an operation new feature
   /// In addition to the default realization it appends the created line feature to
index ba194d6ba7aa1c03f324d28f31ba363f49e29fac..5d456d875352b8678095b66598dbf35b2b32ebb8 100644 (file)
@@ -65,7 +65,8 @@ std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<
   return aModes;
 }
 
-void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                       const std::list<XGUI_ViewerPrs>& /*thePresentations*/)
 {
   if (!theFeature)
     return;
index b048ef8a7b451dc018878adf551a88a37d0a41af..f6a281c6391c7438e04bf1390a59fe7dd3b127d1 100644 (file)
@@ -46,7 +46,9 @@ public:
 
   /// Initializes some fields accorging to the feature
   /// \param theFeature the feature
-  virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
+  /// \param thePresentations the list of additional presentations
+  virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                    const std::list<XGUI_ViewerPrs>& thePresentations);
 
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
index 8daeaa9ed808efd4c3aeae18401926ebb719fa55..ee091f19be1e4cfda61724f991f58920a1ad3097 100644 (file)
@@ -6,6 +6,7 @@
 #include "XGUI_Viewer.h"
 #include "XGUI_Workshop.h"
 #include "XGUI_ViewerProxy.h"
+#include "XGUI_Tools.h"
 
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Data.h>
@@ -16,6 +17,8 @@
 
 #include <AIS_Shape.hxx>
 
+#include <set>
+
 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
 {
   myWorkshop = theWorkshop;
@@ -35,7 +38,7 @@ void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
 {
 }
 
-void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
+/*void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
                              const TopoDS_Shape& theShape, const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
@@ -46,39 +49,32 @@ void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
   aContext->Display(anAIS, Standard_False);
   if (isUpdateViewer)
     aContext->UpdateCurrentViewer();
-}
+}*/
 
-boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(const TopoDS_Shape& theShape)
-{
-  boost::shared_ptr<ModelAPI_Feature> aFeature;
 
-  FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
-                                  aFLast = myFeature2AISObjectMap.end();
-  for (; aFIt != aFLast && !aFeature; aFIt++)
-  {
-    Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
-    Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
-    if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) {
-      aFeature = (*aFIt).first;
-    }
-  }
-  return aFeature;
-}
-
-std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs
-                                                (const NCollection_List<TopoDS_Shape>& theShapes)
+std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs()
 {
+  std::set<boost::shared_ptr<ModelAPI_Feature> > aPrsFeatures;
   std::list<XGUI_ViewerPrs> aPresentations;
-  if (theShapes.IsEmpty())
-    return aPresentations;
 
-  NCollection_List<TopoDS_Shape>::Iterator anIt(theShapes);
-  for (; anIt.More(); anIt.Next()) {
-    const TopoDS_Shape& aShape = anIt.Value();
-    if (aShape.IsNull())
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+    Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
+    TopoDS_Shape aShape = aContext->SelectedShape();
+
+    boost::shared_ptr<ModelAPI_Feature> aFeature;
+    FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
+                                    aFLast = myFeature2AISObjectMap.end();
+    for (; aFIt != aFLast && !aFeature; aFIt++) {
+      Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
+      if (anAIS != anIO)
+        continue;
+      aFeature = (*aFIt).first;
+    }
+    if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
       continue;
-    boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(aShape);
     aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+    aPrsFeatures.insert(aFeature);
   }
 
   return aPresentations;
@@ -119,8 +115,18 @@ void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature>
   if (IsVisible(theFeature)) {
     anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
     if (!anAIS.IsNull()) {
+      // if the AIS object is displayed in the opened local context in some mode, additional
+      // AIS sub objects are created there. They should be rebuild for correct selecting.
+      // It is possible to correct it by closing local context before the shape set and opening
+      // after. Another workaround to thrown down the selection and reselecting the AIS.
+      // If there was a problem here, try the first solution with close/open local context.
       anAIS->Set(theShape);
       anAIS->Redisplay();
+      if (aContext->IsSelected(anAIS)) {
+        aContext->AddOrRemoveSelected(anAIS, false);
+        aContext->AddOrRemoveSelected(anAIS, false);
+        //aContext->SetSelected(anAIS, false);
+      }
     }
   }
   else {
index c03157885da2ed2e51c5720b07e774aef2371fc0..118d7268efa368d930ab283df9663eec5c87a59d 100644 (file)
@@ -55,17 +55,12 @@ public:
   /// \param theFeature a feature instance
   /// \param theShape a shape
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
-  void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
-               const bool isUpdateViewer = true);
+  //void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
+  //             const bool isUpdateViewer = true);
   
-  /// Returns the feature, that was displayed with this shape
-  /// \param theShape a shape
-  boost::shared_ptr<ModelAPI_Feature> GetFeature(const TopoDS_Shape& theShape);
-
   /// Returns a list of viewer presentations
-  /// \param theShapes list of shapes to find corresponded features
   /// \return list of presentations
-  std::list<XGUI_ViewerPrs> GetViewerPrs(const NCollection_List<TopoDS_Shape>& theShapes);
+  std::list<XGUI_ViewerPrs> GetViewerPrs();
 
   /// Display the shape and activate selection of sub-shapes
   /// \param theFeature a feature instance
index 77c38599d99f9c8115ea40727e9c39068b6c130e..9626802992c2a4a2cfa159be26b8b4e6c66d977e 100644 (file)
@@ -1,7 +1,13 @@
 #include "XGUI_Tools.h"
 
+#include <TopoDS_Shape.hxx>
+#include <ModelAPI_Feature.h>
+
 #include <QDir>
 
+#include <iostream>
+#include <sstream>
+
 //******************************************************************
 QString dir(const QString& path, bool isAbs)
 {
@@ -46,3 +52,13 @@ QRect makeRect(const int x1, const int y1, const int x2, const int y2)
 {
   return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1));
 }
+
+//******************************************************************
+std::string featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  std::ostringstream aStream; 
+  if (theFeature)
+    aStream << theFeature.get();
+  return QString(aStream.str().c_str()).toStdString();
+}
+
index aebea7f6e37aed046c4d07e0369cb6986248bcd6..5c8be08e85065d082c519e782efa1056285032ac 100644 (file)
@@ -5,6 +5,10 @@
 #include <QString>
 #include <QRect>
 
+#include <boost/shared_ptr.hpp>
+
+class TopoDS_Shape;
+class ModelAPI_Feature;
 /*!
  \brief Return directory part of the file path.
 
@@ -52,4 +56,9 @@ QString XGUI_EXPORT addSlash(const QString& path);
  */
 QRect XGUI_EXPORT makeRect(const int x1, const int y1, const int x2, const int y2);
 
+/*!
+ Returns the string presentation of the given feature
+ \param theFeature a feature
+*/
+std::string XGUI_EXPORT featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature);
 #endif