Skip to content

Commit ee78ba9

Browse files
committed
Moved AggregationDataType module name to AggregationDataTypes
1 parent 575c77d commit ee78ba9

10 files changed

Lines changed: 190 additions & 28 deletions

File tree

File renamed without changes.

src/fedex_python/python/SCL/Expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def EvalDerivedAttribute(class_instance, str_expr):
5959
for item in props:
6060
str_expr = str_expr.replace(item,"class_instance.%s"%item)
6161
# after that step, the expression should be:
62-
# PI*class_instance.radiüs*class_instance.radius
62+
# PI*class_instance.radius*class_instance.radius
6363
# this can be evaluated with the eval function
6464
# CAREFUL: eval is known to be unsafe. This should be changed in the future
6565
# (using a parser, or simpy for instance)

src/fedex_python/python/SCL/Part21.py

Lines changed: 95 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,27 @@ def print_instances(self):
6767
"=========="
6868
print "Instance #%i"%(idx+1)
6969
print self._instances[idx]
70-
71-
class Part21Loader:
70+
71+
class Part21EntityInstance:
72+
"""
73+
A class to represent a Part21 instance as defined in one Part21 file
74+
A Part21EntityInstance is defined by the following arguments:
75+
entity_name: a string
76+
entity_attributes: a list of strings to represent an attribute.
77+
For instance, the following expression:
78+
#4 = PRODUCT_DEFINITION_SHAPE('$','$',#5);
79+
will result in :
80+
entity : <class 'config_control_design.product_definition_shape'>
81+
entity_instance_attributes: ['$','$','#5']
82+
"""
83+
def __init__(self,entity_name,attributes):
84+
self._entity
85+
self._attributes_definition = attributes
86+
print self._entity_name
87+
print self._attributes_definition
88+
89+
90+
class Part21Parser:
7291
"""
7392
Loads all instances definition of a Part21 file into memory.
7493
Two dicts are created:
@@ -79,31 +98,65 @@ class Part21Loader:
7998
def __init__(self, filename):
8099
self._filename = filename
81100
# the schema
82-
self._schema = ""
101+
self._schema_name = ""
83102
# the dict self._instances contain instance definition
84103
self._instances_definition = {}
85104
# this dict contains lists of 0 ancestors, 1 ancestor, etc.
86105
# initializes this dict
87106
self._number_of_ancestors = {}
88107
for i in range(2000):
89108
self._number_of_ancestors[i]=[]
90-
print "Parsing file %s..."%filename,
91109
self.parse_file()
92-
print "done."
93110
# reduce number_of_ancestors dict
94111
for item in self._number_of_ancestors.keys():
95112
if len(self._number_of_ancestors[item])==0:
96113
del self._number_of_ancestors[item]
97114

98-
def get_schema(self):
99-
return self._schema
115+
def get_schema_name(self):
116+
return self._schema_name
117+
print schema_name
100118

101119
def get_number_of_instances(self):
102120
return len(self._instances_definition.keys())
103-
121+
122+
def parse_attributes(self, attr_str):
123+
"""
124+
This method takes a string an returns a list of attributes (but without any mapping).
125+
For instance:
126+
input = "'',(#11,#15,#19,#23,#27),#31"
127+
output = ['',(#11,#15,#19,#23,#27),'#31']
128+
"""
129+
aggr_scope_level = 0
130+
attrs = []
131+
current_attr = ''
132+
previous_ch = ''
133+
for ch in attr_str:
134+
if ch == ',' and aggr_scope_level == 0:
135+
attrs.append(current_attr)
136+
current_attr = ''
137+
else:
138+
if ch == '(':
139+
aggr_scope_level +=1
140+
elif ch == ')':
141+
aggr_scope_level -= 1
142+
current_attr += ch
143+
previous_ch = ch
144+
# finally add the last attr when exiting loop
145+
attrs.append(current_attr)
146+
return attrs
147+
104148
def parse_file(self):
149+
init_time = time.time()
150+
print "Parsing file %s..."%self._filename,
105151
fp = open(self._filename)
106-
for line in fp:
152+
while True:
153+
line = fp.readline()
154+
if not line:
155+
break
156+
# there may be a multline definition. In this case, we read lines untill we found
157+
# a ;
158+
while (not line.endswith(";\r\n")): #its a multiline
159+
line = line.replace("\r\n","") + fp.readline()
107160
# parse line
108161
match_instance_definition = INSTANCE_DEFINITION_RE.search(line) # id,name,attrs
109162
if match_instance_definition:
@@ -113,13 +166,33 @@ def parse_file(self):
113166
number_of_ancestors = entity_attrs.count('#')
114167
# fill number of ancestors dict
115168
self._number_of_ancestors[number_of_ancestors].append(instance_int_id)
116-
self._instances_definition[instance_int_id] = [entity_name,entity_attrs]
169+
# parse attributes string
170+
entity_attrs_list = self.parse_attributes(entity_attrs)
171+
# then finally append this instance to the disct instance
172+
self._instances_definition[instance_int_id] = (entity_name,entity_attrs_list)
117173
else: #does not match with entity instance definition, parse the header
118174
if line.startswith('FILE_SCHEMA'):
119175
#identify the schema name
120-
self._schema = line.split("'")[1].split("'")[0].split(" ")[0].lower()
176+
self._schema_name = line.split("'")[1].split("'")[0].split(" ")[0].lower()
121177
fp.close()
122-
178+
print 'done in %fs.'%(time.time()-init_time)
179+
print 'schema: - %s entities %i'%(self._schema_name,len(self._instances_definition.keys()))
180+
181+
class EntityInstancesFactory(object):
182+
'''
183+
This class creates entity instances from the str definition
184+
For instance, the definition:
185+
20: ('CARTESIAN_POINT', ["''", '(5.,125.,20.)'])
186+
will result in:
187+
p = ARRAY(1,3,REAL)
188+
p.[1]=REAL(5)
189+
p.[2] = REAL(125)
190+
p.[3] = REAL(20)
191+
new_instance = cartesian_point(STRING(''),p)
192+
'''
193+
def __init__(self, schema_name, instance_definition):
194+
# First try to import the schema module
195+
pass
123196
class Part21Population(object):
124197
def __init__(self, part21_loader):
125198
""" Take a part21_loader a tries to create entities
@@ -185,19 +258,15 @@ def map_express_to_python(self,attr):
185258
if __name__ == "__main__":
186259
import time
187260
import sys
188-
sys.path.append("..")
189-
from config_control_design import *
190-
t1 = time.time()
191-
print "Loading file into memory"
192-
#file = Part21Loader("as1-oc-214.stp")
261+
#sys.path.append("..")
262+
#from config_control_design import *
263+
#p21loader = Part21Loader("as1-oc-214.stp")
193264
#file = Part21Loader("as1-tu-203.stp")
194265
#file = Part21Loader("HAYON.stp")
195-
p21loader = Part21Loader("as1.stp")
196-
t2 = time.time()
197-
print "Loading schema took: %s s \n" % ((t2-t1))
198-
t1 = time.time()
199-
print "Creating instances"
200-
p21population = Part21Population(p21loader)
201-
p21population.create_entity_instances()
202-
t2 = time.time()
203-
print "Creating instances took: %s s \n" % ((t2-t1))
266+
p21loader = Part21Parser("as1.stp")
267+
print p21loader._instances_definition
268+
#print "Creating instances"
269+
#p21population = Part21Population(p21loader)
270+
#p21population.create_entity_instances()
271+
#t2 = time.time()
272+
#print "Creating instances took: %s s \n" % ((t2-t1))
7.04 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__all__ = ['SCLBase','SimpleDataTypes','AggregationDataType','TypeChecker','ConstructedDataTypes','Expr','Part21']
258 Bytes
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
ISO-10303-21;
2+
HEADER;
3+
FILE_DESCRIPTION(('Open CASCADE Model'),'2;1');
4+
FILE_NAME('Open CASCADE Shape Model','2008-07-24T15:00:20',(
5+
'--- Datakit Converter ---'),('--- Datakit www.datakit.com---'),
6+
' Release Version Jun 30 2008','Open CASCADE 6.1',' ');
7+
FILE_SCHEMA(('AUTOMOTIVE_DESIGN { 1 0 10303 214 1 1 1 1 }'));
8+
ENDSEC;
9+
DATA;
10+
#1 = APPLICATION_PROTOCOL_DEFINITION('international standard',
11+
'automotive_design',2000,#2);
12+
#2 = APPLICATION_CONTEXT(
13+
'core data for automotive mechanical design processes');
14+
#3 = SHAPE_DEFINITION_REPRESENTATION(#4,#10);
15+
#4 = PRODUCT_DEFINITION_SHAPE('$','$',#5);
16+
#5 = PRODUCT_DEFINITION('design','',#6,#9);
17+
#6 = PRODUCT_DEFINITION_FORMATION('','',#7);
18+
#7 = PRODUCT('as1','as1','',(#8));
19+
#8 = PRODUCT_CONTEXT('',#2,'mechanical');
20+
#9 = PRODUCT_DEFINITION_CONTEXT('part definition',#2,'design');
21+
#10 = SHAPE_REPRESENTATION('',(#11,#15,#19,#23,#27),#31);
22+
#11 = AXIS2_PLACEMENT_3D('',#12,#13,#14);
23+
#12 = CARTESIAN_POINT('',(0.E+000,0.E+000,0.E+000));
24+
#13 = DIRECTION('',(0.E+000,0.E+000,1.));
25+
#14 = DIRECTION('',(1.,0.E+000,0.E+000));
26+
#15 = AXIS2_PLACEMENT_3D('',#16,#17,#18);
27+
#16 = CARTESIAN_POINT('',(-10.,75.,60.));
28+
#17 = DIRECTION('',(1.,0.E+000,0.E+000));
29+
#18 = DIRECTION('',(0.E+000,0.E+000,-1.));
30+
#19 = AXIS2_PLACEMENT_3D('',#20,#21,#22);
31+
#20 = CARTESIAN_POINT('',(5.,125.,20.));
32+
#21 = DIRECTION('',(0.E+000,0.E+000,1.));
33+
#22 = DIRECTION('',(1.,0.E+000,0.E+000));
34+
ENDSEC;
35+
END-ISO-10303-21;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
def process_nested_parent_str(attr_str):
2+
'''
3+
The first letter should be a parenthesis
4+
input string: "(1,4,(5,6),7)"
5+
output: tuple (1,4,(4,6),7)
6+
'''
7+
params = []
8+
agg_scope_level = 0
9+
current_param = ''
10+
for i,ch in enumerate(attr_str):
11+
if ch==',':
12+
params.append(current_param)
13+
current_param = ''
14+
elif ch=='(':
15+
agg_scope_level +=1
16+
elif ch==')':
17+
agg_scope_level = 0
18+
elif agg_scope_level == 0:
19+
current_param += ch
20+
return params
21+
22+
idx = 0
23+
def process_nested_parent_str2(attr_str):
24+
'''
25+
The first letter should be a parenthesis
26+
input string: "(1,4,(5,6),7)"
27+
output: ['1','4',['5','6'],'7']
28+
'''
29+
global idx
30+
acc=0
31+
print 'Entering function with string %s and index %i'%(attr_str,idx)
32+
params = []
33+
current_param = ''
34+
for i,ch in enumerate(attr_str):
35+
idx += 1
36+
acc +=1
37+
if ch==',':
38+
params.append(current_param)
39+
current_param = ''
40+
elif ch=='(':
41+
nv = attr_str[idx:]
42+
print "params",params
43+
print "Str passed to the function:%s (idx=%i)"%(nv,idx)
44+
current_param = process_nested_parent_str2(nv)
45+
elif ch==')':
46+
params.append(current_param)
47+
idx -= acc+1
48+
return params
49+
else:
50+
current_param += ch
51+
params.append(current_param)
52+
return params
53+
#print process_nested_parent_str2('1,2,3,4,5,6')
54+
print process_nested_parent_str2("'A','B',('C','D'),'E'")

src/fedex_python/python/SCL_unittest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def test_create_array(self):
160160
else:
161161
self.fail('ExpectedException not thrown')
162162

163+
def test_array_bounds(self):
164+
a = ARRAY()
165+
163166
def test_array_unique(self):
164167
# if UNIQUE is not set to True (False by default),
165168
# the array may contain the same instance at different

src/fedex_python/src/classes_wrapper_python.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol,
350350
fprintf(libfile,"from SCL.SCLBase import *\n");
351351
fprintf(libfile,"from SCL.SimpleDataTypes import *\n");
352352
fprintf(libfile,"from SCL.ConstructedDataTypes import *\n");
353-
fprintf(libfile,"from SCL.AggregationDataType import *\n");
353+
fprintf(libfile,"from SCL.AggregationDataTypes import *\n");
354354
fprintf(libfile,"from SCL.TypeChecker import check_type\n");
355355
fprintf(libfile,"from SCL.Expr import *\n");
356356

0 commit comments

Comments
 (0)