Exemplo n.º 1
0
 def test_to_brep(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     r1 = s1.center()
     s1.to_brep('tmp.brp')
     s2 = cm.from_brep('tmp.brp')
     r2 = s2.center()
     self.assert_(close(r1, (1.0, 2.0, 3.0)) and close(r2, (1.0, 2.0, 3.0)))
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 def test_copy(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     s2 = s1.copy()
     s1.translate((1.0, 1.0, 1.0))
     self.assert_(
         close(s2.center(), (1.0, 2.0, 3.0))
         and close(s1.center(), (2.0, 3.0, 4.0)))
Exemplo n.º 5
0
 def test_to_iges(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     r1 = s1.center()
     s1.to_iges('tmp.igs', brep_mode=1)
     s2 = cm.from_iges('tmp.igs')
     r2 = s2.center()
     self.assert_(close(r1, (1.0, 2.0, 3.0)) and close(r2, (1.0, 2.0, 3.0)))
Exemplo n.º 6
0
 def test_to_brep(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     r1 = s1.center()
     s1.to_brep('tmp.brp')
     s2 = cm.from_brep('tmp.brp')
     r2 = s2.center()
     self.assert_(close(r1, (1.0, 2.0, 3.0)) and
                  close(r2, (1.0, 2.0, 3.0)))
Exemplo n.º 7
0
 def test_to_iges(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     r1 = s1.center()
     s1.to_iges('tmp.igs', brep_mode=1)
     s2 = cm.from_iges('tmp.igs')
     r2 = s2.center()
     self.assert_(close(r1, (1.0, 2.0, 3.0)) and
                  close(r2, (1.0, 2.0, 3.0)))
Exemplo n.º 8
0
def edge_spline():
    pts = [(0.0, 0.0, 0.0), (0.2, 0.1, 0.0), (0.5, 0.2, 0.0), (-0.5, 0.3, 0.0)]
    e1 = cm.spline(pts)
    v.viewstandard(viewtype='top')
    v.display(e1, (0.0, 0.0, 0.0))
    for pt in pts:
        v.display(cm.vertex(pt), (1.0, 0.0, 0.0))
    v.fit()
    v.save('edge_spline.png')
    v.clear()
Exemplo n.º 9
0
def edge_spline():
    pts = [(0.0, 0.0, 0.0),
           (0.2, 0.1, 0.0),
           (0.5, 0.2, 0.0),
           (-0.5, 0.3, 0.0)]
    e1 = cm.spline(pts)
    v.viewstandard(viewtype='top')
    v.display(e1, (0.0, 0.0, 0.0))
    for pt in pts:
        v.display(cm.vertex(pt), (1.0, 0.0, 0.0))
    v.fit()
    v.save('edge_spline.png')
    v.clear()
Exemplo n.º 10
0
 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()
Exemplo n.º 11
0
 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()
Exemplo n.º 12
0
 def draw(self, view):
     self.geom = model.vertex([self.x.val, self.y.val, 0])
     view.display(self.geom)
Exemplo n.º 13
0
 def tolerance(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     self.assert_(close(s1.tolerance(), 1e-7, eps=1e-9))
Exemplo n.º 14
0
 def test_bounds(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     self.assert_(close(s1.bounds(), (1.0, 2.0, 3.0, 1.0, 2.0, 3.0)))
Exemplo n.º 15
0
 def test_fix(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     s1.fix()
     self.assert_(close(s1.center(), (1.0, 2.0, 3.0)))
Exemplo n.º 16
0
 def test_dump(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     s1.dump()
     self.assert_(True)
Exemplo n.º 17
0
 def test_bounds(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     self.assert_(close(s1.bounds(), (1.0, 2.0, 3.0, 1.0, 2.0, 3.0)))
Exemplo n.º 18
0
 def test_check(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     self.assert_(s1.check())
Exemplo n.º 19
0
 def test_copy(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     s2 = s1.copy()
     s1.translate((1.0, 1.0, 1.0))
     self.assert_(close(s2.center(), (1.0, 2.0, 3.0)) and
                  close(s1.center(), (2.0, 3.0, 4.0)))
Exemplo n.º 20
0
 def test_check(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     self.assert_(s1.check())
Exemplo n.º 21
0
 def test_fix(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     s1.fix()
     self.assert_(close(s1.center(), (1.0, 2.0, 3.0)))
Exemplo n.º 22
0
 def test_dump(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     s1.dump()
     self.assert_(True)
Exemplo n.º 23
0
 def tolerance(self):
     s1 = cm.vertex((1.0, 2.0, 3.0))
     self.assert_(close(s1.tolerance(), 1e-7, eps=1e-9))