1 // Created on: 2000-12-26
2 // Created by: Vladislav ROMASHKO <vro@nnov.matra-dtv.fr>
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Tool.hxx>
18 #include <QANewBRepNaming_Limitation.hxx>
19 #include <QANewBRepNaming_Loader.hxx>
20 #include <QANewModTopOpe_Limitation.hxx>
21 #include <QANewModTopOpe_ModeOfLimitation.hxx>
22 #include <TDataStd_Name.hxx>
23 #include <TDF_Label.hxx>
24 #include <TNaming_Builder.hxx>
25 #include <TNaming_NamedShape.hxx>
27 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Iterator.hxx>
30 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
31 #include <TopTools_IndexedMapOfShape.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
36 //=======================================================================
37 //function : QANewBRepNaming_Limitation
39 //=======================================================================
40 QANewBRepNaming_Limitation::QANewBRepNaming_Limitation() {}
42 //=======================================================================
43 //function : QANewBRepNaming_Limitation
45 //=======================================================================
47 QANewBRepNaming_Limitation::QANewBRepNaming_Limitation(const TDF_Label& ResultLabel)
48 :QANewBRepNaming_BooleanOperationFeat(ResultLabel) {}
50 //=======================================================================
53 //=======================================================================
55 void QANewBRepNaming_Limitation::Load(QANewModTopOpe_Limitation& MS) const {
56 TopoDS_Shape ResSh = MS.Shape();
58 const TopoDS_Shape& ObjSh = MS.Shape1();
59 const TopAbs_ShapeEnum& ObjType = ShapeType(ObjSh);
63 cout<<"QANewBRepNaming_Limitation::Load(): The result of the boolean operation is null"<<endl;
68 if (MS.Shape().ShapeType() == TopAbs_COMPOUND) {
69 Standard_Integer nbSubResults = 0;
70 TopoDS_Iterator itr(MS.Shape());
71 for (; itr.More(); itr.Next()) nbSubResults++;
72 if (nbSubResults == 1) {
73 itr.Initialize(MS.Shape());
74 if (itr.More()) ResSh = itr.Value();
77 if(MS.Shape1().IsSame(ResSh)) {
78 // If the shapes are the same - select the result and exit:
80 cout<<"QANewBRepNaming_Limitation::Load(): The object and the result of LIMITATION operation are the same"<<endl;
82 TNaming_Builder aBuilder(ResultLabel());
83 aBuilder.Select(ResSh, ObjSh);
86 // Naming of the result:
89 // Naming of the content:
90 // if (ResSh.ShapeType() == TopAbs_COMPOUND) {
96 // Naming of modified, deleted and new sub shapes:
97 if (ObjType == TopAbs_WIRE || ObjType == TopAbs_EDGE) {
99 TNaming_Builder ModBuilder(ModifiedEdges());
100 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_EDGE, ModBuilder, Standard_False);
101 if(MS.HasGenerated()) {
102 TNaming_Builder nBuilder (NewShapes());
103 // generated Vertexes
104 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_EDGE, nBuilder);
105 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder);
106 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_EDGE, nBuilder);
109 TNaming_Builder DelEBuilder(DeletedEdges());
110 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_EDGE, DelEBuilder);
111 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_EDGE, DelEBuilder);
112 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_VERTEX, DelEBuilder);
113 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_VERTEX, DelEBuilder);
116 else if (ObjType == TopAbs_SHELL || ObjType == TopAbs_FACE) {
118 TNaming_Builder ModBuilder(ModifiedFaces());
119 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_FACE, ModBuilder, Standard_False);
120 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_EDGE, ModBuilder, Standard_False);
122 if(MS.HasGenerated()) {
123 TNaming_Builder nBuilder (NewShapes());
124 // generated free Edges
125 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_FACE, nBuilder);
126 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder);
127 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_EDGE, nBuilder);
130 TNaming_Builder DelEBuilder(DeletedFaces());
131 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelEBuilder);
132 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelEBuilder);
133 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_EDGE, DelEBuilder); //free bound.
134 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_EDGE, DelEBuilder);
137 else if(ObjType == TopAbs_SOLID) {
138 TNaming_Builder ModBuilder(ModifiedFaces());
139 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_FACE, ModBuilder, Standard_False);
140 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape2(), TopAbs_FACE, ModBuilder, Standard_False);
143 TNaming_Builder DelEBuilder(DeletedFaces());
144 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelEBuilder);
145 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelEBuilder);
153 //=======================================================================
154 //function : LoadResult
156 //=======================================================================
158 void QANewBRepNaming_Limitation::LoadResult(QANewModTopOpe_Limitation& MS) const {
159 Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel());
160 if (Tagger.IsNull()) return;
162 TNaming_Builder Builder (ResultLabel());
163 TopoDS_Shape aResult = MS.Shape();
164 if (aResult.ShapeType() == TopAbs_COMPOUND) {
165 Standard_Integer nbSubResults = 0;
166 TopoDS_Iterator itr(aResult);
167 for (; itr.More(); itr.Next()) nbSubResults++;
168 if (nbSubResults == 1) {
169 itr.Initialize(aResult);
170 if (itr.More()) aResult = itr.Value();
173 if (MS.Shape1().IsNull()) Builder.Generated(aResult);
174 else Builder.Modify(MS.Shape1(), aResult);
177 //=======================================================================
178 //function : LoadDegenerated
180 //=======================================================================
182 void QANewBRepNaming_Limitation::LoadDegenerated(QANewModTopOpe_Limitation& MS) const {
183 TopTools_IndexedMapOfShape allEdges;
184 TopExp::MapShapes(MS.Shape1(), TopAbs_EDGE, allEdges);
185 Standard_Integer i = 1;
186 for (; i <= allEdges.Extent(); i++) {
187 if (BRep_Tool::Degenerated(TopoDS::Edge(allEdges.FindKey(i)))) {
188 if (MS.IsDeleted(allEdges.FindKey(i))) {
189 TNaming_Builder DegeneratedBuilder(DeletedDegeneratedEdges());
190 DegeneratedBuilder.Generated(allEdges.FindKey(i));
192 TDataStd_Name::Set(DegeneratedBuilder.NamedShape()->Label(), "DeletedDegenerated");
198 //=======================================================================
199 //function : LoadContent
201 //=======================================================================
203 void QANewBRepNaming_Limitation::LoadContent(QANewModTopOpe_Limitation& MS) const {
204 if (MS.Shape().ShapeType() == TopAbs_COMPSOLID || MS.Shape().ShapeType() == TopAbs_COMPOUND) {
205 TopoDS_Iterator itr(MS.Shape());
206 Standard_Integer nbShapes = 0;
212 for (itr.Initialize(MS.Shape()); itr.More(); itr.Next()) {
213 TNaming_Builder bContent(Content());
214 bContent.Generated(MS.Shape1(),itr.Value());
215 bContent.Generated(MS.Shape2(),itr.Value());