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. |
7fd59977 |
13 | |
7fd59977 |
14 | |
42cf5bc1 |
15 | #include <IFSelect_ContextWrite.hxx> |
16 | #include <IFSelect_GeneralModifier.hxx> |
7fd59977 |
17 | #include <IGESAppli.hxx> |
42cf5bc1 |
18 | #include <IGESAppli_Protocol.hxx> |
19 | #include <IGESData_FileProtocol.hxx> |
20 | #include <IGESData_IGESDumper.hxx> |
21 | #include <IGESData_IGESEntity.hxx> |
7fd59977 |
22 | #include <IGESData_IGESModel.hxx> |
42cf5bc1 |
23 | #include <IGESData_IGESWriter.hxx> |
7fd59977 |
24 | #include <IGESData_Protocol.hxx> |
42cf5bc1 |
25 | #include <IGESDefs.hxx> |
7fd59977 |
26 | #include <IGESFile_Read.hxx> |
27 | #include <IGESSelect_Dumper.hxx> |
7fd59977 |
28 | #include <IGESSelect_FileModifier.hxx> |
42cf5bc1 |
29 | #include <IGESSelect_WorkLibrary.hxx> |
30 | #include <IGESSolid.hxx> |
c04c30b3 |
31 | #include <IGESSolid_Protocol.hxx> |
7fd59977 |
32 | #include <Interface_Check.hxx> |
42cf5bc1 |
33 | #include <Interface_InterfaceModel.hxx> |
7fd59977 |
34 | #include <Interface_Macros.hxx> |
42cf5bc1 |
35 | #include <Interface_Protocol.hxx> |
36 | #include <Interface_ReportEntity.hxx> |
37 | #include <Message.hxx> |
38 | #include <Message_Messenger.hxx> |
94708556 |
39 | #include <OSD_OpenFile.hxx> |
42cf5bc1 |
40 | #include <Standard_ErrorHandler.hxx> |
41 | #include <Standard_Stream.hxx> |
42 | #include <Standard_Transient.hxx> |
43 | #include <Standard_Type.hxx> |
44 | #include <TColStd_HSequenceOfInteger.hxx> |
7fd59977 |
45 | |
42cf5bc1 |
46 | #include <errno.h> |
92efcf78 |
47 | IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_WorkLibrary,IFSelect_WorkLibrary) |
48 | |
7fd59977 |
49 | static int deja = 0; |
50 | static Handle(IGESData_FileProtocol) IGESProto; |
51 | |
52 | |
53 | IGESSelect_WorkLibrary::IGESSelect_WorkLibrary |
54 | (const Standard_Boolean modefnes) |
55 | : themodefnes (modefnes) |
56 | { |
57 | IGESSolid::Init(); |
58 | IGESAppli::Init(); |
59 | IGESDefs::Init(); |
60 | |
61 | if (!deja) { |
62 | Handle(IGESSelect_Dumper) sesdump = new IGESSelect_Dumper; // ainsi,cestfait |
63 | deja = 1; |
64 | } |
65 | SetDumpLevels (4,6); |
66 | SetDumpHelp (0,"Only DNum"); |
67 | SetDumpHelp (1,"DNum, IGES Type & Form"); |
68 | SetDumpHelp (2,"Main Directory Informations"); |
69 | SetDumpHelp (3,"Complete Directory Part"); |
70 | SetDumpHelp (4,"Directory + Fields (except list contents)"); |
71 | SetDumpHelp (5,"Complete (with list contents)"); |
72 | SetDumpHelp (6,"Complete + Transformed data"); |
73 | } |
74 | |
75 | Standard_Integer IGESSelect_WorkLibrary::ReadFile |
76 | (const Standard_CString name, |
77 | Handle(Interface_InterfaceModel)& model, |
78 | const Handle(Interface_Protocol)& protocol) const |
79 | { |
80 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
81 | Handle(IGESData_IGESModel) igesmod = new IGESData_IGESModel; |
82 | DeclareAndCast(IGESData_Protocol,prot,protocol); |
83 | |
84 | char* pname=(char*) name; |
85 | Standard_Integer status = IGESFile_Read (pname,igesmod,prot); |
86 | |
87 | if (status < 0) sout<<"File not found : "<<name<<endl; |
88 | if (status > 0) sout<<"Error when reading file : "<<name<<endl; |
89 | if (status == 0) model = igesmod; |
90 | else model.Nullify(); |
91 | return status; |
92 | } |
93 | |
94 | |
95 | Standard_Boolean IGESSelect_WorkLibrary::WriteFile |
96 | (IFSelect_ContextWrite& ctx) const |
97 | { |
98 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
99 | // Preparation |
100 | DeclareAndCast(IGESData_IGESModel,igesmod,ctx.Model()); |
101 | DeclareAndCast(IGESData_Protocol,prot,ctx.Protocol()); |
102 | |
103 | if (igesmod.IsNull() || prot.IsNull()) return Standard_False; |
104 | ofstream fout; |
94708556 |
105 | OSD_OpenStream(fout,ctx.FileName(),ios::out ); |
7fd59977 |
106 | if (!fout) { |
107 | ctx.CCheck(0)->AddFail("IGES File could not be created"); |
108 | sout<<" - IGES File could not be created : " << ctx.FileName() << endl; return 0; |
109 | } |
110 | sout<<" IGES File Name : "<<ctx.FileName(); |
111 | IGESData_IGESWriter VW(igesmod); |
112 | sout<<"("<<igesmod->NbEntities()<<" ents) "; |
113 | |
114 | // File Modifiers |
115 | Standard_Integer nbmod = ctx.NbModifiers(); |
116 | for (Standard_Integer numod = 1; numod <= nbmod; numod ++) { |
117 | ctx.SetModifier (numod); |
118 | DeclareAndCast(IGESSelect_FileModifier,filemod,ctx.FileModifier()); |
119 | if (!filemod.IsNull()) filemod->Perform(ctx,VW); |
120 | // (impressions de mise au point) |
121 | sout << " .. FileMod." << numod <<" "<< filemod->Label(); |
122 | if (ctx.IsForAll()) sout << " (all model)"; |
123 | else sout << " (" << ctx.NbEntities() << " entities)"; |
124 | // sout << flush; |
125 | } |
126 | |
127 | // Envoi |
128 | VW.SendModel(prot); |
129 | sout<<" Write "; |
130 | if (themodefnes) VW.WriteMode() = 10; |
131 | Standard_Boolean status = VW.Print(fout); sout<<" Done"<<endl; |
132 | |
133 | errno = 0; |
134 | fout.close(); |
135 | status = fout.good() && status && !errno; |
136 | if(errno) |
137 | sout << strerror(errno) << endl; |
138 | |
139 | return status; |
140 | } |
141 | |
142 | Handle(IGESData_Protocol) IGESSelect_WorkLibrary::DefineProtocol () |
143 | { |
144 | if (!IGESProto.IsNull()) return IGESProto; |
145 | Handle(IGESData_Protocol) IGESProto1 = IGESSolid::Protocol(); |
146 | Handle(IGESData_Protocol) IGESProto2 = IGESAppli::Protocol(); |
147 | // Handle(IGESData_FileProtocol) IGESProto = new IGESData_FileProtocol; |
148 | IGESProto = new IGESData_FileProtocol; |
149 | IGESProto->Add(IGESProto1); |
150 | IGESProto->Add(IGESProto2); |
151 | return IGESProto; |
152 | } |
153 | |
154 | |
155 | void IGESSelect_WorkLibrary::DumpEntity |
156 | (const Handle(Interface_InterfaceModel)& model, |
157 | const Handle(Interface_Protocol)& protocol, |
158 | const Handle(Standard_Transient)& entity, |
159 | const Handle(Message_Messenger)& S, const Standard_Integer level) const |
160 | { |
161 | DeclareAndCast(IGESData_IGESModel,igesmod,model); |
162 | DeclareAndCast(IGESData_Protocol,igespro,protocol); |
163 | DeclareAndCast(IGESData_IGESEntity,igesent,entity); |
164 | if (igesmod.IsNull() || igespro.IsNull() || igesent.IsNull()) return; |
165 | Standard_Integer num = igesmod->Number(igesent); |
166 | if (num == 0) return; |
167 | |
168 | S<<" --- Entity "<<num; |
169 | Standard_Boolean iserr = model->IsRedefinedContent(num); |
170 | Handle(Standard_Transient) con; |
171 | if (iserr) con = model->ReportEntity(num)->Content(); |
172 | if (entity.IsNull()) { S<<" Null"<<endl; return ; } |
173 | |
174 | // On attaque le dump : d abord cas de l Erreur |
175 | if (iserr) { |
176 | S << " ERRONEOUS, Content, Type cdl : "; |
177 | if (!con.IsNull()) S << con->DynamicType()->Name(); |
178 | else S << "(undefined)" << endl; |
179 | igesent = GetCasted(IGESData_IGESEntity,con); |
180 | con.Nullify(); |
181 | Handle(Interface_Check) check = model->ReportEntity(num)->Check(); |
182 | Interface_CheckIterator chlist; |
183 | chlist.Add (check,num); |
184 | chlist.Print (S,igesmod,Standard_False); |
185 | if (igesent.IsNull()) return; |
186 | } |
187 | else S << " Type cdl : " << igesent->DynamicType()->Name(); |
188 | |
189 | IGESData_IGESDumper dump(igesmod,igespro); |
190 | try { |
191 | OCC_CATCH_SIGNALS |
192 | dump.Dump(igesent,S,level,(level-1)/3); |
193 | } |
194 | catch (Standard_Failure) { |
195 | S << " ** Dump Interrupt **" << endl; |
196 | } |
197 | } |