]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Mon, 19 May 2014 14:17:59 +0000 (18:17 +0400)
committernds <natalia.donis@opencascade.com>
Mon, 19 May 2014 14:17:59 +0000 (18:17 +0400)
Separation of AIS objects activation in the local selection from the feature display/redisplay

src/PartSet/PartSet_Listener.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationEditLine.cpp
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Tools.cpp

index b97b34f8ef4857039f2ae1adee119cd9f30da82a..9379735429ef24159a7fd121fd62d4e86a61a4fe 100644 (file)
@@ -40,8 +40,12 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage)
     const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
     boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
     if (myModule->workshop()->displayer()->IsVisible(aFeature) ||
-        aType == EVENT_FEATURE_CREATED)
-      myModule->visualizePreview(aFeature, true);
+        aType == EVENT_FEATURE_CREATED) {
+      myModule->visualizePreview(aFeature, true, false);
+      if (aType == EVENT_FEATURE_CREATED)
+        myModule->activateFeature(aFeature, true);
+      myModule->workshop()->displayer()->UpdateViewer();
+    }
   }
   if (aType == EVENT_FEATURE_DELETED)
   {
index 08b5bf2b66300052cd2a920d498e0d3f78ab64ca..24d9044fae631352226bde41dbbebe6ba8097821 100644 (file)
@@ -195,11 +195,21 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
   aViewer->enableMultiselection(theEnabled);
 }
 
+void PartSet_Module::onStopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop)
+{
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  aDisplayer->StopSelection(theFeatures, isStop);
+  
+}
+
 void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
                                           int theMode)
 {
   bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Abort;
-  visualizePreview(theFeature, isDisplay);
+  visualizePreview(theFeature, isDisplay, false);
+
+  if (theMode == FM_Activation || theMode == FM_Deactivation)
+    activateFeature(theFeature, true);
 }
 
 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId)
@@ -246,6 +256,11 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
     connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
             this, SLOT(onMultiSelectionEnabled(bool)));
 
+    connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
+            this, SLOT(onMultiSelectionEnabled(bool)));
+    connect(aPreviewOp, SIGNAL(stopSelection(const std::list<XGUI_ViewerPrs>&, const bool)),
+            this, SLOT(onStopSelection(const std::list<XGUI_ViewerPrs>&, const bool)));
+
     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
     if (aSketchOp) {
       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
@@ -265,7 +280,8 @@ void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
   Events_Loop::loop()->send(aMessage);
 }
 
-void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay)
+void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+                                      const bool isUpdateViewer)
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   if (!anOperation)
@@ -278,13 +294,25 @@ void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFea
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (isDisplay) {
     boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
-    aDisplayer->RedisplayInLocalContext(theFeature,
-                                        aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
-                                        aPreviewOp->getSelectionModes(theFeature));
+    aDisplayer->Redisplay(theFeature,
+                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
   }
-  else {
-    //aDisplayer->CloseLocalContexts(false);
-    aDisplayer->Erase(anOperation->feature());
+  else
+    aDisplayer->Erase(anOperation->feature(), false);
+
+  if (isUpdateViewer)
+    aDisplayer->UpdateViewer();
+}
+
+void PartSet_Module::activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                     const bool isUpdateViewer)
+{
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+  if (aPreviewOp) {
+    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+    aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
+                                       isUpdateViewer);
   }
 }
 
@@ -312,9 +340,9 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
   for (; anIt != aLast; anIt++) {
     boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
     boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
-    aDisplayer->RedisplayInLocalContext(aFeature,
-                                        aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
-                                        aModes, false);
+    aDisplayer->Redisplay(aFeature,
+                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+    aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
   }
   aDisplayer->UpdateViewer();
 }
index 86c2d95f6b38ed99599461e1907e740b96b9813f..cba0367e6b4a245fcd7cd40e4f6b5ee5fdf8eb2a 100644 (file)
@@ -17,6 +17,7 @@ class QMouseEvent;
 class QKeyEvent;
 class PartSet_Listener;
 class ModelAPI_Feature;
+class XGUI_ViewerPrs;
 
 class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
 {
@@ -40,9 +41,17 @@ public:
   virtual void launchOperation(const QString& theCmdId);
 
   /// Displays or erase the current operation preview, if it has it.
-  /// \param theF
+  /// \param theFeature the feature instance to be displayed
   /// \param isDisplay the state whether the presentation should be displayed or erased
-  void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay);
+  /// \param isUpdateViewer the flag whether the viewer should be updated
+  void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+                        const bool isUpdateViewer = true);
+
+  /// Activates the feature in the displayer
+  /// \param theFeature the feature instance to be displayed
+  /// \param isUpdateViewer the flag whether the viewer should be updated
+  void activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                       const bool isUpdateViewer);
 
   /// Updates current operation preview, if it has it.
   /// \param theCmdId the operation name
@@ -83,6 +92,11 @@ public slots:
   /// \param theEnabled the enabled state
   void onMultiSelectionEnabled(bool theEnabled);
 
+  /// SLOT, to stop or start selection for the features
+  /// \param theFeatures a list of features to be disabled
+  /// \param theToStop the boolean state whether it it stopped or non stopped
+  void onStopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop);
+
   /// 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 c9fbbfd8692b7f271fcf8ee81bfcf29301b66e29..2c39948d759ffd3a1dc3829e879fde5a4e39cac0 100644 (file)
@@ -43,9 +43,9 @@ bool PartSet_OperationEditLine::isGranted() const
 std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
   std::list<int> aModes;
-  aModes.push_back(TopAbs_VERTEX);
-  aModes.push_back(TopAbs_EDGE);
+  aModes.push_back(-1);
   return aModes;
+  //return PartSet_OperationSketchBase::getSelectionModes(theFeature);
 }
 
 void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
@@ -126,12 +126,14 @@ void PartSet_OperationEditLine::startOperation()
 {
   // do nothing in order to do not create a new feature
   emit multiSelectionEnabled(false);
+  emit stopSelection(myFeatures, true);
   myCurPoint.clear();
 }
 
 void PartSet_OperationEditLine::stopOperation()
 {
   emit multiSelectionEnabled(true);
+  emit stopSelection(myFeatures, false);
   myFeatures.clear();
 }
 
index be977401bd73b9edfdc20fb388831a478145678c..3bb916fab0926f66e023cdf65286d2bf88461962 100644 (file)
@@ -46,10 +46,8 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
   std::list<int> aModes;
   if (!myIsEditMode)
     aModes.push_back(TopAbs_FACE);
-  else {
-    aModes.push_back(TopAbs_VERTEX);
-    aModes.push_back(TopAbs_EDGE);
-  }
+  else
+    aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
   return aModes;
 }
 
index 9eac6c82afb55df6867d81a97dffc5918aa593a7..3412a2e19bb8473595dfe3792fbbc3e6187db1c6 100644 (file)
@@ -38,6 +38,13 @@ std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
   return std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >();
 }
 
+std::list<int> PartSet_OperationSketchBase::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
+{
+  std::list<int> aModes;
+  aModes.push_back(TopAbs_VERTEX);
+  aModes.push_back(TopAbs_EDGE);
+  return aModes;
+}
 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature()
 {
   boost::shared_ptr<ModelAPI_Feature> aFeature = ModuleBase_Operation::createFeature();
index 62de3116be461513ee152639edc724378ec645e6..4fb941df9784f9af42e88024506c17e7ad76b232 100644 (file)
@@ -100,6 +100,11 @@ signals:
   /// \param theEnabled the boolean state
   void multiSelectionEnabled(bool theEnabled);
 
+  /// signal to enable/disable selection in the viewer
+  /// \param theFeatures a list of features to be disabled
+  /// \param theToStop the boolean state whether it it stopped or non stopped
+  void stopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool theToStop);
+
   /// signal to enable/disable usual selection in the viewer
   /// \param theEnabled the boolean state
   void selectionEnabled(bool theEnabled);
index a4e09b856709ad111794076adcf63f58d1be2069..0b05a8ef9a6393bbe7c800f1a6cf101298e5f6a3 100644 (file)
@@ -58,10 +58,7 @@ std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<
 {
   std::list<int> aModes;
   if (theFeature != feature())
-  {
-    aModes.push_back(TopAbs_VERTEX);
-    aModes.push_back(TopAbs_EDGE);
-  }
+    aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
   return aModes;
 }
 
index ee091f19be1e4cfda61724f991f58920a1ad3097..cbfb9413cfb483fecdb4a6cda6d64873be08c666 100644 (file)
@@ -99,16 +99,14 @@ void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
     aContext->UpdateCurrentViewer();
 }
 
-void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                             const TopoDS_Shape& theShape,
-                                             const std::list<int>& theModes, const bool isUpdateViewer)
+void XGUI_Displayer::Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                               const TopoDS_Shape& theShape, const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
   // Open local context if there is no one
   if (!aContext->HasOpenedContext()) {
     aContext->ClearCurrents(false);
-    aContext->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
-                         true/*allow shape decomposition*/);
+    aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
   }
   // display or redisplay presentation
   Handle(AIS_Shape) anAIS;
@@ -122,11 +120,11 @@ void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature>
       // If there was a problem here, try the first solution with close/open local context.
       anAIS->Set(theShape);
       anAIS->Redisplay();
-      if (aContext->IsSelected(anAIS)) {
+      /*if (aContext->IsSelected(anAIS)) {
         aContext->AddOrRemoveSelected(anAIS, false);
         aContext->AddOrRemoveSelected(anAIS, false);
         //aContext->SetSelected(anAIS, false);
-      }
+      }*/
     }
   }
   else {
@@ -134,20 +132,82 @@ void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature>
     myFeature2AISObjectMap[theFeature] = anAIS;
     aContext->Display(anAIS, false);
   }
+}
+
+void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                         const std::list<int>& theModes, const bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  // Open local context if there is no one
+  if (!aContext->HasOpenedContext()) {
+    aContext->ClearCurrents(false);
+    aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
+  }
+  // display or redisplay presentation
+  Handle(AIS_Shape) anAIS;
+  if (IsVisible(theFeature))
+    anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
+  //if (!anAIS.IsNull())
+  //  return;
+
   // Activate selection of objects from prs
   if (!anAIS.IsNull()) {
-    aContext->Load(anAIS, -1, true/*allow decomposition*/);
+       aContext->Load(anAIS, -1, true/*allow decomposition*/);
+    aContext->Deactivate(anAIS);
+
     std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
+    QString aDebugStr = QString(featureInfo(theFeature).c_str()) + QString("; modes: ");
     for (; anIt != aLast; anIt++)
     {
       aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
-    }
+         aDebugStr += QString("%1").arg(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt)) + QString(", ");
+       }
+    /*if (theModes.empty()) {
+      aContext->Deactivate(anAIS);
+      aContext->Activate(anAIS, -1);
+         aContext->ClearSelected();
+         aDebugStr += " deactivated";
+         QColor aColor(Qt::white);
+         anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+       }*/
+       qDebug(aDebugStr.toStdString().c_str());
   }
 
   if (isUpdateViewer)
     aContext->UpdateCurrentViewer();
 }
 
+void XGUI_Displayer::StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop)
+{
+  return;
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+
+  Handle(AIS_Shape) anAIS;
+  std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+  boost::shared_ptr<ModelAPI_Feature> aFeature;
+  for (; anIt != aLast; anIt++) {
+    aFeature = (*anIt).feature();
+    if (IsVisible(aFeature))
+      anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]);
+    if (anAIS.IsNull())
+      continue;
+
+    if (isStop) {
+      aContext->Deactivate(anAIS);
+      aContext->Activate(anAIS, -1);
+      aContext->ClearSelected();
+      
+      //aDebugStr += " deactivated";
+      QColor aColor(Qt::white);
+      anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+    }
+    else {
+      //QColor aColor(Qt::red);
+      //anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+    }
+  }
+}
+
 void XGUI_Displayer::EraseAll(const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) ic = AISContext();
index 118d7268efa368d930ab283df9663eec5c87a59d..5e0b334e5bc0fd250119468c936987afae28edad 100644 (file)
@@ -67,9 +67,21 @@ public:
   /// \param theShape a shape
   /// \param theMode a local selection mode
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
-  void RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                             const TopoDS_Shape& theShape,
-                             const std::list<int>& theMode, const bool isUpdateViewer = true);
+  void Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                             const TopoDS_Shape& theShape, const bool isUpdateViewer = true);
+
+  /// Display the shape and activate selection of sub-shapes
+  /// \param theFeature a feature instance
+  /// \param theShape a shape
+  /// \param theMode a list of local selection modes
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                              const std::list<int>& theModes, const bool isUpdateViewer = true);
+
+  /// Stop the current selection and color the given features to the selection color
+  /// \param theFeatures a list of features to be disabled
+  /// \param theToStop the boolean state whether it it stopped or non stopped
+  void StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop);
 
   /// Erase the feature and a shape.
   /// \param theFeature a feature instance
@@ -106,4 +118,5 @@ protected:
   FeatureToAISMap myFeature2AISObjectMap;
 };
 
+
 #endif
index 9626802992c2a4a2cfa159be26b8b4e6c66d977e..8ce0a36ac0bcb25349a31bd518513a43d995496f 100644 (file)
@@ -58,7 +58,7 @@ std::string featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature)
 {
   std::ostringstream aStream; 
   if (theFeature)
-    aStream << theFeature.get();
+    aStream << theFeature.get() << " " << theFeature->getKind();
   return QString(aStream.str().c_str()).toStdString();
 }