Open-source Revit MCP server: let Claude and other AI assistants read and edit BIM models, with human approval on every change.
Python aecai-agentsautodeskautomationbimclaudeifcmcpmcp-servermodel-context-protocolnavisworksrevitrevit-addinrevit-apirhino
Scaffolds 6 & 7: Rooms + Documentation validation (6 tasks)
sammohammad5786e1d36d4175f
diff --git a/packages/model-checker/src/model_checker/rooms.py b/packages/model-checker/src/model_checker/rooms.pynew file mode 100644index 0000000..5e7400a--- /dev/null+++ b/packages/model-checker/src/model_checker/rooms.py@@ -0,0 +1,279 @@+"""Room and space validation (Scaffold 6) + Documentation validation (Scaffold 7)."""++from __future__ import annotations++from dataclasses import dataclass+from typing import Any+++@dataclass+class RoomIssue:+ """Room or documentation validation issue."""++ element_id: str | int+ element_type: str+ issue_type: str+ description: str+ location: dict[str, float] | None = None+ severity: str = "medium"+++# SCAFFOLD 6: Room and Space Validation++class RoomValidator:+ """Validator for rooms and spaces."""++ def __init__(self) -> None:+ """Initialize room validator."""+ self.issues: list[RoomIssue] = []++ # Task 6.1: Room boundary checker+ def validate_room_boundaries(self, rooms: list[dict[str, Any]]) -> list[RoomIssue]:+ """Validate room boundaries."""+ issues = []++ for room in rooms:+ # Check if room is bound+ if not room.get("is_bound", True):+ issue = RoomIssue(+ element_id=room["id"],+ element_type="room",+ issue_type="unbound",+ description=f"Room '{room.get('name', room['id'])}' is not bound",+ severity="high",+ )+ issues.append(issue)+ self.issues.append(issue)++ # Check for overlapping rooms+ # (simplified - would need actual boundary geometry)+ if room.get("overlaps_with"):+ issue = RoomIssue(+ element_id=room["id"],+ element_type="room",+ issue_type="overlapping",+ description=f"Room overlaps with {room['overlaps_with']}",+ severity="critical",+ )+ issues.append(issue)+ self.issues.append(issue)++ return issues++ # Task 6.2: Area calculation validation+ def validate_room_areas(+ self,+ rooms: list[dict[str, Any]],+ min_area: float = 5.0, # m²+ max_area: float = 500.0, # m²+ ) -> list[RoomIssue]:+ """Validate room areas."""+ issues = []++ for room in rooms:+ area = room.get("area", 0)+ required_area = room.get("required_area")++ # Check minimum area+ if area < min_area:+ issue = RoomIssue(+ element_id=room["id"],+ element_type="room",+ issue_type="area_too_small",+ description=f"Room area {area:.1f}m² is below minimum {min_area}m²",+ )+ issues.append(issue)+ self.issues.append(issue)++ # Check maximum area+ if area > max_area:+ issue = RoomIssue(+ element_id=room["id"],+ element_type="room",+ issue_type="area_too_large",+ description=f"Room area {area:.1f}m² exceeds maximum {max_area}m²",+ )+ issues.append(issue)+ self.issues.append(issue)++ # Check against required area+ if required_area and abs(area - required_area) / required_area > 0.1: # 10% tolerance+ issue = RoomIssue(+ element_id=room["id"],+ element_type="room",+ issue_type="area_mismatch",+ description=f"Room area {area:.1f}m² differs from required {required_area:.1f}m²",+ )+ issues.append(issue)+ self.issues.append(issue)++ return issues++ # Task 6.3: Occupancy and egress validation+ def validate_occupancy(+ self, rooms: list[dict[str, Any]], max_occupant_load_factor: float = 10.0+ ) -> list[RoomIssue]:+ """Validate occupancy loads and egress."""+ issues = []++ for room in rooms:+ area = room.get("area", 0)+ occupant_load = area / max_occupant_load_factor++ # Check exit access+ has_exit = room.get("has_exit_access", False)+ if not has_exit and occupant_load > 1:+ issue = RoomIssue(+ element_id=room["id"],+ element_type="room",+ issue_type="no_exit_access",+ description=f"Room with {occupant_load:.0f} occupants has no exit access",+ severity="critical",+ )+ issues.append(issue)+ self.issues.append(issue)++ # Check exit width (750mm per 50 occupants)+ required_exit_width = (occupant_load / 50) * 750+ actual_exit_width = room.get("exit_width", 0)++ if actual_exit_width < required_exit_width:+ issue = RoomIssue(+ element_id=room["id"],+ element_type="room",+ issue_type="insufficient_exit_width",+ description=f"Exit width {actual_exit_width}mm insufficient for {occupant_load:.0f} occupants (need {required_exit_width:.0f}mm)",+ severity="high",+ )+ issues.append(issue)+ self.issues.append(issue)++ return issues++ def get_issues(self) -> list[RoomIssue]:+ """Get all room issues."""+ return self.issues++ def clear_issues(self) -> None:+ """Clear all issues."""+ self.issues = []+++# SCAFFOLD 7: Documentation Completeness++class DocumentationValidator:+ """Validator for documentation completeness."""++ def __init__(self) -> None:+ """Initialize documentation validator."""+ self.issues: list[RoomIssue] = []++ # Task 7.1: View completeness checker+ def validate_view_coverage(+ self, elements: list[dict[str, Any]], views: list[dict[str, Any]]+ ) -> list[RoomIssue]:+ """Validate that all elements appear in required views."""+ issues = []++ for element in elements:+ element_views = element.get("visible_in_views", [])+ required_view_types = element.get("required_view_types", ["floor_plan"])++ for view_type in required_view_types:+ has_view_type = any(+ view["id"] in element_views and view.get("type") == view_type+ for view in views+ )++ if not has_view_type:+ issue = RoomIssue(+ element_id=element["id"],+ element_type=element.get("type", "element"),+ issue_type="missing_from_view",+ description=f"Element not shown in any {view_type} view",+ severity="medium",+ )+ issues.append(issue)+ self.issues.append(issue)++ return issues++ # Task 7.2: Sheet validation+ def validate_sheets(self, sheets: list[dict[str, Any]]) -> list[RoomIssue]:+ """Validate sheets for completeness."""+ issues = []++ for sheet in sheets:+ # Check for titleblock+ if not sheet.get("has_titleblock"):+ issue = RoomIssue(+ element_id=sheet["id"],+ element_type="sheet",+ issue_type="missing_titleblock",+ description=f"Sheet {sheet.get('number', sheet['id'])} has no titleblock",+ severity="high",+ )+ issues.append(issue)+ self.issues.append(issue)++ # Check for placed views+ viewports = sheet.get("viewports", [])+ if len(viewports) == 0:+ issue = RoomIssue(+ element_id=sheet["id"],+ element_type="sheet",+ issue_type="no_views",+ description=f"Sheet {sheet.get('number', sheet['id'])} has no views placed",+ severity="high",+ )+ issues.append(issue)+ self.issues.append(issue)++ return issues++ # Task 7.3: Revision tracking validation+ def validate_revisions(+ self, sheets: list[dict[str, Any]], revisions: list[dict[str, Any]]+ ) -> list[RoomIssue]:+ """Validate revision tracking."""+ issues = []++ revision_ids = {rev["id"] for rev in revisions}++ for sheet in sheets:+ sheet_revisions = sheet.get("revisions", [])++ for rev_id in sheet_revisions:+ if rev_id not in revision_ids:+ issue = RoomIssue(+ element_id=sheet["id"],+ element_type="sheet",+ issue_type="invalid_revision",+ description=f"Sheet references invalid revision {rev_id}",+ severity="medium",+ )+ issues.append(issue)+ self.issues.append(issue)++ # Check for revision clouds+ has_clouds = sheet.get("has_revision_clouds", False)+ if sheet_revisions and not has_clouds:+ issue = RoomIssue(+ element_id=sheet["id"],+ element_type="sheet",+ issue_type="missing_revision_clouds",+ description="Sheet has revisions but no revision clouds",+ severity="low",+ )+ issues.append(issue)+ self.issues.append(issue)++ return issues++ def get_issues(self) -> list[RoomIssue]:+ """Get all documentation issues."""+ return self.issues++ def clear_issues(self) -> None:+ """Clear all issues."""+ self.issues = []diff --git a/packages/model-checker/tests/test_rooms_and_docs.py b/packages/model-checker/tests/test_rooms_and_docs.pynew file mode 100644index 0000000..d6d624e--- /dev/null+++ b/packages/model-checker/tests/test_rooms_and_docs.py@@ -0,0 +1,135 @@+"""Test room and documentation validation (Scaffolds 6 & 7)."""++from model_checker.rooms import DocumentationValidator, RoomValidator+++# SCAFFOLD 6 TESTS: Rooms++def test_validate_room_boundaries():+ """Test room boundary validation."""+ validator = RoomValidator()++ rooms = [+ {"id": "room_1", "name": "Office 1", "is_bound": True},+ {"id": "room_2", "name": "Office 2", "is_bound": False}, # Unbound+ {"id": "room_3", "name": "Office 3", "is_bound": True, "overlaps_with": "room_1"}, # Overlapping+ ]++ issues = validator.validate_room_boundaries(rooms)+ assert len(issues) == 2 # 1 unbound + 1 overlapping+++def test_validate_room_areas():+ """Test room area validation."""+ validator = RoomValidator()++ rooms = [+ {"id": "room_1", "area": 3.0}, # Too small+ {"id": "room_2", "area": 600.0}, # Too large+ {"id": "room_3", "area": 50.0, "required_area": 60.0}, # Mismatch (>10%)+ {"id": "room_4", "area": 100.0, "required_area": 105.0}, # OK (within 10%)+ ]++ issues = validator.validate_room_areas(rooms, min_area=5.0, max_area=500.0)+ assert len(issues) == 3 # Too small, too large, mismatch+++def test_validate_occupancy():+ """Test occupancy and egress validation."""+ validator = RoomValidator()++ rooms = [+ {"id": "room_1", "area": 100.0, "has_exit_access": True, "exit_width": 1500}, # OK+ {"id": "room_2", "area": 50.0, "has_exit_access": False, "exit_width": 0}, # No exit+ {"id": "room_3", "area": 200.0, "has_exit_access": True, "exit_width": 900}, # Insufficient width+ ]++ issues = validator.validate_occupancy(rooms, max_occupant_load_factor=10.0)+ assert len(issues) >= 2 # No exit + insufficient width+++# SCAFFOLD 7 TESTS: Documentation++def test_validate_view_coverage():+ """Test view coverage validation."""+ validator = DocumentationValidator()++ views = [+ {"id": "view_1", "type": "floor_plan"},+ {"id": "view_2", "type": "section"},+ ]++ elements = [+ {"id": "elem_1", "type": "wall", "visible_in_views": ["view_1"], "required_view_types": ["floor_plan"]}, # OK+ {"id": "elem_2", "type": "beam", "visible_in_views": [], "required_view_types": ["floor_plan"]}, # Missing+ ]++ issues = validator.validate_view_coverage(elements, views)+ assert len(issues) == 1 # elem_2 not in floor plan+++def test_validate_sheets():+ """Test sheet validation."""+ validator = DocumentationValidator()++ sheets = [+ {"id": "sheet_1", "number": "A-101", "has_titleblock": True, "viewports": ["vp_1"]}, # OK+ {"id": "sheet_2", "number": "A-102", "has_titleblock": False, "viewports": []}, # No titleblock, no views+ {"id": "sheet_3", "number": "A-103", "has_titleblock": True, "viewports": []}, # No views+ ]++ issues = validator.validate_sheets(sheets)+ assert len(issues) == 3 # sheet_2: 2 issues, sheet_3: 1 issue+++def test_validate_revisions():+ """Test revision tracking validation."""+ validator = DocumentationValidator()++ revisions = [+ {"id": "rev_1", "description": "Initial Issue"},+ {"id": "rev_2", "description": "Design Development"},+ ]++ sheets = [+ {"id": "sheet_1", "revisions": ["rev_1"], "has_revision_clouds": True}, # OK+ {"id": "sheet_2", "revisions": ["rev_999"], "has_revision_clouds": False}, # Invalid revision+ {"id": "sheet_3", "revisions": ["rev_2"], "has_revision_clouds": False}, # Missing clouds+ ]++ issues = validator.validate_revisions(sheets, revisions)+ assert len(issues) == 3 # sheet_2: invalid revision + missing clouds, sheet_3: missing clouds+++def test_complete_room_workflow():+ """Test complete room validation workflow."""+ validator = RoomValidator()++ rooms = [+ {"id": "office_1", "name": "Office", "is_bound": True, "area": 25.0, "has_exit_access": True, "exit_width": 900},+ {"id": "conf_1", "name": "Conference", "is_bound": False, "area": 2.0, "has_exit_access": False, "exit_width": 0},+ ]++ validator.validate_room_boundaries(rooms)+ validator.validate_room_areas(rooms, min_area=5.0)+ validator.validate_occupancy(rooms)++ issues = validator.get_issues()+ assert len(issues) >= 3 # Unbound, too small area, no exit+++def test_complete_documentation_workflow():+ """Test complete documentation validation workflow."""+ validator = DocumentationValidator()++ views = [{"id": "view_1", "type": "floor_plan"}]+ elements = [{"id": "elem_1", "visible_in_views": [], "required_view_types": ["floor_plan"]}]+ sheets = [{"id": "sheet_1", "number": "A-101", "has_titleblock": False, "viewports": []}]+ revisions = []++ validator.validate_view_coverage(elements, views)+ validator.validate_sheets(sheets)+ validator.validate_revisions(sheets, revisions)++ issues = validator.get_issues()+ assert len(issues) >= 3 # Missing from view + no titleblock + no views