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 //myWorkshop->contextMenuMgr()->disconnectViewer();
161 return LightApp_Module::deactivateModule(theStudy);
164 //******************************************************
165 void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
168 mySelector = createSelector(theMgr);
172 //******************************************************
173 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
175 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
176 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
177 NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr());
178 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
179 QList<SUIT_Selector*> aList;
180 aMgr->selectors(aList);
181 foreach(SUIT_Selector* aSel, aList)
183 aSel->setEnabled(aSel == aSelector);
185 myProxyViewer->setSelector(aSelector);
191 //******************************************************
192 CAM_DataModel* NewGeom_Module::createDataModel()
194 return new NewGeom_DataModel(this);
197 //******************************************************
198 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
199 const QString& theTitle, const QString& theTip,
200 const QIcon& theIcon, const QKeySequence& theKeys,
203 int aMenu = createMenu(theWBName, -1, -1, 50);
204 int aTool = createTool(theWBName);
206 int aId = myActionsList.size();
207 myActionsList.append(theId);
208 SUIT_Desktop* aDesk = application()->desktop();
210 for (unsigned int i = 0; i < theKeys.count(); i++)
212 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
214 aAction->setData(theId);
215 int aItemId = createMenu(aId, aMenu, -1, 10);
216 int aToolId = createTool(aId, aTool);
220 //******************************************************
221 QAction* NewGeom_Module::addEditCommand(const QString& theId, const QString& theTitle,
222 const QString& theTip, const QIcon& theIcon,
223 const QKeySequence& theKeys, bool isCheckable)
225 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
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 createMenu(aId, aMenu, 10);
240 //******************************************************
241 void NewGeom_Module::addEditMenuSeparator()
243 int aMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1);
244 createMenu(separator(), aMenu, -1, 10);
247 //******************************************************
248 QList<QAction*> NewGeom_Module::commandList() const
250 QList<QAction*> aActions;
251 for (int i = 0; i < myActionsList.size(); i++)
252 aActions.append(action(i));
256 //******************************************************
257 QStringList NewGeom_Module::commandIdList() const
259 return myActionsList;
262 //******************************************************
263 QMainWindow* NewGeom_Module::desktop() const
265 return application()->desktop();
268 //******************************************************
269 QString NewGeom_Module::commandId(const QAction* theCmd) const
271 int aId = actionId(theCmd);
272 if (aId < myActionsList.size())
273 return myActionsList[aId];
277 //******************************************************
278 QAction* NewGeom_Module::command(const QString& theId) const
280 int aId = myActionsList.indexOf(theId);
281 if ((aId != -1) && (aId < myActionsList.size())) {
287 //******************************************************
288 void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
290 myNestedActions[theId] = theActions;
293 //******************************************************
294 QStringList NewGeom_Module::nestedActions(const QString& theId) const
296 if (myNestedActions.contains(theId))
297 return myNestedActions[theId];
298 return QStringList();
301 //******************************************************
302 void NewGeom_Module::selectionChanged()
304 LightApp_Module::selectionChanged();
305 myWorkshop->salomeViewerSelectionChanged();
308 //******************************************************
309 void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
311 myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
312 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
316 //******************************************************
317 void NewGeom_Module::createPreferences()
319 LightApp_Preferences* pref = preferences();
322 XGUI_Preferences::updateCustomProps();
323 QString aModName = moduleName();
325 QtxPreferenceItem* item = pref->findItem(aModName, true );
326 if ( item && (!item->isEmpty() )) {
327 item->parentItem()->removeItem(item);
331 int catId = pref->addPreference(aModName, -1 );
334 NewGeom_PrefMgr aMgr(pref, aModName);
335 XGUI_Preferences::createEditContent(&aMgr, catId);
339 //******************************************************
340 void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam)
342 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
343 QString aVal = aResMgr->stringValue(theSection, theParam);
344 if (!aVal.isNull()) {
345 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
346 aProp->setValue(aVal.toStdString());