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