#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
-#include <GeomDataAPI_Point2D.h>
-
#ifdef _DEBUG
#include <QDebug>
#endif
SET(PROJECT_HEADERS
PartSet.h
+ PartSet_Listener.h
PartSet_Module.h
PartSet_OperationSketchBase.h
PartSet_OperationSketch.h
PartSet_OperationSketchLine.h
+ PartSet_Tools.h
)
SET(PROJECT_SOURCES
+ PartSet_Listener.cpp
PartSet_Module.cpp
PartSet_OperationSketchBase.cpp
PartSet_OperationSketch.cpp
PartSet_OperationSketchLine.cpp
+ PartSet_Tools.cpp
)
SET(PROJECT_RESOURCES
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI
${CMAKE_SOURCE_DIR}/src/Config
${CMAKE_SOURCE_DIR}/src/Events
+ ${CMAKE_SOURCE_DIR}/src/Model
${CMAKE_SOURCE_DIR}/src/ModuleBase
${CMAKE_SOURCE_DIR}/src/ModelAPI
${CMAKE_SOURCE_DIR}/src/GeomDataAPI
--- /dev/null
+// File: PartSet_Listener.h
+// Created: 28 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_Listener.h>
+
+#include <PartSet_Module.h>
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+using namespace std;
+
+PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
+: myModule(theModule)
+{
+ Events_Loop* aLoop = Events_Loop::loop();
+ Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
+ aLoop->registerListener(this, aFeatureUpdatedId);
+}
+
+PartSet_Listener::~PartSet_Listener()
+{
+}
+
+//******************************************************
+void PartSet_Listener::processEvent(const Events_Message* theMessage)
+{
+ if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED)
+ {
+ myModule->visualizePreview(true);
+ }
+}
--- /dev/null
+// File: PartSet_Listener.h
+// Created: 28 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_Listener_H
+#define PartSet_Listener_H
+
+#include "PartSet.h"
+
+#include <Events_Listener.h>
+
+class PartSet_Module;
+
+/*!
+ \class PartSet_Listener
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_Listener : public Events_Listener
+{
+public:
+ /// Constructor
+ /// \param theId the feature identifier
+ /// \param theParent the operation parent
+ PartSet_Listener(PartSet_Module* theModule);
+ /// Destructor
+ virtual ~PartSet_Listener();
+
+ /// This method is called by loop when the event is started to process.
+ virtual void processEvent(const Events_Message* theMessage);
+
+private:
+ PartSet_Module* myModule; ///< the current module
+};
+
+#endif
#include <PartSet_Module.h>
#include <PartSet_OperationSketch.h>
#include <PartSet_OperationSketchLine.h>
+#include <PartSet_Listener.h>
+#include <PartSet_Tools.h>
#include <ModuleBase_Operation.h>
#include <XGUI_Viewer.h>
#include <XGUI_Workshop.h>
#include <XGUI_OperationMgr.h>
+#include <XGUI_ViewWindow.h>
+#include <XGUI_ViewPort.h>
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
{
myWorkshop = theWshop;
+ myListener = new PartSet_Listener(this);
+
XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
this, SLOT(onOperationStopped(ModuleBase_Operation*)));
- if (!myWorkshop->isSalomeMode())
- connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
- this, SLOT(onViewSelectionChanged()));
+ if (!myWorkshop->isSalomeMode()) {
+ connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseReleased(QPoint)),
+ this, SLOT(onMouseReleased(QPoint)));
+ connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseMoved(QPoint)),
+ this, SLOT(onMouseMoved(QPoint)));
+ }
}
PartSet_Module::~PartSet_Module()
visualizePreview(false);
}
-void PartSet_Module::onViewSelectionChanged()
+void PartSet_Module::onMouseReleased(QPoint thePoint)
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aViewer) {
NCollection_List<TopoDS_Shape> aList;
aViewer->getSelectedShapes(aList);
- aPreviewOp->setSelectedShapes(aList);
+ XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
+ if (aWindow) {
+ Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
+ if ( !aView3d.IsNull() ) {
+ gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d);
+ aPreviewOp->setSelectedShapes(aList, aPoint);
+ }
+ }
+ }
+ }
+}
+
+void PartSet_Module::onMouseMoved(QPoint thePoint)
+{
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp) {
+ XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+ if (aViewer) {
+ XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
+ if (aWindow) {
+ Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
+ if ( !aView3d.IsNull() ) {
+ gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d);
+ aPreviewOp->setMouseMovePoint(aPoint);
+ }
+ }
}
}
}
if (!aPreviewOp)
return;
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (isDisplay) {
boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
- if (aPreview)
- myWorkshop->displayer()->LocalSelection(anOperation->feature(),
+ if (aPreview) {
+ aDisplayer->LocalSelection(anOperation->feature(),
aPreview->impl<TopoDS_Shape>(), aPreviewOp->getSelectionMode());
+ }
}
else {
- myWorkshop->displayer()->GlobalSelection(false);
- myWorkshop->displayer()->Erase(anOperation->feature());
+ aDisplayer->GlobalSelection(false);
+ aDisplayer->Erase(anOperation->feature());
}
}
#include <string>
+class PartSet_Listener;
+
class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
{
Q_OBJECT
virtual void launchOperation(const QString& theCmdId);
+ /// Displays or erase the current operation preview, if it has it.
+ /// \param isDisplay the state whether the presentation should be displayed or erased
+ void visualizePreview(bool isDisplay);
+
public slots:
void onFeatureTriggered();
/// SLOT, that is called after the operation is started. Perform some specific for module
void onOperationStopped(ModuleBase_Operation* theOperation);
/// SLOT, that is called by the selection in the viewer is changed.
/// The selection is sent to the current operation if it listen the selection.
- void onViewSelectionChanged();
+ void onMouseReleased(QPoint thePoint);
+ /// SLOT, that is called by the selection in the viewer is changed.
+ /// The selection is sent to the current operation if it listen the selection.
+ /// \thePoint the mouse point
+ void onMouseMoved(QPoint thePoint);
+
/// SLOT, to apply to the current viewer the operation
/// \param theX the X projection value
/// \param theY the Y projection value
/// \param theZ the Z projection value
void onViewerProjectionChange(double theX, double theY, double theZ);
-private:
- /// Displays or erase the current operation preview, if it has it.
- /// \param isDisplay the state whether the presentation should be displayed or erased
- void visualizePreview(bool isDisplay);
-
private:
XGUI_Workshop* myWorkshop;
+ PartSet_Listener* myListener;
std::map<std::string, std::string> myFeaturesInFiles;
};
return TopAbs_FACE;
}
-void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
+void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+ const gp_Pnt& theSelectedPoint)
{
if (theList.IsEmpty())
return;
/// Gives the current selected objects to be processed by the operation
/// \param theList a list of interactive selected shapes
- virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList);
+ /// \param theSelectedPoint a point clidked in the viewer
+ virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+ const gp_Pnt& theSelectedPoint);
};
#endif
#include "PartSet.h"
#include <TopoDS_Shape.hxx>
+#include <gp_Pnt.hxx>
#include <NCollection_List.hxx>
#include <ModuleBase_PropPanelOperation.h>
virtual int getSelectionMode() const = 0;
/// Gives the current selected objects to be processed by the operation
- /// \param a list of interactive selected objects
- virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList) = 0;
+ /// \param theList a list of interactive selected shapes
+ /// \param theSelectedPoint a 3D selected point
+ virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+ const gp_Pnt& thePoint) = 0;
+ /// Gives the current mouse point in the viewer
+ /// \param thePoint a point clidked in the viewer
+ virtual void setMouseMovePoint(const gp_Pnt& thePoint) {};
signals:
void viewerProjectionChange(double theX, double theY, double theZ);
#include <PartSet_OperationSketchLine.h>
#include <SketchPlugin_Feature.h>
+#include <GeomDataAPI_Point2D.h>
+#include <ModelAPI_Data.h>
+
+#include <SketchPlugin_Line.h>
#ifdef _DEBUG
#include <QDebug>
PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId,
QObject* theParent,
boost::shared_ptr<ModelAPI_Feature> theFeature)
-: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
+: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature),
+ myPointSelectionMode(SM_FirstPoint)
{
}
int PartSet_OperationSketchLine::getSelectionMode() const
{
- return TopAbs_FACE;
+ return 0;//TopAbs_FACE;
}
-void PartSet_OperationSketchLine::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
+void PartSet_OperationSketchLine::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+ const gp_Pnt& thePoint)
{
if (theList.IsEmpty())
return;
+
+ switch (myPointSelectionMode)
+ {
+ case SM_FirstPoint: {
+ setLinePoint(thePoint, LINE_ATTR_START);
+ myPointSelectionMode = SM_SecondPoint;
+ }
+ break;
+ case SM_SecondPoint: {
+ setLinePoint(thePoint, LINE_ATTR_END);
+ commit();
+ }
+ break;
+ case SM_None: {
+
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void PartSet_OperationSketchLine::setMouseMovePoint(const gp_Pnt& thePoint)
+{
+ if (myPointSelectionMode == SM_SecondPoint)
+ setLinePoint(thePoint, LINE_ATTR_END);
}
void PartSet_OperationSketchLine::startOperation()
aFeature->addSub(feature());
}
+ myPointSelectionMode = SM_FirstPoint;
}
+
+void PartSet_OperationSketchLine::stopOperation()
+{
+ PartSet_OperationSketchBase::stopOperation();
+
+ myPointSelectionMode = SM_None;
+}
+
+void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
+ const std::string& theAttribute)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+ double aX = thePoint.X(), anY = thePoint.Y();
+ aPoint->setValue(aX, anY);
+}
+
/// Gives the current selected objects to be processed by the operation
/// \param theList a list of interactive selected shapes
- virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList);
+ /// \param theSelectedPoint a point clidked in the viewer
+ virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
+ const gp_Pnt& thePoint);
+ /// Gives the current mouse point in the viewer
+ /// \param thePoint a point clidked in the viewer
+ virtual void setMouseMovePoint(const gp_Pnt& thePoint);
protected:
/// \brief Virtual method called when operation is started
/// After the parent operation body perform, set sketch feature to the created line feature
virtual void startOperation();
+ /// \brief Virtual method called when operation is started
+ /// Virtual method called when operation stopped - committed or aborted.
+ /// After the parent operation body perform, reset selection point mode of the operation
+ virtual void stopOperation();
+
+protected:
+ /// \brief Save the point to the line.
+ /// \param thePoint the 3D point in the viewer
+ /// \param theAttribute the start or end attribute of the line
+ void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
+
+protected:
+ ///< Structure to lists the possible types of point selection modes
+ enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None};
+
private:
boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+ PointSelectionMode myPointSelectionMode; ///< point selection mode
};
#endif
--- /dev/null
+// File: PartSet_Tools.h
+// Created: 28 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_Tools.h>
+
+#include <V3d_View.hxx>
+#include <gp_Pln.hxx>
+#include <ProjLib.hxx>
+#include <ElSLib.hxx>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
+{
+ V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
+ theView->Eye( XEye, YEye, ZEye );
+
+ theView->At( XAt, YAt, ZAt );
+ gp_Pnt EyePoint( XEye, YEye, ZEye );
+ gp_Pnt AtPoint( XAt, YAt, ZAt );
+
+ gp_Vec EyeVector( EyePoint, AtPoint );
+ gp_Dir EyeDir( EyeVector );
+
+ gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
+ Standard_Real X, Y, Z;
+ theView->Convert( thePoint.x(), thePoint.y(), X, Y, Z );
+ gp_Pnt ConvertedPoint( X, Y, Z );
+
+ gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
+ gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
+ return ResultPoint;
+}
--- /dev/null
+// File: PartSet_Tools.h
+// Created: 28 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_Tools_H
+#define PartSet_Tools_H
+
+#include "PartSet.h"
+
+#include <gp_Pnt.hxx>
+
+#include <QPoint>
+
+class Handle_V3d_View;
+
+/*!
+ \class PartSet_Tools
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_Tools
+{
+public:
+ /// Converts the 2D screen point to the 3D point on the view according to the point of view
+ /// \param thePoint a screen point
+ /// \param theView a 3D view
+ static gp_Pnt ConvertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
+
+};
+
+#endif
{
}
+bool XGUI_Displayer::IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end();
+}
+
void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
const bool isUpdateViewer)
{
const int theMode, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
+
+ if (IsVisible(theFeature)) {
+ Erase(theFeature, false);
+ }
Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
/// or can not be initialized in constructor
void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
+ /// Returns the feature visibility state.
+ /// \param theFeature a feature instance
+ bool IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
/// 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
return aWnd;
}
+XGUI_ViewWindow* XGUI_Viewer::activeViewWindow() const
+{
+ return dynamic_cast<XGUI_ViewWindow*>(myActiveView->widget());
+}
void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
{
XGUI_ViewPort* aViewPort = theWindow->viewPort();
Handle(V3d_View) aView3d = aViewPort->getView();
- if ( !aView3d.IsNull() )
+ if ( !aView3d.IsNull() ) {
myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
+ mouseMoved(theEvent->pos());
+ }
}
/*!
{
myAISContext->Select();
- emit selectionChanged();
+ emit mouseReleased(theEvent->pos());
}
#include <NCollection_List.hxx>
#include <TopoDS_Shape.hxx>
+#include <QPoint>
+
class XGUI_MainWindow;
class QMdiSubWindow;
class XGUI_ViewWindow;
return myAISContext;
}
+ //! Returns an active view window or NULL
+ XGUI_ViewWindow* activeViewWindow() const;
+
/// Return objects selected in 3D viewer
/// \param theList - list to be filled with selected objects
void getSelectedObjects(AIS_ListOfInteractive& theList);
void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
void activated(XGUI_ViewWindow* theWindow);
void selectionChanged();
+ void mouseReleased(QPoint thePoint);
+ void mouseMoved(QPoint thePoint);
public slots:
void onWindowMinimized(QMdiSubWindow*);