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