Add vertex snapping of already drawn sketch primitives.
}
-bool PartSet_MouseProcessor::convertPointToLocal(
+/*static*/ bool PartSet_MouseProcessor::convertPointToLocal(
ModuleBase_IWorkshop* theWorkshop,
const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
ModuleBase_IViewWindow* theWindow,
const QPoint& theEventPos,
double& theX, double& theY,
+ bool theSnap,
bool theHighlight,
bool theAddOffset
-) const {
+) {
ModuleBase_IViewer* const viewer = theWorkshop->viewer();
if (!viewer)
return false;
const Handle(V3d_View) view = theWindow->v3dView();
PartSet_PreviewSketchPlane* previewPlane = module->sketchMgr()->previewSketchPlane();
- if (!aV3dViewer || !aV3dViewer->Grid()->IsActive() || previewPlane->getGridSnappingMode() == PartSet_PreviewSketchPlane::GridSnappingMode::Off) {
+ if (!theSnap || !aV3dViewer || !aV3dViewer->Grid()->IsActive() || previewPlane->getGridSnappingMode() == PartSet_PreviewSketchPlane::GridSnappingMode::Off) {
const gp_Pnt mousePoint = PartSet_Tools::convertClickToPoint(theEventPos, view);
PartSet_Tools::convertTo2D(mousePoint, theSketch, view, theX, theY);
return true;
ModuleBase_IViewWindow* theWnd,
QMouseEvent* theEvent) {}
- protected:
/// \brief Converts position of mouse cursor to local coordinates on sketch plane.
/// Snaps on-sketch-plane-coordinates to closest construction grid node.
/// \param theEventPos is position of mouse cursor.
/// \param theX and \param theY are local coordinates on sketch plane.
+ /// \param theSnap theX and theY are snapped to construction grid if both theSnap == true and snapping is enabled.
/// \param theHighlight If point is snapped, hightlight grid point.
/// \param theAddOffset If true, serves as a remedy for odd crash during drawing of a line on a sketch.
- /// \return true on success.
- virtual bool convertPointToLocal(
+ /// \returns true on success.
+ static bool convertPointToLocal(
ModuleBase_IWorkshop* theWorkshop,
const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch, // Passing by reference is intentionally.
ModuleBase_IViewWindow* theWindow,
const QPoint& theEventPos,
double& theX, double& theY,
+ bool theSnap = true,
bool theHighlight = false,
bool theAddOffset = false
- ) const;
+ );
};
#endif
#include <set>
+#include <iostream>
+
//#define DEBUG_DO_NOT_BY_ENTER
//#define DEBUG_SKETCHER_ENTITIES
//#define DEBUG_SKETCH_ENTITIES_ON_MOVE
void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
+ std::wcout << "PartSet_SketcherMgr::onMousePressed BEGIN" << std::endl;
+
MyModeByDrag = isDragModeCreation();
// Clear dragging mode
myMousePoint.setX(theEvent->x());
myMousePoint.setY(theEvent->y());
- if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
+ if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent)) {
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END A" << std::endl;
return;
+ }
//get2dPoint(theWnd, theEvent, myClickedPoint);
- if (!(theEvent->buttons() & Qt::LeftButton))
+ if (!(theEvent->buttons() & Qt::LeftButton)) {
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END B" << std::endl;
return;
+ }
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
ModuleBase_IViewer* aViewer = aWorkshop->viewer();
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(getCurrentOperation());
- if (!aFOperation)
+ if (!aFOperation) {
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END C" << std::endl;
return;
+ }
bool isEditing = aFOperation->isEditOperation();
bool aCanDrag = aViewer->canDragByMouse();
// If the current widget is a selector, do nothing, it processes the mouse press
ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
if(anActiveWidget && anActiveWidget->isViewerSelector()) {
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END D" << std::endl;
return;
}
}
// Use only for sketch operations
if (myCurrentSketch) {
- if (!PartSet_Tools::sketchPlane(myCurrentSketch))
+ if (!PartSet_Tools::sketchPlane(myCurrentSketch)) {
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END E" << std::endl;
return;
+ }
bool isSketcher = isSketchOperation(aFOperation);
bool isSketchOpe = isNestedSketchOperation(aFOperation);
// Avoid non-sketch operations
- if ((!isSketchOpe) && (!isSketcher))
+ if ((!isSketchOpe) && (!isSketcher)) {
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END F" << std::endl;
return;
+ }
// Ignore creation sketch operation
if ((!isSketcher) && (!isEditing)) {
aProcessor->mouseReleased(theWnd, theEvent);
}
}
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END G" << std::endl;
return;
}
bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
// commit previous operation
if (!aFOperation->commit())
aFOperation->abort();
+
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END H" << std::endl;
return;
}
// Init flyout point for radius rotation
}
}
}
+ std::wcout << "PartSet_SketcherMgr::onMousePressed END LAST" << std::endl;
}
void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
+ std::wcout << "PartSet_SketcherMgr::onMouseMoved START" << std::endl;
#ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
CompositeFeaturePtr aSketch = activeSketch();
if (aSketch.get()) {
}
#endif
- if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
+ if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent)) {
+ std::wcout << "PartSet_SketcherMgr::onMouseMoved END A" << std::endl;
return;
+ }
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
// deselected). This flag should be restored in the slot, processed the mouse release signal.
ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
if (!aCurrentOperation) {
+ std::wcout << "PartSet_SketcherMgr::onMouseMoved END B" << std::endl;
return;
}
if (isSketchOperation(aCurrentOperation)) {
+ std::wcout << "PartSet_SketcherMgr::onMouseMoved END C" << std::endl;
return; // No edit operation activated
}
Handle(V3d_View) aView = theWnd->v3dView();
Point aMousePnt;
- get2dPoint(theWnd, theEvent, aMousePnt);
+ get2dPoint(theWnd, theEvent, aMousePnt, true /*theSnap*/);
- std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
- new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
- std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
- new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
+ auto anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
+ auto aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
// 3. the flag to disable the update viewer should be set in order to avoid blinking in the
// viewer happens by deselect/select the modified objects. The flag should be restored after
aPoint->attributeType() == GeomDataAPI_Point2DArray::typeId()) {
bool isImmutable = aPoint->setImmutable(true);
- std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
- <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
+ auto aMessage = std::shared_ptr<ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
aMessage->setMovedAttribute(aPoint, anAttIt->second);
aMessage->setOriginalPosition(anOriginalPosition);
aMessage->setCurrentPosition(aCurrentPosition);
}
else {
// Process selection by feature
- std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ auto aSketchFeature = std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if (aSketchFeature) {
- std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
- <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
+ auto aMessage = std::shared_ptr<ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
aMessage->setMovedObject(aFeature);
aMessage->setOriginalPosition(anOriginalPosition);
aMessage->setCurrentPosition(aCurrentPosition);
#endif
myDragDone = true;
+ get2dPoint(theWnd, theEvent, aMousePnt, true /*theSnap*/);
myCurrentPoint = aMousePnt;
}
+
+ std::wcout << "PartSet_SketcherMgr::onMouseMoved END LAST" << std::endl;
}
void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
myIsPopupMenuActive = false;
}
-void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
- Point& thePoint)
+void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, Point& thePoint, bool theSnap)
{
- Handle(V3d_View) aView = theWnd->v3dView();
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
- double aX, anY;
- PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
- thePoint.setValue(aX, anY);
+
+ double aX = 0, aY = 0; // Coords at sketch plane.
+ bool success = PartSet_MouseProcessor::convertPointToLocal(workshop()->moduleConnector(), myCurrentSketch, theWnd, theEvent->pos(), aX, aY, theSnap, true, true);
+ if (!success)
+ return;
+
+ //Handle(V3d_View) aView = theWnd->v3dView();
+ //gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
+ //double aX, anY;
+ //PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
+ thePoint.setValue(aX, aY);
}
void PartSet_SketcherMgr::launchEditing()
/// Converts mouse position to 2d coordinates.
/// Member myCurrentSketch has to be correctly defined
+ /// \param theSnap If true and snapping is enabled, snaps coordinates to the grid.
void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
- Point& thePoint);
+ Point& thePoint, bool theSnap = true);
/// Show distance value editor if it is a distance operation and all attribute references
/// are filled by preseletion
theWindow,
theEvent->pos(),
aX, aY,
+ true,
true
);
#include <cfloat>
#include <climits>
+#include <iostream>
+
const double MaxCoordinate = 1e12;
static QStringList MyFeaturesForCoincedence;
bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
{
+ std::wcout << "PartSet_WidgetPoint2D::isValidSelectionCustom BEGIN" << std::endl;
+
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
if (aModule->sketchReentranceMgr()->isInternalEditActive())
return true; /// when internal edit is started a new feature is created. I has not results, AIS
const ModuleBase_ViewerPrsPtr& theValue,
const AttributePtr& theAttribute)
{
+ std::wcout << "PartSet_WidgetPoint2D::isValidSelectionForAttribute_ BEGIN" << std::endl;
+
bool aValid = false;
// stores the current values of the widget attribute
bool PartSet_WidgetPoint2D::setSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
{
+ std::wcout << "PartSet_WidgetPoint2D::setSelectionCustom BEGIN" << std::endl;
+
bool isDone = false;
GeomShapePtr aShape = theValue->shape();
if (aShape.get() && !aShape->isNull()) {
bool PartSet_WidgetPoint2D::resetCustom()
{
+ std::wcout << "PartSet_WidgetPoint2D::resetCustom BEGIN" << std::endl;
+
bool aDone = false;
if (!isUseReset() || isComputedDefault()
/*|| myXSpin->hasVariable() || myYSpin->hasVariable()*/) {
bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
const bool theToValidate)
{
+ std::wcout << "PartSet_WidgetPoint2D::setSelection BEGIN" << std::endl;
+
bool isDone = false;
if (theValues.empty())
return isDone;
bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
{
+ std::wcout << "PartSet_WidgetPoint2D::setPoint BEGIN" << std::endl;
+
if (fabs(theX) >= MaxCoordinate)
return false;
if (fabs(theY) >= MaxCoordinate)
bool PartSet_WidgetPoint2D::storeValueCustom()
{
+ std::wcout << "PartSet_WidgetPoint2D::storeValueCustom BEGIN" << std::endl;
+
std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
if (!aData || !aData->isValid()) // can be on abort of sketcher element
return false;
bool PartSet_WidgetPoint2D::restoreValueCustom()
{
+ std::wcout << "PartSet_WidgetPoint2D::restoreValueCustom BEGIN" << std::endl;
+
std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(attributeID()));
+
double aValueX = aPoint->isInitialized() ? aPoint->x() : 0.;
double aValueY = aPoint->isInitialized() ? aPoint->y() : 0.;
+
myXSpin->setValue(aValueX);
myYSpin->setValue(aValueY);
void PartSet_WidgetPoint2D::storeCurentValue()
{
+ std::wcout << "PartSet_WidgetPoint2D::storeCurentValue BEGIN" << std::endl;
+
// do not use cash if a variable is used
//if (myXSpin->hasVariable() || myYSpin->hasVariable())
// return;
bool PartSet_WidgetPoint2D::restoreCurentValue()
{
+ std::wcout << "PartSet_WidgetPoint2D::restoreCurentValue BEGIN" << std::endl;
+
bool aRestoredAndHidden = true;
bool isVisible = myIsFeatureVisibleInCash;
QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
{
+ std::wcout << "PartSet_WidgetPoint2D::getControls BEGIN" << std::endl;
+
QList<QWidget*> aControls;
aControls.append(myXSpin);
aControls.append(myYSpin);
//********************************************************************
void PartSet_WidgetPoint2D::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
{
+ std::wcout << "PartSet_WidgetPoint2D::selectionModes BEGIN" << std::endl;
+
theModuleSelectionModes = -1;
theModes << TopAbs_VERTEX;
theModes << TopAbs_EDGE;
//********************************************************************
void PartSet_WidgetPoint2D::activateCustom()
{
+ std::wcout << "PartSet_WidgetPoint2D::activateCustom BEGIN" << std::endl;
+
if (!isEditingMode()) {
FeaturePtr aFeature = feature();
if (aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID())
void PartSet_WidgetPoint2D::deactivate()
{
+ std::wcout << "PartSet_WidgetPoint2D::deactivate BEGIN" << std::endl;
+
// the value of the control should be stored to model if it was not
// initialized yet. It is important when we leave this control by Tab key.
// It should not be performed by the widget activation as the preview
bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY,
const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
{
+ std::wcout << "PartSet_WidgetPoint2D::setConstraintToPoint BEGIN" << std::endl;
+
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
if (aRefAttr.get())
fillRefAttribute(theClickedX, theClickedY, theValue);
bool PartSet_WidgetPoint2D::setConstraintToObject(const ObjectPtr& theObject)
{
+ std::wcout << "PartSet_WidgetPoint2D::setConstraintToObject BEGIN" << std::endl;
+
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
if (aRefAttr.get()) {
fillRefAttribute(theObject);
}
}
if (!aHasPoint) {
- bool success = convertPointToLocal(myWorkshop, mySketch, theWindow, theEvent->pos(), aX, aY, false);
+ bool success = PartSet_MouseProcessor::convertPointToLocal(myWorkshop, mySketch, theWindow, theEvent->pos(), aX, aY, true, false);
if (!success)
return;
}
void PartSet_WidgetPoint2D::processSelection(const ModuleBase_ViewerPrsPtr& theValue,
double theX, double theY)
{
+ std::wcout << "PartSet_WidgetPoint2D::processSelection BEGIN" << std::endl;
+
if (!setPoint(theX, theY))
return;
// if we have selection and use it
ModuleBase_IViewWindow* theWnd,
QMouseEvent* theEvent)
{
+ std::wcout << "PartSet_WidgetPoint2D::setPreSelection BEGIN" << std::endl;
+
myPreSelected = thePreSelected;
mouseReleased(theWnd, theEvent);
}
void PartSet_WidgetPoint2D::mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent)
{
+ std::wcout << "PartSet_WidgetPoint2D:::mouseMoved BEGIN" << std::endl;
+
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
- if (isEditingMode() || aModule->sketchReentranceMgr()->isInternalEditActive())
+ if (isEditingMode() || aModule->sketchReentranceMgr()->isInternalEditActive()) {
+ std::wcout << "PartSet_WidgetPoint2D:::mouseMoved if (isEditingMode() || aModule->sketchReentranceMgr()->isInternalEditActive()) BEGIN" << std::endl;
return;
+ }
double aX = 0, aY = 0; // Coords at sketch plane.
- bool success = convertPointToLocal(myWorkshop, mySketch, theWindow, theEvent->pos(), aX, aY, true, true);
+ bool success = PartSet_MouseProcessor::convertPointToLocal(myWorkshop, mySketch, theWindow, theEvent->pos(), aX, aY, true, true, true);
if (!success)
return;
bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
double theX, double theY)
{
+ std::wcout << "PartSet_WidgetPoint2D:::isFeatureContainsPoint BEGIN" << std::endl;
+
bool aPointIsFound = false;
if (feature()->getKind() != SketchPlugin_Line::ID())