Salome HOME
Merge branch 'master' of newgeom:newgeom
[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
23 extern "C" {
24   NewGeom_EXPORT CAM_Module* createModule() {
25     return new NewGeom_Module();
26   }
27     
28   NewGeom_EXPORT char* getModuleVersion() {
29     return "0.0";
30   }
31 }
32
33
34 //******************************************************
35 NewGeom_Module::NewGeom_Module()
36 : LightApp_Module( "NewGeom" ), mySelector(0)
37 {
38   myWorkshop = new XGUI_Workshop(this);
39   myProxyViewer = new NewGeom_SalomeViewer(this);
40 }
41
42 //******************************************************
43 NewGeom_Module::~NewGeom_Module()
44 {
45 }
46
47 //******************************************************
48 void NewGeom_Module::initialize(CAM_Application* theApp)
49 {
50   LightApp_Module::initialize(theApp);
51   
52   myWorkshop->startApplication();
53 }
54
55 //******************************************************
56 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
57 {
58   theWndMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
59 }
60
61 //******************************************************
62 void NewGeom_Module::viewManagers(QStringList& theList) const
63 {
64   theList.append( OCCViewer_Viewer::Type() );
65 }
66
67 //******************************************************
68 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
69 {
70   bool isDone = LightApp_Module::activateModule(theStudy);
71   if (isDone) {
72     setMenuShown( true );
73     setToolShown( true );
74     myWorkshop->propertyPanel()->hide();
75
76     if (!mySelector) {
77       ViewManagerList OCCViewManagers;
78       application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
79       if (OCCViewManagers.size() > 0) {
80         mySelector = createSelector(OCCViewManagers.first());
81       }
82     }
83   }
84   return isDone;
85 }
86
87 //******************************************************
88 void NewGeom_Module::onViewManagerAdded( SUIT_ViewManager* theMgr )
89 {
90   if ((!mySelector)) {
91     mySelector = createSelector(theMgr);
92   }
93 }
94
95 //******************************************************
96 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
97 {
98   if (theMgr->getType() == OCCViewer_Viewer::Type()) {
99     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
100     NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, 
101                                                              getApp()->selectionMgr());
102     LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
103     QList<SUIT_Selector*> aList;
104     aMgr->selectors(aList);
105     foreach(SUIT_Selector* aSel, aList) {
106       aSel->setEnabled(aSel == aSelector);
107     }
108     myProxyViewer->setSelector(aSelector);
109     return aSelector;
110   }
111   return 0;
112 }
113
114 //******************************************************
115 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
116 {
117   setMenuShown( false );
118   setToolShown( false );
119   return LightApp_Module::deactivateModule(theStudy);
120 }
121
122 //******************************************************
123 CAM_DataModel* NewGeom_Module::createDataModel()
124 {
125   return new NewGeom_DataModel( this );
126 }
127
128 //******************************************************
129 void NewGeom_Module::addFeature(const QString& theWBName,
130                                 const QString& theId, 
131                                 const QString& theTitle, 
132                                 const QString& theTip,
133                                 const QIcon& theIcon, 
134                                 bool isCheckable,
135                                 QObject* theReciever,
136                                 const char* theMember,
137                                 const QKeySequence& theKeys)
138 {
139   int aMenu = createMenu(theWBName, -1, -1, 50);
140   int aTool = createTool(theWBName);
141
142   int aId = myActionsList.size();
143   myActionsList.append(theId);
144   SUIT_Desktop* aDesk = application()->desktop();
145   int aKeys = 0;
146   for (int i = 0; i < theKeys.count(); i++) 
147     aKeys += theKeys[i];
148   createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
149                isCheckable, theReciever, theMember);
150   int aItemId = createMenu( aId,  aMenu, -1, 10 );
151   int aToolId = createTool( aId, aTool );
152 }
153
154 //******************************************************
155 void NewGeom_Module::addEditCommand(const QString& theId,
156                                     const QString& theTitle,
157                                     const QString& theTip,
158                                     const QIcon& theIcon, 
159                                     bool isCheckable,
160                                     QObject* theReciever,
161                                     const char* theMember,
162                                     const QKeySequence& theKeys)
163 {
164   int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1);
165
166   int aId = myActionsList.size();
167   myActionsList.append(theId);
168   SUIT_Desktop* aDesk = application()->desktop();
169   int aKeys = 0;
170   for (int i = 0; i < theKeys.count(); i++) 
171     aKeys += theKeys[i];
172   createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
173                isCheckable, theReciever, theMember);
174   createMenu( aId, aMenu, 10 );
175 }
176
177 //******************************************************
178 void NewGeom_Module::addEditMenuSeparator()
179 {
180   int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1);
181   createMenu( separator(), aMenu, -1, 10 );
182 }
183
184 //******************************************************
185 QMainWindow* NewGeom_Module::desktop() const
186 {
187   return application()->desktop();
188 }
189
190 //******************************************************
191 QString NewGeom_Module::commandId(const QAction* theCmd) const
192 {
193   int aId = actionId(theCmd);
194   if (aId < myActionsList.size())
195     return myActionsList[aId];
196   return QString();
197 }
198
199 //******************************************************
200 QAction* NewGeom_Module::command(const QString& theId) const
201 {
202   int aId = myActionsList.indexOf(theId);
203   if ((aId != -1) && (aId < myActionsList.size())) {
204     return action(aId);
205   }
206   return 0;
207 }
208
209 //******************************************************
210 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
211 {
212   myNestedActions[theId] = theActions;
213 }
214
215 //******************************************************
216 QStringList NewGeom_Module::nestedActions(const QString& theId) const
217 {
218   if (myNestedActions.contains(theId))
219     return myNestedActions[theId];
220   return QStringList();
221 }
222
223 //******************************************************
224 void NewGeom_Module::selectionChanged()
225 {
226   LightApp_Module::selectionChanged();
227   myWorkshop->salomeViewerSelectionChanged();
228 }