Salome HOME
Arc problems fixing: 1. reentrant of the tangent arc should not fill center point...
[modules/shaper.git] / src / XGUI / XGUI_ModuleConnector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_ModuleConnector.cpp
4 // Created:     3 June 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "XGUI_ModuleConnector.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_ViewerProxy.h"
10 #include "XGUI_SelectionMgr.h"
11 #include "XGUI_Selection.h"
12 #include "XGUI_OperationMgr.h"
13 #include "XGUI_Displayer.h"
14 #include "XGUI_PropertyPanel.h"
15 #include "XGUI_ActionsMgr.h"
16
17 #include <ModuleBase_IModule.h>
18 #include <ModuleBase_ViewerPrs.h>
19 #include <ModuleBase_OperationDescription.h>
20
21 #include <AIS_Shape.hxx>
22
23 #ifndef HAVE_SALOME
24 #include "AppElements_Command.h"
25 #else
26 #include "XGUI_SalomeConnector.h"
27 #endif
28
29 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
30     : ModuleBase_IWorkshop(theWorkshop),
31       myWorkshop(theWorkshop)
32 {
33   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
34   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
35 }
36
37 XGUI_ModuleConnector::~XGUI_ModuleConnector()
38 {
39 }
40
41 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
42 {
43   return myWorkshop->selector()->selection();
44 }
45
46 ModuleBase_IModule* XGUI_ModuleConnector::module() const
47 {
48   return myWorkshop->module();
49 }
50
51 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
52 {
53   return myWorkshop->viewer();
54 }
55
56 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
57 {
58   return myWorkshop->propertyPanel();
59 }
60
61 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
62 {
63   return myWorkshop->operationMgr()->currentOperation();
64 }
65
66
67 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
68 {
69   QObjectPtrList aActiveOPbjects;
70   ModuleBase_IModule* aModule = myWorkshop->module();
71   // Activate objects only which can be activated
72   foreach (ObjectPtr aObj, theObjList) {
73     if (aModule->canActivateSelection(aObj))
74       aActiveOPbjects.append(aObj);
75   }
76   return aActiveOPbjects;
77 }
78
79 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
80 {
81   QIntList aTypes = theTypes;
82
83   XGUI_Displayer* aDisp = myWorkshop->displayer();
84   myWorkshop->module()->customSubShapesSelectionModes(aTypes);
85   aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
86 }
87
88 void XGUI_ModuleConnector::deactivateSubShapesSelection()
89 {
90   // Clear selection modes
91   activateModuleSelectionModes();
92 }
93
94 void XGUI_ModuleConnector::activateModuleSelectionModes()
95 {
96   XGUI_Displayer* aDisp = myWorkshop->displayer();
97   myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
98 }
99
100 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
101 {
102   XGUI_Displayer* aDisp = myWorkshop->displayer();
103   return aDisp->getAISObject(theObject);
104 }
105
106 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
107 {
108   XGUI_Displayer* aDisp = myWorkshop->displayer();
109   ObjectPtr anObject = aDisp->getObject(theAIS);
110   return anObject;
111 }
112
113 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
114 {
115   XGUI_Displayer* aDisp = myWorkshop->displayer();
116   if (theValues.isEmpty()) {
117     myWorkshop->selector()->clearSelection();
118   } else {
119     aDisp->setSelected(theValues);
120   }    
121 }
122
123 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
124 {
125   myWorkshop->setStatusBarMessage(theMessage);
126 }
127
128 bool XGUI_ModuleConnector::canStartOperation(QString theId)
129 {
130   return myWorkshop->operationMgr()->canStartOperation(theId);
131 }
132
133 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation,
134                                                   const bool isUpdatePropertyPanel)
135 {
136   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
137
138   if (anOperationMgr->startOperation(theOperation)) {
139     if (isUpdatePropertyPanel) {
140       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
141       if (aFOperation) {
142         workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
143         workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
144       }
145     }
146     if (!theOperation->getDescription()->hasXmlRepresentation()) {
147       if (theOperation->commit())
148         workshop()->updateCommandStatus();
149     }
150   }
151 }
152
153 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
154 {
155   return myWorkshop->operationMgr()->findOperation(theId);
156 }
157
158 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
159 {
160   return myWorkshop->operationMgr()->canStopOperation(theOperation);
161 }
162
163 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation)
164 {
165   myWorkshop->operationMgr()->stopOperation(theOperation);
166 }
167
168 void XGUI_ModuleConnector::updateCommandStatus()
169 {
170   myWorkshop->updateCommandStatus();
171 }
172
173 QMainWindow* XGUI_ModuleConnector::desktop() const 
174
175   return myWorkshop->desktop(); 
176 }
177
178
179 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
180 {
181 #ifdef HAVE_SALOME
182   return myWorkshop->salomeConnector()->featureInfo(theId);
183 #else 
184   AppElements_Command* aAction = 
185     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
186   if (aAction)
187     return aAction->featureMessage();
188   return std::shared_ptr<Config_FeatureMessage>();
189 #endif
190 }