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 run {args} { |
---|
32 | sync ;# sync all widget values to XML |
---|
33 | |
---|
34 | foreach {status result} [eval $_task run $args] break |
---|
35 | if {$status == 0} { |
---|
36 | # move good results to the data/results directory |
---|
37 | $_task save $result |
---|
38 | } |
---|
39 | |
---|
40 | return [list $status $result] |
---|
41 | } |
---|
42 | public method abort {} { |
---|
43 | $_task abort |
---|
44 | } |
---|
45 | public method reset {} { |
---|
46 | $_task reset |
---|
47 | } |
---|
48 | |
---|
49 | private variable _task "" ;# underlying task for the tool |
---|
50 | |
---|
51 | # global resources for this tool session (from task) |
---|
52 | public proc resources {{option ""}} { |
---|
53 | eval ::Rappture::Task::resources $option |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | # ---------------------------------------------------------------------- |
---|
58 | # CONSTRUCTOR |
---|
59 | # ---------------------------------------------------------------------- |
---|
60 | itcl::body Rappture::Tool::constructor {xmlobj installdir} { |
---|
61 | if {![Rappture::library isvalid $xmlobj]} { |
---|
62 | error "bad value \"$xmlobj\": should be Rappture::Library" |
---|
63 | } |
---|
64 | |
---|
65 | set _task [Rappture::Task ::#auto $xmlobj $installdir \ |
---|
66 | -logger ::Rappture::Logger::log] |
---|
67 | |
---|
68 | # save a reference to the tool XML in the ControlOwner |
---|
69 | set _xmlobj $xmlobj |
---|
70 | } |
---|
71 | |
---|
72 | # ---------------------------------------------------------------------- |
---|
73 | # DESTRUCTOR |
---|
74 | # ---------------------------------------------------------------------- |
---|
75 | itcl::body Rappture::Tool::destructor {} { |
---|
76 | itcl::delete object $_task |
---|
77 | } |
---|