3 #include "NewGeom_Module.h"
4 #include "NewGeom_DataModel.h"
5 #include "NewGeom_OCCSelector.h"
7 #include <XGUI_Workshop.h>
8 #include <XGUI_PropertyPanel.h>
9 #include <XGUI_ContextMenuMgr.h>
11 #include <LightApp_Application.h>
12 #include <LightApp_SelectionMgr.h>
13 #include <LightApp_OCCSelector.h>
14 #include <OCCViewer_ViewModel.h>
16 #include <SUIT_Selector.h>
17 #include <SUIT_Desktop.h>
18 #include <SUIT_ViewManager.h>
20 #include <QtxPopupMgr.h>
21 #include <QtxActionMenuMgr.h>
23 #include <QDockWidget>
27 NewGeom_EXPORT CAM_Module* createModule() {
28 return new NewGeom_Module();
31 NewGeom_EXPORT char* getModuleVersion() {
37 //******************************************************
38 NewGeom_Module::NewGeom_Module()
39 : LightApp_Module( "NewGeom" ), mySelector(0)
41 myWorkshop = new XGUI_Workshop(this);
42 myProxyViewer = new NewGeom_SalomeViewer(this);
45 //******************************************************
46 NewGeom_Module::~NewGeom_Module()
50 //******************************************************
51 void NewGeom_Module::initialize(CAM_Application* theApp)
53 LightApp_Module::initialize(theApp);
55 myWorkshop->startApplication();
58 //******************************************************
59 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
61 theWndMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
64 //******************************************************
65 void NewGeom_Module::viewManagers(QStringList& theList) const
67 theList.append( OCCViewer_Viewer::Type() );
70 //******************************************************
71 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
73 bool isDone = LightApp_Module::activateModule(theStudy);
79 ViewManagerList OCCViewManagers;
80 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
81 if (OCCViewManagers.size() > 0) {
82 mySelector = createSelector(OCCViewManagers.first());
85 myWorkshop->propertyPanel()->hide();
86 QtxPopupMgr* aMgr = popupMgr(); // Create popup manager
87 action(myEraseAll)->setEnabled(false);
92 //******************************************************
93 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
95 setMenuShown( false );
96 setToolShown( false );
97 //myWorkshop->contextMenuMgr()->disconnectViewer();
98 return LightApp_Module::deactivateModule(theStudy);
101 //******************************************************
102 void NewGeom_Module::onViewManagerAdded( SUIT_ViewManager* theMgr )
105 mySelector = createSelector(theMgr);
109 //******************************************************
110 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
112 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
113 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
114 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer,
115 getApp()->selectionMgr());
116 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
117 QList<SUIT_Selector*> aList;
118 aMgr->selectors(aList);
119 foreach(SUIT_Selector* aSel, aList) {
120 aSel->setEnabled(aSel == aSelector);
122 myProxyViewer->setSelector(aSelector);
128 //******************************************************
129 CAM_DataModel* NewGeom_Module::createDataModel()
131 return new NewGeom_DataModel( this );
134 //******************************************************
135 QAction* NewGeom_Module::addFeature(const QString& theWBName,
136 const QString& theId,
137 const QString& theTitle,
138 const QString& theTip,
139 const QIcon& theIcon,
140 const QKeySequence& theKeys,
143 int aMenu = createMenu(theWBName, -1, -1, 50);
144 int aTool = createTool(theWBName);
146 int aId = myActionsList.size();
147 myActionsList.append(theId);
148 SUIT_Desktop* aDesk = application()->desktop();
150 for (int i = 0; i < theKeys.count(); i++)
152 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
154 aAction->setData(theId);
155 int aItemId = createMenu( aId, aMenu, -1, 10 );
156 int aToolId = createTool( aId, aTool );
160 //******************************************************
161 QAction* NewGeom_Module::addEditCommand(const QString& theId,
162 const QString& theTitle,
163 const QString& theTip,
164 const QIcon& theIcon,
165 const QKeySequence& theKeys,
168 int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1);
170 int aId = myActionsList.size();
171 myActionsList.append(theId);
172 SUIT_Desktop* aDesk = application()->desktop();
174 for (int i = 0; i < theKeys.count(); i++)
176 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
178 aAction->setData(theId);
179 createMenu( aId, aMenu, 10 );
183 //******************************************************
184 void NewGeom_Module::addEditMenuSeparator()
186 int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1);
187 createMenu( separator(), aMenu, -1, 10 );
190 //******************************************************
191 QList<QAction*> NewGeom_Module::commandList() const
193 QList<QAction*> aActions;
194 for (int i = 0; i < myActionsList.size(); i++)
195 aActions.append(action(i));
199 //******************************************************
200 QStringList NewGeom_Module::commandIdList() const
202 return myActionsList;
205 //******************************************************
206 QMainWindow* NewGeom_Module::desktop() const
208 return application()->desktop();
211 //******************************************************
212 QString NewGeom_Module::commandId(const QAction* theCmd) const
214 int aId = actionId(theCmd);
215 if (aId < myActionsList.size())
216 return myActionsList[aId];
220 //******************************************************
221 QAction* NewGeom_Module::command(const QString& theId) const
223 int aId = myActionsList.indexOf(theId);
224 if ((aId != -1) && (aId < myActionsList.size())) {
230 //******************************************************
231 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
233 myNestedActions[theId] = theActions;
236 //******************************************************
237 QStringList NewGeom_Module::nestedActions(const QString& theId) const
239 if (myNestedActions.contains(theId))
240 return myNestedActions[theId];
241 return QStringList();
244 //******************************************************
245 void NewGeom_Module::selectionChanged()
247 LightApp_Module::selectionChanged();
248 myWorkshop->salomeViewerSelectionChanged();
251 //******************************************************
252 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
254 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
255 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);