1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and / or modify it
6 // under the terms of the GNU Lesser General Public version 2.1 as published
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Standard_Stream.hxx>
16 #include <IGESSelect_WorkLibrary.ixx>
17 #include <Standard_ErrorHandler.hxx>
18 #include <Message_Messenger.hxx>
19 #include <Message.hxx>
21 #include <IGESSolid.hxx>
22 #include <IGESAppli.hxx>
23 #include <IGESDefs.hxx>
25 #include <IGESData_IGESWriter.hxx>
26 #include <IGESData_IGESModel.hxx>
27 #include <IGESData_Protocol.hxx>
28 #include <IGESData_FileProtocol.hxx>
29 #include <IGESFile_Read.hxx>
30 #include <IGESSelect_Dumper.hxx>
31 #include <IFSelect_GeneralModifier.hxx>
32 #include <TColStd_HSequenceOfInteger.hxx>
33 #include <IGESSelect_FileModifier.hxx>
35 #include <Interface_ReportEntity.hxx>
36 #include <IGESData_IGESEntity.hxx>
37 #include <IGESData_IGESDumper.hxx>
39 #include <Interface_Check.hxx>
41 #include <Interface_Macros.hxx>
45 static Handle(IGESData_FileProtocol) IGESProto;
48 IGESSelect_WorkLibrary::IGESSelect_WorkLibrary
49 (const Standard_Boolean modefnes)
50 : themodefnes (modefnes)
57 Handle(IGESSelect_Dumper) sesdump = new IGESSelect_Dumper; // ainsi,cestfait
61 SetDumpHelp (0,"Only DNum");
62 SetDumpHelp (1,"DNum, IGES Type & Form");
63 SetDumpHelp (2,"Main Directory Informations");
64 SetDumpHelp (3,"Complete Directory Part");
65 SetDumpHelp (4,"Directory + Fields (except list contents)");
66 SetDumpHelp (5,"Complete (with list contents)");
67 SetDumpHelp (6,"Complete + Transformed data");
70 Standard_Integer IGESSelect_WorkLibrary::ReadFile
71 (const Standard_CString name,
72 Handle(Interface_InterfaceModel)& model,
73 const Handle(Interface_Protocol)& protocol) const
75 Handle(Message_Messenger) sout = Message::DefaultMessenger();
76 Handle(IGESData_IGESModel) igesmod = new IGESData_IGESModel;
77 DeclareAndCast(IGESData_Protocol,prot,protocol);
79 char* pname=(char*) name;
80 Standard_Integer status = IGESFile_Read (pname,igesmod,prot);
82 if (status < 0) sout<<"File not found : "<<name<<endl;
83 if (status > 0) sout<<"Error when reading file : "<<name<<endl;
84 if (status == 0) model = igesmod;
90 Standard_Boolean IGESSelect_WorkLibrary::WriteFile
91 (IFSelect_ContextWrite& ctx) const
93 Handle(Message_Messenger) sout = Message::DefaultMessenger();
95 DeclareAndCast(IGESData_IGESModel,igesmod,ctx.Model());
96 DeclareAndCast(IGESData_Protocol,prot,ctx.Protocol());
98 if (igesmod.IsNull() || prot.IsNull()) return Standard_False;
100 fout.rdbuf()->open(ctx.FileName(),ios::out );
102 ctx.CCheck(0)->AddFail("IGES File could not be created");
103 sout<<" - IGES File could not be created : " << ctx.FileName() << endl; return 0;
105 sout<<" IGES File Name : "<<ctx.FileName();
106 IGESData_IGESWriter VW(igesmod);
107 sout<<"("<<igesmod->NbEntities()<<" ents) ";
110 Standard_Integer nbmod = ctx.NbModifiers();
111 for (Standard_Integer numod = 1; numod <= nbmod; numod ++) {
112 ctx.SetModifier (numod);
113 DeclareAndCast(IGESSelect_FileModifier,filemod,ctx.FileModifier());
114 if (!filemod.IsNull()) filemod->Perform(ctx,VW);
115 // (impressions de mise au point)
116 sout << " .. FileMod." << numod <<" "<< filemod->Label();
117 if (ctx.IsForAll()) sout << " (all model)";
118 else sout << " (" << ctx.NbEntities() << " entities)";
125 if (themodefnes) VW.WriteMode() = 10;
126 Standard_Boolean status = VW.Print(fout); sout<<" Done"<<endl;
130 status = fout.good() && status && !errno;
132 sout << strerror(errno) << endl;
137 Handle(IGESData_Protocol) IGESSelect_WorkLibrary::DefineProtocol ()
139 if (!IGESProto.IsNull()) return IGESProto;
140 Handle(IGESData_Protocol) IGESProto1 = IGESSolid::Protocol();
141 Handle(IGESData_Protocol) IGESProto2 = IGESAppli::Protocol();
142 // Handle(IGESData_FileProtocol) IGESProto = new IGESData_FileProtocol;
143 IGESProto = new IGESData_FileProtocol;
144 IGESProto->Add(IGESProto1);
145 IGESProto->Add(IGESProto2);
150 void IGESSelect_WorkLibrary::DumpEntity
151 (const Handle(Interface_InterfaceModel)& model,
152 const Handle(Interface_Protocol)& protocol,
153 const Handle(Standard_Transient)& entity,
154 const Handle(Message_Messenger)& S, const Standard_Integer level) const
156 DeclareAndCast(IGESData_IGESModel,igesmod,model);
157 DeclareAndCast(IGESData_Protocol,igespro,protocol);
158 DeclareAndCast(IGESData_IGESEntity,igesent,entity);
159 if (igesmod.IsNull() || igespro.IsNull() || igesent.IsNull()) return;
160 Standard_Integer num = igesmod->Number(igesent);
161 if (num == 0) return;
163 S<<" --- Entity "<<num;
164 Standard_Boolean iserr = model->IsRedefinedContent(num);
165 Handle(Standard_Transient) con;
166 if (iserr) con = model->ReportEntity(num)->Content();
167 if (entity.IsNull()) { S<<" Null"<<endl; return ; }
169 // On attaque le dump : d abord cas de l Erreur
171 S << " ERRONEOUS, Content, Type cdl : ";
172 if (!con.IsNull()) S << con->DynamicType()->Name();
173 else S << "(undefined)" << endl;
174 igesent = GetCasted(IGESData_IGESEntity,con);
176 Handle(Interface_Check) check = model->ReportEntity(num)->Check();
177 Interface_CheckIterator chlist;
178 chlist.Add (check,num);
179 chlist.Print (S,igesmod,Standard_False);
180 if (igesent.IsNull()) return;
182 else S << " Type cdl : " << igesent->DynamicType()->Name();
184 IGESData_IGESDumper dump(igesmod,igespro);
187 dump.Dump(igesent,S,level,(level-1)/3);
189 catch (Standard_Failure) {
190 S << " ** Dump Interrupt **" << endl;