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 under
6 // the terms of the GNU Lesser General Public License 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>
42 #include <OSD_OpenFile.hxx>
46 static Handle(IGESData_FileProtocol) IGESProto;
49 IGESSelect_WorkLibrary::IGESSelect_WorkLibrary
50 (const Standard_Boolean modefnes)
51 : themodefnes (modefnes)
58 Handle(IGESSelect_Dumper) sesdump = new IGESSelect_Dumper; // ainsi,cestfait
62 SetDumpHelp (0,"Only DNum");
63 SetDumpHelp (1,"DNum, IGES Type & Form");
64 SetDumpHelp (2,"Main Directory Informations");
65 SetDumpHelp (3,"Complete Directory Part");
66 SetDumpHelp (4,"Directory + Fields (except list contents)");
67 SetDumpHelp (5,"Complete (with list contents)");
68 SetDumpHelp (6,"Complete + Transformed data");
71 Standard_Integer IGESSelect_WorkLibrary::ReadFile
72 (const Standard_CString name,
73 Handle(Interface_InterfaceModel)& model,
74 const Handle(Interface_Protocol)& protocol) const
76 Handle(Message_Messenger) sout = Message::DefaultMessenger();
77 Handle(IGESData_IGESModel) igesmod = new IGESData_IGESModel;
78 DeclareAndCast(IGESData_Protocol,prot,protocol);
80 char* pname=(char*) name;
81 Standard_Integer status = IGESFile_Read (pname,igesmod,prot);
83 if (status < 0) sout<<"File not found : "<<name<<endl;
84 if (status > 0) sout<<"Error when reading file : "<<name<<endl;
85 if (status == 0) model = igesmod;
91 Standard_Boolean IGESSelect_WorkLibrary::WriteFile
92 (IFSelect_ContextWrite& ctx) const
94 Handle(Message_Messenger) sout = Message::DefaultMessenger();
96 DeclareAndCast(IGESData_IGESModel,igesmod,ctx.Model());
97 DeclareAndCast(IGESData_Protocol,prot,ctx.Protocol());
99 if (igesmod.IsNull() || prot.IsNull()) return Standard_False;
101 OSD_OpenStream(fout,ctx.FileName(),ios::out );
103 ctx.CCheck(0)->AddFail("IGES File could not be created");
104 sout<<" - IGES File could not be created : " << ctx.FileName() << endl; return 0;
106 sout<<" IGES File Name : "<<ctx.FileName();
107 IGESData_IGESWriter VW(igesmod);
108 sout<<"("<<igesmod->NbEntities()<<" ents) ";
111 Standard_Integer nbmod = ctx.NbModifiers();
112 for (Standard_Integer numod = 1; numod <= nbmod; numod ++) {
113 ctx.SetModifier (numod);
114 DeclareAndCast(IGESSelect_FileModifier,filemod,ctx.FileModifier());
115 if (!filemod.IsNull()) filemod->Perform(ctx,VW);
116 // (impressions de mise au point)
117 sout << " .. FileMod." << numod <<" "<< filemod->Label();
118 if (ctx.IsForAll()) sout << " (all model)";
119 else sout << " (" << ctx.NbEntities() << " entities)";
126 if (themodefnes) VW.WriteMode() = 10;
127 Standard_Boolean status = VW.Print(fout); sout<<" Done"<<endl;
131 status = fout.good() && status && !errno;
133 sout << strerror(errno) << endl;
138 Handle(IGESData_Protocol) IGESSelect_WorkLibrary::DefineProtocol ()
140 if (!IGESProto.IsNull()) return IGESProto;
141 Handle(IGESData_Protocol) IGESProto1 = IGESSolid::Protocol();
142 Handle(IGESData_Protocol) IGESProto2 = IGESAppli::Protocol();
143 // Handle(IGESData_FileProtocol) IGESProto = new IGESData_FileProtocol;
144 IGESProto = new IGESData_FileProtocol;
145 IGESProto->Add(IGESProto1);
146 IGESProto->Add(IGESProto2);
151 void IGESSelect_WorkLibrary::DumpEntity
152 (const Handle(Interface_InterfaceModel)& model,
153 const Handle(Interface_Protocol)& protocol,
154 const Handle(Standard_Transient)& entity,
155 const Handle(Message_Messenger)& S, const Standard_Integer level) const
157 DeclareAndCast(IGESData_IGESModel,igesmod,model);
158 DeclareAndCast(IGESData_Protocol,igespro,protocol);
159 DeclareAndCast(IGESData_IGESEntity,igesent,entity);
160 if (igesmod.IsNull() || igespro.IsNull() || igesent.IsNull()) return;
161 Standard_Integer num = igesmod->Number(igesent);
162 if (num == 0) return;
164 S<<" --- Entity "<<num;
165 Standard_Boolean iserr = model->IsRedefinedContent(num);
166 Handle(Standard_Transient) con;
167 if (iserr) con = model->ReportEntity(num)->Content();
168 if (entity.IsNull()) { S<<" Null"<<endl; return ; }
170 // On attaque le dump : d abord cas de l Erreur
172 S << " ERRONEOUS, Content, Type cdl : ";
173 if (!con.IsNull()) S << con->DynamicType()->Name();
174 else S << "(undefined)" << endl;
175 igesent = GetCasted(IGESData_IGESEntity,con);
177 Handle(Interface_Check) check = model->ReportEntity(num)->Check();
178 Interface_CheckIterator chlist;
179 chlist.Add (check,num);
180 chlist.Print (S,igesmod,Standard_False);
181 if (igesent.IsNull()) return;
183 else S << " Type cdl : " << igesent->DynamicType()->Name();
185 IGESData_IGESDumper dump(igesmod,igespro);
188 dump.Dump(igesent,S,level,(level-1)/3);
190 catch (Standard_Failure) {
191 S << " ** Dump Interrupt **" << endl;