def testOffsetReferences(): #f = TestObjects.makeHeartFace(); #f must be a face with one outer and one inner wire f = TestObjects.makeSquareWithRoundHole() wires = OCCUtil.wireListFromFace(f) outer = wires[0] inner = wires[1] display.DisplayColoredShape(outer, 'GREEN') display.DisplayColoredShape(inner, 'WHITE') #add wires to offset. bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() bo.AddWire(outer) bo.AddWire(inner) bo.Perform(-0.2, 0.0) #do an offset shape = bo.Shape() for w in Topo(shape).wires(): display.DisplayColoredShape(OCCUtil.cast(shape), 'YELLOW') for e in Topo(outer).edges(): print "Outer Edge %d has %d generated shapes" % ( e.__hash__(), len(OCCUtil.listFromTopToolsListOfShape(bo.Generated(e)))) for e in Topo(inner).edges(): print "Inner Edge %d has %d generated shapes" % ( e.__hash__(), len(OCCUtil.listFromTopToolsListOfShape(bo.Generated(e)))) display.FitAll()
def testOffsetReferences(): #f = TestObjects.makeHeartFace(); #f must be a face with one outer and one inner wire f = TestObjects.makeSquareWithRoundHole(); wires = OCCUtil.wireListFromFace(f); outer = wires[0]; inner = wires[1]; display.DisplayColoredShape(outer,'GREEN'); display.DisplayColoredShape(inner,'WHITE'); #add wires to offset. bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset(); bo.AddWire(outer); bo.AddWire(inner); bo.Perform(-0.2,0.0); #do an offset shape = bo.Shape(); for w in Topo(shape).wires(): display.DisplayColoredShape(OCCUtil.cast(shape),'YELLOW'); for e in Topo(outer).edges(): print "Outer Edge %d has %d generated shapes" % ( e.__hash__(), len(OCCUtil.listFromTopToolsListOfShape(bo.Generated(e) )) ); for e in Topo(inner).edges(): print "Inner Edge %d has %d generated shapes" % ( e.__hash__(), len(OCCUtil.listFromTopToolsListOfShape(bo.Generated(e) )) ); display.FitAll();
def setUp(self): os.chdir(orig_wd) test_doc_1 = os.getcwd( ) + r'\static_files\TEST-org.apache.tika.cli.TikaCLIBatchCommandLineTest.xml' test_doc_2 = os.getcwd( ) + r'\static_files\MavenProj\sub_mod_2\target\surefire-reports\TEST-p_1.AssafTest.xml' self.test_report_1 = TestObjects.TestClassReport(test_doc_1, '') try: self.test_report_2 = TestObjects.TestClassReport( test_doc_2, os.getcwd() + r'\static_files\MavenProj\sub_mod_2') except TestObjects.TestParserException as e: print("Unexpected state of the test driver. Caused excpetion:") print(e.msg) #resetEnvritonment() self.test_1 = TestObjects.TestClass( os.getcwd() + r'\static_files\MavenProj\sub_mod_2\src\test\java\NaimTest.java') self.test_2 = TestObjects.TestClass( os.getcwd() + r'\static_files\MavenProj\sub_mod_1\src\test\java\p_1\AmitTest.java' ) self.test_2 = TestObjects.TestClass( os.getcwd() + r'\static_files\MavenProj\sub_mod_1\src\test\java\p_1\AmitTest.java' ) self.test_3 = TestObjects.TestClass( os.getcwd() + r'\static_files\tika_1\src\test\java\org\apache\tika\parser\AutoDetectParserTest.java' ) self.test_4 = TestObjects.TestClass( os.getcwd() + r'\static_files\tika_1\src\test\java\org\apache\tika\sax\AppendableAdaptorTest.java' ) self.test_5 = TestObjects.TestClass( os.getcwd() + r'\static_files\tika_1\src\test\java\org\apache\tika\sax _1\AppendableAdaptorTest.java' ) self.testcase_1 = [ t for t in self.test_3.testcases if t.id.endswith('None_testExcel()') ][0] self.testcase_2 = [ t for t in self.test_4.testcases if t.id.endswith('None_testAppendChar()') ][0] self.testcase_3 = [ t for t in self.test_5.testcases if t.id.endswith('None_testAppendChar()') ][0] self.testcase_4 = [ t for t in self.test_5.testcases if t.id.endswith('None_testAppendString()') ][0]
def testBasicFaceOffset(): f = TestObjects.makeHeartFaceNoHole(); startWires = OCCUtil.wireListFromFace(f); display.DisplayColoredShape(startWires,'GREEN'); cw = startWires; for i in range(3): w = OCCUtil.offsetWireList(cw,-0.2); display.DisplayColoredShape(w,'RED'); cw = w;
def testOffsetMapBasic(): #tests whether the offestting works f = TestObjects.makeSquareWithRoundHole(); #face that will have odd offsets om = OffsetMap(f); om.offsetOnce(-0.2); display.DisplayColoredShape(om.originalWires,'GREEN'); display.DisplayColoredShape(om.otherWires,'RED');
def parse_tests(tests_dir): ans = [] for filename in os.listdir(tests_dir): abs_path = os.path.join(tests_dir, filename) if os.path.isdir(abs_path): ans.extend(parse_tests(abs_path)) elif filename.endswith(".java"): ans.append(TestObjects.TestClass(abs_path)) return ans
def testBasicFaceOffset(): f = TestObjects.makeHeartFaceNoHole() startWires = OCCUtil.wireListFromFace(f) display.DisplayColoredShape(startWires, 'GREEN') cw = startWires for i in range(3): w = OCCUtil.offsetWireList(cw, -0.2) display.DisplayColoredShape(w, 'RED') cw = w
def testOffsetMapBasic(): #tests whether the offestting works f = TestObjects.makeSquareWithRoundHole() #face that will have odd offsets om = OffsetMap(f) om.offsetOnce(-0.2) display.DisplayColoredShape(om.originalWires, 'GREEN') display.DisplayColoredShape(om.otherWires, 'RED')
def parse_tests_reports(self, path_to_reports, module=None): inspected_module = self.repo_dir if not module == None: inspected_module = module ans = [] for filename in os.listdir(path_to_reports): if filename.endswith(".xml"): ans.append( TestObjects.TestClassReport( os.path.join(path_to_reports, filename), inspected_module)) return ans
def TestWireJoiner(): wire = TestObjects.makeOffsetTestWire() conditions = [] #each test condition is two points, representing an edge #that was drawn last. #in these tests, the red curve is the trimmed one, and the green is the original. #the yellow markers on the leadin edges and the joining segment is closer to the end #in each case, the solution found should minimize overlap and trim the other edge #as necessary. conditions.append((gp.gp_Pnt(11.2, 1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(15.2, 0.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -3.0, 0), gp.gp_Pnt(11.2, -1.0, 0))) conditions.append((gp.gp_Pnt(20.2, 19.0, 0), gp.gp_Pnt(20.2, 20.0, 0))) conditions.append((gp.gp_Pnt(30.2, 25.0, 0), gp.gp_Pnt(20.2, 20.0, 0))) for (startPoint, endPoint) in conditions: display.EraseAll() display.DisplayColoredShape(wire, 'GREEN') initVector = OCCUtil.edgeFromTwoPoints(startPoint, endPoint) display.DisplayColoredShape( OCCUtil.edgeFromTwoPoints(startPoint, endPoint), 'BLUE') display.DisplayColoredShape(TestObjects.makeEdgeIndicator(initVector)) vec = gp.gp_Vec(startPoint, endPoint) jrequest = JointRequest(endPoint, vec, 0.8, wire) wj = WireJoiner(jrequest, 4.0) #this is a huge tolerance, but helps for testing solution = wj.build() display.DisplayColoredShape(solution.wire, 'RED') entryEdge = OCCUtil.edgeFromTwoPoints(endPoint, solution.entryPoint) display.DisplayColoredShape(TestObjects.makeEdgeIndicator(entryEdge)) if solution.isJoint: display.DisplayColoredShape(entryEdge, 'WHITE') else: display.DisplayColoredShape(entryEdge, 'YELLOW') time.sleep(5)
def TestWireJoiner(): wire = TestObjects.makeOffsetTestWire() conditions = [] # each test condition is two points, representing an edge # that was drawn last. # in these tests, the red curve is the trimmed one, and the green is the original. # the yellow markers on the leadin edges and the joining segment is closer to the end # in each case, the solution found should minimize overlap and trim the other edge # as necessary. conditions.append((gp.gp_Pnt(11.2, 1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(15.2, 0.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -3.0, 0), gp.gp_Pnt(11.2, -1.0, 0))) conditions.append((gp.gp_Pnt(20.2, 19.0, 0), gp.gp_Pnt(20.2, 20.0, 0))) conditions.append((gp.gp_Pnt(30.2, 25.0, 0), gp.gp_Pnt(20.2, 20.0, 0))) for (startPoint, endPoint) in conditions: display.EraseAll() display.DisplayColoredShape(wire, "GREEN") initVector = OCCUtil.edgeFromTwoPoints(startPoint, endPoint) display.DisplayColoredShape(OCCUtil.edgeFromTwoPoints(startPoint, endPoint), "BLUE") display.DisplayColoredShape(TestObjects.makeEdgeIndicator(initVector)) vec = gp.gp_Vec(startPoint, endPoint) jrequest = JointRequest(endPoint, vec, 0.8, wire) wj = WireJoiner(jrequest, 4.0) # this is a huge tolerance, but helps for testing solution = wj.build() display.DisplayColoredShape(solution.wire, "RED") entryEdge = OCCUtil.edgeFromTwoPoints(endPoint, solution.entryPoint) display.DisplayColoredShape(TestObjects.makeEdgeIndicator(entryEdge)) if solution.isJoint: display.DisplayColoredShape(entryEdge, "WHITE") else: display.DisplayColoredShape(entryEdge, "YELLOW") time.sleep(5)
def testOffsetMapPathWalker(): #test that we can walk all of the wires in the offset map exactly once by using getNextEdge #f = TestObjects.makeSquareWithRoundHole(); #face that will have odd offsets f = TestObjects.makeHeartFace() om = OffsetMap(f) #display.DisplayColoredShape(om.originalWires,'GREEN'); #om.display = display; #WEIRD BUG-- after one offset, things are good, but after two offsets, #the curve is offest back outwards instead of inwards? wires1 = om.offsetOnceSimple(-0.1) wires2 = om.offsetOnceSimple(-0.1) wires3 = om.offsetOnceSimple(-0.1) #display.DisplayColoredShape(wires1,'RED'); #display.DisplayColoredShape(wires2,'RED'); #display.DisplayColoredShape(wires3,'RED'); display.DisplayColoredShape(om.originalWires, 'GREEN')
def testOffsetMapPathWalker(): #test that we can walk all of the wires in the offset map exactly once by using getNextEdge #f = TestObjects.makeSquareWithRoundHole(); #face that will have odd offsets f = TestObjects.makeHeartFace(); om = OffsetMap(f); #display.DisplayColoredShape(om.originalWires,'GREEN'); #om.display = display; #WEIRD BUG-- after one offset, things are good, but after two offsets, #the curve is offest back outwards instead of inwards? wires1 = om.offsetOnceSimple(-0.1); wires2 = om.offsetOnceSimple(-0.1); wires3 = om.offsetOnceSimple(-0.1); #display.DisplayColoredShape(wires1,'RED'); #display.DisplayColoredShape(wires2,'RED'); #display.DisplayColoredShape(wires3,'RED'); display.DisplayColoredShape(om.originalWires,'GREEN');
def testOffsetMapDecendants(): #test that we can find the edge, vertex, and wire from a given edge f = TestObjects.makeSquareWithRoundHole(); #face that will have odd offsets om = OffsetMap(f); om.offsetOnce(-0.2); #display each edge and its decendant edge. #each original edge and vertex is checked #in each case the result should be the edge that was created from the one in green, #and the blue point should be the vertex of that edge closest to the green vertex for w in om.originalWires: for e in Topo(w).edges(): for v in Topo(e).vertices(): display.EraseAll(); display.DisplayColoredShape(v,'GREEN'); display.DisplayColoredShape(e,'GREEN'); (nv,ne,nw) = om.getNextEdge(e,v); display.DisplayColoredShape(nw,'YELLOW'); display.DisplayColoredShape(ne,'RED'); display.DisplayColoredShape(nv,'BLUE'); time.sleep(5);
def testOffsetMapDecendants(): #test that we can find the edge, vertex, and wire from a given edge f = TestObjects.makeSquareWithRoundHole() #face that will have odd offsets om = OffsetMap(f) om.offsetOnce(-0.2) #display each edge and its decendant edge. #each original edge and vertex is checked #in each case the result should be the edge that was created from the one in green, #and the blue point should be the vertex of that edge closest to the green vertex for w in om.originalWires: for e in Topo(w).edges(): for v in Topo(e).vertices(): display.EraseAll() display.DisplayColoredShape(v, 'GREEN') display.DisplayColoredShape(e, 'GREEN') (nv, ne, nw) = om.getNextEdge(e, v) display.DisplayColoredShape(nw, 'YELLOW') display.DisplayColoredShape(ne, 'RED') display.DisplayColoredShape(nv, 'BLUE') time.sleep(5)
def TestTrimmedWire(): # test triming a wire #this will select each vertex of the heart. square = TestObjects.makeOffsetTestWire() conditions = [] #each test condition is two points, representing an edge #that was drawn last. conditions.append((gp.gp_Pnt(11.2, 1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) for (startPoint, endPoint) in conditions: display.EraseAll() display.DisplayColoredShape(square, 'GREEN') display.DisplayColoredShape(edgeFromTwoPoints(startPoint, endPoint), 'YELLOW') vec = gp.gp_Vec(startPoint, endPoint) (w2, edge, p2, newVec) = getTrimmedWire(square, vec, endPoint, 0.1) display.DisplayColoredShape(w2, 'RED') display.DisplayColoredShape(make_vertex(p2), 'RED') time.sleep(5)
def TestTrimmedWire(): # test triming a wire #this will select each vertex of the heart. square = TestObjects.makeOffsetTestWire(); conditions= []; #each test condition is two points, representing an edge #that was drawn last. conditions.append((gp.gp_Pnt(11.2,1.0,0),gp.gp_Pnt(11.2,0.0,0)) ); conditions.append((gp.gp_Pnt(11.2,-1.0,0),gp.gp_Pnt(11.2,0.0,0)) ); for (startPoint,endPoint) in conditions: display.EraseAll(); display.DisplayColoredShape(square, 'GREEN'); display.DisplayColoredShape(edgeFromTwoPoints(startPoint,endPoint),'YELLOW'); vec = gp.gp_Vec(startPoint,endPoint); (w2,edge,p2,newVec) = getTrimmedWire(square,vec,endPoint,0.1); display.DisplayColoredShape(w2,'RED'); display.DisplayColoredShape(make_vertex(p2),'RED'); time.sleep(5);
def TestWireJoiner(): heartWire = TestObjects.makeHeartWire() #man this is hard to test without resorting to graphical test. #this is sort of a semi-automatic method testPoints = [] testPoints.append([gp.gp_Pnt(-1.0, 0, 0), 5]) testPoints.append([gp.gp_Pnt(0, -1.0, 0), 5]) testPoints.append([gp.gp_Pnt(-1.0, -1.0, 0), 5]) testPoints.append([gp.gp_Pnt(1.0, 0, 0), 5]) testPoints.append([gp.gp_Pnt(1.6, 1.8, 0), 6]) testPoints.append([gp.gp_Pnt(4.15, 4.4, 0), 5]) testPoints.append([gp.gp_Pnt(0.5, 3.5, 0), 5]) testPoints.append([gp.gp_Pnt(4.0, 4.7, 0), 6]) for tp in testPoints: display.EraseAll() display.DisplayColoredShape(heartWire, 'GREEN') wj = WireJoiner(heartWire, tp[0], 0.08) result = wj.build() assert len(Wrappers.Wire(result).edgesAsList()) == tp[1] display.DisplayColoredShape(result, 'RED') time.sleep(1)
def TestWireJoiner(): heartWire = TestObjects.makeHeartWire(); #man this is hard to test without resorting to graphical test. #this is sort of a semi-automatic method testPoints = []; testPoints.append ( [ gp.gp_Pnt(-1.0,0,0),5]); testPoints.append ( [ gp.gp_Pnt(0,-1.0,0),5]); testPoints.append ( [ gp.gp_Pnt(-1.0,-1.0,0),5]); testPoints.append ( [ gp.gp_Pnt(1.0,0,0 ),5]); testPoints.append ( [ gp.gp_Pnt(1.6,1.8,0),6]); testPoints.append ( [ gp.gp_Pnt(4.15,4.4,0),5] ); testPoints.append ( [ gp.gp_Pnt(0.5,3.5,0),5] ); testPoints.append ( [ gp.gp_Pnt(4.0,4.7,0),6] ); for tp in testPoints: display.EraseAll(); display.DisplayColoredShape(heartWire,'GREEN'); wj = WireJoiner(heartWire,tp[0],0.08); result = wj.build(); assert len(Wrappers.Wire(result).edgesAsList()) == tp[1] display.DisplayColoredShape(result,'RED'); time.sleep(1);
""" same as discretePoints, but returns a list of tuples not a generator fo gp_Pnt """ def discreteTuples(self, deflection): r = [] for p in self.discretePoints(deflection): r.append((p.X(), p.Y())) return r def discretePoints(self, deflection): "discrete points for all of a wire" for e in self.edges(): for m in Edge(e).discretePoints(deflection): yield m if __name__ == '__main__': print "Basic Wrappers" from OCC.Display.SimpleGui import * import TestObjects display, start_display, add_menu, add_function_to_menu = init_display() w = TestObjects.makeSquareWire() for e in Wire(w).edgesAsList(): display.DisplayShape(e) start_display()
display.DisplayShape(OCCUtil.make_vertex(p),update=False); print "%d nodes total" % i if __name__=='__main__': from OCC.Display.SimpleGui import * display, start_display, add_menu, add_function_to_menu = init_display() print "******************************" print " HatchLib Unit Tests...." print "******************************" #w = TestDisplay.makeSquareWire(); #box around 0,0 <--> 5,5 #w2=TestDisplay.makeCircleWire(); #circle centered at 2,2, radius 1 #h = Hatcher([w,w2],0.0,( 0,0,5.0,5.0) ); w = TestObjects.makeHeartWire(); w2=TestObjects.makeCircleWire2(); h = Hatcher([w,w2],0.0,( -6,0,10.0,10.0), 0.25, 45 ); #display.DisplayShape(w); #display.DisplayShape(w2); #runProfiled('h.hatch()',0.9); t = Util.Timer(); h.hatch(); q = time.clock(); ww = h.getWires(); print "got Wires in %0.3f" % ( time.clock() - q ); display.DisplayShape(ww,False ); display.FitAll(); g = h.graphBuilder.graph;
print "%d nodes total" % i if __name__ == '__main__': from OCC.Display.SimpleGui import * display, start_display, add_menu, add_function_to_menu = init_display() print "******************************" print " HatchLib Unit Tests...." print "******************************" #w = TestDisplay.makeSquareWire(); #box around 0,0 <--> 5,5 #w2=TestDisplay.makeCircleWire(); #circle centered at 2,2, radius 1 #h = Hatcher([w,w2],0.0,( 0,0,5.0,5.0) ); w = TestObjects.makeHeartWire() w2 = TestObjects.makeCircleWire2() h = Hatcher([w, w2], 0.0, (-6, 0, 10.0, 10.0), 0.25, 45) #display.DisplayShape(w); #display.DisplayShape(w2); #runProfiled('h.hatch()',0.9); t = Util.Timer() h.hatch() q = time.clock() ww = h.getWires() print "got Wires in %0.3f" % (time.clock() - q) display.DisplayShape(ww, False) display.FitAll() g = h.graphBuilder.graph
""" same as discretePoints, but returns a list of tuples not a generator fo gp_Pnt """ def discreteTuples(self,deflection): r = []; for p in self.discretePoints(deflection): r.append(( p.X(), p.Y() ) ); return r; def discretePoints(self,deflection): "discrete points for all of a wire" for e in self.edges(): for m in Edge(e).discretePoints(deflection): yield m; if __name__=='__main__': print "Basic Wrappers" from OCC.Display.SimpleGui import * import TestObjects display, start_display, add_menu, add_function_to_menu = init_display() w = TestObjects.makeSquareWire(); for e in Wire(w).edgesAsList(): display.DisplayShape(e); start_display();
def testBasicFaceOffset2(): f = TestObjects.makeHeartFaceNoHole(); om = OffsetMap(f); om.offsetOnceSimple(-0.2); om.offsetOnceSimple(-0.2); om.offsetOnceSimple(-0.2);
wb.add ( e3); for e in topoWire.edges(): if e.IsSame(e1): continue; if e2 and e.IsSame(e2): continue; wb.add ( e ); return wb.wire(); if __name__=='__main__': from OCC.Display.SimpleGui import * display, start_display, add_menu, add_function_to_menu = init_display() heart = TestObjects.makeHeartWire(); #p1 = gp.gp_Pnt(0.0,-0.5,0.0); p1 = gp.gp_Pnt(2.1,1.5,0.0); v1 = OCCUtil.make_vertex ( gp.gp_Pnt(2.0,3.1,0.0)); #t = time.clock(); #for i in range(1000): # p2 = distToPoint(heart,v1 ); #print "dist time %0.3f" % ( time.clock() - t ); #about 1.6ms per call for a simple heart wire . not too shabby #v2 = OCCUtil.make_vertex ( p2 ); #display.DisplayShape([heart,v1,v2]); #test splitting a wire newWire= makeExtrusionWire(heart,p1,0.25);
def testBasicFaceOffset2(): f = TestObjects.makeHeartFaceNoHole() om = OffsetMap(f) om.offsetOnceSimple(-0.2) om.offsetOnceSimple(-0.2) om.offsetOnceSimple(-0.2)