From: mpv Date: Wed, 23 Apr 2014 04:17:13 +0000 (+0400) Subject: Merge branch 'master' of newgeom:newgeom X-Git-Tag: V_0.2~138 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=29b4b1b5e692ebc45e8a27703b9307b075d2cff2;p=modules%2Fshaper.git Merge branch 'master' of newgeom:newgeom Conflicts: CMakeLists.txt src/Config/CMakeLists.txt src/Config/plugins.xml --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b5dd0ebd4..dc4b8fd19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ ADD_SUBDIRECTORY (src/ModuleBase) ADD_SUBDIRECTORY (src/PartSet) ADD_SUBDIRECTORY (src/PartSetPlugin) ADD_SUBDIRECTORY (src/ConstructionPlugin) +ADD_SUBDIRECTORY (src/SketchPlugin) ADD_SUBDIRECTORY (src/PyConsole) ADD_SUBDIRECTORY (src/PyEvent) ADD_SUBDIRECTORY (src/PyInterp) diff --git a/src/Config/plugins.xml b/src/Config/plugins.xml index fa22efe2a..2f4f45fd9 100644 --- a/src/Config/plugins.xml +++ b/src/Config/plugins.xml @@ -1,4 +1,5 @@ + diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 9f5f838e9..378915c63 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -20,6 +20,8 @@ static const std::string PARAMETERS_GROUP = "Parameters"; static const std::string CONSTRUCTIONS_GROUP = "Construction"; /// Group of parts static const std::string PARTS_GROUP = "Parts"; +/// Group of sketches +static const std::string SKETCHS_GROUP = "Sketchs"; /**\class Model_Document * \ingroup DataModel diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index a6afc4d5f..e2e6891c4 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -54,6 +54,11 @@ QString ModuleBase_Operation::operationId() const return myOperationId; } +std::shared_ptr ModuleBase_Operation::feature() const +{ + return myFeature; +} + /*! * \brief Gets state of operation * \return Value from OperationState enumeration diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 5daf8e6c6..a3c0c40c1 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -46,7 +46,7 @@ public: enum OperationState { Waiting, //!< Operation is not used (it is not run or suspended) - Running, //!< Operation is started + Running //!< Operation is started }; /*! @@ -76,6 +76,8 @@ public: // Operation processing. virtual QString operationId() const; + std::shared_ptr feature() const; + OperationState state() const; bool isRunning() const; virtual bool isValid(ModuleBase_Operation* theOtherOp) const; diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 0300761e6..81da4af83 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -1,13 +1,19 @@ INCLUDE(Common) +INCLUDE(FindCAS) + SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS PartSet.h PartSet_Module.h + PartSet_OperationSketchBase.h + PartSet_OperationSketch.h ) SET(PROJECT_SOURCES PartSet_Module.cpp + PartSet_OperationSketchBase.cpp + PartSet_OperationSketch.cpp ) SET(PROJECT_RESOURCES @@ -22,6 +28,7 @@ SET(PROJECT_LIBRARIES ModuleBase Config ${QT_LIBRARIES} + ${CAS_KERNEL} ) SET(PROJECT_AUTOMOC @@ -38,9 +45,12 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI ${CMAKE_SOURCE_DIR}/src/Config ${CMAKE_SOURCE_DIR}/src/Event ${CMAKE_SOURCE_DIR}/src/ModuleBase + ${CMAKE_SOURCE_DIR}/src/ModelAPI + ${CMAKE_SOURCE_DIR}/src/SketchPlugin + ${CAS_INCLUDE_DIRS} ) -ADD_DEFINITIONS(-DPARTSET_EXPORTS) +ADD_DEFINITIONS(-DPARTSET_EXPORTS ${CAS_DEFINITIONS}) ADD_LIBRARY(PartSet SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} @@ -50,7 +60,7 @@ ADD_LIBRARY(PartSet SHARED ) # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore -TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES}) +TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES} XGUI ModelAPI SketchPlugin) ADD_DEPENDENCIES(PartSet ModuleBase) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index fb437c5ba..7a32a90bb 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,5 +1,10 @@ #include -#include +#include + +#include + +#include +#include #include #include @@ -59,9 +64,31 @@ void PartSet_Module::onFeatureTriggered() //TODO(sbh): Implement static method to extract event id [SEID] static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent"); Config_PointerMessage aMessage(aModuleEvent, this); - ModuleBase_PropPanelOperation* aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this); + ModuleBase_PropPanelOperation* aPartSetOp; + if (aCmdId == "Sketch" ) + aPartSetOp = new PartSet_OperationSketch(aCmdId, this); + else + aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this); + + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(aPartSetOp); + if (aPreviewOp) + connect(aPreviewOp, SIGNAL(visualizePreview()), this, SLOT(onVisualizePreview())); + aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg)); aPartSetOp->setDescription(QString::fromStdString(aDescription)); aMessage.setPointer(aPartSetOp); Event_Loop::loop()->send(aMessage); } + +void PartSet_Module::onVisualizePreview() +{ + ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); + if (!anOperation) + return; + + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (!aPreviewOp) + return; + + myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview()); +} diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index f4894e239..b33d2ad7d 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -20,6 +20,7 @@ public: public slots: void onFeatureTriggered(); + void onVisualizePreview(); private: XGUI_Workshop* myWorkshop; diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp new file mode 100644 index 000000000..b5aa18747 --- /dev/null +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -0,0 +1,22 @@ +#include + +#include + +#ifdef _DEBUG +#include +#endif + +using namespace std; + +PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, + QObject* theParent) +: PartSet_OperationSketchBase(theId, theParent) +{ +} + +/*! + * \brief Destructor + */ +PartSet_OperationSketch::~PartSet_OperationSketch() +{ +} diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h new file mode 100644 index 000000000..99cacfbb6 --- /dev/null +++ b/src/PartSet/PartSet_OperationSketch.h @@ -0,0 +1,23 @@ +#ifndef PartSet_OperationSketch_H +#define PartSet_OperationSketch_H + +#include "PartSet.h" + +#include +#include + +/*! + \class PartSet_OperationSketch + * \brief The operation for the sketch creation + * + * Base class for all operations. If you perform an action it is reasonable to create +*/ +class PARTSET_EXPORT PartSet_OperationSketch : public PartSet_OperationSketchBase +{ +Q_OBJECT +public: + PartSet_OperationSketch(const QString& theId, QObject* theParent); + virtual ~PartSet_OperationSketch(); +}; + +#endif diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp new file mode 100644 index 000000000..c5b70b0e0 --- /dev/null +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -0,0 +1,46 @@ +#include + +#include + +#ifdef _DEBUG +#include +#endif + +using namespace std; + +/*! + \brief Constructor + \param theId an feature index + \param theParent the object parent + */ +PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId, + QObject* theParent) +: ModuleBase_PropPanelOperation(theId, theParent) +{ +} + +/*! + * \brief Destructor + */ +PartSet_OperationSketchBase::~PartSet_OperationSketchBase() +{ +} + +/** + * Returns the feature preview shape + */ +const TopoDS_Shape& PartSet_OperationSketchBase::preview() const +{ + shared_ptr aFeature = dynamic_pointer_cast(feature()); + return aFeature->preview(); +} + +/*! + * Perform the operation start and emit signal about visualization of the operation preview + */ +void PartSet_OperationSketchBase::startOperation() +{ + ModuleBase_PropPanelOperation::startOperation(); + + emit visualizePreview(); +} diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h new file mode 100644 index 000000000..ceb880264 --- /dev/null +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -0,0 +1,33 @@ +#ifndef PartSet_OperationSketchBase_H +#define PartSet_OperationSketchBase_H + +#include "PartSet.h" + +#include + +#include +#include + +/*! + \class PartSet_OperationSketchBase + * \brief The base operation for the sketch features. + * + * Base class for all sketch operations. It provides an access to the feature preview +*/ +class PARTSET_EXPORT PartSet_OperationSketchBase : public ModuleBase_PropPanelOperation +{ +Q_OBJECT +public: + PartSet_OperationSketchBase(const QString& theId, QObject* theParent); + virtual ~PartSet_OperationSketchBase(); + + const TopoDS_Shape& preview() const; + +signals: + void visualizePreview(); + +protected: + virtual void startOperation(); +}; + +#endif diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 571e1cd6f..f3300ede5 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -11,5 +11,7 @@ icons/revol.png icons/common.png icons/import.png + icons/line.png + icons/sketch.png diff --git a/src/PartSet/icons/line.png b/src/PartSet/icons/line.png new file mode 100644 index 000000000..6176fb62d Binary files /dev/null and b/src/PartSet/icons/line.png differ diff --git a/src/PartSet/icons/sketch.png b/src/PartSet/icons/sketch.png new file mode 100644 index 000000000..f2964c744 Binary files /dev/null and b/src/PartSet/icons/sketch.png differ diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt new file mode 100644 index 000000000..f9e47c7a8 --- /dev/null +++ b/src/SketchPlugin/CMakeLists.txt @@ -0,0 +1,36 @@ +INCLUDE(Common) +INCLUDE(FindCAS) + +SET(PROJECT_HEADERS + SketchPlugin.h + SketchPlugin_Feature.h + SketchPlugin_Plugin.h + SketchPlugin_Sketch.h +) + +SET(PROJECT_SOURCES + SketchPlugin_Feature.cpp + SketchPlugin_Plugin.cpp + SketchPlugin_Sketch.cpp +) + +SET(PROJECT_LIBRARIES + ${CAS_KERNEL} + ${CAS_MODELER} +) + +ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS} ${CAS_DEFINITIONS}) +ADD_LIBRARY(SketchPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES} ModelAPI) + +INCLUDE_DIRECTORIES( + ${CAS_INCLUDE_DIRS} + ../ModelAPI +) + +SET(XML_RESOURCES + plugin-Sketch.xml +) + +INSTALL(TARGETS SketchPlugin DESTINATION plugins) +INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) diff --git a/src/SketchPlugin/SketchPlugin.h b/src/SketchPlugin/SketchPlugin.h new file mode 100644 index 000000000..b7a5fcf11 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin.h @@ -0,0 +1,18 @@ +#ifndef SKETCHPLUGIN_H +#define SKETCHPLUGIN_H + +#if defined SKETCHPLUGIN_EXPORTS +#if defined WIN32 +#define SKETCHPLUGIN_EXPORT __declspec( dllexport ) +#else +#define SKETCHPLUGIN_EXPORT +#endif +#else +#if defined WIN32 +#define SKETCHPLUGIN_EXPORT __declspec( dllimport ) +#else +#define SKETCHPLUGIN_EXPORT +#endif +#endif + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp new file mode 100644 index 000000000..57bc3582d --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -0,0 +1,18 @@ +#include "SketchPlugin_Feature.h" + +/** + * Returns the sketch preview + */ +const TopoDS_Shape& SketchPlugin_Feature::preview() +{ + return myPreview; +} + +/** + * Set the shape to the internal preview field + * \param theShape a preview shape + */ +void SketchPlugin_Feature::setPreview(const TopoDS_Shape& theShape) +{ + myPreview = theShape; +} diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h new file mode 100644 index 000000000..4b91631c9 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -0,0 +1,29 @@ +// File: SketchPlugin_Feature.h +// Created: 27 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef SketchPlugin_Feature_HeaderFile +#define SketchPlugin_Feature_HeaderFile + +#include "SketchPlugin.h" +#include + +#include "TopoDS_Shape.hxx" + +/**\class SketchPlugin_Feature + * \ingroup DataModel + * \brief Feature for creation of the new part in PartSet. + */ +class SketchPlugin_Feature: public ModelAPI_Feature +{ +public: + SKETCHPLUGIN_EXPORT virtual const TopoDS_Shape& preview() = 0; + +protected: + void setPreview(const TopoDS_Shape& theShape); ///< the preview shape + +private: + TopoDS_Shape myPreview; ///< the preview shape +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp new file mode 100644 index 000000000..56f3b20e7 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -0,0 +1,27 @@ +#include "SketchPlugin_Plugin.h" +#include "SketchPlugin_Sketch.h" +#include +#include + +using namespace std; + +// the only created instance of this plugin +static SketchPlugin_Plugin* MY_INSTANCE = new SketchPlugin_Plugin(); + +SketchPlugin_Plugin::SketchPlugin_Plugin() +{ + // register this plugin + ModelAPI_PluginManager::get()->registerPlugin(this); +} + +shared_ptr SketchPlugin_Plugin::createFeature(string theFeatureID) +{ + if (theFeatureID == "Sketch") { + return shared_ptr(new SketchPlugin_Sketch); + } + /*else if (theFeatureID == "Point") { + return shared_ptr(new SketchPlugin_Point); + }*/ + // feature of such kind is not found + return shared_ptr(); +} diff --git a/src/SketchPlugin/SketchPlugin_Plugin.h b/src/SketchPlugin/SketchPlugin_Plugin.h new file mode 100644 index 000000000..2b2666350 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Plugin.h @@ -0,0 +1,23 @@ +// File: SketchPlugin_Plugin.hxx +// Created: 31 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef SketchPlugin_Plugin_HeaderFile +#define SketchPlugin_Plugin_HeaderFile + + +#include "SketchPlugin.h" +#include "ModelAPI_Plugin.h" + +class SKETCHPLUGIN_EXPORT SketchPlugin_Plugin: public ModelAPI_Plugin +{ +public: + /// Creates the feature object of this plugin by the feature string ID + virtual std::shared_ptr createFeature(std::string theFeatureID); + +public: + /// Is needed for python wrapping by swig + SketchPlugin_Plugin(); +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp new file mode 100644 index 000000000..a665a700f --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -0,0 +1,60 @@ +// File: SketchPlugin_Sketch.cxx +// Created: 27 Mar 2014 +// Author: Mikhail PONIKAROV + +#include "SketchPlugin_Sketch.h" +#include "ModelAPI_Data.h" +#include "ModelAPI_AttributeDocRef.h" + +using namespace std; +#include +#include +#include + +#include +#include + +#include +#include +#include + +const double PLANE_U_MIN = -100; +const double PLANE_U_MAX = 100; +const double PLANE_V_MIN = -100; +const double PLANE_V_MAX = 100; + +SketchPlugin_Sketch::SketchPlugin_Sketch() +{ +} + +void SketchPlugin_Sketch::initAttributes() +{ + data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type()); +} + +void SketchPlugin_Sketch::execute() +{ + shared_ptr aDocRef = data()->docRef(PART_ATTR_DOC_REF); + if (!aDocRef->value()) { // create a document if not yet created + shared_ptr aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument(); + aDocRef->setValue(aPartSetDoc->subDocument(data()->getName())); + } +} + +shared_ptr SketchPlugin_Sketch::documentToAdd() { + return ModelAPI_PluginManager::get()->rootDocument(); +} + +const TopoDS_Shape& SketchPlugin_Sketch::preview() +{ + if (SketchPlugin_Feature::preview().IsNull()) + { + gp_Pnt anOrigin(0, 0, 0); + gp_Dir aDir(gp_Vec(gp_Pnt(0,0,0), gp_Pnt(1,0,0))); + gp_Pln aPlane(anOrigin, aDir); + BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, PLANE_U_MIN, PLANE_U_MAX, PLANE_V_MIN, + PLANE_V_MAX); + setPreview(aFaceBuilder.Face()); + } + return SketchPlugin_Feature::preview(); +} diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h new file mode 100644 index 000000000..0ac6ce1c8 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -0,0 +1,46 @@ +// File: SketchPlugin_Sketch.h +// Created: 27 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef SketchPlugin_Sketch_HeaderFile +#define SketchPlugin_Sketch_HeaderFile + +#include "SketchPlugin.h" +#include + +#include + +/// part reference attribute +const std::string PART_ATTR_DOC_REF = "SketchDocument"; + +/**\class SketchPlugin_Sketch + * \ingroup DataModel + * \brief Feature for creation of the new part in PartSet. + */ +class SketchPlugin_Sketch: public SketchPlugin_Feature +{ +public: + /// Returns the kind of a feature + SKETCHPLUGIN_EXPORT virtual const std::string& getKind() + {static std::string MY_KIND = "Sketch"; return MY_KIND;} + + /// Returns to which group in the document must be added feature + SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() + {static std::string MY_GROUP = "Sketchs"; return MY_GROUP;} + + /// Creates a new part document if needed + SKETCHPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + SKETCHPLUGIN_EXPORT virtual void initAttributes(); + + SKETCHPLUGIN_EXPORT virtual std::shared_ptr documentToAdd(); + + /// Returns the sketch preview + SKETCHPLUGIN_EXPORT virtual const TopoDS_Shape& preview(); + + /// Use plugin manager for features creation + SketchPlugin_Sketch(); +}; + +#endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml new file mode 100644 index 000000000..755458ba0 --- /dev/null +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index a10e48e68..309498380 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -5,6 +5,7 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS XGUI.h XGUI_Command.h + XGUI_Displayer.h XGUI_MainMenu.h XGUI_MainWindow.h XGUI_MenuGroupPanel.h @@ -32,6 +33,7 @@ SET(PROJECT_AUTOMOC SET(PROJECT_SOURCES XGUI_Command.cpp + XGUI_Displayer.cpp XGUI_MainMenu.cpp XGUI_MainWindow.cpp XGUI_MenuGroupPanel.cpp diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp new file mode 100644 index 000000000..1df329170 --- /dev/null +++ b/src/XGUI/XGUI_Displayer.cpp @@ -0,0 +1,47 @@ +#include "XGUI_Displayer.h" +#include "XGUI_Tools.h" +#include "XGUI_Viewer.h" + +#include + +#include +#include + +/*! + \brief Constructor + */ +XGUI_Displayer::XGUI_Displayer(XGUI_Viewer* theViewer) +: myViewer(theViewer) +{ +} + +/*! + \brief Destructor + */ +XGUI_Displayer::~XGUI_Displayer() +{ +} + +/*! + * Display the feature + * \param theFeature a feature instance + */ +void XGUI_Displayer::Display(std::shared_ptr theFeature) +{ +} + +/*! + * Display the feature and a shape. This shape would be associated to the given feature + * \param theFeature a feature instance + * \param theFeature a shape + */ +void XGUI_Displayer::Display(std::shared_ptr theFeature, + const TopoDS_Shape& theShape) +{ + Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); + + Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); + aContext->Display(anAIS, Standard_False); + + aContext->UpdateCurrentViewer(); +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h new file mode 100644 index 000000000..cf5dbbbd9 --- /dev/null +++ b/src/XGUI/XGUI_Displayer.h @@ -0,0 +1,31 @@ +#ifndef XGUI_Displayer_H +#define XGUI_Displayer_H + +#include "XGUI.h" + +#include + +#include + +class XGUI_Viewer; +class ModelAPI_Feature; + +/**\class XGUI_Displayer + * \ingroup GUI + * \brief Displayer. Provides mechanizm of displa/erase of objects in viewer + */ +class XGUI_EXPORT XGUI_Displayer +{ +public: + XGUI_Displayer(XGUI_Viewer* theViewer); + virtual ~XGUI_Displayer(); + + void Display(std::shared_ptr theFeature); + + void Display(std::shared_ptr theFeature, const TopoDS_Shape& theShape); + +protected: + XGUI_Viewer* myViewer; ///< the viewer +}; + +#endif diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index b02a735eb..6d4c10068 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -18,6 +18,9 @@ #include #include #include +#include + +#include #ifdef WIN32 #include @@ -389,7 +392,7 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView) this, SIGNAL(tryCloseView(XGUI_ViewWindow*))); connect(aWindow, SIGNAL(mousePressed(XGUI_ViewWindow*, QMouseEvent*)), - this, SIGNAL(mousePress(XGUI_ViewWindow*, QMouseEvent*))); + this, SLOT(onMousePressed(XGUI_ViewWindow*, QMouseEvent*))); connect(aWindow, SIGNAL(mouseReleased(XGUI_ViewWindow*, QMouseEvent*)), this, SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*))); @@ -409,6 +412,12 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView) // connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )), // this, SLOT (onContextMenuRequested( QContextMenuEvent* ))); + connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)), + this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*))); + + connect(aWindow, SIGNAL(mouseReleased(XGUI_ViewWindow*, QMouseEvent*)), + this, SLOT(onMouseReleased(XGUI_ViewWindow*, QMouseEvent*))); + myViews.append(theView); } @@ -444,3 +453,25 @@ void XGUI_Viewer::onWindowMinimized(QMdiSubWindow* theWnd) } } } + +/*! + SLOT: called on mouse move, processes hilighting +*/ +void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) +{ + XGUI_ViewPort* aViewPort = theWindow->viewPort(); + Handle(V3d_View) aView3d = aViewPort->getView(); + + if ( !aView3d.IsNull() ) + myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d); +} + +/*! + SLOT: called on mouse button release, finishes selection +*/ +void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) +{ + myAISContext->Select(); + + emit selectionChanged(); +} diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index b68f9accb..5b68ebdf0 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -110,6 +110,7 @@ signals: void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent); void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent); void activated(XGUI_ViewWindow* theWindow); + void selectionChanged(); public slots: void onWindowMinimized(QMdiSubWindow*); @@ -117,6 +118,8 @@ public slots: private slots: void onViewClosed(QMdiSubWindow*); + void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent); + void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent); private: void addView(QMdiSubWindow* theView); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 48e3770ce..891172028 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -11,6 +11,7 @@ #include "XGUI_WidgetFactory.h" #include "XGUI_SelectionMgr.h" #include "XGUI_ObjectsBrowser.h" +#include "XGUI_Displayer.h" #include #include @@ -19,6 +20,7 @@ #include #include +#include #include #include @@ -46,6 +48,7 @@ XGUI_Workshop::XGUI_Workshop() { myMainWindow = new XGUI_MainWindow(); mySelector = new XGUI_SelectionMgr(this); + myDisplayer = new XGUI_Displayer(myMainWindow->viewer()); } //****************************************************** diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index aff5c239b..50e0a44cc 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -14,6 +14,7 @@ class XGUI_Command; class XGUI_Module; class XGUI_Workbench; class XGUI_SelectionMgr; +class XGUI_Displayer; class ModuleBase_Operation; class ModuleBase_PropPanelOperation; @@ -44,9 +45,15 @@ public: //! Returns selection manager object XGUI_SelectionMgr* selector() const { return mySelector; } + //! Returns displayer + XGUI_Displayer* displayer() const { return myDisplayer; } + //! Creates and adds a new workbench (menu group) with the given name and returns it XGUI_Workbench* addWorkbench(const QString& theName); + //! Returns the current operation or NULL + ModuleBase_Operation* currentOperation() { return myCurrentOperation; } + //! Redefinition of Event_Listener method virtual void processEvent(const Event_Message* theMessage); @@ -78,6 +85,7 @@ private: XGUI_Module* myPartSetModule; XGUI_SelectionMgr* mySelector; + XGUI_Displayer* myDisplayer; ModuleBase_Operation* myCurrentOperation; };