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