From: nds Date: Wed, 24 Feb 2016 07:09:35 +0000 (+0300) Subject: Rename NewGeom_* into SHAPERGUI_* X-Git-Tag: V_2.2.0~78 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a9bdd72e4748283ea455fef89e11eb0eae3b7b48;p=modules%2Fshaper.git Rename NewGeom_* into SHAPERGUI_* --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 32b2f6506..a3aaaf287 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.10) -PROJECT (NewGEOM) -SET (NewGeom_Version 2.1.2) +PROJECT (SHAPER) +SET (SHAPER_Version 2.1.2) SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeCommon" ${CMAKE_MODULE_PATH}) @@ -68,7 +68,7 @@ ADD_SUBDIRECTORY (src/PythonAddons) ADD_SUBDIRECTORY (src/PythonAPI) IF(${HAVE_SALOME}) - ADD_SUBDIRECTORY (src/NewGeom) + ADD_SUBDIRECTORY (src/SHAPERGUI) ADD_SUBDIRECTORY (src/ConnectorPlugin) ENDIF(${HAVE_SALOME}) diff --git a/build_Salome_deb.bat b/build_Salome_deb.bat index 77a58f1ed..fe8ac9a65 100644 --- a/build_Salome_deb.bat +++ b/build_Salome_deb.bat @@ -16,4 +16,4 @@ cd %ROOT_DIR%\build cmake %SRC_DIR% -G "Visual Studio 10" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python_d.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install -start "" %MSVC_EXE% NewGEOM.sln +start "" %MSVC_EXE% SHAPER.sln diff --git a/build_Salome_eclipse.bat b/build_Salome_eclipse.bat index 6cc46a809..b2c3e8a04 100644 --- a/build_Salome_eclipse.bat +++ b/build_Salome_eclipse.bat @@ -9,8 +9,8 @@ popd @SET SRC_DIR=%ROOT_DIR%\sources @SET OCC_LIB_PREFIX=d -@SET NEWGEOM_ROOT_DIR=%ROOT_DIR%\install -@SET SalomeAppConfig=%ROOT_DIR%\install\share\salome\resources\newgeom;%GUI_ROOT_DIR%\share\salome\resources\gui +@SET SHAPER_ROOT_DIR=%ROOT_DIR%\install +@SET SalomeAppConfig=%ROOT_DIR%\install\share\salome\resources\shaper;%GUI_ROOT_DIR%\share\salome\resources\gui call %SRC_DIR%\env_Salome.bat d mkdir %ROOT_DIR%\build-eclipse diff --git a/build_Salome_rel.bat b/build_Salome_rel.bat index 4f3a06137..7dc13e202 100644 --- a/build_Salome_rel.bat +++ b/build_Salome_rel.bat @@ -15,4 +15,4 @@ cd %ROOT_DIR%\build cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install -start "" %MSVC_EXE% NewGEOM.sln +start "" %MSVC_EXE% SHAPER.sln diff --git a/doc/doxyfile.in b/doc/doxyfile.in index 86b762f27..f9ff3e2c6 100644 --- a/doc/doxyfile.in +++ b/doc/doxyfile.in @@ -32,7 +32,7 @@ PROJECT_NAME = @CMAKE_PROJECT_NAME@ # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = @NewGeom_Version@ +PROJECT_NUMBER = @SHAPER_Version@ # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer diff --git a/env_Salome.bat b/env_Salome.bat index a056258e7..0a97e7c72 100644 --- a/env_Salome.bat +++ b/env_Salome.bat @@ -100,9 +100,9 @@ IF "%ARCH%" == "Win64" ( ) @SET NEW_GEOM_CONFIG_FILE=%ROOT_DIR%\install\plugins -@SET NEWGEOM_ROOT_DIR=%ROOT_DIR%\install -@SET PATH=%NEWGEOM_ROOT_DIR%\swig;%NEWGEOM_ROOT_DIR%\plugins;%NEWGEOM_ROOT_DIR%\bin;%PATH% -@SET PYTHONPATH=%NEWGEOM_ROOT_DIR%\swig;%NEWGEOM_ROOT_DIR%\plugins;%NEWGEOM_ROOT_DIR%\addons;%NEWGEOM_ROOT_DIR%\pythonAPI;%PYTHONPATH% +@SET SHAPER_ROOT_DIR=%ROOT_DIR%\install +@SET PATH=%SHAPER_ROOT_DIR%\swig;%SHAPER_ROOT_DIR%\plugins;%SHAPER_ROOT_DIR%\bin;%PATH% +@SET PYTHONPATH=%SHAPER_ROOT_DIR%\swig;%SHAPER_ROOT_DIR%\plugins;%SHAPER_ROOT_DIR%\addons;%SHAPER_ROOT_DIR%\pythonAPI;%PYTHONPATH% -@SET LightAppConfig=%%NEWGEOM_ROOT_DIR%\share\salome\resources\newgeom;%GUI_ROOT_DIR%\share\salome\resources\gui -@SET NewGeomResources=%NEWGEOM_ROOT_DIR%\resources +@SET LightAppConfig=%%SHAPER_ROOT_DIR%\share\salome\resources\shaper;%GUI_ROOT_DIR%\share\salome\resources\gui +@SET SHAPERResources=%SHAPER_ROOT_DIR%\resources diff --git a/msvc10_env.bat b/msvc10_env.bat index e05b56ec1..aaa3a32c1 100644 --- a/msvc10_env.bat +++ b/msvc10_env.bat @@ -172,11 +172,11 @@ set PATH=%CMAKEDIR%\bin;%PATH% @REM ------------------------- @REM OPENPARTS -@SET NEWGEOM_ROOT_DIR=%ROOT_DIR%\install -@SET NEW_GEOM_CONFIG_FILE=%NEWGEOM_ROOT_DIR%\plugins -@SET PATH=%NEWGEOM_ROOT_DIR%\swig;%NEWGEOM_ROOT_DIR%\plugins;%NEWGEOM_ROOT_DIR%\bin;%PATH% -@SET PYTHONPATH=%NEWGEOM_ROOT_DIR%\swig;%NEWGEOM_ROOT_DIR%\plugins;%NEWGEOM_ROOT_DIR%\addons;%NEWGEOM_ROOT_DIR%\pythonAPI;%PYTHONPATH% -@SET NewGeomResources=%NEWGEOM_ROOT_DIR%\resources +@SET SHAPER_ROOT_DIR=%ROOT_DIR%\install +@SET NEW_GEOM_CONFIG_FILE=%SHAPER_ROOT_DIR%\plugins +@SET PATH=%SHAPER_ROOT_DIR%\swig;%SHAPER_ROOT_DIR%\plugins;%SHAPER_ROOT_DIR%\bin;%PATH% +@SET PYTHONPATH=%SHAPER_ROOT_DIR%\swig;%SHAPER_ROOT_DIR%\plugins;%SHAPER_ROOT_DIR%\addons;%SHAPER_ROOT_DIR%\pythonAPI;%PYTHONPATH% +@SET SHAPERResources=%SHAPER_ROOT_DIR%\resources rem -------- Visual Studio -------------------- rem Detect Visual Studio (either commercial or Express edition) diff --git a/salomeRun.bat b/salomeRun.bat index 6d5ea04a7..010cb93cb 100644 --- a/salomeRun.bat +++ b/salomeRun.bat @@ -2,7 +2,7 @@ call env_Salome.bat -@SET NEWGEOM_ROOT_DIR=%ROOT_DIR%\install -@SET SalomeAppConfig=%NEWGEOM_ROOT_DIR%\share\salome\resources\newgeom;%GUI_ROOT_DIR%\share\salome\resources\gui +@SET SHAPER_ROOT_DIR=%ROOT_DIR%\install +@SET SalomeAppConfig=%SHAPER_ROOT_DIR%\share\salome\resources\shaper;%GUI_ROOT_DIR%\share\salome\resources\gui start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" %* diff --git a/src/NewGeom/CMakeLists.txt b/src/NewGeom/CMakeLists.txt deleted file mode 100644 index 70f406e6f..000000000 --- a/src/NewGeom/CMakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ -## Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -SET(CMAKE_AUTOMOC ON) - -SET(PROJECT_HEADERS - NewGeom.h - NewGeom_Module.h - NewGeom_DataModel.h - NewGeom_OCCSelector.h - NewGeom_SalomeViewer.h - NewGeom_NestedButton.h -) - -SET(PROJECT_AUTOMOC - ${CMAKE_CURRENT_BINARY_DIR}/NewGeom_automoc.cpp -) - -SET(PROJECT_SOURCES - NewGeom_Module.cpp - NewGeom_DataModel.cpp - NewGeom_OCCSelector.cpp - NewGeom_SalomeViewer.cpp - NewGeom_NestedButton.cpp -) - -SET(PROJECT_RESOURCES - resources/LightApp.xml - resources/SalomeApp.xml - resources/newgeom.png -) - -SET(PROJECT_LIBRARIES - Events - Config - XGUI - ModuleBase - ${QT_LIBRARIES} - ${suit} - ${std} - ${LightApp} - ${CAM} - ${OCCViewer} - ${qtx} - ${CAS_SHAPE} -) - -ADD_DEFINITIONS( -DNewGeom_EXPORTS ${CAS_DEFINITIONS} ) - -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/XGUI - ${PROJECT_SOURCE_DIR}/src/Events - ${PROJECT_SOURCE_DIR}/src/ModuleBase - ${PROJECT_SOURCE_DIR}/src/ModelAPI - ${PROJECT_SOURCE_DIR}/src/GeomAPI - ${PROJECT_SOURCE_DIR}/src/Config - ${SALOME_GUI_INCLUDE} - ${SALOME_KERNEL_INCLUDE} - ${CAS_INCLUDE_DIRS} -) - -ADD_LIBRARY(NewGeom SHARED - ${PROJECT_SOURCES} - ${PROJECT_HEADERS} -) - -ADD_DEPENDENCIES(NewGeom XGUI) - -# The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore -TARGET_LINK_LIBRARIES(NewGeom ${PROJECT_LIBRARIES}) - -INSTALL(TARGETS NewGeom DESTINATION bin) -INSTALL(FILES ${PROJECT_RESOURCES} DESTINATION share/salome/resources/newgeom ) diff --git a/src/NewGeom/NewGeom.h b/src/NewGeom/NewGeom.h deleted file mode 100644 index a8c6978f4..000000000 --- a/src/NewGeom/NewGeom.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -#ifndef NewGeom_H -#define NewGeom_H - -#if defined NewGeom_EXPORTS -#if defined WIN32 -#define NewGeom_EXPORT __declspec( dllexport ) -#else -#define NewGeom_EXPORT -#endif -#else -#if defined WIN32 -#define NewGeom_EXPORT __declspec( dllimport ) -#else -#define NewGeom_EXPORT -#endif -#endif - -#endif - diff --git a/src/NewGeom/NewGeom_DataModel.cpp b/src/NewGeom/NewGeom_DataModel.cpp deleted file mode 100644 index 2f2089509..000000000 --- a/src/NewGeom/NewGeom_DataModel.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -#include "NewGeom_DataModel.h" -#include "NewGeom_Module.h" - -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include - -NewGeom_DataModel::NewGeom_DataModel(NewGeom_Module* theModule) - : LightApp_DataModel(theModule), myStudyPath(""), myModule(theModule) -{ -} - -NewGeom_DataModel::~NewGeom_DataModel() -{ -} - -bool NewGeom_DataModel::open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles) -{ - LightApp_DataModel::open( thePath, theStudy, theFiles ); - if (theFiles.size() == 0) - return false; - - myStudyPath = thePath; - - // If the file is Multi(contain all module files inside), the open SALOME functionality creates - // these files in a temporary directory. After the open functionality is finished, it removes - // these files (in the full SALOME mode). - // The postponed loading of the files is realized in the NewGEOM module. So, it is important do - // not remove the opened files. - // The following code creates a new tmp directory with a copy of files. - QString aTmpDir = theFiles.first(); - - LightApp_Study* aStudy = dynamic_cast( myModule->application()->activeStudy() ); - QString aNewTmpDir = aStudy->GetTmpDir("", false).c_str(); - - bool isDone = true; - QDir aDir(aTmpDir); - QStringList aFiles = aDir.entryList(QDir::Files); - QStringList::const_iterator anIt = aFiles.begin(), aLast = aFiles.end(); - for (; anIt != aLast; anIt++) { - QString aFileName = *anIt; - - QString aCurrentFile = SUIT_Tools::addSlash(aTmpDir) + aFileName; - QString aNewFile = SUIT_Tools::addSlash(aNewTmpDir) + aFileName; - if (!QFile::copy(aCurrentFile, aNewFile)) - isDone = false; - } - if (isDone) { - myTmpDirectory = aNewTmpDir; - } - else { - removeDirectory(aNewTmpDir); - myTmpDirectory = ""; - } - - SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->load(qPrintable(aNewTmpDir)); - myModule->setIsOpened(true); - return true; -} - -bool NewGeom_DataModel::save(QStringList& theFiles) -{ - LightApp_DataModel::save( theFiles ); - XGUI_Workshop* aWorkShop = myModule->workshop(); - std::list aFileNames; - - CAM_Application* anApp = myModule->application(); - LightApp_Study* aStudy = dynamic_cast(anApp->activeStudy()); - SUIT_ResourceMgr* aResMgr = anApp->resourceMgr(); - - // it is important to check whether the file is saved in the multi-files mode in order to save - // files in temporary directories, which are removed in the full SALOME mode after copiying - // the files content in a result file. - bool isMultiFile = aResMgr ? aResMgr->booleanValue("Study", "multi_file", false) : false; - - std::string aTmpDir = aStudy->GetTmpDir(qPrintable(myStudyPath), isMultiFile); - //std::string aTmpDir = aStudy->GetTmpDir("", false);//true ); - theFiles.append(QString(aTmpDir.c_str())); - - aWorkShop->saveDocument(QString(aTmpDir.c_str()), aFileNames); - std::list::iterator aIt; - for (aIt = aFileNames.begin(); aIt != aFileNames.end(); ++aIt) { - QString aName((*aIt).c_str()); - aName.replace(QChar('\\'), QChar('/')); - int aN = aName.lastIndexOf('/'); - theFiles.append(aName.right(aName.length() - aN - 1)); - } - return true; -} - -bool NewGeom_DataModel::saveAs(const QString& thePath, CAM_Study* theStudy, QStringList& theFiles) -{ - myStudyPath = thePath; - return save(theFiles); -} - -bool NewGeom_DataModel::close() -{ - myModule->workshop()->closeDocument(); - removeDirectory(myTmpDirectory); - myTmpDirectory = ""; - return LightApp_DataModel::close(); -} - -bool NewGeom_DataModel::create(CAM_Study* theStudy) -{ - return true; -} - -bool NewGeom_DataModel::isModified() const -{ - SessionPtr aMgr = ModelAPI_Session::get(); - return aMgr->isModified(); -} - -bool NewGeom_DataModel::isSaved() const -{ - return !isModified(); -} - -void NewGeom_DataModel::update(LightApp_DataObject* theObj, LightApp_Study* theStudy) -{ - // Nothing to do here: we always keep the data tree in the up-to-date state - // The only goal of this method is to hide default behavior from LightApp_DataModel - return; -} - -void NewGeom_DataModel::initRootObject() -{ - LightApp_Study* study = dynamic_cast( module()->application()->activeStudy() ); - CAM_ModuleObject *aModelRoot = dynamic_cast(root()); - if(study && aModelRoot == NULL) { - aModelRoot = createModuleObject( study->root() ); - aModelRoot->setDataModel( this ); - setRoot(aModelRoot); - } -} - -void NewGeom_DataModel::removeDirectory(const QString& theDirectoryName) -{ - Qtx::rmDir(theDirectoryName); -} - diff --git a/src/NewGeom/NewGeom_DataModel.h b/src/NewGeom/NewGeom_DataModel.h deleted file mode 100644 index e553f8ccc..000000000 --- a/src/NewGeom/NewGeom_DataModel.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -#ifndef NEWGEOM_DATAMODEL_H -#define NEWGEOM_DATAMODEL_H - -#include "NewGeom.h" -#include - -class NewGeom_Module; - -/** -* \ingroup Salome -* A Data Model class provides a connection of SALOME data structure and OpenParts application data model -*/ -class NewGeom_EXPORT NewGeom_DataModel : public LightApp_DataModel -{ - Q_OBJECT - public: - /// Constructor - /// \param theModule a module instance - NewGeom_DataModel(NewGeom_Module* theModule); - virtual ~NewGeom_DataModel(); - - /// Open a data file - /// \param thePath a path to the directory - /// \param theStudy a current study - /// \param theFiles a list of files to open - virtual bool open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles); - - /// Save module data to file - /// \param theFiles list of created files - virtual bool save(QStringList& theFiles); - - /// Save module data to a file - /// \param thePath a path to the directory - /// \param theStudy a current study - /// \param theFiles a list of files to open - virtual bool saveAs(const QString& thePath, CAM_Study* theStudy, QStringList& theFiles); - - /// Close data structure - virtual bool close(); - - /// Create data structure - /// \param theStudy a current study - virtual bool create(CAM_Study* theStudy); - - /// Returns True if the data structure has been modified - virtual bool isModified() const; - - /// Returns True if the data structure is already saved - virtual bool isSaved() const; - - /// Creates a module root object if it has not been created yet - /// and append it to the active study. It is necessary for correct persistent - /// of the model. - void initRootObject(); - - /// Update data object - /// \param theObj an data object - /// \param theStudy a current study - virtual void update(LightApp_DataObject* theObj = 0, LightApp_Study* theStudy = 0); - -protected: - /** - * Removes the directory with content if it exists - * \param theDirectoryName a directory name - */ - static void removeDirectory(const QString& theDirectoryName); - - private: - /// Pat to a study file - QString myStudyPath; - - /// a path to the temporary directory, created by opening a document file - QString myTmpDirectory; - - /// it should be created because the files reading is postponed in the module. The directory - // should be removed after the model document is closed. - NewGeom_Module* myModule; -}; - -#endif diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp deleted file mode 100644 index 7361accf9..000000000 --- a/src/NewGeom/NewGeom_Module.cpp +++ /dev/null @@ -1,646 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -#include "NewGeom_Module.h" -#include "NewGeom_DataModel.h" -#include "NewGeom_OCCSelector.h" -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include - - -extern "C" { -NewGeom_EXPORT CAM_Module* createModule() -{ - return new NewGeom_Module(); -} - -NewGeom_EXPORT char* getModuleVersion() -{ - return (char*)"0.0"; -} -} // extern "C" - -/** -* Class for preferences management -*/ -class NewGeom_PrefMgr: public ModuleBase_IPrefMgr -{ -public: - /// Constructor - /// \param theMgr preferences manager of SALOME - /// \param theModName name of the module - NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {} - - virtual int addPreference(const QString& theLbl, int pId, - SUIT_PreferenceMgr::PrefItemType theType, - const QString& theSection, const QString& theName ) - { - return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName); - } - - virtual void setItemProperty(const QString& thePropName, - const QVariant& theValue, - const int theId = -1) - { - myMgr->setItemProperty(thePropName, theValue, theId); - } - - - virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; } - -private: - LightApp_Preferences* myMgr; - QString myModName; -}; - - - - -//****************************************************** -NewGeom_Module::NewGeom_Module() - : LightApp_Module("NewGeom"), - mySelector(0), myIsOpened(0), myPopupMgr(0) -{ - myWorkshop = new XGUI_Workshop(this); - connect(myWorkshop, SIGNAL(commandStatusUpdated()), - this, SLOT(onUpdateCommandStatus())); - - myProxyViewer = new NewGeom_SalomeViewer(this); - - ModuleBase_Preferences::setResourceMgr(application()->resourceMgr()); - ModuleBase_Preferences::loadCustomProps(); -} - -//****************************************************** -NewGeom_Module::~NewGeom_Module() -{ -} - -//****************************************************** -void NewGeom_Module::initialize(CAM_Application* theApp) -{ - LightApp_Module::initialize(theApp); - inspectSalomeModules(); - - myWorkshop->startApplication(); - LightApp_Application* anApp = dynamic_cast(theApp); - if (anApp) - { - connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences())); - } -} - -//****************************************************** -void NewGeom_Module::windows(QMap& theWndMap) const -{ - theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea); -} - -//****************************************************** -void NewGeom_Module::viewManagers(QStringList& theList) const -{ - theList.append(OCCViewer_Viewer::Type()); -} - -//****************************************************** -void NewGeom_Module::connectToStudy(CAM_Study* theStudy) -{ - // if there are created viewer managers, we should try to create viewer - // selector and initialize viewer with it. It sets interactive contect to the - // proxy viewer. If study is opened, CAM application calls this method before the open() of data model - // the NewGeom data model is specific and during open(load) redisplay signals are flushed, so - // we need to connect to the viewer before it. Here, it seems the most appropriate place for this - // according to SALOME architecture. - if (!mySelector) { - ViewManagerList OCCViewManagers; - application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers); - if (OCCViewManagers.size() > 0) { - mySelector = createSelector(OCCViewManagers.first()); - } - } - LightApp_Module::connectToStudy(theStudy); -} - -//****************************************************** -bool NewGeom_Module::activateModule(SUIT_Study* theStudy) -{ - bool isDone = LightApp_Module::activateModule(theStudy); - NewGeom_DataModel* aDataModel = dynamic_cast(dataModel()); - aDataModel->initRootObject(); - - if (isDone) { - setMenuShown(true); - setToolShown(true); - - QObject* aObj = myWorkshop->objectBrowser()->parent(); - QDockWidget* aObjDoc = dynamic_cast(aObj); - if (aObjDoc) { - QAction* aViewAct = aObjDoc->toggleViewAction(); - aViewAct->setEnabled(true); - myWorkshop->objectBrowser()->setVisible(true); - aObjDoc->setVisible(true); - desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel()); - } - - if (!mySelector) { - ViewManagerList OCCViewManagers; - application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers); - if (OCCViewManagers.size() > 0) { - mySelector = createSelector(OCCViewManagers.first()); - } - } - // it should be pefromed after the selector creation in order to have AISContext - myWorkshop->activateModule(); - //action(myEraseAll)->setEnabled(false); - - if (myIsOpened) { - myWorkshop->objectBrowser()->rebuildDataTree(); - myWorkshop->updateCommandStatus(); - myIsOpened = false; - } - else - myWorkshop->updateCommandStatus(); - } - SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); - myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true); - myIsEditEnabled = getApp()->isEditEnabled(); - getApp()->setEditEnabled(false); - - // this following row is caused by #187 bug. - // SALOME saves the dock widget positions before deactivateModule() and - // load it after the module activation. So, if the panel is visible before - // deactivate, it becomes visible after activate. - // In order to avoid the visible property panel, the widget position save is - // switch off in this module - aResMgr->setValue("Study", "store_positions", false); - - // Synchronize displayed objects - Handle(AIS_InteractiveContext) aContext; - if (mySelector && mySelector->viewer()) - aContext = mySelector->viewer()->getAISContext(); - - if (!aContext.IsNull()) { - XGUI_Displayer* aDisp = myWorkshop->displayer(); - QObjectPtrList aObjList = aDisp->displayedObjects(); - - AIS_ListOfInteractive aList; - aContext->DisplayedObjects(aList); - AIS_ListIteratorOfListOfInteractive aLIt; - Handle(AIS_InteractiveObject) anAISIO; - foreach (ObjectPtr aObj, aObjList) { - AISObjectPtr aPrs = aDisp->getAISObject(aObj); - Handle(AIS_InteractiveObject) aAIS = aPrs->impl(); - bool aFound = false; - for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) { - anAISIO = aLIt.Value(); - if (anAISIO.Access() == aAIS.Access()) { - aFound = true; - break; - } - } - if (!aFound) { - aObj->setDisplayed(false); - //aDisp->erase(aObj, false); - } - } - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); - } - myProxyViewer->activateViewer(true); - return isDone; -} - -//****************************************************** -bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy) -{ - myProxyViewer->activateViewer(false); - setMenuShown(false); - setToolShown(false); - - myWorkshop->deactivateModule(); - - QObject* aObj = myWorkshop->objectBrowser()->parent(); - QDockWidget* aObjDoc = dynamic_cast(aObj); - if (aObjDoc) { - aObjDoc->setVisible(false); - myWorkshop->objectBrowser()->setVisible(false); - QAction* aViewAct = aObjDoc->toggleViewAction(); - aViewAct->setEnabled(false); - } - - // the active operation should be stopped for the next activation. - // There should not be active operation and visualized preview. - // Abort operation should be performed before the selection's remove - // because the displayed objects should be removed from the viewer, but - // the AIS context is obtained from the selector. - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - while (anOperation) { - anOperation->abort(); - anOperation = myWorkshop->operationMgr()->currentOperation(); - } - // Delete selector because it has to be redefined on next activation - if (mySelector) { - myProxyViewer->setSelector(0); - delete mySelector; - mySelector = 0; - } - - //myWorkshop->contextMenuMgr()->disconnectViewer(); - - SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); - aResMgr->setValue("Study", "store_positions", myIsStorePositions); - getApp()->setEditEnabled(myIsEditEnabled); - - return LightApp_Module::deactivateModule(theStudy); -} - -//****************************************************** -void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr) -{ - if (!mySelector) { - mySelector = createSelector(theMgr); - myWorkshop->module()->activateSelectionFilters(); - myWorkshop->synchronizeViewer(); - } -} - -//****************************************************** -void NewGeom_Module::onViewManagerRemoved(SUIT_ViewManager* theMgr) -{ - if (mySelector) { - if (theMgr->getType() == OCCViewer_Viewer::Type()) { - OCCViewer_Viewer* aViewer = static_cast(theMgr->getViewModel()); - if (mySelector->viewer() == aViewer) { - XGUI_Displayer* aDisp = myWorkshop->displayer(); - QObjectPtrList aObjects = aDisp->displayedObjects(); - foreach(ObjectPtr aObj, aObjects) - aObj->setDisplayed(false); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); - myProxyViewer->setSelector(0); - delete mySelector; - mySelector = 0; - - myWorkshop->module()->clearViewer(); - } - } - } -} - -//****************************************************** -QtxPopupMgr* NewGeom_Module::popupMgr() -{ - if (!myPopupMgr) - myPopupMgr = new QtxPopupMgr( 0, this ); - return myPopupMgr; -} - -//****************************************************** -void NewGeom_Module::onDefaultPreferences() -{ - // reset main resources - ModuleBase_Preferences::resetResourcePreferences(preferences()); - // reset plugin's resources - ModuleBase_Preferences::resetConfigPropPreferences(preferences()); - - myWorkshop->displayer()->redisplayObjects(); -} - -//****************************************************** -void NewGeom_Module::onUpdateCommandStatus() -{ - getApp()->updateActions(); -} - -//****************************************************** -NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr) -{ - if (theMgr->getType() == OCCViewer_Viewer::Type()) { - OCCViewer_Viewer* aViewer = static_cast(theMgr->getViewModel()); - NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr()); - LightApp_SelectionMgr* aMgr = getApp()->selectionMgr(); - QList aList; - aMgr->selectors(aList); - foreach(SUIT_Selector* aSel, aList) - { - aSel->setEnabled(aSel == aSelector); - } - myProxyViewer->setSelector(aSelector); - return aSelector; - } - return 0; -} - -//****************************************************** -CAM_DataModel* NewGeom_Module::createDataModel() -{ - return new NewGeom_DataModel(this); -} - -QAction* NewGeom_Module::addFeature(const QString& theWBName, const ActionInfo& theInfo) -{ - return addFeature(theWBName, - theInfo.id, - theInfo.text, - theInfo.toolTip, - theInfo.icon, - theInfo.shortcut, - theInfo.checkable); -} - -//****************************************************** -QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId, - const QString& theTitle, const QString& theTip, - const QIcon& theIcon, const QKeySequence& theKeys, - bool isCheckable) -{ - static QString aLastTool = ""; - static int aNb = 0; - if (aLastTool.isEmpty()) - aLastTool = theWBName; - else if (theWBName != aLastTool) { - aLastTool = theWBName; - if (aNb > 20) { - desktop()->addToolBarBreak(); - aNb = 0; - } - } - aNb++; - - int aMenu = createMenu(theWBName, -1, -1, 50); - int aTool = createTool(theWBName, theWBName); - - int aId = myActionsList.size(); - myActionsList.append(theId); - SUIT_Desktop* aDesk = application()->desktop(); - int aKeys = 0; - for (unsigned int i = 0; i < theKeys.count(); i++) - aKeys += theKeys[i]; - QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, - isCheckable); - aAction->setData(theId); - int aItemId = createMenu(aId, aMenu, -1, 10); - int aToolId = createTool(aId, aTool); - - return aAction; -} - -bool NewGeom_Module::isFeatureOfNested(const QAction* theAction) -{ - return dynamic_cast(theAction); -} - -QAction* NewGeom_Module::addFeatureOfNested(const QString& theWBName, - const ActionInfo& theInfo, - const QList& theNestedActions) -{ - int aMenu = createMenu(theWBName, -1, -1, 50); - int aTool = createTool(theWBName, theWBName); - - int aId = myActionsList.size(); - myActionsList.append(theInfo.id); - SUIT_Desktop* aDesk = application()->desktop(); - NewGeom_NestedButton* anAction = new NewGeom_NestedButton(aDesk, theNestedActions); - anAction->setData(theInfo.id); - anAction->setCheckable(theInfo.checkable); - anAction->setChecked(theInfo.checked); - anAction->setEnabled(theInfo.enabled); - anAction->setVisible(theInfo.visible); - anAction->setIcon(theInfo.icon); - anAction->setText(theInfo.text); - anAction->setToolTip(theInfo.toolTip); - anAction->setShortcut(theInfo.shortcut); - anAction->setFont(theInfo.font); - - //int aItemId = createMenu(aId, aMenu, -1, 10); - int aToolId = createTool(anAction, aTool, aId); - - return anAction; -} - - -//****************************************************** -QAction* NewGeom_Module::addDesktopCommand(const QString& theId, const QString& theTitle, - const QString& theTip, const QIcon& theIcon, - const QKeySequence& theKeys, bool isCheckable, - const char* theMenuSourceText, const int theMenuPosition) -{ - int aMenu = createMenu(tr(theMenuSourceText), -1, -1); - - int aId = myActionsList.size(); - myActionsList.append(theId); - SUIT_Desktop* aDesk = application()->desktop(); - int aKeys = 0; - for (unsigned int i = 0; i < theKeys.count(); i++) - aKeys += theKeys[i]; - QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, - isCheckable); - aAction->setData(theId); - createMenu(aId, aMenu, theMenuPosition); - return aAction; -} - -//****************************************************** -void NewGeom_Module::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition) -{ - int aMenu = createMenu(tr(theMenuSourceText), -1, -1); - createMenu(separator(), aMenu, -1, theMenuPosition); -} - -bool NewGeom_Module::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) -{ - if( !theAction ) - return false; - - SUIT_Desktop* aDesktop = application()->desktop(); - if( !aDesktop ) - return false; - - QtxActionToolMgr* aToolMgr = aDesktop->toolMgr(); - if( !aToolMgr ) - return false; - - aToolMgr->append( theAction, theToolBarTitle ); - return true; -} - -//****************************************************** -QList NewGeom_Module::commandList() const -{ - QList aActions; - for (int i = 0; i < myActionsList.size(); i++) { - QAction* aCmd = action(i); - if (aCmd && myActionsList.contains(aCmd->data().toString())) - aActions.append(aCmd); - } - return aActions; -} - -//****************************************************** -QStringList NewGeom_Module::commandIdList() const -{ - return myActionsList; -} - -//****************************************************** -QMainWindow* NewGeom_Module::desktop() const -{ - return application()->desktop(); -} - -//****************************************************** -QString NewGeom_Module::commandId(const QAction* theCmd) const -{ - int aId = actionId(theCmd); - if (aId < myActionsList.size()) - return myActionsList[aId]; - return QString(); -} - -//****************************************************** -QAction* NewGeom_Module::command(const QString& theId) const -{ - int aId = myActionsList.indexOf(theId); - if ((aId != -1) && (aId < myActionsList.size())) { - return action(aId); - } - return 0; -} - -//****************************************************** -void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions) -{ - myNestedActions[theId] = theActions; -} - -//****************************************************** -QStringList NewGeom_Module::nestedActions(const QString& theId) const -{ - if (myNestedActions.contains(theId)) - return myNestedActions[theId]; - return QStringList(); -} - -//****************************************************** -void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind) -{ - myDocumentType[theId] = theKind; -} - -//****************************************************** -QString NewGeom_Module::documentKind(const QString& theId) const -{ - if (myDocumentType.contains(theId)) - return myDocumentType[theId]; - return QString(); - -} - -//****************************************************** -void NewGeom_Module::selectionChanged() -{ - LightApp_Module::selectionChanged(); - myWorkshop->salomeViewerSelectionChanged(); -} - -//****************************************************** -void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle) -{ - myWorkshop->contextMenuMgr()->updateViewerMenu(); - myWorkshop->contextMenuMgr()->addViewerMenu(theMenu); - LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle); -} - - -//****************************************************** -void NewGeom_Module::createPreferences() -{ - LightApp_Preferences* pref = preferences(); - if (!pref) - return; - ModuleBase_Preferences::updateConfigByResources(); - QString aModName = moduleName(); - - QtxPreferenceItem* item = pref->findItem(aModName, true ); - if ( item && (!item->isEmpty() )) { - item->parentItem()->removeItem(item); - delete item; - } - - int catId = pref->addPreference(aModName, -1 ); - if ( catId == -1 ) - return; - NewGeom_PrefMgr aMgr(pref, aModName); - ModuleBase_Preferences::createEditContent(&aMgr, catId); - pref->retrieve(); -} - -//****************************************************** -void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam) -{ - SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); - QString aVal = aResMgr->stringValue(theSection, theParam); - Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString()); - std::string aValue = aVal.toStdString(); - if (aValue.empty()) { - aValue = aProp->defaultValue(); - aResMgr->setValue(theSection, theParam, QString(aValue.c_str())); - - LightApp_Preferences* pref = preferences(); - if (pref) - pref->retrieve(); - } - aProp->setValue(aValue); - - myWorkshop->displayer()->redisplayObjects(); -} - -void NewGeom_Module::inspectSalomeModules() -{ - QStringList aModuleNames; - getApp()->modules(aModuleNames, false); - foreach(QString eachModule, aModuleNames) { - Config_ModuleReader::addDependencyModule(eachModule.toStdString()); - } -} - -bool NewGeom_Module::abortAllOperations() -{ - return workshop()->operationMgr()->abortAllOperations(); -} diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h deleted file mode 100644 index 4920b1bee..000000000 --- a/src/NewGeom/NewGeom_Module.h +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -#ifndef NewGeom_Module_H -#define NewGeom_Module_H - -#include "NewGeom.h" -#include "NewGeom_SalomeViewer.h" - -#include -#include - -#include - -#include -#include - -class XGUI_Workshop; -class NewGeom_OCCSelector; -class OCCViewer_Viewer; -class CAM_Study; - -/** - * \ingroup Salome - * An implementation of SALOME connector class for implementation of - * XGUI functionality as a module of SALOME - */ -class NewGeom_EXPORT NewGeom_Module : public LightApp_Module, public XGUI_SalomeConnector -{ -Q_OBJECT - public: - NewGeom_Module(); - virtual ~NewGeom_Module(); - - //----- LightAPP_Module interface --------------- - - /// \brief Initializing of the module - /// \param theApp application instance - virtual void initialize(CAM_Application* theApp); - - /// \brief Definition of module standard windows - virtual void windows(QMap& theWndMap) const; - - /// \brief Definition of module viewer - virtual void viewManagers(QStringList& theList) const; - - /// \brief The method is called on selection changed event - virtual void selectionChanged(); - - //--- XGUI connector interface ----- - - virtual QAction* addFeature(const QString& theWBName, const QString& theId, - const QString& theTitle, const QString& theTip, const QIcon& theIcon, - const QKeySequence& theKeys = QKeySequence(), - bool isCheckable = false); - - //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action - virtual QAction* addFeature(const QString& theWBName, - const ActionInfo& theInfo); - - /// Add a nested feature - /// \param theWBName a workbench name - /// \param theInfo the action parameters - /// \param theNestedActions a list of nested actions - virtual QAction* addFeatureOfNested(const QString& theWBName, - const ActionInfo& theInfo, - const QList& theNestedActions); - - //! Returns true if the feature action is a nested action, in other words, - //! it is created by addNestedFeature(). - //! \param theAction - an action of a feature - //! returns boolean result - virtual bool isFeatureOfNested(const QAction* theAction); - - virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle, - const QString& theTip, const QIcon& theIcon, - const QKeySequence& theKeys, bool isCheckable, - const char* theMenuSourceText, - const int theMenuPosition = 10); - - virtual void addDesktopMenuSeparator(const char* theMenuSourceText, - const int theMenuPosition = 10); - - /// Add an action to a tool bar - /// \param theAction an ation to add - /// \param theToolBarTitle a name of tool bar - virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ); - - virtual QMainWindow* desktop() const; - - virtual QString commandId(const QAction* theCmd) const; - - virtual QAction* command(const QString& theId) const; - - //! Set nested actions dependent on command Id - //! \param theId - the command ID - //! \param theActions - the list of nested actions - virtual void setNestedActions(const QString& theId, const QStringList& theActions); - - //! Returns list of nested actions according to the given command ID - virtual QStringList nestedActions(const QString& theId) const; - - //! Set the document kind of the action by the given command Id - //! \param theId - the command ID - //! \param theKind - the document kind - virtual void setDocumentKind(const QString& theId, const QString& theKind); - - //! Returns the document kind of the action by the given command ID - virtual QString documentKind(const QString& theId) const; - - //! Returns interface to Salome viewer - virtual ModuleBase_IViewer* viewer() const - { - return myProxyViewer; - } - - //! Returns list of defined actions (just by NewGeom module) - virtual QList commandList() const; - - //! Returns list of Ids of defined actions (just by NewGeom module) - virtual QStringList commandIdList() const; - - /// Redefinition of virtual function. - /// \param theClient name of pop-up client - /// \param theMenu popup menu instance - /// \param theTitle menu title. - virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle); - - /// Redefinition of virtual function for preferences creation. - virtual void createPreferences(); - - /// Redefinition of virtual function for preferences changed event. - virtual void preferencesChanged(const QString& theSection, const QString& theParam); - - /// \return Workshop class instance - XGUI_Workshop* workshop() const { return myWorkshop; } - - /// \brief Set flag about opened document state - void setIsOpened(bool theOpened) { myIsOpened = theOpened; } - - /// Register current modules of SALOME - void inspectSalomeModules(); - - public slots: - /// \brief The method is redefined to connect to the study viewer before the data - /// model is filled by opened file. This file open will flush redisplay signals for, - /// objects which should be visualized - virtual void connectToStudy(CAM_Study* theStudy); - - /// \brief The method is called on the module activation - /// \param theStudy current study - virtual bool activateModule(SUIT_Study* theStudy); - - /// \brief The method is called on the module activation - /// \param theStudy current study - virtual bool deactivateModule(SUIT_Study* theStudy); - - protected slots: - /// Redefinition of virtual function - /// \param theMgr view manager - virtual void onViewManagerAdded(SUIT_ViewManager* theMgr); - - /// Redefinition of virtual function - /// \param theMgr view manager - virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr); - - /// Set preferences to default - void onDefaultPreferences(); - - /// Obtains the current application and updates its actions - void onUpdateCommandStatus(); - - protected: - /// Create data model - CAM_DataModel* createDataModel(); - - /// Create popup menu manager - virtual QtxPopupMgr* popupMgr(); - - /// Abort all operations - virtual bool abortAllOperations(); - - private: - /// Create selector for OCC Viewer - /// \param theMgr view manager - NewGeom_OCCSelector* createSelector(SUIT_ViewManager* theMgr); - - /// List of registered actions - QStringList myActionsList; - - /// Reference to workshop - XGUI_Workshop* myWorkshop; - - /// OCC viewer selector instance - NewGeom_OCCSelector* mySelector; - - /// Proxy viewer for connection to OCC Viewer in SALOME - NewGeom_SalomeViewer* myProxyViewer; - - /// Map of nested actions [ActionID: list of nested actions Id] - QMap myNestedActions; - - /// Map of document types - QMap myDocumentType; - - /// Flag of opened document state - bool myIsOpened; - - // the next parameters should be restored after this module deactivation - - /// The application value of the preferences parameter - bool myIsStorePositions; - - /// The application value - bool myIsEditEnabled; - - /// Popup manager - QtxPopupMgr* myPopupMgr; -}; - -#endif diff --git a/src/NewGeom/NewGeom_NestedButton.cpp b/src/NewGeom/NewGeom_NestedButton.cpp deleted file mode 100644 index 1440d92e9..000000000 --- a/src/NewGeom/NewGeom_NestedButton.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * NewGeom_NestedButton.cpp - * - * Created on: Apr 13, 2015 - * Author: sbh - */ - -#include - -#include -#include -#include -#include -#include - -NewGeom_NestedButton::NewGeom_NestedButton(QObject* theParent, - const QList& theNestedActions) -: QWidgetAction(theParent), - myNestedActions(theNestedActions), - myAdditionalButtonsWidget(0), - myButtonFrame(0), - myThisButton(0) -{ -} - -NewGeom_NestedButton::~NewGeom_NestedButton() -{ -} - -void NewGeom_NestedButton::showAdditionalButtons(bool isShow) -{ - myAdditionalButtonsWidget->setVisible(isShow); - if (isShow) { - myButtonFrame->setFrameStyle(QFrame::WinPanel); - myButtonFrame->setFrameShadow(QFrame::Sunken); - myThisButton->setAutoRaise(false); - } else { - myButtonFrame->setFrameStyle(QFrame::NoFrame); - myButtonFrame->setFrameShadow(QFrame::Plain); - myThisButton->setAutoRaise(true); - } -} - -QWidget * NewGeom_NestedButton::createWidget(QWidget * theParent) -{ - myButtonFrame = new QFrame(theParent); - QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame); - aBoxLay->setContentsMargins(2, 0, 0, 0); - aBoxLay->setSpacing(1); - QSizePolicy aSizePolicy; - aSizePolicy.setControlType(QSizePolicy::ToolButton); - myButtonFrame->setSizePolicy(aSizePolicy); - - myThisButton = new QToolButton(myButtonFrame); - myThisButton->setDefaultAction(this); - myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - aBoxLay->addWidget(myThisButton, 1); - - myAdditionalButtonsWidget = new QWidget(myButtonFrame); - QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget); - aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0); - aAdditionalBoxLay->setSpacing(1); - foreach (QAction* eachAct, myNestedActions) { - QToolButton* aButton = new QToolButton(myButtonFrame); - aButton->setDefaultAction(eachAct); - aButton->setAutoRaise(true); - aAdditionalBoxLay->addWidget(aButton); - } - myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay); - aBoxLay->addWidget(myAdditionalButtonsWidget); - - myButtonFrame->setLayout(aBoxLay); - - showAdditionalButtons(false); - connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool))); - connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged())); - return myButtonFrame; -} - -bool NewGeom_NestedButton::event(QEvent* theEvent) -{ - if (theEvent->type() == QEvent::ActionChanged) { - if (myThisButton) { - myThisButton->setEnabled(isEnabled()); - return true; - } - } - return QWidgetAction::event(theEvent); -} - - -void NewGeom_NestedButton::actionStateChanged() -{ - if (isEnabled()) { - QString s = "true"; - } else { - QString s = "false"; - } - -} diff --git a/src/NewGeom/NewGeom_NestedButton.h b/src/NewGeom/NewGeom_NestedButton.h deleted file mode 100644 index eb4eb2ea1..000000000 --- a/src/NewGeom/NewGeom_NestedButton.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * NewGeom_NestedButton.h - * - * Created on: Apr 13, 2015 - * Author: sbh - */ - -#ifndef SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_ -#define SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_ - -#include - -class QFrame; -class QAction; -class QWidget; -class QToolButton; - -/*! - * \ingroup Salome - * Custom (nested) button in salome mode. - */ -class NewGeom_NestedButton : public QWidgetAction -{ - Q_OBJECT - public: - /// Constructor - /// \param theParent a parent objects - /// \param theNestedActions a list of nested actions - NewGeom_NestedButton(QObject* theParent, const QList& theNestedActions); - virtual ~NewGeom_NestedButton(); - - private slots: - /// Shows/hides the additional buttons widget - void showAdditionalButtons(bool); - - /// Slot called on action state - void actionStateChanged(); - - protected: - /// Creates the button representation - /// \param theParent a parent widget - virtual QWidget * createWidget(QWidget * theParent); - - virtual bool event(QEvent* theEvent); - - private: - QList myNestedActions; ///< list of nested actions - QWidget* myAdditionalButtonsWidget; ///< widget to precess additional buttons visibility - QFrame* myButtonFrame; ///< frame arround button representation - QToolButton* myThisButton; ///< main button -}; - -#endif /* SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_ */ diff --git a/src/NewGeom/NewGeom_OCCSelector.cpp b/src/NewGeom/NewGeom_OCCSelector.cpp deleted file mode 100644 index 2331662bf..000000000 --- a/src/NewGeom/NewGeom_OCCSelector.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -#include "NewGeom_OCCSelector.h" - -NewGeom_OCCSelector::NewGeom_OCCSelector(OCCViewer_Viewer* theViewer, SUIT_SelectionMgr* theMgr) - : LightApp_OCCSelector(theViewer, theMgr) -{ -} - -NewGeom_OCCSelector::~NewGeom_OCCSelector() -{ -} - -void NewGeom_OCCSelector::getSelection(SUIT_DataOwnerPtrList& thePtrList) const -{ - OCCViewer_Viewer* vw = viewer(); - if (!vw) - return; -} - -void NewGeom_OCCSelector::setSelection(const SUIT_DataOwnerPtrList& thePtrList) -{ - OCCViewer_Viewer* vw = viewer(); - if (!vw) - return; - -} diff --git a/src/NewGeom/NewGeom_OCCSelector.h b/src/NewGeom/NewGeom_OCCSelector.h deleted file mode 100644 index d27a62c79..000000000 --- a/src/NewGeom/NewGeom_OCCSelector.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -#ifndef NewGeom_OCCSelector_H -#define NewGeom_OCCSelector_H - -#include "NewGeom.h" - -#include - -/** -* \ingroup Salome -* Redefinition of standard OCC selector in order to adapt it to NewGeom needs -*/ -class NewGeom_EXPORT NewGeom_OCCSelector : public LightApp_OCCSelector -{ - public: - /// Constructor - /// \param theViewer a viewer - /// \param theMgr a selection manager - NewGeom_OCCSelector(OCCViewer_Viewer* theViewer, SUIT_SelectionMgr* theMgr); - virtual ~NewGeom_OCCSelector(); - - protected: - /// Redifinition of virtual function - virtual void getSelection(SUIT_DataOwnerPtrList& theList) const; - - /// Redifinition of virtual function - virtual void setSelection(const SUIT_DataOwnerPtrList& theList); -}; - -#endif diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp deleted file mode 100644 index f116db233..000000000 --- a/src/NewGeom/NewGeom_SalomeViewer.cpp +++ /dev/null @@ -1,476 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -#include "NewGeom_SalomeViewer.h" -#include "NewGeom_OCCSelector.h" - -#include -#include - -#include - -#include - -#include - -#include -#include - -NewGeom_SalomeView::NewGeom_SalomeView(OCCViewer_Viewer* theViewer) -: ModuleBase_IViewWindow(), myCurrentView(0) -{ - myViewer = theViewer; -} - - -Handle(V3d_View) NewGeom_SalomeView::v3dView() const -{ - Handle(V3d_View) aView; - if (myCurrentView) { - OCCViewer_ViewWindow* aWnd = static_cast(myCurrentView); - aView = aWnd->getViewPort()->getView(); - } - return aView; -} - -QWidget* NewGeom_SalomeView::viewPort() const -{ - QWidget* aViewPort = 0; - if (myCurrentView) { - OCCViewer_ViewWindow* aWnd = static_cast(myCurrentView); - aViewPort = aWnd->getViewPort(); - } - return aViewPort; -} - -//********************************************** -//********************************************** -//********************************************** - - - -NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent) - : ModuleBase_IViewer(theParent), - mySelector(0), myView(0), myIsSelectionChanged(false) -{ -} - -NewGeom_SalomeViewer::~NewGeom_SalomeViewer() -{ - if (myView) - delete myView; -} - - -//********************************************** -Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const -{ - if (mySelector && mySelector->viewer()) - return mySelector->viewer()->getAISContext(); - Handle(AIS_InteractiveContext) aNull; - return aNull; -} - -//********************************************** -Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const -{ - if (mySelector) - return mySelector->viewer()->getViewer3d(); - return Handle(V3d_Viewer)(); -} - -//********************************************** -Handle(AIS_Trihedron) NewGeom_SalomeViewer::trihedron() const -{ - return mySelector->viewer()->getTrihedron(); -} - -//********************************************** -Handle(V3d_View) NewGeom_SalomeViewer::activeView() const -{ - if (mySelector) { - OCCViewer_Viewer* aViewer = mySelector->viewer(); - SUIT_ViewManager* aMgr = aViewer->getViewManager(); - OCCViewer_ViewWindow* aWnd = static_cast(aMgr->getActiveView()); - return aWnd->getViewPort()->getView(); - } - return Handle(V3d_View)(); -} - -//********************************************** -QWidget* NewGeom_SalomeViewer::activeViewPort() const -{ - QWidget* aViewPort; - if (mySelector) { - OCCViewer_Viewer* aViewer = mySelector->viewer(); - SUIT_ViewManager* aMgr = aViewer->getViewManager(); - OCCViewer_ViewWindow* aWnd = static_cast(aMgr->getActiveView()); - aViewPort = aWnd->getViewPort(); - } - return aViewPort; -} - -//********************************************** -void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel) -{ - if (mySelector) { - if (mySelector == theSel) - return; - else { - mySelector->viewer()->getViewManager()->disconnect(this); - OCCViewer_Viewer* aViewer = mySelector->viewer(); - if (aViewer) - aViewer->disconnect(this); - } - } - mySelector = theSel; - if (!mySelector) - return; - OCCViewer_Viewer* aViewer = mySelector->viewer(); - SUIT_ViewManager* aMgr = aViewer->getViewManager(); - - myView = new NewGeom_SalomeView(mySelector->viewer()); - - // TODO: Provide ModuleBase_IViewWindow interface - connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed())); - - connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)), - this, SLOT(onTryCloseView(SUIT_ViewWindow*))); - connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)), - this, SLOT(onDeleteView(SUIT_ViewWindow*))); - connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)), - this, SLOT(onViewCreated(SUIT_ViewWindow*))); - connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), - this, SLOT(onActivated(SUIT_ViewManager*))); - - connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this, - SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); - connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this, - SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); - connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this, - SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*))); - connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this, - SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*))); - - connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this, - SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*))); - connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this, - SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*))); - - connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); -} - -//********************************************** -void NewGeom_SalomeViewer::onSelectionChanged() -{ - // Selection event must be sent only after mouse release - myIsSelectionChanged = true; -} - -//********************************************** -void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow* theView, QMouseEvent* theEvent) -{ - myView->setCurrentView(theView); - emit mousePress(myView, theEvent); -} - -//********************************************** -void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow* theView, QMouseEvent* theEvent) -{ - myView->setCurrentView(theView); - emit mouseRelease(myView, theEvent); - if (myIsSelectionChanged) { - emit selectionChanged(); - myIsSelectionChanged = false; - } -} - -//********************************************** -void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow* theView, QMouseEvent* theEvent) -{ - myView->setCurrentView(theView); - emit mouseDoubleClick(myView, theEvent); -} - -//********************************************** -void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow* theView, QMouseEvent* theEvent) -{ - myView->setCurrentView(theView); - emit mouseMove(myView, theEvent); -} - -//********************************************** -bool NewGeom_SalomeViewer::canDragByMouse() const -{ - OCCViewer_Viewer* aViewer = mySelector->viewer(); - SUIT_ViewWindow* aWnd = aViewer->getViewManager()->getActiveView(); - OCCViewer_ViewWindow* aViewWnd = dynamic_cast(aWnd); - if (aViewWnd) { - return (aViewWnd->interactionStyle() == 0); - } - return true; -} - - -//********************************************** -void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent) -{ - emit keyPress(myView, theEvent); -} - -//********************************************** -void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow* theView, QKeyEvent* theEvent) -{ - emit keyRelease(myView, theEvent); -} - -//********************************************** -void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*) -{ - emit tryCloseView(myView); -} - -//********************************************** -void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*) -{ - if(myWindowScale.contains(myView->v3dView())) - myWindowScale.remove(myView->v3dView()); - emit deleteView(myView); -} - -//********************************************** -void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView) -{ - myView->setCurrentView(theView); - - OCCViewer_ViewFrame* aView = dynamic_cast(theView); - - OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW); - if (aWnd) { - connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), - this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); - OCCViewer_ViewPort3d* aViewPort = aWnd->getViewPort(); - if (aViewPort) - connect(aViewPort, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewPortMapped())); - } - reconnectActions(aWnd, true); - - myWindowScale.insert (aView->getViewPort()->getView(), aView->getViewPort()->getView()->Camera()->Scale()); - - emit viewCreated(myView); - - -} - -//********************************************** -void NewGeom_SalomeViewer::onActivated(SUIT_ViewManager* theMgr) -{ - myView->setCurrentView(theMgr->getActiveView()); - emit activated(myView); -} - -//********************************************** -void NewGeom_SalomeViewer::enableSelection(bool isEnabled) -{ - if (mySelector) - if (mySelector->viewer()->isSelectionEnabled() != isEnabled) - mySelector->viewer()->enableSelection(isEnabled); - // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking) - // After this is corrected, the first row should be recommented, the last - removed - //mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD - // : SUIT_ViewModel::KEY_FREE); -} - -//********************************************** -bool NewGeom_SalomeViewer::isSelectionEnabled() const -{ - if (mySelector) - return mySelector->viewer()->isSelectionEnabled(); - return false; -} - -//********************************************** -void NewGeom_SalomeViewer::enableMultiselection(bool isEnable) -{ - if (mySelector) - mySelector->viewer()->enableMultiselection(isEnable); -} - -//********************************************** -bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const -{ - if (mySelector) - return mySelector->viewer()->isMultiSelectionEnabled(); - return false; -} - -//********************************************** -bool NewGeom_SalomeViewer::enableDrawMode(bool isEnabled) -{ - // TODO: Has to be replaced when SALOME patch become available - if (mySelector) - return mySelector->viewer()->enableDrawMode(isEnabled); - return false; -} - -//********************************************** -void NewGeom_SalomeViewer::reconnectActions(SUIT_ViewWindow* theWindow, - const bool theUseNewGeomSlot) -{ - OCCViewer_ViewWindow* aWindow = dynamic_cast(theWindow); - if (!aWindow) - return; - - QAction* anAction = theWindow->toolMgr()->action(OCCViewer_ViewWindow::TrihedronShowId); - if (!anAction) - return; - - if (theUseNewGeomSlot) { - anAction->disconnect(anAction, SIGNAL(toggled(bool)), - theWindow, SLOT(onTrihedronShow(bool))); - anAction->connect(anAction, SIGNAL(toggled(bool)), - this, SIGNAL(trihedronVisibilityChanged(bool))); - } - else { - anAction->connect(anAction, SIGNAL(toggled(bool)), - theWindow, SLOT(onTrihedronShow(bool))); - anAction->disconnect(anAction, SIGNAL(toggled(bool)), - this, SIGNAL(trihedronVisibilityChanged(bool))); - } -} - -//********************************************** -void NewGeom_SalomeViewer::fitAll() -{ - if (mySelector) { - SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); - OCCViewer_ViewFrame* aVFrame = dynamic_cast(aMgr->getActiveView()); - if (aVFrame) { - aVFrame->onFitAll(); - } - } -} - -//********************************************** -void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ, double theTwist) -{ - if (!mySelector) - return; - - SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); - OCCViewer_ViewFrame* aVFrame = dynamic_cast(aMgr->getActiveView()); - if (aVFrame) { - Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView(); - if (!aView3d.IsNull()) { - aView3d->SetProj(theX, theY, theZ); - aView3d->SetTwist( theTwist ); - aView3d->FitAll(0.01, false); - aView3d->SetZSize(0.); - if (aView3d->Depth() < 0.1) - aView3d->DepthFitAll(); - } - } -} - -//*************************************** -void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - aContext->AddFilter(theFilter); - } -} - -//*************************************** -void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - aContext->RemoveFilter(theFilter); - } -} - -//*************************************** -bool NewGeom_SalomeViewer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) -{ - bool aFoundFilter = false; - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - const SelectMgr_ListOfFilter& aFilters = aContext->Filters(); - SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); - for (; aIt.More() && !aFoundFilter; aIt.Next()) { - aFoundFilter = theFilter.Access() == aIt.Value().Access(); - } - } - return aFoundFilter; -} - -//*************************************** -void NewGeom_SalomeViewer::clearSelectionFilters() -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - aContext->RemoveFilters(); - } -} - -//*************************************** -void NewGeom_SalomeViewer::update() -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - aContext->UpdateCurrentViewer(); - } -} - -//*************************************** -void NewGeom_SalomeViewer::onViewTransformed(OCCViewer_ViewWindow::OperationType theType) -{ - emit viewTransformed((int) theType); -} - -//*************************************** -void NewGeom_SalomeViewer::onViewPortMapped() -{ - emit trihedronVisibilityChanged(true); -} - -//*************************************** -void NewGeom_SalomeViewer::activateViewer(bool toActivate) -{ - if (!mySelector || !mySelector->viewer()) - return; - SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); - QVector aViews = aMgr->getViews(); - if (toActivate) { - foreach (SUIT_ViewWindow* aView, aViews) { - OCCViewer_ViewFrame* aOCCView = dynamic_cast(aView); - OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW); - connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), - this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); - reconnectActions(aWnd, true); - } - } else { - foreach (SUIT_ViewWindow* aView, aViews) { - OCCViewer_ViewFrame* aOCCView = dynamic_cast(aView); - OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW); - disconnect((OCCViewer_ViewWindow*)aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), - this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); - reconnectActions(aWnd, false); - } - } -} - -void NewGeom_SalomeViewer::Zfitall() -{ - if (!mySelector || !mySelector->viewer()) - return; - SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); - OCCViewer_ViewFrame* aView = dynamic_cast(aMgr->getActiveView()); - if (aView) { - OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW); - Handle(V3d_View) aView3d = aWnd->getViewPort()->getView(); - aView3d->ZFitAll(); - if (aView3d->Depth() < 0.1) - aView3d->DepthFitAll(); - } -} \ No newline at end of file diff --git a/src/NewGeom/NewGeom_SalomeViewer.h b/src/NewGeom/NewGeom_SalomeViewer.h deleted file mode 100644 index e32cfbbdf..000000000 --- a/src/NewGeom/NewGeom_SalomeViewer.h +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -#ifndef NewGeom_SalomeViewer_H -#define NewGeom_SalomeViewer_H - -#include "NewGeom.h" - -#include -#include - -#include - -#include -#include - -class SUIT_ViewWindow; -class QMouseEvent; -class QKeyEvent; - -class NewGeom_OCCSelector; -class OCCViewer_Viewer; -class SUIT_ViewManager; - -/** -* \ingroup Salome -* A class for providing access of NewGeom functionality to -* SALOME view window functionality -*/ -class NewGeom_SalomeView: public ModuleBase_IViewWindow -{ -public: - /// Constructor - /// \param theViewer a reference to a viewer - NewGeom_SalomeView(OCCViewer_Viewer* theViewer); - - virtual Handle(V3d_View) v3dView() const; - - /// Returns the view window view port - virtual QWidget* viewPort() const; - - /// Set the current viewer - /// \param theViewer a viewer instance - void setViewer(OCCViewer_Viewer* theViewer) { myViewer = theViewer; } - - /// Returns current viewer - OCCViewer_Viewer* viewer() const { return myViewer; } - - /// Sets the current view - void setCurrentView(SUIT_ViewWindow* theView) { myCurrentView = theView; } - -private: - /// A reference to a viewer - OCCViewer_Viewer* myViewer; - SUIT_ViewWindow* myCurrentView; -}; - - -/** -* \ingroup Salome -* A class for providing access of NewGeom functionality to -* SALOME viewer functionality -*/ -class NewGeom_SalomeViewer : public ModuleBase_IViewer -{ -Q_OBJECT - public: - /// Constructor - /// \param theParent a parent object - NewGeom_SalomeViewer(QObject* theParent); - - ~NewGeom_SalomeViewer(); - - //! Returns AIS_InteractiveContext from current OCCViewer - virtual Handle(AIS_InteractiveContext) AISContext() const; - - //! Retrurns V3d_Vioewer from current viewer - virtual Handle(V3d_Viewer) v3dViewer() const; - - //! Trihedron 3d object shown in the viewer - virtual Handle(AIS_Trihedron) trihedron() const; - - //! Returns Vsd_View object from currently active view window - virtual Handle(V3d_View) activeView() const; - - //! Returns viewer view port - virtual QWidget* activeViewPort() const; - - //! Enable or disable selection in the viewer - virtual void enableSelection(bool isEnabled); - - //! Returns true if selection is enabled - virtual bool isSelectionEnabled() const; - - //! Enable or disable multiselection in the viewer - virtual void enableMultiselection(bool isEnable); - - //! Returns true if multiselection is enabled - virtual bool isMultiSelectionEnabled() const; - - //! Enable or disable draw mode in the viewer - virtual bool enableDrawMode(bool isEnabled); - - //! For some signals it disconnects the window from usual signal and connect it to the module ones - void reconnectActions(SUIT_ViewWindow* theWindow, const bool theUseNewGeomSlot); - - //! Perfroms the fit all for the active view - virtual void fitAll(); - - //! Sets the view projection - /// \param theX the X projection value - /// \param theY the Y projection value - /// \param theZ the Z projection value - /// \param theTwist the twist angle in radians - virtual void setViewProjection( double theX, double theY, double theZ, - double theTwist ); - - /// Set selector - /// \param theSel a selector instance - void setSelector(NewGeom_OCCSelector* theSel); - - /// Add selection filter to the viewer - virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); - - /// Remove selection filter from the viewer - virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); - - /// Returns true if the selection filter is set to the viewer - /// \param theFilter a selection filter - virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); - - /// Remove all selection filters from the viewer - virtual void clearSelectionFilters(); - - /// Returns current selector - NewGeom_OCCSelector* selector() const - { - return mySelector; - } - - /// Update current viewer - virtual void update(); - - /// Method returns True if the viewer can process editing objects - /// by mouse drugging. If this is impossible thet it has to return False. - virtual bool canDragByMouse() const; - - /// Activate or deactivate viewer - /// \param toActivate - activation flag - void activateViewer(bool toActivate); - - // Fit all along Z (perpendicular to display) - virtual void Zfitall(); - - private slots: - void onMousePress(SUIT_ViewWindow*, QMouseEvent*); - void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*); - void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*); - void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); - void onKeyPress(SUIT_ViewWindow*, QKeyEvent*); - void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*); - - void onTryCloseView(SUIT_ViewWindow*); - void onDeleteView(SUIT_ViewWindow*); - void onViewCreated(SUIT_ViewWindow*); - void onActivated(SUIT_ViewManager*); - - void onSelectionChanged(); - void onViewTransformed(OCCViewer_ViewWindow::OperationType); - - /// Emit signal about trihedron visiblity change because SALOME sets the trihedron visible by this signal. - /// It is necessary to activate the viewer trihedron in the current selection mode - void onViewPortMapped(); - - private: - NewGeom_OCCSelector* mySelector; - NewGeom_SalomeView* myView; - bool myIsSelectionChanged; -}; - - -#endif diff --git a/src/NewGeom/resources/LightApp.xml b/src/NewGeom/resources/LightApp.xml deleted file mode 100644 index 35f5954da..000000000 --- a/src/NewGeom/resources/LightApp.xml +++ /dev/null @@ -1,37 +0,0 @@ - - -
- - - - - -
-
- - -
-
- - -
-
diff --git a/src/NewGeom/resources/SalomeApp.xml b/src/NewGeom/resources/SalomeApp.xml deleted file mode 100644 index 0df9ffd62..000000000 --- a/src/NewGeom/resources/SalomeApp.xml +++ /dev/null @@ -1,41 +0,0 @@ - - -
- - -
-
- - - - - -
-
- - -
-
- - -
-
diff --git a/src/NewGeom/resources/newgeom.png b/src/NewGeom/resources/newgeom.png deleted file mode 100644 index d4827e272..000000000 Binary files a/src/NewGeom/resources/newgeom.png and /dev/null differ diff --git a/src/SHAPERGUI/CMakeLists.txt b/src/SHAPERGUI/CMakeLists.txt new file mode 100644 index 000000000..c8616d383 --- /dev/null +++ b/src/SHAPERGUI/CMakeLists.txt @@ -0,0 +1,72 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +SET(CMAKE_AUTOMOC ON) + +SET(PROJECT_HEADERS + SHAPER_SHAPERGUI.h + SHAPERGUI.h + SHAPERGUI_DataModel.h + SHAPERGUI_OCCSelector.h + SHAPERGUI_SalomeViewer.h + SHAPERGUI_NestedButton.h +) + +SET(PROJECT_AUTOMOC + ${CMAKE_CURRENT_BINARY_DIR}/SHAPERGUI_automoc.cpp +) + +SET(PROJECT_SOURCES + SHAPERGUI.cpp + SHAPERGUI_DataModel.cpp + SHAPERGUI_OCCSelector.cpp + SHAPERGUI_SalomeViewer.cpp + SHAPERGUI_NestedButton.cpp +) + +SET(PROJECT_RESOURCES + resources/LightApp.xml + resources/SalomeApp.xml + resources/newgeom.png +) + +SET(PROJECT_LIBRARIES + Events + Config + XGUI + ModuleBase + ${QT_LIBRARIES} + ${suit} + ${std} + ${LightApp} + ${CAM} + ${OCCViewer} + ${qtx} + ${CAS_SHAPE} +) + +ADD_DEFINITIONS( -DSHAPERGUI_EXPORTS ${CAS_DEFINITIONS} ) + +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/XGUI + ${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/ModuleBase + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/GeomAPI + ${PROJECT_SOURCE_DIR}/src/Config + ${SALOME_GUI_INCLUDE} + ${SALOME_KERNEL_INCLUDE} + ${CAS_INCLUDE_DIRS} +) + +ADD_LIBRARY(SHAPERGUI SHARED + ${PROJECT_SOURCES} + ${PROJECT_HEADERS} +) + +ADD_DEPENDENCIES(SHAPERGUI XGUI) + +# The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore +TARGET_LINK_LIBRARIES(SHAPERGUI ${PROJECT_LIBRARIES}) + +INSTALL(TARGETS SHAPERGUI DESTINATION bin) +INSTALL(FILES ${PROJECT_RESOURCES} DESTINATION share/salome/resources/shaper ) diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp new file mode 100644 index 000000000..7361accf9 --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -0,0 +1,646 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +#include "NewGeom_Module.h" +#include "NewGeom_DataModel.h" +#include "NewGeom_OCCSelector.h" +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + + +extern "C" { +NewGeom_EXPORT CAM_Module* createModule() +{ + return new NewGeom_Module(); +} + +NewGeom_EXPORT char* getModuleVersion() +{ + return (char*)"0.0"; +} +} // extern "C" + +/** +* Class for preferences management +*/ +class NewGeom_PrefMgr: public ModuleBase_IPrefMgr +{ +public: + /// Constructor + /// \param theMgr preferences manager of SALOME + /// \param theModName name of the module + NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {} + + virtual int addPreference(const QString& theLbl, int pId, + SUIT_PreferenceMgr::PrefItemType theType, + const QString& theSection, const QString& theName ) + { + return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName); + } + + virtual void setItemProperty(const QString& thePropName, + const QVariant& theValue, + const int theId = -1) + { + myMgr->setItemProperty(thePropName, theValue, theId); + } + + + virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; } + +private: + LightApp_Preferences* myMgr; + QString myModName; +}; + + + + +//****************************************************** +NewGeom_Module::NewGeom_Module() + : LightApp_Module("NewGeom"), + mySelector(0), myIsOpened(0), myPopupMgr(0) +{ + myWorkshop = new XGUI_Workshop(this); + connect(myWorkshop, SIGNAL(commandStatusUpdated()), + this, SLOT(onUpdateCommandStatus())); + + myProxyViewer = new NewGeom_SalomeViewer(this); + + ModuleBase_Preferences::setResourceMgr(application()->resourceMgr()); + ModuleBase_Preferences::loadCustomProps(); +} + +//****************************************************** +NewGeom_Module::~NewGeom_Module() +{ +} + +//****************************************************** +void NewGeom_Module::initialize(CAM_Application* theApp) +{ + LightApp_Module::initialize(theApp); + inspectSalomeModules(); + + myWorkshop->startApplication(); + LightApp_Application* anApp = dynamic_cast(theApp); + if (anApp) + { + connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences())); + } +} + +//****************************************************** +void NewGeom_Module::windows(QMap& theWndMap) const +{ + theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea); +} + +//****************************************************** +void NewGeom_Module::viewManagers(QStringList& theList) const +{ + theList.append(OCCViewer_Viewer::Type()); +} + +//****************************************************** +void NewGeom_Module::connectToStudy(CAM_Study* theStudy) +{ + // if there are created viewer managers, we should try to create viewer + // selector and initialize viewer with it. It sets interactive contect to the + // proxy viewer. If study is opened, CAM application calls this method before the open() of data model + // the NewGeom data model is specific and during open(load) redisplay signals are flushed, so + // we need to connect to the viewer before it. Here, it seems the most appropriate place for this + // according to SALOME architecture. + if (!mySelector) { + ViewManagerList OCCViewManagers; + application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers); + if (OCCViewManagers.size() > 0) { + mySelector = createSelector(OCCViewManagers.first()); + } + } + LightApp_Module::connectToStudy(theStudy); +} + +//****************************************************** +bool NewGeom_Module::activateModule(SUIT_Study* theStudy) +{ + bool isDone = LightApp_Module::activateModule(theStudy); + NewGeom_DataModel* aDataModel = dynamic_cast(dataModel()); + aDataModel->initRootObject(); + + if (isDone) { + setMenuShown(true); + setToolShown(true); + + QObject* aObj = myWorkshop->objectBrowser()->parent(); + QDockWidget* aObjDoc = dynamic_cast(aObj); + if (aObjDoc) { + QAction* aViewAct = aObjDoc->toggleViewAction(); + aViewAct->setEnabled(true); + myWorkshop->objectBrowser()->setVisible(true); + aObjDoc->setVisible(true); + desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel()); + } + + if (!mySelector) { + ViewManagerList OCCViewManagers; + application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers); + if (OCCViewManagers.size() > 0) { + mySelector = createSelector(OCCViewManagers.first()); + } + } + // it should be pefromed after the selector creation in order to have AISContext + myWorkshop->activateModule(); + //action(myEraseAll)->setEnabled(false); + + if (myIsOpened) { + myWorkshop->objectBrowser()->rebuildDataTree(); + myWorkshop->updateCommandStatus(); + myIsOpened = false; + } + else + myWorkshop->updateCommandStatus(); + } + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true); + myIsEditEnabled = getApp()->isEditEnabled(); + getApp()->setEditEnabled(false); + + // this following row is caused by #187 bug. + // SALOME saves the dock widget positions before deactivateModule() and + // load it after the module activation. So, if the panel is visible before + // deactivate, it becomes visible after activate. + // In order to avoid the visible property panel, the widget position save is + // switch off in this module + aResMgr->setValue("Study", "store_positions", false); + + // Synchronize displayed objects + Handle(AIS_InteractiveContext) aContext; + if (mySelector && mySelector->viewer()) + aContext = mySelector->viewer()->getAISContext(); + + if (!aContext.IsNull()) { + XGUI_Displayer* aDisp = myWorkshop->displayer(); + QObjectPtrList aObjList = aDisp->displayedObjects(); + + AIS_ListOfInteractive aList; + aContext->DisplayedObjects(aList); + AIS_ListIteratorOfListOfInteractive aLIt; + Handle(AIS_InteractiveObject) anAISIO; + foreach (ObjectPtr aObj, aObjList) { + AISObjectPtr aPrs = aDisp->getAISObject(aObj); + Handle(AIS_InteractiveObject) aAIS = aPrs->impl(); + bool aFound = false; + for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) { + anAISIO = aLIt.Value(); + if (anAISIO.Access() == aAIS.Access()) { + aFound = true; + break; + } + } + if (!aFound) { + aObj->setDisplayed(false); + //aDisp->erase(aObj, false); + } + } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } + myProxyViewer->activateViewer(true); + return isDone; +} + +//****************************************************** +bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy) +{ + myProxyViewer->activateViewer(false); + setMenuShown(false); + setToolShown(false); + + myWorkshop->deactivateModule(); + + QObject* aObj = myWorkshop->objectBrowser()->parent(); + QDockWidget* aObjDoc = dynamic_cast(aObj); + if (aObjDoc) { + aObjDoc->setVisible(false); + myWorkshop->objectBrowser()->setVisible(false); + QAction* aViewAct = aObjDoc->toggleViewAction(); + aViewAct->setEnabled(false); + } + + // the active operation should be stopped for the next activation. + // There should not be active operation and visualized preview. + // Abort operation should be performed before the selection's remove + // because the displayed objects should be removed from the viewer, but + // the AIS context is obtained from the selector. + ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); + while (anOperation) { + anOperation->abort(); + anOperation = myWorkshop->operationMgr()->currentOperation(); + } + // Delete selector because it has to be redefined on next activation + if (mySelector) { + myProxyViewer->setSelector(0); + delete mySelector; + mySelector = 0; + } + + //myWorkshop->contextMenuMgr()->disconnectViewer(); + + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + aResMgr->setValue("Study", "store_positions", myIsStorePositions); + getApp()->setEditEnabled(myIsEditEnabled); + + return LightApp_Module::deactivateModule(theStudy); +} + +//****************************************************** +void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr) +{ + if (!mySelector) { + mySelector = createSelector(theMgr); + myWorkshop->module()->activateSelectionFilters(); + myWorkshop->synchronizeViewer(); + } +} + +//****************************************************** +void NewGeom_Module::onViewManagerRemoved(SUIT_ViewManager* theMgr) +{ + if (mySelector) { + if (theMgr->getType() == OCCViewer_Viewer::Type()) { + OCCViewer_Viewer* aViewer = static_cast(theMgr->getViewModel()); + if (mySelector->viewer() == aViewer) { + XGUI_Displayer* aDisp = myWorkshop->displayer(); + QObjectPtrList aObjects = aDisp->displayedObjects(); + foreach(ObjectPtr aObj, aObjects) + aObj->setDisplayed(false); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + myProxyViewer->setSelector(0); + delete mySelector; + mySelector = 0; + + myWorkshop->module()->clearViewer(); + } + } + } +} + +//****************************************************** +QtxPopupMgr* NewGeom_Module::popupMgr() +{ + if (!myPopupMgr) + myPopupMgr = new QtxPopupMgr( 0, this ); + return myPopupMgr; +} + +//****************************************************** +void NewGeom_Module::onDefaultPreferences() +{ + // reset main resources + ModuleBase_Preferences::resetResourcePreferences(preferences()); + // reset plugin's resources + ModuleBase_Preferences::resetConfigPropPreferences(preferences()); + + myWorkshop->displayer()->redisplayObjects(); +} + +//****************************************************** +void NewGeom_Module::onUpdateCommandStatus() +{ + getApp()->updateActions(); +} + +//****************************************************** +NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr) +{ + if (theMgr->getType() == OCCViewer_Viewer::Type()) { + OCCViewer_Viewer* aViewer = static_cast(theMgr->getViewModel()); + NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr()); + LightApp_SelectionMgr* aMgr = getApp()->selectionMgr(); + QList aList; + aMgr->selectors(aList); + foreach(SUIT_Selector* aSel, aList) + { + aSel->setEnabled(aSel == aSelector); + } + myProxyViewer->setSelector(aSelector); + return aSelector; + } + return 0; +} + +//****************************************************** +CAM_DataModel* NewGeom_Module::createDataModel() +{ + return new NewGeom_DataModel(this); +} + +QAction* NewGeom_Module::addFeature(const QString& theWBName, const ActionInfo& theInfo) +{ + return addFeature(theWBName, + theInfo.id, + theInfo.text, + theInfo.toolTip, + theInfo.icon, + theInfo.shortcut, + theInfo.checkable); +} + +//****************************************************** +QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId, + const QString& theTitle, const QString& theTip, + const QIcon& theIcon, const QKeySequence& theKeys, + bool isCheckable) +{ + static QString aLastTool = ""; + static int aNb = 0; + if (aLastTool.isEmpty()) + aLastTool = theWBName; + else if (theWBName != aLastTool) { + aLastTool = theWBName; + if (aNb > 20) { + desktop()->addToolBarBreak(); + aNb = 0; + } + } + aNb++; + + int aMenu = createMenu(theWBName, -1, -1, 50); + int aTool = createTool(theWBName, theWBName); + + int aId = myActionsList.size(); + myActionsList.append(theId); + SUIT_Desktop* aDesk = application()->desktop(); + int aKeys = 0; + for (unsigned int i = 0; i < theKeys.count(); i++) + aKeys += theKeys[i]; + QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, + isCheckable); + aAction->setData(theId); + int aItemId = createMenu(aId, aMenu, -1, 10); + int aToolId = createTool(aId, aTool); + + return aAction; +} + +bool NewGeom_Module::isFeatureOfNested(const QAction* theAction) +{ + return dynamic_cast(theAction); +} + +QAction* NewGeom_Module::addFeatureOfNested(const QString& theWBName, + const ActionInfo& theInfo, + const QList& theNestedActions) +{ + int aMenu = createMenu(theWBName, -1, -1, 50); + int aTool = createTool(theWBName, theWBName); + + int aId = myActionsList.size(); + myActionsList.append(theInfo.id); + SUIT_Desktop* aDesk = application()->desktop(); + NewGeom_NestedButton* anAction = new NewGeom_NestedButton(aDesk, theNestedActions); + anAction->setData(theInfo.id); + anAction->setCheckable(theInfo.checkable); + anAction->setChecked(theInfo.checked); + anAction->setEnabled(theInfo.enabled); + anAction->setVisible(theInfo.visible); + anAction->setIcon(theInfo.icon); + anAction->setText(theInfo.text); + anAction->setToolTip(theInfo.toolTip); + anAction->setShortcut(theInfo.shortcut); + anAction->setFont(theInfo.font); + + //int aItemId = createMenu(aId, aMenu, -1, 10); + int aToolId = createTool(anAction, aTool, aId); + + return anAction; +} + + +//****************************************************** +QAction* NewGeom_Module::addDesktopCommand(const QString& theId, const QString& theTitle, + const QString& theTip, const QIcon& theIcon, + const QKeySequence& theKeys, bool isCheckable, + const char* theMenuSourceText, const int theMenuPosition) +{ + int aMenu = createMenu(tr(theMenuSourceText), -1, -1); + + int aId = myActionsList.size(); + myActionsList.append(theId); + SUIT_Desktop* aDesk = application()->desktop(); + int aKeys = 0; + for (unsigned int i = 0; i < theKeys.count(); i++) + aKeys += theKeys[i]; + QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, + isCheckable); + aAction->setData(theId); + createMenu(aId, aMenu, theMenuPosition); + return aAction; +} + +//****************************************************** +void NewGeom_Module::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition) +{ + int aMenu = createMenu(tr(theMenuSourceText), -1, -1); + createMenu(separator(), aMenu, -1, theMenuPosition); +} + +bool NewGeom_Module::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) +{ + if( !theAction ) + return false; + + SUIT_Desktop* aDesktop = application()->desktop(); + if( !aDesktop ) + return false; + + QtxActionToolMgr* aToolMgr = aDesktop->toolMgr(); + if( !aToolMgr ) + return false; + + aToolMgr->append( theAction, theToolBarTitle ); + return true; +} + +//****************************************************** +QList NewGeom_Module::commandList() const +{ + QList aActions; + for (int i = 0; i < myActionsList.size(); i++) { + QAction* aCmd = action(i); + if (aCmd && myActionsList.contains(aCmd->data().toString())) + aActions.append(aCmd); + } + return aActions; +} + +//****************************************************** +QStringList NewGeom_Module::commandIdList() const +{ + return myActionsList; +} + +//****************************************************** +QMainWindow* NewGeom_Module::desktop() const +{ + return application()->desktop(); +} + +//****************************************************** +QString NewGeom_Module::commandId(const QAction* theCmd) const +{ + int aId = actionId(theCmd); + if (aId < myActionsList.size()) + return myActionsList[aId]; + return QString(); +} + +//****************************************************** +QAction* NewGeom_Module::command(const QString& theId) const +{ + int aId = myActionsList.indexOf(theId); + if ((aId != -1) && (aId < myActionsList.size())) { + return action(aId); + } + return 0; +} + +//****************************************************** +void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions) +{ + myNestedActions[theId] = theActions; +} + +//****************************************************** +QStringList NewGeom_Module::nestedActions(const QString& theId) const +{ + if (myNestedActions.contains(theId)) + return myNestedActions[theId]; + return QStringList(); +} + +//****************************************************** +void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind) +{ + myDocumentType[theId] = theKind; +} + +//****************************************************** +QString NewGeom_Module::documentKind(const QString& theId) const +{ + if (myDocumentType.contains(theId)) + return myDocumentType[theId]; + return QString(); + +} + +//****************************************************** +void NewGeom_Module::selectionChanged() +{ + LightApp_Module::selectionChanged(); + myWorkshop->salomeViewerSelectionChanged(); +} + +//****************************************************** +void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle) +{ + myWorkshop->contextMenuMgr()->updateViewerMenu(); + myWorkshop->contextMenuMgr()->addViewerMenu(theMenu); + LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle); +} + + +//****************************************************** +void NewGeom_Module::createPreferences() +{ + LightApp_Preferences* pref = preferences(); + if (!pref) + return; + ModuleBase_Preferences::updateConfigByResources(); + QString aModName = moduleName(); + + QtxPreferenceItem* item = pref->findItem(aModName, true ); + if ( item && (!item->isEmpty() )) { + item->parentItem()->removeItem(item); + delete item; + } + + int catId = pref->addPreference(aModName, -1 ); + if ( catId == -1 ) + return; + NewGeom_PrefMgr aMgr(pref, aModName); + ModuleBase_Preferences::createEditContent(&aMgr, catId); + pref->retrieve(); +} + +//****************************************************** +void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam) +{ + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + QString aVal = aResMgr->stringValue(theSection, theParam); + Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString()); + std::string aValue = aVal.toStdString(); + if (aValue.empty()) { + aValue = aProp->defaultValue(); + aResMgr->setValue(theSection, theParam, QString(aValue.c_str())); + + LightApp_Preferences* pref = preferences(); + if (pref) + pref->retrieve(); + } + aProp->setValue(aValue); + + myWorkshop->displayer()->redisplayObjects(); +} + +void NewGeom_Module::inspectSalomeModules() +{ + QStringList aModuleNames; + getApp()->modules(aModuleNames, false); + foreach(QString eachModule, aModuleNames) { + Config_ModuleReader::addDependencyModule(eachModule.toStdString()); + } +} + +bool NewGeom_Module::abortAllOperations() +{ + return workshop()->operationMgr()->abortAllOperations(); +} diff --git a/src/SHAPERGUI/SHAPERGUI.h b/src/SHAPERGUI/SHAPERGUI.h new file mode 100644 index 000000000..4920b1bee --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI.h @@ -0,0 +1,221 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +#ifndef NewGeom_Module_H +#define NewGeom_Module_H + +#include "NewGeom.h" +#include "NewGeom_SalomeViewer.h" + +#include +#include + +#include + +#include +#include + +class XGUI_Workshop; +class NewGeom_OCCSelector; +class OCCViewer_Viewer; +class CAM_Study; + +/** + * \ingroup Salome + * An implementation of SALOME connector class for implementation of + * XGUI functionality as a module of SALOME + */ +class NewGeom_EXPORT NewGeom_Module : public LightApp_Module, public XGUI_SalomeConnector +{ +Q_OBJECT + public: + NewGeom_Module(); + virtual ~NewGeom_Module(); + + //----- LightAPP_Module interface --------------- + + /// \brief Initializing of the module + /// \param theApp application instance + virtual void initialize(CAM_Application* theApp); + + /// \brief Definition of module standard windows + virtual void windows(QMap& theWndMap) const; + + /// \brief Definition of module viewer + virtual void viewManagers(QStringList& theList) const; + + /// \brief The method is called on selection changed event + virtual void selectionChanged(); + + //--- XGUI connector interface ----- + + virtual QAction* addFeature(const QString& theWBName, const QString& theId, + const QString& theTitle, const QString& theTip, const QIcon& theIcon, + const QKeySequence& theKeys = QKeySequence(), + bool isCheckable = false); + + //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action + virtual QAction* addFeature(const QString& theWBName, + const ActionInfo& theInfo); + + /// Add a nested feature + /// \param theWBName a workbench name + /// \param theInfo the action parameters + /// \param theNestedActions a list of nested actions + virtual QAction* addFeatureOfNested(const QString& theWBName, + const ActionInfo& theInfo, + const QList& theNestedActions); + + //! Returns true if the feature action is a nested action, in other words, + //! it is created by addNestedFeature(). + //! \param theAction - an action of a feature + //! returns boolean result + virtual bool isFeatureOfNested(const QAction* theAction); + + virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle, + const QString& theTip, const QIcon& theIcon, + const QKeySequence& theKeys, bool isCheckable, + const char* theMenuSourceText, + const int theMenuPosition = 10); + + virtual void addDesktopMenuSeparator(const char* theMenuSourceText, + const int theMenuPosition = 10); + + /// Add an action to a tool bar + /// \param theAction an ation to add + /// \param theToolBarTitle a name of tool bar + virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ); + + virtual QMainWindow* desktop() const; + + virtual QString commandId(const QAction* theCmd) const; + + virtual QAction* command(const QString& theId) const; + + //! Set nested actions dependent on command Id + //! \param theId - the command ID + //! \param theActions - the list of nested actions + virtual void setNestedActions(const QString& theId, const QStringList& theActions); + + //! Returns list of nested actions according to the given command ID + virtual QStringList nestedActions(const QString& theId) const; + + //! Set the document kind of the action by the given command Id + //! \param theId - the command ID + //! \param theKind - the document kind + virtual void setDocumentKind(const QString& theId, const QString& theKind); + + //! Returns the document kind of the action by the given command ID + virtual QString documentKind(const QString& theId) const; + + //! Returns interface to Salome viewer + virtual ModuleBase_IViewer* viewer() const + { + return myProxyViewer; + } + + //! Returns list of defined actions (just by NewGeom module) + virtual QList commandList() const; + + //! Returns list of Ids of defined actions (just by NewGeom module) + virtual QStringList commandIdList() const; + + /// Redefinition of virtual function. + /// \param theClient name of pop-up client + /// \param theMenu popup menu instance + /// \param theTitle menu title. + virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle); + + /// Redefinition of virtual function for preferences creation. + virtual void createPreferences(); + + /// Redefinition of virtual function for preferences changed event. + virtual void preferencesChanged(const QString& theSection, const QString& theParam); + + /// \return Workshop class instance + XGUI_Workshop* workshop() const { return myWorkshop; } + + /// \brief Set flag about opened document state + void setIsOpened(bool theOpened) { myIsOpened = theOpened; } + + /// Register current modules of SALOME + void inspectSalomeModules(); + + public slots: + /// \brief The method is redefined to connect to the study viewer before the data + /// model is filled by opened file. This file open will flush redisplay signals for, + /// objects which should be visualized + virtual void connectToStudy(CAM_Study* theStudy); + + /// \brief The method is called on the module activation + /// \param theStudy current study + virtual bool activateModule(SUIT_Study* theStudy); + + /// \brief The method is called on the module activation + /// \param theStudy current study + virtual bool deactivateModule(SUIT_Study* theStudy); + + protected slots: + /// Redefinition of virtual function + /// \param theMgr view manager + virtual void onViewManagerAdded(SUIT_ViewManager* theMgr); + + /// Redefinition of virtual function + /// \param theMgr view manager + virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr); + + /// Set preferences to default + void onDefaultPreferences(); + + /// Obtains the current application and updates its actions + void onUpdateCommandStatus(); + + protected: + /// Create data model + CAM_DataModel* createDataModel(); + + /// Create popup menu manager + virtual QtxPopupMgr* popupMgr(); + + /// Abort all operations + virtual bool abortAllOperations(); + + private: + /// Create selector for OCC Viewer + /// \param theMgr view manager + NewGeom_OCCSelector* createSelector(SUIT_ViewManager* theMgr); + + /// List of registered actions + QStringList myActionsList; + + /// Reference to workshop + XGUI_Workshop* myWorkshop; + + /// OCC viewer selector instance + NewGeom_OCCSelector* mySelector; + + /// Proxy viewer for connection to OCC Viewer in SALOME + NewGeom_SalomeViewer* myProxyViewer; + + /// Map of nested actions [ActionID: list of nested actions Id] + QMap myNestedActions; + + /// Map of document types + QMap myDocumentType; + + /// Flag of opened document state + bool myIsOpened; + + // the next parameters should be restored after this module deactivation + + /// The application value of the preferences parameter + bool myIsStorePositions; + + /// The application value + bool myIsEditEnabled; + + /// Popup manager + QtxPopupMgr* myPopupMgr; +}; + +#endif diff --git a/src/SHAPERGUI/SHAPERGUI_DataModel.cpp b/src/SHAPERGUI/SHAPERGUI_DataModel.cpp new file mode 100644 index 000000000..2f2089509 --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_DataModel.cpp @@ -0,0 +1,155 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include "NewGeom_DataModel.h" +#include "NewGeom_Module.h" + +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +NewGeom_DataModel::NewGeom_DataModel(NewGeom_Module* theModule) + : LightApp_DataModel(theModule), myStudyPath(""), myModule(theModule) +{ +} + +NewGeom_DataModel::~NewGeom_DataModel() +{ +} + +bool NewGeom_DataModel::open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles) +{ + LightApp_DataModel::open( thePath, theStudy, theFiles ); + if (theFiles.size() == 0) + return false; + + myStudyPath = thePath; + + // If the file is Multi(contain all module files inside), the open SALOME functionality creates + // these files in a temporary directory. After the open functionality is finished, it removes + // these files (in the full SALOME mode). + // The postponed loading of the files is realized in the NewGEOM module. So, it is important do + // not remove the opened files. + // The following code creates a new tmp directory with a copy of files. + QString aTmpDir = theFiles.first(); + + LightApp_Study* aStudy = dynamic_cast( myModule->application()->activeStudy() ); + QString aNewTmpDir = aStudy->GetTmpDir("", false).c_str(); + + bool isDone = true; + QDir aDir(aTmpDir); + QStringList aFiles = aDir.entryList(QDir::Files); + QStringList::const_iterator anIt = aFiles.begin(), aLast = aFiles.end(); + for (; anIt != aLast; anIt++) { + QString aFileName = *anIt; + + QString aCurrentFile = SUIT_Tools::addSlash(aTmpDir) + aFileName; + QString aNewFile = SUIT_Tools::addSlash(aNewTmpDir) + aFileName; + if (!QFile::copy(aCurrentFile, aNewFile)) + isDone = false; + } + if (isDone) { + myTmpDirectory = aNewTmpDir; + } + else { + removeDirectory(aNewTmpDir); + myTmpDirectory = ""; + } + + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->load(qPrintable(aNewTmpDir)); + myModule->setIsOpened(true); + return true; +} + +bool NewGeom_DataModel::save(QStringList& theFiles) +{ + LightApp_DataModel::save( theFiles ); + XGUI_Workshop* aWorkShop = myModule->workshop(); + std::list aFileNames; + + CAM_Application* anApp = myModule->application(); + LightApp_Study* aStudy = dynamic_cast(anApp->activeStudy()); + SUIT_ResourceMgr* aResMgr = anApp->resourceMgr(); + + // it is important to check whether the file is saved in the multi-files mode in order to save + // files in temporary directories, which are removed in the full SALOME mode after copiying + // the files content in a result file. + bool isMultiFile = aResMgr ? aResMgr->booleanValue("Study", "multi_file", false) : false; + + std::string aTmpDir = aStudy->GetTmpDir(qPrintable(myStudyPath), isMultiFile); + //std::string aTmpDir = aStudy->GetTmpDir("", false);//true ); + theFiles.append(QString(aTmpDir.c_str())); + + aWorkShop->saveDocument(QString(aTmpDir.c_str()), aFileNames); + std::list::iterator aIt; + for (aIt = aFileNames.begin(); aIt != aFileNames.end(); ++aIt) { + QString aName((*aIt).c_str()); + aName.replace(QChar('\\'), QChar('/')); + int aN = aName.lastIndexOf('/'); + theFiles.append(aName.right(aName.length() - aN - 1)); + } + return true; +} + +bool NewGeom_DataModel::saveAs(const QString& thePath, CAM_Study* theStudy, QStringList& theFiles) +{ + myStudyPath = thePath; + return save(theFiles); +} + +bool NewGeom_DataModel::close() +{ + myModule->workshop()->closeDocument(); + removeDirectory(myTmpDirectory); + myTmpDirectory = ""; + return LightApp_DataModel::close(); +} + +bool NewGeom_DataModel::create(CAM_Study* theStudy) +{ + return true; +} + +bool NewGeom_DataModel::isModified() const +{ + SessionPtr aMgr = ModelAPI_Session::get(); + return aMgr->isModified(); +} + +bool NewGeom_DataModel::isSaved() const +{ + return !isModified(); +} + +void NewGeom_DataModel::update(LightApp_DataObject* theObj, LightApp_Study* theStudy) +{ + // Nothing to do here: we always keep the data tree in the up-to-date state + // The only goal of this method is to hide default behavior from LightApp_DataModel + return; +} + +void NewGeom_DataModel::initRootObject() +{ + LightApp_Study* study = dynamic_cast( module()->application()->activeStudy() ); + CAM_ModuleObject *aModelRoot = dynamic_cast(root()); + if(study && aModelRoot == NULL) { + aModelRoot = createModuleObject( study->root() ); + aModelRoot->setDataModel( this ); + setRoot(aModelRoot); + } +} + +void NewGeom_DataModel::removeDirectory(const QString& theDirectoryName) +{ + Qtx::rmDir(theDirectoryName); +} + diff --git a/src/SHAPERGUI/SHAPERGUI_DataModel.h b/src/SHAPERGUI/SHAPERGUI_DataModel.h new file mode 100644 index 000000000..e553f8ccc --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_DataModel.h @@ -0,0 +1,83 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +#ifndef NEWGEOM_DATAMODEL_H +#define NEWGEOM_DATAMODEL_H + +#include "NewGeom.h" +#include + +class NewGeom_Module; + +/** +* \ingroup Salome +* A Data Model class provides a connection of SALOME data structure and OpenParts application data model +*/ +class NewGeom_EXPORT NewGeom_DataModel : public LightApp_DataModel +{ + Q_OBJECT + public: + /// Constructor + /// \param theModule a module instance + NewGeom_DataModel(NewGeom_Module* theModule); + virtual ~NewGeom_DataModel(); + + /// Open a data file + /// \param thePath a path to the directory + /// \param theStudy a current study + /// \param theFiles a list of files to open + virtual bool open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles); + + /// Save module data to file + /// \param theFiles list of created files + virtual bool save(QStringList& theFiles); + + /// Save module data to a file + /// \param thePath a path to the directory + /// \param theStudy a current study + /// \param theFiles a list of files to open + virtual bool saveAs(const QString& thePath, CAM_Study* theStudy, QStringList& theFiles); + + /// Close data structure + virtual bool close(); + + /// Create data structure + /// \param theStudy a current study + virtual bool create(CAM_Study* theStudy); + + /// Returns True if the data structure has been modified + virtual bool isModified() const; + + /// Returns True if the data structure is already saved + virtual bool isSaved() const; + + /// Creates a module root object if it has not been created yet + /// and append it to the active study. It is necessary for correct persistent + /// of the model. + void initRootObject(); + + /// Update data object + /// \param theObj an data object + /// \param theStudy a current study + virtual void update(LightApp_DataObject* theObj = 0, LightApp_Study* theStudy = 0); + +protected: + /** + * Removes the directory with content if it exists + * \param theDirectoryName a directory name + */ + static void removeDirectory(const QString& theDirectoryName); + + private: + /// Pat to a study file + QString myStudyPath; + + /// a path to the temporary directory, created by opening a document file + QString myTmpDirectory; + + /// it should be created because the files reading is postponed in the module. The directory + // should be removed after the model document is closed. + NewGeom_Module* myModule; +}; + +#endif diff --git a/src/SHAPERGUI/SHAPERGUI_NestedButton.cpp b/src/SHAPERGUI/SHAPERGUI_NestedButton.cpp new file mode 100644 index 000000000..1440d92e9 --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_NestedButton.cpp @@ -0,0 +1,100 @@ +/* + * NewGeom_NestedButton.cpp + * + * Created on: Apr 13, 2015 + * Author: sbh + */ + +#include + +#include +#include +#include +#include +#include + +NewGeom_NestedButton::NewGeom_NestedButton(QObject* theParent, + const QList& theNestedActions) +: QWidgetAction(theParent), + myNestedActions(theNestedActions), + myAdditionalButtonsWidget(0), + myButtonFrame(0), + myThisButton(0) +{ +} + +NewGeom_NestedButton::~NewGeom_NestedButton() +{ +} + +void NewGeom_NestedButton::showAdditionalButtons(bool isShow) +{ + myAdditionalButtonsWidget->setVisible(isShow); + if (isShow) { + myButtonFrame->setFrameStyle(QFrame::WinPanel); + myButtonFrame->setFrameShadow(QFrame::Sunken); + myThisButton->setAutoRaise(false); + } else { + myButtonFrame->setFrameStyle(QFrame::NoFrame); + myButtonFrame->setFrameShadow(QFrame::Plain); + myThisButton->setAutoRaise(true); + } +} + +QWidget * NewGeom_NestedButton::createWidget(QWidget * theParent) +{ + myButtonFrame = new QFrame(theParent); + QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame); + aBoxLay->setContentsMargins(2, 0, 0, 0); + aBoxLay->setSpacing(1); + QSizePolicy aSizePolicy; + aSizePolicy.setControlType(QSizePolicy::ToolButton); + myButtonFrame->setSizePolicy(aSizePolicy); + + myThisButton = new QToolButton(myButtonFrame); + myThisButton->setDefaultAction(this); + myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + aBoxLay->addWidget(myThisButton, 1); + + myAdditionalButtonsWidget = new QWidget(myButtonFrame); + QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget); + aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0); + aAdditionalBoxLay->setSpacing(1); + foreach (QAction* eachAct, myNestedActions) { + QToolButton* aButton = new QToolButton(myButtonFrame); + aButton->setDefaultAction(eachAct); + aButton->setAutoRaise(true); + aAdditionalBoxLay->addWidget(aButton); + } + myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay); + aBoxLay->addWidget(myAdditionalButtonsWidget); + + myButtonFrame->setLayout(aBoxLay); + + showAdditionalButtons(false); + connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool))); + connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged())); + return myButtonFrame; +} + +bool NewGeom_NestedButton::event(QEvent* theEvent) +{ + if (theEvent->type() == QEvent::ActionChanged) { + if (myThisButton) { + myThisButton->setEnabled(isEnabled()); + return true; + } + } + return QWidgetAction::event(theEvent); +} + + +void NewGeom_NestedButton::actionStateChanged() +{ + if (isEnabled()) { + QString s = "true"; + } else { + QString s = "false"; + } + +} diff --git a/src/SHAPERGUI/SHAPERGUI_NestedButton.h b/src/SHAPERGUI/SHAPERGUI_NestedButton.h new file mode 100644 index 000000000..eb4eb2ea1 --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_NestedButton.h @@ -0,0 +1,53 @@ +/* + * NewGeom_NestedButton.h + * + * Created on: Apr 13, 2015 + * Author: sbh + */ + +#ifndef SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_ +#define SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_ + +#include + +class QFrame; +class QAction; +class QWidget; +class QToolButton; + +/*! + * \ingroup Salome + * Custom (nested) button in salome mode. + */ +class NewGeom_NestedButton : public QWidgetAction +{ + Q_OBJECT + public: + /// Constructor + /// \param theParent a parent objects + /// \param theNestedActions a list of nested actions + NewGeom_NestedButton(QObject* theParent, const QList& theNestedActions); + virtual ~NewGeom_NestedButton(); + + private slots: + /// Shows/hides the additional buttons widget + void showAdditionalButtons(bool); + + /// Slot called on action state + void actionStateChanged(); + + protected: + /// Creates the button representation + /// \param theParent a parent widget + virtual QWidget * createWidget(QWidget * theParent); + + virtual bool event(QEvent* theEvent); + + private: + QList myNestedActions; ///< list of nested actions + QWidget* myAdditionalButtonsWidget; ///< widget to precess additional buttons visibility + QFrame* myButtonFrame; ///< frame arround button representation + QToolButton* myThisButton; ///< main button +}; + +#endif /* SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_ */ diff --git a/src/SHAPERGUI/SHAPERGUI_OCCSelector.cpp b/src/SHAPERGUI/SHAPERGUI_OCCSelector.cpp new file mode 100644 index 000000000..2331662bf --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_OCCSelector.cpp @@ -0,0 +1,27 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include "NewGeom_OCCSelector.h" + +NewGeom_OCCSelector::NewGeom_OCCSelector(OCCViewer_Viewer* theViewer, SUIT_SelectionMgr* theMgr) + : LightApp_OCCSelector(theViewer, theMgr) +{ +} + +NewGeom_OCCSelector::~NewGeom_OCCSelector() +{ +} + +void NewGeom_OCCSelector::getSelection(SUIT_DataOwnerPtrList& thePtrList) const +{ + OCCViewer_Viewer* vw = viewer(); + if (!vw) + return; +} + +void NewGeom_OCCSelector::setSelection(const SUIT_DataOwnerPtrList& thePtrList) +{ + OCCViewer_Viewer* vw = viewer(); + if (!vw) + return; + +} diff --git a/src/SHAPERGUI/SHAPERGUI_OCCSelector.h b/src/SHAPERGUI/SHAPERGUI_OCCSelector.h new file mode 100644 index 000000000..d27a62c79 --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_OCCSelector.h @@ -0,0 +1,31 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef NewGeom_OCCSelector_H +#define NewGeom_OCCSelector_H + +#include "NewGeom.h" + +#include + +/** +* \ingroup Salome +* Redefinition of standard OCC selector in order to adapt it to NewGeom needs +*/ +class NewGeom_EXPORT NewGeom_OCCSelector : public LightApp_OCCSelector +{ + public: + /// Constructor + /// \param theViewer a viewer + /// \param theMgr a selection manager + NewGeom_OCCSelector(OCCViewer_Viewer* theViewer, SUIT_SelectionMgr* theMgr); + virtual ~NewGeom_OCCSelector(); + + protected: + /// Redifinition of virtual function + virtual void getSelection(SUIT_DataOwnerPtrList& theList) const; + + /// Redifinition of virtual function + virtual void setSelection(const SUIT_DataOwnerPtrList& theList); +}; + +#endif diff --git a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp new file mode 100644 index 000000000..f116db233 --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp @@ -0,0 +1,476 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include "NewGeom_SalomeViewer.h" +#include "NewGeom_OCCSelector.h" + +#include +#include + +#include + +#include + +#include + +#include +#include + +NewGeom_SalomeView::NewGeom_SalomeView(OCCViewer_Viewer* theViewer) +: ModuleBase_IViewWindow(), myCurrentView(0) +{ + myViewer = theViewer; +} + + +Handle(V3d_View) NewGeom_SalomeView::v3dView() const +{ + Handle(V3d_View) aView; + if (myCurrentView) { + OCCViewer_ViewWindow* aWnd = static_cast(myCurrentView); + aView = aWnd->getViewPort()->getView(); + } + return aView; +} + +QWidget* NewGeom_SalomeView::viewPort() const +{ + QWidget* aViewPort = 0; + if (myCurrentView) { + OCCViewer_ViewWindow* aWnd = static_cast(myCurrentView); + aViewPort = aWnd->getViewPort(); + } + return aViewPort; +} + +//********************************************** +//********************************************** +//********************************************** + + + +NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent) + : ModuleBase_IViewer(theParent), + mySelector(0), myView(0), myIsSelectionChanged(false) +{ +} + +NewGeom_SalomeViewer::~NewGeom_SalomeViewer() +{ + if (myView) + delete myView; +} + + +//********************************************** +Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const +{ + if (mySelector && mySelector->viewer()) + return mySelector->viewer()->getAISContext(); + Handle(AIS_InteractiveContext) aNull; + return aNull; +} + +//********************************************** +Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const +{ + if (mySelector) + return mySelector->viewer()->getViewer3d(); + return Handle(V3d_Viewer)(); +} + +//********************************************** +Handle(AIS_Trihedron) NewGeom_SalomeViewer::trihedron() const +{ + return mySelector->viewer()->getTrihedron(); +} + +//********************************************** +Handle(V3d_View) NewGeom_SalomeViewer::activeView() const +{ + if (mySelector) { + OCCViewer_Viewer* aViewer = mySelector->viewer(); + SUIT_ViewManager* aMgr = aViewer->getViewManager(); + OCCViewer_ViewWindow* aWnd = static_cast(aMgr->getActiveView()); + return aWnd->getViewPort()->getView(); + } + return Handle(V3d_View)(); +} + +//********************************************** +QWidget* NewGeom_SalomeViewer::activeViewPort() const +{ + QWidget* aViewPort; + if (mySelector) { + OCCViewer_Viewer* aViewer = mySelector->viewer(); + SUIT_ViewManager* aMgr = aViewer->getViewManager(); + OCCViewer_ViewWindow* aWnd = static_cast(aMgr->getActiveView()); + aViewPort = aWnd->getViewPort(); + } + return aViewPort; +} + +//********************************************** +void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel) +{ + if (mySelector) { + if (mySelector == theSel) + return; + else { + mySelector->viewer()->getViewManager()->disconnect(this); + OCCViewer_Viewer* aViewer = mySelector->viewer(); + if (aViewer) + aViewer->disconnect(this); + } + } + mySelector = theSel; + if (!mySelector) + return; + OCCViewer_Viewer* aViewer = mySelector->viewer(); + SUIT_ViewManager* aMgr = aViewer->getViewManager(); + + myView = new NewGeom_SalomeView(mySelector->viewer()); + + // TODO: Provide ModuleBase_IViewWindow interface + connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed())); + + connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)), + this, SLOT(onTryCloseView(SUIT_ViewWindow*))); + connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)), + this, SLOT(onDeleteView(SUIT_ViewWindow*))); + connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)), + this, SLOT(onViewCreated(SUIT_ViewWindow*))); + connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), + this, SLOT(onActivated(SUIT_ViewManager*))); + + connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this, + SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this, + SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); + connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this, + SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*))); + connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this, + SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*))); + + connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this, + SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*))); + connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this, + SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*))); + + connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); +} + +//********************************************** +void NewGeom_SalomeViewer::onSelectionChanged() +{ + // Selection event must be sent only after mouse release + myIsSelectionChanged = true; +} + +//********************************************** +void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow* theView, QMouseEvent* theEvent) +{ + myView->setCurrentView(theView); + emit mousePress(myView, theEvent); +} + +//********************************************** +void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow* theView, QMouseEvent* theEvent) +{ + myView->setCurrentView(theView); + emit mouseRelease(myView, theEvent); + if (myIsSelectionChanged) { + emit selectionChanged(); + myIsSelectionChanged = false; + } +} + +//********************************************** +void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow* theView, QMouseEvent* theEvent) +{ + myView->setCurrentView(theView); + emit mouseDoubleClick(myView, theEvent); +} + +//********************************************** +void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow* theView, QMouseEvent* theEvent) +{ + myView->setCurrentView(theView); + emit mouseMove(myView, theEvent); +} + +//********************************************** +bool NewGeom_SalomeViewer::canDragByMouse() const +{ + OCCViewer_Viewer* aViewer = mySelector->viewer(); + SUIT_ViewWindow* aWnd = aViewer->getViewManager()->getActiveView(); + OCCViewer_ViewWindow* aViewWnd = dynamic_cast(aWnd); + if (aViewWnd) { + return (aViewWnd->interactionStyle() == 0); + } + return true; +} + + +//********************************************** +void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent) +{ + emit keyPress(myView, theEvent); +} + +//********************************************** +void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow* theView, QKeyEvent* theEvent) +{ + emit keyRelease(myView, theEvent); +} + +//********************************************** +void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*) +{ + emit tryCloseView(myView); +} + +//********************************************** +void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*) +{ + if(myWindowScale.contains(myView->v3dView())) + myWindowScale.remove(myView->v3dView()); + emit deleteView(myView); +} + +//********************************************** +void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView) +{ + myView->setCurrentView(theView); + + OCCViewer_ViewFrame* aView = dynamic_cast(theView); + + OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW); + if (aWnd) { + connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), + this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); + OCCViewer_ViewPort3d* aViewPort = aWnd->getViewPort(); + if (aViewPort) + connect(aViewPort, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewPortMapped())); + } + reconnectActions(aWnd, true); + + myWindowScale.insert (aView->getViewPort()->getView(), aView->getViewPort()->getView()->Camera()->Scale()); + + emit viewCreated(myView); + + +} + +//********************************************** +void NewGeom_SalomeViewer::onActivated(SUIT_ViewManager* theMgr) +{ + myView->setCurrentView(theMgr->getActiveView()); + emit activated(myView); +} + +//********************************************** +void NewGeom_SalomeViewer::enableSelection(bool isEnabled) +{ + if (mySelector) + if (mySelector->viewer()->isSelectionEnabled() != isEnabled) + mySelector->viewer()->enableSelection(isEnabled); + // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking) + // After this is corrected, the first row should be recommented, the last - removed + //mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD + // : SUIT_ViewModel::KEY_FREE); +} + +//********************************************** +bool NewGeom_SalomeViewer::isSelectionEnabled() const +{ + if (mySelector) + return mySelector->viewer()->isSelectionEnabled(); + return false; +} + +//********************************************** +void NewGeom_SalomeViewer::enableMultiselection(bool isEnable) +{ + if (mySelector) + mySelector->viewer()->enableMultiselection(isEnable); +} + +//********************************************** +bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const +{ + if (mySelector) + return mySelector->viewer()->isMultiSelectionEnabled(); + return false; +} + +//********************************************** +bool NewGeom_SalomeViewer::enableDrawMode(bool isEnabled) +{ + // TODO: Has to be replaced when SALOME patch become available + if (mySelector) + return mySelector->viewer()->enableDrawMode(isEnabled); + return false; +} + +//********************************************** +void NewGeom_SalomeViewer::reconnectActions(SUIT_ViewWindow* theWindow, + const bool theUseNewGeomSlot) +{ + OCCViewer_ViewWindow* aWindow = dynamic_cast(theWindow); + if (!aWindow) + return; + + QAction* anAction = theWindow->toolMgr()->action(OCCViewer_ViewWindow::TrihedronShowId); + if (!anAction) + return; + + if (theUseNewGeomSlot) { + anAction->disconnect(anAction, SIGNAL(toggled(bool)), + theWindow, SLOT(onTrihedronShow(bool))); + anAction->connect(anAction, SIGNAL(toggled(bool)), + this, SIGNAL(trihedronVisibilityChanged(bool))); + } + else { + anAction->connect(anAction, SIGNAL(toggled(bool)), + theWindow, SLOT(onTrihedronShow(bool))); + anAction->disconnect(anAction, SIGNAL(toggled(bool)), + this, SIGNAL(trihedronVisibilityChanged(bool))); + } +} + +//********************************************** +void NewGeom_SalomeViewer::fitAll() +{ + if (mySelector) { + SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); + OCCViewer_ViewFrame* aVFrame = dynamic_cast(aMgr->getActiveView()); + if (aVFrame) { + aVFrame->onFitAll(); + } + } +} + +//********************************************** +void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ, double theTwist) +{ + if (!mySelector) + return; + + SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); + OCCViewer_ViewFrame* aVFrame = dynamic_cast(aMgr->getActiveView()); + if (aVFrame) { + Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView(); + if (!aView3d.IsNull()) { + aView3d->SetProj(theX, theY, theZ); + aView3d->SetTwist( theTwist ); + aView3d->FitAll(0.01, false); + aView3d->SetZSize(0.); + if (aView3d->Depth() < 0.1) + aView3d->DepthFitAll(); + } + } +} + +//*************************************** +void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + aContext->AddFilter(theFilter); + } +} + +//*************************************** +void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + aContext->RemoveFilter(theFilter); + } +} + +//*************************************** +bool NewGeom_SalomeViewer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) +{ + bool aFoundFilter = false; + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + const SelectMgr_ListOfFilter& aFilters = aContext->Filters(); + SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); + for (; aIt.More() && !aFoundFilter; aIt.Next()) { + aFoundFilter = theFilter.Access() == aIt.Value().Access(); + } + } + return aFoundFilter; +} + +//*************************************** +void NewGeom_SalomeViewer::clearSelectionFilters() +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + aContext->RemoveFilters(); + } +} + +//*************************************** +void NewGeom_SalomeViewer::update() +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + aContext->UpdateCurrentViewer(); + } +} + +//*************************************** +void NewGeom_SalomeViewer::onViewTransformed(OCCViewer_ViewWindow::OperationType theType) +{ + emit viewTransformed((int) theType); +} + +//*************************************** +void NewGeom_SalomeViewer::onViewPortMapped() +{ + emit trihedronVisibilityChanged(true); +} + +//*************************************** +void NewGeom_SalomeViewer::activateViewer(bool toActivate) +{ + if (!mySelector || !mySelector->viewer()) + return; + SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); + QVector aViews = aMgr->getViews(); + if (toActivate) { + foreach (SUIT_ViewWindow* aView, aViews) { + OCCViewer_ViewFrame* aOCCView = dynamic_cast(aView); + OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW); + connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), + this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); + reconnectActions(aWnd, true); + } + } else { + foreach (SUIT_ViewWindow* aView, aViews) { + OCCViewer_ViewFrame* aOCCView = dynamic_cast(aView); + OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW); + disconnect((OCCViewer_ViewWindow*)aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), + this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); + reconnectActions(aWnd, false); + } + } +} + +void NewGeom_SalomeViewer::Zfitall() +{ + if (!mySelector || !mySelector->viewer()) + return; + SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); + OCCViewer_ViewFrame* aView = dynamic_cast(aMgr->getActiveView()); + if (aView) { + OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW); + Handle(V3d_View) aView3d = aWnd->getViewPort()->getView(); + aView3d->ZFitAll(); + if (aView3d->Depth() < 0.1) + aView3d->DepthFitAll(); + } +} \ No newline at end of file diff --git a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h new file mode 100644 index 000000000..e32cfbbdf --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h @@ -0,0 +1,182 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +#ifndef NewGeom_SalomeViewer_H +#define NewGeom_SalomeViewer_H + +#include "NewGeom.h" + +#include +#include + +#include + +#include +#include + +class SUIT_ViewWindow; +class QMouseEvent; +class QKeyEvent; + +class NewGeom_OCCSelector; +class OCCViewer_Viewer; +class SUIT_ViewManager; + +/** +* \ingroup Salome +* A class for providing access of NewGeom functionality to +* SALOME view window functionality +*/ +class NewGeom_SalomeView: public ModuleBase_IViewWindow +{ +public: + /// Constructor + /// \param theViewer a reference to a viewer + NewGeom_SalomeView(OCCViewer_Viewer* theViewer); + + virtual Handle(V3d_View) v3dView() const; + + /// Returns the view window view port + virtual QWidget* viewPort() const; + + /// Set the current viewer + /// \param theViewer a viewer instance + void setViewer(OCCViewer_Viewer* theViewer) { myViewer = theViewer; } + + /// Returns current viewer + OCCViewer_Viewer* viewer() const { return myViewer; } + + /// Sets the current view + void setCurrentView(SUIT_ViewWindow* theView) { myCurrentView = theView; } + +private: + /// A reference to a viewer + OCCViewer_Viewer* myViewer; + SUIT_ViewWindow* myCurrentView; +}; + + +/** +* \ingroup Salome +* A class for providing access of NewGeom functionality to +* SALOME viewer functionality +*/ +class NewGeom_SalomeViewer : public ModuleBase_IViewer +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent a parent object + NewGeom_SalomeViewer(QObject* theParent); + + ~NewGeom_SalomeViewer(); + + //! Returns AIS_InteractiveContext from current OCCViewer + virtual Handle(AIS_InteractiveContext) AISContext() const; + + //! Retrurns V3d_Vioewer from current viewer + virtual Handle(V3d_Viewer) v3dViewer() const; + + //! Trihedron 3d object shown in the viewer + virtual Handle(AIS_Trihedron) trihedron() const; + + //! Returns Vsd_View object from currently active view window + virtual Handle(V3d_View) activeView() const; + + //! Returns viewer view port + virtual QWidget* activeViewPort() const; + + //! Enable or disable selection in the viewer + virtual void enableSelection(bool isEnabled); + + //! Returns true if selection is enabled + virtual bool isSelectionEnabled() const; + + //! Enable or disable multiselection in the viewer + virtual void enableMultiselection(bool isEnable); + + //! Returns true if multiselection is enabled + virtual bool isMultiSelectionEnabled() const; + + //! Enable or disable draw mode in the viewer + virtual bool enableDrawMode(bool isEnabled); + + //! For some signals it disconnects the window from usual signal and connect it to the module ones + void reconnectActions(SUIT_ViewWindow* theWindow, const bool theUseNewGeomSlot); + + //! Perfroms the fit all for the active view + virtual void fitAll(); + + //! Sets the view projection + /// \param theX the X projection value + /// \param theY the Y projection value + /// \param theZ the Z projection value + /// \param theTwist the twist angle in radians + virtual void setViewProjection( double theX, double theY, double theZ, + double theTwist ); + + /// Set selector + /// \param theSel a selector instance + void setSelector(NewGeom_OCCSelector* theSel); + + /// Add selection filter to the viewer + virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); + + /// Remove selection filter from the viewer + virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); + + /// Returns true if the selection filter is set to the viewer + /// \param theFilter a selection filter + virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); + + /// Remove all selection filters from the viewer + virtual void clearSelectionFilters(); + + /// Returns current selector + NewGeom_OCCSelector* selector() const + { + return mySelector; + } + + /// Update current viewer + virtual void update(); + + /// Method returns True if the viewer can process editing objects + /// by mouse drugging. If this is impossible thet it has to return False. + virtual bool canDragByMouse() const; + + /// Activate or deactivate viewer + /// \param toActivate - activation flag + void activateViewer(bool toActivate); + + // Fit all along Z (perpendicular to display) + virtual void Zfitall(); + + private slots: + void onMousePress(SUIT_ViewWindow*, QMouseEvent*); + void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*); + void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*); + void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); + void onKeyPress(SUIT_ViewWindow*, QKeyEvent*); + void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*); + + void onTryCloseView(SUIT_ViewWindow*); + void onDeleteView(SUIT_ViewWindow*); + void onViewCreated(SUIT_ViewWindow*); + void onActivated(SUIT_ViewManager*); + + void onSelectionChanged(); + void onViewTransformed(OCCViewer_ViewWindow::OperationType); + + /// Emit signal about trihedron visiblity change because SALOME sets the trihedron visible by this signal. + /// It is necessary to activate the viewer trihedron in the current selection mode + void onViewPortMapped(); + + private: + NewGeom_OCCSelector* mySelector; + NewGeom_SalomeView* myView; + bool myIsSelectionChanged; +}; + + +#endif diff --git a/src/SHAPERGUI/SHAPER_SHAPERGUI.h b/src/SHAPERGUI/SHAPER_SHAPERGUI.h new file mode 100644 index 000000000..a8c6978f4 --- /dev/null +++ b/src/SHAPERGUI/SHAPER_SHAPERGUI.h @@ -0,0 +1,21 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef NewGeom_H +#define NewGeom_H + +#if defined NewGeom_EXPORTS +#if defined WIN32 +#define NewGeom_EXPORT __declspec( dllexport ) +#else +#define NewGeom_EXPORT +#endif +#else +#if defined WIN32 +#define NewGeom_EXPORT __declspec( dllimport ) +#else +#define NewGeom_EXPORT +#endif +#endif + +#endif + diff --git a/src/SHAPERGUI/resources/LightApp.xml b/src/SHAPERGUI/resources/LightApp.xml new file mode 100644 index 000000000..35f5954da --- /dev/null +++ b/src/SHAPERGUI/resources/LightApp.xml @@ -0,0 +1,37 @@ + + +
+ + + + + +
+
+ + +
+
+ + +
+
diff --git a/src/SHAPERGUI/resources/SalomeApp.xml b/src/SHAPERGUI/resources/SalomeApp.xml new file mode 100644 index 000000000..0df9ffd62 --- /dev/null +++ b/src/SHAPERGUI/resources/SalomeApp.xml @@ -0,0 +1,41 @@ + + +
+ + +
+
+ + + + + +
+
+ + +
+
+ + +
+
diff --git a/src/SHAPERGUI/resources/newgeom.png b/src/SHAPERGUI/resources/newgeom.png new file mode 100644 index 000000000..d4827e272 Binary files /dev/null and b/src/SHAPERGUI/resources/newgeom.png differ diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index b928158f3..bebf1a79c 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -61,7 +61,7 @@ SET(PROJECT_RESOURCES ) SET(PREFERENCES_XML - NewGeom.xml + SHAPER.xml ) SET(TEXT_RESOURCES diff --git a/src/XGUI/NewGeom.xml b/src/XGUI/NewGeom.xml deleted file mode 100644 index 267113d71..000000000 --- a/src/XGUI/NewGeom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - -
- - - -
-
- - -
-
- - - -
-
- - -
- -
diff --git a/src/XGUI/SHAPER.xml b/src/XGUI/SHAPER.xml new file mode 100644 index 000000000..267113d71 --- /dev/null +++ b/src/XGUI/SHAPER.xml @@ -0,0 +1,25 @@ + + + + +
+ + + +
+
+ + +
+
+ + + +
+
+ + +
+ +