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>
10 #include <XGUI_ObjectsBrowser.h>
12 #include <LightApp_Application.h>
13 #include <LightApp_SelectionMgr.h>
14 #include <LightApp_OCCSelector.h>
15 #include <OCCViewer_ViewModel.h>
17 #include <SUIT_Selector.h>
18 #include <SUIT_Desktop.h>
19 #include <SUIT_ViewManager.h>
20 #include <SUIT_ResourceMgr.h>
22 #include <QtxPopupMgr.h>
23 #include <QtxActionMenuMgr.h>
24 #include <QtxResourceMgr.h>
26 #include <Config_PropManager.h>
28 #include <QDockWidget>
34 NewGeom_EXPORT CAM_Module* createModule()
36 return new NewGeom_Module();
39 NewGeom_EXPORT char* getModuleVersion()
45 class NewGeom_PrefMgr: public XGUI_IPrefMgr
48 NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {}
50 virtual int addPreference(const QString& theLbl, int pId,
51 SUIT_PreferenceMgr::PrefItemType theType,
52 const QString& theSection, const QString& theName )
54 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
57 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
60 LightApp_Preferences* myMgr;
67 //******************************************************
68 NewGeom_Module::NewGeom_Module()
69 : LightApp_Module("NewGeom"),
70 mySelector(0), myIsOpened(0)
72 myWorkshop = new XGUI_Workshop(this);
73 myProxyViewer = new NewGeom_SalomeViewer(this);
75 XGUI_Preferences::setResourceMgr(application()->resourceMgr());
76 XGUI_Preferences::loadCustomProps();
79 //******************************************************
80 NewGeom_Module::~NewGeom_Module()
84 //******************************************************
85 void NewGeom_Module::initialize(CAM_Application* theApp)
87 LightApp_Module::initialize(theApp);
89 myWorkshop->startApplication();
92 //******************************************************
93 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
95 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
98 //******************************************************
99 void NewGeom_Module::viewManagers(QStringList& theList) const
101 theList.append(OCCViewer_Viewer::Type());
104 //******************************************************
105 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
107 bool isDone = LightApp_Module::activateModule(theStudy);
113 ViewManagerList OCCViewManagers;
114 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
115 if (OCCViewManagers.size() > 0) {
116 mySelector = createSelector(OCCViewManagers.first());
119 myWorkshop->propertyPanel()->hide();
120 QtxPopupMgr* aMgr = popupMgr(); // Create popup manager
121 action(myEraseAll)->setEnabled(false);
124 myWorkshop->objectBrowser()->rebuildDataTree();
125 myWorkshop->updateCommandStatus();
127 QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
133 //******************************************************
134 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
138 //myWorkshop->contextMenuMgr()->disconnectViewer();
139 return LightApp_Module::deactivateModule(theStudy);
142 //******************************************************
143 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
146 mySelector = createSelector(theMgr);
150 //******************************************************
151 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
153 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
154 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
155 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
156 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
157 QList<SUIT_Selector*> aList;
158 aMgr->selectors(aList);
159 foreach(SUIT_Selector* aSel, aList)
161 aSel->setEnabled(aSel == aSelector);
163 myProxyViewer->setSelector(aSelector);
169 //******************************************************
170 CAM_DataModel* NewGeom_Module::createDataModel()
172 return new NewGeom_DataModel(this);
175 //******************************************************
176 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
177 const QString& theTitle, const QString& theTip,
178 const QIcon& theIcon, const QKeySequence& theKeys,
181 int aMenu = createMenu(theWBName, -1, -1, 50);
182 int aTool = createTool(theWBName);
184 int aId = myActionsList.size();
185 myActionsList.append(theId);
186 SUIT_Desktop* aDesk = application()->desktop();
188 for (unsigned int i = 0; i < theKeys.count(); i++)
190 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
192 aAction->setData(theId);
193 int aItemId = createMenu(aId, aMenu, -1, 10);
194 int aToolId = createTool(aId, aTool);
198 //******************************************************
199 QAction* NewGeom_Module::addEditCommand(const QString& theId, const QString& theTitle,
200 const QString& theTip, const QIcon& theIcon,
201 const QKeySequence& theKeys, bool isCheckable)
203 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
205 int aId = myActionsList.size();
206 myActionsList.append(theId);
207 SUIT_Desktop* aDesk = application()->desktop();
209 for (unsigned int i = 0; i < theKeys.count(); i++)
211 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
213 aAction->setData(theId);
214 createMenu(aId, aMenu, 10);
218 //******************************************************
219 void NewGeom_Module::addEditMenuSeparator()
221 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
222 createMenu(separator(), aMenu, -1, 10);
225 //******************************************************
226 QList<QAction*> NewGeom_Module::commandList() const
228 QList<QAction*> aActions;
229 for (int i = 0; i < myActionsList.size(); i++)
230 aActions.append(action(i));
234 //******************************************************
235 QStringList NewGeom_Module::commandIdList() const
237 return myActionsList;
240 //******************************************************
241 QMainWindow* NewGeom_Module::desktop() const
243 return application()->desktop();
246 //******************************************************
247 QString NewGeom_Module::commandId(const QAction* theCmd) const
249 int aId = actionId(theCmd);
250 if (aId < myActionsList.size())
251 return myActionsList[aId];
255 //******************************************************
256 QAction* NewGeom_Module::command(const QString& theId) const
258 int aId = myActionsList.indexOf(theId);
259 if ((aId != -1) && (aId < myActionsList.size())) {
265 //******************************************************
266 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
268 myNestedActions[theId] = theActions;
271 //******************************************************
272 QStringList NewGeom_Module::nestedActions(const QString& theId) const
274 if (myNestedActions.contains(theId))
275 return myNestedActions[theId];
276 return QStringList();
279 //******************************************************
280 void NewGeom_Module::selectionChanged()
282 LightApp_Module::selectionChanged();
283 myWorkshop->salomeViewerSelectionChanged();
286 //******************************************************
287 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
289 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
290 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
294 //******************************************************
295 void NewGeom_Module::createPreferences()
297 LightApp_Preferences* pref = preferences();
300 XGUI_Preferences::updateCustomProps();
301 QString aModName = moduleName();
303 QtxPreferenceItem* item = pref->findItem(aModName, true );
304 if ( item && (!item->isEmpty() )) {
305 item->parentItem()->removeItem(item);
309 int catId = pref->addPreference(aModName, -1 );
312 NewGeom_PrefMgr aMgr(pref, aModName);
313 XGUI_Preferences::createEditContent(&aMgr, catId);
317 //******************************************************
318 void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam)
320 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
321 QString aVal = aResMgr->stringValue(theSection, theParam);
322 if (!aVal.isNull()) {
323 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
324 aProp->setValue(aVal.toStdString());