A tool for analyzing connections between DXF modules in an automation database.
The project is organized into the following packages:
src/: Main source code directorygui/: GUI-related componentsdialogs/: Dialog windowswidgets/: Custom widgets
threads/: Background processing threadsmodels/: Data modelsutils/: Utility functions and classes
DXFMetaApp: Main application windowMainWindow: Connection analyzer windowModuleProcessorThread: Background thread for processing DXF filesIOScannerThread: Background thread for scanning IO modulesIOScanner: Utility for analyzing IO blocksDXFParser: Parser for DXF filesConnectionAnalyzer: Analyzer for module connectionsConnectionVisualizer: Visualizer for connection graphs
- Ensure you have Python 3.6+ installed
- Install required dependencies:
pip install PyQt5 - Run the application:
python src/main.py
- Select a modules folder containing DXF files
- Load the DXF files to analyze connections
- Use the various tabs to explore module details, blocks, and IO connections
- Scan for IO blocks to identify input/output connections
The application is built with a modular architecture to facilitate maintenance and extension:
- GUI components are separated from business logic
- Background processing is done in threads to keep the UI responsive
- Data persistence is handled through a SQLite database
- IO block definitions are saved in application settings for persistence
- DXF File Parsing: Extracts module information and reference data from DXF files
- Connection Analysis: Identifies connections between modules based on reference notations
- Visualization:
- Connection graph showing all modules and their relationships
- Connection matrix for a quick overview of all dependencies
- Individual module dependency diagrams
- Interactive HTML report with detailed connection information
- Direct visualization in the GUI: All visualizations are now displayed directly in the application window
- Interactive zooming: Zoom in/out using buttons, slider, or mouse wheel to explore complex graphs
- Option to open visualizations in external viewers
- Statistics: Calculates metrics like connection density and dependency counts
- Circular Dependency Detection: Identifies circular dependencies in the module network
- User-friendly GUI: Explore and analyze connections with an intuitive interface
- Python 3.7 or later
- Dependencies listed in
requirements.txt:- PyQt5
- ezdxf
- networkx
- matplotlib
- numpy
- pandas
- Clone this repository or download the source code
- Install the required dependencies:
pip install -r requirements.txt
On Windows, simply run the included batch file:
run_dxf_analyzer.bat
This will:
- Check for Python and required dependencies
- Create a virtual environment (if needed)
- Install required packages
- Generate sample DXF files if none exist
- Launch the application
- Ensure you have DXF files in the
datadirectory (or runpython src/create_sample_dxf.pyto generate samples) - Run the main application:
python src/main.py
For quick testing of the parser and analyzer without the GUI:
python src/test_parser.py
- Select a Directory: Click "Select Directory" to choose a folder containing DXF files
- Analyze Connections: Click "Analyze Connections" to process the files
- Explore Modules: Select modules from the list to see their details and dependencies
- Generate Visualizations:
- In the "Visualizations" tab, select the desired visualization type
- Click "Generate" to create and display the visualization directly in the application
- The visualization will be displayed in the main window
- Use the zoom controls (buttons, slider, or mouse wheel) to zoom in/out for detailed inspection
- Use the "Open in External Viewer" button to view the visualization in your system's default application
- View Statistics: Check the "Statistics" tab for metrics about the module connections
The application now provides interactive zooming for visualizations:
- Use the "+" and "−" buttons to zoom in and out
- Adjust the zoom slider for precise control (10% to 500%)
- Use the mouse wheel over the image to zoom in/out quickly
- Click the "Reset" button to return to the original size (100%)
All generated visualizations and reports are saved to the output directory:
module_connections.png: Graph visualization of all module connectionsconnection_matrix.png: Matrix representation of all dependencies<MODULE_ID>_dependencies.png: Dependency diagram for a specific moduleconnection_report.html: Interactive HTML report with all connection details
- Sample DXF creation can be customized in
src/create_sample_dxf.py - Visualization settings can be adjusted in
src/visualizer.py - Parser settings for different reference formats can be modified in
src/dxf_parser.py
This project is licensed under the MIT License - see the LICENSE file for details.
This repository contains several utilities to help maintain code quality and standards in the DXFMeta application.
We follow these key principles to ensure our code is robust, maintainable, and easy to debug:
- Proper Indentation: Use 4 spaces for indentation (no tabs)
- Maximum Line Length: 100 characters, hard limit at 120
- Function/Method Size: Keep methods under 50 lines
- Error Handling: Always use proper try/except blocks
- Type Annotations: Use type hints for function parameters and return values
- Docstrings: Document all public functions, classes, and methods
- Naming Conventions: Use descriptive names, following Python PEP8 guidelines
- Modularity: Write code that is loosely coupled and easily movable between files/applications
The repository includes several utility tools to help enforce and maintain these standards:
This module provides decorators and utility functions to implement code standards and robust error handling patterns:
log_exceptions: Decorator to log exceptions raised by functionsmethod_timer: Decorator to time method execution and log slow methodsvalidate_method_length: Decorator to validate method length at import timeensure_exception_handling: Decorator to ensure a function has proper exception handling
Example usage:
from src.utils.code_standards import log_exceptions, method_timer
@log_exceptions()
@method_timer(threshold_ms=100)
def my_function(arg1, arg2):
# Your code here
passA utility script to automatically fix common syntax issues in Python files:
- Missing except clauses in try blocks
- Indentation issues
- Duplicate code blocks
- Nested conditionals
Usage:
python -m src.utils.syntax_fixer path/to/file.py
A tool to analyze Python files for common issues:
- Method/function length
- Code complexity
- Missing exception handling
- Improper indentation
- Duplicate code
- Missing docstrings
- Type annotation issues
Usage:
python -m src.utils.code_analyzer path/to/file.py
To enforce code standards automatically, we use pre-commit hooks. Install them with:
pip install pre-commit
pre-commit install
This will run the configured hooks from .pre-commit-config.yaml before each commit.
The repository includes VSCode settings (.vscode/settings.json) that configure the editor to follow our code standards. This ensures:
- Correct formatting on save
- Linting with Flake8
- Type checking with mypy
- Import organization with isort
- Enforcing proper indentation and line length
-
Error Handling:
- Always include proper exception handling in try/except blocks
- Log exceptions with context information
- Don't use bare except clauses
-
Code Organization:
- Keep functions focused on a single responsibility
- Break long methods into smaller, more focused ones
- Limit nesting depth to 3 levels maximum
-
Modularity:
- Use dependency injection rather than direct imports when possible
- Avoid direct dependencies on global state or singleton instances
- Minimize side effects; functions should be largely self-contained
- Group related functionality together in logical modules or classes
- Use interfaces/protocols to define clear module boundaries
- Pass configuration as parameters rather than reading global configs
- Prefer composition over inheritance for flexibility
- Create pure functions where possible (same inputs always produce same outputs)
- Structure code so individual components can be tested in isolation
-
Testing:
- Write unit tests for critical functionality
- Use pytest for testing
- Aim for at least 70% code coverage
-
Performance:
- Use the method_timer decorator to identify slow functions
- Process data in batches when dealing with large datasets
- Consider user experience by keeping the UI responsive
| Issue | Solution |
|---|---|
| Missing except clause | Always add an appropriate except or finally clause after a try |
| Inconsistent indentation | Use 4 spaces consistently for indentation levels |
| Functions too long | Break down long functions into smaller, more focused helper functions |
| Bare except clause | Specify the exception type to catch rather than using a bare except |
| Duplicated code | Extract repeated logic into helper functions |
| Tight coupling | Use dependency injection and interfaces to reduce direct dependencies |
# Check a file for code quality issues
python -m src.utils.code_analyzer path/to/your_file.py
# Fix common syntax issues in a file
python -m src.utils.syntax_fixer path/to/your_file.py
# Run pre-commit hooks manually on all files
pre-commit run --all-files