b311480e |
1 | // Created on: 2003-06-20 |
2 | // Created by: Sergey ZARITCHNY |
3 | // Copyright (c) 2003-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
7fd59977 |
19 | |
20 | #include <QANewBRepNaming.ixx> |
21 | |
22 | #include <TopTools_ListOfShape.hxx> |
23 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
24 | #include <TDF_Label.hxx> |
25 | #include <TDF_ChildIterator.hxx> |
26 | #include <TNaming.hxx> |
27 | #include <TNaming_Iterator.hxx> |
28 | #include <TNaming_Builder.hxx> |
29 | #include <TNaming_NamedShape.hxx> |
30 | |
31 | //======================================================================= |
32 | //function : CleanStructure |
33 | //purpose : |
34 | //======================================================================= |
35 | |
36 | void QANewBRepNaming::CleanStructure(const TDF_Label& theLabel) { |
37 | |
38 | TopTools_ListOfShape Olds; |
39 | TopTools_ListOfShape News; |
40 | TNaming_Evolution anEvol; |
41 | TNaming_Iterator anIt(theLabel); |
42 | if (anIt.More()) { |
43 | anEvol = anIt.Evolution(); |
44 | for ( ; anIt.More(); anIt.Next()) { |
45 | Olds.Append(anIt.OldShape()); |
46 | News.Append(anIt.NewShape()); |
47 | } |
48 | |
49 | TopTools_ListIteratorOfListOfShape itOlds(Olds); |
50 | TopTools_ListIteratorOfListOfShape itNews(News); |
51 | TNaming_Builder aBuilder(theLabel); |
52 | anEvol = TNaming_DELETE; |
53 | |
54 | for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) { |
55 | const TopoDS_Shape& OS = itOlds.Value(); |
56 | const TopoDS_Shape& NS = itNews.Value(); |
57 | LoadNamedShape ( aBuilder, anEvol, OS, NS); |
58 | } |
59 | } |
60 | for (TDF_ChildIterator chlIt(theLabel, Standard_True); chlIt.More(); chlIt.Next()) { |
61 | CleanStructure (chlIt.Value()); |
62 | } |
63 | } |
64 | |
65 | //======================================================================= |
66 | //function : LoadNamedShape |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | void QANewBRepNaming::LoadNamedShape (TNaming_Builder& theBuilder, |
71 | const TNaming_Evolution theEvol, |
72 | const TopoDS_Shape& theOS, |
73 | const TopoDS_Shape& theNS) |
74 | { |
75 | switch (theEvol) { |
76 | case TNaming_PRIMITIVE : |
77 | { |
78 | theBuilder.Generated(theNS); |
79 | break; |
80 | } |
81 | case TNaming_GENERATED : |
82 | { |
83 | theBuilder.Generated(theOS, theNS); |
84 | break; |
85 | } |
86 | case TNaming_MODIFY : |
87 | { |
88 | theBuilder.Modify(theOS, theNS); |
89 | break; |
90 | } |
566f8441 |
91 | case TNaming_REPLACE : |
92 | { |
93 | theBuilder.Modify(theOS, theNS); |
94 | break; |
95 | } // for compatibility |
1ec8a59e |
96 | // case TNaming_REPLACE : |
97 | // { |
98 | // theBuilder.Replace(theOS, theNS); |
99 | // break; |
100 | // } |
7fd59977 |
101 | case TNaming_DELETE : |
102 | { |
103 | theBuilder.Delete (theOS); |
104 | break; |
105 | } |
106 | case TNaming_SELECTED : |
107 | { |
108 | theBuilder.Select(theNS, theOS); |
109 | } |
7fd59977 |
110 | default: |
111 | break; |
7fd59977 |
112 | } |
113 | } |
114 | |
115 | //======================================================================= |
116 | //function : Displace |
117 | //purpose : if WithOld == True, dsplace with old subshapes |
118 | //======================================================================= |
119 | |
120 | void QANewBRepNaming::Displace (const TDF_Label& theLabel, |
121 | const TopLoc_Location& theLoc, |
122 | const Standard_Boolean theWithOld) |
123 | { |
124 | TopTools_ListOfShape Olds; |
125 | TopTools_ListOfShape News; |
126 | TNaming_Evolution Evol; |
127 | TNaming_Iterator it(theLabel); |
128 | |
129 | if (it.More()) { |
130 | Evol = it.Evolution(); |
131 | for ( ; it.More(); it.Next()) { |
132 | Olds.Append(it.OldShape()); |
133 | News.Append(it.NewShape()); |
134 | } |
135 | |
136 | TopTools_ListIteratorOfListOfShape itOlds(Olds); |
137 | TopTools_ListIteratorOfListOfShape itNews(News); |
138 | TNaming_Builder B(theLabel); |
139 | |
140 | for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) { |
141 | TopoDS_Shape OS,NS; |
142 | const TopoDS_Shape& SO = itOlds.Value(); |
143 | const TopoDS_Shape& SN = itNews.Value(); |
144 | OS = SO; |
145 | if (theWithOld && !SO.IsNull()) OS = SO.Moved(theLoc); |
146 | if (!SN.IsNull()) NS = SN.Moved(theLoc); |
147 | |
148 | LoadNamedShape ( B, Evol, OS, NS); |
149 | } |
150 | } |
151 | for (TDF_ChildIterator ciL(theLabel); ciL.More(); ciL.Next()) { |
152 | Displace (ciL.Value(),theLoc,theWithOld); |
153 | } |
154 | } |