Ejemplo n.º 1
1
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);
                } 
            }
        }
    }
}
Ejemplo n.º 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;


}
Ejemplo n.º 3
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;
    }
}
//! 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;
}
Ejemplo n.º 5
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] << " scale " << scale[0] << "," << scale[1] << "," << scale[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)->getShape();
                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]*optionScaling,point[1]*optionScaling,point[2]*optionScaling);
                pcomp->transformShape(mat,true);
                AddObject(pcomp);
            }
        }
    } 
}
Ejemplo n.º 6
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();
}
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;
}
Ejemplo n.º 8
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; 
}
// 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;
}
Ejemplo n.º 10
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;
    }
}
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();
}
Ejemplo n.º 12
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

}
Ejemplo n.º 13
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::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;
    }
}
Ejemplo n.º 15
0
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);
    }
  }
}
Ejemplo n.º 16
0
void OCCRegion::replaceFacesInternal(std::list<GFace*> &new_faces)
{
  // we simply replace old faces by new faces in the structure
  TopExp_Explorer aExpS, aExpF;
  BRep_Builder aBB;
  TopoDS_Compound aCmp;
  aBB.MakeCompound(aCmp);
  TopoDS_Solid _s_replacement;
  aBB.MakeSolid(_s_replacement);
  _s_replacement.Orientation(s.Orientation());
  aExpS.Init(s, TopAbs_SHELL);
  for (; aExpS.More(); aExpS.Next()) {
    const TopoDS_Shell& _shell=TopoDS::Shell(aExpS.Current());
    TopoDS_Shell _shell_replacement;
    aBB.MakeShell(_shell_replacement);
    _shell_replacement.Orientation(_shell.Orientation());
    aExpF.Init(_shell, TopAbs_FACE);
    for (; aExpF.More(); aExpF.Next()) {
      const TopoDS_Face& _face=TopoDS::Face(aExpF.Current());
      TopoDS_Face _face_replacement;

      std::list<GFace*>::iterator it  = l_faces.begin();
      std::list<GFace*>::iterator it2 = new_faces.begin();

      for ( ; it != l_faces.end() ; ++it,++it2){
	OCCFace *occF = dynamic_cast<OCCFace*>(*it);
	if (occF){
	  TopoDS_Face oldf = occF->getTopoDS_Face();
	  if (oldf.IsSame(_face)){
	    _face_replacement = *((TopoDS_Face*)(*it2)->getNativePtr());
	  }
	  else {
	    oldf = occF->getTopoDS_FaceOld();
	    if (oldf.IsSame(_face)){
	      _face_replacement = *((TopoDS_Face*)(*it2)->getNativePtr());
	    }
	  }
	}
      }
      if (_face_replacement.IsNull()){
	Msg::Error("cannot find an face for gluing a region");
      }

      if (_face_replacement.IsSame(_face)) {
	aBB.Add(_shell_replacement, _face);
      }
      else {
	if(FaceHaveDifferentOrientations(_face, _face_replacement))
          _face_replacement.Reverse();
	aBB.Add(_shell_replacement, _face_replacement);
      }
    }
    aBB.Add(_s_replacement, _shell_replacement);
  }
  s = _s_replacement;
  setup();
}
Ejemplo n.º 17
0
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
    }
}
Ejemplo n.º 18
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);
    }
}
Standard_Boolean ShHealOper_RemoveFace::removeFaces(const TopoDS_Solid& theShape,
                                                    TopoDS_Shape& theNewShape)
{
  Standard_Boolean isDone = Standard_False;
  TopoDS_Solid aSol;
  BRep_Builder aB;
  aB.MakeSolid(aSol);
  TopoDS_Compound aComp;
  aB.MakeCompound(aComp);
  Standard_Boolean isAddSol = Standard_False, isAddComp = Standard_False;

  //firslty faces will be deleted from each shell.
  TopoDS_Iterator aItSol(theShape,Standard_False);
  for( ; aItSol.More(); aItSol.Next()) {
    TopoDS_Shape aSh = aItSol.Value();
    TopoDS_Shape aNewShape;
    if(removeFaces(aSh,aNewShape)) 
      isDone = Standard_True;
    
    if(aNewShape.IsNull())
      continue;
    else if(aNewShape.ShapeType() == TopAbs_SHELL ) {
      aB.Add(aSol,aNewShape);
      isAddSol = Standard_True;
    }
    else {
      aB.Add(aComp,aNewShape);
      isAddComp = Standard_True;
    }
    
  }
  if(isDone) {
    //for getting correct solids class ShapeFix_Solid will be used.
    if(isAddSol) {
      Handle(ShapeFix_Solid) aSfSol = new ShapeFix_Solid(aSol);
      aSfSol->FixShellMode()= Standard_False;
      aSfSol->Perform();
      TopoDS_Shape aresSol = aSfSol->Shape();
      if(!isAddComp) 
        theNewShape = aresSol;
      else 
        aB.Add(aComp,aresSol);
    }
    else if(isAddComp)
        theNewShape = aComp;
    else
      theNewShape.Nullify();
  }
  else
    theNewShape = theShape; 
  return isDone;
}
Ejemplo n.º 20
0
void OCC_Connect::Collect(void)
{
    TopoDS_Compound result;
    BRep_Builder BB;
    BB.MakeCompound(result);
    while(assembly.size()>0) {
        if(verbose&Cutting)
            cout << "Adding item\n";
        BB.Add(result,assembly.front());
        assembly.pop_front();
    }
    assembly.push_back(result);
}
Ejemplo n.º 21
0
BldElement::BldElement(int id, string guid, string name, string type,
                       const IfcGeomObjects::IfcGeomShapeModelObject *o):id(id),guid(guid),name(name),type(type),geomtool(new Geometry){
    BRep_Builder builder;
    builder.MakeCompound(shape);
    for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->mesh().begin(); it != o->mesh().end(); ++ it) {
        TopoDS_Shape brep = it->Shape();
        gp_Trsf trsf = it->Placement().Trsf();
        brep.Move(trsf);
//        FIXME are the shells in the shape fixed by ifcopenshell?
        builder.Add(shape,brep);
    }
    shape_original=shape;
}
Standard_Boolean ShHealOper_RemoveFace::isReplace(const TopoDS_Shape& theShape, 
                                                  TopoDS_Shape& theNewShape)
{
  
  Standard_Boolean isChange = Standard_False;
  TopTools_SequenceOfShape aSeqShapes;
  if(theShape.ShapeType() == TopAbs_COMPOUND || theShape.ShapeType() == TopAbs_COMPSOLID ||
     theShape.ShapeType() == TopAbs_SOLID) {
    TopoDS_Iterator aEs(theShape);
    for( ; aEs.More(); aEs.Next()) {
      TopoDS_Shape aNewShell = aEs.Value();
      if(aNewShell.ShapeType()!= TopAbs_SHELL) {
        aSeqShapes.Append(aNewShell);
        continue;
      }
      TopoDS_Shape as = getResultShell(TopoDS::Shell(aNewShell));
      isChange = (as.IsNull() || (as.ShapeType() == TopAbs_FACE));
      if(!as.IsNull()) {
        aSeqShapes.Append(as);
      }
    }
  }
  else if(theShape.ShapeType() == TopAbs_SHELL) {
    TopoDS_Shape aSh = getResultShell(TopoDS::Shell(theShape));
    isChange = (aSh.IsNull() || (aSh.ShapeType() == TopAbs_FACE));
    if(!aSh.IsNull())
      aSeqShapes.Append(aSh);
  }
  else aSeqShapes.Append(theShape);

  if(aSeqShapes.IsEmpty())
    return Standard_True;

  if(isChange) {
    if(aSeqShapes.Length() == 1)
      theNewShape = aSeqShapes.Value(1);
    else if (aSeqShapes.Length() > 1) {
      TopoDS_Compound aComp1;
      BRep_Builder aBB;
      aBB.MakeCompound(aComp1);
      Standard_Integer kk =1;
      for( ; kk <=  aSeqShapes.Length(); kk++)
        aBB.Add(aComp1,aSeqShapes.Value(kk));
      if(aSeqShapes.Length())
        theNewShape = aComp1;
    }
  }
  else
    theNewShape = theShape;
  return isChange;
}
Ejemplo n.º 23
0
//=======================================================================
//function :  SupressFaces
//purpose  :
//=======================================================================
void SuppressFacesRec (const TopTools_SequenceOfShape& theShapesFaces,
                       const TopoDS_Shape&             theOriginalShape,
                       TopoDS_Shape&                   theOutShape)
{
  if ((theOriginalShape.ShapeType() != TopAbs_COMPOUND &&
       theOriginalShape.ShapeType() != TopAbs_COMPSOLID))
  {
    ShHealOper_RemoveFace aHealer (theOriginalShape);
    Standard_Boolean aResult = aHealer.Perform(theShapesFaces);

    if (aResult)
      theOutShape = aHealer.GetResultShape();
    else
      raiseNotDoneExeption(aHealer.GetErrorStatus());
  }
  else
  {
    BRep_Builder BB;
    TopoDS_Compound CC;
    BB.MakeCompound(CC);

    TopTools_MapOfShape mapShape;
    TopoDS_Iterator It (theOriginalShape, Standard_True, Standard_True);

    for (; It.More(); It.Next()) {
      TopoDS_Shape aShape_i = It.Value();
      if (mapShape.Add(aShape_i)) {
        // check, if current shape contains at least one of faces to be removed
        bool isFound = false;
        TopTools_IndexedMapOfShape aShapes_i;
        TopExp::MapShapes(aShape_i, aShapes_i);
        for (int i = 1; i <= theShapesFaces.Length() && !isFound; i++) {
          const TopoDS_Shape& aFace_i = theShapesFaces.Value(i);
          if (aShapes_i.Contains(aFace_i)) isFound = true;
        }
        if (isFound) {
          TopoDS_Shape anOutSh_i;
          SuppressFacesRec(theShapesFaces, aShape_i, anOutSh_i);
          if ( !anOutSh_i.IsNull() )
            BB.Add(CC, anOutSh_i);
        }
        else {
          // nothing to do
          BB.Add(CC, aShape_i);
        }
      }
    }
    theOutShape = CC;
  }
}
App::DocumentObjectExecReturn *FeatureProjection::execute(void)
{
    App::DocumentObject* link = Source.getValue();
    if (!link)
        return new App::DocumentObjectExecReturn("No object linked");
    if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
        return new App::DocumentObjectExecReturn("Linked object is not a Part object");
    const TopoDS_Shape& shape = static_cast<Part::Feature*>(link)->Shape.getShape()._Shape;
    if (shape.IsNull())
        return new App::DocumentObjectExecReturn("Linked shape object is empty");

    try {
        const Base::Vector3f& dir = Direction.getValue();
        Drawing::ProjectionAlgos alg(shape, dir);

        TopoDS_Compound comp;
        BRep_Builder builder;
        builder.MakeCompound(comp);
        if (!alg.V.IsNull() && VCompound.getValue())
            builder.Add(comp, alg.V);
        if (!alg.V1.IsNull() && Rg1LineVCompound.getValue())
            builder.Add(comp, alg.V1);
        if (!alg.VN.IsNull() && RgNLineVCompound.getValue())
            builder.Add(comp, alg.VN);
        if (!alg.VO.IsNull() && OutLineVCompound.getValue())
            builder.Add(comp, alg.VO);
        if (!alg.VI.IsNull() && IsoLineVCompound.getValue())
            builder.Add(comp, alg.VI);
        if (!alg.H.IsNull() && HCompound.getValue())
            builder.Add(comp, alg.H);
        if (!alg.H1.IsNull() && Rg1LineHCompound.getValue())
            builder.Add(comp, alg.H1);
        if (!alg.HN.IsNull() && RgNLineHCompound.getValue())
            builder.Add(comp, alg.HN);
        if (!alg.HO.IsNull() && OutLineHCompound.getValue())
            builder.Add(comp, alg.HO);
        if (!alg.HI.IsNull() && IsoLineHCompound.getValue())
            builder.Add(comp, alg.HI);

        Shape.setValue(comp);
        return App::DocumentObject::StdReturn;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        return new App::DocumentObjectExecReturn(e->GetMessageString());
    }
}
Ejemplo n.º 25
0
int OCC_Connect::SaveBRep(char const *name)
{
    gp_Pnt center(0,0,0);
    gce_MakeScale transform(center, 0.001);
    BRepBuilderAPI_Transform scale(assembly.front(), transform.Value());
    BRep_Builder BB;
    TopoDS_Compound compound;
    BB.MakeCompound(compound);
    TopTools_ListOfShape p;
    for(p=scale.Modified(assembly.front());
        !p.IsEmpty();
        p.RemoveFirst()
    )
        BB.Add(compound,p.First());
    BRepTools::Write(compound, (char*)name);
    return 1;
}
Ejemplo n.º 26
0
//=======================================================================
// function: MakeContainer
// purpose: 
//=======================================================================
  void GEOMAlgo_Tools3D::MakeContainer(const TopAbs_ShapeEnum theType,
                                      TopoDS_Shape& theC)
{
  BRep_Builder aBB;
  //
  switch(theType) {
    case TopAbs_COMPOUND:{
      TopoDS_Compound aC;
      aBB.MakeCompound(aC);
      theC=aC;
    }
      break;
      //
    case TopAbs_COMPSOLID:{
      TopoDS_CompSolid aCS;
      aBB.MakeCompSolid(aCS);
      theC=aCS;
    }
      break;
      //
    case TopAbs_SOLID:{
      TopoDS_Solid aSolid;
      aBB.MakeSolid(aSolid);
      theC=aSolid;
    }  
      break;
      //
      //
    case TopAbs_SHELL:{
      TopoDS_Shell aShell;
      aBB.MakeShell(aShell);
      theC=aShell;
    }  
      break;
      //
    case TopAbs_WIRE: {
      TopoDS_Wire aWire;
      aBB.MakeWire(aWire);
      theC=aWire;
    }
      break;
      //
    default:
      break;
  }
}
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 (it->hasStyle() && it->Style().Diffuse()) {
			const IfcGeom::SurfaceStyle::ColorComponent& clr = *it->Style().Diffuse();
			_surface_styles.push_back(clr.R());
			_surface_styles.push_back(clr.G());
			_surface_styles.push_back(clr.B());
		} else {
			_surface_styles.push_back(-1.);
			_surface_styles.push_back(-1.);
			_surface_styles.push_back(-1.);
		}
		if (it->hasStyle() && it->Style().Transparency()) {
			_surface_styles.push_back(1. - *it->Style().Transparency());
		} else {
			_surface_styles.push_back(1.);
		}
		
		if (settings().get(IteratorSettings::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();
}
Ejemplo n.º 28
0
TopoDS_Compound Assembly::compound ( void )
{
  TopoDS_Compound assembly;
  BRep_Builder builder;
  builder.MakeCompound( assembly );

  QMap<uint,Figure*>::const_iterator figure = figures_.begin();

  for ( ; figure != figures_.end(); ++figure ) {
    Subassembly* subassembly = dynamic_cast<Subassembly*>( figure.value() );
    if ( subassembly != 0 ) {
      subassembly->compound( assembly );
    }
  }

  return assembly;
}
App::DocumentObjectExecReturn *DrawViewMulti::execute(void)
{
    const std::vector<App::DocumentObject*>& links = Sources.getValues();
    if (links.empty())  {
        Base::Console().Log("INFO - DVM::execute - No Sources - creation?\n");
        return DrawViewPart::execute();
    }

    //Base::Console().Message("TRACE - DVM::execute() - %s/%s\n",getNameInDocument(),Label.getValue());

    (void) DrawView::execute();          //make sure Scale is up to date

    BRep_Builder builder;
    TopoDS_Compound comp;
    builder.MakeCompound(comp);
    for (auto& l:links) {
        const Part::TopoShape &partTopo = static_cast<Part::Feature*>(l)->Shape.getShape();
        BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape());
        TopoDS_Shape shape = BuilderCopy.Shape();
        builder.Add(comp, shape);
    }
    m_compound = comp;

    gp_Pnt inputCenter;
    try {
        inputCenter = TechDrawGeometry::findCentroid(comp,
                                                     Direction.getValue());
        TopoDS_Shape mirroredShape = TechDrawGeometry::mirrorShape(comp,
                                                    inputCenter,
                                                    Scale.getValue());
        gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),Direction.getValue());
        geometryObject = buildGeometryObject(mirroredShape,viewAxis);

#if MOD_TECHDRAW_HANDLE_FACES
        extractFaces();
#endif //#if MOD_TECHDRAW_HANDLE_FACES
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e1 = Standard_Failure::Caught();
        Base::Console().Log("LOG - DVM::execute - projection failed for %s - %s **\n",getNameInDocument(),e1->GetMessageString());
        return new App::DocumentObjectExecReturn(e1->GetMessageString());
    }

    return App::DocumentObject::StdReturn;
}
Ejemplo n.º 30
0
	callback_CascadeDoc_getnamed(const char* name_with_path) : res_found(false), set_location_to_root(true), res_level(0)  
	{
		aBuilder.MakeCompound(res_comp);

		strcpy(search_string, name_with_path);

		char* mpath = search_string;

		while (*mpath)
		{
			int copyid=-2; // default -2 means use no copy number #
			char abuffer[200];
			char* ch = abuffer;
			while (*mpath && (*mpath!=*"/") && (*mpath!=*"#"))
			{
				*ch = *mpath;
				++ch;
				++mpath;
			}
			*ch=0;
			
			if (*mpath==*"#")
			{
				mpath++;
				char numbuffer[200];
				char *nh = numbuffer;
				while (*mpath && (*mpath!=*"/"))
				{
					*nh = *mpath;
					++nh;
					++mpath;
				}
				copyid = atoi(numbuffer);
			}

			if (*mpath==*"/") 
			mpath++;

			std::string levelname(abuffer);
			level_names.push_back(levelname);
			level_copy.push_back(copyid);
		}

	}