Reimplementing constraint solver

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Sat May 02, 2020 7:59 am ...
I was thinking of implementing the shape equality constraint.

However this constraint is defined differently:
1. There are no transforms of 3D, not even a generic do nothing one.
2. There are no 3D ParaShapes.
3. Thus it is defined in terms of ParaGeometry (3D) instead of ParaShape (2D).

Code: Select all

class FCSExport ConstraintEqualShape : public Constraint
{
public: //data
    HParaGeometry geom1;
    HParaGeometry geom2;
    bool equalTrim = false;

My questions relate to what the solution should be at this moment: Are you planning to extend 1 and 2 to 3D in the short-term? Should I stay away of this constraint? Should I implement this one in terms of Geometry and not in terms of Shape (which is funny when it is called EqualShape)?

EDIT: I have implemented equality constraint based on Geometry, not Shape, this is without transformations.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

Apparently there is no constraint supporting radius/diameter either.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

I have pushed all I had locally to the branch.

Congratulations DeepSOIC!

Everything implemented in the Sketcher so far works:
Screenshot_20200502_200512.png
Screenshot_20200502_200512.png (24.49 KiB) Viewed 1697 times
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

I have implemented the Arc of Circle in FCSSketch.

I am running into issues relating to the CCW emulation and makeRules.

I have pushed what I have to the branch.

Three places in FCSSketch deal with this:

Code: Select all

int FCSSketch::addArc(const Part::GeomArcOfCircle &arc, bool fixed)
{
    // create our own copy
    GeomArcOfCircle *arcc = static_cast<GeomArcOfCircle*>(arc.clone());

    Base::Vector3d center = arcc->getCenter();
    double radius         = arcc->getRadius();

    Base::Vector3d startPnt = arcc->getStartPoint(/*emulateCCW=*/true);
    Base::Vector3d endPnt   = arcc->getEndPoint(/*emulateCCW=*/true);

Code: Select all

int FCSSketch::solve(void)
{
   ...

    for(auto &g : LineSegments)
        sys->addConstraint(g->makeRuleConstraints());

    for(auto &g : Arcs)
        sys->addConstraint(g->makeRuleConstraints());
and

Code: Select all

bool FCSSketch::updateGeometry()
{
     ...
     else if (it->type == GeoType::Arc) {
                GeomArcOfCircle *aoc = static_cast<GeomArcOfCircle*>((*it).geo.get());
                aoc->setCenter(Vector3d(Points[it->midPointId]->x.savedValue(),
                                         Points[it->midPointId]->y.savedValue(),
                                         0.0)
                               );
                aoc->setRadius(Arcs[it->index]->radius.savedValue());
                aoc->setRange(Arcs[it->index]->u0.savedValue(), Arcs[it->index]->u1.savedValue(), true);
            } 
getPoint and setRange have the option of CCW emulation.

If I remove the makeRuleConstraints() for arcs in solve().
1. With CCW=true in addArc() and updateGeometry() The arc that is created is not the one I draw (unless it is in the first quadrant)
2. With CCW=false in addArc() the arc is the one I draw.
3. Obviously when I can add a coincident constraint endpoint of the arc to a line, the times it works, only the line moves but not to make connection (somehow right because it does not have endofarc rules)

However, if I create the rule constraints:
1. With CCW=true in addArc() the arc is not even created, LM indicates step too small. It appears a conflicting constraint problem that does not converge.
2. With CCW=false the arc is created, but no coincidence on endpoint can be added with the issue of LM being too small.

Hopefully, you will have an idea of what the issue is. I remember you had an example with arcs of circle working from Python, so it should work. I do not get why it does not.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

Excellent progress, Abdullah!
Sorry, I've been away, moving to my countryhouse.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

abdullah wrote: Sun May 03, 2020 2:10 pm If I remove the makeRuleConstraints() for arcs in solve().
1. With CCW=true in addArc() and updateGeometry() The arc that is created is not the one I draw (unless it is in the first quadrant)
You don't set parameter range of FCS arc when converting from Part arc, it seems. Then, you read out that very parameter range when converting back to Part geometry. This is to be expected when you don't add the rule constraints, which keep endpoint coordinates in sync with parameter range. I have not investigated it any further, yet.

abdullah wrote: Sun May 03, 2020 2:10 pm However, if I create the rule constraints:
1. With CCW=true in addArc() the arc is not even created, LM indicates step too small. It appears a conflicting constraint problem that does not converge.
2. With CCW=false the arc is created, but no coincidence on endpoint can be added with the issue of LM being too small.
I will look into that later...
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

abdullah wrote: Sat May 02, 2020 5:43 pm My questions relate to what the solution should be at this moment: Are you planning to extend 1 and 2 to 3D in the short-term? Should I stay away of this constraint? Should I implement this one in terms of Geometry and not in terms of Shape (which is funny when it is called EqualShape)?
I think the constraint is the way it is meant to be. Shape equality implies that transform is irrelevant.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

I have fixed the arc of circle. It was caused by difficult-to-discover bug in ConstraintSolver - a missing update() call for constraint objects.

I have quickly made a change that exposes solver subsystem as sksys variable in py console: https://github.com/DeepSOIC/FreeCAD-ell ... a5e70620d9
May come in handy again, so I saved it to a branch.

EDIT: edited the commit
Last edited by DeepSOIC on Tue May 05, 2020 10:54 pm, edited 1 time in total.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Mon May 04, 2020 6:46 pm
abdullah wrote: Sat May 02, 2020 5:43 pm My questions relate to what the solution should be at this moment: Are you planning to extend 1 and 2 to 3D in the short-term? Should I stay away of this constraint? Should I implement this one in terms of Geometry and not in terms of Shape (which is funny when it is called EqualShape)?
I think the constraint is the way it is meant to be. Shape equality implies that transform is irrelevant.
:?:

Then I have misunderstood the concept of transformation.

As it is not necessary know, I will get it when there is an actual example. No problem there ;)
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Sun May 03, 2020 11:33 pm Excellent progress, Abdullah!
Sorry, I've been away, moving to my countryhouse.
Ahh!!! Lockdown!!! Time to enjoy nature... when you can actually leave for the contryside ;)
Post Reply