def offset_cube(event=None):
    # smoothed
#    S1 = BRepPrimAPI_MakeBox(150,200,110).Shape()    
#    offsetA = BRepOffsetAPI_MakeOffsetShape(S1,60,0.01)    
#    display.EraseAll()
#    display.Context
#    display.DisplayColoredShape(S1, 'BLUE')
#    offA = display.DisplayColoredShape(offsetA.Shape(), 'GREEN')
#    display.Context.SetTransparency( offA, 0.3 )

    # sharp
    S2 = BRepPrimAPI_MakeBox(gp_Pnt(300,0,0),220,140,180).Shape()    
    offsetB = BRepOffsetAPI_MakeOffsetShape(S2,-20,0.01,BRepOffset_Skin,False,False,GeomAbs_Arc)    
    offB = display.DisplayColoredShape(S2, 'BLUE')
    display.Context.SetTransparency( offB, 0.3 )
    display.DisplayColoredShape(offsetB.Shape(), 'GREEN')
    
    from OCC.TCollection import TCollection_ExtendedString
    topo = Topo(S2)
    faces = topo.faces()
#    faceA, faceB = topo.faces_from_edge(topo.edges().next())
    faceA = faces.next()
    faces.next();faces.next(); faces.next()
    faceB = faces.next()
    
    dim = AIS_LengthDimension(faceA, faceB, 120, TCollection_ExtendedString('jelle'))
    dim.SetValue(30)
    display.Context.Display(dim.GetHandle())
    
    display.FitAll()
예제 #2
0
 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)
예제 #3
0
 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 test_draft_angle(self):
     print 'Test: draft angle'
     S = BRepPrimAPI_MakeBox(200.,300.,150.).Shape()
     adraft = BRepOffsetAPI_DraftAngle(S)
     
     topo = Topo(S)
     for f in topo.faces():
         surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(f)).GetObject()
         dirf = surf.Pln().Axis().Direction()
         print 'direction',dirf.Coord()
         ddd = gp_Dir(0,0,1)
         if dirf.IsNormal(ddd, Precision_Angular()):
             adraft.Add(f, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))         
     adraft.Build()
     self.assertTrue(adraft.IsDone())
 def test_draft_angle(self):
     print 'Test: draft angle'
     S = BRepPrimAPI_MakeBox(200.,300.,150.).Shape()
     adraft = BRepOffsetAPI_DraftAngle(S)
     
     topo = Topo(S)
     for f in topo.faces():
         surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(f)).GetObject()
         dirf = surf.Pln().Axis().Direction()
         print 'direction',dirf.Coord()
         ddd = gp_Dir(0,0,1)
         if dirf.IsNormal(ddd, Precision_Angular()):
             adraft.Add(f, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))         
     adraft.Build()
     self.assertTrue(adraft.IsDone())
예제 #6
0
def draft_angle(event=None):
    S = BRepPrimAPI_MakeBox(200.,300.,150.).Shape()
    adraft = BRepOffsetAPI_DraftAngle(S)
    
    topo = Topo(S)
    for f in topo.faces():
        surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(f)).GetObject()
        dirf = surf.Pln().Axis().Direction()
        print 'direction',dirf.Coord()
        ddd = gp_Dir(0,0,1)
        if dirf.IsNormal(ddd, Precision_Angular()):
            adraft.Add(f, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))
            
    adraft.Build()
    display.EraseAll()
    display.DisplayShape(adraft.Shape())
예제 #7
0
    def testRemovedByRefFeature(self):
        """ test that arguments returned by ref transormation is ok
        """
        from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere
        from OCC.BRep import BRep_Tool_Surface
        from OCC.GeomLProp import GeomLProp_SLProps
        from OCC.gp import gp_Pnt

        sphere_shape = BRepPrimAPI_MakeSphere(40.0).Shape()
        # build a surface from this sphere
        from OCC.Utils.Topology import Topo

        t = Topo(sphere_shape)
        for f in t.faces():
            face = f

        surf = BRep_Tool_Surface(face)
        lprop = GeomLProp_SLProps(0, 1e-12)
        lprop.SetSurface(surf)

        # evaluate_uv_coordinates
        coords = []
        p = 0.0
        # first point
        u, v = [0, 0]
        lprop.SetParameters(u, v)
        pnt = lprop.Value()
        print "First point coords : ", pnt.Coord()
        print surf.GetObject().Value(u, v).Coord()
        # This one is [40.0,0.,0.]
        self.assertEqual(str(pnt.Coord()), "(40.0, 0.0, 0.0)")
        coords.append(pnt)
        # second point
        u, v = [0.5, 0.5]
        lprop.SetParameters(u, v)
        pnt2 = lprop.Value()
        # check then that the value has not changed (it does if returned by ref)
        self.assertEqual(str(pnt.Coord()), "(40.0, 0.0, 0.0)")
예제 #8
0
    def testRemovedByRefFeature(self):
        ''' test that arguments returned by ref transormation is ok
        '''
        from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere
        from OCC.BRep import BRep_Tool_Surface
        from OCC.GeomLProp import GeomLProp_SLProps
        from OCC.gp import gp_Pnt
        sphere_shape = BRepPrimAPI_MakeSphere(40.).Shape()
        # build a surface from this sphere
        from OCC.Utils.Topology import Topo
        t = Topo(sphere_shape)
        for f in t.faces():
            face = f

        surf = BRep_Tool_Surface(face)
        lprop = GeomLProp_SLProps(0, 1e-12)
        lprop.SetSurface(surf)

        # evaluate_uv_coordinates
        coords = []
        p = 0.0
        # first point
        u, v = [0, 0]
        lprop.SetParameters(u, v)
        pnt = lprop.Value()
        print 'First point coords : ', pnt.Coord()
        print surf.GetObject().Value(u, v).Coord()
        # This one is [40.0,0.,0.]
        self.assertEqual(str(pnt.Coord()), '(40.0, 0.0, 0.0)')
        coords.append(pnt)
        #second point
        u, v = [0.5, 0.5]
        lprop.SetParameters(u, v)
        pnt2 = lprop.Value()
        # check then that the value has not changed (it does if returned by ref)
        self.assertEqual(str(pnt.Coord()), '(40.0, 0.0, 0.0)')
예제 #9
0
class TestTopology(unittest.TestCase):
    def setUp(self):
        self.topo = Topo(BRepPrimAPI_MakeBox(10, 10, 10).Shape())

    def test_nested_iteration(self):
        '''check nested looping'''
        for f in self.topo.faces():
            for e in self.topo.edges():
                self.assert_(isinstance(f, TopoDS_Face))
                self.assert_(isinstance(e, TopoDS_Edge))

    def test_kept_reference(self):
        '''did we keep a reference after looping several time through a list of topological entities?'''
        _tmp = []
        _faces = [i for i in self.topo.faces()]
        for f in _faces:
            _tmp.append(0 == f.IsNull())
        for f in _faces:
            _tmp.append(0 == f.IsNull())
        self.assert_(all(_tmp))

    def test_number_of_topological_entities(self):
        self.assert_(self.topo.number_of_vertices() == 8)
        self.assert_(self.topo.number_of_edges() == 12)
        self.assert_(self.topo.number_of_wires() == 6)
        self.assert_(self.topo.number_of_faces() == 6)
        self.assert_(self.topo.number_of_solids() == 1)
        self.assert_(self.topo.number_of_comp_solids() == 0)
        self.assert_(self.topo.number_of_compounds() == 0)

#===============================================================================
# EDGE <-> FACE
#===============================================================================

    def test_edge_face(self):
        edg = self.topo.edges().next()
        face = self.topo.faces().next()
        faces_from_edge = [i for i in self.topo.faces_from_edge(edg)]
        self.assert_(
            len(faces_from_edge) == self.topo.number_of_faces_from_edge(edg))
        edges_from_face = [i for i in self.topo.edges_from_face(face)]
        self.assert_(
            len(edges_from_face) == self.topo.number_of_edges_from_face(face))

#===============================================================================
# EDGE <-> WIRE
#===============================================================================

    def test_edge_wire(self):
        edg = self.topo.edges().next()
        wire = self.topo.wires().next()
        wires_from_edge = [i for i in self.topo.wires_from_edge(edg)]
        self.assert_(
            len(wires_from_edge) == self.topo.number_of_wires_from_edge(edg))
        edges_from_wire = [i for i in self.topo.edges_from_wire(wire)]
        self.assert_(
            len(edges_from_wire) == self.topo.number_of_edges_from_wire(wire))

#===============================================================================
# VERTEX <-> EDGE
#===============================================================================

    def test_vertex_edge(self):
        vert = self.topo.vertices().next()
        verts_from_edge = [i for i in self.topo.vertices_from_edge(vert)]
        self.assert_(
            len(verts_from_edge) == self.topo.number_of_vertices_from_edge(
                vert))
        edges_from_vert = [i for i in self.topo.edges_from_vertex(vert)]
        self.assert_(
            len(edges_from_vert) == self.topo.number_of_edges_from_vertex(
                vert))

#===============================================================================
# VERTEX <-> FACE
#===============================================================================

    def test_vertex_face(self):
        vert = self.topo.vertices().next()
        face = self.topo.faces().next()
        faces_from_vertex = [i for i in self.topo.faces_from_vertex(vert)]
        self.assert_(
            len(faces_from_vertex) == self.topo.number_of_faces_from_vertex(
                vert))
        verts_from_face = [i for i in self.topo.vertices_from_face(face)]
        self.assert_(
            len(verts_from_face) == self.topo.number_of_vertices_from_face(
                face))

#===============================================================================
# FACE <-> SOLID
#===============================================================================

    def test_face_solid(self):
        face = self.topo.faces().next()
        solid = self.topo.solids().next()
        faces_from_solid = [i for i in self.topo.faces_from_solids(face)]
        self.assert_(
            len(faces_from_solid) == self.topo.number_of_faces_from_solids(
                face))
        solids_from_face = [i for i in self.topo.solids_from_face(face)]
        self.assert_(
            len(solids_from_face) == self.topo.number_of_solids_from_face(
                face))

#===============================================================================
# WIRE <-> FACE
#===============================================================================

    def test_wire_face(self):
        wire = self.topo.wires().next()
        face = self.topo.faces().next()
        faces_from_wire = [i for i in self.topo.faces_from_wire(wire)]
        self.assert_(
            len(faces_from_wire) == self.topo.number_of_faces_from_wires(wire))
        wires_from_face = [i for i in self.topo.wires_from_face(face)]
        self.assert_(
            len(wires_from_face) == self.topo.number_of_wires_from_face(face))


#===============================================================================
# TEST POINTERS OUT OF SCOPE
#===============================================================================

    def test_edges_out_of_scope(self):
        face = self.topo.faces().next()
        _edges = []
        for edg in Topo(face).edges():
            _edges.append(edg)
        for edg in _edges:
            self.assert_(edg.IsNull() == False)

    def test_wires_out_of_scope(self):
        face = self.topo.wires().next()
        _edges = []
        for edg in WireExplorer(face).ordered_edges():
            _edges.append(edg)
        for edg in _edges:
            self.assert_(edg.IsNull() == False)
예제 #10
0
        """
        
        assert aMesh.NbNodes() != 0, 'the mesh has not yet been built ( no nodes on the mesh ).\ncompute the mesh before creating groups'
        group_load = SMESHDS_GroupOnGeom(self.indx, aMesh.GetMeshDS(), meshType, aShape)

        aMesh.AddGroup(group_load.GetType(), groupName, group_load.GetShape())
        self.indx += 1
        return True

from OCC.KBE.Level2API import *
from OCC.Utils.Topology import Topo

# compute and sort faces by area
# use the 2 first faces on which boundary conditions will be set 
topo = Topo(aShape)
faces = [Face(i) for i in topo.faces()]

# create the groups 
# note that groups can only be created when the mesh is computed
# calling group will check if any nodes are present in the mesh
# and assumes that its computed when it finds any nodes
group = GroupOnGeom()
group(aMesh, faces[0].face, SMDSAbs_Face, 'load')
group(aMesh, faces[4].face, SMDSAbs_Face, 'lock')

# ===============================================================================
# EXPORT
# ===============================================================================

# Export the data
aMesh.ExportDAT("_TEST.DAT")
예제 #11
0
                                         )

        aMesh.AddGroup( group_load.GetType(),
                        groupName,
                        group_load.GetShape()
                        )
        self.indx += 1
        return True

from OCC.KBE.Level2API import *
from OCC.Utils.Topology import Topo

# compute and sort faces by area
# use the 2 first faces on which boundary conditions will be set 
topo = Topo(aShape)
faces = [Face(i) for i in topo.faces()]

# create the groups 
# note that groups can only be created when the mesh is computed
# calling group will check if any nodes are present in the mesh
# and assumes that its computed when it finds any nodes
group =  GroupOnGeom()
group(aMesh,faces[0].face,SMDSAbs_Face,'load')
group(aMesh,faces[4].face,SMDSAbs_Face, 'lock')

#===============================================================================
# EXPORT
#===============================================================================

# Export the data
aMesh.ExportDAT("_TEST.DAT")
예제 #12
0
파일: FEM.py 프로젝트: NiSchultz/pythonocc
    '''
    concrete visualization class, using the vtk
    '''
    raise NotImplementedError
    

#===============================================================================
# Example of usage of the future framework ---
#===============================================================================

from OCC.BRepPrimAPI import *
from OCC.gp import *

shape = BRepPrimAPI_MakeBox(1,1,1).Shape()  # stupid shape for analysis
topo = Topo(shape)                          # for traversing the topology
faces = topo.faces()                        # faces of the box  
face1 = faces.next()                        # face used for loads
face2 = faces.next()                        # face that will be locked

mesh_driver = QuadMeshDriver('nadah')       # set up the mesh driver. when geometry is updated, so will the mesh before solving it
analysis    = LinearElasticityAnalysis()    # set up the problem to be solved
solver      = AbacusSolver()                # configure the solver

FEMSimulation = FEMSimulation(shape)            
FEMSimulation.load(face1, gp_Vec())       
FEMSimulation.lock(face2, x=False, y=False, z=True)
FEMSimulation.analysis = analysis
FEMSimulation.solver = solver
FEMSimulation.mesh_driver = mesh_driver
FEMSimulation.output_dir = '/dev/null/simulation.fem'
FEMSimulation.solve()
예제 #13
0
파일: FEM.py 프로젝트: zebrajack/pythonocc
    '''
    concrete visualization class, using the vtk
    '''
    raise NotImplementedError


#===============================================================================
# Example of usage of the future framework ---
#===============================================================================

from OCC.BRepPrimAPI import *
from OCC.gp import *

shape = BRepPrimAPI_MakeBox(1, 1, 1).Shape()  # stupid shape for analysis
topo = Topo(shape)  # for traversing the topology
faces = topo.faces()  # faces of the box
face1 = faces.next()  # face used for loads
face2 = faces.next()  # face that will be locked

mesh_driver = QuadMeshDriver(
    'nadah'
)  # set up the mesh driver. when geometry is updated, so will the mesh before solving it
analysis = LinearElasticityAnalysis()  # set up the problem to be solved
solver = AbacusSolver()  # configure the solver

FEMSimulation = FEMSimulation(shape)
FEMSimulation.load(face1, gp_Vec())
FEMSimulation.lock(face2, x=False, y=False, z=True)
FEMSimulation.analysis = analysis
FEMSimulation.solver = solver
FEMSimulation.mesh_driver = mesh_driver
예제 #14
0
class TestTopology(unittest.TestCase):
    def setUp(self):
        self.topo = Topo(BRepPrimAPI_MakeBox(10., 10., 10).Shape())

    def test_nested_iteration(self):
        '''check nested looping'''
        for f in self.topo.faces():
            for e in self.topo.edges():
                self.assert_(isinstance(f, TopoDS_Face))
                self.assert_(isinstance(e, TopoDS_Edge))

    def test_kept_reference(self):
        '''did we keep a reference after looping several time through a list
        of topological entities?'''
        _tmp = []
        _faces = [i for i in self.topo.faces()]
        for f in _faces:
            _tmp.append(0 == f.IsNull())
        for f in _faces:
            _tmp.append(0 == f.IsNull())
        self.assert_(all(_tmp))

    def test_number_of_topological_entities(self):
        self.assert_(self.topo.number_of_vertices() == 8)
        self.assert_(self.topo.number_of_edges() == 12)
        self.assert_(self.topo.number_of_wires() == 6)
        self.assert_(self.topo.number_of_faces() == 6)
        self.assert_(self.topo.number_of_solids() == 1)
        self.assert_(self.topo.number_of_comp_solids() == 0)
        self.assert_(self.topo.number_of_compounds() == 0)

    def test_edge_face(self):
        edg = self.topo.edges().next()
        face = self.topo.faces().next()
        faces_from_edge = [i for i in self.topo.faces_from_edge(edg)]
        self.assert_(len(faces_from_edge) == self.topo.number_of_faces_from_edge(edg))
        edges_from_face = [i for i in self.topo.edges_from_face(face)]
        self.assert_(len(edges_from_face) == self.topo.number_of_edges_from_face(face))

    def test_edge_wire(self):
        edg = self.topo.edges().next()
        wire = self.topo.wires().next()
        wires_from_edge = [i for i in self.topo.wires_from_edge(edg)]
        self.assert_(len(wires_from_edge) == self.topo.number_of_wires_from_edge(edg))
        edges_from_wire = [i for i in self.topo.edges_from_wire(wire)]
        self.assert_(len(edges_from_wire) == self.topo.number_of_edges_from_wire(wire))

    def test_vertex_edge(self):
        vert = self.topo.vertices().next()
        verts_from_edge = [i for i in self.topo.vertices_from_edge(vert)]
        self.assert_(len(verts_from_edge) == self.topo.number_of_vertices_from_edge(vert))
        edges_from_vert = [ i for i in self.topo.edges_from_vertex(vert)]
        self.assert_(len(edges_from_vert) == self.topo.number_of_edges_from_vertex(vert))

    def test_vertex_face(self):
        vert = self.topo.vertices().next()
        face = self.topo.faces().next()
        faces_from_vertex = [i for i in self.topo.faces_from_vertex(vert)]
        self.assert_(len(faces_from_vertex) == self.topo.number_of_faces_from_vertex(vert))
        verts_from_face = [i for i in self.topo.vertices_from_face(face)]
        self.assert_(len(verts_from_face) == self.topo.number_of_vertices_from_face(face))

    def test_face_solid(self):
        face = self.topo.faces().next()
        solid = self.topo.solids().next()
        faces_from_solid = [i for i in self.topo.faces_from_solids(solid)]
        self.assert_(len(faces_from_solid) == self.topo.number_of_faces_from_solids(solid))
        solids_from_face = [i for i in self.topo.solids_from_face(face)]
        self.assert_(len(solids_from_face) == self.topo.number_of_solids_from_face(face))

    def test_wire_face(self):
        wire = self.topo.wires().next()
        face = self.topo.faces().next()
        faces_from_wire = [i for i in self.topo.faces_from_wire(wire)]
        self.assert_(len(faces_from_wire) == self.topo.number_of_faces_from_wires(wire))
        wires_from_face = [i for i in self.topo.wires_from_face(face)]
        self.assert_(len(wires_from_face) == self.topo.number_of_wires_from_face(face))

    def test_edges_out_of_scope(self):
        face = self.topo.faces().next()
        _edges = []
        for edg in Topo(face).edges():
            _edges.append(edg)
        for edg in _edges:
            self.assert_(edg.IsNull() == False)

    def test_wires_out_of_scope(self):
        face = self.topo.wires().next()
        _edges = []
        for edg in WireExplorer(face).ordered_edges():
            _edges.append(edg)
        for edg in _edges:
            self.assert_(edg.IsNull() == False)