diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 708b6ea3b9..297ab2154b 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -213,6 +213,28 @@ void DocumentObject::touch(bool noRecompute) _pDoc->signalTouchedObject(*this); } +/** + * @brief Set this document object freezed. + * A freezed document object does not recompute ever. + */ +void DocumentObject::freeze() +{ + StatusBits.set(ObjectStatus::Freeze); + // use the signalTouchedObject to refresh the Gui + if (_pDoc) + _pDoc->signalTouchedObject(*this); +} + +/** + * @brief Set this document object unfreezed. + * A freezed document object does not recompute ever. + */ +void DocumentObject::unfreeze(bool noRecompute) +{ + StatusBits.set(ObjectStatus::Freeze, false); + touch(noRecompute); +} + /** * @brief Check whether the document object is touched or not. * @return true if document object is touched, false if not. @@ -240,6 +262,9 @@ void DocumentObject::enforceRecompute() */ bool DocumentObject::mustRecompute() const { + if (StatusBits.test(ObjectStatus::Freeze)) + return false; + if (StatusBits.test(ObjectStatus::Enforce)) return true; @@ -726,6 +751,9 @@ void DocumentObject::onBeforeChange(const Property* prop) /// get called by the container when a Property was changed void DocumentObject::onChanged(const Property* prop) { + if (isFreezed()) + return; + if(GetApplication().isClosingAll()) return; diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index b9b745ad54..a321f97370 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -67,6 +67,7 @@ enum ObjectStatus { PendingTransactionUpdate = 18, // mark that the object expects a call to onUndoRedoFinished() after transaction is finished. RecomputeExtension = 19, // mark the object to recompute its extensions TouchOnColorChange = 20, // inform view provider touch object on color change + Freeze = 21, // do not recompute ever }; /** Return object for feature execution @@ -177,6 +178,12 @@ public: bool isRestoring() const {return StatusBits.test(ObjectStatus::Restore);} /// returns true if this objects is currently removed from the document bool isRemoving() const {return StatusBits.test(ObjectStatus::Remove);} + /// set this document object freezed (prevent recomputation) + void freeze(); + /// set this document object unfreezed (and touch it) + void unfreeze(bool noRecompute=false); + /// returns true if this objects is currently freezed + bool isFreezed() const {return StatusBits.test(ObjectStatus::Freeze);} /// return the status bits unsigned long getStatus() const {return StatusBits.to_ulong();} bool testStatus(ObjectStatus pos) const {return StatusBits.test(size_t(pos));} diff --git a/src/Gui/CommandFeat.cpp b/src/Gui/CommandFeat.cpp index e80dae50f7..31dcb0a3e4 100644 --- a/src/Gui/CommandFeat.cpp +++ b/src/Gui/CommandFeat.cpp @@ -120,6 +120,55 @@ bool StdCmdRandomColor::isActive() return (Gui::Selection().size() != 0); } +//=========================================================================== +// Std_ToggleFreeze +//=========================================================================== +DEF_STD_CMD_A(StdCmdToggleFreeze) + +StdCmdToggleFreeze::StdCmdToggleFreeze() + : Command("Std_ToggleFreeze") +{ + sGroup = "File"; + sMenuText = QT_TR_NOOP("Toggle freeze"); + static std::string toolTip = std::string("
") + + QT_TR_NOOP("Toggles freeze sate of the selected objects. A freezed object is not recomputed when its parents change.") + + "
"; + sToolTipText = toolTip.c_str(); + sStatusTip = sToolTipText; + sWhatsThis = "Std_ToggleFreeze"; + sPixmap = "Std_ToggleFreeze"; + sAccel = ""; + eType = AlterDoc; +} + +void StdCmdToggleFreeze::activated(int iMsg) +{ + Q_UNUSED(iMsg); + getActiveGuiDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Toggle freeze")); + + std::vector