Skip to content

Conversation

@vinicius795
Copy link

Before anything else, everything “I” did here was actually done by ChatGPT Codex in VS Code. I can program, but not that well, and I don’t have the time needed to learn and implement everything required to do what I’d like to do.

So… I don’t expect this PR to be accepted; I’d just like to get a code review. I want to split this PR into three different ones, but that will take me a while, and I think someone might find the changes I made useful and start using them before they officially make it into the project. I’ll explain each change.

–‐inner_corner dogbone –‐D D –‐R R

Although the project is meant to create boxes cut on laser cutters, the only thing that stops it from working on any CNC router is that the internal corners need to have a dogbone shape. So I did exactly that, because I don’t have a laser cutter but I do have a CNC router. Since the corner drawing process required a lot of code, I thought it was better to put everything in a separate file. It follows the same flow as any other --inner_corner value, but adds the --D and --R options so you can specify the diameter or radius of the dogbone arcs. If you choose --inner_corner dogbone, then you must provide either --D or --R.

DogBone Inner Corners

There was a bug where if the distance between one notch and the next was very small, less than 2×D, the corner drawings would overlap. But that’s already been fixed, and now they stop where the two drawings meet.

image

DXF Generator

Currently, to generate DXF files we use a PS‑to‑DXF converter. The problem is that it flattens all curves into line segments. At first that isn’t a problem, but if the computer isn’t powerful and the file is very large—especially with the dogbone option—opening the file to do anything can be difficult. Another thing is that G‑code generation software can benefit from the drawing having arc entities; instead of creating 20 G1 lines to draw each arc, it can create just one G2/G3. So I wrote a “native” generator using ezdxf, and I took the opportunity to implement some improvements:

  • Cubic curves become Arc, Circle, or Spline entities
  • Concentric arcs of the same radius are flattened into a single arc or a single circle
  • Collinear lines are joined into a single line
  • Closed drawings are joined into a single polyline

This way the DXF file becomes shorter and more efficient.
The only “bug” I couldn’t solve is when using --inner_corner loop: the loop is flattened into line segments, but if it isn’t flattened like that, it can’t be joined into the polyline. To do that, the polyline would need to be a spline, which would add a lot of complexity that I didn’t think was worthwhile.

I didn’t test the DXF generator with every generator in the project or with all edge types, so there may be cases where it produces a bug. But I tested all the scenarios I could think of.

ToolBox / BriefCase Generator

I’m undecided about the name for this generator because I made it to store my power tools, but when you look at it you think “this is a briefcase.”
It’s a box with hinges that opens at the middle of the value of --H, it has a handle and an internal divider. I still need to make a mechanism to lock it closed so it doesn’t open when you’re carrying it by the handle. I haven’t had time to build one yet, but in a few days I should be able to and will post a picture. Because I had to create some custom edges, there are some bugs with parameters that I still need to fix.

…nner_corners

Add dogbone inner corner option
…nner_corners-hqst97

Implement dogbone arc generation
…nner_corners

Fix dogbone arc orientation
…ion-for-inner_corners

Revert "Fix dogbone arc orientation"
TODO:
fix broken corner wen 2R is bigger than half of the sizes of the edge
fix arc segment becoming lines in dxf export
…limpo e libera um exportador DXF interno.

Em boxes/dogbone.py:63 e boxes/dogbone.py:209 normalizei ângulos e troquei a geração de splines por comandos 'A' completos, atualizando a substituição no caminho para operar só com listas e sem depender de Context.
Em boxes/drawing.py:17, boxes/drawing.py:151 e boxes/drawing.py:285 adicionei utilitários para arcos, centralizei o pré-processamento de caminhos em Surface.prepare_paths e ensinei Path.extents/transform a recalcular bounding boxes e orientações quando aparecem comandos 'A'.
Em boxes/drawing.py:662, boxes/drawing.py:832 e boxes/drawing.py:1177 adaptei SVG, PostScript e LBRN2: SVG/LBRN2 expandem arcos para curvas quando necessário e o backend PS agora emite arc/arcn nativos.
boxes/drawing.py:892 introduz DXFSurface, que converte cada comando em entidades LINE/ARC/TEXT e escreve um DXF AC1009 completo sem depender do pstoedit.
boxes/formats.py:22, boxes/formats.py:30, boxes/formats.py:65 e boxes/formats.py:72 passaram a registrar o formato 'dxf' como base e a instanciar o novo DXFSurface diretamente.
Sugestão: 1) gerar um DXF e abrir no CAD de referência para validar os arcos; 2) exportar SVG/PS para garantir que a expansão dos arcos mantém o contorno esperado.
…g imports to keep exports stable, and leave drawing.py focused on shared rendering helpers.
… da trilha após apply_dogbone, detectando interseções entre arcos consecutivos (tanto pós/pré quanto arcos principais) e ajustando seus pontos de início/fim para que se encontrem no ponto correto; os segmentos intermediários redundantes são removidos e os ângulos recalculados com as novas geometrias.
…tamento original mas expondo _hinge_spacing_segment para customização.

Implementa uso condicional do perfil de dedo nos vãos entre módulos de dobradiça (boxes/generators/toolbox.py:37-63), aplicando apenas à borda 'u' e respeitando as dimensões da alça.
Substitui as instâncias padrão da dobradiça pelo edge customizado no ToolBox, preservando as demais paredes e renderizações.
- agrupa segmentos de arco contíguos com mesmo centro/raio em uma única entidade
- detecta varreduras completas e passa a emitir CIRCLE em vez de vários ARC
- converte curvas cúbicas compatíveis diretamente em arcos/círculos, evitando discretizações

TODO
Alguns arcos estão com o sentido invertido
Loops são desenhados como seguimentos de linhas, devem ser desenhados como splines
Desenhos fechados devem ser desenhados como polyline

TODO Dogbone
*Arco principal do dogbone não esta encontrando com os arcos complementares
*Geometria quebrada em situações especificas do dogbone (quadrado com lado menor que 2*--D)
Melhora conversão de arcos no DXF
…on-issue-in-dxf-conversion

Melhora conversão de arcos no DXF - Preserve cubic arc orientação
arcs is now circles

TODO:

--inner-corner loop is faling back to line segments
…, circle, and text data so segment helpers share a consistent contract.

boxes/ezdxf_generator.py:62 _lineweight_to_hundredths now clamps values to 211 hundredths, matching the DXF specification and avoiding invalid entity weights.
boxes/ezdxf_generator.py:93 Centralized arc creation through _arc_segment, reducing duplicated dictionary literals and keeping type hints aligned.
boxes/ezdxf_generator.py:211 Updated circle detection to operate on the new Segment alias without changing the geometric checks.
boxes/ezdxf_generator.py:424 Text command parameters are copied only when a dict; double-check upstream callers don’t rely on non-dict mappings or those options will now be dropped.
- introduce an ezdxf-based DXFSurface and helper builder for generating entities
- update format/test-path imports to use the new surface
- declare the ezdxf dependency needed for DXF output
Replace DXF surface with ezdxf backend
@florianfesti
Copy link
Owner

This indeed is a lot. I have to warn you that my track record of reviewing large patch sets is not great. Can you at least split this into separate branches and PRs?

If your git foo is not up to that I can also try.

@vinicius795
Copy link
Author

vinicius795 commented Oct 29, 2025

Sure i can, my skills in git are not grate, but i will try. i think i will start with the dxf generator. it introduces very litle changes to the main code. do you think i should keep it in a separeted file or merge it into the drawing file?

a lot of commits is just me using github as a "pendrive", i have my pensonal computer and my work computer, and i use the commits to keep the code synchronized between the PCs.

@florianfesti
Copy link
Owner

Keep is separate for now. Now that we have 4 different backends I wonder if we should split everything into their own file instead of mashing them together

@vinicius795
Copy link
Author

I just created PR #843, It added the new DXF generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants