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