0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / TNaming / TNaming_Naming.cxx
CommitLineData
7fd59977 1// File: TNaming_Naming.cxx
2// Created: Wed Sep 3 09:36:05 1997
3// Author: Yves FRICAUD
4// <yfr@claquox.paris1.matra-dtv.fr>
5//Copyright: Matra Datavision 1997
6
7
8#include <TNaming_Naming.ixx>
9
10#include <TNaming_Builder.hxx>
11#include <TNaming_Tool.hxx>
12#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
13#include <TNaming_Iterator.hxx>
14//
15#include <TNaming_Scope.hxx>
16#include <TNaming_NamingTool.hxx>
17#include <TNaming_Name.hxx>
18#include <TNaming_Identifier.hxx>
19#include <TNaming_Localizer.hxx>
20#include <TNaming_NewShapeIterator.hxx>
21#include <TNaming_OldShapeIterator.hxx>
22#include <TNaming_Selector.hxx>
23#include <TNaming.hxx>
24//
25#include <TDF_ChildIterator.hxx>
26#include <TDF_LabelList.hxx>
27#include <TDF_Data.hxx>
28#include <TDF_LabelMap.hxx>
29#include <TDF_TagSource.hxx>
30#include <TopoDS_Iterator.hxx>
31#include <TopTools_MapOfShape.hxx>
32#include <TopExp.hxx>
33#include <TopExp_Explorer.hxx>
34#include <TopTools_MapIteratorOfMapOfShape.hxx>
35#include <Standard_DomainError.hxx>
36#include <TopTools_ListOfShape.hxx>
37#include <TopTools_ListIteratorOfListOfShape.hxx>
38#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
39#include <TColStd_MapOfInteger.hxx>
40#include <TColStd_MapIteratorOfMapOfInteger.hxx>
41#include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
42#include <TopTools_HArray1OfShape.hxx>
43#include <BRep_Tool.hxx>
44#include <TopoDS.hxx>
45// #include <TNaming_NCollections.hxx>
46#include <NCollection_Map.hxx>
47#include <NCollection_DataMap.hxx>
48typedef NCollection_Map<TopoDS_Shape> TNaming_MapOfShape;
49typedef TNaming_MapOfShape::Iterator TNaming_MapIteratorOfMapOfShape;
50typedef NCollection_DataMap<TopoDS_Shape, TNaming_MapOfShape> TNaming_DataMapOfShapeMapOfShape;
51typedef TNaming_DataMapOfShapeMapOfShape::Iterator TNaming_DataMapIteratorOfDataMapOfShapeMapOfShape;
52// The bug concerns access to a null object in the method Filter():
53#define BUC60847
54
55#define OCC273
56#define OCC350
57#define OCC352
58#define ALLOW_CHILD_NBS
59//#define MDTV_DEB_CC
60//#define MDTV_DEB_OR
61//#define MDTV_DEB_MOD
62//#define MDTV_OR
63//#define MDTV_DEB_INNS
64//#define MDTV_DEB_NBS
65//#define MDTV_DEB_71
66//#define MDTV_DEB_WIN
67#ifdef MDTV_DEB
68#include <TDF_MapIteratorOfLabelMap.hxx>
69#include <TCollection_AsciiString.hxx>
70#include <TDF_Tool.hxx>
71#include <BRepTools.hxx>
72#include <TNaming_Tool.hxx>
73#include <DbgTools.hxx>
74#endif
75#ifdef DEB
76#include <TDF_Tool.hxx>
77#include <TDF_MapIteratorOfLabelMap.hxx>
78
79#include <TCollection_AsciiString.hxx>
80#include <BRepTools.hxx>
81void Print_Entry(const TDF_Label& label)
82{
83 TCollection_AsciiString entry;
84 TDF_Tool::Entry(label, entry);
85 cout << "LabelEntry = "<< entry << endl;
86}
87static void Write(const TopoDS_Shape& shape,
88 const Standard_CString filename)
89{
90 char buf[256];
91 if(strlen(filename) > 256) return;
92 strcpy (buf, filename);
93 char* p = buf;
94 while (*p) {
95 if(*p == ':')
96 *p = '-';
97 p++;
98 }
99 ofstream save (buf);
100 if(!save)
101 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
102 save << "DBRep_DrawableShape" << endl << endl;
103 if(!shape.IsNull()) BRepTools::Write(shape, save);
104 save.close();
105}
106void WriteNSOnLabel(const Handle(TNaming_NamedShape) & NS, const TCollection_AsciiString& Nam)
107{
108 if (!NS.IsNull()) {
109 TCollection_AsciiString entry;
110 TDF_Tool::Entry(NS->Label(), entry);
111 TopoDS_Shape Sh = TNaming_Tool::GetShape (NS);
112 if(!Sh.IsNull()) {
113 TCollection_AsciiString Entry = Nam + entry + ".brep";
114 Write(Sh, Entry.ToCString());
115 }
116 else
117 cout << "WriteNSOnLabel>>> TopoDS_Shape IS NULL on Entry = "<< entry << endl;
118 }
119 else
120 cout << "WriteNSOnLabel >>> NamedShape IS NULL" << endl;
121}
122//=======================================================================
123static void Write(const TopTools_MapOfShape& MS, const Standard_CString filename)
124{
125 if (!MS.IsEmpty ()) {
126 TCollection_AsciiString aNam (filename);
127 Standard_Integer i(0);
128 TopTools_MapIteratorOfMapOfShape it(MS);
129 for(;it.More();it.Next(),i++) {
130 TCollection_AsciiString aName = aNam + "_" + i + ".brep";
131 Write ( it.Key(), aName.ToCString());
132 }
133 }
134}
135#endif
136
137//==========================================================================================
138static Handle(TNaming_NamedShape) BuildName (const TDF_Label& F,
139 TNaming_Scope& MDF,
140 const TopoDS_Shape& S,
141 const TopoDS_Shape& Context,
142 const Handle(TNaming_NamedShape)& Stop,
143 const Standard_Boolean Geometry);
144
145//=======================================================================
146static Standard_Integer RepeatabilityInContext(const TopoDS_Shape& Selection,
147 const TopoDS_Shape& Context);
148//=======================================================================
149extern Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2);
150
151//=======================================================================
152//function : Solve
153//purpose : voir avec YFR comment retrouver le bon resulat et le mettre
154// : dans le NamedShape de L
155//=======================================================================
156Standard_Boolean TNaming_Naming::Solve (TDF_LabelMap& Valid)
157{
158 Handle(TNaming_Naming) subname;
159 for (TDF_ChildIterator it (Label(),Standard_False); it.More(); it.Next()) {
160#ifdef MDTV_DEB_NBS
161 TCollection_AsciiString anEntry;
162 TDF_Tool::Entry(it.Value(), anEntry);
163 cout << "TNaming_Naming::Solve: Label to be solved = " << anEntry << endl;
164#endif
165 if (it.Value().FindAttribute(TNaming_Naming::GetID(),subname)) {
166 if (!subname->Solve (Valid)) {
167 return Standard_False; // not necessary to continue
168 }
169 }
170 }
171#ifdef MDTV_DEB_CC
172 TDF_MapIteratorOfLabelMap anItr(Valid);
173 cout << "TNaming_Naming::Solve:: Valid label Map" << endl;
174 for (; anItr.More(); anItr.Next()) {
175 const TDF_Label& aLabel = anItr.Key();
176 TCollection_AsciiString anEntry;
177 TDF_Tool::Entry(aLabel, anEntry);
178 cout << "Label = " << anEntry << endl;
179 }
180#endif
181 if (Regenerate(Valid)) {
182 if (!Valid.IsEmpty()) Valid.Add(Label());
183 return Standard_True;
184 }
185 return Standard_False;
186}
187
188
189//=======================================================================
190//function : GetID
191//purpose :
192//=======================================================================
193
194const Standard_GUID& TNaming_Naming::GetID ()
195{
196 static Standard_GUID TNaming_NamingID("c0a19201-5b78-11d1-8940-080009dc3333");
197 return TNaming_NamingID;
198}
199
200//=======================================================================
201//function : Insert
202//purpose :
203//=======================================================================
204
205Handle(TNaming_Naming) TNaming_Naming::Insert (const TDF_Label& under)
206{
207 Handle(TNaming_Naming) N;
208 TDF_Label child = TDF_TagSource::NewChild(under);
209 N = new TNaming_Naming ();
210 child.AddAttribute (N);
211 return N;
212}
213
214//=======================================================================
215//function : BuildNS
216//purpose : returns a new NamedShape, which is built as selection:
217// : TNaming_Builder::Select("S","S") at the new child label of the label <F>.
218//=======================================================================
219
220static Handle(TNaming_NamedShape) BuildNS (const TDF_Label& F,
221 const TopoDS_Shape& S,
222 const TNaming_NameType& Name)
223{
224 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert (F);
225
226 TNaming_Name& theName = Naming->ChangeName();
227 theName.ShapeType(S.ShapeType());
228 theName.Shape(S);
229 theName.Type(Name);
230 TNaming_Builder B(Naming->Label());
231 B.Select(S,S);
232 return B.NamedShape();
233}
234
235//=======================================================================
236//function : FindIndex
237//purpose :
238//=======================================================================
239
240static Standard_Integer FindIndex(const Handle(TNaming_NamedShape)& NS,
241 const TopoDS_Shape& S)
242{
243 TDF_LabelList Labels;
244 TopoDS_Shape IS = TNaming_Tool::InitialShape(S,NS->Label(),Labels);
245 Standard_Integer Index = 1;
246 for (TNaming_Iterator itNS(NS); itNS.More(); itNS.Next(),Index++) {
247 if (IS.IsSame(itNS.NewShape())) break;
248 }
249 return Index;
250}
251
252
253//=======================================================================
254//function : CompareInGeneration
255//purpose : returns true, only if the specified NS contains only <S> in
256// : the "new shapes" set.
257//=======================================================================
258
259static Standard_Boolean CompareInGeneration (const Handle(TNaming_NamedShape)& NS,
260 const TopoDS_Shape& S)
261{
262 for (TNaming_Iterator it(NS); it.More(); it.Next()) {
263 if (!it.NewShape().IsSame(S)) return 0;
264 }
265 return 1;
266}
267
268#ifdef OCC350
269
270//=======================================================================
271//function : GetShapeEvolutions
272//purpose : returns Standard_True, if target has parent in source; list contains inheritance chain
273//=======================================================================
274static Standard_Boolean GetShapeEvolutions(const TopoDS_Shape& theTarget, // this is changed in recursion
275 const Handle(TNaming_NamedShape)& theSource,
276 TopTools_ListOfShape& aList) // returns list in the backward order
277{
278 Handle(TNaming_NamedShape) aTarget = TNaming_Tool::NamedShape(theTarget,theSource->Label());
279 if (!aTarget.IsNull()) {
280#ifdef MDTV_DEB_71
281 cout <<"GetShapeEvolutions: target NS = ";
282 Print_Entry(aTarget->Label());
283 cout <<"GetShapeEvolutions: Source NS = ";
284 Print_Entry(theSource->Label());
285 TCollection_AsciiString aNam("GetShapeEvolutions");
286 WriteNSOnLabel(aTarget,aNam);
287#endif
288 if (aTarget->Label() == theSource->Label()) return Standard_True; // check if target is in the source
289 } else return Standard_False;
290
291 TNaming_Iterator anIter(aTarget);
292 for(;anIter.More();anIter.Next()) { // check all appropriate old shapes of target
293#ifdef MDTV_DEB_71
294 if(!anIter.OldShape().IsNull()) {
295 Write(anIter.OldShape(), "Target_OldS.brep");
296 cout <<"Target OldS TS =" <<anIter.OldShape().TShape()->This() <<endl;
297 }
298 if(!anIter.NewShape().IsNull()) {
299 Write(anIter.NewShape(), "Target_NewS.brep");
300 cout <<"Target NewS TS =" <<anIter.NewShape().TShape()->This() <<endl;
301 }
302#endif
303 if (anIter.OldShape().IsNull() || anIter.NewShape().IsNull()) continue;
304 if (!anIter.NewShape().IsSame(theTarget)) continue;
305 if (GetShapeEvolutions(anIter.OldShape(),theSource,aList)) { // recursion: now target is old shape
306 aList.Append(theTarget); // if oldshape has the source as parent (or belongs to it) , fill the list
307 return Standard_True;
308 }
309 }
310 return Standard_False;
311}
312
313//=======================================================================
314//function : CompareInModification
315//purpose : returns empty named shape if naming is already done
316//=======================================================================
317
318static Handle(TNaming_NamedShape) CompareInModification (const Handle(TNaming_NamedShape)& NS, // parent
319 const TopoDS_Shape& S) // target
320{
321 Handle(TNaming_NamedShape) aResult;
322 if (S.IsNull() || NS.IsNull()) return aResult;
323#ifdef MDTV_DEB_71
324 cout <<"CompareInModification: parent NS = ";
325 Print_Entry(NS->Label());
326 Write(S, "CompareInM_S.brep");
327 TCollection_AsciiString aNam("CompareInM");
328 WriteNSOnLabel(NS,aNam);
329#endif
330 Handle(TNaming_NamedShape) aSource; // parent NamedShape, which can be found by TopoDS shape
331 TNaming_Iterator anIt(NS);
332 for(;anIt.More() && aSource.IsNull();anIt.Next()) {
333 if (!anIt.NewShape().IsNull()) {
334 aSource = TNaming_Tool::NamedShape(anIt.NewShape(),NS->Label());
335#ifdef MDTV_DEB_71
336 TCollection_AsciiString aNam("CompareInM_Source");
337 WriteNSOnLabel(aSource,aNam);
338#endif
339 }
340 }
341 // searching for 1:n to the same label modifications (in this case current naming is insufficient)
342 TopTools_ListOfShape aList;
343 if (GetShapeEvolutions(S,aSource,aList) && aList.Extent() > 0) {
344 TopTools_ListIteratorOfListOfShape anIter(aList);
345 for(;anIter.More();anIter.Next()) {
346 aResult = TNaming_Tool::NamedShape(anIter.Value(),NS->Label());
347 if (aResult->Evolution()!=TNaming_MODIFY) { // evolution must be modify, otherwise everything is OK
348 aResult.Nullify();
349 return aResult;
350 }
351 TopTools_MapOfShape aMap; // collection of the old shapes of the shape from list
352 TNaming_Iterator aNIter1(aResult);
353
354 for(;aNIter1.More();aNIter1.Next()) {
355 if (aNIter1.NewShape().IsSame(anIter.Value())) {// if isSame
356 aMap.Add(aNIter1.OldShape());
357 }
358 }
359 TNaming_Iterator aNIter2(aResult); // if some another shapes has oldshape from map, return namedshape with this oldshape
360
361 for(;aNIter2.More();aNIter2.Next()) {
362 if (aNIter2.NewShape().IsSame(anIter.Value())) continue;
363 if (aMap.Contains(aNIter2.OldShape())) { // if one shape was modified to the two at the shared label, return this one
364 aResult = TNaming_Tool::NamedShape(aNIter2.OldShape(),NS->Label());
365 if (!aResult.IsNull()) return aResult;
366 }
367 }
368 }
369 aResult.Nullify();
370 }
371 return aResult;
372}
373#endif
374
375//=======================================================================
376static Standard_Boolean FillSMap(const TopoDS_Shape& S, TopTools_MapOfShape& MS)
377{
378 if(S.IsNull()) return Standard_False;
379 Standard_Boolean isHomogen(Standard_True);
380 TopAbs_ShapeEnum aPrevType(TopAbs_SHAPE);
381 TopoDS_Iterator it(S);
382 for (; it.More(); it.Next()) {
383 const TopAbs_ShapeEnum aType = it.Value().ShapeType();
384#ifdef MDTV_DEB_CC
385 cout <<"TestSolution_FillMap: S_Type = :" << it.Value().ShapeType() <<" TShape = " << it.Value().TShape()->This() <<endl;
386#endif
387 if(aType > TopAbs_COMPSOLID) {
388 MS.Add(it.Value());
389 if(aPrevType == TopAbs_SHAPE)
390 aPrevType = aType;
391 else if(aPrevType != aType)
392 isHomogen = Standard_False;
393 }
394 else
395 if(!FillSMap(it.Value(), MS))
396 isHomogen = Standard_False;
397 }
398 return isHomogen;
399}
400//=======================================================================
401//function : Compare
402//purpose : checks naming of the shape <S> in the NamedShape <NS>.
403// : Returns true, if it's correct. Details ==>
404// : The method takes all modifications of the "NS" (see CurrentShape method),
405// : which are in the "MDF" (if it's not empty) before <Stop> shape and check them.
406// : whether these modifications contain only "S". If yes then the method
407// : returns true, otherwise it returns false.
408//=======================================================================
409
410static Standard_Boolean Compare (const Handle(TNaming_NamedShape)& NS,
411 const TNaming_Scope& MDF,
412 const Handle(TNaming_NamedShape)& Stop,
413 const TopoDS_Shape& S)
414{
415 TDF_LabelMap Forbiden;
416 TopTools_MapOfShape MS;
417 if (!Stop.IsNull()) TNaming_NamingTool::BuildDescendants(Stop,Forbiden);
418 TNaming_NamingTool::CurrentShape(MDF.GetValid(),Forbiden,NS,MS);
419#ifdef MDTV_DEB_NBS
420 Write(S, "Compare_S.brep");
421 cout << "S: TShape = " <<S.TShape()->This() <<endl;
422 Standard_Integer i =1;
423 TopTools_MapIteratorOfMapOfShape it(MS);
424 TCollection_AsciiString aNam("Compare_MS_");
425 TCollection_AsciiString ext(".brep");
426 for(;it.More();it.Next(), i++) {
427 TCollection_AsciiString aName = aNam + i + ext;
428 Write(it.Key(), aName.ToCString()) ;
429 cout << aName.ToCString()<< ": TShape = " <<it.Key().TShape()->This() <<endl;
430 }
431#endif
432 return (MS.Contains(S) && MS.Extent() == 1);
433}
434//=======================================================================
435//function : TestSolution
436//purpose : returns true, if last modification of shape from "NS" is equal to "S":
437// : If shape "S" has atomic type (TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX),
438// : then returns S.IsSame(shape from "NS").
439// : Otherwise the result of exploration of these shapes must be same.
440//=======================================================================
441
442static Standard_Boolean TestSolution(const TNaming_Scope& MDF,
443 const Handle(TNaming_NamedShape)& NS,
444 const TopoDS_Shape& S)
445{
446
447 if (NS.IsNull()) return Standard_False;
448 TopoDS_Shape Res = MDF.CurrentShape(NS);// last modification of NS taken into account Valid map
449 if(S.IsNull() || Res.IsNull()) return Standard_False;
450#ifdef MDTV_DEB_CC
451 Write(S, "TSol_S.brep");
452 Write(Res, "TSol_Res.brep");
453#endif
454#ifdef OCC352
455
456 if ((S.ShapeType() == TopAbs_FACE ||
457 S.ShapeType() == TopAbs_EDGE ||
458 S.ShapeType() == TopAbs_VERTEX ) &&
459 Res.ShapeType() != TopAbs_COMPOUND) {
460 return (Res.IsSame(S));
461 } else if (S.ShapeType() == TopAbs_SOLID ||
462 S.ShapeType() == TopAbs_COMPSOLID) {
463 TopTools_MapOfShape aMS;
464 TopExp_Explorer exp;
465 for (exp.Init(S,TopAbs_FACE) ; exp.More(); exp.Next()) {
466 aMS.Add(exp.Current());
467 }
468 for (exp.Init(Res,TopAbs_FACE) ; exp.More(); exp.Next()) { //content of MS and Res should be the same
469 if (aMS.Contains(exp.Current())) {
470 aMS.Remove(exp.Current());
471 }
472 else return 0;
473 }
474 return aMS.IsEmpty();
475 } else {
476
477#else
478
479 if (S.ShapeType() == TopAbs_SOLID ||
480 S.ShapeType() == TopAbs_FACE ||
481 S.ShapeType() == TopAbs_EDGE ||
482 S.ShapeType() == TopAbs_VERTEX ) {
483 return (Res.IsSame(S));
484 }
485 else {
486
487#endif
488
489 TopTools_MapOfShape MS;
490 Standard_Boolean isHom = FillSMap(S, MS);
491 TopAbs_ShapeEnum aType(TopAbs_SHAPE);
492 TColStd_MapOfInteger aView;
493 TopTools_MapIteratorOfMapOfShape itm(MS);
494 for(;itm.More();itm.Next()) {
495 aType = itm.Key().ShapeType();
496 if(isHom)
497 break;
498 else
499 aView.Add(itm.Key().ShapeType());
500 }
501
502 if (MS.Contains(Res)) {
503 MS.Remove(Res);
504 if (MS.IsEmpty()) return 1;
505 }
506 if (Res.ShapeType() == TopAbs_SOLID ||
507 Res.ShapeType() == TopAbs_COMPSOLID ||
508 Res.ShapeType() == TopAbs_COMPOUND)
509 {
510 TopExp_Explorer exp;
511 if(isHom)
512 for (exp.Init(Res,aType) ; exp.More(); exp.Next()) {
513 if (MS.Contains(exp.Current())) {
514 MS.Remove(exp.Current());
515 }
516 } else {
517 TColStd_MapIteratorOfMapOfInteger itm(aView);
518 for(;itm.More();itm.Next()) {
519 TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)itm.Key();
520 for (exp.Init(Res,aType) ; exp.More(); exp.Next()) {
521 if (MS.Contains(exp.Current())) {
522 MS.Remove(exp.Current());
523 }
524 }
525 }
526 }
527 } else {
528 if(S.IsSame(Res))
529 return Standard_True;
530 TopoDS_Iterator it(Res);
531 for (; it.More(); it.Next()) { //content of MS and Res should be the same
532 if (MS.Contains(it.Value())) {
533 MS.Remove(it.Value());
534 }
535 else return 0;
536 }
537 }
538 return MS.IsEmpty();
539 }
540}
541
542//=======================================================================
543//function : FindNewShapeInFather
544//purpose :
545//=======================================================================
546
547static void FindNewShapeInFather (const Handle(TNaming_NamedShape)& NS,
548 TopoDS_Shape& SC)
549{
550 TDF_Label Father = NS->Label().Father();
551 TNaming_Iterator itLab(Father);
552 for (; itLab.More(); itLab.Next()) {
553 SC= itLab.NewShape();
554 break;
555 }
556}
557
558//=======================================================================
559//function : NextModif
560//purpose :
561//=======================================================================
562
563static Handle(TNaming_NamedShape) NextModif(const Handle(TNaming_NamedShape)& NS)
564{
565 Handle (TNaming_NamedShape) Next;
566 if (!NS.IsNull()) {
567 TNaming_NewShapeIterator it(NS);
568 if (it.More()&& it.IsModification()) Next = it.NamedShape();
569 }
570 return Next;
571}
572//=======================================================================
573// C1 - cand shape of the father, C2 - shape of rebuild child Naming attr.
574// (to be Compound of elementary shapes)
575//=======================================================================
576static Standard_Boolean IsContSame(const TopoDS_Shape& C1, const TopoDS_Shape& C2)
577{
578 Standard_Boolean aRes(Standard_False);
579 if(!C1.IsNull() && !C2.IsNull()) {
580 TopTools_MapOfShape aMap;
581 if(FillSMap(C1, aMap)) {
582 aRes = Standard_True;
583 TopoDS_Iterator it(C2);
584 for(;it.More();it.Next()) {
585 if(!aMap.Contains(it.Value())) {
586 aRes = Standard_False;
587 break;
588 }
589 }
590 }
591 }
592 return aRes;
593}
594
595//=======================================================================
596// Identifies the case when Filter haven't sense because of multiplicity
597//=======================================================================
598static Standard_Boolean IsMultipleCase(const TopoDS_Shape& S,
599 const TopoDS_Shape& Context,
600 const TopTools_MapOfShape& Neighbourgs) {
601
602 TopTools_IndexedDataMapOfShapeListOfShape aDM;
603 TNaming_MapOfShape aM;
604 TopTools_MapOfShape aNbs;
605 aNbs.Assign(Neighbourgs);
606 aNbs.Add(S);
607 TNaming_DataMapOfShapeMapOfShape aDMM;
608 TopExp::MapShapesAndAncestors (Context, TopAbs_EDGE, TopAbs_FACE, aDM);
609 TopTools_MapIteratorOfMapOfShape it(aNbs);
610 for(;it.More();it.Next()) {
611 if(aDM.Contains(it.Key())) {
612 TNaming_MapOfShape aMS;
613 const TopTools_ListOfShape& aL = aDM.FindFromKey(it.Key());
614 TopTools_ListIteratorOfListOfShape lit(aL);
615 for(;lit.More();lit.Next()) {
616 aM.Add(lit.Value());
617 aMS.Add(lit.Value());
618 }
619 if(aMS.Extent())
620 aDMM.Bind(it.Key(), aMS);
621 } else {
622#ifdef DEB
623 cout << "Key is not BOUND!" <<endl;
624#endif
625 return Standard_False;
626 }
627 }
628
629 Standard_Boolean isCommon(Standard_True);
630 TNaming_MapIteratorOfMapOfShape itm(aM);
631 for(;itm.More();itm.Next()) {
632 isCommon = Standard_True; // statement: this shape (itm.Key()) is common (to be checked below)
633 TNaming_DataMapIteratorOfDataMapOfShapeMapOfShape itdm(aDMM);
634 for (;itdm.More();itdm.Next()) {
7fd59977 635 const TNaming_MapOfShape& aMap = itdm.Value();
636 if(!aMap.Contains(itm.Key())) {
637 isCommon = Standard_False;
638 break;
639 }
640 }
641 if(isCommon) break; // common single face found
642 }
643 if(isCommon && aM.Extent() < aNbs.Extent()) {// number of unique faces (to have single solution)
644 //should be at least no less than (Nb of Neighbourgs) +1
645 return Standard_True;
646 }
647 return Standard_False;
648}
649//=======================================================================
650//function : Filter
651//purpose : sets the name with type "FILTERBYNEIGHBOURGS" and returns true,
652// : if it was correctly done.
653// :
654// :
655//=======================================================================
656
657static Standard_Boolean Filter (const TDF_Label& F,
658 TNaming_Scope& MDF,
659 const TopoDS_Shape& S,
660 const TopoDS_Shape& Context,
661 TNaming_Localizer& Localizer,
662 Handle(TNaming_NamedShape)& NS,
663 const Standard_Integer Lev)
664{
665 // 1. Localizer.FindNeighbourg("Context", "S", "Neighbourg") - looks for neighbourgs of "S" with the same shape type in the "Context"
666 // shape and adds them to the "Neighbourg" map;
667 // 2. If "Neighbourg" map is empty, tries to do the same with the new context shape: shape from the father label of the "S" named shape;
668 // 3. If "Neighbourg" map is still empty, returns false;
669 // 4. Adds to the new child of label "L" new TNaming_Naming attribute with the next properties name: shape type is shape type of the "S",
670 // type is TNaming_FILTERBYNEIGHBOURGS, stop shape ( "Until" ) is "Context" of corresponding NamedShape;
671 // first argument of name is "NS" NamedShape.
672 // 5. Adds to the Name all shapes from "Neighbourg" map: build it with the BuildName( new generated TNaming_Naming attribute, MDF,
673 // argument shape from "Neighbourg", "Context", NextModif( "Until" ), true ) method.
674 // 6. Creates resulting NamedShape with the "Regenerate" ( it just calls TName::Solve method ) method from TNaming_Naming class.
675 // 7. If Compare( result NamedShape, MDF, stop, "S" ) returns true, "Filter" method returns true, else returns false.
676
677 //------------------------------
678 // Construction des voisins ==> of neighbors.
679 //------------------------------
680 Standard_Integer aLev(Lev);
681 TopTools_MapOfShape Neighbourg;
682 Localizer.FindNeighbourg (Context,S,Neighbourg);
683#ifdef MDTV_DEB_NBS
684 //DbgTools::DisplayShape(Context, F, Quantity_NOC_GREEN);
685 //DbgTools::DisplayShape(S, F, Quantity_NOC_BLUE1);
686 Write(Context, "FNBS_Context.brep");
687 Write(S, "FNBS_S.brep");
688#endif
689#ifdef OCC273
690 // mpv : NS and shape must be the same
691 Standard_Boolean isIn = Standard_False;
692 TNaming_Iterator anIter(NS);
693 for(;anIter.More();anIter.Next()) {
694#ifdef MDTV_DEB
695 //DbgTools::DisplayShape(anIter.NewShape(), F, Quantity_NOC_RED);
696#endif
697 if (anIter.NewShape().IsSame(S)) {
698 isIn = Standard_True;
699 break;
700 }
701 }
702 if (!isIn) if (!TNaming_Tool::NamedShape(S,F).IsNull()) NS = TNaming_Tool::NamedShape(S,F);
703// if (!TNaming_Tool::NamedShape(S,F).IsNull()) NS = TNaming_Tool::NamedShape(S,F);
704#endif
705
706 if (Neighbourg.IsEmpty()) {
707 // Recherche du vrai context. (Research of context truth)
708 Handle(TNaming_NamedShape) GenS = TNaming_Tool::NamedShape(S,NS->Label());
709#ifdef BUC60847
710 if (GenS.IsNull()) return Standard_False;
711#endif
712 TDF_Label Father = (GenS->Label()).Father();
713 Father.FindAttribute(TNaming_NamedShape::GetID(),GenS);
714 TopoDS_Shape GoodContext = TNaming_Tool::GetShape(GenS);
715 Localizer.FindNeighbourg (GoodContext,S,Neighbourg);
716 }
717
718
719 if (Neighbourg.IsEmpty()) {
720#ifdef DEB
721 cout <<"FindNeighbourg: impossible"<<endl;
722#endif
723 return 0;
724 } else {
725#ifdef MDTV_DEB_NBS
726 Write(Neighbourg, "Neighbourgs");
727#endif
728 aLev++;
729 //cout <<"Filter: Lev = " << aLev << endl;
730 }
731 if(aLev > 3) return 0;
732#ifdef ALLOW_CHILD_NBS
733 Handle(TNaming_Naming) aFNaming;
734 TopoDS_Shape aFatherCandSh;
735 F.FindAttribute(TNaming_Naming::GetID(), aFNaming);
736 if(!aFNaming.IsNull()) {
737 const TNaming_Name& aName = aFNaming->GetName();
738 if (aName.Type() == TNaming_FILTERBYNEIGHBOURGS) {
739 aFatherCandSh = aName.Arguments().First()->Get();
740 }
741 }
742 if(S.ShapeType() == TopAbs_EDGE && aFatherCandSh.IsNull()) {
743 //check the applicability
744 if(!NS.IsNull() && !NS->Get().IsNull() && NS->Get().ShapeType() == TopAbs_COMPOUND)
745 if(IsMultipleCase(S, Context, Neighbourg)) {
746 //cout << "Filter: ==> MultipleCase!" << endl;
747 NS->Label().FindAttribute(TNaming_Naming::GetID(), aFNaming);
748 if(!aFNaming.IsNull()) {
749 TNaming_Name& aName = aFNaming->ChangeName();
750 if (aName.Type() == TNaming_INTERSECTION) {
751 Standard_Integer ij(1);
752 TNaming_ListIteratorOfListOfNamedShape itA(aName.Arguments());
753 for (; itA.More(); itA.Next(), ij++) {
754 const TopoDS_Shape& aFace = TNaming_Tool::CurrentShape(itA.Value());
755#ifdef MDTV_DEB_MOD
756 Write(aFace, "First_Face.brep");
757 cout <<"Selection TS = " << S.TShape()->This() <<endl;
758#endif
759 Standard_Integer i(1), indxW(0),indxE(0),nbW(0),nbE(0), indxF(0);
760 Standard_Boolean isFound(Standard_False);
761 TopoDS_Iterator it(aFace);
762 for (;it.More();it.Next(),i++) {
763 nbW++;
764#ifdef MDTV_DEB_MOD
765 Write(it.Value(), "First_Wire.brep");
766#endif
767 if(!isFound) {
768 Standard_Integer j(1);
769 TopoDS_Iterator it2(it.Value());
770 for (;it2.More();it2.Next(),j++) {
771 nbE++;
772#ifdef MDTV_DEB_MOD
773 Write(it2.Value(), "First_Wire.brep");
774 cout <<"Edge TS = " << it2.Value().TShape()->This() <<endl;
775#endif
776 if(S.IsEqual(it2.Value())) {
777 indxE = j;
778 indxW = i;
779 indxF = ij;
780 isFound = Standard_True;
781 }
782 }
783 }
784 }
785 if(isFound) {
786 Standard_Integer Index = indxE & 0x000000FF;
787 Index = Index | (nbE << 8);
788 Index = Index | (indxW << 16);
789 Index = Index | (nbW << 20);
790 Index = Index | (indxF << 24);
791 aName.Index(Index);
792 //------------------------------
793 // Compute the TNaming_NamedShape
794 //------------------------------
795 aFNaming->Regenerate(MDF.ChangeValid());
796 aFNaming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
797 Handle (TNaming_NamedShape) Until = TNaming_Tool::NamedShape(Context,NS->Label());
798 Handle (TNaming_NamedShape) Stop = NextModif(Until);
799 if (Compare (NS,MDF,Stop,S)) return 1;
800 break;
801 }
802 }
803 }
804 }
805 return 0;
806 }
807 }
808#endif
809
810 //-----------------------------------------------------
811 // Construction function de naming. et insertion sous F
812 //-----------------------------------------------------
813 Handle (TNaming_Naming) NF = TNaming_Naming::Insert (F);
814
815 Handle (TNaming_NamedShape) Until = TNaming_Tool::NamedShape(Context,NS->Label());
816 Handle (TNaming_NamedShape) Stop = NextModif(Until);
817 TNaming_Name& theName = NF->ChangeName();
818 theName.ShapeType(S.ShapeType());
819 theName.Shape(S);
820 theName.Type(TNaming_FILTERBYNEIGHBOURGS);
821 theName.Append(NS);
822 theName.StopNamedShape (Until);
823#ifdef MDTV_DEB_NBS
824 cout << "FilterByNBS: ";
825 Print_Entry(NF->Label());
826#endif
827 //---------------------
828 // Naming des voisins.
829 //---------------------
830
831 TopTools_MapIteratorOfMapOfShape itN(Neighbourg);
832 for (; itN.More(); itN.Next()) {
833#ifdef ALLOW_CHILD_NBS
834 const TopoDS_Shape& aS = itN.Key();
835 Handle (TNaming_NamedShape) aNS =
836 BuildName(NF->Label(), MDF, aS, Context, Stop, 1);
837#ifdef MDTV_DEB_NBS
838 const TopoDS_Shape& aS2 = aNS->Get();
839 if(!aS.IsNull())
840 cout << "Shape arg type = " << aS.ShapeType() <<" TSH = " << aS.TShape()->This()<<endl;
841 if(!aS2.IsNull())
842 cout << "Build shape type = " << aS2.ShapeType() <<" TSH = " << aS2.TShape()->This()<<endl;
843#endif
844
845 const TopoDS_Shape aSNS = aNS->Get(); //allow child level
846 Standard_Boolean allowChild(Standard_True);
847 if(!aSNS.IsNull() && aSNS.ShapeType() == TopAbs_COMPOUND && !aFatherCandSh.IsNull())
848 allowChild = !IsContSame(aFatherCandSh, aSNS);
849 if(allowChild && !aSNS.IsNull() && aS.ShapeType() != aSNS.ShapeType() &&
850 aSNS.ShapeType() == TopAbs_COMPOUND)
851 { // aLev < 3
852#ifdef MDTV_DEB_NBS
853 cout <<"Father label = ";
854 Print_Entry(aNS->Label().Father());
855 Write(aS,"SelectionS.brep");
856 Write(aSNS,"SelectionSNS.brep");
857#endif
858 Handle(TNaming_Naming) aNaming;
859 Standard_Boolean StandardFilter(Standard_True);
860 aNS->FindAttribute(TNaming_Naming::GetID(), aNaming);
861 if(!aNaming.IsNull()) {
862 const TNaming_Name& aName = aNaming->GetName();
863 if (aName.Type() == TNaming_GENERATION)
864 StandardFilter = Standard_False;
865 if(StandardFilter)
866 if (!Compare (aNS,MDF,Stop,aS)) {
867 TNaming_Localizer aLocalizer;
868 Filter (NF->Label(), MDF,aS,Context, aLocalizer,aNS, aLev);
869 }
870 }
871 }
872 theName.Append(aNS);
873#else
874 theName.Append(BuildName(NF->Label(), MDF, itN.Key(), Context, Stop, 1));
875#endif
876 }
877 //------------------------------
878 // Compute the TNaming_NamedShape
879 //------------------------------
880 NF->Regenerate(MDF.ChangeValid());
881 NF->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
882
883 //-----------------
884 // Check du filtre.
885 //-----------------
886 if (Compare (NS,MDF,Stop,S)) return 1;
887#ifdef MDTV_DEB
888 cout <<"TNaming_Naming::Name Filter insufficient"<<endl;
889#endif
890 return 0;
891}
892
893
894//=======================================================================
895//function : BuildNameInNS
896//purpose : Calls BuildName method, but with new context and new stop shape.
897// : Context is searched at the father label of the "Context" label :
898// : old shapes from the NamedShape at the defined father label.
899// : If it's impossible, then "S" set as context.
900// : If "S" is in new context, then stop shape is named shape,
901// : which belongs to the father label of the "Context" named shape.
902// : For example, face (F2) of prism (P) is generated from the edge (E)
903// : of primitive face (F1) of box (B). F2 is named as GENERATION from E.
904// : Naming of E is done with help BuildNameInNS function:
905// : with context B and stop shape P.
906//=======================================================================
907static Handle(TNaming_NamedShape) BuildNameInNS (const TDF_Label& F,
908 TNaming_Scope& MDF,
909 const TopoDS_Shape& S,
910 const Handle(TNaming_NamedShape)& Context,
911 const Handle(TNaming_NamedShape)& Stop,
912 const Standard_Boolean Geometry)
913
914{
915 // il faut determiner un nouveau context et un nouveau Stop.
916 // it is necessary to determine new a context and a new Stop
917 TopoDS_Shape SC;
918 Handle(TNaming_NamedShape) NewStop = Stop;
919
920 TNaming_Localizer::FindShapeContext (Context,S,SC);
921
922 if(!SC.IsNull()){
923// <Context> is Ident.NamedShapeOfGeneration() ==
924 TDF_Label Father = Context->Label().Father();
925 Father.FindAttribute(TNaming_NamedShape::GetID(),NewStop);
926#ifdef MDTV_DEB_INNS
927 if(!Stop.IsNull())
928 {cout <<" Stop NS : "; Print_Entry( Stop->Label());}
929 if(!NewStop.IsNull())
930 {cout <<" NewStop : "; Print_Entry( NewStop->Label());}
931 cout <<"ContextLabel: "; Print_Entry( Context->Label());
932 cout <<"Father : "; Print_Entry( Father);
933#endif
934 }
935#ifdef MDTV_DEB_INNS
936 if(NewStop.IsNull())
937 cout <<"BuildNameInNS:: NewStop shape is NULL" << endl;
938#endif
939 return BuildName (F,MDF,S,SC,NewStop,Geometry);
940}
941
942//=======================================================================
943//function :
944//purpose :
945//=======================================================================
946
947static Handle(TNaming_NamedShape) BuildName (const TDF_Label& F,
948 TNaming_Scope& MDF,
949 const TopoDS_Shape& Selection,
950 const TopoDS_Shape& Context,
951 const Handle(TNaming_NamedShape)& Stop,
952 const Standard_Boolean Geom)
953{
954
955
956
957 // Create an identifier
958 Standard_Boolean OnlyOne = !Geom;
959 Standard_Boolean IsGeneration = Standard_False;
960#ifdef MDTV_DEB_MOD
961 cout <<"BuildName: F => ";
962 Print_Entry(F);
963 cout <<" Selection type = " << Selection.ShapeType() << " TS = " << Selection.TShape()->This() << endl;
964 Write(Selection, "BName_Selection.brep");
965 Write(Context, "BName_Context.brep");
966#endif
967 TNaming_Identifier Ident(F, Selection, Context,OnlyOne);
968
969 Handle (TNaming_Naming) Naming;
970 Handle (TNaming_NamedShape) NS;
971
972 if (!Ident.IsDone()) {
973 return BuildNS (F,Selection, TNaming_UNKNOWN);
974 }
975 if (Ident.IsFeature() && Stop.IsNull()) {
976 //-------------
977 // Deja Nomme
978 //-------------
979 if (!OnlyOne) return Ident.FeatureArg();
980 else NS = Ident.FeatureArg();
981 }
982 else {
983 //---------------------------------------------
984 // Construction de la fonction d identification.
985 //---------------------------------------------
986 //Standard_Boolean NotOnlyOne = 0;
987
988 Naming = TNaming_Naming::Insert(F);
989
990 TNaming_Name& theName = Naming->ChangeName();
991 theName.ShapeType(Selection.ShapeType());
992 theName.Shape(Selection);
993 theName.Type(Ident.Type());
994#ifdef MDTV_DEB_MOD
995 cout <<"BuildName: Inserted Naming Att at ";
996 Print_Entry(Naming->Label());
997 cout <<" NameType = " << theName.Type() <<endl;
998#endif
999 if (Ident.IsFeature()) {
1000 theName.Append(Ident.FeatureArg());
1001 }
1002 if (theName.Type() == TNaming_GENERATION) {
1003 theName.Append(Ident.NamedShapeOfGeneration());
1004 IsGeneration = Standard_True;
1005 }
1006 if (theName.Type() == TNaming_CONSTSHAPE) {
1007 theName.Index(FindIndex(Ident.FeatureArg(),Selection));
1008 }
1009 //------------------------------------
1010 // Renseignement du NamedShape d arret.
1011 //------------------------------------
1012 theName.StopNamedShape (Stop);
1013#ifdef MDTV_DEB_MOD
1014 if(!Stop.IsNull()) {
1015 TCollection_AsciiString Es;
1016 TDF_Tool::Entry(Stop->Label(), Es);
1017 cout <<"StopNS at Label = "<< Es << endl;
1018 }
1019#endif
1020 //---------------------------------
1021 // Identification des arguments.
1022 //---------------------------------
1023
1024 for (Ident.InitArgs(); Ident.MoreArgs(); Ident.NextArg()) {
1025 if (Ident.ArgIsFeature()) {
1026 theName.Append(Ident.FeatureArg());
1027#ifdef MDTV_DEB_MOD
1028 if(!Ident.FeatureArg().IsNull()) {
1029 TCollection_AsciiString E;
1030 TDF_Tool::Entry(Ident.FeatureArg()->Label(), E);
1031 cout <<"Added argument NS from Label = "<< E << endl;
1032 }
1033#endif
1034 }
1035 else {
1036#ifdef MDTV_DEB_MOD
1037 cout <<"BuildName: NameType = " <<theName.Type() << " NS ";
1038 Print_Entry(Naming->Label());
1039 cout <<"Ident.ShapeArg() type = " << Ident.ShapeArg().ShapeType() << " TS = " << Ident.ShapeArg().TShape()->This() << endl;
1040 Write(Ident.ShapeArg(), "BName_ShapeArg.brep");
1041#endif
1042 if (theName.Type() == TNaming_GENERATION)
1043 theName.Append(BuildNameInNS(Naming->Label(),MDF,Ident.ShapeArg(),Ident.NamedShapeOfGeneration(),Stop,Geom));
1044 else
1045 theName.Append(BuildName(Naming->Label(),MDF,Ident.ShapeArg(),Context,Stop,Geom));
1046 }
1047 }
1048
1049 //------------------------
1050 // Reconstruction of Name
1051 //------------------------
1052 Naming->Regenerate(MDF.ChangeValid());
1053#ifdef MDTV_DEB_MOD
1054 TCollection_AsciiString E2;
1055 TDF_Tool::Entry(Naming->Label(), E2);
1056 cout <<"Regenerated Naming Att at Label = "<< E2 << endl;
1057#endif
1058 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1059 if(NS.IsNull()) return NS;
1060 if (MDF.WithValid()) MDF.Valid(NS->Label());
1061#ifdef MDTV_DEB_MOD
1062 if(!NS.IsNull()) {
1063 TCollection_AsciiString E;
1064 TDF_Tool::Entry(NS->Label(), E);
1065 cout <<"Regenerated NS at Label = "<< E << endl;
1066 }
1067#endif
1068 }
1069
1070 if (OnlyOne) {
1071 //-------------------------------------------------
1072 // Filtre par les voisins
1073 // pour construire le nom correspondant a S.
1074 //-------------------------------------------------
1075
1076#ifdef OCC273
1077 if(NS.IsNull()) return NS;
1078#endif
1079
1080 TNaming_Localizer Localizer;
1081 TNaming_Iterator itNS(NS);
1082 if (itNS.More()) {
1083 //----------------
1084 // Check + Filtre
1085 //----------------
1086
1087#ifdef OCC350
1088
1089 Standard_Boolean StandardFilter = !IsGeneration;
1090 if (IsGeneration) {
1091 if (!CompareInGeneration (NS,Selection)) {
1092
1093 TopoDS_Shape NewContext;
1094 Handle(TNaming_NamedShape) NewStop;
1095 FindNewShapeInFather (Ident.NamedShapeOfGeneration(),NewContext);
1096 Filter (F,MDF,Selection,NewContext,Localizer,NS,0);
1097 }
1098 } else if (Ident.Type() == TNaming_MODIFUNTIL ||
1099 (Ident.Type() == TNaming_INTERSECTION && Naming->ChangeName().Arguments().Extent() == 1)) {
1100#ifdef MDTV_DEB_MOD
1101 cout <<"BuildName(CompareInModification): NameType = " <<Ident.Type() << " NS ";
1102 Print_Entry(Ident.Type() == TNaming_MODIFUNTIL ? NS->Label() : Naming->ChangeName().Arguments().First()->Label());
1103 cout <<"Selection type = " << Selection.ShapeType() << " TS = " << Selection.TShape()->This() << endl;
1104#endif
1105 Handle(TNaming_NamedShape) NewNS =
1106 CompareInModification(Ident.Type() == TNaming_MODIFUNTIL ? NS : Naming->ChangeName().Arguments().First(), Selection);
1107 if (!NewNS.IsNull()) { // there is need to describe name in detail: modification with type 1:n in the same label
1108 StandardFilter = Standard_False;
1109 if (Ident.IsFeature()) { // for MODIFUNTIL: change it to the GENERATION
1110 Naming = TNaming_Naming::Insert(F);
1111 TNaming_Name& theName = Naming->ChangeName();
1112 theName.ShapeType(Selection.ShapeType());
1113 theName.Shape(Selection); //szy 21.10.03
1114 theName.Type(TNaming_GENERATION);
1115 theName.Append(TNaming_Tool::NamedShape(Selection,F));
1116 theName.Append(NewNS);
1117 Naming->Regenerate(MDF.ChangeValid());
1118 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1119
1120 }
1121 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1122 }
1123 }
1124 if (StandardFilter) if (!Compare (NS,MDF,Stop,Selection)) {
1125 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1126 }
1127
1128#else
1129
1130 if (IsGeneration) {
1131 if (!CompareInGeneration (NS,Selection)) {
1132 TopoDS_Shape NewContext;
1133 Handle(TNaming_NamedShape) NewStop;
1134 FindNewShapeInFather (Ident.NamedShapeOfGeneration(),NewContext);
1135 Filter (F,MDF,Selection,NewContext,Localizer,NS,0);
1136 }
1137 }
1138 else {
1139 if (!Compare (NS,MDF,Stop,Selection))
1140 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1141 }
1142
1143#endif
1144
1145 }
1146 }
1147 if (MDF.WithValid()) MDF.Valid(NS->Label());
1148#ifdef MDTV_DEB_MOD
1149 if(!NS.IsNull()) {
1150 TCollection_AsciiString E;
1151 TDF_Tool::Entry(NS->Label(), E);
1152 cout <<"Returned NS from Label = "<< E << endl;
1153 }
1154#endif
1155 return NS;
1156}
1157
1158//=======================================================================
1159//function : Validate
1160//purpose :
1161//=======================================================================
1162
1163static void Validate(TNaming_Scope& MDF,
1164 TNaming_OldShapeIterator& it)
1165{
1166 MDF.Valid(it.Label());
1167 MDF.ValidChildren(it.Label());
1168
1169 TNaming_OldShapeIterator it2(it);
1170 for (; it2.More(); it2.Next()) {
1171 Validate (MDF,it2);
1172 }
1173}
1174
1175//=======================================================================
1176//function : UnValidate
1177//purpose :
1178//=======================================================================
1179
1180static void UnValidate(TNaming_Scope& MDF,
1181 TNaming_NewShapeIterator& it)
1182{
1183 MDF.Unvalid(it.Label());
1184 MDF.UnvalidChildren(it.Label());
1185
1186 TNaming_NewShapeIterator it2(it);
1187 for (; it2.More(); it2.Next()) {
1188 UnValidate (MDF,it2);
1189 }
1190}
1191
1192//=======================================================================
1193//function : BuildScope
1194//purpose : adds to the MDF the label of <Context> NamedShape,
1195// : its children, all its oldShapes and its children.
1196// : unvalidates all newShapes and it's children.
1197// : If <Context> is null or next modification has an empty newShape
1198// : ( this shape was deleted ), then MDF.WithValid(Standard_False)
1199// : and nothing is added to the scope.
1200//=======================================================================
1201
1202static void BuildScope (TNaming_Scope& MDF,
1203 const TopoDS_Shape& Context,
1204 const TDF_Label& Acces)
1205{
1206 if (Context.IsNull()) {
1207 MDF.WithValid(Standard_False);
1208 return;
1209 }
1210
1211 //----------------------------------------------------
1212 // Is context the current state
1213 //----------------------------------------------------
1214 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(Context,Acces);
1215 Handle(TNaming_NamedShape) Next = NextModif(NS); // if NS has subsequent evolution = MODIFY, return it
1216 if (Next.IsNull()) {
1217 MDF.WithValid(Standard_False);
1218 return;
1219 }
1220 //-----------------------------
1221 // a posteriori naming
1222 //-----------------------------
1223 MDF.WithValid(Standard_True);
1224 MDF.Valid(NS->Label());
1225 MDF.ValidChildren(NS->Label());
1226 TNaming_OldShapeIterator it(Context,Acces);
1227
1228 for (; it.More(); it.Next()) {
1229 Validate(MDF,it);
1230 }
1231
1232 TNaming_NewShapeIterator it2(Context,Acces);
1233 for (;it2.More(); it2.Next()) {
1234 UnValidate (MDF,it2);
1235 }
1236}
1237
1238//=======================================================================
1239static Standard_Boolean HasAncFace(const TopoDS_Shape& Context,
1240 const TopoDS_Shape& W, TopoDS_Shape& Face)
1241{
1242 Standard_Boolean hasFace(Standard_False);
1243 if(W.ShapeType() != TopAbs_WIRE)
1244 return hasFace;
1245 TopExp_Explorer exp(Context, TopAbs_FACE);
1246 for(;exp.More(); exp.Next()) {
1247 for (TopoDS_Iterator it(exp.Current()) ; it.More(); it.Next()) {
1248 if(it.Value().IsEqual(W)) {// is the Wire ?
1249 Face = exp.Current();
1250 if(!Face.IsNull()) {
1251 hasFace = Standard_True;
1252 // cout << "HasAncFace: TS = " <<theFace.TShape()->This() <<endl;
1253 break;
1254 }
1255 }
1256 }
1257 if(hasFace) break;
1258 }
1259 return hasFace;
1260}
1261
1262//=======================================================================
1263//function : BuildNameWire
1264//purpose : Names Wire
1265//=======================================================================
1266
1267static Handle(TNaming_NamedShape) BuildNameWire (const TDF_Label& F,
1268 TNaming_Scope& MDF,
1269 const TopoDS_Shape& Selection,
1270 const TopoDS_Shape& Context,
1271 const Handle(TNaming_NamedShape)& Stop,
1272 const Standard_Boolean Geom)
1273{
1274 Handle (TNaming_NamedShape) NS;
1275 Standard_Boolean found(Standard_False);
1276 Handle (TNaming_Naming) Naming;
1277 if(!F.FindAttribute(TNaming_Naming::GetID(), Naming)) {
1278 Naming = new TNaming_Naming ();
1279 F.AddAttribute (Naming);
1280 TNaming_Name& theName = Naming->ChangeName();
1281 theName.ShapeType(Selection.ShapeType());
1282 theName.Shape(Selection);
1283 }
1284
1285 TNaming_Name& theName = Naming->ChangeName();
1286 TopoDS_Shape aFace;
1287 Standard_Boolean hasFace = HasAncFace(Context, Selection, aFace);
1288 if(Selection.ShapeType() == TopAbs_WIRE && Context.ShapeType() < Selection.ShapeType() && hasFace) {
1289 theName.Type(TNaming_WIREIN);
1290 if(Context.ShapeType() == TopAbs_FACE) {
1291 for (TopoDS_Iterator it(Context) ; it.More(); it.Next()) {
1292 if(it.Value().IsEqual(Selection)) {
1293 if (TNaming_Selector::IsIdentified (F, Context, NS, Geom)) {
1294 theName.Append(NS);
1295 found = Standard_True;
1296 break;
1297 }
1298 }
1299 }
1300 if(!found)
1301 return BuildNS (F,Selection, TNaming_UNKNOWN);
1302 } else {
1303 Standard_Integer indx(0), i(0);
1304 for (TopoDS_Iterator it(aFace); it.More(); it.Next()) {
1305 i++;
1306 if(it.Value().IsEqual(Selection)) {
1307 found = Standard_True;
1308 theName.Append(BuildName (Naming->Label(),MDF,aFace,Context,Stop,Geom));
1309 indx = i;
1310 }
1311 }
1312 if(found) {
1313 const Standard_Integer num(i);
1314 indx = indx | num << 8;
1315 //cout << " final Index = " << indx <<endl;
1316 theName.Index(indx);
1317 } else
1318 return BuildNS (F,Selection, TNaming_UNKNOWN);
1319 }
1320 }
1321 else {
1322 theName.Type(TNaming_UNION);
1323 for (TopExp_Explorer exp(Selection,TopAbs_EDGE) ; exp.More(); exp.Next()) {
1324 if(exp.Current().IsNull()) continue;
1325 if (BRep_Tool::Degenerated(TopoDS::Edge(exp.Current()))) continue;//03.03.2010
1326 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1327 }
1328 }
1329 //Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1330 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1331 return NS;
1332}
1333
1334//=======================================================================
1335static Standard_Boolean IsOneIn (const TopoDS_Shape& S, const TopoDS_Shape& Context)
1336{
1337 Standard_Boolean found(Standard_False);
1338 if(S.IsNull() || Context.IsNull()) return found;
1339 for (TopExp_Explorer exp(Context,S.ShapeType()); exp.More(); exp.Next()) {
1340 if (exp.Current().IsEqual(S)) {
1341 found = Standard_True;
1342 break;
1343 }
1344 }
1345 return found;
1346}
1347
1348//=======================================================================
1349static Standard_Boolean IsAllIn (const TopoDS_Shape& S, const TopoDS_Shape& Context)
1350{
1351#ifdef MDTV_DEB_CC
1352 Write(S, "IsAllIn_Sel.brep");
1353#endif
1354 Standard_Boolean found(Standard_False);
1355 if(S.IsNull() || Context.IsNull()) return found;
1356 Standard_Integer num1(0), num2(0);
1357 for(TopoDS_Iterator it(S);it.More();it.Next(),num1++) {
1358#ifdef MDTV_DEB_CC
1359 cout <<"S sub-shape type = " << it.Value().ShapeType() <<endl;
1360 Write (it.Value(), "Sel_ItValue.brep");
1361#endif
1362 if(it.Value().ShapeType() != TopAbs_COMPOUND)
1363 for (TopExp_Explorer exp(Context,it.Value().ShapeType()); exp.More(); exp.Next()) {
1364#ifdef MDTV_DEB_CC
1365 cout <<"Context sub-shape type = " << exp.Current().ShapeType() <<endl;
1366 Write(exp.Current(), "Contex_Curnt.brep");
1367#endif
1368 if (exp.Current().IsEqual(it.Value())) {
1369 num2++;
1370 break;
1371 }
1372 } else {
1373 Standard_Boolean isAll = IsAllIn(it.Value(), Context);
1374 if(isAll)
1375 num2++;
1376 }
1377 }
1378 if(num1 == num2)
1379 found = Standard_True;
1380#ifdef MDTV_DEB_CC
1381 else
1382 cout <<"Compound case : selected num1 = " << num1 << " context contains num2 = " << num2 << endl;
1383#endif
1384 return found;
1385}
1386//=======================================================================
1387//function : RepeatabilityInContext
1388//purpose :
1389//=======================================================================
1390static Standard_Integer RepeatabilityInContext(const TopoDS_Shape& Selection,
1391 const TopoDS_Shape& Context)
1392{
1393 Standard_Integer aNum(0);
1394 if (!Context.IsNull() && !Selection.IsNull()) {
1395// Write(Selection, "Repeat_Selection.brep");
1396// Write(Context, "Repeat_Context.brep");
1397 if (Context.ShapeType() < Selection.ShapeType()) {
1398 for (TopExp_Explorer exp(Context,Selection.ShapeType()); exp.More(); exp.Next()) {
1399 if (exp.Current().IsSame(Selection))
1400 aNum++;
1401 }
1402 }
1403 else if(Selection.ShapeType() == TopAbs_COMPOUND) {
1404 TopoDS_Iterator it(Selection);
1405 for(;it.More();it.Next()) {
1406 Standard_Integer n(0);
1407 for (TopExp_Explorer exp(Context,it.Value().ShapeType()); exp.More(); exp.Next()) {
1408 if (exp.Current().IsSame(it.Value())) {
1409 n++;
1410 }
1411 }
1412 if(n > aNum) aNum = n;
1413 }
1414 }
1415 }
1416#ifdef MDTV_DEB_OR
1417 cout <<"RepeatabilityInContext: = " <<aNum <<endl;
1418#endif
1419 return aNum;
1420}
1421//=======================================================================
1422//function : BuildAggregationNam
1423//purpose :
1424//=======================================================================
1425static void BuildAggregationName (const TDF_Label& F,
1426 TNaming_Scope& MDF,
1427 const TopoDS_Shape& S,
1428 const TopoDS_Shape& Context,
1429 const Handle(TNaming_NamedShape)& Stop,
1430 const Standard_Boolean Geom)
1431{
1432 const Standard_Boolean found2 = IsAllIn(S, Context);
1433 Handle (TNaming_Naming) Naming;
1434 if(!F.FindAttribute(TNaming_Naming::GetID(), Naming)) {
1435 Naming = new TNaming_Naming ();
1436 F.AddAttribute (Naming);
1437 TNaming_Name& theName = Naming->ChangeName();
1438 theName.ShapeType(S.ShapeType());
1439 theName.Shape(S);
1440 }
1441#ifdef MDTV_DEB_CC
1442 cout <<"BuildAggregationName ==> ";
1443 Print_Entry(Naming->Label());
1444#endif
1445 TNaming_Name& theName = Naming->ChangeName();
1446 for (TopoDS_Iterator itc(S) ; itc.More(); itc.Next()) {
1447 const TopoDS_Shape& aS = itc.Value();
1448 if ((aS.ShapeType() == TopAbs_SOLID && !TNaming_Tool::NamedShape(aS,Naming->Label()).IsNull()) ||
1449 aS.ShapeType() == TopAbs_FACE ||
1450 aS.ShapeType() == TopAbs_EDGE ||
1451 aS.ShapeType() == TopAbs_VERTEX ) {
1452 theName.Append(BuildName (F, MDF, aS,Context,Stop,Geom));
1453 } else { // ==> union of union || union of wires
1454 TopAbs_ShapeEnum atomTyp;
1455 switch (aS.ShapeType())
1456 {
1457 case TopAbs_SOLID:
1458 case TopAbs_SHELL:
1459 atomTyp = TopAbs_FACE;
1460 break;
1461 case TopAbs_WIRE:
1462 atomTyp = TopAbs_EDGE;
1463 break;
1464 default:
1465 atomTyp = TopAbs_SHAPE;
1466 }
1467
1468 Handle(TNaming_NamedShape) aNS;
1469 Handle (TNaming_Naming) aNaming = TNaming_Naming::Insert(F);
1470 TNaming_Name& aName = aNaming->ChangeName();
1471 aName.ShapeType(aS.ShapeType());
1472 aName.Shape(aS);
1473 aName.Type(TNaming_UNION);
1474
1475 if (atomTyp != TopAbs_SHAPE) {
1476 if(aS.ShapeType() == TopAbs_WIRE) {
1477 aNS = BuildNameWire (aNaming->Label(), MDF, aS, Context,Stop,Geom);
1478 }
1479 else {
1480 for (TopExp_Explorer exp(aS,atomTyp) ; exp.More(); exp.Next()) {
1481 aName.Append(BuildName (aNaming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1482 }
1483 }
1484 } else {
1485#ifdef MDTV_DEB_CC
1486 cout << "atomic type is NOT defined ... ==> Aggregation" <<endl;
1487#endif
1488 BuildAggregationName(aNaming->Label(),MDF, aS, Context,Stop,Geom);
1489 }
1490 if(found2) {
1491 aNS = TNaming_Tool::NamedShape(Context, F);
1492 if(!aNS.IsNull())
1493 aNaming->ChangeName().ContextLabel(aNS->Label());
1494 }
1495
1496 aNaming->GetName().Solve(aNaming->Label(),MDF.GetValid());
1497 if(aNaming->Label().FindAttribute(TNaming_NamedShape::GetID(),aNS))
1498 if (!Geom && TestSolution(MDF,aNS,aS)) {
1499 theName.Append(aNS);
1500 }
1501 }
1502 }
1503}
1504
1505
1506//=======================================================================
1507//function : Name
1508//purpose :
1509//=======================================================================
1510
1511Handle(TNaming_NamedShape) TNaming_Naming::Name (const TDF_Label& F,
1512 const TopoDS_Shape& S,
1513 const TopoDS_Shape& Context,
1514 const Standard_Boolean Geom,
1515 const Standard_Boolean KeepOrientation,
1516 const Standard_Boolean BNProblem)
1517
1518{
1519 Handle(TNaming_NamedShape) NS;
1520 if (KeepOrientation) {
1521#ifdef MDTV_DEB_INNS
1522 cout <<"KeepOR = 1: "; Print_Entry(F);
1523#endif
1524 Standard_Integer aNum = RepeatabilityInContext(S, Context);
1525
1526 Standard_Boolean aBNproblem = (BNProblem) ? (aNum /*== 1*/ && S != Context) : Standard_False;
1527
1528 if (aNum > 1 || aBNproblem) {
1529 TopoDS_Shape UC = TNaming::FindUniqueContext(S, Context);
1530 Handle(TopTools_HArray1OfShape) Arr;
1531 if (UC.IsNull() && S.ShapeType() == TopAbs_COMPOUND) {
1532 UC = TNaming::FindUniqueContextSet(S, Context, Arr);
1533#ifdef MDTV_DEB_CC
1534 Write(UC, "UniqueContextSet.brep");
1535 Write(S, "InitialSelection.brep");
1536 if(S.ShapeType()==TopAbs_COMPOUND) {
1537 TCollection_AsciiString aNam("S_");
1538 TopoDS_Iterator it(S);
1539 for(int i=1;it.More();it.Next(),i++) {
1540 TCollection_AsciiString aName = aNam + i + ".brep";
1541 Write(it.Value(), aName.ToCString());
1542 }
1543 }
1544#endif
1545 }
1546 if(!UC.IsNull()) {
1547 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert(F);
1548 TNaming_Name& theName = Naming->ChangeName();
1549 theName.ShapeType(S.ShapeType());
1550 theName.Shape(S);
1551 theName.Type(TNaming_ORIENTATION);
1552
1553 if (!TNaming_Selector::IsIdentified (F, S, NS, Geom))
1554 NS = TNaming_Naming::Name(Naming->Label(),S,Context,Geom,0);
1555 theName.Append (NS);
1556#ifdef MDTV_OR
1557 cout << " Sel Label ==> "; Print_Entry(NS->Label());
1558#endif
1559//szy 21.10.2009
1560 if(S.ShapeType() == TopAbs_EDGE && UC.ShapeType() == TopAbs_FACE) {
1561 if(RepeatabilityInContext(S, UC) == 2) { //sim. edge
1562 TopoDS_Iterator itw(UC);
1563 for(;itw.More();itw.Next()) {
1564 Standard_Boolean found(Standard_False);
1565 TopoDS_Iterator it(itw.Value());
1566 for(int i=1;it.More();it.Next(),i++) {
1567 if(it.Value().IsEqual(S)) {
1568 theName.Index(i);
1569 found = Standard_True;
1570#ifdef MDTV_OR
1571 cout << "ORDER = " << i <<endl;
1572#endif
1573 break;
1574 }
1575 }
1576 if(found) break;
1577 }
1578 }
1579 }
1580//
1581 if(S.ShapeType() == TopAbs_COMPOUND && Arr->Length() > 1) {
1582 // N arguments: to be optimized to avoid duplication of the same Context shape
1583 for(Standard_Integer i = Arr->Lower(); i <= Arr->Upper(); i++) {
1584 NS = TNaming_Naming::Name(Naming->Label(), Arr->Value(i), Context, Geom, 1, aBNproblem);
1585 theName.Append (NS);
1586 }
1587 } else {
1588 NS = TNaming_Naming::Name(Naming->Label(),UC,Context, Geom, 1, aBNproblem);
1589 theName.Append (NS);
1590#ifdef MDTV_OR
1591 cout << " Cont Label ==> "; Print_Entry(NS->Label());
1592#endif
1593 }
1594 //Naming->Update();
1595 TNaming_Scope MDF;
1596 BuildScope (MDF,Context,F);
1597 Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1598 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1599 theName.ContextLabel(NS->Label());
1600 if (Geom) return NS;
1601 if(NS.IsNull()) {
1602 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1603 return BuildNS (F,S, TNaming_UNKNOWN);
1604 }
1605
1606 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1607 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1608
1609 // Naming n is unsatisfactory
1610 return BuildNS (F,S, TNaming_UNKNOWN);
1611 }
1612 } else
1613 if (TNaming_Selector::IsIdentified (F, S, NS, Geom))
1614 return NS;
1615 }
1616
1617 //------------------------------------------------------------
1618 // Construction du MDF tel que <Context> soit le dernier etat
1619 // valide,
1620 // Ceci pour les localisation a posteriori par exemple.
1621 //------------------------------------------------------------
1622
1623 TNaming_Scope MDF;
1624 BuildScope (MDF,Context,F);
1625 Handle(TNaming_NamedShape) Stop;
1626
1627#ifdef OCC352
1628
1629 if ((S.ShapeType() == TopAbs_SOLID && !TNaming_Tool::NamedShape(S,F).IsNull()) ||
1630
1631#else
1632
1633 if (S.ShapeType() == TopAbs_SOLID ||
1634
1635#endif
1636
1637 S.ShapeType() == TopAbs_FACE ||
1638 S.ShapeType() == TopAbs_EDGE ||
1639 S.ShapeType() == TopAbs_VERTEX ) {
1640 //---------------------------------------
1641 // Localisation de S comme element simple.
1642 //---------------------------------------
1643 Handle(TNaming_NamedShape) NS = BuildName (F,MDF,S,Context,Stop,Geom);
1644 if (Geom) return NS;
1645 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1646 }
1647 else {
1648 //----------------------------------------------------
1649 // Localisation de S comme ensemble d elements simples.
1650 //-----------------------------------------------------
1651 Handle(TNaming_NamedShape) NS;
1652 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert(F);
1653 TNaming_Name& theName = Naming->ChangeName();
1654
1655 theName.ShapeType(S.ShapeType());// modified by vro 05.09.00
1656 theName.Shape(S);
1657 if(S.ShapeType() != TopAbs_WIRE)
1658 theName.Type(TNaming_UNION);
1659
1660#ifdef OCC352
1661 TopAbs_ShapeEnum atomType;
1662 switch (S.ShapeType()) {
1663 case TopAbs_COMPSOLID:
1664 case TopAbs_SOLID:
1665 case TopAbs_SHELL:
1666 atomType = TopAbs_FACE;
1667 break;
1668 case TopAbs_WIRE:
1669 atomType = TopAbs_EDGE;
1670 break;
1671 default:
1672 atomType = TopAbs_SHAPE;
1673 }
1674 Standard_Boolean found(Standard_False);
1675 if (!Context.IsNull()) {
1676 if (Context.ShapeType() < S.ShapeType())
1677 found = IsOneIn(S, Context);
1678 if(found) {
1679 NS = TNaming_Tool::NamedShape(Context, F);
1680 if(!NS.IsNull())
1681 theName.ContextLabel(NS->Label());
1682 }
1683 }
1684 if (atomType == TopAbs_SHAPE) {
1685 if(S.ShapeType() == TopAbs_COMPOUND) {
1686 BuildAggregationName(Naming->Label(),MDF, S, Context,Stop,Geom);
1687 } else {
1688 for (TopoDS_Iterator it(S) ; it.More(); it.Next()) {
1689 theName.Append(BuildName (Naming->Label(),MDF,it.Value(),Context,Stop,Geom));
1690 }
1691 }
1692 } else {
1693 if(S.ShapeType() == TopAbs_WIRE)
1694 NS = BuildNameWire (Naming->Label(), MDF, S, Context,Stop,Geom);
1695 else {
1696 theName.Type(TNaming_UNION);
1697 for (TopExp_Explorer exp(S,atomType) ; exp.More(); exp.Next()) {
1698 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1699 }
1700 }
1701 }
1702#else
1703 for (TopoDS_Iterator it(S) ; it.More(); it.Next()) {
1704 theName.Append(BuildName (Naming->Label(),MDF,it.Value(),Context,Stop,Geom));
1705 }
1706#endif
1707
1708 //Naming->Update();
1709 Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1710 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1711 if (Geom) return NS;
1712
1713#ifdef OCC273
1714 if(NS.IsNull()) return BuildNS (F,S, TNaming_UNKNOWN);
1715#endif
1716
1717 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1718 }
1719
1720 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1721
1722 // Naming n is not satisfactory
1723 return BuildNS (F,S, TNaming_UNKNOWN);
1724}
1725
1726
1727//=======================================================================
1728//function : TNaming_Naming
1729//purpose :
1730//=======================================================================
1731
1732TNaming_Naming::TNaming_Naming() {}
1733
1734//=======================================================================
1735//function : ID
1736//purpose :
1737//=======================================================================
1738
1739const Standard_GUID& TNaming_Naming::ID () const
1740{
1741 return GetID();
1742}
1743
1744
1745//=======================================================================
1746//function : IsDefined
1747//purpose :
1748//=======================================================================
1749
1750Standard_Boolean TNaming_Naming::IsDefined() const
1751{
1752 return (myName.Type() != TNaming_UNKNOWN);
1753}
1754
1755//=======================================================================
1756//function : GetName
1757//purpose :
1758//=======================================================================
1759
1760const TNaming_Name& TNaming_Naming::GetName() const
1761{
1762 return myName;
1763}
1764
1765//=======================================================================
1766//function : ChangeName
1767//purpose :
1768//=======================================================================
1769
1770TNaming_Name& TNaming_Naming::ChangeName()
1771{
1772 return myName;
1773}
1774
1775//=======================================================================
1776//function : Regenerate
1777//purpose : idem designer
1778//=======================================================================
1779
1780Standard_Boolean TNaming_Naming::Regenerate (TDF_LabelMap& MDF)
1781
1782{
1783 return myName.Solve(Label(),MDF);
1784}
1785
1786
1787//=======================================================================
1788//function : NewEmpty
1789//purpose :
1790//=======================================================================
1791
1792Handle(TDF_Attribute) TNaming_Naming::NewEmpty () const
1793{
1794 return new TNaming_Naming ();
1795}
1796
1797
1798//=======================================================================
1799//function : Restore
1800//purpose :
1801//=======================================================================
1802
1803void TNaming_Naming::Restore(const Handle(TDF_Attribute)& other)
1804{
1805 Handle(TNaming_Naming) OtherNaming = Handle(TNaming_Naming)::DownCast(other);
1806 myName = OtherNaming->ChangeName();
1807}
1808
1809//=======================================================================
1810//function : Paste
1811//purpose :
1812//=======================================================================
1813
1814void TNaming_Naming::Paste (const Handle(TDF_Attribute)& into,
1815 const Handle(TDF_RelocationTable)& RT) const
1816{
1817 Handle(TNaming_Naming) NewNaming = Handle(TNaming_Naming)::DownCast(into);
1818 myName.Paste(NewNaming->ChangeName(),RT);
1819}
1820
1821//=======================================================================
1822//function : References
1823//purpose : Redefined from TDF_Attribute
1824//=======================================================================
1825
1826void TNaming_Naming::References(const Handle(TDF_DataSet)& DataSet) const
1827{
1828 // Iteration on NamedShape of the name
1829 TNaming_ListIteratorOfListOfNamedShape it(myName.Arguments());
1830 for (;it.More();it.Next()) DataSet->AddAttribute(it.Value());
1831 if (!myName.StopNamedShape().IsNull()) DataSet->AddAttribute(myName.StopNamedShape());
1832}
1833//=======================================================================
1834//function : Dump
1835//purpose :
1836//=======================================================================
1837
1838Standard_OStream& TNaming_Naming::Dump (Standard_OStream& anOS) const
1839{
1840 anOS << "TNaming_Naming";
1841 return anOS;
1842}
1843
1844
1845//=======================================================================
1846//function :ExtendedDump
1847//purpose :
1848//=======================================================================
1849
1850void TNaming_Naming::ExtendedDump(Standard_OStream& anOS,
1851 const TDF_IDFilter& /*aFilter*/,
1852 TDF_AttributeIndexedMap& /*aMap*/) const
1853{
1854 anOS << "TNaming_Naming ExtendedDump ";
1855 //anOS<<"myContext: #" <<aMap.Add(myContext)<<endl;
1856}
1857