0025656: Specification of semantic of Closed flag of an edge
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_makeedges.cxx
CommitLineData
b311480e 1// Created on: 1996-03-07
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TopOpeBRepBuild_Builder.ixx>
18
19#include <TopExp.hxx>
20#include <TopoDS.hxx>
21#include <BRep_Tool.hxx>
22#include <TopOpeBRepTool_TOOL.hxx>
23#include <TopOpeBRepDS_EXPORT.hxx>
24#include <TopOpeBRepBuild_define.hxx>
25
0797d9d3 26#ifdef OCCT_DEBUG
1d0a9d4d 27extern void debfillp(const Standard_Integer i);
28extern void debedbu(const Standard_Integer i) {cout<<"++ debedbu "<<i<<endl;}
7fd59977 29#endif
30
31#ifdef DRAW
32#include <TopOpeBRepTool_DRAW.hxx>
33#endif
34
35//=======================================================================
36//function : GPVSMakeEdges
37//purpose :
38//=======================================================================
39void TopOpeBRepBuild_Builder::GPVSMakeEdges
40(const TopoDS_Shape& EF,TopOpeBRepBuild_PaveSet& PVS,TopTools_ListOfShape& LOE) const
41{
0797d9d3 42#ifdef OCCT_DEBUG
7fd59977 43 Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EF,iE);
44 if (tSPS) debfillp(iE);
45#endif
46
47 TopOpeBRepBuild_PaveClassifier VCL(EF);
48 Standard_Boolean equalpar = PVS.HasEqualParameters();
49 if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
50
51 PVS.InitLoop();
52 Standard_Boolean novertex = ( ! PVS.MoreLoop() );
0797d9d3 53#ifdef OCCT_DEBUG
7fd59977 54 if(tSPS&&novertex)cout<<"#--- GPVSMakeEdges : no vertex from edge "<<iE<<endl;
55#endif
56 if (novertex) return;
57
58 TopOpeBRepBuild_EdgeBuilder EDBU;
59 Standard_Boolean ForceClass = Standard_False;
60 EDBU.InitEdgeBuilder(PVS,VCL,ForceClass);
61 GEDBUMakeEdges(EF,EDBU,LOE);
62
63} // GPVSMakeEdges
64
65//=======================================================================
66//function : GEDBUMakeEdges
67//purpose :
68//=======================================================================
69void TopOpeBRepBuild_Builder::GEDBUMakeEdges
70(const TopoDS_Shape& EF,TopOpeBRepBuild_EdgeBuilder& EDBU,TopTools_ListOfShape& LOE) const
71{
0797d9d3 72#ifdef OCCT_DEBUG
7fd59977 73 Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EF,iE);
74 if(tSPS){cout<<endl;GdumpSHA(EF, (char *) "#--- GEDBUMakeEdges ");cout<<endl;}
75 if(tSPS){GdumpEDBU(EDBU);}
76 if(tSPS){debedbu(iE);}
77#endif
78
79 TopoDS_Shape newEdge;
80 for (EDBU.InitEdge(); EDBU.MoreEdge(); EDBU.NextEdge()) {
81
82 Standard_Integer nloop = 0;
83 Standard_Boolean tosplit = Standard_False;
84 for (EDBU.InitVertex(); EDBU.MoreVertex(); EDBU.NextVertex()) nloop++;
85 // 0 ou 1 vertex sur edge courante => suppression edge
86 if ( nloop <= 1 ) continue;
87
88 myBuildTool.CopyEdge(EF,newEdge);
89
90 Standard_Integer nVF = 0, nVR = 0; // nb vertex FORWARD,REVERSED
91
92 TopoDS_Shape VF,VR; // gestion du bit Closed
93 VF.Nullify();
94 VR.Nullify();
95
96 for (EDBU.InitVertex(); EDBU.MoreVertex(); EDBU.NextVertex()) {
97 TopoDS_Shape V = EDBU.Vertex();
98 TopAbs_Orientation Vori = V.Orientation();
99
100 Standard_Boolean hassd = myDataStructure->HasSameDomain(V);
101 if (hassd) { // on prend le vertex reference de V
102 Standard_Integer iref = myDataStructure->SameDomainReference(V);
103 V = myDataStructure->Shape(iref);
104 V.Orientation(Vori);
105 }
106
107 TopAbs_Orientation oriV = V.Orientation();
108 if ( oriV == TopAbs_EXTERNAL ) continue;
109
110 Standard_Boolean equafound = Standard_False;
111 TopExp_Explorer exE(newEdge,TopAbs_VERTEX);
112 for (; exE.More(); exE.Next() ) {
113 const TopoDS_Shape& VE = exE.Current();
114 TopAbs_Orientation oriVE = VE.Orientation();
115
116 if ( V.IsEqual(VE) ) {
117 equafound = Standard_True;
118 break;
119 }
120 else if (oriVE == TopAbs_FORWARD || oriVE == TopAbs_REVERSED) {
121 if (oriV == oriVE) {
122 equafound = Standard_True;
123 break;
124 }
125 }
126 else if (oriVE == TopAbs_INTERNAL || oriVE == TopAbs_EXTERNAL) {
127 Standard_Real parV = EDBU.Parameter();
128 Standard_Real parVE = BRep_Tool::Parameter(TopoDS::Vertex(VE),TopoDS::Edge(newEdge));
129 if ( parV == parVE ) {
130 equafound = Standard_True;
131 break;
132 }
133 }
134 }
135 if ( !equafound ) {
136 if (Vori == TopAbs_FORWARD) {
137 nVF++;
138 if (nVF == 1) VF = V;
139 }
140 if (Vori == TopAbs_REVERSED) {
141 nVR++;
142 if (nVR == 1) VR = V;
143 }
144 if (oriV == TopAbs_INTERNAL) tosplit = Standard_True;
145 Standard_Real parV = EDBU.Parameter();
146 myBuildTool.AddEdgeVertex(newEdge,V);
147 myBuildTool.Parameter(newEdge,V,parV);
148 } // !equafound
149
150 } // EDBUloop.InitVertex : on vertices of new edge newEdge
151
152 Standard_Boolean addedge = (nVF == 1 && nVR == 1);
7fd59977 153 if (addedge) {
154 if (tosplit) {
155 TopTools_ListOfShape loe; Standard_Boolean ok = TopOpeBRepTool_TOOL::SplitE(TopoDS::Edge(newEdge),loe);
156 if (!ok) tosplit = Standard_False;
157 else LOE.Append(loe);
158 }
159 if (!tosplit) LOE.Append(newEdge);
160 }
161 } // EDBU.InitEdge : loop on EDBU edges
162
163
164#ifdef DRAW
165 if(tSPS) {
166 TCollection_AsciiString str1; str1 = "e";
167 TCollection_AsciiString str2; str2 = iE;
168 FDRAW_DINLOE("",LOE,str1,str2);
169 }
170#endif
171
172} // GEDBUMakeEdges