2D improvement

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Alexandr Parkhomenko
Posts: 18
Joined: Sat Mar 02, 2019 4:35 pm

2D improvement

Postby Alexandr Parkhomenko » Sun Mar 03, 2019 7:17 pm

I found some incorrect behavior in opencascade. It is skipping items:

1 image - Example sketch model. Create minimum any 3 wires (lines, circles and other) with shared point.
2 image - Path module generate this.
3 image - a little magic and you can do so
Attachments
Screenshot from 2019-03-02 19-54-54.png
Example sketch model. Create minimum any 3 wires with shared point.
Screenshot from 2019-03-02 19-54-54.png (158.57 KiB) Viewed 668 times
Screenshot from 2019-03-02 19-55-05.png
Now freecad calculate this.
Screenshot from 2019-03-02 19-55-05.png (113.29 KiB) Viewed 668 times
Screenshot from 2019-03-02 19-59-11.png
This is not released in freecad
Screenshot from 2019-03-02 19-59-11.png (135.34 KiB) Viewed 668 times
User avatar
Kunda1
Posts: 9202
Joined: Thu Jan 05, 2017 9:03 pm

Re: 2D improvement

Postby Kunda1 » Sun Mar 03, 2019 7:30 pm

can you use a more up to date version of FreeCAD and OCC and test this issue?
also please share your Help > About FreeCAD > Copy to clipboard when you ask for help. It saves folks time to troubleshoot the issue for you.
Alone you go faster. Together we go farther
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
Alexandr Parkhomenko
Posts: 18
Joined: Sat Mar 02, 2019 4:35 pm

Re: 2D improvement

Postby Alexandr Parkhomenko » Sun Mar 03, 2019 8:18 pm

OS: Arch Linux
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.10
Build type: Release
Python version: 3.7.2
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)

pacman -Ss opencascade
community/opencascade 7.3.0-4 [installed]
Open CASCADE Technology, 3D modeling & numerical simulation
latest from:
opencascade.com/sites/default/files/private/occt/OCC_7.3.0_release/opencascade-7.3.0.tgz
User avatar
Kunda1
Posts: 9202
Joined: Thu Jan 05, 2017 9:03 pm

Re: 2D improvement

Postby Kunda1 » Sun Mar 03, 2019 8:45 pm

Code: Select all

Version: 0.19.10
???
0.19 hasn't been released yet. Did you hack this yourself?

Also can you share an example file to reproduce this issue?
Alone you go faster. Together we go farther
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
Alexandr Parkhomenko
Posts: 18
Joined: Sat Mar 02, 2019 4:35 pm

Re: 2D improvement

Postby Alexandr Parkhomenko » Sun Mar 03, 2019 9:26 pm

oops
here pkgver=0.17 --https://aur.archlinux.org/cgit/aur.git/ ... reecad-git
on screenshots 0.17
Alexandr Parkhomenko
Posts: 18
Joined: Sat Mar 02, 2019 4:35 pm

Re: 2D improvement

Postby Alexandr Parkhomenko » Sun Mar 03, 2019 9:30 pm

Standalone example of this trouble

Code: Select all

// some headers
#include <STEPControl_Reader.hxx>
#include <Interface_Static.hxx>
#include <TopExp_Explorer.hxx>

#include <BRepLib.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepBuilderAPI_FindPlane.hxx>
#include <BRepLib_FindSurface.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepTools.hxx>
#include <BRepTools_WireExplorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <GeomAbs_JoinType.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_Line.hxx>
#include <Geom_Plane.hxx>
#include <Standard_Failure.hxx>
#include <gp_Circ.hxx>
#include <gp_GTrsf.hxx>
#include <Standard_Version.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <GCPnts_UniformAbscissa.hxx>
#include <BRepBndLib.hxx>
#include <BRepLib_MakeFace.hxx>
#include <Bnd_Box.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <HLRBRep.hxx>
#include <HLRBRep_Algo.hxx>
#include <HLRBRep_HLRToShape.hxx>
#include <HLRAlgo_Projector.hxx>
#include <ShapeFix_ShapeTolerance.hxx>
#include <ShapeExtend_WireData.hxx>
#include <ShapeFix_Wire.hxx>
#include <ShapeAnalysis_FreeBounds.hxx>
#include <TopTools_HSequenceOfShape.hxx>

#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepTools_ReShape.hxx>
#include <chrono>
#include <thread>
using namespace std;

int main(){
    // Loads file the STEP file
    TopoDS_Shape wires;
    STEPControl_Reader reader;
    IFSelect_ReturnStatus stat = reader.ReadFile("./shape.stp");
    bool failsonly = true;
    IFSelect_PrintCount fmode = IFSelect_ItemsByEntity;
    reader.PrintCheckLoad(failsonly,fmode);
    Standard_Real rp = Interface_Static::RVal("read.precision.val");
    Standard_Integer NbRoots = reader.NbRootsForTransfer();
    Standard_Integer NbTrans = reader.TransferRoots();
    reader.PrintCheckTransfer(failsonly,fmode);
	wires = reader.Shape();
	// here in sources make list...

    //-------------------------------------------------------------
    // version in freecad
    //-------------------------------------------------------------
	for (TopExp_Explorer it(wires, TopAbs_WIRE); it.More(); it.Next()) {
		BRepTools_WireExplorer xp(TopoDS::Wire(it.Current()));
		for (; xp.More(); xp.Next()) {
			xp.More();
			cout << "*" << endl;
		}
	}
    //-------------------------------------------------------------
    // correct version
    //-------------------------------------------------------------
    TopTools_IndexedMapOfShape localmap;
    TopExp::MapShapes(wires,TopAbs_EDGE,localmap);
    Standard_Integer numEdges = localmap.Extent();
    cout << "num EDGEs:" << numEdges << endl; //
    for (int count = 0; count < numEdges; count++ ){
    	TopoDS_Edge edge = TopoDS::Edge(localmap(count+1));
        BRepAdaptor_Curve curve(edge);
        switch (curve.GetType()) {
        case GeomAbs_Line: {
        	cout << "Line" << endl;
        	break;
        }
        case GeomAbs_Circle:{
        	cout << "Circle" << endl;
        	break;
        }
        default:{
        	cout << "Other" << endl;
        }
        }
    }

	return 0;
}
Alexandr Parkhomenko
Posts: 18
Joined: Sat Mar 02, 2019 4:35 pm

Re: 2D improvement

Postby Alexandr Parkhomenko » Sun Mar 03, 2019 9:39 pm

Also can you share an example file to reproduce this issue?
Recompute (refresh) this project and put please screen here.
Attachments
snowflake.FCStd
(5.77 KiB) Downloaded 14 times
chrisb
Posts: 30592
Joined: Tue Mar 17, 2015 9:14 am

Re: 2D improvement

Postby chrisb » Mon Mar 04, 2019 6:23 am

In another topic you talk about a patch, here you talk about a little magic, but I'm a bit confused, because I cannot find it.
Alexandr Parkhomenko wrote:
Sun Mar 03, 2019 9:30 pm
In the standalone example you load a local step file, so I did not investigate this further. Could you please elaborate what you are doing/have done/will do?

The snowflake path changes here to the inner hexagon, if I change Direction from None to e.g. ZNegative.
Attachments
Bildschirmfoto 2019-03-04 um 07.26.04.png
Bildschirmfoto 2019-03-04 um 07.26.04.png (9.1 KiB) Viewed 591 times
You need at least FreeCAD 0.19.23300 to edit my current sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Alexandr Parkhomenko
Posts: 18
Joined: Sat Mar 02, 2019 4:35 pm

Re: 2D improvement

Postby Alexandr Parkhomenko » Mon Mar 04, 2019 7:12 pm

Local step file in attachments. (Open snowflake.FCStd > Export Sketch as STEP)

Code: Select all

...
        case GeomAbs_Line: {
        	cout << "Line" << endl;
        	gp_Pnt a, b;
            a = curve.Value(curve.FirstParameter());
            b = curve.Value(curve.LastParameter());
            cout << "     X" << a.X() << " Y" << a.Y() << "- X" << b.X() << " Y" << b.Y() << endl;
        	break;
        }
...       
OUTPUT:
num EDGEs:18
Line
     X19.05 Y22.4412- X14.605 Y30.2187
Line
     X17.78 Y20.32- X8.89 Y20.32
Line
     X19.05 Y18.1203- X14.605 Y10.4213
...
Attachments
snowflake.step
(8.49 KiB) Downloaded 13 times
Alexandr Parkhomenko
Posts: 18
Joined: Sat Mar 02, 2019 4:35 pm

Re: 2D improvement

Postby Alexandr Parkhomenko » Mon Mar 04, 2019 7:30 pm

https://github.com/FreeCAD/FreeCAD/blob ... .cpp#L3265

Code: Select all

// see this function:
void Area::toPath(Toolpath &path, const std::list<TopoDS_Shape> &shapes,
const gp_Pnt *_pstart, gp_Pnt *pend, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_PATH))
...
Minimum patch:

Code: Select all

    for(const TopoDS_Shape &wire : wires) {
//#        BRepTools_WireExplorer xp(TopoDS::Wire(wire));
        TopTools_IndexedMapOfShape localmap;
        TopExp::MapShapes(wire,TopAbs_EDGE,localmap);
        Standard_Integer numEdges = localmap.Extent();
        cout << "num EDGEs:" << numEdges << endl; //
        gp_Pnt a, b;
//#        for(;xp.More();xp.Next(),plast=p) {
//#            const auto &edge = xp.Current();
        for (int count = 0; count < numEdges; count++ ){

        	TopoDS_Edge edge = TopoDS::Edge(localmap(count+1));
...
In attachments full version. This is the working sketch. Some people can use it to yourself with modifications.
Attachments
Area.cpp
Try this file here: FreeCAD/src/Mod/Path/App/Area.cpp
(122.91 KiB) Downloaded 24 times