From: vsv Date: Wed, 19 Nov 2014 09:51:34 +0000 (+0300) Subject: Redisplay objects after closing interactive context. Activate/Deactivate widget metho... X-Git-Tag: V_0.6.0^2~63 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=715da9e329ec0c7046067340831b6c168cc2dc96;p=modules%2Fshaper.git Redisplay objects after closing interactive context. Activate/Deactivate widget methods are added --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 5787ccfb0..08a33e42d 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -1,61 +1,61 @@ -#ifndef ModuleBase_IModule_H -#define ModuleBase_IModule_H - -#include "ModuleBase.h" -#include "ModuleBase_IWorkshop.h" - -#include -#include - - -class QAction; +#ifndef ModuleBase_IModule_H +#define ModuleBase_IModule_H + +#include "ModuleBase.h" +#include "ModuleBase_IWorkshop.h" + +#include +#include + + +class QAction; class QMouseEvent; class QKeyEvent; -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& theModelWidgets) - { - return 0; - } - - ModuleBase_IWorkshop* workshop() const { return myWorkshop; } - -protected slots: - - /// Called on selection changed event - virtual void onSelectionChanged() {} - +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& theModelWidgets) + { + return 0; + } + + ModuleBase_IWorkshop* workshop() const { return myWorkshop; } + +protected slots: + + /// Called on selection changed event + virtual void onSelectionChanged() {} + /// SLOT, that is called by mouse press in the viewer. /// The mouse released point is sent to the current operation to be processed. /// \param theEvent the mouse event @@ -78,30 +78,30 @@ protected slots: /// SLOT, that is called by the key in the viewer is clicked. /// \param theEvent the mouse event virtual void onKeyRelease(QKeyEvent* theEvent) {} - - 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 + + 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 diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 7e77804ac..9f55dab1e 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -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; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 91cc255e8..146e62efb 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -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); +} diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 7284d8ae5..eef773421 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -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 diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 0d0f6e384..6afd8f16a 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -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(); 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(); 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 aRemoved; - for (; aFIt != aFLast; aFIt++) { - ObjectPtr aFeature = (*aFIt).first; + QList 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(); if (!anAIS.IsNull()) { aContext->Remove(anAIS, false); - aRemoved.push_back(aFeature); + aRemoved.append(aFeature); } } } - std::list::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(); + 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(); - if (anAIS != theIO) - continue; - aFeature = (*aFIt).first; + foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) { + AISObjectPtr aAIS = myResult2AISObjectMap[anObj]; + Handle(AIS_InteractiveObject) anAIS = aAIS->impl(); + 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(); + foreach (AISObjectPtr aAIS, myResult2AISObjectMap) { + anAISIO = aAIS->impl(); aContext->Load(anAISIO, -1, true); if (theModes.size() == 0) aContext->Activate(anAISIO); diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 5d770e85e..7c1ee1cf7 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -7,11 +7,7 @@ #include "XGUI.h" -#include -#include - #include - #include #include #include @@ -22,9 +18,8 @@ #include #include -#include -#include -#include +#include +#include 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 ResultToAISMap; + typedef QMap ResultToAISMap; ResultToAISMap myResult2AISObjectMap; // A flag of initialization of external objects selection diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index caa9b07a4..d36354589 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -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; diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index b07d4676a..3bff59605 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -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;