0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / RWStepAP242 / RWStepAP242_RWItemIdentifiedRepresentationUsage.cxx
1 // Created on: 2015-07-07
2 // Created by: Irina KRYLOVA
3 // Copyright (c) 2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <RWStepAP242_RWItemIdentifiedRepresentationUsage.hxx>
17 #include <Interface_EntityIterator.hxx>
18 #include <StepRepr_HArray1OfRepresentationItem.hxx>
19 #include <StepData_StepReaderData.hxx>
20 #include <StepData_StepWriter.hxx>
21 #include <StepAP242_ItemIdentifiedRepresentationUsage.hxx>
22 #include <StepAP242_ItemIdentifiedRepresentationUsageDefinition.hxx>
23 #include <StepRepr_Representation.hxx>
24 #include <StepRepr_RepresentationItem.hxx>
25
26
27 RWStepAP242_RWItemIdentifiedRepresentationUsage::RWStepAP242_RWItemIdentifiedRepresentationUsage () {}
28
29 void RWStepAP242_RWItemIdentifiedRepresentationUsage::ReadStep
30   (const Handle(StepData_StepReaderData)& data,
31    const Standard_Integer num,
32    Handle(Interface_Check)& ach,
33    const Handle(StepAP242_ItemIdentifiedRepresentationUsage)& ent) const
34 {
35   // --- Number of Parameter Control ---
36
37   if (!data->CheckNbParams(num,5,ach,"item_identified_representation_usage")) return;
38
39   // --- own field : name ---
40
41   Handle(TCollection_HAsciiString) aName;
42   data->ReadString (num,1,"name",ach,aName);
43
44   // --- own field : description ---
45
46   Handle(TCollection_HAsciiString) aDescription;
47   if (data->IsParamDefined (num,2)) {
48     data->ReadString (num,2,"description",ach,aDescription);
49   }
50   // --- own field : definition ---
51
52   StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
53   data->ReadEntity(num,3,"definition",ach,aDefinition);
54
55   // --- own field : used_representation ---
56
57   Handle(StepRepr_Representation) aRepresentation;
58   data->ReadEntity (num,4,"used_representation",ach,STANDARD_TYPE(StepRepr_Representation), aRepresentation);
59
60   // --- own field : identified_item
61
62   Handle(StepRepr_HArray1OfRepresentationItem) anItems;
63   Handle(StepRepr_RepresentationItem) anEnt;
64   Standard_Integer nbSub;
65   Interface_ParamType aType = data->ParamType(num, 5);
66   if (aType == Interface_ParamIdent) {
67     data->ReadEntity(num, 5,"item_identified_representation_usage.identified_item", ach, STANDARD_TYPE(StepRepr_RepresentationItem), anEnt);
68     anItems = new StepRepr_HArray1OfRepresentationItem (1, 1);
69     anItems->SetValue(1, anEnt);
70   }
71   else if (data->ReadSubList (num,5,"item_identified_representation_usage.identified_item",ach,nbSub)) {
72     Standard_Integer nbElements = data->NbParams(nbSub);
73     anItems = new StepRepr_HArray1OfRepresentationItem (1, nbElements);
74     for (Standard_Integer i = 1; i <= nbElements; i++) {
75       if (data->ReadEntity(nbSub, i,"representation_item", ach,
76          STANDARD_TYPE(StepRepr_RepresentationItem), anEnt))
77         anItems->SetValue(i, anEnt);
78     }
79   }
80
81   //--- Initialisation of the read entity ---
82
83
84   ent->Init(aName, aDescription, aDefinition, aRepresentation, anItems);
85 }
86
87
88 void RWStepAP242_RWItemIdentifiedRepresentationUsage::WriteStep
89   (StepData_StepWriter& SW,
90    const Handle(StepAP242_ItemIdentifiedRepresentationUsage)& ent) const
91 {
92
93   // --- own field : name ---
94
95   SW.Send(ent->Name());
96
97   // --- own field : description ---
98
99   SW.Send(ent->Description());
100
101   // --- own field : definition ---
102
103   SW.Send(ent->Definition().Value());
104
105   // --- own field : used_representation ---
106
107   SW.Send(ent->UsedRepresentation());
108
109   // --- own field : identified_item ---
110
111   if (ent->NbIdentifiedItem() == 1)
112     SW.Send(ent->IdentifiedItemValue(1));
113   else {
114     SW.OpenSub();
115     for (Standard_Integer i = 1;  i <= ent->NbIdentifiedItem();  i++) {
116       SW.Send(ent->IdentifiedItemValue(i));
117     }
118     SW.CloseSub();
119   }
120 }
121
122
123 void RWStepAP242_RWItemIdentifiedRepresentationUsage::Share(
124   const Handle(StepAP242_ItemIdentifiedRepresentationUsage)& ent, 
125   Interface_EntityIterator& iter) const
126 {
127   iter.AddItem(ent->Definition().Value());
128   Standard_Integer i, nb = ent->NbIdentifiedItem();
129   for (i = 1; i <= nb; i++)  
130     iter.AddItem (ent->IdentifiedItemValue(i));
131 }
132