Skip to main content
Glama

OpenSCAD MCP Server

by jhacksman
stl_validator.cpython-312.pyc5.64 kB
� -��gz��l�ddlZddlZddlZddlZddlmZmZeje�Z Gd�d�Z y)�N)�Tuple�Optionalc��eZdZdZededeeeeffd��Z ededeeeeffd��Z ededeeeeffd��Z ededeeeeffd��Z y) � STLValidatorzd Validates STL files to ensure they are manifold (watertight) and suitable for 3D printing. �stl_file�returnc��tjj|�sdd|��fStjj|�}|dk(ry t |d�5}|j d�}|dk(rt j|�\}}nt j|�\}}||fcddd�S#1swYyxYw#t$r;}tjd t|����dd t|���fcYd}~Sd}~wwxYw) z� Validate an STL file to ensure it is manifold and suitable for 3D printing. Args: stl_file: Path to the STL file to validate Returns: Tuple of (is_valid, error_message) FzSTL file not found: r)FzSTL file is empty�rb�ssolidNzError validating STL file: ) �os�path�exists�getsize�open�readr�_validate_ascii_stl�_validate_binary_stl� Exception�logger�error�str)r� file_size�f�header�is_validr�es �;/home/ubuntu/openscad-mcp-server/src/utils/stl_validator.py� validate_stlzSTLValidator.validate_stls����w�w�~�~�h�'��0�� �;�;� ;��G�G�O�O�H�-� � ��>�-� A��h��%���������X�%�&2�&F�&F�x�&P�O�H�e�'3�&G�&G��&Q�O�H�e����&�%�%��� A� �L�L�6�s�1�v�h�?� @��7��A��x�@�@� @�� A�s=� B:�A B.�$ B:�.B7�3B:�7B:�: C>�0C9�3C>�9C>c��� t|d�5}|j�}ddd�j�jd�sy|j�j d�sy|j d�}|j d�}|d k(ry ||d zk7r d d |d z�d|��fSy#1swY��xYw#t $r;}tjdt|����d dt|���fcYd}~Sd}~wwxYw)zValidate an ASCII STL file.�rN�solid)Fz)Invalid ASCII STL: Missing 'solid' header�endsolid)Fz,Invalid ASCII STL: Missing 'endsolid' footerz facet normal�vertexr)Fz"Invalid ASCII STL: No facets found�FzInvalid ASCII STL: Expected z vertices, found �TNzError validating ASCII STL: ) rr�strip� startswith�endswith�countrrrr)rr�content� facet_count� vertex_countrs rrz STLValidator._validate_ascii_stl2s��� B��h��$���&�&�(��%��=�=�?�-�-�g�6�I��=�=�?�+�+�J�7�L�"�-�-��7�K�"�=�=��2�L��a��B��{�Q��.�� <�[�1�_�<M�M^�_k�^l�m�m�m��)%�$��*� B� �L�L�7��A��x�@� A��8��Q���A�A� A�� B�sE� B1�B%�'B1�B1�''B1�B1�%B.�*B1�1 C5�:0C0�*C5�0C5c��� t|d�5}|jd�|jd�}t|�dk7r ddd�ytj |d��}d|d zz}t jj|�}||k7rd d |�d |��fcddd�S ddd�y #1swYyxYw#t$r;}tjdt|����d dt|���fcYd}~Sd}~wwxYw)zValidate a binary STL file.r �P�N)Fz"Invalid binary STL: File too short�little)� byteorder�T�2Fz"Invalid binary STL: Expected size z, actual size r%zError validating binary STL: ) r�seekr�len�int� from_bytesr r rrrrr)rr�triangle_count_bytes�triangle_count� expected_size� actual_sizers rrz!STLValidator._validate_binary_stlOs��� C��h��%�����r� �()�v�v�a�y�$��+�,��1�F�&�%�"%���0D�PX��!Y��!#�n�r�&9� :� � �g�g�o�o�h�7� ��-�/� �$F�}�o�Uc�do�cp�"q�q�#&�%�&"�'&�%�%��(� C� �L�L�8��Q���A� B��9�#�a�&��B�B� B�� C�sS� B5�2B)�B5� A B)� B5�B)� B5�)B2�.B5�2B5�5 C9�>0C4�.C9�4C9c�4�tjd|���y)z� Attempt to repair a non-manifold STL file. Args: stl_file: Path to the STL file to repair Returns: Tuple of (success, error_message) zSTL repair not implemented: )FzSTL repair not implemented)r�warning)rs r� repair_stlzSTLValidator.repair_stlks�� ���5�h�Z�@�A�2�N) �__name__� __module__� __qualname__�__doc__� staticmethodrr�boolrrrrr>�r?rrr s�����!A�s�!A�u�T�8�C�=�-@�'A�!A��!A�F�B�c�B�e�D�(�3�-�4G�.H�B��B�8�C�s�C�u�T�8�C�=�5H�/I�C��C�6�3�S�3�U�4��#��+>�%?�3��3r?r) r �logging� subprocess�tempfile�typingrr� getLoggerr@rrrFr?r�<module>rLs2�� ����"� �� � �8� $��r3�r3r?

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jhacksman/OpenSCAD-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server