Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by mariwan »

Sorry for not being so clear:
1- The widget is in
https://github.com/MariwanJ/Design456/b ... _widget.py

2-The tool i mentioned is in :
https://github.com/MariwanJ/Design456/b ... endEdge.py

I hope you find them :)
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by paullee »

mariwan wrote: Thu Dec 02, 2021 7:50 pm Sorry for not being so clear:
1- The widget is in
https://github.com/MariwanJ/Design456/b ... _widget.py

2-The tool i mentioned is in :
https://github.com/MariwanJ/Design456/b ... endEdge.py

I hope you find them :)
Thanks for the pointer :D
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by mariwan »

paullee wrote: Sat Dec 04, 2021 6:08 pm
mariwan wrote: Thu Dec 02, 2021 7:50 pm Sorry for not being so clear:
1- The widget is in
https://github.com/MariwanJ/Design456/b ... _widget.py

2-The tool i mentioned is in :
https://github.com/MariwanJ/Design456/b ... endEdge.py

I hope you find them :)
Thanks for the pointer :D
But please notice the points below:
1-The 3arrows widget is not totally finished. I am working on it. I need to figure out how I make the rotation calculation and math good.
2-There might be some bugs. I am using the tool for rotating the face (Design456_ExtendFAce tool).. during this week I should be able to finalize the widget and the tool.
3-When I made the arrows, I didn't thought about making it to scale .. i.e the needed to be 1mm long and at the origin. Unfortunately the drawing are longer and In my code I scale them in the drawing to return them back to 1mm .. and in the widget (not drawing file) I scale them to the need of the tool. So, Scale them in your widget to the size you need for both X,Y and Z .. you can scale only one of the axis or as you wish.
4-You have several type of arrows .. Choose the one you want or make your own. I have a post about how you can convert an SVG file from inkscape to FreeCAD to COIN3D to python code.
Hope that will help you. Let me know if you want any help.
Regards,
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by paullee »

Thanks again for more information :D
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by mariwan »

A quick Info about My WB:
All Angles used in my WB are (Degrees) .. I know that some where they are radians and some where else are degrees. But in my WB it is only degrees.
Coin3D uses radians, and I convert the radians in my FR_WIDGET toolkit so you don't get problem there.
Another thing that I use in my FR_WIDGET toolkit .. To rotate the widget, specially when there are 3 Axis .. I use a tuple of three angles as a per-initialization of the rotation. each value is only an angle for each axis. The axis are hard coded inside the code.
Normally COIN3D and even FreeCAD uses the (coin.SbVec3f()/App.Vector(x,y,z)) as an axis and an radians angle.. But in my widget I do two things
1-A 3 angels tuple used to rotate each axis separately to the other. First X, and the result is rotated by Y axis and the result of Y axis is rotated by Z axis. This allow you to specify exactly multiple rotation as a setup for the widget.
2-Another rotation which is similar to FreeCAD and normal COIN3D .. i.e. three float values and an angle (they are in a tuple list) .. this one will acts like normal you rotate the shapes in FreeCAD. This one controls all other rotations by rotating the whole widget to the given axis+angle.
Hope it is clear even it is little bit complicated.

Here is an example

Code: Select all

               self.w_XsoSeparator = draw_2Darrow(App.Vector(self.w_vector[0].x +
                                                              self.distanceBetweenThem[0],
                                                              self.w_vector[0].y,
                                                              self.w_vector[0].z),
                                                   # default FR_COLOR.FR_RED
                                                   self.w_PadAxis_color[0], self.w_Scale,
                                                   self.DrawingType, self.Opacity,
                                                   [0.0, 90.0, 0.0])    #pre-Rotation # RED
                self.w_YsoSeparator = draw_2Darrow(App.Vector(self.w_vector[0].x,
                                                              self.w_vector[0].y +
                                                              self.distanceBetweenThem[1],
                                                              self.w_vector[0].z),
                                                   # default FR_COLOR.FR_GREEN
                                                   self.w_PadAxis_color[1], self.w_Scale,
                                                   self.DrawingType, self.Opacity,
                                                   [0.0, 90.0, 90.0])  #pre-Rotation GREEN
                self.w_ZsoSeparator = draw_2Darrow(App.Vector(self.w_vector[0].x,
                                                              self.w_vector[0].y,
                                                              self.w_vector[0].z +
                                                              self.distanceBetweenThem[2]),
                                                   # default FR_COLOR.FR_BLUE
                                                   self.w_PadAxis_color[2], self.w_Scale,
                                                   self.DrawingType, self.Opacity,
                                                   [0.0, 0.0, 0.0])  #pre-Rotation BLUE
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by mariwan »

Bug hunting:
During the time I was planning to make a new 2D-3Arrows with rotation pad for the FaceExtend (Tweak), I found serious bugs in several COIN3D widgets that affected many tools.
Handle function (related to callbacks) was not correct %100 and sometime didn't work at all .. For example SmartDirectScale was not working..
It was working at some stage but not when I tried last days.
Now, many are fixed. I found also the way to make the arrows move smoother and more accurately (not fixed for all tools - but soon will be fixed).
I apologies to anyone tried to use the tools and didn't work for them.
I hope soon these base widgets get a stable version that developing them will be just an easy task (copy-paste).
Development is continuing by daily basis.. Just it is HUGE!! The good news is that I know many many things that I didn't know before. And solutions for many problems are available. I just need time to write down them.
Regards,
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by mariwan »

There are some improvements, now the extrusion value is shown with the arrows.
Mouse movement is better for many tools.
Please keep in mind, sometimes when I need to improve a COIN3D widget, it affects other tools. For that reason, it could happen that another tool can get a problem.
I hope, soon the FR_WIDGET become more stable.
Note:
As I mentioned before, Chamfer and Fillet are not so stable .. not due to my WB .. It is OCC's problem. It can crashes due to a high value of them.
phpBB [video]
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by mariwan »

At the end.
Many days I try to figure out how to convert mouse-position to angle. FLTK uses a way of calculating the angle which I used in the beginning but it is not correct. Even when I used the Fl_Dial I discovered that it wasn't working so well.

Code: Select all

int Fl_Dial::handle(int event, int X, int Y, int W, int H) {
...
  case FL_DRAG: {
    int mx = (Fl::event_x()-X-W/2)*H;
    int my = (Fl::event_y()-Y-H/2)*W;
    printf("mx,my %i %i\n", mx, my);
    if (!mx && !my) return 1;
    double angle = -atan2((float)-my, (float)mx)*180/M_PI;
    double oldangle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
    while (angle < oldangle-180) angle += 360;
    while (angle > oldangle+180) angle -= 360;
    printf("angle = %f\n", angle);

    double val;
    if ((a1<a2) ? (angle <= a1) : (angle >= a1)) {
      val = minimum();
    } else if ((a1<a2) ? (angle >= a2) : (angle <= a2)) {
      val = maximum();
    } else {
      val = minimum() + (maximum()-minimum())*(angle-a1)/(a2-a1);
    }
    handle_drag(clamp(round(val)));
  ...
  
It is difficult to implement it (when you see the code it is simple) but thinking how all those conditions should work wasn't easy.
Anyway, it is working now.

The old wheel widget didn't work well. I made the three arrows widget but the rotation was not implemented. (used in the edge-extend and even in the face extend)
I discovered that it would be too much complicated to make the three rotation wheel in one widget.
Now I made one-arrow-rotation widget which should then be used by the three-arrows widget. The three-arrows widget should use the one-arrow-widget to simplify the code.
The disc has it's own callback and the arrow has also it's own callback. you can get the angle at any time by calling the function made for that.
I need to re-implement the three-arrow widget.
Mouse-position to angle was the most difficult part of this widget. But now I know how to do it and will fix also the wheel widget I have in other tool.
Might inspire you also how to convert mouse position to angle on the 3D scene (not 2D).
phpBB [video]
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by mariwan »

Design456_ExtendFace released and merged to main branch.

After a long development phase, I release the tool.
It might need some fixes in the future .. but for now I release it.
Known weaknesses:

1- Even I use a "smart" way to convert xy to rotation for the discs, they are tricky to use. You have to have the camera focused to the disc to get the best results. Don't know what can make that better. Look at the code to know how I made it
2- There is still a small bug in the mouse click Some times you need to click the arrow/disc before it start to react to the mouse dragging ..
3- Three_arrows_widget is complex .. It has 6 callbacks. I tried many things to do this widget .. Many approaches failed but current is working. Yet not perfect.
4- ALL TWEAK TOOLS ARE DANGEROUS!! use it with care .. Undo/Redo is not added yet .. but I will add them.
5- Some time the shape is not correct (or correct?). The problem is you have to divide the square shapes to triangles to avoid getting that kind of problem.. this is a future fix not now.
6-Curved surfaces will fail. It needs more knowledge that I don't have now.
Enjoy

phpBB [video]
Attachments
test.FCStd
(98.67 KiB) Downloaded 17 times
Last edited by mariwan on Sat Dec 25, 2021 1:47 pm, edited 1 time in total.
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: Progress thread of New Design456 Workbench - FreeCAD's Direct Modeling workbench

Post by paullee »

Looks cool 8-)
Post Reply