0024890: Result of uniform scaling is invalid
[occt.git] / src / BRepBuilderAPI / BRepBuilderAPI_NurbsConvert.cxx
CommitLineData
b311480e 1// Created on: 1994-12-09
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1994-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
42cf5bc1 17
18#include <BRep_Builder.hxx>
19#include <BRepBuilderAPI_NurbsConvert.hxx>
7fd59977 20#include <BRepLib.hxx>
42cf5bc1 21#include <BRepTools_NurbsConvertModification.hxx>
7fd59977 22#include <TopAbs.hxx>
42cf5bc1 23#include <TopExp_Explorer.hxx>
7fd59977 24#include <TopoDS.hxx>
25#include <TopoDS_Edge.hxx>
42cf5bc1 26#include <TopoDS_Shape.hxx>
7fd59977 27#include <TopTools_MapOfShape.hxx>
7fd59977 28
42cf5bc1 29//#include <gp.hxx>
7fd59977 30//=======================================================================
31//function : BRepBuilderAPI_NurbsConvert
32//purpose :
33//=======================================================================
7fd59977 34BRepBuilderAPI_NurbsConvert::BRepBuilderAPI_NurbsConvert ()
35
36{
37 myModification = new BRepTools_NurbsConvertModification();
38}
39
40//=======================================================================
41//function : BRepBuilderAPI_NurbsConvert
42//purpose :
43//=======================================================================
44
45BRepBuilderAPI_NurbsConvert::BRepBuilderAPI_NurbsConvert (const TopoDS_Shape& S,
35e08fe8 46 const Standard_Boolean Copy)
7fd59977 47
48{
49 myModification = new BRepTools_NurbsConvertModification();
50 Perform(S,Copy);
51}
52
53//=======================================================================
54//function : Perform
55//purpose :
56//=======================================================================
57
58void BRepBuilderAPI_NurbsConvert::Perform(const TopoDS_Shape& S,
35e08fe8 59 const Standard_Boolean /*Copy*/)
7fd59977 60{
61 Handle(BRepTools_NurbsConvertModification) theModif =
62 Handle(BRepTools_NurbsConvertModification)::DownCast(myModification);
63 DoModif(S,myModification);
2651bfde 64 CorrectVertexTol();
7fd59977 65}
66
67
2651bfde 68//=======================================================================
69//function : CorrectVertexTol
70//purpose :
71//=======================================================================
72
73void BRepBuilderAPI_NurbsConvert::CorrectVertexTol()
74{
75 TopTools_MapOfShape anInitVertices;
76 TopExp_Explorer anExp(myInitialShape, TopAbs_VERTEX);
77 for(; anExp.More(); anExp.Next())
78 {
79 anInitVertices.Add(anExp.Current());
80 }
81 //
82 Handle(BRepTools_NurbsConvertModification) aModif =
83 Handle(BRepTools_NurbsConvertModification)::DownCast(myModification);
7fd59977 84
2651bfde 85 BRep_Builder aBB;
86 myVtxToReplace.Clear();
87 TopTools_ListIteratorOfListOfShape anEIter(aModif->GetUpdatedEdges());
88 for(; anEIter.More(); anEIter.Next())
89 {
90 const TopoDS_Shape& anE = anEIter.Value();
91 //
92 Standard_Real anETol = BRep_Tool::Tolerance(TopoDS::Edge(anE));
93 TopoDS_Iterator anIter(anE);
94 for(; anIter.More(); anIter.Next())
95 {
96 const TopoDS_Vertex& aVtx = TopoDS::Vertex(anIter.Value());
97 if(anInitVertices.Contains(aVtx))
98 {
99 if(myVtxToReplace.IsBound(aVtx))
100 {
101 aBB.UpdateVertex(TopoDS::Vertex(myVtxToReplace(aVtx)), anETol + Epsilon(anETol));
102 }
103 else
104 {
105 Standard_Real aVTol = BRep_Tool::Tolerance(aVtx);
106 if(aVTol < anETol)
107 {
108 TopoDS_Vertex aNewVtx;
109 gp_Pnt aVPnt = BRep_Tool::Pnt(aVtx);
110 aBB.MakeVertex(aNewVtx, aVPnt,anETol + Epsilon(anETol));
111 aNewVtx.Orientation(aVtx.Orientation());
112 myVtxToReplace.Bind(aVtx, aNewVtx);
113 }
114 }
115 }
116 else
117 {
118 aBB.UpdateVertex(aVtx, anETol + Epsilon(anETol));
119 }
120 }
121 }
122 //
123 if(myVtxToReplace.IsEmpty())
124 {
125 return;
126 }
127 //
128 mySubs.Clear();
129 TopTools_DataMapIteratorOfDataMapOfShapeShape anIter(myVtxToReplace);
130 for(; anIter.More(); anIter.Next())
131 {
132 mySubs.Replace(anIter.Key(), anIter.Value());
133 }
134 mySubs.Apply( myShape );
135 myShape = mySubs.Value(myShape);
136 //
137}
138
139//=======================================================================
140//function : ModifiedShape
141//purpose :
142//=======================================================================
143
144TopoDS_Shape BRepBuilderAPI_NurbsConvert::ModifiedShape
145 (const TopoDS_Shape& S) const
146{
147 if(S.ShapeType() == TopAbs_VERTEX)
148 {
149 if(myVtxToReplace.IsBound(S))
150 {
151 return myVtxToReplace(S);
152 }
153 }
154 if(myVtxToReplace.IsEmpty())
155 {
156 return myModifier.ModifiedShape(S);
157 }
158 else
159 {
160 const TopoDS_Shape& aNS = myModifier.ModifiedShape(S);
161 return mySubs.Value(aNS);
162 }
163}
164
165//=======================================================================
166//function : Modified
167//purpose :
168//=======================================================================
169
170const TopTools_ListOfShape& BRepBuilderAPI_NurbsConvert::Modified
171 (const TopoDS_Shape& F)
172{
173 myGenerated.Clear();
174 if(F.ShapeType() == TopAbs_VERTEX)
175 {
176 if(myVtxToReplace.IsBound(F))
177 {
178 myGenerated.Append(myVtxToReplace(F));
179 }
180 else
181 {
182 myGenerated.Append(myModifier.ModifiedShape(F));
183 }
184 }
185 else
186 {
187 if(myVtxToReplace.IsEmpty())
188 {
189 myGenerated.Append(myModifier.ModifiedShape(F));
190 }
191 else
192 {
193 const TopoDS_Shape& aNS = myModifier.ModifiedShape(F);
194 myGenerated.Append(mySubs.Value(aNS));
195 }
196 }
197 return myGenerated;
198}