[New feature] Sketcher Constrain Contextually

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by paddle »

Sorry I did not tried to read through the alst 2 pages of messages as it ended up with 'So yes, everyone is talking in circles here' so I did not tried :)

So I've been busy going on the development today and just pushed a commit that brings :
- Sketch Chamfer tool.
- Support of fillet/chamfer in ToolSettings. Which enables us to have only 2 Tools in the dropdown : Fillet and Chamfer. Fillet with point has been removed and keeping the point can be done using a checkbox in the toolsetting.
Also the tool settings enables to make more than 1 lines for polychamfers. And to create inward fillet/polychamfers.
Also it let you set the radius if you want to.

Overall it's really pretty cool.
One thing missing that that I'd like the "Preserve Corner Point" checkbox setting to be stored as a preference for the user. Such that if user always use it then it stays put. Currently the checkbox reset everytime.
I'm checking TaskSketcherGeneral.cpp and I found 2 things that could be doing this saving checkbox setting :

Code: Select all

void SketcherGeneralWidget::saveSettings()
{
    ui->checkBoxShowGrid->onSave();
    ui->gridSize->onSave();
    ui->checkBoxGridSnap->onSave();
    ui->checkBoxAutoconstraints->onSave();
    ui->checkBoxRedundantAutoconstraints->onSave();

    saveOrderingOrder();
}
void SketcherGeneralWidget::loadSettings()
{
    ui->checkBoxShowGrid->onRestore();
    ui->gridSize->onRestore();
    if (ui->gridSize->rawValue() == 0) { ui->gridSize->setValue(10.0); }
    ui->checkBoxGridSnap->onRestore();
    ui->checkBoxAutoconstraints->onRestore();
    ui->checkBoxRedundantAutoconstraints->onRestore();

    loadOrderingOrder();
}
But also in the class activation :

Code: Select all

        widget->checkGridSnap(sketchView->GridSnap.getValue());
        widget->enableGridSettings(sketchView->ShowGrid.getValue());
        widget->checkAutoconstraints(sketchView->Autoconstraints.getValue());
        widget->checkAvoidRedundant(sketchView->AvoidRedundant.getValue());
        widget->enableAvoidRedundant(sketchView->Autoconstraints.getValue());
Someone know which should be used? The second seem to add this setting only until program is closed. I need to have a deeper look

If you want to build and try :)
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by paddle »

Ok I found how to make a permanent setting for the checkbox. It's actually very simple.
In .ui file you need to declare those two properties prefEntry and prefPath

Code: Select all

<item>
    <widget class="Gui::PrefCheckBox" name="checkBoxPreserveFilletChamferCorner">
     <property name="enabled">
      <bool>true</bool>
     </property>
        <property name="toolTip">
         <string>Preserve corner and most constraints when using Fillet or Chamfer</string>
        </property>
        <property name="text">
         <string>Preserve Fillet or Chamfer corner and most constraints</string>
        </property>
        <property name="checked">
         <bool>false</bool>
        </property>
        <property name="prefEntry" stdset="0">
         <cstring>PreserveFilletChamferCorner</cstring>
        </property>
        <property name="prefPath" stdset="0">
         <cstring>Mod/Sketcher/General</cstring>
        </property>
    </widget>
   </item>
   
   This may also be required at the end before <resources/>: 
   
 <tabstops>
  <tabstop>checkBoxPreserveFilletChamferCorner</tabstop>
 </tabstops>
   
Which will let you access the setting from anywhere in the code with

Code: Select all

    ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
    setEscapeButtonEnabled(hGrp->GetBool("PreserveFilletChamferCorner", true));
And on the .cpp side you need to call the function onSave on the checkbox when the checkbox is toggled. So just connect the signal.

Code: Select all

SketcherToolWidget::SketcherToolWidget(QWidget *parent, ViewProviderSketch* sketchView)
  : QWidget(parent), ui(new Ui_TaskSketcherTool), sketchView(sketchView)
{
    ui->setupUi(this);
    connect(ui->checkBoxPreserveFilletChamferCorner, SIGNAL(toggled(bool)),
        this, SLOT(emitTogglePreserveFilletChamferCorner(bool)));
}

void SketcherToolWidget::emitTogglePreserveFilletChamferCorner(bool val) {
    ui->checkBoxPreserveFilletChamferCorner->onSave();
}
User avatar
PedjaS
Posts: 147
Joined: Sat Jan 18, 2020 6:35 pm

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by PedjaS »

I am delighted to see this! Excellent work. This was really needed improvement on user interface.

I did not notice mention on making tangent constraint among two circles. It defaults to equal constraint.

That is not only situation when application cannot recognize what constraint to offer based on context. It is definitely needed that user may choose on his own. Maybe middle button on the mouse may be used to flip through the possible constraints or simply popup menu with possible constraints listed so he can chose from that.
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by paddle »

PedjaS wrote: Wed Jul 20, 2022 10:17 pm I am delighted to see this! Excellent work. This was really needed improvement on user interface.

I did not notice mention on making tangent constraint among two circles. It defaults to equal constraint.

That is not only situation when application cannot recognize what constraint to offer based on context. It is definitely needed that user may choose on his own. Maybe middle button on the mouse may be used to flip through the possible constraints or simply popup menu with possible constraints listed so he can chose from that.
You can cycle through available contraints using right-Shift (or try ctrl or M I'm not sure which we used at the end on that branch)
User avatar
ifohancroft
Posts: 205
Joined: Fri May 31, 2019 11:25 pm
Location: Sofia, Bulgaria
Contact:

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by ifohancroft »

This tool is great! I am sure many people would love it! Good job!

As long as it doesn't replace the separate constrain tools, I'm up for it. I don't want it to replace the separate constraints because I find the workflow of just a context constrain tool slow and tedious. For example: Most often, I click on a line or other geometry, then click on the constrain tool (the opposite works as well if you are into that sort of thing: I.e. selecting the constraint tool and clicking the geometry with it), however, when having just a contextual constrain tool (like in OnShape for example) you can't do that. You must select the constraint tool first and click with the geometry with it. One of the main reasons why I love FreeCAD and hate all commercial CADs I've had to use so far (Alibre, Fusion 360 and OnShape). Even if the tool was made so you can click the geometry and then click it, it still shouldn't replace the other tools. I hate spending time fighting with the tool when it's trying to guess what I want to do. Yes, I am slower with such a tool than with separate constraints. The ability to select the current geometries with hot keys (regardless of whether you have clicked the geometry before that or not) must also remain the way it currently is.
I like making, breaking and modding stuff, using a soldering iron, code or both. https://ifohancroft.com
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by adrianinsaval »

Yes, these automated tools are generally useful but if they fully replace the regular commands it becomes a hurdle the moment you need something it can't guess.
freedman
Veteran
Posts: 3440
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by freedman »

ifohancroft » Thu Jul 21, 2022 3:51 pm
As long as it doesn't replace the separate constrain tools, I'm up for it.
+1
It normally gets codded like that but I think it is worth saying.

Adding anything new has a risk of breaking existing/working code and Sketcher is certainly the backbone of FreeCAD, we all like that code to be tight.
User avatar
ifohancroft
Posts: 205
Joined: Fri May 31, 2019 11:25 pm
Location: Sofia, Bulgaria
Contact:

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by ifohancroft »

One thing that may have been already mentioned, but I couldn't read all 14 pages:

When you use the tool and it creates a dimension constraint, the value shouldn't be in the panel on the left.

It should work like the separate constraint tools. I.e. after you click and it creates a dimensional constraint, when you click to confirm the constraint, you should get the popup window for the value. That way, you probably wouldn't even need to code the value window separate, but can probably reuse it from the other dimensional constraints. I.e. I'm guessing there's a method that gets called when a dimensional constraint is set that shows it, that you can probably call when clicking to confirm the constraint if it's dimensional.
I like making, breaking and modding stuff, using a soldering iron, code or both. https://ifohancroft.com
bleber
Posts: 259
Joined: Thu Jun 30, 2016 5:12 pm

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by bleber »

If it implemented, I think that a speeding method to launch these function is with click with right mouse key on geometry (line/circle/diameter/...) and drag to launch the needed constraint.

Actually a right mouse click opens a menu, but the specific action to launch the contextually constraint will be: put the mouse pointer on the geometry (it changes the color under the mouse) and drag with right key pressed, a very specific action that indicates that you want a constraint not the menu.
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: NEW FEATURE ! Sketcher Constrain Contextually

Post by paddle »

Hey guys,

Just to let you know that I picked this up again, rebased, reviewed etc and posted a new PR for this :
https://github.com/FreeCAD/FreeCAD/pull/9810

Cheers
Post Reply