Assemblies: Set translate and rotate via point-and-click (#6167)
* WIP: Add point-and-click Import for geometry Will eventually fix #6120 Right now the whole loop is there but the codemod doesn't work yet * Better pathToNOde, log on non-working cm dispatch call * Add workaround to updateModelingState not working * Back to updateModelingState with a skip flag * Better todo * Change working from Import to Insert, cleanups * Sister command in kclCommands to populate file options * Improve path selector * Unsure: move importAstMod to kclCommands onSubmit 😶 * Add e2e test * Clean up for review * Add native file menu entry and test * No await yo lint said so * WIP: UX improvements around foreign file imports Fixes #6152 * WIP: Set translate and rotate via point-and-click on imports. Boilerplate code Will eventually close #6020 * Full working loop of rotate and translate pipe mutation, including edits, only on module imports. VERY VERBOSE * Add first e2e test for set transform. Bunch of caveats listed as TODOs * @lrev-Dev's suggestion to remove a comment Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> * Update to scene.settled(cmdBar) * Add partNNN default name for alias * Lint * Lint * Fix unit tests * Add sad path insert test Thanks @Irev-Dev for the suggestion * Add step insert test * Lint * Add test for second foreign import thru file tree click * WIP: Add point-and-click Load to copy files from outside the project into the project Towards #6210 * Move Insert button to modeling toolbar, update menus and toolbars * Add default value for local name alias * Aligning tests * Fix tests * Add padding for filenames starting with a digit * Lint * Lint * Update snapshots * Merge branch 'main' into pierremtb/issue6210-Add-point-and-click-Load-to-copy-files-from-outside-the-project-into-the-project * Add disabled transform subbutton * Allow start of Transform flow from toolbar with selection * Merge kcl-samples and local disk load into one 'Load external model' command * Fix em tests * Fix test * Add test for file pick import, better input * Fix non .kcl loading * Lint * Update snapshots * Fix issue leading to test failure * Fix clone test * Add note * Fix nested clone issue * Clean up for review * Add valueSummary for path * Fix test after path change * Clean up for review * Support much wider range for transform * Set display names * Bug fixed itself moment... * Add test for extrude tranform * Oops missed a thing * Clean up selection arg * More tests incl for variable stuff * Fix imports * Add supportsTransform: true on all solids returning operations * Fix edit flow on variables, add test * Split transform command into translate and rotate * Clean up and comment * Clean up operations.ts * Add comment * Improve assemblies test * Support more things * Typo * Fix test after unit change on import * Last clean up for review * Fix remaining test --------- Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit is contained in:
		@ -169,6 +169,180 @@ test.describe('Point-and-click assemblies tests', () => {
 | 
			
		||||
    }
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  test(
 | 
			
		||||
    `Insert the bracket part into an assembly and transform it`,
 | 
			
		||||
    { tag: ['@electron'] },
 | 
			
		||||
    async ({
 | 
			
		||||
      context,
 | 
			
		||||
      page,
 | 
			
		||||
      homePage,
 | 
			
		||||
      scene,
 | 
			
		||||
      editor,
 | 
			
		||||
      toolbar,
 | 
			
		||||
      cmdBar,
 | 
			
		||||
      tronApp,
 | 
			
		||||
    }) => {
 | 
			
		||||
      if (!tronApp) {
 | 
			
		||||
        fail()
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      const midPoint = { x: 500, y: 250 }
 | 
			
		||||
      const moreToTheRightPoint = { x: 900, y: 250 }
 | 
			
		||||
      const bgColor: [number, number, number] = [30, 30, 30]
 | 
			
		||||
      const partColor: [number, number, number] = [100, 100, 100]
 | 
			
		||||
      const tolerance = 30
 | 
			
		||||
      const u = await getUtils(page)
 | 
			
		||||
      const gizmo = page.locator('[aria-label*=gizmo]')
 | 
			
		||||
      const resetCameraButton = page.getByRole('button', { name: 'Reset view' })
 | 
			
		||||
 | 
			
		||||
      await test.step('Setup parts and expect empty assembly scene', async () => {
 | 
			
		||||
        const projectName = 'assembly'
 | 
			
		||||
        await context.folderSetupFn(async (dir) => {
 | 
			
		||||
          const bracketDir = path.join(dir, projectName)
 | 
			
		||||
          await fsp.mkdir(bracketDir, { recursive: true })
 | 
			
		||||
          await Promise.all([
 | 
			
		||||
            fsp.copyFile(
 | 
			
		||||
              path.join('public', 'kcl-samples', 'bracket', 'main.kcl'),
 | 
			
		||||
              path.join(bracketDir, 'bracket.kcl')
 | 
			
		||||
            ),
 | 
			
		||||
            fsp.writeFile(path.join(bracketDir, 'main.kcl'), ''),
 | 
			
		||||
          ])
 | 
			
		||||
        })
 | 
			
		||||
        await page.setBodyDimensions({ width: 1000, height: 500 })
 | 
			
		||||
        await homePage.openProject(projectName)
 | 
			
		||||
        await scene.settled(cmdBar)
 | 
			
		||||
        await toolbar.closePane('code')
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      await test.step('Insert kcl as module', async () => {
 | 
			
		||||
        await insertPartIntoAssembly(
 | 
			
		||||
          'bracket.kcl',
 | 
			
		||||
          'bracket',
 | 
			
		||||
          toolbar,
 | 
			
		||||
          cmdBar,
 | 
			
		||||
          page
 | 
			
		||||
        )
 | 
			
		||||
        await toolbar.openPane('code')
 | 
			
		||||
        await editor.expectEditor.toContain(
 | 
			
		||||
          `
 | 
			
		||||
        import "bracket.kcl" as bracket
 | 
			
		||||
        bracket
 | 
			
		||||
      `,
 | 
			
		||||
          { shouldNormalise: true }
 | 
			
		||||
        )
 | 
			
		||||
        await scene.settled(cmdBar)
 | 
			
		||||
 | 
			
		||||
        // Check scene for changes
 | 
			
		||||
        await toolbar.closePane('code')
 | 
			
		||||
        await u.doAndWaitForCmd(async () => {
 | 
			
		||||
          await gizmo.click({ button: 'right' })
 | 
			
		||||
          await resetCameraButton.click()
 | 
			
		||||
        }, 'zoom_to_fit')
 | 
			
		||||
        await toolbar.closePane('debug')
 | 
			
		||||
        await scene.expectPixelColor(partColor, midPoint, tolerance)
 | 
			
		||||
        await scene.expectPixelColor(bgColor, moreToTheRightPoint, tolerance)
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      await test.step('Set translate on module', async () => {
 | 
			
		||||
        await toolbar.openPane('feature-tree')
 | 
			
		||||
 | 
			
		||||
        const op = await toolbar.getFeatureTreeOperation('bracket', 0)
 | 
			
		||||
        await op.click({ button: 'right' })
 | 
			
		||||
        await page.getByTestId('context-menu-set-translate').click()
 | 
			
		||||
        await cmdBar.expectState({
 | 
			
		||||
          stage: 'arguments',
 | 
			
		||||
          currentArgKey: 'x',
 | 
			
		||||
          currentArgValue: '0',
 | 
			
		||||
          headerArguments: {
 | 
			
		||||
            X: '',
 | 
			
		||||
            Y: '',
 | 
			
		||||
            Z: '',
 | 
			
		||||
          },
 | 
			
		||||
          highlightedHeaderArg: 'x',
 | 
			
		||||
          commandName: 'Translate',
 | 
			
		||||
        })
 | 
			
		||||
        await page.keyboard.insertText('5')
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await page.keyboard.insertText('0.1')
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await page.keyboard.insertText('0.2')
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await cmdBar.expectState({
 | 
			
		||||
          stage: 'review',
 | 
			
		||||
          headerArguments: {
 | 
			
		||||
            X: '5',
 | 
			
		||||
            Y: '0.1',
 | 
			
		||||
            Z: '0.2',
 | 
			
		||||
          },
 | 
			
		||||
          commandName: 'Translate',
 | 
			
		||||
        })
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await toolbar.closePane('feature-tree')
 | 
			
		||||
        await toolbar.openPane('code')
 | 
			
		||||
        await editor.expectEditor.toContain(
 | 
			
		||||
          `
 | 
			
		||||
        bracket
 | 
			
		||||
          |> translate(x = 5, y = 0.1, z = 0.2)
 | 
			
		||||
        `,
 | 
			
		||||
          { shouldNormalise: true }
 | 
			
		||||
        )
 | 
			
		||||
        // Expect translated part in the scene
 | 
			
		||||
        await scene.expectPixelColor(bgColor, midPoint, tolerance)
 | 
			
		||||
        await scene.expectPixelColor(partColor, moreToTheRightPoint, tolerance)
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      await test.step('Set rotate on module', async () => {
 | 
			
		||||
        await toolbar.closePane('code')
 | 
			
		||||
        await toolbar.openPane('feature-tree')
 | 
			
		||||
 | 
			
		||||
        const op = await toolbar.getFeatureTreeOperation('bracket', 0)
 | 
			
		||||
        await op.click({ button: 'right' })
 | 
			
		||||
        await page.getByTestId('context-menu-set-rotate').click()
 | 
			
		||||
        await cmdBar.expectState({
 | 
			
		||||
          stage: 'arguments',
 | 
			
		||||
          currentArgKey: 'roll',
 | 
			
		||||
          currentArgValue: '0',
 | 
			
		||||
          headerArguments: {
 | 
			
		||||
            Roll: '',
 | 
			
		||||
            Pitch: '',
 | 
			
		||||
            Yaw: '',
 | 
			
		||||
          },
 | 
			
		||||
          highlightedHeaderArg: 'roll',
 | 
			
		||||
          commandName: 'Rotate',
 | 
			
		||||
        })
 | 
			
		||||
        await page.keyboard.insertText('0.1')
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await page.keyboard.insertText('0.2')
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await page.keyboard.insertText('0.3')
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await cmdBar.expectState({
 | 
			
		||||
          stage: 'review',
 | 
			
		||||
          headerArguments: {
 | 
			
		||||
            Roll: '0.1',
 | 
			
		||||
            Pitch: '0.2',
 | 
			
		||||
            Yaw: '0.3',
 | 
			
		||||
          },
 | 
			
		||||
          commandName: 'Rotate',
 | 
			
		||||
        })
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await toolbar.closePane('feature-tree')
 | 
			
		||||
        await toolbar.openPane('code')
 | 
			
		||||
        await editor.expectEditor.toContain(
 | 
			
		||||
          `
 | 
			
		||||
        bracket
 | 
			
		||||
          |> translate(x = 5, y = 0.1, z = 0.2)
 | 
			
		||||
          |> rotate(roll = 0.1, pitch = 0.2, yaw = 0.3)
 | 
			
		||||
        `,
 | 
			
		||||
          { shouldNormalise: true }
 | 
			
		||||
        )
 | 
			
		||||
        // Expect no change in the scene as the rotations are tiny
 | 
			
		||||
        await scene.expectPixelColor(bgColor, midPoint, tolerance)
 | 
			
		||||
        await scene.expectPixelColor(partColor, moreToTheRightPoint, tolerance)
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  test(
 | 
			
		||||
    `Insert foreign parts into assembly as whole module import`,
 | 
			
		||||
    { tag: ['@electron'] },
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user