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