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();
90 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
92 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
95 //******************************************************
96 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
98 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
101 //******************************************************
102 void NewGeom_Module::viewManagers(QStringList& theList) const
104 theList.append(OCCViewer_Viewer::Type());
107 //******************************************************
108 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
110 bool isDone = LightApp_Module::activateModule(theStudy);
115 QObject* aObj = myWorkshop->objectBrowser()->parent();
116 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
118 QAction* aViewAct = aObjDoc->toggleViewAction();
119 aViewAct->setEnabled(true);
120 myWorkshop->objectBrowser()->setVisible(true);
121 aObjDoc->setVisible(true);
125 ViewManagerList OCCViewManagers;
126 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
127 if (OCCViewManagers.size() > 0) {
128 mySelector = createSelector(OCCViewManagers.first());
131 myWorkshop->propertyPanel()->hide();
132 QtxPopupMgr* aMgr = popupMgr(); // Create popup manager
133 action(myEraseAll)->setEnabled(false);
136 myWorkshop->objectBrowser()->rebuildDataTree();
137 myWorkshop->updateCommandStatus();
139 QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
145 //******************************************************
146 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
151 myWorkshop->propertyPanel()->setVisible(false);
152 desktop()->removeDockWidget(myWorkshop->propertyPanel());
154 QObject* aObj = myWorkshop->objectBrowser()->parent();
155 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
157 aObjDoc->setVisible(false);
158 myWorkshop->objectBrowser()->setVisible(false);
159 QAction* aViewAct = aObjDoc->toggleViewAction();
160 aViewAct->setEnabled(false);
163 // Delete selector because it has to be redefined on next activation
165 myProxyViewer->setSelector(0);
170 //myWorkshop->contextMenuMgr()->disconnectViewer();
171 return LightApp_Module::deactivateModule(theStudy);
174 //******************************************************
175 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
178 mySelector = createSelector(theMgr);
182 //******************************************************
183 void NewGeom_Module::onDefaultPreferences()
185 XGUI_Preferences::resetConfig();
186 XGUI_Preferences::updateResourcesByConfig();
188 LightApp_Preferences* pref = preferences();
193 //******************************************************
194 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
196 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
197 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
198 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
199 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
200 QList<SUIT_Selector*> aList;
201 aMgr->selectors(aList);
202 foreach(SUIT_Selector* aSel, aList)
204 aSel->setEnabled(aSel == aSelector);
206 myProxyViewer->setSelector(aSelector);
212 //******************************************************
213 CAM_DataModel* NewGeom_Module::createDataModel()
215 return new NewGeom_DataModel(this);
218 //******************************************************
219 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
220 const QString& theTitle, const QString& theTip,
221 const QIcon& theIcon, const QKeySequence& theKeys,
224 int aMenu = createMenu(theWBName, -1, -1, 50);
225 int aTool = createTool(theWBName);
227 int aId = myActionsList.size();
228 myActionsList.append(theId);
229 SUIT_Desktop* aDesk = application()->desktop();
231 for (unsigned int i = 0; i < theKeys.count(); i++)
233 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
235 aAction->setData(theId);
236 int aItemId = createMenu(aId, aMenu, -1, 10);
237 int aToolId = createTool(aId, aTool);
241 //******************************************************
242 QAction* NewGeom_Module::addEditCommand(const QString& theId, const QString& theTitle,
243 const QString& theTip, const QIcon& theIcon,
244 const QKeySequence& theKeys, bool isCheckable)
246 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
248 int aId = myActionsList.size();
249 myActionsList.append(theId);
250 SUIT_Desktop* aDesk = application()->desktop();
252 for (unsigned int i = 0; i < theKeys.count(); i++)
254 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
256 aAction->setData(theId);
257 createMenu(aId, aMenu, 10);
261 //******************************************************
262 void NewGeom_Module::addEditMenuSeparator()
264 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
265 createMenu(separator(), aMenu, -1, 10);
268 //******************************************************
269 QList<QAction*> NewGeom_Module::commandList() const
271 QList<QAction*> aActions;
272 for (int i = 0; i < myActionsList.size(); i++)
273 aActions.append(action(i));
277 //******************************************************
278 QStringList NewGeom_Module::commandIdList() const
280 return myActionsList;
283 //******************************************************
284 QMainWindow* NewGeom_Module::desktop() const
286 return application()->desktop();
289 //******************************************************
290 QString NewGeom_Module::commandId(const QAction* theCmd) const
292 int aId = actionId(theCmd);
293 if (aId < myActionsList.size())
294 return myActionsList[aId];
298 //******************************************************
299 QAction* NewGeom_Module::command(const QString& theId) const
301 int aId = myActionsList.indexOf(theId);
302 if ((aId != -1) && (aId < myActionsList.size())) {
308 //******************************************************
309 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
311 myNestedActions[theId] = theActions;
314 //******************************************************
315 QStringList NewGeom_Module::nestedActions(const QString& theId) const
317 if (myNestedActions.contains(theId))
318 return myNestedActions[theId];
319 return QStringList();
322 //******************************************************
323 void NewGeom_Module::selectionChanged()
325 LightApp_Module::selectionChanged();
326 myWorkshop->salomeViewerSelectionChanged();
329 //******************************************************
330 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
332 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
333 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
337 //******************************************************
338 void NewGeom_Module::createPreferences()
340 LightApp_Preferences* pref = preferences();
343 XGUI_Preferences::updateConfigByResources();
344 QString aModName = moduleName();
346 QtxPreferenceItem* item = pref->findItem(aModName, true );
347 if ( item && (!item->isEmpty() )) {
348 item->parentItem()->removeItem(item);
352 int catId = pref->addPreference(aModName, -1 );
355 NewGeom_PrefMgr aMgr(pref, aModName);
356 XGUI_Preferences::createEditContent(&aMgr, catId);
360 //******************************************************
361 void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam)
363 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
364 QString aVal = aResMgr->stringValue(theSection, theParam);
365 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
366 std::string aValue = aVal.toStdString();
367 if (aValue.empty()) {
368 aValue = aProp->defaultValue();
369 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
371 LightApp_Preferences* pref = preferences();
375 aProp->setValue(aValue);