summaryrefslogtreecommitdiff
path: root/src/TopoDSToStep/TopoDSToStep_Builder.cxx
blob: fc6dd0b7575dd395fa4ce178ba31a7d850937f2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// File:	TopoDSToStep_Builder.cxx
// Created:	Fri Nov 25 11:00:33 1994
// Author:	Frederic MAUPAS
//		<fma@stylox>


#include <TopoDSToStep_Builder.ixx>

#include <TopoDSToStep_Tool.hxx>

#include <TopoDSToStep_MakeStepFace.hxx>

#include <StepShape_ConnectedFaceSet.hxx>
#include <StepShape_HArray1OfFace.hxx>
#include <StepShape_ClosedShell.hxx>
#include <StepShape_OpenShell.hxx>
#include <StepShape_FaceSurface.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Face.hxx>

#include <TopExp_Explorer.hxx>

#include <TColStd_SequenceOfTransient.hxx>
#include <TransferBRep_ShapeMapper.hxx>
#include <TCollection_HAsciiString.hxx>

#include <Message_ProgressIndicator.hxx>

// ============================================================================
// Method  : TopoDSToStep_Builder::TopoDSToStep_Builder
// Purpose :
// ============================================================================

TopoDSToStep_Builder::TopoDSToStep_Builder()
{
  done = Standard_False;
}

// ============================================================================
// Method  : TopoDSToStep_Builder::TopoDSToStep_Builder
// Purpose :
// ============================================================================

TopoDSToStep_Builder::TopoDSToStep_Builder
(const TopoDS_Shape& aShape,
 TopoDSToStep_Tool& aTool, const Handle(Transfer_FinderProcess)& FP)
{
  done = Standard_False;
  Init(aShape, aTool, FP);
}

// ============================================================================
// Method  : TopoDSToStep_Builder::Init
// Purpose :
// ============================================================================

void TopoDSToStep_Builder::Init(const TopoDS_Shape& aShape,
                                TopoDSToStep_Tool& myTool,
                                const Handle(Transfer_FinderProcess)& FP)
{
  
   if (myTool.IsBound(aShape)) {
    myError  = TopoDSToStep_BuilderDone;
    done     = Standard_True;
    myResult = myTool.Find(aShape);
    return;
  }

  Handle(Message_ProgressIndicator) progress = FP->GetProgress();

  switch (aShape.ShapeType()) 
    {      
    case TopAbs_SHELL: 
      {	
	TopoDS_Shell myShell = TopoDS::Shell(aShape);	  
	myTool.SetCurrentShell(myShell);
	
	Handle(StepShape_FaceSurface)                   FS;
	Handle(StepShape_TopologicalRepresentationItem) Fpms;
	TColStd_SequenceOfTransient                 mySeq;
	
//	const TopoDS_Shell ForwardShell = 
//	  TopoDS::Shell(myShell.Oriented(TopAbs_FORWARD));

//	TopExp_Explorer myExp(ForwardShell, TopAbs_FACE);
//  CKY  9-DEC-1997 (PRO9824 et consorts)
//   Pour passer les orientations : ELLES SONT DONNEES EN RELATIF
//   Donc, pour SHELL, on doit l ecrire en direct en STEP (pas le choix)
//   -> il faut repercuter en dessous, donc explorer le Shell TEL QUEL
//   Pour FACE WIRE, d une part on ECRIT SON ORIENTATION relative au contenant
//     (puisqu on peut), d autre part on EXPLORE EN FORWARD : ainsi les
//     orientations des sous-shapes sont relatives a leur contenant immediat
//     et la recombinaison en lecture est sans malice
//  Il reste ici et la du code relatif a "en Faceted on combine differemment"
//  -> reste encore du menage a faire



	TopExp_Explorer myExp(myShell, TopAbs_FACE);

	TopoDSToStep_MakeStepFace MkFace;

	for (;myExp.More();myExp.Next()) {

	  const TopoDS_Face Face = TopoDS::Face(myExp.Current());
    
    MkFace.Init(Face, myTool, FP);

	  if (MkFace.IsDone()) {
	    FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
	    Fpms = FS;
	    mySeq.Append(Fpms);
	  }
	  else {
	    // MakeFace Error Handling : warning only
//	    cout << "Warning : one Face has not been mapped" << endl;
//	  Handle(TransferBRep_ShapeMapper) errShape =
//	    new TransferBRep_ShapeMapper(Face);
//	    FP->AddWarning(errShape, " a Face from a Shell has not been mapped");
	  }
    if (!progress.IsNull()) progress->Increment();
	}

	Standard_Integer nbFaces = mySeq.Length();
	if ( nbFaces >= 1) {
	  Handle(StepShape_HArray1OfFace) aSet = 
	    new StepShape_HArray1OfFace(1,nbFaces);
	  for (Standard_Integer i=1; i<=nbFaces; i++ ) {
	    aSet->SetValue(i, Handle(StepShape_Face)::DownCast(mySeq.Value(i)));
	  }
	  Handle(StepShape_ConnectedFaceSet) CFSpms;
	  if (myShell.Closed())
	    CFSpms = new StepShape_ClosedShell();
	  else
	    CFSpms = new StepShape_OpenShell();
	  Handle(TCollection_HAsciiString) aName = 
	    new TCollection_HAsciiString("");
	  CFSpms->Init(aName, aSet);

	  // --------------------------------------------------------------
	  // To add later : if not facetted context & shell is reversed
	  //                then shall create an oriented_shell with
	  //                orientation flag to false.
	  // --------------------------------------------------------------

	  myTool.Bind(aShape, CFSpms);
	  myResult = CFSpms;
	  done     = Standard_True;
	}
	else {
	  // Builder Error handling;
	  myError = TopoDSToStep_NoFaceMapped;
	  done    = Standard_False;
	}
	break;
      }
      
    case TopAbs_FACE:
      {
	const TopoDS_Face Face = TopoDS::Face(aShape);	  

	Handle(StepShape_FaceSurface)                   FS;
	Handle(StepShape_TopologicalRepresentationItem) Fpms;

	TopoDSToStep_MakeStepFace MkFace(Face, myTool, FP);

	if (MkFace.IsDone()) {
	  FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
	  Fpms = FS;
	  myResult = Fpms;
	  myError = TopoDSToStep_BuilderDone;
	  done = Standard_True;
	}
	else {
	  // MakeFace Error Handling : Face not Mapped
	  myError = TopoDSToStep_BuilderOther;
//	  Handle(TransferBRep_ShapeMapper) errShape =
//	    new TransferBRep_ShapeMapper(Face);
//	  FP->AddWarning(errShape, " the Face has not been mapped");
	  done = Standard_False;
	}
        if (!progress.IsNull()) progress->Increment();
	break;
      }
    default: break;
    }
}

// ============================================================================
// Method  : TopoDSToStep_Builder::Value
// Purpose :
// ============================================================================

const Handle(StepShape_TopologicalRepresentationItem)& 
TopoDSToStep_Builder::Value() const 
{
  StdFail_NotDone_Raise_if(!done,"");
  return myResult;
}

// ============================================================================
// Method  : TopoDSToStep_Builder::Error
// Purpose :
// ============================================================================

TopoDSToStep_BuilderError TopoDSToStep_Builder::Error() const 
{
  return myError;
}