Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
ee53bd27
Commit
ee53bd27
authored
6 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
wip better typing for state selection
parent
223e9081
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-plugin/state/animation/built-in.ts
+3
-3
3 additions, 3 deletions
src/mol-plugin/state/animation/built-in.ts
src/mol-state/state.ts
+1
-1
1 addition, 1 deletion
src/mol-state/state.ts
src/mol-state/state/selection.ts
+31
-31
31 additions, 31 deletions
src/mol-state/state/selection.ts
with
35 additions
and
35 deletions
src/mol-plugin/state/animation/built-in.ts
+
3
−
3
View file @
ee53bd27
...
...
@@ -165,10 +165,10 @@ export const AnimateUnitsExplode = PluginStateAnimation.create({
const
update
=
state
.
build
();
let
changed
=
false
;
for
(
const
r
of
reprs
)
{
const
unwind
s
=
state
.
select
(
StateSelection
.
Generators
.
byValue
(
r
)
const
explode
s
=
state
.
select
(
StateSelection
.
Generators
.
byValue
(
r
)
.
children
()
.
filter
(
c
=>
c
.
transform
.
transformer
===
StateTransforms
.
Representation
.
Unwind
Structure
Assembly
Representation3D
));
if
(
unwind
s
.
length
>
0
)
continue
;
.
filter
(
c
=>
c
.
transform
.
transformer
===
StateTransforms
.
Representation
.
Explode
StructureRepresentation3D
));
if
(
explode
s
.
length
>
0
)
continue
;
changed
=
true
;
update
.
to
(
r
.
transform
.
ref
)
...
...
This diff is collapsed.
Click to expand it.
src/mol-state/state.ts
+
1
−
1
View file @
ee53bd27
...
...
@@ -95,7 +95,7 @@ class State {
* @example state.query(StateSelection.Generators.byRef('test').ancestorOfType([type]))
* @example state.query('test')
*/
select
(
selector
:
StateSelection
.
Selector
)
{
select
<
C
extends
StateObjectCell
>
(
selector
:
StateSelection
.
Selector
<
C
>
)
{
return
StateSelection
.
select
(
selector
,
this
)
}
...
...
This diff is collapsed.
Click to expand it.
src/mol-state/state/selection.ts
+
31
−
31
View file @
ee53bd27
...
...
@@ -10,22 +10,22 @@ import { StateTree } from '../tree';
import
{
StateTransform
}
from
'
../transform
'
;
namespace
StateSelection
{
export
type
Selector
=
Query
|
Builder
|
string
|
StateObjectCell
;
export
type
CellSeq
=
StateObjectCell
[]
export
type
Query
=
(
state
:
State
)
=>
CellSeq
;
export
type
Selector
<
C
extends
StateObjectCell
=
StateObjectCell
>
=
Query
<
C
>
|
Builder
<
C
>
|
string
|
C
;
export
type
CellSeq
<
C
extends
StateObjectCell
=
StateObjectCell
>
=
C
[]
export
type
Query
<
C
extends
StateObjectCell
=
StateObjectCell
>
=
(
state
:
State
)
=>
CellSeq
<
C
>
;
export
function
select
(
s
:
Selector
,
state
:
State
)
{
export
function
select
<
C
extends
StateObjectCell
>
(
s
:
Selector
<
C
>
,
state
:
State
)
{
return
compile
(
s
)(
state
);
}
export
function
compile
(
s
:
Selector
):
Query
{
export
function
compile
<
C
extends
StateObjectCell
>
(
s
:
Selector
<
C
>
):
Query
<
C
>
{
const
selector
=
s
?
s
:
Generators
.
root
;
let
query
:
Query
;
if
(
isBuilder
(
selector
))
query
=
(
selector
as
any
).
compile
();
else
if
(
isObj
(
selector
))
query
=
(
Generators
.
byValue
(
selector
)
as
any
).
compile
();
else
if
(
isQuery
(
selector
))
query
=
selector
;
else
query
=
(
Generators
.
byRef
(
selector
as
string
)
as
any
).
compile
();
return
query
;
return
query
as
Query
<
C
>
;
}
function
isObj
(
arg
:
any
):
arg
is
StateObjectCell
{
...
...
@@ -40,22 +40,22 @@ namespace StateSelection {
return
typeof
arg
===
'
function
'
;
}
export
interface
Builder
{
flatMap
(
f
:
(
n
:
StateObjectCell
)
=>
StateObjectCell
[]):
Builder
;
map
Entity
(
f
:
(
n
:
StateObjectCell
)
=>
StateObjectCell
):
Builder
;
unique
():
Builder
;
export
interface
Builder
<
C
extends
StateObjectCell
=
StateObjectCell
>
{
flatMap
<
D
extends
StateObjectCell
>
(
f
:
(
n
:
C
)
=>
D
[]):
Builder
<
D
>
;
map
Object
<
D
extends
StateObjectCell
>
(
f
:
(
n
:
C
)
=>
D
):
Builder
<
D
>
;
unique
():
Builder
<
C
>
;
parent
():
Builder
;
first
():
Builder
;
filter
(
p
:
(
n
:
StateObjectCell
)
=>
boolean
):
Builder
;
withStatus
(
s
:
StateObjectCell
.
Status
):
Builder
;
parent
():
Builder
<
C
>
;
first
():
Builder
<
C
>
;
filter
(
p
:
(
n
:
C
)
=>
boolean
):
Builder
<
C
>
;
withStatus
(
s
:
StateObjectCell
.
Status
):
Builder
<
C
>
;
subtree
():
Builder
;
children
():
Builder
;
ofType
(
t
:
StateObject
.
Ctor
):
Builder
;
ancestorOfType
(
t
:
StateObject
.
Ctor
[]):
Builder
;
ofType
<
T
extends
StateObject
.
Ctor
>
(
t
:
T
):
Builder
<
StateObjectCell
<
StateObject
.
From
<
T
>>>
;
ancestorOfType
<
T
extends
StateObject
.
Ctor
>
(
t
:
T
[]):
Builder
<
StateObjectCell
<
StateObject
.
From
<
T
>>>
;
rootOfType
(
t
:
StateObject
.
Ctor
[]):
Builder
;
select
(
state
:
State
):
CellSeq
select
(
state
:
State
):
CellSeq
<
C
>
}
const
BuilderPrototype
:
any
=
{
...
...
@@ -68,38 +68,38 @@ namespace StateSelection {
BuilderPrototype
[
name
]
=
function
(
this
:
any
,
...
args
:
any
[])
{
return
f
.
call
(
void
0
,
this
,
...
args
)
};
}
function
build
(
compile
:
()
=>
Query
):
Builder
{
function
build
<
C
extends
StateObjectCell
>
(
compile
:
()
=>
Query
<
C
>
):
Builder
<
C
>
{
return
Object
.
create
(
BuilderPrototype
,
{
compile
:
{
writable
:
false
,
configurable
:
false
,
value
:
compile
}
});
}
export
namespace
Generators
{
export
const
root
=
build
(()
=>
(
state
:
State
)
=>
[
state
.
cells
.
get
(
state
.
tree
.
root
.
ref
)
!
]);
export
function
byRef
(...
refs
:
StateTransform
.
Ref
[])
{
export
function
byRef
<
T
extends
StateObject
.
Ctor
>
(...
refs
:
StateTransform
.
Ref
[])
{
return
build
(()
=>
(
state
:
State
)
=>
{
const
ret
:
StateObjectCell
[]
=
[];
const
ret
:
StateObjectCell
<
StateObject
.
From
<
T
>>
[]
=
[];
for
(
const
ref
of
refs
)
{
const
n
=
state
.
cells
.
get
(
ref
);
if
(
!
n
)
continue
;
ret
.
push
(
n
);
ret
.
push
(
n
as
any
);
}
return
ret
;
});
}
export
function
byValue
(...
objects
:
StateObjectCell
[])
{
return
build
(()
=>
(
state
:
State
)
=>
objects
);
}
export
function
byValue
<
T
extends
StateObjectCell
>
(...
objects
:
T
[])
{
return
build
(()
=>
(
state
:
State
)
=>
objects
);
}
export
function
rootsOfType
(
type
:
StateObject
.
Ctor
)
{
export
function
rootsOfType
<
T
extends
StateObject
.
Ctor
>
(
type
:
T
)
{
return
build
(()
=>
state
=>
{
const
ctx
=
{
roots
:
[]
as
StateObjectCell
[],
cells
:
state
.
cells
,
type
:
type
.
type
};
const
ctx
=
{
roots
:
[]
as
StateObjectCell
<
StateObject
.
From
<
T
>>
[],
cells
:
state
.
cells
,
type
:
type
.
type
};
StateTree
.
doPreOrder
(
state
.
tree
,
state
.
tree
.
root
,
ctx
,
_findRootsOfType
);
return
ctx
.
roots
;
});
}
export
function
ofType
(
type
:
StateObject
.
Ctor
)
{
export
function
ofType
<
T
extends
StateObject
.
Ctor
>
(
type
:
T
)
{
return
build
(()
=>
state
=>
{
const
ctx
=
{
ret
:
[]
as
StateObjectCell
[],
cells
:
state
.
cells
,
type
:
type
.
type
};
const
ctx
=
{
ret
:
[]
as
StateObjectCell
<
StateObject
.
From
<
T
>>
[],
cells
:
state
.
cells
,
type
:
type
.
type
};
StateTree
.
doPreOrder
(
state
.
tree
,
state
.
tree
.
root
,
ctx
,
_findOfType
);
return
ctx
.
ret
;
});
...
...
@@ -137,8 +137,8 @@ namespace StateSelection {
});
}
registerModifier
(
'
map
Entity
'
,
mapEntity
);
export
function
map
Entity
(
b
:
Selector
,
f
:
(
n
:
StateObjectCell
,
state
:
State
)
=>
StateObjectCell
|
undefined
)
{
registerModifier
(
'
map
Object
'
,
mapObject
);
export
function
map
Object
(
b
:
Selector
,
f
:
(
n
:
StateObjectCell
,
state
:
State
)
=>
StateObjectCell
|
undefined
)
{
const
q
=
compile
(
b
);
return
build
(()
=>
(
state
:
State
)
=>
{
const
ret
:
StateObjectCell
[]
=
[];
...
...
@@ -204,13 +204,13 @@ namespace StateSelection {
export
function
ofType
(
b
:
Selector
,
t
:
StateObject
.
Ctor
)
{
return
filter
(
b
,
n
=>
n
.
obj
?
n
.
obj
.
type
===
t
.
type
:
false
);
}
registerModifier
(
'
ancestorOfType
'
,
ancestorOfType
);
export
function
ancestorOfType
(
b
:
Selector
,
types
:
StateObject
.
Ctor
[])
{
return
unique
(
map
Entity
(
b
,
(
n
,
s
)
=>
findAncestorOfType
(
s
.
tree
,
s
.
cells
,
n
.
transform
.
ref
,
types
)));
}
export
function
ancestorOfType
(
b
:
Selector
,
types
:
StateObject
.
Ctor
[])
{
return
unique
(
map
Object
(
b
,
(
n
,
s
)
=>
findAncestorOfType
(
s
.
tree
,
s
.
cells
,
n
.
transform
.
ref
,
types
)));
}
registerModifier
(
'
rootOfType
'
,
rootOfType
);
export
function
rootOfType
(
b
:
Selector
,
types
:
StateObject
.
Ctor
[])
{
return
unique
(
map
Entity
(
b
,
(
n
,
s
)
=>
findRootOfType
(
s
.
tree
,
s
.
cells
,
n
.
transform
.
ref
,
types
)));
}
export
function
rootOfType
(
b
:
Selector
,
types
:
StateObject
.
Ctor
[])
{
return
unique
(
map
Object
(
b
,
(
n
,
s
)
=>
findRootOfType
(
s
.
tree
,
s
.
cells
,
n
.
transform
.
ref
,
types
)));
}
registerModifier
(
'
parent
'
,
parent
);
export
function
parent
(
b
:
Selector
)
{
return
unique
(
map
Entity
(
b
,
(
n
,
s
)
=>
s
.
cells
.
get
(
s
.
tree
.
transforms
.
get
(
n
.
transform
.
ref
)
!
.
parent
)));
}
export
function
parent
(
b
:
Selector
)
{
return
unique
(
map
Object
(
b
,
(
n
,
s
)
=>
s
.
cells
.
get
(
s
.
tree
.
transforms
.
get
(
n
.
transform
.
ref
)
!
.
parent
)));
}
export
function
findAncestorOfType
<
T
extends
StateObject
.
Ctor
>
(
tree
:
StateTree
,
cells
:
State
.
Cells
,
root
:
StateTransform
.
Ref
,
types
:
T
[]):
StateObjectCell
<
StateObject
.
From
<
T
>>
|
undefined
{
let
current
=
tree
.
transforms
.
get
(
root
)
!
,
len
=
types
.
length
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment