Metadata-Version: 2.4
Name: cadi_saml
Version: 0.4.0
Summary: CADi SAML: Deterministic, Zero-Coordinate, LLM-Native CAD & Kinematics Engine for Python built on OpenCASCADE
Author: CADi Team
License: MIT
Project-URL: Homepage, https://github.com/Omerersen/Project-CAD-
Project-URL: Repository, https://github.com/Omerersen/Project-CAD-
Keywords: cad,opencascade,brep,llm,ai,parametric,assembly,3d-modeling,cadpy,mechanical-engineering
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Manufacturing
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: pyyaml>=6.0
Requires-Dist: numpy>=1.24.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: twine>=5.0.0; extra == "dev"

# CADi SAML — Semantic Assembly Modeling Language for Python

[![PyPI Version](https://img.shields.io/pypi/v/cadi_saml.svg)](https://pypi.org/project/cadi_saml/)
[![Python Versions](https://img.shields.io/pypi/pyversions/cadi_saml.svg)](https://pypi.org/project/cadi_saml/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

**Deterministic, Zero-Coordinate, LLM-Native CAD & Kinematics Engine built on OpenCASCADE (OCCT)**

`cadi_saml` is a high-level Python CAD library purpose-built for AI/LLM code generation and mechanical engineering automation. Instead of thousands of lines of fragile coordinate transformations, `cadi_saml` enables declarative modeling — using semantic ports, kinematic joint mates, cascading parametric formulas, and monolithic mechanical assemblies — while an industrial-grade OpenCASCADE core generates watertight B-Rep solids, 2D ISO drawings, and interactive 3D WebGL motion simulations.

---

## ⚡ Quick Installation

```bash
pip install cadi_saml
```

*Note: For full B-Rep solid kernel compilation, ensure an OpenCASCADE Python binding (such as `cadquery-ocp` / `OCP`) is available in your Python environment.*

---

## 🚀 Key Features

### 1. Planar Linkages & Reciprocating Engines
Model authentic monolithic crankshafts, connecting rods, pistons, and engine frames with coupled non-linear kinematics:

```python
from cadi_saml import Assembly, OCCTBackend

with Assembly("Planar_Crank_Slider", units="mm", material="Steel4140") as asm:
    # 1. Engine Bedplate Frame with Main Bearing Stand & 36mm Cylinder Bore
    frame = asm.add_engine_frame(
        "engine_frame",
        base_length=250.0,
        base_width=90.0,
        cylinder_bore_dia=36.0,
        origin=(0.0, 0.0, 0.0)
    )

    # 2. Monolithic Counterweighted Crankshaft (R=30mm)
    crank = asm.add_crankshaft(
        "crankshaft",
        crank_radius=30.0,
        disc_radius=44.0,
        origin=(0.0, 0.0, 17.0)
    )

    # 3. Forged Connecting Rod (L=90mm)
    conrod = asm.add_connecting_rod(
        "connecting_rod",
        length=90.0,
        origin=(30.0, 0.0, 27.0)
    )

    # 4. Horizontal Slider Piston with Ring Grooves & Wristpin
    piston = asm.add_slider_piston(
        "slider_piston",
        diameter=34.0,
        length=42.0,
        origin=(120.0, 0.0, 32.0)
    )

    # Define Kinematic Joints
    asm.add_revolute_joint("crankshaft", origin=(0.0, 0.0, 17.0), axis=(0.0, 0.0, 1.0))
    asm.add_revolute_joint("connecting_rod", origin=(30.0, 0.0, 27.0), axis=(0.0, 0.0, 1.0))
    asm.add_prismatic_joint("slider_piston", origin=(120.0, 0.0, 32.0), axis=(1.0, 0.0, 0.0))

    # Coupled Planar Slider-Crank Motion Coupler
    asm.add_slider_crank_relation(
        crank_part="crankshaft",
        conrod_part="connecting_rod",
        piston_part="slider_piston",
        crank_radius=30.0,
        conrod_length=90.0,
        crank_center=(0.0, 0.0, 17.0),
        slide_axis=(1.0, 0.0, 0.0)
    )

    # Solve forward kinematics at 90° crank rotation
    states = asm.solve_motion("crankshaft", value=90.0)
    print(f"Piston Position: {states['slider_piston'].translation_mm:.2f} mm")

    # Generate interactive 3D WebGL motion animation
    asm.export_motion_html("planar_mechanism.html", driver_part="crankshaft")
```

---

### 2. Involute Spur & Helical Gear Transmissions
High-precision gear modeling with standard modules, pitch circles, keyways, and automatic center-distance speed ratios:

```python
with Assembly("GearReductionStage", units="mm") as asm:
    # Driving Pinion (m=2.5 mm, z=20)
    pinion = asm.add_spur_gear("pinion", module=2.5, teeth=20, face_width=25.0, bore_dia=16.0, origin=(0, 0, 0))

    # Driven Wheel (m=2.5 mm, z=40) at Center Distance a = 75 mm
    wheel = asm.add_spur_gear("wheel", module=2.5, teeth=40, face_width=25.0, bore_dia=25.0, origin=(75.0, 0, 0))

    # Kinematic Transmission Mate (i = 20 / 40 = 0.5)
    asm.add_revolute_joint("pinion", origin=(0, 0, 0), axis=(0, 0, 1))
    asm.add_revolute_joint("wheel", origin=(75.0, 0, 0), axis=(0, 0, 1))
    asm.add_gear_relation("pinion", "wheel", ratio=0.5, reverse=True)
```

---

### 3. Sheet Metal with DIN 6935 K-Factor Bend Deduction
Generate folded sheet metal parts with exact industrial bend allowances and flat pattern calculation:

```python
with Assembly("SheetMetalEnclosure", units="mm") as asm:
    bracket = asm.add_sheet_metal_bracket(
        name="chassis_mount",
        bracket_type="U",
        width=50.0,
        length1=60.0,
        length2=40.0,
        thickness=2.0,
        k_factor=0.44,
        hole_diameter=6.5
    )
```

---

### 4. Motorsport Running Gear & High-Performance Suspension
Formula Student and GT3 racing standard parts library:

```python
with Assembly("MotorsportCorner", units="mm") as asm:
    rotor = asm.add_brake_rotor("ventilated_rotor", outer_diameter=240.0)
    caliper = asm.add_brake_caliper("caliper", length=140.0)
    nut = asm.add_centerlock_nut("wheel_nut", size="M30")
    coilover = asm.add_coilover("suspension_damper", extended_length=320.0, stroke=80.0, wire_dia=10.0)
    rod_end = asm.add_heim_joint("heim_joint", thread_size="M10")
```

---

### 5. Standard Hardware & Modular Profiles
Single-line insertion of off-the-shelf industrial parts:

```python
# Aluminum Extrusion Profiles
rail = asm.add_profile("rail_x", profile_type="2040", length=300.0)

# Stepper Motors
motor = asm.add_motor("z_stepper", frame="NEMA17", body_length=40.0)

# Bearings & Fasteners
bearing = asm.add_bearing("shaft_bearing", standard="SKF", code="608ZZ")
bolt = asm.add_bolt("clamp_bolt", size="M6", length=25.0)
```

---

### 6. Organic Modeling & NACA Aerodynamics
Exact C2-continuous aerodynamic NACA 4-digit airfoil lofts:

```python
with Assembly("AerodynamicWing", units="mm") as asm:
    root = asm.section_naca(code="2412", chord=160.0, center=(0, 0, 0))
    tip = asm.section_naca(code="0012", chord=100.0, center=(0, 250.0, 30.0))
    wing = asm.add_loft("fsae_rear_wing", sections=[root, tip])
```

---

### 7. Automated 2D ISO Engineering Drawings
Export multi-view engineering technical drawings with OpenCASCADE Hidden Line Removal (HLR):

```python
asm.export_drawing(
    filepath="technical_drawing.svg",
    sheet_size="A4",
    title="PLANAR CRANK-SLIDER MECHANISM",
    material="Steel4140"
)
```

---

### 8. Geometry Validation & Physical Properties
Full B-Rep manifold verification, clash detection, and GProp physical mass properties:

```python
from cadi_saml import ValidationEngineer

validator = ValidationEngineer()
validator.check_manifold(solid)       # Is it a watertight manifold 3D solid?
clashes = validator.check_clashes(solids) # Are components colliding?

# Physical mass & center of gravity calculation
mass_props = asm.get_mass_properties()
print(f"Total Mass: {mass_props['total_mass_kg']:.3f} kg")
print(f"Center of Gravity: {mass_props['center_of_gravity']}")
```

---

## 📦 Multi-Format Export Support

| Format | Extension | Target |
|---|---|---|
| **STEP** | `.step`, `.stp` | SolidWorks, Siemens NX, CATIA, Fusion 360, FreeCAD |
| **IGES** | `.igs`, `.iges` | Legacy CAM / CNC Machining |
| **STL** | `.stl` | 3D Printing (SLA / SLS / FDM) |
| **GLTF** | `.gltf`, `.glb` | Three.js, Blender, Unreal Engine, Web 3D |
| **SVG** | `.svg` | ISO 2D Engineering Drawings with Title Block |
| **HTML** | `.html` | Standalone interactive 3D WebGL Motion Player |

---

## 📄 License
MIT License. Developed by the CADi Team.
