summaryrefslogtreecommitdiff
path: root/src/StepData/StepData_StepModel.cxx
blob: 3f9f1da1b46bf496136a6ad74c59e388dac9999b (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <StepData_StepModel.ixx>
#include <Standard_NoSuchObject.hxx>
#include <StepData_Protocol.hxx>
#include <StepData_StepWriter.hxx>

#include <StepData.hxx>
#include <Interface_CopyTool.hxx>
#include <Interface_GeneralLib.hxx>
#include <Interface_ShareTool.hxx>
#include <Interface_GeneralModule.hxx>
#include <Interface_Macros.hxx>
#include <stdio.h>


// Entete de fichier : liste d entites

    StepData_StepModel::StepData_StepModel ()  {  }

    void  StepData_StepModel::Reservate (const Standard_Integer nbent)
{
  Interface_InterfaceModel::Reservate(nbent);
  if (nbent > theidnums.NbBuckets()) theidnums.ReSize (nbent);
}

    Handle(Standard_Transient) StepData_StepModel::Entity
      (const Standard_Integer num) const
      {  return Value(num);  }      // nom plus joli

    void StepData_StepModel::GetFromAnother
  (const Handle(Interface_InterfaceModel)& other)
{
  theheader.Clear();
  DeclareAndCast(StepData_StepModel,another,other);
  if (another.IsNull()) return;
  Interface_EntityIterator iter = another->Header();
//  recopier le header. Attention, header distinct du contenu ...
  Interface_CopyTool TC (this,StepData::HeaderProtocol());
  for (; iter.More(); iter.Next()) {
    Handle(Standard_Transient) newhead;
    if (!TC.Copy(iter.Value(),newhead,Standard_False,Standard_False)) continue;
    if (!newhead.IsNull()) theheader.Append(newhead);
  }
}

    Handle(Interface_InterfaceModel) StepData_StepModel::NewEmptyModel () const
      {  return new StepData_StepModel;  }


    Interface_EntityIterator StepData_StepModel::Header () const
{
  Interface_EntityIterator iter;
  theheader.FillIterator(iter);
  return iter;
}

    Standard_Boolean StepData_StepModel::HasHeaderEntity
      (const Handle(Standard_Type)& atype) const
      {  return (theheader.NbTypedEntities(atype) == 1);  }

    Handle(Standard_Transient) StepData_StepModel::HeaderEntity
      (const Handle(Standard_Type)& atype) const
      {  return theheader.TypedEntity(atype);  }


//   Remplissage du Header

    void StepData_StepModel::ClearHeader ()
      {  theheader.Clear();  }


    void StepData_StepModel::AddHeaderEntity
  (const Handle(Standard_Transient)& ent)
      {  theheader.Append(ent);  }


void StepData_StepModel::VerifyCheck(Handle(Interface_Check)& ach) const
{
  Interface_GeneralLib lib(StepData::HeaderProtocol());
  Interface_ShareTool sh(this,StepData::HeaderProtocol());
  Handle(Interface_GeneralModule) module;  Standard_Integer CN;
  for (Interface_EntityIterator iter = Header(); iter.More(); iter.Next()) {
    Handle(Standard_Transient) head = iter.Value();
    if (!lib.Select(head,module,CN)) continue;
    module->CheckCase(CN,head,sh,ach);
  }
}


    void StepData_StepModel::DumpHeader
  (const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
{
//  NB : level n est pas utilise

  Handle(StepData_Protocol) stepro = StepData::HeaderProtocol();
  Standard_Boolean iapro = !stepro.IsNull();
  if (!iapro) S<<" -- WARNING : StepModel DumpHeader, Protocol not defined\n";

  Interface_EntityIterator iter = Header();
  Standard_Integer nb = iter.NbEntities();
  S << " --  Step Model Header : " <<iter.NbEntities() << " Entities :\n";
  for (iter.Start(); iter.More(); iter.Next()) {
    S << "  "  << iter.Value()->DynamicType()->Name() << "\n";
  }
  if (!iapro || nb == 0) return;
  S << " --  --        STEP MODEL    HEADER  CONTENT      --  --" << endl;
  S << " --   Dumped with Protocol : " << stepro->DynamicType()->Name()
    << "   --"<<endl;

  Standard_SStream aSStream;
  StepData_StepWriter SW(this);
  SW.SendModel(stepro,Standard_True);    // envoi HEADER seul
  SW.Print(aSStream);
  S << aSStream.str().c_str();
}


    void  StepData_StepModel::ClearLabels ()
      {  theidnums.Clear();  }

    void  StepData_StepModel::SetIdentLabel
  (const Handle(Standard_Transient)& ent, const Standard_Integer ident)
{
  if (Number(ent) == 0) return;
  if (theidnums.NbBuckets() < NbEntities()) theidnums.ReSize (NbEntities());
  if (theidnums.IsBound(ent)) theidnums.ChangeFind(ent) = ident;
  else theidnums.Bind (ent,ident);
}

    Standard_Integer  StepData_StepModel::IdentLabel
  (const Handle(Standard_Transient)& ent) const
{
  if (theidnums.IsBound(ent)) return theidnums.Find(ent);
  return 0;
}

    void  StepData_StepModel::PrintLabel
  (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
{
  Standard_Integer num = 0 , nid = 0;
  if (theidnums.IsBound(ent)) nid = theidnums.Find(ent);
  if (nid <= 0) num = Number(ent);

  if      (nid > 0) S<<"#"<<nid;
  else if (num > 0) S<<"(#"<<num<<")";
  else              S<<"(#0..)";
}

    Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel
  (const Handle(Standard_Transient)& ent) const
{
  Handle(TCollection_HAsciiString) label;
  char text[20];
  Standard_Integer num = 0 , nid = 0;
  if (theidnums.IsBound(ent)) nid = theidnums.Find(ent);
  if (nid <= 0) num = Number(ent);

  if      (nid > 0) sprintf (text, "#%d",nid);
  else if (num > 0) sprintf (text, "(#%d)",num);
  else              sprintf (text, "(#0..)");

  label = new TCollection_HAsciiString(text);
  return label;
}