void ImpExpDxfRead::AddGraphics() const
{
    if (optionGroupLayers) {
        for(std::map<std::string,std::vector<Part::TopoShape*> > ::const_iterator i = layers.begin(); i != layers.end(); ++i) {
            BRep_Builder builder;
            TopoDS_Compound comp;
            builder.MakeCompound(comp);
            std::string k = i->first;
            if (k == "0") // FreeCAD doesn't like an object name being '0'...
                k = "LAYER_0";
            std::vector<Part::TopoShape*> v = i->second;
            if(k.substr(0, 6) != "BLOCKS") {
                for(std::vector<Part::TopoShape*>::const_iterator j = v.begin(); j != v.end(); ++j) { 
                    const TopoDS_Shape& sh = (*j)->getShape();
                    if (!sh.IsNull())
                        builder.Add(comp, sh);
                }
                if (!comp.IsNull()) {
                    Part::Feature *pcFeature = (Part::Feature *)document->addObject("Part::Feature", k.c_str());
                    pcFeature->Shape.setValue(comp);
                } 
            }
        }
    }
}
Beispiel #2
1
IFSelect_ReturnStatus GeomImportExport::ReadSTEP(const QString& aFileName,
                                              TopoDS_Shape& aSequenceOfShape)
{
	 
 TopoDS_Shape aShape;
		TopoDS_Compound comp;
		BRep_Builder builder;
		builder.MakeCompound( comp );
	 STEPControl_Reader aReader;

 IFSelect_ReturnStatus status = aReader.ReadFile(aFileName.toAscii().data());
 if (status == IFSelect_RetDone)
 {
 Standard_CString LogFileName = "ReadStepFile.log";
 
 Interface_TraceFile::SetDefault(2,LogFileName,Standard_True);

 Standard_Boolean failsonly = Standard_False;
 aReader.PrintCheckLoad
      (failsonly, IFSelect_ItemsByEntity);
 // Root transfers
 Standard_Integer nbr = aReader.NbRootsForTransfer();
 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
 for ( Standard_Integer n = 1; n<= nbr; n++)
 {
 	Standard_Boolean ok = aReader.TransferRoot(n);
  // Collecting resulting entities
  Standard_Integer nbs = aReader.NbShapes();
  if (nbs == 0) 
  {
  aSequenceOfShape.Nullify();
  return IFSelect_RetVoid;
  } else 
  {
  for (Standard_Integer i =1; i<=nbs; i++) 
  {
   aShape=aReader.Shape(i);
   builder.Add( comp, aShape );
   
   }
   }
  }
  }
  else{
  aSequenceOfShape.Nullify();
  }
  
  aSequenceOfShape = comp;
  return status;


}
Beispiel #3
0
TopoDS_Compound* OCCBody::make_Compound(DLIList<Lump*>& my_lumps,
                                        DLIList<OCCShell*>& shells,
                                        DLIList<OCCSurface*>& surfaces)
{
  BRep_Builder B;
  TopoDS_Compound Co;
  B.MakeCompound(Co);
  for(int i = 0; i < my_lumps.size(); i ++)
  {
     OCCLump* lump = CAST_TO(my_lumps.get_and_step(), OCCLump);
     if(!lump)
     {
       PRINT_ERROR("Cannot create an OCC BodySM from the given lumps.\n"
                   "Possible incompatible geometry engines.\n");
       return (TopoDS_Compound *)NULL;
     }
     TopoDS_Solid * solid = CAST_TO(lump, OCCLump)->get_TopoDS_Solid();
     B.Add(Co, *solid);
  }
  for(int i = 0; i < shells.size(); i ++)
  {
     TopoDS_Shell * shell = shells.get_and_step()->get_TopoDS_Shell();
     B.Add(Co, *shell);
  }
  for(int i = 0; i < surfaces.size(); i ++)
  {
     TopoDS_Face * face = surfaces.get_and_step()->get_TopoDS_Face();
     B.Add(Co, *face);
  }

  TopoDS_Compound* new_top = new TopoDS_Compound(Co);
  return new_top; 
}
Beispiel #4
0
bool CTiglExportBrep::Write(const std::string& filename) const
{
    if (filename.empty()) {
       LOG(ERROR) << "Error: Empty filename in CTiglExportBrep::Write.";
       return false;
    }
    
    if (_shapes.size() > 1) {
        TopoDS_Compound c;
        BRep_Builder b;
        b.MakeCompound(c);
        
        for (ListPNamedShape::const_iterator it = _shapes.begin(); it != _shapes.end(); ++it) {
            PNamedShape shape = *it;
            if (shape) {
                b.Add(c, shape->Shape());
            }
        }
        
        // write the file
        return BRepTools::Write(c, filename.c_str());
    }
    else if ( _shapes.size() == 1) {
        PNamedShape shape = _shapes[0];
        return BRepTools::Write(shape->Shape(), filename.c_str());
    }
    else {
        LOG(WARNING) << "No shapes defined in BRep export. Abort!";
        return false;
    }
}
const TopoDS_Shape& BRepOffsetAPI_MakeOffsetFix::Shape()
{
    if (myResult.IsNull()) {
        TopoDS_Shape result = mkOffset.Shape();
        if (result.ShapeType() == TopAbs_WIRE) {
            MakeWire(result);
        }
        else if (result.ShapeType() == TopAbs_COMPOUND) {
            BRep_Builder builder;
            TopoDS_Compound comp;
            builder.MakeCompound(comp);

            TopExp_Explorer xp(result, TopAbs_WIRE);
            while (xp.More()) {
                TopoDS_Wire wire = TopoDS::Wire(xp.Current());
                MakeWire(wire);
                builder.Add(comp, wire);
                xp.Next();
            }

            result = comp;
        }

        myResult = result;
    }
    return myResult;
}
Beispiel #6
0
Part::TopoShape ShapeBinder::buildShapeFromReferences( Part::Feature* obj, std::vector< std::string > subs) {

    if (!obj)
        return TopoDS_Shape();

    if (subs.empty())
        return obj->Shape.getShape();

    std::vector<TopoDS_Shape> shapes;
    for (std::string sub : subs) {
        shapes.push_back(obj->Shape.getShape().getSubShape(sub.c_str()));
    }

    if (shapes.size() == 1){
        //single subshape. Return directly.
        return shapes[0];
    } else {
        //multiple subshapes. Make a compound.
        BRep_Builder builder;
        TopoDS_Compound cmp;
        builder.MakeCompound(cmp);
        for(const TopoDS_Shape& sh : shapes){
            builder.Add(cmp, sh);
        }
        return cmp;
    }
}
IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
	: Representation(brep.settings())
	, _id(brep.getId())
{
	TopoDS_Compound compound;
	BRep_Builder builder;
	builder.MakeCompound(compound);
	for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = brep.begin(); it != brep.end(); ++ it) {
		const TopoDS_Shape& s = it->Shape();
		gp_GTrsf trsf = it->Placement();
		if (settings().convert_back_units()) {
			gp_Trsf scale;
			scale.SetScaleFactor(1.0 / settings().unit_magnitude());
			trsf.PreMultiply(scale);
		}
		bool trsf_valid = false;
		gp_Trsf _trsf;
		try {
			_trsf = trsf.Trsf();
			trsf_valid = true;
		} catch (...) {}
		const TopoDS_Shape moved_shape = trsf_valid ? s.Moved(_trsf) :
			BRepBuilderAPI_GTransform(s,trsf,true).Shape();
		builder.Add(compound,moved_shape);
	}
	std::stringstream sstream;
	BRepTools::Write(compound,sstream);
	_brep_data = sstream.str();
}
Beispiel #8
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCompositeProfileDef* l, TopoDS_Shape& face) {
	// BRepBuilderAPI_MakeFace mf;

	TopoDS_Compound compound;
	BRep_Builder builder;
	builder.MakeCompound(compound);

	IfcSchema::IfcProfileDef::list::ptr profiles = l->Profiles();
	//bool first = true;
	for (IfcSchema::IfcProfileDef::list::it it = profiles->begin(); it != profiles->end(); ++it) {
		TopoDS_Face f;
		if (convert_face(*it, f)) {
			builder.Add(compound, f);
			/* TopExp_Explorer exp(f, TopAbs_WIRE);
			for (; exp.More(); exp.Next()) {
				const TopoDS_Wire& wire = TopoDS::Wire(exp.Current());
				if (first) {
					mf.Init(BRepBuilderAPI_MakeFace(wire));
				} else {
					mf.Add(wire);
				}
				first = false;
			} */
		}
	}

	face = compound;
	return !face.IsNull();
}
//=======================================================================
// function: CheckIntermediatePoint
// purpose:
//=======================================================================
Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
                                                             const TopoDS_Edge& aE2,
                                                             const Standard_Real aTolC)
{
  Standard_Real aT11, aT12, aTM, aTmp;
  Standard_Integer iVM;
  gp_Pnt aPM;
  BRep_Builder aBB;
  TopoDS_Vertex aVM;
  //
  // Vertex
  const BOPTools_Pave& aPave11=aPB.Pave1();
  aT11=aPave11.Param();
  //
  const BOPTools_Pave& aPave12=aPB.Pave2();
  aT12=aPave12.Param();
  //
  aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
  //
  const IntTools_Curve& aIC=aPB.Curve();
  aIC.D0(aTM, aPM);
  //
  aBB.MakeVertex (aVM, aPM, aTolC);
  //
  iVM=myContext->ComputeVE(aVM, aE2, aTmp);
  //
  return iVM;
}
//! tries to find the intersection of the section plane with the shape giving a collection of planar faces
TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shape& shape)
{
    TopoDS_Compound result;
    if(shape.IsNull()){
        Base::Console().Log("DrawViewSection::getSectionSurface - Sectional View shape is Empty\n");
        return result;
    }

    gp_Pln plnSection = getSectionPlane();
    BRep_Builder builder;
    builder.MakeCompound(result);

    TopExp_Explorer expFaces(shape, TopAbs_FACE);
    int i;
    int dbAdded = 0;
    for (i = 1 ; expFaces.More(); expFaces.Next(), i++) {
        const TopoDS_Face& face = TopoDS::Face(expFaces.Current());
        BRepAdaptor_Surface adapt(face);
        if (adapt.GetType() == GeomAbs_Plane){
            gp_Pln plnFace = adapt.Plane();

            if(plnSection.Contains(plnFace.Location(), Precision::Confusion()) &&
               plnFace.Axis().IsParallel(plnSection.Axis(), Precision::Angular())) {
                dbAdded++;
                builder.Add(result, face);
            }
        }
    }
    return result;
}
// constructor method
int TopoShapeCompoundPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
    PyObject *pcObj;
    if (!PyArg_ParseTuple(args, "O!", &(PyList_Type), &pcObj))
        return -1;

    BRep_Builder builder;
    TopoDS_Compound Comp;
    builder.MakeCompound(Comp);
    
    try {
        Py::List list(pcObj);
        for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
            if (PyObject_TypeCheck((*it).ptr(), &(Part::TopoShapePy::Type))) {
                const TopoDS_Shape& sh = static_cast<TopoShapePy*>((*it).ptr())->
                    getTopoShapePtr()->_Shape;
                if (!sh.IsNull())
                    builder.Add(Comp, sh);
            }
        }
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PyExc_Exception, e->GetMessageString());
        return -1;
    }

    getTopoShapePtr()->_Shape = Comp;
    return 0;
}
PyObject* TopoShapeCompoundPy::connectEdgesToWires(PyObject *args)
{
    PyObject *shared=Py_True;
    double tol = Precision::Confusion();
    if (!PyArg_ParseTuple(args, "|O!d",&PyBool_Type,&shared,&tol))
        return 0;

    try {
        const TopoDS_Shape& s = getTopoShapePtr()->_Shape;

        Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape();
        Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape();
        for (TopExp_Explorer xp(s, TopAbs_EDGE); xp.More(); xp.Next())
            hEdges->Append(xp.Current());

        ShapeAnalysis_FreeBounds::ConnectEdgesToWires(hEdges, tol, PyObject_IsTrue(shared), hWires);
     
        TopoDS_Compound comp;
        BRep_Builder builder;
        builder.MakeCompound(comp);

        int len = hWires->Length();
        for(int i=1;i<=len;i++) {
            builder.Add(comp, hWires->Value(i));
        }

        getTopoShapePtr()->_Shape = comp;
        return new TopoShapeCompoundPy(new TopoShape(comp));
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PyExc_Exception, e->GetMessageString());
        return 0;
    }
}
Beispiel #13
0
//#include <BRepBuilder.hxx>
TopoDS_Shape Edgesort::GetDesiredCutShape(int desiredIndex)
{
    m_edges.clear();
    m_EdgeBBoxMap.clear();
    m_vertices.clear();

    Perform();

    if (m_EdgeBBoxMap.size()>1)
    {
        if (desiredIndex == 1) //Return the smallest to return it
        {
            m_edges = m_EdgeBBoxMap.begin()->second;

        }
        else
        {
            m_edges = m_EdgeBBoxMap.rbegin()->second;
        }
        BRep_Builder aBuilder;
        TopoDS_Compound aCompound;
        aBuilder.MakeCompound(aCompound);
        for (m_edgeIter = m_edges.begin();m_edgeIter!=m_edges.end();++m_edgeIter)
        {
            aBuilder.Add(aCompound,*m_edgeIter);
        }
        return aCompound;
    }
    else
    {
        return m_shape;
    }
    //Go through the edges of the result you do not like and remove this result from the original shape

}
Beispiel #14
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);
    }
}
Beispiel #15
0
void DraftDxfRead::OnReadInsert(const double* point, const double* scale, const char* name, double rotation)
{
    std::cout << "Inserting block " << name << " rotation " << rotation << " pos " << point[0] << "," << point[1] << "," << point[2] << std::endl;
    for(std::map<std::string,std::vector<Part::TopoShape*> > ::const_iterator i = layers.begin(); i != layers.end(); ++i) {
        std::string k = i->first;
        std::string prefix = "BLOCKS ";
        prefix += name;
        prefix += " ";
        if(k.substr(0, prefix.size()) == prefix) {
            BRep_Builder builder;
            TopoDS_Compound comp;
            builder.MakeCompound(comp);
            std::vector<Part::TopoShape*> v = i->second;
            for(std::vector<Part::TopoShape*>::const_iterator j = v.begin(); j != v.end(); ++j) { 
                const TopoDS_Shape& sh = (*j)->_Shape;
                if (!sh.IsNull())
                    builder.Add(comp, sh);
            }
            if (!comp.IsNull()) {
                Part::TopoShape* pcomp = new Part::TopoShape(comp);
                Base::Matrix4D mat;
                mat.scale(scale[0],scale[1],scale[2]);
                mat.rotZ(rotation);
                mat.move(point[0],point[1],point[2]);
                pcomp->transformShape(mat,true);
                AddObject(pcomp);
            }
        }
    } 
}
PyObject*  TopoShapeCompSolidPy::add(PyObject *args)
{
    PyObject *obj;
    if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &obj))
        return NULL;

    BRep_Builder builder;
    TopoDS_Shape& comp = getTopoShapePtr()->_Shape;
    
    try {
        const TopoDS_Shape& sh = static_cast<TopoShapePy*>(obj)->
            getTopoShapePtr()->_Shape;
        if (!sh.IsNull())
            builder.Add(comp, sh);
        else
            Standard_Failure::Raise("Cannot empty shape to compound solid");
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PyExc_Exception, e->GetMessageString());
        return 0;
    }

    Py_Return;
}
Beispiel #17
0
int OCCTools::writeVRML(const char *filename, std::vector<OCCBase *> shapes)
{
    try {
        BRep_Builder B;
        TopoDS_Compound shape;
        B.MakeCompound(shape);
        
        for (unsigned i = 0; i < shapes.size(); i++) {
            B.Add(shape, shapes[i]->getShape());
        }
        VrmlAPI_Writer writer;
        writer.Write(shape, filename);
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        //printf("ERROR: %s\n", e->GetMessageString());
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to write VRML file");
        }
        return 0;
    }
    return 1;
}
PyObject*  TopoShapeCompoundPy::add(PyObject *args)
{
    PyObject *obj;
    if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &obj))
        return NULL;

    BRep_Builder builder;
    TopoDS_Shape comp = getTopoShapePtr()->getShape();
    
    try {
        const TopoDS_Shape& sh = static_cast<TopoShapePy*>(obj)->
            getTopoShapePtr()->getShape();
        if (!sh.IsNull())
            builder.Add(comp, sh);
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }

    getTopoShapePtr()->setShape(comp);

    Py_Return;
}
PyObject*  TopoShapeShellPy::add(PyObject *args)
{
    PyObject *obj;
    if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &obj))
        return NULL;

    BRep_Builder builder;
    TopoDS_Shape& shell = getTopoShapePtr()->_Shape;
    
    try {
        const TopoDS_Shape& sh = static_cast<TopoShapeFacePy*>(obj)->
            getTopoShapePtr()->_Shape;
        if (!sh.IsNull()) {
            builder.Add(shell, sh);
            BRepCheck_Analyzer check(shell);
            if (!check.IsValid()) {
                ShapeUpgrade_ShellSewing sewShell;
                getTopoShapePtr()->_Shape = sewShell.ApplySewing(shell);
            }
        }
        else {
            Standard_Failure::Raise("cannot add empty shape");
        }
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }

    Py_Return;
}
void Transformed::divideTools(const std::vector<TopoDS_Shape> &toolsIn, std::vector<TopoDS_Shape> &individualsOut,
                              TopoDS_Compound &compoundOut) const
{
  typedef std::pair<TopoDS_Shape, Bnd_Box> ShapeBoundPair;
  typedef std::list<ShapeBoundPair> PairList;
  typedef std::vector<ShapeBoundPair> PairVector;
  
  PairList pairList;
  
  std::vector<TopoDS_Shape>::const_iterator it;
  for (it = toolsIn.begin(); it != toolsIn.end(); ++it)
  {
    Bnd_Box bound;
    BRepBndLib::Add(*it, bound);
    bound.SetGap(0.0);
    ShapeBoundPair temp = std::make_pair(*it, bound);
    pairList.push_back(temp);
  }
  
  BRep_Builder builder;
  builder.MakeCompound(compoundOut);
  
  while(!pairList.empty())
  {
    PairVector currentGroup;
    currentGroup.push_back(pairList.front());
    pairList.pop_front();
    PairList::iterator it = pairList.begin();
    while(it != pairList.end())
    {
      PairVector::const_iterator groupIt;
      bool found(false);
      for (groupIt = currentGroup.begin(); groupIt != currentGroup.end(); ++groupIt)
      {
	if (!(*it).second.IsOut((*groupIt).second))//touching means is out.
	{
	  found = true;
	  break;
	}
      }
      if (found)
      {
	currentGroup.push_back(*it);
	pairList.erase(it);
	it=pairList.begin();
	continue;
      }
      it++;
    }
    if (currentGroup.size() == 1)
      builder.Add(compoundOut, currentGroup.front().first);
    else
    {
      PairVector::const_iterator groupIt;
      for (groupIt = currentGroup.begin(); groupIt != currentGroup.end(); ++groupIt)
	individualsOut.push_back((*groupIt).first);
    }
  }
}
//=======================================================================
//function : FillContainers
//purpose  :
//=======================================================================
void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
{
  Standard_Boolean bHasImage, bToReverse;
  Standard_Integer i, aNbW;
  TopoDS_Shape aWnew, aEnew;
  TopoDS_Iterator aItS;
  BRep_Builder aBB;
  TopTools_IndexedMapOfShape aMW;
  TopTools_MapOfShape aMFence;
  //
  myErrorStatus=0;
  myWarningStatus=0;
  //
  TopExp::MapShapes(myArgument, aType, aMW);
  //
  aNbW=aMW.Extent();
  for (i=1; i<=aNbW; ++i) {
    const TopoDS_Shape& aW=aMW(i);
    //
    if (!aMFence.Add(aW)) {
      continue;
    }
    //
    bHasImage=HasImage(aW);
    if (!bHasImage) {
      continue;
    }
    //
    GEOMAlgo_Tools3D::MakeContainer(aType, aWnew);
    aWnew.Orientation(aW.Orientation());
    //
    aItS.Initialize(aW);
    for (; aItS.More(); aItS.Next()) {
      const TopoDS_Shape& aE=aItS.Value();
      if (myOrigins.IsBound(aE)) {
        aEnew=myOrigins.Find(aE);
        //
        bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aEnew, aE, myContext);
        if (bToReverse) {
          aEnew.Reverse();
        }
        //
        aBB.Add(aWnew, aEnew);
      }
      else {
        aBB.Add(aWnew, aE);
      }
    }
    //
    //myImages / myOrigins
    TopTools_ListOfShape aLSD;
    //
    aLSD.Append(aW);
    myImages.Bind(aWnew, aLSD);
    myOrigins.Bind(aW, aWnew);
    //
  }//for (i=1; i<=aNbE; ++i) {
}
//=======================================================================
//function : Execute
//purpose  :
//=======================================================================
Standard_Integer GEOM_SubShapeDriver::Execute(TFunction_Logbook& log) const
{
  if (Label().IsNull()) return 0;
  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());

  GEOM_ISubShape aCI (aFunction);

  TDF_Label aLabel = aCI.GetMainShape()->GetOwnerEntry();
  if (aLabel.IsRoot()) return 0;
  Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel);
  if (anObj.IsNull()) return 0;
  TopoDS_Shape aMainShape = anObj->GetValue();
  if (aMainShape.IsNull()) return 0;

  Handle(TColStd_HArray1OfInteger) anIndices = aCI.GetIndices();
  if (anIndices.IsNull() || anIndices->Length() <= 0) return 0;

  BRep_Builder B;
  TopoDS_Compound aCompound;
  TopoDS_Shape aShape;

  if (anIndices->Length() == 1 && anIndices->Value(1) == -1) { //The empty sub-shape
    B.MakeCompound(aCompound);
    aShape = aCompound;
  }
  else {
    TopTools_IndexedMapOfShape aMapOfShapes;
    TopExp::MapShapes(aMainShape, aMapOfShapes);

    if (anIndices->Length() > 1) {
      B.MakeCompound(aCompound);

      for (int i = anIndices->Lower(); i <= anIndices->Upper(); i++) {
        if (aMapOfShapes.Extent() < anIndices->Value(i))
          Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
        TopoDS_Shape aSubShape = aMapOfShapes.FindKey(anIndices->Value(i));
        if (aSubShape.IsNull()) continue;
        B.Add(aCompound,aSubShape);
      }

      aShape = aCompound;
    }
    else {
      int i = anIndices->Lower();
      if (aMapOfShapes.Extent() < anIndices->Value(i))
        Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
      aShape = aMapOfShapes.FindKey(anIndices->Value(i));
    }
  }

  if (aShape.IsNull()) return 0;

  aFunction->SetValue(aShape);

  log.SetTouched(Label());

  return 1;
}
//=======================================================================
//function : BuildResult
//purpose  :
//=======================================================================
void GEOMAlgo_Gluer2::BuildResult()
{
  Standard_Boolean bHasImage;
  TopoDS_Shape aCnew, aCXnew;
  TopoDS_Iterator aItC;
  BRep_Builder aBB;
  //
  myErrorStatus=0;
  myWarningStatus=0;
  //
  aItC.Initialize(myArgument);
  for (; aItC.More(); aItC.Next()) {
    const TopoDS_Shape& aCx=aItC.Value();
    bHasImage=HasImage(aCx);
    if (bHasImage) {
      break;
    }
  }
  //
  if (!bHasImage) {
    myShape=myArgument;
    return;
  }
  //
  GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
  //
  aItC.Initialize(myArgument);
  for (; aItC.More(); aItC.Next()) {
    const TopoDS_Shape& aCX=aItC.Value();
    if (myOrigins.IsBound(aCX)) {
      aCXnew=myOrigins.Find(aCX);
      aCXnew.Orientation(aCX.Orientation());
      aBB.Add(aCnew, aCXnew);
    }
    else {
      aBB.Add(aCnew, aCX);
    }
  }
  //
  if (!myKeepNonSolids) {
    Standard_Integer i, aNb;
    TopoDS_Shape aCnew1;
    TopTools_IndexedMapOfShape aM;
    //
    GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew1);
    //
    TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);

    aNb=aM.Extent();
    for (i=1; i<=aNb; ++i) {
      const TopoDS_Shape& aS=aM(i);
      aBB.Add(aCnew1, aS);
    }
    aCnew=aCnew1;
  }
  //
  myShape=aCnew;
}
PyObject* TopoShapeFacePy::setTolerance(PyObject *args)
{
    double tol;
    if (!PyArg_ParseTuple(args, "d", &tol))
        return 0;
    BRep_Builder aBuilder;
    const TopoDS_Face& f = TopoDS::Face(getTopoShapePtr()->getShape());
    aBuilder.UpdateFace(f, tol);
    Py_Return;
}
PyObject* TopoShapeVertexPy::setTolerance(PyObject *args)
{
    double tol;
    if (!PyArg_ParseTuple(args, "d", &tol))
        return 0;
    BRep_Builder aBuilder;
    const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->getShape());
    aBuilder.UpdateVertex(v, tol);
    Py_Return;
}
PyObject* TopoShapeEdgePy::setTolerance(PyObject *args)
{
    double tol;
    if (!PyArg_ParseTuple(args, "d", &tol))
        return 0;
    BRep_Builder aBuilder;
    const TopoDS_Edge& e = TopoDS::Edge(getTopoShapePtr()->_Shape);
    aBuilder.UpdateEdge(e, tol);
    Py_Return;
}
TopoDS_Shape FaceMakerCheese::makeFace(const std::vector<TopoDS_Wire>& w)
{
    if (w.empty())
        return TopoDS_Shape();

    //FIXME: Need a safe method to sort wire that the outermost one comes last
    // Currently it's done with the diagonal lengths of the bounding boxes
    std::vector<TopoDS_Wire> wires = w;
    std::sort(wires.begin(), wires.end(), Wire_Compare());
    std::list<TopoDS_Wire> wire_list;
    wire_list.insert(wire_list.begin(), wires.rbegin(), wires.rend());

    // separate the wires into several independent faces
    std::list< std::list<TopoDS_Wire> > sep_wire_list;
    while (!wire_list.empty()) {
        std::list<TopoDS_Wire> sep_list;
        TopoDS_Wire wire = wire_list.front();
        wire_list.pop_front();
        sep_list.push_back(wire);

        std::list<TopoDS_Wire>::iterator it = wire_list.begin();
        while (it != wire_list.end()) {
            if (isInside(wire, *it)) {
                sep_list.push_back(*it);
                it = wire_list.erase(it);
            }
            else {
                ++it;
            }
        }

        sep_wire_list.push_back(sep_list);
    }

    if (sep_wire_list.size() == 1) {
        std::list<TopoDS_Wire>& wires = sep_wire_list.front();
        return makeFace(wires);
    }
    else if (sep_wire_list.size() > 1) {
        TopoDS_Compound comp;
        BRep_Builder builder;
        builder.MakeCompound(comp);
        for (std::list< std::list<TopoDS_Wire> >::iterator it = sep_wire_list.begin(); it != sep_wire_list.end(); ++it) {
            TopoDS_Shape aFace = makeFace(*it);
            if (!aFace.IsNull())
                builder.Add(comp, aFace);
        }

        return comp;
    }
    else {
        return TopoDS_Shape(); // error
    }
}
Beispiel #28
0
void OCC_Connect::Connect(void)
{
    while(assembly.size()>1) {
        TopoDS_Compound result;
        BRep_Builder BB;
        BB.MakeCompound(result);
        Intersect(BB,result,assembly.front(),assembly.back());
        assembly.pop_front();
        assembly.pop_back();
        assembly.push_back(result);
    }
}
//=======================================================================
//function : FillImagesCompound
//purpose  :
//=======================================================================
void FillImagesCompound(const TopoDS_Shape& theS,
                        BRepAlgo_Image& theImages,
                        TopTools_MapOfShape& theMFP)
{
    Standard_Boolean bInterferred;
    TopAbs_ShapeEnum aTypeX;
    TopAbs_Orientation aOrX;
    TopoDS_Iterator aIt;
    BRep_Builder aBB;
    TopTools_ListIteratorOfListOfShape aItIm;
    //
    if (!theMFP.Add(theS)) {
        return;
    }
    //
    bInterferred=Standard_False;
    aIt.Initialize(theS);
    for (; aIt.More(); aIt.Next()) {
        const TopoDS_Shape& aSX=aIt.Value();
        aTypeX=aSX.ShapeType();
        if (aTypeX==TopAbs_COMPOUND) {
            FillImagesCompound(aSX, theImages, theMFP);
        }
        if (theImages.HasImage(aSX)) {
            bInterferred=Standard_True;
        }
    }
    if (!bInterferred) {
        return;
    }
    //
    TopoDS_Shape aCIm;
    GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCIm);
    //
    aIt.Initialize(theS);
    for (; aIt.More(); aIt.Next()) {
        const TopoDS_Shape& aSX=aIt.Value();
        aOrX=aSX.Orientation();
        if (theImages.HasImage(aSX)) {
            const TopTools_ListOfShape& aLFIm=theImages.Image(aSX);
            aItIm.Initialize(aLFIm);
            for (; aItIm.More(); aItIm.Next()) {
                TopoDS_Shape aSXIm=aItIm.Value();
                aSXIm.Orientation(aOrX);
                aBB.Add(aCIm, aSXIm);
            }
        }
        else {
            aBB.Add(aCIm, aSX);
        }
    }
    theImages.Bind(theS, aCIm);
}
Beispiel #30
0
// sometimes, we ask to replace the ending points of the curve
// in gluing operations for example
void OCCEdge::replaceEndingPointsInternals(GVertex *g0, GVertex *g1)
{
  TopoDS_Vertex aV1 = *((TopoDS_Vertex*)v0->getNativePtr());
  TopoDS_Vertex aV2 = *((TopoDS_Vertex*)v1->getNativePtr());
  TopoDS_Vertex aVR1 = *((TopoDS_Vertex*)g0->getNativePtr());
  TopoDS_Vertex aVR2 = *((TopoDS_Vertex*)g1->getNativePtr());

  //  printf("%p %p --- %p %p replacing %d %d by %d %d in occedge %d\n",
  //	 v0,v1,g0,g1,v0->tag(),v1->tag(),g0->tag(),g1->tag(),tag());

  Standard_Boolean bIsDE = BRep_Tool::Degenerated(c);

  TopoDS_Edge aEx = c;
  aEx.Orientation(TopAbs_FORWARD);

  Standard_Real t1=s0;
  Standard_Real t2=s1;

  aVR1.Orientation(TopAbs_FORWARD);
  aVR2.Orientation(TopAbs_REVERSED);

  if (bIsDE) {
    Standard_Real aTol;
    BRep_Builder aBB;
    TopoDS_Edge E;
    //TopAbs_Orientation anOrE;
    //anOrE = c.Orientation();
    aTol = BRep_Tool::Tolerance(c);
    E = aEx;
    E.EmptyCopy();
    aBB.Add(E, aVR1);
    aBB.Add(E, aVR2);
    aBB.Range(E, t1, t2);
    aBB.Degenerated(E, Standard_True);
    aBB.UpdateEdge(E, aTol);
    _replacement=E;
  }
  else {
#if (OCC_VERSION_MAJOR == 6) && (OCC_VERSION_MINOR < 6)
    BOPTools_Tools::MakeSplitEdge(aEx, aVR1, t1, aVR2, t2, _replacement);
#else
    BOPTools_AlgoTools::MakeSplitEdge(aEx, aVR1, t1, aVR2, t2, _replacement);
#endif
  }
  TopoDS_Edge temp = c;
  c = _replacement;
  _replacement = temp;
  curve = BRep_Tool::Curve(c, s0, s1);
  //build the reverse curve
  c_rev = c;
  c_rev.Reverse();
}