973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
15 | #include <IFSelect_ContextModif.hxx> |
16 | #include <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx> |
17 | #include <IGESData_HArray1OfIGESEntity.hxx> |
18 | #include <IGESData_IGESEntity.hxx> |
19 | #include <IGESData_IGESModel.hxx> |
7fd59977 |
20 | #include <IGESGeom_BoundedSurface.hxx> |
42cf5bc1 |
21 | #include <IGESGeom_TrimmedSurface.hxx> |
22 | #include <IGESSelect_RemoveCurves.hxx> |
23 | #include <Interface_CopyTool.hxx> |
24 | #include <Interface_Macros.hxx> |
25 | #include <Standard_Type.hxx> |
26 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
27 | #include <TColStd_HArray1OfInteger.hxx> |
28 | |
92efcf78 |
29 | IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_RemoveCurves,IGESSelect_ModelModifier) |
30 | |
7fd59977 |
31 | IGESSelect_RemoveCurves::IGESSelect_RemoveCurves (const Standard_Boolean UV) |
32 | : IGESSelect_ModelModifier (Standard_True) , theUV (UV) { } |
33 | |
34 | static Standard_Boolean Edit |
35 | (const Handle(Standard_Transient)& ent, const Standard_Boolean UV) |
36 | { |
37 | Standard_Boolean res = Standard_False; |
38 | DeclareAndCast(IGESGeom_TrimmedSurface,trsu,ent); |
39 | if (!trsu.IsNull()) { |
40 | res = Edit (trsu->OuterContour(),UV); |
41 | Standard_Integer i,nb = trsu->NbInnerContours(); |
42 | for (i = 1; i <= nb; i ++) { |
43 | res = res | Edit (trsu->InnerContour(i),UV); |
44 | } |
45 | return res; |
46 | } |
47 | |
48 | DeclareAndCast(IGESGeom_BoundedSurface,bnsu,ent); |
49 | if (!bnsu.IsNull()) { |
50 | Standard_Integer i,nb = bnsu->NbBoundaries(); |
51 | for (i = 1; i <= nb; i ++) { |
52 | res = res | Edit (bnsu->Boundary(i),UV); |
53 | } |
54 | return res; |
55 | } |
56 | |
57 | DeclareAndCast(IGESGeom_CurveOnSurface,cons,ent); |
58 | if (!cons.IsNull()) { |
59 | Handle(IGESData_IGESEntity) cuv,c3d; |
60 | cuv = cons->CurveUV(); |
61 | c3d = cons->Curve3D(); |
62 | Standard_Integer pref = cons->PreferenceMode(); |
63 | if (UV && !c3d.IsNull()) { |
64 | if (cuv.IsNull() || c3d.IsNull()) return Standard_False; // rien a faire |
65 | cuv.Nullify(); |
66 | if (pref == 1) pref = 0; |
67 | if (pref == 3) pref = 2; |
68 | } else if (!cuv.IsNull()) { |
69 | if (cuv.IsNull() || c3d.IsNull()) return Standard_False; // rien a faire |
70 | c3d.Nullify(); |
71 | if (pref == 2) pref = 0; |
72 | if (pref == 3) pref = 1; |
73 | } |
74 | cons->Init ( cons->CreationMode(), cons->Surface(), cuv, c3d, pref ); |
75 | return Standard_True; |
76 | } |
77 | |
78 | DeclareAndCast(IGESGeom_Boundary,bndy,ent); |
79 | if (!bndy.IsNull()) { |
80 | Standard_Integer i, nb = bndy->NbModelSpaceCurves(); |
81 | if (nb == 0) return Standard_False; |
82 | Handle(IGESData_HArray1OfIGESEntity) arc3d = new IGESData_HArray1OfIGESEntity(1,nb); |
83 | Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) arcuv = new IGESBasic_HArray1OfHArray1OfIGESEntity (1,nb); |
84 | Handle(TColStd_HArray1OfInteger) sens = new TColStd_HArray1OfInteger(1,nb); |
85 | for (i = 1; i <= nb; i ++) { |
86 | sens->SetValue (i,bndy->Sense(i)); |
87 | Handle(IGESData_HArray1OfIGESEntity) cuv = bndy->ParameterCurves(i); |
88 | Handle(IGESData_IGESEntity) c3d = bndy->ModelSpaceCurve (i); |
89 | if (UV) { |
90 | if (cuv.IsNull() || c3d.IsNull()) continue; // rien a faire |
91 | cuv.Nullify(); |
92 | arcuv->SetValue (i,cuv); |
93 | } else { |
94 | if (cuv.IsNull() || c3d.IsNull()) continue; // rien a faire |
95 | c3d.Nullify(); |
96 | arc3d->SetValue (i,c3d); |
97 | res = Standard_True; |
98 | } |
99 | } |
100 | // Y a-t-il eu de la retouche ? |
101 | Standard_Integer pref = bndy->PreferenceType(); |
102 | if (UV) { |
103 | if (pref == 2) pref = 0; |
104 | if (pref == 3) pref = 1; |
105 | } else { |
106 | if (pref == 1) pref = 0; |
107 | if (pref == 3) pref = 2; |
108 | } |
109 | if (res) bndy->Init (bndy->BoundaryType(),pref,bndy->Surface(),arc3d,sens,arcuv); |
110 | return res; |
111 | } |
112 | |
113 | return Standard_False; |
114 | } |
115 | |
116 | |
35e08fe8 |
117 | void IGESSelect_RemoveCurves::Performing (IFSelect_ContextModif& ctx, |
118 | const Handle(IGESData_IGESModel)& /*target*/, |
119 | Interface_CopyTool& /*TC*/) const |
7fd59977 |
120 | { |
121 | for (ctx.Start(); ctx.More(); ctx.Next()) { |
122 | if (Edit (ctx.ValueResult(),theUV) ) ctx.Trace (); |
123 | } |
124 | } |
125 | |
126 | TCollection_AsciiString IGESSelect_RemoveCurves::Label () const |
127 | { |
128 | if (theUV) return TCollection_AsciiString ("Remove Curves UV on Face"); |
129 | else return TCollection_AsciiString ("Remove Curves 3D on Face"); |
130 | } |