Sketcher: Do not recompute on geometry deletion

fixes #3642
This commit is contained in:
Abdullah Tahiri
2018-12-15 14:09:27 +01:00
committed by wmayer
parent cc0ea5571e
commit 57b7142cd7
5 changed files with 182 additions and 12 deletions

View File

@@ -114,6 +114,8 @@ SET(SketcherGui_SRCS
TaskSketcherValidation.ui
TaskSketcherValidation.cpp
TaskSketcherValidation.h
ShortcutListener.h
ShortcutListener.cpp
ViewProviderSketch.cpp
ViewProviderSketch.h
DrawSketchHandler.cpp

View File

@@ -0,0 +1,60 @@
/***************************************************************************
* Copyright (c) 2018 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QKeyEvent>
#endif
#include "ShortcutListener.h"
#include "ViewProviderSketch.h"
using namespace SketcherGui;
ShortcutListener::ShortcutListener(ViewProviderSketch * vp):QObject()
{
pViewProvider = vp;
}
ShortcutListener::~ShortcutListener()
{
}
bool ShortcutListener::eventFilter(QObject *obj, QEvent *event) {
if (event->type() == QEvent::ShortcutOverride) {
QKeyEvent * kevent = static_cast<QKeyEvent*>(event);
if (kevent->modifiers() == Qt::NoModifier ||
kevent->modifiers() == Qt::ShiftModifier ||
kevent->modifiers() == Qt::KeypadModifier) {
switch (kevent->key()) {
case Qt::Key_Delete:
kevent->accept();
pViewProvider->deleteSelected(); // this takes a list of objects
return true;
default:
break;
}
}
}
return QObject::eventFilter(obj, event);
}

View File

@@ -0,0 +1,53 @@
/***************************************************************************
* Copyright (c) 2018 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef SKETCHERGUI_SHORTCUTLISTENER_H
#define SKETCHERGUI_SHORTCUTLISTENER_H
#include <QObject>
namespace SketcherGui {
class ViewProviderSketch;
class ShortcutListener: public QObject
{
//Q_OBJECT
public:
ShortcutListener(ViewProviderSketch * vp);
~ShortcutListener();
protected:
bool eventFilter(QObject *obj, QEvent *event);
ViewProviderSketch * pViewProvider;
};
} // namespace PartGui
#endif // SKETCHERGUI_SHORTCUTLISTENER_H

View File

@@ -69,6 +69,7 @@
# include <QMessageBox>
# include <QPainter>
# include <QTextStream>
# include <QKeyEvent>
#endif
#ifndef _PreComp_
@@ -281,7 +282,8 @@ ViewProviderSketch::ViewProviderSketch()
Mode(STATUS_NONE),
visibleInformationChanged(true),
combrepscalehyst(0),
isShownVirtualSpace(false)
isShownVirtualSpace(false),
listener(0)
{
ADD_PROPERTY_TYPE(Autoconstraints,(true),"Auto Constraints",(App::PropertyType)(App::Prop_None),"Create auto constraints");
ADD_PROPERTY_TYPE(TempoVis,(Py::None()),"Visibility automation",(App::PropertyType)(App::Prop_None),"Object that handles hiding and showing other objects when entering/leaving sketch.");
@@ -5689,6 +5691,12 @@ bool ViewProviderSketch::setEdit(int ModNum)
getSketchObject()->getSolvedSketch().RecalculateInitialSolutionWhileMovingPoint = hGrp2->GetBool("RecalculateInitialSolutionWhileDragging",true);
// intercept del key press from main app
listener = new ShortcutListener(this);
Gui::getMainWindow()->installEventFilter(listener);
return true;
}
@@ -5972,6 +5980,11 @@ void ViewProviderSketch::unsetEdit(int ModNum)
ShowGrid.setValue(false);
TightGrid.setValue(true);
if(listener) {
Gui::getMainWindow()->removeEventFilter(listener);
delete listener;
}
if (edit) {
if (edit->sketchHandler)
deactivateHandler();
@@ -6224,6 +6237,31 @@ Sketcher::SketchObject *ViewProviderSketch::getSketchObject(void) const
return dynamic_cast<Sketcher::SketchObject *>(pcObject);
}
void ViewProviderSketch::deleteSelected()
{
std::vector<Gui::SelectionObject> selection;
selection = Gui::Selection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId());
// only one sketch with its subelements are allowed to be selected
if (selection.size() != 1) {
Base::Console().Warning("Delete: Selection not restricted to one sketch and its subelements");
return;
}
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
if(SubNames.size()>0) {
App::Document* doc = getSketchObject()->getDocument();
doc->openTransaction("delete sketch geometry");
onDelete(SubNames);
doc->commitTransaction();
}
}
bool ViewProviderSketch::onDelete(const std::vector<std::string> &subList)
{
if (edit) {
@@ -6349,8 +6387,20 @@ bool ViewProviderSketch::onDelete(const std::vector<std::string> &subList)
// This function is generally called from StdCmdDelete::activated
// Since 2015-05-03 that function includes a recompute at the end.
/*this->drawConstraintIcons();
this->updateColor();*/
// Since December 2018, the function is no longer called from StdCmdDelete::activated,
// as there is an event filter installed that intercepts the del key event. So now we do
// need to tidy up after ourselves again.
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
bool autoRecompute = hGrp->GetBool("AutoRecompute",false);
if (autoRecompute) {
Gui::Command::updateActive();
}
else {
this->drawConstraintIcons();
this->updateColor();
}
// if in edit not delete the object
return false;

View File

@@ -36,6 +36,7 @@
#include <boost/signals2.hpp>
#include <QCoreApplication>
#include <Gui/Document.h>
#include "ShortcutListener.h"
class TopoDS_Shape;
@@ -123,7 +124,7 @@ public:
/// Show/Hide nodes from information layer
void showRestoreInformationLayer();
/** @name handler control */
//@{
/// sets an DrawSketchHandler in control
@@ -224,11 +225,13 @@ public:
virtual bool mouseButtonPressed(int Button, bool pressed, const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer);
//@}
void deleteSelected();
/// updates the visibility of the virtual space
void updateVirtualSpace(void);
void setIsShownVirtualSpace(bool isshownvirtualspace);
bool getIsShownVirtualSpace(void) const;
friend class DrawSketchHandler;
friend struct ::EditData;
@@ -240,7 +243,7 @@ public:
boost::signals2::signal<void (QString msg)> signalSolved;
/// signals if the elements list has changed
boost::signals2::signal<void ()> signalElementsChanged;
protected:
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
@@ -263,14 +266,14 @@ protected:
EditData *edit;
/// build up the visual of the constraints
void rebuildConstraintsVisual(void);
void slotUndoDocument(const Gui::Document&);
void slotRedoDocument(const Gui::Document&);
protected:
boost::signals2::connection connectUndoDocument;
boost::signals2::connection connectRedoDocument;
/// Return display string for constraint including hiding units if
//requested.
QString getPresentationString(const Sketcher::Constraint *constraint);
@@ -308,7 +311,7 @@ protected:
/// Pointer to SoInfo object where we store the constraint IDs that the icon refers to
SoInfo *infoPtr;
/// Angle to rotate an icon
double iconRotation;
};
@@ -363,7 +366,7 @@ protected:
void addSelectPoint(int SelectPoint);
void removeSelectPoint(int SelectPoint);
void clearSelectPoints(void);
// modes while sketching
SketchMode Mode;
@@ -416,9 +419,11 @@ protected:
// information layer variables
bool visibleInformationChanged;
double combrepscalehyst;
// Virtual space variables
bool isShownVirtualSpace; // indicates whether the present virtual space view is the Real Space or the Virtual Space (virtual space 1 or 2)
ShortcutListener* listener;
};
} // namespace PartGui