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