]> SALOME platform Git repositories - modules/shaper.git/blob - src/NewGeom/NewGeom_Module.cpp
Salome HOME
Adaptation of the application to SALOME interface (issue #31)
[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
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 <QtxActionMenuMgr.h>
20
21 #include <QDockWidget>
22 #include <QAction>
23
24 extern "C" {
25   NewGeom_EXPORT CAM_Module* createModule() {
26     return new NewGeom_Module();
27   }
28     
29   NewGeom_EXPORT char* getModuleVersion() {
30     return "0.0";
31   }
32 }
33
34
35 //******************************************************
36 NewGeom_Module::NewGeom_Module()
37 : LightApp_Module( "NewGeom" ), mySelector(0)
38 {
39   myWorkshop = new XGUI_Workshop(this);
40   myProxyViewer = new NewGeom_SalomeViewer(this);
41 }
42
43 //******************************************************
44 NewGeom_Module::~NewGeom_Module()
45 {
46 }
47
48 //******************************************************
49 void NewGeom_Module::initialize(CAM_Application* theApp)
50 {
51   LightApp_Module::initialize(theApp);
52   
53   myWorkshop->startApplication();
54 }
55
56 //******************************************************
57 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
58 {
59   theWndMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
60 }
61
62 //******************************************************
63 void NewGeom_Module::viewManagers(QStringList& theList) const
64 {
65   theList.append( OCCViewer_Viewer::Type() );
66 }
67
68 //******************************************************
69 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
70 {
71   bool isDone = LightApp_Module::activateModule(theStudy);
72   if (isDone) {
73     setMenuShown( true );
74     setToolShown( true );
75     myWorkshop->propertyPanel()->hide();
76
77     if (!mySelector) {
78       ViewManagerList OCCViewManagers;
79       application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
80       if (OCCViewManagers.size() > 0) {
81         mySelector = createSelector(OCCViewManagers.first());
82       }
83     }
84   }
85   return isDone;
86 }
87
88 //******************************************************
89 void NewGeom_Module::onViewManagerAdded( SUIT_ViewManager* theMgr )
90 {
91   if ((!mySelector)) {
92     mySelector = createSelector(theMgr);
93   }
94 }
95
96 //******************************************************
97 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
98 {
99   if (theMgr->getType() == OCCViewer_Viewer::Type()) {
100     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
101     NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, 
102                                                              getApp()->selectionMgr());
103     LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
104     QList<SUIT_Selector*> aList;
105     aMgr->selectors(aList);
106     foreach(SUIT_Selector* aSel, aList) {
107       aSel->setEnabled(aSel == aSelector);
108     }
109     myProxyViewer->setSelector(aSelector);
110     return aSelector;
111   }
112   return 0;
113 }
114
115 //******************************************************
116 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
117 {
118   setMenuShown( false );
119   setToolShown( false );
120   return LightApp_Module::deactivateModule(theStudy);
121 }
122
123 //******************************************************
124 CAM_DataModel* NewGeom_Module::createDataModel()
125 {
126   return new NewGeom_DataModel( this );
127 }
128
129 //******************************************************
130 QAction* NewGeom_Module::addFeature(const QString& theWBName,
131                                     const QString& theId, 
132                                     const QString& theTitle, 
133                                     const QString& theTip,
134                                     const QIcon& theIcon, 
135                                     const QKeySequence& theKeys,
136                                     bool isCheckable)
137 {
138   int aMenu = createMenu(theWBName, -1, -1, 50);
139   int aTool = createTool(theWBName);
140
141   int aId = myActionsList.size();
142   myActionsList.append(theId);
143   SUIT_Desktop* aDesk = application()->desktop();
144   int aKeys = 0;
145   for (int i = 0; i < theKeys.count(); i++) 
146     aKeys += theKeys[i];
147   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
148                                   isCheckable);
149   aAction->setData(theId);
150   int aItemId = createMenu( aId,  aMenu, -1, 10 );
151   int aToolId = createTool( aId, aTool );
152   return aAction;
153 }
154
155 //******************************************************
156 QAction* NewGeom_Module::addEditCommand(const QString& theId,
157                                         const QString& theTitle,
158                                         const QString& theTip,
159                                         const QIcon& theIcon, 
160                                         const QKeySequence& theKeys,
161                                         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 }