2 #include "NewGeom_Module.h"
3 #include "NewGeom_DataModel.h"
4 #include "NewGeom_OCCSelector.h"
6 #include <XGUI_Workshop.h>
7 #include <XGUI_PropertyPanel.h>
8 #include <XGUI_ContextMenuMgr.h>
9 #include <XGUI_Preferences.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>
19 #include <SUIT_ResourceMgr.h>
21 #include <QtxPopupMgr.h>
22 #include <QtxActionMenuMgr.h>
23 #include <QtxResourceMgr.h>
25 #include <Config_PropManager.h>
27 #include <QDockWidget>
31 NewGeom_EXPORT CAM_Module* createModule()
33 return new NewGeom_Module();
36 NewGeom_EXPORT char* getModuleVersion()
42 class NewGeom_PrefMgr: public XGUI_IPrefMgr
45 NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {}
47 virtual int addPreference(const QString& theLbl, int pId,
48 SUIT_PreferenceMgr::PrefItemType theType,
49 const QString& theSection, const QString& theName )
51 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
54 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
57 LightApp_Preferences* myMgr;
64 //******************************************************
65 NewGeom_Module::NewGeom_Module()
66 : LightApp_Module("NewGeom"),
69 myWorkshop = new XGUI_Workshop(this);
70 myProxyViewer = new NewGeom_SalomeViewer(this);
72 XGUI_Preferences::setResourceMgr(application()->resourceMgr());
73 XGUI_Preferences::loadCustomProps();
76 //******************************************************
77 NewGeom_Module::~NewGeom_Module()
81 //******************************************************
82 void NewGeom_Module::initialize(CAM_Application* theApp)
84 LightApp_Module::initialize(theApp);
86 myWorkshop->startApplication();
89 //******************************************************
90 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
92 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
95 //******************************************************
96 void NewGeom_Module::viewManagers(QStringList& theList) const
98 theList.append(OCCViewer_Viewer::Type());
101 //******************************************************
102 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
104 bool isDone = LightApp_Module::activateModule(theStudy);
110 ViewManagerList OCCViewManagers;
111 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
112 if (OCCViewManagers.size() > 0) {
113 mySelector = createSelector(OCCViewManagers.first());
116 myWorkshop->propertyPanel()->hide();
117 QtxPopupMgr* aMgr = popupMgr(); // Create popup manager
118 action(myEraseAll)->setEnabled(false);
123 //******************************************************
124 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
128 //myWorkshop->contextMenuMgr()->disconnectViewer();
129 return LightApp_Module::deactivateModule(theStudy);
132 //******************************************************
133 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
136 mySelector = createSelector(theMgr);
140 //******************************************************
141 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
143 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
144 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
145 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
146 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
147 QList<SUIT_Selector*> aList;
148 aMgr->selectors(aList);
149 foreach(SUIT_Selector* aSel, aList)
151 aSel->setEnabled(aSel == aSelector);
153 myProxyViewer->setSelector(aSelector);
159 //******************************************************
160 CAM_DataModel* NewGeom_Module::createDataModel()
162 return new NewGeom_DataModel(this);
165 //******************************************************
166 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
167 const QString& theTitle, const QString& theTip,
168 const QIcon& theIcon, const QKeySequence& theKeys,
171 int aMenu = createMenu(theWBName, -1, -1, 50);
172 int aTool = createTool(theWBName);
174 int aId = myActionsList.size();
175 myActionsList.append(theId);
176 SUIT_Desktop* aDesk = application()->desktop();
178 for (unsigned int i = 0; i < theKeys.count(); i++)
180 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
182 aAction->setData(theId);
183 int aItemId = createMenu(aId, aMenu, -1, 10);
184 int aToolId = createTool(aId, aTool);
188 //******************************************************
189 QAction* NewGeom_Module::addEditCommand(const QString& theId, const QString& theTitle,
190 const QString& theTip, const QIcon& theIcon,
191 const QKeySequence& theKeys, bool isCheckable)
193 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
195 int aId = myActionsList.size();
196 myActionsList.append(theId);
197 SUIT_Desktop* aDesk = application()->desktop();
199 for (unsigned int i = 0; i < theKeys.count(); i++)
201 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
203 aAction->setData(theId);
204 createMenu(aId, aMenu, 10);
208 //******************************************************
209 void NewGeom_Module::addEditMenuSeparator()
211 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
212 createMenu(separator(), aMenu, -1, 10);
215 //******************************************************
216 QList<QAction*> NewGeom_Module::commandList() const
218 QList<QAction*> aActions;
219 for (int i = 0; i < myActionsList.size(); i++)
220 aActions.append(action(i));
224 //******************************************************
225 QStringList NewGeom_Module::commandIdList() const
227 return myActionsList;
230 //******************************************************
231 QMainWindow* NewGeom_Module::desktop() const
233 return application()->desktop();
236 //******************************************************
237 QString NewGeom_Module::commandId(const QAction* theCmd) const
239 int aId = actionId(theCmd);
240 if (aId < myActionsList.size())
241 return myActionsList[aId];
245 //******************************************************
246 QAction* NewGeom_Module::command(const QString& theId) const
248 int aId = myActionsList.indexOf(theId);
249 if ((aId != -1) && (aId < myActionsList.size())) {
255 //******************************************************
256 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
258 myNestedActions[theId] = theActions;
261 //******************************************************
262 QStringList NewGeom_Module::nestedActions(const QString& theId) const
264 if (myNestedActions.contains(theId))
265 return myNestedActions[theId];
266 return QStringList();
269 //******************************************************
270 void NewGeom_Module::selectionChanged()
272 LightApp_Module::selectionChanged();
273 myWorkshop->salomeViewerSelectionChanged();
276 //******************************************************
277 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
279 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
280 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
284 //******************************************************
285 void NewGeom_Module::createPreferences()
287 XGUI_Preferences::updateCustomProps();
288 LightApp_Preferences* pref = preferences();
289 int catId = pref->addPreference( moduleName(), -1 );
292 NewGeom_PrefMgr aMgr(pref, moduleName());
293 XGUI_Preferences::createEditContent(&aMgr, catId);
297 //******************************************************
298 void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam)
300 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
301 QString aVal = aResMgr->stringValue(theSection, theParam);
302 if (!aVal.isNull()) {
303 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
304 aProp->setValue(aVal.toStdString());