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);
113 // modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___
114 XSAlgo::AlgoContainer()->MergeTransferInfo(theTP, info);
115 // modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___
117 //22.10.98 gka BUC60080
119 Standard_Integer oldnb = themod->NbEntities();
120 Standard_Boolean aent = AddEntity (ent);
121 Standard_Integer newnb = themod->NbEntities();
123 Standard_Real oldtol = themod->GlobalSection().Resolution(), newtol;
125 Standard_Integer tolmod = Interface_Static::IVal("write.precision.mode");
127 newtol = Interface_Static::RVal("write.precision.val");
129 ShapeAnalysis_ShapeTolerance stu;
130 Standard_Real Tolv = stu.Tolerance (Shape, tolmod, TopAbs_VERTEX);
131 Standard_Real Tole = stu.Tolerance (Shape, tolmod, TopAbs_EDGE);
133 if (tolmod == 0 ) { //Average
134 Standard_Real Tol1 = (Tolv + Tole) / 2;
135 newtol = (oldtol * oldnb + Tol1 * (newnb - oldnb)) / newnb;
137 else if (tolmod < 0) {//Least
138 newtol = Min (Tolv, Tole);
139 if (oldnb > 0) newtol = Min (oldtol, newtol);
142 newtol = Max (Tolv, Tole);
143 if (oldnb > 0) newtol = Max (oldtol, newtol);
147 IGESData_GlobalSection gs = themod->GlobalSection();
148 gs.SetResolution (newtol / gs.UnitValue());//rln 28.12.98 CCI60005
150 //#34 22.10.98 rln BUC60081
152 BRepBndLib::Add (Shape, box);
153 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
154 box.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
155 gs.MaxMaxCoords (gp_XYZ (aXmax / gs.UnitValue(),
156 aYmax / gs.UnitValue(),
157 aZmax / gs.UnitValue()));
158 gs.MaxMaxCoords (gp_XYZ (aXmin / gs.UnitValue(),
159 aYmin / gs.UnitValue(),
160 aZmin / gs.UnitValue()));
162 themod->SetGlobalSection(gs);
167 Standard_Boolean IGESControl_Writer::AddGeom (const Handle(Standard_Transient)& geom)
169 if (geom.IsNull() || !geom->IsKind (STANDARD_TYPE (Geom_Geometry)))
170 return Standard_False;
171 DeclareAndCast(Geom_Curve,Curve,geom);
172 DeclareAndCast(Geom_Surface,Surf,geom);
173 Handle(IGESData_IGESEntity) ent;
175 // On reconnait : Curve et Surface de Geom
176 // quid de Point; Geom2d ?
178 // GeomToIGES_GeomPoint GP;
179 GeomToIGES_GeomCurve GC; GC.SetModel(themod);
180 GeomToIGES_GeomSurface GS; GS.SetModel(themod);
182 //#34 22.10.98 rln BUC60081
183 IGESData_GlobalSection gs = themod->GlobalSection();
186 if (!Curve.IsNull()) {
187 ent = GC.TransferCurve(Curve,Curve->FirstParameter(),Curve->LastParameter());
188 BndLib_Add3dCurve::Add (GeomAdaptor_Curve (Curve), 0, box); }
189 else if (!Surf.IsNull()) {
190 Standard_Real U1,U2,V1,V2;
191 Surf->Bounds(U1,U2,V1,V2);
192 ent = GS.TransferSurface(Surf,U1,U2,V1,V2);
193 BndLib_AddSurface::Add (GeomAdaptor_Surface (Surf), 0, box);
196 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
197 box.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
198 gs.MaxMaxCoords (gp_XYZ (aXmax / gs.UnitValue(),
199 aYmax / gs.UnitValue(),
200 aZmax / gs.UnitValue()));
201 gs.MaxMaxCoords (gp_XYZ (aXmin / gs.UnitValue(),
202 aYmin / gs.UnitValue(),
203 aZmin / gs.UnitValue()));
204 themod->SetGlobalSection(gs);
205 return AddEntity (ent);
208 Standard_Boolean IGESControl_Writer::AddEntity (const Handle(IGESData_IGESEntity)& ent)
210 if (ent.IsNull()) return Standard_False;
211 themod->AddWithRefs(ent,IGESSelect_WorkLibrary::DefineProtocol());
212 thest = Standard_False;
213 return Standard_True;
216 void IGESControl_Writer::ComputeModel ()
219 thedit.ComputeStatus();
220 thedit.AutoCorrectModel();
221 thest = Standard_True;
224 Standard_Boolean IGESControl_Writer::Write
225 (Standard_OStream& S, const Standard_Boolean fnes)
227 if (!S) return Standard_False;
230 cout<<" IGES Write : "<<themod->NbEntities()<<" ent.s"<< flush;
232 IGESData_IGESWriter IW (themod);
233 // ne pas oublier le mode fnes ... a transmettre a IW
234 IW.SendModel (IGESSelect_WorkLibrary::DefineProtocol());
236 cout<<" ... ecriture ..."<<flush;
238 if (fnes) IW.WriteMode() = 10;
239 Standard_Boolean status = IW.Print(S);
241 cout<<" ... fichier ecrit ..."<<endl;
246 Standard_Boolean IGESControl_Writer::Write
247 (const Standard_CString file, const Standard_Boolean fnes)
249 ofstream fout(file,ios::out);
250 if (!fout) return Standard_False;
252 cout<<" Ecriture fichier ("<< (fnes ? "fnes" : "IGES") <<"): "<<file<<endl;
254 Standard_Boolean res = Write (fout,fnes);
258 res = fout.good() && res && !errno;
263 void IGESControl_Writer::PrintStatsTransfer
264 (const Standard_Integer what, const Standard_Integer mode) const
266 XSControl_TransferWriter::PrintStatsProcess (theTP,what,mode);