Update Undo/Redo action enable state.
#include <ModelAPI_Events.h>
#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Session.h>
#include <Config_PointerMessage.h>
#include <Config_WidgetReader.h>
return anOperation && anOperation->hasObject(theObject);
}
+bool ModuleBase_IModule::canUndo() const
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ return aMgr->hasModuleDocument() && aMgr->canUndo() && !aMgr->isOperation();
+}
+
+bool ModuleBase_IModule::canRedo() const
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ return aMgr->hasModuleDocument() && aMgr->canRedo() && !aMgr->isOperation();
+}
+
void ModuleBase_IModule::onFeatureTriggered()
{
QAction* aCmd = dynamic_cast<QAction*>(sender());
/// It is called as on clearing of property panel as on filling with new widgets\r
virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}\r
\r
+ //! Returns True if there are available Undos and there is not an active operation\r
+ virtual bool canUndo() const;\r
+\r
+ //! Returns True if there are available Redos and there is not an active operation\r
+ virtual bool canRedo() const;\r
+\r
/// Returns whether the object can be displayed at the bounds of the active operation.\r
/// Display only current operation results\r
/// \param theObject a model object\r
\r
/// Register selection filters for this module\r
virtual void registerFilters() {}\r
-
- /// Register properties of this module
- virtual void registerProperties() {}
+\r
+ /// Register properties of this module\r
+ virtual void registerProperties() {}\r
\r
/// Returns new instance of operation object (used in createOperation for customization)\r
virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);\r
myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
}
+bool PartSet_Module::canUndo() const
+{
+ bool aCanUndo = false;
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
+ aCanUndo = !aMgr->isOperation();
+ if (!aCanUndo) // check the enable state additionally by sketch manager
+ aCanUndo = aMgr->canUndo();
+ }
+ return aCanUndo;
+}
+
+bool PartSet_Module::canRedo() const
+{
+ bool aCanRedo = false;
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
+ aCanRedo = !aMgr->isOperation();
+ if (!aCanRedo) // check the enable state additionally by sketch manager
+ aCanRedo = aMgr->canRedo();
+ }
+ return aCanRedo;
+}
+
bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
{
bool aCanDisplay = false;
/// \param theOperation a stopped operation
virtual void operationStopped(ModuleBase_Operation* theOperation);
+ /// Returns True if there are available Undos and the sketch manager allows undo
+ /// \return the boolean result
+ virtual bool canUndo() const;
+
+ //! Returns True if there are available Redos and the sketch manager allows redo
+ /// \return the boolean result
+ virtual bool canRedo() const;
+
/// Returns whether the object can be displayed at the bounds of the active operation.
/// Display only current operation results for usual operation and ask the sketcher manager
/// if it is a sketch operation
#include "PartSet_SketcherMgr.h"
#include "PartSet_Module.h"
#include "PartSet_WidgetPoint2d.h"
+#include "PartSet_WidgetPoint2dDistance.h"
#include "PartSet_Tools.h"
#include <XGUI_ModuleConnector.h>
PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
: QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
- myIsMouseOverWindow(false), myIsPropertyPanelValueChanged(false)
+ myIsPropertyPanelValueChanged(false), myIsMouseOverViewProcessed(true)
{
ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
void PartSet_SketcherMgr::onMouseMoveOverWindow(bool theOverWindow)
{
- ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
- if (!aOperation || aOperation->isEditOperation())
+ if (!isNestedCreateOperation() || theOverWindow)
return;
-
- myIsMouseOverWindow = theOverWindow;
- if (theOverWindow)
+ // 1. if the mouse over window, update the next flag. Do not perform update visibility of
+ // created feature because it should be done in onMouseMove(). Some widgets watch
+ // the mouse move and use the cursor position to update own values. If the presentaion is
+ // redisplayed before this update, the feature presentation jumps from reset value to current.
+ if (theOverWindow) {
myIsPropertyPanelValueChanged = false;
- else {
- ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
- ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
- if(aActiveWgt) {
- aActiveWgt->reset();
- }
- }
+ return;
+ }
+ myIsMouseOverViewProcessed = false;
+
+ // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
+ ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+ XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+ // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
+ // obtained after reset value
+ bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
+ ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+ ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
+ if (aActiveWgt) {
+ aActiveWgt->reset();
+ }
+ aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
+
+ // hides the presentation of the current operation feature
+ myIsPropertyPanelValueChanged = false;
updateVisibilityOfCreatedFeature();
}
void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
{
- ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
- if (!aOperation || aOperation->isEditOperation())
+ if (!isNestedCreateOperation())
return;
+ // visualize the current operation feature
myIsPropertyPanelValueChanged = true;
-
updateVisibilityOfCreatedFeature();
}
void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
+ if (isNestedCreateOperation() && !myIsMouseOverViewProcessed) {
+ myIsMouseOverViewProcessed = true;
+ // 1. perform the widget mouse move functionality and display the presentation
+ ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+ ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
+ // the mouse move should be processed in the widget, if it can in order to visualize correct
+ // presentation. These widgets correct the feature attribute according to the mouse position
+ PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
+ if (aPoint2DWdg) {
+ aPoint2DWdg->onMouseMove(theWnd, theEvent);
+ }
+ PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
+ (anActiveWdg);
+ if (aDistanceWdg) {
+ aDistanceWdg->onMouseMove(theWnd, theEvent);
+ }
+ updateVisibilityOfCreatedFeature();
+ }
+
myClickedPoint.clear();
if (myIsDragging) {
void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* )
{
connectToPropertyPanel(false);
+ myIsPropertyPanelValueChanged = false;
+ myIsMouseOverViewProcessed = true;
+}
+
+bool PartSet_SketcherMgr::canUndo() const
+{
+ return isNestedCreateOperation();
+}
+
+bool PartSet_SketcherMgr::canRedo() const
+{
+ return isNestedCreateOperation();
}
bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
{
- return myIsMouseOverWindow || myIsPropertyPanelValueChanged;
+ bool aCanDisplay = true;
+ if (!isNestedCreateOperation())
+ return aCanDisplay;
+
+ // during a nested create operation, the feature is redisplayed only if the mouse over view
+ // of there was a value modified in the property panel after the mouse left the view
+ aCanDisplay = myIsPropertyPanelValueChanged;
+ if (!aCanDisplay) {
+ ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ AppElements_MainWindow* aMainWindow = aWorkshop->mainWindow();
+
+ aCanDisplay = aMainWindow->isMouseOverWindow();
+ }
+ return aCanDisplay;
}
void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
}
}
+bool PartSet_SketcherMgr::isNestedCreateOperation() const
+{
+ ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+ return aOperation && !aOperation->isEditOperation() && isNestedSketchOperation(aOperation);
+}
+
void PartSet_SketcherMgr::updateVisibilityOfCreatedFeature()
{
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
}
}
aDisplayer->updateViewer();
-}
\ No newline at end of file
+}
/// Stops sketch operation
void stopNestedSketch(ModuleBase_Operation* );
+ /// Returns True if there are available Undos and the sketch manager allows undo
+ /// \return the boolean result
+ bool canUndo() const;
+
+ //! Returns True if there are available Redos and the sketch manager allows redo
+ /// \return the boolean result
+ bool canRedo() const;
+
/// Returns whether the object can be displayed at the bounds of the active operation.
/// Display only current operation results for usual operation and ask the sketcher manager
/// if it is a sketch operation
/// \param isToConnect a boolean value whether connect or disconnect
void connectToPropertyPanel(const bool isToConnect);
+ /// Returns true if the created feature is visible
+ /// \param
+ bool isVisibleCreatedFeature() const;
+
+ /// Returns true if the current operation is create a nested feature
+ //// \return boolean value
+ bool isNestedCreateOperation() const;
+
+ /// Erase or display the feature of the current operation. If the mouse over the active view or
+ /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
void updateVisibilityOfCreatedFeature();
private:
bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
bool myIsDragging;
bool myDragDone;
- bool myIsMouseOverWindow; /// the state that mouse is over view
bool myIsPropertyPanelValueChanged; /// the state that value in the property panel is changed
+ bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
Point myCurrentPoint;
Point myClickedPoint;
/// Signal about selection of an existing vertex from an object
void vertexSelected();
-protected slots:
- /// Process mouse release event
+public slots:
+ /// Process mouse move event
/// \param theWnd a view window
/// \param theEvent a mouse event
- void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
+ void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
- /// Process mouse move event
+protected slots:
+ /// Process mouse release event
/// \param theWnd a view window
/// \param theEvent a mouse event
- void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
+ void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
protected:
/// Saves the internal parameters to the given feature
/// Set sketch instance
void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
- protected slots:
- /// Process of mouse release
+public slots:
+ /// Process of mouse move
/// \param theWnd a pointer to a window
/// \param theEvent a mouse event
- void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
+ void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
- /// Process of mouse move
+ protected slots:
+ /// Process of mouse release
/// \param theWnd a pointer to a window
/// \param theEvent a mouse event
- void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
+ void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
protected:
/// The methiod called when widget is activated
// Enable all commands
aCmd->setEnabled(true);
}
- aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation());
- aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation());
+ aUndoCmd->setEnabled(myModule->canUndo());
+ aRedoCmd->setEnabled(myModule->canRedo());
updateHistory();