aboutsummaryrefslogtreecommitdiff
path: root/vendor/x11iraf/guidemo/marker.gui
blob: bb0fd4897b4e5bd9c6214222692362f6f55acfd3 (plain) (blame)
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# MTEST.GUI --

reset-server
appInitialize mtest Mtest {
!
! Application defaults for the hello world program.
!

Mtest*objects:\
	toplevel	Layout		imgLayout \
	imgLayout	Frame		imviewFrame \
	imviewFrame	Gterm		gterm \
        imgLayout       Layout          tclLayout\
        tclLayout       Group           tclCmdGroup\
        tclLayout       Frame           tclFrame\
        tclFrame        AsciiText       tclEntry\
        tclCmdGroup     Layout          tclCmd\
        tclCmd          Command         tclClear\
        tclCmd          Command         tclExecute\
	tclCmd	        Command		quitButton\


	*shrinkToFit:              			True

	*imgLayout*borderWidth:                    	0
	*imgLayout*highlightThickness:             	0
	*imgLayout*background:                     	ivory3
	*imgLayout*Frame*background:               	ivory3
	*imgLayout*Frame*frameWidth:               	2
	*imgLayout*Command.highlightThickness:     	2

	*imgLayout.layout: vertical { \
	    imviewFrame < +inf -inf * +inf -inf > \
	    tclLayout < +inf -inf * +inf -inf > \
	}

	*imgLayout*imviewFrame.outerOffset:		5
	*imgLayout*imviewFrame.innerOffset:		0
	*imgLayout*imviewFrame.frameWidth:		3
	*imgLayout*imviewFrame.frameType:		sunken
	*gterm.cmapName:                   		image
	*gterm.width:                      		400
	*gterm.height:                     		300
	*gterm.borderColor:                		black
	*gterm.resizable:                  		True
	*gterm.copyOnResize:               		False
	*gterm.ginmodeCursor:              		circle
	*gterm.dialogBgColor:              		cyan
	*gterm.dialogFgColor:              		black
	*gterm.crosshairCursorColor:       		cyan
	*gterm.translations: \
	    <Btn1Down>: call(polyMarker, $x, $y) \n\
	 <EnterWindow>: enter-window()           \n\
	 <LeaveWindow>: leave-window()           \n\
	    <KeyPress>: graphics-input()         \n\
	      <Motion>: track-cursor() call(wcsUpdate,$x,$y)


    	! Define a Debug Tcl shell.
    	!--------------------------
    	*tclLayout*borderWidth:				0
    	*tclLayout*Frame.frameType:			sunken
    	*tclLayout*Frame.frameWidth:			2
    	*tclLayout*Frame.outerOffset:			5
	*imgLayout*tclLayout*Text*foreground:           wheat2
	*imgLayout*tclLayout*Text*background:           gray35
    	*tclLayout*Text*height:				90
    	*tclLayout*Text*editType:			edit
    	*tclLayout.layout:  vertical { \
        	tclFrame < +inf -inf * > \
        	tclCmdGroup < +inf -inf * > \
    	}

    	! Do the command bar group resources.
    	!------------------------------------
    	*tclCmdGroup.width:				300	
    	*tclCmdGroup.height:				40	
    	*tclCmdGroup.label:		
    	*tclCmdGroup.outerOffset:			0
    	*tclCmdGroup.innerOffset:			5
    	*tclCmdGroup*Command.background:		ivory3
    	*tclCmd.layout: horizontal { \
            5 \
            tclClear tclExecute \
	    50 < +inf -inf > \
	    quitButton \
            5 \
    	}
    	*tclClear.label:				Clear
    	*tclExecute.label:				Execute
	*quitButton.label:                         	Quit
}

createObjects
activate

proc Quit args { 
    send client gkey q ; deactivate unmap
}; send quitButton addCallback Quit



# Define some TCL debug procedures

send tclClear   addCallback "send tclEntry set string \"\""

proc tclExec args {
    send server [send tclEntry get string]
} ; send tclExecute addCallback tclExec


# Define a WCS box to track coords

proc makeWCSMarker { args } {
    send gterm createMarker wcsbox {
        type                text
        createMode          noninteractive
        width               20ch
        height              1ch
        lineWidth           0
        imageText           true
        textBgColor         black
        textColor           yellow
        visible             false
    }

    set box_width [send wcsbox get width]
    set box_height [send wcsbox get height]
    set defGeom [format "%sx%s-5-5" $box_width $box_height]
    send gterm parseGeometry "-5-5" $defGeom x y width height

    send wcsbox setAttributes \
        x                   $x \
        y                   $y \
        activated           true \
        visible             true \
        sensitive           true

} ; makeWCSMarker


proc wcsUpdate {x y} \
{
    # Update coords box.
    set text [ format " %7.2f %7.2f " $x $y ]
    send wcsbox "set text \{$text\}; redraw noerase"
}


createMenu markerMenu toplevel {
    { "Marker Type"	f.title			        }
    {            	f.dblline			}
    { "Box"             f.exec  "set_mtype box"         }
    { "Circle"          f.exec  "set_mtype circle"      }
    { "Ellipse"         f.exec  "set_mtype ellipse"     }
    { "Polygon"         f.exec  "set_poly  polygon"     }
    { "Rectangle"       f.exec  "set_mtype rectangle"   }
    { "Text"            f.exec  "set_mtype text"        }
    {            	f.dblline			}
    { "Print geometry"  f.exec "print [send objmarker getRegion]"     }

}

proc set_mtype { type } { send objmarker "markpos; set type $type; redraw" }
proc set_poly args { 
    send objmarker getAttributes x xcur y ycur
    set poly "{ { [expr "$xcur+00"] [expr "$ycur+00"] } \
	        { [expr "$xcur-50"] [expr "$ycur+20"] } \
	        { [expr "$xcur-50"] [expr "$ycur-30"] } \
	        { [expr "$xcur+00"] [expr "$ycur-50"] } \
	        { [expr "$xcur+50"] [expr "$ycur-30"] } \
	        { [expr "$xcur+50"] [expr "$ycur+20"] } }"

    send objmarker "markpos; set type polygon; redraw" 
    #print "input vertices=" $poly
    #send objmarker setVertices $poly
    #send objmarker getVertices tpoly
    #print "output vertices=" $tpoly

    send objmarker getAttributes x x y y width w height h type t rotangle r
}


# Translations when pointer is inside a marker. Notice I have turned of
# all resizeing and rotating options
set objmarkerTranslations { \
       !Shift <Btn1Motion>:     m_rotateResize()
              <Btn1Motion>:     m_moveResize()
         !Shift <Btn1Down>:     m_raise()  m_markpos()
                <Btn1Down>:     m_raise()  m_markposAdd()
                  <Btn1Up>:     m_redraw() m_destroyNull()
                <Btn2Down>:     m_lower()
                <Btn3Down>:     popup(markerMenu)
                  <Btn3Up>:     popdown(markerMenu)
            <Key>BackSpace:     m_deleteDestroy()
               <Key>Delete:     m_deleteDestroy()
                <KeyPress>:     m_input()
                  <Motion>:     track-cursor()
}


set mtype ellipse
set mtype text
set mtype rectangle
set mtype polygon
set mtype box
set mtype circle

proc polyMarker { xcur  ycur } {

    global objmarkerTranslations mtype

    print "marker type=" $mtype
    print "position =" $xcur "  " $ycur

    set posangle 0
    send gterm createMarker objmarker \
        type                $mtype \
        createMode          noninteractive \
        translations        $objmarkerTranslations \
        lineColor           red \
	knotSize	    1 \
	knotColor	    yellow \
        x                   [expr $xcur + 000] \
        y                   [expr $ycur + 000] \
        width               50 \
        height              50 \
        rotangle            $posangle \
        rotIndicator        True \
        highlightColor      green \
	textBgColor	    black \
        imageText           True \
        activated           True \
        visible             False \
        sensitive           True

    # Closed polygon.
    set poly "{ { [expr "$xcur+00"] [expr "$ycur+00"] } \
	        { [expr "$xcur-50"] [expr "$ycur+20"] } \
	        { [expr "$xcur-50"] [expr "$ycur-30"] } \
	        { [expr "$xcur+00"] [expr "$ycur-50"] } \
	        { [expr "$xcur+50"] [expr "$ycur-30"] } \
	        { [expr "$xcur+50"] [expr "$ycur+20"] } \
	        { [expr "$xcur+00"] [expr "$ycur+00"] } }"

    # Unclosed polygon.
    set poly "{ { [expr "$xcur+00"] [expr "$ycur+00"] } \
	        { [expr "$xcur-50"] [expr "$ycur+20"] } \
	        { [expr "$xcur-50"] [expr "$ycur-30"] } \
	        { [expr "$xcur+00"] [expr "$ycur-50"] } \
	        { [expr "$xcur+50"] [expr "$ycur-30"] } \
	        { [expr "$xcur+50"] [expr "$ycur+20"] } }"

    if { $mtype == "polygon" } {
        print "input vertices=" $poly
	
	# Note a setVertices resets the initial rotation angle to 0.0
        send objmarker setVertices $poly
        send objmarker setAttribute rotangle $posangle
        send objmarker setAttributes x $xcur y $ycur
        send objmarker getVertices tpoly
        print "output vertices=" $tpoly
        print [send objmarker getRegion]
    }

    send objmarker getAttributes x x y y width w height h type t rotangle r
    print "initial attributes " $x $y $w $h $t $r

    #send objmarker addCallback markerConstraint constraint 

    if { $mtype == "text" } {
	set text "This is a test string"
        send objmarker "set text \{$text\}; redraw noerase"
    }

    send objmarker set visible True
    print "AFter visible - " 
	print "getRegions= " [send objmarker getRegion]
        send objmarker getVertices tpoly
        print "getVertices= " $tpoly

    send objmarker getAttributes x x y y width w height h type t rotangle r
    print "visible attributes " $x $y $w $h $t $r
}

proc markerConstraint { marker event attributes } {
    set constraints [ ]

    #print $marker $event $attributes

    # Constrain X and Y to not move.
    foreach i $attributes {
        set old [lindex $i 1]
        set new [lindex $i 2]
        switch [lindex $i 0] {
	    x		{ if {[send $marker get type] == "rectangle "} {
				lappend constraints "x $old"
			  } else {
				lappend constraints "x $new"
			  }
			}
	    y		{ if {[send $marker get type] == "rectangle "} {
				lappend constraints "y $old"
			  } else {
				lappend constraints "y $new"
			  }
			}
	    width	{ lappend constraints "width $new"    }
	    height	{ lappend constraints "height $new"   }
	    rotangle	{ lappend constraints "rotangle $new" }
 	}
    }
    return $constraints
}