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