b311480e |
1 | // Created on: 2003-06-20 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2003-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <QANewBRepNaming.hxx> |
7fd59977 |
18 | #include <TDF_ChildIterator.hxx> |
42cf5bc1 |
19 | #include <TDF_Label.hxx> |
7fd59977 |
20 | #include <TNaming.hxx> |
7fd59977 |
21 | #include <TNaming_Builder.hxx> |
42cf5bc1 |
22 | #include <TNaming_Iterator.hxx> |
7fd59977 |
23 | #include <TNaming_NamedShape.hxx> |
42cf5bc1 |
24 | #include <TopLoc_Location.hxx> |
25 | #include <TopoDS_Shape.hxx> |
26 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
27 | #include <TopTools_ListOfShape.hxx> |
7fd59977 |
28 | |
29 | //======================================================================= |
30 | //function : CleanStructure |
31 | //purpose : |
32 | //======================================================================= |
7fd59977 |
33 | void QANewBRepNaming::CleanStructure(const TDF_Label& theLabel) { |
34 | |
35 | TopTools_ListOfShape Olds; |
36 | TopTools_ListOfShape News; |
37 | TNaming_Evolution anEvol; |
38 | TNaming_Iterator anIt(theLabel); |
39 | if (anIt.More()) { |
40 | anEvol = anIt.Evolution(); |
41 | for ( ; anIt.More(); anIt.Next()) { |
42 | Olds.Append(anIt.OldShape()); |
43 | News.Append(anIt.NewShape()); |
44 | } |
45 | |
46 | TopTools_ListIteratorOfListOfShape itOlds(Olds); |
47 | TopTools_ListIteratorOfListOfShape itNews(News); |
48 | TNaming_Builder aBuilder(theLabel); |
49 | anEvol = TNaming_DELETE; |
50 | |
51 | for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) { |
52 | const TopoDS_Shape& OS = itOlds.Value(); |
53 | const TopoDS_Shape& NS = itNews.Value(); |
54 | LoadNamedShape ( aBuilder, anEvol, OS, NS); |
55 | } |
56 | } |
57 | for (TDF_ChildIterator chlIt(theLabel, Standard_True); chlIt.More(); chlIt.Next()) { |
58 | CleanStructure (chlIt.Value()); |
59 | } |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : LoadNamedShape |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | void QANewBRepNaming::LoadNamedShape (TNaming_Builder& theBuilder, |
68 | const TNaming_Evolution theEvol, |
69 | const TopoDS_Shape& theOS, |
70 | const TopoDS_Shape& theNS) |
71 | { |
72 | switch (theEvol) { |
73 | case TNaming_PRIMITIVE : |
74 | { |
75 | theBuilder.Generated(theNS); |
76 | break; |
77 | } |
78 | case TNaming_GENERATED : |
79 | { |
80 | theBuilder.Generated(theOS, theNS); |
81 | break; |
82 | } |
83 | case TNaming_MODIFY : |
84 | { |
85 | theBuilder.Modify(theOS, theNS); |
86 | break; |
87 | } |
566f8441 |
88 | case TNaming_REPLACE : |
89 | { |
90 | theBuilder.Modify(theOS, theNS); |
91 | break; |
92 | } // for compatibility |
1ec8a59e |
93 | // case TNaming_REPLACE : |
94 | // { |
95 | // theBuilder.Replace(theOS, theNS); |
96 | // break; |
97 | // } |
7fd59977 |
98 | case TNaming_DELETE : |
99 | { |
100 | theBuilder.Delete (theOS); |
101 | break; |
102 | } |
103 | case TNaming_SELECTED : |
104 | { |
105 | theBuilder.Select(theNS, theOS); |
106 | } |
7fd59977 |
107 | default: |
108 | break; |
7fd59977 |
109 | } |
110 | } |
111 | |
112 | //======================================================================= |
113 | //function : Displace |
114 | //purpose : if WithOld == True, dsplace with old subshapes |
115 | //======================================================================= |
116 | |
117 | void QANewBRepNaming::Displace (const TDF_Label& theLabel, |
118 | const TopLoc_Location& theLoc, |
119 | const Standard_Boolean theWithOld) |
120 | { |
121 | TopTools_ListOfShape Olds; |
122 | TopTools_ListOfShape News; |
123 | TNaming_Evolution Evol; |
124 | TNaming_Iterator it(theLabel); |
125 | |
126 | if (it.More()) { |
127 | Evol = it.Evolution(); |
128 | for ( ; it.More(); it.Next()) { |
129 | Olds.Append(it.OldShape()); |
130 | News.Append(it.NewShape()); |
131 | } |
132 | |
133 | TopTools_ListIteratorOfListOfShape itOlds(Olds); |
134 | TopTools_ListIteratorOfListOfShape itNews(News); |
135 | TNaming_Builder B(theLabel); |
136 | |
137 | for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) { |
138 | TopoDS_Shape OS,NS; |
139 | const TopoDS_Shape& SO = itOlds.Value(); |
140 | const TopoDS_Shape& SN = itNews.Value(); |
141 | OS = SO; |
142 | if (theWithOld && !SO.IsNull()) OS = SO.Moved(theLoc); |
143 | if (!SN.IsNull()) NS = SN.Moved(theLoc); |
144 | |
145 | LoadNamedShape ( B, Evol, OS, NS); |
146 | } |
147 | } |
148 | for (TDF_ChildIterator ciL(theLabel); ciL.More(); ciL.Next()) { |
149 | Displace (ciL.Value(),theLoc,theWithOld); |
150 | } |
151 | } |