Добрый день!
Если вы хотите добавить в 3Д сцену отображение сигнала, то лучший способ сделать это - через тег.
Рассмотрим на примере модификации таблички с именем станка для отображения текущего имени запущенной программы.
Для начала добавим тег к учету, поскольку это уже делается в объекте для работы колб и тех же самых табличек - мы легко сможем улучшить его.
WNScriptForCylinders
Теперь вместе с колбами у нас есть данные для отображения.
В нашем случае мы можем немного изменить табличку с именем станка, и добавить полученное значение:
Вы можете попробовать свой вариант вывода других сигналов, привязав к ним свой тег и добавив его для отображения.
Hello World!:
- Сообщений не найдено.
Если вы хотите добавить в 3Д сцену отображение сигнала, то лучший способ сделать это - через тег.
Рассмотрим на примере модификации таблички с именем станка для отображения текущего имени запущенной программы.
Для начала добавим тег к учету, поскольку это уже делается в объекте для работы колб и тех же самых табличек - мы легко сможем улучшить его.
WNScriptForCylinders
Код:
var currentDate = new Date();
var curDateTimeText = '';
var delay = 0;
var delay_limit = 10000;
var debug = false;
scene.userData.appid = 'winnum.org.app.WNApplicationInstance:1';
var tag_oid;
_getPlatformDateTime_();
function update( event ) {
delay += parseInt(event.delta);
if ( delay < delay_limit ) { return; } else { delay = 0; } //delay for delay_limit
_getPlatformDateTime_();
}
// Время платформы
function _getPlatformDateTime_(){
baseSdkUtils.service.WNCalendarHelper.getPlatformDateTime(function(data){
var curDateTime = DateTime_Attr(data);
currentDate = new Date(curDateTime);
if (debug) {console.log('current DateTime Platform:');console.log(curDateTime)};
});
}
baseSdkUtils._getTag_ = {};
baseSdkUtils._getTag_ = function(tag_name){
baseSdkUtils.service.WNApplicationHelper.getTag(scene.userData.appid, function(data){
if ( baseSdkUtils.isSuccess(data) ){
for(var i = 0; i < data.getElementsByTagName('item').length ; i++ ) {
var _temp_item_ = data.getElementsByTagName('item')[i];
var _attr_ = baseSdkUtils.decode(_temp_item_.getAttribute('tag'));
if (_attr_ == tag_name){
if(tag_name == 'NC_ON'){scene.userData.tag_oid1 = baseSdkUtils.decode(_temp_item_.getAttribute('id'));}
if(tag_name == 'NC_PROGRAM_RUN'){scene.userData.tag_oid2 = baseSdkUtils.decode(_temp_item_.getAttribute('id'));}
if(tag_name == 'NC_WIP'){scene.userData.tag_oid3 = baseSdkUtils.decode(_temp_item_.getAttribute('id'));}
if(tag_name == 'NC_FEEDRATE_OVERRIDE'){scene.userData.tag_oid_overfeedrate = baseSdkUtils.decode(_temp_item_.getAttribute('id'));}
if(tag_name == 'NC_ALARM_MESSAGE'){scene.userData.tag_oid_alarmmessage = baseSdkUtils.decode(_temp_item_.getAttribute('id'));}
// ДОБАВЛЕНО: поиск тега NC_PROGRAM_NAME
if(tag_name == 'NC_PROGRAM_NAME'){scene.userData.tag_oid_programname = baseSdkUtils.decode(_temp_item_.getAttribute('id'));}
scene.userData.tag_oid = baseSdkUtils.decode(_temp_item_.getAttribute('id'));
if (debug){console.log('tag_oid for ' + tag_name + ':');console.log(scene.userData.tag_oid)};
return;
}
}
}
})
}
function start(event){
baseSdkUtils._getTag_('NC_ON');
baseSdkUtils._getTag_('NC_PROGRAM_RUN');
baseSdkUtils._getTag_('NC_WIP');
baseSdkUtils._getTag_('NC_FEEDRATE_OVERRIDE');
baseSdkUtils._getTag_('NC_ALARM_MESSAGE');
// ДОБАВЛЕНО: инициализация поиска тега NC_PROGRAM_NAME
baseSdkUtils._getTag_('NC_PROGRAM_NAME');
}
baseSdkUtils._getCurrentWorkShiftStartDate_ = {};
baseSdkUtils._getCurrentWorkShiftStartDate_ = function(_poid_, theThis, tag_name, relatedProductLine, relatedProductName){
baseSdkUtils.service.WNCalendarHelper.getCurrentWorkShiftStartDate(_poid_, function(data){
var startShiftDate = DateTime_Attr(data);
if (debug){console.log('start current shift Date:'); console.log(startShiftDate)};
if (startShiftDate == 'error'){
if(debug){console.log('Нет текущей смены для ' + _poid_)};
base3DUtils[tag_name][relatedProductLine][relatedProductName] = 0.0;
theThis.scale.y = 0.0001;
return;
};
var startTime = baseSdkUtils.toDateTimeString(startShiftDate, true);
var endTime = baseSdkUtils.toDateTimeString(currentDate, true);
var _tag_oid_ = '';
if(tag_name == 'NC_ON'){_tag_oid_ = scene.userData.tag_oid1 ;}
if(tag_name == 'NC_PROGRAM_RUN'){_tag_oid_ = scene.userData.tag_oid2 ;}
if(tag_name == 'NC_WIP'){_tag_oid_ = scene.userData.tag_oid3 ;}
try{
baseSdkUtils.service.WNApplicationTagHelper.getSimpleTagCalculation(scene.userData.appid, _poid_, _tag_oid_, startTime, endTime, 60000, function(TagCalculation_data){
if ( baseSdkUtils.isSuccess(TagCalculation_data) ){
if(debug){console.log('getSimpleTagCalculation for ' + _poid_ + ' :'); console.log(TagCalculation_data)};
if(TagCalculation_data.getElementsByTagName('item').length === 0){return;}
for(var i = 0; i < TagCalculation_data.getElementsByTagName('item').length ; i++ ) {
var _temp_item_ = TagCalculation_data.getElementsByTagName('item')[i];
var _attr_ = baseSdkUtils.decode(_temp_item_.getAttribute('percent'));
var _attr1_ = parseFloat(baseSdkUtils.decode(_temp_item_.getAttribute('hours'))).toFixed(2);
var _rel_mesh_ = _attr_/100;
if (base3DUtils[tag_name][relatedProductLine]['hour'] === undefined){
base3DUtils[tag_name][relatedProductLine]['hour'] = {};
base3DUtils[tag_name][relatedProductLine]['hour'][relatedProductName] = 0.0;
}
base3DUtils[tag_name][relatedProductLine][relatedProductName] =_rel_mesh_;
base3DUtils[tag_name][relatedProductLine]['hour'][relatedProductName] =_attr1_;
if (_rel_mesh_ > 1){baseSdkUtils[tag_name][relatedProductLine][relatedProductName] = 1.0};
if (_rel_mesh_ > 0){theThis.scale.y = _rel_mesh_};
if (_rel_mesh_ === 0){theThis.scale.y = 0.0001};
}
}
});
}
catch (error) {
}
})
}
function DateTime_Attr(data){
if ( baseSdkUtils.isSuccess(data) ){
var _temp_item_ = data.getElementsByTagName('item')[0];
var _attr_ = baseSdkUtils.decode(_temp_item_.getAttribute('datetime'));
if (_attr_.length === 0 || _attr_ == null){return 'error';}
var _datetime_type_date_ = new Date(baseSdkUtils.toDateObject(_attr_));
return _datetime_type_date_;
}
}
function Text_Attr(data, attr, num){
if ( baseSdkUtils.isSuccess(data) ){
var _temp_item_ = data.getElementsByTagName('item')[num];
var _attr_ = baseSdkUtils.decode(_temp_item_.getAttribute(attr));
return _attr_;
}
}
baseSdkUtils.spriteTexture = {};
// МОДИФИЦИРОВАНО: добавлен параметр programname
baseSdkUtils.spriteTexture = function(theThis, hexcolor, canvas_rect1, context_rect1, relatedProductLine, relatedProductName, _font_, _text_, color, texture, feedrate, alarmmessage, programname){
hexcolor = '#' + color.getHexString();
context_rect1.clearRect(0, 0, canvas_rect1.width, canvas_rect1.height);
var _contextWidth_ = context_rect1.measureText(_text_).width + 20;
var _contextHeight_ = context_rect1.measureText(_text_).fontBoundingBoxAscent + context_rect1.measureText(_text_).fontBoundingBoxDescent ;
canvas_rect1.width = _contextWidth_ + 40 + 100;
// МОДИФИЦИРОВАНО: увеличение высоты для размещения имени программы
canvas_rect1.height = _contextHeight_ + 90;
theThis.scale.x = theThis.scale.y*((canvas_rect1.width)/canvas_rect1.height);
context_rect1.beginPath();
context_rect1.fillStyle = "rgba(255, 255, 240, 0.8)";
context_rect1.fillRect(20, 0, _contextWidth_ + 20, _contextHeight_);
context_rect1.fillStyle = hexcolor;
context_rect1.fillRect(0, 0, 20, _contextHeight_);
context_rect1.beginPath();
context_rect1.stroke();
context_rect1.beginPath();
context_rect1.strokeStyle = "grey";
context_rect1.moveTo(20, _contextHeight_);
context_rect1.lineTo(40, _contextHeight_/2);
context_rect1.lineTo(20, 0);
context_rect1.fill();
context_rect1.stroke();
context_rect1.fillStyle = 'yellow';
var _tag_arr_ = ['NC_ON', 'NC_PROGRAM_RUN', 'NC_WIP'];
for (var i = 0; i < _tag_arr_.length; i++){
if ( base3DUtils[_tag_arr_[i]] === undefined ){
base3DUtils[_tag_arr_[i]] = {};
}
if ( base3DUtils[_tag_arr_[i]][relatedProductLine] === undefined ){
base3DUtils[_tag_arr_[i]][relatedProductLine] = {};
base3DUtils[_tag_arr_[i]][relatedProductLine][relatedProductName] = 0.00;
}
}
context_rect1.fillRect(0, _contextHeight_ + 10, canvas_rect1.width * base3DUtils['NC_ON'][relatedProductLine][relatedProductName], 20);
context_rect1.fillStyle = 'GreenYellow';
context_rect1.fillRect(0, _contextHeight_ + 10, canvas_rect1.width * base3DUtils['NC_PROGRAM_RUN'][relatedProductLine][relatedProductName], 20);
context_rect1.fillStyle = 'green';
context_rect1.fillRect(0, _contextHeight_ + 10, canvas_rect1.width * base3DUtils['NC_WIP'][relatedProductLine][relatedProductName], 20);
context_rect1.textAlign = "center";
context_rect1.fillStyle = "black";
context_rect1.font = '18px "bahnschrift semicondensed"';
//var _text_temp_ = 'По программе в смену ';
var _text_temp_ = '';
_text_temp_ = _text_temp_ + (base3DUtils['NC_PROGRAM_RUN'][relatedProductLine][relatedProductName]*100).toFixed(2) + ' %';
if (base3DUtils['NC_PROGRAM_RUN'][relatedProductLine]['hour'] !== undefined && base3DUtils['NC_PROGRAM_RUN'][relatedProductLine]['hour'][relatedProductName] !== undefined){
_text_temp_ = _text_temp_ + ' (' + base3DUtils['NC_PROGRAM_RUN'][relatedProductLine]['hour'][relatedProductName] + ' ч.)';
}
context_rect1.fillText(_text_temp_, _contextWidth_/2 + 20, _contextHeight_ + 25);
// ДОБАВЛЕНО: отображение имени программы внизу спрайта
if (programname !== undefined && programname !== '') {
context_rect1.fillStyle = "blue";
context_rect1.font = '14px "bahnschrift semicondensed"';
context_rect1.fillText('' + programname, _contextWidth_/2 + 20, _contextHeight_ + 50);
}
context_rect1.fillStyle = "black";
context_rect1.font = _font_;
context_rect1.fillText(_text_, _contextWidth_/2 + 40, context_rect1.measureText(_text_).fontBoundingBoxAscent);
// прямоугольник справа
context_rect1.fillStyle = "rgba(255, 255, 240, 0.8)";
context_rect1.fillRect(_contextWidth_ + 50, 0, _contextWidth_ + 20, _contextHeight_);
// коррекция подачи
//_text_temp_ = ' ' + feedrate + '%';
if (feedrate === undefined)(_text_temp_ = '');
if (feedrate !== undefined) {
if (feedrate != ''){context_rect1.fillStyle = "black";context_rect1.strokeStyle = "green";_text_temp_ = ' ' + feedrate + '%';}
if (feedrate == ''){context_rect1.fillStyle = "black";context_rect1.strokeStyle = "red";_text_temp_ = '';}
context_rect1.beginPath();
var offset = 50;
var offsetV = 20; var heightF = 8;
context_rect1.lineWidth = 2;
context_rect1.moveTo(_contextWidth_ + offset + 10, offsetV);
context_rect1.lineTo(_contextWidth_ + offset + 12.5, offsetV - heightF);
context_rect1.lineTo(_contextWidth_ + offset + 15, offsetV + heightF);
context_rect1.lineTo(_contextWidth_ + offset + 17.5, offsetV - heightF);
context_rect1.lineTo(_contextWidth_ + offset + 20, offsetV + heightF);
context_rect1.lineTo(_contextWidth_ + offset + 22.5, offsetV - heightF);
context_rect1.lineTo(_contextWidth_ + offset + 25, offsetV + heightF);
context_rect1.lineTo(_contextWidth_ + offset + 27.5, offsetV - heightF);
context_rect1.lineTo(_contextWidth_ + offset + 30, offsetV + heightF);
context_rect1.lineTo(_contextWidth_ + offset + 32.5, offsetV);
context_rect1.stroke();
context_rect1.font = '24px "bahnschrift semicondensed"';
context_rect1.fillText(_text_temp_, _contextWidth_ + offset + 60, 25);
}
// аларм
if (alarmmessage !== undefined) {
if ( alarmmessage != ''){
context_rect1.fillStyle = "red";
}
else{context_rect1.fillStyle = "grey";}
context_rect1.font = '24px FontAwesome';
context_rect1.fillText('\uF071', _contextWidth_ + offset + 20, 60);
context_rect1.fillStyle = "black";
context_rect1.font = '12px "bahnschrift semicondensed"';
context_rect1.textAlign = "left";
context_rect1.fillText(alarmmessage.substring(0, 10), _contextWidth_ + offset + 40, 60);
context_rect1.fillText(alarmmessage.substring(10, 16), _contextWidth_ + offset + 5, 75);
}
context_rect1.font = _font_;
context_rect1.textAlign = "center";
//
texture.needsUpdate = true;
}
baseSdkUtils.getLastTagCalculation = {};
baseSdkUtils.getLastTagCalculation = function(appid, pid, tid, endTime, timeout_mills, callBackFunc){
var _attr_ = '';
baseSdkUtils.service.WNApplicationTagHelper.getLastTagCalculationValue(appid, pid, tid, curDateTimeText, timeout_mills, function(data){
if ( baseSdkUtils.isSuccess(data) ){
if(debug){console.log('getLastTagCalculation for ' + pid + ' :'); console.log(data)};
if(data.getElementsByTagName('item').length === 0){return;}
var _temp_item_ = data.getElementsByTagName('item')[0];
_attr_ = baseSdkUtils.decode(_temp_item_.getAttribute('value'));
}
if ( callBackFunc ){
callBackFunc.call( this, _attr_);
}
})
}Теперь вместе с колбами у нас есть данные для отображения.
В нашем случае мы можем немного изменить табличку с именем станка, и добавить полученное значение:
Код:
var relatedProductName = '20614';// ввести имя детали станка, к которой привязан сигнал
var relatedProductLine = '1';
var _font_ = '30px "bahnschrift semicondensed"'; // шрифт по умолчаию
var _text_ = 'Не найдено'; // имя по умолчанию
var flag_text = 1; // 0 - отображать имя по умолчанию из переменной _text_. 1 - отображать фактическое наименование станка
var color = new THREE.Color( 'black' );
var obj=scene.getObjectByName(relatedProductName);
var _poid_ = '';
if (obj !== undefined){
if (obj.material !== undefined && obj.material.color !== undefined){color=obj.material.color;}
if ( base3DUtils.WNSignalArray[ obj.uuid ] !== undefined &&
base3DUtils.WNSignalArray[ obj.uuid ].length != undefined &&
base3DUtils.WNSignalArray[ obj.uuid ].length > 0 &&
flag_text == 1){
// _text_ = base3DUtils.WNSignalArray[ obj.uuid ][0].product_name;
_text_ = base3DUtils.WNSignalArray[ obj.uuid ][0].product_serial;
// _text_ = _text_.split(' ')[0];
_poid_ = base3DUtils.WNSignalArray[ obj.uuid ][0].product_oid;
}
}
//
var hexcolor = '#' + color.getHexString();
var delay = 0;
var delay_tag = 0;
var delay_start_tag = 1000;
var feedrate_override = '';
var alarmmessage = ''
// ДОБАВЛЕНО: переменная для имени программы
var program_name = '';
var canvas_rect1 = document.createElement('canvas');
var context_rect1 = canvas_rect1.getContext('2d');
context_rect1.fillStyle = 'white';
context_rect1.beginPath();
context_rect1.stroke();
context_rect1.font = _font_;
var texture = new THREE.Texture(canvas_rect1)
texture.anisotropy = renderer.getMaxAnisotropy();
texture.needsUpdate = true;
var material = new THREE.SpriteMaterial({ map: texture, color: 'white' });
material.map.minFilter = THREE.LinearFilter;
this.material.map = texture;
//this.material.transparent = true;
this.material = material;
texture.needsUpdate = true;
function start(event){
baseSdkUtils.spriteTexture(this, hexcolor, canvas_rect1, context_rect1, relatedProductLine, relatedProductName, _font_, _text_, color, texture);
}
function update (event){
// return;
if ((delay+=event.delta) > 500){
if (obj !== undefined && obj.material !== undefined && obj.material.color !== undefined){color = obj.material.color;}
// if (hexcolor == '#' + color.getHexString()){return;}
// МОДИФИЦИРОВАНО: добавлен параметр program_name
baseSdkUtils.spriteTexture(this, hexcolor, canvas_rect1, context_rect1, relatedProductLine, relatedProductName, _font_, _text_, color, texture, feedrate_override, alarmmessage, program_name);
delay = 0;
}
if ((delay_tag+=event.delta) > delay_start_tag){
delay_start_tag = scene.userData.tag_inc;
baseSdkUtils.getLastTagCalculation(scene.userData.appid , _poid_, scene.userData.tag_oid_overfeedrate, '', 60000, function(data){
feedrate_override = data;
});
baseSdkUtils.getLastTagCalculation(scene.userData.appid , _poid_, scene.userData.tag_oid_alarmmessage, '', 60000, function(data){
alarmmessage = data;
});
// ДОБАВЛЕНО: получение имени программы
baseSdkUtils.getLastTagCalculation(scene.userData.appid , _poid_, scene.userData.tag_oid_programname, '', 60000, function(data){
program_name = data;
});
delay_tag = 0;
}
}Вы можете попробовать свой вариант вывода других сигналов, привязав к ним свой тег и добавив его для отображения.
Hello World!:
- Сообщений не найдено.

