Salome HOME
Redisplay objects after closing interactive context. Activate/Deactivate widget metho...
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 19 Nov 2014 09:51:34 +0000 (12:51 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 19 Nov 2014 09:51:34 +0000 (12:51 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_ViewWindow.cpp

index 5787ccfb09989d5aa62afee6753a0117fc91b384..08a33e42d18714c5dcf1f247705ea50567ada151 100644 (file)
@@ -1,61 +1,61 @@
-#ifndef ModuleBase_IModule_H
-#define ModuleBase_IModule_H
-
-#include "ModuleBase.h"
-#include "ModuleBase_IWorkshop.h"
-
-#include <QString>
-#include <QObject>
-
-
-class QAction;
+#ifndef ModuleBase_IModule_H\r
+#define ModuleBase_IModule_H\r
+\r
+#include "ModuleBase.h"\r
+#include "ModuleBase_IWorkshop.h"\r
+\r
+#include <QString>\r
+#include <QObject>\r
+\r
+\r
+class QAction;\r
 class QMouseEvent;\r
 class QKeyEvent;\r
-class Config_WidgetAPI;
-class ModuleBase_ModelWidget;
-class ModuleBase_Operation;
-class ModuleBase_IWorkshop;
-
-/**
- * Interface to a module
- */
-class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
-{
-  Q_OBJECT
- public:
-
-   ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
-
-  virtual ~ModuleBase_IModule() {}
-
-  /// Reads description of features from XML file 
-  virtual void createFeatures() = 0;
-
-  /// Called on creation of menu item in desktop
-  virtual void featureCreated(QAction*) = 0;
-
-  /// Creates an operation and send it to loop
-  /// \param theCmdId the operation name
-  virtual void launchOperation(const QString& theCmdId);
-
-  /// Called when it is necessary to update a command state (enable or disable it)
-  //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;
-
-  /// Creates custom widgets for property panel
-  virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
-                                      Config_WidgetAPI* theWidgetApi,
-                                      QList<ModuleBase_ModelWidget*>& theModelWidgets)
-  {
-    return 0;
-  }
-
-  ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
-
-protected slots:
-
-  /// Called on selection changed event
-  virtual void onSelectionChanged() {}
-
+class Config_WidgetAPI;\r
+class ModuleBase_ModelWidget;\r
+class ModuleBase_Operation;\r
+class ModuleBase_IWorkshop;\r
+\r
+/**\r
+ * Interface to a module\r
+ */\r
+class MODULEBASE_EXPORT ModuleBase_IModule : public QObject\r
+{\r
+  Q_OBJECT\r
+ public:\r
+\r
+   ModuleBase_IModule(ModuleBase_IWorkshop* theParent);\r
+\r
+  virtual ~ModuleBase_IModule() {}\r
+\r
+  /// Reads description of features from XML file \r
+  virtual void createFeatures() = 0;\r
+\r
+  /// Called on creation of menu item in desktop\r
+  virtual void featureCreated(QAction*) = 0;\r
+\r
+  /// Creates an operation and send it to loop\r
+  /// \param theCmdId the operation name\r
+  virtual void launchOperation(const QString& theCmdId);\r
+\r
+  /// Called when it is necessary to update a command state (enable or disable it)\r
+  //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;\r
+\r
+  /// Creates custom widgets for property panel\r
+  virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
+                                      Config_WidgetAPI* theWidgetApi,\r
+                                      QList<ModuleBase_ModelWidget*>& theModelWidgets)\r
+  {\r
+    return 0;\r
+  }\r
+\r
+  ModuleBase_IWorkshop* workshop() const { return myWorkshop; }\r
+\r
+protected slots:\r
+\r
+  /// Called on selection changed event\r
+  virtual void onSelectionChanged() {}\r
+\r
   /// SLOT, that is called by mouse press in the viewer.\r
   /// The mouse released point is sent to the current operation to be processed.\r
   /// \param theEvent the mouse event\r
@@ -78,30 +78,30 @@ protected slots:
   /// SLOT, that is called by the key in the viewer is clicked.\r
   /// \param theEvent the mouse event\r
   virtual void onKeyRelease(QKeyEvent* theEvent) {}\r
-
- protected:
-  /// Sends the operation for launching
-  /// \param theOperation the operation
-  void sendOperation(ModuleBase_Operation* theOperation);
-
-  /// Creates a new operation
-  /// \param theCmdId the operation name
-  /// \param theFeatureKind a kind of feature to get the feature xml description
-  virtual ModuleBase_Operation* createOperation(const std::string& theCmdId,
-                                        const std::string& theFeatureKind = "") = 0;
-
-
-protected:
-
-  ModuleBase_IWorkshop* myWorkshop;
-
-};
-
-//! This function must return a new module instance.
-extern "C" {
-typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
-}
-
-#define CREATE_MODULE "createModule"
-
-#endif //ModuleBase_IModule
+\r
+ protected:\r
+  /// Sends the operation for launching\r
+  /// \param theOperation the operation\r
+  void sendOperation(ModuleBase_Operation* theOperation);\r
+\r
+  /// Creates a new operation\r
+  /// \param theCmdId the operation name\r
+  /// \param theFeatureKind a kind of feature to get the feature xml description\r
+  virtual ModuleBase_Operation* createOperation(const std::string& theCmdId,\r
+                                        const std::string& theFeatureKind = "") = 0;\r
+\r
+\r
+protected:\r
+\r
+  ModuleBase_IWorkshop* myWorkshop;\r
+\r
+};\r
+\r
+//! This function must return a new module instance.\r
+extern "C" {\r
+typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);\r
+}\r
+\r
+#define CREATE_MODULE "createModule"\r
+\r
+#endif //ModuleBase_IModule\r
index 7e77804ac36a440d483d726af92e7b29b97d0fac..9f55dab1e56e48bc4799670bfb66a4c56f53ab5a 100644 (file)
@@ -70,6 +70,12 @@ Q_OBJECT
   /// \return the state whether the widget can accept the focus
   virtual bool focusTo();
 
+  /// The methiod called when widget is activated
+  virtual void activate() {}
+
+  /// The methiod called when widget is deactivated
+  virtual void deactivate() {}
+
   /// Returns the internal parent wiget control, that can be shown anywhere
   /// \returns the widget
   virtual QWidget* getControl() const = 0;
index 91cc255e8c7af1d3d5416549a88853f95d00a6ca..146e62efb02f475cb9703dc233c69c7264f0895d 100644 (file)
@@ -255,7 +255,7 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr
     }
   } 
   updateSelectionName();
-  activateSelection(false);
+  //activateSelection(false);
   emit valuesChanged();
 }
 
@@ -336,6 +336,8 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
 {
+  if (myIsActive == toActivate)
+    return;
   myIsActive = toActivate;
   updateSelectionName();
 
@@ -385,17 +387,17 @@ void ModuleBase_WidgetShapeSelector::raisePanel() const
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::focusTo()
 {
-  activateSelection(true);
+  //activateSelection(true);
   return ModuleBase_ModelWidget::focusTo();
 }
 
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::eventFilter(QObject* theObj, QEvent* theEvent)
 {
-  if (theObj == myTextLine) {
-    if (theEvent->type() == QEvent::FocusIn)
-      activateSelection(true);
-  }
+  //if (theObj == myTextLine) {
+  //  if (theEvent->type() == QEvent::FocusIn)
+  //    activateSelection(true);
+  //}
   return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
 }
 
@@ -416,3 +418,14 @@ bool ModuleBase_WidgetShapeSelector::setValue(ModuleBase_WidgetValue* theValue)
   return false;
 }
 
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::activate()
+{
+  activateSelection(true);
+}
+
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::deactivate()
+{
+  activateSelection(false);
+}
index 7284d8ae59ec8c7e305457122850d1a75f53c1b3..eef773421869f5ed6ae758ae2172bebf1b645e2b 100644 (file)
@@ -63,6 +63,14 @@ Q_OBJECT
   /// \param theValue the wrapped widget value
   virtual bool setValue(ModuleBase_WidgetValue* theValue);
 
+
+  /// The methiod called when widget is activated
+  virtual void activate();
+
+  /// The methiod called when widget is deactivated
+  virtual void deactivate();
+
+
  public slots:
 
   /// Activate or deactivate selection
index 0d0f6e384e3c6e21197237272ab2152bef0a4273..6afd8f16afc15194247d6b73195bd5833c3a1f2b 100644 (file)
@@ -43,7 +43,7 @@ XGUI_Displayer::~XGUI_Displayer()
 
 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
 {
-  return myResult2AISObjectMap.find(theObject) != myResult2AISObjectMap.end();
+  return myResult2AISObjectMap.contains(theObject);
 }
 
 void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
@@ -115,7 +115,7 @@ void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
       aContext->Remove(anAIS, isUpdateViewer);
     }
   }
-  myResult2AISObjectMap.erase(theObject);
+  myResult2AISObjectMap.remove(theObject);
 }
 
 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
@@ -189,7 +189,7 @@ bool XGUI_Displayer::isActive(ObjectPtr theObject) const
   if (!isVisible(theObject))
     return false;
     
-  AISObjectPtr anObj = myResult2AISObjectMap.at(theObject);
+  AISObjectPtr anObj = myResult2AISObjectMap[theObject];
   Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
 
   TColStd_ListOfInteger aModes;
@@ -272,13 +272,11 @@ void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
   if (ic.IsNull())
     return;
 
-   ResultToAISMap::iterator aIt;
-   for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
+   foreach (AISObjectPtr aAISObj, myResult2AISObjectMap) {
      // erase an object
-     AISObjectPtr aAISObj = (*aIt).second;
      Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
      if (!anIO.IsNull())
-      ic->Remove(anIO, false);
+       ic->Remove(anIO, false);
    }
    myResult2AISObjectMap.clear();
    if (isUpdateViewer)
@@ -291,25 +289,21 @@ void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer)
   if (aContext.IsNull())
     return;
 
-  ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(), aFLast =
-      myResult2AISObjectMap.end();
-  std::list<ObjectPtr> aRemoved;
-  for (; aFIt != aFLast; aFIt++) {
-    ObjectPtr aFeature = (*aFIt).first;
+  QList<ObjectPtr> aRemoved;
+  foreach (ObjectPtr aFeature, myResult2AISObjectMap.keys()) {
     if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
-      AISObjectPtr anObj = (*aFIt).second;
+      AISObjectPtr anObj = myResult2AISObjectMap[aFeature];
       if (!anObj)
         continue;
       Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
       if (!anAIS.IsNull()) {
         aContext->Remove(anAIS, false);
-        aRemoved.push_back(aFeature);
+        aRemoved.append(aFeature);
       }
     }
   }
-  std::list<ObjectPtr>::const_iterator anIt = aRemoved.begin(), aLast = aRemoved.end();
-  for (; anIt != aLast; anIt++) {
-    myResult2AISObjectMap.erase(myResult2AISObjectMap.find(*anIt));
+  foreach(ObjectPtr aObj, aRemoved) {
+    myResult2AISObjectMap.remove(aObj);
   }
 
   if (isUpdateViewer)
@@ -335,15 +329,32 @@ void XGUI_Displayer::openLocalContext()
 
 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
 {
-  AISContext()->ClearSelected(false);
-  closeAllContexts(true);
+  Handle(AIS_InteractiveContext) ic = AISContext();
+  if ( (!ic.IsNull()) && (ic->HasOpenedContext()) ) {
+    ic->ClearSelected(false);
+    ic->CloseAllContexts(false);
+
+    // Redisplay all object if they were displayed in localContext
+    Handle(AIS_InteractiveObject) aAISIO;
+    foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
+      aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
+      if (ic->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
+        ic->Display(aAISIO, false);
+        ic->SetDisplayMode(aAISIO, Shading, false);
+      }
+    }
+    if (isUpdateViewer)
+      updateViewer();
+    myUseExternalObjects = false;
+    myActiveSelectionModes.clear();
+  }
 }
 
 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
 {
   AISObjectPtr anIO;
-  if (myResult2AISObjectMap.find(theObject) != myResult2AISObjectMap.end())
-    anIO = (myResult2AISObjectMap.find(theObject))->second;
+  if (myResult2AISObjectMap.contains(theObject))
+    anIO = myResult2AISObjectMap[theObject];
   return anIO;
 }
 
@@ -356,32 +367,15 @@ ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
 {
   ObjectPtr aFeature;
-  ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(), aFLast =
-      myResult2AISObjectMap.end();
-  for (; aFIt != aFLast && !aFeature; aFIt++) {
-    AISObjectPtr anObj = (*aFIt).second;
-    if (!anObj)
-      continue;
-    Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
-    if (anAIS != theIO)
-      continue;
-    aFeature = (*aFIt).first;
+  foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
+    AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
+    Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
+    if (anAIS == theIO)
+      return anObj;
   }
   return aFeature;
 }
 
-void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
-{
-  Handle(AIS_InteractiveContext) ic = AISContext();
-  if (!ic.IsNull()) {
-    ic->CloseAllContexts(false);
-    if (isUpdateViewer)
-      updateViewer();
-    myUseExternalObjects = false;
-    myActiveSelectionModes.clear();
-  }
-}
-
 void XGUI_Displayer::updateViewer()
 {
   Handle(AIS_InteractiveContext) ic = AISContext();
@@ -448,10 +442,9 @@ void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes)
     }
   }
 
-  ResultToAISMap::iterator aIt;
   Handle(AIS_InteractiveObject) anAISIO;
-  for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
-  anAISIO = (*aIt).second->impl<Handle(AIS_InteractiveObject)>();
+  foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
+  anAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
     aContext->Load(anAISIO, -1, true);
     if (theModes.size() == 0)
       aContext->Activate(anAISIO);
index 5d770e85ee5b2dd9ae95072d492f4ed6c3911e71..7c1ee1cf7c6c65eb314b96fb90d50e0cff95261f 100644 (file)
@@ -7,11 +7,7 @@
 
 #include "XGUI.h"
 
-#include <QString>
-#include <memory>
-
 #include <GeomAPI_AISObject.h>
-
 #include <TopoDS_Shape.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_InteractiveContext.hxx>
@@ -22,9 +18,8 @@
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_ViewerPrs.h>
 
-#include <map>
-#include <vector>
-#include <list>
+#include <QString>
+#include <QMap>
 
 class XGUI_Viewer;
 class ModelAPI_Feature;
@@ -152,10 +147,6 @@ class XGUI_EXPORT XGUI_Displayer
   int objectsCount() const { return myResult2AISObjectMap.size(); }
 
  protected:
-  /// Deactivate local selection
-  /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
-  void closeAllContexts(const bool isUpdateViewer);
-
   /// Returns currently installed AIS_InteractiveContext
   Handle(AIS_InteractiveContext) AISContext() const;
 
@@ -185,7 +176,7 @@ class XGUI_EXPORT XGUI_Displayer
  protected:
   XGUI_Workshop* myWorkshop;
 
-  typedef std::map<ObjectPtr, AISObjectPtr> ResultToAISMap;
+  typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
   ResultToAISMap myResult2AISObjectMap;
 
   // A flag of initialization of external objects selection
index caa9b07a429195744b440e98611f47a90b5bbb53..d36354589a1c9d57ce2881acae09cac05dda27d5 100644 (file)
@@ -151,9 +151,9 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
   }
   // Normaly focusTo is enough to activate widget
   // here is a special case on mouse click in the viewer
-  if(aNextWidget == NULL) {
-    activateWidget(NULL);
-  }
+  //if(aNextWidget == NULL) {
+    activateWidget(aNextWidget);
+  //}
 }
 
 void XGUI_PropertyPanel::activateNextWidget()
@@ -169,10 +169,15 @@ void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
 
 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
 {
+  // Avoid activation of already actve widget. It could happen on focusIn event many times
+  if (theWidget == myActiveWidget)
+    return;
   if(myActiveWidget) {
+    myActiveWidget->deactivate();
     myActiveWidget->setHighlighted(false);
   }
   if(theWidget) {
+    theWidget->activate();
     theWidget->setHighlighted(true);
   }
   myActiveWidget = theWidget;
index b07d4676aa76480f9cc2b6e374390ad85db1d3d4..3bff59605b5a223abb403224f66321970cbfbe36 100644 (file)
@@ -672,7 +672,7 @@ void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
               if (ic->NbSelected() == 0)
                 myCurrPointType = myPrevPointType;
               //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
-              ic->CloseAllContexts();
+              //ic->CloseAllContexts();
               myOperation = NOTHING;
               myViewPort->setCursor(myCursor);
               myCursorIsHand = false;