@@ -3,11 +3,13 @@ import * as THREE from "three";
3
3
import { MEASUREMENT_MODES_ENUM } from "../../enums" ;
4
4
import { BaseTHREEGroupManager } from "../base" ;
5
5
import { BaseLabelsManager , LabelsManagerConstructor } from "../labels/base" ;
6
+ import { LinesManager } from "../lines/LinesManager" ;
6
7
import { RaycasterMixinWithListeners } from "../listeners/mixins" ;
7
8
import {
8
9
getObjectCoordinateAsArray ,
9
10
highlightAtom ,
10
11
isIntersectionObjectAnAtom ,
12
+ isObjectAnAtom ,
11
13
setAtomAsHovered ,
12
14
setColorForAtom ,
13
15
unsetAtomAsHovered ,
@@ -32,8 +34,12 @@ export class BaseMeasurementManager<T extends BaseLabelsManager> extends BaseMan
32
34
33
35
labelsManager : any ;
34
36
37
+ linesManager : LinesManager ;
38
+
35
39
updateState : any ;
36
40
41
+ currentSelectedLine : THREE . Line | null = null ;
42
+
37
43
constructor (
38
44
waveStructureGroup : THREE . Group ,
39
45
waveCamera : THREE . Camera ,
@@ -44,8 +50,9 @@ export class BaseMeasurementManager<T extends BaseLabelsManager> extends BaseMan
44
50
super ( waveStructureGroup , waveCamera , wave , groupName + "-measurement-group" ) ;
45
51
this . initRaycaster ( ) ;
46
52
this . selectedAtoms = [ ] ;
47
- this . intersectedAtom = null ;
53
+ this . intersectedObject = null ;
48
54
this . canvas = wave . renderer . domElement ;
55
+ this . linesManager = new LinesManager ( waveStructureGroup , waveCamera , wave , groupName ) ;
49
56
this . updateState = updateState ;
50
57
}
51
58
@@ -93,21 +100,24 @@ export class BaseMeasurementManager<T extends BaseLabelsManager> extends BaseMan
93
100
) ;
94
101
}
95
102
96
- setIntersectedAtom ( intersectItem : THREE . Object3D | null ) {
97
- if ( this . intersectedAtom !== intersectItem ) {
98
- this . intersectedAtom = intersectItem ;
103
+ setIntersectedAtom ( intersectItem : THREE . Object3D ) {
104
+ if ( this . intersectedObject !== intersectItem && isObjectAnAtom ( intersectItem ) ) {
105
+ this . intersectedObject = intersectItem ;
99
106
}
100
107
}
101
108
102
109
isIntersectedAtomSelected ( ) {
103
- if ( ! this . intersectedAtom ) return false ;
110
+ if ( ! this . intersectedObject ) return false ;
104
111
return this . selectedAtoms . some (
105
- ( atom ) => atom . userData . atomicIndex === this . intersectedAtom ?. userData . atomicIndex ,
112
+ ( atom ) => atom . userData . atomicIndex === this . intersectedObject ?. userData . atomicIndex ,
106
113
) ;
107
114
}
108
115
109
116
getIntersections ( ) {
110
- return this . raycaster . intersectObjects ( [ ...this . wave . getAtomGroups ( ) ] , true ) ;
117
+ return this . raycaster . intersectObjects (
118
+ [ ...this . wave . getAtomGroups ( ) , ...this . linesManager . getLines ( ) ] ,
119
+ true ,
120
+ ) ;
111
121
}
112
122
113
123
toggleAtomSelection ( atomObject : THREE . Object3D ) {
@@ -118,6 +128,17 @@ export class BaseMeasurementManager<T extends BaseLabelsManager> extends BaseMan
118
128
}
119
129
}
120
130
131
+ toggleLineSelection ( line : THREE . Line ) {
132
+ console . log ( "toggleLineSelection" , line ) ;
133
+ console . log ( "selected line" , this . currentSelectedLine ) ;
134
+
135
+ if ( line . userData . selected ) {
136
+ this . handleLineDeselection ( line ) ;
137
+ } else {
138
+ this . handleLineSelection ( line ) ;
139
+ }
140
+ }
141
+
121
142
refillSelectedAtoms ( ) : void {
122
143
const validAtoms : THREE . Object3D [ ] = [ ] ;
123
144
@@ -144,12 +165,17 @@ export class BaseMeasurementManager<T extends BaseLabelsManager> extends BaseMan
144
165
if ( ! this . isActive ) return ;
145
166
this . checkMouseCoordinates ( event , this . waveCamera ) ;
146
167
const intersects = this . getIntersections ( ) ;
168
+ console . log ( "INTERSECTS" , intersects ) ;
147
169
148
170
intersects . forEach ( ( object : THREE . Intersection < THREE . Object3D < THREE . Object3DEventMap > > ) => {
149
171
if ( isIntersectionObjectAnAtom ( object ) ) {
150
172
const atom = object . object ;
151
173
this . toggleAtomSelection ( atom ) ;
152
174
}
175
+ if ( object . object . type === "Line" ) {
176
+ console . log ( "LINE" , object . object ) ;
177
+ this . toggleLineSelection ( object . object ) ;
178
+ }
153
179
} ) ;
154
180
this . copyValuesToClipboard ( ) ;
155
181
}
@@ -159,17 +185,17 @@ export class BaseMeasurementManager<T extends BaseLabelsManager> extends BaseMan
159
185
this . checkMouseCoordinates ( event , this . waveCamera ) ;
160
186
const intersects = this . getIntersections ( ) ;
161
187
162
- intersects . forEach ( ( object : THREE . Intersection < THREE . Object3D < THREE . Object3DEventMap > > ) => {
188
+ intersects . forEach ( ( object : THREE . Intersection < THREE . Object3D | THREE . Line > ) => {
163
189
if ( isIntersectionObjectAnAtom ( object ) ) {
164
190
this . setIntersectedAtom ( object . object ) ;
165
191
setAtomAsHovered ( object . object ) ;
166
192
}
167
193
} ) ;
168
194
169
- if ( ! intersects . length && this . intersectedAtom ) {
195
+ if ( ! intersects . length && this . intersectedObject ) {
170
196
const isSelected = this . isIntersectedAtomSelected ( ) ;
171
- if ( this . intersectedAtom && ! isSelected ) {
172
- unsetAtomAsHovered ( this . intersectedAtom ) ;
197
+ if ( this . intersectedObject && ! isSelected && isObjectAnAtom ( this . intersectedObject ) ) {
198
+ unsetAtomAsHovered ( this . intersectedObject ) ;
173
199
}
174
200
this . setIntersectedAtom ( null ) ;
175
201
}
@@ -243,4 +269,38 @@ export class BaseMeasurementManager<T extends BaseLabelsManager> extends BaseMan
243
269
this . THREEGroup . clear ( ) ;
244
270
this . labelsManager . THREEGroup . clear ( ) ;
245
271
}
272
+
273
+ handleLineSelection ( line : THREE . Line ) : void {
274
+ this . linesManager . setLineAsSelected ( line ) ;
275
+ this . currentSelectedLine = line ;
276
+ }
277
+
278
+ handleLineDeselection ( line : THREE . Line ) : void {
279
+ this . linesManager . unsetLineAsSelected ( line ) ;
280
+ this . currentSelectedLine = null ;
281
+ }
282
+
283
+ removeAtomsFromSelectionByIndices ( atomicIndices : number [ ] ) : void {
284
+ this . selectedAtoms = this . selectedAtoms . filter (
285
+ ( atom ) => ! atomicIndices . includes ( atom . userData . atomicIndex ) ,
286
+ ) ;
287
+
288
+ atomicIndices . forEach ( ( index ) => {
289
+ const atom = this . getAtomObjectByAtomicIndex ( index ) ;
290
+ if ( atom ) {
291
+ atom . userData . selected = false ;
292
+ setColorForAtom ( atom ) ;
293
+ }
294
+ } ) ;
295
+ }
296
+
297
+ deleteSelectedLine ( ) : void {
298
+ if ( this . currentSelectedLine ) {
299
+ const atomicIndices = this . currentSelectedLine . userData . atomicIndices || [ ] ;
300
+ this . linesManager . removeLine ( this . currentSelectedLine ) ;
301
+ this . removeAtomsFromSelectionByIndices ( atomicIndices ) ;
302
+ this . currentSelectedLine = null ;
303
+ this . createMeasurements ( ) ;
304
+ }
305
+ }
246
306
}
0 commit comments