-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathselection.ts
90 lines (72 loc) · 2.08 KB
/
selection.ts
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
/**
* @file Selection
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
import { Signal } from 'signals'
import { parseSele } from './selection-parser'
import {
SelectionTest, SelectionRule,
makeAtomTest, makeResidueTest, makeChainTest, makeModelTest
} from './selection-test'
import { SelectAllKeyword, SelectNoneKeyword } from './selection-constants'
type SelectionSignals = {
stringChanged: Signal
}
/**
* Selection
*/
class Selection {
signals: SelectionSignals
string: string
selection: SelectionRule
test: SelectionTest
residueTest: SelectionTest
chainTest: SelectionTest
modelTest: SelectionTest
atomOnlyTest: SelectionTest
residueOnlyTest: SelectionTest
chainOnlyTest: SelectionTest
modelOnlyTest: SelectionTest
/**
* Create Selection
* @param {String} string - selection string, see {@tutorial selection-language}
*/
constructor (string: string) {
this.signals = {
stringChanged: new Signal()
}
this.setString(string)
}
get type () { return 'selection' }
setString (string: string, silent?: boolean) {
if (string === undefined) string = this.string || ''
if (string === this.string) return
try {
this.selection = parseSele(string)
} catch (e) {
// Log.error( e.stack );
this.selection = { 'error': e.message }
}
const selection = this.selection
this.string = string
this.test = makeAtomTest(selection)
this.residueTest = makeResidueTest(selection)
this.chainTest = makeChainTest(selection)
this.modelTest = makeModelTest(selection)
this.atomOnlyTest = makeAtomTest(selection, true)
this.residueOnlyTest = makeResidueTest(selection, true)
this.chainOnlyTest = makeChainTest(selection, true)
this.modelOnlyTest = makeModelTest(selection, true)
if (!silent) {
this.signals.stringChanged.dispatch(this.string)
}
}
isAllSelection () {
return SelectAllKeyword.includes(this.string.toUpperCase())
}
isNoneSelection () {
return SelectNoneKeyword.includes(this.string.toUpperCase())
}
}
export default Selection