if (aSelector) {
NCollection_List<TopoDS_Shape> aList;
aSelector->selectedShapes(aList);
-
aPresentations = myWorkshop->displayer()->GetViewerPrs(aList);
}
aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
myWorkshop->operationMgr()->currentOperation());
if (aPreviewOp)
{
- aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView());
+ XGUI_SelectionMgr* aSelector = myWorkshop->selector();
+ std::list<XGUI_ViewerPrs> aPresentations;
+ if (aSelector) {
+ NCollection_List<TopoDS_Shape> aList;
+ aSelector->selectedShapes(aList);
+ aPresentations = myWorkshop->displayer()->GetViewerPrs(aList);
+ }
+ aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
}
}
aViewer->enableMultiselection(theEnabled);
}
+void PartSet_Module::onSelectionEnabled(bool theEnabled)
+{
+ XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+ aViewer->enableSelection(theEnabled);
+}
+
void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
int theMode)
{
this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
this, SLOT(onMultiSelectionEnabled(bool)));
+ connect(aPreviewOp, SIGNAL(selectionEnabled(bool)),
+ this, SLOT(onSelectionEnabled(bool)));
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
/// \param theEnabled the enabled state
void onMultiSelectionEnabled(bool theEnabled);
+ /// SLOT, to switch on/off the selection in the viewer
+ /// \param theEnabled the enabled state
+ void onSelectionEnabled(bool theEnabled);
+
/// SLOT, to visualize the feature in another local context mode
/// \param theFeature the feature to be put in another local context mode
/// \param theMode the mode appeared on the feature
if (!(theEvent->buttons() & Qt::LeftButton))
return;
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
- myCurPressed = aPoint;
+ myCurPoint.setPoint(aPoint);
}
-void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
+ const std::list<XGUI_ViewerPrs>& theSelected)
{
if (!(theEvent->buttons() & Qt::LeftButton))
return;
-
- double aCurX, aCurY;
- PartSet_Tools::ConvertTo2D(myCurPressed, mySketch, theView, aCurX, aCurY);
-
- double aX, anY;
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
-
- double aDeltaX = aX - aCurX;
- double aDeltaY = anY - aCurY;
- moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_START);
- moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_END);
- myCurPressed = aPoint;
+ if (myCurPoint.myIsInitialized) {
+ double aCurX, aCurY;
+ PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY);
+
+ double aX, anY;
+ PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+
+ double aDeltaX = aX - aCurX;
+ double aDeltaY = anY - aCurY;
+
+ moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START);
+ moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END);
+
+ /*std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
+ for (; anIt != aLast; anIt++) {
+ boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
+ if (!aFeature)
+ continue;
+ moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
+ moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END);
+ }*/
+ }
+ myCurPoint.setPoint(aPoint);
}
void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
void PartSet_OperationEditLine::startOperation()
{
// do nothing in order to do not create a new feature
- emit multiSelectionEnabled(false);
+ emit selectionEnabled(false);
+ myCurPoint.clear();
}
void PartSet_OperationEditLine::stopOperation()
{
- emit multiSelectionEnabled(true);
+ emit selectionEnabled(true);
}
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
return boost::shared_ptr<ModelAPI_Feature>();
}
-void PartSet_OperationEditLine::moveLinePoint(double theDeltaX, double theDeltaY,
+void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ double theDeltaX, double theDeltaY,
const std::string& theAttribute)
{
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ if (!theFeature)
+ return;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
class PARTSET_EXPORT PartSet_OperationEditLine : public PartSet_OperationSketchBase
{
Q_OBJECT
+ /// Struct to define gp point, with the state is the point is initialized
+ struct Point
+ {
+ /// Constructor
+ Point() {}
+ /// Constructor
+ /// \param thePoint the point
+ Point(gp_Pnt thePoint)
+ {
+ setPoint(thePoint);
+ }
+ ~Point() {}
+
+ /// clear the initialized flag.
+ void clear() { myIsInitialized = false; }
+ /// set the point and switch on the initialized flag
+ /// \param thePoint the point
+ void setPoint(const gp_Pnt& thePoint)
+ {
+ myIsInitialized = true;
+ myPoint = thePoint;
+ }
+
+ bool myIsInitialized; /// the state whether the point is set
+ gp_Pnt myPoint; /// the point
+ };
+
public:
/// Returns the operation type key
static std::string Type() { return "EditLine"; }
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ /// \param theSelected the list of selected presentations
+ virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected);
/// Gives the current selected objects to be processed by the operation
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
/// \param theSelected the list of selected presentations
virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected);
+ const std::list<XGUI_ViewerPrs>& theSelected);
protected:
/// \brief Virtual method called when operation is started
/// Virtual method called when operation started (see start() method for more description)
protected:
/// \brief Save the point to the line.
+ /// \param theFeature the source feature
/// \param theDeltaX the delta for X coordinate is moved
/// \param theDeltaY the delta for Y coordinate is moved
/// \param theAttribute the start or end attribute of the line
- void moveLinePoint(double theDeltaX, double theDeltaY,
+ void moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ double theDeltaX, double theDeltaY,
const std::string& theAttribute);
private:
boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+ Point myCurPoint; ///< the current 3D point clicked or moved
gp_Pnt myCurPressed; ///< the current 3D point clicked or moved
};
#include <PartSet_OperationSketch.h>
#include <PartSet_OperationEditLine.h>
+#include <PartSet_Tools.h>
#include <SketchPlugin_Sketch.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDouble.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <QDebug>
#endif
+#include <QMouseEvent>
+
using namespace std;
PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
{
if (theSelected.empty())
return;
- XGUI_ViewerPrs aPrs = theSelected.front();
if (!myIsEditMode) {
+ XGUI_ViewerPrs aPrs = theSelected.front();
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
setSketchPlane(aShape);
myIsEditMode = true;
}
}
- else {
- if (aPrs.feature())
- emit launchOperation(PartSet_OperationEditLine::Type(), aPrs.feature());
- }
+}
+
+void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
+ const std::list<XGUI_ViewerPrs>& theSelected)
+{
+ if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || theSelected.empty())
+ return;
+
+ boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
+ theView, feature(), theSelected);
+ if (aFeature)
+ emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
}
void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
emit planeSelected(aDir->x(), aDir->y(), aDir->z());
}
-
/// \param theSelected the list of selected presentations
virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
const std::list<XGUI_ViewerPrs>& theSelected);
+ /// Gives the current mouse point in the viewer
+ /// \param thePoint a point clicked in the viewer
+ /// \param theEvent the mouse event
+ /// \param theSelected the list of selected presentations
+ virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected);
signals:
/// signal about the sketch plane is selected
const std::list<XGUI_ViewerPrs>& theSelected)
{
}
-void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
+ const std::list<XGUI_ViewerPrs>& theSelected)
{
}
/// Processes the mouse move in the point
/// \param thePoint a 3D point clicked in the viewer
/// \param theEvent the mouse event
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ /// \param theSelected the list of selected presentations
+ virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected);
/// Processes the key pressed in the view
/// \param theKey a key value
/// \param theEnabled the boolean state
void multiSelectionEnabled(bool theEnabled);
+ /// signal to enable/disable usual selection in the viewer
+ /// \param theEnabled the boolean state
+ void selectionEnabled(bool theEnabled);
+
protected:
/// Creates an operation new feature
/// In addition to the default realization it appends the created line feature to
{
double aX, anY;
+ bool isFoundPoint = false;
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
if (theSelected.empty()) {
PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+ isFoundPoint = true;
}
else {
XGUI_ViewerPrs aPrs = theSelected.front();
if (!aVertex.IsNull()) {
aPoint = BRep_Tool::Pnt(aVertex);
PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+ isFoundPoint = true;
setConstraints(aX, anY);
}
default:
break;
}
+ isFoundPoint = true;
}
}
}
}
+ //if (!isFoundPoint)
+ // return;
+
switch (myPointSelectionMode)
{
case SM_FirstPoint: {
}
}
-void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/)
{
switch (myPointSelectionMode)
{
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ /// \param theSelected the list of selected presentations
+ virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected);
/// Processes the key pressed in the view
/// \param theKey a key value
virtual void keyReleased(const int theKey);
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_XYZ.h>
#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Line.h>
+
+#include <XGUI_ViewerPrs.h>
#include <V3d_View.hxx>
#include <gp_Pln.hxx>
theY = aPoint.Y();
}
}
+
+boost::shared_ptr<ModelAPI_Feature> PartSet_Tools::NearestFeature(QPoint thePoint,
+ Handle_V3d_View theView,
+ boost::shared_ptr<ModelAPI_Feature> theSketch,
+ const std::list<XGUI_ViewerPrs>& theFeatures)
+{
+ double aX, anY;
+ gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, theView);
+ PartSet_Tools::ConvertTo2D(aPoint, theSketch, theView, aX, anY);
+
+ boost::shared_ptr<ModelAPI_Feature> aFeature;
+ std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+
+ boost::shared_ptr<ModelAPI_Feature> aDeltaFeature;
+ double aMinDelta = -1;
+ XGUI_ViewerPrs aPrs;
+ for (; anIt != aLast; anIt++) {
+ aPrs = *anIt;
+ if (!aPrs.feature())
+ continue;
+ double aDelta = DistanceToPoint(aPrs.feature(), aX, anY);
+ if (aMinDelta < 0 || aMinDelta > aDelta) {
+ aMinDelta = aDelta;
+ aDeltaFeature = aPrs.feature();
+ }
+ }
+ return aDeltaFeature;
+}
+
+double PartSet_Tools::DistanceToPoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ double theX, double theY)
+{
+ double aDelta = 0;
+ if (theFeature->getKind() != "SketchLine")
+ return aDelta;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+
+ double aX, anY;
+ PartSet_Tools::ProjectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY);
+
+ aDelta = gp_Pnt(theX, theY, 0).Distance(gp_Pnt(aX, anY, 0));
+
+ return aDelta;
+}
#include <boost/shared_ptr.hpp>
+#include <list>
+
class Handle_V3d_View;
class ModelAPI_Feature;
+class XGUI_ViewerPrs;
/*!
\class PartSet_Tools
/// \param theY2 the vertical coordinate of the second line point
static void ProjectPointOnLine(double theX1, double theY1, double theX2, double theY2,
double thePointX, double thePointY, double& theX, double& theY);
+
+ /// Returns a feature that is under the mouse point
+ /// \param thePoint a screen point
+ /// \param theView a 3D view
+ /// \param theSketch the sketch feature
+ /// \param theFeatures the list of selected presentations
+ static boost::shared_ptr<ModelAPI_Feature> NearestFeature(QPoint thePoint, Handle_V3d_View theView,
+ boost::shared_ptr<ModelAPI_Feature> theSketch,
+ const std::list<XGUI_ViewerPrs>& theFeatures);
+private:
+ /// Return the distance between the feature and the point
+ /// \param theFeature feature object
+ /// \param theX the horizontal coordinate of the point
+ /// \param theX the vertical coordinate of the point
+ static double DistanceToPoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ double theX, double theY);
};
#endif
*/
void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
{
- if (!mySelectionEnabled) return;
- if (theEvent->button() != Qt::LeftButton) return;
+ if (!mySelectionEnabled || theEvent->button() != Qt::LeftButton) {
+ emit mouseRelease(theWindow, theEvent);
+ return;
+ }
myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);