Salome HOME
Update Part item on activation of loaded document
[modules/shaper.git] / src / PartSet / PartSet_LockApplyMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_LockApplyMgr.cpp
4 // Created:     25 Jun 2015
5 // Author:      Natalia Ermolaeva
6
7 #include "PartSet_LockApplyMgr.h"
8 #include "PartSet_Module.h"
9
10 #include <ModuleBase_IWorkshop.h>
11 #include <ModuleBase_IViewer.h>
12
13 #include <XGUI_Workshop.h>
14 #include <XGUI_ViewerProxy.h>
15 #include <XGUI_ModuleConnector.h>
16 #include <XGUI_OperationMgr.h>
17
18 PartSet_LockApplyMgr::PartSet_LockApplyMgr(QObject* theParent,
19                                            ModuleBase_IWorkshop* theWorkshop)
20 : QObject(theParent), myWorkshop(theWorkshop)
21 {
22 }
23
24 void PartSet_LockApplyMgr::activate()
25 {
26   XGUI_ViewerProxy* aViewer = dynamic_cast<XGUI_ViewerProxy*>(myWorkshop->viewer());
27   connect(aViewer, SIGNAL(enterViewPort()), this, SLOT(onLockValidating()));
28   connect(aViewer, SIGNAL(leaveViewPort()), this, SLOT(onUnlockValidating()));
29
30   PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
31   if (aModule->isMouseOverWindow())
32     onLockValidating();
33 }
34
35 void PartSet_LockApplyMgr::deactivate()
36 {
37   XGUI_ViewerProxy* aViewer = dynamic_cast<XGUI_ViewerProxy*>(myWorkshop->viewer());
38   disconnect(aViewer, SIGNAL(enterViewPort()), this, SLOT(onLockValidating()));
39   disconnect(aViewer, SIGNAL(leaveViewPort()), this, SLOT(onUnlockValidating()));
40
41   onUnlockValidating();
42 }
43
44 void PartSet_LockApplyMgr::valuesChanged()
45 {
46   operationMgr()->setLockValidating(false);
47 }
48
49 void PartSet_LockApplyMgr::onLockValidating()
50 {
51   XGUI_OperationMgr* anOperationMgr = operationMgr();
52
53   anOperationMgr->setLockValidating(true);
54   // the Ok button should be disabled in the property panel by moving the mouse point in the viewer
55   // this leads that the user does not try to click Ok and it avoids an incorrect situation that the
56   // line is moved to the cursor to the Ok button
57   //anOperationMgr->setApplyEnabled(false);
58 }
59
60 void PartSet_LockApplyMgr::onUnlockValidating()
61 {
62   XGUI_OperationMgr* anOperationMgr = operationMgr();
63
64   // it is important to restore the validity state in the property panel after leaving the
65   // view port. Unlock the validating.
66   if (anOperationMgr->isValidationLocked()) {
67     anOperationMgr->setLockValidating(false);
68     //anOperationMgr->onValidateOperation();
69   }
70 }
71
72 XGUI_OperationMgr* PartSet_LockApplyMgr::operationMgr() const
73 {
74   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
75   XGUI_Workshop* aWorkshop = aConnector->workshop();
76
77   return aWorkshop->operationMgr();
78 }