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 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 thecr = Interface_Static::IVal ("write.iges.brep.mode");
45 themod = thedit.Model();
48 IGESControl_Writer::IGESControl_Writer
49 (const Standard_CString unit, const Standard_Integer modecr)
50 : theTP (new Transfer_FinderProcess(10000)) ,
51 thedit (IGESSelect_WorkLibrary::DefineProtocol()) ,
52 thecr (modecr) , thest (Standard_False)
54 // faudrait aussi (?) prendre les parametres par defaut ... ?
55 IGESControl_Controller::Init();
56 thedit.SetUnitName(unit);
58 themod = thedit.Model();
61 IGESControl_Writer::IGESControl_Writer
62 (const Handle(IGESData_IGESModel)& model, const Standard_Integer modecr)
63 : theTP (new Transfer_FinderProcess(10000)) ,
65 thedit (model,IGESSelect_WorkLibrary::DefineProtocol()) ,
66 thecr (modecr) , thest (Standard_False) { }
68 Handle(IGESData_IGESModel) IGESControl_Writer::Model () const
73 Handle(Transfer_FinderProcess) IGESControl_Writer::TransferProcess () const
78 void IGESControl_Writer::SetTransferProcess
79 (const Handle(Transfer_FinderProcess)& TP)
84 Standard_Boolean IGESControl_Writer::AddShape (const TopoDS_Shape& theShape)
86 if (theShape.IsNull()) return Standard_False;
88 // for progress indication
89 Handle(Message_ProgressIndicator) progress = theTP->GetProgress();
90 if ( ! progress.IsNull() ) {
91 Standard_Integer nbfaces=0;
92 for( TopExp_Explorer exp(theShape,TopAbs_FACE); exp.More(); exp.Next() )
94 progress->SetScale ( "Faces", 0, nbfaces, 1 );
97 XSAlgo::AlgoContainer()->PrepareForTransfer();
99 // modified by NIZHNY-EAP Tue Aug 29 11:16:54 2000 ___BEGIN___
100 Handle(Standard_Transient) info;
101 Standard_Real Tol = Interface_Static::RVal("write.precision.val");
102 Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val");
103 TopoDS_Shape Shape = XSAlgo::AlgoContainer()->ProcessShape( theShape, Tol, maxTol,
104 "write.iges.resource.name",
105 "write.iges.sequence", info,
107 // modified by NIZHNY-EAP Tue Aug 29 11:17:01 2000 ___END___
108 Handle(IGESData_IGESEntity) ent;
109 BRepToIGES_BREntity B0; B0.SetTransferProcess(theTP); B0.SetModel(themod);
110 BRepToIGESBRep_Entity B1; B1.SetTransferProcess(theTP); B1.SetModel(themod);
111 if (thecr) ent = B1.TransferShape(Shape);
112 else ent = B0.TransferShape(Shape);
115 return Standard_False;
116 // modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___
117 XSAlgo::AlgoContainer()->MergeTransferInfo(theTP, info);
118 // modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___
120 //22.10.98 gka BUC60080
122 Standard_Integer oldnb = themod->NbEntities();
123 Standard_Boolean aent = AddEntity (ent);
124 Standard_Integer newnb = themod->NbEntities();
126 Standard_Real oldtol = themod->GlobalSection().Resolution(), newtol;
128 Standard_Integer tolmod = Interface_Static::IVal("write.precision.mode");
130 newtol = Interface_Static::RVal("write.precision.val");
132 ShapeAnalysis_ShapeTolerance stu;
133 Standard_Real Tolv = stu.Tolerance (Shape, tolmod, TopAbs_VERTEX);
134 Standard_Real Tole = stu.Tolerance (Shape, tolmod, TopAbs_EDGE);
136 if (tolmod == 0 ) { //Average
137 Standard_Real Tol1 = (Tolv + Tole) / 2;
138 newtol = (oldtol * oldnb + Tol1 * (newnb - oldnb)) / newnb;
140 else if (tolmod < 0) {//Least
141 newtol = Min (Tolv, Tole);
142 if (oldnb > 0) newtol = Min (oldtol, newtol);
145 newtol = Max (Tolv, Tole);
146 if (oldnb > 0) newtol = Max (oldtol, newtol);
150 IGESData_GlobalSection gs = themod->GlobalSection();
151 gs.SetResolution (newtol / gs.UnitValue());//rln 28.12.98 CCI60005
153 //#34 22.10.98 rln BUC60081
155 BRepBndLib::Add (Shape, box);
156 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
157 box.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
158 gs.MaxMaxCoords (gp_XYZ (aXmax / gs.UnitValue(),
159 aYmax / gs.UnitValue(),
160 aZmax / gs.UnitValue()));
161 gs.MaxMaxCoords (gp_XYZ (aXmin / gs.UnitValue(),
162 aYmin / gs.UnitValue(),
163 aZmin / gs.UnitValue()));
165 themod->SetGlobalSection(gs);
170 Standard_Boolean IGESControl_Writer::AddGeom (const Handle(Standard_Transient)& geom)
172 if (geom.IsNull() || !geom->IsKind (STANDARD_TYPE (Geom_Geometry)))
173 return Standard_False;
174 DeclareAndCast(Geom_Curve,Curve,geom);
175 DeclareAndCast(Geom_Surface,Surf,geom);
176 Handle(IGESData_IGESEntity) ent;
178 // On reconnait : Curve et Surface de Geom
179 // quid de Point; Geom2d ?
181 // GeomToIGES_GeomPoint GP;
182 GeomToIGES_GeomCurve GC; GC.SetModel(themod);
183 GeomToIGES_GeomSurface GS; GS.SetModel(themod);
185 //#34 22.10.98 rln BUC60081
186 IGESData_GlobalSection gs = themod->GlobalSection();
189 if (!Curve.IsNull()) {
190 ent = GC.TransferCurve(Curve,Curve->FirstParameter(),Curve->LastParameter());
191 BndLib_Add3dCurve::Add (GeomAdaptor_Curve (Curve), 0, box); }
192 else if (!Surf.IsNull()) {
193 Standard_Real U1,U2,V1,V2;
194 Surf->Bounds(U1,U2,V1,V2);
195 ent = GS.TransferSurface(Surf,U1,U2,V1,V2);
196 BndLib_AddSurface::Add (GeomAdaptor_Surface (Surf), 0, box);
199 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
200 box.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
201 gs.MaxMaxCoords (gp_XYZ (aXmax / gs.UnitValue(),
202 aYmax / gs.UnitValue(),
203 aZmax / gs.UnitValue()));
204 gs.MaxMaxCoords (gp_XYZ (aXmin / gs.UnitValue(),
205 aYmin / gs.UnitValue(),
206 aZmin / gs.UnitValue()));
207 themod->SetGlobalSection(gs);
208 return AddEntity (ent);
211 Standard_Boolean IGESControl_Writer::AddEntity (const Handle(IGESData_IGESEntity)& ent)
213 if (ent.IsNull()) return Standard_False;
214 themod->AddWithRefs(ent,IGESSelect_WorkLibrary::DefineProtocol());
215 thest = Standard_False;
216 return Standard_True;
219 void IGESControl_Writer::ComputeModel ()
222 thedit.ComputeStatus();
223 thedit.AutoCorrectModel();
224 thest = Standard_True;
227 Standard_Boolean IGESControl_Writer::Write
228 (Standard_OStream& S, const Standard_Boolean fnes)
230 if (!S) return Standard_False;
232 Standard_Integer nbEnt = themod->NbEntities();
234 cout<<" IGES Write : "<<nbEnt<<" ent.s"<< flush;
237 return Standard_False;
238 IGESData_IGESWriter IW (themod);
239 // ne pas oublier le mode fnes ... a transmettre a IW
240 IW.SendModel (IGESSelect_WorkLibrary::DefineProtocol());
242 cout<<" ... ecriture ..."<<flush;
244 if (fnes) IW.WriteMode() = 10;
245 Standard_Boolean status = IW.Print(S);
247 cout<<" ... fichier ecrit ..."<<endl;
252 Standard_Boolean IGESControl_Writer::Write
253 (const Standard_CString file, const Standard_Boolean fnes)
255 ofstream fout(file,ios::out);
256 if (!fout) return Standard_False;
258 cout<<" Ecriture fichier ("<< (fnes ? "fnes" : "IGES") <<"): "<<file<<endl;
260 Standard_Boolean res = Write (fout,fnes);
264 res = fout.good() && res && !errno;
269 void IGESControl_Writer::PrintStatsTransfer
270 (const Standard_Integer what, const Standard_Integer mode) const
272 XSControl_TransferWriter::PrintStatsProcess (theTP,what,mode);