def derived_loft(): w1 = cm.wire([cm.circle(1.0)]) w2 = cm.wire([cm.circle(2.0)]) w2.translate((0.0, 0.0, 5.0)) w3 = cm.wire([cm.circle(1.5)]) w3.translate((0.0, 0.0, 10.0)) s1 = cm.loft([w1, w2, w3]) save_iso(s1, 'derived_loft.png')
def derived_loft(): w1 = cm.wire([cm.circle(1.0)]) w2 = cm.wire([cm.circle(2.0)]) w2.translate((0.0, 0.0, 5.0)) w3 = cm.wire([cm.circle(1.5)]) w3.translate((0.0, 0.0, 10.0)) s1 = cm.loft([w1, w2, w3]) save_iso(s1, 'derived_loft.png')
def test_loft(self): w1 = cm.wire([cm.circle(1.0)]) w2 = cm.wire([cm.circle(2.0)]) w2.translate((0.0, 0.0, 5.0)) w3 = cm.wire([cm.circle(1.5)]) w3.translate((0.0, 0.0, 10.0)) s1 = cm.loft([w1, w2, w3]) # empirical self.assert_(close(98.407, s1.volume(), 0.001))
def test_loft(self): w1 = cm.wire([cm.circle(1.0)]) w2 = cm.wire([cm.circle(2.0)]) w2.translate((0.0, 0.0, 5.0)) w3 = cm.wire([cm.circle(1.5)]) w3.translate((0.0, 0.0, 10.0)) s1 = cm.loft([w1, w2, w3]) # empirical self.assert_(close(98.407, s1.volume(), 0.001))
def query(self, widget=None): """ Reports the properties of a selection Should do something other than print (popup?) *** """ if self.selected is not None: if self.selection_type == 'vertex': s = _cm.vertex(self.selected) retval = 'center: ' + str(s.center()) + \ '\ntolerance: ' + str(s.tolerance()) elif self.selection_type == 'edge': s = _cm.edge(self.selected) retval = 'center: ' + str(s.center()) + \ '\nlength: ' + str(s.length()) + \ '\ntolerance: ' + str(s.tolerance()) elif self.selection_type == 'wire': s = _cm.wire(self.selected) retval = 'center: ' + str(s.center()) + \ '\nlength: ' + str(s.length()) elif self.selection_type == 'face': s = _cm.face(self.selected) retval = 'center: ' + str(s.center()) + \ '\ntype: ' + str(s.type()) + \ '\narea: ' + str(s.area()) + \ '\ntolerance: ' + str(s.tolerance()) else: retval = 'No properties for type ' + self.selection_type print(retval)
def query(self, widget=None): """ Reports the properties of a selection Should do something other than print (popup?) *** """ if self.selected is not None: if self.selection_type == 'vertex': s = _cm.vertex(self.selected) retval = 'center: ' + str(s.center()) + \ '\ntolerance: ' + str(s.tolerance()) elif self.selection_type == 'edge': s = _cm.edge(self.selected) retval = 'center: ' + str(s.center()) + \ '\nlength: ' + str(s.length()) + \ '\ntolerance: ' + str(s.tolerance()) elif self.selection_type == 'wire': s = _cm.wire(self.selected) retval = 'center: ' + str(s.center()) + \ '\nlength: ' + str(s.length()) elif self.selection_type == 'face': s = _cm.face(self.selected) retval = 'center: ' + str(s.center()) + \ '\ntype: ' + str(s.type()) + \ '\narea: ' + str(s.area()) + \ '\ntolerance: ' + str(s.tolerance()) else: retval = 'No properties for type ' + self.selection_type print(retval)
def derived_pipe(): profile = cm.ngon(2.0, 6) e1 = cm.arc(8.0, 0.0, math.pi / 2) e2 = cm.segment((0.0, 8.0, 0.0), (-8.0, 8.0, 0.0)) spine = cm.wire([e1, e2]) spine.translate((-8.0, 0.0, 0.0)) spine.rotatex(math.pi / 2) s1 = cm.pipe(profile, spine) save_iso(s1, 'derived_pipe.png')
def wire(): e1 = cm.arc(1.0, -math.pi / 2, math.pi / 2) e1.translate((1.0, 0.0, 0.0)) e2 = cm.segment((1.0, 1.0, 0.0), (-1.0, 1.0, 0.0)) e3 = cm.arc(1.0, math.pi / 2, 3 * math.pi / 2) e3.translate((-1.0, 0.0, 0.0)) e4 = cm.segment((-1.0, -1.0, 0.0), (1.0, -1.0, 0.0)) w1 = cm.wire([e1, e2, e3, e4]) save_top(w1, 'wire.png', (0.0, 0.0, 0.0))
def derived_pipe(): profile = cm.ngon(2.0, 6) e1 = cm.arc(8.0, 0.0, math.pi / 2) e2 = cm.segment((0.0, 8.0, 0.0), (-8.0, 8.0, 0.0)) spine = cm.wire([e1, e2]) spine.translate((-8.0, 0.0, 0.0)) spine.rotatex(math.pi / 2) s1 = cm.pipe(profile, spine) save_iso(s1, 'derived_pipe.png')
def test_filling(self): e1 = cm.spline([(0.0, 0.0, 0.0), (1.0, 0.2, 0.3), (1.5, 0.8, 1.0), (0.8, 1.2, 0.2), (0.0, 1.0, 0.0)]) e2 = cm.spline([(0.0, 0.0, 0.0), (-1.0, 0.2, 0.3), (-1.5, 0.8, 1.0), (-0.8, 1.2, 0.2), (0.0, 1.0, 0.0)]) w1 = cm.wire([e1, e2]) f1 = cm.filling(w1) # empirical self.assert_(close(5.479, f1.area(), 0.01)) # Can vary
def derived_revol(): e1 = cm.arc(1.0, -math.pi / 2, math.pi / 2) e1.translate((3.0, 0.0, 0.0)) w1 = cm.polygon([(3.0, 1.0, 0.0), (2.0, 1.0, 0.0), (2.0, -1.0, 0.0), (3.0, -1.0, 0.0)]) f1 = cm.plane(cm.wire([e1, w1])) f1.rotatex(math.pi / 2) s1 = cm.revol(f1, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), 2 * math.pi) save_iso(s1, 'derived_revol.png')
def wire(): e1 = cm.arc(1.0, -math.pi / 2, math.pi / 2) e1.translate((1.0, 0.0, 0.0)) e2 = cm.segment((1.0, 1.0, 0.0), (-1.0, 1.0, 0.0)) e3 = cm.arc(1.0, math.pi / 2, 3 * math.pi / 2) e3.translate((-1.0, 0.0, 0.0)) e4 = cm.segment((-1.0, -1.0, 0.0), (1.0, -1.0, 0.0)) w1 = cm.wire([e1, e2, e3, e4]) save_top(w1, 'wire.png', (0.0, 0.0, 0.0))
def test_pipe(self): profile = cm.ngon(2.0, 6) e1 = cm.arc(8.0, 0.0, math.pi / 2) e2 = cm.segment((0.0, 8.0, 0.0), (-8.0, 8.0, 0.0)) spine = cm.wire([e1, e2]) spine.translate((-8.0, 0.0, 0.0)) spine.rotatex(math.pi / 2) s1 = cm.pipe(profile, spine) # empirical self.assert_(close(213.732, s1.volume(), 0.001))
def test_pipe(self): profile = cm.ngon(2.0, 6) e1 = cm.arc(8.0, 0.0, math.pi / 2) e2 = cm.segment((0.0, 8.0, 0.0), (-8.0, 8.0, 0.0)) spine = cm.wire([e1, e2]) spine.translate((-8.0, 0.0, 0.0)) spine.rotatex(math.pi / 2) s1 = cm.pipe(profile, spine) # empirical self.assert_(close(213.732, s1.volume(), 0.001))
def derived_revol(): e1 = cm.arc(1.0, -math.pi / 2, math.pi / 2) e1.translate((3.0, 0.0, 0.0)) w1 = cm.polygon([(3.0, 1.0, 0.0), (2.0, 1.0, 0.0), (2.0, -1.0, 0.0), (3.0, -1.0, 0.0)]) f1 = cm.plane(cm.wire([e1, w1])) f1.rotatex(math.pi / 2) s1 = cm.revol(f1, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), 2 * math.pi) save_iso(s1, 'derived_revol.png')
def face_filling(): e1 = cm.spline([(0.0, 0.0, 0.0), (1.0, 0.2, 0.3), (1.5, 0.8, 1.0), (0.8, 1.2, 0.2), (0.0, 1.0, 0.0)]) e2 = cm.spline([(0.0, 0.0, 0.0), (-1.0, 0.2, 0.3), (-1.5, 0.8, 1.0), (-0.8, 1.2, 0.2), (0.0, 1.0, 0.0)]) w1 = cm.wire([e1, e2]) f1 = cm.filling(w1) v.viewstandard(viewtype='iso') v.display(w1, color=(1.0, 0.0, 0.0)) v.display(f1) v.fit() v.save('face_filling.png') v.clear()
def test_filling(self): e1 = cm.spline([(0.0, 0.0, 0.0), (1.0, 0.2, 0.3), (1.5, 0.8, 1.0), (0.8, 1.2, 0.2), (0.0, 1.0, 0.0)]) e2 = cm.spline([(0.0, 0.0, 0.0), (-1.0, 0.2, 0.3), (-1.5, 0.8, 1.0), (-0.8, 1.2, 0.2), (0.0, 1.0, 0.0)]) w1 = cm.wire([e1, e2]) f1 = cm.filling(w1) # empirical self.assert_(close(5.479, f1.area(), 0.01)) # Can vary
def face_filling(): e1 = cm.spline([(0.0, 0.0, 0.0), (1.0, 0.2, 0.3), (1.5, 0.8, 1.0), (0.8, 1.2, 0.2), (0.0, 1.0, 0.0)]) e2 = cm.spline([(0.0, 0.0, 0.0), (-1.0, 0.2, 0.3), (-1.5, 0.8, 1.0), (-0.8, 1.2, 0.2), (0.0, 1.0, 0.0)]) w1 = cm.wire([e1, e2]) f1 = cm.filling(w1) v.viewstandard(viewtype='iso') v.display(w1, color=(1.0, 0.0, 0.0)) v.display(f1) v.fit() v.save('face_filling.png') v.clear()
def _build_hashes(self, htype): if htype == 'face': ex_type = _TopAbs.TopAbs_FACE elif htype == 'wire': ex_type = _TopAbs.TopAbs_WIRE elif htype == 'edge': ex_type = _TopAbs.TopAbs_EDGE elif htype == 'vertex': ex_type = _TopAbs.TopAbs_VERTEX else: print('Error: Unknown hash type', htype) if (self.selected_shape.ShapeType == _TopAbs.TopAbs_WIRE and htype == 'edge'): ex = _BRepTools_WireExplorer(selected_shape) # Ordered this way else: ex = _TopExp_Explorer(self.selected_shape, ex_type) self.hashes = [] self.positions = [] while ex.More(): s1 = ex.Current() # Calculate hash s1_hash = s1.__hash__() if s1_hash not in self.hashes: self.hashes.append(s1_hash) # Calculate position if htype == 'face': f = _cm.face(s1) c = (' type ' + f.type(), f.center()) elif htype == 'wire': w = _cm.wire(s1) c = ('', w.center()) elif htype == 'edge': e = _cm.edge(s1) c = ('', e.center()) elif htype == 'vertex': c = ('', _cm.vertex(s1).center()) self.positions.append(c) ex.Next()
def _build_hashes(self, htype): if htype == 'face': ex_type = _TopAbs.TopAbs_FACE elif htype == 'wire': ex_type = _TopAbs.TopAbs_WIRE elif htype == 'edge': ex_type = _TopAbs.TopAbs_EDGE elif htype == 'vertex': ex_type = _TopAbs.TopAbs_VERTEX else: print('Error: Unknown hash type', htype) if (self.selected_shape.ShapeType == _TopAbs.TopAbs_WIRE and htype == 'edge'): ex = _BRepTools_WireExplorer(selected_shape) # Ordered this way else: ex = _TopExp_Explorer(self.selected_shape, ex_type) self.hashes = [] self.positions = [] while ex.More(): s1 = ex.Current() # Calculate hash s1_hash = s1.__hash__() if s1_hash not in self.hashes: self.hashes.append(s1_hash) # Calculate position if htype == 'face': f = _cm.face(s1) c = (' type ' + f.type(), f.center()) elif htype == 'wire': w = _cm.wire(s1) c = ('', w.center()) elif htype == 'edge': e = _cm.edge(s1) c = ('', e.center()) elif htype == 'vertex': c = ('', _cm.vertex(s1).center()) self.positions.append(c) ex.Next()