@@ -534,7 +534,7 @@ def copyAttribute(
534534 attributeNameTo : str ,
535535 onPoints : bool = False ,
536536 logger : Union [ Logger , None ] = None ,
537- ) -> bool :
537+ ) -> None :
538538 """Copy an attribute from a multiBlockDataSet to a similar one on the same piece.
539539
540540 Args:
@@ -547,66 +547,46 @@ def copyAttribute(
547547 logger (Union[Logger, None], optional): A logger to manage the output messages.
548548 Defaults to None, an internal logger is used.
549549
550- Returns:
551- bool: True if copy successfully ended, False otherwise.
550+ Raises:
551+ TypeError: Error with the type of the mesh from or to.
552+ ValueError: Error with the data of the meshes from and to.
553+ AttributeError: Error with the attribute attributeNameFrom or attributeNameTo.
552554 """
553555 # Check if an external logger is given.
554556 if logger is None :
555557 logger = getLogger ( "copyAttribute" , True )
556558
557559 # Check if the multiBlockDataSetFrom is inherited from vtkMultiBlockDataSet.
558560 if not isinstance ( multiBlockDataSetFrom , vtkMultiBlockDataSet ):
559- logger .error ( # type: ignore[unreachable]
560- "multiBlockDataSetFrom has to be inherited from vtkMultiBlockDataSet." )
561- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
562- return False
561+ raise TypeError ( "Input mesh from has to be inherited from vtkMultiBlockDataSet." )
563562
564563 # Check if the multiBlockDataSetTo is inherited from vtkMultiBlockDataSet.
565564 if not isinstance ( multiBlockDataSetTo , vtkMultiBlockDataSet ):
566- logger .error ( # type: ignore[unreachable]
567- "multiBlockDataSetTo has to be inherited from vtkMultiBlockDataSet." )
568- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
569- return False
565+ raise TypeError ( "Input mesh to has to be inherited from vtkMultiBlockDataSet." )
570566
571567 # Check if the attribute exist in the multiBlockDataSetFrom.
572568 if not isAttributeInObjectMultiBlockDataSet ( multiBlockDataSetFrom , attributeNameFrom , onPoints ):
573- logger .error ( f"The attribute { attributeNameFrom } is not in the multiBlockDataSetFrom." )
574- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
575- return False
569+ raise AttributeError ( f"The attribute { attributeNameFrom } is not present in the mesh from." )
576570
577571 # Check if the attribute already exist in the multiBlockDataSetTo.
578572 if isAttributeInObjectMultiBlockDataSet ( multiBlockDataSetTo , attributeNameTo , onPoints ):
579- logger .error ( f"The attribute { attributeNameTo } is already in the multiBlockDataSetTo." )
580- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
581- return False
573+ raise AttributeError ( f"The attribute { attributeNameTo } is already present in the mesh to." )
582574
583575 # Check if the two multiBlockDataSets are similar.
584576 elementaryBlockIndexesTo : list [ int ] = getBlockElementIndexesFlatten ( multiBlockDataSetTo )
585577 elementaryBlockIndexesFrom : list [ int ] = getBlockElementIndexesFlatten ( multiBlockDataSetFrom )
586578 if elementaryBlockIndexesTo != elementaryBlockIndexesFrom :
587- logger .error ( "multiBlockDataSetFrom and multiBlockDataSetTo do not have the same block indexes." )
588- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
589- return False
579+ raise ValueError ( "The two meshes do not have the same block indexes." )
590580
591581 # Parse blocks of the two mesh to copy the attribute.
592582 for idBlock in elementaryBlockIndexesTo :
593583 dataSetFrom : vtkDataSet = vtkDataSet .SafeDownCast ( multiBlockDataSetFrom .GetDataSet ( idBlock ) )
594- if dataSetFrom is None :
595- logger .error ( f"Block { idBlock } of multiBlockDataSetFrom is null." ) # type: ignore[unreachable]
596- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
597- return False
598-
599584 dataSetTo : vtkDataSet = vtkDataSet .SafeDownCast ( multiBlockDataSetTo .GetDataSet ( idBlock ) )
600- if dataSetTo is None :
601- logger .error ( f"Block { idBlock } of multiBlockDataSetTo is null." ) # type: ignore[unreachable]
602- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
603- return False
604585
605- if isAttributeInObjectDataSet ( dataSetFrom , attributeNameFrom , onPoints ) and \
606- not copyAttributeDataSet ( dataSetFrom , dataSetTo , attributeNameFrom , attributeNameTo , onPoints , logger ):
607- return False
586+ if isAttributeInObjectDataSet ( dataSetFrom , attributeNameFrom , onPoints ):
587+ copyAttributeDataSet ( dataSetFrom , dataSetTo , attributeNameFrom , attributeNameTo , onPoints , logger )
608588
609- return True
589+ return
610590
611591
612592def copyAttributeDataSet (
@@ -616,7 +596,7 @@ def copyAttributeDataSet(
616596 attributeNameTo : str ,
617597 onPoints : bool = False ,
618598 logger : Union [ Logger , Any ] = None ,
619- ) -> bool :
599+ ) -> None :
620600 """Copy an attribute from a dataSet to a similar one on the same piece.
621601
622602 Args:
@@ -629,43 +609,29 @@ def copyAttributeDataSet(
629609 logger (Union[Logger, None], optional): A logger to manage the output messages.
630610 Defaults to None, an internal logger is used.
631611
632- Returns:
633- bool: True if copy successfully ended, False otherwise.
612+ Raises:
613+ TypeError: Error with the type of the mesh from.
614+ AttributeError: Error with the attribute attributeNameFrom.
634615 """
635616 # Check if an external logger is given.
636617 if logger is None :
637618 logger = getLogger ( "copyAttributeDataSet" , True )
638619
639620 # Check if the dataSetFrom is inherited from vtkDataSet.
640621 if not isinstance ( dataSetFrom , vtkDataSet ):
641- logger .error ( "dataSetFrom has to be inherited from vtkDataSet." ) # type: ignore[unreachable]
642- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
643- return False
644-
645- # Check if the dataSetTo is inherited from vtkDataSet.
646- if not isinstance ( dataSetTo , vtkDataSet ):
647- logger .error ( "dataSetTo has to be inherited from vtkDataSet." ) # type: ignore[unreachable]
648- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
649- return False
622+ raise TypeError ( "Input mesh from has to be inherited from vtkDataSet." )
650623
651624 # Check if the attribute exist in the dataSetFrom.
652625 if not isAttributeInObjectDataSet ( dataSetFrom , attributeNameFrom , onPoints ):
653- logger .error ( f"The attribute { attributeNameFrom } is not in the dataSetFrom." )
654- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
655- return False
656-
657- # Check if the attribute already exist in the dataSetTo.
658- if isAttributeInObjectDataSet ( dataSetTo , attributeNameTo , onPoints ):
659- logger .error ( f"The attribute { attributeNameTo } is already in the dataSetTo." )
660- logger .error ( f"The attribute { attributeNameFrom } has not been copied." )
661- return False
626+ raise AttributeError ( f"The attribute { attributeNameFrom } is not in the input mesh from." )
662627
663628 npArray : npt .NDArray [ Any ] = getArrayInObject ( dataSetFrom , attributeNameFrom , onPoints )
664629 componentNames : tuple [ str , ...] = getComponentNamesDataSet ( dataSetFrom , attributeNameFrom , onPoints )
665630 vtkArrayType : int = getVtkArrayTypeInObject ( dataSetFrom , attributeNameFrom , onPoints )
666631
667632 createAttribute ( dataSetTo , npArray , attributeNameTo , componentNames , onPoints , vtkArrayType , logger )
668- return True
633+
634+ return
669635
670636
671637def transferAttributeToDataSetWithElementMap (
0 commit comments