def update_naming(self, make_shape): label = self.label shape = make_shape.Shape() input_shape = make_shape.Shape1() tool_shape = make_shape.Shape2() builder = TNaming.TNaming_Builder(label) builder.Generated(input_shape, shape) builder.Generated(tool_shape, shape) gen_label = label.FindChild(1) mod_label = label.FindChild(2) del_label = label.FindChild(3) gen_builder = TNaming.TNaming_Builder(gen_label) mod_builder = TNaming.TNaming_Builder(mod_label) del_builder = TNaming.TNaming_Builder(del_label) if make_shape.HasGenerated(): for in_shape in [input_shape, tool_shape]: for face in Topo(in_shape).faces(): gen_shapes = make_shape.Generated(face) itr = TopTools.TopTools_ListIteratorOfListOfShape( gen_shapes) while itr.More(): this = itr.Value() gen_builder.Generated(face, this) print "generated", face, this itr.Next() if make_shape.HasModified(): for face in Topo(input_shape).faces(): mod_shapes = make_shape.Modified(face) itr = TopTools.TopTools_ListIteratorOfListOfShape(mod_shapes) while itr.More(): this = itr.Value() mod_builder.Modify(face, this) print "modified", face, this itr.Next() for face in Topo(tool_shape).faces(): mod_shapes = make_shape.Modified2(face) itr = TopTools.TopTools_ListIteratorOfListOfShape(mod_shapes) while itr.More(): this = itr.Value() mod_builder.Modify(face, this) print "modified2", face, this itr.Next() if make_shape.HasDeleted(): for face in Topo(input_shape).faces(): if make_shape.IsDeleted(face): del_builder.Delete(face) for face in Topo(tool_shape).faces(): if make_shape.IsDeleted(face): del_builder.Delete(face)
def on_change_selection(self): new_id = self.edge_id input = self.input label = self.label if not all((input, label)): return input_shape = input.shape sel_label = self.label.FindChild(4) selector = TNaming.TNaming_Selector(sel_label) self.selector = selector topo = Topo(input_shape) self._n_edges = topo.number_of_edges() for i,edge in enumerate(topo.edges()): if i==new_id: selector.Select(edge, input_shape) print "got selection!" break else: print "no selection" self.modified = False self.modified = True
def update_naming(self, make_shape): """ Create named shapes for the created primitive and all the sub-shapes we want to track. It seems sufficient to track faces. TNaming_Selector automatically identifies other topology (edges, vertices) based on the faces to which they belong """ label = self.label shape = make_shape.Shape() builder = TNaming.TNaming_Builder(label) builder.Generated(shape) for i, face in enumerate(Topo(shape).faces()): f_label = label.FindChild(i+1) #creates a new label if it is not found builder = TNaming.TNaming_Builder(f_label) builder.Generated(face)
def _TDocStd_changed(self, new_doc): root_label = new_doc.Main().Root() label = Label(TDF_Label=root_label) self.root_label = label print "root label entry", label.entry h_u = TNaming.Handle_TNaming_UsedShapes() gid = h_u.GetObject().getid() if root_label.FindAttribute(gid, h_u): print "got used shapes"
def update_naming(self, make_shape): label = self.label shape = make_shape.Shape() input_shape = make_shape.Shape() builder = TNaming.TNaming_Builder(label) builder.Generated(input_shape, shape) #FindChild creates a new label, if one doesn't exist. #Label entry numbers are not necessarily incremental. #They are more like dictionary keys. gen_label = label.FindChild(1) mod_label = label.FindChild(2) del_label = label.FindChild(3) gen_builder = TNaming.TNaming_Builder(gen_label) mod_builder = TNaming.TNaming_Builder(mod_label) del_builder = TNaming.TNaming_Builder(del_label) topo = Topo(input_shape) for face in topo.faces(): gen_shapes = make_shape.Generated(face) itr = TopTools.TopTools_ListIteratorOfListOfShape(gen_shapes) while itr.More(): this = itr.Value() gen_builder.Generated(face, this) print "generated", face, this itr.Next() for face in topo.faces(): mod_shapes = make_shape.Modified(face) itr = TopTools.TopTools_ListIteratorOfListOfShape(mod_shapes) while itr.More(): this = itr.Value() mod_builder.Modified(face, this) print "modified", face, this itr.Next() for face in topo.faces(): if make_shape.IsDeleted(face): del_builder.Delete(face)
def execute(self): input_shape = self.input.shape topo = Topo(input_shape) self._n_edges = topo.number_of_edges() builder = BRepFilletAPI.BRepFilletAPI_MakeChamfer(input_shape) Map = TDF.TDF_LabelMap() itr = TDF.TDF_ChildIterator(self.parent_label, True) while itr.More(): sub_label = itr.Value() Map.Add(sub_label) itr.Next() selector = self.selector ret = selector.Solve(Map) if not ret: raise Exception("Failed to solve for edge") #print "Failed to solve for edge" nt = TNaming.TNaming_Tool() selected_shape = nt.CurrentShape(selector.NamedShape()) selected_edge = TopoDS.TopoDS().Edge(selected_shape) try: face = Topo(input_shape).faces_from_edge(selected_edge).next() except RuntimeError: raise #not sure how to handle this size = self.size builder.Add(size, size, selected_edge, face) self.update_naming(builder) return builder.Shape()
app = AppStd.AppStd_Application() h_doc = TDocStd.Handle_TDocStd_Document() schema = TCollection.TCollection_ExtendedString("MyFormat") app.NewDocument(schema, h_doc) doc = h_doc.GetObject() root = doc.Main() ts = TDF.TDF_TagSource() box = BRepPrimAPI.BRepPrimAPI_MakeBox(20.0, 20.0, 20.0).Shape() box_label = ts.NewChild(root) ns_builder = TNaming.TNaming_Builder(box_label) ns_builder.Generated(box) topo = Topo(box) ## ##Name all the subshape we *might* want to refer to later ## for edge in topo.edges(): sub_label = ts.NewChild(box_label) ns_builder = TNaming.TNaming_Builder(sub_label) ns_builder.Generated(edge) # #Find and Name an edge #