I have been working on an idea yesterday, the third alternative that I did not quite explain, using a Geometry Extension in the sketcher TextGeometryExtension (it exists in my computer, will publish later on).davidosterberg wrote: ↑Fri Jan 08, 2021 12:30 am I am ok, with closing this one, in favor of a Sketcher based tool. Oh well. I was hoping for a quick fix and on to the next one.
The advantages of this idea are:
1. Transparent to the solver - no solver support for new geometry/constraints needed.
2. Rather translucid to the Sketcher in General - almost every tool works as before on "text objects" (small letter below). Most of the implementation concentrates on a single object, requiring 2 modifications outside this class (Sketch::toShape in Sketch.cpp and ViewProviderSketch::draw) and minor additions to command to create the text object. At a second phase maybe some minor handling of a new Sketcher internal alignment constraint (to derive the height of the font and make it "more parametric").
2. Low entry point (from a code point of view), enabling successive improvements (no need to produce lots of code at once)
Description of the basic idea
1. A geometry object defines the path to be followed by the text (similar to the screenshots shown in this thread). In my mind can be any object (preferably not a geom point, although it can be treated as a special case). We might talk here about a line, but it could be a B-Spline or an arc. Let's call this Base-Path.
2. This Part::Geometry object is added an extension to (TextGeometryExtension). This extension concentrates all font data members (type of font, tracking, italic,...). All this is exposed to Python, in the most basic idea, by the extension twin object, TextGeometryExtensionPy. In the most basic implementation, it also has the height of the font (but this I would really like to extend so that this aspect is controlled by the Sketcher via constraints, more below) and derives length and other parameters from the length of the path. This object is capable of two functions:
2.1. Create a TopoDS_Shape, preferably a plurality of Wires (but could also be a plurality of TopoDS_Edges), having the "profile" of the fonts along the path defined by the geometry. I have not seen your code, but you should have this somewhere.
2.2. Be able to draw the font profile into the scenography, into a SoLineSet or provide a way so that ViewProvider::draw can easily draw whatever is provided into a SoLineSet (more on this below).
3. The basic idea draws to the scenograph in the "information layer" (green layer used for B-Splines for curvature, poles, knot multiplicity). From there, we can evolve further then (in fact you may choose to first just output the shape and draw nothing, which would be similar in appearance to your sketch).
Showing something following this basic idea should have a relatively low entry point, with:
1. Creating the extension and configuring the parameters from Python
2. Adding the extension to a geometry from Python
3. Causing ViewProvider::draw to draw in the scenograph of any Geometry having a TextGeometryExtension.
4. Causing Sketch::toShape to add to the profile the wires of a Geometry having a TextGeometryExtension.
The end. You get a sketch with the profile of the shapes. This could be the "First milestone".
Parametric Height
Probably the best addition towards having the text substantially parametric, is to allow to have a line that one could constraint to a height. An image better that a thousand words: Those are two fully constrained "Text Placeholders". The place holder should allow to constraint the text from the sketcher point of view (height and length).
Here you need to imagine two things:
1) that you see a green profile of the text in the information layer following the Base-Path.
2) that the perpendicular line defining the height is not blue, but yellow (internal geometry)
Point 2) is the important bit here:
2.1. The alignment constraint should be added a new Alignment type (HeightAlignment), and the corresponding alignment to the InternalGeometryType status (status is controlled by constraint life time, there are tons of examples of this, like the major axis of a ellipse, for example).
2.2. Sketch.cpp is modified to implement this constraint of the aligmnentconstraint as a perpendicular to a the Base-Path at its starting point (basically all this is available, is putting some glue in).
2.3. In TextGeometryExtension, you need to get the dimension of that line (this needs to solve the challenge that a Geometry extension has no knowledge of the SketchObject, and a dependency here from sketch is probably not acceptable, so some helper object would need to convey this information). Identifying the line is easy, because it is the one having the alignment constraint of alignment type "HeightAlignment" to the base geometry.
Creation of the text
The text creating tool is CommandSketcherTool (in that .cpp). One basic option can be to take the Base-Path object, click the tool, get a pop-up with text editor information (similar to the Datum Edit Dialog, but for text, with the text properties), add the "HeightAlignment" line with the alignment constraint.
In addition or instead, there can be a lot of commands under a single icon (as all the conics that appear when clicking the arrow), one icon per each supported sketcher geometry, and from there a "text placeholder" is created. Probably not a great idea. But a good incentive so that the community things how they want it. They excel at that .
Other forms of sketcher text representation and possibilities - advanced
Above I selected to draw the letters on the information layer. This has advantages:
- If one does lines, one interferes with the line selection mechanism and the mapping of ViewProvider "CurveId" to GeoId, basically is a sandbox where one only needs to take care not to interfere with other information layer... information, which basically only happens with B-Splines.
And disadvantages? (not sure if they are features, time will tell):
- No possibility of having the edges as geometry (external geometry or real geometry) and be able to edit them individually.
If drawing to the SoLineSet is done properly, it should be possible to just switch from one layer to the other. At the end Coin representation in the Sketcher, is similar for the normal layer and the information layer.
There is one thing I would like to know: Are you in for the challenge?