@@ -14,28 +14,30 @@ import {primePlot, getDrawLayerById} from '../visualize/PlotViewUtil.js';
14
14
import CoordUtil from '../visualize/CoordUtil.js' ;
15
15
import CsysConverter from '../visualize/CsysConverter.js' ;
16
16
import { visRoot } from '../visualize/ImagePlotCntlr.js' ;
17
- import { isNil , get } from 'lodash' ;
17
+ import { InputFieldView } from '../ui/InputFieldView.jsx' ;
18
+ import { isNil , get , isEmpty } from 'lodash' ;
18
19
import numeral from 'numeral' ;
20
+ import validator from 'validator' ;
19
21
20
22
export const getFootprintToolUIComponent = ( drawLayer , pv ) => < FootprintToolUI drawLayer = { drawLayer } pv = { pv } /> ;
21
23
export const defaultFootprintTextLoc = TextLocation . REGION_SE ;
22
24
25
+ const precision = '0[.000000]' ;
26
+
23
27
class FootprintToolUI extends React . Component {
24
28
constructor ( props ) {
25
29
super ( props ) ;
26
30
27
- var fpText = get ( this . props . drawLayer , [ 'drawData' , 'data' , '0' , 'text' ] , '' ) ;
28
- var fpTextLoc = get ( this . props . drawLayer , [ 'drawData' , 'data' , '0' , 'textLoc' ] , defaultFootprintTextLoc ) ;
29
- var angle = get ( this . props . drawLayer , [ 'drawData' , 'data' , '0' , 'angle' ] , 0.0 ) ;
30
- var angleUnit = get ( this . props . drawLayer , [ 'drawData' , 'data' , '0' , angleUnit ] , ANGLE_UNIT . radian ) ;
31
- var angleDeg = convertAngle ( angleUnit . key , 'deg' , angle ) ;
32
- var fpInfo = get ( this . props . drawLayer , 'fpInfo' ) ;
31
+ var { angle = 0.0 , angleUnit = ANGLE_UNIT . radian ,
32
+ text = '' , textLoc = defaultFootprintTextLoc } = get ( this . props . drawLayer , [ 'drawData' , 'data' , '0' ] ) || { } ;
33
+
34
+ var angleDeg = `${ formatAngle ( convertAngle ( angleUnit . key , 'deg' , angle ) ) } ` ;
35
+ var { fpInfo, currentPt} = this . props . drawLayer ;
33
36
const plot = primePlot ( visRoot ( ) , this . props . pv . plotId ) ;
34
- var { currentPt} = this . props . drawLayer ;
35
37
36
38
this . csys = CsysConverter . make ( plot ) ;
37
- this . state = { fpText, fpTextLoc : fpTextLoc . key , angleDeg, fpInfo,
38
- currentPt : this . csys . getWorldCoords ( currentPt ) } ;
39
+ this . state = { fpText : text , fpTextLoc : textLoc . key , angleDeg, fpInfo,
40
+ currentPt : this . csys . getWorldCoords ( currentPt ) , isValidAngle : true } ;
39
41
this . changeFootprintText = this . changeFootprintText . bind ( this ) ;
40
42
this . changeFootprintTextLocation = this . changeFootprintTextLocation . bind ( this ) ;
41
43
this . changeFootprintAngle = this . changeFootprintAngle . bind ( this ) ;
@@ -63,11 +65,11 @@ class FootprintToolUI extends React.Component {
63
65
this . setState ( { currentPt} ) ;
64
66
}
65
67
66
- var { angle = 0.0 , angleUnit = ANGLE_UNIT . radian } = get ( dl , [ 'drawData' , 'data' , '0' ] ) ;
67
- var angleDeg = convertAngle ( angleUnit . key , 'radian ', angle ) ;
68
+ if ( ! get ( dl , [ 'drawData' , 'data' , '0' , 'angleFromUI' ] , false ) ) {
69
+ var { angle = 0.0 , angleUnit = ANGLE_UNIT . radian } = get ( dl , [ 'drawData ', 'data' , '0' ] ) || { } ;
68
70
69
- if ( angleDeg !== this . state . angleDeg ) {
70
- this . setState ( { angleDeg} ) ;
71
+ angle = convertAngle ( angleUnit . key , 'deg' , angle ) ;
72
+ this . setState ( { angleDeg : ` ${ formatAngle ( angle ) } ` , isValidAngle : true } ) ;
71
73
}
72
74
}
73
75
}
@@ -93,9 +95,16 @@ class FootprintToolUI extends React.Component {
93
95
94
96
changeFootprintAngle ( ev ) {
95
97
var angleDeg = get ( ev , 'target.value' ) ;
98
+ var isValidAngle = true ;
96
99
97
- this . setState ( { angleDeg} ) ;
98
- dispatchModifyCustomField ( this . props . drawLayer . drawLayerId , { angleDeg} , this . props . pv . plotId ) ;
100
+ if ( isEmpty ( angleDeg ) || ! validator . isFloat ( angleDeg ) ) {
101
+ if ( ! angleDeg ) angleDeg = '' ;
102
+ isValidAngle = false ;
103
+ }
104
+ this . setState ( { isValidAngle, angleDeg} ) ;
105
+ if ( isValidAngle ) {
106
+ dispatchModifyCustomField ( this . props . drawLayer . drawLayerId , { angleDeg} , this . props . pv . plotId ) ;
107
+ }
99
108
}
100
109
101
110
render ( ) {
@@ -106,17 +115,18 @@ class FootprintToolUI extends React.Component {
106
115
} ;
107
116
108
117
var textOnLink = `Add ${ get ( this . state . fpInfo , 'footprint' ) } ${ get ( this . state . fpInfo , 'instrument' ) } ` ;
118
+ var { isValidAngle, angleDeg, fpText, fpTextLoc} = this . state ;
109
119
110
120
return (
111
121
< div style = { { display :'flex' , justifyContent :'flex-start' , padding :'5px 0 9px 0' } } >
112
122
< div style = { tStyle } >
113
123
< div > Label:< input style = { { width : 60 } }
114
124
type = 'text'
115
- value = { this . state . fpText }
125
+ value = { fpText }
116
126
onChange = { this . changeFootprintText } />
117
127
</ div >
118
128
< div > Corners:
119
- < select value = { this . state . fpTextLoc } onChange = { this . changeFootprintTextLocation } >
129
+ < select value = { fpTextLoc } onChange = { this . changeFootprintTextLocation } >
120
130
< option value = { TextLocation . REGION_NE . key } > NE </ option >
121
131
< option value = { TextLocation . REGION_NW . key } > NW </ option >
122
132
< option value = { TextLocation . REGION_SE . key } > SE </ option >
@@ -125,11 +135,15 @@ class FootprintToolUI extends React.Component {
125
135
</ div >
126
136
</ div >
127
137
< div style = { tStyle } >
128
- < div > Angle:< input style = { { width : 60 } }
129
- type = 'text'
130
- value = { this . state . angleDeg }
131
- onChange = { this . changeFootprintAngle } />
132
- </ div >
138
+ < InputFieldView
139
+ valid = { isValidAngle }
140
+ onChange = { this . changeFootprintAngle }
141
+ value = { angleDeg }
142
+ message = { 'invalid angle value' }
143
+ label = { 'Angle:' }
144
+ labelWidth = { 30 }
145
+
146
+ />
133
147
< div title = { textOnLink } >
134
148
< a className = 'ff-href' style = { { textDecoration : 'underline' } }
135
149
onClick = { ( ) => addFootprintDrawLayer ( this . props . pv , this . state . fpInfo ) } > { textOnLink } </ a >
@@ -173,6 +187,11 @@ function convertWorldToString(pt) {
173
187
var str = '' ;
174
188
if ( ! pt ) return str ;
175
189
176
- var precision = '0.0000' ;
177
190
return `${ numeral ( pt . x ) . format ( precision ) } ${ numeral ( pt . y ) . format ( precision ) } ` ;
178
- }
191
+ }
192
+
193
+ function formatAngle ( angle ) {
194
+ var anglePre = parseFloat ( `${ numeral ( angle ) . format ( precision ) } ` ) ;
195
+
196
+ return `${ anglePre } ` ;
197
+ }
0 commit comments