summaryrefslogtreecommitdiff
path: root/src/TopOpeBRepBuild/TopOpeBRepBuild_BuildEdges.cxx
blob: 8dd3ec00cb9fe9747bf275fe47af70e72cccf4a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// File:	TopOpeBRepBuild_BuildEdges.cxx
// Created:	Mon Jun 14 11:48:36 1993
// Author:	Jean Yves LEBEY
//		<jyl@zerox>

#include <TopOpeBRepBuild_Builder.jxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <TopOpeBRepDS_CurveExplorer.hxx>
#include <TopOpeBRepDS_Curve.hxx>
#include <TopoDS.hxx>
#include <TopOpeBRepBuild_define.hxx>

#ifdef DEB
Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceCU();
#endif

//=======================================================================
//function : BuildEdges
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_Builder::BuildEdges(const Standard_Integer iC,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
{
#ifdef DEB
  if (TopOpeBRepBuild_GettraceCU()) cout<<"\nBuildEdges on C "<<iC<<endl;
#endif
  const TopOpeBRepDS_Curve& C = HDS->Curve(iC);
  const Handle(Geom_Curve)& C3D = C.Curve(); 
  const Handle(TopOpeBRepDS_Interference)& I1 = C.GetSCI1();
  const Handle(TopOpeBRepDS_Interference)& I2 = C.GetSCI2();
  Standard_Boolean nnn = C3D.IsNull() && I1.IsNull() && I2.IsNull();
  if (nnn) {
    return;
  }
  
  TopoDS_Shape anEdge;
  const TopOpeBRepDS_Curve& curC = HDS->Curve(iC);
  myBuildTool.MakeEdge(anEdge,curC,HDS->DS());
  TopOpeBRepBuild_PaveSet PVS(anEdge);
  TopOpeBRepDS_PointIterator CPIT(HDS->CurvePoints(iC));
  FillVertexSet(CPIT,TopAbs_IN,PVS);
  TopOpeBRepBuild_PaveClassifier VCL(anEdge);
  Standard_Boolean equalpar = PVS.HasEqualParameters();
  if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
  Standard_Boolean closvert = PVS.ClosedVertices();
  VCL.ClosedVertices(closvert);  
  PVS.InitLoop();
  if ( !PVS.MoreLoop() ) {
    return;
  }
  TopOpeBRepBuild_EdgeBuilder EDBU(PVS,VCL);
  TopTools_ListOfShape& EL = ChangeNewEdges(iC);
  MakeEdges(anEdge,EDBU,EL);
  TopTools_ListIteratorOfListOfShape It(EL);
  Standard_Integer inewC = -1;
  for (; It.More(); It.Next()) {
    TopoDS_Edge& newEdge = TopoDS::Edge(It.Value());
    myBuildTool.RecomputeCurves(curC,TopoDS::Edge(anEdge),newEdge,inewC,HDS);
    if (inewC != -1) ChangeNewEdges(inewC).Append(newEdge);
  }
  if (inewC != -1) {
    HDS->RemoveCurve(iC);
  }
  else {
    for (It.Initialize(EL);It.More();It.Next()) {
      TopoDS_Edge& newEdge = TopoDS::Edge(It.Value());
      myBuildTool.UpdateEdge(anEdge,newEdge);
    }
  }
}

//=======================================================================
//function : BuildEdges
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_Builder::BuildEdges(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
{
  TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();

  myNewEdges.Clear();
  TopOpeBRepDS_CurveExplorer cex;

  Standard_Integer ick = 0;
  for (cex.Init(BDS,Standard_False); cex.More(); cex.Next()) {
    Standard_Integer ic = cex.Index();
    Standard_Boolean ck = cex.IsCurveKeep(ic);
    Standard_Integer im = cex.Curve(ic).Mother();
    if (ck == 1 && im != 0 && ick == 0) { ick = ic; break; }
  }
  if (ick) {
    for (cex.Init(BDS,Standard_True); cex.More(); cex.Next()) {
      Standard_Integer ic = cex.Index();
      BDS.RemoveCurve(ic);
    }
    BDS.ChangeNbCurves(ick-1);
  }

  for (cex.Init(BDS,Standard_False); cex.More(); cex.Next()) {
    Standard_Integer ic = cex.Index();
    Standard_Integer im = cex.Curve(ic).Mother();
    if (im != 0 ) continue;
    BuildEdges(ic,HDS);
  }

  Standard_Integer ip, np = HDS->NbPoints();
  TColStd_HArray1OfInteger tp(0,np,0);
  for (cex.Init(BDS); cex.More(); cex.Next()) {
#ifdef DEB
//    const TopOpeBRepDS_Curve& C = cex.Curve();
#endif
    Standard_Integer ic = cex.Index();
    TopOpeBRepDS_ListIteratorOfListOfInterference it(BDS.CurveInterferences(ic));
    for(;it.More();it.Next()) {
      const Handle(TopOpeBRepDS_Interference)& I = it.Value();
      {
        Standard_Integer ig = I->Geometry();
        TopOpeBRepDS_Kind kg = I->GeometryType();
        if (kg == TopOpeBRepDS_POINT && ig <= np) tp.ChangeValue(ig) = tp.Value(ig) + 1;
      }
      {
        Standard_Integer is = I->Support();
        TopOpeBRepDS_Kind ks = I->SupportType();
        if (ks == TopOpeBRepDS_POINT) tp.ChangeValue(is) = tp.Value(is) + 1;
      }
    }
  }
  Standard_Integer is, ns = BDS.NbShapes();
  for (is = 1; is <= ns; is++ ) {
    const TopoDS_Shape& S = BDS.Shape(is);
    if(S.IsNull()) continue;
    Standard_Boolean test = (S.ShapeType() == TopAbs_EDGE); 
    if ( !test ) continue;
    TopOpeBRepDS_ListIteratorOfListOfInterference it(BDS.ShapeInterferences(is));
    for(;it.More();it.Next()) {
      const Handle(TopOpeBRepDS_Interference)& I = it.Value(); 
      {
        Standard_Integer ig = I->Geometry();
        TopOpeBRepDS_Kind kg = I->GeometryType();
        if (kg == TopOpeBRepDS_POINT) tp.ChangeValue(ig) = tp.Value(ig) + 1;
      }
      {
        Standard_Integer is1 = I->Support();
        TopOpeBRepDS_Kind ks = I->SupportType();
       if (ks == TopOpeBRepDS_POINT) tp.ChangeValue(is1) = tp.Value(is1) + 1;
      }
    }
  }
  for (ip = 1; ip <= np; ip++) if (tp.Value(ip) == 0) BDS.RemovePoint(ip);
}