def expand_product(shape_tool, product, shapes_simples, deep, doc_id, product_root, product_id, file_path): """ :param shape_tool: :class:`.OCC.XCAFDoc.XCAFDoc_ShapeTool` :param product: :class:`.Product` that will be expanded :param shapes_simples: list of :class:`.SimpleShape` :param deep: Depth of the node that we explore :param doc_id: id that references a :class:`.DocumentFile` of which we are generating the :class:`.Product` :param product_root: :class:`.Product` root of the arborescense We are going to expand a :class:`.Product` (**product**) from the :class:`.OCC.TDF.TDF_Label` who identifies it (**product**.label_reference) If the **product** is an assembly: * We generate the **list** of the :class:`.OCC.TDF.TDF_Label` that define it * for each :class:`.OCC.TDF.TDF_Label` in **list**: - We generate a new :class:`.document3D.classes.Link` or if two or more :class:`.OCC.TDF.TDF_Label` of the list are partner, add an occurrence extra to the :class:`.document3D.classes.Link` that already was generated - The :class:`.document3D.classes.Link` is going to point at a new :class:`.Product` or, if the :class:`.Product` is already present in **product_root**, at the already definite product - If the :class:`.document3D.classes.Link` pointed at a new :class:`.Product` we need to expand it * The atribute **label_reference** of the new :class:`.Product` should be the :class:`.OCC.TDF.TDF_Label` * We expand the :class:`.Product` in a recursive call of method Else the **product** is a simple shape: * We look in the list of **shapes_simples** for his partner * We set the attribute **product**.geometry like the index+1 (>0) of the position of his partner in the list of **SimpleShape** """ if shape_tool.IsAssembly(product.label_reference): l_c = TDF_LabelSequence() shape_tool.GetComponents(product.label_reference, l_c) for i in range(l_c.Length()): label = l_c.Value(i + 1) if shape_tool.IsReference(label): label_reference = TDF_Label() shape_tool.GetReferredShape(label, label_reference) reference_found = False matrix = TransformationMatrix( get_matrix(shape_tool.GetLocation(label).Transformation())) shape = shape_tool.GetShape(label_reference) for link in product.links: if shape_tool.GetShape( link.product.label_reference).IsPartner(shape): link.add_occurrence(get_label_name(label), matrix) reference_found = True break if not reference_found: new_product = Product(get_label_name(label_reference), deep, label_reference, doc_id, product_id[0], file_path) product_assembly = search_assembly(new_product, product_root) if product_assembly: product.links.append(Link(product_assembly)) else: product.links.append(Link(new_product)) product_id[0] += 1 expand_product(shape_tool, new_product, shapes_simples, deep + 1, doc_id, product_root, product_id, file_path) product.links[-1].add_occurrence(get_label_name(label), matrix) else: compShape = shape_tool.GetShape(product.label_reference) for index in range(len(shapes_simples)): if compShape.IsPartner(shapes_simples[index].shape): product.set_geometry(index + 1) #to avoid index==0
from datetime import datetime from openpyxl import load_workbook from classes import Product, Review from mapping import PRODUCT_ID, PRODUCT_PARENT, PRODUCT_TITLE,\ PRODUCT_CATEGORY, REVIEW_DATE, REVIEW_ID, REVIEW_CUSTOMER,\ REVIEW_STARS, REVIEW_HEADLINE, REVIEW_BODY wb = load_workbook(filename='reviews-sample.xlsx', read_only=True) sheet = wb.active products = [] reviews = [] for row in sheet.iter_rows(min_row=2, values_only=True): product = Product(id=row[PRODUCT_ID], parent=row[PRODUCT_PARENT], title=row[PRODUCT_TITLE], category=row[PRODUCT_CATEGORY]) products.append(product) spread_date = row[REVIEW_DATE] parsed_date = datetime.strptime(spread_date, '%Y-%m-%d') review = Review(id=row[PRODUCT_ID], customer_id=row[REVIEW_CUSTOMER], stars=row[REVIEW_STARS], headline=row[REVIEW_HEADLINE], body=row[REVIEW_BODY], date=parsed_date) reviews.append(review) print(products[0])