From: vsv Date: Fri, 25 Apr 2014 15:59:58 +0000 (+0400) Subject: Provided connection of XGUI Displayer to SALOME OCC Viewer X-Git-Tag: V_0.2~117 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=966a065a9d171680be1fa3ae820b5252578048ba;p=modules%2Fshaper.git Provided connection of XGUI Displayer to SALOME OCC Viewer --- diff --git a/src/NewGeom/CMakeLists.txt b/src/NewGeom/CMakeLists.txt index c2c71aae1..20404f8b1 100644 --- a/src/NewGeom/CMakeLists.txt +++ b/src/NewGeom/CMakeLists.txt @@ -28,6 +28,8 @@ SET(PROJECT_LIBRARIES Config XGUI ${QT_LIBRARIES} + ${suit} + ${std} ${LightApp} ${CAM} ${OCCViewer} diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index affe26d79..ee68ba0c9 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -7,7 +7,10 @@ #include #include + #include +#include + #include @@ -158,4 +161,16 @@ QAction* NewGeom_Module::command(const QString& theId) const return action(aId); } return 0; +} + +//****************************************************** +Handle(AIS_InteractiveContext) NewGeom_Module::AISContext() const +{ + Handle(AIS_InteractiveContext) aContext; + SUIT_ViewManager* aMgr = application()->viewManager(OCCViewer_Viewer::Type()); + if (aMgr) { + OCCViewer_Viewer* aViewer = static_cast(aMgr->getViewModel()); + aContext = aViewer->getAISContext(); + } + return aContext; } \ No newline at end of file diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index 8df0ef372..1440856ff 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -12,6 +12,10 @@ class XGUI_Workshop; +/** +* 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 @@ -51,6 +55,9 @@ public: virtual QAction* command(const QString& theId) const; + //! Returns AIS_InteractiveContext from current OCCViewer + virtual Handle(AIS_InteractiveContext) AISContext() const; + public slots: bool activateModule( SUIT_Study* theStudy); bool deactivateModule( SUIT_Study* theStudy); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index bca8d2d24..5b510bbb6 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -13,9 +13,9 @@ #include -XGUI_Displayer::XGUI_Displayer(XGUI_Viewer* theViewer) -: myViewer(theViewer) +XGUI_Displayer::XGUI_Displayer(const Handle(AIS_InteractiveContext)& theAIS) { + myAISContext = theAIS; } XGUI_Displayer::~XGUI_Displayer() @@ -30,7 +30,7 @@ void XGUI_Displayer::Display(boost::shared_ptr theFeature, void XGUI_Displayer::Display(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, const bool isUpdateViewer) { - Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); + Handle(AIS_InteractiveContext) aContext = AISContext(); Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); std::vector aDispAIS; @@ -55,7 +55,7 @@ void XGUI_Displayer::Erase(boost::shared_ptr theFeature, std::vector aDispAIS = myFeature2AISObjectMap[theFeature]; std::vector::const_iterator anIt = aDispAIS.begin(), aLast = aDispAIS.end(); - Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); + Handle(AIS_InteractiveContext) aContext = AISContext(); for (; anIt != aLast; anIt++) { Handle(AIS_InteractiveObject) anAIS = *anIt; Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); @@ -72,7 +72,7 @@ void XGUI_Displayer::LocalSelection(boost::shared_ptr theFeatu const TopoDS_Shape& theShape, const int theMode, const bool isUpdateViewer) { - Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); + Handle(AIS_InteractiveContext) aContext = AISContext(); Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); std::vector aDispAIS; @@ -85,11 +85,51 @@ void XGUI_Displayer::LocalSelection(boost::shared_ptr theFeatu AIS_ListOfInteractive anAISList; anAISList.Append(anAIS); - myViewer->setLocalSelection(anAISList, theMode, true); + setLocalSelection(anAISList, theMode, true); } void XGUI_Displayer::GlobalSelection(const bool isUpdateViewer) { - myViewer->setGlobalSelection(true); + setGlobalSelection(true); } +void XGUI_Displayer::setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode, + const bool isUpdateViewer) +{ + Handle(AIS_InteractiveContext) ic = AISContext(); + + // Open local context if there is no one + bool allObjects = false; // calculate by AIS shape + if (!ic->HasOpenedContext()) { + ic->ClearCurrents(false); + ic->OpenLocalContext(allObjects, true, true); + } + + // Activate selection of objects from prs + AIS_ListIteratorOfListOfInteractive aIter(theAISObjects); + for (; aIter.More(); aIter.Next()) { + Handle(AIS_InteractiveObject) anAIS = aIter.Value(); + if (!anAIS.IsNull()) { + if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) { + ic->Load(anAIS, -1, false); + ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode)); + } + else if (anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron)) { + ic->Load(anAIS, -1, false); + ic->Activate(anAIS, theMode); + } + } + } + if (isUpdateViewer) + ic->UpdateCurrentViewer(); +} + +void XGUI_Displayer::setGlobalSelection(const bool isUpdateViewer) +{ + Handle(AIS_InteractiveContext) ic = AISContext(); + if (!ic.IsNull()) { + ic->CloseAllContexts(false); + if (isUpdateViewer) + ic->UpdateCurrentViewer(); + } +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 2a54cb9e4..319a07a5e 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -29,10 +30,14 @@ class XGUI_EXPORT XGUI_Displayer public: /// Constructor /// \param theViewer the viewer - XGUI_Displayer(XGUI_Viewer* theViewer); + XGUI_Displayer(const Handle(AIS_InteractiveContext)& theAIS); /// Destructor virtual ~XGUI_Displayer(); + /// Set AIS_InteractiveContext object in case if it was changed + /// or can not be initialized in constructor + void setAISContext(const Handle(AIS_InteractiveContext)& theAIS); + /// Display the feature. Obtain the visualized object from the feature. /// \param theFeature a feature instance /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly @@ -62,8 +67,22 @@ public: /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly void GlobalSelection(const bool isUpdateViewer = true); + /// Activate local selection + /// \param theAIS the list of objects + /// \param theMode the selection mode + /// \param isUpdateViewer the state wether the viewer should be updated immediatelly + void setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode, + const bool isUpdateViewer); + /// Deactivate local selection + /// \param isUpdateViewer the state wether the viewer should be updated immediatelly + void setGlobalSelection(const bool isUpdateViewer); + + /// Returns currently installed AIS_InteractiveContext + Handle(AIS_InteractiveContext) AISContext() const { return myAISContext; } + protected: - XGUI_Viewer* myViewer; ///< the viewer where the objects should be visualized + ///< the viewer where the objects should be visualized + Handle(AIS_InteractiveContext) myAISContext; std::map, std::vector > myFeature2AISObjectMap; }; diff --git a/src/XGUI/XGUI_SalomeConnector.h b/src/XGUI/XGUI_SalomeConnector.h index b2384b62d..6418cdf46 100644 --- a/src/XGUI/XGUI_SalomeConnector.h +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -3,13 +3,28 @@ #include "XGUI.h" +#include #include class QMainWindow; +/** +* An interface which provides a connection of XGUI functionality +* with functionality of SALOME module interface. +*/ class XGUI_EXPORT XGUI_SalomeConnector { public: + //! Creates a feature (command) in SALOME desktop + //! \param theWBName - a workbench name + //! \param theId - an id of the feature + //! \param theTitle - a menu item string + //! \param theTip - a tooltip string (help) + //! \param theIcon - icon + //! \param isCheckable - is checkable or not + //! \param reciever - QObject which will react on the command call + //! \param member - a method of receiver which will be called on the command + //! \param theKeys - hot keys virtual void addFeature(const QString& theWBName, const QString& theId, const QString& theTitle, @@ -20,6 +35,15 @@ public: const char* member, const QKeySequence& theKeys) = 0; + //! Creates a command in Edit menu of SALOME desktop + //! \param theId - an id of the feature + //! \param theTitle - a menu item string + //! \param theTip - a tooltip string (help) + //! \param theIcon - icon + //! \param isCheckable - is checkable or not + //! \param reciever - QObject which will react on the command call + //! \param member - a method of receiver which will be called on the command + //! \param theKeys - hot keys virtual void addEditCommand(const QString& theId, const QString& theTitle, const QString& theTip, @@ -28,12 +52,21 @@ public: QObject* reciever, const char* member, const QKeySequence& theKeys) = 0; + + //! Insert separator into Edit menu of SALOME desktop virtual void addEditMenuSeparator() = 0; + //! Returns desktop window of SALOME virtual QMainWindow* desktop() const = 0; + //! Returns command string Id by QAction instance virtual QString commandId(const QAction* theCmd) const = 0; + + //! Returns QAction instance by command string Id virtual QAction* command(const QString& theId) const = 0; + + //! Returns AIS_InteractiveContext from current OCCViewer + virtual Handle(AIS_InteractiveContext) AISContext() const = 0; }; #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index dd50e3e11..0d93d6cc0 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -190,46 +190,6 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType) return aWnd; } -void XGUI_Viewer::setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode, - const bool isUpdateViewer) -{ - Handle(AIS_InteractiveContext) ic = AISContext(); - - // Open local context if there is no one - bool allObjects = false; // calculate by AIS shape - if (!ic->HasOpenedContext()) { - ic->ClearCurrents(false); - ic->OpenLocalContext(allObjects, true, true); - } - - // Activate selection of objects from prs - AIS_ListIteratorOfListOfInteractive aIter(theAISObjects); - for (; aIter.More(); aIter.Next()) { - Handle(AIS_InteractiveObject) anAIS = aIter.Value(); - if (!anAIS.IsNull()) { - if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) { - ic->Load(anAIS, -1, false); - ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode)); - } - else if (anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron)) { - ic->Load(anAIS, -1, false); - ic->Activate(anAIS, theMode); - } - } - } - if (isUpdateViewer) - ic->UpdateCurrentViewer(); -} - -void XGUI_Viewer::setGlobalSelection(const bool isUpdateViewer) -{ - Handle(AIS_InteractiveContext) ic = AISContext(); - if (!ic.IsNull()) { - ic->CloseAllContexts(false); - if (isUpdateViewer) - ic->UpdateCurrentViewer(); - } -} void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList) { diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 27df6840d..784ddd3cf 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -57,16 +57,6 @@ public: return myAISContext; } - //! Activate local selection - //! \param theAIS the list of objects - //! \param theMode the selection mode - //! \param isUpdateViewer the state wether the viewer should be updated immediatelly - void setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode, - const bool isUpdateViewer); - //! Deactivate local selection - //! \param isUpdateViewer the state wether the viewer should be updated immediatelly - void setGlobalSelection(const bool isUpdateViewer); - /// Return objects selected in 3D viewer /// \param theList - list to be filled with selected objects void getSelectedObjects(AIS_ListOfInteractive& theList); @@ -166,7 +156,9 @@ private: private: XGUI_MainWindow* myMainWindow; - Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext; + Handle(V3d_Viewer) myV3dViewer; + Handle(AIS_Trihedron) myTrihedron; + Handle(AIS_InteractiveContext) myAISContext; XGUI::InteractionStyle myInteractionStyle; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index cbd6239cb..3539c7966 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -49,11 +49,16 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myPartSetModule(NULL), mySalomeConnector(theConnector), myPropertyPanelDock(0), - myObjectBrowser(0) + myObjectBrowser(0), + myDisplayer(0) { myMainWindow = mySalomeConnector? 0 : new XGUI_MainWindow(); + + // In SALOME viewer is accessible only when module is initialized + // and in SALOME mode myDisplayer object has to be created later + // So, displayer will be created on demand. + mySelector = new XGUI_SelectionMgr(this); - myDisplayer = myMainWindow? new XGUI_Displayer(myMainWindow->viewer()) : 0; myOperationMgr = new XGUI_OperationMgr(this); connect(myOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), @@ -590,3 +595,17 @@ void XGUI_Workshop::onFeatureTriggered() myPartSetModule->launchOperation(aId); } } + +//****************************************************** +XGUI_Displayer* XGUI_Workshop::displayer() const +{ + // In SALOME viewer is accessible only when module is initialized + // and in SALOME mode myDisplayer object has to be created later (on demand) + if (!myDisplayer) { + XGUI_Workshop* that = (XGUI_Workshop*)this; + that->myDisplayer = isSalomeMode() ? + new XGUI_Displayer(salomeConnector()->AISContext()): + new XGUI_Displayer(myMainWindow->viewer()->AISContext()); + } + return myDisplayer; +} diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 0b477c526..937aca383 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -52,7 +52,7 @@ public: XGUI_SelectionMgr* selector() const { return mySelector; } //! Returns displayer - XGUI_Displayer* displayer() const { return myDisplayer; } + XGUI_Displayer* displayer() const; //! ! Returns operation manager. XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }