roipoussiere / cadquery-vscode

Build parametric 2D/3D CAD models in VSCode with the CadQuery library.
https://open-vsx.org/extension/roipoussiere/cadquery
MIT License
17 stars 4 forks source link

On start sometimes only the `options` event is thrown and `model` doesn't come #2

Closed bernhard-42 closed 2 years ago

bernhard-42 commented 2 years ago

I have installed CadQuery locally and then I get great code completion and syntax help on hovering. See https://github.com/bernhard-42/jupyter-cadquery/issues/78

bernhard-42 commented 2 years ago

This works in cq-viewer.html:

  function trimUI() {
      viewer.trimUI(["ortho", "axes0"], false);
  }

  function render(model) {
      viewer?.clear();
      const [shapes, states] = model;
      const [group, tree] = viewer.renderTessellatedShapes(shapes, states, options);
      viewer.render(group, tree, states, options);
      setTimeout(trimUI, 100);
  }

  function nc(change) {
      // console.debug('viewer info:', JSON.stringify(change, null, 2));
  }

  function updateView(new_options) {
      container.innerHTML = '';
      viewer = new Viewer(container, Object.assign({}, options, new_options), nc);
      setTimeout(trimUI, 100);
  }

Of course, you shouldn't use setTimeout, but it is a hint that the asynchronous building of the DOM in the background is not ready immediately after new Viewer. You might want to observe whether the viewer is ready, e.g. via an observer as in https://github.com/bernhard-42/three-cad-viewer/blob/ac71278ba4425e46dffc10d37f4dc1f562c3976a/src/treeview.js#L177-L191 (or any smarter method)

roipoussiere commented 2 years ago

Thanks! I will investigate this.

I have installed CadQuery locally and then I get great code completion and syntax help on hovering.

It's an interesting feature actually, I may provide a cadquery type hinting module for users that use the cadquery server.

roipoussiere commented 2 years ago

It should be fixed in the last release. Want to give a try?

bernhard-42 commented 2 years ago

works for me now, closing