Example #1
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();
}
Example #2
0
OCCFace *OCCFace::copy(bool deepCopy = false)
{
    OCCFace *ret = new OCCFace();
    try {
        if (deepCopy) {
            BRepBuilderAPI_Copy A;
            A.Perform(this->getShape());
            ret->setShape(A.Shape());
        } else {
            ret->setShape(this->getShape());
        }
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to copy face");
        }
        return NULL;
    }
    return ret;
}
Example #3
0
int extractSubShape(const TopoDS_Shape& shape, std::vector<OCCBase *>& shapes)
{
    TopAbs_ShapeEnum type = shape.ShapeType();
    switch (type)
    {
    case TopAbs_COMPOUND:
        return 0;
    case TopAbs_COMPSOLID:
    case TopAbs_SOLID:
    {
        OCCSolid *ret = new OCCSolid();
        ret->setShape(shape);
        if (!ret->fixShape()) {
            delete ret;
            return 0;
        }
        shapes.push_back((OCCBase *)ret);
        break;
    }
    case TopAbs_FACE:
    case TopAbs_SHELL:
    {
        OCCFace *ret = new OCCFace();
        ret->setShape(shape);
        if (!ret->fixShape()) {
            delete ret;
            return 0;
        }
        shapes.push_back((OCCBase *)ret);
        break;
    }
    case TopAbs_WIRE:
    {
        OCCWire *ret = new OCCWire();
        ret->setShape(shape);
        if (!ret->fixShape()) {
            delete ret;
            return 0;
        }
        shapes.push_back((OCCBase *)ret);
        break;
    }
    case TopAbs_EDGE:
    {
        OCCEdge *ret = new OCCEdge();
        ret->setShape(shape);
        if (!ret->fixShape()) {
            delete ret;
            return 0;
        }
        shapes.push_back((OCCBase *)ret);
        break;
    }
    case TopAbs_VERTEX:
    {
        OCCVertex *ret = new OCCVertex();
        ret->setShape(shape);
        if (!ret->fixShape()) {
            delete ret;
            return 0;
        }
        shapes.push_back((OCCBase *)ret);
        break;
    }
    default:
        return 0;
    }
    return 1;
}