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