]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 29 Apr 2014 06:05:59 +0000 (10:05 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 29 Apr 2014 06:05:59 +0000 (10:05 +0400)
Conflicts:
src/PartSet/PartSet_Module.cpp

26 files changed:
src/ModuleBase/ModuleBase_Operation.cpp
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Listener.cpp [new file with mode: 0644]
src/PartSet/PartSet_Listener.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/PartSet/PartSet_Tools.cpp [new file with mode: 0644]
src/PartSet/PartSet_Tools.h [new file with mode: 0644]
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ActionsMgr.cpp [new file with mode: 0644]
src/XGUI/XGUI_ActionsMgr.h [new file with mode: 0644]
src/XGUI/XGUI_Command.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_MainMenu.cpp
src/XGUI/XGUI_MainMenu.h
src/XGUI/XGUI_MainWindow.h
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 519efbf13ebacbf35de46b6122d47232925a8f21..f31a292e0c4ef4c8d6a494a29dfcc22b0b081833 100644 (file)
@@ -16,8 +16,6 @@
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
 
-#include <GeomDataAPI_Point2D.h>
-
 #ifdef _DEBUG
 #include <QDebug>
 #endif
index 5a999aabae5229a06c830c01788a0ee3d81046a7..3744b2d4c831579b16370f16a1d6ed53b0ddb8e0 100644 (file)
@@ -5,17 +5,21 @@ SET(CMAKE_AUTOMOC ON)
 
 SET(PROJECT_HEADERS
        PartSet.h
+       PartSet_Listener.h
        PartSet_Module.h
        PartSet_OperationSketchBase.h
        PartSet_OperationSketch.h
        PartSet_OperationSketchLine.h
+       PartSet_Tools.h
 )
 
 SET(PROJECT_SOURCES
+       PartSet_Listener.cpp
        PartSet_Module.cpp
        PartSet_OperationSketchBase.cpp
        PartSet_OperationSketch.cpp
        PartSet_OperationSketchLine.cpp
+       PartSet_Tools.cpp
 )
 
 SET(PROJECT_RESOURCES 
@@ -47,6 +51,7 @@ SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES})
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI 
                     ${CMAKE_SOURCE_DIR}/src/Config
                     ${CMAKE_SOURCE_DIR}/src/Events
+                    ${CMAKE_SOURCE_DIR}/src/Model
                     ${CMAKE_SOURCE_DIR}/src/ModuleBase
                     ${CMAKE_SOURCE_DIR}/src/ModelAPI
                     ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp
new file mode 100644 (file)
index 0000000..580186b
--- /dev/null
@@ -0,0 +1,37 @@
+// File:        PartSet_Listener.h
+// Created:     28 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_Listener.h>
+
+#include <PartSet_Module.h>
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+using namespace std;
+
+PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
+: myModule(theModule)
+{
+  Events_Loop* aLoop = Events_Loop::loop();
+  Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
+  aLoop->registerListener(this, aFeatureUpdatedId);
+}
+
+PartSet_Listener::~PartSet_Listener()
+{
+}
+
+//******************************************************
+void PartSet_Listener::processEvent(const Events_Message* theMessage)
+{
+  if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED)
+  {
+    myModule->visualizePreview(true);
+  }
+}
diff --git a/src/PartSet/PartSet_Listener.h b/src/PartSet/PartSet_Listener.h
new file mode 100644 (file)
index 0000000..0512245
--- /dev/null
@@ -0,0 +1,35 @@
+// File:        PartSet_Listener.h
+// Created:     28 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_Listener_H
+#define PartSet_Listener_H
+
+#include "PartSet.h"
+
+#include <Events_Listener.h>
+
+class PartSet_Module;
+
+/*!
+ \class PartSet_Listener
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_Listener : public Events_Listener
+{
+public:
+  /// Constructor
+  /// \param theId the feature identifier
+  /// \param theParent the operation parent
+  PartSet_Listener(PartSet_Module* theModule);
+  /// Destructor
+  virtual ~PartSet_Listener();
+
+  /// This method is called by loop when the event is started to process.
+  virtual void processEvent(const Events_Message* theMessage);
+
+private:
+  PartSet_Module* myModule; ///< the current module
+};
+
+#endif
index 4d0b8867e05f7b09761547a7703032ecae08f3d2..bc383d3019f745a6025c688d96652a46685c3315 100644 (file)
@@ -1,6 +1,8 @@
 #include <PartSet_Module.h>
 #include <PartSet_OperationSketch.h>
 #include <PartSet_OperationSketchLine.h>
+#include <PartSet_Listener.h>
+#include <PartSet_Tools.h>
 
 #include <ModuleBase_Operation.h>
 
@@ -9,7 +11,9 @@
 #include <XGUI_Viewer.h>
 #include <XGUI_Workshop.h>
 #include <XGUI_OperationMgr.h>
+#include <XGUI_ViewWindow.h>
 #include <XGUI_SelectionMgr.h>
+#include <XGUI_ViewPort.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -38,13 +42,19 @@ extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
 {
   myWorkshop = theWshop;
+  myListener = new PartSet_Listener(this);
+
   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
 
   connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
-  connect(myWorkshop->selector(), SIGNAL(selectionChanged()),
-            this, SLOT(onViewSelectionChanged()));
+  if (!myWorkshop->isSalomeMode()) {
+    connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseReleased(QPoint)),
+            this, SLOT(onMouseReleased(QPoint)));
+    connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseMoved(QPoint)),
+            this, SLOT(onMouseMoved(QPoint)));
+  }
 }
 
 PartSet_Module::~PartSet_Module()
@@ -63,6 +73,11 @@ void PartSet_Module::featureCreated(XGUI_Command* theFeature)
   theFeature->connectTo(this, SLOT(onFeatureTriggered()));
 }
 
+QStringList PartSet_Module::nestedFeatures(QString)
+{
+  return QStringList();
+}
+
 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
 {
   return myFeaturesInFiles[theFeatureId];
@@ -74,6 +89,9 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
 void PartSet_Module::onFeatureTriggered()
 {
   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
+  //Do nothing on uncheck
+  if(aCmd->isCheckable() && !aCmd->isChecked())
+    return;
   launchOperation(aCmd->id());
 }
   
@@ -131,7 +149,7 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
     visualizePreview(false);
 }
 
-void PartSet_Module::onViewSelectionChanged()
+void PartSet_Module::onMouseReleased(QPoint thePoint)
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
@@ -140,7 +158,33 @@ void PartSet_Module::onViewSelectionChanged()
     if (aSelector) {
       NCollection_List<TopoDS_Shape> aList;
       aSelector->selectedShapes(aList);
-      aPreviewOp->setSelectedShapes(aList);
+      XGUI_ViewWindow* aWindow = myWorkshop->mainWindow()->viewer()->activeViewWindow();
+      if (aWindow) {
+        Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
+        if ( !aView3d.IsNull() ) {
+          gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d);
+          aPreviewOp->setSelectedShapes(aList, aPoint);
+        }
+      }
+    }
+  }
+}
+
+void PartSet_Module::onMouseMoved(QPoint thePoint)
+{
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+  if (aPreviewOp) {
+    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+    if (aViewer) {
+      XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
+      if (aWindow) {
+        Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
+        if ( !aView3d.IsNull() ) {
+          gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d);
+          aPreviewOp->setMouseMovePoint(aPoint);
+        }
+      }
     }
   }
 }
@@ -163,14 +207,16 @@ void PartSet_Module::visualizePreview(bool isDisplay)
   if (!aPreviewOp)
     return;
 
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (isDisplay) {
     boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
-    if (aPreview)
-      myWorkshop->displayer()->LocalSelection(anOperation->feature(),
+    if (aPreview) {
+      aDisplayer->LocalSelection(anOperation->feature(),
                                    aPreview->impl<TopoDS_Shape>(), aPreviewOp->getSelectionMode());
+    }
   }
   else {
-    myWorkshop->displayer()->GlobalSelection(false);
-    myWorkshop->displayer()->Erase(anOperation->feature());
+    aDisplayer->GlobalSelection(false);
+    aDisplayer->Erase(anOperation->feature());
   }
 }
index 523a15ad210a702de378f66562dc510329ff97c5..b71c7fb2e31140bb4618661809655ad7113744c2 100644 (file)
@@ -11,6 +11,8 @@
 
 #include <string>
 
+class PartSet_Listener;
+
 class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
 {
 Q_OBJECT
@@ -21,10 +23,15 @@ public:
 
   virtual void createFeatures();
   virtual void featureCreated(XGUI_Command* theFeature);
+  virtual QStringList nestedFeatures(QString theFeature);
   std::string featureFile(const std::string&);
 
   virtual void launchOperation(const QString& theCmdId);
 
+  /// Displays or erase the current operation preview, if it has it.
+  /// \param isDisplay the state whether the presentation should be displayed or erased
+  void visualizePreview(bool isDisplay);
+
 public slots:
   void onFeatureTriggered();
   /// SLOT, that is called after the operation is started. Perform some specific for module
@@ -35,20 +42,21 @@ public slots:
   void onOperationStopped(ModuleBase_Operation* theOperation);
   /// SLOT, that is called by the selection in the viewer is changed.
   /// The selection is sent to the current operation if it listen the selection.
-  void onViewSelectionChanged();
+  void onMouseReleased(QPoint thePoint);
+  /// SLOT, that is called by the selection in the viewer is changed.
+  /// The selection is sent to the current operation if it listen the selection.
+  /// \thePoint the mouse point
+  void onMouseMoved(QPoint thePoint);
+
   /// SLOT, to apply to the current viewer the operation
   /// \param theX the X projection value
   /// \param theY the Y projection value
   /// \param theZ the Z projection value
   void onViewerProjectionChange(double theX, double theY, double theZ);
 
-private:
-  /// Displays or erase the current operation preview, if it has it.
-  /// \param isDisplay the state whether the presentation should be displayed or erased
-  void visualizePreview(bool isDisplay);
-
 private:
   XGUI_Workshop* myWorkshop;
+  PartSet_Listener* myListener;
 
   std::map<std::string, std::string> myFeaturesInFiles;
 };
index 32a2199b8d2b6fe1d8acebfaaf2c9ef0f3d8bb81..48bd5f0e34de92fe5da62a1c6b2285c64155bd27 100644 (file)
@@ -35,7 +35,8 @@ int PartSet_OperationSketch::getSelectionMode() const
   return TopAbs_FACE;
 }
 
-void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
+void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+                                                const gp_Pnt& theSelectedPoint)
 {
   if (theList.IsEmpty())
     return;
index 4a4fd74bc547a47978e739aa98ecf0be6c591729..021a8c8cdebf7981a3e5040880668d9188694126 100644 (file)
@@ -31,7 +31,9 @@ public:
 
   /// Gives the current selected objects to be processed by the operation
   /// \param theList a list of interactive selected shapes
-  virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList);
+  /// \param theSelectedPoint a point clidked in the viewer
+  virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+                                 const gp_Pnt& theSelectedPoint);
 };
 
 #endif
index 916ebc46648ab9b402ee03581b6e38c2c3027f5f..0e6c242635f6974a48ecbd587af7d503843a5e99 100644 (file)
@@ -8,6 +8,7 @@
 #include "PartSet.h"
 
 #include <TopoDS_Shape.hxx>
+#include <gp_Pnt.hxx>
 #include <NCollection_List.hxx>
 
 #include <ModuleBase_PropPanelOperation.h>
@@ -39,8 +40,13 @@ public:
   virtual int getSelectionMode() const = 0;
 
   /// Gives the current selected objects to be processed by the operation
-  /// \param a list of interactive selected objects
-  virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList) = 0;
+  /// \param theList a list of interactive selected shapes
+  /// \param theSelectedPoint a 3D selected point
+  virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+                                 const gp_Pnt& thePoint) = 0;
+  /// Gives the current mouse point in the viewer
+  /// \param thePoint a point clidked in the viewer
+  virtual void setMouseMovePoint(const gp_Pnt& thePoint) {};
 
 signals:
   void viewerProjectionChange(double theX, double theY, double theZ);
index 6ceda06f1366b9ac35429c956ed54b2b7985e39e..57d5f764603bcd745e2e55746595ae8f8b37caf7 100644 (file)
@@ -5,6 +5,10 @@
 #include <PartSet_OperationSketchLine.h>
 
 #include <SketchPlugin_Feature.h>
+#include <GeomDataAPI_Point2D.h>
+#include <ModelAPI_Data.h>
+
+#include <SketchPlugin_Line.h>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -15,7 +19,8 @@ using namespace std;
 PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId,
                                                  QObject* theParent,
                                               boost::shared_ptr<ModelAPI_Feature> theFeature)
-: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
+: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature),
+  myPointSelectionMode(SM_FirstPoint)
 {
 }
 
@@ -30,13 +35,40 @@ bool PartSet_OperationSketchLine::isGranted() const
 
 int PartSet_OperationSketchLine::getSelectionMode() const
 {
-  return TopAbs_FACE;
+  return 0;//TopAbs_FACE;
 }
 
-void PartSet_OperationSketchLine::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
+void PartSet_OperationSketchLine::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+                                                    const gp_Pnt& thePoint)
 {
   if (theList.IsEmpty())
     return;
+
+  switch (myPointSelectionMode)
+  {
+    case SM_FirstPoint: {
+      setLinePoint(thePoint, LINE_ATTR_START);
+      myPointSelectionMode = SM_SecondPoint;
+    }
+    break;
+    case SM_SecondPoint: {
+      setLinePoint(thePoint, LINE_ATTR_END);
+      commit();
+    }
+    break;
+    case SM_None: {
+
+    }
+    break;
+    default:
+      break;
+  }
+}
+
+void PartSet_OperationSketchLine::setMouseMovePoint(const gp_Pnt& thePoint)
+{
+  if (myPointSelectionMode == SM_SecondPoint)
+    setLinePoint(thePoint, LINE_ATTR_END);
 }
 
 void PartSet_OperationSketchLine::startOperation()
@@ -49,4 +81,23 @@ void PartSet_OperationSketchLine::startOperation()
 
     aFeature->addSub(feature());
   }
+  myPointSelectionMode = SM_FirstPoint;
 }
+
+void PartSet_OperationSketchLine::stopOperation()
+{
+  PartSet_OperationSketchBase::stopOperation();
+
+  myPointSelectionMode = SM_None;
+}
+
+void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
+                                               const std::string& theAttribute)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+  double aX = thePoint.X(), anY = thePoint.Y();
+  aPoint->setValue(aX, anY);
+}
+
index 737c73c36780c098125de5f1a0c2cd5afda724e1..27a03a43f8af98192646aed69c014b04fe319ba3 100644 (file)
@@ -37,7 +37,12 @@ public:
 
   /// Gives the current selected objects to be processed by the operation
   /// \param theList a list of interactive selected shapes
-  virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList);
+  /// \param theSelectedPoint a point clidked in the viewer
+  virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+                                 const gp_Pnt& thePoint);
+  /// Gives the current mouse point in the viewer
+  /// \param thePoint a point clidked in the viewer
+  virtual void setMouseMovePoint(const gp_Pnt& thePoint);
 
 protected:
   /// \brief Virtual method called when operation is started
@@ -45,8 +50,24 @@ protected:
   /// After the parent operation body perform, set sketch feature to the created line feature
   virtual void startOperation();
 
+  /// \brief Virtual method called when operation is started
+  /// Virtual method called when operation stopped - committed or aborted.
+  /// After the parent operation body perform, reset selection point mode of the operation
+  virtual void stopOperation();
+
+protected:
+  /// \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
+  void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
+
+protected:
+  ///< Structure to lists the possible types of point selection modes
+  enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None};
+
 private:
   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+  PointSelectionMode myPointSelectionMode; ///< point selection mode
 };
 
 #endif
diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp
new file mode 100644 (file)
index 0000000..8afc9ae
--- /dev/null
@@ -0,0 +1,36 @@
+// File:        PartSet_Tools.h
+// Created:     28 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_Tools.h>
+
+#include <V3d_View.hxx>
+#include <gp_Pln.hxx>
+#include <ProjLib.hxx>
+#include <ElSLib.hxx>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
+{
+  V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
+  theView->Eye( XEye, YEye, ZEye );
+
+  theView->At( XAt, YAt, ZAt );
+  gp_Pnt EyePoint( XEye, YEye, ZEye );
+  gp_Pnt AtPoint( XAt, YAt, ZAt );
+
+  gp_Vec EyeVector( EyePoint, AtPoint );
+  gp_Dir EyeDir( EyeVector );
+
+  gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
+  Standard_Real X, Y, Z;
+  theView->Convert( thePoint.x(), thePoint.y(), X, Y, Z );
+  gp_Pnt ConvertedPoint( X, Y, Z );
+
+  gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
+  gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
+  return ResultPoint;
+}
diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h
new file mode 100644 (file)
index 0000000..4139385
--- /dev/null
@@ -0,0 +1,30 @@
+// File:        PartSet_Tools.h
+// Created:     28 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_Tools_H
+#define PartSet_Tools_H
+
+#include "PartSet.h"
+
+#include <gp_Pnt.hxx>
+
+#include <QPoint>
+
+class Handle_V3d_View;
+
+/*!
+ \class PartSet_Tools
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_Tools
+{
+public:
+  /// Converts the 2D screen point to the 3D point on the view according to the point of view
+  /// \param thePoint a screen point
+  /// \param theView a 3D view
+  static gp_Pnt ConvertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
+
+};
+
+#endif
index 460458d1ab561bfc9abc421cca0a489eafa594ad..989980d3b6703be775e7e581dceab9942f963da5 100644 (file)
@@ -26,6 +26,7 @@ SET(PROJECT_HEADERS
     XGUI_DataTreeModel.h
     XGUI_SelectionMgr.h
     XGUI_SalomeConnector.h
+    XGUI_ActionsMgr.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -51,6 +52,7 @@ SET(PROJECT_SOURCES
        XGUI_ObjectsBrowser.cpp
        XGUI_OperationMgr.cpp
     XGUI_SelectionMgr.cpp
+    XGUI_ActionsMgr.cpp
 )
 
 SET(PROJECT_RESOURCES 
diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp
new file mode 100644 (file)
index 0000000..0d652dc
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * XGUI_ActionsMgr.cpp
+ */
+
+#include <XGUI_ActionsMgr.h>
+#include <XGUI_Command.h>
+#include <QAction>
+
+
+XGUI_ActionsMgr::XGUI_ActionsMgr(QObject* theParent)
+ : QObject(theParent)
+{
+
+}
+
+XGUI_ActionsMgr::~XGUI_ActionsMgr()
+{
+}
+
+
+void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd)
+{
+  myActions.insert(theCmd->id(),theCmd);
+  myActionsState.insert(theCmd->id(), theCmd->enabled());
+  theCmd->connectTo(this, SLOT(setActionsDisabled(bool)));
+}
+
+void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
+{
+  //Re-enable actions (just restore their state)
+  if (!isDisabled) {
+    restoreCommandState();
+    return;
+  }
+  //Disable all actions, but caller and unblockable (defined in a xml)
+  saveCommandsState();
+  QStringList aSkippedIds;
+  XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
+  aSkippedIds.append(aToggledFeature->unblockableCommands());
+  aSkippedIds.append(aToggledFeature->id());
+  QStringList anActionIdsList = myActions.keys();
+  foreach(QString eachKey, anActionIdsList) {
+    if (aSkippedIds.removeAll(eachKey) > 0) {
+      continue;
+    }
+    myActions[eachKey]->setEnabled(false);
+  }
+}
+
+void XGUI_ActionsMgr::saveCommandsState()
+{
+  myActionsState.clear();
+  QStringList anActionIdsList = myActions.keys();
+  foreach(QString eachKey, anActionIdsList) {
+    myActionsState.insert(eachKey, myActions[eachKey]->isEnabled());
+  }
+
+}
+
+void XGUI_ActionsMgr::restoreCommandState()
+{
+  QStringList anActionIdsList = myActions.keys();
+  foreach(QString eachKey, anActionIdsList) {
+    myActions[eachKey]->setEnabled(myActionsState[eachKey]);
+    myActions[eachKey]->setChecked(false);
+  }
+}
diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h
new file mode 100644 (file)
index 0000000..a3d7dea
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * XGUI_ActionsMgr.h
+ */
+
+#ifndef XGUI_ACTIONSMGR_H_
+#define XGUI_ACTIONSMGR_H_
+
+#include <QObject>
+#include <QMap>
+#include <QStringList>
+
+class XGUI_Command;
+class QAction;
+
+class XGUI_ActionsMgr: public QObject
+{
+  Q_OBJECT
+
+public:
+  XGUI_ActionsMgr(QObject* theParent);
+  virtual ~XGUI_ActionsMgr();
+
+  void addCommand(XGUI_Command* theCmd);
+  void restoreCommandState();
+  void saveCommandsState();
+
+public slots:
+  void setActionsDisabled(bool isEnabled);
+
+private:
+  QMap<QString, QAction*> myActions;
+  QMap<QString, bool> myActionsState;
+};
+
+#endif /* XGUI_ACTIONSMGR_H_ */
index ffd6ab103f7338b833a05020b60e635534532867..9b5dd7b9abfa4ea89a6e5e81f9e2ecbc529a0dab 100644 (file)
@@ -63,7 +63,7 @@ void XGUI_Command::disable()
 
 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
 {
-    connect(this, SIGNAL(triggered()), theResiver, theSlot);
+    connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
 }
 
 const QStringList& XGUI_Command::unblockableCommands() const
index 5b510bbb67a29d4b9459b4ca92401a9d05463aa7..41c912f1a4e29248576cb291a820f10dc38f6dc5 100644 (file)
@@ -22,6 +22,11 @@ XGUI_Displayer::~XGUI_Displayer()
 {
 }
 
+bool XGUI_Displayer::IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end();
+}
+
 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
                              const bool isUpdateViewer)
 {
@@ -73,6 +78,10 @@ void XGUI_Displayer::LocalSelection(boost::shared_ptr<ModelAPI_Feature> theFeatu
                                     const int theMode, const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
+  
+  if (IsVisible(theFeature)) {
+    Erase(theFeature, false);
+  }
 
   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
   std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
index 319a07a5e1bf6a6e3e6f63c21b1a49027c7753f9..b6967a2ab5d3366b60117d7ec6f775b63eb12ba6 100644 (file)
@@ -38,6 +38,10 @@ public:
   /// or can not be initialized in constructor
   void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
 
+  /// Returns the feature visibility state.
+  /// \param theFeature a feature instance
+  bool IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
   /// Display the feature. Obtain the visualized object from the feature.
   /// \param theFeature a feature instance
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
index 96106a9111357da303ce4d14993cd204893aa057..4c8e7dc3c6ce612b6530213ce6c974f56ae5cdda 100644 (file)
@@ -91,48 +91,3 @@ QList<XGUI_Command*> XGUI_MainMenu::features() const
   return aList;
 }
 
-void XGUI_MainMenu::onFeatureChecked(bool isChecked)
-{
-  if (!isChecked) {
-    restoreCommandState();
-    return;
-  }
-
-  saveCommandsState();
-  QStringList aSkippedIds;
-  XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
-  aSkippedIds.append(aToggledFeature->unblockableCommands());
-//  aSkippedIds.append(aToggledFeature->id());
-  XGUI_Workbench* aGeneralWB = findWorkbench(tr("General"));
-  foreach(XGUI_Command* eachFeature, aGeneralWB->features()) {
-    aSkippedIds.append(eachFeature->id());
-  }
-  QList<XGUI_Command*> allFeatures = features();
-  foreach(XGUI_Command* eachFeature, allFeatures) {
-    QString aFeatureId = eachFeature->id();
-    if (aSkippedIds.removeAll(aFeatureId) > 0) {
-      continue;
-    }
-    eachFeature->setEnabled(false);
-  }
-}
-
-void XGUI_MainMenu::saveCommandsState()
-{
-  myCommandState.clear();
-  QList<XGUI_Command*> allFeatures = features();
-  XGUI_Command* eachFeature = NULL;
-  foreach(eachFeature, allFeatures) {
-    myCommandState.insert(eachFeature, eachFeature->enabled());
-  }
-}
-
-void XGUI_MainMenu::restoreCommandState()
-{
-  QList<XGUI_Command*> allFeatures = features();
-  XGUI_Command* eachFeature = NULL;
-  foreach(eachFeature, allFeatures) {
-    eachFeature->setChecked(false);
-    eachFeature->setEnabled(myCommandState[eachFeature]);
-  }
-}
index 0fed1a07ff64a11c83d68665cd2b1e11b11aac21..48d97459135f78be9f26e3f2b6a6d7450e10f833 100644 (file)
@@ -47,12 +47,6 @@ public:
   //! Returns list of created commands
   QList<XGUI_Command*> features() const;
 
-public slots:
-  void onFeatureChecked(bool);
-
-  void saveCommandsState();
-  void restoreCommandState();
-
   virtual bool eventFilter(QObject *theWatched, QEvent *theEvent);
 
 private:
index 553aa27358cf613de2479593b1897022770034e5..17357858d7a89abc248b8113be9392368966aaf0 100644 (file)
@@ -6,6 +6,7 @@
 
 class XGUI_MainMenu;
 class XGUI_Viewer;
+class XGUI_ActionsMgr;
 class QMdiArea;
 class PyConsole_EnhConsole;
 
@@ -43,7 +44,6 @@ public slots:
 
 private:
   XGUI_MainMenu* myMenuBar;
-
   XGUI_Viewer* myViewer;
 
   PyConsole_EnhConsole* myPythonConsole;
index 0d93d6cc04f8eeee6f995deb253278f79ac49eb9..23560ca86031d369571e2dcf5d864eb5a43d675e 100644 (file)
@@ -190,6 +190,10 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType)
   return aWnd;
 }
 
+XGUI_ViewWindow* XGUI_Viewer::activeViewWindow() const
+{
+  return dynamic_cast<XGUI_ViewWindow*>(myActiveView->widget());
+}
 
 void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
 {
@@ -502,8 +506,10 @@ void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
   XGUI_ViewPort* aViewPort = theWindow->viewPort();
   Handle(V3d_View) aView3d = aViewPort->getView();
 
-  if ( !aView3d.IsNull() )
+  if ( !aView3d.IsNull() ) {
     myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
+    mouseMoved(theEvent->pos());
+  }
 }
 
 /*!
@@ -513,5 +519,5 @@ void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEv
 {
   myAISContext->Select();
 
-  emit selectionChanged();
+  emit mouseReleased(theEvent->pos());
 }
index 784ddd3cf67661c77c4b273a9db1646292f26117..23d66656a92bf3badab36e66d613ce5dd5630665 100644 (file)
@@ -14,6 +14,8 @@
 #include <NCollection_List.hxx>
 #include <TopoDS_Shape.hxx>
 
+#include <QPoint>
+
 class XGUI_MainWindow;
 class QMdiSubWindow;
 class XGUI_ViewWindow;
@@ -57,6 +59,9 @@ public:
     return myAISContext;
   }
 
+  //! Returns an active view window or NULL
+  XGUI_ViewWindow* activeViewWindow() const;
+
   /// Return objects selected in 3D viewer
   /// \param theList - list to be filled with selected objects
   void  getSelectedObjects(AIS_ListOfInteractive& theList);
@@ -137,6 +142,8 @@ signals:
   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
   void activated(XGUI_ViewWindow* theWindow);
   void selectionChanged();
+  void mouseReleased(QPoint thePoint);
+  void mouseMoved(QPoint thePoint);
 
 public slots:
   void onWindowMinimized(QMdiSubWindow*);
index 51bc022d5b58210b620cb1434d4b8de9decf2336..2655b569456ab43b28ea6227a5a35987696e4185 100644 (file)
@@ -14,6 +14,7 @@
 #include "XGUI_Displayer.h"
 #include "XGUI_OperationMgr.h"
 #include "XGUI_SalomeConnector.h"
+#include "XGUI_ActionsMgr.h"
 
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Feature.h>
@@ -61,6 +62,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   mySelector = new XGUI_SelectionMgr(this);
   connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument()));
   myOperationMgr = new XGUI_OperationMgr(this);
+  myActionsMgr = new XGUI_ActionsMgr(this);
   connect(myOperationMgr, SIGNAL(operationStarted()),  this, SLOT(onOperationStarted()));
   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
@@ -231,10 +233,9 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
     hidePropertyPanel();
     updateCommandStatus();
 
-  if (myMainWindow) {
-    XGUI_MainMenu* aMenu = myMainWindow->menuObject();
-    aMenu->restoreCommandState();
-  }
+    if (myMainWindow) {
+      myActionsMgr->restoreCommandState();
+    }
   }
 }
 
@@ -278,9 +279,7 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
                                                 QString::fromStdString(theMessage->tooltip()),
                                                 QIcon(theMessage->icon().c_str()),
                                                 QKeySequence(), isUsePropPanel);
-    
-    connect(aCommand,                   SIGNAL(toggled(bool)),
-            myMainWindow->menuObject(), SLOT(onFeatureChecked(bool)));
+    myActionsMgr->addCommand(aCommand);
     myPartSetModule->featureCreated(aCommand);
   }
 }
@@ -305,7 +304,7 @@ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
     aCommand = aMenu->feature(theOperation->operationId());
   }
   //Abort operation on uncheck the command
-  connect(aCommand, SIGNAL(toggled(bool)), theOperation, SLOT(setRunning(bool)));
+  connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
 }
 
 //******************************************************
@@ -631,4 +630,4 @@ void XGUI_Workshop::changeCurrentDocument()
 void XGUI_Workshop::salomeViewerSelectionChanged()
 {
   emit salomeViewerSelection();
-}
\ No newline at end of file
+}
index 5ea558ca2fc4c9763054219dcc7901df7ca83417..7d75839cfae07bc44d117b5e762b673b8212a8cb 100644 (file)
@@ -18,6 +18,7 @@ class XGUI_Displayer;
 class XGUI_OperationMgr;
 class XGUI_SalomeConnector;
 class XGUI_ObjectsBrowser;
+class XGUI_ActionsMgr;
 class ModuleBase_Operation;
 class ModuleBase_PropPanelOperation;
 
@@ -134,6 +135,8 @@ private:
   XGUI_Displayer* myDisplayer;
 
   XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
+  XGUI_ActionsMgr* myActionsMgr;
+
 
   XGUI_SalomeConnector* mySalomeConnector;
 };