Ejemplo n.º 1
0
def line():
    # create a line
    p1 = gp_Pnt(2., 3., 4.)
    d1 = gp_Dir(4., 5., 6.)
    line1 = Geom_Line(p1, d1)

    ais_line1 = AIS_Line(line1)

    # if we need to edit color, we can simply use SetColor
    # ais_line1.SetColor(Quantity_NOC_RED)

    # but actually we need to edit more, not just color. Line width and style as well
    # To do that, we need to do use AIS_Drawer and apply it to ais_line1
    drawer = Prs3d_Drawer()
    ais_line1.SetAttributes(drawer)

    display.Context.Display(ais_line1, False)
    # we can apply the same rule for other lines by just doing a for loop
    for i in range(1, 5):
        p2 = gp_Pnt(i, 2., 5.)
        d2 = gp_Dir(4 * i, 6., 9.)
        line2 = Geom_Line(p2, d2)

        ais_line2 = AIS_Line(line2)

        width = float(i)
        drawer = ais_line2.Attributes()
        # asp : first parameter color, second type, last width
        asp = Prs3d_LineAspect(9 * i, i, width)
        drawer.SetLineAspect(asp)
        ais_line2.SetAttributes(drawer)

        display.Context.Display(ais_line2, False)
    start_display()
Ejemplo n.º 2
0
 def make_axis_triedron(self):
     self.x_axis = AIS_Axis(
         Geom_Line(gp_Lin(gp_Pnt(0, 0, 0), gp_Dir(gp_XYZ(1, 0, 0)))))
     self.y_axis = AIS_Axis(
         Geom_Line(gp_Lin(gp_Pnt(0, 0, 0), gp_Dir(gp_XYZ(0, 1, 0)))))
     self.z_axis = AIS_Axis(
         Geom_Line(gp_Lin(gp_Pnt(0, 0, 0), gp_Dir(gp_XYZ(0, 0, 1)))))
     self.x_axis.SetColor(Quantity_Color(1, 0, 0, Quantity_TOC_RGB))
     self.y_axis.SetColor(Quantity_Color(0, 1, 0, Quantity_TOC_RGB))
     self.z_axis.SetColor(Quantity_Color(0, 0, 1, Quantity_TOC_RGB))
Ejemplo n.º 3
0
def reflect(p0, v0, face):
    h_surf = BRep_Tool.Surface(face)
    ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0)))
    uvw = GeomAPI_IntCS(ray.GetHandle(), h_surf).Parameters(1)
    u, v, w = uvw
    p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
    vz = vx.Crossed(vy)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz)))
    return p1, v1
Ejemplo n.º 4
0
 def to_Geom_Line(self):
     return Geom_Line(
         gp_Lin(
             gp_Pnt(0, 0, 0),
             gp_Dir(
                 gp_XYZ(self._coords[0], self._coords[1],
                        self._coords[2]))))
 def test_Standard_Type(self) -> None:
     """ test that Standard_Type returns the correct type name
     """
     edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, 0), gp_Pnt(1, 0, 0)).Edge()
     curve, _, _ = BRep_Tool_Curve(edge)
     line = Geom_Line.DownCast(curve)
     self.assertEqual(line.DynamicType().Name(), "Geom_Line")
Ejemplo n.º 6
0
    def mk_colored_line(self, start, direction, color, linestyle, width):
        line = Geom_Line(start, direction)
        ais_line = AIS_Line(line)

        drawer = ais_line.Attributes()
        aspect = Prs3d_LineAspect(color, linestyle, width)
        drawer.SetLineAspect(aspect)
        ais_line.SetAttributes(drawer)
        return ais_line
Ejemplo n.º 7
0
 def geomLineBldr(self, cline):
     """Convert native cline to type: <Geom_Line>."""
     a, b, c = cline
     gpLin2d = gp_Lin2d(a, b, c)
     gpDir2d = gpLin2d.Direction()
     gpPnt2d = gpLin2d.Location()
     gpPnt = gp_Pnt(gpPnt2d.X(), gpPnt2d.Y(), 0).Transformed(self.Trsf)
     gpDir = gp_Dir(gpDir2d.X(), gpDir2d.Y(), 0).Transformed(self.Trsf)
     return Geom_Line(gpPnt, gpDir)
Ejemplo n.º 8
0
 def Reflect(self):
     h_surf = BRep_Tool.Surface(self.tar.srf)
     g_line = gp_Lin(self.ini.beam.Location(), self.ini.beam.Direction())
     ray = Geom_Line(g_line)
     if GeomAPI_IntCS(ray, h_surf).NbPoints():
         self.tar.beam = reflect(self.ini.beam, self.tar.srf)
     else:
         pln = make_plane(self.tar.axs.Location(),
                          dir_to_vec(self.tar.axs.Direction()), 500, -500,
                          500, -500)
         self.tar.beam = reflect(self.ini.beam, pln)
 def test_downcast_curve(self) -> None:
     """Test if a GeomCurve can be DownCasted to a GeomLine"""
     edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, 0), gp_Pnt(1, 0, 0)).Edge()
     curve, _, _ = BRep_Tool_Curve(edge)
     self.assertTrue(isinstance(curve, Geom_Curve))
     # The edge is internally a line, so we should be able to downcast it
     line = Geom_Line.DownCast(curve)
     self.assertTrue(isinstance(line, Geom_Curve))
     # Hence, it should not be possible to downcast it as a B-Spline curve
     bspline = Geom_BSplineCurve.DownCast(curve)
     self.assertTrue(bspline is None)
Ejemplo n.º 10
0
    def __init__(self, theDisplay, sg: Sketch_QTGUI = None):
        self.myCoordinateSystem = gp_Ax3(gp.XOY())
        self.myContext: AIS_InteractiveContext = theDisplay.Context
        self.myDisplay = theDisplay
        self.myView: V3d_View = theDisplay.View
        self.myGUI = sg
        self.myGUI.SetAx3(self.myCoordinateSystem)
        self.myGUI.SetContext(self.myContext)

        self.myCurrentMethod = Sketch_ObjectTypeOfMethod.Nothing_Method

        self.myCurrentDir: gp_Dir = gp.DZ()
        self.myTempPnt: gp_Pnt = gp.Origin()
        self.myCurrentPnt2d: gp_Pnt2d = gp.Origin2d()
        self.myCurrentPlane = Geom_Plane(self.myCoordinateSystem)
        self.myCurrentLine = Geom_Line(self.myTempPnt, self.myCurrentDir)

        self.myIntCS = GeomAPI_IntCS()

        self.PolylineFirstPoint = gp.Origin2d()
        self.PolylineFirstPointExist = False

        self.myData = []
        self.myNode: SketchObjectNode = None
        self.myModel = None
        self.SnapToGridPoint = False
        self.myCommands = []

        self.myAnalyserSnap = Sketch_AnalyserSnap(self.myContext, self.myData,
                                                  self.myCoordinateSystem)

        self.addCommand(Sketch_CommandPoint())
        self.addCommand(Sketch_CommandLine2P())
        self.addCommand(Sketch_CommandBezierCurve())
        self.addCommand(Sketch_CommandArcCenter2P())
        self.addCommand(Sketch_CommandCircleCenterRadius())
        self.addCommand(Sketch_CommandBSpline())
        self.addCommand(Sketch_CommandPointToBSpline())
        self.addCommand(Sketch_CommandMoveObject())
        self.addCommand(Sketch_CommandNurbCircleSquare())
        self.addCommand(Sketch_CommandNurbCircleTriangle())
Ejemplo n.º 11
0
 def reflect_b2(self, num=1):
     h_surf = BRep_Tool.Surface(self.b2)
     ray = Geom_Line(self.beam.Axis())
     self.RayTrace.Perform(ray.GetHandle(), h_surf)
     if self.RayTrace.NbPoints() == 0:
         beam = self.beam
     else:
         self.num += 1
         uvw = self.RayTrace.Parameters(num)
         u, v, w = uvw
         p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
         GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
         vz = vx.Crossed(vy).Reversed()
         norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
         self.show_axs_pln(norm, scale=10)
         beam = self.beam
         beam.SetLocation(p1)
         beam.SetDirection(beam.Direction().Reversed())
         beam.Mirror(norm.Axis())
         print(self.num, self.b2, p1)
         self.pts.append(p1)
         # self.beam.XReverse()
         # self.beam.Mirror(norm.Ax2())
     return beam
Ejemplo n.º 12
0
    def addLines(self):

        origin = (0, 0, 0)
        ais_list = []

        for name, color, direction in zip(('X', 'Y', 'Z'),
                                          ('ff0000', '00ff00', '0000ff'),
                                          ((1, 0, 0), (0, 1, 0), (0, 0, 1))):
            line_placement = Geom_Line(
                gp_Ax1(gp_Pnt(*origin), gp_Dir(*direction)))
            line = AIS_Line(line_placement)

            self.Helpers.addChild(ObjectTreeItem(name, ais=line, color=color))

            ais_list.append(line)

        self.sigObjectsAdded.emit(ais_list)
Ejemplo n.º 13
0
 def FindGeometry(self, object: AIS_InteractiveObject):
     if object.Type() == AIS_KOI_Shape:
         shape = self.myContext.SelectedShape()
         if shape.ShapeType() == TopAbs_VERTEX:
             pass
         elif shape.ShapeType() == TopAbs_EDGE:
             curve = BRepAdaptor_Curve(shape)
             curve_type = curve.GetType()
             if curve_type == GeomAbs_BezierCurve:
                 return curve.Bezier()
             elif curve_type == GeomAbs_BSplineCurve:
                 return curve.BSpline()
             elif curve_type == GeomAbs_Circle:
                 return Geom_Circle(curve.Circle())
             elif curve_type == GeomAbs_Line:
                 return Geom_Line(curve.Line())
         elif shape.ShapeType() == TopAbs_FACE:
             pass
Ejemplo n.º 14
0
    def __init__(self):
        plotocc.__init__(self)
        self.b1 = self.get_face(gen_ellipsoid(rxyz=[100, 100, 105]))
        self.b2 = self.get_face(gen_ellipsoid(rxyz=[210, 210, 210]))
        self.beam = gp_Ax3(gp_Pnt(0, 150, 0), gp_Dir(1, 1.5, 0))
        print(self.b1)

        h_surf = BRep_Tool.Surface(self.b2)
        ray = Geom_Line(self.beam.Axis())
        self.RayTrace = GeomAPI_IntCS(ray, h_surf)
        print(self.RayTrace.NbPoints())
        self.num = 0
        self.pts = [self.beam.Location()]
        for i in range(5):
            self.beam = self.reflect_b1(num=1)
            self.beam = self.reflect_b1(num=2)
            self.beam = self.reflect_b2(num=1)
            self.beam = self.reflect_b2(num=2)
Ejemplo n.º 15
0
    def addLines(self):

        origin = (0, 0, 0)
        ais_list = []

        for name, color, direction in zip(('X', 'Y', 'Z'),
                                          ('red', 'lawngreen', 'blue'),
                                          ((1, 0, 0), (0, 1, 0), (0, 0, 1))):
            line_placement = Geom_Line(
                gp_Ax1(gp_Pnt(*origin), gp_Dir(*direction)))
            line = AIS_Line(line_placement)
            line.SetColor(to_occ_color(color))

            self.Helpers.addChild(ObjectTreeItem(name, ais=line))

            ais_list.append(line)

        self.sigObjectsAdded.emit(ais_list)
Ejemplo n.º 16
0
    def addLines(self):

        origin = (0, 0, 0)
        ais_list = []

        for name, color, direction in zip(('X', 'Y', 'Z'), (RED, GREEN, BLUE),
                                          ((1, 0, 0), (0, 1, 0), (0, 0, 1))):
            line_placement = Geom_Line(
                gp_Ax1(gp_Pnt(*origin), gp_Dir(*direction)))
            line = AIS_Line(line_placement)
            line.SetColor(color)

            self.Helpers.addChild(ObjectTreeItem(name, ais=line))

            ais_list.append(line)

        self.sigObjectsAdded.emit(ais_list)
        self.tree.expandToDepth(1)
Ejemplo n.º 17
0
def reflect_axs2(beam, surf, axs=gp_Ax3(), indx=1):
    p0, v0 = beam.Location(), dir_to_vec(beam.Direction())
    h_surf = BRep_Tool.Surface(surf)
    ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0)))
    if GeomAPI_IntCS(ray, h_surf).NbPoints() == 0:
        return beam, beam, None
    elif GeomAPI_IntCS(ray, h_surf).NbPoints() == 1:
        return beam, beam, None
    GeomAPI_IntCS(ray, h_surf).IsDone()
    u, v, w = GeomAPI_IntCS(ray, h_surf).Parameters(indx)
    p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
    vz = vx.Crossed(vy)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz), vec_to_dir(vx)))
    norm_ax = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
    beam_ax = gp_Ax3(p1, vec_to_dir(v1), beam.XDirection().Reversed())
    return beam_ax, norm_ax, 1
Ejemplo n.º 18
0
    def intersections_with_line(self, line):
        """Compute the intersections with a line.

        Parameters
        ----------
        line : :class:`~compas.geometry.Line`

        Returns
        -------
        list[:class:`~compas.geometry.Point`]

        """
        intersection = GeomAPI_IntCS(Geom_Line(line.to_occ()),
                                     self.occ_surface)
        points = []
        for index in range(intersection.NbPoints()):
            pnt = intersection.Point(index + 1)
            point = Point.from_occ(pnt)
            points.append(point)
        return points
Ejemplo n.º 19
0
def reflect(beam, face, axs=gp_Ax3()):
    p0, v0 = beam.Location(), dir_to_vec(beam.Direction())
    h_surf = BRep_Tool.Surface(face)
    ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0)))
    if GeomAPI_IntCS(ray, h_surf).NbPoints() == 0:
        print("Out of Surface", axs.Location())
        pln = make_plane(axs.Location(), dir_to_vec(axs.Direction()), 500,
                         -500, 500, -500)
        h_surf = BRep_Tool.Surface(pln)
    GeomAPI_IntCS(ray, h_surf).IsDone()
    uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1)
    u, v, w = uvw
    p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
    vz = vx.Crossed(vy)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz), vec_to_dir(vx)))
    return gp_Ax3(p1, vec_to_dir(v1), beam.XDirection().Reversed())
Ejemplo n.º 20
0
 def Reflect(self, beam=gp_Ax3(), surf=make_plane()):
     h_surf = BRep_Tool.Surface(surf)
     ray = Geom_Line(beam.Location(), beam.Direction())
     if GeomAPI_IntCS(ray, h_surf).NbPoints() == 0:
         beam_v1 = beam
     else:
         GeomAPI_IntCS(ray, h_surf).IsDone()
         uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1)
         u, v, w = uvw
         p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
         GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
         vz = vx.Crossed(vy)
         vx.Normalize()
         vy.Normalize()
         vz.Normalize()
         norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
         beam_v0 = beam
         beam_v0.SetLocation(p1)
         beam_v1 = beam_v0.Mirrored(norm.Ax2())
         beam_v1.XReverse()
     return beam_v1
Ejemplo n.º 21
0
    def Reflect(self):
        h_surf = BRep_Tool.Surface(self.tar.srf)
        g_line = gp_Lin(self.ini.beam.Location(), self.ini.beam.Direction())
        ray = Geom_Line(g_line)
        if GeomAPI_IntCS(ray, h_surf).NbPoints():
            self.tar.beam = reflect(self.ini.beam, self.tar.srf)
        else:
            pln = make_plane(self.tar.axs.Location(),
                             dir_to_vec(self.tar.axs.Direction()), 500, -500,
                             500, -500)
            h_surf = BRep_Tool.Surface(pln)
            self.tar.beam = reflect(self.ini.beam, pln)

        print(self.ini.beam.Location())
        print(self.tar.beam.Location())

        GeomAPI_IntCS(ray, h_surf).IsDone()
        uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1)
        u, v, w = uvw
        print(u, v, w)
        vz, v1, v2, r1, r2 = axs_curvature(h_surf, u, v)

        tar_surf_axs = gp_Ax3(self.tar.beam.Location(), vec_to_dir(vz),
                              vec_to_dir(v1))
        tar_surf = wavefront([r1, r2], tar_surf_axs)
        self.display.DisplayShape(tar_surf, color="BLUE")
        self.display.DisplayShape(axs_pln(tar_surf_axs))

        self.GO_Prop(w)

        h_tar_wave = BRep_Tool.Surface(self.ini_wave)
        vz, v1, v2, r1, r2 = axs_curvature(h_tar_wave, u, v)
        tar_wave_axs = self.tar.beam.Translated(gp_Vec(0, 0, 0))
        tar_wave_axs.SetXDirection(vec_to_dir(v1))
        self.tar.wave = wavefront([r1, r2], tar_wave_axs)
        self.display.DisplayShape(self.tar.wave, color="RED")
        self.display.DisplayShape(axs_pln(tar_wave_axs))
Ejemplo n.º 22
0
 def reflect_beam(self, beam0=gp_Ax3(), tr=0):
     v0 = dir_to_vec(beam0.Direction())
     v1 = dir_to_vec(beam0.XDirection())
     surf = BRep_Tool.Surface(self.surf)
     ray = Geom_Line(beam0.Axis())
     uvw = GeomAPI_IntCS(ray, surf).Parameters(1)
     u, v, w = uvw
     p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
     GeomLProp_SurfaceTool.D1(surf, u, v, p1, vx, vy)
     vz = vx.Crossed(vy)
     if vz.Dot(v0) > 0:
         vz.Reverse()
     vx.Normalize()
     vy.Normalize()
     vz.Normalize()
     self.beam = gp_Ax3(p1, vec_to_dir(v0.Reversed()),
                        vec_to_dir(v1.Reversed()))
     self.norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
     if tr == 0:
         self.beam.Mirror(self.norm.Ax2())
         if self.beam.Direction().Dot(self.norm.Direction()) < 0:
             self.beam.ZReverse()
     elif tr == 1:
         self.beam.ZReverse()
Ejemplo n.º 23
0
def _line(pnt, dir) -> Curve:
    return Curve(Geom_Line(to_Pnt(pnt), to_Dir(dir)))
Ejemplo n.º 24
0
 def proj_pnt_pln(self, pnt, surf, axs=gp_Ax3()):
     lin = gp_Lin(pnt, axs.Direction())
     sxy = GeomAPI_IntCS(Geom_Line(lin), BRep_Tool.Surface(surf)).Point(1)
     return sxy
Ejemplo n.º 25
0
points1.append(Point(-7, 2, 2))
points1.append(Point(-6, 3, 1))
points1.append(Point(-4, 3, -1))
points1.append(Point(-3, 5, -2))
spline1 = BSplineCurve.from_points(points1)

points2 = []
points2.append(Point(-4, 0, 2))
points2.append(Point(-2, 2, 0))
points2.append(Point(2, 3, -1))
points2.append(Point(3, 7, -2))
points2.append(Point(4, 9, -1))
spline2 = BSplineCurve.from_points(points2)

surface = BSplineSurface.from_fill(spline1, spline2)
line = Geom_Line(gp_Pnt(0, 4, 0), gp_Dir(0, 0, 1))

# ==============================================================================
# Intersection
# ==============================================================================

intersection = GeomAPI_IntCS(line, surface.occ_surface)

pnt = intersection.Point(1)
point = Point.from_occ(pnt)

# ==============================================================================
# Viz
# ==============================================================================

mesh = surface.to_vizmesh()
Ejemplo n.º 26
0
def Prj_pnt_to_face(axs, pnt, face):
    lin = gp_Lin(pnt, axs.Direction())
    sxy = GeomAPI_IntCS(Geom_Line(lin).GetHandle(),
                        BRep_Tool.Surface(face)).Point(1)
    return sxy
Ejemplo n.º 27
0
class Sketch(object):
    def __init__(self, theDisplay, sg: Sketch_QTGUI = None):
        self.myCoordinateSystem = gp_Ax3(gp.XOY())
        self.myContext: AIS_InteractiveContext = theDisplay.Context
        self.myDisplay = theDisplay
        self.myView: V3d_View = theDisplay.View
        self.myGUI = sg
        self.myGUI.SetAx3(self.myCoordinateSystem)
        self.myGUI.SetContext(self.myContext)

        self.myCurrentMethod = Sketch_ObjectTypeOfMethod.Nothing_Method

        self.myCurrentDir: gp_Dir = gp.DZ()
        self.myTempPnt: gp_Pnt = gp.Origin()
        self.myCurrentPnt2d: gp_Pnt2d = gp.Origin2d()
        self.myCurrentPlane = Geom_Plane(self.myCoordinateSystem)
        self.myCurrentLine = Geom_Line(self.myTempPnt, self.myCurrentDir)

        self.myIntCS = GeomAPI_IntCS()

        self.PolylineFirstPoint = gp.Origin2d()
        self.PolylineFirstPointExist = False

        self.myData = []
        self.myNode: SketchObjectNode = None
        self.myModel = None
        self.SnapToGridPoint = False
        self.myCommands = []

        self.myAnalyserSnap = Sketch_AnalyserSnap(self.myContext, self.myData,
                                                  self.myCoordinateSystem)

        self.addCommand(Sketch_CommandPoint())
        self.addCommand(Sketch_CommandLine2P())
        self.addCommand(Sketch_CommandBezierCurve())
        self.addCommand(Sketch_CommandArcCenter2P())
        self.addCommand(Sketch_CommandCircleCenterRadius())
        self.addCommand(Sketch_CommandBSpline())
        self.addCommand(Sketch_CommandPointToBSpline())
        self.addCommand(Sketch_CommandMoveObject())
        self.addCommand(Sketch_CommandNurbCircleSquare())
        self.addCommand(Sketch_CommandNurbCircleTriangle())

    def SetContext(self, theContext: AIS_InteractiveContext):
        self.myContext = theContext
        self.myAnalyserSnap.SetContext(self.myContext)
        self.myGUI.SetContext(theContext)
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            self.CurCommand.SetContext(self.myContext)

    def SetData(self, thedata: list):
        self.myData = thedata
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            self.CurCommand.SetData(self.myData)

    def SetRootNode(self, theNode):
        self.myNode = theNode
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            self.CurCommand.SetRootNode(self.myNode)

    def SetModel(self, theModel):
        self.myModel = theModel
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            self.CurCommand.SetModel(self.myModel)

    def GetData(self):
        return self.myData

    def SetCoordinateSystem(self, theCS: gp_Ax3):
        self.myCoordinateSystem = theCS
        self.myCurrentPlane.SetPosition(self.myCoordinateSystem)
        self.myAnalyserSnap.SetAx3(self.myCoordinateSystem)
        self.myGUI.SetAx3(self.myCoordinateSystem)
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            self.CurCommand.SetAx3(self.myCoordinateSystem)

    def GetCoordinateSystem(self):
        return self.myCoordinateSystem

    def SetPrecise(self, aPrecise: float):
        if aPrecise > 0:
            self.myAnalyserSnap.SetMinDistance(aPrecise)

    def SetColor(self, theColor: Quantity_Color):
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            self.CurCommand.SetColor(theColor)

    def SetType(self, theType: Sketch_ObjectType):
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            self.CurCommand.SetType(theType)

    def SetStyle(self, theLineStyle: Prs3d_LineAspect):
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            self.CurCommand.SetStyle(theLineStyle)

    def ObjectAction(self, theMethod: Sketch_ObjectTypeOfMethod):
        self.myCurrentMethod = theMethod
        self.SelectCurCommand()
        self.CurCommand.Action()
        if (self.myCurrentMethod == Sketch_ObjectTypeOfMethod.Line2P_Method
                or self.myCurrentMethod
                == Sketch_ObjectTypeOfMethod.ArcCenter2P_Method
            ) and self.PolylineFirstPointExist:
            self.CurCommand.SetPolylineFirstPnt(self.PolylineFirstPoint)
        else:
            self.PolylineFirstPointExist = False

    def GetStatus(self):
        return self.myCurrentMethod

    def ProjectPointOnPlane(self, v3dX, v3dY, v3dZ, projVx, projVy, projVz):
        self.myTempPnt.SetCoord(v3dX, v3dY, v3dZ)
        self.myCurrentDir.SetCoord(projVx, projVy, projVz)

        self.myCurrentLine.SetDirection(self.myCurrentDir)
        self.myCurrentLine.SetLocation(self.myTempPnt)
        # pnt=self.myCurrentPlane.Pln().Location ()
        # print(pnt.X(),pnt.Y(),pnt.Z())
        self.myIntCS.Perform(
            self.myCurrentLine,
            self.myCurrentPlane)  # perfrom intersection calculation
        if self.myIntCS.NbPoints() >= 1:
            self.myTempPnt = self.myIntCS.Point(1)
            self.myCurrentPnt2d.SetX(
                (self.myTempPnt.X() - self.myCoordinateSystem.Location().X()) *
                self.myCoordinateSystem.XDirection().X() +
                (self.myTempPnt.Y() - self.myCoordinateSystem.Location().Y()) *
                self.myCoordinateSystem.XDirection().Y() +
                (self.myTempPnt.Z() - self.myCoordinateSystem.Location().Z()) *
                self.myCoordinateSystem.XDirection().Z())
            self.myCurrentPnt2d.SetY(
                (self.myTempPnt.X() - self.myCoordinateSystem.Location().X()) *
                self.myCoordinateSystem.YDirection().X() +
                (self.myTempPnt.Y() - self.myCoordinateSystem.Location().Y()) *
                self.myCoordinateSystem.YDirection().Y() +
                (self.myTempPnt.Z() - self.myCoordinateSystem.Location().Z()) *
                self.myCoordinateSystem.YDirection().Z())
            return True
        else:
            return False

    def OnMouseInputEvent(self, *kargs):
        theX, theY, buttons, modifier = kargs
        aView: V3d_View = self.myView
        v3dX, v3dY, v3dZ, projVx, projVy, projVz = aView.ConvertWithProj(
            theX, theY)
        if self.SnapToGridPoint:
            # grid echo
            v3dX, v3dY, v3dZ = self.myView.ConvertToGrid(theX, theY)
            self.myDisplay.Viewer.ShowGridEcho(
                self.myView, Graphic3d_Vertex(v3dX, v3dY, v3dZ))
            self.myDisplay.Viewer.SetGridEcho(True)
        if self.ProjectPointOnPlane(v3dX, v3dY, v3dZ, projVx, projVy, projVz):
            self.SelectCurCommand()
            if self.CurCommand.MouseInputEvent(self.myCurrentPnt2d, buttons,
                                               modifier):
                self.myCurrentMethod = Sketch_ObjectTypeOfMethod.Nothing_Method

    def OnMouseMoveEvent(self, *kargs):
        theX, theY, buttons, modifier = kargs
        aView: V3d_View = self.myView
        v3dX, v3dY, v3dZ, projVx, projVy, projVz = aView.ConvertWithProj(
            theX, theY)
        if self.SnapToGridPoint:
            # grid echo
            v3dX, v3dY, v3dZ = self.myView.ConvertToGrid(theX, theY)
            self.myDisplay.Viewer.ShowGridEcho(
                self.myView, Graphic3d_Vertex(v3dX, v3dY, v3dZ))
            self.myDisplay.Viewer.SetGridEcho(True)
        if self.ProjectPointOnPlane(v3dX, v3dY, v3dZ, projVx, projVy, projVz):
            self.SelectCurCommand()
            self.CurCommand.MouseMoveEvent(self.myCurrentPnt2d, buttons,
                                           modifier)

    def OnMouseReleaseEvent(self, *kargs):
        buttons, modifier = kargs
        self.SelectCurCommand()
        self.CurCommand.MouseReleaseEvent(buttons, modifier)

    def GetCurPoint2D(self):
        return self.myCurrentPnt2d

    def GetCurPoint3D(self):
        return elclib.To3d(self.myCoordinateSystem.Ax2(), self.myCurrentPnt2d)

    def SetPickTolerance(self, thePrecision):
        # selector
        selector_manager = self.myContext.MainSelector()
        # self._display.Context.SetPixelTolerance(5)
        selector_manager.SetPixelTolerance(thePrecision)
        print(selector_manager.PixelTolerance())

    def OnCancel(self):
        self.SelectCurCommand()
        self.myAnalyserSnap.Cancel()
        if (self.myCurrentMethod == Sketch_ObjectTypeOfMethod.Line2P_Method
                and self.myCurrentMethod
                == Sketch_ObjectTypeOfMethod.ArcCenter2P_Method):
            self.PolylineFirstPointExist = self.CurCommand.GetPolylineFirstPnt(
                self.PolylineFirstPoint)
        self.CurCommand.CancelEvent()
        self.myCurrentMethod = Sketch_ObjectTypeOfMethod.Nothing_Method
        # Acitivate selection automaticlly
        # self.myContext.SetAutoActivateSelection(True)
        # self.SetPickTolerance(20)
        # self.myContext.ActivatedModes()
        # # for all the sketch object selectable
        # self.myContext.Deactivate()
        self.myContext.Activate(0)

    def DeleteSelectedObject(self):
        index = 0
        while index < self.myNode.childCount():
            child = self.myNode.child(index)
            assert isinstance(child, SketchObjectNode)
            myCurObject: Sketch_Geometry = child.getSketchObject()
            if self.myContext.IsSelected(myCurObject.GetAIS_Object()):
                myCurObject.RemoveDisplay()
                self.myNode.removeChild(index)
            else:
                index += 1

    def ViewProperties(self):
        # for idx in range(len(self.myData)):
        #     myCurObject: Sketch_Object = self.myData[idx]
        #     if self.myContext.IsSelected(myCurObject.GetAIS_Object()):
        #         self.myContext.ClearSelected(True)
        #         self.myGUI.SetSketch_Object(myCurObject)
        #         break
        for child in self.myNode.children():
            assert isinstance(child, SketchObjectNode)
            myCurObject: Sketch_Geometry = child.getSketchObject()
            if self.myContext.IsSelected(myCurObject.GetAIS_Object()):
                self.myContext.ClearSelected(True)
                self.myGUI.SetSketch_Object(myCurObject)
                break

    def RedrawAll(self):
        for idx in range(len(self.myData)):
            myCurObject: Sketch_Object = self.myData[idx]
            if self.myContext.IsSelected(myCurObject.GetAIS_Object()):
                self.myContext.Display(myCurObject.GetAIS_Object(), True)

    def SetPolylineMode(self, amode):
        for idx in range(len(self.myCommands)):
            self.CurCommand = self.myCommands[idx]
            self.CurCommand.SetPolylineMode(amode)

    def SetSnap(self, theSnap):
        self.myAnalyserSnap.SetSnapType(theSnap)

    def GetSnap(self):
        return self.myAnalyserSnap.GetSnapType()

    def addCommand(self, theCommand: Sketch_Command):
        theCommand.SetData(self.myData)
        theCommand.SetContext(self.myContext)
        theCommand.SetRootNode(self.myNode)
        theCommand.SetAnalyserSnap(self.myAnalyserSnap)

        theCommand.SetAx3(self.myCoordinateSystem)
        self.myCommands.append(theCommand)

    def SelectCurCommand(self):
        for idx in range(len(self.myCommands)):
            self.CurCommand: Sketch_Command = self.myCommands[idx]
            if self.CurCommand.GetTypeOfMethod() == self.myCurrentMethod:
                # Acitivate selection automaticlly
                # This is a bug!! Remove the following line will lead to critical error when enable sketch command.
                self.myContext.SetAutoActivateSelection(False)
                break
Ejemplo n.º 28
0
    surf = BRep_Tool.Surface(face)
    surf.Rotate(gp_Ax1(ax0.Location(), ax0.Direction()), np.deg2rad(15))

    ax1 = gp_Ax3(gp_Pnt(150, 150, -20),
                 gp_Dir(0.5, 0.1, 1.0),
                 gp_Dir(0.0, 0.1, 1.0))
    pnt = ax1.Location()
    api = GeomAPI_ProjectPointOnSurf(pnt, surf)
    print(api.NbPoints(), api.NearestPoint())
    for i in range(api.NbPoints()):
        idx = i + 1
        u, v = api.Parameters(idx)
        obj.display.DisplayShape(api.Point(idx))
        print(idx, u, v)

    print(GeomAPI_IntCS(Geom_Line(ax1.Axis()), surf).NbPoints())
    u, v, w = GeomAPI_IntCS(Geom_Line(ax1.Axis()), surf).Parameters(1)
    p, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    api = GeomLProp_SLProps(surf, u, v, 1, 0.1E-03)
    pnt = api.Value()
    dst = pnt.Distance(ax1.Location())
    ax2 = obj.prop_axs(ax1, dst)
    rim_u = surf.UIso(u)
    rim_v = surf.VIso(v)
    print(v, rim_u.FirstParameter(), rim_u.LastParameter())
    print(u, rim_v.FirstParameter(), rim_v.LastParameter())
    obj.display.DisplayShape(rim_u, color="BLUE")
    obj.display.DisplayShape(rim_v, color="BLUE")
    print(api.GaussianCurvature())
    print(api.MinCurvature(), api.MeanCurvature(), api.MaxCurvature())
    print(dir_to_vec(api.Normal()))
Ejemplo n.º 29
0
    def show_line(self, origin=(0, 0, 0), direction=(0, 0, 1)):

        line_placement = Geom_Line(gp_Ax1(gp_Pnt(*origin), gp_Dir(*direction)))
        line = AIS_Line(line_placement)
        self._display_ais(line)
Ejemplo n.º 30
0
def doscreen_impl(model, path, size, yaw=None, pitch=None, triedron=True):
    scn = Scene()
    try:
        mmm = model
        if isinstance(mmm, evalcache.LazyObject):
            mmm = mmm.unlazy()

        c = zencad.default_color()
        if REVERSE_COLOR:
            c = (c[2], c[1], c[0])

        scn.add(mmm, c)
    except:
        for m in model:
            if isinstance(m, (tuple, list)):
                c = m[1]
                m = m[0]
            else:
                c = zencad.default_color()

            if REVERSE_COLOR:
                c = (c[2], c[1], c[0])

            mod = m
            if isinstance(mod, evalcache.LazyObject):
                mod = mod.unlazy()

            if isinstance(mod, zencad.util.point3):
                c = Color(1, 0, 0)
                if REVERSE_COLOR:
                    c = (c[2], c[1], c[0])
                scn.add(mod, c)

            else:
                scn.add(mod, c)

    #viewer = scn.viewer
    # if triedron:  # Always add triedron
    #    viewer.set_triedron_axes()
    #view = viewer.create_view()
    # view.set_triedron(False)
    #view.set_virtual_window(size[0], size[1])

    if yaw is None:
        yaw = math.pi * (7 / 16) + math.pi / 2
    if pitch is None:
        pitch = math.pi * -0.15

    render = OffscreenRenderer(path, size)

    for i in scn.interactives:
        render.Context.Display(i.ais_object, True)
        i.bind_context(render.Context)

    if triedron:

        x_axis = AIS_Axis(
            Geom_Line(gp_Lin(gp_Pnt(0, 0, 0), gp_Dir(gp_XYZ(1, 0, 0)))))
        y_axis = AIS_Axis(
            Geom_Line(gp_Lin(gp_Pnt(0, 0, 0), gp_Dir(gp_XYZ(0, 1, 0)))))
        z_axis = AIS_Axis(
            Geom_Line(gp_Lin(gp_Pnt(0, 0, 0), gp_Dir(gp_XYZ(0, 0, 1)))))

        x_axis.SetColor(Quantity_Color(1, 0, 0, Quantity_TOC_RGB))
        y_axis.SetColor(Quantity_Color(0, 1, 0, Quantity_TOC_RGB))
        z_axis.SetColor(Quantity_Color(0, 0, 1, Quantity_TOC_RGB))

        render.Context.Display(x_axis, True)
        render.Context.Display(y_axis, True)
        render.Context.Display(z_axis, True)

    render.View.Camera().SetDirection(gp_Dir(
        math.cos(pitch) * math.cos(yaw),
        math.cos(pitch) * math.sin(yaw),
        math.sin(pitch),
    ))
    render.View.Camera().SetUp(gp_Dir(0, 0, 1))
    render.View.FitAll(0.07)

    render.DoIt()