awv3
Version:
⚡ AWV3 embedded CAD
470 lines (427 loc) • 14.2 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, _temp, _initialiseProps, _class3, _temp2;
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { buildFeaturePath } from '../../session/helpers';
import Plugin from '../../session/plugin';
import Graphics from './graphics';
var resources = ['plane'].reduce(function (prev, item) {
var _extends2;
return _extends({}, prev, (_extends2 = {}, _extends2[item] = require('!!url-loader!awv3-icons/32x32/' + item + '.png'), _extends2));
}, {});
var WORKPLANE_TYPE = ['XYPLANE', 'XZPLANE', 'YZPLANE', 'USERDEFINED', 'FIXED', 'PLANE', 'EDGEPOINT', '3POINTS', 'POINTNORMAL', 'POINTFACE', '2CURVES', 'LINEPLANEANGLE'];
/*WP_XYPLANE = 0,
WP_XZPLANE = 1,
WP_YZPLANE = 2,
WP_USERDEFINED = 3,
WP_PLANE = 10,
WP_EDGEPOINT = 11,
WP_3POINTS = 12,
WP_POINTNORMAL = 13,
WP_POINTFACE = 14,
WP_LINEPLANEANGLE = 16*/
var NONE_REF_WORKPLANE_TYPES = new Map([[0, 'XYPLANE'], [1, 'XZPLANE'], [2, 'YZPLANE'], [3, 'USERDEFINED']]);
var REF_WORKPLANE_TYPES = new Map([[10, 'WP_PLANE'], [11, 'WP_EDGEPOINT'], [12, 'WP_3POINTS'], [13, 'WP_POINTNORMAL'], [14, 'WP_POINTFACE'], [15, 'WP_2CURVES'], [16, 'WP_LINEPLANEANGLE']]);
var Root = (_dec = connect(function (state, props) {
return {
feature: state.connections[state.globals.activeConnection].tree[props.featureId]
};
}), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(Root, _React$Component);
function Root(props, context) {
var _this;
_this = _React$Component.call(this) || this;
_initialiseProps.call(_assertThisInitialized(_this));
_this.state = context.plugin.getFeatureData();
_this.connection = context.plugin.connection;
_this.session = context.plugin.session;
return _this;
}
var _proto = Root.prototype;
_proto.render = function render() {
var _this2 = this;
var _state = this.state,
type = _state.type,
origin = _state.origin,
normal = _state.normal,
offset = _state.offset,
workplaneName = _state.workplaneName;
return React.createElement("group", {
format: "Table"
}, React.createElement("input", {
name: "Name",
value: workplaneName,
onValue: this.setWorkplaneName
}), React.createElement("dropdown", {
name: "Type",
items: Array.from(NONE_REF_WORKPLANE_TYPES.values()).concat(Array.from(REF_WORKPLANE_TYPES.values())),
value: this.getTypeName(type),
onValue: this.setType
}), type === this.getTypeId('USERDEFINED') && React.createElement("group", {
format: "Table"
}, "Origin", React.createElement("input", {
name: "origin",
value: origin,
format: "Vector",
onValue: this.setOrigin,
onLastEvent: this.update
}), "Normal", React.createElement("input", {
name: "Normal",
value: normal,
format: "Vector",
onValue: this.setNormal,
onLastEvent: this.update
}), "Offset", React.createElement("input", {
name: "Offset",
value: offset,
format: "Number",
onValue: this.setOffset,
onLastEvent: this.update
})), (type === this.getTypeId('WP_PLANE') || type === this.getTypeId('WP_LINEPLANEANGLE')) && React.createElement("group", {
format: "Table"
}, React.createElement("selection", {
name: "Plane",
types: ['Mesh'],
limit: 1,
onItems: this.setPlane
}), type === this.getTypeId('WP_LINEPLANEANGLE') && React.createElement("input", {
name: "Offset",
value: offset,
format: "Number",
onValue: this.setOffset,
onLastEvent: this.update
})), type === this.getTypeId('WP_2CURVES') && React.createElement("group", {
format: "Table"
}, "Curve1", React.createElement("selection", {
name: "Curve1",
types: ['LineSegments'],
limit: 1,
onItems: function onItems(curve1) {
_this2.setReference('curve1');
}
}), "Curve2", React.createElement("selection", {
name: "Curve2",
types: ['LineSegments'],
limit: 1,
onItems: function onItems(curve2) {
_this2.setReference('curve2');
}
})), type === this.getTypeId('WP_3POINTS') && React.createElement("group", {
format: "Table"
}, "Point1", React.createElement("selection", {
name: "Point 1",
types: ['Region'],
limit: 1,
onItems: function onItems(point1) {
_this2.setReference('point1');
}
}), "Point2", React.createElement("selection", {
name: "Point 2",
types: ['Region'],
limit: 1,
onItems: function onItems(point2) {
_this2.setReference('point2');
}
}), "Point3", React.createElement("selection", {
name: "Point 3",
types: ['Region'],
limit: 1,
onItems: function onItems(point3) {
_this2.setReference('point3');
}
})), (type === this.getTypeId('WP_EDGEPOINT') || type === this.getTypeId('WP_POINTNORMAL') || type === this.getTypeId('WP_POINTFACE')) && React.createElement("group", {
format: "Table"
}, "Point", React.createElement("selection", {
name: "Vertex",
types: ['Region'],
limit: 1,
onItems: function onItems(vertex) {
_this2.setReference('vertex');
}
}), React.createElement("selection", {
name: type === this.getTypeId('WP_POINTFACE') ? "Face" : "Edge",
types: type === this.getTypeId('WP_POINTFACE') ? ['Mesh'] : ['LineSegments'],
limit: 1,
onItems: function onItems(item) {
var name = type === _this2.getTypeId('WP_POINTFACE') ? "face" : "edge";
_this2.setReference(name);
}
}), React.createElement("input", {
name: "Offset",
value: offset,
format: "Number",
onValue: this.setOffset,
onLastEvent: this.update
})), React.createElement("button", {
name: "Update",
flex: 0,
color: "blue",
onLastEvent: this.change
}));
};
return Root;
}(React.Component), Object.defineProperty(_class2, "contextTypes", {
configurable: true,
enumerable: true,
writable: true,
value: {
plugin: PropTypes.object
}
}), _initialiseProps = function _initialiseProps() {
var _this3 = this;
Object.defineProperty(this, "componentWillReceiveProps", {
configurable: true,
enumerable: true,
writable: true,
value: function value(props) {
_this3.setState(_this3.context.plugin.getFeatureData(props));
_this3.context.plugin.updateGraphics();
}
});
Object.defineProperty(this, "change", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var plugin = _this3.context.plugin;
var _this3$state = _this3.state,
type = _this3$state.type,
origin = _this3$state.origin,
normal = _this3$state.normal,
offset = _this3$state.offset,
name = _this3$state.name;
var local = true; //TODO
var root = _this3.connection.tree[_this3.connection.activeRoot || _this3.connection.tree.root];
var references = [];
var _this3$state2 = _this3.state,
plane = _this3$state2.plane,
vertex = _this3$state2.vertex,
edge = _this3$state2.edge,
point1 = _this3$state2.point1,
point2 = _this3$state2.point2,
point3 = _this3$state2.point3,
curve1 = _this3$state2.curve1,
curve2 = _this3$state2.curve2,
face = _this3$state2.face;
switch (_this3.getTypeName(type)) {
case 'WP_PLANE':
references = [plane];
break;
case 'WP_EDGEPOINT':
references = [vertex, edge];
break;
case 'WP_3POINTS':
references = [point1, point2, point3];
break;
case 'WP_POINTNORMAL':
references = [vertex, edge];
break;
case 'WP_POINTFACE':
references = [vertex, face];
break;
case 'WP_2CURVES':
references = [curve1, curve2];
break;
case 'WP_LINEPLANEANG':
references = [plane];
break;
}
var originArray = origin.split(',');
var originObj = {
'x': parseInt(originArray[0]),
'y': parseInt(originArray[1]),
'z': parseInt(originArray[2])
};
var normalArray = normal.split(',');
var normalObj = {
'x': parseInt(normalArray[0]),
'y': parseInt(normalArray[1]),
'z': parseInt(normalArray[2])
};
var result = _this3.connection.execute([{
"Feature.UpdateWorkPlane": [plugin.feature, type, references, offset, name, originObj, normalObj, local]
}]);
}
});
Object.defineProperty(this, "getTypeName", {
configurable: true,
enumerable: true,
writable: true,
value: function value(typeId) {
if (NONE_REF_WORKPLANE_TYPES.has(typeId)) return NONE_REF_WORKPLANE_TYPES.get(typeId);
if (REF_WORKPLANE_TYPES.has(typeId)) return REF_WORKPLANE_TYPES.get(typeId); //TODO: throw error.
}
});
Object.defineProperty(this, "getTypeId", {
configurable: true,
enumerable: true,
writable: true,
value: function value(typeName) {
var i = Array.from(NONE_REF_WORKPLANE_TYPES.values()).indexOf(typeName);
var key = -1;
if (i !== -1) {
key = Array.from(NONE_REF_WORKPLANE_TYPES.keys())[i];
return key;
}
i = Array.from(REF_WORKPLANE_TYPES.values()).indexOf(typeName);
if (i !== -1) {
key = Array.from(REF_WORKPLANE_TYPES.keys())[i];
return key;
}
}
});
Object.defineProperty(this, "update", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
return event.key === 'Enter' && _this3.change();
}
});
Object.defineProperty(this, "setNormal", {
configurable: true,
enumerable: true,
writable: true,
value: function value(normal) {
_this3.setState({
normal: normal
});
}
});
Object.defineProperty(this, "setOrigin", {
configurable: true,
enumerable: true,
writable: true,
value: function value(origin) {
return _this3.setState({
origin: origin
});
}
});
Object.defineProperty(this, "setType", {
configurable: true,
enumerable: true,
writable: true,
value: function value(typeName) {
return _this3.setState({
type: _this3.getTypeId(typeName)
});
}
});
Object.defineProperty(this, "setOffset", {
configurable: true,
enumerable: true,
writable: true,
value: function value(offset) {
return _this3.setState({
offset: offset
});
}
});
Object.defineProperty(this, "setWorkplaneName", {
configurable: true,
enumerable: true,
writable: true,
value: function value(workplaneName) {
return _this3.setState({
workplaneName: workplaneName
});
}
});
Object.defineProperty(this, "setPlane", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var object = _this3.session.selector.selectedObjects[0];
if (object === undefined) return;
var meta = object.userData.meta;
if (meta === undefined) {
_this3.setState({
plane: _this3.session.selector.selectedMaterials[0].meta.id
});
} else {
_this3.setState({
plane: meta.id
});
}
}
});
Object.defineProperty(this, "setReference", {
configurable: true,
enumerable: true,
writable: true,
value: function value(name) {
var meta = _this3.session.selector.selectedMaterials[0].meta;
var obj = {};
obj[name] = meta.id;
_this3.setState(obj); // if (meta.type === 'point') {
// } else if (meta.type === 'line' && !s.equals(e)) {
// }
}
});
}, _temp)) || _class);
var Workplane = (_temp2 = _class3 =
/*#__PURE__*/
function (_Plugin) {
_inheritsLoose(Workplane, _Plugin);
function Workplane(session, args) {
var _this4;
_this4 = _Plugin.call(this, session, _extends({
type: 'Workplane',
icon: 'plane',
resources: resources
}, args)) || this;
Object.defineProperty(_assertThisInitialized(_this4), "updateGraphics", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _this4.workplane.updateFromState(_this4.tree[_this4.feature]);
}
});
_this4.workplane = new Graphics(_assertThisInitialized(_this4));
_this4.pool.measurable = true;
_this4.pool.add(_this4.workplane);
_this4.visibleSubscription = _this4.connection.observe(function (state) {
var _state$tree$_this4$fe, _state$tree$_this4$fe2;
return (_state$tree$_this4$fe = (_state$tree$_this4$fe2 = state.tree[_this4.feature]) === null || _state$tree$_this4$fe2 === void 0 ? void 0 : _state$tree$_this4$fe2.visible) !== null && _state$tree$_this4$fe !== void 0 ? _state$tree$_this4$fe : false;
}, function (visible) {
_this4.workplane.visible = Boolean(visible);
_this4.updateGraphics();
}, {
fireOnStart: true
});
return _this4;
}
var _proto2 = Workplane.prototype;
_proto2.render = function render() {
return React.createElement(Root, {
featureId: this.feature
});
};
_proto2.onDestroyed = function onDestroyed() {
this.workplane.destroy();
};
_proto2.getFeatureData = function getFeatureData() {
var featureObj = this.tree[this.feature];
return {
type: featureObj.members.Type.value,
origin: featureObj.members.Position.value.join(','),
normal: featureObj.members.Normal.value.join(','),
offset: featureObj.members.Offset.value
};
};
return Workplane;
}(Plugin), Object.defineProperty(_class3, "persistent", {
configurable: true,
enumerable: true,
writable: true,
value: true
}), _temp2);
export { Workplane as default };