snapmark 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snapmark-2.0.0/LICENSE +21 -0
- snapmark-2.0.0/PKG-INFO +95 -0
- snapmark-2.0.0/README.md +81 -0
- snapmark-2.0.0/pyproject.toml +23 -0
- snapmark-2.0.0/setup.cfg +4 -0
- snapmark-2.0.0/snapmark/__init__.py +165 -0
- snapmark-2.0.0/snapmark/checking/__init__.py +0 -0
- snapmark-2.0.0/snapmark/checking/checking.py +183 -0
- snapmark-2.0.0/snapmark/core.py +154 -0
- snapmark-2.0.0/snapmark/entities/__init__.py +0 -0
- snapmark-2.0.0/snapmark/entities/add_entities.py +120 -0
- snapmark-2.0.0/snapmark/mark_algorithm/__init__.py +0 -0
- snapmark-2.0.0/snapmark/mark_algorithm/mark_algorithm.py +668 -0
- snapmark-2.0.0/snapmark/operations/__init__.py +0 -0
- snapmark-2.0.0/snapmark/operations/aligner.py +303 -0
- snapmark-2.0.0/snapmark/operations/basic_operations.py +361 -0
- snapmark-2.0.0/snapmark/operations/counter.py +172 -0
- snapmark-2.0.0/snapmark/sequence/__init__.py +0 -0
- snapmark-2.0.0/snapmark/sequence/sequence_legacy.py +141 -0
- snapmark-2.0.0/snapmark/sequence/sequence_system.py +337 -0
- snapmark-2.0.0/snapmark/shortcuts.py +183 -0
- snapmark-2.0.0/snapmark/utils/__init__.py +0 -0
- snapmark-2.0.0/snapmark/utils/backup_manager.py +161 -0
- snapmark-2.0.0/snapmark/utils/helpers.py +64 -0
- snapmark-2.0.0/snapmark/utils/segments_dict.py +44 -0
- snapmark-2.0.0/snapmark.egg-info/PKG-INFO +95 -0
- snapmark-2.0.0/snapmark.egg-info/SOURCES.txt +28 -0
- snapmark-2.0.0/snapmark.egg-info/dependency_links.txt +1 -0
- snapmark-2.0.0/snapmark.egg-info/requires.txt +1 -0
- snapmark-2.0.0/snapmark.egg-info/top_level.txt +1 -0
snapmark-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Federico Sidraschi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
snapmark-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: snapmark
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Python library for automated DXF file marking and manipulation
|
|
5
|
+
Author: serg_you_lin
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/serg-you-lin/snapmark
|
|
8
|
+
Project-URL: Repository, https://github.com/serg-you-lin/snapmark
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: ezdxf>=1.0.0
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# SnapMark
|
|
16
|
+
SnapMark is a Python-based tool designed to apply customizable markings to DXF files using a flexible sequence logic. It leverages the ezdxf library to manipulate DXF files and supports operations like adding counters, alignment, character scaling, and more.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
Automatic DXF file scanning and processing
|
|
20
|
+
|
|
21
|
+
Flexible character sequencing (e.g., counters, file-based naming, custom patterns)
|
|
22
|
+
|
|
23
|
+
Text scaling, alignment, and positioning
|
|
24
|
+
|
|
25
|
+
Modular structure for extending operations
|
|
26
|
+
|
|
27
|
+
Easy integration into existing workflows
|
|
28
|
+
|
|
29
|
+
# Quick Start
|
|
30
|
+
## 1. Clone the repository:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/serg-you-lin/snapmark.git
|
|
34
|
+
```
|
|
35
|
+
## 2. Install the dependencies:
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install -r requirements.txt
|
|
40
|
+
```
|
|
41
|
+
## 3.Run the example:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python examples/run_example.py
|
|
45
|
+
```
|
|
46
|
+
The script will process the sample DXF files located in examples/input/ and save the marked versions to a new folder (e.g., examples/input_Marked/).
|
|
47
|
+
|
|
48
|
+
## Parameters:
|
|
49
|
+
### Object:
|
|
50
|
+
suffix: adding suffix on both new file and new folder.
|
|
51
|
+
|
|
52
|
+
### AddMark operation:
|
|
53
|
+
sequence: text put on file.
|
|
54
|
+
layer: choose layer where put the text
|
|
55
|
+
min_char/max_char: minimum/maximum heigth of text
|
|
56
|
+
align: part f file where mark is located ('r'->right, 'l'->left, 'c'->center)
|
|
57
|
+
start_y: minimum place for text on y axis
|
|
58
|
+
down to: allowing text toi be smaller if does not fit while min_char.
|
|
59
|
+
|
|
60
|
+
### Sequence:
|
|
61
|
+
You can built a fix sequence or concatenate your sequence by file name, folder name, etc.
|
|
62
|
+
|
|
63
|
+
## Other features
|
|
64
|
+
### CountHoles
|
|
65
|
+
```bash
|
|
66
|
+
ToMark.add_operation(CountHoles(find_circle_by_radius(max_diam=5.2, min_diam=4.8)))
|
|
67
|
+
```
|
|
68
|
+
In this example, you can count all holes between 4.8 and 5.2 mm diameter in all files on a folder. Total and partial result.
|
|
69
|
+
|
|
70
|
+
### AddX
|
|
71
|
+
```bash
|
|
72
|
+
ToMark.add_operation(AddX(find_circle_by_radius(min_diam=2, max_diam=15), size=15, delete_hole=True, layer='Marcatura'))
|
|
73
|
+
```
|
|
74
|
+
In this example, all holes between 2 and 15 mm will be substituite from a 'X' sign of 15mm, on 'Marcatura' layer. Holes will been deleted.
|
|
75
|
+
|
|
76
|
+
# Project Structure
|
|
77
|
+
```bash
|
|
78
|
+
SnapMark/
|
|
79
|
+
│
|
|
80
|
+
├── snapmark/ # Main package
|
|
81
|
+
│ ├── snapmark.py # Main module combining logic
|
|
82
|
+
│ ├── operations/ # Marking operations
|
|
83
|
+
│ ├── sequence/ # Sequence logic
|
|
84
|
+
│ ├── checking/ # Input validation
|
|
85
|
+
│ └── __init__.
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
MIT License — feel free to use, modify, and share with attribution.
|
|
90
|
+
|
|
91
|
+
## Contributions
|
|
92
|
+
Pull requests are welcome! If you find issues or have suggestions, please open an issue in the repository.
|
|
93
|
+
|
|
94
|
+
## Author
|
|
95
|
+
Federico Sidraschi https://www.linkedin.com/in/federico-sidraschi-059a961b9/
|
snapmark-2.0.0/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# SnapMark
|
|
2
|
+
SnapMark is a Python-based tool designed to apply customizable markings to DXF files using a flexible sequence logic. It leverages the ezdxf library to manipulate DXF files and supports operations like adding counters, alignment, character scaling, and more.
|
|
3
|
+
|
|
4
|
+
## Features
|
|
5
|
+
Automatic DXF file scanning and processing
|
|
6
|
+
|
|
7
|
+
Flexible character sequencing (e.g., counters, file-based naming, custom patterns)
|
|
8
|
+
|
|
9
|
+
Text scaling, alignment, and positioning
|
|
10
|
+
|
|
11
|
+
Modular structure for extending operations
|
|
12
|
+
|
|
13
|
+
Easy integration into existing workflows
|
|
14
|
+
|
|
15
|
+
# Quick Start
|
|
16
|
+
## 1. Clone the repository:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
git clone https://github.com/serg-you-lin/snapmark.git
|
|
20
|
+
```
|
|
21
|
+
## 2. Install the dependencies:
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -r requirements.txt
|
|
26
|
+
```
|
|
27
|
+
## 3.Run the example:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
python examples/run_example.py
|
|
31
|
+
```
|
|
32
|
+
The script will process the sample DXF files located in examples/input/ and save the marked versions to a new folder (e.g., examples/input_Marked/).
|
|
33
|
+
|
|
34
|
+
## Parameters:
|
|
35
|
+
### Object:
|
|
36
|
+
suffix: adding suffix on both new file and new folder.
|
|
37
|
+
|
|
38
|
+
### AddMark operation:
|
|
39
|
+
sequence: text put on file.
|
|
40
|
+
layer: choose layer where put the text
|
|
41
|
+
min_char/max_char: minimum/maximum heigth of text
|
|
42
|
+
align: part f file where mark is located ('r'->right, 'l'->left, 'c'->center)
|
|
43
|
+
start_y: minimum place for text on y axis
|
|
44
|
+
down to: allowing text toi be smaller if does not fit while min_char.
|
|
45
|
+
|
|
46
|
+
### Sequence:
|
|
47
|
+
You can built a fix sequence or concatenate your sequence by file name, folder name, etc.
|
|
48
|
+
|
|
49
|
+
## Other features
|
|
50
|
+
### CountHoles
|
|
51
|
+
```bash
|
|
52
|
+
ToMark.add_operation(CountHoles(find_circle_by_radius(max_diam=5.2, min_diam=4.8)))
|
|
53
|
+
```
|
|
54
|
+
In this example, you can count all holes between 4.8 and 5.2 mm diameter in all files on a folder. Total and partial result.
|
|
55
|
+
|
|
56
|
+
### AddX
|
|
57
|
+
```bash
|
|
58
|
+
ToMark.add_operation(AddX(find_circle_by_radius(min_diam=2, max_diam=15), size=15, delete_hole=True, layer='Marcatura'))
|
|
59
|
+
```
|
|
60
|
+
In this example, all holes between 2 and 15 mm will be substituite from a 'X' sign of 15mm, on 'Marcatura' layer. Holes will been deleted.
|
|
61
|
+
|
|
62
|
+
# Project Structure
|
|
63
|
+
```bash
|
|
64
|
+
SnapMark/
|
|
65
|
+
│
|
|
66
|
+
├── snapmark/ # Main package
|
|
67
|
+
│ ├── snapmark.py # Main module combining logic
|
|
68
|
+
│ ├── operations/ # Marking operations
|
|
69
|
+
│ ├── sequence/ # Sequence logic
|
|
70
|
+
│ ├── checking/ # Input validation
|
|
71
|
+
│ └── __init__.
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
MIT License — feel free to use, modify, and share with attribution.
|
|
76
|
+
|
|
77
|
+
## Contributions
|
|
78
|
+
Pull requests are welcome! If you find issues or have suggestions, please open an issue in the repository.
|
|
79
|
+
|
|
80
|
+
## Author
|
|
81
|
+
Federico Sidraschi https://www.linkedin.com/in/federico-sidraschi-059a961b9/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "snapmark"
|
|
7
|
+
version = "2.0.0"
|
|
8
|
+
description = "Python library for automated DXF file marking and manipulation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{name = "serg_you_lin"}]
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"ezdxf>=1.0.0",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://github.com/serg-you-lin/snapmark"
|
|
19
|
+
Repository = "https://github.com/serg-you-lin/snapmark"
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.packages.find]
|
|
22
|
+
include = ["snapmark*"]
|
|
23
|
+
exclude = ["dev*", "examples*"]
|
snapmark-2.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SnapMark - Library for marking and manipulating DXF files.
|
|
3
|
+
|
|
4
|
+
Basic Usage:
|
|
5
|
+
import snapmark as sm
|
|
6
|
+
|
|
7
|
+
# Quick mark by file name
|
|
8
|
+
sm.mark_by_name("Examples/Input")
|
|
9
|
+
|
|
10
|
+
# Mark folder
|
|
11
|
+
sm.Operation.process_folder("folder", mark)
|
|
12
|
+
|
|
13
|
+
# Multiple pipeline example
|
|
14
|
+
manager = sm.IterationManager("folder")
|
|
15
|
+
manager.add_operation(
|
|
16
|
+
sm.Aligner(),
|
|
17
|
+
sm.AddMark(sequence),
|
|
18
|
+
sm.CountHoles(sm.find_circle_by_radius(5, 10))
|
|
19
|
+
)
|
|
20
|
+
manager.execute()
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
# ========== CORE: Main operations ==========
|
|
24
|
+
from .operations.basic_operations import (
|
|
25
|
+
Operation,
|
|
26
|
+
AddMark,
|
|
27
|
+
SubstituteCircle,
|
|
28
|
+
AddX,
|
|
29
|
+
RemoveCircle,
|
|
30
|
+
RemoveLayer,
|
|
31
|
+
PrintLayers,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
from .operations.counter import (
|
|
35
|
+
Counter,
|
|
36
|
+
CountFiles,
|
|
37
|
+
CountHoles,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
from .operations.aligner import Aligner
|
|
41
|
+
|
|
42
|
+
# ========== SEQUENCE (NEW SYSTEM) ==========
|
|
43
|
+
from .sequence.sequence_system import (
|
|
44
|
+
SequenceBuilder,
|
|
45
|
+
from_file_name,
|
|
46
|
+
from_splitted_text
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# ========== SEQUENCE (OLD - DEPRECATED) ==========
|
|
50
|
+
from .sequence.sequence_legacy import (
|
|
51
|
+
Conc,
|
|
52
|
+
FixSeq,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# ========== SHORTCUTS ==========
|
|
56
|
+
from .shortcuts import (
|
|
57
|
+
mark_by_name,
|
|
58
|
+
mark_by_splitted_text,
|
|
59
|
+
mark_with_sequence,
|
|
60
|
+
quick_count_holes,
|
|
61
|
+
single_file_pipeline,
|
|
62
|
+
restore_backup
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# ========== ITERATION MANAGER ==========
|
|
67
|
+
from .core import IterationManager, iteration_manager # iteration_manager = alias legacy
|
|
68
|
+
|
|
69
|
+
# ========== UTILITIES ==========
|
|
70
|
+
from .utils.backup_manager import BackupManager
|
|
71
|
+
from .utils.helpers import (
|
|
72
|
+
count_holes,
|
|
73
|
+
find_all_circles,
|
|
74
|
+
find_circle_by_radius,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# ========== CHECKING/SEARCH ==========
|
|
78
|
+
from .checking.checking import (
|
|
79
|
+
find_spec_holes,
|
|
80
|
+
find_circle_centers,
|
|
81
|
+
find_longer_entity,
|
|
82
|
+
print_layers as print_document_layers,
|
|
83
|
+
print_entities,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# ========== METADATA ==========
|
|
88
|
+
__version__ = "2.0.0"
|
|
89
|
+
__author__ = "serg_you_lin"
|
|
90
|
+
__all__ = [
|
|
91
|
+
# Shortcuts (main API)
|
|
92
|
+
'mark_by_name',
|
|
93
|
+
'mark_by_splitted_text',
|
|
94
|
+
'mark_with_sequence',
|
|
95
|
+
'quick_count_holes',
|
|
96
|
+
'single_file_pipeline',
|
|
97
|
+
'restore_backup',
|
|
98
|
+
|
|
99
|
+
# Sequence Builder
|
|
100
|
+
'SequenceBuilder',
|
|
101
|
+
'from_file_name',
|
|
102
|
+
'from_file_part',
|
|
103
|
+
|
|
104
|
+
# Operations
|
|
105
|
+
'Operation',
|
|
106
|
+
'AddMark',
|
|
107
|
+
'AddCircle',
|
|
108
|
+
'SubstituteCircle',
|
|
109
|
+
'AddX',
|
|
110
|
+
'RemoveCircle',
|
|
111
|
+
'RemoveLayer',
|
|
112
|
+
'PrintLayers',
|
|
113
|
+
'Counter',
|
|
114
|
+
'CountFiles',
|
|
115
|
+
'CountHoles',
|
|
116
|
+
'Aligner',
|
|
117
|
+
|
|
118
|
+
# Manager
|
|
119
|
+
'IterationManager',
|
|
120
|
+
'iteration_manager', # Alias legacy
|
|
121
|
+
|
|
122
|
+
# Utils
|
|
123
|
+
'BackupManager',
|
|
124
|
+
'count_holes',
|
|
125
|
+
'mult_campana',
|
|
126
|
+
'find_all_circles',
|
|
127
|
+
'find_circle_by_radius',
|
|
128
|
+
|
|
129
|
+
# Checking
|
|
130
|
+
'find_spec_holes',
|
|
131
|
+
'find_circle_centers',
|
|
132
|
+
'find_longer_entity',
|
|
133
|
+
'print_document_layers',
|
|
134
|
+
'print_entities',
|
|
135
|
+
|
|
136
|
+
# DEPRECATED (manteinence to backward compatibility)
|
|
137
|
+
'Conc',
|
|
138
|
+
'FixSeq',
|
|
139
|
+
]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# ========== DEPRECATION WARNINGS ==========
|
|
144
|
+
|
|
145
|
+
def __getattr__(name):
|
|
146
|
+
"""
|
|
147
|
+
Manages import of deprecated functions with warning.
|
|
148
|
+
"""
|
|
149
|
+
import warnings
|
|
150
|
+
|
|
151
|
+
deprecated = {
|
|
152
|
+
'select_files': 'Use file_pattern in process_folder() instead',
|
|
153
|
+
'iter_on_a_folder': 'Use Operation.process_folder() or IterationManager',
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if name in deprecated:
|
|
157
|
+
warnings.warn(
|
|
158
|
+
f"{name} is deprecated. {deprecated[name]}",
|
|
159
|
+
DeprecationWarning,
|
|
160
|
+
stacklevel=2
|
|
161
|
+
)
|
|
162
|
+
# Per ora solleva errore (funzioni rimosse)
|
|
163
|
+
raise AttributeError(f"Deprecated removed function: {name}")
|
|
164
|
+
|
|
165
|
+
raise AttributeError(f"module 'snapmark' has no attribute '{name}'")
|
|
File without changes
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import ezdxf
|
|
4
|
+
from snapmark.mark_algorithm.mark_algorithm import *
|
|
5
|
+
from snapmark.entities.add_entities import *
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Print the names of the layers
|
|
9
|
+
def print_layers(doc):
|
|
10
|
+
# print("Layers:")
|
|
11
|
+
for layer in doc.layers:
|
|
12
|
+
print(layer.dxf.name)
|
|
13
|
+
return print(layer.dxf.name)
|
|
14
|
+
|
|
15
|
+
def find_spec_holes(doc, diametro_minimo=0, diametro_massimo=float('inf')):
|
|
16
|
+
"""
|
|
17
|
+
Searches for specific holes in a document based on diameter range.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
doc: The document containing the entities to search.
|
|
21
|
+
diametro_minimo: Minimum diameter of the holes to find (default: 0).
|
|
22
|
+
diametro_massimo: Maximum diameter of the holes to find (default: infinity).
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
A list of circular entities that match the specified diameter range.
|
|
26
|
+
"""
|
|
27
|
+
holes = [] # List to store circular entities
|
|
28
|
+
|
|
29
|
+
msp = doc.modelspace() # Access the model space of the drawing
|
|
30
|
+
|
|
31
|
+
# Iterate through all entities in the model space
|
|
32
|
+
for entity in msp.query('CIRCLE'): # Filter only entities of type circle
|
|
33
|
+
diameter = entity.dxf.radius * 2 # Calculate the diameter of the circle
|
|
34
|
+
if diametro_minimo <= diameter <= diametro_massimo:
|
|
35
|
+
holes.append(entity)
|
|
36
|
+
# Add the circular entity to the list if it falls within the diameter range
|
|
37
|
+
|
|
38
|
+
return holes
|
|
39
|
+
|
|
40
|
+
# # Cerca fori specifici
|
|
41
|
+
# def find_spec_holes(doc, diametro_minimo=0, diametro_massimo=float('inf')):
|
|
42
|
+
# holes = [] # Lista per memorizzare le entità circolari
|
|
43
|
+
|
|
44
|
+
# msp = doc.modelspace() # Accedi al modello spaziale del disegno
|
|
45
|
+
|
|
46
|
+
# # Itera attraverso tutte le entità nel modello spaziale
|
|
47
|
+
# for entity in msp.query('CIRCLE'): # Filtra solo le entità di tipo cerchio
|
|
48
|
+
# diametro = entity.dxf.radius * 2 # Calcola il diametro del cerchio
|
|
49
|
+
# if diametro_minimo <= diametro <= diametro_massimo:
|
|
50
|
+
# holes.append(entity)
|
|
51
|
+
# # print(entity)# Aggiungi l'entità circolare alla lista se rientra nel range di diametri
|
|
52
|
+
|
|
53
|
+
# return holes
|
|
54
|
+
|
|
55
|
+
def find_entities(file_path, entity_type):
|
|
56
|
+
"""Return a list of DXF entities of the given type from the specified file."""
|
|
57
|
+
# Load DXF file using ezdxf
|
|
58
|
+
doc = ezdxf.readfile(file_path)
|
|
59
|
+
|
|
60
|
+
# extract entities from model
|
|
61
|
+
msp = doc.modelspace()
|
|
62
|
+
|
|
63
|
+
entities = []
|
|
64
|
+
|
|
65
|
+
# Iterate through all entities of the specified type
|
|
66
|
+
for entity in msp.query(entity_type):
|
|
67
|
+
entities.append(entity)
|
|
68
|
+
|
|
69
|
+
return entities
|
|
70
|
+
|
|
71
|
+
def print_entities(msp):
|
|
72
|
+
for e in msp.query():
|
|
73
|
+
print(e)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# def find_longer_entity(entities):
|
|
78
|
+
|
|
79
|
+
# lato_piu_lungo = None
|
|
80
|
+
# lunghezza_lato_piu_lungo = 0
|
|
81
|
+
# lato_piu_lungo_is_sotto = True
|
|
82
|
+
# minimum_point = float('inf')
|
|
83
|
+
# # Itera tutte le linee nel modello
|
|
84
|
+
# for entity in entities:
|
|
85
|
+
# minimum_point = min(entity.dxf.start.y, entity.dxf.end.y, minimum_point)
|
|
86
|
+
# # Calcola la lunghezza della linea utilizzando il teorema di Pitagora
|
|
87
|
+
# lunghezza = ((entity.dxf.start.x - entity.dxf.end.x) ** 2 + (entity.dxf.start.y - entity.dxf.end.y) ** 2) ** 0.5
|
|
88
|
+
# # Se la lunghezza della linea è maggiore della lunghezza massima finora trovata, aggiornala
|
|
89
|
+
# if lunghezza > lunghezza_lato_piu_lungo:
|
|
90
|
+
# lunghezza_lato_piu_lungo = lunghezza
|
|
91
|
+
# lato_piu_lungo = entity
|
|
92
|
+
|
|
93
|
+
# # Controllare che il lato più lungo sia una linea perimetrale
|
|
94
|
+
# if min(lato_piu_lungo.dxf.start.y, lato_piu_lungo.dxf.end.y) > minimum_point:
|
|
95
|
+
# lato_piu_lungo_is_sotto = False
|
|
96
|
+
|
|
97
|
+
# return lato_piu_lungo, lato_piu_lungo_is_sotto
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def find_longer_entity(entities):
|
|
101
|
+
"""
|
|
102
|
+
Finds the longest entity among the given entities and checks if it is below a certain minimum point.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
entities: A list of entities to evaluate.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
A tuple containing the longest entity and a boolean indicating if it is below the minimum point.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
longest_side = None
|
|
112
|
+
longest_side_length = 0
|
|
113
|
+
longest_side_is_below = True
|
|
114
|
+
minimum_point = float('inf')
|
|
115
|
+
|
|
116
|
+
# Iterate through all the lines in the model
|
|
117
|
+
for entity in entities:
|
|
118
|
+
minimum_point = min(entity.dxf.start.y, entity.dxf.end.y, minimum_point)
|
|
119
|
+
# Calculate the length of the line using the Pythagorean theorem
|
|
120
|
+
length = ((entity.dxf.start.x - entity.dxf.end.x) ** 2 + (entity.dxf.start.y - entity.dxf.end.y) ** 2) ** 0.5
|
|
121
|
+
# If the length of the line is greater than the maximum length found so far, update it
|
|
122
|
+
if length > longest_side_length:
|
|
123
|
+
longest_side_length = length
|
|
124
|
+
longest_side = entity
|
|
125
|
+
|
|
126
|
+
# Check if the longest side is a perimeter line
|
|
127
|
+
if min(longest_side.dxf.start.y, longest_side.dxf.end.y) > minimum_point:
|
|
128
|
+
longest_side_is_below = False
|
|
129
|
+
|
|
130
|
+
return longest_side, longest_side_is_below
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def find_circle_centers(holes_list):
|
|
135
|
+
"""
|
|
136
|
+
Finds the centers of circles from a list of holes.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
holes_list: A list of circular entities representing holes.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
A list of tuples containing the (x, y) coordinates of the circle centers.
|
|
143
|
+
"""
|
|
144
|
+
centers = [] # List to store the centers of the circles
|
|
145
|
+
|
|
146
|
+
# Iterate through the circular entities in the holes_list
|
|
147
|
+
for circle in holes_list: # Use the list passed as an argument
|
|
148
|
+
center_x = circle.dxf.center.x # Extract the x coordinate of the circle's center
|
|
149
|
+
center_y = circle.dxf.center.y # Extract the y coordinate of the circle's center
|
|
150
|
+
centers.append((center_x, center_y)) # Add the x and y coordinates of the center to the list
|
|
151
|
+
|
|
152
|
+
return centers
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def find_circle_centers_2(doc):
|
|
156
|
+
"""
|
|
157
|
+
Searches for circles in a document and detects their centers.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
doc: The document containing the entities to search.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
A list of tuples containing the (x, y) coordinates of the circle centers.
|
|
164
|
+
"""
|
|
165
|
+
centers = [] # List to store the centers of the circles
|
|
166
|
+
|
|
167
|
+
msp = doc.modelspace() # Access the model space of the drawing
|
|
168
|
+
|
|
169
|
+
# Iterate through all entities in the model space
|
|
170
|
+
for circle in msp.query('CIRCLE'): # Filter only entities of type circle
|
|
171
|
+
center_x = circle.dxf.center.x # Extract the x coordinate of the circle's center
|
|
172
|
+
center_y = circle.dxf.center.y # Extract the y coordinate of the circle's center
|
|
173
|
+
centers.append((center_x, center_y)) # Add the x and y coordinates of the center to the list
|
|
174
|
+
|
|
175
|
+
return centers
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def change_layer(entities, new_layer):
|
|
179
|
+
for entity in entities:
|
|
180
|
+
entity.set_dxf_attrib('layer', new_layer)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|