UNPKG

awv3

Version:
177 lines (158 loc) 5.68 kB
import _extends from "@babel/runtime/helpers/extends"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; var _class, _temp2; import * as THREE from 'three'; import React from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import Plugin from '../../session/plugin'; import { actions as connectionActions } from '../../session/store/connections'; import filletPlugin from './../fillet'; import dimensionsPlugin from './../dimensions'; import treePlugin from './../tree'; var HOVERED = THREE.Object3D.Events.Interaction.Hovered; var CLICKED = THREE.Object3D.Events.Interaction.Clicked; var Root = (_temp2 = _class = /*#__PURE__*/ function (_React$Component) { _inheritsLoose(Root, _React$Component); function Root() { var _temp, _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return (_temp = _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this, Object.defineProperty(_assertThisInitialized(_this), "state", { configurable: true, enumerable: true, writable: true, value: { tab: 'Dimensions', items: [] } }), Object.defineProperty(_assertThisInitialized(_this), "handleChange", { configurable: true, enumerable: true, writable: true, value: function value(items) { var _this$context = _this.context, session = _this$context.session, store = _this$context.store, plugin = _this$context.plugin; console.log(_assertThisInitialized(_this)); var root, object = session.selector.selectedObjects[0]; var part = object && object.findReverse(function (obj) { return obj.type === 'Part'; }); if (part) { var instanceProto = plugin.tree[part.userData.id]; if (instanceProto) root = instanceProto.link; } store.dispatch(connectionActions.setActiveRoot(plugin.connection.id, root)); requestAnimationFrame(function () { if (part) plugin.view.controls.focus(part.getCenter()).zoom(part.getRadius() * 8);else plugin.view.controls.focus().zoom(); }); } }), Object.defineProperty(_assertThisInitialized(_this), "changeTab", { configurable: true, enumerable: true, writable: true, value: function value(tab) { return _this.setState({ tab: tab }); } }), _temp) || _assertThisInitialized(_this); } var _proto = Root.prototype; _proto.componentWillUnmount = function componentWillUnmount() { this.context.store.dispatch(connectionActions.setActiveRoot(this.context.plugin.connection.id, undefined)); }; _proto.render = function render() { var _Assembly, _Part, _Mesh; var _state = this.state, tab = _state.tab, items = _state.items; var plugin = this.context.plugin; return React.createElement("group", null, React.createElement("group", { format: "Tabs", value: tab, onValue: this.changeTab }, React.createElement("link", { name: "Assembly", value: plugin.treeview.id, flat: true, collapsable: false, enabled: tab === 'Assembly' }), React.createElement("group", { name: "Dimensions" }, React.createElement("selection", { active: tab === 'Dimensions', types: ['Assembly', 'Part', 'Mesh'], properties: { Assembly: (_Assembly = {}, _Assembly[HOVERED] = { opacity: 0.2 }, _Assembly[CLICKED] = { opacity: 0.2 }, _Assembly), Part: (_Part = {}, _Part[HOVERED] = { color: new THREE.Color('#28d79f'), opacity: 1 }, _Part[CLICKED] = { opacity: 1 }, _Part), Mesh: (_Mesh = {}, _Mesh[HOVERED] = { color: new THREE.Color('#28d79f'), opacity: 1 }, _Mesh[CLICKED] = { opacity: 1 }, _Mesh) }, limit: 1, onItems: this.handleChange }), React.createElement("spacer", null), React.createElement("link", { value: plugin.dimensions.id, flat: true, collapsable: false, enabled: tab === 'Dimensions' })), React.createElement("link", { name: "Edges", value: plugin.fillet.id, flat: true, collapsable: false, enabled: tab === 'Edges' }))); }; return Root; }(React.Component), Object.defineProperty(_class, "contextTypes", { configurable: true, enumerable: true, writable: true, value: { session: PropTypes.object, plugin: PropTypes.object, store: PropTypes.object } }), _temp2); var EditorControls = /*#__PURE__*/ function (_Plugin) { _inheritsLoose(EditorControls, _Plugin); function EditorControls(session, args) { var _this2; _this2 = _Plugin.call(this, session, _extends({ type: 'Controls', render: React.createElement(Root, null) }, args)) || this; _this2.dimensions = new dimensionsPlugin(_this2.session); _this2.dimensions.afterSetCallback = function (dim, name, value) { return dim && dim.members.drivenComponent && _this2.connection.execute("_O.ToolDesigner3d.SetComponentOffset(\"" + _this2.tree[dim.members.drivenComponent.value].name + "\",1,{0,0,-" + value + "});"); }; _this2.fillet = new filletPlugin(_this2.session); _this2.treeview = new treePlugin(_this2.session); return _this2; } return EditorControls; }(Plugin); export { EditorControls as default };