Salome HOME
Sources formated according to the codeing standards
[modules/shaper.git] / src / NewGeom / NewGeom_Module.cpp
1
2 #include "NewGeom_Module.h"
3 #include "NewGeom_DataModel.h"
4 #include "NewGeom_OCCSelector.h"
5
6 #include <XGUI_Workshop.h>
7 #include <XGUI_PropertyPanel.h>
8 #include <XGUI_ContextMenuMgr.h>
9
10 #include <LightApp_Application.h>
11 #include <LightApp_SelectionMgr.h>
12 #include <LightApp_OCCSelector.h>
13 #include <OCCViewer_ViewModel.h>
14
15 #include <SUIT_Selector.h>
16 #include <SUIT_Desktop.h>
17 #include <SUIT_ViewManager.h>
18
19 #include <QtxPopupMgr.h>
20 #include <QtxActionMenuMgr.h>
21
22 #include <QDockWidget>
23 #include <QAction>
24
25 extern "C" {
26 NewGeom_EXPORT CAM_Module* createModule()
27 {
28   return new NewGeom_Module();
29 }
30
31 NewGeom_EXPORT char* getModuleVersion()
32 {
33   return "0.0";
34 }
35 }
36
37 //******************************************************
38 NewGeom_Module::NewGeom_Module()
39     : LightApp_Module("NewGeom"),
40       mySelector(0)
41 {
42   myWorkshop = new XGUI_Workshop(this);
43   myProxyViewer = new NewGeom_SalomeViewer(this);
44 }
45
46 //******************************************************
47 NewGeom_Module::~NewGeom_Module()
48 {
49 }
50
51 //******************************************************
52 void NewGeom_Module::initialize(CAM_Application* theApp)
53 {
54   LightApp_Module::initialize(theApp);
55
56   myWorkshop->startApplication();
57 }
58
59 //******************************************************
60 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
61 {
62   theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
63 }
64
65 //******************************************************
66 void NewGeom_Module::viewManagers(QStringList& theList) const
67 {
68   theList.append(OCCViewer_Viewer::Type());
69 }
70
71 //******************************************************
72 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
73 {
74   bool isDone = LightApp_Module::activateModule(theStudy);
75   if (isDone) {
76     setMenuShown(true);
77     setToolShown(true);
78
79     if (!mySelector) {
80       ViewManagerList OCCViewManagers;
81       application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
82       if (OCCViewManagers.size() > 0) {
83         mySelector = createSelector(OCCViewManagers.first());
84       }
85     }
86     myWorkshop->propertyPanel()->hide();
87     QtxPopupMgr* aMgr = popupMgr();  // Create popup manager
88     action(myEraseAll)->setEnabled(false);
89   }
90   return isDone;
91 }
92
93 //******************************************************
94 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
95 {
96   setMenuShown(false);
97   setToolShown(false);
98   //myWorkshop->contextMenuMgr()->disconnectViewer();
99   return LightApp_Module::deactivateModule(theStudy);
100 }
101
102 //******************************************************
103 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
104 {
105   if ((!mySelector)) {
106     mySelector = createSelector(theMgr);
107   }
108 }
109
110 //******************************************************
111 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
112 {
113   if (theMgr->getType() == OCCViewer_Viewer::Type()) {
114     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
115     NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
116     LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
117     QList<SUIT_Selector*> aList;
118     aMgr->selectors(aList);
119     foreach(SUIT_Selector* aSel, aList)
120     {
121       aSel->setEnabled(aSel == aSelector);
122     }
123     myProxyViewer->setSelector(aSelector);
124     return aSelector;
125   }
126   return 0;
127 }
128
129 //******************************************************
130 CAM_DataModel* NewGeom_Module::createDataModel()
131 {
132   return new NewGeom_DataModel(this);
133 }
134
135 //******************************************************
136 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
137                                     const QString& theTitle, const QString& theTip,
138                                     const QIcon& theIcon, const QKeySequence& theKeys,
139                                     bool isCheckable)
140 {
141   int aMenu = createMenu(theWBName, -1, -1, 50);
142   int aTool = createTool(theWBName);
143
144   int aId = myActionsList.size();
145   myActionsList.append(theId);
146   SUIT_Desktop* aDesk = application()->desktop();
147   int aKeys = 0;
148   for (int i = 0; i < theKeys.count(); i++)
149     aKeys += theKeys[i];
150   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
151                                   isCheckable);
152   aAction->setData(theId);
153   int aItemId = createMenu(aId, aMenu, -1, 10);
154   int aToolId = createTool(aId, aTool);
155   return aAction;
156 }
157
158 //******************************************************
159 QAction* NewGeom_Module::addEditCommand(const QString& theId, const QString& theTitle,
160                                         const QString& theTip, const QIcon& theIcon,
161                                         const QKeySequence& theKeys, bool isCheckable)
162 {
163   int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
164
165   int aId = myActionsList.size();
166   myActionsList.append(theId);
167   SUIT_Desktop* aDesk = application()->desktop();
168   int aKeys = 0;
169   for (int i = 0; i < theKeys.count(); i++)
170     aKeys += theKeys[i];
171   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
172                                   isCheckable);
173   aAction->setData(theId);
174   createMenu(aId, aMenu, 10);
175   return aAction;
176 }
177
178 //******************************************************
179 void NewGeom_Module::addEditMenuSeparator()
180 {
181   int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
182   createMenu(separator(), aMenu, -1, 10);
183 }
184
185 //******************************************************
186 QList<QAction*> NewGeom_Module::commandList() const
187 {
188   QList<QAction*> aActions;
189   for (int i = 0; i < myActionsList.size(); i++)
190     aActions.append(action(i));
191   return aActions;
192 }
193
194 //******************************************************
195 QStringList NewGeom_Module::commandIdList() const
196 {
197   return myActionsList;
198 }
199
200 //******************************************************
201 QMainWindow* NewGeom_Module::desktop() const
202 {
203   return application()->desktop();
204 }
205
206 //******************************************************
207 QString NewGeom_Module::commandId(const QAction* theCmd) const
208 {
209   int aId = actionId(theCmd);
210   if (aId < myActionsList.size())
211     return myActionsList[aId];
212   return QString();
213 }
214
215 //******************************************************
216 QAction* NewGeom_Module::command(const QString& theId) const
217 {
218   int aId = myActionsList.indexOf(theId);
219   if ((aId != -1) && (aId < myActionsList.size())) {
220     return action(aId);
221   }
222   return 0;
223 }
224
225 //******************************************************
226 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
227 {
228   myNestedActions[theId] = theActions;
229 }
230
231 //******************************************************
232 QStringList NewGeom_Module::nestedActions(const QString& theId) const
233 {
234   if (myNestedActions.contains(theId))
235     return myNestedActions[theId];
236   return QStringList();
237 }
238
239 //******************************************************
240 void NewGeom_Module::selectionChanged()
241 {
242   LightApp_Module::selectionChanged();
243   myWorkshop->salomeViewerSelectionChanged();
244 }
245
246 //******************************************************
247 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
248 {
249   myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
250   LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
251 }