awv3
Version:
⚡ AWV3 embedded CAD
170 lines (148 loc) • 5.11 kB
JavaScript
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _extends from "@babel/runtime/helpers/extends";
var _dec, _class, _class2, _temp2;
import * as THREE from 'three';
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import Plugin from '../../session/plugin';
import Selector from '../../session/selector';
import { actions as connectionActions } from '../../session/store/connections';
var HOVERED = THREE.Object3D.Events.Interaction.Hovered;
var CLICKED = THREE.Object3D.Events.Interaction.Clicked;
var RESOURCES = ['isometric'].reduce(function (prev, item) {
var _extends2;
return _extends({}, prev, (_extends2 = {}, _extends2[item] = require('!!url-loader!awv3-icons/32x32/' + item + '.png'), _extends2));
}, {});
var Root = (_dec = connect(function (state, props) {
var activeConnection = state.globals.activeConnection;
if (!activeConnection) return {};
var connection = state.connections[activeConnection];
var tree = connection.tree;
var root = connection.activeRoot || tree.root;
return {
connection: activeConnection,
instances: tree[tree.root].instances,
root: root
};
}), _dec(_class = (_temp2 = _class2 =
/*#__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), "handleChange", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value, old) {
if (_value !== old) {
console.log(_value); //this.plugin.sel.clicked(this.plugin.session.pool.findMaterial(m => m.item))
_this.context.plugin.focusActivated();
}
}
}), _temp) || _assertThisInitialized(_this);
}
var _proto = Root.prototype;
_proto.render = function render() {
var _props = this.props,
_props$instances = _props.instances,
instances = _props$instances === void 0 ? [] : _props$instances,
root = _props.root;
var tree = this.context.plugin.tree;
var items = instances.map(function (instance) {
return tree[instance].name;
});
var active = instances.filter(function (instance) {
return tree[instance].link === root;
})[0] || tree.root;
return React.createElement("group", {
format: "Table"
}, React.createElement("dropdown", {
name: "Active",
value: tree[active].name,
items: items,
onValue: this.handleChange
}));
};
return Root;
}(React.Component), Object.defineProperty(_class2, "contextTypes", {
configurable: true,
enumerable: true,
writable: true,
value: {
plugin: PropTypes.object
}
}), _temp2)) || _class);
var Tree =
/*#__PURE__*/
function (_Plugin) {
_inheritsLoose(Tree, _Plugin);
function Tree(session, args) {
return _Plugin.call(this, session, _extends({
type: 'Tree',
icon: 'isometric',
resources: RESOURCES,
render: React.createElement(Root, null)
}, args)) || this;
}
var _proto2 = Tree.prototype;
_proto2.focusActivated = function focusActivated() {
var _this2 = this;
var root,
object = this.sel.selectedObjects[0];
var part = object && object.findReverse(function (obj) {
return obj.type === 'Part';
});
if (part) {
var instanceProto = this.tree[part.userData.id];
if (instanceProto) root = instanceProto.link;
}
this.store.dispatch(connectionActions.setActiveRoot(this.connection.id, root));
requestAnimationFrame(function () {
if (part) _this2.view.controls.focus(part.getCenter()).zoom(part.getRadius() * 8);else _this2.view.controls.focus().zoom();
});
};
_proto2.onEnabled = function onEnabled() {
var _Assembly,
_Part,
_Mesh,
_this3 = this;
this.sel = new Selector(session, {
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
}).on('changed', function () {
return _this3.focusActivated();
});
};
_proto2.onDisabled = function onDisabled() {
this.sel.destroy();
this.focusActivated();
};
return Tree;
}(Plugin);
export { Tree as default };