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 void setItemProperty(const QString& thePropName,
61 const QVariant& theValue,
64 myMgr->setItemProperty(thePropName, theValue, theId);
68 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
71 LightApp_Preferences* myMgr;
78 //******************************************************
79 NewGeom_Module::NewGeom_Module()
80 : LightApp_Module("NewGeom"),
81 mySelector(0), myIsOpened(0), myPopupMgr(0)
83 myWorkshop = new XGUI_Workshop(this);
84 myProxyViewer = new NewGeom_SalomeViewer(this);
86 XGUI_Preferences::setResourceMgr(application()->resourceMgr());
87 XGUI_Preferences::loadCustomProps();
90 //******************************************************
91 NewGeom_Module::~NewGeom_Module()
95 //******************************************************
96 void NewGeom_Module::initialize(CAM_Application* theApp)
98 LightApp_Module::initialize(theApp);
100 myWorkshop->startApplication();
101 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
103 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
106 //******************************************************
107 void NewGeom_Module::windows(QMap<int, int>& theWndMap) const
109 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
112 //******************************************************
113 void NewGeom_Module::viewManagers(QStringList& theList) const
115 theList.append(OCCViewer_Viewer::Type());
118 //******************************************************
119 bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
121 bool isDone = LightApp_Module::activateModule(theStudy);
126 QObject* aObj = myWorkshop->objectBrowser()->parent();
127 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
129 QAction* aViewAct = aObjDoc->toggleViewAction();
130 aViewAct->setEnabled(true);
131 myWorkshop->objectBrowser()->setVisible(true);
132 aObjDoc->setVisible(true);
136 ViewManagerList OCCViewManagers;
137 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
138 if (OCCViewManagers.size() > 0) {
139 mySelector = createSelector(OCCViewManagers.first());
142 //action(myEraseAll)->setEnabled(false);
145 myWorkshop->objectBrowser()->rebuildDataTree();
146 myWorkshop->updateCommandStatus();
148 QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
151 myWorkshop->updateCommandStatus();
153 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
154 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
155 myIsEditEnabled = getApp()->isEditEnabled();
156 getApp()->setEditEnabled(false);
158 // this following row is caused by #187 bug.
159 // SALOME saves the dock widget positions before deactivateModule() and
160 // load it after the module activation. So, if the panel is visible before
161 // deactivate, it becomes visible after activate.
162 // In order to avoid the visible property panel, the widget position save is
163 // switch off in this module
164 aResMgr->setValue("Study", "store_positions", false);
169 //******************************************************
170 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
175 QObject* aObj = myWorkshop->objectBrowser()->parent();
176 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
178 aObjDoc->setVisible(false);
179 myWorkshop->objectBrowser()->setVisible(false);
180 QAction* aViewAct = aObjDoc->toggleViewAction();
181 aViewAct->setEnabled(false);
184 // the active operation should be stopped for the next activation.
185 // There should not be active operation and visualized preview.
186 // Abort operation should be performed before the selection's remove
187 // because the displayed objects should be removed from the viewer, but
188 // the AIS context is obtained from the selector.
189 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
191 anOperation->abort();
193 // Delete selector because it has to be redefined on next activation
195 myProxyViewer->setSelector(0);
200 //myWorkshop->contextMenuMgr()->disconnectViewer();
202 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
203 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
204 getApp()->setEditEnabled(myIsEditEnabled);
206 return LightApp_Module::deactivateModule(theStudy);
209 //******************************************************
210 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
213 mySelector = createSelector(theMgr);
217 //******************************************************
218 QtxPopupMgr* NewGeom_Module::popupMgr()
221 myPopupMgr = new QtxPopupMgr( 0, this );
225 //******************************************************
226 void NewGeom_Module::onDefaultPreferences()
228 XGUI_Preferences::resetConfig();
229 XGUI_Preferences::updateResourcesByConfig();
231 LightApp_Preferences* pref = preferences();
236 //******************************************************
237 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
239 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
240 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
241 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
242 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
243 QList<SUIT_Selector*> aList;
244 aMgr->selectors(aList);
245 foreach(SUIT_Selector* aSel, aList)
247 aSel->setEnabled(aSel == aSelector);
249 myProxyViewer->setSelector(aSelector);
255 //******************************************************
256 CAM_DataModel* NewGeom_Module::createDataModel()
258 return new NewGeom_DataModel(this);
261 //******************************************************
262 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
263 const QString& theTitle, const QString& theTip,
264 const QIcon& theIcon, const QKeySequence& theKeys,
267 int aMenu = createMenu(theWBName, -1, -1, 50);
268 int aTool = createTool(theWBName);
270 int aId = myActionsList.size();
271 myActionsList.append(theId);
272 SUIT_Desktop* aDesk = application()->desktop();
274 for (unsigned int i = 0; i < theKeys.count(); i++)
276 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
278 aAction->setData(theId);
279 int aItemId = createMenu(aId, aMenu, -1, 10);
280 int aToolId = createTool(aId, aTool);
284 //******************************************************
285 QAction* NewGeom_Module::addDesktopCommand(const QString& theId, const QString& theTitle,
286 const QString& theTip, const QIcon& theIcon,
287 const QKeySequence& theKeys, bool isCheckable,
288 const char* theMenuSourceText, const int theMenuPosition)
290 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
292 int aId = myActionsList.size();
293 myActionsList.append(theId);
294 SUIT_Desktop* aDesk = application()->desktop();
296 for (unsigned int i = 0; i < theKeys.count(); i++)
298 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
300 aAction->setData(theId);
301 createMenu(aId, aMenu, theMenuPosition);
305 //******************************************************
306 void NewGeom_Module::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
308 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
309 createMenu(separator(), aMenu, -1, theMenuPosition);
312 //******************************************************
313 QList<QAction*> NewGeom_Module::commandList() const
315 QList<QAction*> aActions;
316 for (int i = 0; i < myActionsList.size(); i++)
317 aActions.append(action(i));
321 //******************************************************
322 QStringList NewGeom_Module::commandIdList() const
324 return myActionsList;
327 //******************************************************
328 QMainWindow* NewGeom_Module::desktop() const
330 return application()->desktop();
333 //******************************************************
334 QString NewGeom_Module::commandId(const QAction* theCmd) const
336 int aId = actionId(theCmd);
337 if (aId < myActionsList.size())
338 return myActionsList[aId];
342 //******************************************************
343 QAction* NewGeom_Module::command(const QString& theId) const
345 int aId = myActionsList.indexOf(theId);
346 if ((aId != -1) && (aId < myActionsList.size())) {
352 //******************************************************
353 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
355 myNestedActions[theId] = theActions;
358 //******************************************************
359 QStringList NewGeom_Module::nestedActions(const QString& theId) const
361 if (myNestedActions.contains(theId))
362 return myNestedActions[theId];
363 return QStringList();
366 //******************************************************
367 void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind)
369 myDocumentType[theId] = theKind;
372 //******************************************************
373 QString NewGeom_Module::documentKind(const QString& theId) const
375 if (myDocumentType.contains(theId))
376 return myDocumentType[theId];
381 //******************************************************
382 void NewGeom_Module::selectionChanged()
384 LightApp_Module::selectionChanged();
385 myWorkshop->salomeViewerSelectionChanged();
388 //******************************************************
389 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
391 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
392 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
396 //******************************************************
397 void NewGeom_Module::createPreferences()
399 LightApp_Preferences* pref = preferences();
402 XGUI_Preferences::updateConfigByResources();
403 QString aModName = moduleName();
405 QtxPreferenceItem* item = pref->findItem(aModName, true );
406 if ( item && (!item->isEmpty() )) {
407 item->parentItem()->removeItem(item);
411 int catId = pref->addPreference(aModName, -1 );
414 NewGeom_PrefMgr aMgr(pref, aModName);
415 XGUI_Preferences::createEditContent(&aMgr, catId);
419 //******************************************************
420 void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam)
422 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
423 QString aVal = aResMgr->stringValue(theSection, theParam);
424 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
425 std::string aValue = aVal.toStdString();
426 if (aValue.empty()) {
427 aValue = aProp->defaultValue();
428 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
430 LightApp_Preferences* pref = preferences();
434 aProp->setValue(aValue);