Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
e94cf475
Commit
e94cf475
authored
Nov 08, 2011
by
kliment
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #81 from sdevijver/master
Limited loading of OpenSCAD files
parents
c4884cf1
06a69074
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
71 deletions
+118
-71
plater.py
plater.py
+118
-71
No files found.
plater.py
View file @
e94cf475
...
@@ -2,6 +2,12 @@
...
@@ -2,6 +2,12 @@
import
wx
,
time
,
random
,
threading
,
os
,
math
import
wx
,
time
,
random
,
threading
,
os
,
math
import
stltool
import
stltool
def
translate
(
l
):
return
l
def
rotate
(
l
):
return
l
def
import_stl
(
s
):
return
s
class
stlwrap
:
class
stlwrap
:
def
__init__
(
self
,
obj
,
name
=
None
):
def
__init__
(
self
,
obj
,
name
=
None
):
self
.
obj
=
obj
self
.
obj
=
obj
...
@@ -16,12 +22,16 @@ class stlwrap:
...
@@ -16,12 +22,16 @@ class stlwrap:
class
showstl
(
wx
.
Window
):
class
showstl
(
wx
.
Window
):
def
__init__
(
self
,
parent
,
size
,
pos
):
def
__init__
(
self
,
parent
,
size
,
pos
):
wx
.
Window
.
__init__
(
self
,
parent
,
size
=
size
,
pos
=
pos
)
wx
.
Window
.
__init__
(
self
,
parent
,
size
=
size
,
pos
=
pos
)
self
.
l
=
wx
.
ListBox
(
self
,
size
=
(
300
,
130
),
pos
=
(
0
,
size
[
1
]
-
130
))
self
.
l
=
wx
.
ListBox
(
self
,
size
=
(
300
,
180
),
pos
=
(
0
,
size
[
1
]
-
180
))
self
.
cl
=
wx
.
Button
(
self
,
label
=
"Clear"
,
pos
=
(
300
,
size
[
1
]
-
180
))
self
.
lb
=
wx
.
Button
(
self
,
label
=
"Load"
,
pos
=
(
300
,
size
[
1
]
-
155
))
self
.
eb
=
wx
.
Button
(
self
,
label
=
"Export"
,
pos
=
(
300
,
size
[
1
]
-
130
))
self
.
eb
=
wx
.
Button
(
self
,
label
=
"Export"
,
pos
=
(
300
,
size
[
1
]
-
130
))
self
.
sb
=
wx
.
Button
(
self
,
label
=
"Snap to Z=0"
,
pos
=
(
300
,
size
[
1
]
-
105
))
self
.
sb
=
wx
.
Button
(
self
,
label
=
"Snap to Z=0"
,
pos
=
(
300
,
size
[
1
]
-
105
))
self
.
cb
=
wx
.
Button
(
self
,
label
=
"Put at 100,100"
,
pos
=
(
300
,
size
[
1
]
-
80
))
self
.
cb
=
wx
.
Button
(
self
,
label
=
"Put at 100,100"
,
pos
=
(
300
,
size
[
1
]
-
80
))
self
.
db
=
wx
.
Button
(
self
,
label
=
"Delete"
,
pos
=
(
300
,
size
[
1
]
-
55
))
self
.
db
=
wx
.
Button
(
self
,
label
=
"Delete"
,
pos
=
(
300
,
size
[
1
]
-
55
))
self
.
ab
=
wx
.
Button
(
self
,
label
=
"Auto"
,
pos
=
(
300
,
size
[
1
]
-
30
))
self
.
ab
=
wx
.
Button
(
self
,
label
=
"Auto"
,
pos
=
(
300
,
size
[
1
]
-
30
))
self
.
cl
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
clear
)
self
.
lb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
right
)
self
.
eb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
export
)
self
.
eb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
export
)
self
.
sb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
snap
)
self
.
sb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
snap
)
self
.
cb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
center
)
self
.
cb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
center
)
...
@@ -125,10 +135,37 @@ class showstl(wx.Window):
...
@@ -125,10 +135,37 @@ class showstl(wx.Window):
self
.
Refresh
()
self
.
Refresh
()
def
right
(
self
,
event
):
def
right
(
self
,
event
):
dlg
=
wx
.
FileDialog
(
self
,
"
Open file to print
"
,
self
.
basedir
,
style
=
wx
.
FD_OPEN
|
wx
.
FD_FILE_MUST_EXIST
)
dlg
=
wx
.
FileDialog
(
self
,
"
Pick file to load
"
,
self
.
basedir
,
style
=
wx
.
FD_OPEN
|
wx
.
FD_FILE_MUST_EXIST
)
dlg
.
SetWildcard
(
"STL files (;*.stl;)"
)
dlg
.
SetWildcard
(
"STL files (;*.stl;)
|*.stl|OpenSCAD files (;*.scad;)|*.scad
"
)
if
(
dlg
.
ShowModal
()
==
wx
.
ID_OK
):
if
(
dlg
.
ShowModal
()
==
wx
.
ID_OK
):
name
=
dlg
.
GetPath
()
name
=
dlg
.
GetPath
()
if
(
name
.
lower
()
.
endswith
(
".stl"
)):
self
.
load_stl
(
event
,
name
)
elif
(
name
.
lower
()
.
endswith
(
".scad"
)):
self
.
load_scad
(
event
,
name
)
def
load_scad
(
self
,
event
,
name
):
lf
=
open
(
name
)
s
=
[
i
.
replace
(
"
\n
"
,
""
)
.
replace
(
"
\r
"
,
""
)
.
replace
(
";"
,
""
)
for
i
in
lf
]
lf
.
close
()
for
i
in
s
:
parts
=
i
.
split
()
translate_list
=
eval
(
parts
[
0
])
rotate_list
=
eval
(
parts
[
1
])
stl_file
=
eval
(
parts
[
2
])
newname
=
os
.
path
.
split
(
stl_file
.
lower
())[
1
]
c
=
1
while
newname
in
self
.
models
:
newname
=
os
.
path
.
split
(
stl_file
.
lower
())[
1
]
newname
=
newname
+
"(
%
d)"
%
c
c
+=
1
stl_path
=
os
.
path
.
join
(
os
.
path
.
split
(
name
)[
0
:
len
(
os
.
path
.
split
(
stl_file
))
-
1
])
stl_full_path
=
os
.
path
.
join
(
stl_path
[
0
],
str
(
stl_file
))
self
.
load_stl_into_model
(
stl_full_path
,
stl_file
,
translate_list
,
rotate_list
[
2
])
def
load_stl
(
self
,
event
,
name
):
if
not
(
os
.
path
.
exists
(
name
)):
if
not
(
os
.
path
.
exists
(
name
)):
return
return
path
=
os
.
path
.
split
(
name
)[
0
]
path
=
os
.
path
.
split
(
name
)[
0
]
...
@@ -137,15 +174,20 @@ class showstl(wx.Window):
...
@@ -137,15 +174,20 @@ class showstl(wx.Window):
#print name
#print name
if
name
.
lower
()
.
endswith
(
".stl"
):
if
name
.
lower
()
.
endswith
(
".stl"
):
#Filter out the path, just show the STL filename.
#Filter out the path, just show the STL filename.
self
.
load_stl_into_model
(
name
,
name
)
self
.
Refresh
()
#print time.time()-t
def
load_stl_into_model
(
self
,
path
,
name
,
offset
=
[
0
,
0
,
0
],
rotation
=
0
):
newname
=
os
.
path
.
split
(
name
.
lower
())[
1
]
newname
=
os
.
path
.
split
(
name
.
lower
())[
1
]
c
=
1
c
=
1
while
newname
in
self
.
models
:
while
newname
in
self
.
models
:
newname
=
os
.
path
.
split
(
name
.
lower
())[
1
]
newname
=
os
.
path
.
split
(
name
.
lower
())[
1
]
newname
=
newname
+
"(
%
d)"
%
c
newname
=
newname
+
"(
%
d)"
%
c
c
+=
1
c
+=
1
self
.
models
[
newname
]
=
stltool
.
stl
(
name
)
self
.
models
[
newname
]
=
stltool
.
stl
(
path
)
self
.
models
[
newname
]
.
offsets
=
[
0
,
0
,
0
]
self
.
models
[
newname
]
.
offsets
=
offset
self
.
models
[
newname
]
.
rot
=
0
self
.
models
[
newname
]
.
rot
=
rotation
self
.
models
[
newname
]
.
filename
=
name
self
.
models
[
newname
]
.
filename
=
name
minx
,
miny
,
minz
,
maxx
,
maxy
,
maxz
=
(
10000
,
10000
,
10000
,
0
,
0
,
0
)
minx
,
miny
,
minz
,
maxx
,
maxy
,
maxz
=
(
10000
,
10000
,
10000
,
0
,
0
,
0
)
for
i
in
self
.
models
[
newname
]
.
facets
:
for
i
in
self
.
models
[
newname
]
.
facets
:
...
@@ -193,8 +235,13 @@ class showstl(wx.Window):
...
@@ -193,8 +235,13 @@ class showstl(wx.Window):
self
.
l
.
Select
(
0
)
self
.
l
.
Select
(
0
)
self
.
l
.
Select
(
self
.
l
.
GetCount
()
-
1
)
self
.
l
.
Select
(
self
.
l
.
GetCount
()
-
1
)
def
clear
(
self
,
event
):
result
=
wx
.
MessageBox
(
'Are you sure you want to clear the grid? All unsaved changes will be lost.'
,
'Clear the grid?'
,
wx
.
YES_NO
|
wx
.
ICON_QUESTION
)
if
(
result
==
2
):
self
.
models
=
{}
self
.
Refresh
()
self
.
Refresh
()
#print time.time()-t
def
move
(
self
,
event
):
def
move
(
self
,
event
):
if
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
if
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
...
@@ -297,11 +344,11 @@ class showstl(wx.Window):
...
@@ -297,11 +344,11 @@ class showstl(wx.Window):
#s.export()
#s.export()
class
stlwin
(
wx
.
Frame
):
class
stlwin
(
wx
.
Frame
):
def
__init__
(
self
,
size
=
(
400
,
5
3
0
)):
def
__init__
(
self
,
size
=
(
400
,
5
8
0
)):
wx
.
Frame
.
__init__
(
self
,
None
,
title
=
"Right-click to add a file"
,
size
=
size
)
wx
.
Frame
.
__init__
(
self
,
None
,
title
=
"Right-click to add a file"
,
size
=
size
)
self
.
SetIcon
(
wx
.
Icon
(
"plater.ico"
,
wx
.
BITMAP_TYPE_ICO
))
self
.
SetIcon
(
wx
.
Icon
(
"plater.ico"
,
wx
.
BITMAP_TYPE_ICO
))
self
.
SetClientSize
(
size
)
self
.
SetClientSize
(
size
)
self
.
s
=
showstl
(
self
,(
400
,
5
3
0
),(
0
,
0
))
self
.
s
=
showstl
(
self
,(
400
,
5
8
0
),(
0
,
0
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
=
wx
.
App
(
False
)
app
=
wx
.
App
(
False
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment