Adding UnitsAPI in resources for FoundationClasses.tcl of OS package.
[occt.git] / src / STEPControl / STEPControl_ActorWrite.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18//:k8 abv 6 Jan 99: unique names for PRODUCTs
19//:k9 abv 6 Jan 99: TR10: eliminating duplicated APPLICATION_CONTEXT entities
20//abv,gka 05.04.99: S4136: change parameters and update units
21// PTV 22.08.2002 OCC609 transfer solo vertices into step file.
22// PTV 16.09.2002 OCC725 transfer compound of vertices into one geometrical curve set.
23#include <STEPControl_ActorWrite.ixx>
24#include <STEPControl_StepModelType.hxx>
25
26// Transfer
27#include <Transfer_SimpleBinderOfTransient.hxx>
28#include <gp_Ax2.hxx>
29#include <GeomToStep_MakeAxis2Placement3d.hxx>
30#include <StepGeom_Axis2Placement3d.hxx>
31
32#include <STEPConstruct_Part.hxx>
33#include <STEPConstruct_Assembly.hxx>
34#include <STEPConstruct_ContextTool.hxx>
35#include <STEPConstruct_UnitContext.hxx>
36
37// TransferShape
38#include <TopoDSToStep.hxx>
39#include <TopoDSToStep_Builder.hxx>
40#include <TopoDSToStep_FacetedTool.hxx>
41#include <TopoDSToStep_Tool.hxx>
42#include <TopoDSToStep_MakeManifoldSolidBrep.hxx>
43#include <TopoDSToStep_MakeBrepWithVoids.hxx>
44#include <TopoDSToStep_MakeFacetedBrep.hxx>
45#include <TopoDSToStep_MakeFacetedBrepAndBrepWithVoids.hxx>
46#include <TopoDSToStep_MakeGeometricCurveSet.hxx>
47#include <TopoDSToStep_MakeShellBasedSurfaceModel.hxx>
48
49#include <TopoDS.hxx>
50#include <TopoDS_Shape.hxx>
51#include <TopoDS_Solid.hxx>
52#include <Geom_Surface.hxx>
53#include <Geom_Plane.hxx>
54#include <Geom_Curve.hxx>
55#include <Geom_Line.hxx>
56
57#include <StepShape_ShapeDefinitionRepresentation.hxx>
58#include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
59#include <StepShape_FacetedBrep.hxx>
60#include <StepShape_GeometricCurveSet.hxx>
61#include <StepShape_ShellBasedSurfaceModel.hxx>
62#include <StepShape_ManifoldSolidBrep.hxx>
63#include <StepShape_BrepWithVoids.hxx>
64#include <StepRepr_HArray1OfRepresentationItem.hxx>
65#include <StepBasic_HArray1OfProduct.hxx>
66#include <StepRepr_GlobalUnitAssignedContext.hxx>
67#include <StepShape_AdvancedBrepShapeRepresentation.hxx>
68#include <StepShape_FacetedBrepShapeRepresentation.hxx>
69#include <StepShape_TopologicalRepresentationItem.hxx>
70#include <StepShape_ManifoldSurfaceShapeRepresentation.hxx>
71#include <StepShape_GeometricallyBoundedWireframeShapeRepresentation.hxx>
72#include <StepBasic_ApplicationProtocolDefinition.hxx>
73#include <StepRepr_PropertyDefinition.hxx>
74
75#include <TopExp_Explorer.hxx>
76#include <TColStd_HSequenceOfTransient.hxx>
77#include <TCollection_HAsciiString.hxx>
78
79#include <Transfer_TransientProcess.hxx>
80#include <Transfer_Binder.hxx>
81#include <Transfer_Finder.hxx>
82#include <Transfer_FinderProcess.hxx>
83#include <TransferBRep_ShapeMapper.hxx>
84#include <TransferBRep.hxx>
85#include <OSD_Timer.hxx>
86
87#include <ShapeExtend_Explorer.hxx>
88#include <ShapeAnalysis_ShapeTolerance.hxx>
89#include <Interface_MSG.hxx>
90#include <Interface_Static.hxx>
91
92#include <Interface_Macros.hxx>
93#include <TopTools_HSequenceOfShape.hxx>
94
95#include <BRep_Tool.hxx>
96#include <TopoDS_Iterator.hxx> //:d6
97#include <UnitsMethods.hxx>
98#include <STEPConstruct_AP203Context.hxx>
99#include <BRepTools_Modifier.hxx>
100
101#include <XSAlgo.hxx>
102#include <XSAlgo_AlgoContainer.hxx>
103#include <StepRepr_ShapeRepresentationRelationship.hxx>
104#include <Transfer_SequenceOfBinder.hxx>
105
106#include <TopoDSToStep_MakeStepVertex.hxx>
107#include <StepShape_VertexPoint.hxx>
108#include <MoniTool_DataMapOfShapeTransient.hxx>
109#include <StepShape_HArray1OfGeometricSetSelect.hxx>
110#include <StepShape_GeometricSetSelect.hxx>
111#include <TopoDS_Compound.hxx>
112#include <BRep_Builder.hxx>
113
114// Non-manifold topology processing (ssv; 10.11.2010)
115#include <StepShape_NonManifoldSurfaceShapeRepresentation.hxx>
116#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
117#include <TopTools_ListOfShape.hxx>
118#include <TopExp.hxx>
119#include <TopTools_MapOfShape.hxx>
120#include <TopTools_ListIteratorOfListOfShape.hxx>
121
122// ============================================================================
123// Function: DumpWhatIs
124// Purpose: Use it in DEB mode to dump your shapes
125// ============================================================================
126
127static void DumpWhatIs(const TopoDS_Shape& S) {
128
129 TopTools_MapOfShape aMapOfShape;
130 aMapOfShape.Add(S);
131 TopTools_ListOfShape aListOfShape;
132 aListOfShape.Append(S);
133 TopTools_ListIteratorOfListOfShape itL(aListOfShape);
134 Standard_Integer nbSolids = 0,
135 nbShells = 0,
136 nbOpenShells = 0,
137 nbFaces = 0,
138 nbWires = 0,
139 nbEdges = 0,
140 nbVertexes = 0;
141
142 for( ; itL.More(); itL.Next() ) {
143 TopoDS_Iterator it( itL.Value() );
144 for ( ; it.More(); it.Next() ) {
145 TopoDS_Shape aSubShape = it.Value();
146 if ( !aMapOfShape.Add(aSubShape) )
147 continue;
148 aListOfShape.Append(aSubShape);
149 if (aSubShape.ShapeType() == TopAbs_SOLID)
150 nbSolids++;
151 if (aSubShape.ShapeType() == TopAbs_SHELL) {
152 if ( !aSubShape.Closed() )
153 nbOpenShells++;
154 nbShells++;
155 }
156 if (aSubShape.ShapeType() == TopAbs_FACE)
157 nbFaces++;
158 if (aSubShape.ShapeType() == TopAbs_WIRE)
159 nbWires++;
160 if (aSubShape.ShapeType() == TopAbs_EDGE)
161 nbEdges++;
162 if (aSubShape.ShapeType() == TopAbs_VERTEX)
163 nbVertexes++;
164 }
165 }
166 #ifdef DEB
167 cout << "//What is?// NB SOLIDS: " << nbSolids << endl;
168 cout << "//What is?// NB SHELLS: " << nbShells << endl;
169 cout << "//What is?// OPEN SHELLS: " << nbOpenShells << endl;
170 cout << "//What is?// CLOSED SHELLS: " << nbShells - nbOpenShells << endl;
171 cout << "//What is?// NB FACES: " << nbFaces << endl;
172 cout << "//What is?// NB WIRES: " << nbWires << endl;
173 cout << "//What is?// NB EDGES: " << nbEdges << endl;
174 cout << "//What is?// NB VERTEXES: " << nbVertexes << endl;
175 #endif
176}
177
178//=======================================================================
179// Function : IsManifoldShape
180// Purpose : Used to define whether the passed shape has manifold
181// topology or not
182//=======================================================================
183
184static Standard_Boolean IsManifoldShape(const TopoDS_Shape& theShape) {
185
186 Standard_Boolean aResult = Standard_True;
187
188 // Do not check nested Compounds
189 TopoDS_Compound aDirectShapes;
190 BRep_Builder aBrepBuilder;
191 aBrepBuilder.MakeCompound(aDirectShapes);
192
193 TopoDS_Iterator anIt(theShape);
194 for ( ; anIt.More(); anIt.Next() ) {
195 TopoDS_Shape aDirectChild = anIt.Value();
196 if (aDirectChild.ShapeType() != TopAbs_COMPOUND)
197 aBrepBuilder.Add(aDirectShapes, aDirectChild);
198 }
199
200 #ifdef DEB
201 DumpWhatIs(aDirectShapes);
202 #endif
203
204 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
205 TopExp::MapShapesAndAncestors(aDirectShapes, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
206
207 Standard_Integer aNbEdges = aMapEdgeFaces.Extent();
208 #ifdef DEB
209 cout << "Checking whether the topology passed is manifold..." << endl;
210 #endif
211
212 // Check topology
213 for (Standard_Integer i = 1; i <= aNbEdges; i++) {
214 TopoDS_Edge aCurrentEdge = TopoDS::Edge( aMapEdgeFaces.FindKey(i) );
215 if ( !BRep_Tool::Degenerated(aCurrentEdge) ) {
216 Standard_Integer aNbAncestors = aMapEdgeFaces.FindFromIndex(i).Extent();
217 if (aNbAncestors > 2) {
218 aResult = Standard_False;
219 break;
220 }
221 }
222 }
223
224 #ifdef DEB
225 cout << "Check result: "
226 << (aResult ? "TRUE" : "FALSE") << endl;
227 #endif
228
229 return aResult;
230}
231
232/* this is a start of a comment! */
233#ifdef DEB
234void DumpBinder (const Handle(Transfer_Binder) &binder)
235{
236 Handle(Transfer_Binder) bbb = binder;
237 while ( ! bbb.IsNull() ) {
238 Handle(Transfer_SimpleBinderOfTransient) bx =
239 Handle(Transfer_SimpleBinderOfTransient)::DownCast ( bbb );
240 cout << (void*)&bx;
241 if ( ! bx.IsNull() ) {
242 cout << "--> " << bx->ResultTypeName() << " " << *(void**)&bx->Result() << endl;
243 }
244 else cout << "--> ???" << endl;
245 bbb = bbb->NextResult();
246 }
247 cout << endl;
248}
249#endif
250/* this is a end of a comment */
251
252//=======================================================================
253//function : STEPControl_ActorWrite
254//purpose :
255//=======================================================================
256
257STEPControl_ActorWrite::STEPControl_ActorWrite ()
258: mygroup (0) , mytoler (-1.)
259{
260 SetMode(STEPControl_ShellBasedSurfaceModel);
261}
262
263//=======================================================================
264//method: getNMSSRForGroup
265//purpose: allows to get NMSSR (NON_MANIFOLD_SURFACE_SHAPE_REPRESENTATION)
266// STEP's entity for the group of shells (!) passed
267//=======================================================================
268
269Handle(StepShape_NonManifoldSurfaceShapeRepresentation) STEPControl_ActorWrite::getNMSSRForGroup(const Handle(TopTools_HSequenceOfShape)& shapeGroup,
270 const Handle(Transfer_FinderProcess)& FP,
271 Standard_Boolean& isNMSSRCreated) const
272{
273 Handle(StepShape_NonManifoldSurfaceShapeRepresentation) aResult;
274
275 if ( !shapeGroup.IsNull() ) {
276 for (Standard_Integer i = 1; i <= shapeGroup->Length(); i++) {
277 TopoDS_Shape aCurrentShape = shapeGroup->Value(i);
278 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper(FP, aCurrentShape);
279 if ( FP->FindTypedTransient(mapper, STANDARD_TYPE(StepShape_NonManifoldSurfaceShapeRepresentation), aResult) )
280 break;
281 }
282 }
283
284 if ( aResult.IsNull() ) {
285 #ifdef DEB
286 cout << "\nNew NMSSR created" << endl;
287 #endif
288 aResult = new StepShape_NonManifoldSurfaceShapeRepresentation;
289 isNMSSRCreated = Standard_True;
290 } else {
291 #ifdef DEB
292 cout << "\nExisting NMSSR is used" << endl;
293 #endif
294 isNMSSRCreated = Standard_False;
295 }
296
297 return aResult;
298}
299
300
301//=======================================================================
302//function : SetMode
303//purpose :
304//=======================================================================
305
306void STEPControl_ActorWrite::SetMode (const STEPControl_StepModelType M)
307{
308 switch (M) {
309 case STEPControl_AsIs : ModeTrans() = 0; break;
310 case STEPControl_ManifoldSolidBrep : ModeTrans() = 3; break;
311 case STEPControl_BrepWithVoids : ModeTrans() = 5; break;
312 case STEPControl_FacetedBrep : ModeTrans() = 1; break;
313 case STEPControl_FacetedBrepAndBrepWithVoids : ModeTrans() = 6; break;
314 case STEPControl_ShellBasedSurfaceModel : ModeTrans() = 2;
315 case STEPControl_GeometricCurveSet : ModeTrans() = 4;
316 case STEPControl_Hybrid : ModeTrans() = 0; break; // PAS IMPLEMENTE !!
317 default: break;
318 }
319}
320
321//=======================================================================
322//function : Mode
323//purpose :
324//=======================================================================
325
326STEPControl_StepModelType STEPControl_ActorWrite::Mode () const
327{
328 switch (themodetrans) {
329 case 0 : return STEPControl_AsIs;
330 case 1 : return STEPControl_FacetedBrep;
331 case 2 : return STEPControl_ShellBasedSurfaceModel;
332 case 3 : return STEPControl_ManifoldSolidBrep;
333 case 4 : return STEPControl_GeometricCurveSet;
334 case 5 : return STEPControl_BrepWithVoids;
335 case 6 : return STEPControl_FacetedBrepAndBrepWithVoids;
336 default : break;
337 }
338 return STEPControl_AsIs;
339}
340
341//=======================================================================
342//function : SetGroupMode
343//purpose :
344//=======================================================================
345
346void STEPControl_ActorWrite::SetGroupMode (const Standard_Integer mode)
347{
348 if (mode >= 0) mygroup = mode;
349}
350
351//=======================================================================
352//function : GroupMode
353//purpose :
354//=======================================================================
355
356Standard_Integer STEPControl_ActorWrite::GroupMode () const
357{
358 return mygroup;
359}
360
361//=======================================================================
362//function : SetTolerance
363//purpose :
364//=======================================================================
365
366void STEPControl_ActorWrite::SetTolerance (const Standard_Real Tol)
367{
368 mytoler = Tol;
369}
370
371//=======================================================================
372//function : Recognize
373// ATTENTION, Recognize doit s aligner sur ce que Transfer sait faire
374//purpose :
375//=======================================================================
376
377Standard_Boolean STEPControl_ActorWrite::Recognize (const Handle(Transfer_Finder)& start)
378{
379 STEPControl_StepModelType mymode = Mode();
380 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
381 if (mapper.IsNull()) return Standard_False;
382 if (mymode == STEPControl_AsIs) return Standard_True;
383
384 Standard_Boolean yasolid = Standard_False, yashell = Standard_False,
385 yaface = Standard_False;
386
387 TopoDS_Shape theShape, aShape;
388// theShape = TopoDSToStep::DirectFaces(mapper->Value());
389 theShape = mapper->Value(); // pour une reconnaissance c est bien assez
390
391 if (theShape.ShapeType() == TopAbs_COMPOUND) {
392
393 TopExp_Explorer SolidExp, ShellExp, FaceExp;
394
395 for (SolidExp.Init(theShape, TopAbs_SOLID);
396 SolidExp.More();SolidExp.Next()) yasolid = Standard_True;
397 for (ShellExp.Init(theShape, TopAbs_SHELL, TopAbs_SOLID);
398 ShellExp.More();ShellExp.Next()) yashell = Standard_True;
399 for (FaceExp.Init(theShape, TopAbs_FACE, TopAbs_SHELL);
400 FaceExp.More();FaceExp.Next()) yaface = Standard_True;
401 }
402 else if (theShape.ShapeType() == TopAbs_SOLID) yasolid = Standard_True;
403 else if (theShape.ShapeType() == TopAbs_SHELL) yashell = Standard_True;
404 else if (theShape.ShapeType() == TopAbs_FACE) yaface = Standard_True;
405 else if (mymode != STEPControl_GeometricCurveSet) return Standard_False;
406// pour wireframe ?
407
408// Faceted : il est OBLIGATOIRE d avoir des surfaces support Plane et des
409// courbes 3D Line (pcurves ignorees)
410
411 if (mymode == STEPControl_FacetedBrep || mymode == STEPControl_FacetedBrepAndBrepWithVoids) {
412 for (TopExp_Explorer ffac(theShape,TopAbs_FACE); ffac.More(); ffac.Next()) {
413 const TopoDS_Face& F = TopoDS::Face (ffac.Current());
414 TopLoc_Location locbid;
415 Handle(Geom_Surface) surf = BRep_Tool::Surface (F,locbid);
416 if (surf.IsNull() || !surf->IsKind(STANDARD_TYPE(Geom_Plane)) ) return Standard_False;
417 }
418 for (TopExp_Explorer fedg(theShape,TopAbs_EDGE); fedg.More(); fedg.Next()) {
419 const TopoDS_Edge& E = TopoDS::Edge (fedg.Current());
420 TopLoc_Location locbid; Standard_Real first,last;
421 Handle(Geom_Curve) curv = BRep_Tool::Curve (E,locbid,first,last);
422 if (curv.IsNull() || !curv->IsKind(STANDARD_TYPE(Geom_Line)) ) return Standard_False;
423 }
424 }
425
426 switch (mymode) {
427 case STEPControl_ManifoldSolidBrep: return (yasolid || yashell);
428 case STEPControl_BrepWithVoids:
429 case STEPControl_FacetedBrep:
430 case STEPControl_FacetedBrepAndBrepWithVoids: return yasolid;
431 case STEPControl_ShellBasedSurfaceModel:
432 return (yasolid || yashell || yaface);
433 case STEPControl_GeometricCurveSet: return Standard_True; // tout OK
434 default : break;
435 }
436 return Standard_False;
437}
438
439
440// ######## MAKE PRODUCT DATA + CONTEXT ########
441
442//=======================================================================
443//function : Transfer
444//purpose :
445//=======================================================================
446
447Handle(Transfer_Binder) STEPControl_ActorWrite::Transfer (const Handle(Transfer_Finder)& start,
448 const Handle(Transfer_FinderProcess)& FP)
449{
450 XSAlgo::AlgoContainer()->PrepareForTransfer();
451
452 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
453
454 if (mapper.IsNull()) return NullResult();
455 TopoDS_Shape shape = mapper->Value();
456
457 // init context
458 Handle(StepData_StepModel) model = Handle(StepData_StepModel)::DownCast ( FP->Model() );
459 if ( ! model.IsNull() ) myContext.SetModel ( model ); //: abv 04.11.00: take APD from model
460 myContext.AddAPD ( Standard_False ); // update APD
461 myContext.SetLevel ( 1 ); // set assembly level to 1 (to ensure)
462
463 //:S4136: init UnitsMethods to reset angle unit factors (see TopoDSToStep)
464 Standard_Real lFactor = UnitsMethods::GetLengthFactorValue ( Interface_Static::IVal ( "write.step.unit" ) );
465 lFactor /= UnitsMethods::GetCasCadeLengthUnit();
466 Standard_Integer anglemode = Interface_Static::IVal("step.angleunit.mode");
c6541a0c 467 UnitsMethods::InitializeFactors ( lFactor, ( anglemode <= 1 ? 1. : M_PI/180. ), 1. );
7fd59977 468
469 // create SDR
470 STEPConstruct_Part SDRTool;
471 SDRTool.MakeSDR ( 0, myContext.GetProductName(), myContext.GetAPD()->Application() );
472 Handle(StepShape_ShapeDefinitionRepresentation) sdr = SDRTool.SDRValue();
473 // transfer shape
474
475 Handle(Transfer_Binder) resbind = TransferShape (mapper,sdr,FP);
476
477// Handle(StepShape_ShapeRepresentation) resultat;
478// FP->GetTypedTransient (resbind,STANDARD_TYPE(StepShape_ShapeRepresentation),resultat);
479// sdr->SetUsedRepresentation (resultat);
480
481 // create binder with all root entities produced from shape
482 Handle(TColStd_HSequenceOfTransient) roots = myContext.GetRootsForPart ( SDRTool );
483 Handle(Transfer_Binder) resprod = TransientResult ( myContext.GetAPD() );
484 for ( Standard_Integer i=1; i <= roots->Length(); i++ )
485 resprod->AddResult ( TransientResult ( roots->Value(i) ) );
486 resprod->AddResult(resbind);
487
488 // bind and exit
489 //FP->Bind (mapper,resprod);
490 myContext.NextIndex();
491 return resprod;
492}
493
494//==========================================
495
496static Standard_Real UsedTolerance (const Standard_Real mytoler,
497 const TopoDS_Shape& theShape)
498{
499
500 // COMPUTING 3D TOLERANCE
501 // Either from Session, or Computed (Least,Average, or Greatest)
502 // Then given to TopoDSToStep_Tool
503
504 Standard_Real Tol = mytoler;
505 Standard_Integer tolmod = Interface_Static::IVal("write.precision.mode");
506 if (Tol <= 0 && tolmod == 2) Tol =
507 Interface_Static::RVal("write.precision.val");
508 if (Tol <= 0) {
509 ShapeAnalysis_ShapeTolerance stu;
510 Tol = stu.Tolerance (theShape,tolmod);
511 // Par defaut, on prend une tolerance moyenne, on elimine les aberrations
512 Tol = Interface_MSG::Intervalled (Tol * 1.5); // arrondi a 1 2 5 ...
513 }
514 if (Tol == 0) Tol = 1.e-07; // minimum ...
515
516 return Tol;
517}
518
519//=======================================================================
520//function : IsAssembly
521//purpose :
522//=======================================================================
523// if GroupMode is >1 downgrades all compounds having single subshape to that
524// subshape
525
526Standard_Boolean STEPControl_ActorWrite::IsAssembly (TopoDS_Shape &S) const
527{
528 if ( ! GroupMode() || S.ShapeType() != TopAbs_COMPOUND ) return Standard_False;
529 // PTV 16.09.2002 OCC725 for storing compound of vertices
530 if (S.ShapeType() == TopAbs_COMPOUND ) {
531 Standard_Boolean IsOnlyVertices = Standard_True;
532 TopoDS_Iterator anItr( S );
533 for ( ; anItr.More(); anItr.Next() ) {
534 if ( anItr.Value().ShapeType() != TopAbs_VERTEX ) {
535 IsOnlyVertices = Standard_False;
536 break;
537 }
538 }
539 if ( IsOnlyVertices )
540 return Standard_False;
541 }
542 if ( GroupMode() ==1 ) return Standard_True;
543 TopoDS_Iterator it ( S );
544 if ( ! it.More() ) return Standard_False;
545 TopoDS_Shape shape = it.Value();
546 it.Next();
547 if ( it.More() ) return Standard_True;
548 S = shape;
549 return IsAssembly ( S );
550}
551
552//=======================================================================
553//function : TransferShape
554//purpose :
555//=======================================================================
556
557/*
558static void UpdateMap (const TopoDS_Shape &shape,
559 BRepTools_Modifier &M1,
560 BRepTools_Modifier &M2,
561 const Handle(Transfer_FinderProcess) &FinderProcess)
562{
563 TopoDS_Shape S = M1.ModifiedShape ( shape );
564 S = M2.ModifiedShape ( S );
565 if ( S == shape ) return;
566
567 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess, S );
568 Handle(Transfer_Binder) binder = FinderProcess->Find ( mapper );
569 if ( ! binder.IsNull() ) {
570 mapper = TransferBRep::ShapeMapper ( FinderProcess, shape );
571 FinderProcess->Bind ( mapper, binder );
572 }
573
574 for ( TopoDS_Iterator it(shape); it.More(); it.Next() )
575 UpdateMap ( it.Value(), M1, M2, FinderProcess );
576}
577*/
578
579// PTV 16.09.2002 added for transfering vertices.
580static Standard_Boolean transferVertex (const Handle(Transfer_FinderProcess)& FP,
581 Handle(StepShape_HArray1OfGeometricSetSelect)& aGSS,
582 const TopoDS_Shape& aShVrtx,
583 const Standard_Integer theNum)
584{
585 Standard_Boolean IsDone = Standard_False;
586 MoniTool_DataMapOfShapeTransient aMap;
587 TopoDSToStep_Tool aTool(aMap, Standard_True);
588 TopoDSToStep_MakeStepVertex aMkVrtx ( TopoDS::Vertex(aShVrtx), aTool, FP );
589
590 if (!aMkVrtx.IsDone())
591 return IsDone;
592
593 Handle(StepShape_VertexPoint) aVP =
594 Handle(StepShape_VertexPoint)::DownCast(aTool.Find(aShVrtx));
595 if (aVP.IsNull())
596 return IsDone;
597
598 StepShape_GeometricSetSelect select;
599 select.SetValue(aVP->VertexGeometry());
600 // add current result
601 aGSS->SetValue( theNum, select );
602 IsDone = Standard_True;
603 return IsDone;
604}
605
606
607Handle(Transfer_Binder) STEPControl_ActorWrite::TransferShape (const Handle(Transfer_Finder)& start,
608 const Handle(StepShape_ShapeDefinitionRepresentation)& SDR0,
609 const Handle(Transfer_FinderProcess)& FP,
610 const Handle(TopTools_HSequenceOfShape)& shapeGroup,
611 const Standard_Boolean isManifold)
612{
613 STEPControl_StepModelType mymode = Mode();
614 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
615 Handle(Transfer_Binder) binder;
616
617 // Indicates whether to use an exising NMSSR to write items to (ss; 13.11.2010)
618 Standard_Boolean useExistingNMSSR = Standard_False;
619
620 if (mapper.IsNull()) return binder;
621 TopoDS_Shape theShape = mapper->Value();
622
623 if (theShape.IsNull()) return binder;
624
625 // INDIVIDUAL SHAPE ALREADY TRANSFERRED : RETURN IT !
626 binder = FP->Find(start);
627 if (!binder.IsNull()) { if (!binder->HasResult()) binder.Nullify(); }
628 if (!binder.IsNull()) {
629 //:abv 20.05.02: writing box & face from it (shared) in one compound
630 // as assembly - while face already translated, it should be
631 // re-translated to break sharing
632#ifdef DEB
633 cout << "Warning: STEPControl_ActorWrite::TransferShape(): shape already translated" << endl;
634#endif
635// return binder;
636 }
637
638 // MODE ASSEMBLY : if Compound, (sub-)assembly
639 if ( IsAssembly(theShape) )
640 return TransferCompound(start, SDR0, FP);
641
642 // [BEGIN] Separate manifold topology from non-manifold in group mode 0 (ssv; 18.11.2010)
643 Standard_Boolean isNMMode = Interface_Static::IVal("write.step.nonmanifold");
644 Handle(Transfer_Binder) aNMBinder;
645 if (isNMMode && !GroupMode() && theShape.ShapeType() == TopAbs_COMPOUND) {
646 TopoDS_Compound aNMCompound;
647 TopoDS_Compound aManifoldCompound;
648 BRep_Builder brepBuilder;
649
650 // Create empty Compounds
651 brepBuilder.MakeCompound(aManifoldCompound);
652 brepBuilder.MakeCompound(aNMCompound);
653
654 // Indicates whether there is only non-manifold topology detected
655 // (there is no manifold topology found in the Compound passed)
656 Standard_Boolean isOnlyNonManifold = Standard_False;
657
658 // Find a Compound containing non-manifold topology.
659 // NOTE: only one such Compound must exist in the entire Compound passed
660 if ( !IsManifoldShape(theShape) ) {
661 aNMCompound = TopoDS::Compound(theShape);
662 isOnlyNonManifold = Standard_True;
663 }
664 else {
665 TopTools_ListOfShape aListOfShapes;
666 TopTools_ListOfShape aListOfManifoldShapes;
667 aListOfShapes.Append(theShape);
668
669 TopTools_ListIteratorOfListOfShape itL(aListOfShapes);
670 for ( ; itL.More(); itL.Next() ) {
671 TopoDS_Shape aParentShape = itL.Value();
672 TopoDS_Iterator it(aParentShape);
673 for ( ; it.More(); it.Next() ) {
674 TopoDS_Shape aSubShape = it.Value();
675 if (aSubShape.ShapeType() == TopAbs_COMPOUND && !IsManifoldShape(aSubShape) )
676 aNMCompound = TopoDS::Compound(aSubShape);
677 else if (aSubShape.ShapeType() == TopAbs_COMPOUND)
678 aListOfShapes.Append(aSubShape);
679 else
680 aListOfManifoldShapes.Append(aSubShape);
681 }
682 }
683
684 // Group manifold topology together.
685 // NOTE: there is no sense that initial Compound structure was lost as
686 // group mode is set to 0 (no Assemblies are mapped)
687 for ( itL.Initialize(aListOfManifoldShapes); itL.More(); itL.Next() ) {
688 TopoDS_Shape aCurrentManiShape = itL.Value();
689 brepBuilder.Add(aManifoldCompound, aCurrentManiShape);
690 }
691
692 }
693
694 // Process only manifold topology in the current TransferShape invocation.
695 // Invoke TransferShape for non-manifold topology separately (see below)
696 theShape = aManifoldCompound;
697
698 // List of items to transfer
699 Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
700 // Non-manifold group to pass into TransferShape with each shape from RepItemSeq
701 Handle(TopTools_HSequenceOfShape) NonManifoldGroup = new TopTools_HSequenceOfShape();
702
703 // Transfer Solids to closed Shells. Prepare RepItemSeq & NonManifoldGroup
704 for ( TopoDS_Iterator iter(aNMCompound); iter.More(); iter.Next() ) {
705 TopoDS_Shape aSubShape = iter.Value();
706 if (aSubShape.ShapeType() == TopAbs_SOLID) {
707 for ( TopoDS_Iterator aSubIter(aSubShape); aSubIter.More(); aSubIter.Next() ) {
708 TopoDS_Shell aSubShell = TopoDS::Shell( aSubIter.Value() );
709 aSubShell.Closed(Standard_True);
710 RepItemSeq->Append(aSubShell);
711 NonManifoldGroup->Append(aSubShell);
712 }
713 }
714 else if (!isManifold && (aSubShape.ShapeType() == TopAbs_SHELL) ) {
715 RepItemSeq->Append(aSubShape);
716 NonManifoldGroup->Append(aSubShape);
717 }
718 else
719 RepItemSeq->Append( iter.Value() );
720 }
721
722 Standard_Integer aNMItemsNb = RepItemSeq->Length();
723
724 // In case of pure manifold topology do nothing; theShape is processed as usual (see below)
725 if (aNMItemsNb > 0) {
726
727 // Prepare SDR for non-manifold group. This SDR will be linked to NMSSR by means
728 // of TransferShape invocation. SDR is not created if there is no any manifold
729 // topology in the passed Compound. If topology is pure non-manifold, SDR0 (passed)
730 // is used
731 Handle(StepShape_ShapeDefinitionRepresentation) sdr;
732 if (isOnlyNonManifold)
733 sdr = SDR0;
734 else {
735 STEPConstruct_Part SDRTool;
736 SDRTool.MakeSDR( 0, myContext.GetProductName(), myContext.GetAPD()->Application() );
737 sdr = SDRTool.SDRValue();
738 }
739
740 aNMBinder = TransientResult(sdr);
741
742 // Complete SDR with shape representations.
743 // NOTE: aNMBinder is connected now with this SDR. It will be added to the resulting
744 // binder in the end of this invocation of TransferShape
745 for (Standard_Integer i = 1; i <= aNMItemsNb; i++) {
746 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper( FP, RepItemSeq->Value(i) );
747 TransferShape(mapper, sdr, FP, NonManifoldGroup, Standard_False);
748 }
749
750 // Nothing else needed for pure non-manifold topology, return
751 if (isOnlyNonManifold)
752 return aNMBinder;
753
754 }
755
756 }
757 // [END] Separate manifold topology from non-manifold in group mode 0 (ssv; 18.11.2010)
758
759 // create a list of items to translate
760 Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
761
762 // PTV 16.09.2002 OCC725 separate shape from solo vertices.
66d6976f 763 Standard_Boolean isOnlyVertices = Standard_False;
7fd59977 764 if (theShape.ShapeType() == TopAbs_COMPOUND) {
765 Standard_Integer countVrtx = 0;
766 Standard_Integer countSh = 0;
767 TopoDS_Compound aNewShape, aCompOfVrtx;
768 BRep_Builder aB;
769 aB.MakeCompound(aNewShape);
770 aB.MakeCompound(aCompOfVrtx);
771 TopoDS_Iterator anCompIt(theShape);
772 for (; anCompIt.More(); anCompIt.Next()) {
773 TopoDS_Shape aCurSh = anCompIt.Value();
774 if (aCurSh.ShapeType() != TopAbs_VERTEX) {
775 aB.Add(aNewShape, aCurSh);
776 countSh++;
777 }
778 else {
779 aB.Add(aCompOfVrtx, aCurSh);
780 countVrtx++;
781 }
782 }
783 // replace the shapes
784 if (countSh)
785 theShape = aNewShape;
786 if (countVrtx)
787 RepItemSeq->Append(aCompOfVrtx);
66d6976f 788 if (countSh == 0)
789 isOnlyVertices = Standard_True;
7fd59977 790 }
7fd59977 791
7fd59977 792 if (theShape.ShapeType() == TopAbs_COMPOUND) {
793 TopExp_Explorer SolidExp, ShellExp, FaceExp;
794 if (mymode != STEPControl_GeometricCurveSet) {
795 for (SolidExp.Init(theShape, TopAbs_SOLID);
796 SolidExp.More();SolidExp.Next()) {
797 RepItemSeq->Append(TopoDS::Solid(SolidExp.Current()));
798 }
799 for (ShellExp.Init(theShape, TopAbs_SHELL, TopAbs_SOLID);
800 ShellExp.More();ShellExp.Next()) {
801 RepItemSeq->Append(TopoDS::Shell(ShellExp.Current()));
802 }
803
804 for (FaceExp.Init(theShape, TopAbs_FACE, TopAbs_SHELL);
805 FaceExp.More();FaceExp.Next()) {
806 RepItemSeq->Append(TopoDS::Face(FaceExp.Current()));
807 }
808 }
809 else {
66d6976f 810 if (!isOnlyVertices)
811 RepItemSeq->Append(theShape); //:j1
7fd59977 812 }
813 if(mymode == STEPControl_AsIs) {
814 TopExp_Explorer WireExp, EdgeExp;
815 for (WireExp.Init(theShape, TopAbs_WIRE, TopAbs_FACE);
816 WireExp.More();WireExp.Next())
817 RepItemSeq->Append(TopoDS::Wire(WireExp.Current()));
818 for (EdgeExp.Init(theShape, TopAbs_EDGE, TopAbs_WIRE);
819 EdgeExp.More();EdgeExp.Next())
820 RepItemSeq->Append(TopoDS::Edge(EdgeExp.Current()));
821 }
822
823 }
824 else if (theShape.ShapeType() == TopAbs_SOLID) {
825 RepItemSeq->Append(TopoDS::Solid(theShape));
826 }
827 else if (theShape.ShapeType() == TopAbs_SHELL) {
828 RepItemSeq->Append(TopoDS::Shell(theShape));
829 }
830 else if (theShape.ShapeType() == TopAbs_FACE) {
831 RepItemSeq->Append(TopoDS::Face(theShape));
832 }
833 else if (mymode != STEPControl_GeometricCurveSet && mymode != STEPControl_AsIs) {
834 FP->AddFail(start,"The Shape is not a SOLID, nor a SHELL, nor a FACE");
835 return binder;
836 }
837 else RepItemSeq->Append (theShape);
838
839 // COMPUTING 3D TOLERANCE
840 // Either from Session, or Computed (Least,Average, or Greatest)
841 // Then given to TopoDSToStep_Tool
842 Standard_Real Tol = UsedTolerance (mytoler,theShape);
843
844 // Create a STEP-Entity for each TopoDS_Shape
845 // according to the current StepModelMode
846
847 Standard_Integer nbs = RepItemSeq->Length();
848 Handle(TColStd_HSequenceOfTransient) ItemSeq =
849 new TColStd_HSequenceOfTransient();
850
851//ptv 10.11.00: allow to write empty Compound: if (GroupMode() >0)
852 ItemSeq->Append (myContext.GetDefaultAxis());
853 STEPControl_StepModelType trmode = mymode;
854 for (Standard_Integer i = 1; i <= nbs; i++) {
855 TopoDS_Shape xShape = RepItemSeq->Value(i);
856
857 if(mymode == STEPControl_AsIs) {
858 switch(xShape.ShapeType()) {
859 case TopAbs_SOLID : trmode = STEPControl_ManifoldSolidBrep;break;
860 case TopAbs_SHELL : trmode = STEPControl_ShellBasedSurfaceModel; break;
861 case TopAbs_FACE : trmode = STEPControl_ShellBasedSurfaceModel;break;
862 default : trmode =STEPControl_GeometricCurveSet; break;
863 }
864 }
865 //:abv 24Jan99 CAX-IF TRJ3: expanded Shape Processing
866// TopoDS_Shape aShape = xShape;
867 // eliminate conical surfaces with negative semiangles
868// Handle(TopoDSToStep_ConicalSurfModif) CSM = new TopoDSToStep_ConicalSurfModif();
869// BRepTools_Modifier CSMT(aShape,CSM);
870// if ( CSMT.IsDone() ) aShape = CSMT.ModifiedShape ( aShape );
871// // eliminate indirect elementary surfaces
872// Handle(TopoDSToStep_DirectModification) DM = new TopoDSToStep_DirectModification();
873// BRepTools_Modifier DMT(aShape,DM);
874// if ( DMT.IsDone() ) aShape = DMT.ModifiedShape ( aShape );
875//// aShape = TopoDSToStep::DirectFaces(xShape);
876 Handle(Standard_Transient) info;
877 Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val");
878
879 // Fix only manifold shapes, do nothing with non-manifold topology as it is processed separately (ssv; 13.11.2010)
880 TopoDS_Shape aShape;
881 if (isManifold)
882 aShape = XSAlgo::AlgoContainer()->ProcessShape(xShape, Tol, maxTol,
883 "write.step.resource.name",
b485ee79
KD
884 "write.step.sequence", info,
885 FP->GetProgress() );
7fd59977 886 else
887 aShape = xShape;
888
889 // create a STEP entity corresponding to shape
890 Handle(StepGeom_GeometricRepresentationItem) item;
891 switch (trmode)
892 {
893 case STEPControl_ManifoldSolidBrep:
894 {
895 if (aShape.ShapeType() == TopAbs_SOLID) {
896 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
897
898 //:d6 abv 13 Mar 98: if solid has more than 1 shell,
899 // try to treat it as solid with voids
900 Standard_Integer nbShells = 0;
901 for ( TopoDS_Iterator It ( aSolid ); It.More(); It.Next() )
902 if (It.Value().ShapeType() == TopAbs_SHELL) nbShells++;
903 if ( nbShells >1 ) {
904 TopoDSToStep_MakeBrepWithVoids MkBRepWithVoids(aSolid,FP);
905 MkBRepWithVoids.Tolerance() = Tol;
906 if (MkBRepWithVoids.IsDone()) {
907 item = MkBRepWithVoids.Value();
908 }
909 else nbShells = 1; //smth went wrong; let it will be just Manifold
910 }
911 if ( nbShells ==1 ) {
912
913 TopoDSToStep_MakeManifoldSolidBrep MkManifoldSolidBrep(aSolid,FP);
914 MkManifoldSolidBrep.Tolerance() = Tol;
915 if (MkManifoldSolidBrep.IsDone()) {
916 item = MkManifoldSolidBrep.Value();
917 }
918 }
919 }
920 else if (aShape.ShapeType() == TopAbs_SHELL) {
921 TopoDS_Shell aShell = TopoDS::Shell(aShape);
922 TopoDSToStep_MakeManifoldSolidBrep MkManifoldSolidBrep(aShell,FP);
923 MkManifoldSolidBrep.Tolerance() = Tol;
924 if (MkManifoldSolidBrep.IsDone()) {
925 item = MkManifoldSolidBrep.Value();
926 }
927 }
928 break;
929 }
930 case STEPControl_BrepWithVoids:
931 {
932 if (aShape.ShapeType() == TopAbs_SOLID) {
933 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
934 TopoDSToStep_MakeBrepWithVoids MkBRepWithVoids(aSolid,FP);
935 MkBRepWithVoids.Tolerance() = Tol;
936 if (MkBRepWithVoids.IsDone()) {
937 item = MkBRepWithVoids.Value();
938 }
939 }
940 break;
941 }
942 case STEPControl_FacetedBrep:
943 {
944 TopoDSToStep_FacetedError facErr = TopoDSToStep_FacetedTool::CheckTopoDSShape(aShape);
945 if (facErr != TopoDSToStep_FacetedDone) {
946 FP->AddFail(start,"Error in Faceted Shape from TopoDS");
947 if (facErr == TopoDSToStep_SurfaceNotPlane) {
948 FP->AddFail(start,"-- The TopoDS_Face is not plane");
949 }
950 else if (facErr == TopoDSToStep_PCurveNotLinear) {
951 FP->AddFail(start,"-- The Face contains non linear PCurves");
952 }
953 return binder;
954 }
955 if (aShape.ShapeType() == TopAbs_SOLID) {
956 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
957 TopoDSToStep_MakeFacetedBrep MkFacetedBrep(aSolid,FP);
958 MkFacetedBrep.Tolerance() = Tol;
959 if (MkFacetedBrep.IsDone()) {
960 item = MkFacetedBrep.Value();
961 }
962 }
963 break;
964 }
965 case STEPControl_FacetedBrepAndBrepWithVoids:
966 {
967 TopoDSToStep_FacetedError facErr = TopoDSToStep_FacetedTool::CheckTopoDSShape(aShape);
968 if (facErr != TopoDSToStep_FacetedDone) {
969 FP->AddFail(start,"Error in Faceted Shape from TopoDS");
970 if (facErr == TopoDSToStep_SurfaceNotPlane) {
971 FP->AddFail(start,"-- The TopoDS_Face is not plane");
972 }
973 else if (facErr == TopoDSToStep_PCurveNotLinear) {
974 FP->AddFail(start,"-- The Face contains non linear PCurves");
975 }
976 return binder;
977 }
978 if (aShape.ShapeType() == TopAbs_SOLID) {
979 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
980 TopoDSToStep_MakeFacetedBrepAndBrepWithVoids
981 MkFacetedBrepAndBrepWithVoids(aSolid,FP);
982 MkFacetedBrepAndBrepWithVoids.Tolerance() = Tol;
983 if (MkFacetedBrepAndBrepWithVoids.IsDone()) {
984 item = MkFacetedBrepAndBrepWithVoids.Value();
985 }
986 }
987 break;
988 }
989 case STEPControl_ShellBasedSurfaceModel:
990 {
991 if (aShape.ShapeType() == TopAbs_SOLID) {
992 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
993 TopoDSToStep_MakeShellBasedSurfaceModel
994 MkShellBasedSurfaceModel(aSolid, FP);
995 MkShellBasedSurfaceModel.Tolerance() = Tol;
996 if (MkShellBasedSurfaceModel.IsDone()) {
997 item = MkShellBasedSurfaceModel.Value();
998 }
999 }
1000 else if (aShape.ShapeType() == TopAbs_SHELL) {
1001 TopoDS_Shell aShell = TopoDS::Shell(aShape);
1002 // Non-manifold topology is stored via NMSSR containing series of SBSM (ssv; 13.11.2010)
1003 TopoDSToStep_MakeShellBasedSurfaceModel MkShellBasedSurfaceModel(aShell, FP);
1004 MkShellBasedSurfaceModel.Tolerance() = Tol;
1005 if (MkShellBasedSurfaceModel.IsDone()) {
1006 item = MkShellBasedSurfaceModel.Value();
1007 }
1008 }
1009 else if (aShape.ShapeType() == TopAbs_FACE) {
1010 TopoDS_Face aFace = TopoDS::Face(aShape);
1011 TopoDSToStep_MakeShellBasedSurfaceModel
1012 MkShellBasedSurfaceModel(aFace, FP);
1013 MkShellBasedSurfaceModel.Tolerance() = Tol;
1014 if (MkShellBasedSurfaceModel.IsDone()) {
1015 item = MkShellBasedSurfaceModel.Value();
1016 }
1017 }
1018 break;
1019 }
1020 case STEPControl_GeometricCurveSet:
1021 {
1022 TopoDSToStep_MakeGeometricCurveSet MkGeometricCurveSet(aShape,FP);
1023 MkGeometricCurveSet.Tolerance() = Tol;
1024 if (MkGeometricCurveSet.IsDone()) {
1025 item = MkGeometricCurveSet.Value();
1026 }
1027 // PTV 22.08.2002 OCC609 ------------------------- begin --------------------
1028 // modified by PTV 16.09.2002 OCC725
1029 else if (aShape.ShapeType() == TopAbs_COMPOUND ||
1030 aShape.ShapeType() == TopAbs_VERTEX) {
1031 // it is compund with solo vertices.
1032 Standard_Integer aNbVrtx = 0;
1033 Standard_Integer curNb = 0;
1034 TopExp_Explorer anExp (aShape, TopAbs_VERTEX);
1035 for ( ; anExp.More(); anExp.Next() ) {
1036 if ( anExp.Current().ShapeType() != TopAbs_VERTEX )
1037 continue;
1038 aNbVrtx++;
1039 }
1040 if ( aNbVrtx ) {
1041 // create new geometric curve set for all vertices
1042 Handle(StepShape_HArray1OfGeometricSetSelect) aGSS =
1043 new StepShape_HArray1OfGeometricSetSelect(1,aNbVrtx);
1044 Handle(TCollection_HAsciiString) empty = new TCollection_HAsciiString("");
1045 Handle(StepShape_GeometricCurveSet) aGCSet =
1046 new StepShape_GeometricCurveSet;
1047 aGCSet->SetName(empty);
1048 // iterates on compound with vertices and trances each vertex
1049 for ( anExp.ReInit() ; anExp.More(); anExp.Next() ) {
1050 TopoDS_Shape aVertex = anExp.Current();
1051 if ( aVertex.ShapeType() != TopAbs_VERTEX )
1052 continue;
1053 curNb++;
1054 transferVertex (FP, aGSS, aVertex, curNb);
1055 } // end of iteration on compound with vertices.
1056 aGCSet->SetElements(aGSS);
1057 item = aGCSet;
1058 } // end of check that number of vertices is not null
1059 }
1060 // PTV 22.08.2002 OCC609------------------------- end --------------------
1061 break;
1062 }
1063 default: break;
1064 }
1065 if ( item.IsNull() ) continue;
1066
1067 // add resulting item to the FP
1068 ItemSeq->Append(item);
1069 Handle(TransferBRep_ShapeMapper) submapper;
1070 if ( xShape.IsSame ( mapper->Value() ) )
1071 submapper = Handle(TransferBRep_ShapeMapper)::DownCast ( start );
1072 if ( submapper.IsNull() ) submapper = TransferBRep::ShapeMapper (FP,xShape);
1073 Handle(Transfer_Binder) subbind = FP->Find ( submapper );
1074 if ( subbind.IsNull() ) {
1075 subbind = TransientResult ( item );
1076 FP->Bind ( submapper, subbind );
1077 }
1078 else subbind->AddResult ( TransientResult ( item ) );
1079
1080 //:abv 24Jan99 CAX-IF TRJ3: Update FinderProcess map to take into account shape processing
1081// UpdateMap ( xShape, CSMT, DMT, FP );
1082 XSAlgo::AlgoContainer()->MergeTransferInfo(FP, info);
1083 }
1084
1085 // - Make Shape Representation
1086 Standard_Integer nCc1 = ItemSeq->Length();
1087 if (nCc1 < 1) {
1088 FP->AddFail(start,"The Shape has not the appropriate type");
1089 return binder;
1090 }
1091 Handle(StepShape_ShapeRepresentation) shapeRep;
1092 if ( theShape.ShapeType() == TopAbs_SHAPE ) { // for external references
1093 shapeRep = new StepShape_ShapeRepresentation;
1094 }
1095 else {
1096 switch (mymode) {
1097 case STEPControl_ManifoldSolidBrep:
1098 shapeRep = new StepShape_AdvancedBrepShapeRepresentation;
1099 break;
1100 case STEPControl_FacetedBrep:
1101 shapeRep = new StepShape_FacetedBrepShapeRepresentation;
1102 break;
1103 // NOTE: STEPControl_AsIs mode is normally used to transfer non-manifold topology.
1104 // However, as ShellBasedSurfaceModel is used in non-manifold processing
1105 // internally, STEPControl_ShellBasedSurfaceModel is also adjusted to
1106 // be able to work with non-manifold cases
1107 case STEPControl_ShellBasedSurfaceModel:
1108 if (isManifold)
1109 shapeRep = new StepShape_ManifoldSurfaceShapeRepresentation;
1110 else {
1111 Standard_Boolean isNewNMSSRCreated;
1112 shapeRep = this->getNMSSRForGroup(shapeGroup, FP, isNewNMSSRCreated);
1113 useExistingNMSSR = !isNewNMSSRCreated;
1114 }
1115 break;
1116 case STEPControl_GeometricCurveSet:
1117 shapeRep = new StepShape_GeometricallyBoundedWireframeShapeRepresentation;
1118 break;
1119 case STEPControl_AsIs :
1120 {
1121 if(nbs == 1) {
1122 if(trmode == STEPControl_ManifoldSolidBrep)
1123 shapeRep = new StepShape_AdvancedBrepShapeRepresentation;
1124 else if(trmode == STEPControl_ShellBasedSurfaceModel)
1125 // Process non-manifold topology separately (ssv; 13.11.2010)
1126 if (isManifold)
1127 shapeRep = new StepShape_ManifoldSurfaceShapeRepresentation;
1128 else {
1129 Standard_Boolean isNewNMSSRCreated;
1130 shapeRep = this->getNMSSRForGroup(shapeGroup, FP, isNewNMSSRCreated);
1131 useExistingNMSSR = !isNewNMSSRCreated;
1132 }
1133 else if(trmode == STEPControl_GeometricCurveSet)
1134 shapeRep = new StepShape_GeometricallyBoundedWireframeShapeRepresentation;
1135 else if(trmode ==STEPControl_FacetedBrep)
1136 shapeRep = new StepShape_FacetedBrepShapeRepresentation;
1137 }
1138 else shapeRep = new StepShape_ShapeRepresentation;
1139 }
1140 break;
1141 default: break;
1142 }
1143 }
1144 if(shapeRep.IsNull()) {
1145 Handle(Transfer_Binder) resb;
1146 return resb;
1147 }
1148
1149 Handle(StepRepr_HArray1OfRepresentationItem) items =
1150 new StepRepr_HArray1OfRepresentationItem(1,nCc1);
1151
1152 for (Standard_Integer rep = 1; rep <= nCc1; rep++) {
1153 Handle(StepRepr_RepresentationItem) repit =
1154 GetCasted(StepRepr_RepresentationItem, ItemSeq->Value(rep));
1155 items->SetValue(rep,repit);
1156 }
1157 Standard_Integer ap = Interface_Static::IVal("write.step.schema");
1158 Transfer_SequenceOfBinder aSeqBindRelation;
1159 if(ap == 3 && nbs > 1) {
1160 Standard_Integer j = 1;
1161 if(items->Value(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d))) {
1162 Handle(StepRepr_HArray1OfRepresentationItem) axis =
1163 new StepRepr_HArray1OfRepresentationItem(1,1);
1164 axis->SetValue(1,items->Value(j++));
1165 shapeRep->SetItems(axis);
1166 }
1167 for (; j <= items->Length(); j++) {
1168
1169 Handle(StepShape_ShapeRepresentation) ShapeRepr1;
1170 if(items->Value(j)->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep)))
1171 ShapeRepr1 = new StepShape_AdvancedBrepShapeRepresentation;
1172 else if(items->Value(j)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel)))
1173 ShapeRepr1 = new StepShape_ManifoldSurfaceShapeRepresentation;
1174 else if(items->Value(j)->IsKind(STANDARD_TYPE(StepShape_GeometricCurveSet)))
1175 ShapeRepr1 = new StepShape_GeometricallyBoundedWireframeShapeRepresentation;
1176 else if (items->Value(j)->IsKind(STANDARD_TYPE(StepShape_FacetedBrep)))
1177 ShapeRepr1 = new StepShape_FacetedBrepShapeRepresentation;
1178 else ShapeRepr1 = new StepShape_ShapeRepresentation;
1179
1180 Handle(StepRepr_HArray1OfRepresentationItem) repr1 = new StepRepr_HArray1OfRepresentationItem(1,2);
1181 repr1->SetValue(1,myContext.GetDefaultAxis());
1182 repr1->SetValue(2,items->Value(j));
1183 ShapeRepr1->SetItems(repr1);
1184 STEPConstruct_UnitContext mk1;
1185 mk1.Init(Tol);
1186 ShapeRepr1->SetContextOfItems(mk1.Value()); // la tolerance, voir au debut
1187 ShapeRepr1->SetName (new TCollection_HAsciiString(""));
1188
1189 Handle(StepRepr_ShapeRepresentationRelationship) aShapeRel = new StepRepr_ShapeRepresentationRelationship;
1190 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
1191 Handle(TCollection_HAsciiString) aDescr = new TCollection_HAsciiString("");
1192 aShapeRel->SetName(aName);
1193 aShapeRel->SetDescription(aDescr);
1194 aShapeRel->SetRep2(shapeRep);
1195 aShapeRel->SetRep1(ShapeRepr1);
1196
1197 aSeqBindRelation.Append(TransientResult (aShapeRel));
1198 }
1199 }
1200 else {
1201 if (!useExistingNMSSR)
1202 shapeRep->SetItems(items);
1203 else {
1204 // Add new representation item to the NMSSR's existing collection (ssv; 13.11.2010)
1205 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = shapeRep->Items();
1206 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1207 new StepRepr_HArray1OfRepresentationItem(1, oldItems->Length() + 1);
1208 Standard_Integer el = 1;
1209 for (Standard_Integer i = 1; i <= oldItems->Length(); i++)
1210 newItems->SetValue( el++, oldItems->Value(i) );
1211 newItems->SetValue( el, items->Value( items->Length() ) );
1212 shapeRep->SetItems(newItems);
1213 }
1214 }
1215
1216 // init representation
1217 STEPConstruct_UnitContext mk;
1218 mk.Init(Tol);
1219 shapeRep->SetContextOfItems(mk.Value()); // la tolerance, voir au debut
1220 shapeRep->SetName (new TCollection_HAsciiString(""));
1221
1222 // Create SDR (only once for non-manifold group)
1223 if (!useExistingNMSSR) {
1224 SDR0->SetUsedRepresentation (shapeRep);
1225 // create binder for SR and attach to it binder for RepItem (if exists)
1226 Handle(Transfer_Binder) resbind = TransientResult(shapeRep);
1227 binder = FP->Find(start);
1228 if ( ! binder.IsNull() ) {
1229 resbind->AddResult ( binder );
1230 FP->Rebind(start,resbind);
1231 //binder->AddResult ( resbind );
1232 //resbind = binder;
1233 }
1234 for(Standard_Integer k = 1; k <= aSeqBindRelation.Length(); k++)
1235 resbind->AddResult(aSeqBindRelation.Value(k));
1236
1237 // Add SDR for non-manifold topology in group mode 0 (ssv; 18.11.2010)
1238 if ( !aNMBinder.IsNull() )
1239 resbind->AddResult(aNMBinder);
1240
1241 return resbind;
1242 } else return FP->Find(start);
1243
1244}
1245
1246//=======================================================================
1247//function : TransferCompound
1248// #### TRANSFER COMPOUND AS (SUB-)ASSEMBLY
1249//purpose :
1250//=======================================================================
1251
1252Handle(Transfer_Binder) STEPControl_ActorWrite::TransferCompound (const Handle(Transfer_Finder)& start,
1253 const Handle(StepShape_ShapeDefinitionRepresentation)& SDR0,
1254 const Handle(Transfer_FinderProcess)& FP)
1255{
1256 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
1257 Handle(Transfer_Binder) binder;
1258 if (mapper.IsNull()) return binder;
1259 TopoDS_Shape theShape = mapper->Value();
1260
1261 // Inspect non-manifold topology case (ssv; 10.11.2010)
1262 Standard_Boolean isNMMode = Interface_Static::IVal("write.step.nonmanifold");
1263 Standard_Boolean isManifold;
1264 if (isNMMode)
1265 isManifold = IsManifoldShape(theShape);
1266 else
1267 isManifold = Standard_True;
1268
1269 // get a sequence of components (subshapes)
1270 Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
1271 // Prepare a collection for non-manifold group of shapes
1272 Handle(TopTools_HSequenceOfShape) NonManifoldGroup = new TopTools_HSequenceOfShape();
1273 // PTV OCC725 17.09.2002 -- begin --
1274 Standard_Integer nbFreeVrtx = 0;
1275 TopoDS_Compound aCompOfVrtx;
1276 BRep_Builder aB;
1277 aB.MakeCompound(aCompOfVrtx);
1278
1279 #ifdef DEB
1280 if (!isManifold)
1281 cout << "Exploding Solids to Shells if any..." << endl;
1282 #endif
1283
1284 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
1285 TopoDS_Shape aSubShape = iter.Value();
1286 if (aSubShape.ShapeType() != TopAbs_VERTEX) {
1287
1288 // Store non-manifold topology as shells (ssv; 10.11.2010)
1289 if (!isManifold && aSubShape.ShapeType() == TopAbs_SOLID) {
1290 for ( TopoDS_Iterator aSubIter(aSubShape); aSubIter.More(); aSubIter.Next() ) {
1291 TopoDS_Shell aSubShell = TopoDS::Shell( aSubIter.Value() );
1292 aSubShell.Closed(Standard_True);
1293 RepItemSeq->Append(aSubShell);
1294 NonManifoldGroup->Append(aSubShell);
1295 }
1296 }
1297 else if (!isManifold && (aSubShape.ShapeType() == TopAbs_SHELL) ) {
1298 RepItemSeq->Append(aSubShape);
1299 NonManifoldGroup->Append(aSubShape);
1300 }
1301 else
1302 RepItemSeq->Append(aSubShape);
1303
1304 continue;
1305 }
1306 aB.Add(aCompOfVrtx, iter.Value());
1307 nbFreeVrtx++;
1308 }
1309 if (nbFreeVrtx)
1310 RepItemSeq->Append (aCompOfVrtx);
1311
1312 // PTV OCC725 17.09.2002 -- end --
1313
1314 // Constitution : liste d axes, le premier est l origine, les suivants : 1
1315 // par sous-item
1316 Handle(StepShape_ShapeRepresentation) shapeRep =
1317 Handle(StepShape_ShapeRepresentation)::DownCast(SDR0->UsedRepresentation());
1318 if ( shapeRep.IsNull() ) {
1319 shapeRep = new StepShape_ShapeRepresentation;
1320 SDR0->SetUsedRepresentation(shapeRep); // to be used by MakeItem
1321 }
1322 binder = TransientResult(SDR0); // set SDR as first item in order to be found first (but not SDR of subshape!)
1323 binder->AddResult ( TransientResult(shapeRep) );
1324
1325 // translate components
1326 Standard_Integer i, nbs = RepItemSeq->Length();
1327 Handle(TColStd_HSequenceOfTransient) ItemSeq = new TColStd_HSequenceOfTransient();
1328 ItemSeq->Append (myContext.GetDefaultAxis());
1329 myContext.NextLevel();
1330 for ( i = 1; i <= nbs; i ++) {
1331 Handle(TransferBRep_ShapeMapper) subs = TransferBRep::ShapeMapper (FP,RepItemSeq->Value(i));
1332 Handle(StepGeom_Axis2Placement3d) AX1;
1333
1334 Handle(Transfer_Binder) bnd = TransferSubShape(subs, SDR0, AX1, FP, NonManifoldGroup, isManifold);
1335
1336 if (!AX1.IsNull()) ItemSeq->Append (AX1);
1337 // copy binders so as to have all roots in upper binder, but do not conflict
1338 while ( !bnd.IsNull() ) {
1339 Handle(Transfer_SimpleBinderOfTransient) bx =
1340 Handle(Transfer_SimpleBinderOfTransient)::DownCast(bnd);
1341 if ( !bx.IsNull() )
1342 // Single SDR is created for a non-manifold group (ssv: 12.11.2010)
1343 if (!isManifold && i > 1)
1344 break;
1345 else
1346 binder->AddResult( TransientResult( bx->Result() ) );
1347 bnd = bnd->NextResult();
1348 }
1349 }
1350 myContext.PrevLevel();
1351
1352 Standard_Integer nsub = ItemSeq->Length();
1353 Handle(StepRepr_HArray1OfRepresentationItem) items =
1354 new StepRepr_HArray1OfRepresentationItem(1,nsub);
1355
1356 // initialize representation
1357 for (Standard_Integer rep = 1; rep <= nsub; rep++)
1358 items->SetValue(rep,GetCasted(StepRepr_RepresentationItem, ItemSeq->Value(rep)));
1359 shapeRep->SetItems(items);
1360 Standard_Real Tol = UsedTolerance (mytoler,theShape);
1361 STEPConstruct_UnitContext mk;
1362 mk.Init(Tol);
1363 shapeRep->SetContextOfItems(mk.Value()); // la tolerance, voir au debut
1364 shapeRep->SetName (new TCollection_HAsciiString(""));
1365
1366 // set it to SDR
1367// SDR0->SetUsedRepresentation (shapeRep);
1368
1369 return binder;
1370}
1371
1372//=======================================================================
1373//function : TransferSubShape
1374//purpose :
1375//=======================================================================
1376
1377Handle(Transfer_Binder) STEPControl_ActorWrite::TransferSubShape (const Handle(Transfer_Finder)& start,
1378 const Handle(StepShape_ShapeDefinitionRepresentation)& SDR0,
1379 Handle(StepGeom_Axis2Placement3d)& AX1,
1380 const Handle(Transfer_FinderProcess)& FP,
1381 const Handle(TopTools_HSequenceOfShape)& shapeGroup,
1382 const Standard_Boolean isManifold)
1383{
1384 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
1385 if (mapper.IsNull()) return NullResult();
1386 TopoDS_Shape shape = mapper->Value();
1387
1388 // SHAPE EN POSITION VENANT D UN ASSEMBLAGE
1389 // Il faut alors distinguer la transformation de la shape meme
1390 // laquelle est consideree a l origine, puis transferee
1391 // A part, un item decrivant une occurence en position est cree
1392 // SINON, la shape est prise et transferee telle quelle
1393 TopoDS_Shape sh0 = shape;
1394 gp_Trsf aLoc;
1395 if ( GroupMode() >0) {
1396 TopLoc_Location shloc = shape.Location();
1397 aLoc = shloc.Transformation();
1398 TopLoc_Location shident;
1399 sh0.Location (shident);
1400 mapper = TransferBRep::ShapeMapper(FP,sh0);
1401 mapper->SameAttributes (start);
1402 }
1403
1404 Handle(Transfer_Binder) resbind = FP->Find(mapper);
1405 Handle(StepShape_ShapeDefinitionRepresentation) sdr;
1406// Handle(StepShape_ShapeRepresentation) resultat;
1407 STEPConstruct_Part SDRTool;
1408
1409 // Already SDR and SR available : take them as are
1410 Standard_Boolean iasdr = FP->GetTypedTransient
1411 (resbind,STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),sdr);
1412 if ( iasdr ) SDRTool.ReadSDR ( sdr );
1413 else {
1414 SDRTool.MakeSDR ( 0, myContext.GetProductName(), myContext.GetAPD()->Application() );
1415 sdr = SDRTool.SDRValue();
1416 }
1417// resultat = GetCasted(StepShape_ShapeRepresentation,sdr->UsedRepresentation());
1418
1419 // if shape itself not yet translated, do it now
1420 //:abv 20.05.02: see comment in TransferShape(): added "! iasdr ||"
1421 Handle(Transfer_Binder) resprod = TransientResult(sdr); //KA - OCC7141(skl 10.11.2004)
1422 if ( ! iasdr || resbind.IsNull() ) {
1423 resbind = TransferShape(mapper, sdr, FP, shapeGroup, isManifold);
1424 Handle(Transfer_Binder) oldbind = FP->Find ( mapper );
1425 if ( ! oldbind.IsNull() && !resbind.IsNull()) resbind->AddResult ( oldbind );
1426 FP->Bind (mapper,resbind);
1427 resprod=resbind; //KA - OCC7141(skl 10.11.2004)
1428 }
1429
1430 // A new resbind may have been produced
1431// DeclareAndCast(Transfer_SimpleBinderOfTransient,restrans,resbind);
1432// if (restrans.IsNull()) return resbind;
1433// FP->GetTypedTransient (resbind,STANDARD_TYPE(StepShape_ShapeRepresentation),resultat);
1434// sdr->SetUsedRepresentation(resultat); // to be used by MakeItem
1435
1436 // make location for assembly placement
1437 GeomToStep_MakeAxis2Placement3d mkax (aLoc);
1438 Handle(StepGeom_Axis2Placement3d) AxLoc = mkax.Value();
1439 AX1 = AxLoc;
1440
1441 // create assembly structures (CDSR, NAUO etc.)
1442 STEPConstruct_Assembly mkitem;
1443 mkitem.Init (sdr,SDR0,myContext.GetDefaultAxis(),AxLoc);
1444 mkitem.MakeRelationship ();
1445 Handle(TColStd_HSequenceOfTransient) roots = myContext.GetRootsForAssemblyLink ( mkitem );
1446
1447 // add roots corresponding to assembly and product structures to binder
1448 //Handle(Transfer_Binder) resprod = resbind; //KA - OCC7141(skl 10.11.2004)
1449 //KA: we need only the current subshape in resprod, since the binder is copied
1450 // in Transfershape which calls Transfersubshape [ OCC7141(skl 10.11.2004) ]
1451 if ( ! iasdr ) {
1452 resprod->AddResult ( TransientResult ( SDRTool.SDRValue() ) );
1453 resbind->AddResult ( TransientResult ( SDRTool.SDRValue() ) ); //KA - OCC7141(skl 10.11.2004)
1454 roots->Append ( myContext.GetRootsForPart ( SDRTool ) );
1455 }
1456 for ( Standard_Integer i=1; i <= roots->Length(); i++ ) {
1457 resprod->AddResult ( TransientResult ( roots->Value(i) ) );
1458 resbind->AddResult ( TransientResult ( roots->Value(i) ) ); //KA - OCC7141(skl 10.11.2004)
1459 }
1460 myContext.NextIndex();
1461
1462 //FP->Bind (mapper,resprod); //KA - OCC7141(skl 10.11.2004)
1463
1464 // abv 16.10.00: bind CDSR (et al) to located shape in order to be able to track instances
1465 if ( mapper != start ) {
1466 Handle(Transfer_Binder) bnd = FP->Find ( start );
1467 for ( Standard_Integer j=1; j <= roots->Length(); j++ )
1468 if ( bnd.IsNull() ) bnd = TransientResult ( roots->Value(j) );
1469 else bnd->AddResult ( TransientResult ( roots->Value(j) ) );
1470 FP->Bind ( start, bnd );
1471 }
1472
1473 return resprod;
1474}