1 //cky 16.01.99 Remove couts.
2 //rln 28.12.98 CCI60005
4 #include <Standard_Stream.hxx>
6 #include <IGESControl_Writer.ixx>
7 #include <IGESControl_Controller.hxx>
8 #include <IGESSelect_WorkLibrary.hxx>
9 #include <BRepToIGES_BREntity.hxx>
10 #include <BRepToIGESBRep_Entity.hxx>
11 #include <Geom_Curve.hxx>
12 #include <Geom_Surface.hxx>
13 #include <GeomToIGES_GeomCurve.hxx>
14 #include <GeomToIGES_GeomSurface.hxx>
15 #include <IGESData_IGESWriter.hxx>
16 #include <XSControl_TransferWriter.hxx>
18 #include <Interface_Macros.hxx>
19 #include <Interface_Static.hxx>
20 #include <ShapeAnalysis_ShapeTolerance.hxx>
23 #include <Bnd_Box.hxx>
24 #include <BRepBndLib.hxx>
25 #include <GeomAdaptor_Curve.hxx>
26 #include <GeomAdaptor_Surface.hxx>
27 #include <BndLib_Add3dCurve.hxx>
28 #include <BndLib_AddSurface.hxx>
30 #include <XSAlgo_AlgoContainer.hxx>
31 #include <TopExp_Explorer.hxx>
32 #include <Message_ProgressIndicator.hxx>
35 IGESControl_Writer::IGESControl_Writer ()
36 : theTP (new Transfer_FinderProcess(10000)) ,
37 thedit (IGESSelect_WorkLibrary::DefineProtocol()) ,
38 thecr (0) , thest (Standard_False)
40 // faudrait aussi (?) prendre les parametres par defaut ... ?
41 IGESControl_Controller::Init();
42 thedit.SetUnitName(Interface_Static::CVal ("write.iges.unit"));
44 themod = thedit.Model();
47 IGESControl_Writer::IGESControl_Writer
48 (const Standard_CString unit, const Standard_Integer modecr)
49 : theTP (new Transfer_FinderProcess(10000)) ,
50 thedit (IGESSelect_WorkLibrary::DefineProtocol()) ,
51 thecr (modecr) , thest (Standard_False)
53 // faudrait aussi (?) prendre les parametres par defaut ... ?
54 IGESControl_Controller::Init();
55 thedit.SetUnitName(unit);
57 themod = thedit.Model();
60 IGESControl_Writer::IGESControl_Writer
61 (const Handle(IGESData_IGESModel)& model, const Standard_Integer modecr)
62 : theTP (new Transfer_FinderProcess(10000)) ,
64 thedit (model,IGESSelect_WorkLibrary::DefineProtocol()) ,
65 thecr (modecr) , thest (Standard_False) { }
67 Handle(IGESData_IGESModel) IGESControl_Writer::Model () const
72 Handle(Transfer_FinderProcess) IGESControl_Writer::TransferProcess () const
77 void IGESControl_Writer::SetTransferProcess
78 (const Handle(Transfer_FinderProcess)& TP)
83 Standard_Boolean IGESControl_Writer::AddShape (const TopoDS_Shape& theShape)
85 if (theShape.IsNull()) return Standard_False;
87 // for progress indication
88 Handle(Message_ProgressIndicator) progress = theTP->GetProgress();
89 if ( ! progress.IsNull() ) {
90 Standard_Integer nbfaces=0;
91 for( TopExp_Explorer exp(theShape,TopAbs_FACE); exp.More(); exp.Next() )
93 progress->SetScale ( "Faces", 0, nbfaces, 1 );
96 XSAlgo::AlgoContainer()->PrepareForTransfer();
98 // modified by NIZHNY-EAP Tue Aug 29 11:16:54 2000 ___BEGIN___
99 Handle(Standard_Transient) info;
100 Standard_Real Tol = Interface_Static::RVal("write.precision.val");
101 Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val");
102 TopoDS_Shape Shape = XSAlgo::AlgoContainer()->ProcessShape( theShape, Tol, maxTol,
103 "write.iges.resource.name",
104 "write.iges.sequence", info,
106 // modified by NIZHNY-EAP Tue Aug 29 11:17:01 2000 ___END___
107 Handle(IGESData_IGESEntity) ent;
108 BRepToIGES_BREntity B0; B0.SetTransferProcess(theTP); B0.SetModel(themod);
109 BRepToIGESBRep_Entity B1; B1.SetTransferProcess(theTP); B1.SetModel(themod);
110 if (thecr) ent = B1.TransferShape(Shape);
111 else ent = B0.TransferShape(Shape);
112 // modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___
113 XSAlgo::AlgoContainer()->MergeTransferInfo(theTP, info);
114 // modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___
116 //22.10.98 gka BUC60080
118 Standard_Integer oldnb = themod->NbEntities();
119 Standard_Boolean aent = AddEntity (ent);
120 Standard_Integer newnb = themod->NbEntities();
122 Standard_Real oldtol = themod->GlobalSection().Resolution(), newtol;
124 Standard_Integer tolmod = Interface_Static::IVal("write.precision.mode");
126 newtol = Interface_Static::RVal("write.precision.val");
128 ShapeAnalysis_ShapeTolerance stu;
129 Standard_Real Tolv = stu.Tolerance (Shape, tolmod, TopAbs_VERTEX);
130 Standard_Real Tole = stu.Tolerance (Shape, tolmod, TopAbs_EDGE);
132 if (tolmod == 0 ) { //Average
133 Standard_Real Tol1 = (Tolv + Tole) / 2;
134 newtol = (oldtol * oldnb + Tol1 * (newnb - oldnb)) / newnb;
136 else if (tolmod < 0) {//Least
137 newtol = Min (Tolv, Tole);
138 if (oldnb > 0) newtol = Min (oldtol, newtol);
141 newtol = Max (Tolv, Tole);
142 if (oldnb > 0) newtol = Max (oldtol, newtol);
146 IGESData_GlobalSection gs = themod->GlobalSection();
147 gs.SetResolution (newtol / gs.UnitValue());//rln 28.12.98 CCI60005
149 //#34 22.10.98 rln BUC60081
151 BRepBndLib::Add (Shape, box);
152 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
153 box.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
154 gs.MaxMaxCoords (gp_XYZ (aXmax / gs.UnitValue(),
155 aYmax / gs.UnitValue(),
156 aZmax / gs.UnitValue()));
157 gs.MaxMaxCoords (gp_XYZ (aXmin / gs.UnitValue(),
158 aYmin / gs.UnitValue(),
159 aZmin / gs.UnitValue()));
161 themod->SetGlobalSection(gs);
166 Standard_Boolean IGESControl_Writer::AddGeom (const Handle(Standard_Transient)& geom)
168 if (geom.IsNull() || !geom->IsKind (STANDARD_TYPE (Geom_Geometry)))
169 return Standard_False;
170 DeclareAndCast(Geom_Curve,Curve,geom);
171 DeclareAndCast(Geom_Surface,Surf,geom);
172 Handle(IGESData_IGESEntity) ent;
174 // On reconnait : Curve et Surface de Geom
175 // quid de Point; Geom2d ?
177 // GeomToIGES_GeomPoint GP;
178 GeomToIGES_GeomCurve GC; GC.SetModel(themod);
179 GeomToIGES_GeomSurface GS; GS.SetModel(themod);
181 //#34 22.10.98 rln BUC60081
182 IGESData_GlobalSection gs = themod->GlobalSection();
185 if (!Curve.IsNull()) {
186 ent = GC.TransferCurve(Curve,Curve->FirstParameter(),Curve->LastParameter());
187 BndLib_Add3dCurve::Add (GeomAdaptor_Curve (Curve), 0, box); }
188 else if (!Surf.IsNull()) {
189 Standard_Real U1,U2,V1,V2;
190 Surf->Bounds(U1,U2,V1,V2);
191 ent = GS.TransferSurface(Surf,U1,U2,V1,V2);
192 BndLib_AddSurface::Add (GeomAdaptor_Surface (Surf), 0, box);
195 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
196 box.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
197 gs.MaxMaxCoords (gp_XYZ (aXmax / gs.UnitValue(),
198 aYmax / gs.UnitValue(),
199 aZmax / gs.UnitValue()));
200 gs.MaxMaxCoords (gp_XYZ (aXmin / gs.UnitValue(),
201 aYmin / gs.UnitValue(),
202 aZmin / gs.UnitValue()));
203 themod->SetGlobalSection(gs);
204 return AddEntity (ent);
207 Standard_Boolean IGESControl_Writer::AddEntity (const Handle(IGESData_IGESEntity)& ent)
209 if (ent.IsNull()) return Standard_False;
210 themod->AddWithRefs(ent,IGESSelect_WorkLibrary::DefineProtocol());
211 thest = Standard_False;
212 return Standard_True;
215 void IGESControl_Writer::ComputeModel ()
218 thedit.ComputeStatus();
219 thedit.AutoCorrectModel();
220 thest = Standard_True;
223 Standard_Boolean IGESControl_Writer::Write
224 (Standard_OStream& S, const Standard_Boolean fnes)
226 if (!S) return Standard_False;
229 cout<<" IGES Write : "<<themod->NbEntities()<<" ent.s"<< flush;
231 IGESData_IGESWriter IW (themod);
232 // ne pas oublier le mode fnes ... a transmettre a IW
233 IW.SendModel (IGESSelect_WorkLibrary::DefineProtocol());
235 cout<<" ... ecriture ..."<<flush;
237 if (fnes) IW.WriteMode() = 10;
238 Standard_Boolean status = IW.Print(S);
240 cout<<" ... fichier ecrit ..."<<endl;
245 Standard_Boolean IGESControl_Writer::Write
246 (const Standard_CString file, const Standard_Boolean fnes)
248 ofstream fout(file,ios::out);
249 if (!fout) return Standard_False;
251 cout<<" Ecriture fichier ("<< (fnes ? "fnes" : "IGES") <<"): "<<file<<endl;
253 Standard_Boolean res = Write (fout,fnes);
257 res = fout.good() && res && !errno;
262 void IGESControl_Writer::PrintStatsTransfer
263 (const Standard_Integer what, const Standard_Integer mode) const
265 XSControl_TransferWriter::PrintStatsProcess (theTP,what,mode);