Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sketcher: Fix Issue 6283 #9328

Merged
merged 2 commits into from
Apr 20, 2023
Merged

Conversation

abdullahtahiriyo
Copy link
Contributor

No description provided.

===================================================

This commit exposes the scale factor used.
=========================================

The scaling factor used  was the one of the ViewProviderSketch, however ZoomTranslation uses its own scaling factor.

fixes FreeCAD#6283
@github-actions github-actions bot added the WB Sketcher Related to the Sketcher Workbench label Apr 20, 2023
@freecadci
Copy link

pipeline status for feature branch PR_9328. Pipeline 843783692 was triggered at e786999. All CI branches and pipelines.

}

SoZoomTranslation::SoZoomTranslation()
SoZoomTranslation::SoZoomTranslation(): scaleFactor(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default 0 for scaleFactor might not be the best idea, especially if there is division involved. 1 sounds better, depending on what the definition is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The objective is to store whatever the ZoomTranslation calculates.

Retrieving the scaleFactor before (internal) calculation will always result in a wrong value. This means that 1 will be as wrong as 0.

There is no risk of exception as the the scale factor is multiplied to a relative translation.

Then, perhaps 0 best serves a user of the client code to realise the mistake, if trying to retrieve a scale before the node is actually in running in the scenegraph.

@@ -96,7 +96,7 @@ void SoZoomTranslation::doAction(SoAction * action)
SbVec3f absVtr = this->abPos.getValue();
SbVec3f relVtr = this->translation.getValue();

float sf = this->getScaleFactor(action);
float sf = this->calculateScaleFactor(action);
// For Sketcher Keep Z value the same
relVtr[0] = (relVtr[0] != 0) ? sf * relVtr[0] : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as relVtr[0] *= sf;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are indeed right. But I did not write that line...

I have also seen other things I do not like from this class (such as a hardcoded 5 in calculateScaleFactor).

I have fought the temptation to make a full review of SoZoomTranslation internal workings at this time.

Just adding a way to retrieve the scaling factor it uses, because that is what is necessary to fix the actual bug of the issue.

If you have time to do a full review and wish to do it, feel free to make a PR. It is welcome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe eventually. We could create an issue about it, but then again we'd need as many as the number of files qe have!

@@ -116,7 +116,7 @@ void SoZoomTranslation::getMatrix(SoGetMatrixAction * action)
SbVec3f absVtr = this->abPos.getValue();
SbVec3f relVtr = this->translation.getValue();

float sf = this->getScaleFactor(action);
float sf = this->calculateScaleFactor(action);
// For Sketcher Keep Z value the same
relVtr[0] = (relVtr[0] != 0) ? sf * relVtr[0] : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment.

@abdullahtahiriyo abdullahtahiriyo merged commit 11c76c9 into FreeCAD:master Apr 20, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WB Sketcher Related to the Sketcher Workbench
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants