]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 20 May 2014 07:25:49 +0000 (11:25 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 20 May 2014 07:25:49 +0000 (11:25 +0400)
19 files changed:
src/ModuleBase/ModuleBase_IOperation.cpp
src/ModuleBase/ModuleBase_IOperation.h
src/PartSet/PartSet_Listener.cpp
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_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/SketchPlugin/SketchPlugin_Feature.cpp
src/SketchPlugin/SketchPlugin_Feature.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_Tools.cpp

index 9a14779c65ab395f6e6d33ee6f6c36a86d03bacb..6853d0d70a27a9f3106c9423e98831c824e10ab7 100644 (file)
@@ -31,7 +31,7 @@ ModuleBase_OperationDescription* ModuleBase_IOperation::getDescription() const
   return myDescription;
 }
 
-bool ModuleBase_IOperation::isGranted() const
+bool ModuleBase_IOperation::isGranted(ModuleBase_IOperation* /*theOperation*/) const
 {
   return false;
 }
index 6b75e7eca17599ca16b3115e908d700572744d01..966d2668104c3d8f55f8602b20e01e36b3f67ce2 100644 (file)
@@ -61,7 +61,8 @@ public:
   /// must be always can start above any launched one. Default impl returns FALSE,
   /// so it is being checked for IsValid, but some operations may overload IsGranted()
   /// In this case they will always start, no matter what operation is running.
-  virtual bool isGranted() const;
+  /// \param theOperation the previous running operation
+  virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
 
 signals:
   void started(); /// the operation is started
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 99806f4621d20ca6223e8cc7dd6779e1542f9b87..f3d1113353700fd328aec98a106fc1cf37ca771d 100644 (file)
@@ -195,11 +195,36 @@ 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();
+  if (!isStop) {
+    std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+    boost::shared_ptr<ModelAPI_Feature> aFeature;
+    for (; anIt != aLast; anIt++) {
+      activateFeature((*anIt).feature(), false);
+    }
+  }
+  aDisplayer->StopSelection(theFeatures, isStop, false);
+  aDisplayer->UpdateViewer();
+}
+
+void PartSet_Module::onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures)
+{
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  aDisplayer->SetSelected(theFeatures, false);
+  aDisplayer->UpdateViewer();
+}
+
 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 == PartSet_OperationSketchBase::FM_Activation ||
+      theMode == PartSet_OperationSketchBase::FM_Deactivation)
+    activateFeature(theFeature, true);
 }
 
 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId)
@@ -222,13 +247,14 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   else if(theCmdId == PartSet_OperationSketchLine::Type() ||
           theCmdId == PartSet_OperationEditLine::Type()) {
     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
-    boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
-    if (aCurOperation)
-      aSketchFeature = aCurOperation->feature();
+    boost::shared_ptr<ModelAPI_Feature> aSketch;
+    PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
+    if (aPrevOp)
+      aSketch = aPrevOp->sketch();
     if (theCmdId == PartSet_OperationSketchLine::Type())
-      anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketchFeature);
+      anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
     else
-      anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketchFeature);
+      anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
   }
   else {
     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
@@ -246,6 +272,13 @@ 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)));
+    connect(aPreviewOp, SIGNAL(setSelection(const std::list<XGUI_ViewerPrs>&)),
+            this, SLOT(onSetSelection(const std::list<XGUI_ViewerPrs>&)));
+
     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
     if (aSketchOp) {
       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
@@ -265,7 +298,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 +312,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 +358,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 0c9e72a4a44b15d20a5fe6f671868d90061668ca..acd5502572b839c9a9db9448fe6109b1aa7071fd 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,15 @@ public slots:
   /// \param theEnabled the enabled state
   void onMultiSelectionEnabled(bool theEnabled);
 
+  /// SLOT, to stop or start selection mode 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 set selection
+  /// \param theFeatures a list of features to be selected
+  void onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures);
+
   /// 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..5383e0d493393863abec6cb728bed0cf49a156d6 100644 (file)
@@ -4,6 +4,9 @@
 
 #include <PartSet_OperationEditLine.h>
 #include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
+
+#include <ModuleBase_OperationDescription.h>
 
 #include <XGUI_ViewerPrs.h>
 
@@ -35,17 +38,14 @@ PartSet_OperationEditLine::~PartSet_OperationEditLine()
 {
 }
 
-bool PartSet_OperationEditLine::isGranted() const
+bool PartSet_OperationEditLine::isGranted(ModuleBase_IOperation* theOperation) const
 {
-  return true;
+  return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
 }
 
 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);
-  return aModes;
+  return PartSet_OperationSketchBase::getSelectionModes(theFeature);
 }
 
 void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
@@ -55,6 +55,11 @@ void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeat
   myFeatures = thePresentations;
 }
 
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
+{
+  return mySketch;
+}
+
 void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
 {
   if (!(theEvent->buttons() &  Qt::LeftButton))
@@ -72,10 +77,10 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie
 
   if (myCurPoint.myIsInitialized) {
     double aCurX, aCurY;
-    PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY);
+    PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
 
     double aX, anY;
-    PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+    PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
 
     double aDeltaX = aX - aCurX;
     double aDeltaY = anY - aCurY;
@@ -100,16 +105,12 @@ void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_
 {
   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())
+    if (theSelected.empty())
       return;
-  
-   commit();
-   if (aFeature)
-     emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+
+    boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
+    commit();
+    emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
   }
   else {
     commit();
@@ -126,12 +127,19 @@ void PartSet_OperationEditLine::startOperation()
 {
   // do nothing in order to do not create a new feature
   emit multiSelectionEnabled(false);
+  emit setSelection(std::list<XGUI_ViewerPrs>());
+  emit stopSelection(myFeatures, true);
   myCurPoint.clear();
 }
 
 void PartSet_OperationEditLine::stopOperation()
 {
   emit multiSelectionEnabled(true);
+  bool isSelectFeatures = myFeatures.size() > 1;
+  emit stopSelection(myFeatures, false);
+  if (isSelectFeatures)
+    emit setSelection(myFeatures);
+
   myFeatures.clear();
 }
 
index 0c225f2f2b0fd2661e66aef6d94941c6d3a7833d..5f447c7305bcd7425703b13458c92b7c85453fdf 100644 (file)
@@ -60,9 +60,10 @@ public:
   /// Destructor
   virtual ~PartSet_OperationEditLine();
 
-   /// Returns that this operator can be started above already running one.
-   /// The runned operation should be the sketch feature modified operation
-  virtual bool isGranted() const;
+  /// Returns that this operator can be started above already running one.
+  /// The runned operation should be the sketch feature modified operation
+  /// \param theOperation the previous running operation
+  virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
 
   /// Returns the operation local selection mode
   /// \param theFeature the feature object to get the selection mode
@@ -75,6 +76,10 @@ public:
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
                     const std::list<XGUI_ViewerPrs>& thePresentations);
 
+  /// Returns the operation sketch feature
+  /// \returns the sketch instance
+  virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index be977401bd73b9edfdc20fb388831a478145678c..4c4aa241db6b01c3237c72cf9789ec955f7ed7ca 100644 (file)
@@ -46,13 +46,16 @@ 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;
 }
 
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketch::sketch() const
+{
+  return feature();
+}
+
 void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
                                            const std::list<XGUI_ViewerPrs>& theSelected)
 {
index 162627c5623a4e350585943c8873663f9f484849..e964939d4607c2b2c930fec8224a500fb949731c 100644 (file)
@@ -34,6 +34,10 @@ public:
   /// \return the selection mode
   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
+  /// Returns the operation sketch feature
+  /// \returns the sketch instance
+  virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index 0dd6efc9010b01e96c3d97acbc3cdaa4dc20dc82..997a96b1217e16b3d1e5dd55e0b530e7b589eac8 100644 (file)
@@ -5,7 +5,7 @@
 #include <PartSet_OperationSketchBase.h>
 
 #include <SketchPlugin_Feature.h>
-#include <Model_Object.h>
+#include <ModelAPI_Object.h>
 
 #include <V3d_View.hxx>
 
@@ -31,8 +31,8 @@ boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
   boost::shared_ptr<SketchPlugin_Feature> aFeature = 
                               boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
   if (!aFeature) { // if it is reference to a object feature
-    boost::shared_ptr<Model_Object> anObj = 
-      boost::dynamic_pointer_cast<Model_Object>(theFeature);
+    boost::shared_ptr<ModelAPI_Object> anObj = 
+      boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
     if (anObj) 
       aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(anObj->featureRef());
   }
@@ -45,6 +45,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..b11406c2db1041b50c4d01ad5da7c04760d40618 100644 (file)
@@ -60,6 +60,10 @@ public:
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
                     const std::list<XGUI_ViewerPrs>& thePresentations) {}
 
+  /// Returns the operation sketch feature
+  /// \returns the sketch instance
+  virtual boost::shared_ptr<ModelAPI_Feature> sketch() const = 0;
+
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
@@ -100,6 +104,14 @@ 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 set selection in the viewer
+  /// \param theFeatures a list of features to be disabled
+  void setSelection(const std::list<XGUI_ViewerPrs>& theFeatures);
+
   /// signal to enable/disable usual selection in the viewer
   /// \param theEnabled the boolean state
   void selectionEnabled(bool theEnabled);
index a4e09b856709ad111794076adcf63f58d1be2069..e1c31afd1e00aa44f340f09507c08a93e6ef4143 100644 (file)
@@ -5,11 +5,15 @@
 #include <PartSet_OperationSketchLine.h>
 
 #include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
 
 #include <GeomDataAPI_Point2D.h>
+
+#include <ModuleBase_OperationDescription.h>
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeRefAttr.h>
@@ -49,19 +53,16 @@ PartSet_OperationSketchLine::~PartSet_OperationSketchLine()
 {
 }
 
-bool PartSet_OperationSketchLine::isGranted() const
+bool PartSet_OperationSketchLine::isGranted(ModuleBase_IOperation* theOperation) const
 {
-  return true;
+  return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
 }
 
 std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
   std::list<int> aModes;
   if (theFeature != feature())
-  {
-    aModes.push_back(TopAbs_VERTEX);
-    aModes.push_back(TopAbs_EDGE);
-  }
+    aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
   return aModes;
 }
 
@@ -75,6 +76,11 @@ void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFe
   myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
 }
 
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::sketch() const
+{
+  return mySketch;
+}
+
 void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
                                                 const std::list<XGUI_ViewerPrs>& theSelected)
 {
@@ -83,7 +89,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
   bool isFoundPoint = false;
   gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
   if (theSelected.empty()) {
-    PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+    PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
     isFoundPoint = true;
   }
   else {
@@ -95,7 +101,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
         const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
         if (!aVertex.IsNull()) {
           aPoint = BRep_Tool::Pnt(aVertex);
-          PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+          PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
           isFoundPoint = true;
 
           setConstraints(aX, anY);
@@ -109,7 +115,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
           double Y0, Y1, Y2, Y3;
           getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
           getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
-          PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, X1, Y1);
+          PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1);
 
           switch (myPointSelectionMode) {
             case SM_FirstPoint:
@@ -134,12 +140,13 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
   switch (myPointSelectionMode)
   {
     case SM_FirstPoint: {
-      setLinePoint(aX, anY, LINE_ATTR_START);
+      setLinePoint(feature(), aX, anY, LINE_ATTR_START);
+      setLinePoint(feature(), aX, anY, LINE_ATTR_END);
       myPointSelectionMode = SM_SecondPoint;
     }
     break;
     case SM_SecondPoint: {
-      setLinePoint(aX, anY, LINE_ATTR_END);
+      setLinePoint(feature(), aX, anY, LINE_ATTR_END);
       commit();
       emit featureConstructed(feature(), FM_Deactivation);
       emit launchOperation(PartSet_OperationSketchLine::Type(), feature());
@@ -204,18 +211,19 @@ void PartSet_OperationSketchLine::stopOperation()
 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
 {
   boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature();
-  if (mySketch) {
+  if (sketch()) {
     boost::shared_ptr<SketchPlugin_Feature> aFeature = 
-                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
 
     aFeature->addSub(aNewFeature);
   }
   if (myInitPoint) {
+    setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START);
+    setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END);
+
     boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
     boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
                                                                 (aData->attribute(LINE_ATTR_START));
-    aPoint->setValue(myInitPoint->x(), myInitPoint->y());
-
     createConstraint(myInitPoint, aPoint);
   }
 
@@ -229,9 +237,9 @@ void PartSet_OperationSketchLine::createConstraint(boost::shared_ptr<GeomDataAPI
   boost::shared_ptr<ModelAPI_Document> aDoc = document();
   boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature("SketchConstraintCoincidence");
 
-  if (mySketch) {
+  if (sketch()) {
     boost::shared_ptr<SketchPlugin_Feature> aSketch = 
-                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
     aSketch->addSub(aFeature);
   }
 
@@ -265,7 +273,7 @@ void PartSet_OperationSketchLine::setConstraints(double theX, double theY)
   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
                                                               (aData->attribute(aPointArg));
-  aData = mySketch->data();
+  aData = sketch()->data();
   boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
         boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
 
@@ -314,10 +322,13 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_OperationSketchLine::findLinePoin
   return aPoint2D;
 }
 
-void PartSet_OperationSketchLine::setLinePoint(double theX, double theY,
+void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                               double theX, double theY,
                                                const std::string& theAttribute)
 {
-  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+  if (!theFeature)
+    return;
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
   aPoint->setValue(theX, theY);
@@ -328,7 +339,7 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
                                                const std::string& theAttribute)
 {
   double aX, anY;
-  PartSet_Tools::ConvertTo2D(thePoint, mySketch, theView, aX, anY);
+  PartSet_Tools::ConvertTo2D(thePoint, sketch(), theView, aX, anY);
   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
index cc5af926c2bbf2522397b2e38f2d667a9a9295a3..e6cabaa88094279333330d2e6a6bf8ac42df1ce3 100644 (file)
@@ -37,7 +37,8 @@ public:
 
    /// Returns that this operator can be started above already running one.
    /// The runned operation should be the sketch feature modified operation
-  virtual bool isGranted() const;
+  /// \param theOperation the previous running operation
+  virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
 
   /// Returns the operation local selection mode
   /// \param theFeature the feature object to get the selection mode
@@ -50,6 +51,10 @@ public:
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
                     const std::list<XGUI_ViewerPrs>& thePresentations);
 
+  /// Returns the operation sketch feature
+  /// \returns the sketch instance
+  virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
@@ -110,10 +115,12 @@ protected:
                                                        double theX, double theY);
 
   /// \brief Save the point to the line.
+  /// \param theFeature the line feature
   /// \param theX the horizontal coordinate
   /// \param theY the vertical coordinate
   /// \param theAttribute the start or end attribute of the line
-  void setLinePoint(double theX, double theY, const std::string& theAttribute);
+  void setLinePoint(boost::shared_ptr<ModelAPI_Feature>, double theX, double theY,
+                    const std::string& theAttribute);
   /// \brief Save the point to the line.
   /// \param thePoint the 3D point in the viewer
   /// \param theAttribute the start or end attribute of the line
index e75bc01e6aa72beb9741ee463d17bfe150e8c232..6f8f41af8d3d86e28279af7e43b3ae04e3931c1e 100644 (file)
@@ -2,6 +2,7 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeRefList.h>
 
 SketchPlugin_Feature::SketchPlugin_Feature()
@@ -9,29 +10,6 @@ SketchPlugin_Feature::SketchPlugin_Feature()
   mySketch = 0;
 }
 
-void SketchPlugin_Feature::setData(boost::shared_ptr<ModelAPI_Data> theData)
-{
-  ModelAPI_Feature::setData(theData);
-
-  // find sketch that references to this feature
-  int aSketches = document()->size("Construction");
-  for(int a = 0; a < aSketches && !mySketch; a++) {
-    boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
-      boost::dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a));
-    if (aSketch) {
-      std::list<boost::shared_ptr<ModelAPI_Feature> > aList = 
-        aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
-      std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
-      for(; aSub != aList.end(); aSub++) {
-        if ((*aSub)->data()->isEqual(theData)) {
-          mySketch = aSketch.get();
-          break;
-        }
-      }
-    }
-  }
-}
-
 void SketchPlugin_Feature::setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape)
 {
   myPreview = theShape;
@@ -41,3 +19,31 @@ const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Feature::getPreview() const
 {
   return myPreview;
 }
+
+SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
+{
+  if (!mySketch) {
+    // find sketch that references to this feature
+    int aSketches = document()->size("Construction");
+    for(int a = 0; a < aSketches && !mySketch; a++) {
+      boost::shared_ptr<ModelAPI_Object> anObj = 
+        boost::dynamic_pointer_cast<ModelAPI_Object>(document()->feature("Construction", a));
+      if (anObj) {
+        boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
+          boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj->featureRef());
+        if (aSketch) {
+          std::list<boost::shared_ptr<ModelAPI_Feature> > aList = 
+            aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
+          std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
+          for(; aSub != aList.end(); aSub++) {
+            if ((*aSub)->data()->isEqual(data())) {
+              mySketch = aSketch.get();
+              break;
+            }
+          }
+        }
+      }
+    }
+  }
+  return mySketch;
+}
index d83e21cceb25894ab2b64b1709dd815a6d6ba239..db6a6d6607aff088a251a6e4f6e43fb30d71b82e 100644 (file)
@@ -42,11 +42,9 @@ protected:
   /// Sets the higher-level feature for the sub-feature (sketch for line)
   void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;}
   /// Returns the sketch of this feature
-  SketchPlugin_Sketch* sketch() {return mySketch;}
+  SketchPlugin_Sketch* sketch();
   /// initializes mySketch
   SketchPlugin_Feature();
-  /// Sets the data manager of an object and here initializes mySketch field
-  SKETCHPLUGIN_EXPORT virtual void setData(boost::shared_ptr<ModelAPI_Data> theData);
 
   friend class SketchPlugin_Sketch;
 
index ee091f19be1e4cfda61724f991f58920a1ad3097..7f6bb00d77885b772f7febee71cd8fac6d7fa6b7 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,12 @@ 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,16 +133,86 @@ 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]);
+
   // 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();
     for (; anIt != aLast; anIt++)
     {
       aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
+       }
+  }
+
+  if (isUpdateViewer)
+    aContext->UpdateCurrentViewer();
+}
+
+void XGUI_Displayer::StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
+                                   const bool isUpdateViewer)
+{
+  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) {
+      QColor aColor(Qt::white);
+      anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+      anAIS->Redisplay();
+    }
+    else {
+      QColor aColor(Qt::red);
+      anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+      anAIS->Redisplay();
     }
   }
+  if (isUpdateViewer)
+    aContext->UpdateCurrentViewer();
+}
+
+void XGUI_Displayer::SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+
+  std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+  boost::shared_ptr<ModelAPI_Feature> aFeature;
 
+  Handle(AIS_Shape) anAIS;
+  aContext->ClearSelected();
+
+  for (; anIt != aLast; anIt++) {
+    aFeature = (*anIt).feature();
+    if (IsVisible(aFeature))
+      anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]);
+    if (anAIS.IsNull())
+      continue;
+    aContext->AddOrRemoveSelected(anAIS, false);
+  }
   if (isUpdateViewer)
     aContext->UpdateCurrentViewer();
 }
@@ -178,7 +247,7 @@ void XGUI_Displayer::EraseDeletedFeatures(const bool isUpdateViewer)
   for (; aFIt != aFLast; aFIt++)
   {
     boost::shared_ptr<ModelAPI_Feature> aFeature = (*aFIt).first;
-    if (!aFeature || !aFeature->data()->isValid()) {
+    if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
       Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
       if (!anAIS.IsNull()) {
         aContext->Erase(anAIS, false);
index 118d7268efa368d930ab283df9663eec5c87a59d..5973cd67e6d1ce064356503dff519a7b2514201e 100644 (file)
@@ -67,9 +67,28 @@ 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
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
+                     const bool isUpdateViewer);
+
+  /// Set the features are selected
+  /// \param theFeatures a list of features to be selected
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer);
 
   /// Erase the feature and a shape.
   /// \param theFeature a feature instance
@@ -106,4 +125,5 @@ protected:
   FeatureToAISMap myFeature2AISObjectMap;
 };
 
+
 #endif
index 792d5846777c786955ced5668b1878c2d9b34566..00aa7ecc5373c77116021faddf613bfabca4d4ae 100644 (file)
@@ -68,7 +68,7 @@ bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
 {
   bool aCanStart = true;
   ModuleBase_Operation* aCurrentOp = currentOperation();
-  if (aCurrentOp && !theOperation->isGranted())
+  if (aCurrentOp && !theOperation->isGranted(aCurrentOp))
   {
     if (canStopOperation()) {
       aCurrentOp->abort();
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();
 }