55from ansys .dpf .gate .generated import collection_abstract_api
66from ansys .dpf .gate import object_handler , data_processing_grpcapi , grpc_stream_helpers , errors
77
8- #-------------------------------------------------------------------------------
8+
9+ # -------------------------------------------------------------------------------
910# Collection
10- #-------------------------------------------------------------------------------
11+ # -------------------------------------------------------------------------------
1112
1213def _get_stub (server ):
1314 return server .get_stub (CollectionGRPCAPI .STUBNAME )
@@ -29,7 +30,8 @@ def init_collection_environment(object):
2930 server .create_stub_if_necessary (
3031 CollectionGRPCAPI .STUBNAME , collection_pb2_grpc .CollectionServiceStub )
3132
32- object ._deleter_func = (_get_stub (server ).Delete , lambda obj : obj ._internal_obj if isinstance (obj ,collection_pb2 .Collection ) else None )
33+ object ._deleter_func = (
34+ _get_stub (server ).Delete , lambda obj : obj ._internal_obj if isinstance (obj , collection_pb2 .Collection ) else None )
3335
3436 @staticmethod
3537 def collection_of_scoping_new_on_client (client ):
@@ -135,7 +137,7 @@ def collection_get_obj_by_index_for_label_space(collection, space, index):
135137
136138 @staticmethod
137139 def collection_get_obj_by_index (collection , index ):
138- return data_processing_grpcapi .DataProcessingGRPCAPI .data_processing_duplicate_object_reference (
140+ return data_processing_grpcapi .DataProcessingGRPCAPI .data_processing_duplicate_object_reference (
139141 CollectionGRPCAPI ._collection_get_entries (collection , index )[0 ].entry
140142 )
141143
@@ -145,7 +147,8 @@ def collection_get_obj_label_space_by_index(collection, index):
145147
146148 @staticmethod
147149 def _collection_get_entries (collection , label_space_or_index ):
148- from ansys .grpc .dpf import collection_pb2 , scoping_pb2 , field_pb2 , meshed_region_pb2 , base_pb2 , dpf_any_message_pb2
150+ from ansys .grpc .dpf import collection_pb2 , scoping_pb2 , field_pb2 , meshed_region_pb2 , base_pb2 , \
151+ dpf_any_message_pb2
149152 request = collection_pb2 .EntryRequest ()
150153 request .collection .CopyFrom (collection ._internal_obj )
151154
@@ -154,7 +157,7 @@ def _collection_get_entries(collection, label_space_or_index):
154157 else :
155158 request .label_space .CopyFrom (label_space_or_index ._internal_obj )
156159
157- out = _get_stub (collection ._server ).GetEntries (request )
160+ out = _get_stub (collection ._server ).GetEntries (request )
158161 list_out = []
159162 for obj in out .entries :
160163 label_space = {}
@@ -163,15 +166,19 @@ def _collection_get_entries(collection, label_space_or_index):
163166 label_space [key ] = obj .label_space .label_space [key ]
164167 if obj .HasField ("dpf_type" ):
165168 if collection ._internal_obj .type == base_pb2 .Type .Value ("SCOPING" ):
166- entry = object_handler .ObjHandler (data_processing_grpcapi .DataProcessingGRPCAPI , scoping_pb2 .Scoping ())
169+ entry = object_handler .ObjHandler (data_processing_grpcapi .DataProcessingGRPCAPI ,
170+ scoping_pb2 .Scoping ())
167171 elif collection ._internal_obj .type == base_pb2 .Type .Value ("FIELD" ):
168172 entry = object_handler .ObjHandler (data_processing_grpcapi .DataProcessingGRPCAPI , field_pb2 .Field ())
169173 elif collection ._internal_obj .type == base_pb2 .Type .Value ("MESHED_REGION" ):
170- entry = object_handler .ObjHandler (data_processing_grpcapi .DataProcessingGRPCAPI , meshed_region_pb2 .MeshedRegion ())
174+ entry = object_handler .ObjHandler (data_processing_grpcapi .DataProcessingGRPCAPI ,
175+ meshed_region_pb2 .MeshedRegion ())
171176 elif collection ._internal_obj .type == base_pb2 .Type .Value ("ANY" ):
172- entry = object_handler .ObjHandler (data_processing_grpcapi .DataProcessingGRPCAPI , dpf_any_message_pb2 .DpfAny ())
177+ entry = object_handler .ObjHandler (data_processing_grpcapi .DataProcessingGRPCAPI ,
178+ dpf_any_message_pb2 .DpfAny ())
173179 else :
174- raise NotImplementedError (f"collection { base_pb2 .Type .Name (collection ._internal_obj .type )} type is not implemented" )
180+ raise NotImplementedError (
181+ f"collection { base_pb2 .Type .Name (collection ._internal_obj .type )} type is not implemented" )
175182 obj .dpf_type .Unpack (entry ._internal_obj )
176183 entry ._server = collection ._server
177184 list_out .append (_CollectionEntry (label_space , entry ))
@@ -193,7 +200,7 @@ def collection_add_entry(collection, labelspace, obj):
193200 request = collection_pb2 .UpdateRequest ()
194201 request .collection .CopyFrom (collection ._internal_obj )
195202 if hasattr (obj , "_message" ):
196- #TO DO: remove
203+ # TO DO: remove
197204 request .entry .dpf_type .Pack (obj ._message )
198205 else :
199206 request .entry .dpf_type .Pack (obj ._internal_obj )
@@ -206,7 +213,8 @@ def _collection_set_data_as_integral_type(collection, data, size):
206213 metadata = [(u"size_bytes" , f"{ size * data .itemsize } " )]
207214 request = collection_pb2 .UpdateAllDataRequest ()
208215 request .collection .CopyFrom (collection ._internal_obj )
209- _get_stub (collection ._server ).UpdateAllData (grpc_stream_helpers ._data_chunk_yielder (request , data ), metadata = metadata )
216+ _get_stub (collection ._server ).UpdateAllData (grpc_stream_helpers ._data_chunk_yielder (request , data ),
217+ metadata = metadata )
210218
211219 @staticmethod
212220 def collection_set_data_as_int (collection , data , size ):
@@ -219,9 +227,15 @@ def collection_set_data_as_double(collection, data, size):
219227 @staticmethod
220228 def collection_set_support (collection , label , support ):
221229 from ansys .grpc .dpf import collection_pb2
230+ from ansys .grpc .dpf import time_freq_support_pb2
231+ from ansys .grpc .dpf import support_pb2
222232 request = collection_pb2 .UpdateSupportRequest ()
223233 request .collection .CopyFrom (collection ._internal_obj )
224- request .time_freq_support .CopyFrom (support ._internal_obj )
234+ if isinstance (support ._internal_obj , time_freq_support_pb2 .TimeFreqSupport ):
235+ request .time_freq_support .CopyFrom (support ._internal_obj )
236+ else :
237+ supp = support_pb2 .Support (id = support ._internal_obj .id )
238+ request .support .CopyFrom (supp )
225239 request .label = label
226240 _get_stub (collection ._server ).UpdateSupport (request )
227241
@@ -230,7 +244,11 @@ def collection_get_support(collection, label):
230244 from ansys .grpc .dpf import collection_pb2 , base_pb2
231245 request = collection_pb2 .SupportRequest ()
232246 request .collection .CopyFrom (collection ._internal_obj )
233- request .type = base_pb2 .Type .Value ("TIME_FREQ_SUPPORT" )
247+ if collection ._server .meet_version ("5.0" ):
248+ request .label = label
249+ request .type = base_pb2 .Type .Value ("SUPPORT" )
250+ else :
251+ request .type = base_pb2 .Type .Value ("TIME_FREQ_SUPPORT" )
234252 message = _get_stub (collection ._server ).GetSupport (request )
235253 return message
236254
@@ -284,5 +302,3 @@ def collection_add_string_entry(collection, obj):
284302class _CollectionEntry (NamedTuple ):
285303 label_space : dict
286304 entry : object
287-
288-
0 commit comments