0024428: Implementation of LGPL license
[occt.git] / src / IGESControl / IGESControl_ActorWrite.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and / or modify it
6 // under the terms of the GNU Lesser General Public 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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <IGESControl_ActorWrite.ixx>
15 #include <TransferBRep_ShapeMapper.hxx>
16 #include <Interface_Macros.hxx>
17 #include <IGESData_IGESModel.hxx>
18
19 #include <BRepToIGES_BREntity.hxx>
20 #include <BRepToIGESBRep_Entity.hxx>
21
22 #include <Transfer_TransientMapper.hxx>
23 #include <Geom_Curve.hxx>
24 #include <Geom_Surface.hxx>
25 #include <GeomToIGES_GeomCurve.hxx>
26 #include <GeomToIGES_GeomSurface.hxx>
27 #include <XSAlgo.hxx>
28 #include <XSAlgo_AlgoContainer.hxx>
29 #include <Interface_Static.hxx>
30
31 IGESControl_ActorWrite::IGESControl_ActorWrite ()  {  ModeTrans() = 0;  }
32
33 Standard_Boolean  IGESControl_ActorWrite::Recognize
34   (const Handle(Transfer_Finder)& start)
35 {
36   DeclareAndCast(TransferBRep_ShapeMapper,shmap,start);
37   if (!shmap.IsNull()) return Standard_True;
38   DeclareAndCast(Transfer_TransientMapper,gemap,start);
39   if (!gemap.IsNull()) {
40     Handle(Standard_Transient) geom = gemap->Value();
41     DeclareAndCast(Geom_Curve,Curve,geom);
42     DeclareAndCast(Geom_Surface,Surf,geom);
43     if (!Curve.IsNull() || !Surf.IsNull()) return Standard_True;
44   }
45   return Standard_False;
46 }
47
48 Handle(Transfer_Binder)  IGESControl_ActorWrite::Transfer
49   (const Handle(Transfer_Finder)& start,
50    const Handle(Transfer_FinderProcess)& FP)
51 {
52   XSAlgo::AlgoContainer()->PrepareForTransfer();
53     
54   DeclareAndCast(IGESData_IGESModel,modl,FP->Model());
55   if (modl.IsNull()) return NullResult();
56   if (themodetrans < 0 || themodetrans > 1) return NullResult();
57   Handle(Standard_Transient) ent;
58
59   DeclareAndCast(TransferBRep_ShapeMapper,shmap,start);
60   if (!shmap.IsNull()) {
61     TopoDS_Shape shape = shmap->Value();
62     if (shape.IsNull()) return NullResult();
63 //  modified by NIZHNY-EAP Tue Aug 29 11:16:54 2000 ___BEGIN___
64     Handle(Standard_Transient) info;
65     Standard_Real Tol = Interface_Static::RVal("write.precision.val");
66     Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val");
67     shape = XSAlgo::AlgoContainer()->ProcessShape( shape, Tol, maxTol, 
68                                                    "write.iges.resource.name", 
69                                                    "write.iges.sequence", info,
70                                                    FP->GetProgress() );
71 //  modified by NIZHNY-EAP Tue Aug 29 11:17:01 2000 ___END___
72
73     BRepToIGES_BREntity   BR0; BR0.SetModel(modl);  BR0.SetTransferProcess(FP);
74     BRepToIGESBRep_Entity BR1; BR1.SetModel(modl);  BR1.SetTransferProcess(FP);
75
76     if (themodetrans == 0) ent = BR0.TransferShape(shape);
77     if (themodetrans == 1) ent = BR1.TransferShape(shape);
78 //  modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___
79     XSAlgo::AlgoContainer()->MergeTransferInfo(FP, info);
80 //  modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___
81     if (!ent.IsNull()) return TransientResult(ent);
82   }
83   DeclareAndCast(Transfer_TransientMapper,gemap,start);
84   if (!gemap.IsNull()) {
85     Handle(Standard_Transient) geom = gemap->Value();
86     DeclareAndCast(Geom_Curve,Curve,geom);
87     DeclareAndCast(Geom_Surface,Surf,geom);
88  
89 //  On reconnait : Curve et Surface de Geom
90 //   quid de Point; Geom2d ?
91  
92 //  GeomToIGES_GeomPoint GP;
93     GeomToIGES_GeomCurve GC;    GC.SetModel(modl);
94     GeomToIGES_GeomSurface GS;  GS.SetModel(modl);
95     if (!Curve.IsNull())
96       ent = GC.TransferCurve(Curve,Curve->FirstParameter(),Curve->LastParameter())
97 ;
98     else if (!Surf.IsNull()) {
99       Standard_Real U1,U2,V1,V2;
100       Surf->Bounds(U1,U2,V1,V2);
101       ent = GS.TransferSurface(Surf,U1,U2,V1,V2);
102     }
103     if (!ent.IsNull()) return TransientResult(ent);
104   }
105
106   return NullResult();
107 }