3619 def _set_in_units(self, desired_units, no_act=False):
3620 """Set the units of the application of this operator.
3621
3622 This mixin is used for the <times> and <divide> operators.
3623 There are 2 possible strategies here. One is to pick one of the
3624 operands and convert it so that the overall units match those
3625 required. The other is to pick units from the set of those
3626 possible for this application, and convert the result to the
3627 desired units. We go with the latter option, picking the units
3628 that are least in the sense that they have the least multipicative
3629 factor, but where possible that factor is no less than that on the
3630 desired units.
3631 """
3632 app = self.xml_parent
3633 min_factor, best_factor = None, None
3634 least_units, best_units = None, None
3636 DEBUG(
'validator',
'>',self.localName,
':',desired_factor,
3637 desired_units.description())
3638 units_set = app.get_units().get_consistent_set(desired_units)
3639 for possible_units in units_set:
3641 if min_factor is None or f<min_factor:
3642 least_units, min_factor = possible_units, f
3643 if f >= desired_factor and (best_factor is None or f < best_factor):
3644 best_units, best_factor = possible_units, f
3645 if best_units is None:
3646
3647 units = least_units
3648 else:
3649 units = best_units
3650 DEBUG(
'validator',
'\t<-',
3652 units.description())
3653
3654 app._add_units_conversion(app, units, desired_units, no_act)
3655
3656 for src_units_set, src_units in app.get_units()._get_sources(units):
3657 expr = src_units_set.get_expression()
3658 DEBUG(
'validator',
'#',self.localName,
':',
3659 src_units.description(),expr.localName)
3660 self._set_element_in_units(expr, src_units, no_act)
3661
3662 if not no_act:
3663 app._cml_units = units
3664 return
def get_multiplicative_factor(self)
def DEBUG(facility, *args)