Esempio n. 1
0
    def _get_sorted_hlr_edges(self, topods_shape, ax=gp_Ax2(), export_hidden_edges=True,
                             use_smooth_edges=False, use_sewn_edges=False):
        """ Return hidden and visible edges as two lists of edges
        """
        hlr = HLRBRep_Algo()

        hlr.Add(topods_shape)

        projector = HLRAlgo_Projector(ax)

        hlr.Projector(projector)
        hlr.Update()
        hlr.Hide()

        hlr_shapes = HLRBRep_HLRToShape(hlr)

        # visible edges
        visible = []

        visible_sharp_edges_as_compound = hlr_shapes.VCompound()
        if visible_sharp_edges_as_compound:
            visible += list(TopologyExplorer(visible_sharp_edges_as_compound).edges())

        visible_smooth_edges_as_compound = hlr_shapes.Rg1LineVCompound()
        if visible_smooth_edges_as_compound and use_smooth_edges:
            visible += list(TopologyExplorer(visible_smooth_edges_as_compound).edges())

        visible_sewn_edges_as_compound = hlr_shapes.RgNLineVCompound()
        if visible_sewn_edges_as_compound and use_sewn_edges:
           visible += list(TopologyExplorer(visible_sewn_edges_as_compound).edges())

        visible_contour_edges_as_compound = hlr_shapes.OutLineVCompound()
        if visible_contour_edges_as_compound:
            visible += list(TopologyExplorer(visible_contour_edges_as_compound).edges())

        #visible_isoparameter_edges_as_compound = hlr_shapes.IsoLineVCompound()
        #if visible_isoparameter_edges_as_compound:
        #    visible += list(TopologyExplorer(visible_isoparameter_edges_as_compound).edges())

        # hidden edges
        hidden = []
        if export_hidden_edges:
            hidden_sharp_edges_as_compound = hlr_shapes.HCompound()
            if hidden_sharp_edges_as_compound:
                hidden += list(TopologyExplorer(hidden_sharp_edges_as_compound).edges())

            hidden_smooth_edges_as_compound = hlr_shapes.Rg1LineHCompound()
            if hidden_smooth_edges_as_compound and use_smooth_edges:
                hidden += list(TopologyExplorer(hidden_smooth_edges_as_compound).edges())

            hidden_sewn_edges_as_compound = hlr_shapes.RgNLineHCompound()
            if hidden_sewn_edges_as_compound and use_sewn_edges:
                hidden += list(TopologyExplorer(hidden_sewn_edges_as_compound).edges())

            hidden_contour_edges_as_compound = hlr_shapes.OutLineHCompound()
            if hidden_contour_edges_as_compound:
                hidden += list(TopologyExplorer(hidden_contour_edges_as_compound).edges())

        return visible, hidden
 def test_shape_conversion_as_py_none(self):
     # see issue #600 and PR #614
     # a null topods_shape should be returned as Py_None by the TopoDS transformer
     # the following test case returns a null topods_shape
     box = BRepPrimAPI_MakeBox(1., 1., 1.).Shape()
     hlr = HLRBRep_Algo()
     hlr.Add(box)
     projector = HLRAlgo_Projector(gp_Ax2(gp_Pnt(), gp_Dir(-1.75, 1.1, 5)))
     hlr.Projector(projector)
     hlr.Update()
     hlr.Hide()
     hlr_shapes = HLRBRep_HLRToShape(hlr)
     visible_smooth_edges = hlr_shapes.Rg1LineVCompound()
     self.assertTrue(visible_smooth_edges is None)
Esempio n. 3
0
def get_sorted_hlr_edges(
    topods_shape: TopoDS_Shape,
    position: Optional[gp_Pnt] = gp_Pnt(),
    direction: Optional[gp_Dir] = gp_Dir(),
    export_hidden_edges: Optional[bool] = True,
) -> Tuple[List, List]:
    """Return hidden and visible edges as two lists of edges"""
    hlr = HLRBRep_Algo()
    hlr.Add(topods_shape)

    projector = HLRAlgo_Projector(gp_Ax2(position, direction))

    hlr.Projector(projector)
    hlr.Update()
    hlr.Hide()

    hlr_shapes = HLRBRep_HLRToShape(hlr)

    # visible edges
    visible = []
    visible_sharp_edges_as_compound = hlr_shapes.VCompound()
    if visible_sharp_edges_as_compound:
        visible += list(
            TopologyExplorer(visible_sharp_edges_as_compound).edges())
    visible_smooth_edges_as_compound = hlr_shapes.Rg1LineVCompound()
    if visible_smooth_edges_as_compound:
        visible += list(
            TopologyExplorer(visible_smooth_edges_as_compound).edges())
    # visible_sewn_edges_as_compound = hlr_shapes.RgNLineVCompound()
    # if visible_sewn_edges_as_compound:
    #    visible += list(TopologyExplorer(visible_sewn_edges_as_compound).edges())
    visible_contour_edges_as_compound = hlr_shapes.OutLineVCompound()
    if visible_contour_edges_as_compound:
        visible += list(
            TopologyExplorer(visible_contour_edges_as_compound).edges())
    # visible_isoparameter_edges_as_compound = hlr_shapes.IsoLineVCompound()
    # if visible_isoparameter_edges_as_compound:
    #    visible += list(TopologyExplorer(visible_isoparameter_edges_as_compound).edges())
    # hidden edges
    hidden = []
    if export_hidden_edges:
        hidden_sharp_edges_as_compound = hlr_shapes.HCompound()
        if hidden_sharp_edges_as_compound:
            hidden += list(
                TopologyExplorer(hidden_sharp_edges_as_compound).edges())
        hidden_contour_edges_as_compound = hlr_shapes.OutLineHCompound()
        if hidden_contour_edges_as_compound:
            hidden += list(
                TopologyExplorer(hidden_contour_edges_as_compound).edges())

    return visible, hidden
def get_sorted_hlr_edges(topods_shape,
                         position=gp_Pnt(),
                         direction=gp_Dir(),
                         export_hidden_edges=True):
    """ Return hidden and visible edges as two lists of edges
    """
    hlr = HLRBRep_Algo()
    hlr.Add(topods_shape)

    projector = HLRAlgo_Projector(gp_Ax2(position, direction))

    hlr.Projector(projector)
    hlr.Update()
    hlr.Hide()

    hlr_shapes = HLRBRep_HLRToShape(hlr)

    # visible edges
    visible = []
    visible_sharp_edges_as_compound = hlr_shapes.VCompound()
    if visible_sharp_edges_as_compound:
        visible += list(
            TopologyExplorer(visible_sharp_edges_as_compound).edges())
    visible_smooth_edges_as_compound = hlr_shapes.Rg1LineVCompound()
    if visible_smooth_edges_as_compound:
        visible += list(
            TopologyExplorer(visible_sharp_edges_as_compound).edges())

    visible_contour_edges_as_compound = hlr_shapes.OutLineVCompound()
    if visible_contour_edges_as_compound:
        visible += list(
            TopologyExplorer(visible_contour_edges_as_compound).edges())

    hidden = []
    if export_hidden_edges:
        hidden_sharp_edges_as_compound = hlr_shapes.HCompound()
        if hidden_sharp_edges_as_compound:
            hidden += list(
                TopologyExplorer(hidden_sharp_edges_as_compound).edges())
        hidden_contour_edges_as_compound = hlr_shapes.OutLineHCompound()
        if hidden_contour_edges_as_compound:
            hidden += list(
                TopologyExplorer(hidden_contour_edges_as_compound).edges())

    return visible, hidden
Esempio n. 5
0
def getSVG(shape, opts=None):
    """
        Export a shape to SVG
    """

    d = {"width": 800, "height": 240, "marginLeft": 200, "marginTop": 20}

    if opts:
        d.update(opts)

    # need to guess the scale and the coordinate center
    uom = guessUnitOfMeasure(shape)

    width = float(d["width"])
    height = float(d["height"])
    marginLeft = float(d["marginLeft"])
    marginTop = float(d["marginTop"])

    hlr = HLRBRep_Algo()
    hlr.Add(shape.wrapped)

    projector = HLRAlgo_Projector(gp_Ax2(gp_Pnt(), DEFAULT_DIR))

    hlr.Projector(projector)
    hlr.Update()
    hlr.Hide()

    hlr_shapes = HLRBRep_HLRToShape(hlr)

    visible = []

    visible_sharp_edges = hlr_shapes.VCompound()
    if visible_sharp_edges:
        visible.append(visible_sharp_edges)

    visible_smooth_edges = hlr_shapes.Rg1LineVCompound()
    if visible_smooth_edges:
        visible.append(visible_smooth_edges)

    visible_contour_edges = hlr_shapes.OutLineVCompound()
    if visible_contour_edges:
        visible.append(visible_contour_edges)

    hidden = []

    hidden_sharp_edges = hlr_shapes.HCompound()
    if hidden_sharp_edges:
        hidden.append(hidden_sharp_edges)

    hidden_contour_edges = hlr_shapes.OutLineHCompound()
    if hidden_contour_edges:
        hidden.append(hidden_contour_edges)

    # Fix the underlying geometry - otherwise we will get segfaults
    for el in visible:
        breplib.BuildCurves3d(el, TOLERANCE)
    for el in hidden:
        breplib.BuildCurves3d(el, TOLERANCE)

    # convert to native CQ objects
    visible = list(map(Shape, visible))
    hidden = list(map(Shape, hidden))
    (hiddenPaths, visiblePaths) = getPaths(visible, hidden)

    # get bounding box -- these are all in 2-d space
    bb = Compound.makeCompound(hidden + visible).BoundingBox()

    # width pixels for x, height pixesl for y
    unitScale = min(width / bb.xlen * 0.75, height / bb.ylen * 0.75)

    # compute amount to translate-- move the top left into view
    (xTranslate, yTranslate) = (
        (0 - bb.xmin) + marginLeft / unitScale,
        (0 - bb.ymax) - marginTop / unitScale,
    )

    # compute paths ( again -- had to strip out freecad crap )
    hiddenContent = ""
    for p in hiddenPaths:
        hiddenContent += PATHTEMPLATE % p

    visibleContent = ""
    for p in visiblePaths:
        visibleContent += PATHTEMPLATE % p

    svg = SVG_TEMPLATE % (
        {
            "unitScale": str(unitScale),
            "strokeWidth": str(1.0 / unitScale),
            "hiddenContent": hiddenContent,
            "visibleContent": visibleContent,
            "xTranslate": str(xTranslate),
            "yTranslate": str(yTranslate),
            "width": str(width),
            "height": str(height),
            "textboxY": str(height - 30),
            "uom": str(uom),
        }
    )
    # svg = SVG_TEMPLATE % (
    #    {"content": projectedContent}
    # )
    return svg
Esempio n. 6
0
 def hlr_project(self, shapes):
     hlralgo = HLRBRep_Algo()
     if len(shapes) > 0:
         for s in shapes:
             hlralgo.Add(s)
         self.children = []
         trsf = gp_Trsf()
         p = HLRAlgo_Projector(gp_Ax2(gp_Pnt(), gp_Dir(0, 0, 1)))
         hlralgo.Projector(p)
         hlralgo.Update()
         hlralgo.Hide()
         hlrtoshape = HLRBRep_HLRToShape(hlralgo)
         vcompound = hlrtoshape.VCompound()
         voutline = hlrtoshape.OutLineVCompound()
         rg1linevcompound = hlrtoshape.Rg1LineVCompound()
         rgnlinevcompound = hlrtoshape.RgNLineVCompound()
         isolinevcompound = hlrtoshape.IsoLineVCompound()
         hcompound = hlrtoshape.HCompound()
         houtline = hlrtoshape.OutLineHCompound()
         rg1linehcompound = hlrtoshape.Rg1LineHCompound()
         rgnlinehcompound = hlrtoshape.RgNLineHCompound()
         isolinehcompound = hlrtoshape.IsoLineHCompound()
         debug("vcompound: %s" % (str(vcompound), ))
         debug("voutline: %s" % (str(voutline), ))
         debug("rg1linevcompound: %s" % (str(rg1linevcompound), ))
         debug("rgnlinevcompound: %s" % (str(rgnlinevcompound), ))
         debug("isolinevcompound: %s" % (str(isolinevcompound), ))
         debug("hcompound: %s" % (str(hcompound), ))
         debug("houtline: %s" % (str(houtline), ))
         debug("rg1linehcompound: %s" % (str(rg1linehcompound), ))
         debug("rgnlinehcompound: %s" % (str(rgnlinehcompound), ))
         debug("isolinehcompound: %s" % (str(isolinehcompound), ))
         name = get_inc_name("projection")
         if (vcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(vcompound)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'vcompound')
             self.add_child_context(sclp)
         if (voutline != None):
             sclp = SCLPart3(self)
             scls = SCLShape(voutline)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'voutline')
             self.add_child_context(sclp)
         if (rg1linevcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(rg1linevcompound)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'rg1linevcompound')
             self.add_child_context(sclp)
         if (rgnlinevcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(rgnlinevcompound)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'rgnlinecompound')
             self.add_child_context(sclp)
         if (isolinevcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(isolinevcompound)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'isolinevcompound')
             self.add_child_context(sclp)
         if (hcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(hcompound)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'hcompound')
             self.add_child_context(sclp)
         if (houtline != None):
             sclp = SCLPart3(self)
             scls = SCLShape(houtline)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'houtline')
             self.add_child_context(sclp)
         if (rg1linehcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(rg1linehcompound)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'rg1linehcompound')
             self.add_child_context(sclp)
         if (rgnlinehcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(rgnlinehcompound)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'rgnlinehcompound')
             self.add_child_context(sclp)
         if (isolinehcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(isolinehcompound)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'isolinehcompound')
             self.add_child_context(sclp)
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from OCC.Display.SimpleGui import init_display
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.HLRTopoBRep import HLRTopoBRep_OutLiner
from OCC.Core.BRepTools import breptools_Read
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.BRep import BRep_Builder
from OCC.Core.HLRBRep import HLRBRep_Algo, HLRBRep_HLRToShape

cylinder_head = TopoDS_Shape()
outt = TopoDS_Shape()
builder = BRep_Builder()
breptools_Read(cylinder_head, '../assets/models/cylinder_head.brep', builder)

myAlgo = HLRBRep_Algo()
myAlgo.Add(cylinder_head)
myAlgo.Update()

print(dir(HLRBRep_HLRToShape))
aHLRToShape = HLRBRep_HLRToShape(myAlgo)
o = aHLRToShape.OutLineVCompound3d()
display, start_display, add_menu, add_function_to_menu = init_display(
    'qt-pyqt5')
display.DisplayShape(o, update=True)
start_display()