Python Topological Namer/Tracker

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
DeepSOIC
Posts: 7074
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Python Topological Namer/Tracker

Postby DeepSOIC » Sun Jul 16, 2017 12:32 pm

ezzieyguywuf wrote:
Wed Jul 12, 2017 8:32 pm
Namely, I'll need to expose the Modified/Deleted/Created faces from any given OpenCascade operation via the TopoShapePy implementation.
https://github.com/FreeCAD/FreeCAD/pull/868
ezzieyguywuf
Posts: 558
Joined: Tue May 19, 2015 1:11 am

Re: Python Topological Namer/Tracker

Postby ezzieyguywuf » Sun Jul 16, 2017 2:11 pm

Sweet! I'll rework my example to use these
ezzieyguywuf
Posts: 558
Joined: Tue May 19, 2015 1:11 am

Re: Python Topological Namer/Tracker

Postby ezzieyguywuf » Wed Jul 19, 2017 1:17 pm

I have updated my example to use @jnxd's GSoC history framework. It works great now, with no 'cheating'! In other words, in my original example I had to hard-code which faces got modified/deleted etc., but now I am able to do it all programatically.

I realized that it may be helpful to give a step-by-step on how to run my example as well as provide a screenshot that shows what's going on. Here it goes:
  1. Download PyTopoNamer

    Code: Select all

    $> cd ~
    $> git clone https://github.com/ezzieyguywuf/PyTopoNamer.git
  2. Edit the `path` variable in the `~/PyTopoNamer/FreeCAD_scripts/testNamer.FCMacro` test Macro. In our example, it should be set to `'~/PyTopoNamer'`
  3. Compile a copy of jnxd's tnaming-pr branch
  4. Open FreeCAD (which you just compiled)
  5. Run the macro. You can either select it from the gui or perform the following in the Python console. If you do it this way, all the objects will remain available in the python console for further inspection/tinkering.

    Code: Select all

    >>> myFile = '~/PyTopoNamer/FreeCAD_scripts/testNamer.FCMacro'
    >>> execfile(myFile)
freecad_toponamer.png
freecad_toponamer.png (16.42 KiB) Viewed 1223 times
Above is a screenshot of the generated solids after running the script. Here is what you are seeing:
  • The red solids show the current FreeCAD implementation of Topological Naming. You can see that in the second solid (from the left) the Chamfer has moved when FreeCAD recomputed the solid (after the cylinder was shortened)
  • The blue solids show the PyTopoNamer implementation of Topological Naming. You can see that in the second solid (from the left) the Chamfer is still on the same Edge. That is because I have a robust way of referencing that Edge
  • The third solid for both cases is the fusion object that was used to create the Chamfer. I have included these in order to show that there is no funny business going on: both the red and blue fusion objects will show (via the Report View) that the "edge to be chamfered" is named "Edge3".
    The original Edge, in case you are wondering, was named "Edge10". This is why the FreeCAD implementation fails
Note: I did not use any of the Part::Feature objects because then all the recomputes are done automatically by FreeCAD. Instead, I re-implemented the Part Workbench's Part::Feature object in order to, as best as I could, re-create how the Part Workbench handles and recomputes solids. This way, I was able to intercept the recompute and use my PyTopoNamer instead. This was easier (kind of) than re-writing or hacking the recompute in C++.

I think, for now, I am going to take a break from the PyTopoNamer and begin work on what I'm calling CppTopoNamer. It will be the same as the Python prototype but written from the ground up in C++. This may take me some time, as I am new to unit testing in C++, and I feel it is imperitive that this component have robust unit testing.
chrisb
Posts: 19042
Joined: Tue Mar 17, 2015 9:14 am

Re: Python Topological Namer/Tracker

Postby chrisb » Wed Jul 19, 2017 4:10 pm

That is very promising!!
User avatar
fosselius
Posts: 344
Joined: Sat Apr 23, 2016 10:03 am

Re: Python Topological Namer/Tracker

Postby fosselius » Fri Jul 21, 2017 7:27 am

This is truly awesome! makes me cry when i think of how many hours i have spent fighting issues related to topological naming... Keep it up!
cox
Posts: 963
Joined: Wed Nov 26, 2014 11:37 pm

Re: Python Topological Namer/Tracker

Postby cox » Fri Jul 21, 2017 10:27 am

Tears in my eye as well, be weary you confused references, @ezzieyguywuf is coming to eradicate you! Your days are numbered.
Need help? Feel free to ask, but please read the guidelines first
ezzieyguywuf
Posts: 558
Joined: Tue May 19, 2015 1:11 am

Re: Python Topological Namer/Tracker

Postby ezzieyguywuf » Fri Jul 21, 2017 12:17 pm

Glad people are excited! The CppTopoNamer is taking form slowly, as i said in an earlier post I'm not familiar at all with C++ and unit tests so it's taking a while to get rolling - I have made progress though. Right now I'm trying to figure out a good way to mock the OpenCascade classes, i.e. TopoDS_Shape.
triplus
Posts: 8757
Joined: Mon Dec 12, 2011 4:45 pm

Re: Python Topological Namer/Tracker

Postby triplus » Fri Jul 21, 2017 12:25 pm

Good to see progress!
User avatar
apeltauer
Posts: 212
Joined: Fri Aug 11, 2017 2:19 pm

Re: Python Topological Namer/Tracker

Postby apeltauer » Fri Aug 11, 2017 2:36 pm

Hello all,

at the beginning thanks to everybody who is working on FreeCAD an making this wonderful piece of software work...

@ezzieyguywuf i am interested in how you are realizing the unit tests in c++. What framework are you using?
I have no clue how a unit test with c++ should look like for FreeCAD. I would try to use gtest, but i dont know what the commen way in FreeCAD is...

Also i havent found the answer in the forum or the dokumentation....
I hope someone can lead me to the answer...

Thanks...
ezzieyguywuf
Posts: 558
Joined: Tue May 19, 2015 1:11 am

Re: Python Topological Namer/Tracker

Postby ezzieyguywuf » Mon Aug 14, 2017 2:02 am

apeltauer wrote:
Fri Aug 11, 2017 2:36 pm
@ezzieyguywuf i am interested in how you are realizing the unit tests in c++. What framework are you using?
I have no clue how a unit test with c++ should look like for FreeCAD. I would try to use gtest, but i dont know what the commen way in FreeCAD is...
I have made some small progress on this. You can see my work here on my github. You'll want to start with SolidManager_PrimitiveTester.cpp which shows some very basic tests for the Topological Namer that I'm working on.

You'll also want to take a look at IEdge.h, IFace.h, and ISolid.h. These three header files describe a generic interface to a topological Edge, Face, and Solid respectively. The idea is that my Topological Namer (and really, any component within FreeCAD in general) does not need to know specifically about TopoDS_Edge, TopoDS_Face, nor TopoDS_Solid from OpenCascade. Rather, what the Topological Namer needs to know is about an interface to these entities.

So, what I have right now is a very very basic interface for these - essentially, only exposing the functionality that I need for a basic Topological Namer test. You'll notice in my test/include folder I've defined some classes (i.e. Mock_Edge.h) which implement these headers. These 'mock' classes implement the respective interfaces in a very naive manner: for example, for checking equality they accept an integer to identify themselves and check if this value is equal. This works well for my basic tests - you can see how I use these mock classes in the MockObjectMaker helper class.

Anywho, hopefully this helps a little bit. Let me know if you have any questions, I haven't really gotten around to documenting this code yet.