b311480e |
1 | // Created on: 1993-07-23 |
2 | // Created by: Martine LANGLOIS |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <BRepClass3d.hxx> |
7fd59977 |
19 | #include <MoniTool_DataMapOfShapeTransient.hxx> |
42cf5bc1 |
20 | #include <StdFail_NotDone.hxx> |
21 | #include <StepShape_BrepWithVoids.hxx> |
7fd59977 |
22 | #include <StepShape_ClosedShell.hxx> |
7fd59977 |
23 | #include <StepShape_HArray1OfOrientedClosedShell.hxx> |
42cf5bc1 |
24 | #include <StepShape_OpenShell.hxx> |
25 | #include <StepShape_OrientedClosedShell.hxx> |
26 | #include <StepShape_TopologicalRepresentationItem.hxx> |
27 | #include <TCollection_HAsciiString.hxx> |
28 | #include <TColStd_SequenceOfTransient.hxx> |
29 | #include <TopoDS.hxx> |
7fd59977 |
30 | #include <TopoDS_Iterator.hxx> |
31 | #include <TopoDS_Shell.hxx> |
42cf5bc1 |
32 | #include <TopoDS_Solid.hxx> |
33 | #include <TopoDSToStep.hxx> |
34 | #include <TopoDSToStep_Builder.hxx> |
35 | #include <TopoDSToStep_MakeBrepWithVoids.hxx> |
36 | #include <TopoDSToStep_Tool.hxx> |
7fd59977 |
37 | #include <Transfer_FinderProcess.hxx> |
38 | #include <TransferBRep_ShapeMapper.hxx> |
7fd59977 |
39 | |
42cf5bc1 |
40 | //:d7 |
0797d9d3 |
41 | #ifdef OCCT_DEBUG |
7fd59977 |
42 | #define DEBUG |
43 | #endif |
44 | |
45 | //============================================================================= |
46 | // Create a BrepWithVoids of StepShape from a Solid of TopoDS containing |
47 | // more than one closed shell |
48 | //============================================================================= |
49 | |
50 | TopoDSToStep_MakeBrepWithVoids:: |
51 | TopoDSToStep_MakeBrepWithVoids(const TopoDS_Solid& aSolid, |
52 | const Handle(Transfer_FinderProcess)& FP) |
53 | { |
54 | done = Standard_False ; |
55 | TopoDS_Iterator It; |
56 | MoniTool_DataMapOfShapeTransient aMap; |
57 | TColStd_SequenceOfTransient S; |
58 | TopoDS_Shell aOutShell; |
59 | |
60 | Handle(StepShape_TopologicalRepresentationItem) aItem; |
61 | Handle(StepShape_ClosedShell) aOuter, aCShell; |
62 | Handle(StepShape_OrientedClosedShell) aOCShell; |
63 | Handle(StepShape_HArray1OfOrientedClosedShell) aVoids; |
64 | |
2f0109b7 |
65 | aOutShell = BRepClass3d::OuterShell(aSolid); |
7fd59977 |
66 | |
67 | TopoDSToStep_Builder StepB; |
68 | TopoDSToStep_Tool aTool; |
69 | |
70 | if (!aOutShell.IsNull()) { |
71 | It.Initialize(aSolid); |
72 | for ( ; It.More(); It.Next() ) { |
73 | if (It.Value().ShapeType() == TopAbs_SHELL) { |
74 | TopoDS_Shell CurrentShell = TopoDS::Shell(It.Value()); |
75 | if ( ! aOutShell.IsEqual(CurrentShell) ) //:e0 abv 25 Mar 98: voids should be reversed according to EXPRESS for ABSR |
76 | CurrentShell.Reverse(); |
77 | //:d7 abv 16 Mar 98: try to treat 'open' shells as closed since flag |
78 | // IsClosed() is often incorrect (taken from MakeManifoldSolid(Solid)) |
79 | aTool.Init(aMap, Standard_False); |
80 | StepB.Init(CurrentShell, aTool, FP); |
81 | TopoDSToStep::AddResult ( FP, aTool ); |
82 | if (StepB.IsDone()) { |
83 | aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value()); |
84 | // si OPEN on le force a CLOSED mais que c est une honte ! |
85 | if (aCShell.IsNull()) { |
86 | Handle(StepShape_OpenShell) aOShell = Handle(StepShape_OpenShell)::DownCast(StepB.Value()); |
87 | if (!aOShell.IsNull()) { |
88 | aCShell = new StepShape_ClosedShell; |
89 | aCShell->Init (aOShell->Name(),aOShell->CfsFaces()); |
0797d9d3 |
90 | #ifdef OCCT_DEBUG |
04232180 |
91 | std::cout<<"Warning: MakeBRepWithVoids: Open shell in the solid; treated as closed"<<std::endl; |
7fd59977 |
92 | #endif |
93 | } |
94 | } |
95 | if ( ! aCShell.IsNull() ) { |
96 | if ( aOutShell.IsEqual(It.Value()) ) |
97 | aOuter = aCShell; |
98 | else |
99 | S.Append(aCShell); |
100 | } |
0797d9d3 |
101 | #ifdef OCCT_DEBUG |
04232180 |
102 | else std::cout<<"*** MakeBRepWithVoids : Shell not mapped"<<std::endl; |
7fd59977 |
103 | #endif |
104 | } |
0797d9d3 |
105 | #ifdef OCCT_DEBUG |
04232180 |
106 | else std::cout << "Shell not mapped" << std::endl; |
7fd59977 |
107 | #endif |
108 | /* //:d7 |
109 | if (It.Value().Closed()) { |
110 | aTool.Init(aMap, Standard_False); |
111 | StepB.Init(CurrentShell, aTool, FP); |
112 | TopoDSToStep::AddResult ( FP, aTool ); |
113 | if (StepB.IsDone()) { |
114 | aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value()); |
115 | if ( aOutShell.IsEqual(It.Value()) ) |
116 | aOuter = aCShell; |
117 | else |
118 | S.Append(aCShell); |
119 | } |
120 | else { |
0797d9d3 |
121 | #ifdef OCCT_DEBUG |
04232180 |
122 | std::cout << "Shell not mapped" << std::endl; |
7fd59977 |
123 | #endif |
124 | done = Standard_False; |
125 | } |
126 | } |
127 | else { |
128 | // Error Handling : the Shape is not closed |
129 | done = Standard_False; |
130 | } |
131 | */ |
132 | } |
133 | } |
134 | Standard_Integer N = S.Length(); |
135 | if ( N>=1 ) { |
136 | Handle(TCollection_HAsciiString) aName = |
137 | new TCollection_HAsciiString(""); |
138 | aVoids = new StepShape_HArray1OfOrientedClosedShell(1,N); |
139 | for ( Standard_Integer i=1; i<=N; i++ ) { |
140 | aOCShell = new StepShape_OrientedClosedShell; |
141 | // Warning : the Oriented Shell Orientation is not always |
142 | // TRUE. |
143 | // Shall check the TopoDS_Shell orientation. |
144 | // => if the Shell is reversed, shall create an OrientedShell. |
145 | aOCShell -> Init(aName,Handle(StepShape_ClosedShell)::DownCast(S.Value(i)), |
146 | Standard_False); //:e0 |
147 | //:e0 Standard_True); |
148 | aVoids->SetValue(i, aOCShell); |
149 | } |
150 | theBrepWithVoids = new StepShape_BrepWithVoids(); |
151 | theBrepWithVoids->Init(aName, aOuter, aVoids); |
152 | done = Standard_True; |
153 | } |
154 | else done = Standard_False; |
155 | } |
156 | } |
157 | |
158 | //============================================================================= |
159 | // renvoi des valeurs |
160 | //============================================================================= |
161 | |
162 | const Handle(StepShape_BrepWithVoids) & |
163 | TopoDSToStep_MakeBrepWithVoids::Value() const |
164 | { |
2d2b3d53 |
165 | StdFail_NotDone_Raise_if (!done, "TopoDSToStep_MakeBrepWithVoids::Value() - no result"); |
7fd59977 |
166 | return theBrepWithVoids; |
167 | } |