Ejemplo n.º 1
0
bool DlgExtrusion::canExtrude(const TopoDS_Shape& shape) const
{
    if (shape.IsNull())
        return false;
    TopAbs_ShapeEnum type = shape.ShapeType();
    if (type == TopAbs_VERTEX || type == TopAbs_EDGE ||
        type == TopAbs_WIRE || type == TopAbs_FACE ||
        type == TopAbs_SHELL)
        return true;
    if (type == TopAbs_COMPOUND) {
        TopExp_Explorer xp;
        xp.Init(shape,TopAbs_SOLID);
        while (xp.More()) {
            return false;
        }
        xp.Init(shape,TopAbs_COMPSOLID);
        while (xp.More()) {
            return false;
        }

        return true;
    }

    return false;
}
void DlgRevolution::findShapes()
{
    App::Document* activeDoc = App::GetApplication().getActiveDocument();
    if (!activeDoc) return;
    Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc);

    std::vector<App::DocumentObject*> objs = activeDoc->getObjectsOfType
            (Part::Feature::getClassTypeId());
    for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it!=objs.end(); ++it) {
        const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
        if (shape.IsNull()) continue;

        TopExp_Explorer xp;
        xp.Init(shape,TopAbs_SOLID);
        if (xp.More()) continue; // solids not allowed
        xp.Init(shape,TopAbs_COMPSOLID);
        if (xp.More()) continue; // compound solids not allowed
        // So allowed are: vertex, edge, wire, face, shell and compound
        QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget);
        item->setText(0, QString::fromUtf8((*it)->Label.getValue()));
        item->setData(0, Qt::UserRole, QString::fromAscii((*it)->getNameInDocument()));
        Gui::ViewProvider* vp = activeGui->getViewProvider(*it);
        if (vp) item->setIcon(0, vp->getIcon());
    }
}
Ejemplo n.º 3
0
void PovTools::writeShapeCSV(const char *FileName,
                             const TopoDS_Shape& Shape,
                             float fMeshDeviation,
                             float fLength)
{
    const char cSeperator = ',';

    Base::Console().Log("Meshing with Deviation: %f\n",fMeshDeviation);

    TopExp_Explorer ex;
    BRepMesh_IncrementalMesh MESH(Shape,fMeshDeviation);

    // open the file and write
    std::ofstream fout(FileName);

    // counting faces and start sequencer
    int l = 1;
    for (ex.Init(Shape, TopAbs_FACE); ex.More(); ex.Next(),l++) {}
    Base::SequencerLauncher seq("Writing file", l);

    // write the file
    l = 1;
    for (ex.Init(Shape, TopAbs_FACE); ex.More(); ex.Next(),l++) {

        // get the shape and mesh it
        const TopoDS_Face& aFace = TopoDS::Face(ex.Current());

        // this block mesh the face and transfers it in a C array of vertices and face indexes
        Standard_Integer nbNodesInFace,nbTriInFace;
        gp_Vec* vertices=0;
        gp_Vec* vertexnormals=0;
        long* cons=0;

        transferToArray(aFace,&vertices,&vertexnormals,&cons,nbNodesInFace,nbTriInFace);

        if (!vertices) break;
        // writing per face header
        // writing vertices
        for (int i=0; i < nbNodesInFace; i++) {
            fout << vertices[i].X() << cSeperator
            << vertices[i].Z() << cSeperator
            << vertices[i].Y() << cSeperator
            << vertexnormals[i].X() * fLength <<cSeperator
            << vertexnormals[i].Z() * fLength <<cSeperator
            << vertexnormals[i].Y() * fLength <<cSeperator
            << endl;
        }

        delete [] vertexnormals;
        delete [] vertices;
        delete [] cons;

        seq.next();

    } // end of face loop

    fout.close();
}
Ejemplo n.º 4
0
// constructor method
int TopoShapeSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
    PyObject *obj;
    if (!PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &obj))
        return -1;

    try {
        const TopoDS_Shape& shape = static_cast<TopoShapePy*>(obj)
            ->getTopoShapePtr()->getShape();
        //first, if we were given a compsolid, try making a solid out of it
        TopExp_Explorer CSExp (shape, TopAbs_COMPSOLID);
        TopoDS_CompSolid compsolid;
        int count=0;
        for (; CSExp.More(); CSExp.Next()) {
            ++count;
            compsolid = TopoDS::CompSolid(CSExp.Current());
            if (count > 1)
                break;
        }
        if (count == 0) {
            //no compsolids. Get shells...
            BRepBuilderAPI_MakeSolid mkSolid;
            TopExp_Explorer anExp (shape, TopAbs_SHELL);
            count=0;
            for (; anExp.More(); anExp.Next()) {
                ++count;
                mkSolid.Add(TopoDS::Shell(anExp.Current()));
            }

            if (count == 0)//no shells?
                Standard_Failure::Raise("No shells or compsolids found in shape");

            TopoDS_Solid solid = mkSolid.Solid();
            BRepLib::OrientClosedSolid(solid);
            getTopoShapePtr()->setShape(solid);
        } else if (count == 1) {
            BRepBuilderAPI_MakeSolid mkSolid(compsolid);
            TopoDS_Solid solid = mkSolid.Solid();
            getTopoShapePtr()->setShape(solid);
        } else if (count > 1) {
            Standard_Failure::Raise("Only one compsolid can be accepted. Provided shape has more than one compsolid.");
        }

    }
    catch (Standard_Failure err) {
        std::stringstream errmsg;
        errmsg << "Creation of solid failed: " << err.GetMessageString();
        PyErr_SetString(PartExceptionOCCError, errmsg.str().c_str());
        return -1;
    }

    return 0;
}
Ejemplo n.º 5
0
FaceAdjacencySplitter::FaceAdjacencySplitter(const TopoDS_Shell &shell)
{
    TopExp_Explorer shellIt;
    for (shellIt.Init(shell, TopAbs_FACE); shellIt.More(); shellIt.Next())
    {
        TopTools_ListOfShape shapeList;
        TopExp_Explorer it;
        for (it.Init(shellIt.Current(), TopAbs_EDGE); it.More(); it.Next())
            shapeList.Append(it.Current());
        faceToEdgeMap.Add(shellIt.Current(), shapeList);
    }
    TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE, TopAbs_FACE, edgeToFaceMap);
}
Ejemplo n.º 6
0
 /**
  * Writes out a vtk 2.0 file, currently hardcoded to c:\\outputcascade.vtk
  */
 void OCGeometryRenderer::WriteVTK(TopoDS_Shape* out)
 {
   FILE *fp=fopen("C:\\outputcascade.vtk","w+");
   fprintf(fp,"# vtk DataFile Version 2.0 \nOpenCascade data\nASCII\n");
   fprintf(fp,"DATASET POLYDATA\n");
   //			BRepMesh::Mesh(out,0.1);
   TopExp_Explorer Ex;
   int countVert=0;
   int countFace=0;
   for(Ex.Init(*out,TopAbs_FACE);Ex.More();Ex.Next())
   {
     TopoDS_Face F=TopoDS::Face(Ex.Current());
     TopLoc_Location L;
     Handle (Poly_Triangulation) facing=BRep_Tool::Triangulation(F,L);
     countVert+=facing->NbNodes();
     countFace+=facing->NbTriangles();
   }
   fprintf(fp,"POINTS %d float\n",countVert);
   for(Ex.Init(*out,TopAbs_FACE);Ex.More();Ex.Next())
   {
     TopoDS_Face F=TopoDS::Face(Ex.Current());
     TopLoc_Location L;
     Handle (Poly_Triangulation) facing=BRep_Tool::Triangulation(F,L);
     TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
     tab = facing->Nodes();
     for (Standard_Integer i=1;i<=(facing->NbNodes());i++) {
       gp_Pnt pnt=tab.Value(i);
       fprintf(fp,"%f %f %f\n",pnt.X(),pnt.Y(),pnt.Z());
     }
   }
   fprintf(fp,"POLYGONS %d %d\n",countFace,countFace*4);
   int maxindex=0;
   for(Ex.Init(*out,TopAbs_FACE);Ex.More();Ex.Next())
   {
     TopoDS_Face F=TopoDS::Face(Ex.Current());
     TopLoc_Location L;
     Handle (Poly_Triangulation) facing=BRep_Tool::Triangulation(F,L);
     TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
     tab = facing->Nodes();
     Poly_Array1OfTriangle tri(1,facing->NbTriangles());
     tri = facing->Triangles();
     for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) {
       Poly_Triangle trian = tri.Value(i);
       Standard_Integer index1,index2,index3;
       trian.Get(index1,index2,index3);
       fprintf(fp,"3 %d %d %d\n",maxindex+index1-1,maxindex+index2-1,maxindex+index3-1);
     }
     maxindex+=facing->NbNodes();
   }
   fclose(fp);
 }
Ejemplo n.º 7
0
//added by tanderson. aka blobfish.
//projection algorithms build a 2d curve(pcurve) but no 3d curve.
//this causes problems with meshing algorithms after save and load.
static const TopoDS_Shape& build3dCurves(const TopoDS_Shape &shape)
{
  TopExp_Explorer it;
  for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next())
    BRepLib::BuildCurve3d(TopoDS::Edge(it.Current()));
  return shape;
}
Ejemplo n.º 8
0
//=======================================================================
//function : GetEdgeOff
//purpose  : 
//=======================================================================
  Standard_Boolean GEOMAlgo_Tools3D::GetEdgeOff(const TopoDS_Edge& theE1,
                                               const TopoDS_Face& theF2,
                                               TopoDS_Edge& theE2)
     
{
  Standard_Boolean bFound;
  TopAbs_Orientation aOr1, aOr1C, aOr2;
  TopExp_Explorer anExp;
  //
  bFound=Standard_False;
  aOr1=theE1.Orientation();
  aOr1C=TopAbs::Reverse(aOr1);
  //
  anExp.Init(theF2, TopAbs_EDGE);
  for (; anExp.More(); anExp.Next()) {
    const TopoDS_Edge& aEF2=TopoDS::Edge(anExp.Current());
    if (aEF2.IsSame(theE1)) {
      aOr2=aEF2.Orientation();
      if (aOr2==aOr1C) {
        theE2=aEF2;
        bFound=!bFound;
        return bFound;
      }
    }
  }
  return bFound;
}
std::vector<TopoDS_Wire> SketchBased::getSketchWires() const {
    std::vector<TopoDS_Wire> result;

    TopoDS_Shape shape = getVerifiedSketch()->Shape.getShape()._Shape;
    if (shape.IsNull())
        throw Base::Exception("Linked shape object is empty");

    // this is a workaround for an obscure OCC bug which leads to empty tessellations
    // for some faces. Making an explicit copy of the linked shape seems to fix it.
    // The error almost happens when re-computing the shape but sometimes also for the
    // first time
    BRepBuilderAPI_Copy copy(shape);
    shape = copy.Shape();
    if (shape.IsNull())
        throw Base::Exception("Linked shape object is empty");

    TopExp_Explorer ex;
    for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
        result.push_back(TopoDS::Wire(ex.Current()));
    }
    if (result.empty()) // there can be several wires
        throw Base::Exception("Linked shape object is not a wire");

    return result;
}
Ejemplo n.º 10
0
// constructor method
int TopoShapeSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
    PyObject *obj;
    if (!PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &obj))
        return -1;

    try {
        BRepBuilderAPI_MakeSolid mkSolid;
        const TopoDS_Shape& shape = static_cast<TopoShapePy*>(obj)
            ->getTopoShapePtr()->_Shape;
        TopExp_Explorer anExp (shape, TopAbs_SHELL);
        int count=0;
        for (; anExp.More(); anExp.Next()) {
            ++count;
            mkSolid.Add(TopoDS::Shell(anExp.Current()));
        }

        if (count == 0)
            Standard_Failure::Raise("No shells found in shape");

        TopoDS_Solid solid = mkSolid.Solid();
        BRepLib::OrientClosedSolid(solid);
        getTopoShapePtr()->_Shape = solid;
    }
    catch (Standard_Failure) {
        PyErr_SetString(PartExceptionOCCError, "creation of solid failed");
        return -1;
    }

    return 0;
}
Ejemplo n.º 11
0
void TaskCheckGeometryResults::checkSub(const BRepCheck_Analyzer &shapeCheck, const TopoDS_Shape &shape,
                                        const TopAbs_ShapeEnum subType, ResultEntry *parent)
{
    BRepCheck_ListIteratorOfListOfStatus itl;
    TopExp_Explorer exp;
    for (exp.Init(shape,subType); exp.More(); exp.Next())
    {
        const Handle(BRepCheck_Result)& res = shapeCheck.Result(exp.Current());
        const TopoDS_Shape& sub = exp.Current();
        for (res->InitContextIterator(); res->MoreShapeInContext(); res->NextShapeInContext())
        {
            if (res->ContextualShape().IsSame(shape))
            {
                for (itl.Initialize(res->StatusOnShape()); itl.More(); itl.Next())
                {
                     if (itl.Value() == BRepCheck_NoError)
                         break;
                     checkedMap.Add(sub);
                     ResultEntry *entry = new ResultEntry();
                     entry->parent = parent;
                     entry->shape = sub;
                     entry->buildEntryName();
                     entry->type = shapeEnumToString(sub.ShapeType());
                     entry->error = checkStatusToString(itl.Value());
                     entry->viewProviderRoot = currentSeparator;
                     entry->viewProviderRoot->ref();
                     dispatchError(entry, itl.Value());
                     parent->children.push_back(entry);
                }
            }
        }
    }
}
Ejemplo n.º 12
0
//=======================================================================
//function : CorrectWires
//purpose  :
//=======================================================================
  Standard_Boolean GEOMAlgo_Tools::CorrectWires(const TopoDS_Shape& aShape)
{
  Standard_Boolean bRet;
  TopoDS_Iterator aItF;
  TopExp_Explorer aExp;
  TopTools_MapOfShape aMF;
  GeomAdaptor_Surface aGAS;
  GeomAbs_SurfaceType aTS;
  TopLoc_Location aLoc;
  //
  bRet=Standard_False;
  //
  aExp.Init(aShape, TopAbs_FACE);
  for (; aExp.More(); aExp.Next()) {
    const TopoDS_Face& aF=*((TopoDS_Face*)&aExp.Current());
    if (aMF.Add(aF)) {
      const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aF, aLoc);
      aGAS.Load(aS);
      aTS=aGAS.GetType();
      if (aTS==GeomAbs_Cylinder || aTS==GeomAbs_Plane) {
	aItF.Initialize(aF);
	for (; aItF.More(); aItF.Next()) {
	  const TopoDS_Wire& aW=*((TopoDS_Wire*)&aItF.Value());
	  if (CorrectWire(aW, aF)) {
	   bRet=Standard_True;
	  }
	}
      }
    }
  }
  return bRet;
}
Ejemplo n.º 13
0
//=======================================================================
//function : CheckTriangulation
//purpose  :
//=======================================================================
bool GEOMUtils::CheckTriangulation (const TopoDS_Shape& aShape)
{
  bool isTriangulation = true;

  TopExp_Explorer exp (aShape, TopAbs_FACE);
  if (exp.More())
  {
    TopLoc_Location aTopLoc;
    Handle(Poly_Triangulation) aTRF;
    aTRF = BRep_Tool::Triangulation(TopoDS::Face(exp.Current()), aTopLoc);
    if (aTRF.IsNull()) {
      isTriangulation = false;
    }
  }
  else // no faces, try edges
  {
    TopExp_Explorer expe (aShape, TopAbs_EDGE);
    if (!expe.More()) {
      return false;
    }
    TopLoc_Location aLoc;
    Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(TopoDS::Edge(expe.Current()), aLoc);
    if (aPE.IsNull()) {
      isTriangulation = false;
    }
  }

  if (!isTriangulation) {
    // calculate deflection
    Standard_Real aDeviationCoefficient = 0.001;

    Bnd_Box B;
    BRepBndLib::Add(aShape, B);
    Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
    B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);

    Standard_Real dx = aXmax - aXmin, dy = aYmax - aYmin, dz = aZmax - aZmin;
    Standard_Real aDeflection = Max(Max(dx, dy), dz) * aDeviationCoefficient * 4;
    Standard_Real aHLRAngle = 0.349066;

    BRepMesh_IncrementalMesh Inc (aShape, aDeflection, Standard_False, aHLRAngle);
  }

  return true;
}
Ejemplo n.º 14
0
void PartGui::goSetupResultTypedSelection(ResultEntry* entry, const TopoDS_Shape& shape, TopAbs_ShapeEnum type)
{
    TopExp_Explorer it;
    for (it.Init(shape, type); it.More(); it.Next())
    {
        QString name = buildSelectionName(entry, (it.Current()));
        if (!name.isEmpty())
            entry->selectionStrings.append(name);
    }
}
Ejemplo n.º 15
0
void CmdPartDesignPad::activated(int iMsg)
{
    unsigned int n = getSelection().countObjectsOfType(Part::Part2DObject::getClassTypeId());
    if (n != 1) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
            QObject::tr("Select a sketch or 2D object."));
        return;
    }

    std::string FeatName = getUniqueObjectName("Pad");

    std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId());
    Part::Part2DObject* sketch = static_cast<Part::Part2DObject*>(Sel.front());
    const TopoDS_Shape& shape = sketch->Shape.getValue();
    if (shape.IsNull()) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
            QObject::tr("The shape of the selected object is empty."));
        return;
    }

    // count free wires
    int ctWires=0;
    TopExp_Explorer ex;
    for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
        ctWires++;
    }
    if (ctWires == 0) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
            QObject::tr("The shape of the selected object is not a wire."));
        return;
    }

    App::DocumentObject* support = sketch->Support.getValue();

    openCommand("Make Pad");
    doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pad\",\"%s\")",FeatName.c_str());
    doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument());
    doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str());
    updateActive();
    if (isActiveObjectValid()) {
        doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
        if (support)
            doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
    }
    doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());

    //commitCommand();
    adjustCameraPosition();

    if (support) {
        copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument());
        copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument());
        copyVisual(FeatName.c_str(), "PointColor", support->getNameInDocument());
    }
}
Ejemplo n.º 16
0
gp_Pnt GetCentralFacePoint(const TopoDS_Face& face)
{
    // compute point on face
    Standard_Real umin, umax, vmin, vmax;

    gp_Pnt p;

    Handle(Geom_Surface) surface = BRep_Tool::Surface(face);
    BRepTools::UVBounds(face, umin, umax, vmin, vmax);
    Standard_Real umean = 0.5*(umin+umax);
    Standard_Real vmean = 0.5*(vmin+vmax);


    // compute intersection of u-iso line with face boundaries
    Handle(Geom2d_Curve) uiso = new Geom2d_Line(
                gp_Pnt2d(umean,0.),
                gp_Dir2d(0., 1.)
                );

    TopExp_Explorer exp (face,TopAbs_EDGE);
    std::list<double> intersections;
    for (; exp.More(); exp.Next()) {
        TopoDS_Edge edge = TopoDS::Edge(exp.Current());
        Standard_Real first, last;

        // Get geomteric curve from edge
        Handle(Geom2d_Curve) hcurve = BRep_Tool::CurveOnSurface(edge, face, first, last);
        hcurve = new Geom2d_TrimmedCurve(hcurve, first, last);

        Geom2dAPI_InterCurveCurve intersector(uiso, hcurve);
        for (int ipoint = 0; ipoint < intersector.NbPoints(); ++ipoint) {
            gp_Pnt2d p = intersector.Point(ipoint+1);
            intersections.push_back(p.Y());
        }
    }

    // remove duplicate solutions defined by tolerance
    double tolerance = 1e-5;
    intersections.sort();
    intersections.unique(IsSame((vmax-vmin)*tolerance));

    // normally we should have at least two intersections
    // also the number of sections should be even - else something is really strange
    //assert(intersections.size() % 2 == 0);
    if (intersections.size() >= 2) {
        std::list<double>::iterator it = intersections.begin();
        double int1 = *it++;
        double int2 = *it;
        vmean = (int1 + int2)/2.;
    }

    surface->D0(umean, vmean, p);

    return p;
}
Ejemplo n.º 17
0
//=======================================================================
// function: Sense
// purpose: 
//=======================================================================
  Standard_Integer GEOMAlgo_Tools3D::Sense (const TopoDS_Face& theF1,
                                           const TopoDS_Face& theF2)
{
  Standard_Integer iSense=0;
  gp_Dir aDNF1, aDNF2;
  TopoDS_Edge aE1, aE2;
  TopExp_Explorer anExp;
  //
  anExp.Init(theF1, TopAbs_EDGE);
  for (; anExp.More(); anExp.Next()) {
    aE1=TopoDS::Edge(anExp.Current());
    if (!BRep_Tool::Degenerated(aE1)) {
      if (!BRep_Tool::IsClosed(aE1, theF1)) {
        break;
      }
    }
  }
  //
  anExp.Init(theF2, TopAbs_EDGE);
  for (; anExp.More(); anExp.Next()) {
    aE2=TopoDS::Edge(anExp.Current());
    if (!BRep_Tool::Degenerated(aE2)) {
      if (!BRep_Tool::IsClosed(aE2, theF2)) {
        if (aE2.IsSame(aE1)) {
          iSense=1;
          break;
        }
      }
    }
  }
  //
  if (!iSense) {
    return iSense;
  }
  //
  BOPTools_Tools3D::GetNormalToFaceOnEdge(aE1, theF1, aDNF1);
  BOPTools_Tools3D::GetNormalToFaceOnEdge(aE2, theF2, aDNF2);
  //
  iSense=BOPTools_Tools3D::SenseFlag(aDNF1, aDNF2);
  //
  return iSense;
}
Ejemplo n.º 18
0
const TopoDS_Shape& Feature::getBaseShape() const {
    const Part::Feature* BaseObject = getBaseObject();

    const TopoDS_Shape& result = BaseObject->Shape.getValue();
    if (result.IsNull())
        throw Base::Exception("Base feature's shape is invalid");
    TopExp_Explorer xp (result, TopAbs_SOLID);
    if (!xp.More())
        throw Base::Exception("Base feature's shape is not a solid");

    return result;
}
Ejemplo n.º 19
0
TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape)
{
    if (shape.IsNull())
        Standard_Failure::Raise("Shape is null");
    TopExp_Explorer xp;
    xp.Init(shape,TopAbs_SOLID);
    for (;xp.More(); xp.Next()) {
        return xp.Current();
    }

    return TopoDS_Shape();
}
Ejemplo n.º 20
0
void Edgesort::Perform()
{
    if ( m_shape.IsNull() )
        return;

    //adds all the vertices to a map, and store the associated edges
    TopExp_Explorer explorer;
    Standard_Integer nbEdges = 0;
    Standard_Integer nbNonEdges = 0;
    for ( explorer.Init(m_shape,TopAbs_EDGE) ; explorer.More() ; explorer.Next() )
    {
        const TopoDS_Edge& currentEdge = TopoDS::Edge(explorer.Current());
        if (IsValidEdge(currentEdge))
        {
            Perform(currentEdge);
            nbEdges++;
        }
        else
        {
            nbNonEdges++;
        }
    }

    //now, iterate through the edges to sort them



    do
    {
        m_edges.clear();
        tMapPntEdge::iterator iter = m_vertices.begin();
        const gp_Pnt& firstPoint = iter->first;
        gp_Pnt currentPoint = firstPoint;
        Standard_Boolean toContinue;
        do
        {
            toContinue = PerformEdges(currentPoint);
        }
        while (toContinue == Standard_True);

        tEdgeBBoxPair aTempPair;
        aTempPair.first = getBoundingBox(m_edges);
        aTempPair.second = m_edges;
        m_EdgeBBoxMap.insert(aTempPair);
    }
    while (!m_vertices.empty());



    m_done = true;

}
Ejemplo n.º 21
0
void FaceTypeSplitter::split()
{
    TopExp_Explorer shellIt;
    for (shellIt.Init(shell, TopAbs_FACE); shellIt.More(); shellIt.Next())
    {
        TopoDS_Face tempFace(TopoDS::Face(shellIt.Current()));
        GeomAbs_SurfaceType currentType = FaceTypedBase::getFaceType(tempFace);
        SplitMapType::iterator mapIt = typeMap.find(currentType);
        if (mapIt == typeMap.end())
            continue;
        (*mapIt).second.push_back(tempFace);
    }
}
Ejemplo n.º 22
0
//=======================================================================
//function : Add
//purpose  : 
//=======================================================================
  void GEOMAlgo_ShapeSet::Add(const TopoDS_Shape& theShape,
			      const TopAbs_ShapeEnum theType)
{
  TopExp_Explorer aExp;
  //
  aExp.Init(theShape, theType);
  for (; aExp.More(); aExp.Next()) {
    const TopoDS_Shape& aS=aExp.Current();
    if (myMap.Add(aS)) {
      myList.Append(aS);
    }
  }
}
const TopoDS_Shape& SketchBased::getSupportShape() const {
    Part::Feature* SupportObject = getSupport();
    if (SupportObject == NULL)
        throw Base::Exception("No support in Sketch!");

    const TopoDS_Shape& result = SupportObject->Shape.getValue();
    if (result.IsNull())
        throw Base::Exception("Support shape is invalid");
    TopExp_Explorer xp (result, TopAbs_SOLID);
    if (!xp.More())
        throw Base::Exception("Support shape is not a solid");

    return result;
}
Ejemplo n.º 24
0
bool Geometry::GetShells(const TopoDS_Shape &brep, Geometry::ShellSet &shells) {
    TopExp_Explorer Ex;
    int count=0;
    for (Ex.Init(brep,TopAbs_SHELL); Ex.More(); Ex.Next()) {
        shells.push_back(new TopoDS_Shell);
        shells.at(shells.size()-1)= TopoDS::Shell(Ex.Current());
        count++;
    }
//    if(count>=1)
//        cout<<"element: has "<<boost::lexical_cast<string>(count)<<" shells"<<endl;
    if(count < 1)
        cout<<"error! no shell is found in this building element"<<endl;
    return count>0;
}
Ejemplo n.º 25
0
bool Geometry::GetFaces(const TopoDS_Shape &brep, Geometry::FaceSet &faces) {
    TopExp_Explorer Ex;
    int count=0;
    for (Ex.Init(brep,TopAbs_FACE); Ex.More(); Ex.Next()) {
        faces.push_back(new TopoDS_Face);
        faces.at(faces.size()-1)= TopoDS::Face(Ex.Current());
        count++;
    }
//    if(count>=1)
//        cout<<"element: has "<<boost::lexical_cast<string>(count)<<" faces"<<endl;
    if(count < 1)
        cout<<"error! no face is found in this building element"<<endl;
    return count>0;
}
Ejemplo n.º 26
0
const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f)
{
    if (!f.Infinite()) {
        TopExp_Explorer exp;
        exp.Init(f, TopAbs_VERTEX);
        if (exp.More())
            return BRep_Tool::Pnt(TopoDS::Vertex(exp.Current()));
        // Else try the other method
    }

    // TODO: Other method, e.g. intersect X,Y,Z axis with the (unlimited?) face?
    // Or get a "corner" point if the face is limited?
    throw Base::Exception("getPointFromFace(): Not implemented yet for this case");
}
Ejemplo n.º 27
0
std::list<TopoDS_Wire> CrossSection::section(double d) const
{
    std::list<TopoDS_Wire> wires;
    BRepAlgoAPI_Section cs(s, gp_Pln(a,b,c,-d));
    if (cs.IsDone()) {
        std::list<TopoDS_Edge> edges;
        TopExp_Explorer xp;
        for (xp.Init(cs.Shape(), TopAbs_EDGE); xp.More(); xp.Next())
            edges.push_back(TopoDS::Edge(xp.Current()));
        connectEdges(edges, wires);
    }

    return wires;
}
Ejemplo n.º 28
0
void CurveProjectorShape::Do(void)
{
  TopExp_Explorer Ex;
  TopoDS_Shape Edge;

  for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next())
  {
	  const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());

    //std::vector<FaceSplitEdge> vSplitEdges;
    projectCurve(aEdge, mvEdgeSplitPoints[aEdge]);

  }

}
Ejemplo n.º 29
0
void MeshProjection::projectToMesh ( const TopoDS_Shape &aShape, float fMaxDist, std::vector<SplitEdge>& rSplitEdges ) const
{
    // calculate the average edge length and create a grid
    MeshAlgorithm clAlg( _rcMesh );
    float fAvgLen = clAlg.GetAverageEdgeLength();
    MeshFacetGrid cGrid( _rcMesh, 5.0f*fAvgLen );

    TopExp_Explorer Ex;
    TopoDS_Shape Edge;

    int iCnt=0;
    for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next())
        iCnt++;

    Base::Sequencer().start( "Project curve on mesh", iCnt );

    for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
        const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
        projectEdgeToEdge( aEdge, fMaxDist, cGrid, rSplitEdges );
        Base::Sequencer().next();
    }

    Base::Sequencer().stop();
}
// Modified  Thu Sep 14 14:35:18 2006
// Contribution of Samtech www.samcef.com BEGIN
//=======================================================================
//function : Contains
//purpose  :
//=======================================================================
Standard_Boolean Contains(const TopoDS_Face& aF,
                          const TopoDS_Vertex& aV)
{
  Standard_Boolean bRet;
  TopExp_Explorer aExp;
  //
  bRet=Standard_False;
  aExp.Init(aF, TopAbs_VERTEX);
  for (; aExp.More(); aExp.Next()) {
    const TopoDS_Shape& aVF=aExp.Current();
    if (aVF.IsSame(aV)) {
      bRet=!bRet;
      break;
    }
  }
  return bRet;
}