1 // Created on: 2000-10-31
2 // Created by: Sergey ZARITCHNY
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_Common.ixx>
17 #include <TNaming_Builder.hxx>
18 #include <QANewBRepNaming_Loader.hxx>
19 #include <TopExp_Explorer.hxx>
20 #include <TopTools_ListIteratorOfListOfShape.hxx>
21 #include <TNaming_Tool.hxx>
22 #include <TopoDS_Iterator.hxx>
23 #include <TNaming_NamedShape.hxx>
24 #include <TopoDS_Shell.hxx>
25 #include <BRep_Builder.hxx>
26 #include <TopTools_MapOfShape.hxx>
27 //=======================================================================
28 //function : QANewBRepNaming_Common
30 //=======================================================================
32 QANewBRepNaming_Common::QANewBRepNaming_Common() {}
34 //=======================================================================
35 //function : QANewBRepNaming_Common
37 //=======================================================================
39 QANewBRepNaming_Common::QANewBRepNaming_Common(const TDF_Label& ResultLabel)
40 :QANewBRepNaming_BooleanOperationFeat(ResultLabel) {}
42 //=======================================================================
45 //=======================================================================
47 void QANewBRepNaming_Common::Load(BRepAlgoAPI_BooleanOperation& MS) const {
48 TopoDS_Shape ResSh = MS.Shape();
51 cout<<"QANewBRepNaming_Common::Load(): The result of the Common is null"<<endl;
67 const TopAbs_ShapeEnum& ResType = ShapeType(ResSh);
68 const TopoDS_Shape& ObjSh = MS.Shape1();
69 const TopoDS_Shape& ToolSh = MS.Shape2();
71 // If the shapes are the same - select the result and exit:
72 if (IsResultChanged(MS)) {
74 cout<<"QANewBRepNaming_Common::Load(): The object and the result of COMMON operation are the same"<<endl;
76 if (ResType == TopAbs_COMPOUND) {
77 Standard_Integer nbSubResults = 0;
78 TopoDS_Iterator itr(MS.Shape());
79 for (; itr.More(); itr.Next()) nbSubResults++;
80 if (nbSubResults == 1) {
81 itr.Initialize(MS.Shape());
82 if (itr.More()) ResSh = itr.Value();
85 TNaming_Builder aBuilder(ResultLabel());
86 aBuilder.Select(ResSh, ObjSh);
87 aBuilder.Select(ResSh, ToolSh);
90 const TopAbs_ShapeEnum& anObjType = ShapeType(ObjSh);
91 const TopAbs_ShapeEnum& aToolType = ShapeType(ToolSh);
116 if(aToolType == TopAbs_SOLID)
118 else anArg = UNEXPECTED;
122 if(aToolType == TopAbs_SOLID)
124 else anArg = UNEXPECTED;
130 if( anArg == UNEXPECTED)
133 cout <<"QANewBRepNaming_Common:: Unexpected Use Case" << endl;
137 // Naming of the result:
140 // Naming of modified, deleted and new sub shapes:
141 if (anArg == SOLID_WIRE || anArg == WIRE_SOLID) { // Result => Wire/Edge
142 TopoDS_Shape aWire, aSolid;
143 if(anArg == WIRE_SOLID) {
144 aWire = ObjSh; aSolid = ToolSh;}
146 aWire = ToolSh; aSolid = ObjSh;}
148 TNaming_Builder ModEBuilder(ModifiedEdges());
149 QANewBRepNaming_Loader::LoadModifiedShapes(MS, aWire, TopAbs_EDGE, ModEBuilder, Standard_True);
151 if(MS.HasGenerated()) {
152 TNaming_Builder nBuilder (NewShapes());
153 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, aWire, TopAbs_EDGE, nBuilder);
154 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, aSolid, TopAbs_FACE, nBuilder);
155 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, aSolid, TopAbs_VERTEX, nBuilder);
157 //Deleted (Faces, Edges, Vertexes)
159 TNaming_Builder DelFBuilder(DeletedFaces()); // all deleted shapes
160 QANewBRepNaming_Loader::LoadDeletedShapes(MS, aSolid, TopAbs_FACE, DelFBuilder);
161 QANewBRepNaming_Loader::LoadDeletedShapes(MS, aWire, TopAbs_EDGE, DelFBuilder);
162 QANewBRepNaming_Loader::LoadDeletedShapes(MS, aWire, TopAbs_VERTEX, DelFBuilder);
165 else if (anArg == SOLID_SHELL || anArg == SHELL_SOLID) { //Result: Shell/Face
167 if(anArg == SHELL_SOLID)
172 TNaming_Builder ModFBuilder(ModifiedFaces());
173 QANewBRepNaming_Loader::LoadModifiedShapes(MS, aShell, TopAbs_FACE, ModFBuilder, Standard_True);
174 TNaming_Builder ModEBuilder(ModifiedEdges());
175 QANewBRepNaming_Loader::LoadModifiedShapes(MS, aShell, TopAbs_EDGE, ModEBuilder, Standard_True);
176 //Generated edges (edges of free boundaries)
177 if(MS.HasGenerated()) {
178 TNaming_Builder nBuilder (NewShapes());
179 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_FACE, nBuilder);
180 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder);
184 TNaming_Builder DelFBuilder(DeletedFaces());
185 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelFBuilder);
186 QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelFBuilder);
187 QANewBRepNaming_Loader::LoadDeletedShapes(MS, aShell, TopAbs_EDGE, DelFBuilder);
192 // cout <<"Solid case - modified = " << MS.HasModified()<< endl;
194 TNaming_Builder ModBuilder(ModifiedFaces());
195 QANewBRepNaming_Loader::LoadModifiedShapes (MS, ObjSh, TopAbs_FACE, ModBuilder, Standard_True);
196 QANewBRepNaming_Loader::LoadModifiedShapes (MS, ToolSh, TopAbs_FACE, ModBuilder, Standard_True);
197 if(MS.HasGenerated()) {
198 TNaming_Builder GenBuilder (NewShapes());
199 QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ToolSh, TopAbs_FACE, GenBuilder);
202 TNaming_Builder DelBuilder(DeletedFaces());
203 QANewBRepNaming_Loader::LoadDeletedShapes (MS, ObjSh, TopAbs_FACE, DelBuilder);
204 QANewBRepNaming_Loader::LoadDeletedShapes (MS, ToolSh, TopAbs_FACE, DelBuilder);
210 // Naming of the content:
211 if (ShapeType(ObjSh) == TopAbs_SOLID) LoadContent(MS);