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);
112 QObject* aObj = myWorkshop->objectBrowser()->parent();
113 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
115 QAction* aViewAct = aObjDoc->toggleViewAction();
116 aViewAct->setEnabled(true);
117 myWorkshop->objectBrowser()->setVisible(true);
118 aObjDoc->setVisible(true);
122 ViewManagerList OCCViewManagers;
123 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
124 if (OCCViewManagers.size() > 0) {
125 mySelector = createSelector(OCCViewManagers.first());
128 myWorkshop->propertyPanel()->hide();
129 QtxPopupMgr* aMgr = popupMgr(); // Create popup manager
130 action(myEraseAll)->setEnabled(false);
133 myWorkshop->objectBrowser()->rebuildDataTree();
134 myWorkshop->updateCommandStatus();
136 QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
142 //******************************************************
143 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
148 myWorkshop->propertyPanel()->setVisible(false);
149 desktop()->removeDockWidget(myWorkshop->propertyPanel());
151 QObject* aObj = myWorkshop->objectBrowser()->parent();
152 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
154 aObjDoc->setVisible(false);
155 myWorkshop->objectBrowser()->setVisible(false);
156 QAction* aViewAct = aObjDoc->toggleViewAction();
157 aViewAct->setEnabled(false);
160 // Delete selector because it has to be redefined on next activation
162 myProxyViewer->setSelector(0);
167 //myWorkshop->contextMenuMgr()->disconnectViewer();
168 return LightApp_Module::deactivateModule(theStudy);
171 //******************************************************
172 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
175 mySelector = createSelector(theMgr);
179 //******************************************************
180 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
182 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
183 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
184 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
185 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
186 QList<SUIT_Selector*> aList;
187 aMgr->selectors(aList);
188 foreach(SUIT_Selector* aSel, aList)
190 aSel->setEnabled(aSel == aSelector);
192 myProxyViewer->setSelector(aSelector);
198 //******************************************************
199 CAM_DataModel* NewGeom_Module::createDataModel()
201 return new NewGeom_DataModel(this);
204 //******************************************************
205 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
206 const QString& theTitle, const QString& theTip,
207 const QIcon& theIcon, const QKeySequence& theKeys,
210 int aMenu = createMenu(theWBName, -1, -1, 50);
211 int aTool = createTool(theWBName);
213 int aId = myActionsList.size();
214 myActionsList.append(theId);
215 SUIT_Desktop* aDesk = application()->desktop();
217 for (unsigned int i = 0; i < theKeys.count(); i++)
219 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
221 aAction->setData(theId);
222 int aItemId = createMenu(aId, aMenu, -1, 10);
223 int aToolId = createTool(aId, aTool);
227 //******************************************************
228 QAction* NewGeom_Module::addEditCommand(const QString& theId, const QString& theTitle,
229 const QString& theTip, const QIcon& theIcon,
230 const QKeySequence& theKeys, bool isCheckable)
232 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
234 int aId = myActionsList.size();
235 myActionsList.append(theId);
236 SUIT_Desktop* aDesk = application()->desktop();
238 for (unsigned int i = 0; i < theKeys.count(); i++)
240 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
242 aAction->setData(theId);
243 createMenu(aId, aMenu, 10);
247 //******************************************************
248 void NewGeom_Module::addEditMenuSeparator()
250 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
251 createMenu(separator(), aMenu, -1, 10);
254 //******************************************************
255 QList<QAction*> NewGeom_Module::commandList() const
257 QList<QAction*> aActions;
258 for (int i = 0; i < myActionsList.size(); i++)
259 aActions.append(action(i));
263 //******************************************************
264 QStringList NewGeom_Module::commandIdList() const
266 return myActionsList;
269 //******************************************************
270 QMainWindow* NewGeom_Module::desktop() const
272 return application()->desktop();
275 //******************************************************
276 QString NewGeom_Module::commandId(const QAction* theCmd) const
278 int aId = actionId(theCmd);
279 if (aId < myActionsList.size())
280 return myActionsList[aId];
284 //******************************************************
285 QAction* NewGeom_Module::command(const QString& theId) const
287 int aId = myActionsList.indexOf(theId);
288 if ((aId != -1) && (aId < myActionsList.size())) {
294 //******************************************************
295 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
297 myNestedActions[theId] = theActions;
300 //******************************************************
301 QStringList NewGeom_Module::nestedActions(const QString& theId) const
303 if (myNestedActions.contains(theId))
304 return myNestedActions[theId];
305 return QStringList();
308 //******************************************************
309 void NewGeom_Module::selectionChanged()
311 LightApp_Module::selectionChanged();
312 myWorkshop->salomeViewerSelectionChanged();
315 //******************************************************
316 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
318 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
319 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
323 //******************************************************
324 void NewGeom_Module::createPreferences()
326 LightApp_Preferences* pref = preferences();
329 XGUI_Preferences::updateCustomProps();
330 QString aModName = moduleName();
332 QtxPreferenceItem* item = pref->findItem(aModName, true );
333 if ( item && (!item->isEmpty() )) {
334 item->parentItem()->removeItem(item);
338 int catId = pref->addPreference(aModName, -1 );
341 NewGeom_PrefMgr aMgr(pref, aModName);
342 XGUI_Preferences::createEditContent(&aMgr, catId);
346 //******************************************************
347 void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam)
349 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
350 QString aVal = aResMgr->stringValue(theSection, theParam);
351 if (!aVal.isNull()) {
352 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
353 aProp->setValue(aVal.toStdString());