715eac0dbe94f1752f49ca7a438f482b8ab7ed63
[occt.git] / src / QANewBRepNaming / QANewBRepNaming.cxx
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.
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     }
91 //  case TNaming_REPLACE :
92 //    {
93 //      theBuilder.Replace(theOS, theNS);
94 //      break;
95 //    }
96   case TNaming_DELETE :
97     {
98       theBuilder.Delete (theOS);
99       break;
100     }
101   case TNaming_SELECTED :
102     {
103       theBuilder.Select(theNS, theOS);
104     }
105 #ifndef DEB
106   default:
107     break;
108 #endif
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 }