diff --git a/examples/assembly.ipynb b/examples/assembly.ipynb index 2fee49c..dc57012 100644 --- a/examples/assembly.ipynb +++ b/examples/assembly.ipynb @@ -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" ] } ], @@ -44,26 +44,13 @@ "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)" ] }, { @@ -71,43 +58,15 @@ "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": [ { diff --git a/orion_cli/cli.py b/orion_cli/cli.py index 2f63b0b..c77e4f6 100644 --- a/orion_cli/cli.py +++ b/orion_cli/cli.py @@ -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) @@ -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 @@ -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) @@ -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 diff --git a/orion_cli/helpers/remote_helper.py b/orion_cli/helpers/remote_helper.py index 79fbff2..41b9aab 100644 --- a/orion_cli/helpers/remote_helper.py +++ b/orion_cli/helpers/remote_helper.py @@ -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.") @@ -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' diff --git a/orion_cli/services/cad_service.py b/orion_cli/services/cad_service.py index ce29358..18a6421 100644 --- a/orion_cli/services/cad_service.py +++ b/orion_cli/services/cad_service.py @@ -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 @@ -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 @@ -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 @@ -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) @@ -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}") diff --git a/orion_cli/services/create_service.py b/orion_cli/services/create_service.py index 907ba9d..7c1df49 100644 --- a/orion_cli/services/create_service.py +++ b/orion_cli/services/create_service.py @@ -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.") diff --git a/pyproject.toml b/pyproject.toml index e8ab1ff..ca86de9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 ", "Christian "] readme = "README.md" @@ -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'"}