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