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: Arc to Other distance constraint #9166

Merged
merged 8 commits into from Dec 17, 2023

Conversation

FlachyJoe
Copy link
Contributor

Propagate circles distance constraint to arcs.

@github-actions github-actions bot added the WB Sketcher Related to the Sketcher Workbench label Apr 2, 2023
@FlachyJoe
Copy link
Contributor Author

It works but constraints can be shown in strange placements
image

NB : it's also the case for Tangent Constraint
image

@adrianinsaval
Copy link
Member

Is there a way of moving the angle of the constraint after placing it?

@FlachyJoe
Copy link
Contributor Author

FlachyJoe commented Apr 3, 2023

@adrianinsaval Angle is defined by the shorter distance between circles so it can't move.
In the concentric case it could but I don't know how to implement this.
Another solution I see is to draw a thin constraint-colored circle below the arc as an helper.

@freecadci
Copy link

pipeline status for feature branch PR_9166. Pipeline 826752983 was triggered at 94ac740. All CI branches and pipelines.

@FlachyJoe
Copy link
Contributor Author

#9257 fixes the display problems
image

@abdullahtahiriyo abdullahtahiriyo added the 0.22 for the v0.22 development cycle label May 7, 2023
@freecadci
Copy link

pipeline status for feature branch PR_9166. Pipeline 903564958 was triggered at 581e64a. All CI branches and pipelines.

@PaddleStroke
Copy link
Contributor

PaddleStroke commented Jun 22, 2023

Why is this not going in 0.21 ? As circle to circle distance was introduced in 0.21 it would make sense that this goes in as well.

Edit: It's a known issue: (Besides, I can't seem to be able to use circle distances when the tool is activated first (before selection).
If I select the circles first, then start the distance tool, then it works.
But if I try to start the tool, then select circles, the circles don't get selected.
Using windows10, master from 1 day ago.
Do you have this behavior on your side? Should I create an issue for it?)

@FlachyJoe
Copy link
Contributor Author

@PaddleStroke this PR requires #9703

@PaddleStroke
Copy link
Contributor

This one could go in as well Imo. It's not a big change and would make things more consistent rather than having half of circle-circle distance merged in 0.21.

@adrianinsaval
Copy link
Member

I tend to agree but we would need someone to review it.

@PaddleStroke
Copy link
Contributor

I can give it a go tomorrow if my review is deamed sufficient.
#9703 is mostly ui stuff similar to what I've done many time so I should be able to review.
This PR is probably a lot of copy paste of the circle-circle constrain, so I think it'll ok for me.

@PaddleStroke
Copy link
Contributor

#9703 merged so this one can become a not-draft Pull request

Copy link
Contributor

@PaddleStroke PaddleStroke left a comment

Choose a reason for hiding this comment

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

Code looks good to me.
Main complain is that the syntax changes should not belong to this PR and should be a separate PR.
Without the syntax changes this PR would be like 150 lines. Here it's 1500 ... It makes reviewing much more difficult and long.

I have not built to test.

src/Mod/Sketcher/Gui/Utils.cpp Outdated Show resolved Hide resolved
src/Mod/Sketcher/Gui/ViewProviderSketch.cpp Outdated Show resolved Hide resolved
src/Mod/Sketcher/Gui/Utils.cpp Outdated Show resolved Hide resolved
src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp Outdated Show resolved Hide resolved
src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp Outdated Show resolved Hide resolved
@FlachyJoe FlachyJoe marked this pull request as ready for review August 26, 2023 10:13
@chennes
Copy link
Member

chennes commented Aug 28, 2023

@FlachyJoe can you resolve those conflicts?

@FlachyJoe
Copy link
Contributor Author

@PaddleStroke Do I need to add anything to make this work with the Constrain Contextual implementation?

@PaddleStroke
Copy link
Contributor

PaddleStroke commented Aug 30, 2023 via email

@FlachyJoe
Copy link
Contributor Author

FlachyJoe commented Aug 31, 2023

do you plan to do point to arc as well? And line to arc ?

Yes I'll do it. I maybe can add these as commit to this PR so all the arc stuff come in the same time.

EDIT : @PaddleStroke should I allow you to push in my arc-distance branch so the required Contextual code will be merged together?

@PaddleStroke
Copy link
Contributor

Yes I'll do it. I maybe can add these as commit to this PR so all the arc stuff come in the same time.

Good idea.

should I allow you to push in my arc-distance branch so the required Contextual code will be merged together?

That may make things a bit complex especially since there's already open PR touching Sketcher_Dimension (and one that changes the arc stuff in it). So just focus on adding the constraints and once that merge we'll add support for them in Dimension so that we don't have conflicts.

@FlachyJoe FlachyJoe marked this pull request as draft September 1, 2023 10:36
@FlachyJoe
Copy link
Contributor Author

Switch back to Draft until arc-line and arc-point commits are ready.

@abdullahtahiriyo
Copy link
Contributor

At it now.

int Sketch::addDistanceConstraint(int geoId1, int geoId2, double* value, bool driving)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);

if (Geoms[geoId1].type == Circle) {
GCS::Circle *c1, *c2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, we declare variables inside the scope where they are necessary.

I do understand that you can make use of c1 in the two blocks (if and else). However, in practice it is not even the same "c1", but just a circle. In the case of c2, it is not even necessary in the first block.

}
GCS::Line* l = &Lines[Geoms[geoId2].index];
int tag = ++ConstraintsCounter;
GCSsys.addConstraintC2LDistance(*c1, *l, value, tag, driving);
Copy link
Contributor

Choose a reason for hiding this comment

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

And if c1 is not either a circle or an arc, then we pass an uninitialised c1 to addConstraintC2LDistance...

else if (Geoms[geoId2].type == Arc) {
c2 = &Arcs[Geoms[geoId2].index];
}
if (c1 == nullptr || c2 == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we are relying on c1 being nullptr if it was not assigned... however, it is not for granted that a pointer is initialised with nullptr.

radius2 = circleSeg2->getRadius();
center2 = circleSeg2->getCenter();
}
if (radius1 == 0.0 || radius2 == 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 code does not show intent clearly. It relies on what is supported now for edges and the fact that they may have radii.

The whole block is heavy to read because what is written is implied rather than explicit. The branching is not very well structured either... we should look into recoding this.

@@ -4274,6 +4253,45 @@ void CmdSketcherConstrainDistance::activated(int iMsg)

return;
}
double ActDist = 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.

Splitting the block of circle-circle with the circle-line is a little bit awkward.

@@ -815,61 +814,75 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
case DistanceY: {
assert(Constr->First >= -extGeoCount && Constr->First < intGeoCount);
Base::Vector3d pnt1(0., 0., 0.), pnt2(0., 0., 0.);
pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);
Copy link
Contributor

Choose a reason for hiding this comment

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

Then pnt1 can also be directly initialised to this.

pnt1.ProjectToLine(
ct - l2p1,
l2p2 - l2p1); // project on the line translated to origin
if (isCircle(*geo1) || isArcOfCircle(*geo1)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This code keeps being repeated and could be refactored.


point1 = circle1->getCenter();
point2 = circle2->getCenter();
if (geom1->is<Part::GeomCircle>()) {
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 again the repeated code of above.

if (Constr->FirstPos != Sketcher::PointPos::none){ // circular to point distance
Base::Vector3d ct;
double rad = 0.0;
if (isCircle(*geo2)){
Copy link
Contributor

Choose a reason for hiding this comment

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

Idem.

@abdullahtahiriyo
Copy link
Contributor

For fixing the issues above, I provide some commits:
https://github.com/abdullahtahiriyo/FreeCAD_sf_master/commits/arc-distance

However, this branch heavily conflicts with master because of some changes brought to how to represent angles.

I would propose:

  • you take a look to my fixes and see if you agree. If you do, just cherry-pick them into your branch.
  • you then need to address the conflicts.
  • because the conflicts do not seem straight-forward, we should do some testing after solving them.

Does it sound ok?

@FlachyJoe
Copy link
Contributor Author

@abdullahtahiriyo done

@abdullahtahiriyo
Copy link
Contributor

Thanks for the correction in the refactored function with the wrong type cast.

I will merge this.

We should monitor the change to make distances negative possible. I have done some testing, but the tests are not exhaustive. I think there will not be unintended effects for existing sketches, but I definitely want to hear about it if anybody realises.

With respect to sketching stability:

I only want to note here that I am unsure about how stable sketches using this construct will be (also the same goes for circle), due to the flipping that may occur:

image

image

But that, I think is a matter of learning from it.

@abdullahtahiriyo abdullahtahiriyo merged commit df32ad2 into FreeCAD:main Dec 17, 2023
9 checks passed
@FlachyJoe
Copy link
Contributor Author

Thank you @abdullahtahiriyo.
@PaddleStroke you can now upgrade Contextual Dimensions.

@PaddleStroke
Copy link
Contributor

Great work guys ! I will implement in sketcher_dimension asap.

@PaddleStroke
Copy link
Contributor

PaddleStroke commented Dec 20, 2023

Point to line distance is broken. I am not sure but this might be this PR that introduced this problem.
See discussion : https://forum.freecad.org/viewtopic.php?t=83649

@FlachyJoe
Copy link
Contributor Author

@PaddleStroke thank you to show this.
The problem was with the constraint display:
image

Fixed by #11784

@PaddleStroke
Copy link
Contributor

Ah interesting. Great thanks for the quick fix !

@maxwxyz
Copy link
Collaborator

maxwxyz commented Dec 24, 2023

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

9 participants