FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
modelscript/extensions/vscode/src/stepEditorProvider.ts at main · modelscript/modelscript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
modelscript
/
modelscript
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
3
Star
12
Code
Issues
1
Pull requests
5
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
modelscript
/
extensions
/
vscode
/
src
/
stepEditorProvider.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
116 lines (102 loc) · 3.96 KB
Breadcrumbs
modelscript
/
extensions
/
vscode
/
src
/
stepEditorProvider.ts
Copy path
File metadata and controls
116 lines (102 loc) · 3.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import
*
as
vscode
from
"vscode"
;
import
{
LanguageClient
}
from
"vscode-languageclient/browser"
;
export
class
StepEditorProvider
implements
vscode
.
CustomTextEditorProvider
{
static
readonly
viewType
=
"modelscript.stepEditor"
;
constructor
(
private
readonly
context
:
vscode
.
ExtensionContext
,
private
readonly
_client
:
LanguageClient
,
)
{
}
public
async
resolveCustomTextEditor
(
document
:
vscode
.
TextDocument
,
webviewPanel
:
vscode
.
WebviewPanel
,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_token
:
vscode
.
CancellationToken
,
)
:
Promise
<
void
>
{
webviewPanel
.
webview
.
options
=
{
enableScripts
:
true
,
localResourceRoots
:
[
vscode
.
Uri
.
joinPath
(
this
.
context
.
extensionUri
,
"dist"
)
]
,
}
;
let
disposed
=
false
;
webviewPanel
.
webview
.
html
=
this
.
getHtmlForWebview
(
webviewPanel
.
webview
)
;
const
loadMeshes
=
async
(
retries
=
3
,
delayMs
=
500
)
=>
{
if
(
disposed
)
return
;
try
{
webviewPanel
.
webview
.
postMessage
(
{
type
:
"setLoading"
,
data
:
true
}
)
;
const
stepMeshes
=
await
this
.
_client
.
sendRequest
<
unknown
[
]
>
(
"modelscript/getStepMeshes"
,
{
uri
:
document
.
uri
.
toString
(
)
,
}
)
;
if
(
!
disposed
)
{
webviewPanel
.
webview
.
postMessage
(
{
type
:
"stepMeshes"
,
data
:
stepMeshes
}
)
;
webviewPanel
.
webview
.
postMessage
(
{
type
:
"setLoading"
,
data
:
false
}
)
;
}
// If no meshes loaded and we have retries left, wait and try again
// (LSP may still be parsing the STEP file)
if
(
(
!
stepMeshes
||
(
stepMeshes
as
unknown
[
]
)
.
length
===
0
)
&&
retries
>
0
&&
!
disposed
)
{
setTimeout
(
(
)
=>
loadMeshes
(
retries
-
1
,
delayMs
*
2
)
,
delayMs
)
;
}
}
catch
(
e
)
{
console
.
warn
(
"[STEP Editor] Failed to get STEP meshes:"
,
e
)
;
if
(
!
disposed
)
{
webviewPanel
.
webview
.
postMessage
(
{
type
:
"setLoading"
,
data
:
false
}
)
;
}
if
(
retries
>
0
&&
!
disposed
)
{
setTimeout
(
(
)
=>
loadMeshes
(
retries
-
1
,
delayMs
*
2
)
,
delayMs
)
;
}
}
}
;
webviewPanel
.
webview
.
onDidReceiveMessage
(
(
message
)
=>
{
switch
(
message
.
type
||
message
.
command
)
{
case
"ready"
:
loadMeshes
(
)
;
break
;
case
"cadFeatureSelected"
:
vscode
.
window
.
showInformationMessage
(
`Selected CAD Feature ID:
${
message
.
id
}
`
)
;
break
;
case
"generateMultiBody"
:
vscode
.
commands
.
executeCommand
(
"modelscript.generateMultiBody"
)
;
break
;
}
}
)
;
// When the LSP finishes indexing anything, reload meshes in case our STEP file was just processed
const
treeSubscription
=
this
.
_client
.
onNotification
(
"modelscript/projectTreeChanged"
,
(
)
=>
{
loadMeshes
(
1
,
0
)
;
// No retries needed here, it's already an update
}
)
;
const
changeSubscription
=
vscode
.
workspace
.
onDidChangeTextDocument
(
(
e
)
=>
{
if
(
e
.
document
.
uri
.
toString
(
)
===
document
.
uri
.
toString
(
)
)
{
loadMeshes
(
1
,
0
)
;
}
}
)
;
webviewPanel
.
onDidDispose
(
(
)
=>
{
disposed
=
true
;
treeSubscription
.
dispose
(
)
;
changeSubscription
.
dispose
(
)
;
}
)
;
}
private
getHtmlForWebview
(
webview
:
vscode
.
Webview
)
:
string
{
const
scriptUri
=
webview
.
asWebviewUri
(
vscode
.
Uri
.
joinPath
(
this
.
context
.
extensionUri
,
"dist"
,
"stepWebview.js"
)
)
;
const
nonce
=
getNonce
(
)
;
return
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D CAD Viewer (STEP)</title>
<style>
html, body, #root { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; }
</style>
</head>
<body class="vscode-dark">
<div id="root"></div>
<script nonce="
${
nonce
}
" src="
${
scriptUri
}
"></script>
</body>
</html>`
;
}
}
function
getNonce
(
)
{
let
text
=
""
;
const
possible
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
;
for
(
let
i
=
0
;
i
<
32
;
i
++
)
{
text
+=
possible
.
charAt
(
Math
.
floor
(
Math
.
random
(
)
*
possible
.
length
)
)
;
}
return
text
;
}
Back
|
FazBrowse Home
|
New Git URL