Exemplo n.º 1
0
CGroupShapes::CGroupShapes(const ListPNamedShape& list)
{
    if (list.size() == 1) {
        _result = list[0];
        return;
    }

    BRep_Builder b;
    TopoDS_Compound c;
    b.MakeCompound(c);

    for (ListPNamedShape::const_iterator it=list.begin(); it != list.end(); ++it) {
        PNamedShape shape = *it;
        if (!shape) {
            continue;
        }

        b.Add(c, shape->Shape());
    }

    _result = PNamedShape(new CNamedShape(c, "ShapeGroup"));

    // apply face names from the shapes
    for (ListPNamedShape::const_iterator it=list.begin(); it != list.end(); ++it) {
        PNamedShape shape = *it;
        if (!shape) {
            continue;
        }

        CBooleanOperTools::AppendNamesToShape(shape, _result);
    }
}
Exemplo n.º 2
0
PNamedShape InteractiveShapeManager::GetShapeFromName(const std::string& name)
{
    ShapeIterator shapeIt = _shapeEntries.find(name);

    if (shapeIt == _shapeEntries.end())
    {
        return PNamedShape();
    }

    return shapeIt->second.shape;
}
Exemplo n.º 3
0
PNamedShape InteractiveShapeManager::GetShapeFromIObject(const
        Handle_AIS_InteractiveObject obj)
{
    NameIterator it = _names.find(obj);

    if (it == _names.end())
    {
        return PNamedShape();
    }

    std::string name = it->second;

    ShapeIterator shapeIt = _shapeEntries.find(name);

    if (shapeIt == _shapeEntries.end())
    {
        // return null pointer
        return PNamedShape();
    }

    return shapeIt->second.shape;
}
Exemplo n.º 4
0
void CBopCommon::Perform()
{
    if (!_hasPerformed) {
        if (!_tool || !_source) {
           _resultshape.reset();
            return;
        }

        PrepareFiller();

        // use opencascade cutting routine (might be buggy)
        BRepAlgoAPI_Common commonTool(_source->Shape(), _tool->Shape(), *_dsfiller);

        TopoDS_Shape commonShape = commonTool.Shape();

        _resultshape = PNamedShape(new CNamedShape(commonShape, _source->Name()));
        _resultshape->SetName("blubb");
        CBooleanOperTools::MapFaceNamesAfterBOP(commonTool, _source, _resultshape);
        CBooleanOperTools::MapFaceNamesAfterBOP(commonTool, _tool,   _resultshape);

        _hasPerformed = true;
    }
}
Exemplo n.º 5
0
ListPNamedShape GroupFaces(const PNamedShape shape, tigl::ShapeGroupMode groupType)
{
    ListPNamedShape shapeList;
    if (!shape) {
        return shapeList;
    }

    if (groupType == tigl::NAMED_COMPOUNDS) {
        BRep_Builder b;
        TopTools_IndexedMapOfShape faceMap;
        std::map<PNamedShape, TopoDS_Shape> map;
        TopExp::MapShapes(shape->Shape(),   TopAbs_FACE, faceMap);
        if (faceMap.Extent() == 0) {
            // return the shape as is
            shapeList.push_back(shape);
            return shapeList;
        }
        
        for (int iface = 1; iface <= faceMap.Extent(); ++iface) {
            TopoDS_Face face = TopoDS::Face(faceMap(iface));
            PNamedShape origin = shape->GetFaceTraits(iface-1).Origin();

            std::map<PNamedShape, TopoDS_Shape>::iterator it = map.find(origin);
            if (it == map.end()) {
                TopoDS_Compound c;
                b.MakeCompound(c);
                b.Add(c, face);
                map[origin] = c;
            }
            else {
                TopoDS_Shape& c = it->second;
                b.Add(c, face);
            }
        }

        // create Named Shapes
        std::map<PNamedShape, TopoDS_Shape>::iterator it;
        for (it = map.begin(); it != map.end(); ++it) {
            PNamedShape  origin     = it->first;
            TopoDS_Shape toposhape  = it->second;
            PNamedShape curshape;
            if (origin) {
                curshape = PNamedShape(new CNamedShape(toposhape, origin->Name()));
                curshape->SetShortName(origin->ShortName());
            }
            else {
                curshape = PNamedShape(new CNamedShape(toposhape, shape->Name()));
                curshape->SetShortName(shape->ShortName());
            }
            // set the original face traits
            CBooleanOperTools::AppendNamesToShape(shape, curshape);

            // make shells
            curshape = CBooleanOperTools::Shellify(curshape);
            shapeList.push_back(curshape);
        }
    }
    else if (groupType == tigl::WHOLE_SHAPE) {
        shapeList.push_back(shape);
    }
    else if (groupType == tigl::FACES) {
        // store each face as an own shape
        TopTools_IndexedMapOfShape faceMap;
        TopExp::MapShapes(shape->Shape(), TopAbs_FACE, faceMap);
        if (faceMap.Extent() == 0) {
            // return the shape as is
            shapeList.push_back(shape);
            return shapeList;
        }
        
        for (int iface = 1; iface <= faceMap.Extent(); ++iface) {
            TopoDS_Face face = TopoDS::Face(faceMap(iface));
            const CFaceTraits& traits = shape->GetFaceTraits(iface-1);

            PNamedShape faceShape;
            if (traits.Origin()) {
                faceShape = PNamedShape(new CNamedShape(face, traits.Origin()->Name()));
                faceShape->SetShortName(traits.Origin()->ShortName());
            }
            else {
                faceShape = PNamedShape(new CNamedShape(face, shape->Name()));
                faceShape->SetShortName(shape->ShortName());
            }
            faceShape->SetFaceTraits(0, shape->GetFaceTraits(iface-1));
            shapeList.push_back(faceShape);
        }
        
    }
    return shapeList;
}