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>
11 #include <XGUI_OperationMgr.h>
13 #include <ModuleBase_Operation.h>
15 #include <LightApp_Application.h>
16 #include <LightApp_SelectionMgr.h>
17 #include <LightApp_OCCSelector.h>
18 #include <OCCViewer_ViewModel.h>
20 #include <SUIT_Selector.h>
21 #include <SUIT_Desktop.h>
22 #include <SUIT_ViewManager.h>
23 #include <SUIT_ResourceMgr.h>
25 #include <QtxPopupMgr.h>
26 #include <QtxActionMenuMgr.h>
27 #include <QtxResourceMgr.h>
29 #include <Config_PropManager.h>
31 #include <QDockWidget>
37 NewGeom_EXPORT CAM_Module* createModule()
39 return new NewGeom_Module();
42 NewGeom_EXPORT char* getModuleVersion()
48 class NewGeom_PrefMgr: public XGUI_IPrefMgr
51 NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {}
53 virtual int addPreference(const QString& theLbl, int pId,
54 SUIT_PreferenceMgr::PrefItemType theType,
55 const QString& theSection, const QString& theName )
57 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
60 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
63 LightApp_Preferences* myMgr;
70 //******************************************************
71 NewGeom_Module::NewGeom_Module()
72 : LightApp_Module("NewGeom"),
73 mySelector(0), myIsOpened(0), myPopupMgr(0)
75 myWorkshop = new XGUI_Workshop(this);
76 myProxyViewer = new NewGeom_SalomeViewer(this);
78 XGUI_Preferences::setResourceMgr(application()->resourceMgr());
79 XGUI_Preferences::loadCustomProps();
82 //******************************************************
83 NewGeom_Module::~NewGeom_Module()
87 //******************************************************
88 void NewGeom_Module::initialize(CAM_Application* theApp)
90 LightApp_Module::initialize(theApp);
92 myWorkshop->startApplication();
93 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
95 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
98 //******************************************************
99 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
101 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
104 //******************************************************
105 void NewGeom_Module::viewManagers(QStringList& theList) const
107 theList.append(OCCViewer_Viewer::Type());
110 //******************************************************
111 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
113 bool isDone = LightApp_Module::activateModule(theStudy);
118 QObject* aObj = myWorkshop->objectBrowser()->parent();
119 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
121 QAction* aViewAct = aObjDoc->toggleViewAction();
122 aViewAct->setEnabled(true);
123 myWorkshop->objectBrowser()->setVisible(true);
124 aObjDoc->setVisible(true);
128 ViewManagerList OCCViewManagers;
129 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
130 if (OCCViewManagers.size() > 0) {
131 mySelector = createSelector(OCCViewManagers.first());
134 //action(myEraseAll)->setEnabled(false);
137 myWorkshop->objectBrowser()->rebuildDataTree();
138 myWorkshop->updateCommandStatus();
140 QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
143 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
144 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
146 // this following row is caused by #187 bug.
147 // SALOME saves the dock widget positions before deactivateModule() and
148 // load it after the module activation. So, if the panel is visible before
149 // deactivate, it becomes visible after activate.
150 // In order to avoid the visible property panel, the widget position save is
151 // switch off in this module
152 aResMgr->setValue("Study", "store_positions", false);
157 //******************************************************
158 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
163 QObject* aObj = myWorkshop->objectBrowser()->parent();
164 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
166 aObjDoc->setVisible(false);
167 myWorkshop->objectBrowser()->setVisible(false);
168 QAction* aViewAct = aObjDoc->toggleViewAction();
169 aViewAct->setEnabled(false);
172 // the active operation should be stopped for the next activation.
173 // There should not be active operation and visualized preview.
174 // Abort operation should be performed before the selection's remove
175 // because the displayed objects should be removed from the viewer, but
176 // the AIS context is obtained from the selector.
177 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
179 anOperation->abort();
181 // Delete selector because it has to be redefined on next activation
183 myProxyViewer->setSelector(0);
188 //myWorkshop->contextMenuMgr()->disconnectViewer();
190 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
191 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
193 return LightApp_Module::deactivateModule(theStudy);
196 //******************************************************
197 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
200 mySelector = createSelector(theMgr);
204 //******************************************************
205 QtxPopupMgr* NewGeom_Module::popupMgr()
208 myPopupMgr = new QtxPopupMgr( 0, this );
212 //******************************************************
213 void NewGeom_Module::onDefaultPreferences()
215 XGUI_Preferences::resetConfig();
216 XGUI_Preferences::updateResourcesByConfig();
218 LightApp_Preferences* pref = preferences();
223 //******************************************************
224 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
226 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
227 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
228 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
229 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
230 QList<SUIT_Selector*> aList;
231 aMgr->selectors(aList);
232 foreach(SUIT_Selector* aSel, aList)
234 aSel->setEnabled(aSel == aSelector);
236 myProxyViewer->setSelector(aSelector);
242 //******************************************************
243 CAM_DataModel* NewGeom_Module::createDataModel()
245 return new NewGeom_DataModel(this);
248 //******************************************************
249 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
250 const QString& theTitle, const QString& theTip,
251 const QIcon& theIcon, const QKeySequence& theKeys,
254 int aMenu = createMenu(theWBName, -1, -1, 50);
255 int aTool = createTool(theWBName);
257 int aId = myActionsList.size();
258 myActionsList.append(theId);
259 SUIT_Desktop* aDesk = application()->desktop();
261 for (unsigned int i = 0; i < theKeys.count(); i++)
263 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
265 aAction->setData(theId);
266 int aItemId = createMenu(aId, aMenu, -1, 10);
267 int aToolId = createTool(aId, aTool);
271 //******************************************************
272 QAction* NewGeom_Module::addEditCommand(const QString& theId, const QString& theTitle,
273 const QString& theTip, const QIcon& theIcon,
274 const QKeySequence& theKeys, bool isCheckable)
276 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
278 int aId = myActionsList.size();
279 myActionsList.append(theId);
280 SUIT_Desktop* aDesk = application()->desktop();
282 for (unsigned int i = 0; i < theKeys.count(); i++)
284 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
286 aAction->setData(theId);
287 createMenu(aId, aMenu, 10);
291 //******************************************************
292 void NewGeom_Module::addEditMenuSeparator()
294 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
295 createMenu(separator(), aMenu, -1, 10);
298 //******************************************************
299 QList<QAction*> NewGeom_Module::commandList() const
301 QList<QAction*> aActions;
302 for (int i = 0; i < myActionsList.size(); i++)
303 aActions.append(action(i));
307 //******************************************************
308 QStringList NewGeom_Module::commandIdList() const
310 return myActionsList;
313 //******************************************************
314 QMainWindow* NewGeom_Module::desktop() const
316 return application()->desktop();
319 //******************************************************
320 QString NewGeom_Module::commandId(const QAction* theCmd) const
322 int aId = actionId(theCmd);
323 if (aId < myActionsList.size())
324 return myActionsList[aId];
328 //******************************************************
329 QAction* NewGeom_Module::command(const QString& theId) const
331 int aId = myActionsList.indexOf(theId);
332 if ((aId != -1) && (aId < myActionsList.size())) {
338 //******************************************************
339 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
341 myNestedActions[theId] = theActions;
344 //******************************************************
345 QStringList NewGeom_Module::nestedActions(const QString& theId) const
347 if (myNestedActions.contains(theId))
348 return myNestedActions[theId];
349 return QStringList();
352 //******************************************************
353 void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind)
355 myDocumentType[theId] = theKind;
358 //******************************************************
359 QString NewGeom_Module::documentKind(const QString& theId) const
361 if (myDocumentType.contains(theId))
362 return myDocumentType[theId];
367 //******************************************************
368 void NewGeom_Module::selectionChanged()
370 LightApp_Module::selectionChanged();
371 myWorkshop->salomeViewerSelectionChanged();
374 //******************************************************
375 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
377 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
378 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
382 //******************************************************
383 void NewGeom_Module::createPreferences()
385 LightApp_Preferences* pref = preferences();
388 XGUI_Preferences::updateConfigByResources();
389 QString aModName = moduleName();
391 QtxPreferenceItem* item = pref->findItem(aModName, true );
392 if ( item && (!item->isEmpty() )) {
393 item->parentItem()->removeItem(item);
397 int catId = pref->addPreference(aModName, -1 );
400 NewGeom_PrefMgr aMgr(pref, aModName);
401 XGUI_Preferences::createEditContent(&aMgr, catId);
405 //******************************************************
406 void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam)
408 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
409 QString aVal = aResMgr->stringValue(theSection, theParam);
410 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
411 std::string aValue = aVal.toStdString();
412 if (aValue.empty()) {
413 aValue = aProp->defaultValue();
414 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
416 LightApp_Preferences* pref = preferences();
420 aProp->setValue(aValue);