Frusta

Check-in [b3b3d219dc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:initial exercise preview
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b3b3d219dc11ed0bed3f793fc615eb781a4b8efc
User & Date: rmelton 2013-10-23 00:06:37
Context
2013-10-23
00:09
repack exercise preview check-in: 803b3983ed user: rmelton tags: trunk
00:06
initial exercise preview check-in: b3b3d219dc user: rmelton tags: trunk
2013-10-22
00:27
Added circle exercise check-in: d5150d3425 user: rmelton tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/machine/machine_0.1.tcl.



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


namespace eval Machine {
  variable w  .exersiseFrame
  variable v






  set v(x0) 0

  set v(x1) 200

  set v(y0) 0
  set v(y1) 200










  proc ExerciseFrame {} {
    variable w
    catch {destroy $w}
    toplevel $w
    wm title $w "Printer Exercise Frame"

    checkbutton $w.homming -text "Initial X/Y homming"
    scale $w.xMax -orient horizontal -label "xMax"  -bd 2 -relief sunken -from 0 -to 200
    scale $w.yMax -orient horizontal -label "yMax"  -bd 2 -relief sunken -from 0 -to 200
    scale $w.loops -orient vertical  -label "loops" -bd 2 -relief sunken -from 1 -to 200

























































    label $w.stlFileLabel -text "Output STL File:"
    entry $w.stlFileName

    canvas $w.view

    button $w.preview -text "Preview" -command [namespace code Preview]
    button $w.write -text "Write"

    grid $w.homming       -              $w.view
    grid $w.loops         $w.xMax        ^        -sticky ew
    grid ^                $w.yMax        ^        -sticky ew
    grid x                x              $w.preview
    grid $w.stlFileLabel  $w.stlFileName $w.write
  }

  proc Preview {} {
    variable w
    variable v
    $w.view delete all
    lassign {0 0 200 200} X0 Y0 X1 Y1
    $w.view create rect $X0 $Y0 $X1 $Y1 -fill red
    update
    for {set i 0} {$i < 12} {incr i} {
      set x0 [expr {$i*($v(x1)-$v(x0))/12.0+$v(x0)}]
      set x1 [expr {$i*($v(x0)-$v(x1))/12.0+$v(x1)}]

      $w.view create line $x0 $Y0 $x1 $Y1 -fill blue





















      update idletasks
      after 100
    }






    for {set i 0} {$i < 12} {incr i} {





      set y0 [expr {$i*($v(y0)-$v(y1))/12.0+$v(y1)}]
      set y1 [expr {$i*($v(y1)-$v(y0))/12.0+$v(y0)}]
      $w.view create line $X0 $y0 $X1 $y1 -fill blue
      update idletasks
      after 100

    }











    for {set deg 0} {$deg < 180} {incr deg} {
      set i [expr {$deg/360.0*2*3.1415}]
      set x0 [expr {cos($i)*100+100}]
      set y0 [expr {sin($i)*100+100}]
      set x1 [expr {cos($i+3.1415)*100+100}]
      set y1 [expr {sin($i+3.1415)*100+100}]
      $w.view create line $x0 $y0 $x1 $y1 -fill green
      update idletasks
      after 100


    }

    
  }
  proc buildExercise {} {














    






  }













}














































package provide frusta::machine 0.1

## Local Variables:
## mode: tcl
## tcl-indent-level: 2
## indent-tabs-mode: nil
## End:
>
>



>
>
>
>
>
>
|
>
|
>
|
<
>
>
>
>
>
>
>
>
>







<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<
>



|
|
<









|

|
|
<
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
|
>
>
>
>
>
|
|
<
<
<
>

>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
<
<
<
>
>

>
|
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170



171
172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package require frusta::settings

namespace eval Machine {
  variable w  .exersiseFrame
  variable v
  set v(x0) [expr {[Settings::Get buildWidth]*0.1}]
  set v(x1) [expr {[Settings::Get buildWidth]*0.9}]
  set v(y0) [expr {[Settings::Get buildDepth]*0.1}]
  set v(y1) [expr {[Settings::Get buildDepth]*0.9}]
  set v(z0) [expr {[Settings::Get buildHeight]*0.1}]
  set v(z1) [expr {[Settings::Get buildHeight]*0.9}]
  set v(bedX0) 0
  set v(bedX1) [Settings::Get buildWidth]
  set v(bedY0) 0
  set v(bedY1) [Settings::Get buildHeight]
  set v(loops) 20

  set v(autohome)        1
  set v(doOpositeSides)  1
  set v(doOpositeCircle) 1
  set v(doSideStitch)    1
  set v(doSpiral)        1
  set v(segsOpositeSide)    5
  set v(segsOpositeCircle) 10
  set v(segsStitchSides)   20
  set v(segsSpiral)        20

  proc ExerciseFrame {} {
    variable w
    catch {destroy $w}
    toplevel $w
    wm title $w "Printer Exercise Frame"





    eval {
      ttk::labelframe $w.bed -text "Bed Extents"
      label $w.bed.x -text "X"
      label $w.bed.y -text "Y"
      label $w.bed.min -text "Minimum"
      label $w.bed.max -text "Maximum"
      spinbox $w.bed.xMin -from 0 -to [Settings::Get buildWidth]  -textvariable [namespace current]::v(bedX0) -width 6
      spinbox $w.bed.yMin -from 0 -to [Settings::Get buildDepth] -textvariable [namespace current]::v(bedY0) -width 6
      spinbox $w.bed.xMax -from 0 -to [Settings::Get buildWidth]  -textvariable [namespace current]::v(bedX1) -width 6
      spinbox $w.bed.yMax -from 0 -to [Settings::Get buildDepth] -textvariable [namespace current]::v(bedY1) -width 6
      grid x        $w.bed.min  $w.bed.max 
      grid $w.bed.x $w.bed.xMin $w.bed.xMax
      grid $w.bed.y $w.bed.yMin $w.bed.yMax
    }
    eval {
      ttk::labelframe $w.test -text "Test Extents"
      label $w.test.x -text "X"
      label $w.test.y -text "Y"
      label $w.test.z -text "Z"
      label $w.test.min -text "Minimum"
      label $w.test.max -text "Maximum"
      spinbox $w.test.xMin -from 0 -to [Settings::Get buildWidth]  -textvariable [namespace current]::v(x0) -width 6
      spinbox $w.test.yMin -from 0 -to [Settings::Get buildDepth]  -textvariable [namespace current]::v(y0) -width 6
      spinbox $w.test.zMin -from 0 -to [Settings::Get buildHeight] -textvariable [namespace current]::v(z0) -width 6
      spinbox $w.test.xMax -from 0 -to [Settings::Get buildWidth]  -textvariable [namespace current]::v(x1) -width 6
      spinbox $w.test.yMax -from 0 -to [Settings::Get buildDepth]  -textvariable [namespace current]::v(y1) -width 6
      spinbox $w.test.zMax -from 0 -to [Settings::Get buildHeight] -textvariable [namespace current]::v(z1) -width 6
      grid x        $w.test.min  $w.test.max 
      grid $w.test.x $w.test.xMin $w.test.xMax
      grid $w.test.y $w.test.yMin $w.test.yMax
      grid $w.test.z $w.test.zMin $w.test.zMax
    }
    eval {
      ttk::labelframe $w.loop -text "Test procedure"
      label $w.loop.loopL -text "loop test \#times = "
      spinbox $w.loop.loops -from 0 -to 100 -textvariable [namespace current]::v(loops) -width 6 -justify right
      checkbutton $w.loop.homming        -text "X/Y/Z homming"   -variable [namespace current]::v(autohome)
      checkbutton $w.loop.opositeCorners -text "oposite sides"   -variable [namespace current]::v(doOpositeSides)
      checkbutton $w.loop.opositeCircle  -text "oposite circle"  -variable [namespace current]::v(doOpositeCircle)
      checkbutton $w.loop.stitchSides    -text "stitch sides"    -variable [namespace current]::v(doSideStitch)
      checkbutton $w.loop.doSpiral       -text "spiral"          -variable [namespace current]::v(doSpiral)

      label $w.loop.n -text "\# segments"
      spinbox $w.loop.segsOpositeSide   -from 0 -to 100 -textvariable [namespace current]::v(segsOpositeSide)   -width 6 -justify right
      spinbox $w.loop.segsOpositeCircle -from 0 -to 100 -textvariable [namespace current]::v(segsOpositeCircle) -width 6 -justify right
      spinbox $w.loop.segsStitchSides   -from 0 -to 100 -textvariable [namespace current]::v(segsStitchSides)   -width 6 -justify right
      spinbox $w.loop.segsSpiral        -from 0 -to 100 -textvariable [namespace current]::v(segsSpiral)        -width 6 -justify right
      

      grid $w.loop.loopL $w.loop.loops
      grid x             $w.loop.homming        $w.loop.n                 -sticky w
      grid x             $w.loop.opositeCorners $w.loop.segsOpositeSide   -sticky w
      grid x             $w.loop.opositeCircle  $w.loop.segsOpositeCircle -sticky w
      grid x             $w.loop.stitchSides    $w.loop.segsStitchSides   -sticky w
      grid x             $w.loop.doSpiral       $w.loop.segsSpiral        -sticky w
    }

    label $w.stlFileLabel -text "Output STL File:"
    entry $w.stlFileName


    canvas $w.view -width [expr {[Settings::Get buildWidth]}] -height  [expr {[Settings::Get buildDepth]}]
    button $w.preview -text "Preview" -command [namespace code Preview]
    button $w.write -text "Write"

    grid $w.bed           $w.test        $w.view  -sticky n
    grid $w.loop          -              ^        -sticky ew

    grid x                x              $w.preview
    grid $w.stlFileLabel  $w.stlFileName $w.write
  }

  proc Preview {} {
    variable w
    variable v
    $w.view delete all
    lassign {0 0 200 200} X0 Y0 X1 Y1
    $w.view create rect $v(bedX0) $v(bedY0) $v(bedX1) $v(bedY1) -fill red
    update
    if {$v(doOpositeSides)} {
      drawPathInCanvas $w.view [squareCrissCrossXY $v(x0) $v(y0) $v(x1) $v(y1) $v(segsOpositeSide)] 25 {-fill blue}

    }
    if {$v(doOpositeCircle)} {
      drawPathInCanvas $w.view [roundCrissCrossXY  $v(x0) $v(y0) $v(x1) $v(y1) $v(segsOpositeCircle)] 25 {-fill green}
    }
    if {$v(doSideStitch)} {
      drawPathInCanvas $w.view [stitchSidesXY      $v(x0) $v(y0) $v(x1) $v(y1) $v(segsStitchSides)]  25 {-fill white}
    }
    if {$v(doSpiral)} {
      drawPathInCanvas $w.view [spiralOutXY         $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]        5 {-fill purple -arrow none}
      drawPathInCanvas $w.view [spiralInXY          $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]        5 {-fill pink -arrow none}
    }
  }
  proc buildExercise {} {
    
  }
  proc drawPathInCanvas {c path {delay 0} {pathArgs {}}} {
    set pathPt [lassign $path P0]
    lassign $P0 x0 y0
    foreach pt $pathPt {
      lassign $pt x1 y1
      $c create line $x0 $y0 $x1 $y1 -fill green -arrow last {*}$pathArgs
      lassign $pt x0 y0
      if {$delay > 0} {
        update idletasks
        after $delay
      }
    }
  }

  proc squareCrissCrossXY {X0 Y0 X1 Y1 N} {
    ## draw a lines across the face of a square divided into N parts. N=12 looks like a clock
    set path {}
    for {set i 0} {$i <= $N} {incr i} {
      set x0 [expr {$i*($X1-$X0)/$N+$X0}]
      set x1 [expr {$i*($X0-$X1)/$N+$X1}]
      lappend path [list $x0 $Y0] [list $x1 $Y1]
    }
    for {set i 0} {$i <= $N} {incr i} {
      set y0 [expr {$i*($Y0-$Y1)/$N+$Y1}]
      set y1 [expr {$i*($Y1-$Y0)/$N+$Y0}]



      lappend path [list $X0 $y0] [list $X1 $y1]
    }
    return $path
  }

  proc roundCrissCrossXY {X0 Y0 X1 Y1 N} {
    ## draw a lines across the face of a circle divided into N parts. N=12 looks like a clock
    set path {}
    set Xc [expr {($X0+$X1)/2}]
    set Yc [expr {($Y0+$Y1)/2}]
    set R [expr {min(abs($X1-$X0)/2,abs($Y1-$Y0)/2)}]
    lappend path [list $Xc $Yc]
    set Pi 3.14159265
    for {set deg 0} {$deg < 180} {set deg [expr {$deg+(360.0/$N)}]} {
      set i [expr {$deg/360.0*2*$Pi}]
      set x0 [expr {cos($i)    *$R+$Xc}]
      set y0 [expr {sin($i)    *$R+$Yc}]
      set x1 [expr {cos($i+$Pi)*$R+$Xc}]
      set y1 [expr {sin($i+$Pi)*$R+$Yc}]



      lappend path [list $x0 $y0]
      lappend path [list $x1 $y1]
    }
    return $path
  }


  proc stitchSidesXY {X0 Y0 X1 Y1 N} {
    ## chase a line across edges in N steps
    set path {}
    set Xc [expr {$X0+$X1/2}]
    set Yc [expr {$Y0+$Y1/2}]
    set width  [expr {$X1-$X0}]
    set height [expr {$Y1-$Y0}]
    set R [expr {min(abs($X1-$X0)/2,abs($Y1-$Y0)/2)}]
    for {set i 0} {$i <= $N} {incr i} {
      set x0 [expr {1.0*($width/$N)*$i+$X0}]
      set y0 [expr {$Y0}]
      set x1 [expr {$X1}]
      set y1 [expr {1.0*($height/$N)*$i+$Y0}]
      lappend path [list $x0 $y0] [list $x1 $y1]
    }
    for {set i 0} {$i <= $N} {incr i} {
      set x0 [expr {$X1}]
      set y0 [expr {1.0*($height/$N)*$i+$Y0}]
      set x1 [expr {$X1-1.0*($width/$N)*$i}]
      set y1 [expr {$Y1}]
      lappend path [list $x0 $y0] [list $x1 $y1]
    }
    for {set i $N} {$i >= 0} {incr i -1} {
      set x0 [expr {1.0*($width/$N)*$i+$X0}]
      set y0 [expr {$Y1}]
      set x1 [expr {$X0}]
      set y1 [expr {1.0*($height/$N)*$i+$Y0}]
      lappend path [list $x0 $y0] [list $x1 $y1]
    }
    for {set i $N} {$i >= 0} {incr i -1} {
      set x0 [expr {$X0}]
      set y0 [expr {1.0*($height/$N)*$i+$Y0}]
      set x1 [expr {$X1-1.0*($width/$N)*$i}]
      set y1 [expr {$Y0}]
      lappend path [list $x0 $y0] [list $x1 $y1]
    }
    return $path
  }

  proc spiralOutXY {X0 Y0 X1 Y1 N} {
    ## draw spirals
    set path {}
    set Xc [expr {($X0+$X1)/2}]
    set Yc [expr {($Y0+$Y1)/2}]
    set R [expr {min(abs($X1-$X0)/2,abs($Y1-$Y0)/2)}]
    lappend path [list $Xc $Yc]
    set Pi 3.14159265
    for {set j 0} {$j < $N} {incr j} {
      for {set deg 0} {$deg < 360} {incr deg 5} {
        set r [expr {1.0*$R/$N*$j+((1.0*$R/$N)*($deg/360.0))}]
        set i [expr {$deg/360.0*2*$Pi}]
        set x [expr {cos($i)*$r+$Xc}]
        set y [expr {sin($i)*$r+$Yc}]
        lappend path [list $x $y]
      }
    }
    return $path
  }

  proc spiralInXY {X0 Y0 X1 Y1 N} {
    ## draw spirals
    set path {}
    set Xc [expr {($X0+$X1)/2}]
    set Yc [expr {($Y0+$Y1)/2}]
    set R [expr {min(abs($X1-$X0)/2,abs($Y1-$Y0)/2)}]
    lappend path [list $X1 $Yc]
    set Pi 3.14159265
    for {set j [expr {$N-1}]} {$j >= 0} {incr j -1} {
      for {set deg 0} {$deg < 360} {incr deg 5} {
        set r [expr {1.0*$R/$N*$j+((1.0*$R/$N)*(1-($deg/360.0)))}]
        set i [expr {$deg/360.0*2*$Pi}]
        set x [expr {cos($i)*$r+$Xc}]
        set y [expr {sin($i)*$r+$Yc}]
        lappend path [list $x $y]
      }
    }
    return $path
  }


}

package provide frusta::machine 0.1

## Local Variables:
## mode: tcl
## tcl-indent-level: 2
## indent-tabs-mode: nil
## End:

Changes to lib/settings/settings_0.1.tcl.

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
    return $cfg($name)
  }

  proc Init {} {
    variable cfg
    set cfg(options) {}
    AddFloat layerHeight 0.25 "Height in mm of each slice layer"
    AddFloat buildWidth 180 "Width of build volume in mm"

    AddFloat buildHeight 180 "Heigth of build volume in mm"
  }

  proc AddFloat {name default description} {
    variable cfg
    set cfg($name) $default
    set cfg(description,$name) $description
    lappend cfg(options) $name
    if {[info exists cfg(frame)]} {
      
    }
  }
}


package provide frusta::settings 0.1

## Local Variables:
## mode: tcl
## tcl-indent-level: 2
## indent-tabs-mode: nil
## End:







|
>













>








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
    return $cfg($name)
  }

  proc Init {} {
    variable cfg
    set cfg(options) {}
    AddFloat layerHeight 0.25 "Height in mm of each slice layer"
    AddFloat buildWidth  180 "Width of build volume in mm"
    AddFloat buildDepth  180 "Depth of build volume in mm"
    AddFloat buildHeight 180 "Heigth of build volume in mm"
  }

  proc AddFloat {name default description} {
    variable cfg
    set cfg($name) $default
    set cfg(description,$name) $description
    lappend cfg(options) $name
    if {[info exists cfg(frame)]} {
      
    }
  }
}
Settings::Init

package provide frusta::settings 0.1

## Local Variables:
## mode: tcl
## tcl-indent-level: 2
## indent-tabs-mode: nil
## End: