1 // Created on: 2000-02-14
2 // Created by: Denis PASCAL
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 <TNaming_NamingTool.ixx>
17 #include <TNaming_Tool.hxx>
18 #include <TNaming_NewShapeIterator.hxx>
19 #include <TNaming_Iterator.hxx>
20 #include <TopTools_MapIteratorOfMapOfShape.hxx>
21 #include <TNaming_OldShapeIterator.hxx>
22 #include <TNaming_Tool.hxx>
23 #include <TNaming_Naming.hxx>
24 #include <TDF_ChildIterator.hxx>
26 #ifdef OCCT_DEBUG_DESC
27 #include <TCollection_AsciiString.hxx>
28 #include <TDF_Tool.hxx>
29 #include <BRepTools.hxx>
30 static void WriteS(const TopoDS_Shape& shape,
31 const Standard_CString filename)
34 if(strlen(filename) > 255) return;
36 strcpy_s (buf, filename);
38 strcpy (buf, filename);
48 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
49 save << "DBRep_DrawableShape" << endl << endl;
50 if(!shape.IsNull()) BRepTools::Write(shape, save);
55 //=======================================================================
56 //function : IsForbiden
57 //purpose : ANaming voir NamingTool
58 //=======================================================================
60 static Standard_Boolean IsForbiden(const TDF_LabelMap& Forbiden,
64 return Standard_False;
66 if (Forbiden.Contains(Lab))
69 return IsForbiden(Forbiden,Lab.Father());
73 //=======================================================================
74 //function : LastModif
76 //=======================================================================
77 static void LastModif( TNaming_NewShapeIterator& it,
78 const TopoDS_Shape& S,
79 TopTools_MapOfShape& MS,
80 const TDF_LabelMap& Updated,
81 const TDF_LabelMap& Forbiden)
83 Standard_Boolean YaModif = Standard_False;
84 for (; it.More(); it.Next()) {
85 const TDF_Label& Lab = it.Label();
86 #ifdef OCCT_DEBUG_DESC
87 TCollection_AsciiString entry;
88 TDF_Tool::Entry(Lab, entry);
89 cout << "NamingTool:: LastModif LabelEntry = "<< entry << endl;
91 if (!Updated.IsEmpty() && !Updated.Contains(Lab)) continue;
92 if (IsForbiden(Forbiden, Lab)) continue;
93 if (it.IsModification()) {
94 YaModif = Standard_True;
95 TNaming_NewShapeIterator it2(it);
97 const TopoDS_Shape& S = it.Shape();
98 MS.Add (S); // Modified
101 LastModif(it2,it.Shape(),MS,Updated,Forbiden);
107 //=======================================================================
108 static void ApplyOrientation (TopTools_MapOfShape& MS,
109 const TopAbs_Orientation OrientationToApply)
111 if (!MS.IsEmpty ()) {
112 #ifdef OCCT_DEBUG_APPLY
113 cout <<"OrientationToApply = " <<OrientationToApply <<endl;
114 TopTools_MapIteratorOfMapOfShape it1(MS);
115 for (; it1.More(); it1.Next()) {
116 cout << "ApplyOrientation: TShape = " << it1.Key().TShape()->This() << " OR = " <<it1.Key().Orientation() <<endl;
119 TopTools_MapOfShape aMS;
121 TopTools_MapIteratorOfMapOfShape it(aMS);
122 for (; it.More(); it.Next()) {
123 if(it.Key().Orientation() != OrientationToApply) {
124 TopoDS_Shape aS = it.Key();
126 aS.Orientation(OrientationToApply);
132 //=======================================================================
133 //function : CurrentShape
135 //=======================================================================
136 void TNaming_NamingTool::CurrentShape(const TDF_LabelMap& Valid,
137 const TDF_LabelMap& Forbiden,
138 const Handle(TNaming_NamedShape)& Att,
139 TopTools_MapOfShape& MS)
141 TDF_Label Lab = Att->Label();
142 #ifdef OCCT_DEBUG_DESC
143 TCollection_AsciiString entry;
144 TDF_Tool::Entry(Lab, entry);
145 cout << "NamingTool:: LabelEntry = "<< entry << endl;
147 if (!Valid.IsEmpty() && !Valid.Contains(Lab)) {
148 #ifdef OCCT_DEBUG_DESC
149 TCollection_AsciiString entry;
150 TDF_Tool::Entry(Lab, entry);
151 cout << "NamingTool:: LabelEntry = "<< entry << " is out of Valid map" << endl;
156 TNaming_Iterator itL (Att);
157 for (; itL.More(); itL.Next()) {
158 const TopoDS_Shape& S = itL.NewShape();
159 if (S.IsNull()) continue;
160 #ifdef OCCT_DEBUG_DESC
161 WriteS(S, "CS_NewShape.brep");
162 if(itL.OldShape().IsNull())
163 cout <<"OldShape is Null" <<endl;
165 WriteS(itL.OldShape(), "CS_OldShape.brep");
167 Standard_Boolean YaOrientationToApply(Standard_False);
168 TopAbs_Orientation OrientationToApply(TopAbs_FORWARD);
169 if(Att->Evolution() == TNaming_SELECTED) {
170 if (itL.More() && itL.NewShape().ShapeType() != TopAbs_VERTEX) {//OR-N
171 Handle (TNaming_Naming) aNaming;
172 Lab.FindAttribute(TNaming_Naming::GetID(), aNaming);
173 if(!aNaming.IsNull()) {
174 if(aNaming->GetName().Type() == TNaming_ORIENTATION) {
175 OrientationToApply = aNaming->GetName().Orientation();
177 Handle (TNaming_Naming) aNaming2;
178 TDF_ChildIterator it(aNaming->Label());
179 for(;it.More();it.Next()) {
180 const TDF_Label& aLabel = it.Value();
181 aLabel.FindAttribute(TNaming_Naming::GetID(), aNaming2);
182 if(!aNaming2.IsNull()) {
183 if(aNaming2->GetName().Type() == TNaming_ORIENTATION) {
184 OrientationToApply = aNaming2->GetName().Orientation();
190 if(OrientationToApply == TopAbs_FORWARD || OrientationToApply == TopAbs_REVERSED)
191 YaOrientationToApply = Standard_True;
195 TNaming_NewShapeIterator it(itL);
197 if (YaOrientationToApply)
198 MS.Add(S.Oriented(OrientationToApply));
203 // LastModif(it, S, MS, Valid, Forbiden);
204 TopTools_MapOfShape MS2;
205 LastModif(it, S, MS2, Valid, Forbiden);
206 if (YaOrientationToApply) ApplyOrientation (MS2, OrientationToApply);//the solution to be refined
207 for (TopTools_MapIteratorOfMapOfShape itMS2(MS2); itMS2.More();itMS2.Next())
213 //=======================================================================
214 //function : CurrentShapeFromShape
216 //=======================================================================
218 void TNaming_NamingTool::CurrentShapeFromShape(const TDF_LabelMap& Valid,
219 const TDF_LabelMap& Forbiden,
220 const TDF_Label& Acces,
221 const TopoDS_Shape& S,
222 TopTools_MapOfShape& MS)
224 TNaming_NewShapeIterator it(S,Acces);
226 Handle(TNaming_NamedShape) NS = it.NamedShape();
227 if(!NS.IsNull() && NS->Evolution() == TNaming_SELECTED)
228 MS.Add(TNaming_Tool::GetShape(NS));
233 LastModif(it, S, MS, Valid, Forbiden);
237 //=======================================================================
238 //function : MakeDescendants
240 //=======================================================================
242 static void MakeDescendants (TNaming_NewShapeIterator& it,
243 TDF_LabelMap& Descendants)
245 for (; it.More(); it.Next()) {
246 Descendants.Add(it.Label());
247 #ifdef OCCT_DEBUG_DESC
248 TCollection_AsciiString entry;
249 TDF_Tool::Entry(it.Label(), entry);
250 cout<< "MakeDescendants: Label = " <<entry <<endl;
252 if (!it.Shape().IsNull()) {
253 TNaming_NewShapeIterator it2(it);
254 MakeDescendants (it2,Descendants);
258 //=======================================================================
259 void BuildDescendants2 (const Handle(TNaming_NamedShape)& NS, const TDF_Label& ForbLab, TDF_LabelMap& Descendants)
261 if (NS.IsNull()) return;
262 TNaming_NewShapeIterator it(NS);
263 for(;it.More();it.Next()) {
264 if(!it.NamedShape().IsNull()) {
265 #ifdef OCCT_DEBUG_DESC
266 TCollection_AsciiString entry;
267 TDF_Tool::Entry(it.Label(), entry);
268 cout<< "MakeDescendants2: Label = " <<entry <<endl;
270 if(ForbLab == it.Label()) continue;
271 Descendants.Add(it.Label());
272 TNaming_NewShapeIterator it2(it);
273 MakeDescendants (it2,Descendants);
277 //=======================================================================
278 //function : BuildDescendants
280 //=======================================================================
282 void TNaming_NamingTool::BuildDescendants (const Handle(TNaming_NamedShape)& NS,
283 TDF_LabelMap& Descendants)
285 if (NS.IsNull()) return;
286 Descendants.Add(NS->Label());
287 TNaming_NewShapeIterator it(NS);
288 #ifdef OCCT_DEBUG_DESC
289 TCollection_AsciiString entry;
290 TDF_Tool::Entry(NS->Label(), entry);
291 cout<< "MakeDescendants: Label = " <<entry <<endl;
293 MakeDescendants (it,Descendants);
294 TNaming_OldShapeIterator it2(NS);
295 for (; it2.More(); it2.Next()) {
296 if(!it2.Shape().IsNull()) {
297 Handle(TNaming_NamedShape) ONS = TNaming_Tool::NamedShape(it2.Shape(), NS->Label());
299 #ifdef OCCT_DEBUG_DESC
300 TCollection_AsciiString entry;
301 TDF_Tool::Entry(ONS->Label(), entry);
302 cout<< "MakeDescendants_Old: Label = " <<entry <<endl;
304 BuildDescendants2(ONS, NS->Label(), Descendants);