0032781: Coding - get rid of unused headers [BRepCheck to ChFiKPart]
[occt.git] / src / BRepMesh / BRepMesh_IncrementalMesh.cxx
1 // Created on: 1995-06-20
2 // Created by: Stagiaire Alain JOURDAIN
3 // Copyright (c) 1995-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 #include <BRepMesh_IncrementalMesh.hxx>
18 #include <BRepMesh_Context.hxx>
19 #include <BRepMesh_PluginMacro.hxx>
20 #include <IMeshData_Face.hxx>
21 #include <IMeshData_Wire.hxx>
22 #include <IMeshTools_MeshBuilder.hxx>
23
24 IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_IncrementalMesh, BRepMesh_DiscretRoot)
25
26 namespace
27 {
28   //! Default flag to control parallelization for BRepMesh_IncrementalMesh
29   //! tool returned for Mesh Factory
30   static Standard_Boolean IS_IN_PARALLEL = Standard_False;
31 }
32
33 //=======================================================================
34 //function : Default constructor
35 //purpose  : 
36 //=======================================================================
37 BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh()
38 : myModified(Standard_False),
39   myStatus(IMeshData_NoError)
40 {
41 }
42
43 //=======================================================================
44 //function : Constructor
45 //purpose  : 
46 //=======================================================================
47 BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh( const TopoDS_Shape&    theShape,
48                                                     const Standard_Real    theLinDeflection,
49                                                     const Standard_Boolean isRelative,
50                                                     const Standard_Real    theAngDeflection,
51                                                     const Standard_Boolean isInParallel)
52 : myModified(Standard_False),
53   myStatus(IMeshData_NoError)
54 {
55   myParameters.Deflection = theLinDeflection;
56   myParameters.Angle      = theAngDeflection;
57   myParameters.Relative   = isRelative;
58   myParameters.InParallel = isInParallel;
59
60   myShape = theShape;
61   Perform();
62 }
63
64 //=======================================================================
65 //function : Constructor
66 //purpose  : 
67 //=======================================================================
68 BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh(
69   const TopoDS_Shape&          theShape,
70   const IMeshTools_Parameters& theParameters,
71   const Message_ProgressRange& theRange)
72   : myParameters(theParameters)
73 {
74   myShape = theShape;
75   Perform(theRange);
76 }
77
78 //=======================================================================
79 //function : Destructor
80 //purpose  : 
81 //=======================================================================
82 BRepMesh_IncrementalMesh::~BRepMesh_IncrementalMesh()
83 {
84 }
85
86 //=======================================================================
87 //function : Perform
88 //purpose  : 
89 //=======================================================================
90 void BRepMesh_IncrementalMesh::Perform(const Message_ProgressRange& theRange)
91 {
92   Handle(BRepMesh_Context) aContext = new BRepMesh_Context (myParameters.MeshAlgo);
93   Perform (aContext, theRange);
94 }
95
96 //=======================================================================
97 //function : Perform
98 //purpose  : 
99 //=======================================================================
100 void BRepMesh_IncrementalMesh::Perform(const Handle(IMeshTools_Context)& theContext, const Message_ProgressRange& theRange)
101 {
102   initParameters();
103
104   theContext->SetShape(Shape());
105   theContext->ChangeParameters()            = myParameters;
106   theContext->ChangeParameters().CleanModel = Standard_False;
107
108   Message_ProgressScope aPS(theRange, "Perform incmesh", 10);
109   IMeshTools_MeshBuilder aIncMesh(theContext);
110   aIncMesh.Perform(aPS.Next(9));
111   if (!aPS.More())
112   {
113     myStatus = IMeshData_UserBreak;
114     return;
115   }
116   myStatus = IMeshData_NoError;
117   const Handle(IMeshData_Model)& aModel = theContext->GetModel();
118   if (!aModel.IsNull())
119   {
120     for (Standard_Integer aFaceIt = 0; aFaceIt < aModel->FacesNb(); ++aFaceIt)
121     {
122       const IMeshData::IFaceHandle& aDFace = aModel->GetFace(aFaceIt);
123       myStatus |= aDFace->GetStatusMask();
124
125       for (Standard_Integer aWireIt = 0; aWireIt < aDFace->WiresNb(); ++aWireIt)
126       {
127         const IMeshData::IWireHandle& aDWire = aDFace->GetWire(aWireIt);
128         myStatus |= aDWire->GetStatusMask();
129       }
130     }
131   }
132   aPS.Next(1);
133   setDone();
134 }
135
136 //=======================================================================
137 //function : Discret
138 //purpose  :
139 //=======================================================================
140 Standard_Integer BRepMesh_IncrementalMesh::Discret(
141   const TopoDS_Shape&    theShape,
142   const Standard_Real    theDeflection,
143   const Standard_Real    theAngle,
144   BRepMesh_DiscretRoot* &theAlgo)
145 {
146   BRepMesh_IncrementalMesh* anAlgo = new BRepMesh_IncrementalMesh();
147   anAlgo->ChangeParameters().Deflection = theDeflection;
148   anAlgo->ChangeParameters().Angle      = theAngle;
149   anAlgo->ChangeParameters().InParallel = IS_IN_PARALLEL;
150   anAlgo->SetShape (theShape);
151   theAlgo = anAlgo;
152   return 0; // no error
153 }
154
155 //=======================================================================
156 //function : IsParallelDefault
157 //purpose  :
158 //=======================================================================
159 Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault()
160 {
161   return IS_IN_PARALLEL;
162 }
163
164 //=======================================================================
165 //function : Discret
166 //purpose  :
167 //=======================================================================
168 void BRepMesh_IncrementalMesh::SetParallelDefault(
169   const Standard_Boolean theInParallel)
170 {
171   IS_IN_PARALLEL = theInParallel;
172 }
173
174 //! Export Mesh Plugin entry function
175 DISCRETPLUGIN(BRepMesh_IncrementalMesh)