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
|
#include <StepSelect_WorkLibrary.ixx>
#include <sys/stat.h>
#include <errno.h>
#include <StepData_Protocol.hxx>
#include <StepData_StepModel.hxx>
#include <StepFile_Read.hxx>
#include <StepData_StepWriter.hxx>
#include <Interface_CheckIterator.hxx>
#include <StepSelect_FileModifier.hxx>
#include <StepData_UndefinedEntity.hxx>
#include <StepData_StepDumper.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TColStd_HSequenceOfInteger.hxx>
#include <IFSelect_GeneralModifier.hxx>
#include <Interface_ParamType.hxx>
#include <Interface_ReportEntity.hxx>
#include <Interface_UndefinedContent.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <Interface_Macros.hxx>
#include <Interface_Check.hxx>
StepSelect_WorkLibrary::StepSelect_WorkLibrary
(const Standard_Boolean copymode)
: thecopymode (copymode) , thelabmode (0)
{
SetDumpLevels (1,2);
SetDumpHelp (0,"#id + Step Type");
SetDumpHelp (1,"Entity as in file");
SetDumpHelp (2,"Entity + shareds (level 1) as in file");
}
// rq : les init sont faits par ailleurs, pas de souci a se faire
void StepSelect_WorkLibrary::SetDumpLabel (const Standard_Integer mode)
{
thelabmode = mode;
}
Standard_Integer StepSelect_WorkLibrary::ReadFile
(const Standard_CString name,
Handle(Interface_InterfaceModel)& model,
const Handle(Interface_Protocol)& protocol) const
{
long status = 1;
DeclareAndCast(StepData_Protocol,stepro,protocol);
if (stepro.IsNull()) return 1;
Handle(StepData_StepModel) stepmodel = new StepData_StepModel;
model = stepmodel;
StepFile_ReadTrace (0);
char *pName=(char *)name;
status = StepFile_Read (pName,stepmodel,stepro);
return status;
}
Standard_Boolean StepSelect_WorkLibrary::WriteFile
(IFSelect_ContextWrite& ctx) const
{
// Preparation
Handle(Message_Messenger) sout = Message::DefaultMessenger();
DeclareAndCast(StepData_StepModel,stepmodel,ctx.Model());
DeclareAndCast(StepData_Protocol,stepro,ctx.Protocol());
if (stepmodel.IsNull() || stepro.IsNull()) return Standard_False;
ofstream fout;
fout.open(ctx.FileName(),ios::out|ios::trunc);
if (!fout || !fout.rdbuf()->is_open()) {
ctx.CCheck(0)->AddFail("Step File could not be created");
sout<<" Step File could not be created : " << ctx.FileName() << endl; return 0;
}
sout << " Step File Name : "<<ctx.FileName();
StepData_StepWriter SW(stepmodel);
sout<<"("<<stepmodel->NbEntities()<<" ents) ";
// File Modifiers
Standard_Integer nbmod = ctx.NbModifiers();
for (Standard_Integer numod = 1; numod <= nbmod; numod ++) {
ctx.SetModifier (numod);
DeclareAndCast(StepSelect_FileModifier,filemod,ctx.FileModifier());
if (!filemod.IsNull()) filemod->Perform(ctx,SW);
// (impressions de mise au point)
sout << " .. FileMod." << numod << filemod->Label();
if (ctx.IsForAll()) sout << " (all model)";
else sout << " (" << ctx.NbEntities() << " entities)";
// sout << flush;
}
// Envoi
SW.SendModel(stepro);
Interface_CheckIterator chl = SW.CheckList();
for (chl.Start(); chl.More(); chl.Next())
ctx.CCheck(chl.Number())->GetMessages(chl.Value());
sout<<" Write ";
Standard_Boolean isGood = SW.Print(fout);
sout<<" Done"<<endl;
errno = 0;
fout.close();
isGood = fout.good() && isGood && !errno;
if(errno)
sout << strerror(errno) << endl;
return isGood;
}
Standard_Boolean StepSelect_WorkLibrary::CopyModel
(const Handle(Interface_InterfaceModel)& original,
const Handle(Interface_InterfaceModel)& newmodel,
const Interface_EntityIterator& list,
Interface_CopyTool& TC) const
{
if (thecopymode) return
IFSelect_WorkLibrary::CopyModel (original,newmodel,list,TC);
return thecopymode;
}
void StepSelect_WorkLibrary::DumpEntity
(const Handle(Interface_InterfaceModel)& model,
const Handle(Interface_Protocol)& protocol,
const Handle(Standard_Transient)& entity,
const Handle(Message_Messenger)& S, const Standard_Integer level) const
{
Standard_Integer nument = model->Number(entity);
if (nument <= 0 || nument > model->NbEntities()) return;
Standard_Boolean iserr = model->IsRedefinedContent(nument);
Handle(Standard_Transient) ent, con; ent = entity;
S<<" --- (STEP) Entity "; model->Print(entity,S);
if (iserr) con = model->ReportEntity(nument)->Content();
if (entity.IsNull()) { S<<" Null"<<endl; return; }
// On attaque le dump : d abord cas de l Erreur
S << " Type cdl : " << entity->DynamicType()->Name() << endl;
if (iserr)
S<<" *** NOT WELL LOADED : CONTENT FROM FILE ***"<<endl;
else if (model->IsUnknownEntity(nument))
S<<" *** UNKNOWN TYPE ***"<<endl;
StepData_StepDumper dump(GetCasted(StepData_StepModel,model),
GetCasted(StepData_Protocol,protocol),thelabmode);
dump.Dump(S,ent,level);
}
|