1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //:k8 abv 06.01.99: TR10: writing unique names for NAUOs
15 // :j4 16.03.99 gka S4134
16 // abv 18.11.99 renamed from StepPDR_MakeItem
18 #include <Interface_EntityIterator.hxx>
19 #include <Interface_Graph.hxx>
20 #include <Interface_InterfaceModel.hxx>
21 #include <Standard_Transient.hxx>
22 #include <StepBasic_ApplicationContext.hxx>
23 #include <StepBasic_DesignContext.hxx>
24 #include <StepBasic_HArray1OfProductContext.hxx>
25 #include <StepBasic_MechanicalContext.hxx>
26 #include <StepBasic_Product.hxx>
27 #include <StepBasic_ProductDefinition.hxx>
28 #include <StepBasic_ProductDefinitionFormationWithSpecifiedSource.hxx>
29 #include <STEPConstruct_Assembly.hxx>
30 #include <StepGeom_Axis2Placement3d.hxx>
31 #include <StepRepr_CharacterizedDefinition.hxx>
32 #include <StepRepr_HArray1OfRepresentationItem.hxx>
33 #include <StepRepr_ItemDefinedTransformation.hxx>
34 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
35 #include <StepRepr_ProductDefinitionShape.hxx>
36 #include <StepRepr_RepresentationContext.hxx>
37 #include <StepRepr_ShapeRepresentationRelationshipWithTransformation.hxx>
38 #include <StepRepr_Transformation.hxx>
39 #include <StepShape_ContextDependentShapeRepresentation.hxx>
40 #include <StepShape_ShapeDefinitionRepresentation.hxx>
41 #include <StepShape_ShapeRepresentation.hxx>
42 #include <TCollection_HAsciiString.hxx>
44 // ProductDefinition (pour Relationship)
45 // ContextDependentShapeRepresentation qui contient la Relationship
47 //=======================================================================
48 //function : STEPConstruct_Assembly
50 //=======================================================================
51 STEPConstruct_Assembly::STEPConstruct_Assembly ()
55 //=======================================================================
58 //=======================================================================
60 void STEPConstruct_Assembly::Init (const Handle(StepShape_ShapeDefinitionRepresentation)& aSDR,
61 const Handle(StepShape_ShapeDefinitionRepresentation)& SDR0,
62 const Handle(StepGeom_Axis2Placement3d)& Ax0,
63 const Handle(StepGeom_Axis2Placement3d)& AxLoc)
67 thesr = Handle(StepShape_ShapeRepresentation)::DownCast(aSDR->UsedRepresentation());
68 thesr0 = Handle(StepShape_ShapeRepresentation)::DownCast(SDR0->UsedRepresentation());
74 //=======================================================================
75 //function : MakeMappedItem
77 //=======================================================================
79 //void STEPConstruct_Assembly::MakeMappedItem ()
81 // not yet implemented
84 //=======================================================================
85 //function : MakeRelationship
87 //=======================================================================
89 void STEPConstruct_Assembly::MakeRelationship ()
91 // get PDs for assembly (sdr0) and component (sdr)
92 Handle(StepBasic_ProductDefinition) PDED =
93 thesdr->Definition().PropertyDefinition()->Definition().ProductDefinition();
94 Handle(StepBasic_ProductDefinition) PDING =
95 thesdr0->Definition().PropertyDefinition()->Definition().ProductDefinition();
98 //:k8 abv 06 Jan 99: TR10: writing unique names for NAUOs !!!!!
99 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
100 new StepRepr_NextAssemblyUsageOccurrence;
101 static Standard_Integer id = 0;
102 Handle(TCollection_HAsciiString) ocid = new TCollection_HAsciiString(++id);
103 Handle(TCollection_HAsciiString) ocname = new TCollection_HAsciiString("");
104 Handle(TCollection_HAsciiString) ocdesc = new TCollection_HAsciiString("");
105 Handle(TCollection_HAsciiString) refdes; // reste nulle
106 NAUO->Init (ocid,ocname,Standard_True,ocdesc,PDING,PDED,Standard_False,refdes);
108 // create PDS for link CDSR->PDS->NAUO
109 Handle(StepRepr_ProductDefinitionShape) PDS =
110 new StepRepr_ProductDefinitionShape;
111 Handle(TCollection_HAsciiString) pdsname = new TCollection_HAsciiString("Placement");
112 Handle(TCollection_HAsciiString) pdsdesc = new TCollection_HAsciiString("Placement of an item");
113 StepRepr_CharacterizedDefinition CD;
115 PDS->Init (pdsname,Standard_True,pdsdesc,CD);
117 // create transformation
118 Handle(StepRepr_ItemDefinedTransformation) ItemDef =
119 new StepRepr_ItemDefinedTransformation;
120 Handle(TCollection_HAsciiString) idname = new TCollection_HAsciiString("");
121 Handle(TCollection_HAsciiString) idescr = new TCollection_HAsciiString("");
122 ItemDef->Init (idname,idescr,theax0,theloc);
125 Handle(StepRepr_ShapeRepresentationRelationshipWithTransformation) SRRWT =
126 new StepRepr_ShapeRepresentationRelationshipWithTransformation;
127 Handle(TCollection_HAsciiString) stname = new TCollection_HAsciiString("");
128 Handle(TCollection_HAsciiString) stescr = new TCollection_HAsciiString("");
129 StepRepr_Transformation StepTrans;
130 StepTrans.SetValue (ItemDef);
131 SRRWT->Init (stname,stescr,thesr,thesr0,StepTrans);
133 // create CDSR (final result, root)
134 Handle(StepShape_ContextDependentShapeRepresentation) CDSR =
135 new StepShape_ContextDependentShapeRepresentation;
136 CDSR->Init (SRRWT,PDS);
141 //=======================================================================
142 //function : ItemValue
144 //=======================================================================
146 Handle(Standard_Transient) STEPConstruct_Assembly::ItemValue () const
148 if (theval.IsNull()) return Handle(Standard_Transient) (thesr);
152 //=======================================================================
153 //function : ItemLocation
155 //=======================================================================
157 Handle(StepGeom_Axis2Placement3d) STEPConstruct_Assembly::ItemLocation () const
162 //=======================================================================
165 //=======================================================================
167 Handle(StepRepr_NextAssemblyUsageOccurrence) STEPConstruct_Assembly::GetNAUO () const
169 Handle(StepShape_ContextDependentShapeRepresentation) CDSR =
170 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast ( ItemValue() );
171 if ( ! CDSR.IsNull() ) {
172 Handle(StepBasic_ProductDefinitionRelationship) PDR =
173 CDSR->RepresentedProductRelation()->Definition().ProductDefinitionRelationship();
174 return Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast ( PDR );
179 //=======================================================================
180 //function : CheckSRRReversesNAUO
182 //=======================================================================
184 Standard_Boolean STEPConstruct_Assembly::CheckSRRReversesNAUO(const Interface_Graph& theGraph,
185 const Handle(StepShape_ContextDependentShapeRepresentation) &CDSR)
187 Handle(StepRepr_NextAssemblyUsageOccurrence) nauo =
188 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast
189 ( CDSR->RepresentedProductRelation()->Definition().ProductDefinitionRelationship() );
190 if ( nauo.IsNull() ) {
192 std::cout << "Warning: No NAUO found in CDSR !" << std::endl;
194 return Standard_False;
197 Handle(StepBasic_ProductDefinition) pd1, pd2;
198 Handle(StepRepr_Representation) rep1 = CDSR->RepresentationRelation()->Rep1();
199 Handle(StepRepr_Representation) rep2 = CDSR->RepresentationRelation()->Rep2();
200 if( rep1.IsNull() || rep2.IsNull())
201 return Standard_False;
203 // find SDRs corresponding to Rep1 and Rep2 and remember their PDs
204 Handle(Standard_Type) tSDR = STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation);
205 Interface_EntityIterator anIter = theGraph.Sharings(rep1);
206 for (; anIter.More() && pd1.IsNull(); anIter.Next()) {
207 Handle(Standard_Transient) enti = anIter.Value();
208 if (enti->DynamicType() == tSDR) {
209 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
210 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(enti);
211 if ( SDR->UsedRepresentation() == rep1 )
212 pd1 = SDR->Definition().PropertyDefinition()->Definition().ProductDefinition();
216 anIter = theGraph.Sharings(rep2);
217 for (; anIter.More() && pd2.IsNull(); anIter.Next()) {
218 Handle(Standard_Transient) enti = anIter.Value();
219 if (enti->DynamicType() == tSDR) {
220 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
221 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(enti);
222 if ( SDR->UsedRepresentation() == rep2 )
223 pd2 = SDR->Definition().PropertyDefinition()->Definition().ProductDefinition();
229 if ( pd1 == nauo->RelatedProductDefinition() && // OK
230 pd2 == nauo->RelatingProductDefinition() ) return Standard_False;
232 if ( pd2 == nauo->RelatedProductDefinition() && // Reversed
233 pd1 == nauo->RelatingProductDefinition() ) {
234 return Standard_True;
238 std::cout << "Warning: SRR and NAUO are incompatible" << std::endl;
239 // std::cout << "NAUO = " << Model->StringLabel(nauo)->ToCString() <<
240 // ",\tCDSR = " << Model->StringLabel(CDSR)->ToCString() << std::endl;
241 // std::cout << "Rep1 = " << Model->StringLabel(rep1)->ToCString() <<
242 // ",\tRep2 = " << Model->StringLabel(rep2)->ToCString() << std::endl;
243 // std::cout << "PD1 = " << Model->StringLabel(pd1)->ToCString() <<
244 // ",\tPD2 = " << Model->StringLabel(pd2)->ToCString() << std::endl;
245 // std::cout << "Rel1 = " << Model->StringLabel(nauo->RelatingProductDefinition())->ToCString() <<
246 // ",\tRel2 = " << Model->StringLabel(nauo->RelatedProductDefinition())->ToCString() << std::endl;
249 if ( pd2 == nauo->RelatedProductDefinition() || //:k3 abv 25 Nov 98: rp1sd.stp - bad assemblies
250 pd1 == nauo->RelatingProductDefinition() ) {
251 return Standard_True;
254 return Standard_False;