Skip to content

Commit

Permalink
Merge pull request #428 from tpaviot/review/lgtm-fixes
Browse files Browse the repository at this point in the history
Review/lgtm fixes
  • Loading branch information
tpaviot committed May 26, 2017
2 parents bad3df5 + 56f6d66 commit 76b51d5
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 57 deletions.
2 changes: 1 addition & 1 deletion examples/core_display_line_properties.py
Expand Up @@ -47,7 +47,6 @@ def line():
# To do that, we need to do use AIS_Drawer and apply it to ais_line1
width = 1.0
drawer = Prs3d_Drawer()
asp = Prs3d_LineAspect(Quantity_NOC_RED, Aspect_TOL_DASH, width)
ais_line1.SetAttributes(drawer.GetHandle())

display.Context.Display(ais_line1.GetHandle(), False)
Expand All @@ -61,6 +60,7 @@ def line():

width = float(i)
drawer = ais_line2.Attributes().GetObject()
# asp : first parameter color, second type, last width
asp = Prs3d_LineAspect(9*i, i, width)
drawer.SetLineAspect(asp.GetHandle())
ais_line2.SetAttributes(drawer.GetHandle())
Expand Down
4 changes: 1 addition & 3 deletions examples/core_geometry_splinecage.py
Expand Up @@ -95,7 +95,7 @@ def hash_edge_lenght_to_face(faces):
return _edge_length_to_face, _edge_length_to_edge


def build_curve_network(event=None):
def build_curve_network(event=None, enforce_tangency=True):
'''
mimic the curve network surfacing command from rhino
'''
Expand Down Expand Up @@ -132,8 +132,6 @@ def build_curve_network(event=None):

brep_plate_builder = BRepOffsetAPI_MakeFilling()

enforce_tangency = True

if enforce_tangency:
print("going for surface quality")
brep_plate_builder.SetConstrParam(0.0001, 0.001, 0.01, 0.01) # ?!!! Tol2d=1.0, Tol3d=1.0, TolAng=1.0, TolCurv=1.0
Expand Down
5 changes: 3 additions & 2 deletions examples/core_modeling_sprocket.py
Expand Up @@ -20,6 +20,7 @@
# This example is a port of the C++ code
# available at http://www.algotopia.com/contents/opencascade/opencascade_sprocket

import sys
from math import pi as M_PI, sin, cos, pow, atan

from OCC.gp import gp_Pnt2d, gp_Ax2d, gp_Dir2d, gp_Circ2d, gp_Origin2d, gp_DX2d, \
Expand Down Expand Up @@ -119,7 +120,7 @@ def build_tooth():
elif num_points == 1:
p2 = inter.Point(1)
else:
exit(-1)
sys.exit(-1)

# Trim the profile circle and mirror
trimmed_profile = GCE2d_MakeArcOfCircle(profile_circle, p1, p2).Value()
Expand Down Expand Up @@ -207,7 +208,7 @@ def round_tooth(wedge):
# Construct the rounding circle
round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01)
if (round_circle.NbSolutions() != 2):
exit(-2)
sys.exit(-2)

round_circle_2d_1 = round_circle.ThisSolution(1)
round_circle_2d_2 = round_circle.ThisSolution(2)
Expand Down
1 change: 0 additions & 1 deletion examples/core_simple_mesh.py
Expand Up @@ -35,7 +35,6 @@ def simple_mesh():
#
# Create the shape
#
shape = BRepPrimAPI_MakeBox(200, 200, 200).Shape()
theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape()
theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape()
shape = BRepAlgoAPI_Fuse(theSphere, theBox).Shape()
Expand Down
4 changes: 2 additions & 2 deletions examples/core_topology_face.py
Expand Up @@ -71,8 +71,8 @@ def face():

##TopoDS_Wire YellowWire
MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge())
if MW1.IsDone():
yellow_wire = MW1.Wire()
assert MW1.IsDone()
yellow_wire = MW1.Wire()
brown_face = BRepBuilderAPI_MakeFace(yellow_wire)

#The pink face
Expand Down
16 changes: 9 additions & 7 deletions examples/core_topology_fillet.py
Expand Up @@ -61,6 +61,7 @@ def fillet(event=None):


def variable_filleting(event=None):
display.EraseAll()
# Create Box
Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape()
# Fillet
Expand All @@ -74,6 +75,9 @@ def variable_filleting(event=None):
Rake.Build()
if Rake.IsDone():
evolvedBox = Rake.Shape()
display.DisplayShape(evolvedBox)
else:
print("Rake not done.")
# Create Cylinder
Cylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape()
fillet = BRepFilletAPI_MakeFillet(Cylinder)
Expand All @@ -89,7 +93,8 @@ def variable_filleting(event=None):
if fillet.IsDone():
LawEvolvedCylinder = fillet.Shape()
display.DisplayShape(LawEvolvedCylinder)

else:
print("fillet not done.") ## TODO : fillet not done
P = gp_Pnt(350, 0, 0)
Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape()
afillet = BRepFilletAPI_MakeFillet(Box2)
Expand Down Expand Up @@ -117,12 +122,9 @@ def variable_filleting(event=None):
afillet.Build()
if afillet.IsDone():
LawEvolvedBox = afillet.Shape()

display.EraseAll()
display.DisplayShape(Box)
display.EraseAll()
display.DisplayShape(evolvedBox)
display.DisplayShape(LawEvolvedBox)
else:
print("aFillet not done.")
display.DisplayShape(LawEvolvedBox)
display.FitAll()


Expand Down
48 changes: 23 additions & 25 deletions src/Display/WebGl/threejs_renderer.py
Expand Up @@ -393,45 +393,35 @@ def DisplayShape(self,
# generate the mesh
#tess.ExportShapeToThreejs(shape_hash, shape_full_path)
# and also to JSON
json_file = open(shape_full_path, 'w')
json_file.write(tess.ExportShapeToThreejsJSONString(shape_uuid))
json_file.close()
with open(shape_full_path, 'w') as json_file:
json_file.write(tess.ExportShapeToThreejsJSONString(shape_uuid))
# draw edges if necessary
edges = []
if export_edges:
# export each edge to a single json
# get number of edges
nbr_edges = tess.ObjGetEdgeCount()
for i_edge in range(nbr_edges):
edge_hash = "edg%s" % uuid.uuid4().hex
# create the file
edge_full_path = os.path.join(self._path, edge_hash + '.json')
edge_file = open(edge_full_path, "w")
# after that, the file can be appended
str_to_write = ''
edge_point_set = []
nbr_vertices = tess.ObjEdgeGetVertexCount(i_edge)
for i_vert in range(nbr_vertices):
edge_point_set.append(tess.GetEdgeVertex(i_edge, i_vert))
# write to file
edge_hash = "edg%s" % uuid.uuid4().hex
str_to_write += ExportEdgeToJSON(edge_hash, edge_point_set)
edge_file.write(str_to_write)
edge_file.close()
# create the file
edge_full_path = os.path.join(self._path, edge_hash + '.json')
with open(edge_full_path, "w") as edge_file:
edge_file.write(str_to_write)
# store this edge hash
self._edges_hash.append(edge_hash)

def GenerateHTMLFile(self):
""" Generate the HTML file to be rendered by the web browser
"""
global BODY_Part0
fp = open(self._html_filename, "w")
fp.write("<!DOCTYPE HTML>")
fp.write('<html>')
# header
fp.write(HTMLHeader().get_str())
# body
BODY_Part0 = BODY_Part0.replace('@VERSION@', OCC_VERSION)
fp.write(BODY_Part0)
fp.write(HTMLBody_Part1().get_str())
# loop over shapes to generate html shapes stuff
# the following line is a list that will help generating the string
# using "".join()
Expand Down Expand Up @@ -461,8 +451,6 @@ def GenerateHTMLFile(self):
else:
shape_string_list.append("\t});\n")
shape_idx += 1
# write the string for the shape
fp.write("".join(shape_string_list))
# Process edges
edge_string_list = []
for edge_id in self._edges_hash:
Expand All @@ -472,11 +460,21 @@ def GenerateHTMLFile(self):
# add mesh to scene
edge_string_list.append("\tscene.add(line);\n")
edge_string_list.append("\t});\n")
fp.write("".join(edge_string_list))
# then write header part 2
fp.write(BODY_Part2)
fp.write("</html>\n")
fp.close()
# write the string for the shape
with open(self._html_filename, "w") as fp:
fp.write("<!DOCTYPE HTML>")
fp.write('<html>')
# header
fp.write(HTMLHeader().get_str())
# body
BODY_Part0 = BODY_Part0.replace('@VERSION@', OCC_VERSION)
fp.write(BODY_Part0)
fp.write(HTMLBody_Part1().get_str())
fp.write("".join(shape_string_list))
fp.write("".join(edge_string_list))
# then write header part 2
fp.write(BODY_Part2)
fp.write("</html>\n")
print("File written to %s" % self._html_filename)

def render(self, server_port=8080):
Expand Down
22 changes: 10 additions & 12 deletions src/Display/WebGl/x3dom_renderer.py
Expand Up @@ -259,9 +259,8 @@ def to_x3dfile_string(self):
return x3dfile_str

def write_to_file(self, filename):
f = open(filename, "w")
f.write(self.to_x3dfile_string())
f.close()
with open(filename, "w") as f:
f.write(self.to_x3dfile_string())


class X3DomRenderer(object):
Expand Down Expand Up @@ -326,15 +325,14 @@ def GenerateHTMLFile(self):
""" Generate the HTML file to be rendered wy the web browser
"""
print("File written to %s" % self._path)
fp = open(self._html_filename, "w")
fp.write("<!DOCTYPE HTML>")
fp.write('<html lang="en">')
# header
fp.write(HTMLHeader().get_str())
# body
fp.write(HTMLBody(self._x3d_shapes).get_str())
fp.write("</html>\n")
fp.close()
with open(self._html_filename, "w") as fp:
fp.write("<!DOCTYPE HTML>")
fp.write('<html lang="en">')
# header
fp.write(HTMLHeader().get_str())
# body
fp.write(HTMLBody(self._x3d_shapes).get_str())
fp.write("</html>\n")


if __name__ == "__main__":
Expand Down
4 changes: 0 additions & 4 deletions src/Display/qtDisplay.py
Expand Up @@ -23,9 +23,6 @@
import os
import sys

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
log = logging.getLogger(__name__)

from OCC.Display import OCCViewer
from OCC.Display.backend import get_qt_modules

Expand Down Expand Up @@ -256,7 +253,6 @@ def mouseReleaseEvent(self, event):
modifiers = event.modifiers()

if event.button() == QtCore.Qt.LeftButton:
pt = point(event.pos())
if self._select_area:
[Xmin, Ymin, dx, dy] = self._drawbox
self._display.SelectArea(Xmin, Ymin, Xmin + dx, Ymin + dy)
Expand Down

0 comments on commit 76b51d5

Please sign in to comment.