1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
2 | # ---------------------------------------------------------------------- |
---|
3 | # COMPONENT: tool - represents an entire tool |
---|
4 | # |
---|
5 | # This object represents an entire tool defined by Rappture. |
---|
6 | # Each tool resides in an installation directory with other tool |
---|
7 | # resources (libraries, examples, etc.). Each tool is defined by |
---|
8 | # its inputs and outputs, which are tied to various widgets in the |
---|
9 | # GUI. Each tool tracks the inputs, knows when they're changed, |
---|
10 | # and knows how to run itself to produce new results. |
---|
11 | # ====================================================================== |
---|
12 | # AUTHOR: Michael McLennan, Purdue University |
---|
13 | # Copyright (c) 2004-2014 HUBzero Foundation, LLC |
---|
14 | # |
---|
15 | # See the file "license.terms" for information on usage and |
---|
16 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
17 | # ====================================================================== |
---|
18 | |
---|
19 | itcl::class Rappture::Tool { |
---|
20 | inherit Rappture::ControlOwner |
---|
21 | |
---|
22 | constructor {xmlobj installdir} { |
---|
23 | Rappture::ControlOwner::constructor "" |
---|
24 | } { # defined below } |
---|
25 | |
---|
26 | destructor { # defined below } |
---|
27 | |
---|
28 | public method installdir {} { |
---|
29 | return [$_task installdir] |
---|
30 | } |
---|
31 | public method get_uq {args} { |
---|
32 | sync ;# sync all widget values to XML |
---|
33 | return [eval $_task get_uq $args] |
---|
34 | } |
---|
35 | public method run {args} { |
---|
36 | sync ;# sync all widget values to XML |
---|
37 | |
---|
38 | foreach {status result} [eval $_task run $args] break |
---|
39 | if {$status == 0} { |
---|
40 | # move good results to the data/results directory |
---|
41 | $_task save $result |
---|
42 | } |
---|
43 | |
---|
44 | return [list $status $result] |
---|
45 | } |
---|
46 | public method abort {} { |
---|
47 | $_task abort |
---|
48 | } |
---|
49 | public method reset {} { |
---|
50 | $_task reset |
---|
51 | } |
---|
52 | |
---|
53 | private variable _task "" ;# underlying task for the tool |
---|
54 | |
---|
55 | # global resources for this tool session (from task) |
---|
56 | public proc resources {{option ""}} { |
---|
57 | eval ::Rappture::Task::resources $option |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | # ---------------------------------------------------------------------- |
---|
62 | # CONSTRUCTOR |
---|
63 | # ---------------------------------------------------------------------- |
---|
64 | itcl::body Rappture::Tool::constructor {xmlobj installdir} { |
---|
65 | if {![Rappture::library isvalid $xmlobj]} { |
---|
66 | error "bad value \"$xmlobj\": should be Rappture::Library" |
---|
67 | } |
---|
68 | |
---|
69 | set _task [Rappture::Task ::#auto $xmlobj $installdir \ |
---|
70 | -logger ::Rappture::Logger::log] |
---|
71 | |
---|
72 | # save a reference to the tool XML in the ControlOwner |
---|
73 | set _xmlobj $xmlobj |
---|
74 | } |
---|
75 | |
---|
76 | # ---------------------------------------------------------------------- |
---|
77 | # DESTRUCTOR |
---|
78 | # ---------------------------------------------------------------------- |
---|
79 | itcl::body Rappture::Tool::destructor {} { |
---|
80 | itcl::delete object $_task |
---|
81 | } |
---|