Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DXF Module Connection Analyzer

A tool for analyzing connections between DXF modules in an automation database.

Project Structure

The project is organized into the following packages:

  • src/: Main source code directory
    • gui/: GUI-related components
      • dialogs/: Dialog windows
      • widgets/: Custom widgets
    • threads/: Background processing threads
    • models/: Data models
    • utils/: Utility functions and classes

Key Components

  • DXFMetaApp: Main application window
  • MainWindow: Connection analyzer window
  • ModuleProcessorThread: Background thread for processing DXF files
  • IOScannerThread: Background thread for scanning IO modules
  • IOScanner: Utility for analyzing IO blocks
  • DXFParser: Parser for DXF files
  • ConnectionAnalyzer: Analyzer for module connections
  • ConnectionVisualizer: Visualizer for connection graphs

Setup and Running

  1. Ensure you have Python 3.6+ installed
  2. Install required dependencies:
    pip install PyQt5
    
  3. Run the application:
    python src/main.py
    

Usage

  1. Select a modules folder containing DXF files
  2. Load the DXF files to analyze connections
  3. Use the various tabs to explore module details, blocks, and IO connections
  4. Scan for IO blocks to identify input/output connections

Development

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

Features

  • 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

Requirements

  • Python 3.7 or later
  • Dependencies listed in requirements.txt:
    • PyQt5
    • ezdxf
    • networkx
    • matplotlib
    • numpy
    • pandas

Installation

  1. Clone this repository or download the source code
  2. Install the required dependencies:
    pip install -r requirements.txt
    

Usage

Using the Batch File (Recommended)

On Windows, simply run the included batch file:

run_dxf_analyzer.bat

This will:

  1. Check for Python and required dependencies
  2. Create a virtual environment (if needed)
  3. Install required packages
  4. Generate sample DXF files if none exist
  5. Launch the application

Running Directly

  1. Ensure you have DXF files in the data directory (or run python src/create_sample_dxf.py to generate samples)
  2. Run the main application:
    python src/main.py
    

Command Line Testing

For quick testing of the parser and analyzer without the GUI:

python src/test_parser.py

Using the Application

  1. Select a Directory: Click "Select Directory" to choose a folder containing DXF files
  2. Analyze Connections: Click "Analyze Connections" to process the files
  3. Explore Modules: Select modules from the list to see their details and dependencies
  4. 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
  5. View Statistics: Check the "Statistics" tab for metrics about the module connections

Visualization Zooming

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%)

Output Files

All generated visualizations and reports are saved to the output directory:

  • module_connections.png: Graph visualization of all module connections
  • connection_matrix.png: Matrix representation of all dependencies
  • <MODULE_ID>_dependencies.png: Dependency diagram for a specific module
  • connection_report.html: Interactive HTML report with all connection details

Customizing

  • 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

License

This project is licensed under the MIT License - see the LICENSE file for details.

DXFMeta Code Standards and Tools

This repository contains several utilities to help maintain code quality and standards in the DXFMeta application.

Code Standards

We follow these key principles to ensure our code is robust, maintainable, and easy to debug:

  1. Proper Indentation: Use 4 spaces for indentation (no tabs)
  2. Maximum Line Length: 100 characters, hard limit at 120
  3. Function/Method Size: Keep methods under 50 lines
  4. Error Handling: Always use proper try/except blocks
  5. Type Annotations: Use type hints for function parameters and return values
  6. Docstrings: Document all public functions, classes, and methods
  7. Naming Conventions: Use descriptive names, following Python PEP8 guidelines
  8. Modularity: Write code that is loosely coupled and easily movable between files/applications

Utility Tools

The repository includes several utility tools to help enforce and maintain these standards:

1. Code Standards Utility (src/utils/code_standards.py)

This module provides decorators and utility functions to implement code standards and robust error handling patterns:

  • log_exceptions: Decorator to log exceptions raised by functions
  • method_timer: Decorator to time method execution and log slow methods
  • validate_method_length: Decorator to validate method length at import time
  • ensure_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
    pass

2. Syntax Fixer (src/utils/syntax_fixer.py)

A 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

3. Code Analyzer (src/utils/code_analyzer.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

Development Setup

Pre-commit Hooks

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.

VSCode Configuration

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

Best Practices

  1. Error Handling:

    • Always include proper exception handling in try/except blocks
    • Log exceptions with context information
    • Don't use bare except clauses
  2. Code Organization:

    • Keep functions focused on a single responsibility
    • Break long methods into smaller, more focused ones
    • Limit nesting depth to 3 levels maximum
  3. 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
  4. Testing:

    • Write unit tests for critical functionality
    • Use pytest for testing
    • Aim for at least 70% code coverage
  5. 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

Common Issues and Solutions

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

How to Run the Code Quality Tools

# 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages