Skip to content

Commit

Permalink
PartDesign: fix FeatureHole restoring
Browse files Browse the repository at this point in the history
Prevent unnecessary property touch on restore and undo/redo

Related realthunder/FreeCAD_assembly3#562
  • Loading branch information
realthunder committed Apr 8, 2021
1 parent 2fc1e02 commit 1da6f00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions src/Mod/PartDesign/App/FeatureHole.cpp
Expand Up @@ -720,8 +720,16 @@ Hole::Hole()

}

static inline bool _isRestoring(const App::Document *doc)
{
return !doc || doc->testStatus(App::Document::Restoring) || doc->isPerformingTransaction();
}

void Hole::updateHoleCutParams()
{
if (_isRestoring(getDocument()))
return;

std::string holeCutTypeStr = HoleCutType.getValueAsString();

// there is no cut, thus return
Expand Down Expand Up @@ -999,6 +1007,9 @@ double Hole::getThreadPitch()

void Hole::updateThreadDepthParam()
{
if (_isRestoring(getDocument()))
return;

std::string method(DepthType.getValueAsString());
double drillDepth;
if ( method == "Dimension" ) {
Expand All @@ -1022,24 +1033,17 @@ void Hole::updateThreadDepthParam()

void Hole::updateDiameterParam()
{
if (_isRestoring(getDocument()))
return;

// Diameter parameter depends on Threaded, ThreadType, ThreadSize, and ThreadFit

int threadType = ThreadType.getValue();
int threadSize = ThreadSize.getValue();
if (threadType < 0) {
// When restoring the feature it might be in an inconsistent state.
// So, just silently ignore it instead of throwing an exception.
if (isRestoring())
return;
if (threadType < 0)
throw Base::IndexError("Thread type out of range");
}
if (threadSize < 0) {
// When restoring the feature it might be in an inconsistent state.
// So, just silently ignore it instead of throwing an exception.
if (isRestoring())
return;
if (threadSize < 0)
throw Base::IndexError("Thread size out of range");
}
double diameter = threadDescription[threadType][threadSize].diameter;
double pitch = threadDescription[threadType][threadSize].pitch;
double clearance = 0.0;
Expand Down Expand Up @@ -1553,10 +1557,9 @@ short Hole::mustExecute() const
return ProfileBased::mustExecute();
}

void Hole::Restore(Base::XMLReader &reader)
void Hole::onDocumentRestored()
{
ProfileBased::Restore(reader);

ProfileBased::onDocumentRestored();
updateProps();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureHole.h
Expand Up @@ -103,7 +103,7 @@ class PartDesignExport Hole : public ProfileBased
} UTSClearanceDefinition;
static const UTSClearanceDefinition UTSHoleDiameters[22];

virtual void Restore(Base::XMLReader & reader);
virtual void onDocumentRestored();

virtual void updateProps();

Expand Down

0 comments on commit 1da6f00

Please sign in to comment.