0025418: Debug output to be limited to OCC development environment
[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
7fd59977 27//=======================================================================
28//function : FindEntity
29//purpose :
30//=======================================================================
31
32Handle(StepRepr_RepresentationItem) STEPConstruct::FindEntity (const Handle(Transfer_FinderProcess) &FinderProcess,
33 const TopoDS_Shape &Shape)
34{
35 Handle(StepRepr_RepresentationItem) item;
36 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess, Shape );
37 FinderProcess->FindTypedTransient (mapper,STANDARD_TYPE(StepRepr_RepresentationItem), item);
0797d9d3 38#ifdef OCCT_DEBUG
7fd59977 39 if ( item.IsNull() ) cout << Shape.TShape()->DynamicType()->Name() << ": RepItem not found" << endl;
40 else cout << Shape.TShape()->DynamicType()->Name() << ": RepItem found: " << item->DynamicType()->Name() << endl;
41#endif
42 return item;
43}
44
45//=======================================================================
46//function : FindEntity
47//purpose :
48//=======================================================================
49
50Handle(StepRepr_RepresentationItem) STEPConstruct::FindEntity (const Handle(Transfer_FinderProcess) &FinderProcess,
51 const TopoDS_Shape &Shape,
52 TopLoc_Location &Loc)
53{
54 Handle(StepRepr_RepresentationItem) item;
55 Loc = Shape.Location();
56 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess, Shape );
57 if ( ! FinderProcess->FindTypedTransient (mapper,STANDARD_TYPE(StepRepr_RepresentationItem), item) &&
58 ! Loc.IsIdentity() ) {
59 Loc.Identity();
60 TopoDS_Shape S = Shape;
61 S.Location (Loc);
62 mapper = TransferBRep::ShapeMapper ( FinderProcess, S );
63 FinderProcess->FindTypedTransient (mapper,STANDARD_TYPE(StepRepr_RepresentationItem), item);
64 }
0797d9d3 65#ifdef OCCT_DEBUG
7fd59977 66 if ( item.IsNull() ) cout << Shape.TShape()->DynamicType()->Name() << ": RepItem not found" << endl;
67 else if ( Loc != Shape.Location() ) cout << Shape.TShape()->DynamicType()->Name() << ": RepItem found for shape without location: " << item->DynamicType()->Name() << endl;
68 else cout << Shape.TShape()->DynamicType()->Name() << ": RepItem found: " << item->DynamicType()->Name() << endl;
69#endif
70 return item;
71}
72
73//=======================================================================
74//function : FindShape
75//purpose :
76//=======================================================================
77
78TopoDS_Shape STEPConstruct::FindShape (const Handle(Transfer_TransientProcess) &TransientProcess,
79 const Handle(StepRepr_RepresentationItem) &item)
80{
81 TopoDS_Shape S;
82 Handle(Transfer_Binder) binder = TransientProcess->Find(item);
83 if ( ! binder.IsNull() && binder->HasResult() ) {
84 S = TransferBRep::ShapeResult ( TransientProcess, binder );
85 }
86 return S;
87}
88
89//=======================================================================
90//function : FindCDSR
91//purpose :
92//=======================================================================
93
94Standard_Boolean STEPConstruct::FindCDSR
95 (const Handle(Transfer_Binder)& ComponentBinder,
96 const Handle(StepShape_ShapeDefinitionRepresentation)& AssemblySDR,
97 Handle(StepShape_ContextDependentShapeRepresentation)& ComponentCDSR)
98{
99 Standard_Boolean result = Standard_False;
100
101 Handle(StepRepr_PropertyDefinition) PropD = AssemblySDR->Definition().PropertyDefinition();
102 if (!PropD.IsNull()) {
103 Handle(StepBasic_ProductDefinition) AssemblyPD = PropD->Definition().ProductDefinition();
104 if (!AssemblyPD.IsNull()) {
105 Handle(Transfer_Binder) binder = ComponentBinder;
106 Handle(Transfer_SimpleBinderOfTransient) trb;
107 Handle(StepRepr_ProductDefinitionShape) PDS;
108 Handle(StepBasic_ProductDefinitionRelationship) NAUO;
109 Handle(StepBasic_ProductDefinition) ComponentPD;
110 while (!binder.IsNull() && !result) {
111 trb = Handle(Transfer_SimpleBinderOfTransient)::DownCast(binder);
112 if (!trb.IsNull()) {
113 ComponentCDSR = Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(trb->Result());
114 if (!ComponentCDSR.IsNull()) {
115 PDS = ComponentCDSR->RepresentedProductRelation();
116 if (!PDS.IsNull()) {
117 NAUO = PDS->Definition().ProductDefinitionRelationship();
118 if (!NAUO.IsNull()) {
119 ComponentPD = NAUO->RelatingProductDefinition();
120 result = (ComponentPD == AssemblyPD);
121 }
122 }
123 }
124 }
125 binder = binder->NextResult();
126 }
127 }
128 }
129 return result;
130}