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