Logo Search packages:      
Sourcecode: opencascade version File versions  Download package

void BRepFeat_MakeRevolutionForm::Init ( const TopoDS_Shape Sbase,
const TopoDS_Wire W,
const Handle(Geom_Plane)&  Plane,
const gp_Ax1 Axis,
const Standard_Real  Height1,
const Standard_Real  Height2,
const Standard_Integer  Fuse,
Standard_Boolean &  Sliding 
)

Initializes this construction algorithm
A contour W, a shape Sbase and a plane P are initialized to serve as the basic elements
in the construction of the rib or groove. The axis Axis of the revolved surface in the basis
shape defines the feature's axis of revolution. Height1 and Height2 may be
used as limits to the construction of the feature.
Fuse offers a choice between:

  • removing matter with a Boolean cut using the setting 0 in case of the groove
  • adding matter with Boolean fusion using the setting 1 in case of the rib.

Definition at line 147 of file BRepFeat_MakeRevolutionForm.cxx.

References TopoDS_Builder::Add(), gp_Circ::Axis(), Precision::Confusion(), BRepTools_WireExplorer::Current(), TopExp_Explorer::Current(), BRep_Tool::Curve(), gp_Ax1::Direction(), gp_Pnt::Distance(), GeomAPI_ProjectPointOnCurve::Distance(), BRepBuilderAPI_Command::Done(), TopExp::FirstVertex(), TopExp_Explorer::Init(), gp_Ax1::IsCoaxial(), LocOpe_CSIntersector::IsDone(), TopoDS_Shape::IsNull(), TopoDS_Shape::IsSame(), BRepAlgo::IsValid(), TopExp::LastVertex(), BRep_Builder::MakeFace(), TopoDS_Builder3D::MakeShell(), BRep_Builder::MakeVertex(), TopoDS_Builder::MakeWire(), BRepTools_WireExplorer::More(), TopExp_Explorer::More(), LocOpe_CSIntersector::NbPoints(), GeomAPI_ProjectPointOnCurve::NbPoints(), TopExp_Explorer::Next(), BRepTools_WireExplorer::Next(), BRepBuilderAPI_Command::NotDone(), TopoDS_Shape::Nullify(), TopoDS_Shape::Orientation(), TopoDS_Shape::Oriented(), ElSLib::Parameters(), LocOpe_CSIntersector::Perform(), Geom_Plane::Pln(), BRep_Tool::Pnt(), LocOpe_CSIntersector::Point(), GeomAPI_ProjectPointOnCurve::Point(), gp_Circ::Radius(), gp_Pnt::Rotated(), BRepLib_MakeShape::Shape(), BRepBuilderAPI_MakeShape::Shape(), BRepPrimAPI_MakeBox::Solid(), BRep_Tool::Surface(), GeomAPI::To2d(), BRep_Tool::Tolerance(), gp_Pnt2d::X(), and gp_Pnt2d::Y().

{ 
#ifdef DEB
  Standard_Boolean trc = BRepFeat_GettraceFEAT();
  if (trc) cout << "BRepFeat_MakeRevolutionForm::Init" << endl;
#endif
  Standard_Boolean RevolRib = Standard_True;
  Done();

// modify = 0 si on ne veut pas faire de glissement
//        = 1 si on veut essayer de faire un glissement
  Standard_Boolean Sliding = Modify;

  myAxe = Axis;
  Handle(Geom_Line) Line = new Geom_Line(Axis); 
  Standard_Real LineFirst, LineLast;
  
  LocOpe_CSIntersector ASI(Sbase);
  TColGeom_SequenceOfCurve scur;
  scur.Clear();
  scur.Append(Line);
  ASI.Perform(scur);
  if(ASI.IsDone() && ASI.NbPoints(1) >= 2) {
    LineLast = ASI.Point(1, ASI.NbPoints(1)).Parameter();
    LineFirst = ASI.Point(1, 1).Parameter();
  }
  else {
    LineFirst = RealFirst();
    LineLast = RealLast();
  }
  
  Handle(Geom2d_Curve) ln2d = GeomAPI::To2d(Line, Plane->Pln());
  
  TopExp_Explorer exx;
  Standard_Real Rad = RealLast();
  
  exx.Init(W, TopAbs_EDGE);
  for(; exx.More(); exx.Next()) {
    const TopoDS_Edge& e = TopoDS::Edge(exx.Current());
    Standard_Real f, l;
    Handle(Geom_Curve) c = BRep_Tool::Curve(e, f, l);
    Handle(Geom2d_Curve) c2d = GeomAPI::To2d(c, Plane->Pln());
    Geom2dAPI_ExtremaCurveCurve extr(ln2d, c2d, LineFirst, LineLast,f,l);
    Quantity_Length L = RealLast();
    if(extr.NbExtrema() >= 1) {
      L = extr.LowerDistance();
    }
    gp_Pnt p1 = c->Value(f);
    gp_Pnt p2 = c->Value(l);
    GeomAPI_ProjectPointOnCurve proj1(p1, Line);
    GeomAPI_ProjectPointOnCurve proj2(p2, Line);
    if(proj1.NbPoints() < 1 || proj2.NbPoints() < 1) {
#ifdef DEB
      if (trc) cout << " No projection points" << endl;
#endif
      myStatusError = BRepFeat_NoProjPt;
      NotDone();
      return;
    }
    Standard_Real par1 = proj1.Distance(1);
    Standard_Real par2 = proj2.Distance(1);
    Standard_Real Par  = Min(par1, par2);
    if(Par<L) L = Par;
    if(L<Rad && L > 0.) Rad = L;
  }
  
  Standard_Real height = Min(H1, H2);
  
  if(Rad <= height) Rad = height + 0.01*height;  
  
  myAngle1 = asin(H1/Rad) + PI/10.;
  myAngle2 = asin(H2/Rad) + PI/10.;
  
  if((myAngle1 - PI/2) > Precision::Confusion())
    myAngle1 = PI/2;
  if((myAngle2 - PI/2) > Precision::Confusion())
    myAngle2 = PI/2;
  
  mySkface.Nullify();
  myPbase.Nullify();

  if(Mode == 0) 
    myFuse   = Standard_False;
  else // if(Mode == 1) 
    myFuse   = Standard_True;
#ifdef DEB
  if (trc) {
    if (myFuse)  cout << " Fuse" << endl;
    if (!myFuse)  cout << " Cut" << endl;
  }
#endif

// ---Determination Tolerance : tolerance max sur les parametres
  myTol = Precision::Confusion();
  
  exx.Init(W, TopAbs_VERTEX);
  for(; exx.More(); exx.Next()) {
    const Standard_Real& tol = BRep_Tool::
      Tolerance(TopoDS::Vertex(exx.Current()));
    if(tol > myTol) myTol = tol;
  }
  
  exx.Init(Sbase, TopAbs_VERTEX);
  for(; exx.More(); exx.Next()) {
    const Standard_Real& tol = BRep_Tool::
      Tolerance(TopoDS::Vertex(exx.Current()));
    if(tol > myTol) myTol = tol;
  }

  TopoDS_Shape aLocalShape = W.Oriented(TopAbs_FORWARD);
  myWire = TopoDS::Wire(aLocalShape);
//  myWire = TopoDS::Wire(W.Oriented(TopAbs_FORWARD));
  myPln = Plane;
  myHeight1 = H1;
  myHeight2 = H2;
  
  mySbase  = Sbase;
  mySlface.Clear();
  myShape.Nullify();
  myMap.Clear();
  myFShape.Nullify();
  myLShape.Nullify();

// ---Calcul boite englobante
  BRep_Builder BB;
  
  TopTools_ListOfShape theList;  
  
  TopoDS_Shape U;
  U.Nullify();
  gp_Pnt FirstCorner, LastCorner;
  Standard_Real bnd = HeightMax(mySbase, U, FirstCorner, LastCorner);
  myBnd = bnd;
  
  BRepPrimAPI_MakeBox Bndbox(FirstCorner, LastCorner);
  TopoDS_Solid BndBox = Bndbox.Solid();


// ---Construction de la face plan de travail (section boite englobante)
  BRepLib_MakeFace PlaneF(myPln->Pln(), -6.*myBnd, 
                    6.*myBnd, -6.*myBnd, 6.*myBnd);
  TopoDS_Face PlaneFace = TopoDS::Face(PlaneF.Shape());
  
  //modified by NIZNHY-PKV Fri Mar 22 16:52:26 2002 f
  //BRepAlgo_Common PlaneS(BndBox, PlaneFace);
  BRepAlgoAPI_Common PlaneS(BndBox, PlaneFace);
  //modified by NIZNHY-PKV Fri Mar 22 16:52:31 2002 t
  TopExp_Explorer EXP;
  TopoDS_Shape PlaneSect = PlaneS.Shape();
  EXP.Init(PlaneSect, TopAbs_WIRE);
  TopoDS_Wire www = TopoDS::Wire(EXP.Current());
  BRepLib_MakeFace Bndface(myPln->Pln(), www, Standard_True);
  TopoDS_Face BndFace = TopoDS::Face(Bndface.Shape());


// ---Recherche des faces d'appui de la nervure    
  TopoDS_Edge FirstEdge, LastEdge;
  TopoDS_Face FirstFace, LastFace;
  TopoDS_Vertex FirstVertex, LastVertex;
  
  Standard_Boolean OnFirstFace = Standard_False;
  Standard_Boolean OnLastFace = Standard_False;
  Standard_Boolean PtOnFirstEdge = Standard_False;
  Standard_Boolean PtOnLastEdge = Standard_False;
  TopoDS_Edge OnFirstEdge, OnLastEdge;
  OnFirstEdge.Nullify();
  OnLastEdge.Nullify();

  Standard_Boolean Data = ExtremeFaces(RevolRib, myBnd, myPln, FirstEdge, LastEdge, 
                               FirstFace, LastFace, FirstVertex, 
                               LastVertex, OnFirstFace, OnLastFace,
                               PtOnFirstEdge, PtOnLastEdge,
                               OnFirstEdge, OnLastEdge);
  
  if(!Data) {
#ifdef DEB
    if (trc) cout << " No Extreme faces" << endl;
#endif
    myStatusError = BRepFeat_NoExtFace;
    NotDone();
    return;
  }


// ---Point detrompeur pour le cote du wire a remplir - cote matiere
  gp_Pnt CheckPnt = CheckPoint(FirstEdge, bnd/10., myPln);
  
//  Standard_Real f, l;

// ---Controle glissement valable
// Plein de cas ou on sort du glissement
  Standard_Integer Concavite = 3;  // a priori le profile n'est pas concave
  
  myFirstPnt = BRep_Tool::Pnt(FirstVertex);
  myLastPnt  = BRep_Tool::Pnt(LastVertex);

// SliList : liste des faces concernees par la nervure
  TopTools_ListOfShape SliList;
  SliList.Append(FirstFace);
  
  if(Sliding) {    // glissement
#ifdef DEB
    if (trc) cout << " Sliding" << endl;
#endif
    Handle(Geom_Surface) s = BRep_Tool::Surface(FirstFace);
    if (s->DynamicType() == 
      STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
      s = Handle(Geom_RectangularTrimmedSurface)::
      DownCast(s)->BasisSurface();
    }
    if(s->DynamicType() != STANDARD_TYPE(Geom_Plane) && 
       s->DynamicType() != STANDARD_TYPE(Geom_CylindricalSurface) &&
       s->DynamicType() != STANDARD_TYPE(Geom_ConicalSurface) &&
       s->DynamicType() != STANDARD_TYPE(Geom_ToroidalSurface)) 
      Sliding = Standard_False;
  }

  if(Sliding) {     // glissement
    Handle(Geom_Surface) ss = BRep_Tool::Surface(LastFace);
    if (ss->DynamicType() == 
      STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
      ss = Handle(Geom_RectangularTrimmedSurface)::
      DownCast(ss)->BasisSurface();
    }
    if(ss->DynamicType() != STANDARD_TYPE(Geom_Plane) && 
       ss->DynamicType() != STANDARD_TYPE(Geom_CylindricalSurface) &&
       ss->DynamicType() != STANDARD_TYPE(Geom_ConicalSurface) &&
       ss->DynamicType() != STANDARD_TYPE(Geom_ToroidalSurface)) 
      Sliding = Standard_False;
  }

// Controle uniquement points de depart et d'arrivee
// -> pas de controle au milieu - a ameliorer
// Si on faisait un controle entre Surface et sgement entre les 2 points limite
// -> tres cher - a ameliorer  
  //gp_Pnt FirstCenter, LastCenter;
  gp_Circ FirstCircle, LastCircle;
  Handle(Geom_Curve) FirstCrv, LastCrv;
  
  if(Sliding) {    // glissement
    GeomAPI_ProjectPointOnCurve proj(myFirstPnt, Line);
    if(proj.NbPoints() < 1) {
#ifdef DEB
      if (trc) cout << " No First Point projection" << endl;
#endif
      myStatusError = BRepFeat_NoProjPt;
      NotDone();
      return;
    }
    Standard_Real FirstRayon = proj.Distance(1);
    gp_Pnt FirstCenter = proj.Point(1);
    
    GeomAPI_ProjectPointOnCurve proj1(myLastPnt, Line);
    if(proj.NbPoints() < 1) {
#ifdef DEB
      if (trc) cout << " No Last Point projection" << endl;
#endif
      myStatusError = BRepFeat_NoProjPt;
      NotDone();
      return;
    }
    Standard_Real LastRayon = proj1.Distance(1);
    gp_Pnt LastCenter = proj1.Point(1);
    
    gp_Vec axv(myAxe.Direction());
    gp_Ax2 ax2(FirstCenter, axv);
    gp_Ax2 ax2p(LastCenter, axv);
    gp_Circ theFC(ax2, FirstRayon);
    gp_Circ theLC(ax2p, LastRayon);
    
    gp_Pnt RFirstPnt1 = myFirstPnt.Rotated(myAxe, myAngle1);
    gp_Pnt RLastPnt1 = myLastPnt.Rotated(myAxe, myAngle1);
    gp_Pnt RFirstPnt2 = myFirstPnt.Rotated(myAxe, -myAngle2);
    gp_Pnt RLastPnt2 = myLastPnt.Rotated(myAxe, -myAngle2);
    
    BRep_Builder Bu;
    TopoDS_Vertex v1, v2, v3, v4;
    Bu.MakeVertex(v1, RFirstPnt2, Precision::Confusion());
    Bu.MakeVertex(v2, RFirstPnt1, Precision::Confusion());
    Bu.MakeVertex(v3, RLastPnt2, Precision::Confusion());
    Bu.MakeVertex(v4, RLastPnt1, Precision::Confusion());
    
    BRepLib_MakeEdge ee1(theFC, v1, v2);
    BRepLib_MakeEdge ee2(theLC, v3, v4);
    
    if(Sliding && !PtOnFirstEdge) {
      BRepExtrema_ExtCF ext1(TopoDS::Edge(ee1.Shape()), FirstFace);
#ifdef DEB
      Standard_Integer nb = 
#endif
                            ext1.NbExt();
#ifdef DEB
      Standard_Real dist =
#endif
                            ext1.Value(1);
      if(ext1.NbExt() < 1 || ext1.Value(1) > Precision::Confusion()) 
      Sliding = Standard_False;
    }
    if(Sliding && !PtOnLastEdge) {
      BRepExtrema_ExtCF ext2(ee2, LastFace); // ExtCF : courbes et surfaces
      if(ext2.NbExt() < 1 || ext2.Value(1) > Precision::Confusion()) 
      Sliding = Standard_False;
    }
    if(Sliding && PtOnFirstEdge) {
      Standard_Real f, l;
      FirstCrv = BRep_Tool::Curve(OnFirstEdge, f, l);
      if(FirstCrv->DynamicType() != STANDARD_TYPE(Geom_Circle)) 
      Sliding = Standard_False;
      else {
      Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(FirstCrv);
      gp_Circ Circ = C1->Circ();
      FirstCircle = Circ;
      gp_Ax1 circax = FirstCircle.Axis();
      if(!circax.IsCoaxial(myAxe, Precision::Confusion(), 
                       Precision::Confusion())) 
        Sliding = Standard_False;
      else {
//#ifndef DEB
        if(fabs(FirstCircle.Radius()-FirstRayon) >=
//#else
//      if(abs(FirstCircle.Radius()-FirstRayon) >=
//#endif
           Precision::Confusion()) 
          Sliding = Standard_False;
      }     
      }
    }
    
    if(Sliding && PtOnLastEdge) {
      Standard_Real f, l;
      LastCrv = BRep_Tool::Curve(OnLastEdge, f, l);
      if(LastCrv->DynamicType() != STANDARD_TYPE(Geom_Circle)) 
      Sliding = Standard_False;
      else {
      Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(LastCrv);
      gp_Circ Circ = C1->Circ();
      LastCircle = Circ;
      gp_Ax1 circax = LastCircle.Axis();
      if(!circax.IsCoaxial(myAxe, Precision::Confusion(), 
                       Precision::Confusion())) 
        Sliding = Standard_False;
      else {
        Standard_Real rad = LastCircle.Radius();
//#ifndef DEB
        if(fabs(rad - LastRayon) >= Precision::Confusion()) { 
//#else
//      if(abs(rad - LastRayon) >= Precision::Confusion()) { 
//#endif
          Sliding = Standard_False;
        }   
      }
      }
    }
  }


// On construit un gros profil qui va jusqu`a la boite englobante
// -> par tangence avec premier et dernier edge du Wire
// -> par normales aux faces d'appui : statistiquement meilleur
// On intersecte le tout pour trouver le profil final


// ---cas de glissement : construction de la face profil
  if(Sliding) {
#ifdef DEB
    if (trc) cout << " still Sliding" << endl;
#endif
    TopoDS_Face Prof;
    Standard_Boolean ProfileOK;
    ProfileOK = SlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,BndFace,CheckPnt,
                         FirstFace,LastFace,FirstVertex,LastVertex,
                         FirstEdge,LastEdge);

    if (!ProfileOK) {
#ifdef DEB
      cout << "Not computable" << endl;
      if (trc) cout << "Face profile not computable" << endl;
#endif
      myStatusError = BRepFeat_NoFaceProf;
      NotDone();
      return;
    }


// ---Propagation sur les faces du shape initial
// pour trouver les faces concernees par la nervure
    Standard_Boolean falseside = Standard_True;
    Sliding = Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
// Controle si on a ce qu`il faut pour avoir la matiere du bon cote
    if(falseside == Standard_False) {
#ifdef DEB
      cout << " Verify plane and wire orientation" << endl;
#endif
      myStatusError = BRepFeat_FalseSide;
      NotDone();
      return;
    }
  }


// ---Generation du profile de base de la nervure

  TopoDS_Wire w;
  BB.MakeWire(w);
  TopoDS_Edge thePreviousEdge;
  TopoDS_Vertex theFV;
  thePreviousEdge.Nullify();

// compteur du nombre d`edges pour remplir la map
  Standard_Integer counter = 1;

// ---cas de glissement
  if(Sliding && !myListOfEdges.IsEmpty()) {
    BRepTools_WireExplorer EX1(myWire);
    for(; EX1.More(); EX1.Next()) {
      const TopoDS_Edge& E = EX1.Current();
      if(!myLFMap.IsBound(E)) {
        TopTools_ListOfShape theTmpList;
      myLFMap.Bind(E, theTmpList);
      }      
      if(E.IsSame(FirstEdge)) {
      Standard_Real f, l;
      Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
      gp_Pnt pt;
      if(!FirstEdge.IsSame(LastEdge)) {
        pt = BRep_Tool::Pnt(TopExp::LastVertex(E,Standard_True)); 
      }
      else {
        pt = myLastPnt;
        Standard_Real fpar = IntPar(cc, myFirstPnt);
        Standard_Real lpar = IntPar(cc, pt);
        Handle(Geom_Curve) ccc;
        if(fpar > lpar) {
          ccc = Handle(Geom_Curve)::DownCast(cc->Reversed());
          cc = ccc;
        }
      }
      TopoDS_Edge ee1;
      if(thePreviousEdge.IsNull()) {
        BRepLib_MakeVertex v1(myFirstPnt);
        BRepLib_MakeVertex v2(pt);    
        BRepLib_MakeEdge e(cc, v1, v2);
        ee1 = TopoDS::Edge(e.Shape());
      } 
      else {
        const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
        BRepLib_MakeVertex v2(pt);
        
        BRepLib_MakeEdge e(cc, v1, v2);
        ee1 = TopoDS::Edge(e.Shape());
      }
      TopoDS_Shape aLocalShape = ee1.Oriented(E.Orientation());
      ee1 = TopoDS::Edge(aLocalShape);
//    ee1 = TopoDS::Edge(ee1.Oriented(E.Orientation()));
      if(counter == 1) theFV = TopExp::FirstVertex(ee1,Standard_True);
      myLFMap(E).Append(ee1);
      BB.Add(w, ee1);
      thePreviousEdge = ee1;
      counter++;
      EX1.Next();
      break;
      }
    }

// Cas plusieurs edges
    if(!FirstEdge.IsSame(LastEdge)) {
      for(; EX1.More(); EX1.Next()) {
      const TopoDS_Edge& E = EX1.Current();
      if(!myLFMap.IsBound(E)) {
          TopTools_ListOfShape thelist1;
        myLFMap.Bind(E, thelist1);
      }      
      theList.Append(E);
      Standard_Real f, l;
      if(!E.IsSame(LastEdge)) {
        Handle(Geom_Curve) ccc = BRep_Tool::Curve(E, f, l);
        TopoDS_Vertex v1, v2;
        if(!thePreviousEdge.IsNull()) {
          v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
          v2 = TopExp::LastVertex(E,Standard_True);
        }
        else {
//        v1 = TopExp::LastVertex(E,Standard_True);
          v1 = TopExp::FirstVertex(E,Standard_True);
          v2 = TopExp::LastVertex(E,Standard_True);
        }
        BRepLib_MakeEdge E1(ccc, v1, v2);
        TopoDS_Edge E11 = TopoDS::Edge(E1.Shape());
        TopoDS_Shape aLocalShape = E11.Oriented(E.Orientation());
        E11 = TopoDS::Edge(aLocalShape);
//      E11 = TopoDS::Edge(E11.Oriented(E.Orientation()));
        thePreviousEdge = E11;
        myLFMap(E).Append(E11);
        BB.Add(w, E11);
        if(counter == 1) theFV = TopExp::FirstVertex(E11,Standard_True);
        counter++;
      }
      else {
        Standard_Real f, l;
        Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
        gp_Pnt pf = BRep_Tool::Pnt(TopExp::FirstVertex(E,Standard_True));
        gp_Pnt pl = myLastPnt;
        TopoDS_Edge ee;
        if(thePreviousEdge.IsNull()) {
          BRepLib_MakeEdge e(cc, pf , pl); 
          ee = TopoDS::Edge(e.Shape());
        }
        else {
          const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
          BRepLib_MakeVertex v2(pl);
          BRepLib_MakeEdge e(cc, v1, v2);
          ee = TopoDS::Edge(e.Shape());
        }
        TopoDS_Shape aLocalShape = ee.Oriented(E.Orientation());
        ee = TopoDS::Edge(aLocalShape);
//      ee = TopoDS::Edge(ee.Oriented(E.Orientation()));
        BB.Add(w, ee);
        myLFMap(E).Append(ee);
        if(counter == 1) theFV = TopExp::FirstVertex(ee,Standard_True);
        thePreviousEdge = ee;
        counter++;
        break;
      }
      }
    }
    
    TopTools_ListIteratorOfListOfShape it(myListOfEdges);
    Standard_Boolean FirstOK = Standard_False;
    Standard_Boolean LastOK = Standard_False;
    
    gp_Pnt theLastPnt = myLastPnt;
    Standard_Integer sens = 0;
    TopoDS_Edge theEdge, theLEdge, theFEdge;
    Standard_Integer counter1 = counter;
    TopTools_ListOfShape NewListOfEdges;
    NewListOfEdges.Clear();
    while (!FirstOK) {
      const TopoDS_Edge& edg = TopoDS::Edge(it.Value());
      gp_Pnt fp, lp;
      Standard_Real f, l;
      Handle(Geom_Curve) ccc = BRep_Tool::Curve(edg, f, l);
      Handle(Geom_TrimmedCurve) cc = new Geom_TrimmedCurve(ccc, f, l);
      if ( edg.Orientation() == TopAbs_REVERSED) cc->Reverse();
      
      fp = cc->Value(cc->FirstParameter());
      lp = cc->Value(cc->LastParameter());
      Standard_Real dist = fp.Distance(theLastPnt);
      if(dist <= myTol) {
      sens = 1;
      LastOK = Standard_True;
      }
      else {
      dist = lp.Distance(theLastPnt);
      if(dist <= myTol) {
        sens = 2;
        LastOK = Standard_True;
        cc->Reverse();
      }
      }
      Standard_Integer FirstFlag = 0;
      if(sens==1 && lp.Distance(myFirstPnt) <= myTol) {
      FirstOK = Standard_True;
      FirstFlag = 1;
      }
      else if(sens==2 && fp.Distance(myFirstPnt) <= myTol) {
      FirstOK = Standard_True;
      FirstFlag = 2;
      }
      
      if (LastOK) {
      TopoDS_Edge eeee;
      Standard_Real fpar = cc->FirstParameter();
      Standard_Real lpar = cc->LastParameter();
      if(!FirstOK) {
        if(thePreviousEdge.IsNull()) {
          BRepLib_MakeEdge e(cc, fpar, lpar);
          eeee = TopoDS::Edge(e.Shape());
        }
        else {
          const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
          BRepLib_MakeVertex v2(cc->Value(lpar));
          BRepLib_MakeEdge e(cc, v1, v2);
          eeee = TopoDS::Edge(e.Shape());
        }
      }
      else {
        if(thePreviousEdge.IsNull()) {
          BRepLib_MakeVertex v1(cc->Value(fpar)); 
          BRepLib_MakeEdge e(cc, v1, theFV);
          eeee = TopoDS::Edge(e.Shape());
        }
        else {
          const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
          BRepLib_MakeEdge e(cc, v1, theFV);
          eeee = TopoDS::Edge(e.Shape());
        }
      }

      thePreviousEdge = eeee;
      BB.Add(w, eeee);
      if(counter == 1) theFV = TopExp::FirstVertex(eeee,Standard_True);
      counter1++;
      NewListOfEdges.Append(edg);
      theEdge = eeee;
#ifdef DEB
      Standard_Real dist1 = 
#endif
        theLastPnt.Distance(myLastPnt);
      if(dist <= myTol) 
        theFEdge = edg;
      theLastPnt = BRep_Tool::Pnt(TopExp::LastVertex(theEdge,Standard_True));
      }

      if(FirstFlag == 1) {
      theLEdge = edg;
      }
      else if(FirstFlag == 2) {
      theLEdge = theEdge;
      }

      if(LastOK) {
      it.Initialize(myListOfEdges);
      LastOK = Standard_False;
      }
      else if(it.More()) it.Next();
      else {
      Sliding = Standard_False;
      break;
      }     
      sens = 0;
    }
    
    
    TopTools_DataMapOfShapeListOfShape SlidMap;
    SlidMap.Clear();
    
    if(Sliding && counter1 > counter) {
      TopTools_ListIteratorOfListOfShape it;
      TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm;
      TopExp_Explorer EX2(w, TopAbs_EDGE);
      Standard_Integer ii = 0;
      for(; EX2.More(); EX2.Next()) {
      const TopoDS_Edge& E = TopoDS::Edge(EX2.Current());
      ii++; 
      if(ii >= counter && ii <= counter1) {
        it.Initialize(NewListOfEdges);
        Standard_Integer jj = 0;
        for(; it.More(); it.Next()) {
          const TopoDS_Edge& e2 = TopoDS::Edge(it.Value());
          jj++;
          if(jj== (ii - counter +1)) {      
            itm.Initialize(mySlface);
            for(; itm.More(); itm.Next()) {
            const TopoDS_Face& fac = TopoDS::Face(itm.Key());
            const TopTools_ListOfShape& ledg = itm.Value();
            TopTools_ListIteratorOfListOfShape itedg(ledg);
            //Standard_Integer iiii = 0;
            for(; itedg.More(); itedg.Next()) {
              const TopoDS_Edge& e1 = TopoDS::Edge(itedg.Value());
              if(e1.IsSame(e2)){
                if(!SlidMap.IsBound(fac)) {
                      TopTools_ListOfShape thelist2;
                  SlidMap.Bind(fac, thelist2);
                }
                SlidMap(fac).Append(E);
              }
            }           
            }
          }
        } 
      }
      }
    }
    
    mySlface.Clear();
    mySlface = SlidMap;
  }

// ---Arguments de LocOpe_LinearForm : arguments du prism
// glissement
  if(Sliding) {
    TopoDS_Face F;
    BB.MakeFace(F, myPln, myTol);
    BB.Add(F, w);
    mySkface = F;
    myPbase  = mySkface;
    mySUntil.Nullify();
  }


// ---Cas sans glissement : construction de la face profil  
  if(!Sliding) {
#ifdef DEB
    if (trc) {
      if (Modify) cout << " Sliding failure" << endl;
      cout << " no Sliding" << endl;
    }
#endif
    TopExp_Explorer explo1(BndFace, TopAbs_WIRE);
    TopoDS_Wire WWW = TopoDS::Wire(explo1.Current());
    BRepTools_WireExplorer explo(WWW);
    BRep_Builder Bu;
    TopoDS_Wire Wiwiwi;
    Bu.MakeWire(Wiwiwi);
    TopoDS_Vertex NewV1, NewV2, LastV, v; 
    NewV1.Nullify(); NewV2.Nullify(); LastV.Nullify();

    for(; explo.More(); explo.Next()) {
      const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
      TopoDS_Vertex v1 = TopExp::FirstVertex(e,Standard_True);
      TopoDS_Vertex v2 = TopExp::LastVertex(e,Standard_True);
            
      Standard_Real f, l;//, t;
      Handle(Geom_Curve) ln = BRep_Tool::Curve(e, f, l);
//      Handle(Geom_Curve) lln = BRep_Tool::Curve(e, f, l);
//      Handle(Geom_Curve) ln;
//      if(e.Orientation() == TopAbs_REVERSED) {
//    ln = Handle(Geom_Curve)::DownCast(lln->Reversed());
//    v = v1; v1 = v2; v2= v;
//    f = IntPar(ln, BRep_Tool::Pnt(v1));
//    l = IntPar(ln, BRep_Tool::Pnt(v2));
//      }
//      else ln = lln;

      Handle(Geom2d_Curve) l2d = GeomAPI::To2d(ln, Plane->Pln());
      Geom2dAPI_InterCurveCurve intcc(l2d, ln2d, Precision::Confusion());
      TopoDS_Vertex VV; VV.Nullify();
      TopoDS_Edge ee1, ee2;

      if(intcc.NbPoints() > 0) {
      gp_Pnt2d P = intcc.Point(1);
      gp_Pnt point;
      myPln->D0(P.X(), P.Y(), point);
      Standard_Real par = IntPar(ln, point);
      if(f <= par && l >= par) {
        Bu.MakeVertex(VV, point, Precision::Confusion());
      }
      }
      
      if(VV.IsNull() && NewV1.IsNull()) continue;

      if(!VV.IsNull() && NewV1.IsNull()) {
      NewV1 = VV;
      LastV = v2;
      BRepLib_MakeEdge ee1(NewV1, LastV);
      Bu.Add(Wiwiwi, ee1); 
      continue;
      } 

      if(VV.IsNull() && !NewV1.IsNull()) {
      BRepLib_MakeEdge ee1(LastV, v2);
      LastV = v2;
      Bu.Add(Wiwiwi, e); 
      continue;
      } 
      
      if(!VV.IsNull() && !NewV1.IsNull()) {
      NewV2 = VV;
      BRepLib_MakeEdge ee1(LastV, NewV2);
      LastV = NewV2;
      Bu.Add(Wiwiwi, ee1); 
      BRepLib_MakeEdge ee2(LastV, NewV1);
      Bu.Add(Wiwiwi, ee2);
      break;
      } 
    }
    
    BRepLib_MakeFace newbndface(myPln->Pln(), Wiwiwi, Standard_True);
    TopoDS_Face NewBndFace = TopoDS::Face(newbndface.Shape());

    BRepTopAdaptor_FClass2d Cl(NewBndFace, Precision::Confusion());
    Standard_Real paru, parv;
    ElSLib::Parameters(myPln->Pln(), CheckPnt, paru, parv);
    gp_Pnt2d checkpnt2d(paru, parv);
    if(Cl.Perform(checkpnt2d, Standard_True) == TopAbs_OUT) {
      //modified by NIZNHY-PKV Fri Mar 22 16:52:52 2002 f
      //BRepAlgo_Cut c(BndFace, NewBndFace);     
      BRepAlgoAPI_Cut c(BndFace, NewBndFace);     
      //modified by NIZNHY-PKV Fri Mar 22 16:52:57 2002 t
      TopExp_Explorer exp(c.Shape(), TopAbs_WIRE);
      const TopoDS_Wire& w = TopoDS::Wire(exp.Current());
      // akm 13/02/02 : we know the plane. Why not to use it?
      // BRepLib_MakeFace ff(w);
      BRepLib_MakeFace ff(myPln->Pln(), w, Standard_True);
      NewBndFace = TopoDS::Face(ff.Shape());
    }
   
    
    if(!BRepAlgo::IsValid(NewBndFace)) {
#ifdef DEB
      cout << "Invalid new bounding face" << endl;
#endif
      myStatusError = BRepFeat_InvShape;
      NotDone();
      return;      
    }
    
    BndFace = NewBndFace;


    TopoDS_Face Prof;
    Standard_Boolean ProfileOK;
    ProfileOK = NoSlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,
                         bnd,BndFace,CheckPnt,
                         FirstFace,LastFace,FirstVertex,LastVertex,
                         FirstEdge,LastEdge,OnFirstFace,OnLastFace);

    if (!ProfileOK) {
#ifdef DEB
      cout << "Not computable" << endl;
      if (trc) cout << " Face profile not computable" << endl;
#endif
      myStatusError = BRepFeat_NoFaceProf;
      NotDone();
      return;
    }


// ---Propagation sur les faces du shape initial
// pour trouver les faces concernees par la nervure
    Standard_Boolean falseside = Standard_True;
    Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
// Controle si on a ce qu`il faut pour avoir la matiere du bon cote
    if(falseside == Standard_False) {
#ifdef DEB
      cout << " Verify plane and wire orientation" << endl;
#endif
      myStatusError = BRepFeat_FalseSide;
      NotDone();
      return;
    }
    
    mySlface.Clear();

    TopTools_ListIteratorOfListOfShape it;
    it.Initialize(SliList);
    
    TopoDS_Shape comp;
    
    BRep_Builder BB;
    BB.MakeShell(TopoDS::Shell(comp));
    
    for(; it.More(); it.Next()) {
      BB.Add(comp, it.Value());
    }
    
    mySUntil = comp;
   
    mySkface = Prof;
    myPbase  = Prof;
  }

  mySliding = Sliding;

  TopExp_Explorer exp;
  for ( exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
    TopTools_ListOfShape thelist3;
    myMap.Bind(exp.Current(), thelist3);
    myMap(exp.Current()).Append(exp.Current());
  }
}


Generated by  Doxygen 1.6.0   Back to index