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