1 // Created on: 1993-07-23
2 // Created by: Martine LANGLOIS
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 
18 #include <BRepClass3d.hxx>
19 #include <Message_ProgressScope.hxx>
20 #include <MoniTool_DataMapOfShapeTransient.hxx>
21 #include <StdFail_NotDone.hxx>
22 #include <StepShape_ClosedShell.hxx>
23 #include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
24 #include <StepShape_HArray1OfOrientedClosedShell.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>
30 #include <TopoDS_Iterator.hxx>
31 #include <TopoDS_Shell.hxx>
32 #include <TopoDS_Solid.hxx>
33 #include <TopoDSToStep.hxx>
34 #include <TopoDSToStep_Builder.hxx>
35 #include <TopoDSToStep_MakeFacetedBrepAndBrepWithVoids.hxx>
36 #include <TopoDSToStep_Tool.hxx>
37 #include <Transfer_FinderProcess.hxx>
38 #include <TransferBRep_ShapeMapper.hxx>
39 
40 //=============================================================================
41 // Create a FacetedBrepAndBrepWithVoids of StepShape from a Solid of TopoDS
42 // containing more than one closed shell
43 //=============================================================================
44 TopoDSToStep_MakeFacetedBrepAndBrepWithVoids::
TopoDSToStep_MakeFacetedBrepAndBrepWithVoids(const TopoDS_Solid & aSolid,const Handle (Transfer_FinderProcess)& FP,const Message_ProgressRange & theProgress)45   TopoDSToStep_MakeFacetedBrepAndBrepWithVoids(const TopoDS_Solid& aSolid,
46                                                const Handle(Transfer_FinderProcess)& FP,
47                                                const Message_ProgressRange& theProgress)
48 {
49   done = Standard_False;
50   TopoDS_Iterator              It;
51   MoniTool_DataMapOfShapeTransient   aMap;
52   TColStd_SequenceOfTransient  S;
53   TopoDS_Shell                 aOutShell;
54 
55   Handle(StepShape_TopologicalRepresentationItem) aItem;
56   Handle(StepShape_ClosedShell)                   aOuter, aCShell;
57   Handle(StepShape_OrientedClosedShell)           aOCShell;
58   Handle(StepShape_HArray1OfOrientedClosedShell)  aVoids;
59 
60   aOutShell = BRepClass3d::OuterShell(aSolid);
61 
62   TopoDSToStep_Builder StepB;
63   TopoDSToStep_Tool    aTool;
64 
65   if (!aOutShell.IsNull()) {
66     Standard_Integer nbshapes = 0;
67     for (It.Initialize(aSolid); It.More(); It.Next())
68       if (It.Value().ShapeType() == TopAbs_SHELL)
69         nbshapes++;
70     Message_ProgressScope aPS(theProgress, NULL, nbshapes);
71     for (It.Initialize(aSolid); It.More() && aPS.More(); It.Next())
72     {
73       if (It.Value().ShapeType() == TopAbs_SHELL) {
74         Message_ProgressRange aRange = aPS.Next();
75 	TopoDS_Shell CurrentShell = TopoDS::Shell(It.Value());
76 	if (It.Value().Closed()) {
77 
78 	  aTool.Init(aMap, Standard_False);
79 	  StepB.Init(CurrentShell, aTool, FP, aRange);
80 	  TopoDSToStep::AddResult ( FP, aTool );
81 
82 	  if (StepB.IsDone()) {
83 	    aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value());
84 	    if ( aOutShell.IsEqual(It.Value()) )
85 	      aOuter = aCShell;
86 	    else
87 	      S.Append(aCShell);
88 	  }
89 	  else {
90 	    Handle(TransferBRep_ShapeMapper) errShape =
91 	      new TransferBRep_ShapeMapper(CurrentShell);
92 	    FP->AddWarning(errShape," Shell from Solid not mapped to FacetedBrepAndBrepWithVoids");
93 	  }
94 	}
95 	else {
96 	  done = Standard_False;
97 	  Handle(TransferBRep_ShapeMapper) errShape =
98 	    new TransferBRep_ShapeMapper(CurrentShell);
99 	  FP->AddWarning(errShape," Shell from Solid not closed; not mapped to FacetedBrepAndBrepWithVoids");
100 	}
101       }
102     }
103     if (!aPS.More())
104       return;
105   }
106   Standard_Integer N = S.Length();
107   if ( N>=1 ) {
108     aVoids = new StepShape_HArray1OfOrientedClosedShell(1,N);
109     Handle(TCollection_HAsciiString) aName =
110       new TCollection_HAsciiString("");
111     for ( Standard_Integer i=1; i<=N; i++ ) {
112       aOCShell = new StepShape_OrientedClosedShell();
113       aOCShell->Init(aName, Handle(StepShape_ClosedShell)::DownCast(S.Value(i)),
114 		     Standard_True);
115       aVoids->SetValue(i, aOCShell);
116     }
117     theFacetedBrepAndBrepWithVoids =
118       new StepShape_FacetedBrepAndBrepWithVoids();
119     theFacetedBrepAndBrepWithVoids->Init(aName, aOuter, aVoids);
120     done = Standard_True;
121   }
122   else {
123     done = Standard_False;
124     Handle(TransferBRep_ShapeMapper) errShape =
125       new TransferBRep_ShapeMapper(aSolid);
126     FP->AddWarning(errShape," Solid contains no Shell to be mapped to FacetedBrepAndBrepWithVoids");
127   }
128 }
129 
130 //=============================================================================
131 // renvoi des valeurs
132 //=============================================================================
133 
Handle(StepShape_FacetedBrepAndBrepWithVoids)134 const Handle(StepShape_FacetedBrepAndBrepWithVoids) &
135       TopoDSToStep_MakeFacetedBrepAndBrepWithVoids::Value() const
136 {
137   StdFail_NotDone_Raise_if (!done, "TopoDSToStep_MakeFacetedBrepAndBrepWithVoids::Value() - no result");
138   return theFacetedBrepAndBrepWithVoids;
139 }
140