UNPKG

qwc2

Version:
10 lines 11.7 kB
function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return}finally{if(o)throw n}}return a}}function _arrayWithHoles(r){if(Array.isArray(r))return r}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e))}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t})()}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},_getPrototypeOf(t)}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e)}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},_setPrototypeOf(t,e)}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+""}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}/** * Copyright 2025 Sourcepole AG * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */import React from"react";import PropTypes from"prop-types";import{Group}from"three";import{v4 as uuidv4}from"uuid";import LocaleUtils from"../../utils/LocaleUtils";import Icon from"../Icon";import TaskBar from"../TaskBar";import ButtonBar from"../widgets/ButtonBar";import CreateTool3D from"./drawtool/CreateTool3D";import EditTool3D from"./drawtool/EditTool3D";var Draw3D=/*#__PURE__*/function(_React$Component){function Draw3D(){var _this;_classCallCheck(this,Draw3D);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,Draw3D,[].concat(args));_defineProperty(_this,"state",{action:null,baseSize:10,color:[255,105,0,1],geomType:null,drawGroupId:"",selectedObject:null});_defineProperty(_this,"onShow",function(){_this.ensureDrawGroup();_this.setState({action:"Pick"})});_defineProperty(_this,"onHide",function(){// Remove empty draw groups Object.entries(_this.props.sceneContext.sceneObjects).filter(function(_ref){var _ref2=_slicedToArray(_ref,2),objectId=_ref2[0],options=_ref2[1];return options.drawGroup===true}).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),objectId=_ref4[0],options=_ref4[1];var object=_this.props.sceneContext.getSceneObject(objectId);if(object.children.length===0){_this.props.sceneContext.removeSceneObject(objectId)}});_this.setState({selectedObject:null})});_defineProperty(_this,"ensureDrawGroup",function(){// Ensure a draw group is present var drawGroup=Object.entries(_this.props.sceneContext.sceneObjects).find(function(_ref5){var _ref6=_slicedToArray(_ref5,2),key=_ref6[0],options=_ref6[1];return options.drawGroup===true});if(drawGroup===undefined){_this.addDrawGroup(LocaleUtils.tr("draw3d.drawings"))}else{_this.props.sceneContext.updateSceneObject(drawGroup[0],{visibility:true});_this.setState({drawGroupId:drawGroup[0]})}});_defineProperty(_this,"createDrawGroup",function(){var message=LocaleUtils.tr("draw3d.newgroupprompt");// eslint-disable-next-line var name=prompt(message);if(name){_this.addDrawGroup(name)}});_defineProperty(_this,"addDrawGroup",function(name){var objectId=uuidv4();var options={drawGroup:true,layertree:true,title:name};_this.props.sceneContext.addSceneObject(objectId,new Group,options);_this.setState({drawGroupId:objectId})});_defineProperty(_this,"renderBody",function(){var activeButton=_this.state.action==="Create"?_this.state.geomType:_this.state.action;var drawButtons=[{key:"Cuboid",tooltip:LocaleUtils.tr("draw3d.cuboid"),icon:"cuboid",data:{action:"Create",geomType:"Cuboid"}},{key:"Wedge",tooltip:LocaleUtils.tr("draw3d.wedge"),icon:"wedge",data:{action:"Create",geomType:"Wedge"}},{key:"Cylinder",tooltip:LocaleUtils.tr("draw3d.cylinder"),icon:"cylinder",data:{action:"Create",geomType:"Cylinder"}},[{key:"Pyramid",tooltip:LocaleUtils.tr("draw3d.pyramid"),icon:"pyramid",data:{action:"Create",geomType:"Pyramid"}},{key:"Sphere",tooltip:LocaleUtils.tr("draw3d.sphere"),icon:"sphere",data:{action:"Create",geomType:"Sphere"}},{key:"Cone",tooltip:LocaleUtils.tr("draw3d.cone"),icon:"cone",data:{action:"Create",geomType:"Cone"}}]];var editButtons=[{key:"Pick",tooltip:LocaleUtils.tr("draw3d.pick"),icon:"nodetool",data:{action:"Pick",geomType:null}},{key:"Delete",tooltip:LocaleUtils.tr("draw3d.delete"),icon:"trash",data:{action:"Delete",geomType:null},disabled:!_this.state.selectedObject}];var drawGroups=Object.entries(_this.props.sceneContext.sceneObjects).filter(function(_ref7){var _ref8=_slicedToArray(_ref7,2),key=_ref8[0],entry=_ref8[1];return entry.drawGroup===true});return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("div",{className:"redlining-controlsbar"},/*#__PURE__*/React.createElement("div",{className:"redlining-groupcontrol"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.layer")),/*#__PURE__*/React.createElement("div",{className:"controlgroup"},/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return _this.setActiveDrawGroup(ev.target.value)},value:_this.state.drawGroupId},drawGroups.map(function(_ref9){var _ref10=_slicedToArray(_ref9,2),objectId=_ref10[0],options=_ref10[1];return/*#__PURE__*/React.createElement("option",{key:objectId,value:objectId},options.title)})),/*#__PURE__*/React.createElement("button",{className:"button",onClick:_this.createDrawGroup},/*#__PURE__*/React.createElement(Icon,{icon:"plus"})))),/*#__PURE__*/React.createElement("div",{className:"redlining-groupcontrol"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.draw")),/*#__PURE__*/React.createElement(ButtonBar,{active:activeButton,buttons:drawButtons,onClick:function onClick(key,data){return _this.actionChanged(data)}})),/*#__PURE__*/React.createElement("div",{className:"redlining-groupcontrol"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.edit")),/*#__PURE__*/React.createElement(ButtonBar,{active:activeButton,buttons:editButtons,onClick:function onClick(key,data){return _this.actionChanged(data)}}))),_this.renderControl())});_defineProperty(_this,"renderControl",function(){if(_this.state.action==="Create"){return/*#__PURE__*/React.createElement(CreateTool3D,{baseSize:_this.state.baseSize,baseSizeChanged:function baseSizeChanged(baseSize){return _this.setState({baseSize:baseSize})},color:_this.state.color,colorChanged:function colorChanged(color){return _this.setState({color:color})},drawGroupId:_this.state.drawGroupId,geomType:_this.state.geomType,objectCreated:_this.objectCreated,sceneContext:_this.props.sceneContext})}else if(_this.state.action==="Pick"){return/*#__PURE__*/React.createElement(EditTool3D,{color:_this.state.color,colorChanged:function colorChanged(color){return _this.setState({color:color})},drawGroupId:_this.state.drawGroupId,objectPicked:_this.objectPicked,sceneContext:_this.props.sceneContext,selectedObject:_this.state.selectedObject})}return null});_defineProperty(_this,"setActiveDrawGroup",function(drawGroupId){_this.props.sceneContext.updateSceneObject(drawGroupId,{visibility:true});_this.setState({drawGroupId:drawGroupId,selectedObject:null})});_defineProperty(_this,"actionChanged",function(data){if(data.action==="Delete"){_this.deleteSelectedObject()}else{_this.setState({action:data.action,geomType:data.geomType,selectedObject:null})}});_defineProperty(_this,"deleteSelectedObject",function(){var group=_this.props.sceneContext.getSceneObject(_this.state.drawGroupId);var parent=null;group.traverse(function(c){if(c===_this.state.selectedObject){parent=c.parent}});if(parent){parent.remove(_this.state.selectedObject);while(parent.parent&&!parent.isMesh&&parent.children.length===0&&parent!==group){var grandparent=parent.parent;grandparent.remove(parent);parent=grandparent}if(group.children.length===0){_this.props.sceneContext.removeSceneObject(_this.state.drawGroupId,function(){_this.ensureDrawGroup()})}_this.setState({action:"Pick",geomType:null,selectedObject:null});_this.props.sceneContext.scene.notifyChange()}});_defineProperty(_this,"objectCreated",function(object){_this.setState({action:"Pick",geomType:null,selectedObject:object})});_defineProperty(_this,"objectPicked",function(object){_this.setState({selectedObject:object})});return _this}_inherits(Draw3D,_React$Component);return _createClass(Draw3D,[{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement(TaskBar,{onHide:this.onHide,onShow:this.onShow,task:"Draw3D"},function(){return{body:_this2.renderBody()}})}}])}(React.Component);_defineProperty(Draw3D,"propTypes",{sceneContext:PropTypes.object});export{Draw3D as default};