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