0024023: Revamp the OCCT Handle -- general
[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 under
6 // the terms of the GNU Lesser General Public License 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 #include <IGESData_IGESEntity.hxx>
19
20 #include <BRepToIGES_BREntity.hxx>
21 #include <BRepToIGESBRep_Entity.hxx>
22
23 #include <Transfer_TransientMapper.hxx>
24 #include <Transfer_SimpleBinderOfTransient.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_Surface.hxx>
27 #include <GeomToIGES_GeomCurve.hxx>
28 #include <GeomToIGES_GeomSurface.hxx>
29 #include <XSAlgo.hxx>
30 #include <XSAlgo_AlgoContainer.hxx>
31 #include <Interface_Static.hxx>
32
33 IGESControl_ActorWrite::IGESControl_ActorWrite ()  {  ModeTrans() = 0;  }
34
35 Standard_Boolean  IGESControl_ActorWrite::Recognize
36   (const Handle(Transfer_Finder)& start)
37 {
38   DeclareAndCast(TransferBRep_ShapeMapper,shmap,start);
39   if (!shmap.IsNull()) return Standard_True;
40   DeclareAndCast(Transfer_TransientMapper,gemap,start);
41   if (!gemap.IsNull()) {
42     Handle(Standard_Transient) geom = gemap->Value();
43     DeclareAndCast(Geom_Curve,Curve,geom);
44     DeclareAndCast(Geom_Surface,Surf,geom);
45     if (!Curve.IsNull() || !Surf.IsNull()) return Standard_True;
46   }
47   return Standard_False;
48 }
49
50 Handle(Transfer_Binder)  IGESControl_ActorWrite::Transfer
51   (const Handle(Transfer_Finder)& start,
52    const Handle(Transfer_FinderProcess)& FP)
53 {
54   XSAlgo::AlgoContainer()->PrepareForTransfer();
55     
56   DeclareAndCast(IGESData_IGESModel,modl,FP->Model());
57   if (modl.IsNull()) return NullResult();
58   if (themodetrans < 0 || themodetrans > 1) return NullResult();
59   Handle(Standard_Transient) ent;
60
61   DeclareAndCast(TransferBRep_ShapeMapper,shmap,start);
62   if (!shmap.IsNull()) {
63     TopoDS_Shape shape = shmap->Value();
64     if (shape.IsNull()) return NullResult();
65 //  modified by NIZHNY-EAP Tue Aug 29 11:16:54 2000 ___BEGIN___
66     Handle(Standard_Transient) info;
67     Standard_Real Tol = Interface_Static::RVal("write.precision.val");
68     Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val");
69     shape = XSAlgo::AlgoContainer()->ProcessShape( shape, Tol, maxTol, 
70                                                    "write.iges.resource.name", 
71                                                    "write.iges.sequence", info,
72                                                    FP->GetProgress() );
73 //  modified by NIZHNY-EAP Tue Aug 29 11:17:01 2000 ___END___
74
75     BRepToIGES_BREntity   BR0; BR0.SetModel(modl);  BR0.SetTransferProcess(FP);
76     BRepToIGESBRep_Entity BR1; BR1.SetModel(modl);  BR1.SetTransferProcess(FP);
77
78     if (themodetrans == 0) ent = BR0.TransferShape(shape);
79     if (themodetrans == 1) ent = BR1.TransferShape(shape);
80 //  modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___
81     XSAlgo::AlgoContainer()->MergeTransferInfo(FP, info);
82 //  modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___
83     if (!ent.IsNull()) return TransientResult(ent);
84   }
85   DeclareAndCast(Transfer_TransientMapper,gemap,start);
86   if (!gemap.IsNull()) {
87     Handle(Standard_Transient) geom = gemap->Value();
88     DeclareAndCast(Geom_Curve,Curve,geom);
89     DeclareAndCast(Geom_Surface,Surf,geom);
90  
91 //  On reconnait : Curve et Surface de Geom
92 //   quid de Point; Geom2d ?
93  
94 //  GeomToIGES_GeomPoint GP;
95     GeomToIGES_GeomCurve GC;    GC.SetModel(modl);
96     GeomToIGES_GeomSurface GS;  GS.SetModel(modl);
97     if (!Curve.IsNull())
98       ent = GC.TransferCurve(Curve,Curve->FirstParameter(),Curve->LastParameter())
99 ;
100     else if (!Surf.IsNull()) {
101       Standard_Real U1,U2,V1,V2;
102       Surf->Bounds(U1,U2,V1,V2);
103       ent = GS.TransferSurface(Surf,U1,U2,V1,V2);
104     }
105     if (!ent.IsNull()) return TransientResult(ent);
106   }
107
108   return NullResult();
109 }