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