Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an array iterator for *Array1* classes - Fixes issue #29 #48

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/generate_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,44 @@ def process_classes(classes_dict, exclude_classes, exclude_member_functions):
# Extend class by GetHandle method
class_def_str += '%%make_alias(%s)\n\n' % class_name

# All "Array1" classes are considered as python arrays
if 'Array1' in class_name:
class_def_str += """
%%extend %s {
%%pythoncode {
def __getitem__(self, index):
if index + self.Lower() > self.Upper():
raise IndexError("index out of range")
else:
return self.Value(index + self.Lower())

def __setitem__(self, index, value):
if index + self.Lower() > self.Upper():
raise IndexError("index out of range")
else:
self.SetValue(index + self.Lower(), value)

def __len__(self):
return self.Length()

def __iter__(self):
self.low = self.Lower()
self.up = self.Upper()
self.current = self.Lower() - 1
return self

def next(self):
if self.current >= self.Upper():
raise StopIteration
else:
self.current +=1
return self.Value(self.current)

__next__ = next

}
};
""" % class_name
# We add pickling for TopoDS_Shapes
if class_name == 'TopoDS_Shape':
class_def_str += '%extend TopoDS_Shape {\n%pythoncode {\n'
Expand Down