Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error on Propeller.generate_obj (due to OCC.Extend.DataExchange.write_stl_file) #98

Open
ndem0 opened this issue Sep 13, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@ndem0
Copy link
Member

ndem0 commented Sep 13, 2022

Describe the bug
A bug occurs using the Windows OS in the function write_stl_file from the pythonocc library. At the moment no issues related with this bug are opened in the Github page of pythonocc-core library. Additionally, the same method write_stl_file is also used in Propeller.generate_stl with no errors in this case.

To Reproduce
pytest tests/test_propeller

Output

================================== FAILURES ===================================
_______________ TestPropeller.test_generate_obj_blades_and_stem _______________

self = <tests.test_propeller.TestPropeller testMethod=test_generate_obj_blades_and_stem>

    def test_generate_obj_blades_and_stem(self):
        sh = Shaft("tests/test_datasets/shaft.iges")
        prop = create_sample_blade_NACApptc()
        prop = Propeller(sh, prop, 4)
>       prop.generate_obj("tests/test_datasets/propeller_and_shaft.obj", region_selector='blades_and_stem')

tests\test_propeller.py:192: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bladex\propeller.py:105: in generate_obj
    write_stl_file(self.shaft_solid, "/tmp/temp_shaft.stl")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

a_shape = <class 'TopoDS_Solid'>, filename = '/tmp/temp_shaft.stl'
mode = 'ascii', linear_deflection = 0.9, angular_deflection = 0.5

    def write_stl_file(a_shape, filename, mode="ascii", linear_deflection=0.9, angular_deflection=0.5):
        """ export the shape to a STL file
        Be careful, the shape first need to be explicitely meshed using BRepMesh_IncrementalMesh
        a_shape: the topods_shape to export
        filename: the filename
        mode: optional, "ascii" by default. Can either be "binary"
        linear_deflection: optional, default to 0.001. Lower, more occurate mesh
        angular_deflection: optional, default to 0.5. Lower, more accurate_mesh
        """
        if a_shape.IsNull():
            raise AssertionError("Shape is null.")
        if mode not in ["ascii", "binary"]:
            raise AssertionError("mode should be either ascii or binary")
        if os.path.isfile(filename):
            print("Warning: %s file already exists and will be replaced" % filename)
        # first mesh the shape
        mesh = BRepMesh_IncrementalMesh(a_shape, linear_deflection, False, angular_deflection, True)
        #mesh.SetDeflection(0.05)
        mesh.Perform()
        if not mesh.IsDone():
            raise AssertionError("Mesh is not done.")
    
        stl_exporter = StlAPI_Writer()
        if mode == "ascii":
            stl_exporter.SetASCIIMode(True)
        else:  # binary, just set the ASCII flag to False
            stl_exporter.SetASCIIMode(False)
        stl_exporter.Write(a_shape, filename)
    
        if not os.path.isfile(filename):
>           raise IOError("File not written to disk.")
E           OSError: File not written to disk.

C:\Miniconda\envs\__setup_conda\lib\site-packages\OCC\Extend\DataExchange.py:353: OSError
__________________ TestPropeller.test_generate_obj_by_coords __________________

self = <tests.test_propeller.TestPropeller testMethod=test_generate_obj_by_coords>

    def test_generate_obj_by_coords(self):
        sh = Shaft("tests/test_datasets/shaft.iges")
        prop = create_sample_blade_NACApptc()
        prop = Propeller(sh, prop, 4)
>       prop.generate_obj("tests/test_datasets/propeller_and_shaft.obj", region_selector='by_coords')

tests\test_propeller.py:163: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bladex\propeller.py:[105](https://github.com/mathLab/BladeX/actions/runs/3046074863/jobs/4908427376#step:7:106): in generate_obj
    write_stl_file(self.shaft_solid, "/tmp/temp_shaft.stl")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

a_shape = <class 'TopoDS_Solid'>, filename = '/tmp/temp_shaft.stl'
mode = 'ascii', linear_deflection = 0.9, angular_deflection = 0.5

    def write_stl_file(a_shape, filename, mode="ascii", linear_deflection=0.9, angular_deflection=0.5):
        """ export the shape to a STL file
        Be careful, the shape first need to be explicitely meshed using BRepMesh_IncrementalMesh
        a_shape: the topods_shape to export
        filename: the filename
        mode: optional, "ascii" by default. Can either be "binary"
        linear_deflection: optional, default to 0.001. Lower, more occurate mesh
        angular_deflection: optional, default to 0.5. Lower, more accurate_mesh
        """
        if a_shape.IsNull():
            raise AssertionError("Shape is null.")
        if mode not in ["ascii", "binary"]:
            raise AssertionError("mode should be either ascii or binary")
        if os.path.isfile(filename):
            print("Warning: %s file already exists and will be replaced" % filename)
        # first mesh the shape
        mesh = BRepMesh_IncrementalMesh(a_shape, linear_deflection, False, angular_deflection, True)
        #mesh.SetDeflection(0.05)
        mesh.Perform()
        if not mesh.IsDone():
            raise AssertionError("Mesh is not done.")
    
        stl_exporter = StlAPI_Writer()
        if mode == "ascii":
            stl_exporter.SetASCIIMode(True)
        else:  # binary, just set the ASCII flag to False
            stl_exporter.SetASCIIMode(False)
        stl_exporter.Write(a_shape, filename)
    
        if not os.path.isfile(filename):
>           raise IOError("File not written to disk.")
E           OSError: File not written to disk.

C:\Miniconda\envs\__setup_conda\lib\site-packages\OCC\Extend\DataExchange.py:353: OSError

Additional context
No errors using MacOS or Linux.

@ndem0 ndem0 added the bug Something isn't working label Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant