Skip to content

Commit f633fa4

Browse files
authored
Introduce object freeze (FreeCAD#12580)
* Introduce object freeze * do nothing at property change
1 parent 028739d commit f633fa4

7 files changed

+321
-4
lines changed

src/App/DocumentObject.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,28 @@ void DocumentObject::touch(bool noRecompute)
213213
_pDoc->signalTouchedObject(*this);
214214
}
215215

216+
/**
217+
* @brief Set this document object freezed.
218+
* A freezed document object does not recompute ever.
219+
*/
220+
void DocumentObject::freeze()
221+
{
222+
StatusBits.set(ObjectStatus::Freeze);
223+
// use the signalTouchedObject to refresh the Gui
224+
if (_pDoc)
225+
_pDoc->signalTouchedObject(*this);
226+
}
227+
228+
/**
229+
* @brief Set this document object unfreezed.
230+
* A freezed document object does not recompute ever.
231+
*/
232+
void DocumentObject::unfreeze(bool noRecompute)
233+
{
234+
StatusBits.set(ObjectStatus::Freeze, false);
235+
touch(noRecompute);
236+
}
237+
216238
/**
217239
* @brief Check whether the document object is touched or not.
218240
* @return true if document object is touched, false if not.
@@ -240,6 +262,9 @@ void DocumentObject::enforceRecompute()
240262
*/
241263
bool DocumentObject::mustRecompute() const
242264
{
265+
if (StatusBits.test(ObjectStatus::Freeze))
266+
return false;
267+
243268
if (StatusBits.test(ObjectStatus::Enforce))
244269
return true;
245270

@@ -726,6 +751,9 @@ void DocumentObject::onBeforeChange(const Property* prop)
726751
/// get called by the container when a Property was changed
727752
void DocumentObject::onChanged(const Property* prop)
728753
{
754+
if (isFreezed())
755+
return;
756+
729757
if(GetApplication().isClosingAll())
730758
return;
731759

src/App/DocumentObject.h

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum ObjectStatus {
6767
PendingTransactionUpdate = 18, // mark that the object expects a call to onUndoRedoFinished() after transaction is finished.
6868
RecomputeExtension = 19, // mark the object to recompute its extensions
6969
TouchOnColorChange = 20, // inform view provider touch object on color change
70+
Freeze = 21, // do not recompute ever
7071
};
7172

7273
/** Return object for feature execution
@@ -177,6 +178,12 @@ class AppExport DocumentObject: public App::TransactionalObject
177178
bool isRestoring() const {return StatusBits.test(ObjectStatus::Restore);}
178179
/// returns true if this objects is currently removed from the document
179180
bool isRemoving() const {return StatusBits.test(ObjectStatus::Remove);}
181+
/// set this document object freezed (prevent recomputation)
182+
void freeze();
183+
/// set this document object unfreezed (and touch it)
184+
void unfreeze(bool noRecompute=false);
185+
/// returns true if this objects is currently freezed
186+
bool isFreezed() const {return StatusBits.test(ObjectStatus::Freeze);}
180187
/// return the status bits
181188
unsigned long getStatus() const {return StatusBits.to_ulong();}
182189
bool testStatus(ObjectStatus pos) const {return StatusBits.test(size_t(pos));}

src/Gui/CommandFeat.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,55 @@ bool StdCmdRandomColor::isActive()
120120
return (Gui::Selection().size() != 0);
121121
}
122122

123+
//===========================================================================
124+
// Std_ToggleFreeze
125+
//===========================================================================
126+
DEF_STD_CMD_A(StdCmdToggleFreeze)
127+
128+
StdCmdToggleFreeze::StdCmdToggleFreeze()
129+
: Command("Std_ToggleFreeze")
130+
{
131+
sGroup = "File";
132+
sMenuText = QT_TR_NOOP("Toggle freeze");
133+
static std::string toolTip = std::string("<p>")
134+
+ QT_TR_NOOP("Toggles freeze sate of the selected objects. A freezed object is not recomputed when its parents change.")
135+
+ "</p>";
136+
sToolTipText = toolTip.c_str();
137+
sStatusTip = sToolTipText;
138+
sWhatsThis = "Std_ToggleFreeze";
139+
sPixmap = "Std_ToggleFreeze";
140+
sAccel = "";
141+
eType = AlterDoc;
142+
}
143+
144+
void StdCmdToggleFreeze::activated(int iMsg)
145+
{
146+
Q_UNUSED(iMsg);
147+
getActiveGuiDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Toggle freeze"));
148+
149+
std::vector<Gui::SelectionSingleton::SelObj> sels = Gui::Selection().getCompleteSelection();
150+
151+
for (Gui::SelectionSingleton::SelObj& sel : sels) {
152+
App::DocumentObject* obj = sel.pObject;
153+
if (!obj)
154+
continue;
155+
156+
if (obj->isFreezed())
157+
obj->unfreeze();
158+
else
159+
obj->freeze();
160+
}
161+
162+
getActiveGuiDocument()->commitCommand();
163+
}
164+
165+
bool StdCmdToggleFreeze::isActive()
166+
{
167+
return (Gui::Selection().size() != 0);
168+
}
169+
170+
171+
123172

124173
//===========================================================================
125174
// Std_SendToPythonConsole
@@ -221,6 +270,7 @@ void CreateFeatCommands()
221270
CommandManager &rcCmdMgr = Application::Instance->commandManager();
222271

223272
rcCmdMgr.addCommand(new StdCmdFeatRecompute());
273+
rcCmdMgr.addCommand(new StdCmdToggleFreeze());
224274
rcCmdMgr.addCommand(new StdCmdRandomColor());
225275
rcCmdMgr.addCommand(new StdCmdSendToPythonConsole());
226276
}

src/Gui/Icons/Std_ToggleFreeze.svg

+201
Loading

src/Gui/Icons/resource.qrc

+1-3
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,8 @@
270270
<file>image-plane.svg</file>
271271
<file>image-scaling.svg</file>
272272
<file>VarSet.svg</file>
273+
<file>Std_ToggleFreeze.svg</file>
273274
</qresource>
274-
<!-- Demonstrating support for an embedded icon theme -->
275-
<!-- See also http://permalink.gmane.org/gmane.comp.lib.qt.general/26374 -->
276-
<!-- See also https://bugreports.qt.io/browse/QTBUG-75039 -->
277275
<qresource prefix="/icons/FreeCAD-default">
278276
<file>index.theme</file>
279277
</qresource>

src/Gui/Tree.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -5163,8 +5163,10 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
51635163
auto linked = obj->getLinkedObject(false);
51645164
bool external = object()->getDocument() != getOwnerDocument()->document() ||
51655165
(linked && linked->getDocument() != obj->getDocument());
5166+
bool freezed = pObject->isFreezed();
51665167

51675168
int currentStatus =
5169+
((freezed ? 0 : 1) << 5) |
51685170
((external ? 0 : 1) << 4) |
51695171
((object()->showInTree() ? 0 : 1) << 3) |
51705172
((pObject->isError() ? 1 : 0) << 2) |
@@ -5320,6 +5322,36 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
53205322
pxOn = BitmapFactory().merge(pxOn, pxExternal, BitmapFactoryInst::BottomRight);
53215323
}
53225324

5325+
if (freezed) {
5326+
static QPixmap pxFreeze;
5327+
if (pxFreeze.isNull()) {
5328+
// object is in freezed state
5329+
const char* const feature_freezed_xpm[] = {
5330+
"16 16 2 1",
5331+
" c None",
5332+
". c #00EEFF",
5333+
" . . . ",
5334+
" . ... . ",
5335+
" .. . .. ",
5336+
" .... . .... ",
5337+
" .. . .. ",
5338+
" . . . . .",
5339+
" . ... . ",
5340+
" ...............",
5341+
" . ... . ",
5342+
" . . . . .",
5343+
" .. . .. ",
5344+
" .... . .... ",
5345+
" .. . .. ",
5346+
" . ... . ",
5347+
" . . . ",
5348+
" "};
5349+
pxFreeze = QPixmap(feature_freezed_xpm);
5350+
}
5351+
pxOff = BitmapFactory().merge(pxOff, pxFreeze, BitmapFactoryInst::TopLeft);
5352+
pxOn = BitmapFactory().merge(pxOn, pxFreeze, BitmapFactoryInst::TopLeft);
5353+
}
5354+
53235355
icon.addPixmap(pxOn, QIcon::Normal, QIcon::On);
53245356
icon.addPixmap(pxOff, QIcon::Normal, QIcon::Off);
53255357

0 commit comments

Comments
 (0)