@@ -6,8 +6,11 @@ use std::borrow::Cow;
66use std:: ops:: FnOnce ;
77use std:: sync:: { Arc , RwLock } ;
88
9- use crate :: annotation:: PyAnnotations ;
9+ use crate :: annotation:: PyAnnotation ;
10+ use crate :: annotationdataset:: PyAnnotationDataSet ;
11+ use crate :: annotationstore:: MapStore ;
1012use crate :: error:: PyStamError ;
13+ use crate :: resources:: PyTextResource ;
1114use stam:: * ;
1215
1316#[ pyclass( dict, module = "stam" , name = "AnnotationSubStore" ) ]
@@ -79,6 +82,35 @@ impl PyAnnotationSubStore {
7982 fn __hash__ ( & self ) -> usize {
8083 self . handle . as_usize ( )
8184 }
85+
86+ fn associate ( & mut self , item : & PyAny ) -> PyResult < ( ) > {
87+ if item. is_instance_of :: < PyAnnotation > ( ) {
88+ let item: PyRef < PyAnnotation > = item. extract ( ) ?;
89+ let substore_handle = self . handle ;
90+ self . map_store_mut ( |store| store. associate_substore ( item. handle , substore_handle) )
91+ } else if item. is_instance_of :: < PyTextResource > ( ) {
92+ let item: PyRef < PyTextResource > = item. extract ( ) ?;
93+ let substore_handle = self . handle ;
94+ self . map_store_mut ( |store| store. associate_substore ( item. handle , substore_handle) )
95+ } else if item. is_instance_of :: < PyAnnotationDataSet > ( ) {
96+ let item: PyRef < PyAnnotationDataSet > = item. extract ( ) ?;
97+ let substore_handle = self . handle ;
98+ self . map_store_mut ( |store| store. associate_substore ( item. handle , substore_handle) )
99+ } else {
100+ Err ( PyValueError :: new_err (
101+ "Invalid type for item, expected Annotation, TextResource or AnnotationDataSet" ,
102+ ) )
103+ }
104+ }
105+ }
106+
107+ impl MapStore for PyAnnotationSubStore {
108+ fn get_store ( & self ) -> & Arc < RwLock < AnnotationStore > > {
109+ & self . store
110+ }
111+ fn get_store_mut ( & mut self ) -> & mut Arc < RwLock < AnnotationStore > > {
112+ & mut self . store
113+ }
82114}
83115
84116impl PyAnnotationSubStore {
0 commit comments