From e887b8a8436d69a33e04dafb618ead3e916ef401 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Sep 2023 15:57:20 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../Import/App/SCL/AggregationDataTypes.py | 335 +++--- src/Mod/Import/App/SCL/BaseType.py | 29 +- src/Mod/Import/App/SCL/Builtin.py | 955 +++++++++--------- .../Import/App/SCL/ConstructedDataTypes.py | 44 +- src/Mod/Import/App/SCL/Model.py | 20 +- src/Mod/Import/App/SCL/Part21.py | 82 +- src/Mod/Import/App/SCL/Rules.py | 8 +- src/Mod/Import/App/SCL/SCLBase.py | 17 +- src/Mod/Import/App/SCL/SimpleDataTypes.py | 85 +- src/Mod/Import/App/SCL/SimpleReader.py | 132 +-- src/Mod/Import/App/SCL/TypeChecker.py | 72 +- src/Mod/Import/App/SCL/Utils.py | 37 +- src/Mod/Import/App/SCL/__init__.py | 11 +- src/Mod/Import/App/SCL/essa_par.py | 82 +- src/Mod/Import/App/SCL/gasket1.p21 | 2 +- ..._mechanical_parts_and_assemblies_mim_lf.py | 48 +- src/Mod/Import/App/automotive_design.py | 96 +- src/Mod/Import/App/ifc2x3.py | 40 +- src/Mod/Import/App/ifc4.py | 46 +- src/Mod/Import/DxfPlate/blocks10.rub | 2 +- src/Mod/Import/DxfPlate/tables112.rub | 2 +- src/Mod/Import/Resources/Import.qrc | 4 +- 22 files changed, 1157 insertions(+), 992 deletions(-) diff --git a/src/Mod/Import/App/SCL/AggregationDataTypes.py b/src/Mod/Import/App/SCL/AggregationDataTypes.py index 9bb4709e83..b7b7dca020 100644 --- a/src/Mod/Import/App/SCL/AggregationDataTypes.py +++ b/src/Mod/Import/App/SCL/AggregationDataTypes.py @@ -23,7 +23,7 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF @@ -33,37 +33,47 @@ from SimpleDataTypes import * from TypeChecker import check_type import BaseType + class BaseAggregate(object): - """ A class that define common properties to ARRAY, LIST, SET and BAG. - """ - def __init__( self , bound1 , bound2 , base_type ): + """A class that define common properties to ARRAY, LIST, SET and BAG.""" + + def __init__(self, bound1, bound2, base_type): # check that bound1bound2: + if bound1 != None and bound2 != None: + if bound1 > bound2: raise AssertionError("bound1 shall be less than or equal to bound2") self._bound1 = bound1 self._bound2 = bound2 self._base_type = base_type def __getitem__(self, index): - if indexself._bound2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound2,index)) + if index < self._bound1: + raise IndexError( + "ARRAY index out of bound (lower bound is %i, passed %i)" % (self._bound1, index) + ) + elif self._bound2 != None and index > self._bound2: + raise IndexError( + "ARRAY index out of bound (upper bound is %i, passed %i)" % (self._bound2, index) + ) else: - return list.__getitem__(self,index) - - def __setitem__(self,index,value): - if indexself._bound2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound2,index)) - elif not isinstance(value,self._base_type): - raise TypeError("%s type expected, passed %s."%(self._base_type, type(value))) + return list.__getitem__(self, index) + + def __setitem__(self, index, value): + if index < self._bound1: + raise IndexError( + "ARRAY index out of bound (lower bound is %i, passed %i)" % (self._bound1, index) + ) + elif self._bound2 != None and index > self._bound2: + raise IndexError( + "ARRAY index out of bound (upper bound is %i, passed %i)" % (self._bound2, index) + ) + elif not isinstance(value, self._base_type): + raise TypeError("%s type expected, passed %s." % (self._base_type, type(value))) else: # first find the length of the list, and extend it if ever # the index is - list.__setitem__(self,index,value) + list.__setitem__(self, index, value) + class ARRAY(BaseType.Type, BaseType.Aggregate): """ @@ -76,12 +86,12 @@ class ARRAY(BaseType.Type, BaseType.Aggregate): that an array value cannot contain duplicate elements. It may also specify that an array value need not contain an element at every index position. - + Given that m is the lower bound and n is the upper bound, there are exactly n-m+1 elements in the array. These elements are indexed by subscripts from m to n, inclusive (see 12.6.1). NOTE 1 { The bounds may be positive, negative or zero, but may not be indeterminate (?) (see 14.2). - + Syntax: 165 array_type = ARRAY bound_spec OF [ OPTIONAL ] [ UNIQUE ] base_type . 176 bound_spec = '[' bound_1 ':' bound_2 ']' . @@ -119,16 +129,17 @@ class ARRAY(BaseType.Type, BaseType.Aggregate): a total of 40 elements of data type something in the attribute named sectors. Within each ARRAY[11:14], no duplicates may occur; however, the same something instance may occur in two different ARRAY[11:14] values within a single value for the attribute named sectors. - + Python definition: ================== @TODO """ - def __init__( self , bound_1 , bound_2 , base_type , UNIQUE = False, OPTIONAL=False, scope = None): + + def __init__(self, bound_1, bound_2, base_type, UNIQUE=False, OPTIONAL=False, scope=None): BaseType.Type.__init__(self, base_type, scope) - if not type(bound_1)==int: + if not type(bound_1) == int: raise TypeError("ARRAY lower bound must be an integer") - if not type(bound_2)==int: + if not type(bound_2) == int: raise TypeError("ARRAY upper bound must be an integer") if not (bound_1 <= bound_2): raise AssertionError("ARRAY lower bound must be less than or equal to upper bound") @@ -139,8 +150,8 @@ class ARRAY(BaseType.Type, BaseType.Aggregate): self._optional = OPTIONAL # preallocate list elements list_size = bound_2 - bound_1 + 1 - self._container = list_size*[None] - + self._container = list_size * [None] + def bound_1(self): return self._bound_1 @@ -149,10 +160,10 @@ class ARRAY(BaseType.Type, BaseType.Aggregate): def get_hiindex(self): return INTEGER(self._bound_2) - + def get_loindex(self): return INTEGER(self._bound_1) - + def get_hibound(self): return INTEGER(self._bound_2) @@ -160,42 +171,54 @@ class ARRAY(BaseType.Type, BaseType.Aggregate): return INTEGER(self._bound_1) def get_size(self): - return INTEGER(self._bound_2 - self._bound_1 +1) - + return INTEGER(self._bound_2 - self._bound_1 + 1) + def get_value_unique(self): - ''' Return True if all items are different in the container, UNKNOWN if some items are - indeterminate, or False otherwise''' + """Return True if all items are different in the container, UNKNOWN if some items are + indeterminate, or False otherwise""" if None in self._container: return Unknown - if self.get_size()-len(set(self._container))>0: #some items are repeated + if self.get_size() - len(set(self._container)) > 0: # some items are repeated return False else: return True - + def __getitem__(self, index): - if indexself._bound_2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + if index < self._bound_1: + raise IndexError( + "ARRAY index out of bound (lower bound is %i, passed %i)" % (self._bound_1, index) + ) + elif index > self._bound_2: + raise IndexError( + "ARRAY index out of bound (upper bound is %i, passed %i)" % (self._bound_2, index) + ) else: - value = self._container[index-self._bound_1] - if not self._optional and value==None: - raise AssertionError("Not OPTIONAL prevent the value with index %i from being None (default). Please set the value first."%index) + value = self._container[index - self._bound_1] + if not self._optional and value == None: + raise AssertionError( + "Not OPTIONAL prevent the value with index %i from being None (default). Please set the value first." + % index + ) return value - + def __setitem__(self, index, value): - if indexself._bound_2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + if index < self._bound_1: + raise IndexError( + "ARRAY index out of bound (lower bound is %i, passed %i)" % (self._bound_1, index) + ) + elif index > self._bound_2: + raise IndexError( + "ARRAY index out of bound (upper bound is %i, passed %i)" % (self._bound_2, index) + ) else: # first check the type of the value - check_type(value,self.get_type()) + check_type(value, self.get_type()) # then check if the value is already in the array if self._unique: if value in self._container: raise AssertionError("UNIQUE keyword prevents inserting this instance.") - self._container[index-self._bound_1] = value + self._container[index - self._bound_1] = value + class LIST(BaseType.Type, BaseType.Aggregate): """ @@ -206,7 +229,7 @@ class LIST(BaseType.Type, BaseType.Aggregate): elements that can be held in the collection defined by a list data type. A list data type definition may optionally specify that a list value cannot contain duplicate elements. - + Syntax: 237 list_type = LIST [ bound_spec ] OF [ UNIQUE ] base_type . 176 bound_spec = '[' bound_1 ':' bound_2 ']' . @@ -228,24 +251,25 @@ class LIST(BaseType.Type, BaseType.Aggregate): EXAMPLE 28 { This example defines a list of arrays. The list can contain zero to ten arrays. Each array of ten integers shall be different from all other arrays in a particular list. complex_list : LIST[0:10] OF UNIQUE ARRAY[1:10] OF INTEGER; - + Python definition: ================== @TODO """ - def __init__( self , bound_1 , bound_2 , base_type , UNIQUE = False, scope = None): + + def __init__(self, bound_1, bound_2, base_type, UNIQUE=False, scope=None): BaseType.Type.__init__(self, base_type, scope) - if not type(bound_1)==int: + if not type(bound_1) == int: raise TypeError("LIST lower bound must be an integer") # bound_2 can be set to None self._unbounded = False if bound_2 == None: self._unbounded = True - elif not type(bound_2)==int: + elif not type(bound_2) == int: raise TypeError("LIST upper bound must be an integer") - if not bound_1>=0: + if not bound_1 >= 0: raise AssertionError("LIST lower bound must be greater of equal to 0") - if (type(bound_2)==int and not (bound_1 <= bound_2)): + if type(bound_2) == int and not (bound_1 <= bound_2): raise AssertionError("ARRAY lower bound must be less than or equal to upper bound") # set up class attributes self._bound_1 = bound_1 @@ -254,7 +278,7 @@ class LIST(BaseType.Type, BaseType.Aggregate): # preallocate list elements if bounds are both integers if not self._unbounded: list_size = bound_2 - bound_1 + 1 - self._container = list_size*[None] + self._container = list_size * [None] # for unbounded list, this will come after else: self._container = [None] @@ -264,15 +288,15 @@ class LIST(BaseType.Type, BaseType.Aggregate): def bound_2(self): return self._bound_2 - + def get_size(self): number_of_indeterminates = self._container.count(None) hiindex = len(self._container) - number_of_indeterminates return INTEGER(hiindex) - + def get_hiindex(self): - ''' When V is a bag, list or set, the returned value is the actual number of elements in - the aggregate value.''' + """When V is a bag, list or set, the returned value is the actual number of elements in + the aggregate value.""" number_of_indeterminates = self._container.count(None) hiindex = len(self._container) - number_of_indeterminates return INTEGER(hiindex) @@ -282,24 +306,24 @@ class LIST(BaseType.Type, BaseType.Aggregate): def get_hibound(self): hibound = self._bound_2 - if type(hibound)==int: + if type(hibound) == int: return INTEGER(hibound) else: return hibound - + def get_lobound(self): lobound = self._bound_1 - if type(lobound)==int: + if type(lobound) == int: return INTEGER(lobound) else: return lobound def get_value_unique(self): - ''' Return True if all items are different in the container, UNKNOWN if some items are - indeterminate, or False otherwise''' + """Return True if all items are different in the container, UNKNOWN if some items are + indeterminate, or False otherwise""" if None in self._container: return Unknown - if self.get_size()-len(set(self._container))>0: #some items are repeated + if self.get_size() - len(set(self._container)) > 0: # some items are repeated return False else: return True @@ -307,66 +331,88 @@ class LIST(BaseType.Type, BaseType.Aggregate): def __getitem__(self, index): # case bounded if not self._unbounded: - if indexself._bound_2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + if index < self._bound_1: + raise IndexError( + "ARRAY index out of bound (lower bound is %i, passed %i)" + % (self._bound_1, index) + ) + elif index > self._bound_2: + raise IndexError( + "ARRAY index out of bound (upper bound is %i, passed %i)" + % (self._bound_2, index) + ) else: - value = self._container[index-self._bound_1] + value = self._container[index - self._bound_1] if value == None: - raise AssertionError("Value with index %i not defined. Please set the value first."%index) + raise AssertionError( + "Value with index %i not defined. Please set the value first." % index + ) return value - #case unbounded + # case unbounded else: - if index-self._bound_1>len(self._container): - raise AssertionError("Value with index %i not defined. Please set the value first."%index) + if index - self._bound_1 > len(self._container): + raise AssertionError( + "Value with index %i not defined. Please set the value first." % index + ) else: - value = self._container[index-self._bound_1] + value = self._container[index - self._bound_1] if value == None: - raise AssertionError("Value with index %i not defined. Please set the value first."%index) + raise AssertionError( + "Value with index %i not defined. Please set the value first." % index + ) return value - + def __setitem__(self, index, value): # case bounded if not self._unbounded: - if indexself._bound_2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + if index < self._bound_1: + raise IndexError( + "ARRAY index out of bound (lower bound is %i, passed %i)" + % (self._bound_1, index) + ) + elif index > self._bound_2: + raise IndexError( + "ARRAY index out of bound (upper bound is %i, passed %i)" + % (self._bound_2, index) + ) else: # first check the type of the value - check_type(value,self.get_type()) + check_type(value, self.get_type()) # then check if the value is already in the array if self._unique: if value in self._container: raise AssertionError("UNIQUE keyword prevent inserting this instance.") - self._container[index-self._bound_1] = value + self._container[index - self._bound_1] = value # case unbounded else: - if index=0: + if not bound_1 >= 0: raise AssertionError("LIST lower bound must be greater of equal to 0") - if (type(bound_2)==int and not (bound_1 <= bound_2)): + if type(bound_2) == int and not (bound_1 <= bound_2): raise AssertionError("ARRAY lower bound must be less than or equal to upper bound") # set up class attributes self._bound_1 = bound_1 @@ -432,29 +479,29 @@ class BAG(BaseType.Type, BaseType.Aggregate): def bound_2(self): return self._bound_2 - def add(self,value): - ''' + def add(self, value): + """ Adds a value to the bag - ''' + """ if self._unbounded: - check_type(value,self.get_type()) + check_type(value, self.get_type()) self._container.append(value) else: # first ensure that the bag is not full if len(self._container) == self._bound_2 - self._bound_1 + 1: - raise AssertionError('BAG is full. Impossible to add any more item') + raise AssertionError("BAG is full. Impossible to add any more item") else: - check_type(value,self.get_type()) + check_type(value, self.get_type()) self._container.append(value) def get_size(self): - ''' When V is a bag, list or set, the returned value is the actual number of elements in - the aggregate value.''' + """When V is a bag, list or set, the returned value is the actual number of elements in + the aggregate value.""" return INTEGER(len(self._container)) - + def get_hiindex(self): - ''' When V is a bag, list or set, the returned value is the actual number of elements in - the aggregate value.''' + """When V is a bag, list or set, the returned value is the actual number of elements in + the aggregate value.""" return INTEGER(len(self._container)) def get_loindex(self): @@ -462,23 +509,24 @@ class BAG(BaseType.Type, BaseType.Aggregate): def get_hibound(self): hibound = self._bound_2 - if type(hibound)==int: + if type(hibound) == int: return INTEGER(hibound) else: return hibound def get_lobound(self): lobound = self._bound_1 - if type(lobound)==int: + if type(lobound) == int: return INTEGER(lobound) else: return lobound + def get_value_unique(self): - ''' Return True if all items are different in the container, UNKNOWN if some items are - indeterminate, or False otherwise''' + """Return True if all items are different in the container, UNKNOWN if some items are + indeterminate, or False otherwise""" if None in self._container: return Unknown - if self.get_size()-len(set(self._container))>0: #some items are repeated + if self.get_size() - len(set(self._container)) > 0: # some items are repeated return False else: return True @@ -520,24 +568,25 @@ class SET(BaseType.Type, BaseType.Aggregate): as in: a_set_of_points : SET [0:15] OF point; The value of the attribute named a_set_of_points now may contain no more than 15 points. - + Python definition: ================== The difference with the BAG class is that the base container for SET is a set object. """ - def __init__( self , bound_1 , bound_2 , base_type , scope = None): + + def __init__(self, bound_1, bound_2, base_type, scope=None): BaseType.Type.__init__(self, base_type, scope) - if not type(bound_1)==int: + if not type(bound_1) == int: raise TypeError("LIST lower bound must be an integer") # bound_2 can be set to None self._unbounded = False if bound_2 == None: self._unbounded = True - elif not type(bound_2)==int: + elif not type(bound_2) == int: raise TypeError("LIST upper bound must be an integer") - if not bound_1>=0: + if not bound_1 >= 0: raise AssertionError("LIST lower bound must be greater of equal to 0") - if (type(bound_2)==int and not (bound_1 <= bound_2)): + if type(bound_2) == int and not (bound_1 <= bound_2): raise AssertionError("ARRAY lower bound must be less than or equal to upper bound") # set up class attributes self._bound_1 = bound_1 @@ -550,30 +599,30 @@ class SET(BaseType.Type, BaseType.Aggregate): def bound_2(self): return self._bound_2 - def add(self,value): - ''' + def add(self, value): + """ Adds a value to the bag - ''' + """ if self._unbounded: - check_type(value,self.get_type()) + check_type(value, self.get_type()) self._container.add(value) else: # first ensure that the bag is not full if len(self._container) == self._bound_2 - self._bound_1 + 1: if not value in self._container: - raise AssertionError('SET is full. Impossible to add any more item') + raise AssertionError("SET is full. Impossible to add any more item") else: - check_type(value,self.get_type()) + check_type(value, self.get_type()) self._container.add(value) - + def get_size(self): - ''' When V is a bag, list or set, the returned value is the actual number of elements in - the aggregate value.''' + """When V is a bag, list or set, the returned value is the actual number of elements in + the aggregate value.""" return INTEGER(len(self._container)) - + def get_hiindex(self): - ''' When V is a bag, list or set, the returned value is the actual number of elements in - the aggregate value.''' + """When V is a bag, list or set, the returned value is the actual number of elements in + the aggregate value.""" return INTEGER(len(self._container)) def get_loindex(self): @@ -581,21 +630,21 @@ class SET(BaseType.Type, BaseType.Aggregate): def get_hibound(self): hibound = self._bound_2 - if type(hibound)==int: + if type(hibound) == int: return INTEGER(hibound) else: return hibound def get_lobound(self): lobound = self._bound_1 - if type(lobound)==int: + if type(lobound) == int: return INTEGER(lobound) else: return lobound - + def get_value_unique(self): - ''' Return True if all items are different in the container, UNKNOWN if some items are - indeterminate, or False otherwise''' + """Return True if all items are different in the container, UNKNOWN if some items are + indeterminate, or False otherwise""" if None in self._container: return Unknown else: diff --git a/src/Mod/Import/App/SCL/BaseType.py b/src/Mod/Import/App/SCL/BaseType.py index 9a787d1de3..4afdaa3d79 100644 --- a/src/Mod/Import/App/SCL/BaseType.py +++ b/src/Mod/Import/App/SCL/BaseType.py @@ -23,47 +23,54 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + class Type(object): - ''' + """ A type can be defined from its name and scope Looking into the scope dict returns the python type class. This is the base class for aggregated data types or constructed data types - ''' + """ + def __init__(self, typedef, scope): self._scope = scope self._typedef = typedef - + def get_scope(self): return self._scope - + def get_type(self): if type(self._typedef) == str: if self._scope == None: - raise AssertionError('No scope defined for this type') + raise AssertionError("No scope defined for this type") elif self._typedef in vars(self._scope): return vars(self._scope)[self._typedef] else: - raise TypeError("Type '%s' is not defined in given scope"%self._typedef) + raise TypeError("Type '%s' is not defined in given scope" % self._typedef) else: return self._typedef + class Aggregate: - ''' + """ This is an abstract class. ARRAY, LIST, SET and BAG inherit from this class - ''' + """ + pass + if __name__ == "__main__": import sys + scp = sys.modules[__name__] + class line: pass - new_type = Type('lie',scp) + + new_type = Type("lie", scp) print(new_type.get_type()) - \ No newline at end of file diff --git a/src/Mod/Import/App/SCL/Builtin.py b/src/Mod/Import/App/SCL/Builtin.py index ed8d70011b..c9a71e6bbc 100644 --- a/src/Mod/Import/App/SCL/Builtin.py +++ b/src/Mod/Import/App/SCL/Builtin.py @@ -23,7 +23,7 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF @@ -41,625 +41,654 @@ SCL_float_epsilon = 1e-7 # EXPRESS definition: # =================== -#14.1 CONST_E is a REAL constant representing the mathematical value e, the base of the natural -#logarithm function (ln). +# 14.1 CONST_E is a REAL constant representing the mathematical value e, the base of the natural +# logarithm function (ln). CONST_E = REAL(math.pi) # EXPRESS definition: # =================== -#14.2 Indeterminate -#The indeterminate symbol (?) stands for an ambiguous value. It is compatible with all data -#types. -#NOTE - The most common use of indeterminate (?) is as the upper bound specification of a bag, -#list or set. This usage represents the notion that the size of the aggregate value defined by the -#aggregation data type is unbounded. +# 14.2 Indeterminate +# The indeterminate symbol (?) stands for an ambiguous value. It is compatible with all data +# types. +# NOTE - The most common use of indeterminate (?) is as the upper bound specification of a bag, +# list or set. This usage represents the notion that the size of the aggregate value defined by the +# aggregation data type is unbounded. # python note: indeterminate value is mapped to None in aggregate bounds # EXPRESS definition: # =================== -#14.3 False -#false is a logical constant representing the logical notion of falsehood. It is compatible with -#the boolean and logical data types. +# 14.3 False +# false is a logical constant representing the logical notion of falsehood. It is compatible with +# the boolean and logical data types. FALSE = False # EXPRESS definition: # =================== -#14.4 Pi -#PI is a REAL constant representing the mathematical value π, the ratio of a circle's circumference -#to its diameter. +# 14.4 Pi +# PI is a REAL constant representing the mathematical value π, the ratio of a circle's circumference +# to its diameter. PI = REAL(math.pi) # EXPRESS definition: # =================== -#14.5 Self -#SELF refers to the current entity instance or type value. self may appear within an entity -#declaration, a type declaration or an entity constructor. -#NOTE - SELF is not a constant, but behaves as one in every context in which it can appear. +# 14.5 Self +# SELF refers to the current entity instance or type value. self may appear within an entity +# declaration, a type declaration or an entity constructor. +# NOTE - SELF is not a constant, but behaves as one in every context in which it can appear. # python note: SELF is not mapped to any constant, but is mapper to self # EXPRESS definition: # =================== -#14.6 True -#true is a logical constant representing the logical notion of truth. It is compatible with the -#boolean and logical data types. +# 14.6 True +# true is a logical constant representing the logical notion of truth. It is compatible with the +# boolean and logical data types. TRUE = True # EXPRESS definition: # =================== -#14.7 Unknown -#unknown is a logical constant representing that there is insufficient information available to -#be able to evaluate a logical condition. It is compatible with the logical data type, but not -#with the boolean data type. +# 14.7 Unknown +# unknown is a logical constant representing that there is insufficient information available to +# be able to evaluate a logical condition. It is compatible with the logical data type, but not +# with the boolean data type. # @TODO: define UNKNOWN in python # # Builtin Functions -#15 Built-in functions -#All functions (and mathematical operations in general) are assumed to evaluate to exact results. -#The prototype for each of the built-in functions is given to show the type of the formal parameters -#and the result. +# 15 Built-in functions +# All functions (and mathematical operations in general) are assumed to evaluate to exact results. +# The prototype for each of the built-in functions is given to show the type of the formal parameters +# and the result. # # EXPRESS definition: # =================== -#15.1 Abs - arithmetic function -#FUNCTION ABS ( V:NUMBER ) : NUMBER; -#The abs function returns the absolute value of a number. -#Parameters : V is a number. -#Result : The absolute value of V. The returned data type is identical to the data type of V. -#EXAMPLE 125 { ABS ( -10 ) --> 10 +# 15.1 Abs - arithmetic function +# FUNCTION ABS ( V:NUMBER ) : NUMBER; +# The abs function returns the absolute value of a number. +# Parameters : V is a number. +# Result : The absolute value of V. The returned data type is identical to the data type of V. +# EXAMPLE 125 { ABS ( -10 ) --> 10 # Python definition: # ================== # ABS is mapped to python abs builtin function def ABS(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("ABS function takes a NUMBER parameter") return type(V)(abs(V)) + # EXPRESS definition: # =================== -#15.2 ACos - arithmetic function -#FUNCTION ACOS ( V:NUMBER ) : REAL; -#The acos function returns the angle given a cosine value. -#Parameters : V is a number which is the cosine of an angle. -#Result : The angle in radians (0 <= result <= pi) whose cosine is V. -#Conditions : -1.0= 1.266103... +# 15.2 ACos - arithmetic function +# FUNCTION ACOS ( V:NUMBER ) : REAL; +# The acos function returns the angle given a cosine value. +# Parameters : V is a number which is the cosine of an angle. +# Result : The angle in radians (0 <= result <= pi) whose cosine is V. +# Conditions : -1.0= 1.266103... # Python definition: # ================== # ACOS is mapped to python math.acos builtin function def ACOS(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("ACOS function takes a NUMBER parameter") return REAL(math.acos(V)) + # it's the same for ASIN and ATAN def ASIN(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("ASIN function takes a NUMBER parameter") return REAL(math.asin(V)) + # EXPRESS definition: # =================== # 15.3 ATan - arithmetic function -#FUNCTION ATAN ( V1:NUMBER; V2:NUMBER ) : REAL; -#The atan function returns the angle given a tangent value of V , where V is given by the -#expression V = V1/V2. -#Parameters : -#a) V1 is a number. -#b) V2 is a number. -#Result : The angle in radians (-pi/2<=result<=pi/2) whose tangent is V. If V2 is zero, the result -#is pi/2 or -pi/2 depending on the sign of V1. -#Conditions : Both V1 and V2 shall not be zero. -#EXAMPLE 128 { ATAN ( -5.5, 3.0 ) --> -1.071449... -def ATAN(V1,V2): - if not isinstance(V1,NUMBER) and not isinstance(V2,NUMBER): +# FUNCTION ATAN ( V1:NUMBER; V2:NUMBER ) : REAL; +# The atan function returns the angle given a tangent value of V , where V is given by the +# expression V = V1/V2. +# Parameters : +# a) V1 is a number. +# b) V2 is a number. +# Result : The angle in radians (-pi/2<=result<=pi/2) whose tangent is V. If V2 is zero, the result +# is pi/2 or -pi/2 depending on the sign of V1. +# Conditions : Both V1 and V2 shall not be zero. +# EXAMPLE 128 { ATAN ( -5.5, 3.0 ) --> -1.071449... +def ATAN(V1, V2): + if not isinstance(V1, NUMBER) and not isinstance(V2, NUMBER): raise TypeError("ATAN function takes 2 NUMBER parameters") if V2 == 0: - if V1>0: - return REAL(math.pi/2) - elif V1<0: - return REAL(-math.pi/2) + if V1 > 0: + return REAL(math.pi / 2) + elif V1 < 0: + return REAL(-math.pi / 2) else: raise ValueError("ATAN parameters can be both equal to zero") else: - return REAL(math.atan(float(V1)/float(V2))) + return REAL(math.atan(float(V1) / float(V2))) + # EXPRESS definition: # =================== -#15.5 BLength - binary function -#FUNCTION BLENGTH ( V:BINARY ) : INTEGER; -#The blength function returns the number of bits in a binary. -#Parameters : V is a binary value. -#Result : The returned value is the actual number of bits in the binary value passed. -#EXAMPLE 129 -#LOCAL -#n : NUMBER; -#x : BINARY := %01010010 ; -#END_LOCAL; -#... -#n := BLENGTH ( x ); -- n is assigned the value 8 +# 15.5 BLength - binary function +# FUNCTION BLENGTH ( V:BINARY ) : INTEGER; +# The blength function returns the number of bits in a binary. +# Parameters : V is a binary value. +# Result : The returned value is the actual number of bits in the binary value passed. +# EXAMPLE 129 +# LOCAL +# n : NUMBER; +# x : BINARY := %01010010 ; +# END_LOCAL; +# ... +# n := BLENGTH ( x ); -- n is assigned the value 8 def BLENGTH(V): - if not isinstance(V,BINARY): + if not isinstance(V, BINARY): raise TypeError("BLENGTH function takes one BINARY parameter") return INTEGER(len(V)) -# EXPRESS definition: -# =================== -#15.6 Cos - arithmetic function -#FUNCTION COS ( V:NUMBER ) : REAL; -#The cos function returns the cosine of an angle. -#Parameters : V is a number which is an angle in radians. -#Result : The cosine of V (-1.0<=result<=1.0). -#EXAMPLE 130 { COS ( 0.5 ) --> 8.77582...E-1 -# -#15.21 Sin - arithmetic function -#FUNCTION SIN ( V:NUMBER ) : REAL; -#The sin function returns the sine of an angle. -#Parameters : V is a number representing an angle expressed in radians. -#Result : The sine of V (-1.0 <= result <= 1.0). -#EXAMPLE 144 { SIN ( PI ) --> 0.0 -# -def COS(V): - if not isinstance(V,NUMBER): - raise TypeError("COS function takes a NUMBER parameter") - return REAL(math.cos(V)) -def SIN(V): - if not isinstance(V,NUMBER): - raise TypeError("SIN function takes a NUMBER parameter") - return REAL(math.sin(V)) # EXPRESS definition: # =================== -#15.7 Exists - general function -#FUNCTION EXISTS ( V:GENERIC ) : BOOLEAN; -#The exists function returns true if a value exists for the input parameter, or false if no value -#exists for it. The exists function is useful for checking if values have been given to optional -#attributes, or if variables have been initialized. -#Parameters : V is an expression which results in any type. -#Result : true or false depending on whether V has an actual or indeterminate (?) value. -#EXAMPLE 131 { IF EXISTS ( a ) THEN ... +# 15.6 Cos - arithmetic function +# FUNCTION COS ( V:NUMBER ) : REAL; +# The cos function returns the cosine of an angle. +# Parameters : V is a number which is an angle in radians. +# Result : The cosine of V (-1.0<=result<=1.0). +# EXAMPLE 130 { COS ( 0.5 ) --> 8.77582...E-1 +# +# 15.21 Sin - arithmetic function +# FUNCTION SIN ( V:NUMBER ) : REAL; +# The sin function returns the sine of an angle. +# Parameters : V is a number representing an angle expressed in radians. +# Result : The sine of V (-1.0 <= result <= 1.0). +# EXAMPLE 144 { SIN ( PI ) --> 0.0 +# +def COS(V): + if not isinstance(V, NUMBER): + raise TypeError("COS function takes a NUMBER parameter") + return REAL(math.cos(V)) + + +def SIN(V): + if not isinstance(V, NUMBER): + raise TypeError("SIN function takes a NUMBER parameter") + return REAL(math.sin(V)) + + +# EXPRESS definition: +# =================== +# 15.7 Exists - general function +# FUNCTION EXISTS ( V:GENERIC ) : BOOLEAN; +# The exists function returns true if a value exists for the input parameter, or false if no value +# exists for it. The exists function is useful for checking if values have been given to optional +# attributes, or if variables have been initialized. +# Parameters : V is an expression which results in any type. +# Result : true or false depending on whether V has an actual or indeterminate (?) value. +# EXAMPLE 131 { IF EXISTS ( a ) THEN ... def EXISTS(V): - if V==None: + if V == None: return False else: return True + # EXPRESS definition: # =================== -#15.8 Exp - arithmetic function -#FUNCTION EXP ( V:NUMBER ) : REAL; -#The exp function returns e (the base of the natural logarithm system) raised to the power V. -#Parameters : V is a number. -#Result : The value eV . -#EXAMPLE 132 { EXP ( 10 ) --> 2.202646...E+4 +# 15.8 Exp - arithmetic function +# FUNCTION EXP ( V:NUMBER ) : REAL; +# The exp function returns e (the base of the natural logarithm system) raised to the power V. +# Parameters : V is a number. +# Result : The value eV . +# EXAMPLE 132 { EXP ( 10 ) --> 2.202646...E+4 def EXP(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("EXP function takes a NUMBER parameter") return REAL(math.exp(V)) - + + # EXPRESS definition: # =================== -#15.9 Format - general function -#FUNCTION FORMAT(N:NUMBER; F:STRING):STRING; -#The format returns a formatted string representation of a number. -#Parameters : -#a) N is a number (integer or real). -#b) F is a string containing formatting commands. -#Result : A string representation of N formatted according to F. Rounding is applied to the -#string representation if necessary. -#The formatting string contains special characters to indicate the appearance of the result. The -#formatting string can be written in three ways: -#a) The formatting string can give a symbolic description of the output representation. -#b) The formatting string can give a picture description of the output representation. -#c) When the formatting string is empty, a standard output representation is produced. +# 15.9 Format - general function +# FUNCTION FORMAT(N:NUMBER; F:STRING):STRING; +# The format returns a formatted string representation of a number. +# Parameters : +# a) N is a number (integer or real). +# b) F is a string containing formatting commands. +# Result : A string representation of N formatted according to F. Rounding is applied to the +# string representation if necessary. +# The formatting string contains special characters to indicate the appearance of the result. The +# formatting string can be written in three ways: +# a) The formatting string can give a symbolic description of the output representation. +# b) The formatting string can give a picture description of the output representation. +# c) When the formatting string is empty, a standard output representation is produced. # Table 20: -#Number Format Display Comment -#10 +7I ' +10' Zero suppression -#10 +07I '+000010' Zeros not suppressed -#10 10.3E ' 1.000E+01' -#123.456789 8.2F ' 123.46' -#123.456789 8.2E '1.23E+02' -#123.456789 08.2E '0.12E+02' Preceding zero forced -#9.876E123 8.2E '9.88E+123' Exponent part is 3 characters -#and width ignored -#32.777 6I ' 33' Rounded +# Number Format Display Comment +# 10 +7I ' +10' Zero suppression +# 10 +07I '+000010' Zeros not suppressed +# 10 10.3E ' 1.000E+01' +# 123.456789 8.2F ' 123.46' +# 123.456789 8.2E '1.23E+02' +# 123.456789 08.2E '0.12E+02' Preceding zero forced +# 9.876E123 8.2E '9.88E+123' Exponent part is 3 characters +# and width ignored +# 32.777 6I ' 33' Rounded # Python definition # ================= # python string formatting is obtained from the val function # @TODO: implement a safe eval or provide another implementation # that avoids unsafe eval python builtin function. -def FORMAT(N,F): - if not isinstance(N,NUMBER): +def FORMAT(N, F): + if not isinstance(N, NUMBER): raise TypeError("FORMAT function takes a NUMBER parameter") - if not isinstance(F,STRING): + if not isinstance(F, STRING): raise TypeError("FORMAT function takes a NUMBER parameter") py_formatting = F.lower() string_to_evaluate = "'%" - string_to_evaluate += "%s'"%py_formatting + string_to_evaluate += "%s'" % py_formatting string_to_evaluate += "%" - string_to_evaluate += "%s"%N + string_to_evaluate += "%s" % N result = eval(string_to_evaluate).upper() return STRING(result) + # EXPRESS definition: # =================== -#15.10 HiBound - arithmetic function -#FUNCTION HIBOUND ( V:AGGREGATE OF GENERIC ) : INTEGER; -#The hibound function returns the declared upper index of an array or the declared upper -#bound of a bag, list or set. -#Parameters : V is an aggregate value. -#Result : -#a) When V is an array the returned value is the declared upper index. -#b) When V is a bag, list or set the returned value is the declared upper bound; if there -#are no bounds declared or the upper bound is declared to be indeterminate (?) indeterminate -#(?) is returned. -#EXAMPLE 133 { Usage of hibound function on nested aggregate values. -#LOCAL -#a : ARRAY[-3:19] OF SET[2:4] OF LIST[0:?] OF INTEGER; -#h1, h2, h3 : INTEGER; -#END_LOCAL; -#... -#a[-3][1][1] := 2; -- places a value in the list -#... -#h1 := HIBOUND(a); -- =19 (upper bound of array) -#h2 := HIBOUND(a[-3]); -- = 4 (upper bound of set) -#h3 := HIBOUND(a[-3][1]); -- = ? (upper bound of list (unbounded)) +# 15.10 HiBound - arithmetic function +# FUNCTION HIBOUND ( V:AGGREGATE OF GENERIC ) : INTEGER; +# The hibound function returns the declared upper index of an array or the declared upper +# bound of a bag, list or set. +# Parameters : V is an aggregate value. +# Result : +# a) When V is an array the returned value is the declared upper index. +# b) When V is a bag, list or set the returned value is the declared upper bound; if there +# are no bounds declared or the upper bound is declared to be indeterminate (?) indeterminate +# (?) is returned. +# EXAMPLE 133 { Usage of hibound function on nested aggregate values. +# LOCAL +# a : ARRAY[-3:19] OF SET[2:4] OF LIST[0:?] OF INTEGER; +# h1, h2, h3 : INTEGER; +# END_LOCAL; +# ... +# a[-3][1][1] := 2; -- places a value in the list +# ... +# h1 := HIBOUND(a); -- =19 (upper bound of array) +# h2 := HIBOUND(a[-3]); -- = 4 (upper bound of set) +# h3 := HIBOUND(a[-3][1]); -- = ? (upper bound of list (unbounded)) def HIBOUND(V): - if not isinstance(V,Aggregate): + if not isinstance(V, Aggregate): raise TypeError("HIBOUND takes an aggregate of generic") return V.get_hibound() + # EXPRESS definition: # =================== -#15.11 HiIndex - arithmetic function -#FUNCTION HIINDEX ( V:AGGREGATE OF GENERIC ) : INTEGER; -#The hiindex function returns the upper index of an array or the number of elements in a bag, -#list or set -#Parameters : V is an aggregate value. -#Result : -#a) When V is an array, the returned value is the declared upper index. -#b) When V is a bag, list or set, the returned value is the actual number of elements in -#the aggregate value. -#EXAMPLE 134 { Usage of hiindex function on nested aggregate values. -#LOCAL -#a : ARRAY[-3:19] OF SET[2:4] OF LIST[0:?] OF INTEGER; -#h1, h2, h3 : INTEGER; -#END_LOCAL; -#a[-3][1][1] := 2; -- places a value in the list -#h1 := HIINDEX(a); -- = 19 (upper bound of array) -#h2 := HIINDEX(a[-3]); -- = 1 (size of set) -- this is invalid with respect -#-- to the bounds on the SET -#h3 := HIINDEX(a[-3][1]); -- = 1 (size of list) +# 15.11 HiIndex - arithmetic function +# FUNCTION HIINDEX ( V:AGGREGATE OF GENERIC ) : INTEGER; +# The hiindex function returns the upper index of an array or the number of elements in a bag, +# list or set +# Parameters : V is an aggregate value. +# Result : +# a) When V is an array, the returned value is the declared upper index. +# b) When V is a bag, list or set, the returned value is the actual number of elements in +# the aggregate value. +# EXAMPLE 134 { Usage of hiindex function on nested aggregate values. +# LOCAL +# a : ARRAY[-3:19] OF SET[2:4] OF LIST[0:?] OF INTEGER; +# h1, h2, h3 : INTEGER; +# END_LOCAL; +# a[-3][1][1] := 2; -- places a value in the list +# h1 := HIINDEX(a); -- = 19 (upper bound of array) +# h2 := HIINDEX(a[-3]); -- = 1 (size of set) -- this is invalid with respect +# -- to the bounds on the SET +# h3 := HIINDEX(a[-3][1]); -- = 1 (size of list) def HIINDEX(V): - if not isinstance(V,Aggregate): + if not isinstance(V, Aggregate): raise TypeError("HIINDEX takes an aggregate of generic") return V.get_hiindex() + # EXPRESS definition: # =================== -#15.12 Length - string function -#FUNCTION LENGTH ( V:STRING ) : INTEGER; -#The length function returns the number of characters in a string. -#Parameters : V is a string value. -#Result : The returned value is the number of characters in the string and shall be greater than -#or equal to zero. -#EXAMPLE 135 - Usage of the length function. -#LOCAL -#n : NUMBER; -#x1 : STRING := 'abc'; -#x2 : STRING := "000025FF000101B5; -#END_LOCAL; -#... -#n := LENGTH ( x1 ); -- n is assigned the value 3 -#n := LENGTH ( x2 ); -- n is assigned the value 2 +# 15.12 Length - string function +# FUNCTION LENGTH ( V:STRING ) : INTEGER; +# The length function returns the number of characters in a string. +# Parameters : V is a string value. +# Result : The returned value is the number of characters in the string and shall be greater than +# or equal to zero. +# EXAMPLE 135 - Usage of the length function. +# LOCAL +# n : NUMBER; +# x1 : STRING := 'abc'; +# x2 : STRING := "000025FF000101B5; +# END_LOCAL; +# ... +# n := LENGTH ( x1 ); -- n is assigned the value 3 +# n := LENGTH ( x2 ); -- n is assigned the value 2 def LENGTH(V): - if not isinstance(V,STRING): + if not isinstance(V, STRING): raise TypeError("LENGTH take a STRING parameter") return INTEGER(len(V)) + # EXPRESS definition: # =================== -#15.13 LoBound - arithmetic function -#FUNCTION LOBOUND ( V:AGGREGATE OF GENERIC ) : INTEGER; -#The lobound function returns the declared lower index of an array, or the declared lower -#bound of a bag, list or set. -#Parameters : V is an aggregate value. -#Result : -#a) When V is an array the returned value is the declared lower index. -#b) When V is a bag, list or set the returned value is the declared lower bound; if no -#lower bound is declared, zero (0) is returned. -#EXAMPLE 136 { Usage of lobound function on nested aggregate values. -#LOCAL -#a : ARRAY[-3:19] OF SET[2:4] OF LIST[0:?] OF INTEGER; -#h1, h2, h3 : INTEGER; -#END_LOCAL; -#... -#h1 := LOBOUND(a); -- =-3 (lower index of array) -#h2 := LOBOUND(a[-3]); -- = 2 (lower bound of set) -#h3 := LOBOUND(a[-3][1]); -- = 0 (lower bound of list) +# 15.13 LoBound - arithmetic function +# FUNCTION LOBOUND ( V:AGGREGATE OF GENERIC ) : INTEGER; +# The lobound function returns the declared lower index of an array, or the declared lower +# bound of a bag, list or set. +# Parameters : V is an aggregate value. +# Result : +# a) When V is an array the returned value is the declared lower index. +# b) When V is a bag, list or set the returned value is the declared lower bound; if no +# lower bound is declared, zero (0) is returned. +# EXAMPLE 136 { Usage of lobound function on nested aggregate values. +# LOCAL +# a : ARRAY[-3:19] OF SET[2:4] OF LIST[0:?] OF INTEGER; +# h1, h2, h3 : INTEGER; +# END_LOCAL; +# ... +# h1 := LOBOUND(a); -- =-3 (lower index of array) +# h2 := LOBOUND(a[-3]); -- = 2 (lower bound of set) +# h3 := LOBOUND(a[-3][1]); -- = 0 (lower bound of list) def LOBOUND(V): - if not isinstance(V,Aggregate): + if not isinstance(V, Aggregate): raise TypeError("HIBOUND takes an aggregate of generic") return V.get_lobound() - + + # EXPRESS definition: -# =================== -#15.14 Log - arithmetic function -#FUNCTION LOG ( V:NUMBER ) : REAL; -#The log function returns the natural logarithm of a number. -#Parameters : V is a number. -#Result : A real number which is the natural logarithm of V. -#Conditions : V > 0:0 -#EXAMPLE 137 { LOG ( 4.5 ) --> 1.504077...E0 -#15.15 Log2 - arithmetic function -#FUNCTION LOG2 ( V:NUMBER ) : REAL; -#The log2 function returns the base two logarithm of a number. -#Parameters : V is a number. -#Result : A real number which is the base two logarithm of V. -#Conditions : V > 0:0 -#EXAMPLE 138 { LOG2 ( 8 ) --> 3.00...E0 -#15.16 Log10 - arithmetic function -#FUNCTION LOG10 ( V:NUMBER ) : REAL; -#The log10 function returns the base ten logarithm of a number. -#Parameters : V is a number. -#Result : A real number which is the base ten logarithm of V. -#Conditions : V > 0:0 -#EXAMPLE 139 { LOG10 ( 10 ) --> 1.00...E0 +# =================== +# 15.14 Log - arithmetic function +# FUNCTION LOG ( V:NUMBER ) : REAL; +# The log function returns the natural logarithm of a number. +# Parameters : V is a number. +# Result : A real number which is the natural logarithm of V. +# Conditions : V > 0:0 +# EXAMPLE 137 { LOG ( 4.5 ) --> 1.504077...E0 +# 15.15 Log2 - arithmetic function +# FUNCTION LOG2 ( V:NUMBER ) : REAL; +# The log2 function returns the base two logarithm of a number. +# Parameters : V is a number. +# Result : A real number which is the base two logarithm of V. +# Conditions : V > 0:0 +# EXAMPLE 138 { LOG2 ( 8 ) --> 3.00...E0 +# 15.16 Log10 - arithmetic function +# FUNCTION LOG10 ( V:NUMBER ) : REAL; +# The log10 function returns the base ten logarithm of a number. +# Parameters : V is a number. +# Result : A real number which is the base ten logarithm of V. +# Conditions : V > 0:0 +# EXAMPLE 139 { LOG10 ( 10 ) --> 1.00...E0 def LOG(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("LOG function takes a NUMBER parameter") return REAL(math.log(V)) + + def LOG2(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("LOG2 function takes a NUMBER parameter") - return REAL(math.log(V,2)) + return REAL(math.log(V, 2)) + + def LOG10(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("LOG10 function takes a NUMBER parameter") return REAL(math.log10(V)) + # EXPRESS definition: -# =================== -#15.17 LoIndex - arithmetic function -#FUNCTION LOINDEX ( V:AGGREGATE OF GENERIC ) : INTEGER; -#The loindex function returns the lower index of an aggregate value. -#Parameters : V is an aggregate value. -#Result : -#a) When V is an array the returned value is the declared lower index. -#b) When V is a bag, list or set, the returned value is 1 (one). -#EXAMPLE 140 { Usage of loindex function on nested aggregate values. -#LOCAL -#a : ARRAY[-3:19] OF SET[2:4] OF LIST[0:?] OF INTEGER; -#h1, h2, h3 : INTEGER; -#END_LOCAL; -#... -#h1 := LOINDEX(a); -- =-3 (lower bound of array) -#h2 := LOINDEX(a[-3]); -- = 1 (for set) -#h3 := LOINDEX(a[-3][1]); -- = 1 (for list) +# =================== +# 15.17 LoIndex - arithmetic function +# FUNCTION LOINDEX ( V:AGGREGATE OF GENERIC ) : INTEGER; +# The loindex function returns the lower index of an aggregate value. +# Parameters : V is an aggregate value. +# Result : +# a) When V is an array the returned value is the declared lower index. +# b) When V is a bag, list or set, the returned value is 1 (one). +# EXAMPLE 140 { Usage of loindex function on nested aggregate values. +# LOCAL +# a : ARRAY[-3:19] OF SET[2:4] OF LIST[0:?] OF INTEGER; +# h1, h2, h3 : INTEGER; +# END_LOCAL; +# ... +# h1 := LOINDEX(a); -- =-3 (lower bound of array) +# h2 := LOINDEX(a[-3]); -- = 1 (for set) +# h3 := LOINDEX(a[-3][1]); -- = 1 (for list) def LOINDEX(V): - if not isinstance(V,Aggregate): + if not isinstance(V, Aggregate): raise TypeError("LOINDEX takes an aggregate of generic") return V.get_loindex() + # EXPRESS definition: -# =================== -#15.18 NVL - null value function -#FUNCTION NVL(V:GENERIC:GEN1; SUBSTITUTE:GENERIC:GEN1):GENERIC:GEN1; -#The nvl function returns either the input value or an alternate value in the case where the input -#has a indeterminate (?) value. -#Parameters : -#a) V is an expression which is of any type. -#b) SUBSTITUTE is an expression which shall not evaluate to indeterminate (?). -#Result : When V is not indeterminate (?) that value is returned. Otherwise, SUBSTITUTE is -#returned. -#EXAMPLE 141 { ENTITY unit_vector; -#x, y : REAL; -#z : OPTIONAL REAL; -#WHERE -#x**2 + y**2 + NVL(z, 0.0)**2 = 1.0; -#END_ENTITY; -#The nvl function is used to supply zero (0.0) as the value of Z when Z is indeterminate (?). -def NVL(V,SUBSTITUTE): +# =================== +# 15.18 NVL - null value function +# FUNCTION NVL(V:GENERIC:GEN1; SUBSTITUTE:GENERIC:GEN1):GENERIC:GEN1; +# The nvl function returns either the input value or an alternate value in the case where the input +# has a indeterminate (?) value. +# Parameters : +# a) V is an expression which is of any type. +# b) SUBSTITUTE is an expression which shall not evaluate to indeterminate (?). +# Result : When V is not indeterminate (?) that value is returned. Otherwise, SUBSTITUTE is +# returned. +# EXAMPLE 141 { ENTITY unit_vector; +# x, y : REAL; +# z : OPTIONAL REAL; +# WHERE +# x**2 + y**2 + NVL(z, 0.0)**2 = 1.0; +# END_ENTITY; +# The nvl function is used to supply zero (0.0) as the value of Z when Z is indeterminate (?). +def NVL(V, SUBSTITUTE): if V is not None: return V else: return SUBSTITUTE + # EXPRESS definition: -# =================== -#15.19 Odd - arithmetic function -#FUNCTION ODD ( V:INTEGER ) : LOGICAL; -#The odd function returns true or false depending on whether a number is odd or even. -#Parameters : V is an integer number. -#Result : When V MOD 2 = 1 true is returned; otherwise false is returned. -#Conditions : Zero is not odd. -#EXAMPLE 142 { ODD ( 121 ) --> TRUE +# =================== +# 15.19 Odd - arithmetic function +# FUNCTION ODD ( V:INTEGER ) : LOGICAL; +# The odd function returns true or false depending on whether a number is odd or even. +# Parameters : V is an integer number. +# Result : When V MOD 2 = 1 true is returned; otherwise false is returned. +# Conditions : Zero is not odd. +# EXAMPLE 142 { ODD ( 121 ) --> TRUE def ODD(V): - if not isinstance(V,INTEGER): + if not isinstance(V, INTEGER): raise TypeError("ODD takes an INTEGER") - if V%2 == 0: + if V % 2 == 0: return False else: return True + # EXPRESS definition: -# =================== -#15.20 RolesOf - general function -#FUNCTION ROLESOF ( V:GENERIC ) : SET OF STRING; -#The rolesof function returns a set of strings containing the fully qualified names of the roles -#played by the specified entity instance. A fully qualified name is defined to be the name of the -#attribute qualified by the name of the schema and entity in which this attribute is declared (i.e. +# =================== +# 15.20 RolesOf - general function +# FUNCTION ROLESOF ( V:GENERIC ) : SET OF STRING; +# The rolesof function returns a set of strings containing the fully qualified names of the roles +# played by the specified entity instance. A fully qualified name is defined to be the name of the +# attribute qualified by the name of the schema and entity in which this attribute is declared (i.e. #'SCHEMA.ENTITY.ATTRIBUTE'). -#Parameters : V is any instance of an entity data type. -#Result : A set of string values (in upper case) containing the fully qualified names of the -#attributes of the entity instances which use the instance V. -#When a named data type is used or referenced, the schema and the name in that schema, -#if renamed, are also returned. Since use statements may be chained, all the chained schema -#names and the name in each schema are returned. -#EXAMPLE 143 { This example shows that a point might be used as the centre of a circle. The -#rolesof function determines what roles an entity instance actually plays. -#SCHEMA that_schema; -#ENTITY point; -#x, y, z : REAL; -#END_ENTITY; -#ENTITY line; -#start, -#end : point; -#END_ENTITY; -#END_SCHEMA; -#SCHEMA this_schema; -#USE FROM that_schema (point,line); -#CONSTANT -#origin : point := point(0.0, 0.0, 0.0); -#END_CONSTANT; -#ENTITY circle; -#centre : point; -#axis : vector; -#radius : REAL; -#END_ENTITY; -#... -#LOCAL -#p : point := point(1.0, 0.0, 0.0); -#c : circle := circle(p, vector(1,1,1), 1.0); -#l : line := line(p, origin); -#END_LOCAL; -#... -#IF 'THIS_SCHEMA.CIRCLE.CENTRE' IN ROLESOF(p) THEN -- true -#... -#IF 'THIS_SCHEMA.LINE.START' IN ROLESOF(p) THEN -- true -#... -#IF 'THAT_SCHEMA.LINE.START' IN ROLESOF(p) THEN -- true -#... -#IF 'THIS_SCHEMA.LINE.END' IN ROLESOF(p) THEN -- false -# +# Parameters : V is any instance of an entity data type. +# Result : A set of string values (in upper case) containing the fully qualified names of the +# attributes of the entity instances which use the instance V. +# When a named data type is used or referenced, the schema and the name in that schema, +# if renamed, are also returned. Since use statements may be chained, all the chained schema +# names and the name in each schema are returned. +# EXAMPLE 143 { This example shows that a point might be used as the centre of a circle. The +# rolesof function determines what roles an entity instance actually plays. +# SCHEMA that_schema; +# ENTITY point; +# x, y, z : REAL; +# END_ENTITY; +# ENTITY line; +# start, +# end : point; +# END_ENTITY; +# END_SCHEMA; +# SCHEMA this_schema; +# USE FROM that_schema (point,line); +# CONSTANT +# origin : point := point(0.0, 0.0, 0.0); +# END_CONSTANT; +# ENTITY circle; +# centre : point; +# axis : vector; +# radius : REAL; +# END_ENTITY; +# ... +# LOCAL +# p : point := point(1.0, 0.0, 0.0); +# c : circle := circle(p, vector(1,1,1), 1.0); +# l : line := line(p, origin); +# END_LOCAL; +# ... +# IF 'THIS_SCHEMA.CIRCLE.CENTRE' IN ROLESOF(p) THEN -- true +# ... +# IF 'THIS_SCHEMA.LINE.START' IN ROLESOF(p) THEN -- true +# ... +# IF 'THAT_SCHEMA.LINE.START' IN ROLESOF(p) THEN -- true +# ... +# IF 'THIS_SCHEMA.LINE.END' IN ROLESOF(p) THEN -- false +# # Python note: # @TODO: implement the ROLESOF function def ROLESOF(V): raise NotImplemented("Function ROLESOF not implemented") + # EXPRESS definition: -# =================== -#15.22 SizeOf - aggregate function -#FUNCTION SIZEOF ( V:AGGREGATE OF GENERIC ) : INTEGER; -#The sizeof function returns the number of elements in an aggregate value. -#Parameters : V is an aggregate value. -#Result : -#a) When V is an array the returned value is its declared number of elements in the -#aggregation data type. -#b) When V is a bag, list or set, the returned value is the actual number of elements in -#the aggregate value. -#EXAMPLE 145 { LOCAL -#n : NUMBER; -#y : ARRAY[2:5] OF b; -#END_LOCAL; -#... -#n := SIZEOF (y); -- n is assigned the value 4 +# =================== +# 15.22 SizeOf - aggregate function +# FUNCTION SIZEOF ( V:AGGREGATE OF GENERIC ) : INTEGER; +# The sizeof function returns the number of elements in an aggregate value. +# Parameters : V is an aggregate value. +# Result : +# a) When V is an array the returned value is its declared number of elements in the +# aggregation data type. +# b) When V is a bag, list or set, the returned value is the actual number of elements in +# the aggregate value. +# EXAMPLE 145 { LOCAL +# n : NUMBER; +# y : ARRAY[2:5] OF b; +# END_LOCAL; +# ... +# n := SIZEOF (y); -- n is assigned the value 4 def SIZEOF(V): - if not isinstance(V,Aggregate): + if not isinstance(V, Aggregate): raise TypeError("SIZEOF takes an aggregate of generic") return V.get_size() + # EXPRESS definition: -# =================== -#15.23 Sqrt - arithmetic function -#FUNCTION SQRT ( V:NUMBER ) : REAL; -#The sqrt function returns the non-negative square root of a number. -#Parameters : V is any non-negative number. -#Result : The non-negative square root of V. -#Conditions : V >= 0:0 -#EXAMPLE 146 - SQRT ( 121 ) --> 11.0 +# =================== +# 15.23 Sqrt - arithmetic function +# FUNCTION SQRT ( V:NUMBER ) : REAL; +# The sqrt function returns the non-negative square root of a number. +# Parameters : V is any non-negative number. +# Result : The non-negative square root of V. +# Conditions : V >= 0:0 +# EXAMPLE 146 - SQRT ( 121 ) --> 11.0 def SQRT(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("SQRT function takes a NUMBER parameter") - if V<0.0: + if V < 0.0: raise ValueError("SQRT takes a non-negative parameter") return REAL(math.sqrt(V)) - + + # EXPRESS definition: -# =================== -#15.24 Tan - arithmetic function -#FUNCTION TAN ( V:NUMBER ) : REAL; -#The tan function returns the tangent of an angle. -#Parameters : V is a number representing an angle expressed in radians. -#Result : The tangent of the angle. If the angle is npi/2, where n is an odd integer, indeterminate -#(?) is returned. -#EXAMPLE 147 - TAN ( 0.0 ) --> 0.0 +# =================== +# 15.24 Tan - arithmetic function +# FUNCTION TAN ( V:NUMBER ) : REAL; +# The tan function returns the tangent of an angle. +# Parameters : V is a number representing an angle expressed in radians. +# Result : The tangent of the angle. If the angle is npi/2, where n is an odd integer, indeterminate +# (?) is returned. +# EXAMPLE 147 - TAN ( 0.0 ) --> 0.0 def TAN(V): - if not isinstance(V,NUMBER): + if not isinstance(V, NUMBER): raise TypeError("TAN function takes a NUMBER parameter") # check if angle is npi/2 where n is an odd integer - a = V/(PI/2) - if abs(a%2-1.) < SCL_float_epsilon : + a = V / (PI / 2) + if abs(a % 2 - 1.0) < SCL_float_epsilon: return None else: return REAL(math.tan(V)) + # EXPRESS definition: -# =================== -#15.25 TypeOf - general function -#FUNCTION TYPEOF ( V:GENERIC ) : SET OF STRING; -#The typeof function returns a set of strings that contains the names of all the data types -#of which the parameter is a member. Except for the simple data types (binary, boolean, -#integer, logical, number, real, and string) and the aggregation data types (array, bag, -#list, set) these names are qualified by the name of the schema which contains the definition of -#the type. -#NOTE 1 { The primary purpose of this function is to check whether a given value (variable, at- -#tribute value) can be used for a certain purpose, e.g. to ensure assignment compatibility between -#two values. It may also be used if different subtypes or specializations of a given type have to be -#treated differently in some context. -#Parameters : V is a value of any type. -#Result : The contents of the returned set of string values are the names (in upper case) of all -#types the value V is a member of. Such names are qualified by the name of the schema which -#contains the definition of the type ('SCHEMA.TYPE') if it is neither a simple data type nor an -#aggregation data type. It may be derived by the following algorithm (which is given here for -#specification purposes rather than to prescribe any particular type of implementation) +# =================== +# 15.25 TypeOf - general function +# FUNCTION TYPEOF ( V:GENERIC ) : SET OF STRING; +# The typeof function returns a set of strings that contains the names of all the data types +# of which the parameter is a member. Except for the simple data types (binary, boolean, +# integer, logical, number, real, and string) and the aggregation data types (array, bag, +# list, set) these names are qualified by the name of the schema which contains the definition of +# the type. +# NOTE 1 { The primary purpose of this function is to check whether a given value (variable, at- +# tribute value) can be used for a certain purpose, e.g. to ensure assignment compatibility between +# two values. It may also be used if different subtypes or specializations of a given type have to be +# treated differently in some context. +# Parameters : V is a value of any type. +# Result : The contents of the returned set of string values are the names (in upper case) of all +# types the value V is a member of. Such names are qualified by the name of the schema which +# contains the definition of the type ('SCHEMA.TYPE') if it is neither a simple data type nor an +# aggregation data type. It may be derived by the following algorithm (which is given here for +# specification purposes rather than to prescribe any particular type of implementation) def TYPEOF(V): # Create the set to return v_types = set() # append the type of V to the set - try: #it's a class + try: # it's a class to_add = V.__name__.upper() - except AttributeError: #it's an instance, first retrieve the type + except AttributeError: # it's an instance, first retrieve the type to_add = type(V).__name__.upper() - if not to_add in ['FLOAT','INT','AGGREGATE']: + if not to_add in ["FLOAT", "INT", "AGGREGATE"]: v_types.add(to_add) # recursively adds the base class names for base_type in type(V).__bases__: - #print base_type + # print base_type if not base_type == object: v_types = v_types.union(TYPEOF(base_type)) # finally, converts the v_types set to SET return v_types -# EXPRESS definition: -# =================== -#15.26 UsedIn - general function -#FUNCTION USEDIN ( T:GENERIC; R:STRING) : BAG OF GENERIC; -#The usedin function returns each entity instance that uses a specified entity instance in a -#specified role. -def USEDIN(T,R): - raise NotImplemented("USEDIN function not yet implemented.") # EXPRESS definition: -# =================== -#15.27 Value - arithmetic function -#FUNCTION VALUE ( V:STRING ) : NUMBER; -#The value function returns the numeric representation of a string. -#Parameters : V is a string containing either a real or integer literal. -#Result : A number corresponding to the string representation. If it is not possible to interpret -#the string as either a real or integer literal, indeterminate (?) is returned. -#EXAMPLE 151 { VALUE ( '1.234' ) --> 1.234 (REAL) -#VALUE ( '20' ) --> 20 (INTEGER) -#VALUE ( 'abc' ) --> ? null +# =================== +# 15.26 UsedIn - general function +# FUNCTION USEDIN ( T:GENERIC; R:STRING) : BAG OF GENERIC; +# The usedin function returns each entity instance that uses a specified entity instance in a +# specified role. +def USEDIN(T, R): + raise NotImplemented("USEDIN function not yet implemented.") + + +# EXPRESS definition: +# =================== +# 15.27 Value - arithmetic function +# FUNCTION VALUE ( V:STRING ) : NUMBER; +# The value function returns the numeric representation of a string. +# Parameters : V is a string containing either a real or integer literal. +# Result : A number corresponding to the string representation. If it is not possible to interpret +# the string as either a real or integer literal, indeterminate (?) is returned. +# EXAMPLE 151 { VALUE ( '1.234' ) --> 1.234 (REAL) +# VALUE ( '20' ) --> 20 (INTEGER) +# VALUE ( 'abc' ) --> ? null def VALUE(V): - if not isinstance(V,STRING): + if not isinstance(V, STRING): raise TypeError("VALUE function takes a NUMBER parameter") # first try to instantiate an INTEGER from the string: try: return INTEGER(V) except Exception: - pass #not possible, try to cast to REAL + pass # not possible, try to cast to REAL try: return REAL(V) except Exception: @@ -667,50 +696,50 @@ def VALUE(V): # else return None return None + # EXPRESS definition: -# =================== -#15.28 Value in - membership function -#FUNCTION VALUE_IN ( C:AGGREGATE OF GENERIC:GEN; V:GENERIC:GEN ) : LOGICAL; -#The value in function returns a logical value depending on whether or not a particular value -#is a member of an aggregation. -#Parameters : -#a) C is an aggregation of any type. -#b) V is an expression which is assignment compatible with the base type of C. -#Result : -#a) If either V or C is indeterminate (?), unknown is returned. -#b) If any element of C has a value equal to the value of V, true is returned. -#c) If any element of C is indeterminate (?), unknown is returned. -#d) Otherwise false is returned. -#EXAMPLE 152 { The following test ensures that there is at least one point which is positioned at -#the origin. -#LOCAL -#points : SET OF point; -#END_LOCAL; -#... -#IF VALUE_IN(points, point(0.0, 0.0, 0.0)) THEN ... -def VALUE_IN(C,V): - if not isinstance(C,Aggregate): +# =================== +# 15.28 Value in - membership function +# FUNCTION VALUE_IN ( C:AGGREGATE OF GENERIC:GEN; V:GENERIC:GEN ) : LOGICAL; +# The value in function returns a logical value depending on whether or not a particular value +# is a member of an aggregation. +# Parameters : +# a) C is an aggregation of any type. +# b) V is an expression which is assignment compatible with the base type of C. +# Result : +# a) If either V or C is indeterminate (?), unknown is returned. +# b) If any element of C has a value equal to the value of V, true is returned. +# c) If any element of C is indeterminate (?), unknown is returned. +# d) Otherwise false is returned. +# EXAMPLE 152 { The following test ensures that there is at least one point which is positioned at +# the origin. +# LOCAL +# points : SET OF point; +# END_LOCAL; +# ... +# IF VALUE_IN(points, point(0.0, 0.0, 0.0)) THEN ... +def VALUE_IN(C, V): + if not isinstance(C, Aggregate): raise TypeError("VALUE_IN method takes an aggregate as first parameter") raise NotImplemented("VALUE_IN function not yet implemented") + # EXPRESS definition: -# =================== -#15.29 Value unique - uniqueness function -#FUNCTION VALUE UNIQUE ( V:AGGREGATE OF GENERIC) : LOGICAL; -#The value unique function returns a logical value depending on whether or not the elements -#of an aggregation are value unique. -#Parameters : V is an aggregation of any type. -#Result : -#a) If V is indeterminate (?), unknown is returned. -#b) If any any two elements of V are value equal, false is returned. -#c) If any element of V is indeterminate (?), unknown is returned. -#d) Otherwise true is returned. -#EXAMPLE 153 { The following test ensures that each point is placed at a different position, (by -#definition they are distinct, i.e., instance unique). -#IF VALUE_UNIQUE(points) THEN ... +# =================== +# 15.29 Value unique - uniqueness function +# FUNCTION VALUE UNIQUE ( V:AGGREGATE OF GENERIC) : LOGICAL; +# The value unique function returns a logical value depending on whether or not the elements +# of an aggregation are value unique. +# Parameters : V is an aggregation of any type. +# Result : +# a) If V is indeterminate (?), unknown is returned. +# b) If any any two elements of V are value equal, false is returned. +# c) If any element of V is indeterminate (?), unknown is returned. +# d) Otherwise true is returned. +# EXAMPLE 153 { The following test ensures that each point is placed at a different position, (by +# definition they are distinct, i.e., instance unique). +# IF VALUE_UNIQUE(points) THEN ... def VALUE_UNIQUE(V): - if not isinstance(V,Aggregate): + if not isinstance(V, Aggregate): raise TypeError("VALUE_UNIQUE method takes an aggregate as first parameter") return V.get_value_unique() - - \ No newline at end of file diff --git a/src/Mod/Import/App/SCL/ConstructedDataTypes.py b/src/Mod/Import/App/SCL/ConstructedDataTypes.py index 3c9f48626b..959e10336c 100644 --- a/src/Mod/Import/App/SCL/ConstructedDataTypes.py +++ b/src/Mod/Import/App/SCL/ConstructedDataTypes.py @@ -23,7 +23,7 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF @@ -32,6 +32,7 @@ import sys import BaseType + class EnumerationId(object): """ EXPRESS definition: @@ -40,15 +41,17 @@ class EnumerationId(object): values of the enumeration data type. These names are designated by enumeration_ids and are referred to as enumeration items. """ + pass + class ENUMERATION(object): """ EXPRESS definition: =================== An ENUMERATION data type has as its domain an ordered set of names. The names represent values of the enumeration data type. - + Python implementation: ====================== An enumeration is initialized from strings defining the types. @@ -57,21 +60,22 @@ class ENUMERATION(object): (ahead, behind); END_TYPE; -- ahead_or_behind - + is implemented in python with the line: >>> ahead_of_behind = ENUMERATION('ahead','behind', the_current_scope) >>> ahead_or_behind.ahead >>> ahead_of_behind.behind - + And, if and only if ahead and/or behind are not in scope (e.g. they are not entity names, and/or many enums define the same enumeration identifier): >>> ahead >>> behind """ - def __init__(self,*kargs,**args): + + def __init__(self, *kargs, **args): # first defining the scope - if 'scope' in args: - self._scope = args['scope'] + if "scope" in args: + self._scope = args["scope"] else: self._scope = None # store passed enum identifiers @@ -82,14 +86,14 @@ class ENUMERATION(object): # we create an attribute ahead with which is a new # instance of EnumerationId for enum_id_name in self._enum_id_names: - setattr(self,enum_id_name,EnumerationId()) + setattr(self, enum_id_name, EnumerationId()) # we store this new attributes to the enum_ids list, which # will be accessed by the type checker with the get_enum_ids method self._enum_ids.append(self.__getattribute__(enum_id_name)) # # Then we check if the enums names can be added to the current scope: # if the name is already in the scope, then another enums id or select - # has the same name -> we do nothing, enums will be called + # has the same name -> we do nothing, enums will be called # with ahead_of_behind.ahead or ahead_or_behind.behind. # otherwise, they can be called as only ahead or behind # Note: since ENUMERATIONS are defined *before* entities, if an entity @@ -101,24 +105,26 @@ class ENUMERATION(object): def get_enum_ids(self): return self._enum_ids - + + class SELECT(object): - """ A select data type has as its domain the union of the domains of the named data types in + """A select data type has as its domain the union of the domains of the named data types in its select list. The select data type is a generalization of each of the named data types in its select list. """ - def __init__(self,*kargs,**args): + + def __init__(self, *kargs, **args): # first defining the scope - if 'scope' in args: - self._scope = args['scope'] + if "scope" in args: + self._scope = args["scope"] else: self._scope = None # create the types from the list of arguments self._base_types = [] for types in list(kargs): - new_type = BaseType.Type(types,self._scope) + new_type = BaseType.Type(types, self._scope) self._base_types.append(new_type) - + def get_allowed_types(self): _auth_types = [] for types in self._base_types: @@ -126,12 +132,12 @@ class SELECT(object): return _auth_types def get_allowed_basic_types(self): - ''' if a select contains some subselect, goes down through the different - sublayers until there is no more ''' + """if a select contains some subselect, goes down through the different + sublayers until there is no more""" b = [] _auth_types = self.get_allowed_types() for _auth_type in _auth_types: - if isinstance(_auth_type,SELECT) or isinstance(_auth_type,ENUMERATION): + if isinstance(_auth_type, SELECT) or isinstance(_auth_type, ENUMERATION): h = _auth_type.get_allowed_types() b.extend(h) else: diff --git a/src/Mod/Import/App/SCL/Model.py b/src/Mod/Import/App/SCL/Model.py index e19eefc91b..738b10a3fd 100644 --- a/src/Mod/Import/App/SCL/Model.py +++ b/src/Mod/Import/App/SCL/Model.py @@ -23,33 +23,31 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + class Model(objet): - """ The container for entity instances - """ + """The container for entity instances""" + def __init_(self): print("Model initialized") self._instances = [] - + def add_instance(self, entity_instance): self._instances.append(entity_instance) - + def remove_instance(self, entity_instance): self._instances.remove(entity_instance) - + def get_instances(self): return self._instances - + def export_to_p21file(self, filename): raise AssertionError("Not implemented") - + def export_to_p28file(self, filename): raise AssertionError("Not implemented") - - - diff --git a/src/Mod/Import/App/SCL/Part21.py b/src/Mod/Import/App/SCL/Part21.py index f116305dd7..e76ce3eb6d 100644 --- a/src/Mod/Import/App/SCL/Part21.py +++ b/src/Mod/Import/App/SCL/Part21.py @@ -36,19 +36,21 @@ import time INSTANCE_DEFINITION_RE = re.compile("#(\d+)[^\S\n]?=[^\S\n]?(.*?)\((.*)\)[^\S\n]?;[\\r]?$") + def map_string_to_num(stri): - """ Take a string, check whether it is an integer, a float or not - """ - if ('.' in stri) or ('E' in stri): #it's definitely a float + """Take a string, check whether it is an integer, a float or not""" + if ("." in stri) or ("E" in stri): # it's definitely a float return REAL(stri) else: return INTEGER(stri) + class Model: """ A model contains a list of instances """ - def __init__(self,name): + + def __init__(self, name): self._name = name # a dict of instances # each time an instance is added to the model, count is incremented @@ -56,21 +58,22 @@ class Model: self._number_of_instances = 0 def add_instance(self, instance): - ''' + """ Adds an instance to the model - ''' + """ self._number_of_instances += 1 - self._instances[self._number_of_instances-1] = instance + self._instances[self._number_of_instances - 1] = instance def print_instances(self): - ''' + """ Dump instances to stdout - ''' + """ for idx in range(self._number_of_instances): "==========" - print("Instance #%i"%(idx+1)) + print("Instance #%i" % (idx + 1)) print(self._instances[idx]) + class Part21EntityInstance: """ A class to represent a Part21 instance as defined in one Part21 file @@ -83,7 +86,8 @@ class Part21EntityInstance: entity : entity_instance_attributes: ['$','$','#5'] """ - def __init__(self,entity_name,attributes): + + def __init__(self, entity_name, attributes): self._entity self._attributes_definition = attributes print(self._entity_name) @@ -98,6 +102,7 @@ class Part21Parser: self._number_of_ancestors : stores the number of ancestors of entity id. This enables to define the order of instances creation. """ + def __init__(self, filename): self._filename = filename # the schema @@ -106,12 +111,12 @@ class Part21Parser: self._instances_definition = {} # this dict contains lists of 0 ancestors, 1 ancestor, etc. # initializes this dict - #self._number_of_ancestors = {} # this kind of sorting don't work on non-trivial files - #for i in range(2000): + # self._number_of_ancestors = {} # this kind of sorting don't work on non-trivial files + # for i in range(2000): # self._number_of_ancestors[i]=[] self.parse_file() # reduce number_of_ancestors dict - #for item in self._number_of_ancestors.keys(): + # for item in self._number_of_ancestors.keys(): # if len(self._number_of_ancestors[item])==0: # del self._number_of_ancestors[item] @@ -124,7 +129,7 @@ class Part21Parser: def parse_file(self): init_time = time.time() - print("Parsing file %s..."%self._filename) + print("Parsing file %s..." % self._filename) fp = open(self._filename) while True: line = fp.readline() @@ -132,31 +137,32 @@ class Part21Parser: break # there may be a multiline definition. In this case, we read lines until we found # a ; - while (line.find(';') == -1): #it's a multiline - line = line.replace("\n","").replace("\r","") + fp.readline() + while line.find(";") == -1: # it's a multiline + line = line.replace("\n", "").replace("\r", "") + fp.readline() # parse line match_instance_definition = INSTANCE_DEFINITION_RE.search(line) # id,name,attrs if match_instance_definition: instance_id, entity_name, entity_attrs = match_instance_definition.groups() instance_int_id = int(instance_id) # find number of ancestors - #number_of_ancestors = entity_attrs.count('#') + # number_of_ancestors = entity_attrs.count('#') # fill number of ancestors dict - #self._number_of_ancestors[number_of_ancestors].append(instance_int_id) # this kind of sorting don't work on non-trivial files + # self._number_of_ancestors[number_of_ancestors].append(instance_int_id) # this kind of sorting don't work on non-trivial files # parse attributes string entity_attrs_list, str_len = Utils.process_nested_parent_str(entity_attrs) # then finally append this instance to the disct instance - self._instances_definition[instance_int_id] = (entity_name,entity_attrs_list) - else: #does not match with entity instance definition, parse the header - if line.startswith('FILE_SCHEMA'): - #identify the schema name + self._instances_definition[instance_int_id] = (entity_name, entity_attrs_list) + else: # does not match with entity instance definition, parse the header + if line.startswith("FILE_SCHEMA"): + # identify the schema name self._schema_name = line.split("'")[1].split("'")[0].split(" ")[0].lower() fp.close() - print('done in %fs.'%(time.time()-init_time)) - print('schema: - %s entities %i'%(self._schema_name,len(self._instances_definition))) + print("done in %fs." % (time.time() - init_time)) + print("schema: - %s entities %i" % (self._schema_name, len(self._instances_definition))) + class EntityInstancesFactory(object): - ''' + """ This class creates entity instances from the str definition For instance, the definition: 20: ('CARTESIAN_POINT', ["''", '(5.,125.,20.)']) @@ -166,44 +172,48 @@ class EntityInstancesFactory(object): p.[2] = REAL(125) p.[3] = REAL(20) new_instance = cartesian_point(STRING(''),p) - ''' + """ + def __init__(self, schema_name, instance_definition): # First try to import the schema module pass + class Part21Population(object): def __init__(self, part21_loader): - """ Take a part21_loader a tries to create entities - """ + """Take a part21_loader a tries to create entities""" self._part21_loader = part21_loader self._aggregate_scope = [] self._aggr_scope = False self.create_entity_instances() def create_entity_instances(self): - """ Starts entity instances creation - """ + """Starts entity instances creation""" for number_of_ancestor in list(self._part21_loader._number_of_ancestors): - for entity_definition_id in self._part21_loader._number_of_ancestors[number_of_ancestor]: + for entity_definition_id in self._part21_loader._number_of_ancestors[ + number_of_ancestor + ]: self.create_entity_instance(entity_definition_id) def create_entity_instance(self, instance_id): instance_definition = self._part21_loader._instances_definition[instance_id] - print("Instance definition to process",instance_definition) + print("Instance definition to process", instance_definition) # first find class name class_name = instance_definition[0].lower() - print("Class name:%s"%class_name) + print("Class name:%s" % class_name) object_ = globals()[class_name] # then attributes - #print object_.__doc__ + # print object_.__doc__ instance_attributes = instance_definition[1] - print("instance_attributes:",instance_attributes) + print("instance_attributes:", instance_attributes) a = object_(*instance_attributes) + if __name__ == "__main__": import time import sys from config_control_design import * + p21loader = Part21Parser("gasket1.p21") print("Creating instances") p21population = Part21Population(p21loader) diff --git a/src/Mod/Import/App/SCL/Rules.py b/src/Mod/Import/App/SCL/Rules.py index 1267a99d61..14989a97ba 100644 --- a/src/Mod/Import/App/SCL/Rules.py +++ b/src/Mod/Import/App/SCL/Rules.py @@ -23,7 +23,7 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF @@ -31,9 +31,11 @@ __doc__ = "This module defines EXPRESS rules" + class Rule(object): - ''' + """ This class describes a RULE @TODO: to be implemented - ''' + """ + pass diff --git a/src/Mod/Import/App/SCL/SCLBase.py b/src/Mod/Import/App/SCL/SCLBase.py index 617c816ad2..462c6daa30 100644 --- a/src/Mod/Import/App/SCL/SCLBase.py +++ b/src/Mod/Import/App/SCL/SCLBase.py @@ -23,22 +23,25 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + class BaseEntityClass(object): - """ A class that allows advanced __repr__ features for entity instances - """ + """A class that allows advanced __repr__ features for entity instances""" + def __repr__(self): - """ Displays attribute with their values - """ - doc_string = "# %s class description:\n%s\n# Instance attributes:\n"%(self.__class__,self.__doc__) + """Displays attribute with their values""" + doc_string = "# %s class description:\n%s\n# Instance attributes:\n" % ( + self.__class__, + self.__doc__, + ) # write each argument with its value properties = dir(self) for elem in properties: if not elem.startswith("_"): - doc_string += "\t%s:%s\n"%(elem,self.__getattribute__(elem)) + doc_string += "\t%s:%s\n" % (elem, self.__getattribute__(elem)) return doc_string diff --git a/src/Mod/Import/App/SCL/SimpleDataTypes.py b/src/Mod/Import/App/SCL/SimpleDataTypes.py index fa3e8716fe..180cbce340 100644 --- a/src/Mod/Import/App/SCL/SimpleDataTypes.py +++ b/src/Mod/Import/App/SCL/SimpleDataTypes.py @@ -23,7 +23,7 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF @@ -33,6 +33,7 @@ Docstrings are courtesy of ISO 10303-11:1994(E) """ + class NUMBER: """ EXPRESS definition: @@ -45,14 +46,16 @@ class NUMBER: represent it, e.g. the size of the crowd at a football game would be an integer, whereas the area of the pitch would be a real. size : NUMBER ; - + Python definition: ================== class NUMBER is an abstract class, aimed at being specialized. """ + pass - -class REAL(float,NUMBER): + + +class REAL(float, NUMBER): """ EXPRESS definition: =================== @@ -73,17 +76,19 @@ class REAL(float,NUMBER): quired. This expression shall evaluate to a positive integer value. b) When no resolution specification is given the precision of the real number is uncon- strained. - + Note 9.2.6: integer and real are both specializations of number; - + Python definition: ================== REAL both inherits from float and NUMBER """ + pass -class INTEGER(int,NUMBER): + +class INTEGER(int, NUMBER): """ EXPRESS definition: =================== @@ -96,17 +101,19 @@ class INTEGER(int,NUMBER): ENTITY foo; nodes : INTEGER; END_ENTITY; - + Note 9.2.6: integer and real are both specializations of number; - + Python definition: ================== INTEGER both inherits from int and NUMBER - + @TODO: note 9.2.6 tells that integer is a specialization of real """ + pass - + + class STRING(str): """ The string data type has as its domain sequences of characters. The characters which are @@ -118,7 +125,7 @@ class STRING(str): A string data type may be defined as either fixed or varying width (number of characters). If it is not specfically defined as fixed width (by using the fixed reserved word in the dfinition) the string has varying width. - + The domain of a fixed width string data type is the set of all character sequences of exactly the width specified in the type definition. The domain of a varying width string data type is the set of all character sequences of width @@ -127,12 +134,14 @@ class STRING(str): the width of these sequences. Substrings and individual characters may be addressed using subscripts as described in 12.5. The case (upper or lower) of letters within a string is significant. - + Python mapping: INTEGER is mapped the 'str' type. An additional width_spec parameter can be passed to handle the FIXED length constraint """ + pass - + + class LOGICAL: """ The logical data type has as its domain the three literals true, false and unknown. @@ -142,20 +151,24 @@ class LOGICAL: true. The logical data type is compatible with the boolean data type, except that the value unknown cannot be assigned to a boolean variable. """ + pass + + Unknown = LOGICAL() # -#The boolean data type has as its domain the two literals true and false. The boolean data -#type is a specialization of the logical data type. -# -#Python mapping: BOOLEAN is mapped to 'bool' type +# The boolean data type has as its domain the two literals true and false. The boolean data +# type is a specialization of the logical data type. +# +# Python mapping: BOOLEAN is mapped to 'bool' type # # The bool data type can't however be subclassed in Python (see # See http://mail.python.org/pipermail/python-dev/2002-March/020822.html) # so it is just set to bool BOOLEAN = bool - + + class BINARY(str): """ The binary data type has as its domain sequences of bits, each bit being represented by 0 or 1. @@ -172,45 +185,49 @@ class BINARY(str): than or equal to the maximum width specified in the type definition. If no width is specified, the domain is the set of all bit sequences, with no constraint on the width of these sequences. Subbinaries and individual bits may be addressed using subscripts as described in 12.3. - + Python mapping: BINARY is mapped to the 'str' type. A check is performed to validate it is a binary string representing a number. """ + def __new__(self, value, width=-1, fixed=False): return str.__new__(self, value) - + def __init__(self, value, width=-1, fixed=False): - """ By default, length is set to None""" + """By default, length is set to None""" self._specified_width = width self._fixed = fixed # Check implicit width - if (width!=-1) and not fixed: - raise ValueError("The 'width' parameter is passed but 'fixed' is still false. Please explicitly set 'fixed' to True to avoid implicit declaration") + if (width != -1) and not fixed: + raise ValueError( + "The 'width' parameter is passed but 'fixed' is still false. Please explicitly set 'fixed' to True to avoid implicit declaration" + ) # First check the string length if 'fixed' is set to True if fixed: if len(value) != width: - raise ValueError("The BINARY width %i is not consistent with the 'width' declaration(%i)"%(len(value),width)) + raise ValueError( + "The BINARY width %i is not consistent with the 'width' declaration(%i)" + % (len(value), width) + ) # Check that the value passed is actually a binary try: - int(value,2) + int(value, 2) except ValueError: - raise ValueError("%s is not a binary"%value) + raise ValueError("%s is not a binary" % value) -if __name__=="__main__": +if __name__ == "__main__": print("Creating REAL from float value") a = REAL(1.5) - print(a*2) + print(a * 2) print("Creating REAL from string value") a = REAL("1.2") - print(a*3) + print(a * 3) print("Creating INTEGER from int value") b = INTEGER(2) c = INTEGER(3) - print(b+c) + print(b + c) print("Creating INTEGER from string value") e = INTEGER("5") f = INTEGER("8") - print(e*f) - - \ No newline at end of file + print(e * f) diff --git a/src/Mod/Import/App/SCL/SimpleReader.py b/src/Mod/Import/App/SCL/SimpleReader.py index 0df392b55c..222dd39f2f 100644 --- a/src/Mod/Import/App/SCL/SimpleReader.py +++ b/src/Mod/Import/App/SCL/SimpleReader.py @@ -36,18 +36,16 @@ corresponding classes. In addition it writes out a graphviz file with the entity graph. """ -import Part21,sys +import Part21, sys - -__title__="Simple Part21 STEP reader" +__title__ = "Simple Part21 STEP reader" __author__ = "Juergen Riegel" __version__ = "0.1 (Jan 2014)" - class SimpleParser: - """ read the file + """read the file Part21.Part21Parser Loads all instances definition of a Part21 file into memory. Two dicts are created: @@ -55,117 +53,133 @@ class SimpleParser: Part21.Part21Parser._number_of_ancestors : stores the number of ancestors of entity id. This enables to define the order of instances creation. """ + def __init__(self, filename): import time import sys + self._p21loader = Part21.Part21Parser(filename) - #self._p21loader._number_of_ancestors = {} # not needed, save memory + # self._p21loader._number_of_ancestors = {} # not needed, save memory self.schemaModule = None self.schemaClasses = None self.instanceMape = {} - #for i in self._p21loader._instances_definition.keys(): + # for i in self._p21loader._instances_definition.keys(): # print i,self._p21loader._instances_definition[i][0],self._p21loader._instances_definition[i][1] - def _writeGraphVizEdge(self,num,attrList,file): + def _writeGraphVizEdge(self, num, attrList, file): for i in attrList: - if isinstance(i,list): - self._writeGraphVizEdge(num,i,file) - elif isinstance(i,str): - if not i == '' and i[0] == '#': + if isinstance(i, list): + self._writeGraphVizEdge(num, i, file) + elif isinstance(i, str): + if not i == "" and i[0] == "#": key = int(i[1:]) - file.write(' '+repr(num)+' -> '+repr(key)+'\n') + file.write(" " + repr(num) + " -> " + repr(key) + "\n") + def writeGraphViz(self, fileName): + print("Writing GraphViz file %s..." % fileName) + gvFile = open(fileName, "w") - def writeGraphViz(self,fileName): - print("Writing GraphViz file %s..."%fileName) - gvFile = open(fileName,'w') - - gvFile.write('digraph G {\n node [fontname=Verdana,fontsize=12]\n node [style=filled]\n node [fillcolor="#EEEEEE"]\n node [color="#EEEEEE"]\n edge [color="#31CEF0"]\n') + gvFile.write( + 'digraph G {\n node [fontname=Verdana,fontsize=12]\n node [style=filled]\n node [fillcolor="#EEEEEE"]\n node [color="#EEEEEE"]\n edge [color="#31CEF0"]\n' + ) for i in list(self._p21loader._instances_definition): - entityStr = '#'+repr(i) - nameStr = self._p21loader._instances_definition[i][0].lower() - sttrStr = repr(self._p21loader._instances_definition[i][1]).replace('"','').replace("'",'').replace(" ",'') - if len (sttrStr) > 40: - sttrStr = sttrStr[:39]+'....' - gvFile.write(' '+repr(i)+' [label="'+entityStr+'\n'+nameStr+'\n'+sttrStr+'"]\n') - self._writeGraphVizEdge( i,self._p21loader._instances_definition[i][1],gvFile) - gvFile.write('}\n') + entityStr = "#" + repr(i) + nameStr = self._p21loader._instances_definition[i][0].lower() + sttrStr = ( + repr(self._p21loader._instances_definition[i][1]) + .replace('"', "") + .replace("'", "") + .replace(" ", "") + ) + if len(sttrStr) > 40: + sttrStr = sttrStr[:39] + "...." + gvFile.write( + " " + repr(i) + ' [label="' + entityStr + "\n" + nameStr + "\n" + sttrStr + '"]\n' + ) + self._writeGraphVizEdge(i, self._p21loader._instances_definition[i][1], gvFile) + gvFile.write("}\n") def instantiate(self): """Instantiate the python class from the entities""" import inspect + # load the needed schema module - if self._p21loader.get_schema_name() == 'config_control_design': + if self._p21loader.get_schema_name() == "config_control_design": import config_control_design + self.schemaModule = config_control_design - if self._p21loader.get_schema_name() == 'automotive_design': + if self._p21loader.get_schema_name() == "automotive_design": import automotive_design + self.schemaModule = automotive_design if self.schemaModule: self.schemaClasses = dict(inspect.getmembers(self.schemaModule)) for i in list(self._p21loader._instances_definition): - #print i + # print i if i not in self.instanceMape: self._create_entity_instance(i) def _create_entity_instance(self, instance_id): if instance_id in self._p21loader._instances_definition: instance_definition = self._p21loader._instances_definition[instance_id] - #print "Instance definition to process",instance_definition + # print "Instance definition to process",instance_definition # first find class name class_name = instance_definition[0].lower() - #print "Class name:%s"%class_name + # print "Class name:%s"%class_name - if not class_name=='': + if not class_name == "": classDef = self.schemaClasses[class_name] # then attributes - #print object_.__doc__ + # print object_.__doc__ instance_attributes = instance_definition[1] self._transformAttributes(instance_attributes) - print('Attribute list after transform: ',instance_attributes) + print("Attribute list after transform: ", instance_attributes) - self.instanceMape[instance_id] = str('dummy#:'+str(instance_id)) # dummy instance to test + self.instanceMape[instance_id] = str( + "dummy#:" + str(instance_id) + ) # dummy instance to test else: - print('############################# lost entity: ',instance_id) - self.instanceMape[instance_id] = int(41) # dummy - #print "instance_attributes:",instance_attributes - #a = object_(*instance_attributes) + print("############################# lost entity: ", instance_id) + self.instanceMape[instance_id] = int(41) # dummy + # print "instance_attributes:",instance_attributes + # a = object_(*instance_attributes) - def _transformAttributes(self,attrList): + def _transformAttributes(self, attrList): n = 0 for i in attrList: - if isinstance(i,list): + if isinstance(i, list): self._transformAttributes(i) - elif isinstance(i,str): - if i == '': - print('empty string') - elif i[0] == '#': + elif isinstance(i, str): + if i == "": + print("empty string") + elif i[0] == "#": key = int(i[1:]) - #print 'Item: ',int(i[1:]) + # print 'Item: ',int(i[1:]) if key in self.instanceMape: - attrList[n] = self.instanceMape[key] + attrList[n] = self.instanceMape[key] else: self._create_entity_instance(key) if key not in self.instanceMape: - raise NameError("Needed instance not instantiated: ",key) + raise NameError("Needed instance not instantiated: ", key) else: - attrList[n] = self.instanceMape[key] - elif i[0] == '$': - #print 'Dollar' + attrList[n] = self.instanceMape[key] + elif i[0] == "$": + # print 'Dollar' pass elif i[0] == "'": - print('Dopelstring: ',i[1:-1]) + print("Dopelstring: ", i[1:-1]) else: - print('String: ',i) + print("String: ", i) else: raise NameError("Unknown attribute type") - n = n+1 + n = n + 1 + if __name__ == "__main__": - sys.path.append('..') # path where config_control_design.py is found - parser = SimpleReader("Aufspannung.stp") # simple test file - #parser.instantiate() - parser.writeGraphViz('TestGrap.gv') - #dot.exe -Tsvg -o Test.svg e:\fem-dev\src\Mod\Import\App\SCL\TestGrap-geo.gv + sys.path.append("..") # path where config_control_design.py is found + parser = SimpleReader("Aufspannung.stp") # simple test file + # parser.instantiate() + parser.writeGraphViz("TestGrap.gv") + # dot.exe -Tsvg -o Test.svg e:\fem-dev\src\Mod\Import\App\SCL\TestGrap-geo.gv diff --git a/src/Mod/Import/App/SCL/TypeChecker.py b/src/Mod/Import/App/SCL/TypeChecker.py index a4df44ca8d..cdfcb9ee02 100644 --- a/src/Mod/Import/App/SCL/TypeChecker.py +++ b/src/Mod/Import/App/SCL/TypeChecker.py @@ -23,7 +23,7 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF @@ -35,67 +35,89 @@ from . import BaseType RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH = True DEBUG = False + def cast_python_object_to_aggregate(obj, aggregate): - """ This function casts a python object to an aggregate type. For instance: + """This function casts a python object to an aggregate type. For instance: [1.,2.,3.]-> ARRAY(1,3,REAL)""" aggregate_lower_bound = aggregate.bound_1() aggregate_upper_bound = aggregate.bound_2() - if type(obj)==list: - for idx in range(aggregate_lower_bound,aggregate_upper_bound+1): - aggregate[idx] = obj[idx-aggregate_lower_bound] + if type(obj) == list: + for idx in range(aggregate_lower_bound, aggregate_upper_bound + 1): + aggregate[idx] = obj[idx - aggregate_lower_bound] return aggregate + def check_type(instance, expected_type): - """ This function checks whether an object is an instance of a given class + """This function checks whether an object is an instance of a given class returns False or True """ - type_match = False #by default, will be set to True if any match + type_match = False # by default, will be set to True if any match if DEBUG: print("===") - print("Instance passed: ",instance) + print("Instance passed: ", instance) print("Expected type: ", expected_type) # in the case of an enumeration, we have to check if the instance is in the list - if (isinstance(expected_type,ENUMERATION)): + if isinstance(expected_type, ENUMERATION): allowed_ids = expected_type.get_enum_ids() if instance in allowed_ids: type_match = True else: - raise TypeError('Enumeration ids must be %s ( passed %s)'%(allowed_ids,type(instance))) - elif (isinstance(expected_type,SELECT)): + raise TypeError( + "Enumeration ids must be %s ( passed %s)" % (allowed_ids, type(instance)) + ) + elif isinstance(expected_type, SELECT): # we check if the instance is of the type of any of the types that are in the SELECT allowed_types = expected_type.get_allowed_basic_types() for allowed_type in allowed_types: - if isinstance(instance,allowed_type): + if isinstance(instance, allowed_type): type_match = True if not type_match: if RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH: - raise TypeError('Argument type must be %s (you passed %s)'%(allowed_types,type(instance))) + raise TypeError( + "Argument type must be %s (you passed %s)" % (allowed_types, type(instance)) + ) else: - print("WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(allowed_types, type(instance))) + print( + "WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type" + % (allowed_types, type(instance)) + ) return False - elif (isinstance(expected_type, BaseType.Aggregate)): + elif isinstance(expected_type, BaseType.Aggregate): # first check that they are instance of the same class if not (type(instance) == type(expected_type)): - raise TypeError('Expected %s but passed %s'%(type(expected_type),type(instance))) + raise TypeError("Expected %s but passed %s" % (type(expected_type), type(instance))) # then check that the base type is the same elif not (instance.get_type() == expected_type.get_type()): - #print instance.get_type() - #print expected_type.get_type() - raise TypeError('Expected %s:%s base type but passed %s:%s base type'%(type(expected_type),expected_type.get_type(),type(instance), instance.get_type())) + # print instance.get_type() + # print expected_type.get_type() + raise TypeError( + "Expected %s:%s base type but passed %s:%s base type" + % ( + type(expected_type), + expected_type.get_type(), + type(instance), + instance.get_type(), + ) + ) # check optional and unique attributes - #elif not (instance._unique == expected_type._unique): + # elif not (instance._unique == expected_type._unique): # raise TypeError('Aggregate expects UNIQUE:%s property but passed UNIQUE:%s'%(expected_type._unique, instance._unique)) - #elif not (instance._optional == expected_type._optional): + # elif not (instance._optional == expected_type._optional): # raise TypeError('Aggregate expects OPTIONAL:%s property but passed OPTIONAL:%s'%(expected_type._optional, instance._optional)) # @TODO: check aggregate bounds else: type_match = True - else: # simple data types - type_match = isinstance(instance,expected_type) + else: # simple data types + type_match = isinstance(instance, expected_type) if not type_match: if RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH: - raise TypeError('Argument type must be %s (you passed %s)'%(expected_type,type(instance))) + raise TypeError( + "Argument type must be %s (you passed %s)" % (expected_type, type(instance)) + ) else: - print("WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(expected_type, type(instance))) + print( + "WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type" + % (expected_type, type(instance)) + ) return False return True diff --git a/src/Mod/Import/App/SCL/Utils.py b/src/Mod/Import/App/SCL/Utils.py index fc50f83b8e..4680acd9d6 100644 --- a/src/Mod/Import/App/SCL/Utils.py +++ b/src/Mod/Import/App/SCL/Utils.py @@ -23,48 +23,47 @@ # ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -''' This module provide string utils''' +""" This module provide string utils""" -def process_nested_parent_str(attr_str,idx=0): - ''' + +def process_nested_parent_str(attr_str, idx=0): + """ The first letter should be a parenthesis input string: "(1,4,(5,6),7)" output: ['1','4',['5','6'],'7'] - ''' + """ params = [] - current_param = '' + current_param = "" k = 0 - while (k 0) and (p.size_in_y > 0)): return p.size_in_x / p.size_in_y else: - return None + return None #################### # FUNCTION is_acyclic # @@ -41187,7 +41187,7 @@ def get_description_value(obj,): if (SIZEOF(description_bag) == 1): return description_bag[1].attribute_value else: - return None + return None #################### # FUNCTION constraints_param_b_spline # @@ -41392,7 +41392,7 @@ def cross_product(arg1,arg2,): :type arg2:direction ''' if ((( not EXISTS(arg1)) or (arg1.dim == 2)) or (( not EXISTS(arg2)) or (arg2.dim == 2))): - return None + return None else: # begin/end block v1 = normalise(arg1).direction_ratios @@ -41712,10 +41712,10 @@ def dot_product(arg1,arg2,): :type arg2:direction ''' if (( not EXISTS(arg1)) or ( not EXISTS(arg2))): - scalar = None + scalar = None else: if (arg1.dim != arg2.dim): - scalar = None + scalar = None else: # begin/end block vec1 = normalise(arg1) @@ -41737,7 +41737,7 @@ def get_role(obj,): if (SIZEOF(role_bag) == 1): return role_bag[1].role else: - return None + return None #################### # FUNCTION acyclic_curve_replica # diff --git a/src/Mod/Import/App/automotive_design.py b/src/Mod/Import/App/automotive_design.py index 61c42495f9..bd9d39e10a 100644 --- a/src/Mod/Import/App/automotive_design.py +++ b/src/Mod/Import/App/automotive_design.py @@ -40840,7 +40840,7 @@ def get_name_value(obj,): if (SIZEOF(name_bag) == 1): return name_bag[1].attribute_value else: - return None + return None #################### # FUNCTION convert_spatial_to_ypr_rotation # @@ -40863,7 +40863,7 @@ def convert_spatial_to_ypr_rotation(pair,rotation,): dz = axis.direction_ratios[3] conv_angle = plane_angle_for_pair_in_radian(pair,angle) if (conv_angle == None ): - return None + return None ucf = angle / conv_angle s_a = SIN(conv_angle) c_a = COS(conv_angle) @@ -40890,7 +40890,7 @@ def convert_spatial_to_ypr_rotation(pair,rotation,): ya = 0 ra = 0 else: - ya = ucf * PI + ya = ucf * PI ra = ya pa = ucf * ATAN(s_a,ABS(c_a)) if (dy < 0): @@ -40900,29 +40900,29 @@ def convert_spatial_to_ypr_rotation(pair,rotation,): rotmat = [[((dx * dx) * cm1) + c_a,((dx * dy) * cm1) - (dz * s_a),((dx * dz) * cm1) + (dy * s_a)],[((dx * dy) * cm1) + (dz * s_a),((dy * dy) * cm1) + c_a,((dy * dz) * cm1) - (dx * s_a)],[((dx * dz) * cm1) - (dy * s_a),((dy * dz) * cm1) + (dx * s_a),((dz * dz) * cm1) + c_a]] if (ABS(rotmat[1][3]) == 1): if (rotmat[1][3] == 1): - pa = 0.5 * PI + pa = 0.5 * PI else: - pa = (-0.5) * PI + pa = (-0.5) * PI ra = 0 ya = ATAN(rotmat[2][1],rotmat[2][2]) if (rotmat[2][2] < 0): if (ya <= 0): - ya = ya + PI + ya = ya + PI else: - ya = ya - PI + ya = ya - PI else: ya = ATAN(-rotmat[1][2],rotmat[1][1]) if (rotmat[1][1] < 0): if (ya <= 0): - ya = ya + PI + ya = ya + PI else: - ya = ya - PI + ya = ya - PI ra = ATAN(-rotmat[2][3],rotmat[3][3]) if (rotmat[3][3] < 0): if (ra <= 0): - ra = ra + PI + ra = ra + PI else: - ra = ra - PI + ra = ra - PI s_y = SIN(ya) c_y = COS(ya) s_r = SIN(ra) @@ -41187,7 +41187,7 @@ def get_diameter_for_round_hole(rh,): for l in range(1,HIINDEX(ri_set),1): if (('AUTOMOTIVE_DESIGN.MEASURE_REPRESENTATION_ITEM' == TYPEOF(ri_set[l])) and ('AUTOMOTIVE_DESIGN.LENGTH_MEASURE_WITH_UNIT' == TYPEOF(ri_set[l]))): return ri_set[l].measure_with_unit.value_component - return None + return None #################### # FUNCTION list_of_topology_reversed # @@ -41258,7 +41258,7 @@ def shell_reversed(a_shell,): if ('AUTOMOTIVE_DESIGN.CLOSED_SHELL' == TYPEOF(a_shell)): return closed_shell_reversed(a_shell) else: - return None + return None #################### # FUNCTION topology_reversed # @@ -41282,7 +41282,7 @@ def topology_reversed(an_item,): return set_of_topology_reversed(an_item) if ('LIST' == TYPEOF(an_item)): return list_of_topology_reversed(an_item) - return None + return None #################### # FUNCTION first_proj_axis # @@ -41295,7 +41295,7 @@ def first_proj_axis(z_axis,arg,): :type arg:direction ''' if ( not EXISTS(z_axis)): - return None + return None else: z = normalise(z_axis) if ( not EXISTS(arg)): @@ -41305,9 +41305,9 @@ def first_proj_axis(z_axis,arg,): v = dummy_gri == direction([0,1,0]) else: if (arg.dim != 3): - return None + return None if (cross_product(arg,z).magnitude == 0): - return None + return None else: v = normalise(arg) x_vec = scalar_times_vector(dot_product(v,z),z) @@ -41367,7 +41367,7 @@ def orthogonal_complement(vec,): :type vec:direction ''' if ((vec.dim != 2) or ( not EXISTS(vec))): - return None + return None else: result = dummy_gri == direction([-vec.direction_ratios[2],vec.direction_ratios[1]]) return result @@ -41404,13 +41404,13 @@ def make_array_of_array(lis,low1,u1,low2,u2,): :type u2:INTEGER ''' if (((u1 - low1) + 1) != SIZEOF(lis)): - return None + return None if (((u2 - low2) + 1) != SIZEOF(lis[1])): - return None + return None res = [list_to_array(lis[1],low2,u2),(u1 - low1) + 1] for i in range(2,HIINDEX(lis),1): if (((u2 - low2) + 1) != SIZEOF(lis[i])): - return None + return None res[(low1 + i) - 1] = list_to_array(lis[i],low2,u2) return res @@ -41515,7 +41515,7 @@ def vector_difference(arg1,arg2,): :type arg2:vector_or_direction ''' if ((( not EXISTS(arg1)) or ( not EXISTS(arg2))) or (arg1.dim != arg2.dim)): - return None + return None else: if ('AUTOMOTIVE_DESIGN.VECTOR' == TYPEOF(arg1)): mag1 = arg1.magnitude @@ -41712,7 +41712,7 @@ def list_to_array(lis,low,u,): ''' n = SIZEOF(lis) if (n != ((u - low) + 1)): - return None + return None else: res = [lis[1],n] for i in range(2,n,1): @@ -41933,7 +41933,7 @@ def scalar_times_vector(scalar,vec,): :type vec:vector_or_direction ''' if (( not EXISTS(scalar)) or ( not EXISTS(vec))): - return None + return None else: if ('AUTOMOTIVE_DESIGN.VECTOR' == TYPEOF(vec)): v = dummy_gri == direction(vec.vector.orientation.direction_ratios) @@ -42014,7 +42014,7 @@ def dimensions_for_si_unit(n,): elif case_selector == sievert: return dimensional_exponents(2,0,-2,0,0,0,0) else: - return None + return None #################### # FUNCTION assembly_shape_is_defined # @@ -42175,13 +42175,13 @@ def normalise(arg,): :type arg:vector_or_direction ''' if ( not EXISTS(arg)): - result = None + result = None else: ndim = arg.dim if ('AUTOMOTIVE_DESIGN.VECTOR' == TYPEOF(arg)): v = dummy_gri == direction(arg.vector.orientation.direction_ratios) if (arg.magnitude == 0): - return None + return None else: vec = dummy_gri == vector(v,1) else: @@ -42199,7 +42199,7 @@ def normalise(arg,): else: result = v else: - return None + return None return result #################### @@ -42370,7 +42370,7 @@ def get_id_value(obj,): if (SIZEOF(id_bag) == 1): return id_bag[1].attribute_value else: - return None + return None #################### # FUNCTION aspect_ratio # @@ -42383,7 +42383,7 @@ def aspect_ratio(p,): if ((p.size_in_x > 0) and (p.size_in_y > 0)): return p.size_in_x / p.size_in_y else: - return None + return None #################### # FUNCTION convert_plane_angle_for_pair_from_radian # @@ -42397,19 +42397,19 @@ def convert_plane_angle_for_pair_from_radian(pair,angle_expr,): ''' link_cntxt = link_rep.representation.context_of_items if ( not ('AUTOMOTIVE_DESIGN.GLOBAL_UNIT_ASSIGNED_CONTEXT' == TYPEOF(link_cntxt))): - return None + return None pa_units = None if (SIZEOF(pa_units) != 1): - return None + return None pau = pa_units[1] if (( not ('AUTOMOTIVE_DESIGN.SI_UNIT' == TYPEOF(pau))) and ( not ('AUTOMOTIVE_DESIGN.CONVERSION_BASED_UNIT' == TYPEOF(pau)))): - return None + return None for while 'AUTOMOTIVE_DESIGN.CONVERSION_BASED_UNIT' == TYPEOF(pau) conv_factor = conv_factor * pau.conversion_based_unit.conversion_factor.value_component pau = pau.conversion_based_unit.conversion_factor.unit_component if ((( not ('AUTOMOTIVE_DESIGN.SI_UNIT' == TYPEOF(pau))) and ( not ('AUTOMOTIVE_DESIGN.CONVERSION_BASED_UNIT' == TYPEOF(pau)))) or ( not ('AUTOMOTIVE_DESIGN.PLANE_ANGLE_UNIT' == TYPEOF(pau)))): - return None + return None if (pau.si_unit.name != si_unit_name.radian): - return None + return None case_selector = pau.si_unit.prefix if case_selector == si_prefix.exa: conv_factor = 1e+018 * conv_factor @@ -42506,7 +42506,7 @@ def get_description_value(obj,): if (SIZEOF(description_bag) == 1): return description_bag[1].attribute_value else: - return None + return None #################### # FUNCTION constraints_param_b_spline # @@ -42597,7 +42597,7 @@ def representation_of_link(link,): ''' link_rep_rel = USEDIN(link,'AUTOMOTIVE_DESIGN.KINEMATIC_LINK_REPRESENTATION_RELATION.TOPOLOGICAL_ASPECTS') if (SIZEOF(link_rep_rel) == 0): - return None + return None else: return link_rep_rel[1].geometric_aspects @@ -42616,7 +42616,7 @@ def ypr_index(ypr,): return 2 elif case_selector == roll: return 3 - return None + return None #################### # FUNCTION acyclic_mapped_item_usage # @@ -42649,19 +42649,19 @@ def plane_angle_for_pair_in_radian(pair,angle,): ''' link_cntxt = link_rep.representation.context_of_items if ( not ('AUTOMOTIVE_DESIGN.GLOBAL_UNIT_ASSIGNED_CONTEXT' == TYPEOF(link_cntxt))): - return None + return None pa_units = None if (SIZEOF(pa_units) != 1): - return None + return None pau = pa_units[1] if (( not ('AUTOMOTIVE_DESIGN.SI_UNIT' == TYPEOF(pau))) and ( not ('AUTOMOTIVE_DESIGN.CONVERSION_BASED_UNIT' == TYPEOF(pau)))): - return None + return None for while 'AUTOMOTIVE_DESIGN.CONVERSION_BASED_UNIT' == TYPEOF(pau) converted_angle = converted_angle * pau.conversion_based_unit.conversion_factor.value_component pau = pau.conversion_based_unit.conversion_factor.unit_component if ((( not ('AUTOMOTIVE_DESIGN.SI_UNIT' == TYPEOF(pau))) and ( not ('AUTOMOTIVE_DESIGN.CONVERSION_BASED_UNIT' == TYPEOF(pau)))) or ( not ('AUTOMOTIVE_DESIGN.PLANE_ANGLE_UNIT' == TYPEOF(pau)))): - return None + return None if (pau.si_unit.name != si_unit_name.radian): - return None + return None case_selector = pau.si_unit.prefix if case_selector == si_prefix.exa: return 1e+018 * converted_angle @@ -42708,7 +42708,7 @@ def get_multi_language(x,): ''' if (SIZEOF(alas) > 0): return alas[1].language - return None + return None #################### # FUNCTION unique_link_usage # @@ -42806,7 +42806,7 @@ def cross_product(arg1,arg2,): :type arg2:direction ''' if (((( not EXISTS(arg1)) or (arg1.dim == 2)) or ( not EXISTS(arg2))) or (arg2.dim == 2)): - return None + return None else: v1 = normalise(arg1).direction_ratios v2 = normalise(arg2).direction_ratios @@ -43138,10 +43138,10 @@ def dot_product(arg1,arg2,): :type arg2:direction ''' if (( not EXISTS(arg1)) or ( not EXISTS(arg2))): - scalar = None + scalar = None else: if (arg1.dim != arg2.dim): - scalar = None + scalar = None else: vec1 = normalise(arg1) vec2 = normalise(arg2) @@ -43162,7 +43162,7 @@ def get_role(obj,): if (SIZEOF(role_bag) == 1): return role_bag[1].role else: - return None + return None #################### # FUNCTION acyclic_curve_replica # diff --git a/src/Mod/Import/App/ifc2x3.py b/src/Mod/Import/App/ifc2x3.py index 64d5b94beb..c4cc420275 100644 --- a/src/Mod/Import/App/ifc2x3.py +++ b/src/Mod/Import/App/ifc2x3.py @@ -35949,7 +35949,7 @@ def ifcnormalise(arg,): :type arg:ifcvectorordirection ''' if ( not EXISTS(arg)): - return None + return None else: ndim = arg.dim if ('IFC2X3.IFCVECTOR' == TYPEOF(arg)): @@ -35958,7 +35958,7 @@ def ifcnormalise(arg,): vec.magnitude = arg.ifcvector.magnitude vec.orientation = v if (arg.magnitude == 0): - return None + return None else: vec.magnitude = 1 else: @@ -35976,7 +35976,7 @@ def ifcnormalise(arg,): else: result = v else: - return None + return None return result #################### @@ -36033,7 +36033,7 @@ def ifcvectorsum(arg1,arg2,): :type arg2:ifcvectorordirection ''' if ((( not EXISTS(arg1)) or ( not EXISTS(arg2))) or (arg1.dim != arg2.dim)): - return None + return None else: # begin/end block if ('IFC2X3.IFCVECTOR' == TYPEOF(arg1)): @@ -36073,7 +36073,7 @@ def ifcvectordifference(arg1,arg2,): :type arg2:ifcvectorordirection ''' if ((( not EXISTS(arg1)) or ( not EXISTS(arg2))) or (arg1.dim != arg2.dim)): - return None + return None else: # begin/end block if ('IFC2X3.IFCVECTOR' == TYPEOF(arg1)): @@ -36114,7 +36114,7 @@ def ifccorrectlocalplacement(axisplacement,relplacement,): ''' if (EXISTS(relplacement)): if ('IFC2X3.IFCGRIDPLACEMENT' == TYPEOF(relplacement)): - return None + return None if ('IFC2X3.IFCLOCALPLACEMENT' == TYPEOF(relplacement)): if ('IFC2X3.IFCAXIS2PLACEMENT2D' == TYPEOF(axisplacement)): return TRUE @@ -36125,7 +36125,7 @@ def ifccorrectlocalplacement(axisplacement,relplacement,): return FALSE else: return TRUE - return None + return None #################### # FUNCTION ifccorrectfillareastyle # @@ -36185,7 +36185,7 @@ def ifccurvedim(curve,): return 2 if ('IFC2X3.IFCOFFSETCURVE3D' == TYPEOF(curve)): return 3 - return None + return None #################### # FUNCTION ifcsamedirection # @@ -36219,7 +36219,7 @@ def ifclisttoarray(lis,low,u,): ''' n = SIZEOF(lis) if (n != ((u - low) + 1)): - return None + return None else: res = [lis[1],n] for i in range(2,n,1): @@ -36268,7 +36268,7 @@ def ifctopologyrepresentationtypes(reptype,items,): elif case_selector == 'Undefined': return TRUE else: - return None + return None return count == SIZEOF(items) #################### @@ -36300,10 +36300,10 @@ def ifcdotproduct(arg1,arg2,): :type arg2:ifcdirection ''' if (( not EXISTS(arg1)) or ( not EXISTS(arg2))): - scalar = None + scalar = None else: if (arg1.dim != arg2.dim): - scalar = None + scalar = None else: # begin/end block vec1 = ifcnormalise(arg1) @@ -36344,7 +36344,7 @@ def ifcfirstprojaxis(zaxis,arg,): :type arg:ifcdirection ''' if ( not EXISTS(zaxis)): - return None + return None else: z = ifcnormalise(zaxis) if ( not EXISTS(arg)): @@ -36354,9 +36354,9 @@ def ifcfirstprojaxis(zaxis,arg,): v = (ifcrepresentationitem() == ifcgeometricrepresentationitem()) == ifcdirection([0,1,0]) else: if (arg.dim != 3): - return None + return None if (ifccrossproduct(arg,z).magnitude == 0): - return None + return None else: v = ifcnormalise(arg) xvec = ifcscalartimesvector(ifcdotproduct(v,z),z) @@ -36424,7 +36424,7 @@ def ifcshaperepresentationtypes(reptype,items,): # begin/end block count = SIZEOF(None) else: - return None + return None return count == SIZEOF(items) #################### @@ -36509,7 +36509,7 @@ def ifcscalartimesvector(scalar,vec,): :type vec:ifcvectorordirection ''' if (( not EXISTS(scalar)) or ( not EXISTS(vec))): - return None + return None else: if ('IFC2X3.IFCVECTOR' == TYPEOF(vec)): v = vec.ifcvector.orientation @@ -36583,7 +36583,7 @@ def ifcorthogonalcomplement(vec,): :type vec:ifcdirection ''' if (( not EXISTS(vec)) or (vec.dim != 2)): - return None + return None else: result = (ifcrepresentationitem() == ifcgeometricrepresentationitem()) == ifcdirection([-vec.directionratios[2],vec.directionratios[1]]) return result @@ -36889,7 +36889,7 @@ def ifccorrectobjectassignment(constraint,objects,): count = SIZEOF(None) return count == 0 else: - return None + return None #################### # FUNCTION ifcvalidcalendardate # @@ -36968,7 +36968,7 @@ def ifccrossproduct(arg1,arg2,): :type arg2:ifcdirection ''' if ((( not EXISTS(arg1)) or (arg1.dim == 2)) or (( not EXISTS(arg2)) or (arg2.dim == 2))): - return None + return None else: # begin/end block v1 = ifcnormalise(arg1).directionratios diff --git a/src/Mod/Import/App/ifc4.py b/src/Mod/Import/App/ifc4.py index 5f60cd3068..396814f622 100644 --- a/src/Mod/Import/App/ifc4.py +++ b/src/Mod/Import/App/ifc4.py @@ -42688,7 +42688,7 @@ def ifcnormalise(arg,): :type arg:ifcvectorordirection ''' if ( not EXISTS(arg)): - return None + return None else: if ('IFC4.IFCVECTOR' == TYPEOF(arg)): # begin/end block @@ -42697,7 +42697,7 @@ def ifcnormalise(arg,): vec.magnitude = arg.ifcvector.magnitude vec.orientation = v if (arg.ifcvector.magnitude == 0): - return None + return None else: vec.magnitude = 1 else: @@ -42717,7 +42717,7 @@ def ifcnormalise(arg,): else: result = v else: - return None + return None return result #################### @@ -42796,7 +42796,7 @@ def ifcvectorsum(arg1,arg2,): :type arg2:ifcvectorordirection ''' if ((( not EXISTS(arg1)) or ( not EXISTS(arg2))) or (arg1.dim != arg2.dim)): - return None + return None else: # begin/end block if ('IFC4.IFCVECTOR' == TYPEOF(arg1)): @@ -42836,7 +42836,7 @@ def ifcvectordifference(arg1,arg2,): :type arg2:ifcvectorordirection ''' if ((( not EXISTS(arg1)) or ( not EXISTS(arg2))) or (arg1.dim != arg2.dim)): - return None + return None else: # begin/end block if ('IFC4.IFCVECTOR' == TYPEOF(arg1)): @@ -42877,7 +42877,7 @@ def ifccorrectlocalplacement(axisplacement,relplacement,): ''' if (EXISTS(relplacement)): if ('IFC4.IFCGRIDPLACEMENT' == TYPEOF(relplacement)): - return None + return None if ('IFC4.IFCLOCALPLACEMENT' == TYPEOF(relplacement)): if ('IFC4.IFCAXIS2PLACEMENT2D' == TYPEOF(axisplacement)): return TRUE @@ -42888,7 +42888,7 @@ def ifccorrectlocalplacement(axisplacement,relplacement,): return FALSE else: return TRUE - return None + return None #################### # FUNCTION ifccorrectfillareastyle # @@ -42953,13 +42953,13 @@ def ifcmakearrayofarray(lis,low1,u1,low2,u2,): :type u2:INTEGER ''' if (((u1 - low1) + 1) != SIZEOF(lis)): - return None + return None if (((u2 - low2) + 1) != SIZEOF(lis[1])): - return None + return None res = [ifclisttoarray(lis[1],low2,u2),(u1 - low1) + 1] for i in range(2,HIINDEX(lis),1): if (((u2 - low2) + 1) != SIZEOF(lis[i])): - return None + return None res[(low1 + i) - 1] = ifclisttoarray(lis[i],low2,u2) return res @@ -42989,7 +42989,7 @@ def ifccurvedim(curve,): return 3 if ('IFC4.IFCPCURVE' == TYPEOF(curve)): return 3 - return None + return None #################### # FUNCTION ifcsamedirection # @@ -43023,7 +43023,7 @@ def ifclisttoarray(lis,low,u,): ''' n = SIZEOF(lis) if (n != ((u - low) + 1)): - return None + return None else: res = [lis[1],n] for i in range(2,n,1): @@ -43059,7 +43059,7 @@ def ifctopologyrepresentationtypes(reptype,items,): elif case_selector == 'Undefined': return TRUE else: - return None + return None return count == SIZEOF(items) #################### @@ -43091,10 +43091,10 @@ def ifcdotproduct(arg1,arg2,): :type arg2:ifcdirection ''' if (( not EXISTS(arg1)) or ( not EXISTS(arg2))): - scalar = None + scalar = None else: if (arg1.dim != arg2.dim): - scalar = None + scalar = None else: # begin/end block vec1 = ifcnormalise(arg1) @@ -43116,7 +43116,7 @@ def ifcfirstprojaxis(zaxis,arg,): :type arg:ifcdirection ''' if ( not EXISTS(zaxis)): - return None + return None else: z = ifcnormalise(zaxis) if ( not EXISTS(arg)): @@ -43126,9 +43126,9 @@ def ifcfirstprojaxis(zaxis,arg,): v = (ifcrepresentationitem() == ifcgeometricrepresentationitem()) == ifcdirection([0,1,0]) else: if (arg.dim != 3): - return None + return None if (ifccrossproduct(arg,z).magnitude == 0): - return None + return None else: v = ifcnormalise(arg) xvec = ifcscalartimesvector(ifcdotproduct(v,z),z) @@ -43238,7 +43238,7 @@ def ifcshaperepresentationtypes(reptype,items,): # begin/end block count = SIZEOF(None) else: - return None + return None return count == SIZEOF(items) #################### @@ -43323,7 +43323,7 @@ def ifcscalartimesvector(scalar,vec,): :type vec:ifcvectorordirection ''' if (( not EXISTS(scalar)) or ( not EXISTS(vec))): - return None + return None else: if ('IFC4.IFCVECTOR' == TYPEOF(vec)): v = vec.ifcvector.orientation @@ -43428,7 +43428,7 @@ def ifcorthogonalcomplement(vec,): :type vec:ifcdirection ''' if (( not EXISTS(vec)) or (vec.dim != 2)): - return None + return None else: result = (ifcrepresentationitem() == ifcgeometricrepresentationitem()) == ifcdirection([-vec.directionratios[2],vec.directionratios[1]]) return result @@ -43734,7 +43734,7 @@ def ifccorrectobjectassignment(constraint,objects,): count = SIZEOF(None) return count == 0 else: - return None + return None #################### # FUNCTION ifccurveweightspositive # @@ -43824,7 +43824,7 @@ def ifccrossproduct(arg1,arg2,): :type arg2:ifcdirection ''' if ((( not EXISTS(arg1)) or (arg1.dim == 2)) or (( not EXISTS(arg2)) or (arg2.dim == 2))): - return None + return None else: # begin/end block v1 = ifcnormalise(arg1).ifcdirection.directionratios diff --git a/src/Mod/Import/DxfPlate/blocks10.rub b/src/Mod/Import/DxfPlate/blocks10.rub index 31d5f12ed3..cd0eed6f9a 100644 --- a/src/Mod/Import/DxfPlate/blocks10.rub +++ b/src/Mod/Import/DxfPlate/blocks10.rub @@ -19,6 +19,6 @@ BLOCK 3 *MODEL_SPACE 1 - + 0 ENDBLK diff --git a/src/Mod/Import/DxfPlate/tables112.rub b/src/Mod/Import/DxfPlate/tables112.rub index 4d9e1b1cf7..c86e1526c0 100644 --- a/src/Mod/Import/DxfPlate/tables112.rub +++ b/src/Mod/Import/DxfPlate/tables112.rub @@ -67,6 +67,6 @@ txt 42 1 4 - + 0 ENDTAB diff --git a/src/Mod/Import/Resources/Import.qrc b/src/Mod/Import/Resources/Import.qrc index e041b2aec2..55b1e3e31b 100644 --- a/src/Mod/Import/Resources/Import.qrc +++ b/src/Mod/Import/Resources/Import.qrc @@ -1,5 +1,5 @@ - + ui/preferences-import.ui - +