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
a3c03d49
Commit
a3c03d49
authored
Nov 08, 2011
by
Steven Devijver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added loading of OpenSCAD files feature + corrected file wildcard when exporting
parent
262b000f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
60 deletions
+103
-60
plater.py
plater.py
+103
-60
No files found.
plater.py
View file @
a3c03d49
...
...
@@ -2,6 +2,12 @@
import
wx
,
time
,
random
,
threading
,
os
,
math
import
stltool
def
translate
(
l
):
return
l
def
rotate
(
l
):
return
l
def
import_stl
(
s
):
return
s
class
stlwrap
:
def
__init__
(
self
,
obj
,
name
=
None
):
self
.
obj
=
obj
...
...
@@ -16,12 +22,14 @@ class stlwrap:
class
showstl
(
wx
.
Window
):
def
__init__
(
self
,
parent
,
size
,
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
,
155
),
pos
=
(
0
,
size
[
1
]
-
155
))
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
.
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
.
db
=
wx
.
Button
(
self
,
label
=
"Delete"
,
pos
=
(
300
,
size
[
1
]
-
55
))
self
.
ab
=
wx
.
Button
(
self
,
label
=
"Auto"
,
pos
=
(
300
,
size
[
1
]
-
30
))
self
.
lb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
load
)
self
.
eb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
export
)
self
.
sb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
snap
)
self
.
cb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
center
)
...
...
@@ -64,9 +72,40 @@ class showstl(wx.Window):
self
.
l
.
Select
(
self
.
l
.
GetCount
()
-
1
)
self
.
Refresh
()
def
load
(
self
,
event
):
dlg
=
wx
.
FileDialog
(
self
,
"Pick file to load"
,
self
.
basedir
,
style
=
wx
.
FD_OPEN
|
wx
.
FD_FILE_MUST_EXIST
)
dlg
.
SetWildcard
(
"OpenSCAD files (;*.scad;)"
)
if
(
dlg
.
ShowModal
()
==
wx
.
ID_OK
):
name
=
dlg
.
GetPath
()
print
(
"Path:
%
s"
%
(
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
])
print
(
"translate([
%
s,
%
s,
%
s]) rotate([
%
s,
%
s,
%
s]) import_slt('
%
s');"
%
(
translate_list
[
0
],
translate_list
[
1
],
translate_list
[
2
],
rotate_list
[
0
],
rotate_list
[
1
],
rotate_list
[
2
],
stl_file
))
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
])
print
(
"STL file:
%
s"
%
(
stl_file
))
print
(
"STL path:
%
s"
%
(
stl_path
))
stl_full_path
=
os
.
path
.
join
(
stl_path
[
0
],
str
(
stl_file
))
print
(
"STL full path:
%
s"
%
(
stl_full_path
))
self
.
load_stl
(
stl_full_path
,
stl_file
)
def
export
(
self
,
event
):
dlg
=
wx
.
FileDialog
(
self
,
"Pick file to save to"
,
self
.
basedir
,
style
=
wx
.
FD_SAVE
)
dlg
.
SetWildcard
(
"
STL files (;*.stl
;)"
)
dlg
.
SetWildcard
(
"
OpenSCAD files (;*.scad
;)"
)
if
(
dlg
.
ShowModal
()
==
wx
.
ID_OK
):
name
=
dlg
.
GetPath
()
sf
=
open
(
name
.
replace
(
"."
,
"_"
)
+
".scad"
,
"w"
)
...
...
@@ -137,65 +176,69 @@ class showstl(wx.Window):
#print name
if
name
.
lower
()
.
endswith
(
".stl"
):
#Filter out the path, just show the STL filename.
newname
=
os
.
path
.
split
(
name
.
lower
())[
1
]
c
=
1
while
newname
in
self
.
models
:
newname
=
os
.
path
.
split
(
name
.
lower
())[
1
]
newname
=
newname
+
"(
%
d)"
%
c
c
+=
1
self
.
models
[
newname
]
=
stltool
.
stl
(
name
)
self
.
models
[
newname
]
.
offsets
=
[
0
,
0
,
0
]
self
.
models
[
newname
]
.
rot
=
0
self
.
models
[
newname
]
.
filename
=
name
minx
,
miny
,
minz
,
maxx
,
maxy
,
maxz
=
(
10000
,
10000
,
10000
,
0
,
0
,
0
)
for
i
in
self
.
models
[
newname
]
.
facets
:
for
j
in
i
[
1
]:
if
j
[
0
]
<
minx
:
minx
=
j
[
0
]
if
j
[
1
]
<
miny
:
miny
=
j
[
1
]
if
j
[
2
]
<
minz
:
minz
=
j
[
2
]
if
j
[
0
]
>
maxx
:
maxx
=
j
[
0
]
if
j
[
1
]
>
maxy
:
maxy
=
j
[
1
]
if
j
[
2
]
>
maxz
:
maxz
=
j
[
2
]
self
.
models
[
newname
]
.
dims
=
[
minx
,
maxx
,
miny
,
maxy
,
minz
,
maxz
]
#if minx<0:
# self.models[newname].offsets[0]=-minx
#if miny<0:
# self.models[newname].offsets[1]=-miny
self
.
models
[
newname
]
.
bitmap
=
wx
.
EmptyBitmap
(
800
,
800
,
32
)
dc
=
wx
.
MemoryDC
()
dc
.
SelectObject
(
self
.
models
[
newname
]
.
bitmap
)
dc
.
SetBackground
(
wx
.
Brush
((
0
,
0
,
0
,
0
)))
dc
.
SetBrush
(
wx
.
Brush
((
0
,
0
,
0
,
255
)))
#dc.DrawRectangle(-1,-1,10000,10000)
dc
.
SetBrush
(
wx
.
Brush
(
wx
.
Colour
(
128
,
255
,
128
)))
dc
.
SetPen
(
wx
.
Pen
(
wx
.
Colour
(
128
,
128
,
128
)))
m
=
self
.
models
[
newname
]
#m.offsets=[10,10,0]
print
m
.
offsets
,
m
.
dims
scale
=
2
for
i
in
m
.
facets
:
#random.sample(m.facets,min(100000,len(m.facets))):
dc
.
DrawPolygon
([
wx
.
Point
(
400
+
scale
*
p
[
0
],(
400
+
scale
*
p
[
1
]))
for
p
in
i
[
1
]])
#if(time.time()-t)>5:
# break
dc
.
SelectObject
(
wx
.
NullBitmap
)
m
.
bitmap
.
SetMask
(
wx
.
Mask
(
m
.
bitmap
,
wx
.
Colour
(
0
,
0
,
0
,
255
)))
#print time.time()-t
self
.
l
.
Append
(
newname
)
i
=
self
.
l
.
GetSelection
()
if
i
==
wx
.
NOT_FOUND
:
self
.
l
.
Select
(
0
)
self
.
l
.
Select
(
self
.
l
.
GetCount
()
-
1
)
self
.
load_stl
(
name
,
name
)
self
.
Refresh
()
#print time.time()-t
def
load_stl
(
self
,
path
,
name
):
newname
=
os
.
path
.
split
(
name
.
lower
())[
1
]
c
=
1
while
newname
in
self
.
models
:
newname
=
os
.
path
.
split
(
name
.
lower
())[
1
]
newname
=
newname
+
"(
%
d)"
%
c
c
+=
1
self
.
models
[
newname
]
=
stltool
.
stl
(
path
)
self
.
models
[
newname
]
.
offsets
=
[
0
,
0
,
0
]
self
.
models
[
newname
]
.
rot
=
0
self
.
models
[
newname
]
.
filename
=
name
minx
,
miny
,
minz
,
maxx
,
maxy
,
maxz
=
(
10000
,
10000
,
10000
,
0
,
0
,
0
)
for
i
in
self
.
models
[
newname
]
.
facets
:
for
j
in
i
[
1
]:
if
j
[
0
]
<
minx
:
minx
=
j
[
0
]
if
j
[
1
]
<
miny
:
miny
=
j
[
1
]
if
j
[
2
]
<
minz
:
minz
=
j
[
2
]
if
j
[
0
]
>
maxx
:
maxx
=
j
[
0
]
if
j
[
1
]
>
maxy
:
maxy
=
j
[
1
]
if
j
[
2
]
>
maxz
:
maxz
=
j
[
2
]
self
.
models
[
newname
]
.
dims
=
[
minx
,
maxx
,
miny
,
maxy
,
minz
,
maxz
]
#if minx<0:
# self.models[newname].offsets[0]=-minx
#if miny<0:
# self.models[newname].offsets[1]=-miny
self
.
models
[
newname
]
.
bitmap
=
wx
.
EmptyBitmap
(
800
,
800
,
32
)
dc
=
wx
.
MemoryDC
()
dc
.
SelectObject
(
self
.
models
[
newname
]
.
bitmap
)
dc
.
SetBackground
(
wx
.
Brush
((
0
,
0
,
0
,
0
)))
dc
.
SetBrush
(
wx
.
Brush
((
0
,
0
,
0
,
255
)))
#dc.DrawRectangle(-1,-1,10000,10000)
dc
.
SetBrush
(
wx
.
Brush
(
wx
.
Colour
(
128
,
255
,
128
)))
dc
.
SetPen
(
wx
.
Pen
(
wx
.
Colour
(
128
,
128
,
128
)))
m
=
self
.
models
[
newname
]
#m.offsets=[10,10,0]
print
m
.
offsets
,
m
.
dims
scale
=
2
for
i
in
m
.
facets
:
#random.sample(m.facets,min(100000,len(m.facets))):
dc
.
DrawPolygon
([
wx
.
Point
(
400
+
scale
*
p
[
0
],(
400
+
scale
*
p
[
1
]))
for
p
in
i
[
1
]])
#if(time.time()-t)>5:
# break
dc
.
SelectObject
(
wx
.
NullBitmap
)
m
.
bitmap
.
SetMask
(
wx
.
Mask
(
m
.
bitmap
,
wx
.
Colour
(
0
,
0
,
0
,
255
)))
#print time.time()-t
self
.
l
.
Append
(
newname
)
i
=
self
.
l
.
GetSelection
()
if
i
==
wx
.
NOT_FOUND
:
self
.
l
.
Select
(
0
)
self
.
l
.
Select
(
self
.
l
.
GetCount
()
-
1
)
def
move
(
self
,
event
):
if
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
if
(
self
.
initpos
is
not
None
):
...
...
@@ -297,11 +340,11 @@ class showstl(wx.Window):
#s.export()
class
stlwin
(
wx
.
Frame
):
def
__init__
(
self
,
size
=
(
400
,
5
30
)):
def
__init__
(
self
,
size
=
(
400
,
5
55
)):
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
.
SetClientSize
(
size
)
self
.
s
=
showstl
(
self
,(
400
,
5
30
),(
0
,
0
))
self
.
s
=
showstl
(
self
,(
400
,
5
55
),(
0
,
0
))
if
__name__
==
'__main__'
:
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