Salome HOME
27.10.2014. Naming data structure for Extrusion feature.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_DFLoader.cpp
1 // File:        GeomAlgoAPI_DFLoader.cpp
2 // Created:     23 October 2014
3 // Author:      Sergey Zaritchny
4
5 #include <GeomAlgoAPI_DFLoader.h>
6 #include <TopoDS_Iterator.hxx>
7 #include <TopTools_MapOfShape.hxx>
8 #include <TopExp_Explorer.hxx>
9 #include <TopTools_ListIteratorOfListOfShape.hxx>
10 //=======================================================================
11 //function : refineResult
12 //purpose  :
13 //=======================================================================
14 const TopoDS_Shape GeomAlgoAPI_DFLoader::refineResult(const  TopoDS_Shape& theResult)
15 {
16   TopoDS_Shape aResult;
17   if (theResult.ShapeType() == TopAbs_COMPOUND) {
18     Standard_Integer nbSubResults = 0;
19     TopoDS_Iterator itr(theResult);
20     for (; itr.More(); itr.Next()) nbSubResults++;
21     if (nbSubResults == 1) {
22       itr.Initialize(theResult);
23       if (itr.More()) aResult = itr.Value();
24     }
25   }
26   return aResult;
27 }
28 /*
29 //=======================================================================
30 //function : loadDeletedShapes
31 //purpose  : load deleted shapes in DF
32 //=======================================================================
33 void GeomAlgoAPI_DFLoader::loadDeletedShapes (BRepBuilderAPI_MakeShape& theMS,
34                                        const TopoDS_Shape&     theShapeIn,
35                                        const TopAbs_ShapeEnum  theKindOfShape,
36                                        TNaming_Builder&        theBuilder)
37 {
38   TopTools_MapOfShape aView;
39   TopExp_Explorer ShapeExplorer (theShapeIn, theKindOfShape);
40   for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
41     const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
42     if (!aView.Add(aRoot)) continue;
43     if (theMS.IsDeleted (aRoot)) {
44       theBuilder.Delete (aRoot);
45     }
46   }
47 }
48
49 //=======================================================================
50 //function : loadAndOrientModifiedShapes
51 //purpose  : load modified shapes in DF with preliminary orientation adjustment
52 //=======================================================================
53 void GeomAlgoAPI_DFLoader::loadAndOrientModifiedShapes (BRepBuilderAPI_MakeShape&    theMS,
54                                            const TopoDS_Shape&        theShapeIn,
55                                            const TopAbs_ShapeEnum     theKindOfShape,
56                                            TNaming_Builder&           theBuilder,
57                                            const TopTools_DataMapOfShapeShape& theSubShapes)
58 {
59   TopTools_MapOfShape aView;
60   TopExp_Explorer aShapeExplorer (theShapeIn, theKindOfShape);
61   for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
62     const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
63     if (!aView.Add(aRoot)) continue;
64     const TopTools_ListOfShape& aShapes = theMS.Modified (aRoot);
65     TopTools_ListIteratorOfListOfShape aShapesIterator (aShapes);
66     for (;aShapesIterator.More (); aShapesIterator.Next ()) {
67       TopoDS_Shape aNewShape = aShapesIterator.Value ();
68       if (theSubShapes.IsBound(aNewShape)) {
69         aNewShape.Orientation((theSubShapes(aNewShape)).Orientation());
70       }
71       if (!aRoot.IsSame (aNewShape)) theBuilder.Modify (aRoot, aNewShape );
72     }
73   }
74 }
75
76 //=======================================================================
77 //function : loadAndOrientGeneratedShapes
78 //purpose  : load generated shapes in DF with preliminary orientation adjustment
79 //=======================================================================
80
81 void GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes (BRepBuilderAPI_MakeShape&     theMS,
82                                                 const TopoDS_Shape&           theShapeIn,
83                                                 const TopAbs_ShapeEnum        theKindOfShape,
84                                                 TNaming_Builder&              theBuilder,
85                                                 const TopTools_DataMapOfShapeShape&    theSubShapes)
86 {
87   TopTools_MapOfShape aView;
88   TopExp_Explorer aShapeExplorer (theShapeIn, theKindOfShape);
89   for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
90     const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
91     if (!aView.Add(aRoot)) continue;
92     const TopTools_ListOfShape& aShapes = theMS.Generated (aRoot);
93     TopTools_ListIteratorOfListOfShape aShapesIterator (aShapes);
94     for (;aShapesIterator.More (); aShapesIterator.Next ()) {
95       TopoDS_Shape aNewShape = aShapesIterator.Value ();
96       if (theSubShapes.IsBound(aNewShape)) {
97         aNewShape.Orientation((theSubShapes(aNewShape)).Orientation());
98       }
99       if (!aRoot.IsSame (aNewShape)) theBuilder.Generated (aRoot,aNewShape );
100     }
101   }
102 }
103 */