Skip to content

Commit

Permalink
Release changes
Browse files Browse the repository at this point in the history
  • Loading branch information
afshawnlotfi committed Jul 26, 2024
1 parent d2ee229 commit 876ed95
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 64 deletions.
49 changes: 4 additions & 45 deletions examples/assembly.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"output_type": "stream",
"text": [
"Reading STEP file ... parsing Assembly ... done\n",
"duration: 6.5 s\n"
"duration: 6.7 s\n"
]
}
],
Expand All @@ -44,70 +44,29 @@
"assemblies = CadService.read_cq_assembly(cq_assembly, project, index)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from jupyter_cadquery.viewer import show\n",
"show(project.root_assembly.to_cq(project))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"new_project = Project()\n",
"new_index = AssemblyIndex(prev_project=project)\n",
"\n",
"rev_assemblies = CadService.read_cq_assembly(cq_assembly, new_project, new_index)\n"
"CadService.write_project(\"examples/test/Robot\", project, index)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"CadService.write_project(\"examples/test/Robot\", new_project, new_index)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from orion_cli.services.cad_service import CadService, Project, AssemblyIndex\n",
"\n",
"project = CadService.read_project(\"examples/test/Robot\")\n",
"\n",
"# CadService.write_assets(\"examples/test/Robot\", project)\n",
"# out = CadService.get_inventory_markdown(project.inventory, \"examples/test/Robot\")\n",
"# with open(\"/workspaces/orion-cli/examples/test/Robot/inventory/README.md\", \"w\") as f:\n",
"# f.write(out)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"new_project2 = Project()\n",
"new_index2 = AssemblyIndex(prev_project=project)\n",
"\n",
"rev_assemblies = CadService.read_cq_assembly(cq_assembly, new_project2, new_index2)\n"
"project = CadService.read_project(\"examples/test/Robot\")"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down
23 changes: 17 additions & 6 deletions orion_cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
from pathlib import Path
from typing import Optional, Union
import click
import os

from orion_cli.services.display_service import DisplayService
from orion_cli.services.log_service import logger
from typing import Optional
import pkg_resources

version = pkg_resources.get_distribution("orion_cli").version

logo = """
____ _ _______ ____
/ __ \____(_)__ ___ / ___/ / / _/
/ /_/ / __/ / _ \/ _ \ / /__/ /___/ /
\____/_/ /_/\___/_//_/ \___/____/___/
"""

click.echo(logo)


@click.group()
@click.version_option()
@click.version_option(version=version)
def cli():
"""Command-line tool for Open Orion PLM"""


@cli.command(name="create")
@click.option("--name", help="The name of the project", required=False)
Expand All @@ -28,7 +39,7 @@ def create_command(name: str, cad_path: str, remote_url: Optional[str], include_
project_path = Path.cwd()


name = click.prompt("Please enter the project name")
name = str(click.prompt("Please enter the project name")).strip()

full_project_path = project_path / name

Expand All @@ -44,7 +55,7 @@ def create_command(name: str, cad_path: str, remote_url: Optional[str], include_

# Prompt the user for inputs if not provided
if not cad_path:
cad_path = click.prompt("CAD file (*.step, *.stp)", type=click.Path(exists=True))
cad_path = str(click.prompt("CAD file (*.step, *.stp)", type=click.Path(exists=True))).strip()

if not remote_url:
provide_remote_url = click.confirm("Would you like to provide the URL of the remote Git repository?", default=False)
Expand Down Expand Up @@ -109,7 +120,7 @@ def revision_command(project_path: Union[str, Path], cad_path: str):
@cli.command(name="display")
@click.option("--project-path", type=click.Path(exists=True),help="The path of the project to be revised", required=False)
def display_command(project_path: Union[str, Path]):
"""Update the project structure and commit the changes"""
"""Display the CAD file as three.js html file"""
from orion_cli.services.revision_service import RevisionService
from pathlib import Path
from orion_cli.helpers.config_helper import ConfigHelper
Expand Down
4 changes: 2 additions & 2 deletions orion_cli/helpers/remote_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_valid_remote_url(cls, initial_url: Optional[str] = None) -> Optional[str
while True:
if remote_url is not None:
if cls.validate_remote_url(remote_url):
return remote_url
return remote_url.strip()
else:
click.echo("Invalid remote repository or access denied.")

Expand All @@ -56,7 +56,7 @@ def get_valid_remote_url(cls, initial_url: Optional[str] = None) -> Optional[str
)

if choice == '1':
remote_url = click.prompt("Please enter a valid remote URL", type=str)
remote_url = str(click.prompt("Please enter a valid remote URL", type=str)).strip()
elif choice == '2':
return None
else: # choice == '3'
Expand Down
20 changes: 13 additions & 7 deletions orion_cli/services/cad_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InvetoryPartVariationMetadata(BaseModel):

class InventoryPartVariation(BaseModel):
id: int
references: set[AssemblyPath] = Field(default_factory=set)
references: list[AssemblyPath] = Field(default_factory=list)
color: Optional[list[float]] = None
metadata: Optional[InvetoryPartVariationMetadata] = None

Expand Down Expand Up @@ -311,10 +311,11 @@ def read_cq_assembly(

# if variation does not exist, create a new one, otherwise add part reference
if not existing_variation:
part_variation = InventoryPartVariation(id=part_ref.variation.id, references={part_ref.path}, color=part_color)
part_variation = InventoryPartVariation(id=part_ref.variation.id, references=[part_ref.path], color=part_color)
project.inventory.catalog.items[part_checksum].variations.append(part_variation)
else:
existing_variation.references.add(part_ref.path)
if part_ref.path not in existing_variation.references:
existing_variation.references.append(part_ref.path)
part_variation = existing_variation

# keep the metadata from the previous project
Expand Down Expand Up @@ -652,7 +653,7 @@ def revise_project(project_path: Path, cad_path: Path, write=False, project_opti
CadService.read_cq_assembly(cq_assembly, revised_project, index)

if write:
CadService.write_project(project_path, revised_project, verbose=verbose)
CadService.write_project(project_path, revised_project, index, verbose=verbose)

return revised_project

Expand Down Expand Up @@ -688,7 +689,7 @@ def read_project(project_path: Union[Path, str]):
return project

@staticmethod
def visualize_project(project_path: Union[Path, str], remote_viewer=False, export_html=True, verbose=True):
def visualize_project(project_path: Union[Path, str], remote_viewer=False, export_html=True, auto_open=True, verbose=True):
logger.setLevel(logging.INFO if verbose else logging.ERROR)

project_path = Path(project_path)
Expand All @@ -703,5 +704,10 @@ def visualize_project(project_path: Union[Path, str], remote_viewer=False, expor
viewer = CadHelper.get_viewer(cq_assembly, orion_cache_path / "tesselation.cache", remote_viewer)

if viewer and export_html:
viewer.export_html(str(orion_cache_path / "index.html"))
logger.info(f"Exported HTML to {orion_cache_path / 'index.html'}, open in browser to view")
html_path = orion_cache_path / 'index.html'
viewer.export_html(str(html_path))
logger.info(f"\n\nExported HTML to {html_path}")
# open html in browser
# if auto_open:
import webbrowser
webbrowser.open(f"file://{html_path}")
2 changes: 0 additions & 2 deletions orion_cli/services/create_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,5 @@ def create(self, name: str, path: Union[str, Path], cad_path: Union[str, Path],

# Make initial commit
subprocess.run(["git", "add", "."], cwd=project_path, check=True)
subprocess.run(["git", "commit", "-m", "Initial commit"], cwd=project_path, check=True)
click.echo("Initial commit made.")


4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "orion-cli"
version = "0.1.0"
version = "0.1.1"
description = "Command-line tool for Open Orion PLM"
authors = ["Afshawn Lotfi <[email protected]>", "Christian <[email protected]>"]
readme = "README.md"
Expand All @@ -13,7 +13,7 @@ requests = "^2.32.3"
pygithub = "^2.3.0"
numpy = "<2.0.0"
cadquery = [
{version = "^2.4.0", markers = "platform_machine != 'arm64'"},
{version = "^2.4.0", markers = "platform_machine != 'arm64' and platform_machine != 'aarch64'"},
]
cadquery-arm = [
{version = "*", markers = "sys_platform == 'darwin' and platform_machine == 'arm64'"}
Expand Down

0 comments on commit 876ed95

Please sign in to comment.