7fd59977 |
1 | #include <StepSelect_WorkLibrary.ixx> |
2 | |
3 | #include <sys/stat.h> |
4 | #include <errno.h> |
5 | |
6 | #include <StepData_Protocol.hxx> |
7 | #include <StepData_StepModel.hxx> |
8 | #include <StepFile_Read.hxx> |
9 | #include <StepData_StepWriter.hxx> |
10 | #include <Interface_CheckIterator.hxx> |
11 | |
12 | #include <StepSelect_FileModifier.hxx> |
13 | |
14 | #include <StepData_UndefinedEntity.hxx> |
15 | #include <StepData_StepDumper.hxx> |
16 | |
17 | #include <TCollection_HAsciiString.hxx> |
18 | #include <TColStd_HSequenceOfInteger.hxx> |
19 | #include <IFSelect_GeneralModifier.hxx> |
20 | #include <Interface_ParamType.hxx> |
21 | #include <Interface_ReportEntity.hxx> |
22 | #include <Interface_UndefinedContent.hxx> |
23 | |
24 | #include <Message.hxx> |
25 | #include <Message_Messenger.hxx> |
26 | #include <Interface_Macros.hxx> |
27 | #include <Interface_Check.hxx> |
28 | |
29 | StepSelect_WorkLibrary::StepSelect_WorkLibrary |
30 | (const Standard_Boolean copymode) |
31 | : thecopymode (copymode) , thelabmode (0) |
32 | { |
33 | SetDumpLevels (1,2); |
34 | SetDumpHelp (0,"#id + Step Type"); |
35 | SetDumpHelp (1,"Entity as in file"); |
36 | SetDumpHelp (2,"Entity + shareds (level 1) as in file"); |
37 | } |
38 | // rq : les init sont faits par ailleurs, pas de souci a se faire |
39 | |
40 | |
41 | void StepSelect_WorkLibrary::SetDumpLabel (const Standard_Integer mode) |
42 | { |
43 | thelabmode = mode; |
44 | } |
45 | |
46 | |
47 | Standard_Integer StepSelect_WorkLibrary::ReadFile |
48 | (const Standard_CString name, |
49 | Handle(Interface_InterfaceModel)& model, |
50 | const Handle(Interface_Protocol)& protocol) const |
51 | { |
52 | long status = 1; |
53 | DeclareAndCast(StepData_Protocol,stepro,protocol); |
54 | if (stepro.IsNull()) return 1; |
55 | Handle(StepData_StepModel) stepmodel = new StepData_StepModel; |
56 | model = stepmodel; |
57 | StepFile_ReadTrace (0); |
58 | char *pName=(char *)name; |
59 | status = StepFile_Read (pName,stepmodel,stepro); |
60 | return status; |
61 | } |
62 | |
63 | |
64 | Standard_Boolean StepSelect_WorkLibrary::WriteFile |
65 | (IFSelect_ContextWrite& ctx) const |
66 | { |
67 | // Preparation |
68 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
69 | DeclareAndCast(StepData_StepModel,stepmodel,ctx.Model()); |
70 | DeclareAndCast(StepData_Protocol,stepro,ctx.Protocol()); |
71 | if (stepmodel.IsNull() || stepro.IsNull()) return Standard_False; |
72 | |
73 | ofstream fout; |
74 | fout.open(ctx.FileName(),ios::out|ios::trunc); |
75 | |
76 | if (!fout || !fout.rdbuf()->is_open()) { |
77 | ctx.CCheck(0)->AddFail("Step File could not be created"); |
78 | sout<<" Step File could not be created : " << ctx.FileName() << endl; return 0; |
79 | } |
80 | sout << " Step File Name : "<<ctx.FileName(); |
81 | StepData_StepWriter SW(stepmodel); |
82 | sout<<"("<<stepmodel->NbEntities()<<" ents) "; |
83 | |
84 | // File Modifiers |
85 | Standard_Integer nbmod = ctx.NbModifiers(); |
86 | for (Standard_Integer numod = 1; numod <= nbmod; numod ++) { |
87 | ctx.SetModifier (numod); |
88 | DeclareAndCast(StepSelect_FileModifier,filemod,ctx.FileModifier()); |
89 | if (!filemod.IsNull()) filemod->Perform(ctx,SW); |
90 | // (impressions de mise au point) |
91 | sout << " .. FileMod." << numod << filemod->Label(); |
92 | if (ctx.IsForAll()) sout << " (all model)"; |
93 | else sout << " (" << ctx.NbEntities() << " entities)"; |
94 | // sout << flush; |
95 | } |
96 | |
97 | // Envoi |
98 | SW.SendModel(stepro); |
99 | Interface_CheckIterator chl = SW.CheckList(); |
100 | for (chl.Start(); chl.More(); chl.Next()) |
101 | ctx.CCheck(chl.Number())->GetMessages(chl.Value()); |
102 | sout<<" Write "; |
103 | Standard_Boolean isGood = SW.Print(fout); |
104 | sout<<" Done"<<endl; |
105 | |
106 | errno = 0; |
107 | fout.close(); |
108 | isGood = fout.good() && isGood && !errno; |
109 | if(errno) |
110 | sout << strerror(errno) << endl; |
111 | return isGood; |
112 | } |
113 | |
114 | |
115 | Standard_Boolean StepSelect_WorkLibrary::CopyModel |
116 | (const Handle(Interface_InterfaceModel)& original, |
117 | const Handle(Interface_InterfaceModel)& newmodel, |
118 | const Interface_EntityIterator& list, |
119 | Interface_CopyTool& TC) const |
120 | { |
121 | if (thecopymode) return |
122 | IFSelect_WorkLibrary::CopyModel (original,newmodel,list,TC); |
123 | return thecopymode; |
124 | } |
125 | |
126 | |
127 | void StepSelect_WorkLibrary::DumpEntity |
128 | (const Handle(Interface_InterfaceModel)& model, |
129 | const Handle(Interface_Protocol)& protocol, |
130 | const Handle(Standard_Transient)& entity, |
131 | const Handle(Message_Messenger)& S, const Standard_Integer level) const |
132 | { |
133 | Standard_Integer nument = model->Number(entity); |
134 | if (nument <= 0 || nument > model->NbEntities()) return; |
135 | Standard_Boolean iserr = model->IsRedefinedContent(nument); |
136 | Handle(Standard_Transient) ent, con; ent = entity; |
137 | S<<" --- (STEP) Entity "; model->Print(entity,S); |
138 | if (iserr) con = model->ReportEntity(nument)->Content(); |
139 | if (entity.IsNull()) { S<<" Null"<<endl; return; } |
140 | |
141 | // On attaque le dump : d abord cas de l Erreur |
142 | S << " Type cdl : " << entity->DynamicType()->Name() << endl; |
143 | if (iserr) |
144 | S<<" *** NOT WELL LOADED : CONTENT FROM FILE ***"<<endl; |
145 | else if (model->IsUnknownEntity(nument)) |
146 | S<<" *** UNKNOWN TYPE ***"<<endl; |
147 | |
148 | StepData_StepDumper dump(GetCasted(StepData_StepModel,model), |
149 | GetCasted(StepData_Protocol,protocol),thelabmode); |
150 | dump.Dump(S,ent,level); |
151 | } |