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.
15 #include <IFSelect_ContextWrite.hxx>
16 #include <IFSelect_GeneralModifier.hxx>
17 #include <Interface_Check.hxx>
18 #include <Interface_CheckIterator.hxx>
19 #include <Interface_CopyTool.hxx>
20 #include <Interface_EntityIterator.hxx>
21 #include <Interface_InterfaceModel.hxx>
22 #include <Interface_Macros.hxx>
23 #include <Interface_ParamType.hxx>
24 #include <Interface_Protocol.hxx>
25 #include <Interface_ReportEntity.hxx>
26 #include <Interface_UndefinedContent.hxx>
27 #include <Message.hxx>
28 #include <Message_Messenger.hxx>
29 #include <OSD_OpenFile.hxx>
30 #include <Standard_Transient.hxx>
31 #include <Standard_Type.hxx>
32 #include <StepData_Protocol.hxx>
33 #include <StepData_StepDumper.hxx>
34 #include <StepData_StepModel.hxx>
35 #include <StepData_StepWriter.hxx>
36 #include <StepData_UndefinedEntity.hxx>
37 #include <StepFile_Read.hxx>
38 #include <StepSelect_FileModifier.hxx>
39 #include <StepSelect_WorkLibrary.hxx>
40 #include <TCollection_HAsciiString.hxx>
41 #include <TColStd_HSequenceOfInteger.hxx>
45 StepSelect_WorkLibrary::StepSelect_WorkLibrary
46 (const Standard_Boolean copymode)
47 : thecopymode (copymode) , thelabmode (0)
50 SetDumpHelp (0,"#id + Step Type");
51 SetDumpHelp (1,"Entity as in file");
52 SetDumpHelp (2,"Entity + shareds (level 1) as in file");
54 // rq : les init sont faits par ailleurs, pas de souci a se faire
57 void StepSelect_WorkLibrary::SetDumpLabel (const Standard_Integer mode)
63 Standard_Integer StepSelect_WorkLibrary::ReadFile
64 (const Standard_CString name,
65 Handle(Interface_InterfaceModel)& model,
66 const Handle(Interface_Protocol)& protocol) const
69 DeclareAndCast(StepData_Protocol,stepro,protocol);
70 if (stepro.IsNull()) return 1;
71 Handle(StepData_StepModel) stepmodel = new StepData_StepModel;
73 StepFile_ReadTrace (0);
74 char *pName=(char *)name;
75 status = StepFile_Read (pName,stepmodel,stepro);
80 Standard_Boolean StepSelect_WorkLibrary::WriteFile
81 (IFSelect_ContextWrite& ctx) const
84 Handle(Message_Messenger) sout = Message::DefaultMessenger();
85 DeclareAndCast(StepData_StepModel,stepmodel,ctx.Model());
86 DeclareAndCast(StepData_Protocol,stepro,ctx.Protocol());
87 if (stepmodel.IsNull() || stepro.IsNull()) return Standard_False;
90 OSD_OpenStream(fout,ctx.FileName(),ios::out|ios::trunc);
92 if (!fout || !fout.rdbuf()->is_open()) {
93 ctx.CCheck(0)->AddFail("Step File could not be created");
94 sout<<" Step File could not be created : " << ctx.FileName() << endl; return 0;
96 sout << " Step File Name : "<<ctx.FileName();
97 StepData_StepWriter SW(stepmodel);
98 sout<<"("<<stepmodel->NbEntities()<<" ents) ";
101 Standard_Integer nbmod = ctx.NbModifiers();
102 for (Standard_Integer numod = 1; numod <= nbmod; numod ++) {
103 ctx.SetModifier (numod);
104 DeclareAndCast(StepSelect_FileModifier,filemod,ctx.FileModifier());
105 if (!filemod.IsNull()) filemod->Perform(ctx,SW);
106 // (impressions de mise au point)
107 sout << " .. FileMod." << numod << filemod->Label();
108 if (ctx.IsForAll()) sout << " (all model)";
109 else sout << " (" << ctx.NbEntities() << " entities)";
114 SW.SendModel(stepro);
115 Interface_CheckIterator chl = SW.CheckList();
116 for (chl.Start(); chl.More(); chl.Next())
117 ctx.CCheck(chl.Number())->GetMessages(chl.Value());
119 Standard_Boolean isGood = SW.Print(fout);
124 isGood = fout.good() && isGood && !errno;
126 sout << strerror(errno) << endl;
131 Standard_Boolean StepSelect_WorkLibrary::CopyModel
132 (const Handle(Interface_InterfaceModel)& original,
133 const Handle(Interface_InterfaceModel)& newmodel,
134 const Interface_EntityIterator& list,
135 Interface_CopyTool& TC) const
137 if (thecopymode) return
138 IFSelect_WorkLibrary::CopyModel (original,newmodel,list,TC);
143 void StepSelect_WorkLibrary::DumpEntity
144 (const Handle(Interface_InterfaceModel)& model,
145 const Handle(Interface_Protocol)& protocol,
146 const Handle(Standard_Transient)& entity,
147 const Handle(Message_Messenger)& S, const Standard_Integer level) const
149 Standard_Integer nument = model->Number(entity);
150 if (nument <= 0 || nument > model->NbEntities()) return;
151 Standard_Boolean iserr = model->IsRedefinedContent(nument);
152 Handle(Standard_Transient) ent, con; ent = entity;
153 S<<" --- (STEP) Entity "; model->Print(entity,S);
154 if (iserr) con = model->ReportEntity(nument)->Content();
155 if (entity.IsNull()) { S<<" Null"<<endl; return; }
157 // On attaque le dump : d abord cas de l Erreur
158 S << " Type cdl : " << entity->DynamicType()->Name() << endl;
160 S<<" *** NOT WELL LOADED : CONTENT FROM FILE ***"<<endl;
161 else if (model->IsUnknownEntity(nument))
162 S<<" *** UNKNOWN TYPE ***"<<endl;
164 StepData_StepDumper dump(GetCasted(StepData_StepModel,model),
165 GetCasted(StepData_Protocol,protocol),thelabmode);
166 dump.Dump(S,ent,level);