1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include "NewGeom_Module.h"
5 #include "NewGeom_DataModel.h"
6 #include "NewGeom_OCCSelector.h"
8 #include <XGUI_Workshop.h>
9 #include <XGUI_PropertyPanel.h>
10 #include <XGUI_ContextMenuMgr.h>
11 #include <XGUI_ObjectsBrowser.h>
12 #include <XGUI_OperationMgr.h>
14 #include <ModuleBase_Operation.h>
15 #include <ModuleBase_Preferences.h>
17 #include <LightApp_Application.h>
18 #include <LightApp_SelectionMgr.h>
19 #include <LightApp_OCCSelector.h>
20 #include <OCCViewer_ViewModel.h>
22 #include <SUIT_Selector.h>
23 #include <SUIT_Desktop.h>
24 #include <SUIT_ViewManager.h>
25 #include <SUIT_ResourceMgr.h>
27 #include <QtxPopupMgr.h>
28 #include <QtxActionMenuMgr.h>
29 #include <QtxResourceMgr.h>
31 #include <Config_PropManager.h>
33 #include <QDockWidget>
39 NewGeom_EXPORT CAM_Module* createModule()
41 return new NewGeom_Module();
44 NewGeom_EXPORT char* getModuleVersion()
50 class NewGeom_PrefMgr: public ModuleBase_IPrefMgr
53 NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {}
55 virtual int addPreference(const QString& theLbl, int pId,
56 SUIT_PreferenceMgr::PrefItemType theType,
57 const QString& theSection, const QString& theName )
59 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
62 virtual void setItemProperty(const QString& thePropName,
63 const QVariant& theValue,
66 myMgr->setItemProperty(thePropName, theValue, theId);
70 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
73 LightApp_Preferences* myMgr;
80 //******************************************************
81 NewGeom_Module::NewGeom_Module()
82 : LightApp_Module("NewGeom"),
83 mySelector(0), myIsOpened(0), myPopupMgr(0)
85 myWorkshop = new XGUI_Workshop(this);
86 myProxyViewer = new NewGeom_SalomeViewer(this);
88 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
89 ModuleBase_Preferences::loadCustomProps();
92 //******************************************************
93 NewGeom_Module::~NewGeom_Module()
97 //******************************************************
98 void NewGeom_Module::initialize(CAM_Application* theApp)
100 LightApp_Module::initialize(theApp);
102 myWorkshop->startApplication();
103 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
105 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
108 //******************************************************
109 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
111 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
114 //******************************************************
115 void NewGeom_Module::viewManagers(QStringList& theList) const
117 theList.append(OCCViewer_Viewer::Type());
120 //******************************************************
121 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
123 bool isDone = LightApp_Module::activateModule(theStudy);
128 QObject* aObj = myWorkshop->objectBrowser()->parent();
129 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
131 QAction* aViewAct = aObjDoc->toggleViewAction();
132 aViewAct->setEnabled(true);
133 myWorkshop->objectBrowser()->setVisible(true);
134 aObjDoc->setVisible(true);
138 ViewManagerList OCCViewManagers;
139 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
140 if (OCCViewManagers.size() > 0) {
141 mySelector = createSelector(OCCViewManagers.first());
144 //action(myEraseAll)->setEnabled(false);
147 myWorkshop->objectBrowser()->rebuildDataTree();
148 myWorkshop->updateCommandStatus();
150 QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
153 myWorkshop->updateCommandStatus();
155 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
156 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
157 myIsEditEnabled = getApp()->isEditEnabled();
158 getApp()->setEditEnabled(false);
160 // this following row is caused by #187 bug.
161 // SALOME saves the dock widget positions before deactivateModule() and
162 // load it after the module activation. So, if the panel is visible before
163 // deactivate, it becomes visible after activate.
164 // In order to avoid the visible property panel, the widget position save is
165 // switch off in this module
166 aResMgr->setValue("Study", "store_positions", false);
171 //******************************************************
172 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
177 QObject* aObj = myWorkshop->objectBrowser()->parent();
178 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
180 aObjDoc->setVisible(false);
181 myWorkshop->objectBrowser()->setVisible(false);
182 QAction* aViewAct = aObjDoc->toggleViewAction();
183 aViewAct->setEnabled(false);
186 // the active operation should be stopped for the next activation.
187 // There should not be active operation and visualized preview.
188 // Abort operation should be performed before the selection's remove
189 // because the displayed objects should be removed from the viewer, but
190 // the AIS context is obtained from the selector.
191 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
193 anOperation->abort();
195 // Delete selector because it has to be redefined on next activation
197 myProxyViewer->setSelector(0);
202 //myWorkshop->contextMenuMgr()->disconnectViewer();
204 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
205 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
206 getApp()->setEditEnabled(myIsEditEnabled);
208 return LightApp_Module::deactivateModule(theStudy);
211 //******************************************************
212 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
215 mySelector = createSelector(theMgr);
219 //******************************************************
220 QtxPopupMgr* NewGeom_Module::popupMgr()
223 myPopupMgr = new QtxPopupMgr( 0, this );
227 //******************************************************
228 void NewGeom_Module::onDefaultPreferences()
230 ModuleBase_Preferences::resetConfig();
231 ModuleBase_Preferences::updateResourcesByConfig();
233 LightApp_Preferences* pref = preferences();
238 //******************************************************
239 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
241 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
242 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
243 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
244 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
245 QList<SUIT_Selector*> aList;
246 aMgr->selectors(aList);
247 foreach(SUIT_Selector* aSel, aList)
249 aSel->setEnabled(aSel == aSelector);
251 myProxyViewer->setSelector(aSelector);
257 //******************************************************
258 CAM_DataModel* NewGeom_Module::createDataModel()
260 return new NewGeom_DataModel(this);
263 //******************************************************
264 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
265 const QString& theTitle, const QString& theTip,
266 const QIcon& theIcon, const QKeySequence& theKeys,
269 int aMenu = createMenu(theWBName, -1, -1, 50);
270 int aTool = createTool(theWBName);
272 int aId = myActionsList.size();
273 myActionsList.append(theId);
274 SUIT_Desktop* aDesk = application()->desktop();
276 for (unsigned int i = 0; i < theKeys.count(); i++)
278 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
280 aAction->setData(theId);
281 int aItemId = createMenu(aId, aMenu, -1, 10);
282 int aToolId = createTool(aId, aTool);
286 //******************************************************
287 QAction* NewGeom_Module::addDesktopCommand(const QString& theId, const QString& theTitle,
288 const QString& theTip, const QIcon& theIcon,
289 const QKeySequence& theKeys, bool isCheckable,
290 const char* theMenuSourceText, const int theMenuPosition)
292 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
294 int aId = myActionsList.size();
295 myActionsList.append(theId);
296 SUIT_Desktop* aDesk = application()->desktop();
298 for (unsigned int i = 0; i < theKeys.count(); i++)
300 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
302 aAction->setData(theId);
303 createMenu(aId, aMenu, theMenuPosition);
307 //******************************************************
308 void NewGeom_Module::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
310 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
311 createMenu(separator(), aMenu, -1, theMenuPosition);
314 //******************************************************
315 QList<QAction*> NewGeom_Module::commandList() const
317 QList<QAction*> aActions;
318 for (int i = 0; i < myActionsList.size(); i++)
319 aActions.append(action(i));
323 //******************************************************
324 QStringList NewGeom_Module::commandIdList() const
326 return myActionsList;
329 //******************************************************
330 QMainWindow* NewGeom_Module::desktop() const
332 return application()->desktop();
335 //******************************************************
336 QString NewGeom_Module::commandId(const QAction* theCmd) const
338 int aId = actionId(theCmd);
339 if (aId < myActionsList.size())
340 return myActionsList[aId];
344 //******************************************************
345 QAction* NewGeom_Module::command(const QString& theId) const
347 int aId = myActionsList.indexOf(theId);
348 if ((aId != -1) && (aId < myActionsList.size())) {
354 //******************************************************
355 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
357 myNestedActions[theId] = theActions;
360 //******************************************************
361 QStringList NewGeom_Module::nestedActions(const QString& theId) const
363 if (myNestedActions.contains(theId))
364 return myNestedActions[theId];
365 return QStringList();
368 //******************************************************
369 void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind)
371 myDocumentType[theId] = theKind;
374 //******************************************************
375 QString NewGeom_Module::documentKind(const QString& theId) const
377 if (myDocumentType.contains(theId))
378 return myDocumentType[theId];
383 //******************************************************
384 void NewGeom_Module::selectionChanged()
386 LightApp_Module::selectionChanged();
387 myWorkshop->salomeViewerSelectionChanged();
390 //******************************************************
391 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
393 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
394 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
398 //******************************************************
399 void NewGeom_Module::createPreferences()
401 LightApp_Preferences* pref = preferences();
404 ModuleBase_Preferences::updateConfigByResources();
405 QString aModName = moduleName();
407 QtxPreferenceItem* item = pref->findItem(aModName, true );
408 if ( item && (!item->isEmpty() )) {
409 item->parentItem()->removeItem(item);
413 int catId = pref->addPreference(aModName, -1 );
416 NewGeom_PrefMgr aMgr(pref, aModName);
417 ModuleBase_Preferences::createEditContent(&aMgr, catId);
421 //******************************************************
422 void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam)
424 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
425 QString aVal = aResMgr->stringValue(theSection, theParam);
426 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
427 std::string aValue = aVal.toStdString();
428 if (aValue.empty()) {
429 aValue = aProp->defaultValue();
430 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
432 LightApp_Preferences* pref = preferences();
436 aProp->setValue(aValue);