b311480e |
1 | // Created on: 1992-08-25 |
2 | // Created by: Remi Lequette |
3 | // Copyright (c) 1992-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <BRep_TFace.hxx> |
19 | #include <Geom_Surface.hxx> |
20 | #include <Poly_Triangulation.hxx> |
21 | #include <Standard_Type.hxx> |
42cf5bc1 |
22 | #include <TopLoc_Location.hxx> |
b2d1851c |
23 | #include <TopoDS_Shape.hxx> |
7fd59977 |
24 | |
92efcf78 |
25 | IMPLEMENT_STANDARD_RTTIEXT(BRep_TFace,TopoDS_TFace) |
26 | |
7fd59977 |
27 | //======================================================================= |
28 | //function : BRep_TFace |
29 | //purpose : |
30 | //======================================================================= |
7fd59977 |
31 | BRep_TFace::BRep_TFace() : |
32 | TopoDS_TFace(), |
33 | myTolerance(RealEpsilon()), |
34 | myNaturalRestriction(Standard_False) |
35 | { |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : EmptyCopy |
40 | //purpose : |
41 | //======================================================================= |
42 | |
43 | Handle(TopoDS_TShape) BRep_TFace::EmptyCopy() const |
44 | { |
45 | Handle(BRep_TFace) TF = |
46 | new BRep_TFace(); |
47 | TF->Surface(mySurface); |
48 | TF->Location(myLocation); |
49 | TF->Tolerance(myTolerance); |
50 | return TF; |
51 | } |
bc73b006 |
52 | |
e816dce3 |
53 | //======================================================================= |
54 | //function : Triangulation |
55 | //purpose : |
56 | //======================================================================= |
57 | const Handle(Poly_Triangulation)& BRep_TFace::Triangulation (const Poly_MeshPurpose thePurpose) const |
58 | { |
59 | if (thePurpose == Poly_MeshPurpose_NONE) |
60 | { |
61 | return ActiveTriangulation(); |
62 | } |
63 | for (Poly_ListOfTriangulation::Iterator anIter(myTriangulations); anIter.More(); anIter.Next()) |
64 | { |
65 | const Handle(Poly_Triangulation)& aTriangulation = anIter.Value(); |
66 | if ((aTriangulation->MeshPurpose() & thePurpose) != 0) |
67 | { |
68 | return aTriangulation; |
69 | } |
70 | } |
71 | if ((thePurpose & Poly_MeshPurpose_AnyFallback) != 0 |
72 | && !myTriangulations.IsEmpty()) |
73 | { |
74 | // if none matching other criteria was found return the first defined triangulation |
75 | return myTriangulations.First(); |
76 | } |
77 | static const Handle(Poly_Triangulation) anEmptyTriangulation; |
78 | return anEmptyTriangulation; |
79 | } |
80 | |
81 | //======================================================================= |
82 | //function : Triangulation |
83 | //purpose : |
84 | //======================================================================= |
85 | void BRep_TFace::Triangulation (const Handle(Poly_Triangulation)& theTriangulation, |
86 | const Standard_Boolean theToReset) |
87 | { |
88 | if (theToReset || theTriangulation.IsNull()) |
89 | { |
90 | if (!myActiveTriangulation.IsNull()) |
91 | { |
92 | // Reset Active bit |
93 | myActiveTriangulation->SetMeshPurpose (myActiveTriangulation->MeshPurpose() & ~Poly_MeshPurpose_Active); |
94 | myActiveTriangulation.Nullify(); |
95 | } |
96 | myTriangulations.Clear(); |
97 | if (!theTriangulation.IsNull()) |
98 | { |
99 | // Reset list of triangulations to new list with only one input triangulation that will be active |
100 | myTriangulations.Append (theTriangulation); |
101 | myActiveTriangulation = theTriangulation; |
102 | // Set Active bit |
103 | theTriangulation->SetMeshPurpose (theTriangulation->MeshPurpose() | Poly_MeshPurpose_Active); |
104 | } |
105 | return; |
106 | } |
107 | for (Poly_ListOfTriangulation::Iterator anIter(myTriangulations); anIter.More(); anIter.Next()) |
108 | { |
109 | // Make input triangulation active if it is already contained in list of triangulations |
110 | if (anIter.Value() == theTriangulation) |
111 | { |
112 | if (!myActiveTriangulation.IsNull()) |
113 | { |
114 | // Reset Active bit |
115 | myActiveTriangulation->SetMeshPurpose (myActiveTriangulation->MeshPurpose() & ~Poly_MeshPurpose_Active); |
116 | } |
117 | myActiveTriangulation = theTriangulation; |
118 | // Set Active bit |
119 | theTriangulation->SetMeshPurpose (theTriangulation->MeshPurpose() | Poly_MeshPurpose_Active); |
120 | return; |
121 | } |
122 | } |
123 | for (Poly_ListOfTriangulation::Iterator anIter(myTriangulations); anIter.More(); anIter.Next()) |
124 | { |
125 | // Replace active triangulation to input one |
126 | if (anIter.Value() == myActiveTriangulation) |
127 | { |
128 | // Reset Active bit |
129 | myActiveTriangulation->SetMeshPurpose (myActiveTriangulation->MeshPurpose() & ~Poly_MeshPurpose_Active); |
130 | anIter.ChangeValue() = theTriangulation; |
131 | myActiveTriangulation = theTriangulation; |
132 | // Set Active bit |
133 | theTriangulation->SetMeshPurpose (theTriangulation->MeshPurpose() | Poly_MeshPurpose_Active); |
134 | return; |
135 | } |
136 | } |
137 | } |
138 | |
139 | //======================================================================= |
140 | //function : Triangulations |
141 | //purpose : |
142 | //======================================================================= |
143 | void BRep_TFace::Triangulations (const Poly_ListOfTriangulation& theTriangulations, |
144 | const Handle(Poly_Triangulation)& theActiveTriangulation) |
145 | { |
146 | if (theTriangulations.IsEmpty()) |
147 | { |
148 | myActiveTriangulation.Nullify(); |
149 | myTriangulations.Clear(); |
150 | return; |
151 | } |
152 | Standard_Boolean anActiveInList = false; |
153 | for (Poly_ListOfTriangulation::Iterator anIter(theTriangulations); anIter.More(); anIter.Next()) |
154 | { |
155 | const Handle(Poly_Triangulation)& aTriangulation = anIter.Value(); |
156 | Standard_ASSERT_RAISE (!aTriangulation.IsNull(), "Try to set list with NULL triangulation to the face"); |
157 | if (aTriangulation == theActiveTriangulation) |
158 | { |
159 | anActiveInList = true; |
160 | } |
161 | // Reset Active bit |
162 | aTriangulation->SetMeshPurpose (aTriangulation->MeshPurpose() & ~Poly_MeshPurpose_Active); |
163 | } |
164 | Standard_ASSERT_RAISE (theActiveTriangulation.IsNull() || anActiveInList, "Active triangulation isn't part of triangulations list"); |
165 | myTriangulations = theTriangulations; |
166 | if (theActiveTriangulation.IsNull()) |
167 | { |
168 | // Save the first one as active |
169 | myActiveTriangulation = myTriangulations.First(); |
170 | } |
171 | else |
172 | { |
173 | myActiveTriangulation = theActiveTriangulation; |
174 | } |
175 | myActiveTriangulation->SetMeshPurpose (myActiveTriangulation->MeshPurpose() | Poly_MeshPurpose_Active); |
176 | } |
177 | |
bc73b006 |
178 | //======================================================================= |
179 | //function : DumpJson |
180 | //purpose : |
181 | //======================================================================= |
182 | void BRep_TFace::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
183 | { |
184 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
185 | |
186 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TopoDS_TFace) |
187 | |
e816dce3 |
188 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myActiveTriangulation.get()) |
bc73b006 |
189 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, mySurface.get()) |
bc73b006 |
190 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myLocation) |
191 | |
192 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTolerance) |
193 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNaturalRestriction) |
e816dce3 |
194 | |
195 | for (Poly_ListOfTriangulation::Iterator anIter(myTriangulations); anIter.More(); anIter.Next()) |
196 | { |
197 | const Handle(Poly_Triangulation)& aTriangulation = anIter.Value(); |
198 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aTriangulation.get()) |
199 | } |
bc73b006 |
200 | } |