[New feature] Shapestrings in PartDesign or Sketcher

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
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: Shapestrings in PartDesign or Sketcher

Post by abdullah »

davidosterberg wrote: Thu Jan 07, 2021 1:07 pm
hyarion wrote: Thu Jan 07, 2021 12:35 pm
The most intuitive way for me would to have this functionality in sketcher, but limit what the sketcher and solver can interface with to only the base line

In other words:
1. create a sketch on a body
2. create a text object in the sketch, but only expose the base line to the solver
3. close the sketch
4. pad the text-sketch

(this could also be extended to allow creating text on an arc)
This this is actually close to my first idea for this tool. But I discarded it as too complex for me at the moment.

Edit:
After Sketcher has been refactored so that new geometry types (and perhaps a sub type in this case) can be added without touching every single function, I agree that this would be very nice.
I tend to agree to hyarion in how I would approach this.

There is a precedent in the B-Spline where only poles are actually solved.

I think that this idea can be generalised into something more general that can be reused for other complex/arbitrary 2D shapes. Where the solver sees (in its most basic form) a point (location), but then produces the appropriate shape at this location.

With that framework in mind, all the PD tools usable on one profile could be used.

I tend to believe that such idea would supersede a "helix alike" idea (I was looking into that today), when/if implemented.

We should really do something about refactoring geometry handling in v0.20. I do agree to that.
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: Shapestrings in PartDesign or Sketcher

Post by davidosterberg »

abdullah wrote: Thu Jan 07, 2021 4:03 pm I tend to agree to hyarion in how I would approach this.
Does that mean this PR will not be merged? That is OK, if that is the case. But I would like to know that before putting more effort into it. I think this tool is useful as is in PD.

I do think that the BSplines and the text would be a bit different though (maybe not, my knowledge is shallow). For the text in sketcher approach, all the Part design tools have to see the text as a geometric object. It is all the tools in SketchObject that must not see the text. Perhaps there is a simple way to achieve this.
hyarion
Posts: 139
Joined: Fri Jun 26, 2020 6:08 pm

Re: Shapestrings in PartDesign or Sketcher

Post by hyarion »

If the sketcher way is the way to go, maybe this could be made into an addon instead? (There are other addons that inject tools to PD's toolbar IIRC)
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Shapestrings in PartDesign or Sketcher

Post by abdullah »

davidosterberg wrote: Thu Jan 07, 2021 6:08 pm
abdullah wrote: Thu Jan 07, 2021 4:03 pm I tend to agree to hyarion in how I would approach this.
Does that mean this PR will not be merged? That is OK, if that is the case. But I would like to know that before putting more effort into it. I think this tool is useful as is in PD.

I do think that the BSplines and the text would be a bit different though (maybe not, my knowledge is shallow). For the text in sketcher approach, all the Part design tools have to see the text as a geometric object. It is all the tools in SketchObject that must not see the text. Perhaps there is a simple way to achieve this.
I do not get to decide whether a PR will not be merged. I am an equal, just have worked for FreeCAD longer. You do not need to look up to me. I am here to help where I can.

Most PD features either involve the transformation of a previous operation or are sketch based. Primitives are a notable exception, but they are not sketch based. The text feature you propose is neither (or a mixture of both, a third category if you wish).

I point out that the feature you propose could be implemented as a primitive, then it would fall under the category of the primitives (a text string primitive). It would obey support attachment as primitives do (if attached). In fact, it appears to me (I may be wrong) that the sketch is only used as a substitution for an attachment (to indicate an location/orientation of the underlying object). You rightly point out that construction lines are used as references in several PD features, but generally it deals with the transformation itself, rather than the location of the object. If you want to argue that the line defines a transformation in the text object, I would reply it is far fetched argument.

I am not convinced that this third category responds to a natural extension or new use case. Rather, shame on me if I am wrong, to the convenience of implementation.

Let's assume for a moment that after reading the above you became convinced that your feature should work as a primitive (i.e. without the Sketch). And I emphasise this is nothing but an assumption for the sake of the following argumentation (I fully respect if you disagree with this assumption). Then the only disadvantage I see is that, as it is the case with primitives in general, they are not 2D shapes and the remaining tools of PD can not be leveraged on them with the flexibility that can be attained with 2D shapes. This point was raised by hyarion.

My post was never meant to warn you it won't be merged, rather to give you my opinion. It may be merged it you want to pursue it.

Regarding alternatives, there are two ideas that pop-out of my mind (without having given them too much regard, to be honest):
1. Create the ability to incorporate 2D objects to PD, where the text is a 2D object. In a very bad implementation that only serves to illustrate the point a TextSketchObject is a class derived from the Sketcher::SketchObject, where the solver is nullified and you get a text at the origin (it may well be the parent class of the Sketcher Part::Part2DObject instead, not thought through).

2. Add the ability to include text in the sketcher.

2.1. I do not think PD works based directly on Part::Geometry, other that maybe FeatureHole. PD works with the profile (the shape of wires build from the Sketch, which is indeed based on Part::Geometry). Take a look at SketchObject::execute(), you will see that the shape is set there.

2.2. You could derive a class from Part::Geometry, Sketcher::TextGeometry or if you are planning for more features like this one, Sketcher::ArbitraryGeometry. Part::Geometry has a pure virtual function toShape() that you will need to implement returning the shape of whatever you decide to include inside. This will be called by Sketch.cpp to produce the profile.

Then, of course, you would need to teach it to draw as objects are drawn in ViewProviderSketch::draw(bool, bool) and define a solver implementation. Here it is where it is very similar to a B-Spline. You could, for example, draw your text along different geometries (along a line, an arc or a b-spline). This geometry (or the poles if a b-spline) would be internal geometry to your Sketcher::TextGeometry. This geometry is what the solver solves and uses to locate the object...

... now thinking... would it be possible to just associate a text/font/XXX via a GeometryExtension (Sketcher::TextGeometryExtension) to any existing geometry of the Sketcher without all of the above...

... it is getting late... let me think about it... maybe the latter becomes a third alternative...
user1234
Veteran
Posts: 3261
Joined: Mon Jul 11, 2016 5:08 pm

Re: Shapestrings in PartDesign or Sketcher

Post by user1234 »

Just my two cents:

Normally a would say, this feature is not needed in PartDesign **. But of course it is a nice addition, why not taking it. But when, i woud say as sketch based it is better. You can better control it, for example for a pad in with pulling direction for a casting or molding slider. Also then it is useable in Part out of the box.

( ** The reason for this is because the fonts are often not good enough for a sketch or pad. Maybe it is idea to force only fonts there a good enough. But on a second though this is also not a good idea ..... )

Just thinking ..... from a view from a user .....

Greetings
user1234
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: Shapestrings in PartDesign or Sketcher

Post by davidosterberg »

user1234 wrote: Thu Jan 07, 2021 9:03 pm The reason for this is because the fonts are often not good enough for a sketch or pad. Maybe it is idea to force only fonts there a good enough.
Another issue is that the available fonts on a system is not the same in Windows, Mac, and Linux. This means that the model may break when shared. My idea to solve this problem is to ship a small selection of good, liberally licenced, fonts with FreeCAD. These would be the recommended fonts. Then, in an "advanced" section, we offer the user the possiblity to select his font from the system available fonts. With a warning that this might break if the font is not installed, or of poor quality.
User avatar
czinehuba
Posts: 158
Joined: Mon Oct 15, 2018 4:59 am
Location: UK
Contact:

Re: Shapestrings in PartDesign or Sketcher

Post by czinehuba »

davidosterberg wrote: Thu Jan 07, 2021 9:52 pm These would be the recommended fonts. Then, in an "advanced" section, we offer the user the possiblity to select his font from the system available fonts. With a warning that this might break if the font is not installed, or of poor quality.
Would an option (tick-box in the settings) to embed font used in FreeCAD file be a good idea to enable interoperability on different systems? Like LibreOffice does it.
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: Shapestrings in PartDesign or Sketcher

Post by davidosterberg »

abdullah wrote: Thu Jan 07, 2021 8:05 pm I do not get to decide whether a PR will not be merged. I am an equal, just have worked for FreeCAD longer. You do not need to look up to me. I am here to help where I can.
We are equals as men, but due to merit your opinion holds stronger than mine here. Nothing wrong with that.


abdullah wrote: Thu Jan 07, 2021 8:05 pm You rightly point out that construction lines are used as references in several PD features, but generally it deals with the transformation itself, rather than the location of the object. If you want to argue that the line defines a transformation in the text object, I would reply it is far fetched argument.
Why far fetched? It is exacly what it is a the construction line translates into a rotation and a translation, and the length will be used to pre-select a font size. All the information in the sketch is used, 1-1 mapping.

abdullah wrote: Thu Jan 07, 2021 8:05 pm I am not convinced that this third category responds to a natural extension or new use case. Rather, shame on me if I am wrong, to the convenience of implementation.
The principle of using the sketch as a transformation is already used by the Hole feature. It is not a new category in PD.


abdullah wrote: Thu Jan 07, 2021 8:05 pm Then the only disadvantage I see is that, as it is the case with primitives in general, they are not 2D shapes and the remaining tools of PD can not be leveraged on them with the flexibility that can be attained with 2D shapes. This point was raised by hyarion.
If you read further up in the thread, you will see that I initially argued for a sketch based solution. Almost identical to Hyarion's suggestion. It is therefore weird to sit on this side of the argument, :D

What was brought up by @chrisb (as I understood him) was that Text was not a natural extension of Sketcher. How ironic that this is now the argument used against having Text in PD :). None the less I agree to the benefits of having text in sketcher. I would welcome a Text tool in sketcher when that becomes available (I might even work on it). But why does it exclude Text in PD, when the feature is so close to be finished? Of course it has to be maintained, but I don't see that as a large task, in comparison to having a user friendly tool now.


abdullah wrote: Thu Jan 07, 2021 8:05 pm My post was never meant to warn you it won't be merged, rather to give you my opinion. It may be merged it you want to pursue it.
Thanks for that clarification. Fair.



abdullah wrote: Thu Jan 07, 2021 8:05 pm Regarding alternatives, there are two ideas that pop-out of my mind (without having given them too much regard, to be honest):
1. Create the ability to incorporate 2D objects to PD, where the text is a 2D object. In a very bad implementation that only serves to illustrate the point a TextSketchObject is a class derived from the Sketcher::SketchObject, where the solver is nullified and you get a text at the origin (it may well be the parent class of the Sketcher Part::Part2DObject instead, not thought through).
Initial reaction is that this would be a bigger deviation from current PD. That would be something new.


abdullah wrote: Thu Jan 07, 2021 8:05 pm 2. Add the ability to include text in the sketcher.
Yes, why not. As long as it can be done without adding a new switch case to every member of SketchObject.
Thanks for the hints. I will have a look when time allows.
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: Shapestrings in PartDesign or Sketcher

Post by davidosterberg »

czinehuba wrote: Thu Jan 07, 2021 10:01 pm Would an option (tick-box in the settings) to embed font used in FreeCAD file be a good idea to enable interoperability on different systems? Like LibreOffice does it.
Yes, that is a possibility. I don't know the legal implications, and I don't know how to do it. When you say that LibreOffice does that it makes me less worried about legal issues.
hyarion
Posts: 139
Joined: Fri Jun 26, 2020 6:08 pm

Re: Shapestrings in PartDesign or Sketcher

Post by hyarion »

First of: I'm a new user/developer so you don't have to listen to me at all ;)

This is a really complex topic :?

The problem I see with adding a feature to PD, that we're already discussing might be better to implement another way is: if we remove later, it will break users' files, and I don't think that is something we want to do.
So we either need to maintain this functionality or make a way to migrate the features created when we create a better system.

So to me it's a bit worrisome that it sounds like everyone agrees that it would be better to have text in sketcher.
...but then again... I like being able to add parametric text

I kinda like abdullah's first alternative as a compromise:
abdullah wrote: Thu Jan 07, 2021 8:05 pm 1. Create the ability to incorporate 2D objects to PD, where the text is a 2D object.
So if I understand your implementation davidosterberg, then it would be to remove the extrude operation and leave it with a 2d object and let the user create a pad/pocket out of the resulting shape.
That might also be easier to migrate, replacing such features with a new sketch with text on it.
...but then again.. your implementation is almost done..

davidosterberg wrote: Thu Jan 07, 2021 10:24 pm Yes, that is a possibility. I don't know the legal implications, and I don't know how to do it. When you say that LibreOffice does that it makes me less worried about legal issues.
It's common practise to let users choose if they want to embed fonts or not. adobe illustrator does it the same way when exporting pdf files. either way it's not you as a developer or freecad as a software that breaks any licenses, it will be the user who embeds the font that will be in trouble.
Post Reply