void InteractiveShapeManager::addObject(PNamedShape shape, Handle_AIS_InteractiveObject iObject)
{
    std::string name = shape->Name();

    // check if shape is already there
    ShapeIterator shapeIt = _shapeEntries.find(name);

    if (shapeIt != _shapeEntries.end())
    {
        // add iObject to shape
        ShapeEntry& entry = shapeIt->second;
        entry.aisObjects.push_back(iObject);

#ifdef DEBUG
        DLOG(INFO) << "added shape " << name;
#endif
    }
    else
    {
        // Create a new shape entry and add it to map
        ShapeEntry entry;
        entry.aisObjects.push_back(iObject);
        entry.shape     = shape;
        _shapeEntries.insert(shapeIt, ShapeMap::value_type(name, entry));

#ifdef DEBUG
        DLOG(INFO) << "Created new shape " << name;
#endif
    }

    // add also to interactive objects list
    _names[iObject] = name;
}
示例#2
0
/**
 * @briefAdds a shape to the IGES file. All faces are named according to their face
 * traits. If there are no faces, the wires are named according to the shape name.
 * 
 * The level parameter defines the iges layer/level, which is another way of grouping faces.
 */
void CTiglExportIges::AddToIges(PNamedShape shape, IGESControl_Writer& writer, int level) const 
{
    if (!shape) {
        return;
    }
    
    std::string shapeName = shape->Name();
    std::string shapeShortName = shape->ShortName();
    Handle(Transfer_FinderProcess) FP = writer.TransferProcess();
    TopTools_IndexedMapOfShape faceMap;
    TopExp::MapShapes(shape->Shape(),   TopAbs_FACE, faceMap);
    // any faces?
    if (faceMap.Extent() > 0) {
        int ret = writer.AddShape(shape->Shape());
        if (ret > IFSelect_RetDone) {
            throw CTiglError("Error: Export to IGES file failed in CTiglExportStep. Could not translate shape " 
                             + shapeName + " to iges entity,", TIGL_ERROR);
        }
        WriteIgesNames(FP, shape, level);
    }
    else {
        // no faces, export edges as wires
        Handle(TopTools_HSequenceOfShape) Edges = new TopTools_HSequenceOfShape();
        TopExp_Explorer myEdgeExplorer (shape->Shape(), TopAbs_EDGE);
        while (myEdgeExplorer.More()) {
            Edges->Append(TopoDS::Edge(myEdgeExplorer.Current()));
            myEdgeExplorer.Next();
        }
        ShapeAnalysis_FreeBounds::ConnectEdgesToWires(Edges, 1e-7, false, Edges);
        for (int iwire = 1; iwire <= Edges->Length(); ++iwire) {
            int ret = writer.AddShape(Edges->Value(iwire));
            if (ret > IFSelect_RetDone) {
                throw CTiglError("Error: Export to IGES file failed in CTiglExportIges. Could not translate shape " 
                                 + shapeName + " to iges entity,", TIGL_ERROR);
            }
            PNamedShape theWire(new CNamedShape(Edges->Value(iwire),shapeName.c_str()));
            theWire->SetShortName(shapeShortName.c_str());
            WriteIGESShapeNames(FP, theWire, level);
            WriteIgesWireName(FP, theWire);
        }
    }
}
示例#3
0
/// This is the actual fusing
void CFuseShapes::DoFuse()
{
    if (!_parent) {
        throw tigl::CTiglError("Null pointer for parent shape in CFuseShapes", TIGL_NULL_POINTER);
    }

    BRepBuilderAPI_Sewing shellMaker;

    _trimmedChilds.clear();
    ListPNamedShape::const_iterator childIter;

    TrimOperation childTrim  = EXCLUDE;
    TrimOperation parentTrim = EXCLUDE;

    // trim the childs with the parent and vice versa
    _trimmedParent = _parent->DeepCopy();
    for (childIter = _childs.begin(); childIter != _childs.end(); ++childIter) {
        const PNamedShape child = *childIter;
        if (!child) {
            continue;
        }

#ifdef DEBUG_BOP
        clock_t start, stop;
        start = clock();
#endif
        BOPCol_ListOfShape aLS;
        aLS.Append(_trimmedParent->Shape());
        aLS.Append(child->Shape());
        BOPAlgo_PaveFiller DSFill;
        DSFill.SetArguments(aLS);
        DSFill.Perform();
#ifdef DEBUG_BOP
        stop = clock();
        printf("dsfiller [ms]: %f\n", (stop-start)/(double)CLOCKS_PER_SEC * 1000.);

        start = clock();
#endif
        // calculate intersection
        // Todo: make a new BOP out of this
        TopoDS_Shape intersection = BRepAlgoAPI_Section(_trimmedParent->Shape(), child->Shape(), DSFill);
        PNamedShape intersectionShape(new CNamedShape(intersection, std::string("INT" + std::string(_parent->Name()) + child->Name()).c_str()));
        intersectionShape->SetShortName(std::string("INT" + std::string(_parent->ShortName()) + child->ShortName()).c_str());
        _intersections.push_back(intersectionShape);

#ifdef DEBUG_BOP
        stop = clock();
        printf("intersection [ms]: %f\n", (stop-start)/(double)CLOCKS_PER_SEC * 1000.);

        start = clock();
#endif
        _trimmedParent = CTrimShape(_trimmedParent, child, DSFill, parentTrim);

#ifdef DEBUG_BOP
        stop = clock();
        printf("parent split [ms]: %f\n", (stop-start)/(double)CLOCKS_PER_SEC * 1000.);

        start = clock();
#endif
        PNamedShape trimmedChild = CTrimShape(child, _parent, DSFill, childTrim);
        _trimmedChilds.push_back(trimmedChild);

#ifdef DEBUG_BOP
        stop = clock();
        printf("child split [ms]: %f\n", (stop-start)/(double)CLOCKS_PER_SEC * 1000.);
#endif
    } // trimming

    // add trimmed child faces to result
    for (childIter = _trimmedChilds.begin(); childIter != _trimmedChilds.end(); ++childIter) {
        shellMaker.Add((*childIter)->Shape());
    }

    // add trimmed parent faces to result
    shellMaker.Add(_trimmedParent->Shape());
    shellMaker.Perform();

    // make a solid out of the face collection
    TopoDS_Shape shell = shellMaker.SewedShape();


    BRepSewingToBRepBuilderShapeAdapter sewerAdapter(shellMaker);

    // map names to shell
    PNamedShape resultShell(new CNamedShape(shell, "BOP_FUSE"));
    for (childIter = _trimmedChilds.begin(); childIter != _trimmedChilds.end(); ++childIter) {
        const PNamedShape child = *childIter;
        PNamedShape tmpshape(new CNamedShape(*child));
        tmpshape->SetShape(shellMaker.ModifiedSubShape(child->Shape()));
        CBooleanOperTools::MapFaceNamesAfterBOP(sewerAdapter, tmpshape, resultShell);
    }
    PNamedShape tmpshape(new CNamedShape(*_trimmedParent));
    tmpshape->SetShape(shellMaker.ModifiedSubShape(_trimmedParent->Shape()));
    CBooleanOperTools::MapFaceNamesAfterBOP(sewerAdapter, tmpshape, resultShell);

    // map names to solid
    BRepBuilderAPI_MakeSolid solidmaker;
    TopTools_IndexedMapOfShape shellMap;
    TopExp::MapShapes(resultShell->Shape(), TopAbs_SHELL, shellMap);
    for (int ishell = 1; ishell <= shellMap.Extent(); ++ishell) {
        const TopoDS_Shell& shell = TopoDS::Shell(shellMap(ishell));
        solidmaker.Add(shell);
    }

    PNamedShape result(new CNamedShape(solidmaker.Solid(), resultShell->Name()));
    CBooleanOperTools::MapFaceNamesAfterBOP(solidmaker, resultShell, result);

    _resultshape = result;
}
示例#4
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;
}