1 // Created on: 1999-02-11
2 // Created by: Pavel DURANDIN
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Interface_EntityIterator.hxx>
19 #include <Interface_Graph.hxx>
20 #include <Interface_Macros.hxx>
21 #include <Standard_Transient.hxx>
22 #include <StepBasic_ProductRelatedProductCategory.hxx>
23 #include <STEPConstruct_Assembly.hxx>
24 #include <StepGeom_CompositeCurve.hxx>
25 #include <StepGeom_CompositeCurveSegment.hxx>
26 #include <StepGeom_Curve.hxx>
27 #include <StepGeom_Surface.hxx>
28 #include <StepRepr_MappedItem.hxx>
29 #include <StepRepr_RepresentationMap.hxx>
30 #include <StepRepr_RepresentationRelationship.hxx>
31 #include <StepRepr_ShapeRepresentationRelationship.hxx>
32 #include <STEPSelections_Counter.hxx>
33 #include <StepShape_BrepWithVoids.hxx>
34 #include <StepShape_ClosedShell.hxx>
35 #include <StepShape_ConnectedFaceSet.hxx>
36 #include <StepShape_ContextDependentShapeRepresentation.hxx>
37 #include <StepShape_FaceSurface.hxx>
38 #include <StepShape_FacetedBrep.hxx>
39 #include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
40 #include <StepShape_GeometricCurveSet.hxx>
41 #include <StepShape_GeometricSet.hxx>
42 #include <StepShape_GeometricSetSelect.hxx>
43 #include <StepShape_ManifoldSolidBrep.hxx>
44 #include <StepShape_OpenShell.hxx>
45 #include <StepShape_OrientedClosedShell.hxx>
46 #include <StepShape_ShapeDefinitionRepresentation.hxx>
47 #include <StepShape_ShapeRepresentation.hxx>
48 #include <StepShape_Shell.hxx>
49 #include <StepShape_ShellBasedSurfaceModel.hxx>
51 STEPSelections_Counter::STEPSelections_Counter()
60 void STEPSelections_Counter::Count(const Interface_Graph& graph,
61 const Handle(Standard_Transient)& start)
63 if(start.IsNull()) return;
65 if (start->IsKind(STANDARD_TYPE(StepBasic_ProductRelatedProductCategory))) return;
67 if (start->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
68 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,sdr,start);
69 Count(graph,sdr->UsedRepresentation());
70 Interface_EntityIterator subs = graph.Shareds(start);
71 for (subs.Start(); subs.More(); subs.Next()) {
72 DeclareAndCast(StepShape_ContextDependentShapeRepresentation,anitem,subs.Value());
73 if (anitem.IsNull()) continue;
79 if (start->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
80 DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
81 Standard_Integer nb = sr->NbItems();
82 for (Standard_Integer i = 1; i <= nb; i++) {
83 Handle(StepRepr_RepresentationItem) anitem = sr->ItemsValue(i);
89 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrep))) {
90 DeclareAndCast(StepShape_FacetedBrep,fbr,start);
91 myMapOfSolids.Add(start);
93 AddShell(fbr->Outer());
97 if (start->IsKind(STANDARD_TYPE(StepShape_BrepWithVoids))) {
98 DeclareAndCast(StepShape_BrepWithVoids,brwv,start);
99 myMapOfSolids.Add(start);
101 AddShell(brwv->Outer());
102 Standard_Integer nbvoids = brwv->NbVoids();
103 for(Standard_Integer i = 1; i <= nbvoids; i++)
104 AddShell(brwv->VoidsValue(i));
108 if (start->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))) {
109 DeclareAndCast(StepShape_ManifoldSolidBrep,msbr,start);
110 myMapOfSolids.Add(start);
112 AddShell(msbr->Outer());
116 if (start->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
117 DeclareAndCast(StepShape_ShellBasedSurfaceModel,sbsm,start);
118 Standard_Integer nbItems = sbsm->NbSbsmBoundary();
119 for(Standard_Integer i = 1; i <= nbItems; i++) {
120 Handle(StepShape_OpenShell) osh = sbsm->SbsmBoundaryValue(i).OpenShell();
121 if(!osh.IsNull()) AddShell(osh);
122 Handle(StepShape_ClosedShell) csh = sbsm->SbsmBoundaryValue(i).ClosedShell();
123 if(!csh.IsNull()) AddShell(csh);
128 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepAndBrepWithVoids))) {
129 DeclareAndCast(StepShape_FacetedBrepAndBrepWithVoids,fbwv,start);
130 myMapOfSolids.Add(start);
132 AddShell(fbwv->Outer());
133 Standard_Integer nbvoids = fbwv->NbVoids();
134 for(Standard_Integer i = 1; i <= nbvoids; i++)
135 AddShell(fbwv->VoidsValue(i));
139 if (start->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
140 DeclareAndCast(StepShape_GeometricSet,gs,start);
141 Standard_Integer nbElem = gs->NbElements();
142 for (Standard_Integer i = 1; i <= nbElem ; i++) {
143 StepShape_GeometricSetSelect aGSS = gs->ElementsValue(i);
144 Handle(Standard_Transient) ent = aGSS.Value();
145 Handle(StepGeom_CompositeCurve) ccurve = Handle(StepGeom_CompositeCurve)::DownCast(ent);
146 if(!ccurve.IsNull()) {
148 myMapOfWires.Add(ccurve);
149 AddCompositeCurve(ccurve);
151 if(ent->IsKind(STANDARD_TYPE(StepGeom_Curve))) {
153 myMapOfEdges.Add(ent);
155 if(ent->IsKind(STANDARD_TYPE(StepGeom_Surface))) {
157 myMapOfFaces.Add(ent);
163 if (start->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
164 DeclareAndCast(StepRepr_MappedItem,mi,start);
165 Count(graph,mi->MappingTarget());
166 Handle(StepRepr_RepresentationMap) map = mi->MappingSource();
167 if(map.IsNull()) return;
168 Count(graph,map->MappedRepresentation());
172 if (start->IsKind(STANDARD_TYPE(StepShape_FaceSurface))) {
174 myMapOfFaces.Add(start);
178 if (start->IsKind(STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation))) {
179 DeclareAndCast(StepShape_ContextDependentShapeRepresentation,CDSR,start);
180 Handle(StepRepr_RepresentationRelationship) SRR = CDSR->RepresentationRelation();
181 if ( SRR.IsNull() ) return ;
183 Handle(StepRepr_Representation) rep;
184 Standard_Boolean SRRReversed = STEPConstruct_Assembly::CheckSRRReversesNAUO ( graph, CDSR );
190 Interface_EntityIterator subs = graph.Sharings(rep);
191 for (subs.Start(); subs.More(); subs.Next())
192 if ( subs.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
193 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,SDR,subs.Value());
200 if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship)) ) {
201 DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
202 for (Standard_Integer i = 1; i <= 2; i ++) {
203 Handle(Standard_Transient) anitem;
204 if (i == 1) anitem = und->Rep1();
205 if (i == 2) anitem = und->Rep2();
212 void STEPSelections_Counter::Clear()
214 myMapOfFaces.Clear();
215 myMapOfShells.Clear();
216 myMapOfSolids.Clear();
217 myMapOfWires.Clear();
218 myMapOfEdges.Clear();
226 void STEPSelections_Counter::AddShell(const Handle(StepShape_ConnectedFaceSet)& cfs)
228 myMapOfShells.Add(cfs);
230 Standard_Integer nbf = cfs->NbCfsFaces();
231 for(Standard_Integer i =1; i <= nbf; i++)
232 myMapOfFaces.Add(cfs->CfsFacesValue(i));
237 void STEPSelections_Counter::AddCompositeCurve(const Handle(StepGeom_CompositeCurve)& ccurve)
239 Standard_Integer nbs = ccurve->NbSegments();
240 for ( Standard_Integer i=1; i <= nbs; i++ ) {
241 // #ifdef AIX CKY : common code for all platforms: Handle() not Handle()&
242 Handle(StepGeom_CompositeCurveSegment) ccs = ccurve->SegmentsValue ( i );
243 Handle(StepGeom_Curve) crv = ccs->ParentCurve();
245 if(crv->IsKind(STANDARD_TYPE(StepGeom_CompositeCurve)))
246 AddCompositeCurve(Handle(StepGeom_CompositeCurve)::DownCast(crv));
249 myMapOfEdges.Add(crv);