Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Type compoment + drawing count in the Stat module #17

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

## [Unreleased]
### Added
- Adding the type of component into the display of the stat module
- Adding a flag to filter the type of components
- Adding the number of drawings using the parts
### Changed
### Deprecated
### Removed
### Fixed
- Fixing an issue with the configuration name removal. Some parts were not correctly counted in the tree display.
### Security

## v0.7.1 - 2024/09/12
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ You can select the sort mode with `--type-sort`:
- `mass-part`: sort with a decreasing part mass
- `name`: sort with alphabetical order

You can select the type of compoments to include with `--filter`:
- `all`: (default) get both parts and assemblies
- `part`: get only parts. Works only for list display
- `assembly`: get only assemblies

You can get only the elements with a default density (1000 Kg/m³) with the option `--only-default-density`. This option only works with a `type `list`

### Clean
Expand Down
18 changes: 17 additions & 1 deletion pyswtools/helper_sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def open_app_and_file(path_file: str):
# Open app
sw_app = open_app()

# Open the assembly
# Open the file
sw_doc = sw_app.OpenDoc6(os.path.abspath(path_file), 2, 1, "", VT_BYREF, VT_BYREF)

# Get the filename
Expand All @@ -45,6 +45,22 @@ def open_app_and_file(path_file: str):
return sw_app, sw_doc, filename


def open_drawing(sw_app, path_file: str):
"""
Create open document activate it
"""
# Open the assembly
sw_doc = sw_app.OpenDoc6(os.path.abspath(path_file), 3, 1, "", VT_BYREF, VT_BYREF)

# Get the filename
_, filename = os.path.split(path_file)

# Activate it
sw_app.ActivateDoc3(filename, True, 2, VT_BYREF)

return sw_doc, filename


def is_assembly(path: str) -> bool:
"""Return True if paths point to an assembly file"""
return ".SLDASM" in path.upper()
Expand Down
46 changes: 46 additions & 0 deletions pyswtools/stat/definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from enum import Enum
from dataclasses import dataclass, asdict


class TypeComponent(str, Enum):
"""Class represeting an type of parts"""

PART = "part"
ASSEMBLY = "assembly"
ALL = "all"


class TypeOutput(str, Enum):
"""Class represeting an output type"""

TREE = "tree"
LIST = "list"


class TypeSort(str, Enum):
"""Class represeting an output type"""

MASS = "mass"
MASS_PART = "mass-part"
NAME = "name"


@dataclass
class StatComponentTree:
number: int
children: list

def dict(self):
return {k: v for k, v in asdict(self).items()}


@dataclass
class StatComponent:
mass: float
density: float
number: int
typeComponent: TypeComponent
numberDrawing: int

def dict(self):
return {k: v for k, v in asdict(self).items()}
Loading
Loading