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.
16 #include <QANewBRepNaming_Limitation.ixx>
17 #include <TopTools_ListIteratorOfListOfShape.hxx>
18 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
19 #include <TopTools_IndexedMapOfShape.hxx>
20 #include <BRep_Tool.hxx>
22 #include <TopoDS_Iterator.hxx>
24 #include <TopExp_Explorer.hxx>
27 #include <TDataStd_Name.hxx>
28 #include <TNaming_Builder.hxx>
29 #include <TNaming_NamedShape.hxx>
30 #include <QANewBRepNaming_Loader.hxx>
32 #include <QANewModTopOpe_ModeOfLimitation.hxx>
34 //=======================================================================
35 //function : QANewBRepNaming_Limitation
37 //=======================================================================
39 QANewBRepNaming_Limitation::QANewBRepNaming_Limitation() {}
41 //=======================================================================
42 //function : QANewBRepNaming_Limitation
44 //=======================================================================
46 QANewBRepNaming_Limitation::QANewBRepNaming_Limitation(const TDF_Label& ResultLabel)
47 :QANewBRepNaming_BooleanOperationFeat(ResultLabel) {}
49 //=======================================================================
52 //=======================================================================
54 void QANewBRepNaming_Limitation::Load(QANewModTopOpe_Limitation& MS) const {
55 TopoDS_Shape ResSh = MS.Shape();
57 const TopoDS_Shape& ObjSh = MS.Shape1();
58 const TopAbs_ShapeEnum& ObjType = ShapeType(ObjSh);
62 cout<<"QANewBRepNaming_Limitation::Load(): The result of the boolean operation is null"<<endl;
67 if (MS.Shape().ShapeType() == TopAbs_COMPOUND) {
68 Standard_Integer nbSubResults = 0;
69 TopoDS_Iterator itr(MS.Shape());
70 for (; itr.More(); itr.Next()) nbSubResults++;
71 if (nbSubResults == 1) {
72 itr.Initialize(MS.Shape());
73 if (itr.More()) ResSh = itr.Value();
76 if(MS.Shape1().IsSame(ResSh)) {
77 // If the shapes are the same - select the result and exit:
79 cout<<"QANewBRepNaming_Limitation::Load(): The object and the result of LIMITATION operation are the same"<<endl;
81 TNaming_Builder aBuilder(ResultLabel());
82 aBuilder.Select(ResSh, ObjSh);
85 // Naming of the result:
88 // Naming of the content:
89 // if (ResSh.ShapeType() == TopAbs_COMPOUND) {
95 // Naming of modified, deleted and new sub shapes:
96 if (ObjType == TopAbs_WIRE || ObjType == TopAbs_EDGE) {
98 TNaming_Builder ModBuilder(ModifiedEdges());
99 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_EDGE, ModBuilder, Standard_False);
100 if(MS.HasGenerated()) {
101 TNaming_Builder nBuilder (NewShapes());
102 // generated Vertexes
103 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_EDGE, nBuilder);
104 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder);
105 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_EDGE, nBuilder);
108 TNaming_Builder DelEBuilder(DeletedEdges());
109 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_EDGE, DelEBuilder);
110 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_EDGE, DelEBuilder);
111 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_VERTEX, DelEBuilder);
112 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_VERTEX, DelEBuilder);
115 else if (ObjType == TopAbs_SHELL || ObjType == TopAbs_FACE) {
117 TNaming_Builder ModBuilder(ModifiedFaces());
118 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_FACE, ModBuilder, Standard_False);
119 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_EDGE, ModBuilder, Standard_False);
121 if(MS.HasGenerated()) {
122 TNaming_Builder nBuilder (NewShapes());
123 // generated free Edges
124 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_FACE, nBuilder);
125 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder);
126 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_EDGE, nBuilder);
129 TNaming_Builder DelEBuilder(DeletedFaces());
130 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelEBuilder);
131 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelEBuilder);
132 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_EDGE, DelEBuilder); //free bound.
133 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_EDGE, DelEBuilder);
136 else if(ObjType == TopAbs_SOLID) {
137 TNaming_Builder ModBuilder(ModifiedFaces());
138 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_FACE, ModBuilder, Standard_False);
139 QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape2(), TopAbs_FACE, ModBuilder, Standard_False);
142 TNaming_Builder DelEBuilder(DeletedFaces());
143 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelEBuilder);
144 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelEBuilder);
152 //=======================================================================
153 //function : LoadResult
155 //=======================================================================
157 void QANewBRepNaming_Limitation::LoadResult(QANewModTopOpe_Limitation& MS) const {
158 Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel());
159 if (Tagger.IsNull()) return;
161 TNaming_Builder Builder (ResultLabel());
162 TopoDS_Shape aResult = MS.Shape();
163 if (aResult.ShapeType() == TopAbs_COMPOUND) {
164 Standard_Integer nbSubResults = 0;
165 TopoDS_Iterator itr(aResult);
166 for (; itr.More(); itr.Next()) nbSubResults++;
167 if (nbSubResults == 1) {
168 itr.Initialize(aResult);
169 if (itr.More()) aResult = itr.Value();
172 if (MS.Shape1().IsNull()) Builder.Generated(aResult);
173 else Builder.Modify(MS.Shape1(), aResult);
176 //=======================================================================
177 //function : LoadDegenerated
179 //=======================================================================
181 void QANewBRepNaming_Limitation::LoadDegenerated(QANewModTopOpe_Limitation& MS) const {
182 TopTools_IndexedMapOfShape allEdges;
183 TopExp::MapShapes(MS.Shape1(), TopAbs_EDGE, allEdges);
184 Standard_Integer i = 1;
185 for (; i <= allEdges.Extent(); i++) {
186 if (BRep_Tool::Degenerated(TopoDS::Edge(allEdges.FindKey(i)))) {
187 if (MS.IsDeleted(allEdges.FindKey(i))) {
188 TNaming_Builder DegeneratedBuilder(DeletedDegeneratedEdges());
189 DegeneratedBuilder.Generated(allEdges.FindKey(i));
191 TDataStd_Name::Set(DegeneratedBuilder.NamedShape()->Label(), "DeletedDegenerated");
197 //=======================================================================
198 //function : LoadContent
200 //=======================================================================
202 void QANewBRepNaming_Limitation::LoadContent(QANewModTopOpe_Limitation& MS) const {
203 if (MS.Shape().ShapeType() == TopAbs_COMPSOLID || MS.Shape().ShapeType() == TopAbs_COMPOUND) {
204 TopoDS_Iterator itr(MS.Shape());
205 Standard_Integer nbShapes = 0;
211 for (itr.Initialize(MS.Shape()); itr.More(); itr.Next()) {
212 TNaming_Builder bContent(Content());
213 bContent.Generated(MS.Shape1(),itr.Value());
214 bContent.Generated(MS.Shape2(),itr.Value());