@@ -17,6 +17,10 @@ import Replay from "@material-ui/icons/Replay";
17
17
import Spellcheck from "@material-ui/icons/Spellcheck" ;
18
18
import SwitchCamera from "@material-ui/icons/SwitchCamera" ;
19
19
import ThreeDRotation from "@material-ui/icons/ThreeDRotation" ;
20
+ import SquareFootIcon from "@material-ui/icons/SquareFoot" ;
21
+ import HeightIcon from "@material-ui/icons/Height" ;
22
+ import LooksIcon from "@material-ui/icons/Looks" ;
23
+ import DeleteIcon from "@material-ui/icons/Delete" ;
20
24
import setClass from "classnames" ;
21
25
import $ from "jquery" ;
22
26
import PropTypes from "prop-types" ;
@@ -52,6 +56,14 @@ export class ThreeDEditor extends React.Component {
52
56
// on/off switch for the component
53
57
isInteractive : false ,
54
58
isThreejsEditorModalShown : false ,
59
+ // isDistanceAndAnglesShown: false,
60
+ measuresSettings : {
61
+ isDistanceShown : false ,
62
+ isAnglesShown : false ,
63
+ measureLabelsShown : false ,
64
+ distance : 0 ,
65
+ angle : 0 ,
66
+ } ,
55
67
// TODO: remove the need for `viewerTriggerResize`
56
68
// whether to trigger resize
57
69
viewerTriggerResize : false ,
@@ -88,6 +100,13 @@ export class ThreeDEditor extends React.Component {
88
100
this . onThreejsEditorModalHide = this . onThreejsEditorModalHide . bind ( this ) ;
89
101
this . handleChemicalConnectivityFactorChange =
90
102
this . handleChemicalConnectivityFactorChange . bind ( this ) ;
103
+ this . handleToggleDistanceShown = this . handleToggleDistanceShown . bind ( this ) ;
104
+ this . handleToggleAnglesShown = this . handleToggleAnglesShown . bind ( this ) ;
105
+ this . handleSetState = this . handleSetState . bind ( this ) ;
106
+ this . handleDeleteConnection = this . handleDeleteConnection . bind ( this ) ;
107
+ this . handleResetMeasures = this . handleResetMeasures . bind ( this ) ;
108
+ this . offMeasureParam = this . offMeasureParam . bind ( this ) ;
109
+ this . onMeasureParam = this . onMeasureParam . bind ( this ) ;
91
110
}
92
111
93
112
// TODO: update component to fully controlled or fully uncontrolled with a key?
@@ -121,7 +140,6 @@ export class ThreeDEditor extends React.Component {
121
140
} ) ;
122
141
} ;
123
142
124
- // eslint-disable-next-line class-methods-use-this
125
143
handleCellRepetitionsChange ( e ) {
126
144
this . handleSetSetting ( { [ e . target . id ] : parseFloat ( $ ( e . target ) . val ( ) ) } ) ;
127
145
}
@@ -153,6 +171,7 @@ export class ThreeDEditor extends React.Component {
153
171
154
172
handleToggleConventionalCell ( ) {
155
173
const { isConventionalCellShown, originalMaterial } = this . state ;
174
+ this . handleResetMeasures ( ) ;
156
175
this . setState ( {
157
176
isConventionalCellShown : ! isConventionalCellShown ,
158
177
originalMaterial : this . getPrimitiveOrConventionalMaterial (
@@ -185,6 +204,10 @@ export class ThreeDEditor extends React.Component {
185
204
186
205
// TODO: reset the colors for other buttons in the panel on call to the function below
187
206
handleResetViewer ( ) {
207
+ const { measuresSettings } = this . state ;
208
+ this . setState ( {
209
+ measuresSettings : { ...measuresSettings , isDistanceShown : false , isAnglesShown : false } ,
210
+ } ) ;
188
211
this . WaveComponent . initViewer ( ) ;
189
212
this . _resetStateWaveComponent ( ) ;
190
213
}
@@ -212,6 +235,67 @@ export class ThreeDEditor extends React.Component {
212
235
return this . WaveComponent && this . WaveComponent . wave [ name ] ;
213
236
}
214
237
238
+ handleSetState ( newState ) {
239
+ this . setState ( newState ) ;
240
+ }
241
+
242
+ handleDeleteConnection ( ) {
243
+ this . WaveComponent . wave . deleteConnection ( ) ;
244
+ }
245
+
246
+ handleToggleDistanceShown ( ) {
247
+ const { measuresSettings } = this . state ;
248
+ const { isDistanceShown, isAnglesShown } = measuresSettings ;
249
+ if ( isAnglesShown ) {
250
+ this . offMeasureParam ( "isAnglesShown" ) ;
251
+ }
252
+
253
+ if ( ! isDistanceShown ) {
254
+ this . onMeasureParam ( "isDistanceShown" , "isAnglesShown" ) ;
255
+ } else {
256
+ this . offMeasureParam ( "isDistanceShown" ) ;
257
+ }
258
+ }
259
+
260
+ handleResetMeasures ( ) {
261
+ this . WaveComponent . wave . resetMeasures ( ) ;
262
+ }
263
+
264
+ offMeasureParam ( param ) {
265
+ this . WaveComponent . wave . destroyListeners ( ) ;
266
+ this . handleResetMeasures ( ) ;
267
+ this . setState ( ( prevState ) => {
268
+ const { measuresSettings } = prevState ;
269
+ return { ...prevState , measuresSettings : { ...measuresSettings , [ param ] : false } } ;
270
+ } ) ;
271
+ }
272
+
273
+ onMeasureParam ( param , offParam ) {
274
+ this . setState ( ( prevState ) => {
275
+ const { measuresSettings } = prevState ;
276
+ return { ...prevState , measuresSettings : { ...measuresSettings , [ param ] : true } } ;
277
+ } ) ;
278
+ const { measuresSettings } = this . state ;
279
+ this . WaveComponent . wave . initListeners ( this . handleSetState , {
280
+ ...measuresSettings ,
281
+ [ param ] : true ,
282
+ [ offParam ] : false ,
283
+ } ) ;
284
+ }
285
+
286
+ handleToggleAnglesShown ( ) {
287
+ const { measuresSettings } = this . state ;
288
+ const { isAnglesShown, isDistanceShown } = measuresSettings ;
289
+ if ( isDistanceShown ) {
290
+ this . offMeasureParam ( "isDistanceShown" ) ;
291
+ }
292
+ if ( ! isAnglesShown ) {
293
+ this . onMeasureParam ( "isAnglesShown" , "isDistanceShown" ) ;
294
+ } else {
295
+ this . offMeasureParam ( "isAnglesShown" ) ;
296
+ }
297
+ }
298
+
215
299
/**
216
300
* Returns a cover div to cover the area and prevent user interaction with component
217
301
*/
@@ -398,6 +482,66 @@ export class ThreeDEditor extends React.Component {
398
482
) ;
399
483
}
400
484
485
+ getMeasuresToolbarItems ( ) {
486
+ const { measuresSettings } = this . state ;
487
+ const { isDistanceShown, isAnglesShown } = measuresSettings ;
488
+
489
+ return [
490
+ < RoundIconButton
491
+ key = "Distance"
492
+ tooltipPlacement = "top"
493
+ title = "Distance"
494
+ isToggled = { isDistanceShown }
495
+ onClick = { this . handleToggleDistanceShown }
496
+ >
497
+ < HeightIcon />
498
+ </ RoundIconButton > ,
499
+ < RoundIconButton
500
+ key = "Angles"
501
+ tooltipPlacement = "top"
502
+ title = "Angles"
503
+ isToggled = { isAnglesShown }
504
+ onClick = { this . handleToggleAnglesShown }
505
+ >
506
+ < LooksIcon />
507
+ </ RoundIconButton > ,
508
+ < RoundIconButton
509
+ key = "Reset Measures"
510
+ tooltipPlacement = "top"
511
+ title = "Reset Measures"
512
+ isToggleable = { false }
513
+ onClick = { this . handleResetMeasures }
514
+ >
515
+ < Replay />
516
+ </ RoundIconButton > ,
517
+
518
+ < RoundIconButton
519
+ key = "Delete"
520
+ tooltipPlacement = "top"
521
+ title = "Delete connection"
522
+ isToggleable = { false }
523
+ onClick = { this . handleDeleteConnection }
524
+ >
525
+ < DeleteIcon />
526
+ </ RoundIconButton > ,
527
+ ] ;
528
+ }
529
+
530
+ renderMeasuresToolbar ( className ) {
531
+ const { isInteractive } = this . state ;
532
+
533
+ return (
534
+ < IconToolbar
535
+ className = { className }
536
+ title = "Measurements"
537
+ iconComponent = { SquareFootIcon }
538
+ isHidden = { ! isInteractive }
539
+ >
540
+ { this . getMeasuresToolbarItems ( ) }
541
+ </ IconToolbar >
542
+ ) ;
543
+ }
544
+
401
545
getParametersToolbarItems ( ) {
402
546
const { viewerSettings } = this . state ;
403
547
return [
@@ -581,6 +725,7 @@ export class ThreeDEditor extends React.Component {
581
725
582
726
renderWaveOrThreejsEditorModal ( ) {
583
727
const { originalMaterial, isThreejsEditorModalShown } = this . state ;
728
+
584
729
const { editable } = this . props ;
585
730
if ( isThreejsEditorModalShown ) {
586
731
return (
@@ -600,6 +745,7 @@ export class ThreeDEditor extends React.Component {
600
745
{ this . renderViewToolbar ( this . classNamesForTopToolbar + " second-row" ) }
601
746
{ this . renderParametersToolbar ( this . classNamesForTopToolbar + " third-row" ) }
602
747
{ editable && this . render3DEditToggle ( this . classNamesForTopToolbar + " fourth-row" ) }
748
+ { this . renderMeasuresToolbar ( this . classNamesForTopToolbar + " fifth-row" ) }
603
749
{ this . renderExportToolbar ( this . classNamesForBottomToolbar ) }
604
750
</ div >
605
751
) ;
0 commit comments