Part Geometry Extensions
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Part Geometry Extensions
Download the zip from here right?
https://github.com/abdullahtahiriyo/Fre ... _extension_
Hope I can compile it again
https://github.com/abdullahtahiriyo/Fre ... _extension_
Hope I can compile it again
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Part Geometry Extensions
Thanks for your elaborate answer.
Being able to alter the way geometry behaves can be useful. I can imagine one could hack in spiral support into sketcher, for example. Or, I wanted to do a sketcher-powered gearbox constructor tool (but I won't, most likely), and displaying an actual gear instead of just the driving circle could be kinda cool.
Also, quite some time ago I had an idea to expose geometry and constraints as DocumentObjects contained by sketch as a group. However, it hits exactly the same recompute-system related problems as assemblies do, so it requires revolution of recompute machinery. It also puts quite some strain onto FreeCAD, so sketches with thousands of elements will become completely impractical (although enormous sketches isn't a good idea IMO, but people are doing it again and again anyway).
BTW, I wouldn't consider compatibility for opening new files with older version a big advantage. Yes, for users it's important. But if it gets in a way of FreeCAD improvement - screw it.
Re: Part Geometry Extensions
Really thanks to you for putting forward an alternative solution. You are obviously working a different angle and it is good that we look into these details.
With the sketcher current architecture, if I wanted support for spirals, I would have to provide support for spirals in Part::Geometry, teach the sketcher's SketchViewProvider to draw spirals, create commands to create spirals, implement a solver interface for spirals (either a complete one, or an incomplete one like the one of the b-splines),... in all this, having a Sketcher::Geometry or a Part::Geometry does not change anything.DeepSOIC wrote: ↑Sat Jan 26, 2019 11:04 pm Being able to alter the way geometry behaves can be useful. I can imagine one could hack in spiral support into sketcher, for example. Or, I wanted to do a sketcher-powered gearbox constructor tool (but I won't, most likely), and displaying an actual gear instead of just the driving circle could be kinda cool.
I understand that you want to be able to alter the way geometry behaves by encapsulating existing geometry into a new Sketcher::Geometry. But if I am understanding it well, such encapsulation may only serve from an OCCT interfacing point of view, meaning that solver would still need to be provided in GCS, the geometry added to the SketchViewProvider for drawing for example.
You may tell me that you do not like the current Sketcher architecture, where functionality is spread around, for example, that the SketchViewProvider is responsible for displaying just about everything, and that it would be better to have separate ViewProviders, like in the case of Part Design features. This I understand. This could also allow you to selectively display the driving circle or the actual gear (I guess you refer to the 2D representation with the teeth).
However, Sketcher::Geometry, which in such a case would be a documentobject, is just a tiny bit of the puzzle you are presenting. This would be a major Sketcher revamp affecting all areas of the sketch, solver, internal architecture, solver interfacing,... it would basically amount basically to rewriting the sketcher workbench.
While I can agree many parts of the current sketcher could certainly benefit from a big "refactoring"/"reimplementation", we are really talking here about a huge investment. It is just a new workbench. One that I am not sure we could afford with the resources available. Think of how PartDesign, with at least three times more resources, managed to stop FreeCAD releases for a couple of years.
Because of the disruptive characteristic, if we were to introduce something like this, it would probably make sense to write a new workbench and enable to import sketches into that new workbench. I mean, I am not against it. It may be good in the long run and even fun.
Everything is a tradeoff. For sure backward compatibility may be sacrificed to introduce an improvement. However, I think the cost-benefit has to be clear from the outset.
Re: Part Geometry Extensions
I have been revising the concept and I basically end up changing how it works and reimplementing it.
This is the new branch.
This is rebased as of today, so it also includes other improvements to the Python interface that were just merged (like clone() support).
NOTE: I know there is a bug that crashes FreeCAD. I am trying hard to find it.
1. Named extensions
Now extensions, apart from a type, have a name (extension name). The combination of type and name is unique. There is only one such extension. But one can have several extensions of the same type with different names.
2. Extend Geometries using default extension types
Part provides some default extension types, which can be used to store information in a geometry without creating a custom extension. The default extension types implemented as of now are:
- GeometryIntExtension (long int/Py::Long),
- GeometryDoubleExtension (double/Py::Float),
- GeometryBoolExtension(Bool/Py::Boolean),
- GeometryStringExtension(std::string/Py::String).
So if your python macro/wb requires to associate to a geometry a string and three doubles, you can create:
So you get:
3. Extend Geometries using a custom extension
Currently custom extensions (a single extension having a plurality of different values of different types) must be writen in c++.
4. Geometry Interface
A Part::Geometry is a container of extensions, from Python you can:
- List the extensions:
- Set a new extension:
- Remove an extension (by type or by name, if they are several extensions all of them are deleted):
- get an extension (by type or by name)
- modify a preexisting extension. If the extension has the same type and name, the preexisting extension is substituted by the new extension:
4. Default extensions Interface
- The interface is uniform, you can get/set the Name and the Value. This is an example for a GeometryDoubleExtension:
Example session:
This is the new branch.
This is rebased as of today, so it also includes other improvements to the Python interface that were just merged (like clone() support).
NOTE: I know there is a bug that crashes FreeCAD. I am trying hard to find it.
1. Named extensions
Now extensions, apart from a type, have a name (extension name). The combination of type and name is unique. There is only one such extension. But one can have several extensions of the same type with different names.
2. Extend Geometries using default extension types
Part provides some default extension types, which can be used to store information in a geometry without creating a custom extension. The default extension types implemented as of now are:
- GeometryIntExtension (long int/Py::Long),
- GeometryDoubleExtension (double/Py::Float),
- GeometryBoolExtension(Bool/Py::Boolean),
- GeometryStringExtension(std::string/Py::String).
So if your python macro/wb requires to associate to a geometry a string and three doubles, you can create:
Code: Select all
>>> geo0.setExtension(Part.GeometryStringExtension("myrandomstring","ext1"))
>>> geo0.setExtension(Part.GeometryDoubleExtension(3.5,"myval1"))
>>> geo0.setExtension(Part.GeometryDoubleExtension(5.5,"myval2"))
>>> geo0.setExtension(Part.GeometryDoubleExtension(7.5,"myval3"))
Code: Select all
>>> geo0.getExtensions()
[<GeometryStringExtension ('ext1', myrandomstring) >, <GeometryDoubleExtension ('myval1', 3.5) >, <GeometryDoubleExtension ('myval2', 5.5) >, <GeometryDoubleExtension ('myval3', 7.5) >]
Currently custom extensions (a single extension having a plurality of different values of different types) must be writen in c++.
4. Geometry Interface
A Part::Geometry is a container of extensions, from Python you can:
- List the extensions:
Code: Select all
>>> geo0.getExtensions()
[<GeometryStringExtension ('ext1', myrandomstring) >, <GeometryStringExtension ('ext2', myrandomstring2) >, <GeometryIntExtension ('extnumber', 5) >, <GeometryBoolExtension ('geocoolness', True) >, <GeometryDoubleExtension ('myval1', 3.5) >, <GeometryDoubleExtension ('myval2', 5.5) >]
Code: Select all
>>> geo0.setExtension(Part.GeometryStringExtension("myrandomstring","ext1"))
>>> geo0.getExtensions()
[<GeometryStringExtension ('ext1', myrandomstring) >]
Code: Select all
>>> geo0.deleteExtensionOfType("Part::GeometryStringExtension")
>>> geo0.deleteExtensionOfName("myval2")
Code: Select all
>>> geo0.getExtensionOfName("myval1")
<GeometryDoubleExtension ('myval1', 3.5) >
>>> geo0.getExtensionOfName("myval1")
<GeometryDoubleExtension ('myval1', 3.5) >
Code: Select all
>>> geo0.setExtension(Part.GeometryDoubleExtension(5.57,'Micleas'))
>>> geo0.getExtensions()
[<GeometryDoubleExtension ('Micleas', 5.57) >]
>>> ext1 = geo0.getExtensionOfName('Micleas')
>>> ext1
<GeometryDoubleExtension ('Micleas', 5.57) >
>>> ext1.Value=10.5
>>> ext1
<GeometryDoubleExtension ('Micleas', 10.5) >
>>> geo0.setExtension(ext1)
>>> geo0.getExtensions()
[<GeometryDoubleExtension ('Micleas', 10.5) >]
- The interface is uniform, you can get/set the Name and the Value. This is an example for a GeometryDoubleExtension:
Code: Select all
>>> temp0 = geo0.getExtensionOfName("myval1")
>>> temp0
<GeometryDoubleExtension ('myval1', 3.5) >
>>> temp0.Value
3.5
>>> temp0.Name
'myval1'
Example session:
Code: Select all
>>> geos = ActiveSketch.Geometry
>>> geo0 = geos[0]
>>> geo0.getExtensions()
[]
>>> geo0.setExtension(Part.GeometryStringExtension("myrandomstring","ext1"))
>>> geo0.getExtensions()
[<GeometryStringExtension ('ext1', myrandomstring) >]
>>> geo0.setExtension(Part.GeometryStringExtension("myrandomstring2","ext2"))
>>> geo0.getExtensions()
[<GeometryStringExtension ('ext1', myrandomstring) >, <GeometryStringExtension ('ext2', myrandomstring2) >]
>>> geo0.setExtension(Part.GeometryIntExtension(5,"extnumber"))
>>> geo0.getExtensions()
[<GeometryStringExtension ('ext1', myrandomstring) >, <GeometryStringExtension ('ext2', myrandomstring2) >, <GeometryIntExtension ('extnumber', 5) >]
>>> geo0.setExtension(Part.GeometryBoolExtension(True,"geocoolness"))
>>> geo0.getExtensions()
[<GeometryStringExtension ('ext1', myrandomstring) >, <GeometryStringExtension ('ext2', myrandomstring2) >, <GeometryIntExtension ('extnumber', 5) >, <GeometryBoolExtension ('geocoolness', True) >]
>>> geo0.setExtension(Part.GeometryDoubleExtension(3.5,"myval1"))
>>> geo0.setExtension(Part.GeometryDoubleExtension(5.5,"myval2"))
>>> geo0.getExtensions()
[<GeometryStringExtension ('ext1', myrandomstring) >, <GeometryStringExtension ('ext2', myrandomstring2) >, <GeometryIntExtension ('extnumber', 5) >, <GeometryBoolExtension ('geocoolness', True) >, <GeometryDoubleExtension ('myval1', 3.5) >, <GeometryDoubleExtension ('myval2', 5.5) >]
>>> geo0.getExtensionOfName("myval1")
<GeometryDoubleExtension ('myval1', 3.5) >
>>> temp0 = geo0.getExtensionOfName("myval1")
>>> temp0
<GeometryDoubleExtension ('myval1', 3.5) >
>>> temp0.Value
3.5
>>> temp0.Name
'myval1'
>>> geo0.getExtensionOfType("Part::GeometryDoubleExtension")
<GeometryDoubleExtension ('myval1', 3.5) >
>>> temp0 = geo0.getExtensionOfName("myval2")
>>> temp0.Value
5.5
>>> temp0.Name
'myval2'
>>> temp0
<GeometryDoubleExtension ('myval2', 5.5) >
>>> geo0.deleteExtensionOfType("Part::GeometryStringExtension")
>>> geo0.getExtensions()
[<GeometryIntExtension ('extnumber', 5) >, <GeometryBoolExtension ('geocoolness', True) >, <GeometryDoubleExtension ('myval1', 3.5) >, <GeometryDoubleExtension ('myval2', 5.5) >]
>>> geo0.deleteExtensionOfName("myval2")
>>> geo0.getExtensionOfName("geocoolness")
<GeometryBoolExtension ('geocoolness', True) >
>>> geo0.getExtensionOfName("geocoolness").Value
True
>>> geos[0]=geo0
>>> ActiveSketch.Geometry = geos
Re: Part Geometry Extensions
Just pushed some fixes. Maybe the bug is gone (or maybe not, that is testing for )
Re: Part Geometry Extensions
I think you are the ones interested in Geometry Extensions.Joel_graff wrote: ↑Sat Jan 19, 2019 6:52 pmI can probably wait. There's plenty on the to-do list for the moment, anyway. All the same, I could use constraints as a proxy as an interim solution, if I really need to test that before geometry extensions are ready.abdullah wrote: ↑Sat Jan 19, 2019 4:22 pm To be honest with you, I would center in another part of the development until the geometry extensions get merged for two reasons: 1) Geometry extensions will allow you to have whatever you want to have, 2) It is likely that together or immediately after the geometry gets merged, I will include part of the Realthunders idea, which will most likely provide you with a sketch geometry id.
If you do not feel like waiting, of course, you may try to adapt the existing uuid, but it is not going to be straightforward (serialisation), I fear.
I think I have finished the development. It won't be merged before v0.19. If you want to try it you may download the PR below.
PR:
https://github.com/FreeCAD/FreeCAD/pull/1974
Re: Part Geometry Extensions
Downloaded and will try another 'heroic' compiling for me againabdullah wrote: ↑Fri Feb 15, 2019 7:17 pm I think I have finished the development. It won't be merged before v0.19. If you want to try it you may download the PR below.
PR:
https://github.com/FreeCAD/FreeCAD/pull/1974
Thanks !
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Part Geometry Extensions
I'll probably wait for it to show up in 0.19 at this point. I'm up to my eyeballs in other issues atm.abdullah wrote: ↑Fri Feb 15, 2019 7:17 pm I think you are the ones interested in Geometry Extensions.
I think I have finished the development. It won't be merged before v0.19. If you want to try it you may download the PR below.
PR:
https://github.com/FreeCAD/FreeCAD/pull/1974
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: Part Geometry Extensions
Seem compiled without error on Fedora 29, will see it run and test probably another weekend
Re: Part Geometry Extensions
Hi, your branch compiled in Feb, just go through the steps and it works as expected ! Thanksabdullah wrote: ↑Tue Feb 12, 2019 3:44 pm
1. Named extensions
Now extensions, apart from a type, have a name (extension name). The combination of type and name is unique. There is only one such extension. But one can have several extensions of the same type with different names.
2. Extend Geometries using default extension types
Part provides some default extension types, which can be used to store information in a geometry without creating a custom extension. The default extension types implemented as of now are:
- GeometryIntExtension (long int/Py::Long),
- GeometryDoubleExtension (double/Py::Float),
- GeometryBoolExtension(Bool/Py::Boolean),
- GeometryStringExtension(std::string/Py::String).
So if your python macro/wb requires to associate to a geometry a string and three doubles, you can create:
So you get:Code: Select all
>>> geo0.setExtension(Part.GeometryStringExtension("myrandomstring","ext1")) >>> geo0.setExtension(Part.GeometryDoubleExtension(3.5,"myval1")) >>> geo0.setExtension(Part.GeometryDoubleExtension(5.5,"myval2")) >>> geo0.setExtension(Part.GeometryDoubleExtension(7.5,"myval3"))
...
Testing in Sketcher::SketchObjectPython and have some thought see if you can offer some comment:-
SketchObjectPython - Python generated geometries or User added geometries
Using SketchObjectPython object, the def execute() add some geometries to the object. User can 'manually' add geometry also.
Thinking to add a 'tag' for those geometries added by inherent method of the SketchObjectPython object, to distinguish those added by user.
Not sure what exactly each of below mean, wonder if GeometryBoolExtension or GeometryStringExtension ( "autoGenerated", Geometry ) or ( "userAdded", Geometry )
Thanks for any idea.
- GeometryIntExtension (long int/Py::Long),
- GeometryDoubleExtension (double/Py::Float),
- GeometryBoolExtension(Bool/Py::Boolean),
- GeometryStringExtension(std::string/Py::String).