Sketch: Forward non-default edit mode to base class. (#27063)
Ported from Codeberg commit 66dbf277 Co-authored-by: wwmayer <wmayer@freecad.org>
This commit is contained in:
@@ -46,9 +46,8 @@ bool isAlterGeoActive(Gui::Document* doc)
|
||||
{
|
||||
if (doc) {
|
||||
// checks if a Sketch Viewprovider is in Edit
|
||||
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom<SketcherGui::ViewProviderSketch>()) {
|
||||
return true;
|
||||
}
|
||||
auto vp = dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
||||
return (vp && vp->isInEditMode());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -78,12 +78,10 @@ bool isCreateConstraintActive(Gui::Document* doc)
|
||||
{
|
||||
if (doc) {
|
||||
// checks if a Sketch View provider is in Edit and is in no special mode
|
||||
if (doc->getInEdit()
|
||||
&& doc->getInEdit()->isDerivedFrom<SketcherGui::ViewProviderSketch>()) {
|
||||
if (static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())->getSketchMode()
|
||||
== ViewProviderSketch::STATUS_NONE) {
|
||||
if (Gui::Selection().countObjectsOfType<Sketcher::SketchObject>()
|
||||
> 0) {
|
||||
auto vp = dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
||||
if (vp && vp->isInEditMode()) {
|
||||
if (vp->getSketchMode() == ViewProviderSketch::STATUS_NONE) {
|
||||
if (Gui::Selection().countObjectsOfType<Sketcher::SketchObject>() > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,13 +51,13 @@ bool isSketcherVirtualSpaceActive(Gui::Document* doc, bool actsOnSelection)
|
||||
{
|
||||
if (doc) {
|
||||
// checks if a Sketch Viewprovider is in Edit and is in no special mode
|
||||
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom<SketcherGui::ViewProviderSketch>()) {
|
||||
if (static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())->getSketchMode()
|
||||
== ViewProviderSketch::STATUS_NONE) {
|
||||
auto vp = dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
||||
if (vp && vp->isInEditMode()) {
|
||||
if (vp->getSketchMode() == ViewProviderSketch::STATUS_NONE) {
|
||||
if (!actsOnSelection) {
|
||||
return true;
|
||||
}
|
||||
else if (Gui::Selection().countObjectsOfType<Sketcher::SketchObject>() > 0) {
|
||||
if (Gui::Selection().countObjectsOfType<Sketcher::SketchObject>() > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -70,10 +70,8 @@ void ActivateVirtualSpaceHandler(Gui::Document* doc, DrawSketchHandler* handler)
|
||||
{
|
||||
std::unique_ptr<DrawSketchHandler> ptr(handler);
|
||||
if (doc) {
|
||||
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom<SketcherGui::ViewProviderSketch>()) {
|
||||
SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*>(
|
||||
doc->getInEdit()
|
||||
);
|
||||
auto vp = dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
||||
if (vp && vp->isInEditMode()) {
|
||||
vp->purgeHandler();
|
||||
vp->activateHandler(std::move(ptr));
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ bool SketcherGui::isSketchInEdit(Gui::Document* doc)
|
||||
if (doc) {
|
||||
// checks if a Sketch Viewprovider is in Edit and is in no special mode
|
||||
auto* vp = dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
||||
return (vp != nullptr);
|
||||
return (vp != nullptr && vp->isInEditMode());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -838,6 +838,10 @@ void ViewProviderSketch::setSketchMode(SketchMode mode)
|
||||
|
||||
bool ViewProviderSketch::keyPressed(bool pressed, int key)
|
||||
{
|
||||
if (getEditingMode() != ViewProviderSketch::Default) {
|
||||
return ViewProvider2DObject::keyPressed(pressed, key);
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case SoKeyboardEvent::ESCAPE: {
|
||||
// make the handler quit but not the edit mode
|
||||
@@ -962,6 +966,9 @@ void ViewProviderSketch::getCoordsOnSketchPlane(const SbVec3f& point, const SbVe
|
||||
bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVec2s& cursorPos,
|
||||
const Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
if (getEditingMode() != ViewProviderSketch::Default) {
|
||||
return ViewProvider2DObject::mouseButtonPressed(Button, pressed, cursorPos, viewer);
|
||||
}
|
||||
assert(isInEditMode());
|
||||
|
||||
// Calculate 3d point to the mouse position
|
||||
@@ -1327,11 +1334,11 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
bool ViewProviderSketch::mouseWheelEvent(int delta, const SbVec2s& cursorPos,
|
||||
const Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
assert(isInEditMode());
|
||||
if (getEditingMode() != ViewProviderSketch::Default) {
|
||||
return ViewProvider2DObject::mouseWheelEvent(delta, cursorPos, viewer);
|
||||
}
|
||||
|
||||
Q_UNUSED(delta);
|
||||
Q_UNUSED(cursorPos);
|
||||
Q_UNUSED(viewer);
|
||||
assert(isInEditMode());
|
||||
|
||||
editCoinManager->drawConstraintIcons();
|
||||
|
||||
@@ -1439,6 +1446,10 @@ void ViewProviderSketch::toggleWireSelelection(int clickedGeoId)
|
||||
|
||||
bool ViewProviderSketch::mouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
if (getEditingMode() != ViewProviderSketch::Default) {
|
||||
return ViewProvider2DObject::mouseMove(cursorPos, viewer);
|
||||
}
|
||||
|
||||
// maximum radius for mouse moves when selecting a geometry before switching to drag mode
|
||||
const int dragIgnoredDistance = 3;
|
||||
|
||||
@@ -3398,7 +3409,10 @@ void ViewProviderSketch::setupContextMenu(QMenu* menu, QObject* receiver, const
|
||||
|
||||
bool ViewProviderSketch::setEdit(int ModNum)
|
||||
{
|
||||
Q_UNUSED(ModNum)
|
||||
if (ModNum != ViewProviderSketch::Default) {
|
||||
return PartGui::ViewProvider2DObject::setEdit(ModNum);
|
||||
}
|
||||
|
||||
// When double-clicking on the item for this sketch the
|
||||
// object unsets and sets its edit mode without closing
|
||||
// the task panel
|
||||
@@ -3704,7 +3718,9 @@ void ViewProviderSketch::UpdateSolverInformation()
|
||||
|
||||
void ViewProviderSketch::unsetEdit(int ModNum)
|
||||
{
|
||||
Q_UNUSED(ModNum);
|
||||
if (ModNum != ViewProviderSketch::Default) {
|
||||
return PartGui::ViewProvider2DObject::unsetEdit(ModNum);
|
||||
}
|
||||
|
||||
setGridEnabled(false);
|
||||
auto gridnode = getGridNode();
|
||||
@@ -3773,7 +3789,10 @@ void ViewProviderSketch::unsetEdit(int ModNum)
|
||||
|
||||
void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int ModNum)
|
||||
{
|
||||
Q_UNUSED(ModNum);
|
||||
if (ModNum != ViewProviderSketch::Default) {
|
||||
return PartGui::ViewProvider2DObject::setEditViewer(viewer, ModNum);
|
||||
}
|
||||
|
||||
Base::PyGILStateLocker lock;
|
||||
// visibility automation: save camera
|
||||
if (!this->TempoVis.getValue().isNone()) {
|
||||
@@ -3873,6 +3892,10 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo
|
||||
|
||||
void ViewProviderSketch::unsetEditViewer(Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
if (getEditingMode() != ViewProviderSketch::Default) {
|
||||
return PartGui::ViewProvider2DObject::unsetEditViewer(viewer);
|
||||
}
|
||||
|
||||
auto dataPtr = static_cast<VPRender*>(cameraSensor.getData());
|
||||
delete dataPtr;
|
||||
cameraSensor.setData(nullptr);
|
||||
|
||||
@@ -581,6 +581,10 @@ public:
|
||||
return Mode;
|
||||
}
|
||||
|
||||
/// returns whether the sketch is in edit mode.
|
||||
bool isInEditMode() const;
|
||||
//@}
|
||||
|
||||
// create right click context menu based on selection in the 3D view
|
||||
void generateContextMenu();
|
||||
|
||||
@@ -856,10 +860,6 @@ private:
|
||||
);
|
||||
void moveAngleConstraint(Sketcher::Constraint*, int constNum, const Base::Vector2d& toPos);
|
||||
|
||||
/// returns whether the sketch is in edit mode.
|
||||
bool isInEditMode() const;
|
||||
//@}
|
||||
|
||||
/** @name signals*/
|
||||
//@{
|
||||
/// signals a tool change
|
||||
|
||||
Reference in New Issue
Block a user