0029151: GCC 7.1 warnings "this statement may fall through" [-Wimplicit-fallthrough=]
[occt.git] / src / TNaming / TNaming_Name.cxx
CommitLineData
b311480e 1// Created on: 1997-03-21
2// Created by: Yves FRICAUD
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
7fd59977 18#include <BRep_Builder.hxx>
42cf5bc1 19#include <BRepBuilderAPI_MakeFace.hxx>
20#include <BRepBuilderAPI_MakeSolid.hxx>
21#include <BRepBuilderAPI_MakeWire.hxx>
1ec8a59e 22#include <BRepTools.hxx>
42cf5bc1 23#include <Standard_ConstructionError.hxx>
24#include <Standard_ErrorHandler.hxx>
25#include <Standard_NotImplemented.hxx>
26#include <TColStd_Array1OfInteger.hxx>
7fd59977 27#include <TDF_Label.hxx>
28#include <TDF_LabelList.hxx>
29#include <TDF_LabelMap.hxx>
42cf5bc1 30#include <TDF_RelocationTable.hxx>
31#include <TNaming.hxx>
32#include <TNaming_Builder.hxx>
33#include <TNaming_Iterator.hxx>
34#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
35#include <TNaming_ListOfNamedShape.hxx>
36#include <TNaming_Name.hxx>
37#include <TNaming_NamedShape.hxx>
38#include <TNaming_Naming.hxx>
39#include <TNaming_NamingTool.hxx>
40#include <TNaming_NCollections.hxx>
41#include <TNaming_NewShapeIterator.hxx>
42#include <TNaming_ShapesSet.hxx>
7fd59977 43#include <TNaming_Tool.hxx>
42cf5bc1 44#include <TopExp.hxx>
45#include <TopExp_Explorer.hxx>
7fd59977 46#include <TopoDS.hxx>
7fd59977 47#include <TopoDS_Compound.hxx>
42cf5bc1 48#include <TopoDS_CompSolid.hxx>
49#include <TopoDS_Face.hxx>
7fd59977 50#include <TopoDS_Iterator.hxx>
42cf5bc1 51#include <TopoDS_Shape.hxx>
52#include <TopoDS_Shell.hxx>
53#include <TopoDS_Solid.hxx>
54#include <TopoDS_Wire.hxx>
55#include <TopTools_Array1OfShape.hxx>
56#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
57#include <TopTools_DataMapOfShapeListOfShape.hxx>
7fd59977 58#include <TopTools_HArray2OfShape.hxx>
42cf5bc1 59#include <TopTools_IndexedMapOfShape.hxx>
60#include <TopTools_ListIteratorOfListOfShape.hxx>
7fd59977 61#include <TopTools_ListOfShape.hxx>
42cf5bc1 62#include <TopTools_MapIteratorOfMapOfShape.hxx>
63#include <TopTools_MapOfShape.hxx>
7fd59977 64
42cf5bc1 65// mpv modifications 08.04.2002
66// end of mpv modifications 08.04.2002
0797d9d3 67#ifdef OCCT_DEBUG_DBGTOOLS_WRITE
4e18e72a 68#define MDTV_DEB
69#define MDTV_DEB_OR
70#define MDTV_DEB_UNN
71#define MDTV_DEB_INT
72#define MDTV_DEB_GEN
73#define MDTV_DEB_MODUN
74#define MDTV_DEB_FNB
75#define MDTV_DEB_WIN
76#define MDTV_DEB_ARG
77#define MDTV_DEB_SHELL
78#endif
0797d9d3 79#ifdef OCCT_DEBUG
7fd59977 80#include <TCollection_AsciiString.hxx>
81#include <TDF_Tool.hxx>
82#include <BRepTools.hxx>
7fd59977 83#endif
0797d9d3 84#ifdef OCCT_DEBUG
7fd59977 85#include <TCollection_AsciiString.hxx>
86#include <TDF_Tool.hxx>
87#include <TDF_ChildIterator.hxx>
88#include <TDF_MapIteratorOfLabelMap.hxx>
89//=======================================================================
90void PrintEntry(const TDF_Label& label)
91{
92 TCollection_AsciiString entry;
93 TDF_Tool::Entry(label, entry);
94 cout << "LabelEntry = "<< entry << endl;
95}
96//=======================================================================
97void PrintEntries(const TDF_LabelMap& map)
98{
99 cout << "=== Labels Map ===" <<endl;
100 TCollection_AsciiString entry;
101 TDF_MapIteratorOfLabelMap it(map);
102 for(;it.More();it.Next()) {
103 TDF_Tool::Entry(it.Key(), entry);
104 cout << "LabelEntry = "<< entry << endl;
105 }
106}
0797d9d3 107#ifdef OCCT_DEBUG_DBGTOOLS_WRITE
7fd59977 108//=======================================================================
109static void DbgTools_Write(const TopoDS_Shape& shape,
110 const Standard_CString filename)
111{
112 char buf[256];
113 if(strlen(filename) > 256) return;
114 strcpy (buf, filename);
115 char* p = buf;
116 while (*p) {
117 if(*p == ':')
118 *p = '-';
119 p++;
120 }
121 ofstream save (buf);
122 if(!save)
123 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
124 save << "DBRep_DrawableShape" << endl << endl;
125 if(!shape.IsNull()) BRepTools::Write(shape, save);
126 save.close();
127}
128//=======================================================================
0df87563 129static void DbgTools_Write(const TopTools_IndexedMapOfShape& MS, const Standard_CString filename)
7fd59977 130{
131 if (!MS.IsEmpty ()) {
132 TCollection_AsciiString aNam (filename);
0df87563 133 for (Standard_Integer anIt = 1; anIt <= MS.Extent(); ++anIt) {
134 TCollection_AsciiString aName = aNam + "_" + (anIt - 1) + ".brep";
135 DbgTools_Write (MS (anIt), aName.ToCString());
7fd59977 136 }
137 }
138}
139//=======================================================================
140static void DbgTools_WriteNSOnLabel (const Handle(TNaming_NamedShape)& NS,
141 const Standard_CString filename)
142{
143 if(!NS.IsNull() && !NS->IsEmpty() ) {
144 TCollection_AsciiString aNam (filename);
145 TCollection_AsciiString oldS ("_Old");
146 TCollection_AsciiString newS ("_New_");
147 Standard_Integer i(0);
148 TNaming_Iterator it(NS);
149 for(;it.More(); it.Next(),i++) {
150 TCollection_AsciiString aName1 = aNam + oldS + i + ".brep";
151 TCollection_AsciiString aName2 = aNam + newS + i + ".brep";
152 const TopoDS_Shape& oldShape = it.OldShape();
153 const TopoDS_Shape& newShape = it.NewShape();
154 if(!oldShape.IsNull())
155 DbgTools_Write ( oldShape, aName1.ToCString());
156 if(!newShape.IsNull())
157 DbgTools_Write ( newShape, aName2.ToCString());
158 }
159 }
160}
161#endif
4e18e72a 162#endif
7fd59977 163//
164//====================================================================
165static Standard_Boolean ValidArgs(const TNaming_ListOfNamedShape& Args)
166{
167 TNaming_ListIteratorOfListOfNamedShape it(Args);
168 for (;it.More();it.Next()) {
169 const Handle(TNaming_NamedShape)& aNS = it.Value();
170 if(aNS.IsNull()) {
0797d9d3 171#ifdef OCCT_DEBUG_ARG
7fd59977 172 cout << "ValidArgs:: NS (Naming argument) is NULL" <<endl;
173#endif
174 return Standard_False;
175 }
176 else
177 if(aNS->IsEmpty()) {
0797d9d3 178#ifdef OCCT_DEBUG_ARG
7fd59977 179 TCollection_AsciiString entry;
180 TDF_Tool::Entry(aNS->Label(), entry);
181 cout << "ValidArgs:: Empty NS, Label = " << entry <<endl;
182#endif
183 return Standard_False;
184 }
185 else
186 if(!aNS->IsValid()) {
0797d9d3 187#ifdef OCCT_DEBUG_ARG
7fd59977 188 TCollection_AsciiString entry;
189 TDF_Tool::Entry(aNS->Label(), entry);
190 cout << "ValidArgs::Not valid NS Label = " << entry <<endl;
191#endif
192 return Standard_False;
193 }
194 }
195 return Standard_True;
196}
197
198//=======================================================================
199//function : TNaming_Name
200//purpose :
201//=======================================================================
202
c24d4017 203TNaming_Name::TNaming_Name() :
204 myType(TNaming_UNKNOWN),
205 myIndex(-1)
7fd59977 206{
207}
208
209
210//=======================================================================
211//function : Type
212//purpose :
213//=======================================================================
214
215void TNaming_Name::Type(const TNaming_NameType aType)
216{
217 myType = aType;
218}
219
220//=======================================================================
221//function : Type
222//purpose :
223//=======================================================================
224
225void TNaming_Name::ShapeType(const TopAbs_ShapeEnum T)
226{
227 myShapeType = T;
228}
229
230//=======================================================================
231//function : Shape
232//purpose :
233//=======================================================================
234
235void TNaming_Name::Shape(const TopoDS_Shape& theShape)
236{
237 myShape = theShape;
238
239}
240
241//=======================================================================
242//function : Shape
243//purpose :
244//=======================================================================
245
246TopoDS_Shape TNaming_Name::Shape() const
247{
248 return myShape;
249}
250
251//=======================================================================
252//function : Append
253//purpose :
254//=======================================================================
255
256void TNaming_Name::Append(const Handle(TNaming_NamedShape)& arg)
257{
258 myArgs.Append (arg);
259}
260
261//=======================================================================
262//function : StopNamedShape
263//purpose :
264//=======================================================================
265
266void TNaming_Name::StopNamedShape (const Handle(TNaming_NamedShape)& arg)
267{
268 myStop = arg;
269}
270
271//=======================================================================
272//function : Index
273//purpose :
274//=======================================================================
275
276void TNaming_Name::Index (const Standard_Integer I)
277{
278 myIndex = I;
279}
280
281
282//=======================================================================
283//function : TNaming_NameType
284//purpose :
285//=======================================================================
286
287TNaming_NameType TNaming_Name::Type() const
288{
289 return myType;
290}
291
292//=======================================================================
293//function : TNaming_NameType
294//purpose :
295//=======================================================================
296
297TopAbs_ShapeEnum TNaming_Name::ShapeType() const
298{
299 return myShapeType;
300}
301
302//=======================================================================
f18ccc8c 303//function : Paste
7fd59977 304//purpose :
305//=======================================================================
306
307void TNaming_Name::Paste (TNaming_Name& into,
308 const Handle(TDF_RelocationTable)& RT) const
309{
310 into.myType = myType;
311 into.myShapeType = myShapeType;
f18ccc8c 312 into.myShape = myShape;
313 into.myIndex = myIndex;
7fd59977 314 into.myArgs.Clear();
315// into.myOrientation = myOrientation;
316 Handle(TNaming_NamedShape) NS;
317
318 for (TNaming_ListIteratorOfListOfNamedShape it(myArgs); it.More(); it.Next()) {
319 RT->HasRelocation(it.Value(),NS);
320 into.myArgs.Append (NS);
321 }
322 if (!myStop.IsNull()) {
323 RT->HasRelocation(myStop,NS);
324 into.myStop = NS;
325 }
326 if (!myContextLabel.IsNull()) {
327 RT->HasRelocation(myContextLabel,into.myContextLabel);
328 }
329}
330
331//=======================================================================
332//function : Arguments
333//purpose :
334//=======================================================================
335
336const TNaming_ListOfNamedShape& TNaming_Name::Arguments() const
337{
338 return myArgs;
339}
340
341//=======================================================================
342//function : Arguments
343//purpose :
344//=======================================================================
345
346Handle(TNaming_NamedShape) TNaming_Name::StopNamedShape() const
347{
348 return myStop;
349}
350
351//=======================================================================
352//function : Index
353//purpose :
354//=======================================================================
355
356Standard_Integer TNaming_Name::Index() const
357{
358 return myIndex;
359}
360
361//=======================================================================
362//function : MakeShape
363//purpose :
364//=======================================================================
365
0df87563 366static TopoDS_Shape MakeShape (const TopTools_IndexedMapOfShape& MS)
7fd59977 367{
368 if (!MS.IsEmpty ()) {
7fd59977 369 if (MS.Extent() == 1) {
0df87563 370 return MS (1);
7fd59977 371 }
372 else {
373 TopoDS_Compound C;
374 BRep_Builder B;
375 B.MakeCompound(C);
0df87563 376 for (Standard_Integer anIt = 1; anIt <= MS.Extent(); ++anIt)
377 B.Add (C, MS (anIt));
7fd59977 378 return C;
379 }
380 }
381 return TopoDS_Shape();
382}
383
7fd59977 384//=======================================================================
385//function : ShapeWithType
386//purpose : Tries to make shape with given type from the given shape
387//=======================================================================
388
389static TopoDS_Shape ShapeWithType(const TopoDS_Shape theShape,
390 const TopAbs_ShapeEnum theType ) {
391 if (theShape.IsNull() || theType == TopAbs_SHAPE) return theShape;
392 Standard_Integer aType = theShape.ShapeType();
393 if (aType == theType) return theShape;
394
395 TopTools_ListOfShape aShapes;
396 if (aType == TopAbs_COMPOUND) {
397 TopoDS_Iterator anIter(theShape);
398 if (anIter.More()) aType = anIter.Value().ShapeType();
399 for(;anIter.More();anIter.Next()) aShapes.Append(anIter.Value());
400 if (aType == theType) {
401 if (aShapes.Extent() == 1) return aShapes.First();
402 else return theShape;
403 }
404 } else aShapes.Append(theShape);
405
406 TopoDS_Shape aResult;
407 TopTools_ListIteratorOfListOfShape aListIter(aShapes);
408
409 if (aType < theType) {
410 Standard_Integer aCount;
411 for(aCount=0;aListIter.More();aListIter.Next()) {
412 TopExp_Explorer anExp(aListIter.Value(),theType);
413 if (anExp.More()) {
414 if (!anExp.Current().IsNull()) {
415 aResult = anExp.Current();
416 aCount++;
417 if (aCount > 1) return theShape;
418 }
419 }
420 }
421 if (aCount == 1) return aResult;
422 } else { // if the shape type more complex than shapes from aShapes list, try make it
423 switch (aType) {
424 case TopAbs_VERTEX: // can't do something from vertex
425 break;
b1811c1d 426 case TopAbs_EDGE:
427 {
428 // make wire from edges
429 if (theType <= TopAbs_SOLID) break;
430 BRepBuilderAPI_MakeWire aMakeWire;
431 aMakeWire.Add(aShapes);
432 if (!aMakeWire.IsDone()) return theShape;
433 if (theType == TopAbs_WIRE) return aMakeWire.Wire();
434 aShapes.Clear(); // don't break: we can do something more of it
435 aShapes.Append(aMakeWire.Wire());
436 aListIter.Initialize(aShapes);
7fd59977 437 }
b1811c1d 438 Standard_FALLTHROUGH
439 case TopAbs_WIRE:
440 {
441 // make faceS from wires (one per one)
442 if (theType < TopAbs_SOLID) break;
443 TopTools_ListOfShape aFaces;
444 for(;aListIter.More();aListIter.Next()) {
445 BRepBuilderAPI_MakeFace aMakeFace(TopoDS::Wire(aListIter.Value()));
446 if (!aMakeFace.IsDone()) aFaces.Append(aMakeFace.Face());
447 }
448 if (theType == TopAbs_FACE) {
449 if (aFaces.Extent() == 1) return aFaces.First();
450 return theShape;
451 }
452 aShapes.Assign(aFaces); // don't break: we can do something more of it
453 aListIter.Initialize(aShapes);
7fd59977 454 }
b1811c1d 455 Standard_FALLTHROUGH
456 case TopAbs_FACE:
457 {
458 // make shell from faces
459 if (theType < TopAbs_SOLID) break;
460 BRep_Builder aShellBuilder;
461 TopoDS_Shell aShell;
462 aShellBuilder.MakeShell(aShell);
463 for(;aListIter.More();aListIter.Next()) aShellBuilder.Add(aShell,TopoDS::Face(aListIter.Value()));
464 aShell.Closed (BRep_Tool::IsClosed (aShell));
465 if (theType == TopAbs_SHELL) return aShell;
466 aShapes.Clear(); // don't break: we can do something more of it
467 aShapes.Append(aShell);
468 aListIter.Initialize(aShapes);
7fd59977 469 }
b1811c1d 470 Standard_FALLTHROUGH
471 case TopAbs_SHELL:
472 {
473 // make solids from shells (one per one)
474 TopTools_ListOfShape aSolids;
475 for(;aListIter.More();aListIter.Next()) {
476 BRepBuilderAPI_MakeSolid aMakeSolid(TopoDS::Shell(aListIter.Value()));
477 if (aMakeSolid.IsDone()) aSolids.Append(aMakeSolid.Solid());
478 }
479 if (theType == TopAbs_SOLID) {
480 if (aSolids.Extent() == 1) return aSolids.First();
481 return theShape;
482 }
483 aShapes.Assign(aSolids); // don't break: we can do something more of it
484 aListIter.Initialize(aShapes);
485 }
486 Standard_FALLTHROUGH
487 case TopAbs_SOLID:
488 {
489 // make compsolid from solids
490 BRep_Builder aCompBuilder;
491 TopoDS_CompSolid aCompSolid;
492 aCompBuilder.MakeCompSolid(aCompSolid);
493 for(;aListIter.More();aListIter.Next()) aCompBuilder.Add(aCompSolid,TopoDS::Solid(aListIter.Value()));
494 if (theType == TopAbs_COMPSOLID) return aCompSolid;
7fd59977 495 }
7fd59977 496 }
497 }
498 return theShape;
499}
500
7fd59977 501//=======================================================================
502//function : FindModifUntil
503//purpose :
504//=======================================================================
505
506static Standard_Boolean FindModifUntil (TNaming_NewShapeIterator& it,
0df87563 507 TopTools_IndexedMapOfShape& MS,
7fd59977 508 const TopoDS_Shape& S,
509 const Handle(TNaming_NamedShape)& Context)
510{
0797d9d3 511#ifdef OCCT_DEBUG_MODUN
1ec8a59e 512 if(!Context.IsNull())
513 PrintEntry(Context->Label());
514#endif
7fd59977 515 Standard_Boolean found = Standard_False;
516 for (; it.More(); it.Next()) {
517 if (!it.Shape().IsNull()) {
0797d9d3 518#ifdef OCCT_DEBUG_MODUN
1ec8a59e 519 if(!it.NamedShape().IsNull())
520 PrintEntry(it.NamedShape()->Label());
521#endif
7fd59977 522 if (it.NamedShape() == Context) {
523 MS.Add(S);
524 found = Standard_True;
525 }
526 else { // New shape != Context
527 TNaming_NewShapeIterator it2(it);
528 found = FindModifUntil (it2,MS,it.Shape(),Context);
529 }
530 }
531 }
532 return found;
533}
534
535//=======================================================================
536//function : ModifUntil
537//purpose : returns map <theMS> of generators of Target
538//=======================================================================
539
540static void SearchModifUntil (const TDF_LabelMap& /*Valid*/,
541 const Handle(TNaming_NamedShape)& Target,
542 const TNaming_ListOfNamedShape& theListOfGenerators,
0df87563 543 TopTools_IndexedMapOfShape& theMS)
7fd59977 544{
545
0797d9d3 546#ifdef OCCT_DEBUG_MODUN
7fd59977 547 DbgTools_WriteNSOnLabel(Target, "SMUntil_"); // Target <== generated
548 Standard_Integer i = 0;
549 TCollection_AsciiString aGen1("Gens_New_"), aGen2("Gented_Old_"), Und("_");
550#endif
551 // Test si S apparait comme oldshape dans Context. : Test if S appears as oldshape in Context.
552 Standard_Boolean found = Standard_False;
553 for (TNaming_ListIteratorOfListOfNamedShape it(theListOfGenerators); it.More(); it.Next()) {
554 const Handle(TNaming_NamedShape)& aNS = it.Value();
0797d9d3 555#ifdef OCCT_DEBUG_MODUN
7fd59977 556 i++;
557 Standard_Integer j = 0;
558#endif
559 for (TNaming_Iterator itL (aNS); itL.More(); itL.Next()) { // <- generators
560 const TopoDS_Shape& S = itL.NewShape();
561 found = Standard_False;
562
0797d9d3 563#ifdef OCCT_DEBUG_MODUN
7fd59977 564 j++;
565 Standard_Integer k = 0;
566 TCollection_AsciiString aNam1 = aGen1 + i + Und + j + ".brep";
567 DbgTools_Write(S, aNam1.ToCString());
1ec8a59e 568 PrintEntry(aNS->Label());//NSLabel
7fd59977 569#endif
1ec8a59e 570 TNaming_Iterator itC (Target);
571 for (; itC.More(); itC.Next()) { // <- generated
7fd59977 572 const TopoDS_Shape& OS = itC.OldShape();
0797d9d3 573#ifdef OCCT_DEBUG_MODUN
7fd59977 574 k++;
575 TCollection_AsciiString aNam2 = aGen2 + i + Und + j + Und + k + ".brep";
576 DbgTools_Write(OS, aNam2.ToCString());
1ec8a59e 577 PrintEntry(Target->Label());//Target Label
7fd59977 578#endif
579 if (OS.IsSame(S)) {
580 theMS.Add(S);
581 found = Standard_True;
0797d9d3 582#ifdef OCCT_DEBUG_MODUN
7fd59977 583 cout << aNam2 << " is Same with " << aNam1 <<endl;
584#endif
585 break;
586 }
587 }
588 if (!found) {
589 TNaming_NewShapeIterator it1(itL);
590 found = FindModifUntil (it1,theMS,S,Target);
591 }
592 }
593 }
594}
595
596//=======================================================================
597//function : ModifUntil
598//purpose :
599//=======================================================================
600// NamedShape for this type is assembled from all last modifications of the
601// last argument shapes (see method TNaming_NamingTool::CurrentShape),
602// which are not descendants (see method TNaming_NamingTool::BuildDescendants)
603// of the stop shape. This type of naming is used for identification shapes,
604// which has only one parent with evolution PRIMITIVE (or itself), which
605// uniquely identifies it. In most cases stop shape is empty and this algorithm
606// is equal to the algorithm for IDENTITY.
607//=======================================================================
608static Standard_Boolean ModifUntil (const TDF_Label& L,
609 const TDF_LabelMap& Valid,
610 const TNaming_ListOfNamedShape& Args,
611 const Handle(TNaming_NamedShape)& Stop)
612{
0df87563 613 TopTools_IndexedMapOfShape MS;
7fd59977 614 TDF_LabelMap Forbiden;
7fd59977 615 if(!ValidArgs(Args)) return Standard_False;
7fd59977 616 TNaming_NamingTool::BuildDescendants (Stop, Forbiden); // fills Forbidden from Stop
617
0797d9d3 618#ifdef OCCT_DEBUG_GEN
7fd59977 619 cout <<"Regenerating ModifUntil => ";
620 PrintEntry(L);
621 DbgTools_WriteNSOnLabel(Args.Last(), "ModifUntil-");
622
623#endif
624 // all last modifications of the last argument
625 TNaming_NamingTool::CurrentShape (Valid, Forbiden,Args.Last(),MS);
0797d9d3 626#ifdef OCCT_DEBUG_GEN
7fd59977 627 Standard_Integer i(0);
7fd59977 628 TCollection_AsciiString aNam("ModifUnti_MS_");
629 TCollection_AsciiString ext(".brep");
630#endif
631 TNaming_Builder B(L);
0df87563 632 for (Standard_Integer anItMS = 1; anItMS <= MS.Extent(); ++anItMS) {
633 const TopoDS_Shape& S = MS (anItMS);
7fd59977 634 B.Select(S,S);
0797d9d3 635#ifdef OCCT_DEBUG_GEN
7fd59977 636 TCollection_AsciiString aName = aNam + ++i + ext;
637 DbgTools_Write(S, aName.ToCString()) ;
638 cout << aName.ToCString() << " TS = " << S.TShape()->This() <<endl;
639#endif
640 }
641 return Standard_True;
642}
643
644//=======================================================================
645//function : ContShape
646//purpose :
647//=======================================================================
648// from the NS of the first argument TNaming_Iterator is started, shape "S"
649// is the NewShape from Iterator with index "myIndex" of the Name, this
650// shape and all last modifications (except NamedShapes - descendants of
651// the stop shape) are the parts of resulting NamedShape.
652//=======================================================================
653static Standard_Boolean ConstShape (const TDF_Label& L,
654 const TDF_LabelMap& Valid,
655 const TNaming_ListOfNamedShape& Args,
656 const Handle(TNaming_NamedShape)& Stop,
657 const Standard_Integer Index)
658{
0df87563 659 TopTools_IndexedMapOfShape MS;
7fd59977 660 TDF_LabelMap Forbiden;
7fd59977 661 if(!ValidArgs(Args)) return Standard_False;
7fd59977 662 TNaming_NamingTool::BuildDescendants (Stop, Forbiden);
663
664 TopoDS_Shape S;
665 Standard_Integer i = 1;
666 for (TNaming_Iterator it(Args.First()); it.More(); it.Next(), i++) {
667 if (Index == i) {
668 S = it.NewShape();
669 break;
670 }
671 }
672 if (S.IsNull()) return Standard_False;
673
674 TNaming_NamingTool::CurrentShapeFromShape (Valid,Forbiden,L,S,MS);
675
676
677 TNaming_Builder B(L);
0df87563 678 for (Standard_Integer anItMS = 1; anItMS <= MS.Extent(); ++anItMS) {
679 const TopoDS_Shape& SS = MS (anItMS);
7fd59977 680 B.Select(SS,SS);
681 }
682 return Standard_True;
683}
684
685//=======================================================================
686//function : Intersection
687//purpose :
688//=======================================================================
689//algorithm does next steps:
690// 1. Sets to the "Forbiden" map all shapes, which are descendants of stop
691// shape. Named shapes at these labels can't be used.
692// 2. Takes first argument (with method CurrentShape) and sets map "S" of
693// ancestors (shapes, which belong to this one) of its shape with type
694// "ShapeType" of Name.
695// 3. Takes next argument of Name (with method CurrentShape) and removes
696// from the map "S" all ancestors, which not belongs to the shape of
697// this argument. This step is repeated for all arguments of this Name.
698// 4. Adds to the result NamedShape all rest of shapes from the map "S".
699//=======================================================================
700static Standard_Boolean Intersection (const TDF_Label& L,
701 const TDF_LabelMap& Valid,
702 const TNaming_ListOfNamedShape& Args,
703 const Handle(TNaming_NamedShape)& Stop,
704 const TopAbs_ShapeEnum ShapeType,
705 const Standard_Integer Index)
706{
707 if (Args.IsEmpty()) return Standard_False;
7fd59977 708 if(!ValidArgs(Args)) return Standard_False;
7fd59977 709 TNaming_ListIteratorOfListOfNamedShape it(Args);
0df87563 710 TopTools_IndexedMapOfShape MS;
7fd59977 711 TDF_LabelMap Forbiden;
712
0797d9d3 713#ifdef OCCT_DEBUG_INT
7fd59977 714 if(!Stop.IsNull() && !Stop->Get().IsNull()) {
715 DbgTools_Write(Stop->Get(), "Ints_Stop.brep");
716 PrintEntry(Stop->Label());
717 }
718 cout <<"Ints: ShapeType = " << ShapeType << endl;
719 cout <<"Argument 1 at ";
720 PrintEntry(it.Value()->Label());
721#endif
722
723 TNaming_NamingTool::BuildDescendants (Stop, Forbiden); // <==<1>
724
0797d9d3 725#ifdef OCCT_DEBUG_INT
7fd59977 726 cout << "Intersection:: Valid Map: "<<endl;
727 PrintEntries(Valid);
728 cout << "Intersection:: Forbidden Map: "<<endl;
729 PrintEntries(Forbiden);
730#endif
731 TopTools_ListOfShape aListOfAnc;
732 TNaming_NamingTool::CurrentShape (Valid, Forbiden,it.Value(),MS); // first argument
733 TopoDS_Shape CS = MakeShape(MS);
734 TNaming_ShapesSet S(CS,ShapeType); // <==<2>
735 aListOfAnc.Append(CS);
0797d9d3 736#ifdef OCCT_DEBUG_INT
7fd59977 737 if(!CS.IsNull())
738 DbgTools_Write(CS, "Int_CS_1.brep");
739 Standard_Integer i=2;
740 TCollection_AsciiString aNam("Int_CS_");
741 TCollection_AsciiString ext(".brep");
742
743#endif
744 it.Next(); // <<===<3.1>
745 for (; it.More(); it.Next()) {
746 MS.Clear();
747 TNaming_NamingTool::CurrentShape (Valid,Forbiden,it.Value(),MS);
748 CS = MakeShape(MS);
749 aListOfAnc.Append(CS);
0797d9d3 750#ifdef OCCT_DEBUG_INT
7fd59977 751 TCollection_AsciiString aName = aNam + i++ + ext;
752 DbgTools_Write(CS, aName.ToCString()) ;
753 cout <<"Argument " << i << " at ";
754 PrintEntry(it.Value()->Label());
755#endif
756
757 TNaming_ShapesSet OS(CS,ShapeType);
758 S.Filter(OS); //<<===<3.2>
0797d9d3 759#ifdef OCCT_DEBUG_INT
7fd59977 760 Standard_Integer j = 1;
761 TCollection_AsciiString aNam2("SSMap_"), aName3;
762 TopTools_MapIteratorOfMapOfShape itm(S.Map());
763 for(;itm.More();itm.Next(), j++) {
764 aName3 = aNam2 + i + "_" + j + ".brep";
765 DbgTools_Write(itm.Key(), aName3.ToCString());
766 }
767#endif
768 }
769
0797d9d3 770#ifdef OCCT_DEBUG_INT
7fd59977 771 aNam = "Int_S_";
772 i =1;
773#endif
774
775 TNaming_Builder B(L); //<<===<4>
776 Standard_Boolean isOK(Standard_False);
777 if(S.Map().Extent() > 1 && Index > 0 && ShapeType == TopAbs_EDGE) {
778 Standard_Integer indxE(0), nbE(0), indxW(0),nbW(0), indxF(0);
779 indxE = Index & 0x000000FF;
780 nbE = (Index & 0x0000FF00) >> 8;
781 indxW = (Index & 0x000F0000) >> 16;
782 nbW = (Index & 0x00F00000) >> 20;
783 indxF = (Index & 0x0F000000) >> 24;
51740958 784 Standard_Integer k(1);
7fd59977 785 TopoDS_Shape aS;
786 TopTools_ListIteratorOfListOfShape itl(aListOfAnc);
51740958 787 for(;itl.More();itl.Next(),k++) {
788 if(indxF == k) {
7fd59977 789 aS = itl.Value();
790 break;
791 }
792 }
0797d9d3 793#ifdef OCCT_DEBUG_INT
7fd59977 794 cout <<"Kept: indxE = " << indxE <<" maxENum = " << nbE << " indxW = " <<indxW << " nbW = " <<nbW<<endl;
795#endif
796 Standard_Integer aNbW(0), aCaseW(0);
797 TopoDS_Iterator it2(aS);
798 for (;it2.More();it2.Next()) aNbW++;
799 if(aNbW == nbW) aCaseW = 1;//exact solution for wire (nb of wires is kept)
800 else aCaseW = 2; // indefinite description ==> compound which can include expected wire
801 if(aCaseW == 1) {
802 TopoDS_Shape aWire;
803 Standard_Integer i(1);
804 it2.Initialize(aS);
805 for (;it2.More();it2.Next(),i++) {
806 if(indxW == i) {
807 aWire = it2.Value();
808 break;
809 }
810 }
811 Standard_Integer aNbE(0), aCaseE(0);
812 it2.Initialize(aWire);
813 for (;it2.More();it2.Next()) aNbE++;
814 if(aNbE == nbE) aCaseE = 1;//exact solution for edge
815 else aCaseE = 2;
816 if(aCaseE == 1) {
817 i=1;
818 TopoDS_Shape anEdge;
819 it2.Initialize(aWire);
820 for (;it2.More();it2.Next(),i++) {
821 if(indxE == i) {
822 anEdge = it2.Value();
823 break;
824 }
825 }
826 if(!anEdge.IsNull()) {
827 B.Select(anEdge, anEdge);
828 isOK = Standard_True;
829 }
830 }
831 }
832 }
833 if(!isOK)
0797d9d3 834#ifdef OCCT_DEBUG_INT
7fd59977 835 for (TopTools_MapIteratorOfMapOfShape itM(S.Map()); itM.More(); itM.Next(),i++) {
836#else
837
838 for (TopTools_MapIteratorOfMapOfShape itM(S.Map()); itM.More(); itM.Next()) {
839#endif
840 const TopoDS_Shape& S1 = itM.Key();
0797d9d3 841#ifdef OCCT_DEBUG_INT
7fd59977 842 TCollection_AsciiString aName = aNam + i + ext;
843 DbgTools_Write(S1, aName.ToCString()) ;
844#endif
845
846 B.Select(S1,S1);
847 isOK = Standard_True;
848 }
849 return isOK;
850}
851//=======================================================================
852static void KeepInList(const TopoDS_Shape& CS, const TopAbs_ShapeEnum Type, TopTools_ListOfShape& aList)
853{
854 if (CS.IsNull()) return;
855
856 if (Type == TopAbs_SHAPE) {
857 if (CS.ShapeType() == TopAbs_SOLID ||
858 CS.ShapeType() == TopAbs_FACE ||
859 CS.ShapeType() == TopAbs_EDGE ||
860 CS.ShapeType() == TopAbs_VERTEX ) {
861 aList.Append(CS);
862 }
863 else {
864 for (TopoDS_Iterator it(CS) ; it.More(); it.Next()) {
865 aList.Append(it.Value());
866 }
867 }
868 }
869 else {
870 if (Type > CS.ShapeType()) {
871 for (TopExp_Explorer exp(CS,Type) ; exp.More(); exp.Next()) {
872 aList.Append(exp.Current());
873 }
874 } else {
875 aList.Append(CS);
876 }
877 }
878}
879
880//=======================================================================
881//function : Union
882//purpose :
883//=======================================================================
884// Resulting NamedShape contains compound of next shapes:
885// compound of last modifications of each argument (see CurrentShape method)
886// without descendants of the stop shape.
887//=======================================================================
888static Standard_Boolean Union (const TDF_Label& L,
889 const TDF_LabelMap& Valid,
890 const TNaming_ListOfNamedShape& Args,
891 const Handle(TNaming_NamedShape)& Stop,
892 const TopAbs_ShapeEnum ShapeType,
893 const TDF_Label& ContextLabel)
894{
895 if (Args.IsEmpty()) return Standard_False;
7fd59977 896 if(!ValidArgs(Args)) return Standard_False;
7fd59977 897 // temporary solution for Orientation name
898 Standard_Boolean isOr(Standard_True);
899/* not completed
900 const TDF_Label& aLabel = L.Father();
901 if(!aLabel.IsNull()) {
902 PrintEntry(L);
903 PrintEntry(aLabel);
904 Handle (TNaming_Naming) Naming;
905 if(aLabel.FindAttribute(TNaming_Naming::GetID(), Naming)) {
906 const TNaming_Name& aName = Naming->GetName();
907 if(aName.Type() == TNaming_ORIENTATION) {
908 const TNaming_ListOfNamedShape& Args = aName.Arguments();
909 if(Args.Extent() > 2) {
910 const Handle(TNaming_NamedShape)& A = Args.First();
911 if(!A.IsNull()) {
912 PrintEntry(A->Label());
913 if (A->Label() == L)
914 isOr = Standard_True;
915 }
916 } else
917 if(!Args.Extent())
918 isOr = Standard_True;
919 }
920 }
921 }
922*/
923 // end of temp. sol.
924
925 TNaming_ListIteratorOfListOfNamedShape it(Args);
0df87563 926 TopTools_IndexedMapOfShape MS;
7fd59977 927 TDF_LabelMap Forbiden;
928
929 TNaming_NamingTool::BuildDescendants (Stop, Forbiden);//fill Forbidden
930 TNaming_NamingTool::CurrentShape (Valid, Forbiden,it.Value(),MS); // fill MS with last modifications of the first argument
931 TopoDS_Shape CS = MakeShape(MS);
932
933 TopTools_ListOfShape aListS;
934 if(isOr)
935 KeepInList(CS,ShapeType,aListS);
936 TNaming_ShapesSet S(CS,ShapeType);//fill internal map of shapeset by shapes of the specified type
0797d9d3 937#ifdef OCCT_DEBUG_UNN
7fd59977 938 TCollection_AsciiString entry;
939 TDF_Tool::Entry(it.Value()->Label(), entry);
940 TCollection_AsciiString Nam("Arg_");
941 TCollection_AsciiString aNam = Nam + entry + "_" + "1.brep";
942 DbgTools_Write(CS, aNam.ToCString());
943 Standard_Integer ii = 1;
944#endif
945 it.Next();
946 for (; it.More(); it.Next()) {
0797d9d3 947#ifdef OCCT_DEBUG_UNN
7fd59977 948 TDF_Tool::Entry(it.Value()->Label(), entry);
949#endif
950 MS.Clear();
951 TNaming_NamingTool::CurrentShape (Valid, Forbiden,it.Value(),MS);// fill MS with last modifications of the it.Value()
952 CS = MakeShape(MS);
953 if(isOr)
954 KeepInList(CS,ShapeType,aListS);
955 TNaming_ShapesSet OS(CS,ShapeType);
956 S.Add(OS); //concatenate both shapesets
957
0797d9d3 958#ifdef OCCT_DEBUG_UNN
7fd59977 959 ii++;
960 TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep";
961 DbgTools_Write(CS, aNm.ToCString());
962 cout <<"Arg: Entry = " <<entry <<" TShape = " << CS.TShape() <<endl;
963#endif
964 }
965
966// start szy 27.05.08
967 TopoDS_Shape aCand;
968 Standard_Boolean found = Standard_False;
969 if(!ContextLabel.IsNull()) {
970 Handle(TNaming_NamedShape) CNS;
971 ContextLabel.FindAttribute(TNaming_NamedShape::GetID(),CNS);
972 TopoDS_Shape aContext;
973 if(!CNS.IsNull()) {
974 MS.Clear();
975 TNaming_NamingTool::CurrentShape (Valid, Forbiden, CNS, MS);
976 aContext = MakeShape(MS);
0797d9d3 977#ifdef OCCT_DEBUG_UNN
7fd59977 978 TCollection_AsciiString anEntry;
979 TDF_Tool::Entry(ContextLabel, anEntry);
980 cout << "UNION: Context Label = " << anEntry << endl;
981 DbgTools_Write(aContext, "Union_Context.brep");
982 TCollection_AsciiString aN ("aMap_");
983 TopTools_MapIteratorOfMapOfShape it(S.Map());
984 for(Standard_Integer i=1; it.More();it.Next(), i++) {
985 TCollection_AsciiString aName = aN + i + ".brep";
986 DbgTools_Write(it.Key(), aName.ToCString());
987 }
988#endif
989 }
990 TopTools_ListOfShape aList;
991 TopExp_Explorer anExpl(aContext, ShapeType);
992 for(;anExpl.More(); anExpl.Next())
993 aList.Append(anExpl.Current());
0797d9d3 994#ifdef OCCT_DEBUG_UNN
7fd59977 995 cout <<"UNION: ShapeType = " << ShapeType << " List ext = " << aList.Extent()<<endl;
996 TopAbs_ShapeEnum aTyp = TopAbs_SHAPE;
997 TopTools_MapIteratorOfMapOfShape it1 (S.Map());
998 for (int i=1;it1.More();it1.Next(),i++) {
999 cout << "Map("<<i<<"): TShape = " << it1.Key().TShape() << " Orient = " << it1.Key().Orientation() <<endl;
1000 aTyp = it1.Key().ShapeType();
1001 }
1002
1003 TopExp_Explorer exp(aContext, aTyp);
1004 for(int i =1;exp.More();exp.Next(), i++) {
1005 cout << "Context("<<i<<"): TShape = " << exp.Current().TShape() << " Orient = " << exp.Current().Orientation() <<endl;
1006 }
1007
1008#endif
1009 TopTools_ListIteratorOfListOfShape itl(aList);
1010 for(;itl.More();itl.Next()) {
1011 aCand = itl.Value();
0797d9d3 1012#ifdef OCCT_DEBUG_UNN
7fd59977 1013 DbgTools_Write(aCand, "Cand.brep");
1014#endif
1015 Standard_Integer num = S.Map().Extent();
1016 anExpl.Init(aCand, (ShapeType == TopAbs_WIRE) ? TopAbs_EDGE : TopAbs_FACE);
1017 for(;anExpl.More();anExpl.Next()) {
1018 if(S.Map().Contains(anExpl.Current()))
1019 num--;
1020 }
1021 if(num == 0) {
1022 found = Standard_True;
1023 break;
1024 }
1025 }
1026// end szy 27.05.08
1027 }
1028
1029 TNaming_Builder B(L);
0797d9d3 1030#ifdef OCCT_DEBUG_UNN
7fd59977 1031 if(!ContextLabel.IsNull()) {
1032 if(found) cout << "UNION: Shape is found in Context" <<endl;
1033 else cout << "UNION: Shape is NOT found in Context" <<endl;
1034 }
1035#endif
7fd59977 1036 if(found)
1037 B.Select(aCand, aCand);
1038 else {
1039 BRep_Builder aCompoundBuilder;
1040 TopoDS_Compound aCompound;
1041 aCompoundBuilder.MakeCompound(aCompound);
1042 if(!isOr)
1043 for (TopTools_MapIteratorOfMapOfShape itM(S.Map()); itM.More(); itM.Next()) {
1044 aCompoundBuilder.Add(aCompound,itM.Key());
1045 }
1046 else
1047 for (TopTools_ListIteratorOfListOfShape itL(aListS); itL.More(); itL.Next()) {
1048 aCompoundBuilder.Add(aCompound,itL.Value());
1049 }
1050 TopoDS_Shape aShape = ShapeWithType(aCompound,ShapeType);
0797d9d3 1051#ifdef OCCT_DEBUG_UNN
7fd59977 1052 DbgTools_Write(aShape, "Union_Selected.brep");
1053 DbgTools_Write(aCompound, "Union_Compound.brep");
1054#endif
1055 B.Select(aShape,aShape);
1056 }
7fd59977 1057 return Standard_True;
1058}
1059
1060//=======================================================================
7fd59977 1061static TopoDS_Shape FindShape(const TNaming_DataMapOfShapeMapOfShape& DM)
1062{
1063 TopoDS_Shape aResult;
1064 Standard_Integer aNum = DM.Extent();
1065 if(aNum < 1) return aResult;
1066 TopTools_ListOfShape List;
1067 TNaming_DataMapIteratorOfDataMapOfShapeMapOfShape it(DM);
b2197f93 1068 if(it.More()) {
7fd59977 1069 const TopoDS_Shape& aKey1 = it.Key();
1070 const TNaming_MapOfShape& aMap = it.Value();
1071
1072 TNaming_MapIteratorOfMapOfShape itm(aMap); // iterate first map
1073 for (;itm.More();itm.Next()) {
1074 const TopoDS_Shape& aS = itm.Key(); // element of the first map
1075 Standard_Boolean isCand(Standard_True); // aS is a Candidate
1076 TNaming_DataMapIteratorOfDataMapOfShapeMapOfShape it2(DM);
1077 for (;it2.More();it2.Next()) {
7dcac1df 1078 const TopoDS_Shape& aKey2 = it2.Key();
1079 if(aKey2 == aKey1) continue;
1080 const TNaming_MapOfShape& aMap2 = it2.Value();
1081 if(!aMap2.Contains(aS)) isCand = Standard_False;
7fd59977 1082 }
7dcac1df 1083 if(isCand)
1084 List.Append(aS);
7fd59977 1085 }
7fd59977 1086 }
1087 if(List.IsEmpty()) return aResult;
1088 if(List.Extent() == 1) return List.First();
1089 TopTools_ListIteratorOfListOfShape itl (List);
1090 TopoDS_Compound Compound;
1091 BRep_Builder B;
1092 B.MakeCompound(Compound);
1093 for (; itl.More(); itl.Next()){
1094 B.Add(Compound,itl.Value());
1095 }
1096 return Compound;
1097}
1098
1099//=======================================================================
1100//function : Generation
1101//purpose : Resolves Name from arguments: arg1 - generated (target shape)
1102// : arg2 - the generator: the oldest ancestor (usually NS with
1103// : PRIMITIVE evolution. (See TNaming_Localizer::FindGenerator).
1104// : Resulting NamedShape contains shape, which is in the first
1105// : argument NamedShape and is modification of the last argument NS.
1106//=======================================================================
1107
1108static Standard_Boolean Generated (const TDF_Label& L,
1109 const TDF_LabelMap& Valid,
1110 const TNaming_ListOfNamedShape& Args)
1111{
1112 if (Args.Extent() < 2) {
9775fa61 1113 throw Standard_ConstructionError("TNaming_Name::Solve: => Generated");
7fd59977 1114 }
1115 // First argument : label of generation
1116 // Next arguments : generators.
1117
7fd59977 1118 if(!ValidArgs(Args)) return Standard_False;
7fd59977 1119
1120 TDF_Label LabelOfGeneration = Args.First()->Label();
0797d9d3 1121#ifdef OCCT_DEBUG_GEN
7fd59977 1122 DbgTools_Write(Args.First()->Get(), "Generated.brep") ;
1123#endif
1124 // Nouvell valeurs des generateurs dans l attribut de generation
0df87563 1125 TopTools_IndexedMapOfShape aMS;
7fd59977 1126 TNaming_ListOfNamedShape aGenerators;
1127 aGenerators.Assign(Args);
1128 aGenerators.RemoveFirst();
0797d9d3 1129#ifdef OCCT_DEBUG_GEN
7fd59977 1130 DbgTools_Write(aGenerators.First()->Get(), "Generators.brep") ;
1131#endif
1132 SearchModifUntil (Valid, Args.First(), aGenerators, aMS);
1133 Handle(TNaming_Naming) aNaming;
1134 TopoDS_Shape aSelection;
1135 L.FindAttribute(TNaming_Naming::GetID(),aNaming);
1136 if(!aNaming.IsNull())
1137 aSelection = aNaming->GetName().Shape();
0797d9d3 1138#ifdef OCCT_DEBUG_GEN
7fd59977 1139 DbgTools_Write(aSelection, "G_Selection.brep") ;
1140 cout << "Generated::SearchModifUntil aMS.Extent() = " << aMS.Extent() <<endl;
1141 DbgTools_Write(aMS, "SearchModifUntil_Result");
1142#endif
1143 Handle(TNaming_NamedShape) anOldNS;
1144 Standard_Integer aVer = -1;// Initial build of name
1145 L.FindAttribute(TNaming_NamedShape::GetID(),anOldNS);
1146 if(!anOldNS.IsNull())
1147 aVer = anOldNS->Version();
1148
0797d9d3 1149#ifdef OCCT_DEBUG_GEN
7fd59977 1150 Standard_Integer i = 0, j=1;
1151 TCollection_AsciiString aNam2("Gen_New_");
1152 TCollection_AsciiString aNam1("Gen_Old_");
1153 TCollection_AsciiString ext(".brep");
1154#endif
1155 TNaming_Builder B(L); // NS
1156 TopTools_ListOfShape aList;
1157 TNaming_DataMapOfShapeMapOfShape aDM;
0df87563 1158 for (Standard_Integer anItMS = 1; anItMS <= aMS.Extent(); ++anItMS) {
1159 const TopoDS_Shape& OS = aMS (anItMS);
0797d9d3 1160#ifdef OCCT_DEBUG_GEN
7fd59977 1161 TCollection_AsciiString aName = aNam1 + ++i + ext;
1162 DbgTools_Write(OS, aName.ToCString()) ;
1163 Standard_Integer j=0;
1164#endif
1165 TNaming_MapOfShape aMapDM;
1166 for (TNaming_NewShapeIterator itNew(OS,L); itNew.More(); itNew.Next())
1167 if (itNew.Label() == LabelOfGeneration) {
1168 aMapDM.Add(itNew.Shape());
1169 aList.Append(itNew.Shape());//szy 21.10.03
0797d9d3 1170#ifdef OCCT_DEBUG_GEN
7fd59977 1171 TCollection_AsciiString aName = aNam2 + i + "_" + ++j + ext;
1172 DbgTools_Write(itNew.Shape(), aName.ToCString()) ;
1173#endif
1174 }
1175 if(aMapDM.Extent())
1176 aDM.Bind(OS, aMapDM);
1177 }
1178
1179 if(aVer == -1) { //initial
1180 Standard_Integer i = 1;
1181 TNaming_Name& aName = aNaming->ChangeName();
1182 TopTools_ListIteratorOfListOfShape it(aList);
1183 if(!aSelection.IsNull()) {
1184 for(;it.More();it.Next(),i++) {
1185 if(it.Value().IsSame(aSelection)) {
1186 B.Select(it.Value(), it.Value());
1187 aName.Index(i); // for debug - index of selection in the list
1188 break;
1189 }
1190 }
1191 } else {// Selection == Null
1192 for(;it.More();it.Next())
1193 B.Select(it.Value(), it.Value());
1194 }
1195 }
1196 else {
1197 // *** Regeneration *** //
1198 if(aList.Extent() == 1) { // trivial case
1199 B.Select(aList.Last(), aList.Last());
1200 }
1201 else {
1202 TNaming_Name& aName = aNaming->ChangeName();
1203 const TopAbs_ShapeEnum aType = aName.ShapeType();
1204 TopTools_ListOfShape aList2;
1205 TopTools_ListIteratorOfListOfShape it(aList);
1206 for(;it.More();it.Next()) {
1207 if(it.Value().ShapeType() == aType) //collect only the same type
1208 aList2.Append(it.Value());
1209 }
1210 if(!aList2.Extent()) return Standard_False; // Empty
1211
1212 Standard_Boolean found = Standard_False;
7fd59977 1213 TopoDS_Shape aShape = FindShape(aDM);
0797d9d3 1214#ifdef OCCT_DEBUG_GEN
7fd59977 1215 if(!aShape.IsNull())
1216 DbgTools_Write(aShape, "G_FindShape.brep") ;
1217#endif
1218 if(!aShape.IsNull()) found = Standard_True;
0797d9d3 1219#ifdef OCCT_DEBUG_GEN
7fd59977 1220 cout << "Generated ==>aGenerators.Extent() = " <<aGenerators.Extent() <<" aMS.Extent()= " <<aMS.Extent()<<endl;
1221#endif
1222 if(found) {
0797d9d3 1223#ifdef OCCT_DEBUG_GEN
7fd59977 1224 cout << "Generated ==> Shape is found!" <<endl;
1225#endif
1226 TopTools_ListOfShape aLM;
1227 Standard_Boolean aHas = Standard_False;
1228 Standard_Boolean a1NB = Standard_False;
1229 if(aGenerators.Extent() != aMS.Extent()) { //missed generators
1230 aHas = Standard_True;//has lost generatos
0797d9d3 1231#ifdef OCCT_DEBUG_GEN
7fd59977 1232 cout << "Generated ==> has lost generatos!" <<endl;
1233#endif
1234 for (TNaming_ListIteratorOfListOfNamedShape itg(aGenerators); itg.More(); itg.Next()) {
1235 if(!aMS.Contains(itg.Value()->Get()))
1236 aLM.Append(itg.Value()->Get());
1237 }
1238 if(aLM.Extent() == 1) {//lost 1
1239 TopTools_ListIteratorOfListOfShape itm(aLM);
1240 TopoDS_Shape aSM = itm.Value(); // Missed
0df87563 1241 for (Standard_Integer anItMS1 = 1; anItMS1 <= aMS.Extent(); ++anItMS1) {
1242 const TopoDS_Shape& aS = aMS (anItMS1);
7fd59977 1243 if(aSM.ShapeType() == aS.ShapeType()) {
1244 if(aS.ShapeType() == TopAbs_EDGE) {
1245 TopoDS_Vertex aVCom;
1246 if(TopExp::CommonVertex(TopoDS::Edge(aS), TopoDS::Edge(aSM), aVCom))
1247 {a1NB = Standard_True;
1248 break;} //lost only 1 neigbour
1249 } else if(aS.ShapeType() == TopAbs_FACE) {
1250 TopExp_Explorer expl1(aS, TopAbs_EDGE);
1251 for(;expl1.More();expl1.Next()) {
1252 TopExp_Explorer expl2(aSM, TopAbs_EDGE);
1253 for(;expl2.More();expl2.Next()) {
1254 if(expl1.Current().IsSame(expl2.Current()))
1255 {a1NB = Standard_True;
1256 break;} //lost only 1 neigbour
1257 }
1258 }
1259 }
1260 }
1261 }
1262// if(aShape.ShapeType() == TopAbs_VERTEX && a1NBE) {
1263// //if atleast 1 Gen was missed and the Gen is Edge
1264// TopTools_ListIteratorOfListOfShape it(aList);
1265// for(;it.More();it.Next()) {
1266// if(it.Value().ShapeType() == TopAbs_EDGE) {
1267// const TopoDS_Shape& aV1 = TopExp::FirstVertex(TopoDS::Edge(it.Value()));
1268// const TopoDS_Shape& aV2 = TopExp::LastVertex(TopoDS::Edge(it.Value()));
1269// if(aShape.IsSame(aV1)) {aShape2 = aV2; cout << "##### => V2 " <<endl;break;}
1270// else
1271// if(aShape.IsSame(aV2)) {aShape2 = aV1; cout << "##### => V1 " <<endl;break;}
1272// }
1273// }
1274// }
1275 }
1276 }
1277 if(!aHas) // all arguments were kept
1278 B.Select(aShape, aShape); //only this case is correct on 100%
1279 else {
1280 if (a1NB) //Has, but may be ...
1281 B.Select(aShape, aShape);
1282 else {
1283 // put Compound, may be if possible processed later in Sel. Driver
1284 TopTools_ListIteratorOfListOfShape it1(aList2);
1285 for(;it1.More();it1.Next())
1286 B.Select(it1.Value(), it1.Value());
1287 }
1288 }
1289 } else
1290 { //not found
0797d9d3 1291#ifdef OCCT_DEBUG_GEN
7fd59977 1292 cout << "Generated ==> Shape is NOT found! Probably Compound will be built" <<endl;
1293#endif
1294
1295 TopTools_ListIteratorOfListOfShape it2(aList2);
1296 for(;it2.More();it2.Next())
1297 B.Select(it2.Value(), it2.Value());
1298 }
1299 }
1300 }
1301 return Standard_True;
1302}
1303
1304//=======================================================================
1305//function : Identity
1306//purpose : Regenerates Naming attribute with Name = IDENTITY
1307//=======================================================================
1308// Name with this type must contain only one NamedShape attribute as argument.
1309// Algorithm takes all last modifications of NamedShape of this argument
1310// starting with this one ( see method TNaming_NamingTool::CurrentShape ).
1311// Algorithm takes only NamedShapes belonging to the labels from the Valid
1312// labels map (if it's not empty) and put to the resulting NamedShape as compound.
1313//=======================================================================
1314static Standard_Boolean Identity (const TDF_Label& L,
1315 const TDF_LabelMap& Valid,
1316 const TNaming_ListOfNamedShape& Args,
1317 const TopAbs_ShapeEnum ShapeType)
1318{
1319 if (Args.Extent() > 2) {
9775fa61 1320 throw Standard_ConstructionError("TNaming_Name::Solve");
7fd59977 1321 }
7fd59977 1322 if(!ValidArgs(Args)) return Standard_False;
7fd59977 1323 const Handle(TNaming_NamedShape)& A = Args.First();
0df87563 1324 TopTools_IndexedMapOfShape MS;
7fd59977 1325 TDF_LabelMap Forbiden;
1326 TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS);
0797d9d3 1327#ifdef OCCT_DEBUG_SOL2
7fd59977 1328 //TCollection_AsciiString entry;
1329 //TDF_Tool::Entry(L, entry);
1330 //TDF_Tool::Entry(A->Label(), entry);
1331#endif
1332 TNaming_Builder B(L);
0df87563 1333 for (Standard_Integer anItMS = 1; anItMS <= MS.Extent(); ++anItMS) {
1334 const TopoDS_Shape& S = ShapeWithType (MS (anItMS), ShapeType);
0797d9d3 1335#ifdef OCCT_DEBUG_SOL2
7fd59977 1336 //TopAbs_Orientation Or = S.Orientation();
1337#endif
1338 B.Select(S,S);
1339 }
1340 return Standard_True;
1341}
1342
1343//=======================================================================
1344//function : FilterByNeighbourgs
1345//purpose : regenerated the specified shape with help of its neighbours
1346//=======================================================================
1347// result - is a subshape of the first argument of the Name with type =
1348// ShapeType of this Name, which has a common subshapes (boundaries) with
1349// each neighbour - shapes from the other arguments of the Name.
1350//=======================================================================
1351static Standard_Boolean FilterByNeighbourgs (const TDF_Label& L,
1352 const TDF_LabelMap& Valid,
1353 const TNaming_ListOfNamedShape& Args,
1354 const Handle(TNaming_NamedShape)& Stop,
1355 const TopAbs_ShapeEnum ShapeType)
1356{
1357
1358 TNaming_Builder B(L);
1359
1360 TDF_LabelMap Forbiden;
7fd59977 1361 if(!ValidArgs(Args)) return Standard_False;
7fd59977 1362 TNaming_NamingTool::BuildDescendants (Stop, Forbiden); //all descendants of Stop (New shapes) are forbidden
1363 if (!Stop.IsNull()) Forbiden.Remove(Stop->Label());
1364 //----------------------------------------
1365 // First argument: collection has to be filtered.
1366 //----------------------------------------
1367 Handle(TNaming_NamedShape) Cand = Args.First(); //collection of candidates
1368
0797d9d3 1369#ifdef OCCT_DEBUG_FNB
7fd59977 1370 Standard_Integer i = 1;
1371 TCollection_AsciiString aNam("Cand_");
1372 TCollection_AsciiString ext(".brep");
1373 DbgTools_WriteNSOnLabel(Cand, aNam.ToCString());
1374 cout << "Cand (Args.First()) Label = ";
1375 PrintEntry(Cand->Label());
1376 cout << "Valid Label map:" <<endl;
1377 PrintEntries(Valid);
1378#endif
1379
0df87563 1380 TopTools_IndexedMapOfShape SCand;
7fd59977 1381 TNaming_NamingTool::CurrentShape (Valid, Forbiden,Cand,SCand);//fills SCand with last modifications of Cand. CandNS should be at the same level (before) as NS of FilterByNBS
1382
0797d9d3 1383#ifdef OCCT_DEBUG_FNB
7fd59977 1384 TCollection_AsciiString aNam2("SCand");
1385 DbgTools_Write(SCand, aNam2.ToCString());
1386 cout <<"SCand Extent = " << SCand.Extent() << " Expected ShapeType = " << ShapeType << endl;
1387#endif
1388
1389 //------------------------------------------------------------
1390 // Autres arguments : contiennent les voisins du bon candidat.
1391 // Other arguments : contains the neighbors of the good candidate.
1392 //------------------------------------------------------------
1393 TopAbs_ShapeEnum TC = TopAbs_EDGE;
1394 if (ShapeType == TopAbs_EDGE) TC = TopAbs_VERTEX;
1395 if (ShapeType == TopAbs_VERTEX) TC = TopAbs_VERTEX; // szy 31.03.10 - to process case when Candidate is of type Vertex
1396
0797d9d3 1397#ifdef OCCT_DEBUG_FNB
7fd59977 1398 i=1;
1399 aNam = "Boundaries";
1400#endif
efd4b232 1401 Standard_Boolean isDone = Standard_False;
7fd59977 1402 if(SCand.Extent() == 1) { // check if a collection is inside
0df87563 1403 TopoDS_Shape aS = SCand (1);
7fd59977 1404 if(!aS.IsNull())
1405 if(aS.ShapeType() == TopAbs_COMPOUND && aS.ShapeType() != ShapeType) {
0df87563 1406 SCand.Clear();
7fd59977 1407 TopoDS_Iterator itt(aS);
1408 for(;itt.More();itt.Next())
1409 SCand.Add(itt.Value());
7fd59977 1410 }
1411 }
0df87563 1412 for (Standard_Integer anItSCand = 1; anItSCand <= SCand.Extent(); ++anItSCand) { //1
1413 const TopoDS_Shape& S = SCand (anItSCand);
7fd59977 1414 TopTools_MapOfShape Boundaries;
1415 if(S.ShapeType() == TopAbs_VERTEX) //# szy 31.03.10
1416 Boundaries.Add (S); //#
1417 else //#
1418 for (TopExp_Explorer exp(S,TC); exp.More(); exp.Next()) { //put boundaries of each candidate (from SCand) to the Boundaries map
1419 Boundaries.Add (exp.Current());
0797d9d3 1420#ifdef OCCT_DEBUG_FNB
7fd59977 1421 TCollection_AsciiString aName = aNam + i++ + ext;
1422 DbgTools_Write(exp.Current(), aName.ToCString()) ;
1423#endif
1424 }
1425
1426 TNaming_ListIteratorOfListOfNamedShape it(Args);
1427 it.Next();
1428 Standard_Boolean Keep = 1;
0797d9d3 1429#ifdef OCCT_DEBUG_FNB
7fd59977 1430 cout <<"Args number = " << Args.Extent() <<endl;
1431 i=1;
1432 aNam = "Boundaries";
1433#endif
1434 for ( ; it.More(); it.Next()) { //2 ==> for each Arg
1435 Standard_Boolean Connected = Standard_False;
1436 // Le candidat doit etre connexe a au moins un shape de
1437 // chaque NamedShape des voisins.
1438 // The candidate should be connectedand and have at least one shape of NamedShape
1439 // of each neighbor.
1440 const Handle(TNaming_NamedShape)& NSVois = it.Value(); //neighbor
1441
0797d9d3 1442#ifdef OCCT_DEBUG_FNB
7fd59977 1443 DbgTools_WriteNSOnLabel(NSVois, "Next_Neighbor_") ;
1444#endif
1445
0df87563 1446 TopTools_IndexedMapOfShape SVois;
7fd59977 1447 TNaming_NamingTool::CurrentShape (Valid, Forbiden,NSVois,SVois); // fills SVois with last modifications of NSVois
1448
0797d9d3 1449#ifdef OCCT_DEBUG_FNB
7fd59977 1450 TCollection_AsciiString aNam2("SVois");
1451 DbgTools_Write(SVois, aNam2.ToCString());
1452#endif
1453
0df87563 1454 for (Standard_Integer anItSVois = 1; anItSVois <= SVois.Extent(); ++anItSVois) { //6
1455 const TopoDS_Shape& Vois = SVois (anItSVois);
7fd59977 1456 for (TopExp_Explorer exp1(Vois,TC); exp1.More(); exp1.Next()) { //7
1457 if (Boundaries.Contains(exp1.Current())) {
1458 Connected = Standard_True; // has common boundaries with candidate shape
0797d9d3 1459#ifdef OCCT_DEBUG_FNB
7fd59977 1460 DbgTools_Write(Vois, "Neighbor_Connected.brep");
1461#endif
1462 break;
1463 }
1464 } //7
1465 if (Connected) break;
1466 } //6
1467 if (!Connected) {
1468 Keep = 0;
1469 break;
1470 }
1471 } //2
1472 if (Keep) {
1473 B.Select (S,S);
efd4b232 1474 isDone = Standard_True;
0797d9d3 1475#ifdef OCCT_DEBUG_FNB
7fd59977 1476 DbgTools_Write(S, "FilterByNbs_Sel.brep") ;
1477#endif
1478 }
1479 } //1
efd4b232 1480 return isDone;
7fd59977 1481}
1482
1483//=======================================================================
1484static const TopoDS_Shape FindSubShapeInAncestor(const TopoDS_Shape& Selection, const TopoDS_Shape& Context )
1485{
0797d9d3 1486#ifdef OCCT_DEBUG_OR_AG
7fd59977 1487 DbgTools_Write(Selection, "Orientation_Selection.brep");
1488 DbgTools_Write(Context, "Orientation_Context.brep");
1489 TopExp_Explorer expl1(Context, Selection.ShapeType());
1490 int i = 0;
1491 TCollection_AsciiString SS( "Orientation_Current_");
1492 for(;expl1.More(); expl1.Next()) {
1493 if(expl1.Current().IsSame(Selection)) {
1494 i++;
1495 cout <<"FindSubShape: = " <<expl1.Current().ShapeType() << " TS = " <<expl1.Current().TShape() << endl;
1496 TCollection_AsciiString nam = SS + i + ".brep";
1497 DbgTools_Write(expl1.Current(), nam.ToCString());
1498 }
1499 }
1500#endif
1501 if(Selection.ShapeType() != TopAbs_COMPOUND) {
1502 TopExp_Explorer anExpl(Context, Selection.ShapeType());
1503 for(;anExpl.More(); anExpl.Next()) {
0797d9d3 1504#ifdef OCCT_DEBUG_OR_AG
7fd59977 1505 cout <<"FindSubShape: = " <<anExpl.Current().ShapeType() << " TS = " <<anExpl.Current().TShape()->This() << endl;
1506 DbgTools_Write(anExpl.Current(), "Orientation_Current.brep");
1507#endif
1508 if(anExpl.Current().IsSame(Selection))
1509 return anExpl.Current();
1510 }
1511 }
1512
1513 return TopoDS_Shape();
1514}
1515
1516//=======================================================================
1517//static Standard_Integer Count(const TopoDS_Shape& S)
1518//{
1519// Standard_Integer N(0);
1520// TopoDS_Iterator it(S);
1521// for(;it.More();it.Next()) {
1522// if(it.Value().ShapeType() != TopAbs_COMPOUND && it.Value().ShapeType() != TopAbs_COMPSOLID)
1523// N++;
1524// else {
1525// N += Count(it.Value());
1526// }
1527// }
1528// return N;
1529//}
1530//=======================================================================
1531static Standard_Integer Aggregation (const TopoDS_Shape& S, const TopoDS_Shape& AS, TNaming_Builder& B)
1532{
1533 Standard_Integer N(0);
1534 TopoDS_Iterator it(S);
1535 for(;it.More();it.Next()) {
1536 const TopoDS_Shape& sel = it.Value();
1537 if(sel.ShapeType() > TopAbs_COMPSOLID) {
1538 const TopoDS_Shape& CS = FindSubShapeInAncestor(sel, AS);
1539 if(!CS.IsNull()) {
1540 B.Select(CS, CS);
1541 N++;
1542 }
1543 } else
1544 N += Aggregation(sel, AS, B);
1545 }
1546 return N;
1547}
1548
1549//==========================================================================
1550//function : Orientation
1551//purpose : to solve ORIENTATION name
1552// this function explores the second argument | arguments (Context) and
1553// keeps at the label (L) the first argument (S) with the orientation it
1554// has in the context. Index is used only for Seam edge recomputing
1555//==========================================================================
1556static Standard_Boolean ORientation (const TDF_Label& L,
1557 const TDF_LabelMap& Valid,
1558 const TNaming_ListOfNamedShape& Args,
1559 const Handle(TNaming_NamedShape)& Stop,
1560 const Standard_Integer Index)
1561{
1562
1563 if(!ValidArgs(Args)) return Standard_False;
1564
1565 const Handle(TNaming_NamedShape)& A = Args.First();
0df87563 1566 TopTools_IndexedMapOfShape MS;
7fd59977 1567 TDF_LabelMap Forbiden;
1568 TNaming_NamingTool::BuildDescendants (Stop, Forbiden);
1569 TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS);
1570
51740958 1571 TopoDS_Shape aShape;
7fd59977 1572 Standard_Boolean isSplit(Standard_False);
1573 if (!MS.IsEmpty ()) {
7fd59977 1574 if (MS.Extent() == 1) {
51740958 1575 aShape = MS (1);
7fd59977 1576 }
1577 else {
1578 isSplit = Standard_True;
51740958 1579 aShape = MakeShape(MS);
0797d9d3 1580#ifdef OCCT_DEBUG_OR
0df87563 1581 for(Standard_Integer anItMS = 1; anItMS <= MS.Extent(); anItMS++) {
7fd59977 1582 TCollection_AsciiString aNam("OR_Selection_");
0df87563 1583 TCollection_AsciiString aName = aNam + anItMS + ".brep";
1584 DbgTools_Write(MS (anItMS), aName.ToCString());
7fd59977 1585 }
1586#endif
1587 }
1588 }
1589
1590 TNaming_Builder B(L);
51740958 1591 if(aShape.IsNull())
7fd59977 1592 return Standard_False;
0797d9d3 1593#ifdef OCCT_DEBUG_OR
7fd59977 1594 DbgTools_Write(S, "Orientation_S.brep");
1595#endif
1596
1597 TopTools_ListOfShape aSList;
1598 // tmp. solution
51740958 1599 if(aShape.ShapeType() == TopAbs_COMPOUND && !isSplit) {
1600 TopoDS_Iterator it(aShape);
7fd59977 1601 for(;it.More();it.Next())
1602 aSList.Append(it.Value());
1603 } //
1604
0df87563 1605 TopTools_IndexedMapOfShape MSC;
7fd59977 1606 if(aSList.Extent() == 0) {
1607 const Handle(TNaming_NamedShape)& Anc = Args.Last();
0797d9d3 1608#ifdef OCCT_DEBUG_OR
7fd59977 1609 cout << "### ORIENTATION: Ancestor ";
1610 PrintEntry(Anc->Label());
1611#endif
1612 MSC.Clear();
1613 TNaming_NamingTool::CurrentShape (Valid,Forbiden,Anc,MSC);
1614 if(MSC.Extent() == 1) {
0df87563 1615 for (Standard_Integer anItMSC = 1; anItMSC <= MSC.Extent(); ++anItMSC) {
1616 const TopoDS_Shape& AS = MSC (anItMSC);
7fd59977 1617// <=== start 21.10.2009
1618 TopoDS_Shape CS;
1619 if(Index > 0) { //only for seam edge
1620 TopoDS_Iterator itw(AS);
1621 for(;itw.More();itw.Next()) {
1622 Standard_Boolean found(Standard_False);
1623 TopoDS_Iterator it(itw.Value());
1624 for(int i=1;it.More();it.Next(),i++) {
51740958 1625 if(i == Index && it.Value().IsSame(aShape)) {
7fd59977 1626 CS = it.Value();
1627 found = Standard_True;
0797d9d3 1628#ifdef OCCT_DEBUG_OR
7fd59977 1629 cout << "ORIENTATION => ORDER = " << i <<endl;
1630#endif
1631 break;
1632 }
1633 }
1634 if(found) break;
1635 }
1636 } else
51740958 1637 CS = FindSubShapeInAncestor(aShape, AS);
7fd59977 1638// <=== end 21.10.2009
0797d9d3 1639#ifdef OCCT_DEBUG_OR
586db386 1640 cout << "ORIENTATION: Selection TShape = " <<CS.TShape() <<" Orientation = " << CS.Orientation() <<endl;
1641 cout << "ORIENTATION: Context ShapeType = "<<AS.ShapeType() << " TShape = " <<AS.TShape() <<endl;
7fd59977 1642 DbgTools_Write(AS, "Orientation_Cnt.brep");
1643#endif
1644 if(!CS.IsNull()) {
1645 B.Select(CS, CS);
1646 } else {
51740958 1647 if(!Aggregation(aShape, AS, B))
7fd59977 1648 return Standard_False;
1649 }
1650 }
1651 } else {
1652 const TopoDS_Shape AS = MakeShape(MSC);
51740958 1653 const TopoDS_Shape& CS = FindSubShapeInAncestor(aShape, AS);
7fd59977 1654 if(!CS.IsNull()) {
1655 B.Select(CS, CS);
1656 } else {
51740958 1657 if(!Aggregation(aShape, AS, B))
7fd59977 1658 return Standard_False;
1659 }
1660 }
1661 } else {
1662 TNaming_ListIteratorOfListOfNamedShape it(Args);
1663 it.Next(); //skip first
1664
1665 // temporary solution. To be optimized (+ has connection with Union name)
1666 Handle(TopTools_HArray2OfShape) Arr; // Arr(1,1) - selection; Arr(1,2) - Context shape
1667 Arr = new TopTools_HArray2OfShape (1, aSList.Extent(), 1, 2);
1668 TopTools_ListIteratorOfListOfShape it1(aSList);
1669 Standard_Integer i = 1;
1670 for(; it1.More(); it1.Next(), it.Next(), i++) {
1671 Arr->SetValue(i, 1, it1.Value());
1672 MSC.Clear();
1673 TNaming_NamingTool::CurrentShape (Valid,Forbiden,it.Value(),MSC);
1674 if(MSC.Extent() == 1) {
0df87563 1675 Arr->SetValue(i, 2, MSC (1));
7fd59977 1676 } else {
1677 const TopoDS_Shape AS = MakeShape(MSC);
1678 Arr->SetValue(i, 2, AS);
1679 }
1680 }
1681
1682 if(aSList.Extent() == 1) {
1683 const TopoDS_Shape& S = Arr->Value(1,1);
1684 if(S.ShapeType() != TopAbs_COMPOUND) {
1685 const TopoDS_Shape& CS = FindSubShapeInAncestor(S, Arr->Value(1,2));
1686 if(!CS.IsNull()) {
1687 B.Select(CS, CS);
1688 } else
1689 return Standard_False;
1690 }
1691 else {
0797d9d3 1692#ifdef OCCT_DEBUG_OR
7fd59977 1693 DbgTools_Write(Arr->Value(1,2), "Ancestor.brep");
1694#endif
1695 if(!Aggregation(S, Arr->Value(1,2), B)) {
1696 return Standard_False;
1697 }
1698 }
1699 }
1700 else { // > 1
51740958 1701 for(Standard_Integer k = Arr->LowerRow();k <= Arr->UpperRow();k++) {
1702 const TopoDS_Shape& S = Arr->Value(k,1);
1703 const TopoDS_Shape& AC = Arr->Value(k,2);
7fd59977 1704 if(S.ShapeType() != TopAbs_COMPOUND) {
1705 const TopoDS_Shape& CS = FindSubShapeInAncestor(S, AC);
1706 if(!CS.IsNull()) {
1707 B.Select(CS, CS);
1708 } else
1709 return Standard_False;
1710 }
1711 else {
0797d9d3 1712#ifdef OCCT_DEBUG_OR
7fd59977 1713 DbgTools_Write(AC, "Aggregation.brep");
1714#endif
1715 if(!Aggregation(S, AC, B)) {
1716 return Standard_False;
1717 }
1718 }
1719 }
1720 }
1721 } // end of tmp. solution
1722
1723 return Standard_True;
1724}
1725
1726//===========================================================================
1727//function : WireIN
1ec8a59e 1728//purpose : to solve WIREIN name
7fd59977 1729//=======================================================================
1730static Standard_Boolean WireIN(const TDF_Label& L,
1731 const TDF_LabelMap& Valid,
1ec8a59e 1732 const TNaming_ListOfNamedShape& Args,
1733 const Handle(TNaming_NamedShape)& Stop,
1734 Standard_Integer Index)
7fd59977 1735{
1736 Standard_Boolean aResult(Standard_False);
1737 if(!ValidArgs(Args)) return aResult;
51740958 1738 TopTools_IndexedMapOfShape aMapOfSh;
1739 TDF_LabelMap aForbiden;
1ec8a59e 1740 if (Args.Extent() < 1 )
9775fa61 1741 throw Standard_ConstructionError("TNaming_Name::Solve");
1ec8a59e 1742 const Handle(TNaming_NamedShape)& A = Args.First();
51740958 1743 TNaming_NamingTool::CurrentShape (Valid,aForbiden,A, aMapOfSh);
1744 if (aMapOfSh.Extent() != 1) return aResult;
1745 const TopoDS_Shape& aCF = aMapOfSh(1);
0797d9d3 1746#ifdef OCCT_DEBUG_WIN
7fd59977 1747 cout <<"MS Extent = " <<MS.Extent() <<endl;
1ec8a59e 1748 DbgTools_Write(aCF, "Context_Face.brep");
7fd59977 1749#endif
7fd59977 1750 TNaming_Builder B(L);
1ec8a59e 1751 if(Index == 1 ){ //Outer wire case
1752 TopoDS_Wire anOuterWire;
1753 TNaming::OuterWire(TopoDS::Face(aCF), anOuterWire);
1754 if(!anOuterWire.IsNull()) {
1755 B.Select(anOuterWire, anOuterWire);
1756 aResult = Standard_True;
1757 }
1758 } else { //has internal wires
1759 TNaming_ListOfNamedShape ArgsE;
1760 ArgsE.Assign(Args);
1761 ArgsE.RemoveFirst();
1762 // fill Map with edges
51740958 1763 TNaming_ListIteratorOfListOfNamedShape anIter(ArgsE);
0df87563 1764 TopTools_IndexedMapOfShape MS;
1ec8a59e 1765 TDF_LabelMap Forbiden;
1766
1767 TNaming_NamingTool::BuildDescendants (Stop, Forbiden);//fill Forbidden
51740958 1768 TNaming_NamingTool::CurrentShape (Valid, Forbiden, anIter.Value(),MS); // fill MS with last modifications of the first additional argument
1ec8a59e 1769 TopoDS_Shape CS = MakeShape(MS);
1770
1771 TNaming_ShapesSet aSet(CS,TopAbs_EDGE);//fill internal map of shapeset by shapes of the specified type
0797d9d3 1772#ifdef OCCT_DEBUG_WIN
1ec8a59e 1773 TCollection_AsciiString entry;
1774 TDF_Tool::Entry(it.Value()->Label(), entry);
1775 TCollection_AsciiString Nam("Arg_");
1776 TCollection_AsciiString aNam = Nam + entry + "_" + "2.brep";
1777 DbgTools_Write(CS, aNam.ToCString());
1778 Standard_Integer ii = 2;
1779#endif
51740958 1780 anIter.Next();
1781 for (; anIter.More(); anIter.Next()) {
0797d9d3 1782#ifdef OCCT_DEBUG_WIN
1ec8a59e 1783 TDF_Tool::Entry(it.Value()->Label(), entry);
1784#endif
1785 MS.Clear();
51740958 1786 TNaming_NamingTool::CurrentShape (Valid, Forbiden,anIter.Value(),MS);// fill MS with last modifications of the it.Value()
1ec8a59e 1787 CS = MakeShape(MS);
1788 TNaming_ShapesSet OS(CS,TopAbs_EDGE);
1789 aSet.Add(OS); //concatenate both shapesets
1790
0797d9d3 1791#ifdef OCCT_DEBUG_WIN
1ec8a59e 1792 ii++;
1793 TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep";
1794 DbgTools_Write(CS, aNm.ToCString());
1795 cout <<"Arg: Entry = " <<entry <<" TShape = " << CS.TShape() <<endl;
7fd59977 1796#endif
1ec8a59e 1797 }
1798
0797d9d3 1799#ifdef OCCT_DEBUG_WIN
586db386 1800 cout <<"WIREIN: Internal Map ext = " << aSet.Map().Extent()<<endl;
1ec8a59e 1801 TopTools_MapIteratorOfMapOfShape it1 (aSet.Map());
1802 for (int i=1;it1.More();it1.Next(),i++) {
1803 cout << "Map("<<i<<"): TShape = " << it1.Key().TShape() << " Orient = " << it1.Key().Orientation() <<" Type = " <<
1804 it1.Key().ShapeType()<<endl;
7fd59977 1805 }
1806
1ec8a59e 1807 TopExp_Explorer exp(aCF, TopAbs_EDGE);
1808 for(int i =1;exp.More();exp.Next(), i++) {
1809 cout << "Context_Face("<<i<<"): TShape = " << exp.Current().TShape() << " Orient = " << exp.Current().Orientation() <<endl;
1810 }
7fd59977 1811#endif
1ec8a59e 1812//end for edges
1813
1814 for (TopoDS_Iterator itF(aCF); itF.More(); itF.Next()) {// find the expected wire in the face
1815 const TopoDS_Shape& S = itF.Value();//wire
1816 if(!S.IsNull()) {
0797d9d3 1817#ifdef OCCT_DEBUG_WIN
1ec8a59e 1818 DbgTools_Write(S, "WireIN_S.brep");
1819 cout <<"WIREIN: ShapeType = " << S.ShapeType() << " TS = " << S.TShape()->This() <<endl;
1820#endif
1821 if(S.ShapeType() == TopAbs_WIRE) {
1822 TopTools_MapOfShape aView;
1823 Standard_Integer aNum(0x7FFFFFFF);
1824 for (TopoDS_Iterator it(S);it.More();it.Next())
1825 aView.Add(it.Value());// edges of wire of the face in map
1826
1827 TopTools_MapIteratorOfMapOfShape it (aSet.Map());
1828 aNum = aView.Extent();
1829 if(aNum == aSet.Map().Extent()) {
1830 for (;it.More();it.Next()) {
1831 if(aView.Contains(it.Key())) {
1832 aNum--;
1833 }
1834 }
1835 }
1836 if(aNum == 0) {
1837 B.Select(S, S);
1838 aResult = Standard_True;
7fd59977 1839 break;
1ec8a59e 1840 }
1841 }
1842 }
1843 } //
1844
1845 if(!aResult) {
1846 TopoDS_Wire anOuterWire;
1847 TNaming::OuterWire(TopoDS::Face(aCF), anOuterWire);
1848 if(!anOuterWire.IsNull()) {
1849 for (TopoDS_Iterator itF(aCF); itF.More(); itF.Next()) {
1850 const TopoDS_Shape& S = itF.Value();//wire
1851 if(!S.IsNull()&& S.ShapeType() == TopAbs_WIRE) {
1852 if(S.IsEqual(anOuterWire)) continue;
1853 B.Select(S, S);
1854 }
7fd59977 1855 }
1856 }
1ec8a59e 1857 }
1858 }
1859 return aResult;
1860}
1861//===========================================================================
1862//function : ShellIN
1863//purpose : to solve SHELLIN name
1864//===========================================================================
1865static Standard_Boolean ShellIN(const TDF_Label& L,
1866 const TDF_LabelMap& Valid,
1867 const TNaming_ListOfNamedShape& Args,
1868 const Handle(TNaming_NamedShape)& Stop,
1869 Standard_Integer Index)
1870{
1871 Standard_Boolean aResult(Standard_False);
1872 if(!ValidArgs(Args))
1873 return aResult;
51740958 1874 TopTools_IndexedMapOfShape aMapOfSh;
1875 TDF_LabelMap aForbiden;
1ec8a59e 1876 if (Args.Extent() < 1 )
9775fa61 1877 throw Standard_ConstructionError("TNaming_Name::Solve");
1ec8a59e 1878 const Handle(TNaming_NamedShape)& A = Args.First();
51740958 1879 TNaming_NamingTool::CurrentShape (Valid,aForbiden,A, aMapOfSh);
1880 if (aMapOfSh.Extent() != 1) return aResult;
1881 const TopoDS_Shape& aCSO = aMapOfSh(1);
0797d9d3 1882#ifdef OCCT_DEBUG_SHELL
1ec8a59e 1883 cout <<"MS Extent = " <<MS.Extent() <<endl;
1884 DbgTools_Write(aCSO, "Context_Solid.brep");
1885#endif
1886 TNaming_Builder B(L);
1887 if(Index == 1 ){ //Outer Shell case
1888 TopoDS_Shell anOuterShell;
1889 TNaming::OuterShell(TopoDS::Solid(aCSO), anOuterShell);
1890 if(!anOuterShell.IsNull()) {
1891 B.Select(anOuterShell, anOuterShell);
7fd59977 1892 aResult = Standard_True;
0797d9d3 1893#ifdef OCCT_DEBUG_SHELL
1ec8a59e 1894 cout << "Outer Shell case" <<endl;
1895 PrintEntry(L);
1896 DbgTools_Write(anOuterShell, "ShellOut_S.brep");
0df87563 1897 TopoDS_Iterator it (aCSO);
1ec8a59e 1898 for(;it.More();it.Next()){
1899 DbgTools_Write(it.Value(), "ShOut_S.brep");
1900 }
1901#endif
7fd59977 1902 }
1ec8a59e 1903 } else { //has internal Shells
1904 TNaming_ListOfNamedShape ArgsF;
1905 ArgsF.Assign(Args);
1906 ArgsF.RemoveFirst();
1907 // fill Map with faces
51740958 1908 TNaming_ListIteratorOfListOfNamedShape anIter(ArgsF);
0df87563 1909 TopTools_IndexedMapOfShape MS;
1ec8a59e 1910 TDF_LabelMap Forbiden;
1911
1912 TNaming_NamingTool::BuildDescendants (Stop, Forbiden);//fill Forbidden
51740958 1913 TNaming_NamingTool::CurrentShape (Valid, Forbiden, anIter.Value(),MS); // fill MS with last modifications of the first additional argument
1ec8a59e 1914 TopoDS_Shape CS = MakeShape(MS);
1915
1916 TNaming_ShapesSet aSet(CS,TopAbs_FACE);//fill internal map of shapeset by shapes of the specified type
0797d9d3 1917#ifdef OCCT_DEBUG_SHELL
1ec8a59e 1918 TCollection_AsciiString entry;
51740958 1919 TDF_Tool::Entry(anIter.Value()->Label(), entry);
1ec8a59e 1920 TCollection_AsciiString Nam("Arg_");
1921 TCollection_AsciiString aNam = Nam + entry + "_" + "2.brep";
1922 DbgTools_Write(CS, aNam.ToCString());
1923 Standard_Integer ii = 2;
1924#endif
51740958 1925 anIter.Next();
1926 for (; anIter.More(); anIter.Next()) {
0797d9d3 1927#ifdef OCCT_DEBUG_SHELL
51740958 1928 TDF_Tool::Entry(anIter.Value()->Label(), entry);
1ec8a59e 1929#endif
1930 MS.Clear();
51740958 1931 TNaming_NamingTool::CurrentShape (Valid, Forbiden,anIter.Value(),MS);// fill MS with last modifications of the it.Value()
1ec8a59e 1932 CS = MakeShape(MS);
1933 TNaming_ShapesSet OS(CS,TopAbs_FACE);
1934 aSet.Add(OS); //concatenate both shapesets
1935
0797d9d3 1936#ifdef OCCT_DEBUG_SHELL
1ec8a59e 1937 ii++;
1938 TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep";
1939 DbgTools_Write(CS, aNm.ToCString());
1940 cout <<"Arg: Entry = " <<entry <<" TShape = " << CS.TShape() <<endl;
1941#endif
1942 }
1943
0797d9d3 1944#ifdef OCCT_DEBUG_SHELL
586db386 1945 cout <<"SHELLIN: Internal Map ext = " << aSet.Map().Extent()<<endl;
1ec8a59e 1946 TopTools_MapIteratorOfMapOfShape it1 (aSet.Map());
1947 for (int i=1;it1.More();it1.Next(),i++) {
1948 cout << "Map("<<i<<"): TShape = " << it1.Key().TShape() << " Orient = " << it1.Key().Orientation() <<" Type = " <<
1949 it1.Key().ShapeType()<<endl;
7fd59977 1950 }
1ec8a59e 1951
1952 TopExp_Explorer exp(aCSO, TopAbs_FACE);
1953 for(int i = 1;exp.More();exp.Next(), i++) {
1954 cout << "Context_Solid("<<i<<"): TShape = " << exp.Current().TShape() << " Orient = " << exp.Current().Orientation() <<endl;
1955 }
1956#endif
1957//end for faces
1958
1959 for (TopoDS_Iterator itS(aCSO); itS.More(); itS.Next()) {// find the expected shell in the solid
1960 const TopoDS_Shape& S = itS.Value();//shell
1961 if(!S.IsNull()) {
0797d9d3 1962#ifdef OCCT_DEBUG_SHELL
1ec8a59e 1963 DbgTools_Write(S, "ShellIN_S.brep");
1964 cout <<"SHELLIN: ShapeType = " << S.ShapeType() << " TS = " << S.TShape()->This() <<endl;
1965#endif
1966 if(S.ShapeType() == TopAbs_SHELL) {
1967 TopTools_MapOfShape aView;
1968 Standard_Integer aNum(0x7FFFFFFF);
1969 for (TopoDS_Iterator it(S);it.More();it.Next())
1970 aView.Add(it.Value());// faces of shell of the solid in map
1971
1972 aNum = aView.Extent();
1973 if(aNum == aSet.Map().Extent()) {
1974 TopTools_MapIteratorOfMapOfShape it (aSet.Map());
1975 for (;it.More();it.Next()) {
1976 if(aView.Contains(it.Key())) {
1977 aNum--;
1978 }
1979 }
1980 }
1981 if(aNum == 0) {
1982 B.Select(S, S);
1983 aResult = Standard_True;
1984 break;
1985 }
1986 }
1987 }
1988 } //
1989
1990 if(!aResult) {
1991 TopoDS_Shell anOuterShell;
1992 TNaming::OuterShell(TopoDS::Solid(aCSO), anOuterShell);
1993 if(!anOuterShell.IsNull()) {
1994 for (TopoDS_Iterator itS(aCSO); itS.More(); itS.Next()) {
1995 const TopoDS_Shape& S = itS.Value();//shell
1996 if(!S.IsNull()&& S.ShapeType() == TopAbs_SHELL) {
1997 if(S.IsEqual(anOuterShell)) continue;
1998 B.Select(S, S);
1999 }
2000 }
2001 }
2002 }
7fd59977 2003 }
2004 return aResult;
2005}
0797d9d3 2006#ifdef OCCT_DEBUG
7fd59977 2007//=======================================================================
2008static Standard_CString NameTypeToString (const TNaming_NameType Type)
2009{
2010 switch(Type)
2011 {
2012 case TNaming_UNKNOWN : return "UNKNOWN";
2013 case TNaming_IDENTITY : return "IDENTITY";
2014 case TNaming_MODIFUNTIL : return "MODIFUNTIL";
2015 case TNaming_GENERATION : return "GENERATION";
2016 case TNaming_INTERSECTION : return "INTERSECTION";
2017 case TNaming_UNION : return "UNION";
2018 case TNaming_SUBSTRACTION : return "SUBSTRACTION";
2019 case TNaming_CONSTSHAPE : return "CONSTSHAPE";
2020 case TNaming_FILTERBYNEIGHBOURGS : return "FILTERBYNEIGHBOURGS";
2021 case TNaming_ORIENTATION : return "ORIENTATION";
2022 case TNaming_WIREIN : return "WIREIN";
2023 default :
9775fa61 2024 throw Standard_DomainError("TNaming_NameType; enum term unknown ");
7fd59977 2025 }
7fd59977 2026}
2027#endif
2028//=======================================================================
2029//function : Solve
2030//purpose :
2031//=======================================================================
2032
2033Standard_Boolean TNaming_Name::Solve(const TDF_Label& aLab,
2034 const TDF_LabelMap& Valid) const
2035{
2036 Standard_Boolean Done = 0;
0797d9d3 2037#ifdef OCCT_DEBUG_WIN
1ec8a59e 2038 PrintEntry(aLab);
2039#endif
7fd59977 2040 try {
b350f6ee 2041 OCC_CATCH_SIGNALS
7fd59977 2042 switch (myType) {
2043 case TNaming_UNKNOWN :
2044 {
2045 break;
2046 }
2047 case TNaming_IDENTITY :
2048 {
2049 Done = Identity(aLab,Valid,myArgs,myShapeType);
2050 break;
2051 }
2052 case TNaming_MODIFUNTIL:
2053 {
2054 Done = ModifUntil (aLab,Valid,myArgs,myStop);
2055 break;
2056 }
2057 case TNaming_GENERATION:
2058 {
2059 Done = Generated (aLab,Valid,myArgs);
2060 break;
2061 }
2062 case TNaming_INTERSECTION:
2063 {
2064 Done = Intersection (aLab,Valid,myArgs,myStop,myShapeType,myIndex);
2065 break;
2066 }
2067 case TNaming_UNION:
2068 {
2069 Done = Union (aLab,Valid,myArgs,myStop,myShapeType, myContextLabel);
2070 break;
2071 }
2072 case TNaming_SUBSTRACTION:
2073 {
9775fa61 2074 throw Standard_NotImplemented();
7fd59977 2075// Done = Substraction (aLab,Valid,myArgs);
2076 break;
2077 }
2078 case TNaming_CONSTSHAPE:
2079 {
2080 Done = ConstShape (aLab,Valid,myArgs,myStop,myIndex);
2081 break;
2082 }
2083 case TNaming_FILTERBYNEIGHBOURGS:
2084 {
2085 Done = FilterByNeighbourgs (aLab,Valid,myArgs,myStop,myShapeType);
2086 break;
2087 }
2088 case TNaming_ORIENTATION:
2089 {
2090 Done = ORientation (aLab,Valid,myArgs,myStop,myIndex);
2091 break;
2092 }
2093 case TNaming_WIREIN:
2094 {
0797d9d3 2095#ifdef OCCT_DEBUG_WIN
1ec8a59e 2096 cout << "Name::Solve: NameType = " << myType << " ";
2097 PrintEntry(aLab);
2098#endif
2099 Done = WireIN (aLab,Valid,myArgs,myStop,myIndex);
2100 break;
2101 }
2102case TNaming_SHELLIN:
2103 {
0797d9d3 2104#ifdef OCCT_DEBUG_SHELL
1ec8a59e 2105 cout << "Name::Solve: NameType = " << myType << " ";
2106 PrintEntry(aLab);
2107#endif
2108 Done = ShellIN (aLab,Valid,myArgs,myStop,myIndex);
7fd59977 2109 break;
2110 }
2111 }
b350f6ee 2112} catch (Standard_Failure) {
0797d9d3 2113#ifdef OCCT_DEBUG
7fd59977 2114 cout << "Name::Solve: EXCEPTION==> NameType = " << NameTypeToString(myType) << " ";
2115 PrintEntry(aLab);
2116#endif
2117}
2118 return Done;
2119}
2120
2121//=======================================================================
2122//function : ContextLabel
2123//purpose : Set
2124//=======================================================================
2125
2126void TNaming_Name::ContextLabel(const TDF_Label& theLabel)
2127{
2128 myContextLabel = theLabel;
2129}
2130
2131//=======================================================================
2132//function : ContextLabel
2133//purpose : Get
2134//=======================================================================
2135
2136const TDF_Label& TNaming_Name::ContextLabel() const
2137{
2138 return myContextLabel;
2139}
7dcac1df 2140
7fd59977 2141//=======================================================================
2142//function : Orientation
2143//purpose : Set
2144//=======================================================================
7dcac1df 2145void TNaming_Name::Orientation(const TopAbs_Orientation theOrientation)
7fd59977 2146{
2147 myOrientation = theOrientation;
2148}
2149