[Core] Fix for frozen status

A frozen object prevents the document to be saved
The frozen status propagates into object inheritance
A frozen sketch is no more editable
Transform and Placement can't be changed for a frozen object
The freeze icon is reduced
This commit is contained in:
Florian Foinant-Willig
2024-12-01 17:48:15 +01:00
committed by Chris Hennes
parent b6697c12eb
commit 1eb8496aae
4 changed files with 37 additions and 15 deletions

View File

@@ -242,7 +242,7 @@ void DocumentObject::freeze()
*/
void DocumentObject::unfreeze(bool noRecompute)
{
StatusBits.set(ObjectStatus::Freeze, false);
StatusBits.reset(ObjectStatus::Freeze);
touch(noRecompute);
}
@@ -307,6 +307,9 @@ const char* DocumentObject::getStatusString() const
const char* text = getDocument()->getErrorDescription(this);
return text ? text : "Error";
}
else if (isFreezed()){
return "Freezed";
}
else if (isTouched()) {
return "Touched";
}
@@ -795,13 +798,16 @@ App::Property* DocumentObject::addDynamicProperty(const char* type,
void DocumentObject::onBeforeChange(const Property* prop)
{
// Store current name in oldLabel, to be able to easily retrieve old name of document object
// later when renaming expressions.
if (prop == &Label) {
oldLabel = Label.getStrValue();
if (isFreezed() && prop != &Visibility) {
return;
}
if (_pDoc) {
// Store current name in oldLabel, to be able to easily retrieve old name of document object later
// when renaming expressions.
if (prop == &Label)
oldLabel = Label.getStrValue();
if (_pDoc){
onBeforeChangeProperty(_pDoc, prop);
}
@@ -830,7 +836,7 @@ void DocumentObject::onEarlyChange(const Property* prop)
/// get called by the container when a Property was changed
void DocumentObject::onChanged(const Property* prop)
{
if (isFreezed()) {
if (isFreezed() && prop != &Visibility) {
return;
}
@@ -1135,7 +1141,11 @@ DocumentObject* DocumentObject::getLinkedObject(bool recursive,
void DocumentObject::Save(Base::Writer& writer) const
{
if (this->isAttachedToDocument()) {
if (this->isFreezed()) {
throw Base::AbortException("At least one object is frozen, unable to save.");
}
if (this->isAttachedToDocument()){
writer.ObjectName = this->getNameInDocument();
}
App::ExtensionContainer::Save(writer);

View File

@@ -1577,7 +1577,8 @@ void StdCmdPlacement::activated(int iMsg)
bool StdCmdPlacement::isActive()
{
return Gui::Selection().countObjectsOfType(App::GeoFeature::getClassTypeId()) >= 1;
std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType(App::GeoFeature::getClassTypeId());
return (sel.size() == 1 && ! sel.front()->isFreezed());
}
//===========================================================================
@@ -1611,7 +1612,8 @@ void StdCmdTransformManip::activated(int iMsg)
bool StdCmdTransformManip::isActive()
{
return Gui::Selection().countObjectsOfType(App::GeoFeature::getClassTypeId()) == 1;
std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType(App::GeoFeature::getClassTypeId());
return (sel.size() == 1 && ! sel.front()->isFreezed());
}
//===========================================================================

View File

@@ -172,22 +172,27 @@ StdCmdToggleFreeze::StdCmdToggleFreeze()
void StdCmdToggleFreeze::activated(int iMsg)
{
Q_UNUSED(iMsg);
getActiveGuiDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Toggle freeze"));
std::vector<Gui::SelectionSingleton::SelObj> sels = Gui::Selection().getCompleteSelection();
Command::openCommand(QT_TRANSLATE_NOOP("Command", "Toggle freeze"));
for (Gui::SelectionSingleton::SelObj& sel : sels) {
App::DocumentObject* obj = sel.pObject;
if (!obj)
continue;
if (obj->isFreezed())
if (obj->isFreezed()){
obj->unfreeze();
else
for (auto child : obj->getInListRecursive())
child->unfreeze();
} else {
obj->freeze();
}
for (auto parent : obj->getOutListRecursive())
parent->freeze();
}
getActiveGuiDocument()->commitCommand();
}
Command::commitCommand();
}
bool StdCmdToggleFreeze::isActive()

View File

@@ -2987,6 +2987,11 @@ bool ViewProviderSketch::setEdit(int ModNum)
}
Sketcher::SketchObject* sketch = getSketchObject();
if(sketch->isFreezed()) {
return false; // Disallow edit of a frozen sketch
}
if (!sketch->evaluateConstraints()) {
QMessageBox box(Gui::getMainWindow());
box.setIcon(QMessageBox::Critical);