0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / STEPConstruct / STEPConstruct.cxx
CommitLineData
b311480e 1// Created on: 2000-01-11
2// Created by: Andrey BETENEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <STEPConstruct.ixx>
17#include <TransferBRep.hxx>
18#include <TransferBRep_ShapeMapper.hxx>
19#include <Transfer_Binder.hxx>
20#include <Transfer_SimpleBinderOfTransient.hxx>
21
22#include <StepBasic_ProductDefinition.hxx>
23#include <StepBasic_ProductDefinitionRelationship.hxx>
24#include <StepRepr_PropertyDefinition.hxx>
25#include <StepRepr_ProductDefinitionShape.hxx>
26
27#ifdef DEBUG
28void DumpBinder (const Handle(Transfer_Binder) &binder)
29{
30 Handle(Transfer_Binder) bbb = binder;
31 while ( ! bbb.IsNull() ) {
32 Handle(Transfer_SimpleBinderOfTransient) bx =
33 Handle(Transfer_SimpleBinderOfTransient)::DownCast ( bbb );
34 if ( ! bx.IsNull() ) {
35 cout << "--> " << bx->ResultTypeName() << " " << *(void**)&bx->Result() << endl;
36 }
37 else cout << "--> ???" << endl;
38 bbb = bbb->NextResult();
39 }
40 cout << endl;
41}
42#endif
43
44//=======================================================================
45//function : FindEntity
46//purpose :
47//=======================================================================
48
49Handle(StepRepr_RepresentationItem) STEPConstruct::FindEntity (const Handle(Transfer_FinderProcess) &FinderProcess,
50 const TopoDS_Shape &Shape)
51{
52 Handle(StepRepr_RepresentationItem) item;
53 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess, Shape );
54 FinderProcess->FindTypedTransient (mapper,STANDARD_TYPE(StepRepr_RepresentationItem), item);
63c629aa 55#ifdef STEPCONSTRUCT_DEB
7fd59977 56 if ( item.IsNull() ) cout << Shape.TShape()->DynamicType()->Name() << ": RepItem not found" << endl;
57 else cout << Shape.TShape()->DynamicType()->Name() << ": RepItem found: " << item->DynamicType()->Name() << endl;
58#endif
59 return item;
60}
61
62//=======================================================================
63//function : FindEntity
64//purpose :
65//=======================================================================
66
67Handle(StepRepr_RepresentationItem) STEPConstruct::FindEntity (const Handle(Transfer_FinderProcess) &FinderProcess,
68 const TopoDS_Shape &Shape,
69 TopLoc_Location &Loc)
70{
71 Handle(StepRepr_RepresentationItem) item;
72 Loc = Shape.Location();
73 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess, Shape );
74 if ( ! FinderProcess->FindTypedTransient (mapper,STANDARD_TYPE(StepRepr_RepresentationItem), item) &&
75 ! Loc.IsIdentity() ) {
76 Loc.Identity();
77 TopoDS_Shape S = Shape;
78 S.Location (Loc);
79 mapper = TransferBRep::ShapeMapper ( FinderProcess, S );
80 FinderProcess->FindTypedTransient (mapper,STANDARD_TYPE(StepRepr_RepresentationItem), item);
81 }
63c629aa 82#ifdef STEPCONSTRUCT_DEB
7fd59977 83 if ( item.IsNull() ) cout << Shape.TShape()->DynamicType()->Name() << ": RepItem not found" << endl;
84 else if ( Loc != Shape.Location() ) cout << Shape.TShape()->DynamicType()->Name() << ": RepItem found for shape without location: " << item->DynamicType()->Name() << endl;
85 else cout << Shape.TShape()->DynamicType()->Name() << ": RepItem found: " << item->DynamicType()->Name() << endl;
86#endif
87 return item;
88}
89
90//=======================================================================
91//function : FindShape
92//purpose :
93//=======================================================================
94
95TopoDS_Shape STEPConstruct::FindShape (const Handle(Transfer_TransientProcess) &TransientProcess,
96 const Handle(StepRepr_RepresentationItem) &item)
97{
98 TopoDS_Shape S;
99 Handle(Transfer_Binder) binder = TransientProcess->Find(item);
100 if ( ! binder.IsNull() && binder->HasResult() ) {
101 S = TransferBRep::ShapeResult ( TransientProcess, binder );
102 }
103 return S;
104}
105
106//=======================================================================
107//function : FindCDSR
108//purpose :
109//=======================================================================
110
111Standard_Boolean STEPConstruct::FindCDSR
112 (const Handle(Transfer_Binder)& ComponentBinder,
113 const Handle(StepShape_ShapeDefinitionRepresentation)& AssemblySDR,
114 Handle(StepShape_ContextDependentShapeRepresentation)& ComponentCDSR)
115{
116 Standard_Boolean result = Standard_False;
117
118 Handle(StepRepr_PropertyDefinition) PropD = AssemblySDR->Definition().PropertyDefinition();
119 if (!PropD.IsNull()) {
120 Handle(StepBasic_ProductDefinition) AssemblyPD = PropD->Definition().ProductDefinition();
121 if (!AssemblyPD.IsNull()) {
122 Handle(Transfer_Binder) binder = ComponentBinder;
123 Handle(Transfer_SimpleBinderOfTransient) trb;
124 Handle(StepRepr_ProductDefinitionShape) PDS;
125 Handle(StepBasic_ProductDefinitionRelationship) NAUO;
126 Handle(StepBasic_ProductDefinition) ComponentPD;
127 while (!binder.IsNull() && !result) {
128 trb = Handle(Transfer_SimpleBinderOfTransient)::DownCast(binder);
129 if (!trb.IsNull()) {
130 ComponentCDSR = Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(trb->Result());
131 if (!ComponentCDSR.IsNull()) {
132 PDS = ComponentCDSR->RepresentedProductRelation();
133 if (!PDS.IsNull()) {
134 NAUO = PDS->Definition().ProductDefinitionRelationship();
135 if (!NAUO.IsNull()) {
136 ComponentPD = NAUO->RelatingProductDefinition();
137 result = (ComponentPD == AssemblyPD);
138 }
139 }
140 }
141 }
142 binder = binder->NextResult();
143 }
144 }
145 }
146 return result;
147}