summaryrefslogtreecommitdiff
path: root/src/IGESToBRep/IGESToBRep_Actor.cxx
blob: 7d9a767200e820e49d43cb10b551639c9bbb55ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <Standard_ErrorHandler.hxx>
#include <IGESToBRep_Actor.ixx>
#include <Standard_Failure.hxx>

#include <IGESToBRep.hxx>
#include <IGESData_IGESEntity.hxx>
#include <IGESData_IGESModel.hxx>
#include <IGESData_GlobalSection.hxx>

#include <IGESToBRep_CurveAndSurface.hxx>

#include <Interface_Macros.hxx>
#include <Interface_Static.hxx>

#include <TopoDS_Shape.hxx>

#include <TransferBRep.hxx>
#include <TransferBRep_ShapeBinder.hxx>

#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <ShapeFix_ShapeTolerance.hxx>
#include <BRepLib.hxx>
#include <ShapeExtend_Explorer.hxx>

//=======================================================================
//function : IGESToBRep_Actor
//purpose  : 
//=======================================================================
IGESToBRep_Actor::IGESToBRep_Actor ()
{  thecontinuity = 0;  theeps = 0.0001;  }


//=======================================================================
//function : SetModel
//purpose  : 
//=======================================================================
void IGESToBRep_Actor::SetModel (const Handle(Interface_InterfaceModel)& model)
{
  themodel = model;
  theeps = Handle(IGESData_IGESModel)::DownCast(themodel)->GlobalSection().Resolution();
}


//=======================================================================
//function : SetContinuity
//purpose  : 
//=======================================================================
void  IGESToBRep_Actor::SetContinuity (const Standard_Integer continuity)
{
  thecontinuity = continuity;
}


//=======================================================================
//function : GetContinuity
//purpose  : 
//=======================================================================
Standard_Integer  IGESToBRep_Actor::GetContinuity () const
{
  return thecontinuity;
}

//=======================================================================
//function : Recognize
//purpose  : 
//=======================================================================
Standard_Boolean  IGESToBRep_Actor::Recognize
(const Handle(Standard_Transient)& start)
{
  DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
  DeclareAndCast(IGESData_IGESEntity,ent,start);
  if (ent.IsNull()) return Standard_False;

//   Cas reconnus
  Standard_Integer typnum = ent->TypeNumber();
  Standard_Integer fornum = ent->FormNumber();
  if (IGESToBRep::IsCurveAndSurface(ent) ||
      ((typnum == 402 && (fornum == 1 || fornum == 7 || 
                          fornum == 14 || fornum == 15))  ||
      (typnum == 408 ) || (typnum == 308)))
    return Standard_True;

//  Cas restants : non reconnus
  return Standard_False;
}
//=======================================================================
//function : EncodeRegul
//purpose  : INTERNAL to encode regularity on edges
//=======================================================================

static Standard_Boolean  EncodeRegul (const TopoDS_Shape& sh)
{
  Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle");
  if (sh.IsNull()) return Standard_True;
  if (tolang <= 0) return Standard_True;
  try {
    OCC_CATCH_SIGNALS
    BRepLib::EncodeRegularity (sh,tolang);
  }
  catch(Standard_Failure) {
    return Standard_False;
  }
  return Standard_True;
}
//=======================================================================
//function : TrimTolerances
//purpose  : Trims tolerances of the shape according to static parameters
//          
//=======================================================================

static void TrimTolerances (const TopoDS_Shape& shape,
			    const Standard_Real tol)
{
  if( Interface_Static::IVal("read.maxprecision.mode")==1) {
    ShapeFix_ShapeTolerance SFST;
    SFST.LimitTolerance (shape, 0, Max(tol,Interface_Static::RVal ("read.maxprecision.val")));
  }
}



//=======================================================================
//function : Transfer
//purpose  : 
//=======================================================================
Handle(Transfer_Binder) IGESToBRep_Actor::Transfer
(const Handle(Standard_Transient)& start, const Handle(Transfer_TransientProcess)& TP)
{
  DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
  DeclareAndCast(IGESData_IGESEntity,ent,start);
  if (mymodel.IsNull() || ent.IsNull()) return NullResult();
  Standard_Integer anum = mymodel->Number(start);
  
  if(!Interface_Static::IVal("read.iges.faulty.entities") && mymodel->IsErrorEntity(anum)) 
    return NullResult();
  TopoDS_Shape shape;

//   appeler le transfert seulement si type OK
  Standard_Integer typnum = ent->TypeNumber();
  Standard_Integer fornum = ent->FormNumber();
  Standard_Real eps;
  if (IGESToBRep::IsCurveAndSurface(ent) ||
      (typnum == 402 && (fornum == 1 || fornum == 7|| 
                         fornum == 14 || fornum == 15)) || 
      (typnum == 408) || (typnum == 308)) {
    XSAlgo::AlgoContainer()->PrepareForTransfer();
    IGESToBRep_CurveAndSurface CAS;
    CAS.SetModel(mymodel);
    CAS.SetContinuity(thecontinuity);
    CAS.SetTransferProcess(TP);
    Standard_Integer Ival = Interface_Static::IVal("read.precision.mode");
    if ( Ival == 0)
      eps = mymodel->GlobalSection().Resolution();
    else
      eps = Interface_Static::RVal("read.precision.val"); //:10 ABV 11 Nov 97
//:10      eps = BRepAPI::Precision(); 
    Ival = Interface_Static::IVal("read.iges.bspline.approxd1.mode");
    CAS.SetModeApprox ( (Ival > 0) );
    Ival = Interface_Static::IVal("read.surfacecurve.mode");
    CAS.SetSurfaceCurve (Ival);

    if (eps > 1.E-08) {
      CAS.SetEpsGeom(eps);
      theeps = eps*CAS.GetUnitFactor();
//      Interface_Static::SetRVal("lastpreci",theeps);
    }
    Standard_Integer nbTPitems = TP->NbMapped();
    {
      try {
        OCC_CATCH_SIGNALS
	shape = CAS.TransferGeometry(ent);
      }
      catch(Standard_Failure) {
	shape.Nullify();
      }
    }
    
    // fixing shape
//    shape =  XSAlgo::AlgoContainer()->PerformFixShape( shape, TP, theeps, CAS.GetMaxTol() );
    Handle(Standard_Transient) info;
    shape = XSAlgo::AlgoContainer()->ProcessShape( shape, theeps, CAS.GetMaxTol(), 
                                                   "read.iges.resource.name", 
                                                   "read.iges.sequence", info );
    XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
  }
// if (!shape.IsNull()) TransferBRep::SameParameter (shape,Standard_False,eps);
  ShapeExtend_Explorer SBE;
  if (SBE.ShapeType(shape,Standard_True) != TopAbs_SHAPE) {
    if (!shape.IsNull()) {
      EncodeRegul (shape);
      //#74 rln 03.03.99 S4135
      TrimTolerances (shape, UsedTolerance());
   //   Shapes().Append(shape);
    }
  }
  Handle(TransferBRep_ShapeBinder) binder;
  if (!shape.IsNull()) binder = new TransferBRep_ShapeBinder(shape);
  return binder;
}


    Standard_Real  IGESToBRep_Actor::UsedTolerance () const
      {  return theeps;  }