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 );
105 // modified by NIZHNY-EAP Tue Aug 29 11:17:01 2000 ___END___
106 Handle(IGESData_IGESEntity) ent;
107 BRepToIGES_BREntity B0; B0.SetTransferProcess(theTP); B0.SetModel(themod);
108 BRepToIGESBRep_Entity B1; B1.SetTransferProcess(theTP); B1.SetModel(themod);
109 if (thecr) ent = B1.TransferShape(Shape);
110 else ent = B0.TransferShape(Shape);
111 // modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___
112 XSAlgo::AlgoContainer()->MergeTransferInfo(theTP, info);
113 // modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___
115 //22.10.98 gka BUC60080
117 Standard_Integer oldnb = themod->NbEntities();
118 Standard_Boolean aent = AddEntity (ent);
119 Standard_Integer newnb = themod->NbEntities();
121 Standard_Real oldtol = themod->GlobalSection().Resolution(), newtol;
123 Standard_Integer tolmod = Interface_Static::IVal("write.precision.mode");
125 newtol = Interface_Static::RVal("write.precision.val");
127 ShapeAnalysis_ShapeTolerance stu;
128 Standard_Real Tolv = stu.Tolerance (Shape, tolmod, TopAbs_VERTEX);
129 Standard_Real Tole = stu.Tolerance (Shape, tolmod, TopAbs_EDGE);
131 if (tolmod == 0 ) { //Average
132 Standard_Real Tol1 = (Tolv + Tole) / 2;
133 newtol = (oldtol * oldnb + Tol1 * (newnb - oldnb)) / newnb;
135 else if (tolmod < 0) {//Least
136 newtol = Min (Tolv, Tole);
137 if (oldnb > 0) newtol = Min (oldtol, newtol);
140 newtol = Max (Tolv, Tole);
141 if (oldnb > 0) newtol = Max (oldtol, newtol);
145 IGESData_GlobalSection gs = themod->GlobalSection();
146 gs.SetResolution (newtol / gs.UnitValue());//rln 28.12.98 CCI60005
148 //#34 22.10.98 rln BUC60081
150 BRepBndLib::Add (Shape, box);
151 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
152 box.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
153 gs.MaxMaxCoords (gp_XYZ (aXmax / gs.UnitValue(),
154 aYmax / gs.UnitValue(),
155 aZmax / gs.UnitValue()));
156 gs.MaxMaxCoords (gp_XYZ (aXmin / gs.UnitValue(),
157 aYmin / gs.UnitValue(),
158 aZmin / gs.UnitValue()));
160 themod->SetGlobalSection(gs);
165 Standard_Boolean IGESControl_Writer::AddGeom (const Handle(Standard_Transient)& geom)
167 if (geom.IsNull() || !geom->IsKind (STANDARD_TYPE (Geom_Geometry)))
168 return Standard_False;
169 DeclareAndCast(Geom_Curve,Curve,geom);
170 DeclareAndCast(Geom_Surface,Surf,geom);
171 Handle(IGESData_IGESEntity) ent;
173 // On reconnait : Curve et Surface de Geom
174 // quid de Point; Geom2d ?
176 // GeomToIGES_GeomPoint GP;
177 GeomToIGES_GeomCurve GC; GC.SetModel(themod);
178 GeomToIGES_GeomSurface GS; GS.SetModel(themod);
180 //#34 22.10.98 rln BUC60081
181 IGESData_GlobalSection gs = themod->GlobalSection();
184 if (!Curve.IsNull()) {
185 ent = GC.TransferCurve(Curve,Curve->FirstParameter(),Curve->LastParameter());
186 BndLib_Add3dCurve::Add (GeomAdaptor_Curve (Curve), 0, box); }
187 else if (!Surf.IsNull()) {
188 Standard_Real U1,U2,V1,V2;
189 Surf->Bounds(U1,U2,V1,V2);
190 ent = GS.TransferSurface(Surf,U1,U2,V1,V2);
191 BndLib_AddSurface::Add (GeomAdaptor_Surface (Surf), 0, box);
194 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
195 box.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
196 gs.MaxMaxCoords (gp_XYZ (aXmax / gs.UnitValue(),
197 aYmax / gs.UnitValue(),
198 aZmax / gs.UnitValue()));
199 gs.MaxMaxCoords (gp_XYZ (aXmin / gs.UnitValue(),
200 aYmin / gs.UnitValue(),
201 aZmin / gs.UnitValue()));
202 themod->SetGlobalSection(gs);
203 return AddEntity (ent);
206 Standard_Boolean IGESControl_Writer::AddEntity (const Handle(IGESData_IGESEntity)& ent)
208 if (ent.IsNull()) return Standard_False;
209 themod->AddWithRefs(ent,IGESSelect_WorkLibrary::DefineProtocol());
210 thest = Standard_False;
211 return Standard_True;
214 void IGESControl_Writer::ComputeModel ()
217 thedit.ComputeStatus();
218 thedit.AutoCorrectModel();
219 thest = Standard_True;
222 Standard_Boolean IGESControl_Writer::Write
223 (Standard_OStream& S, const Standard_Boolean fnes)
225 if (!S) return Standard_False;
228 cout<<" IGES Write : "<<themod->NbEntities()<<" ent.s"<< flush;
230 IGESData_IGESWriter IW (themod);
231 // ne pas oublier le mode fnes ... a transmettre a IW
232 IW.SendModel (IGESSelect_WorkLibrary::DefineProtocol());
234 cout<<" ... ecriture ..."<<flush;
236 if (fnes) IW.WriteMode() = 10;
237 Standard_Boolean status = IW.Print(S);
239 cout<<" ... fichier ecrit ..."<<endl;
244 Standard_Boolean IGESControl_Writer::Write
245 (const Standard_CString file, const Standard_Boolean fnes)
247 ofstream fout(file,ios::out);
248 if (!fout) return Standard_False;
250 cout<<" Ecriture fichier ("<< (fnes ? "fnes" : "IGES") <<"): "<<file<<endl;
252 Standard_Boolean res = Write (fout,fnes);
256 res = fout.good() && res && !errno;
261 void IGESControl_Writer::PrintStatsTransfer
262 (const Standard_Integer what, const Standard_Integer mode) const
264 XSControl_TransferWriter::PrintStatsProcess (theTP,what,mode);