0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / IGESSelect / IGESSelect_WorkLibrary.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18
19#include <Standard_Stream.hxx>
20
21#include <IGESSelect_WorkLibrary.ixx>
22#include <Standard_ErrorHandler.hxx>
23#include <Message_Messenger.hxx>
24#include <Message.hxx>
25
26#include <IGESSolid.hxx>
27#include <IGESAppli.hxx>
28#include <IGESDefs.hxx>
29
30#include <IGESData_IGESWriter.hxx>
31#include <IGESData_IGESModel.hxx>
32#include <IGESData_Protocol.hxx>
33#include <IGESData_FileProtocol.hxx>
34#include <IGESFile_Read.hxx>
35#include <IGESSelect_Dumper.hxx>
36#include <IFSelect_GeneralModifier.hxx>
37#include <TColStd_HSequenceOfInteger.hxx>
38#include <IGESSelect_FileModifier.hxx>
39
40#include <Interface_ReportEntity.hxx>
41#include <IGESData_IGESEntity.hxx>
42#include <IGESData_IGESDumper.hxx>
43
44#include <Interface_Check.hxx>
45
46#include <Interface_Macros.hxx>
47#include <errno.h>
48
49static int deja = 0;
50static 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;
105 fout.rdbuf()->open(ctx.FileName(),ios::out );
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}