summaryrefslogtreecommitdiff
path: root/src/StepData/StepData_DescrReadWrite.cxx
blob: 0b97260d635134082f7cf6bd674f5d183fdc05a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <StepData_DescrReadWrite.ixx>
#include <StepData_EDescr.hxx>
#include <StepData_ECDescr.hxx>
#include <StepData_ESDescr.hxx>
#include <StepData_Simple.hxx>
#include <StepData_Plex.hxx>
#include <StepData_FieldListN.hxx>
#include <TColStd_HSequenceOfAsciiString.hxx>
#include <Interface_Macros.hxx>

static TCollection_AsciiString nocp("?");


    StepData_DescrReadWrite::StepData_DescrReadWrite
  (const Handle(StepData_Protocol)& proto)
    : theproto (proto)    {  }

    Standard_Integer  StepData_DescrReadWrite::CaseStep
  (const TCollection_AsciiString& atype) const
{
  Handle(StepData_ESDescr) descr = theproto->ESDescr (atype.ToCString(),Standard_False);
  if (descr.IsNull()) return 0;
  return theproto->DescrNumber (descr);
}

    Standard_Integer  StepData_DescrReadWrite::CaseStep
  (const TColStd_SequenceOfAsciiString& types) const
{
  Handle(StepData_ECDescr) descr = theproto->ECDescr (types,Standard_False);
  if (descr.IsNull()) return 0;
  return theproto->DescrNumber (descr);
}


    Standard_Boolean  StepData_DescrReadWrite::IsComplex
  (const Standard_Integer CN) const
{
  Handle(StepData_EDescr)  descr = theproto->Descr (CN);
  if (descr.IsNull()) return Standard_False;
  return descr->IsComplex();
}

    const TCollection_AsciiString& StepData_DescrReadWrite::StepType
  (const Standard_Integer CN) const
{
  Handle(StepData_ESDescr)  descr = Handle(StepData_ESDescr)::DownCast
    (theproto->Descr (CN));
  if (descr.IsNull()) return nocp;
  return descr->StepType();
}

    Standard_Boolean StepData_DescrReadWrite::ComplexType
  (const Standard_Integer CN, TColStd_SequenceOfAsciiString& types) const
{
  Handle(StepData_ECDescr)  descr = Handle(StepData_ECDescr)::DownCast
    (theproto->Descr (CN));
  if (descr.IsNull()) return Standard_False;
  Handle(TColStd_HSequenceOfAsciiString) list = descr->TypeList();
  if (list.IsNull()) return Standard_False;
  Standard_Integer i, nb = list->Length();
  for (i = 1; i <= nb; i ++)  types.Append (list->Value(i));
  return Standard_True;
}


void StepData_DescrReadWrite::ReadStep(const Standard_Integer CN,
                                       const Handle(StepData_StepReaderData)& data,
                                       const Standard_Integer num,
                                       Handle(Interface_Check)& ach,
                                       const Handle(Standard_Transient)&ent) const
{
  if (CN == 0) return;
  DeclareAndCast(StepData_Simple,sent,ent);
  if (!sent.IsNull()) {
    Handle(StepData_ESDescr) sdescr = sent->ESDescr();
    StepData_FieldListN& fl = sent->CFields();
    data->ReadList (num,ach,sdescr,fl);
    return;
  }

  DeclareAndCast(StepData_Plex,cent,ent);
  Standard_Integer i, nb=0;
  if (!cent.IsNull()) nb = cent->NbMembers();
  Standard_Integer n0 = num;
  for (i = 1; i <= nb; i ++) {
    Handle(StepData_Simple) si = cent->Member(i);
    Handle(StepData_ESDescr) sdescr = si->ESDescr();
    StepData_FieldListN& fl = si->CFields();
    data->ReadList (n0,ach,sdescr,fl);
    if (i < nb) n0 = data->NextForComplex(n0);
  }
}


    void StepData_DescrReadWrite::WriteStep
  (const Standard_Integer CN,
   StepData_StepWriter& SW,
   const Handle(Standard_Transient)&ent) const
{
  if (CN == 0) return;

  DeclareAndCast(StepData_Simple,sent,ent);
  if (!sent.IsNull()) {
    Handle(StepData_ESDescr) sdescr = sent->ESDescr();
    const StepData_FieldListN& fl = sent->Fields();
    SW.SendList (fl,sdescr);
    return;
  }

  DeclareAndCast(StepData_Plex,cent,ent);
  Standard_Integer i, nb=0;
  if (!cent.IsNull()) nb = cent->NbMembers();
  for (i = 1; i <= nb; i ++) {
    Handle(StepData_Simple) si = cent->Member(i);
    Handle(StepData_ESDescr) sdescr = si->ESDescr();
      const StepData_FieldListN& fl = si->Fields();
      SW.StartEntity (sdescr->TypeName());
      SW.SendList (fl,sdescr);
  }
}