summaryrefslogtreecommitdiff
path: root/src/IGESSelect/IGESSelect_RemoveCurves.cxx
blob: 998f4b15761ffb8ba9634dca43cfe3e753297bb2 (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
#include <IGESSelect_RemoveCurves.ixx>
#include <Interface_Macros.hxx>
#include <IGESGeom_TrimmedSurface.hxx>
#include <IGESGeom_BoundedSurface.hxx>
#include <IGESGeom_CurveOnSurface.hxx>
#include <IGESGeom_Boundary.hxx>
#include <IGESData_IGESEntity.hxx>
#include <IGESData_HArray1OfIGESEntity.hxx>
#include <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx>
#include <TColStd_HArray1OfInteger.hxx>



IGESSelect_RemoveCurves::IGESSelect_RemoveCurves (const Standard_Boolean UV)
    : IGESSelect_ModelModifier (Standard_True)  ,  theUV (UV)    {  }

static Standard_Boolean  Edit
  (const Handle(Standard_Transient)& ent, const Standard_Boolean UV)
{
  Standard_Boolean res = Standard_False;
  DeclareAndCast(IGESGeom_TrimmedSurface,trsu,ent);
  if (!trsu.IsNull()) {
    res = Edit (trsu->OuterContour(),UV);
    Standard_Integer i,nb = trsu->NbInnerContours();
    for (i = 1; i <= nb; i ++) {
      res = res | Edit (trsu->InnerContour(i),UV);
    }
    return res;
  }

  DeclareAndCast(IGESGeom_BoundedSurface,bnsu,ent);
  if (!bnsu.IsNull()) {
    Standard_Integer i,nb = bnsu->NbBoundaries();
    for (i = 1; i <= nb; i ++) {
      res = res | Edit (bnsu->Boundary(i),UV);
    }
    return res;
  }

  DeclareAndCast(IGESGeom_CurveOnSurface,cons,ent);
  if (!cons.IsNull()) {
    Handle(IGESData_IGESEntity) cuv,c3d;
    cuv  = cons->CurveUV();
    c3d  = cons->Curve3D();
    Standard_Integer pref = cons->PreferenceMode();
    if (UV && !c3d.IsNull()) {
      if (cuv.IsNull() || c3d.IsNull()) return Standard_False;  // rien a faire
      cuv.Nullify();
      if (pref == 1) pref = 0;
      if (pref == 3) pref = 2;
    } else if (!cuv.IsNull()) {
      if (cuv.IsNull() || c3d.IsNull()) return Standard_False;  // rien a faire
      c3d.Nullify();
      if (pref == 2) pref = 0;
      if (pref == 3) pref = 1;
    }
    cons->Init ( cons->CreationMode(), cons->Surface(), cuv, c3d, pref );
    return Standard_True;
  }

  DeclareAndCast(IGESGeom_Boundary,bndy,ent);
  if (!bndy.IsNull()) {
    Standard_Integer i, nb = bndy->NbModelSpaceCurves();
    if (nb == 0) return Standard_False;
    Handle(IGESData_HArray1OfIGESEntity) arc3d = new IGESData_HArray1OfIGESEntity(1,nb);
    Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) arcuv = new IGESBasic_HArray1OfHArray1OfIGESEntity (1,nb);
    Handle(TColStd_HArray1OfInteger) sens = new TColStd_HArray1OfInteger(1,nb);
    for (i = 1; i <= nb; i ++) {
      sens->SetValue (i,bndy->Sense(i));
      Handle(IGESData_HArray1OfIGESEntity) cuv = bndy->ParameterCurves(i);
      Handle(IGESData_IGESEntity) c3d = bndy->ModelSpaceCurve (i);
      if (UV) {
	if (cuv.IsNull() || c3d.IsNull()) continue;  // rien a faire
	cuv.Nullify();
	arcuv->SetValue (i,cuv);
      } else {
	if (cuv.IsNull() || c3d.IsNull()) continue;  // rien a faire
	c3d.Nullify();
	arc3d->SetValue (i,c3d);
	res = Standard_True;
      }
    }
//    Y a-t-il eu de la retouche ?
    Standard_Integer pref = bndy->PreferenceType();
    if (UV) {
      if (pref == 2) pref = 0;
      if (pref == 3) pref = 1;
    } else {
      if (pref == 1) pref = 0;
      if (pref == 3) pref = 2;
    }
    if (res) bndy->Init (bndy->BoundaryType(),pref,bndy->Surface(),arc3d,sens,arcuv);
    return res;
  }

  return Standard_False;
}


    void  IGESSelect_RemoveCurves::Performing
  (IFSelect_ContextModif& ctx,
   const Handle(IGESData_IGESModel)& target,
   Interface_CopyTool& TC) const
{
  for (ctx.Start(); ctx.More(); ctx.Next()) {
    if (Edit (ctx.ValueResult(),theUV) ) ctx.Trace ();
  }
}

    TCollection_AsciiString  IGESSelect_RemoveCurves::Label () const
{
  if (theUV) return TCollection_AsciiString ("Remove Curves UV on Face");
  else       return TCollection_AsciiString ("Remove Curves 3D on Face");
}