diff --git a/ExportThreeJS.cpp b/ExportThreeJS.cpp index 0495912..1510fb5 100644 --- a/ExportThreeJS.cpp +++ b/ExportThreeJS.cpp @@ -1,4 +1,4 @@ -//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- // EgalWare 2022-2022 //---------------------------------------------------------------------------- // File : ExportThreeJS.cpp Data : 05.07.22 Versione : 1.5h2 @@ -63,7 +63,7 @@ ExportThreeJS::SetOptions( int nFilter) //---------------------------------------------------------------------------- bool -ExportThreeJS::Export( IGeomDB* pGDB, int nId, const string& sFile, IEGrScene* pScene) +ExportThreeJS::Export( IGeomDB* pGDB, int nId, const string& sFile, IEGrScene* pScene, bool bUdm) { // verifico il DB geometrico if ( pGDB == nullptr) { @@ -87,6 +87,13 @@ ExportThreeJS::Export( IGeomDB* pGDB, int nId, const string& sFile, IEGrScene* return false ; } + // prelevo le unità di misura + m_bUdm_mm = bUdm; + m_sUdm = "in"; + if (m_bUdm_mm) { + m_sUdm = "mm"; + } + // prelevo il Box3D globale (per ingombro e punto luce) BBox3d b3Globbox ; pGDB->GetGlobalBBox( nId, b3Globbox, BBF_ONLY_VISIBLE) ; @@ -94,6 +101,9 @@ ExportThreeJS::Export( IGeomDB* pGDB, int nId, const string& sFile, IEGrScene* // m_dScala = max( m_dimX, m_dimY, m_dimZ) / 200 ; m_ptMin.ToLoc( m_frTHREEJSFrame) ; + // setto i filter + // m_nFilter = nFilter; + // creazione parte iniziale della pagina html bool bOk = HeadAmbient( pScene, pGDB, nId) ; @@ -104,8 +114,8 @@ ExportThreeJS::Export( IGeomDB* pGDB, int nId, const string& sFile, IEGrScene* pIter->GoTo( nId) ; // esporto l'oggetto e i suoi eventuali figli bOk = ExportObject( *pIter, pGDB, m_nGroupCount) ; - // fine creazione menù con elementi globali - m_Writer.OutText( " groupRoot.add(group0)"); + // fine creazione menù con elementi globali + m_Writer.OutText( " groupRoot.add(group0)"); // creazione parte finale della pagina html bOk = FinishAmbient() ; @@ -140,10 +150,10 @@ ExportThreeJS::HeadAmbient( IEGrScene* pScene, IGeomDB* pGDB, int nId) int nExtStep ; pScene->GetGridParam( &dSnapStep, &nExtStep) ; - m_spath = ""; // <----- da far scegliere all'utente // scrittura parte iniziale del codice e librerie + m_Writer.OutText( "") ; m_Writer.OutText( "") ; m_Writer.OutText( " ") ; // @@ -175,33 +185,146 @@ ExportThreeJS::HeadAmbient( IEGrScene* pScene, IGeomDB* pGDB, int nId) m_Writer.OutText( " ") ; // // body m_Writer.OutText( " ") ; // - m_Writer.OutText( "
") ; - m_Writer.OutText("
") ; - m_Writer.OutText(" ") ; - m_Writer.OutText("
") ; - //m_Writer.OutText( "
"); // div di aiuto per controllo parametri telecamera, zoom - // --- m_Writer.OutText( " ") ; + m_Writer.OutText( " window.addEventListener('mousemove', onMove, false);") ; + m_Writer.OutText( " window.addEventListener('mousedown', onDocumentMouseDown, false);") ; + m_Writer.OutText( " window.addEventListener('keydown', function(e) {"); + m_Writer.OutText( " if (e.target.id != 'listSearch') {") ; + m_Writer.OutText( " if (e.key == 'Escape') {") ; + m_Writer.OutText( " CancelMarkers();") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.key == 'b') {") ; + m_Writer.OutText( " if (controls.bBox) {") ; + m_Writer.OutText( " controls.bBox = false;") ; + m_Writer.OutText( " document.getElementsByTagName('input')[2].checked = false;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " else {") ; + m_Writer.OutText( " controls.bBox = true;") ; + m_Writer.OutText( " document.getElementsByTagName('input')[2].checked = true;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.key == 'r') {") ; + m_Writer.OutText( " if (controls.motion) {") ; + m_Writer.OutText( " controls.motion = false;") ; + m_Writer.OutText( " document.getElementsByTagName('input')[1].checked = false;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " else {") ; + m_Writer.OutText( " controls.motion = true;") ; + m_Writer.OutText( " document.getElementsByTagName('input')[1].checked = true;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.key == 'g') {") ; + m_Writer.OutText( " SetMarkerGrid();") ; + m_Writer.OutText( " GLOB_SEL = false;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.key == 's') {") ; + m_Writer.OutText( " SetMarkersSketch();") ; + m_Writer.OutText( " GLOB_SEL = false;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.key == 'p') {") ; + m_Writer.OutText( " SetMarkersPerimeter();") ; + m_Writer.OutText( " GLOB_SEL = false;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.key == 'm') {") ; + m_Writer.OutText( " GLOB_DIST = false;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.key == 'x') {") ; + m_Writer.OutText( " controls.reset();") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.key == 'i') {") ; + m_Writer.OutText( " GLOB_SEL = true;") ; + m_Writer.OutText( " GLOB_DIST = false;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " });") ; + // Controlli per dispositivi Mobile + m_Writer.OutText( " var onlongtouch;") ; + m_Writer.OutText( " var Ttimer;") ; + m_Writer.OutText( " var touchduration = 800;") ; + m_Writer.OutText( " var nFingers = 1;") ; + m_Writer.OutText( " var touchX;") ; + m_Writer.OutText( " var touchY;") ; + m_Writer.OutText( " function touchstart(e) {") ; + m_Writer.OutText( " if (e.touches.length > 1) {") ; + m_Writer.OutText( " nFingers = 2;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " else {") ; + m_Writer.OutText( " nFingers = 1;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.target.id == 'CScena' && e.touches.length < 2) {") ; + m_Writer.OutText( " touchX = e.touches[0].pageX;") ; + m_Writer.OutText( " touchY = e.touches[0].pageY;") ; + m_Writer.OutText( " if (!Ttimer) {") ; + m_Writer.OutText( " Ttimer = setTimeout(onlongtouch, touchduration, touchX, touchY);") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (controls.bBox || GLOB_DIST || GLOB_SEL) {") ; + m_Writer.OutText( " onMove();") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " onDocumentMouseDown();") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (e.target.id != 'CM_0' && e.target.id != 'CM_1' && e.target.id != 'CM_2' && e.target.id != 'CM_3' && e.target.id != 'CM_4' && e.target.id != 'CM_6') {") ; + m_Writer.OutText( " $('#context-menu').hide();") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " function touchend() {") ; + m_Writer.OutText( " if (Ttimer) {") ; + m_Writer.OutText( " clearTimeout(Ttimer);") ; + m_Writer.OutText( " Ttimer = null;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " onlongtouch = function(touchX, touchY) {") ; + m_Writer.OutText( " Ttimer = null;") ; + m_Writer.OutText( " if (nFingers == 1 && !orbitControls.blockTouchMenu) {") ; + m_Writer.OutText( " document.getElementById('context-menu').style.display = 'block';") ; + m_Writer.OutText( " document.getElementById('context-menu').style.top = touchY + 'px';") ; + m_Writer.OutText( " document.getElementById('context-menu').style.left = touchX + 'px';") ; + m_Writer.OutText( " $('#context-menu').addClass('show');") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " };") ; + m_Writer.OutText( " document.addEventListener('DOMContentLoaded', function(event) {") ; + m_Writer.OutText( " window.addEventListener('touchstart', touchstart, false);") ; + m_Writer.OutText( " window.addEventListener('touchend', touchend, false);") ; + m_Writer.OutText( " });") ; + // Menu contenstuale al click del mouse + m_Writer.OutText( " var choice = null;") ; + m_Writer.OutText( " $('#WebGL-output').on('contextmenu', function(e) {") ; + m_Writer.OutText( " var top = e.pageY - 10;") ; + m_Writer.OutText( " var left = e.pageX - 90;") ; + m_Writer.OutText( " $('#context-menu').css({") ; + m_Writer.OutText( " display: 'block',") ; + m_Writer.OutText( " top : top,") ; + m_Writer.OutText( " left : left") ; + m_Writer.OutText( " }).addClass('show');") ; + m_Writer.OutText( " return false;") ; + m_Writer.OutText( " }).on('click', function() {") ; + m_Writer.OutText( " $('#context-menu').removeClass('show').hide();") ; + m_Writer.OutText( " });") ; + m_Writer.OutText( " $('#context-menu').on('click', function() {") ; + m_Writer.OutText( " if(event.target.id.substr(3, (this).id.length) != 1){") ; + m_Writer.OutText( " $('#context-menu').removeClass('show').hide();") ; + m_Writer.OutText( " choice = event.target.id.substr(3, (this).id.length);") ; + m_Writer.OutText( " switch (choice) {") ; + m_Writer.OutText( " case '0':"); + m_Writer.OutText( " GLOB_SEL = true;") ; + m_Writer.OutText( " CancelMarkers();") ; + m_Writer.OutText( " GLOB_DIST = false;") ; + m_Writer.OutText( " break;") ; + m_Writer.OutText( " case '1':") ; + m_Writer.OutText( " SetMarkersSketch();") ; + m_Writer.OutText( " GLOB_SEL = false;") ; + m_Writer.OutText( " GLOB_DIST = true;") ; + m_Writer.OutText( " break;") ; + m_Writer.OutText( " case '2':") ; + m_Writer.OutText( " SetMarkersSketch();") ; + m_Writer.OutText( " GLOB_SEL = false;") ; + m_Writer.OutText( " GLOB_DIST = true;") ; + m_Writer.OutText( " break;") ; + m_Writer.OutText( " case '3':") ; + m_Writer.OutText( " SetMarkersPerimeter();") ; + m_Writer.OutText( " GLOB_SEL = false;") ; + m_Writer.OutText( " GLOB_DIST = true;") ; + m_Writer.OutText( " break;") ; + m_Writer.OutText( " case '4':") ; + m_Writer.OutText( " SetMarkerGrid();") ; + m_Writer.OutText( " GLOB_SEL = false;") ; + m_Writer.OutText( " GLOB_DIST = true;") ; + m_Writer.OutText( " break;") ; + m_Writer.OutText( " case '6':") ; + m_Writer.OutText( " CancelMarkers();") ; + m_Writer.OutText( " GLOB_SEL = false;") ; + m_Writer.OutText( " GLOB_DIST = false;") ; + m_Writer.OutText( " break; ") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " });") ; + // 18) funzione lightbulb + // - obj: individuare il gruppo a cui applicare la trasparenza + // - par: l'id del gruppo (name per THREEJS) + m_Writer.OutText( " function lightbulb(id) {") ; + m_Writer.OutText( " var lampadina = document.getElementById(id);") ; + m_Writer.OutText( " var stato = ($('#' + id).attr('name')).substr(3, $('#' + id).attr('name').length);") ; + m_Writer.OutText( " changeLBstate(id, stato);") ; + m_Writer.OutText( " findGroupByNameAndId(groupRoot, id.substr(3, id.length), 3);") ; + m_Writer.OutText( " if (stato == 'on') {") ; + m_Writer.OutText( " updateVisibility(CurrentSelectedGroup, 'off');") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " else {") ; + m_Writer.OutText( " updateVisibility(CurrentSelectedGroup, 'on');") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + // 19) funzione changeLBstate + // - obj: cambiare lo stato delle lampadine del menu di sinistra (on - off) + // - par: l'id del gruppo (name per THREEJS) e lo stato da settare (on - off) + m_Writer.OutText( " function changeLBstate(id, state) {") ; + m_Writer.OutText( " if (state == 'on') {") ; + m_Writer.OutText( " $('#' + id).attr('name', 'lb_off');") ; + m_Writer.OutText( " $('#' + id).css('color', 'grey');") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " else {") ; + m_Writer.OutText( " $('#' + id).attr('name', 'lb_on');") ; + m_Writer.OutText( " $('#' + id).css('color', '#f0ad4e');") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + // 20) funzione updateVisibility + // - obj: cambiare lo stato di visibilità dei gruppi e sottogruppi + // - par: il gruppo da cui partire e lo stato da settare + m_Writer.OutText( " function updateVisibility(currGroup, stato) {") ; + m_Writer.OutText( " currGroup.children.forEach(element => {") ; + m_Writer.OutText( " if (stato == 'on') {") ; + m_Writer.OutText( " element.visible = true;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " else {") ; + m_Writer.OutText( " element.visible = false;") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " if (element.type == 'Group') {") ; + m_Writer.OutText( " if (stato == 'on') {") ; + m_Writer.OutText( " changeLBstate('lb_' + element.name, 'off');") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " else {") ; + m_Writer.OutText( " changeLBstate('lb_' + element.name, 'on');") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " }") ; + m_Writer.OutText( " updateVisibility(element, stato);") ; + m_Writer.OutText( " });") ; + m_Writer.OutText( " }") ; + m_Writer.OutText(" "); // script per pulsante del menu laterale m_Writer.OutText( "