Skip to content

Commit

Permalink
Merge pull request #92 from pattern-x/update-demo
Browse files Browse the repository at this point in the history
更新demo
  • Loading branch information
yanzexuan1 committed Jun 7, 2023
2 parents 49bc204 + 6e51d2e commit 0090090
Show file tree
Hide file tree
Showing 5 changed files with 645 additions and 0 deletions.
9 changes: 9 additions & 0 deletions public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@
}, {
"title": "Drawing comparison",
"url": "./demo/dxf_3.html"
}, {
"title": "Drawing comparison with 2 viewports",
"url": "./demo/dxf_8.html"
}, {
"title": "Drawing comparison with 3 viewports",
"url": "./demo/dxf_4.html"
}, {
"title": "Upload files and compare with 2 viewports",
"url": "./demo/dxf_10.html"
}, {
"title": "Markups",
"url": "./demo/dxf_5.html"
}, {
"title": "Take screenshot via markup",
"url": "./demo/dxf_9.html"
}, {
"title": "Hotpoints",
"url": "./demo/dxf_6.html"
Expand Down
235 changes: 235 additions & 0 deletions public/demo/dxf_10.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
<html>
<head>
<link rel="icon" href="./demo/favicon.ico" />
<link rel="stylesheet" type="text/css" href="./demo/global.css" />
<link rel="stylesheet" type="text/css" href="./demo/iconfont/iconfont.css" />
<link rel="stylesheet" href="./demo/compare/dxfComparePanel.css" />
<link rel="stylesheet" href="./demo/layerManager/layerManager.css" />
<link rel="stylesheet" href="./demo/settings/SettingsPanel.css" />
<style>
body {
font-size: 0;
}
#myCanvas1,
#myCanvas2 {
width: calc(50% - 1px);
height: 100%;
margin: 0;
padding: 0;
display: inline-block;
}
.split {
display: inline-block;
width: 1px;
height: 100%;
margin: 0;
padding: 0;
background-color: #eee;
}

.upload-containter {
position: absolute;
width: 100%;
text-align: center;
top: 80px;
}
#uploadModelFile::file-selector-button {
height: 40px;
font-size: 16px;
line-height: 40px;
color: #fff;
border-radius: 5px;
border: 1px solid #409eff;
background-color: #409eff;
font-family: inherit;
cursor: pointer;
}
.button {
height: 40px;
font-size: 16px;
line-height: 40px;
color: #fff;
border-radius: 5px;
border: 1px solid #409eff;
background-color: #409eff;
font-family: inherit;
cursor: pointer;
padding: 0 3px;
margin: 5px;
}
</style>
</head>

<body>
<div id="app" class="app">
<div id="myCanvas1" class="container"></div>
<div class="split"></div>
<div id="myCanvas2" class="container"></div>
</div>
<div class="upload-containter">
<input id="uploadModelFile" accept=".dxf" multiple type="file" />
<button id="syncCamera" class="button" title="Click to sync or unsync cameras">unsynced</button>
<button id="getDetailChange" class="button" class="button">get detail change</button>
</div>
<script type="module">
import {
DxfCompareHelper,
ToolbarMenuId,
} from "./demo/libs/gemini-viewer.esm.min.js";
import DxfComparePanel from "./demo/compare/dxfComparePanel.js";
import DxfSettingsPanel from "./demo/settings/DxfSettingsPanel.js";
import LayerManager from "./demo/layerManager/LayerManager.js";

const compareHelper = new DxfCompareHelper(
{
containerId: "myCanvas1",
enableAxisGizmo: true,
enableStats: true,
enableToolbar: true,
enableBottomBar: true,
enableSelection: true,
},
{
containerId: "myCanvas2",
enableAxisGizmo: true,
enableStats: true,
enableToolbar: true,
enableBottomBar: true,
enableSelection: true,
}
);
window.compareHelper = compareHelper;
const fontFiles = ["./demo/three/fonts/hztxt.shx", "./demo/three/fonts/simplex.shx"];
await compareHelper.setFont(fontFiles);

compareHelper.viewer1.toolbar.updateMenus(
overrideToolbarConfig(compareHelper.viewer1)
);
compareHelper.viewer2.toolbar.updateMenus(
overrideToolbarConfig(compareHelper.viewer2)
);

const syncCameraBtn = document.getElementById("syncCamera");
let enableSyncCamera = false;
syncCameraBtn.onclick = function () {
if (!enableSyncCamera) {
compareHelper.enableSyncCamera = true;
syncCameraBtn.innerText = "synced";
} else {
compareHelper.enableSyncCamera = false;
syncCameraBtn.innerText = "unsynced";
}
enableSyncCamera = !enableSyncCamera;
};

const onProgress = (event) => {
const progress = ((event.loaded * 100) / event.total).toFixed(2);
console.log(`[Demo] Compare progress: ${progress}%`);
};

const uploadBtn = document.getElementById("uploadModelFile");
uploadBtn.onchange = function (e) {
const files = event.target.files;
if (files.length === 2) {
const file1 = files[0];
const file2 = files[1];
const url1 = URL.createObjectURL(file1);
const url2 = URL.createObjectURL(file2);

compareHelper
.compare(
{ src: url1, modelId: file1.name },
{ src: url2, modelId: file2.name },
onProgress
)
.then(() => {
console.log(`[Demo] Compared models: ${url1}, ${url2}`);
new DxfComparePanel(compareHelper, compareHelper.container);
})
.catch((reason) => {
console.error(
`[Demo] Failed to compare models: ${url1}, ${url2}. reason: ${reason}`
);
});
}
};

const detailButton = document.getElementById("getDetailChange");
detailButton.onclick = function () {
alert(JSON.stringify(compareHelper.getCompareChanges()));
}

function overrideToolbarConfig(viewer) {
return [
{
menuId: ToolbarMenuId.Settings,
config: {
onActive: () => {
console.log("[Toolbar]", "Activate Settings");
if (!viewer.dxfSettingsPanel) {
viewer.dxfSettingsPanel = new DxfSettingsPanel(viewer);
}
viewer.dxfSettingsPanel.show();
},
onDeactive: () => {
console.log("[Toolbar]", "Deactivate Settings");
if (!viewer.dxfSettingsPanel) {
viewer.dxfSettingsPanel = new DxfSettingsPanel(viewer);
}
viewer.dxfSettingsPanel.hide();
},
},
},
{
menuId: ToolbarMenuId.Layers,
config: {
onActive: () => {
console.log("[Toolbar]", "Activate Layers");
if (!viewer.layerManager) {
viewer.layerManager = new LayerManager(viewer);
}
viewer.layerManager.show();
},
onDeactive: () => {
console.log("[Toolbar]", "Deactivate Layers");
if (!viewer.layerManager) {
viewer.layerManager = new LayerManager(viewer);
}
viewer.layerManager.hide();
},
},
},
{
menuId: ToolbarMenuId.MarkupVisibility,
config: {
visible: false,
},
},
{
menuId: ToolbarMenuId.Fullscreen,
config: {
onClick: (bimViewer, toolbar) => {
const isFullScreen = !!document.fullscreenElement;
const onResize = () => {
const toolbarMenu = toolbar?.menuList.get(
ToolbarMenuId.Fullscreen
);
toolbarMenu && toolbarMenu.setActive(isFullScreen);
};

if (isFullScreen) {
document.exitFullscreen();
window.removeEventListener("resize", onResize);
} else {
compareHelper.container.requestFullscreen();
}
window.addEventListener("resize", onResize);
},
},
},
];
}
</script>
</body>
</html>

2 changes: 2 additions & 0 deletions public/demo/dxf_5.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<div id="myCanvas" class="container"></div>
<div class="markup-toolbar">
<button id="ArrowMarkup" class="markup-toolbar-btn">Arrow</button>
<button id="CloudRectWithTextMarkup" class="markup-toolbar-btn">CloudRect</button>
<button id="RectMarkup" class="markup-toolbar-btn">Rect</button>
<button id="CircleMarkup" class="markup-toolbar-btn">Circle</button>
<button id="DotMarkup" class="markup-toolbar-btn">Dot</button>
Expand Down Expand Up @@ -178,6 +179,7 @@
};

registerClickEvent("ArrowMarkup");
registerClickEvent("CloudRectWithTextMarkup");
registerClickEvent("RectMarkup");
registerClickEvent("CircleMarkup");
registerClickEvent("DotMarkup");
Expand Down
Loading

0 comments on commit 0090090

Please sign in to comment.